diff --git a/.gitignore b/.gitignore index 9a949cb..9d5dcdb 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,22 @@ base_override.h base-full/ bass.lib + +bins/ +release/ +debug/ + +.qmake.stash + +Makefile* +object_script* +/Attorney_Online_remake_resource.rc +/attorney_online_remake_plugin_import.cpp + +server/__pycache__ +discord/ + +*.o +moc* +/Attorney_Online_CC_resource.rc +/attorney_online_cc_plugin_import.cpp diff --git a/Attorney_Online_remake.pro b/Attorney_Online_remake.pro index 86a8607..b3f93b1 100644 --- a/Attorney_Online_remake.pro +++ b/Attorney_Online_remake.pro @@ -10,7 +10,7 @@ greaterThan(QT_MAJOR_VERSION, 4): QT += widgets RC_ICONS = logo.ico -TARGET = Attorney_Online_remake +TARGET = Attorney_Online TEMPLATE = app VERSION = 2.4.10.0 @@ -48,7 +48,10 @@ SOURCES += main.cpp\ aolineedit.cpp \ aotextedit.cpp \ aoevidencedisplay.cpp \ - discord_rich_presence.cpp + discord_rich_presence.cpp \ + aooptionsdialog.cpp \ + chatlogpiece.cpp \ + aocaseannouncerdialog.cpp HEADERS += lobby.h \ aoimage.h \ @@ -78,12 +81,16 @@ HEADERS += lobby.h \ aotextedit.h \ aoevidencedisplay.h \ discord_rich_presence.h \ - discord-rpc.h + discord-rpc.h \ + aooptionsdialog.h \ + text_file_functions.h \ + chatlogpiece.h \ + aocaseannouncerdialog.h # You need to compile the Discord Rich Presence SDK separately and add the lib/headers. # Discord RPC uses CMake, which does not play nicely with QMake, so this step must be manual. -unix:LIBS += -L$$PWD -ldiscord-rpc +unix:LIBS += -L$$PWD -ldiscord-rpc -lbass win32:LIBS += -L$$PWD -ldiscord-rpc #"$$PWD/discord-rpc.dll" CONFIG += c++11 diff --git a/README.md b/README.md index 569b6b2..0df61ae 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,132 @@ +# Attorney Online 2: Case Café Custom Client (AO2:CCCC) + +This project is a custom client made specifically for the Case Café server of Attorney Online 2. Nevertheless, the client itself has a bunch of features that are server independent, and if you so wish to run a server with the additional features, get yourself a copy of `tsuserver3`, and replace its `server/` folder with the one supplied here. + +Building the project is... complicated. I'm not even sure what I'm doing myself, most of the time. Still, get yourself Qt Creator, and compile the project using that, that's the easiest method of doing things. + +Alternatively, you may wait till I make some stuff, and release a compiled executable. You may find said executables in the 'Tags' submenu to the left. + +## Features + +- **Inline colouring:** allows you to change the text's colour midway through the text. + - `()` (parentheses) will make the text inbetween them blue. + - \` (backwards apostrophes) will make the text green. + - `|` (straight lines) will make the text orange. + - `[]` (square brackets) will make the text grey. + - No need for server support: the clients themselves will interpret these. +- **Additional text features:** + - Type `{` to slow down the text a bit. This takes effect after the character has been typed, so the text may take up different speeds at different points. + - Type `}` to do the opposite! Similar rules apply. + - Both of these can be stacked up to three times, and even against eachother. + - As an example, here is a text: + ``` + Hello there! This text goes at normal speed.} Now, it's a bit faster!{ Now, it's back to normal.}}} Now it goes at maximum speed! {{Now it's only a little bit faster than normal. + ``` + - If you begin a message with `~~` (two tildes), those two tildes will be removed, and your message will be centered. +- **Use the in-game settings button:** + - If the theme supports it, you may have a Settings button on the client now, but you can also just type `/settings` in the OOC. + - Modify the contents of your `config.ini` and `callwords.ini` from inside the game! + - Some options may need a restart to take effect. +- **Custom Discord RPC icon and name!** +- **Enhanced character selection screen:** + - The game preloads the characters' icons available on the server, avoiding lag on page switch this way. + - As a side-effect of this, characters can now easily be filtered down to name, whether they are passworded, and if they're taken. +- **Server-supported features:** These will require the modifications in the `server/` folder applied to the server. + - Call mod reason: allows you to input a reason for your modcall. + - Modcalls can be cancelled, if needed. + - Shouts can be disabled serverside (in the sense that they can still interrupt text, but will not make a sound or make the bubble appear). + - The characters' shownames can be changed. + - This needs the server to specifically approve it in areas. + - The client can also turn off the showing of changed shownames if someone is maliciously impersonating someone. + - Any character in the 'jud' position can make a Guilty / Not Guilty text appear with the new button additions. + - These work like the WT / CE popups. + - Capitalisation ignored for server commands. `/getarea` is exactly the same as `/GEtAreA`! + - Various quality-of-life changes for mods, like `/m`, a server-wide mods-only chat. + - Disallow blankposting using `/allow_blankposting`. + - Avoid cucking by setting a jukebox using `/jukebox_toggle`. + - Check the contents of the jukbox with `/jukebox`. + - If you're a mod or the CM, skip the current jukebox song using `/jukebox_skip`. + - Pair up with someone else! + - If two people select eachother's character's character ID using the in-game pair button, or with `/pair [id]`, they will appear on the same screen (assuming they're both in the same position). + - When you appear alongside someone else, you can offset your character to either side using the in-game spinbox, or with `/offset [percentage]`. The percentage can go from -100% (one whole screen's worth to the left) to 100% (one whole screen's worth to the right). + - Areas can have multiple CMs, and these CMs can be anywhere on the server! + - CMs away from the areas they CM in can still see IC and OOC messages coming from there. + - They can also remotely send messages with the `/a [area_id]` command (works both IC and OOC!) or the `/s` command, if they want to message all areas. + - A CM can add other CMs using `/cm [id]`. + - Tired of waiting for pres to finish? Try non-interrupting pres! + - Tired of waiting for OTHERS' pres to finish? `/force_nonint_pres` that thing! + - Also tired of filling evidence up one-by-one? Try `/load_case`! + - Additional juror and seance positions for your RPing / casing needs. + - Areas can be set to locked and spectatable. + - Spectatable areas (using `/area_spectate`) allow people to join, but not talk if they're not on the invite list. + - Locked areas (using `/area_lock`) forbid people not on the invite list from even entering. + - Can't find people to case with? Try the case alert system! + - +- **Area list:** + - The client automatically filters out areas from music if applicable, and these appear in their own list. + - Use the in-game A/M button, or the `/switch_am` command to switch between them. + - If the server supports it, you can even get constant updates about changes in the areas, like players leaving, CMs appearing, statuses changing, etc. +- **Features not mentioned in here?** + - Check the link given by the `/help` function. + - Alternatively, assuming you're reading this on the Github page, browse the wiki! + +## Modifications that need to be done + +Since this custom client, and the server files supplied with it, add a few features not present in Vanilla, some modifications need to be done to ensure that you can use the full extent of them all. These are as follows: + +- **In `areas.yaml`:** (assuming you are the server owner) + - You may add `shouts_allowed` to any of the areas to enable / disable shouts (and judge buttons, and realisation). By default, it's `shouts_allowed: true`. + - You may add `jukebox` to any of the areas to enable the jukebox in there, but you can also use `/jukebox_toggle` in game as a mod to do the same thing. By default, it's `jukebox: false`. + - You may add `showname_changes_allowed` to any of the areas to allow custom shownames used in there. If it's forbidden, players can't send messages or change music as long as they have a custom name set. By default, it's `showname_changes_allowed: false`. + - You may add `abbreviation` to override the server-generated abbreviation of the area. Instead of area numbers, this server-pack uses area abbreviations in server messages for easier understanding (but still uses area IDs in commands, of course). No default here, but here is an example: `abbreviation: SIN` gives the area the abbreviation of 'SIN'. + - You may add `noninterrupting_pres` to force users to use non-interrupting pres only. CCCC users will see the pres play as the text goes, Vanilla users will not see pres at all. The default is `noninterrupting_pres: false`. +- **In your themes:** + - You'll need the following, additional images: + - `notguilty.gif`, which is a gif of the Not Guilty verdict being given. + - `guilty.gif`, which is a gif of the Guilty verdict being given. + - `notguilty.png`, which is a static image for the button for the Not Guilty verdict. + - `guilty.png`, which is a static image for the button for the Guilty verdict. + - `pair_button.png`, which is a static image for the Pair button, when it isn't pressed. + - `pair_button_pressed.png`, which is the same, but for when the button is pressed. + - In your `lobby_design.ini`: + - Extend the width of the `version` label to a bigger size. Said label now shows both the underlying AO's version, and the custom client's version. + - In your `courtroom_sounds.ini`: + - Add a sound effect for `not_guilty`, for example: `not_guilty = sfx-notguilty.wav`. + - Add a sound effect for `guilty`, for example: `guilty = sfx-guilty.wav`. + - Add a sound effect for the case alerts. They work similarly to modcall alerts, or callword alerts. For example: `case_call = sfx-triplegavel-soj.wav`. + - In your `courtroom_design.ini`, place the following new UI elements as and if you wish: + - `log_limit_label`, which is a simple text that exmplains what the spinbox with the numbers is. Needs an X, Y, width, height number. + - `log_limit_spinbox`, which is the spinbox for the log limit, allowing you to set the size of the log limit in-game. Needs the same stuff as above. + - `ic_chat_name`, which is an input field for your custom showname. Needs the same stuff. + - `ao2_ic_chat_name`, which is the same as above, but comes into play when the background has a desk. + - Further comments on this: all `ao2_` UI elements come into play when the background has a desk. However, in AO2 nowadays, it's customary for every background to have a desk, even if it's just an empty gif. So you most likely have never seen the `ao2_`-less UI elements ever come into play, unless someone mis-named a desk or something. + - `showname_enable` is a tickbox that toggles whether you should see shownames or not. This does not influence whether you can USE custom shownames or not, so you can have it off, while still showing a custom showname to everyone else. Needs X, Y, width, height as usual. + - `settings` is a plain button that takes up the OS's looks, like the 'Call mod' button. Takes the same arguments as above. + - You can also just type `/settings` in OOC. + - `char_search` is a text input box on the character selection screen, which allows you to filter characters down to name. Needs the same arguments. + - `char_passworded` is a tickbox, that when ticked, shows all passworded characters on the character selection screen. Needs the same as above. + - `char_taken` is another tickbox, that does the same, but for characters that are taken. + - `not_guilty` is a button similar to the CE / WT buttons, that if pressed, plays the Not Guilty verdict animation. Needs the same arguments. + - `guilty` is similar to `not_guilty`, but for the Guilty verdict. + - `pair_button` is a toggleable button, that shows and hides the pairing list and the offset spinbox. Works similarly to the mute button. + - `pair_list` is a list of all characters in alphabetical order, shown when the user presses the Pair button. If a character is clicked on it, it is selected as the character the user wants to pair up with. + - `pair_offset_spinbox` is a spinbox that allows the user to choose between offsets of -100% to 100%. + - `switch_area_music` is a button with the text 'A/M', that toggles between the music list and the areas list. Though the two are different, they are programmed to take the same space. + - `pre_no_interrupt` is a tickbox with the text 'No Intrpt', that toggles whether preanimations should delay the text or not. + - `area_free_color` is a combination of red, green, and blue values ranging from 0 to 255. This determines the colour of the area in the Area list if it's free, and has a status of IDLE. + - `area_lfp_color` determines the colour of the area if its status is LOOKING-FOR-PLAYERS. + - `area_casing_color` determines the colour of the area if its status is CASING. + - `area_recess_color` determines the colour of the area if its status is RECESS. + - `area_rp_color` determines the colour of the area if its status is RP. + - `area_gaming_color` determines the colour of the area if its status is GAMING. + - `area_locked_color` determines the colour of the area if it is locked, REGARDLESS of status. + - `ooc_default_color` determines the colour of the username in the OOC chat if the message doesn't come from the server. + - `ooc_server_color` determines the colour of the username if the message arrived from the server. + - `casing_button` is a button with the text 'Casing' that when clicked, brings up the Case Announcements dialog. You can give the case a name, and tick whom do you want to alert. You need to be a CM for it to go through. Only people who have at least one of the roles ticked will get the alert. + - `casing` is a tickbox with the text 'Casing'. If ticked, you will get the case announcements alerts you should get, in accordance to the above. In the settings, you can change your defaults on the 'Casing' tab. (That's a buncha things titled 'Casing'!) + +--- + # Attorney-Online-Client-Remake This is a open-source remake of Attorney Online written by OmniTroid. The original Attorney Online client was written by FanatSors in Delphi. diff --git a/android/AndroidManifest.xml b/android/AndroidManifest.xml deleted file mode 100644 index f458c6a..0000000 --- a/android/AndroidManifest.xml +++ /dev/null @@ -1,79 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/android/project.properties b/android/project.properties deleted file mode 100644 index a08f37e..0000000 --- a/android/project.properties +++ /dev/null @@ -1 +0,0 @@ -target=android-21 \ No newline at end of file diff --git a/aoapplication.cpp b/aoapplication.cpp index 62a4a39..67807ff 100644 --- a/aoapplication.cpp +++ b/aoapplication.cpp @@ -5,8 +5,14 @@ #include "networkmanager.h" #include "debug_functions.h" +#include "aooptionsdialog.h" +#include "aocaseannouncerdialog.h" + AOApplication::AOApplication(int &argc, char **argv) : QApplication(argc, argv) { + // Create the QSettings class that points to the config.ini. + configini = new QSettings(get_base_path() + "config.ini", QSettings::IniFormat); + net_manager = new NetworkManager(this); discord = new AttorneyOnline::Discord(); QObject::connect(net_manager, SIGNAL(ms_connect_finished(bool, bool)), @@ -36,7 +42,7 @@ void AOApplication::construct_lobby() int y = (screenGeometry.height()-w_lobby->height()) / 2; w_lobby->move(x, y); - if(is_discord_enabled()) + if (is_discord_enabled()) discord->state_lobby(); w_lobby->show(); @@ -91,6 +97,14 @@ QString AOApplication::get_version_string() QString::number(MINOR_VERSION); } +QString AOApplication::get_cccc_version_string() +{ + return + QString::number(CCCC_RELEASE) + "." + + QString::number(CCCC_MAJOR_VERSION) + "." + + QString::number(CCCC_MINOR_VERSION); +} + void AOApplication::reload_theme() { current_theme = read_theme(); @@ -164,3 +178,18 @@ void AOApplication::ms_connect_finished(bool connected, bool will_retry) } } } + +void AOApplication::call_settings_menu() +{ + AOOptionsDialog* settings = new AOOptionsDialog(nullptr, this); + settings->exec(); + delete settings; +} + + +void AOApplication::call_announce_menu(Courtroom *court) +{ + AOCaseAnnouncerDialog* announcer = new AOCaseAnnouncerDialog(nullptr, this, court); + announcer->exec(); + delete announcer; +} diff --git a/aoapplication.h b/aoapplication.h index f69a0ea..448a843 100644 --- a/aoapplication.h +++ b/aoapplication.h @@ -8,10 +8,21 @@ #include #include #include +#include + #include #include #include +#include + +#include +#include + +#include +#include +#include + class NetworkManager; class Lobby; class Courtroom; @@ -44,6 +55,9 @@ public: void send_ms_packet(AOPacket *p_packet); void send_server_packet(AOPacket *p_packet, bool encoded = true); + void call_settings_menu(); + void call_announce_menu(Courtroom *court); + /////////////////server metadata////////////////// unsigned int s_decryptor = 5; @@ -56,6 +70,10 @@ public: bool improved_loading_enabled = false; bool desk_mod_enabled = false; bool evidence_enabled = false; + bool cccc_ic_support_enabled = false; + bool arup_enabled = false; + bool casing_alerts_enabled = false; + bool modcall_reason_enabled = false; ///////////////loading info/////////////////// @@ -66,6 +84,7 @@ public: int char_list_size = 0; int loaded_chars = 0; + int generated_chars = 0; int evidence_list_size = 0; int loaded_evidence = 0; int music_list_size = 0; @@ -80,6 +99,11 @@ public: int get_minor_version() {return MINOR_VERSION;} QString get_version_string(); + int get_cccc_release() {return CCCC_RELEASE;} + int get_cccc_major_version() {return CCCC_MAJOR_VERSION;} + int get_cccc_minor_version() {return CCCC_MINOR_VERSION;} + QString get_cccc_version_string(); + /////////////////////////////////////////// void set_favorite_list(); @@ -111,8 +135,13 @@ public: ////// Functions for reading and writing files ////// // Implementations file_functions.cpp + // Instead of reinventing the wheel, we'll use a QSettings class. + QSettings *configini; + //Returns the config value for the passed searchline from a properly formatted config ini file - QString read_config(QString searchline); + //QString read_config(QString searchline); + + // No longer necessary. //Reads the theme from config.ini and loads it into the current_theme variable QString read_theme(); @@ -135,11 +164,26 @@ public: //Returns the value of default_blip in config.ini int get_default_blip(); - //Returns true if discord is enabled in config.ini and false otherwise + // Returns the value of whether Discord should be enabled on startup + // from the config.ini. bool is_discord_enabled(); - //Returns true if reverse IC is enabled in config.ini and false otherwise - bool ic_scroll_down_enabled(); + // Returns the value of the maximum amount of lines the IC chatlog + // may contain, from config.ini. + int get_max_log_size(); + + // Returns whether the log should go upwards (new behaviour) + // or downwards (vanilla behaviour). + bool get_log_goes_downwards(); + + // Returns the username the user may have set in config.ini. + QString get_default_username(); + + // Returns the audio device used for the client. + QString get_audio_output_device(); + + // Returns whether the user would like to have custom shownames on by default. + bool get_showname_enabled_by_default(); //Returns the list of words in callwords.ini QStringList get_call_words(); @@ -165,11 +209,14 @@ public: //Returns the color with p_identifier from p_file QColor get_color(QString p_identifier, QString p_file); + // Returns the colour from the misc folder. + QColor get_chat_color(QString p_identifier, QString p_chat); + //Returns the sfx with p_identifier from sounds.ini in the current theme path QString get_sfx(QString p_identifier); //Returns the value of p_search_line within target_tag and terminator_tag - QString read_char_ini(QString p_char, QString p_search_line, QString target_tag, QString terminator_tag); + QString read_char_ini(QString p_char, QString p_search_line, QString target_tag); //Returns the side of the p_char character from that characters ini file QString get_char_side(QString p_char); @@ -192,6 +239,9 @@ public: //Not in use int get_text_delay(QString p_char, QString p_emote); + // Returns the custom realisation used by the character. + QString get_custom_realization(QString p_char); + //Returns the name of p_char QString get_char_name(QString p_char); @@ -222,11 +272,43 @@ public: //Returns p_char's gender QString get_gender(QString p_char); + // ====== + // These are all casing-related settings. + // ====== + + // Returns if the user has casing alerts enabled. + bool get_casing_enabled(); + + // Returns if the user wants to get alerts for the defence role. + bool get_casing_defence_enabled(); + + // Same for prosecution. + bool get_casing_prosecution_enabled(); + + // Same for judge. + bool get_casing_judge_enabled(); + + // Same for juror. + bool get_casing_juror_enabled(); + + // Same for steno. + bool get_casing_steno_enabled(); + + // Same for CM. + bool get_casing_cm_enabled(); + + // Get the message for the CM for casing alerts. + QString get_casing_can_host_cases(); + private: const int RELEASE = 2; const int MAJOR_VERSION = 4; const int MINOR_VERSION = 10; + const int CCCC_RELEASE = 1; + const int CCCC_MAJOR_VERSION = 4; + const int CCCC_MINOR_VERSION = 1; + QString current_theme = "default"; QVector server_list; diff --git a/aoblipplayer.cpp b/aoblipplayer.cpp index 5e3929e..0ea0897 100644 --- a/aoblipplayer.cpp +++ b/aoblipplayer.cpp @@ -2,32 +2,46 @@ AOBlipPlayer::AOBlipPlayer(QWidget *parent, AOApplication *p_ao_app) { - m_sfxplayer = new QSoundEffect; m_parent = parent; ao_app = p_ao_app; } -AOBlipPlayer::~AOBlipPlayer() -{ - m_sfxplayer->stop(); - m_sfxplayer->deleteLater(); -} - void AOBlipPlayer::set_blips(QString p_sfx) { - m_sfxplayer->stop(); QString f_path = ao_app->get_sounds_path() + p_sfx.toLower(); - m_sfxplayer->setSource(QUrl::fromLocalFile(f_path)); + + for (int n_stream = 0 ; n_stream < 5 ; ++n_stream) + { + BASS_StreamFree(m_stream_list[n_stream]); + + m_stream_list[n_stream] = BASS_StreamCreateFile(FALSE, f_path.utf16(), 0, 0, BASS_UNICODE | BASS_ASYNCFILE); + } + set_volume(m_volume); } void AOBlipPlayer::blip_tick() { - m_sfxplayer->play(); + int f_cycle = m_cycle++; + + if (m_cycle == 5) + m_cycle = 0; + + HSTREAM f_stream = m_stream_list[f_cycle]; + + if (ao_app->get_audio_output_device() != "Default") + BASS_ChannelSetDevice(f_stream, BASS_GetDevice()); + BASS_ChannelPlay(f_stream, false); } void AOBlipPlayer::set_volume(int p_value) { m_volume = p_value; - m_sfxplayer->setVolume(p_value / 100.0); + + float volume = p_value / 100.0f; + + for (int n_stream = 0 ; n_stream < 5 ; ++n_stream) + { + BASS_ChannelSetAttribute(m_stream_list[n_stream], BASS_ATTRIB_VOL, volume); + } } diff --git a/aoblipplayer.h b/aoblipplayer.h index c8a8cb6..aebba77 100644 --- a/aoblipplayer.h +++ b/aoblipplayer.h @@ -1,18 +1,17 @@ #ifndef AOBLIPPLAYER_H #define AOBLIPPLAYER_H +#include "bass.h" #include "aoapplication.h" #include #include #include -#include class AOBlipPlayer { public: AOBlipPlayer(QWidget *parent, AOApplication *p_ao_app); - ~AOBlipPlayer(); void set_blips(QString p_sfx); void blip_tick(); @@ -23,9 +22,9 @@ public: private: QWidget *m_parent; AOApplication *ao_app; - QSoundEffect *m_sfxplayer; int m_volume; + HSTREAM m_stream_list[5]; }; #endif // AOBLIPPLAYER_H diff --git a/aocaseannouncerdialog.cpp b/aocaseannouncerdialog.cpp new file mode 100644 index 0000000..6544833 --- /dev/null +++ b/aocaseannouncerdialog.cpp @@ -0,0 +1,81 @@ +#include "aocaseannouncerdialog.h" + +AOCaseAnnouncerDialog::AOCaseAnnouncerDialog(QWidget *parent, AOApplication *p_ao_app, Courtroom *p_court) +{ + ao_app = p_ao_app; + court = p_court; + + setWindowTitle("Case Announcer"); + resize(405, 235); + + AnnouncerButtons = new QDialogButtonBox(this); + + QSizePolicy sizepolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); + sizepolicy.setHorizontalStretch(0); + sizepolicy.setVerticalStretch(0); + sizepolicy.setHeightForWidth(AnnouncerButtons->sizePolicy().hasHeightForWidth()); + AnnouncerButtons->setSizePolicy(sizepolicy); + AnnouncerButtons->setOrientation(Qt::Horizontal); + AnnouncerButtons->setStandardButtons(QDialogButtonBox::Ok|QDialogButtonBox::Cancel); + + QObject::connect(AnnouncerButtons, SIGNAL(accepted()), this, SLOT(ok_pressed())); + QObject::connect(AnnouncerButtons, SIGNAL(rejected()), this, SLOT(cancel_pressed())); + + setUpdatesEnabled(false); + + VBoxLayout = new QVBoxLayout(this); + + FormLayout = new QFormLayout(this); + FormLayout->setLabelAlignment(Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter); + FormLayout->setFormAlignment(Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop); + FormLayout->setContentsMargins(6, 6, 6, 6); + + VBoxLayout->addItem(FormLayout); + VBoxLayout->addWidget(AnnouncerButtons); + + CaseTitleLabel = new QLabel(this); + CaseTitleLabel->setText("Case title:"); + + FormLayout->setWidget(0, QFormLayout::LabelRole, CaseTitleLabel); + + CaseTitleLineEdit = new QLineEdit(this); + CaseTitleLineEdit->setMaxLength(50); + + FormLayout->setWidget(0, QFormLayout::FieldRole, CaseTitleLineEdit); + + DefenceNeeded = new QCheckBox(this); + DefenceNeeded->setText("Defence needed"); + ProsecutorNeeded = new QCheckBox(this); + ProsecutorNeeded->setText("Prosecution needed"); + JudgeNeeded = new QCheckBox(this); + JudgeNeeded->setText("Judge needed"); + JurorNeeded = new QCheckBox(this); + JurorNeeded->setText("Jurors needed"); + StenographerNeeded = new QCheckBox(this); + StenographerNeeded->setText("Stenographer needed"); + + FormLayout->setWidget(1, QFormLayout::FieldRole, DefenceNeeded); + FormLayout->setWidget(2, QFormLayout::FieldRole, ProsecutorNeeded); + FormLayout->setWidget(3, QFormLayout::FieldRole, JudgeNeeded); + FormLayout->setWidget(4, QFormLayout::FieldRole, JurorNeeded); + FormLayout->setWidget(5, QFormLayout::FieldRole, StenographerNeeded); + + setUpdatesEnabled(true); +} + +void AOCaseAnnouncerDialog::ok_pressed() +{ + court->announce_case(CaseTitleLineEdit->text(), + DefenceNeeded->isChecked(), + ProsecutorNeeded->isChecked(), + JudgeNeeded->isChecked(), + JurorNeeded->isChecked(), + StenographerNeeded->isChecked()); + + done(0); +} + +void AOCaseAnnouncerDialog::cancel_pressed() +{ + done(0); +} diff --git a/aocaseannouncerdialog.h b/aocaseannouncerdialog.h new file mode 100644 index 0000000..78e94f3 --- /dev/null +++ b/aocaseannouncerdialog.h @@ -0,0 +1,45 @@ +#ifndef AOCASEANNOUNCERDIALOG_H +#define AOCASEANNOUNCERDIALOG_H + +#include "aoapplication.h" +#include "courtroom.h" + +#include +#include +#include +#include +#include +#include +#include + +class AOCaseAnnouncerDialog : public QDialog +{ + Q_OBJECT + +public: + explicit AOCaseAnnouncerDialog(QWidget *parent = nullptr, AOApplication *p_ao_app = nullptr, Courtroom *p_court = nullptr); + +private: + AOApplication *ao_app; + Courtroom *court; + + QDialogButtonBox *AnnouncerButtons; + + QVBoxLayout *VBoxLayout; + QFormLayout *FormLayout; + + QLabel *CaseTitleLabel; + QLineEdit *CaseTitleLineEdit; + + QCheckBox *DefenceNeeded; + QCheckBox *ProsecutorNeeded; + QCheckBox *JudgeNeeded; + QCheckBox *JurorNeeded; + QCheckBox *StenographerNeeded; + +public slots: + void ok_pressed(); + void cancel_pressed(); +}; + +#endif // AOCASEANNOUNCERDIALOG_H diff --git a/aocharbutton.cpp b/aocharbutton.cpp index 550e819..2d134b1 100644 --- a/aocharbutton.cpp +++ b/aocharbutton.cpp @@ -2,12 +2,14 @@ #include "file_functions.h" -AOCharButton::AOCharButton(QWidget *parent, AOApplication *p_ao_app, int x_pos, int y_pos) : QPushButton(parent) +AOCharButton::AOCharButton(QWidget *parent, AOApplication *p_ao_app, int x_pos, int y_pos, bool is_taken) : QPushButton(parent) { m_parent = parent; ao_app = p_ao_app; + taken = is_taken; + this->resize(60, 60); this->move(x_pos, y_pos); @@ -40,7 +42,11 @@ void AOCharButton::reset() void AOCharButton::set_taken() { - ui_taken->show(); + if (taken) + { + ui_taken->move(0,0); + ui_taken->show(); + } } void AOCharButton::set_passworded() @@ -73,6 +79,7 @@ void AOCharButton::set_image(QString p_character) void AOCharButton::enterEvent(QEvent * e) { + ui_selector->move(this->x() - 1, this->y() - 1); ui_selector->raise(); ui_selector->show(); diff --git a/aocharbutton.h b/aocharbutton.h index 6b80460..6e5e50e 100644 --- a/aocharbutton.h +++ b/aocharbutton.h @@ -14,10 +14,11 @@ class AOCharButton : public QPushButton Q_OBJECT public: - AOCharButton(QWidget *parent, AOApplication *p_ao_app, int x_pos, int y_pos); + AOCharButton(QWidget *parent, AOApplication *p_ao_app, int x_pos, int y_pos, bool is_taken); AOApplication *ao_app; + void refresh(); void reset(); void set_taken(); void set_passworded(); @@ -25,6 +26,8 @@ public: void set_image(QString p_character); private: + bool taken; + QWidget *m_parent; AOImage *ui_taken; diff --git a/aocharmovie.cpp b/aocharmovie.cpp index b591c22..4170855 100644 --- a/aocharmovie.cpp +++ b/aocharmovie.cpp @@ -146,14 +146,30 @@ void AOCharMovie::combo_resize(int w, int h) m_movie->setScaledSize(f_size); } +void AOCharMovie::move(int ax, int ay) +{ + x = ax; + y = ay; + QLabel::move(x, y); +} + void AOCharMovie::frame_change(int n_frame) { if (movie_frames.size() > n_frame) { QPixmap f_pixmap = QPixmap::fromImage(movie_frames.at(n_frame)); + auto aspect_ratio = Qt::KeepAspectRatio; - this->setPixmap(f_pixmap.scaled(this->width(), this->height())); - } + if (f_pixmap.size().width() > f_pixmap.size().height()) + aspect_ratio = Qt::KeepAspectRatioByExpanding; + + if (f_pixmap.size().width() > this->size().width() || f_pixmap.size().height() > this->size().height()) + this->setPixmap(f_pixmap.scaled(this->width(), this->height(), aspect_ratio, Qt::SmoothTransformation)); + else + this->setPixmap(f_pixmap.scaled(this->width(), this->height(), aspect_ratio, Qt::FastTransformation)); + + QLabel::move(x + (this->width() - this->pixmap()->width())/2, y); + } if (m_movie->frameCount() - 1 == n_frame && play_once) { diff --git a/aocharmovie.h b/aocharmovie.h index b26bada..7ef7da3 100644 --- a/aocharmovie.h +++ b/aocharmovie.h @@ -25,6 +25,8 @@ public: void stop(); + void move(int ax, int ay); + void combo_resize(int w, int h); private: @@ -36,6 +38,10 @@ private: const int time_mod = 62; + // These are the X and Y values before they are fixed based on the sprite's width. + int x = 0; + int y = 0; + bool m_flipped = false; bool play_once = true; diff --git a/aomovie.cpp b/aomovie.cpp index 90c3701..d7727aa 100644 --- a/aomovie.cpp +++ b/aomovie.cpp @@ -32,13 +32,16 @@ void AOMovie::play(QString p_gif, QString p_char, QString p_custom_theme) else custom_path = ao_app->get_character_path(p_char) + p_gif + "_bubble.gif"; + QString misc_path = ao_app->get_base_path() + "misc/" + p_custom_theme + "/" + p_gif + "_bubble.gif"; QString custom_theme_path = ao_app->get_base_path() + "themes/" + p_custom_theme + "/" + p_gif + ".gif"; QString theme_path = ao_app->get_theme_path() + p_gif + ".gif"; QString default_theme_path = ao_app->get_default_theme_path() + p_gif + ".gif"; QString placeholder_path = ao_app->get_theme_path() + "placeholder.gif"; QString default_placeholder_path = ao_app->get_default_theme_path() + "placeholder.gif"; - if (file_exists(custom_path)) + if (file_exists(misc_path)) + gif_path = misc_path; + else if (file_exists(custom_path)) gif_path = custom_path; else if (file_exists(custom_theme_path)) gif_path = custom_theme_path; diff --git a/aomusicplayer.cpp b/aomusicplayer.cpp index ca37ac7..bd36393 100644 --- a/aomusicplayer.cpp +++ b/aomusicplayer.cpp @@ -4,24 +4,31 @@ AOMusicPlayer::AOMusicPlayer(QWidget *parent, AOApplication *p_ao_app) { m_parent = parent; ao_app = p_ao_app; - m_player = new QMediaPlayer; } AOMusicPlayer::~AOMusicPlayer() { - m_player->stop(); - m_player->deleteLater(); + BASS_ChannelStop(m_stream); } void AOMusicPlayer::play(QString p_song) { - m_player->setMedia(QUrl::fromLocalFile(ao_app->get_music_path(p_song))); + BASS_ChannelStop(m_stream); + + QString f_path = ao_app->get_music_path(p_song); + + m_stream = BASS_StreamCreateFile(FALSE, f_path.utf16(), 0, 0, BASS_STREAM_AUTOFREE | BASS_UNICODE | BASS_ASYNCFILE); + this->set_volume(m_volume); - m_player->play(); + + if (ao_app->get_audio_output_device() != "Default") + BASS_ChannelSetDevice(m_stream, BASS_GetDevice()); + BASS_ChannelPlay(m_stream, false); } void AOMusicPlayer::set_volume(int p_value) { m_volume = p_value; - m_player->setVolume(p_value); + float volume = m_volume / 100.0f; + BASS_ChannelSetAttribute(m_stream, BASS_ATTRIB_VOL, volume); } diff --git a/aomusicplayer.h b/aomusicplayer.h index f7b2d0d..560a7f9 100644 --- a/aomusicplayer.h +++ b/aomusicplayer.h @@ -1,12 +1,12 @@ #ifndef AOMUSICPLAYER_H #define AOMUSICPLAYER_H +#include "bass.h" #include "aoapplication.h" #include #include #include -#include class AOMusicPlayer { @@ -21,8 +21,8 @@ private: QWidget *m_parent; AOApplication *ao_app; - QMediaPlayer *m_player; int m_volume = 0; + HSTREAM m_stream; }; #endif // AOMUSICPLAYER_H diff --git a/aooptionsdialog.cpp b/aooptionsdialog.cpp new file mode 100644 index 0000000..b459923 --- /dev/null +++ b/aooptionsdialog.cpp @@ -0,0 +1,497 @@ +#include "aooptionsdialog.h" +#include "aoapplication.h" +#include "bass.h" + +AOOptionsDialog::AOOptionsDialog(QWidget *parent, AOApplication *p_ao_app) : QDialog(parent) +{ + ao_app = p_ao_app; + + // Setting up the basics. + // setAttribute(Qt::WA_DeleteOnClose); + setWindowTitle("Settings"); + resize(398, 320); + + SettingsButtons = new QDialogButtonBox(this); + + QSizePolicy sizePolicy1(QSizePolicy::Expanding, QSizePolicy::Fixed); + sizePolicy1.setHorizontalStretch(0); + sizePolicy1.setVerticalStretch(0); + sizePolicy1.setHeightForWidth(SettingsButtons->sizePolicy().hasHeightForWidth()); + SettingsButtons->setSizePolicy(sizePolicy1); + SettingsButtons->setOrientation(Qt::Horizontal); + SettingsButtons->setStandardButtons(QDialogButtonBox::Cancel|QDialogButtonBox::Save); + + QObject::connect(SettingsButtons, SIGNAL(accepted()), this, SLOT(save_pressed())); + QObject::connect(SettingsButtons, SIGNAL(rejected()), this, SLOT(discard_pressed())); + + // We'll stop updates so that the window won't flicker while it's being made. + setUpdatesEnabled(false); + + // First of all, we want a tabbed dialog, so let's add some layout. + verticalLayout = new QVBoxLayout(this); + SettingsTabs = new QTabWidget(this); + + verticalLayout->addWidget(SettingsTabs); + verticalLayout->addWidget(SettingsButtons); + + // Let's add the tabs one by one. + // First, we'll start with 'Gameplay'. + GameplayTab = new QWidget(); + SettingsTabs->addTab(GameplayTab, "Gameplay"); + + formLayoutWidget = new QWidget(GameplayTab); + formLayoutWidget->setGeometry(QRect(10, 10, 361, 211)); + + GameplayForm = new QFormLayout(formLayoutWidget); + GameplayForm->setLabelAlignment(Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter); + GameplayForm->setFormAlignment(Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop); + GameplayForm->setContentsMargins(0, 0, 0, 0); + + ThemeLabel = new QLabel(formLayoutWidget); + ThemeLabel->setText("Theme:"); + ThemeLabel->setToolTip("Allows you to set the theme used ingame. If your theme changes the lobby's look, too, you'll obviously need to reload the lobby somehow for it take effect. Joining a server and leaving it should work."); + GameplayForm->setWidget(0, QFormLayout::LabelRole, ThemeLabel); + + ThemeCombobox = new QComboBox(formLayoutWidget); + + // Fill the combobox with the names of the themes. + QDirIterator it(p_ao_app->get_base_path() + "themes", QDir::Dirs, QDirIterator::NoIteratorFlags); + while (it.hasNext()) + { + QString actualname = QDir(it.next()).dirName(); + if (actualname != "." && actualname != "..") + ThemeCombobox->addItem(actualname); + if (actualname == p_ao_app->read_theme()) + ThemeCombobox->setCurrentIndex(ThemeCombobox->count()-1); + } + + GameplayForm->setWidget(0, QFormLayout::FieldRole, ThemeCombobox); + + ThemeLogDivider = new QFrame(formLayoutWidget); + ThemeLogDivider->setMidLineWidth(0); + ThemeLogDivider->setFrameShape(QFrame::HLine); + ThemeLogDivider->setFrameShadow(QFrame::Sunken); + + GameplayForm->setWidget(1, QFormLayout::FieldRole, ThemeLogDivider); + + DownwardsLabel = new QLabel(formLayoutWidget); + DownwardsLabel->setText("Log goes downwards:"); + DownwardsLabel->setToolTip("If ticked, the IC chatlog will go downwards, in the sense that new messages will appear at the bottom (like the OOC chatlog). The Vanilla behaviour is equivalent to this being unticked."); + + GameplayForm->setWidget(2, QFormLayout::LabelRole, DownwardsLabel); + + DownwardCheckbox = new QCheckBox(formLayoutWidget); + DownwardCheckbox->setChecked(p_ao_app->get_log_goes_downwards()); + + GameplayForm->setWidget(2, QFormLayout::FieldRole, DownwardCheckbox); + + LengthLabel = new QLabel(formLayoutWidget); + LengthLabel->setText("Log length:"); + LengthLabel->setToolTip("The amount of messages the IC chatlog will keep before getting rid of older messages. A value of 0 or below counts as 'infinite'."); + + GameplayForm->setWidget(3, QFormLayout::LabelRole, LengthLabel); + + LengthSpinbox = new QSpinBox(formLayoutWidget); + LengthSpinbox->setMaximum(10000); + LengthSpinbox->setValue(p_ao_app->get_max_log_size()); + + GameplayForm->setWidget(3, QFormLayout::FieldRole, LengthSpinbox); + + LogNamesDivider = new QFrame(formLayoutWidget); + LogNamesDivider->setFrameShape(QFrame::HLine); + LogNamesDivider->setFrameShadow(QFrame::Sunken); + + GameplayForm->setWidget(4, QFormLayout::FieldRole, LogNamesDivider); + + UsernameLabel = new QLabel(formLayoutWidget); + UsernameLabel->setText("Default username:"); + UsernameLabel->setToolTip("Your OOC name will be filled in with this string when you join a server."); + + GameplayForm->setWidget(5, QFormLayout::LabelRole, UsernameLabel); + + UsernameLineEdit = new QLineEdit(formLayoutWidget); + UsernameLineEdit->setMaxLength(30); + UsernameLineEdit->setText(p_ao_app->get_default_username()); + + GameplayForm->setWidget(5, QFormLayout::FieldRole, UsernameLineEdit); + + ShownameLabel = new QLabel(formLayoutWidget); + ShownameLabel->setText("Custom shownames:"); + ShownameLabel->setToolTip("Gives the default value for the ingame 'Custom shownames' tickbox, which in turn determines whether your client should display custom shownames or not."); + + GameplayForm->setWidget(6, QFormLayout::LabelRole, ShownameLabel); + + ShownameCheckbox = new QCheckBox(formLayoutWidget); + ShownameCheckbox->setChecked(p_ao_app->get_showname_enabled_by_default()); + + GameplayForm->setWidget(6, QFormLayout::FieldRole, ShownameCheckbox); + + NetDivider = new QFrame(formLayoutWidget); + NetDivider->setFrameShape(QFrame::HLine); + NetDivider->setFrameShadow(QFrame::Sunken); + + GameplayForm->setWidget(7, QFormLayout::FieldRole, NetDivider); + + MasterServerLabel = new QLabel(formLayoutWidget); + MasterServerLabel->setText("Backup MS:"); + MasterServerLabel->setToolTip("After the built-in server lookups fail, the game will try the address given here and use it as a backup masterserver address."); + + GameplayForm->setWidget(8, QFormLayout::LabelRole, MasterServerLabel); + + QSettings* configini = ao_app->configini; + MasterServerLineEdit = new QLineEdit(formLayoutWidget); + MasterServerLineEdit->setText(configini->value("master", "").value()); + + GameplayForm->setWidget(8, QFormLayout::FieldRole, MasterServerLineEdit); + + DiscordLabel = new QLabel(formLayoutWidget); + DiscordLabel->setText("Discord:"); + DiscordLabel->setToolTip("If true, allows Discord's Rich Presence to read data about your game. These are: what server you are in, what character are you playing, and how long have you been playing for."); + + GameplayForm->setWidget(9, QFormLayout::LabelRole, DiscordLabel); + + DiscordCheckBox = new QCheckBox(formLayoutWidget); + DiscordCheckBox->setChecked(ao_app->is_discord_enabled()); + + GameplayForm->setWidget(9, QFormLayout::FieldRole, DiscordCheckBox); + + // Here we start the callwords tab. + CallwordsTab = new QWidget(); + SettingsTabs->addTab(CallwordsTab, "Callwords"); + + verticalLayoutWidget = new QWidget(CallwordsTab); + verticalLayoutWidget->setGeometry(QRect(10, 10, 361, 211)); + + CallwordsLayout = new QVBoxLayout(verticalLayoutWidget); + CallwordsLayout->setContentsMargins(0,0,0,0); + + CallwordsTextEdit = new QPlainTextEdit(verticalLayoutWidget); + QSizePolicy sizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); + sizePolicy.setHorizontalStretch(0); + sizePolicy.setVerticalStretch(0); + sizePolicy.setHeightForWidth(CallwordsTextEdit->sizePolicy().hasHeightForWidth()); + CallwordsTextEdit->setSizePolicy(sizePolicy); + + // Let's fill the callwords text edit with the already present callwords. + CallwordsTextEdit->document()->clear(); + foreach (QString callword, p_ao_app->get_call_words()) { + CallwordsTextEdit->appendPlainText(callword); + } + + CallwordsLayout->addWidget(CallwordsTextEdit); + + CallwordsExplainLabel = new QLabel(verticalLayoutWidget); + CallwordsExplainLabel->setWordWrap(true); + CallwordsExplainLabel->setText("Enter as many callwords as you would like. These are case insensitive. Make sure to leave every callword in its own line!
Do not leave a line with a space at the end -- you will be alerted everytime someone uses a space in their messages."); + + CallwordsLayout->addWidget(CallwordsExplainLabel); + + // The audio tab. + AudioTab = new QWidget(); + SettingsTabs->addTab(AudioTab, "Audio"); + + formLayoutWidget_2 = new QWidget(AudioTab); + formLayoutWidget_2->setGeometry(QRect(10, 10, 361, 211)); + + AudioForm = new QFormLayout(formLayoutWidget_2); + AudioForm->setObjectName(QStringLiteral("AudioForm")); + AudioForm->setLabelAlignment(Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter); + AudioForm->setFormAlignment(Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop); + AudioForm->setContentsMargins(0, 0, 0, 0); + + AudioDevideLabel = new QLabel(formLayoutWidget_2); + AudioDevideLabel->setText("Audio device:"); + AudioDevideLabel->setToolTip("Allows you to set the theme used ingame. If your theme changes the lobby's look, too, you'll obviously need to reload the lobby somehow for it take effect. Joining a server and leaving it should work."); + + AudioForm->setWidget(0, QFormLayout::LabelRole, AudioDevideLabel); + + AudioDeviceCombobox = new QComboBox(formLayoutWidget_2); + + // Let's fill out the combobox with the available audio devices. + int a = 0; + BASS_DEVICEINFO info; + + if (needs_default_audiodev()) + { + AudioDeviceCombobox->addItem("Default"); + } + + for (a = 0; BASS_GetDeviceInfo(a, &info); a++) + { + AudioDeviceCombobox->addItem(info.name); + if (p_ao_app->get_audio_output_device() == info.name) + AudioDeviceCombobox->setCurrentIndex(AudioDeviceCombobox->count()-1); + } + + AudioForm->setWidget(0, QFormLayout::FieldRole, AudioDeviceCombobox); + + DeviceVolumeDivider = new QFrame(formLayoutWidget_2); + DeviceVolumeDivider->setFrameShape(QFrame::HLine); + DeviceVolumeDivider->setFrameShadow(QFrame::Sunken); + + AudioForm->setWidget(1, QFormLayout::FieldRole, DeviceVolumeDivider); + + MusicVolumeLabel = new QLabel(formLayoutWidget_2); + MusicVolumeLabel->setText("Music:"); + MusicVolumeLabel->setToolTip("Sets the music's default volume."); + + AudioForm->setWidget(2, QFormLayout::LabelRole, MusicVolumeLabel); + + MusicVolumeSpinbox = new QSpinBox(formLayoutWidget_2); + MusicVolumeSpinbox->setValue(p_ao_app->get_default_music()); + MusicVolumeSpinbox->setMaximum(100); + MusicVolumeSpinbox->setSuffix("%"); + + AudioForm->setWidget(2, QFormLayout::FieldRole, MusicVolumeSpinbox); + + SFXVolumeLabel = new QLabel(formLayoutWidget_2); + SFXVolumeLabel->setText("SFX:"); + SFXVolumeLabel->setToolTip("Sets the SFX's default volume. Interjections and actual sound effects count as 'SFX'."); + + AudioForm->setWidget(3, QFormLayout::LabelRole, SFXVolumeLabel); + + SFXVolumeSpinbox = new QSpinBox(formLayoutWidget_2); + SFXVolumeSpinbox->setValue(p_ao_app->get_default_sfx()); + SFXVolumeSpinbox->setMaximum(100); + SFXVolumeSpinbox->setSuffix("%"); + + AudioForm->setWidget(3, QFormLayout::FieldRole, SFXVolumeSpinbox); + + BlipsVolumeLabel = new QLabel(formLayoutWidget_2); + BlipsVolumeLabel->setText("Blips:"); + BlipsVolumeLabel->setToolTip("Sets the volume of the blips, the talking sound effects."); + + AudioForm->setWidget(4, QFormLayout::LabelRole, BlipsVolumeLabel); + + BlipsVolumeSpinbox = new QSpinBox(formLayoutWidget_2); + BlipsVolumeSpinbox->setValue(p_ao_app->get_default_blip()); + BlipsVolumeSpinbox->setMaximum(100); + BlipsVolumeSpinbox->setSuffix("%"); + + AudioForm->setWidget(4, QFormLayout::FieldRole, BlipsVolumeSpinbox); + + VolumeBlipDivider = new QFrame(formLayoutWidget_2); + VolumeBlipDivider->setFrameShape(QFrame::HLine); + VolumeBlipDivider->setFrameShadow(QFrame::Sunken); + + AudioForm->setWidget(5, QFormLayout::FieldRole, VolumeBlipDivider); + + BlipRateLabel = new QLabel(formLayoutWidget_2); + BlipRateLabel->setText("Blip rate:"); + BlipRateLabel->setToolTip("Sets the delay between playing the blip sounds."); + + AudioForm->setWidget(6, QFormLayout::LabelRole, BlipRateLabel); + + BlipRateSpinbox = new QSpinBox(formLayoutWidget_2); + BlipRateSpinbox->setValue(p_ao_app->read_blip_rate()); + BlipRateSpinbox->setMinimum(1); + + AudioForm->setWidget(6, QFormLayout::FieldRole, BlipRateSpinbox); + + BlankBlipsLabel = new QLabel(formLayoutWidget_2); + BlankBlipsLabel->setText("Blank blips:"); + BlankBlipsLabel->setToolTip("If true, the game will play a blip sound even when a space is 'being said'."); + + AudioForm->setWidget(7, QFormLayout::LabelRole, BlankBlipsLabel); + + BlankBlipsCheckbox = new QCheckBox(formLayoutWidget_2); + BlankBlipsCheckbox->setChecked(p_ao_app->get_blank_blip()); + + AudioForm->setWidget(7, QFormLayout::FieldRole, BlankBlipsCheckbox); + + // The casing tab! + CasingTab = new QWidget(); + SettingsTabs->addTab(CasingTab, "Casing"); + + formLayoutWidget_3 = new QWidget(CasingTab); + formLayoutWidget_3->setGeometry(QRect(10,10, 361, 211)); + + CasingForm = new QFormLayout(formLayoutWidget_3); + CasingForm->setObjectName(QStringLiteral("CasingForm")); + CasingForm->setLabelAlignment(Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter); + CasingForm->setFormAlignment(Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop); + CasingForm->setContentsMargins(0, 0, 0, 0); + + // -- SERVER SUPPORTS CASING + + ServerSupportsCasing = new QLabel(formLayoutWidget_3); + if (ao_app->casing_alerts_enabled) + ServerSupportsCasing->setText("This server supports case alerts."); + else + ServerSupportsCasing->setText("This server does not support case alerts."); + ServerSupportsCasing->setToolTip("Pretty self-explanatory."); + + CasingForm->setWidget(0, QFormLayout::FieldRole, ServerSupportsCasing); + + // -- CASE ANNOUNCEMENTS + + CasingEnabledLabel = new QLabel(formLayoutWidget_3); + CasingEnabledLabel->setText("Casing:"); + CasingEnabledLabel->setToolTip("If checked, you will get alerts about case announcements."); + + CasingForm->setWidget(1, QFormLayout::LabelRole, CasingEnabledLabel); + + CasingEnabledCheckbox = new QCheckBox(formLayoutWidget_3); + CasingEnabledCheckbox->setChecked(ao_app->get_casing_enabled()); + + CasingForm->setWidget(1, QFormLayout::FieldRole, CasingEnabledCheckbox); + + // -- DEFENCE ANNOUNCEMENTS + + DefenceLabel = new QLabel(formLayoutWidget_3); + DefenceLabel->setText("Defence:"); + DefenceLabel->setToolTip("If checked, you will get alerts about case announcements if a defence spot is open."); + + CasingForm->setWidget(2, QFormLayout::LabelRole, DefenceLabel); + + DefenceCheckbox = new QCheckBox(formLayoutWidget_3); + DefenceCheckbox->setChecked(ao_app->get_casing_defence_enabled()); + + CasingForm->setWidget(2, QFormLayout::FieldRole, DefenceCheckbox); + + // -- PROSECUTOR ANNOUNCEMENTS + + ProsecutorLabel = new QLabel(formLayoutWidget_3); + ProsecutorLabel->setText("Prosecution:"); + ProsecutorLabel->setToolTip("If checked, you will get alerts about case announcements if a prosecutor spot is open."); + + CasingForm->setWidget(3, QFormLayout::LabelRole, ProsecutorLabel); + + ProsecutorCheckbox = new QCheckBox(formLayoutWidget_3); + ProsecutorCheckbox->setChecked(ao_app->get_casing_prosecution_enabled()); + + CasingForm->setWidget(3, QFormLayout::FieldRole, ProsecutorCheckbox); + + // -- JUDGE ANNOUNCEMENTS + + JudgeLabel = new QLabel(formLayoutWidget_3); + JudgeLabel->setText("Judge:"); + JudgeLabel->setToolTip("If checked, you will get alerts about case announcements if the judge spot is open."); + + CasingForm->setWidget(4, QFormLayout::LabelRole, JudgeLabel); + + JudgeCheckbox = new QCheckBox(formLayoutWidget_3); + JudgeCheckbox->setChecked(ao_app->get_casing_judge_enabled()); + + CasingForm->setWidget(4, QFormLayout::FieldRole, JudgeCheckbox); + + // -- JUROR ANNOUNCEMENTS + + JurorLabel = new QLabel(formLayoutWidget_3); + JurorLabel->setText("Juror:"); + JurorLabel->setToolTip("If checked, you will get alerts about case announcements if a juror spot is open."); + + CasingForm->setWidget(5, QFormLayout::LabelRole, JurorLabel); + + JurorCheckbox = new QCheckBox(formLayoutWidget_3); + JurorCheckbox->setChecked(ao_app->get_casing_juror_enabled()); + + CasingForm->setWidget(5, QFormLayout::FieldRole, JurorCheckbox); + + // -- STENO ANNOUNCEMENTS + + StenographerLabel = new QLabel(formLayoutWidget_3); + StenographerLabel->setText("Stenographer:"); + StenographerLabel->setToolTip("If checked, you will get alerts about case announcements if a stenographer spot is open."); + + CasingForm->setWidget(6, QFormLayout::LabelRole, StenographerLabel); + + StenographerCheckbox = new QCheckBox(formLayoutWidget_3); + StenographerCheckbox->setChecked(ao_app->get_casing_steno_enabled()); + + CasingForm->setWidget(6, QFormLayout::FieldRole, StenographerCheckbox); + + // -- CM ANNOUNCEMENTS + + CMLabel = new QLabel(formLayoutWidget_3); + CMLabel->setText("CM:"); + CMLabel->setToolTip("If checked, you will appear amongst the potential CMs on the server."); + + CasingForm->setWidget(7, QFormLayout::LabelRole, CMLabel); + + CMCheckbox = new QCheckBox(formLayoutWidget_3); + CMCheckbox->setChecked(ao_app->get_casing_cm_enabled()); + + CasingForm->setWidget(7, QFormLayout::FieldRole, CMCheckbox); + + // -- CM CASES ANNOUNCEMENTS + + CMCasesLabel = new QLabel(formLayoutWidget_3); + CMCasesLabel->setText("Hosting cases:"); + CMCasesLabel->setToolTip("If you're a CM, enter what cases are you willing to host."); + + CasingForm->setWidget(8, QFormLayout::LabelRole, CMCasesLabel); + + CMCasesLineEdit = new QLineEdit(formLayoutWidget_3); + CMCasesLineEdit->setText(ao_app->get_casing_can_host_cases()); + + CasingForm->setWidget(8, QFormLayout::FieldRole, CMCasesLineEdit); + + // When we're done, we should continue the updates! + setUpdatesEnabled(true); +} + +void AOOptionsDialog::save_pressed() +{ + // Save everything into the config.ini. + QSettings* configini = ao_app->configini; + + configini->setValue("theme", ThemeCombobox->currentText()); + configini->setValue("log_goes_downwards", DownwardCheckbox->isChecked()); + configini->setValue("log_maximum", LengthSpinbox->value()); + configini->setValue("default_username", UsernameLineEdit->text()); + configini->setValue("show_custom_shownames", ShownameCheckbox->isChecked()); + configini->setValue("master", MasterServerLineEdit->text()); + configini->setValue("discord", DiscordCheckBox->isChecked()); + + QFile* callwordsini = new QFile(ao_app->get_base_path() + "callwords.ini"); + + if (!callwordsini->open(QIODevice::WriteOnly | QIODevice::Truncate | QIODevice::Text)) + { + // Nevermind! + } + else + { + QTextStream out(callwordsini); + out << CallwordsTextEdit->toPlainText(); + callwordsini->close(); + } + + configini->setValue("default_audio_device", AudioDeviceCombobox->currentText()); + configini->setValue("default_music", MusicVolumeSpinbox->value()); + configini->setValue("default_sfx", SFXVolumeSpinbox->value()); + configini->setValue("default_blip", BlipsVolumeSpinbox->value()); + configini->setValue("blip_rate", BlipRateSpinbox->value()); + configini->setValue("blank_blip", BlankBlipsCheckbox->isChecked()); + + configini->setValue("casing_enabled", CasingEnabledCheckbox->isChecked()); + configini->setValue("casing_defence_enabled", DefenceCheckbox->isChecked()); + configini->setValue("casing_prosecution_enabled", ProsecutorCheckbox->isChecked()); + configini->setValue("casing_judge_enabled", JudgeCheckbox->isChecked()); + configini->setValue("casing_juror_enabled", JurorCheckbox->isChecked()); + configini->setValue("casing_steno_enabled", StenographerCheckbox->isChecked()); + configini->setValue("casing_cm_enabled", CMCheckbox->isChecked()); + configini->setValue("casing_can_host_casees", CMCasesLineEdit->text()); + + callwordsini->close(); + done(0); +} + +void AOOptionsDialog::discard_pressed() +{ + done(0); +} + +#if (defined (_WIN32) || defined (_WIN64)) +bool AOOptionsDialog::needs_default_audiodev() +{ + return true; +} +#elif (defined (LINUX) || defined (__linux__)) +bool AOOptionsDialog::needs_default_audiodev() +{ + return false; +} +#else +#error This operating system is not supported. +#endif diff --git a/aooptionsdialog.h b/aooptionsdialog.h new file mode 100644 index 0000000..0480eb8 --- /dev/null +++ b/aooptionsdialog.h @@ -0,0 +1,115 @@ +#ifndef AOOPTIONSDIALOG_H +#define AOOPTIONSDIALOG_H + +#include "aoapplication.h" +#include "bass.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +class AOOptionsDialog: public QDialog +{ + Q_OBJECT +public: + explicit AOOptionsDialog(QWidget *parent = nullptr, AOApplication *p_ao_app = nullptr); + +private: + AOApplication *ao_app; + + QVBoxLayout *verticalLayout; + QTabWidget *SettingsTabs; + + QWidget *GameplayTab; + QWidget *formLayoutWidget; + QFormLayout *GameplayForm; + QLabel *ThemeLabel; + QComboBox *ThemeCombobox; + QFrame *ThemeLogDivider; + QLabel *DownwardsLabel; + QCheckBox *DownwardCheckbox; + QLabel *LengthLabel; + QSpinBox *LengthSpinbox; + QFrame *LogNamesDivider; + QLineEdit *UsernameLineEdit; + QLabel *UsernameLabel; + QLabel *ShownameLabel; + QCheckBox *ShownameCheckbox; + QFrame *NetDivider; + QLabel *MasterServerLabel; + QLineEdit *MasterServerLineEdit; + QLabel *DiscordLabel; + QCheckBox *DiscordCheckBox; + + QWidget *CallwordsTab; + QWidget *verticalLayoutWidget; + QVBoxLayout *CallwordsLayout; + QPlainTextEdit *CallwordsTextEdit; + QLabel *CallwordsExplainLabel; + QCheckBox *CharacterCallwordsCheckbox; + + QWidget *AudioTab; + QWidget *formLayoutWidget_2; + QFormLayout *AudioForm; + QLabel *AudioDevideLabel; + QComboBox *AudioDeviceCombobox; + QFrame *DeviceVolumeDivider; + QSpinBox *MusicVolumeSpinbox; + QLabel *MusicVolumeLabel; + QSpinBox *SFXVolumeSpinbox; + QSpinBox *BlipsVolumeSpinbox; + QLabel *SFXVolumeLabel; + QLabel *BlipsVolumeLabel; + QFrame *VolumeBlipDivider; + QSpinBox *BlipRateSpinbox; + QLabel *BlipRateLabel; + QCheckBox *BlankBlipsCheckbox; + QLabel *BlankBlipsLabel; + QDialogButtonBox *SettingsButtons; + + QWidget *CasingTab; + QWidget *formLayoutWidget_3; + QFormLayout *CasingForm; + QLabel *ServerSupportsCasing; + QLabel *CasingEnabledLabel; + QCheckBox *CasingEnabledCheckbox; + QLabel *DefenceLabel; + QCheckBox *DefenceCheckbox; + QLabel *ProsecutorLabel; + QCheckBox *ProsecutorCheckbox; + QLabel *JudgeLabel; + QCheckBox *JudgeCheckbox; + QLabel *JurorLabel; + QCheckBox *JurorCheckbox; + QLabel *StenographerLabel; + QCheckBox *StenographerCheckbox; + QLabel *CMLabel; + QCheckBox *CMCheckbox; + QLabel *CMCasesLabel; + QLineEdit *CMCasesLineEdit; + + bool needs_default_audiodev(); + +signals: + +public slots: + void save_pressed(); + void discard_pressed(); +}; + +#endif // AOOPTIONSDIALOG_H diff --git a/aoscene.cpp b/aoscene.cpp index 5fe8304..dde671f 100644 --- a/aoscene.cpp +++ b/aoscene.cpp @@ -6,6 +6,7 @@ AOScene::AOScene(QWidget *parent, AOApplication *p_ao_app) : QLabel(parent) { m_parent = parent; ao_app = p_ao_app; + m_movie = new QMovie(this); } void AOScene::set_image(QString p_image) @@ -15,18 +16,31 @@ void AOScene::set_image(QString p_image) QString default_path = ao_app->get_default_background_path() + p_image; QPixmap background(background_path); - QPixmap animated_background(animated_background_path); QPixmap default_bg(default_path); int w = this->width(); int h = this->height(); - if (file_exists(animated_background_path)) - this->setPixmap(animated_background.scaled(w, h)); + this->clear(); + this->setMovie(nullptr); + + m_movie->stop(); + m_movie->setFileName(animated_background_path); + m_movie->setScaledSize(QSize(w, h)); + + if (m_movie->isValid()) + { + this->setMovie(m_movie); + m_movie->start(); + } else if (file_exists(background_path)) + { this->setPixmap(background.scaled(w, h)); + } else + { this->setPixmap(default_bg.scaled(w, h)); + } } void AOScene::set_legacy_desk(QString p_image) diff --git a/aoscene.h b/aoscene.h index 08c286e..b58c0fd 100644 --- a/aoscene.h +++ b/aoscene.h @@ -3,6 +3,7 @@ #include #include +#include class Courtroom; class AOApplication; @@ -18,6 +19,7 @@ public: private: QWidget *m_parent; + QMovie *m_movie; AOApplication *ao_app; }; diff --git a/aosfxplayer.cpp b/aosfxplayer.cpp index cc2f383..c616121 100644 --- a/aosfxplayer.cpp +++ b/aosfxplayer.cpp @@ -1,41 +1,49 @@ #include "aosfxplayer.h" +#include "file_functions.h" AOSfxPlayer::AOSfxPlayer(QWidget *parent, AOApplication *p_ao_app) { - m_sfxplayer = new QSoundEffect; m_parent = parent; ao_app = p_ao_app; } -AOSfxPlayer::~AOSfxPlayer() +void AOSfxPlayer::play(QString p_sfx, QString p_char, QString shout) { - m_sfxplayer->stop(); - m_sfxplayer->deleteLater(); -} - -void AOSfxPlayer::play(QString p_sfx, QString p_char) -{ - m_sfxplayer->stop(); p_sfx = p_sfx.toLower(); - QString f_path; - if (p_char != "") - f_path = ao_app->get_character_path(p_char) + p_sfx; - else - f_path = ao_app->get_sounds_path() + p_sfx; - m_sfxplayer->setSource(QUrl::fromLocalFile(f_path)); + QString misc_path = ""; + QString char_path = ""; + QString sound_path = ao_app->get_sounds_path() + p_sfx; + + if (shout != "") + misc_path = ao_app->get_base_path() + "misc/" + shout + "/" + p_sfx; + if (p_char != "") + char_path = ao_app->get_character_path(p_char) + p_sfx; + + QString f_path; + + if (file_exists(char_path)) + f_path = char_path; + else if (file_exists(misc_path)) + f_path = misc_path; + else + f_path = sound_path; + set_volume(m_volume); - m_sfxplayer->play(); + if (ao_app->get_audio_output_device() != "Default") + BASS_ChannelSetDevice(m_stream, BASS_GetDevice()); + BASS_ChannelPlay(m_stream, false); } void AOSfxPlayer::stop() { - m_sfxplayer->stop(); + BASS_ChannelStop(m_stream); } void AOSfxPlayer::set_volume(int p_value) { m_volume = p_value; - m_sfxplayer->setVolume(p_value / 100.0); + float volume = p_value / 100.0f; + BASS_ChannelSetAttribute(m_stream, BASS_ATTRIB_VOL, volume); } diff --git a/aosfxplayer.h b/aosfxplayer.h index 1b73e49..30cbe9d 100644 --- a/aosfxplayer.h +++ b/aosfxplayer.h @@ -1,29 +1,28 @@ #ifndef AOSFXPLAYER_H #define AOSFXPLAYER_H +#include "bass.h" #include "aoapplication.h" #include #include #include -#include class AOSfxPlayer { public: AOSfxPlayer(QWidget *parent, AOApplication *p_ao_app); - ~AOSfxPlayer(); - void play(QString p_sfx, QString p_char = ""); + void play(QString p_sfx, QString p_char = "", QString shout = ""); void stop(); void set_volume(int p_volume); private: QWidget *m_parent; AOApplication *ao_app; - QSoundEffect *m_sfxplayer; int m_volume = 0; + HSTREAM m_stream; }; #endif // AOSFXPLAYER_H diff --git a/aotextarea.cpp b/aotextarea.cpp index 16add10..5e14632 100644 --- a/aotextarea.cpp +++ b/aotextarea.cpp @@ -5,7 +5,7 @@ AOTextArea::AOTextArea(QWidget *p_parent) : QTextBrowser(p_parent) } -void AOTextArea::append_chatmessage(QString p_name, QString p_message) +void AOTextArea::append_chatmessage(QString p_name, QString p_message, QString p_colour) { const QTextCursor old_cursor = this->textCursor(); const int old_scrollbar_value = this->verticalScrollBar()->value(); @@ -14,7 +14,7 @@ void AOTextArea::append_chatmessage(QString p_name, QString p_message) this->moveCursor(QTextCursor::End); this->append(""); - this->insertHtml("" + p_name.toHtmlEscaped() + ": "); + this->insertHtml("" + p_name.toHtmlEscaped() + ": "); //cheap workarounds ahoy p_message += " "; diff --git a/aotextarea.h b/aotextarea.h index 9f01f15..d44596b 100644 --- a/aotextarea.h +++ b/aotextarea.h @@ -12,7 +12,7 @@ class AOTextArea : public QTextBrowser public: AOTextArea(QWidget *p_parent = nullptr); - void append_chatmessage(QString p_name, QString p_message); + void append_chatmessage(QString p_name, QString p_message, QString p_colour); void append_error(QString p_message); private: diff --git a/charselect.cpp b/charselect.cpp index 4e4bccb..54286b2 100644 --- a/charselect.cpp +++ b/charselect.cpp @@ -1,11 +1,10 @@ #include "courtroom.h" +#include "lobby.h" #include "file_functions.h" #include "debug_functions.h" #include "hardware_functions.h" -#include - void Courtroom::construct_char_select() { ui_char_select_background = new AOImage(this, ao_app); @@ -19,6 +18,7 @@ void Courtroom::construct_char_select() ui_back_to_lobby = new AOButton(ui_char_select_background, ao_app); ui_char_password = new QLineEdit(ui_char_select_background); + ui_char_password->setPlaceholderText("Password"); ui_char_select_left = new AOButton(ui_char_select_background, ao_app); ui_char_select_right = new AOButton(ui_char_select_background, ao_app); @@ -26,42 +26,24 @@ void Courtroom::construct_char_select() ui_spectator = new AOButton(ui_char_select_background, ao_app); ui_spectator->setText("Spectator"); - QPoint f_spacing = ao_app->get_button_spacing("char_button_spacing", "courtroom_design.ini"); + ui_char_search = new QLineEdit(ui_char_select_background); + ui_char_search->setPlaceholderText("Search"); + ui_char_search->setFocus(); + set_size_and_pos(ui_char_search, "char_search"); - const int button_width = 60; - int x_spacing = f_spacing.x(); - int x_mod_count = 0; + ui_char_passworded = new QCheckBox(ui_char_select_background); + ui_char_passworded->setText("Passworded"); + set_size_and_pos(ui_char_passworded, "char_passworded"); - const int button_height = 60; - int y_spacing = f_spacing.y(); - int y_mod_count = 0; + ui_char_taken = new QCheckBox(ui_char_select_background); + ui_char_taken->setText("Taken"); + set_size_and_pos(ui_char_taken, "char_taken"); + + ui_char_taken->setChecked(true); + ui_char_passworded->setChecked(true); set_size_and_pos(ui_char_buttons, "char_buttons"); - char_columns = ((ui_char_buttons->width() - button_width) / (x_spacing + button_width)) + 1; - char_rows = ((ui_char_buttons->height() - button_height) / (y_spacing + button_height)) + 1; - - max_chars_on_page = char_columns * char_rows; - - for (int n = 0 ; n < max_chars_on_page ; ++n) - { - int x_pos = (button_width + x_spacing) * x_mod_count; - int y_pos = (button_height + y_spacing) * y_mod_count; - - ui_char_button_list.append(new AOCharButton(ui_char_buttons, ao_app, x_pos, y_pos)); - - connect(ui_char_button_list.at(n), SIGNAL(clicked()), char_button_mapper, SLOT(map())) ; - char_button_mapper->setMapping (ui_char_button_list.at(n), n) ; - - ++x_mod_count; - - if (x_mod_count == char_columns) - { - ++y_mod_count; - x_mod_count = 0; - } - } - connect (char_button_mapper, SIGNAL(mapped(int)), this, SLOT(char_clicked(int))); connect(ui_back_to_lobby, SIGNAL(clicked()), this, SLOT(on_back_to_lobby_clicked())); @@ -69,6 +51,10 @@ void Courtroom::construct_char_select() connect(ui_char_select_right, SIGNAL(clicked()), this, SLOT(on_char_select_right_clicked())); connect(ui_spectator, SIGNAL(clicked()), this, SLOT(on_spectator_clicked())); + + connect(ui_char_search, SIGNAL(textEdited(const QString&)), this, SLOT(on_char_search_changed(const QString&))); + connect(ui_char_passworded, SIGNAL(stateChanged(int)), this, SLOT(on_char_passworded_clicked(int))); + connect(ui_char_taken, SIGNAL(stateChanged(int)), this, SLOT(on_char_taken_clicked(int))); } void Courtroom::set_char_select() @@ -87,6 +73,10 @@ void Courtroom::set_char_select() ui_char_select_background->resize(f_charselect.width, f_charselect.height); ui_char_select_background->set_image("charselect_background.png"); + + filter_character_list(); + + ui_char_search->setFocus(); } void Courtroom::set_char_select_page() @@ -97,19 +87,23 @@ void Courtroom::set_char_select_page() ui_char_select_right->hide(); for (AOCharButton *i_button : ui_char_button_list) + { + i_button->reset(); i_button->hide(); + i_button->move(0,0); + } - int total_pages = char_list.size() / max_chars_on_page; + int total_pages = ui_char_button_list_filtered.size() / max_chars_on_page; int chars_on_page = 0; - if (char_list.size() % max_chars_on_page != 0) + if (ui_char_button_list_filtered.size() % max_chars_on_page != 0) { ++total_pages; //i. e. not on the last page if (total_pages > current_char_page + 1) chars_on_page = max_chars_on_page; else - chars_on_page = char_list.size() % max_chars_on_page; + chars_on_page = ui_char_button_list_filtered.size() % max_chars_on_page; } else @@ -121,26 +115,12 @@ void Courtroom::set_char_select_page() if (current_char_page > 0) ui_char_select_left->show(); - for (int n_button = 0 ; n_button < chars_on_page ; ++n_button) - { - int n_real_char = n_button + current_char_page * max_chars_on_page; - AOCharButton *f_button = ui_char_button_list.at(n_button); - - f_button->reset(); - f_button->set_image(char_list.at(n_real_char).name); - f_button->show(); - - if (char_list.at(n_real_char).taken) - f_button->set_taken(); - } - + put_button_in_place(current_char_page * max_chars_on_page, chars_on_page); } void Courtroom::char_clicked(int n_char) { - int n_real_char = n_char + current_char_page * max_chars_on_page; - - QString char_ini_path = ao_app->get_character_path(char_list.at(n_real_char).name) + "char.ini"; + QString char_ini_path = ao_app->get_character_path(char_list.at(n_char).name) + "char.ini"; qDebug() << "char_ini_path" << char_ini_path; if (!file_exists(char_ini_path)) @@ -150,13 +130,134 @@ void Courtroom::char_clicked(int n_char) return; } - if (n_real_char == m_cid) + if (n_char == m_cid) { enter_courtroom(m_cid); } else { - ao_app->send_server_packet(new AOPacket("CC#" + QString::number(ao_app->s_pv) + "#" + QString::number(n_real_char) + "#" + get_hdid() + "#%")); + ao_app->send_server_packet(new AOPacket("CC#" + QString::number(ao_app->s_pv) + "#" + QString::number(n_char) + "#" + get_hdid() + "#%")); } + + ui_ic_chat_name->setPlaceholderText(char_list.at(n_char).name); } +void Courtroom::put_button_in_place(int starting, int chars_on_this_page) +{ + if (ui_char_button_list_filtered.size() == 0) + return; + + QPoint f_spacing = ao_app->get_button_spacing("char_button_spacing", "courtroom_design.ini"); + + int x_spacing = f_spacing.x(); + int x_mod_count = 0; + + int y_spacing = f_spacing.y(); + int y_mod_count = 0; + + char_columns = ((ui_char_buttons->width() - button_width) / (x_spacing + button_width)) + 1; + char_rows = ((ui_char_buttons->height() - button_height) / (y_spacing + button_height)) + 1; + + max_chars_on_page = char_columns * char_rows; + + int startout = starting; + for (int n = starting ; n < startout+chars_on_this_page ; ++n) + { + int x_pos = (button_width + x_spacing) * x_mod_count; + int y_pos = (button_height + y_spacing) * y_mod_count; + + ui_char_button_list_filtered.at(n)->move(x_pos, y_pos); + ui_char_button_list_filtered.at(n)->show(); + + ui_char_button_list_filtered.at(n)->set_taken(); + + ++x_mod_count; + + if (x_mod_count == char_columns) + { + ++y_mod_count; + x_mod_count = 0; + } + } +} + +void Courtroom::character_loading_finished() +{ + // Zeroeth, we'll clear any leftover characters from previous server visits. + ao_app->generated_chars = 0; + if (ui_char_button_list.size() > 0) + { + foreach (AOCharButton* item, ui_char_button_list) { + delete item; + } + ui_char_button_list.clear(); + } + + // First, we'll make all the character buttons in the very beginning. + // We also hide them all, so they can't be accidentally clicked. + // Later on, we'll be revealing buttons as we need them. + for (int n = 0; n < char_list.size(); n++) + { + AOCharButton* character = new AOCharButton(ui_char_buttons, ao_app, 0, 0, char_list.at(n).taken); + character->reset(); + character->hide(); + character->set_image(char_list.at(n).name); + ui_char_button_list.append(character); + + connect(character, SIGNAL(clicked()), char_button_mapper, SLOT(map())); + char_button_mapper->setMapping(character, ui_char_button_list.size() - 1); + + // This part here serves as a way of showing to the player that the game is still running, it is + // just loading the pictures of the characters. + if (ao_app->lobby_constructed) + { + ao_app->generated_chars++; + int total_loading_size = ao_app->char_list_size * 2 + ao_app->evidence_list_size + ao_app->music_list_size; + int loading_value = int(((ao_app->loaded_chars + ao_app->generated_chars + ao_app->loaded_music + ao_app->loaded_evidence) / static_cast(total_loading_size)) * 100); + ao_app->w_lobby->set_loading_value(loading_value); + ao_app->w_lobby->set_loading_text("Generating chars:\n" + QString::number(ao_app->generated_chars) + "/" + QString::number(ao_app->char_list_size)); + } + } + + filter_character_list(); +} + +void Courtroom::filter_character_list() +{ + ui_char_button_list_filtered.clear(); + for (int i = 0; i < char_list.size(); i++) + { + AOCharButton* current_char = ui_char_button_list.at(i); + + // It seems passwording characters is unimplemented yet? + // Until then, this will stay here, I suppose. + //if (ui_char_passworded->isChecked() && character_is_passworded??) + // continue; + + if (!ui_char_taken->isChecked() && char_list.at(i).taken) + continue; + + if (!char_list.at(i).name.contains(ui_char_search->text(), Qt::CaseInsensitive)) + continue; + + ui_char_button_list_filtered.append(current_char); + } + + current_char_page = 0; + set_char_select_page(); +} + +void Courtroom::on_char_search_changed(const QString& newtext) +{ + filter_character_list(); +} + +void Courtroom::on_char_passworded_clicked(int newstate) +{ + filter_character_list(); +} + +void Courtroom::on_char_taken_clicked(int newstate) +{ + filter_character_list(); +} diff --git a/chatlogpiece.cpp b/chatlogpiece.cpp new file mode 100644 index 0000000..6c861f0 --- /dev/null +++ b/chatlogpiece.cpp @@ -0,0 +1,76 @@ +#include "chatlogpiece.h" + +chatlogpiece::chatlogpiece() +{ + name = "UNKNOWN"; + showname = "UNKNOWN"; + message = "UNKNOWN"; + is_song = false; + datetime = QDateTime::currentDateTime().toUTC(); +} + +chatlogpiece::chatlogpiece(QString p_name, QString p_showname, QString p_message, bool p_song) +{ + name = p_name; + showname = p_showname; + message = p_message; + is_song = p_song; + datetime = QDateTime::currentDateTime().toUTC(); +} + +chatlogpiece::chatlogpiece(QString p_name, QString p_showname, QString p_message, bool p_song, QDateTime p_datetime) +{ + name = p_name; + showname = p_showname; + message = p_message; + is_song = p_song; + datetime = p_datetime.toUTC(); +} + +QString chatlogpiece::get_name() +{ + return name; +} + +QString chatlogpiece::get_showname() +{ + return showname; +} + +QString chatlogpiece::get_message() +{ + return message; +} + +QDateTime chatlogpiece::get_datetime() +{ + return datetime; +} + +bool chatlogpiece::get_is_song() +{ + return is_song; +} + +QString chatlogpiece::get_datetime_as_string() +{ + return datetime.toString(); +} + + +QString chatlogpiece::get_full() +{ + QString full = "["; + + full.append(get_datetime_as_string()); + full.append(" UTC] "); + full.append(get_showname()); + full.append(" ("); + full.append(get_name()); + full.append(")"); + if (is_song) + full.append(" has played a song: "); + full.append(get_message()); + + return full; +} diff --git a/chatlogpiece.h b/chatlogpiece.h new file mode 100644 index 0000000..34c5926 --- /dev/null +++ b/chatlogpiece.h @@ -0,0 +1,31 @@ +#ifndef CHATLOGPIECE_H +#define CHATLOGPIECE_H + +#include +#include + +class chatlogpiece +{ +public: + chatlogpiece(); + chatlogpiece(QString p_name, QString p_showname, QString p_message, bool p_song); + chatlogpiece(QString p_name, QString p_showname, QString p_message, bool p_song, QDateTime p_datetime); + + QString get_name(); + QString get_showname(); + QString get_message(); + bool get_is_song(); + QDateTime get_datetime(); + QString get_datetime_as_string(); + + QString get_full(); + +private: + QString name; + QString showname; + QString message; + QDateTime datetime; + bool is_song; +}; + +#endif // CHATLOGPIECE_H diff --git a/courtroom.cpp b/courtroom.cpp index 5c552a1..80ebdc8 100644 --- a/courtroom.cpp +++ b/courtroom.cpp @@ -4,6 +4,31 @@ Courtroom::Courtroom(AOApplication *p_ao_app) : QMainWindow() { ao_app = p_ao_app; + // Change the default audio output device to be the one the user has given + // in his config.ini file for now. + int a = 0; + BASS_DEVICEINFO info; + + if (ao_app->get_audio_output_device() == "Default") + { + BASS_Init(-1, 48000, BASS_DEVICE_LATENCY, 0, NULL); + load_bass_opus_plugin(); + } + else + { + for (a = 0; BASS_GetDeviceInfo(a, &info); a++) + { + if (ao_app->get_audio_output_device() == info.name) + { + BASS_SetDevice(a); + BASS_Init(a, 48000, BASS_DEVICE_LATENCY, 0, NULL); + load_bass_opus_plugin(); + qDebug() << info.name << "was set as the default audio output device."; + break; + } + } + } + keepalive_timer = new QTimer(this); keepalive_timer->start(60000); @@ -45,6 +70,8 @@ Courtroom::Courtroom(AOApplication *p_ao_app) : QMainWindow() ui_vp_speedlines = new AOMovie(ui_viewport, ao_app); ui_vp_speedlines->set_play_once(false); ui_vp_player_char = new AOCharMovie(ui_viewport, ao_app); + ui_vp_sideplayer_char = new AOCharMovie(ui_viewport, ao_app); + ui_vp_sideplayer_char->hide(); ui_vp_desk = new AOScene(ui_viewport, ao_app); ui_vp_legacy_desk = new AOScene(ui_viewport, ao_app); @@ -66,6 +93,9 @@ Courtroom::Courtroom(AOApplication *p_ao_app) : QMainWindow() ui_ic_chatlog = new QTextEdit(this); ui_ic_chatlog->setReadOnly(true); + log_maximum_blocks = ao_app->get_max_log_size(); + log_goes_downwards = ao_app->get_log_goes_downwards(); + ui_ms_chatlog = new AOTextArea(this); ui_ms_chatlog->setReadOnly(true); ui_ms_chatlog->setOpenExternalLinks(true); @@ -76,11 +106,23 @@ Courtroom::Courtroom(AOApplication *p_ao_app) : QMainWindow() ui_server_chatlog->setOpenExternalLinks(true); ui_mute_list = new QListWidget(this); - //ui_area_list = new QListWidget(this); + ui_area_list = new QListWidget(this); + ui_area_list->hide(); ui_music_list = new QListWidget(this); + ui_pair_list = new QListWidget(this); + ui_pair_offset_spinbox = new QSpinBox(this); + ui_pair_offset_spinbox->setRange(-100,100); + ui_pair_offset_spinbox->setSuffix("% offset"); + ui_pair_button = new AOButton(this, ao_app); + + ui_ic_chat_name = new QLineEdit(this); + ui_ic_chat_name->setFrame(false); + ui_ic_chat_name->setPlaceholderText("Showname"); + ui_ic_chat_message = new QLineEdit(this); ui_ic_chat_message->setFrame(false); + ui_ic_chat_message->setPlaceholderText("Message"); ui_muted = new AOImage(ui_ic_chat_message, ao_app); ui_muted->hide(); @@ -91,7 +133,8 @@ Courtroom::Courtroom(AOApplication *p_ao_app) : QMainWindow() ui_ooc_chat_name = new QLineEdit(this); ui_ooc_chat_name->setFrame(false); ui_ooc_chat_name->setPlaceholderText("Name"); - ui_ooc_chat_name->setText(ao_app->get_ooc_name()); + ui_ooc_chat_name->setMaxLength(30); + ui_ooc_chat_name->setText(p_ao_app->get_default_username()); //ui_area_password = new QLineEdit(this); //ui_area_password->setFrame(false); @@ -111,6 +154,8 @@ Courtroom::Courtroom(AOApplication *p_ao_app) : QMainWindow() ui_pos_dropdown->addItem("jud"); ui_pos_dropdown->addItem("hld"); ui_pos_dropdown->addItem("hlp"); + ui_pos_dropdown->addItem("jur"); + ui_pos_dropdown->addItem("sea"); ui_defense_bar = new AOImage(this, ao_app); ui_prosecution_bar = new AOImage(this, ao_app); @@ -119,6 +164,8 @@ Courtroom::Courtroom(AOApplication *p_ao_app) : QMainWindow() ui_sfx_label = new QLabel(this); ui_blip_label = new QLabel(this); + ui_log_limit_label = new QLabel(this); + ui_hold_it = new AOButton(this, ao_app); ui_objection = new AOButton(this, ao_app); ui_take_that = new AOButton(this, ao_app); @@ -126,10 +173,15 @@ Courtroom::Courtroom(AOApplication *p_ao_app) : QMainWindow() ui_ooc_toggle = new AOButton(this, ao_app); ui_witness_testimony = new AOButton(this, ao_app); ui_cross_examination = new AOButton(this, ao_app); + ui_guilty = new AOButton(this, ao_app); + ui_not_guilty = new AOButton(this, ao_app); ui_change_character = new AOButton(this, ao_app); ui_reload_theme = new AOButton(this, ao_app); ui_call_mod = new AOButton(this, ao_app); + ui_settings = new AOButton(this, ao_app); + ui_announce_casing = new AOButton(this, ao_app); + ui_switch_area_music = new AOButton(this, ao_app); ui_pre = new QCheckBox(this); ui_pre->setText("Pre"); @@ -139,6 +191,18 @@ Courtroom::Courtroom(AOApplication *p_ao_app) : QMainWindow() ui_guard = new QCheckBox(this); ui_guard->setText("Guard"); ui_guard->hide(); + ui_casing = new QCheckBox(this); + ui_casing->setChecked(ao_app->get_casing_enabled()); + ui_casing->setText("Casing"); + ui_casing->hide(); + + ui_showname_enable = new QCheckBox(this); + ui_showname_enable->setChecked(ao_app->get_showname_enabled_by_default()); + ui_showname_enable->setText("Shownames"); + + ui_pre_non_interrupt = new QCheckBox(this); + ui_pre_non_interrupt->setText("No Intrpt"); + ui_pre_non_interrupt->hide(); ui_custom_objection = new AOButton(this, ao_app); ui_realization = new AOButton(this, ao_app); @@ -156,8 +220,10 @@ Courtroom::Courtroom(AOApplication *p_ao_app) : QMainWindow() ui_text_color->addItem("Red"); ui_text_color->addItem("Orange"); ui_text_color->addItem("Blue"); - if (ao_app->yellow_text_enabled) - ui_text_color->addItem("Yellow"); + ui_text_color->addItem("Yellow"); + ui_text_color->addItem("Rainbow"); + ui_text_color->addItem("Pink"); + ui_text_color->addItem("Cyan"); ui_music_slider = new QSlider(Qt::Horizontal, this); ui_music_slider->setRange(0, 100); @@ -171,6 +237,10 @@ Courtroom::Courtroom(AOApplication *p_ao_app) : QMainWindow() ui_blip_slider->setRange(0, 100); ui_blip_slider->setValue(ao_app->get_default_blip()); + ui_log_limit_spinbox = new QSpinBox(this); + ui_log_limit_spinbox->setRange(0, 10000); + ui_log_limit_spinbox->setValue(ao_app->get_max_log_size()); + ui_evidence_button = new AOButton(this, ao_app); construct_evidence(); @@ -196,7 +266,7 @@ Courtroom::Courtroom(AOApplication *p_ao_app) : QMainWindow() connect(ui_emote_right, SIGNAL(clicked()), this, SLOT(on_emote_right_clicked())); connect(ui_emote_dropdown, SIGNAL(activated(int)), this, SLOT(on_emote_dropdown_changed(int))); - connect(ui_pos_dropdown, SIGNAL(activated(int)), this, SLOT(on_pos_dropdown_changed(int))); + connect(ui_pos_dropdown, SIGNAL(currentIndexChanged(int)), this, SLOT(on_pos_dropdown_changed(int))); connect(ui_mute_list, SIGNAL(clicked(QModelIndex)), this, SLOT(on_mute_list_clicked(QModelIndex))); @@ -205,6 +275,7 @@ Courtroom::Courtroom(AOApplication *p_ao_app) : QMainWindow() connect(ui_ooc_chat_message, SIGNAL(returnPressed()), this, SLOT(on_ooc_return_pressed())); connect(ui_music_list, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(on_music_list_double_clicked(QModelIndex))); + connect(ui_area_list, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(on_area_list_double_clicked(QModelIndex))); connect(ui_hold_it, SIGNAL(clicked()), this, SLOT(on_hold_it_clicked())); connect(ui_objection, SIGNAL(clicked()), this, SLOT(on_objection_clicked())); @@ -226,20 +297,34 @@ Courtroom::Courtroom(AOApplication *p_ao_app) : QMainWindow() connect(ui_sfx_slider, SIGNAL(valueChanged(int)), this, SLOT(on_sfx_slider_moved(int))); connect(ui_blip_slider, SIGNAL(valueChanged(int)), this, SLOT(on_blip_slider_moved(int))); + connect(ui_log_limit_spinbox, SIGNAL(valueChanged(int)), this, SLOT(on_log_limit_changed(int))); + connect(ui_ooc_toggle, SIGNAL(clicked()), this, SLOT(on_ooc_toggle_clicked())); connect(ui_music_search, SIGNAL(textChanged(QString)), this, SLOT(on_music_search_edited(QString))); connect(ui_witness_testimony, SIGNAL(clicked()), this, SLOT(on_witness_testimony_clicked())); connect(ui_cross_examination, SIGNAL(clicked()), this, SLOT(on_cross_examination_clicked())); + connect(ui_guilty, SIGNAL(clicked()), this, SLOT(on_guilty_clicked())); + connect(ui_not_guilty, SIGNAL(clicked()), this, SLOT(on_not_guilty_clicked())); connect(ui_change_character, SIGNAL(clicked()), this, SLOT(on_change_character_clicked())); connect(ui_reload_theme, SIGNAL(clicked()), this, SLOT(on_reload_theme_clicked())); connect(ui_call_mod, SIGNAL(clicked()), this, SLOT(on_call_mod_clicked())); + connect(ui_settings, SIGNAL(clicked()), this, SLOT(on_settings_clicked())); + connect(ui_announce_casing, SIGNAL(clicked()), this, SLOT(on_announce_casing_clicked())); + connect(ui_switch_area_music, SIGNAL(clicked()), this, SLOT(on_switch_area_music_clicked())); connect(ui_pre, SIGNAL(clicked()), this, SLOT(on_pre_clicked())); connect(ui_flip, SIGNAL(clicked()), this, SLOT(on_flip_clicked())); connect(ui_guard, SIGNAL(clicked()), this, SLOT(on_guard_clicked())); + connect(ui_casing, SIGNAL(clicked()), this, SLOT(on_casing_clicked())); + + connect(ui_showname_enable, SIGNAL(clicked()), this, SLOT(on_showname_enable_clicked())); + + connect(ui_pair_button, SIGNAL(clicked()), this, SLOT(on_pair_clicked())); + connect(ui_pair_list, SIGNAL(clicked(QModelIndex)), this, SLOT(on_pair_list_clicked(QModelIndex))); + connect(ui_pair_offset_spinbox, SIGNAL(valueChanged(int)), this, SLOT(on_pair_offset_changed(int))); connect(ui_evidence_button, SIGNAL(clicked()), this, SLOT(on_evidence_button_clicked())); @@ -272,6 +357,21 @@ void Courtroom::set_mute_list() } } +void Courtroom::set_pair_list() +{ + QStringList sorted_pair_list; + + for (char_type i_char : char_list) + sorted_pair_list.append(i_char.name); + + sorted_pair_list.sort(); + + for (QString i_name : sorted_pair_list) + { + ui_pair_list->addItem(i_name); + } +} + void Courtroom::set_widgets() { blip_rate = ao_app->read_blip_rate(); @@ -303,6 +403,40 @@ void Courtroom::set_widgets() set_size_and_pos(ui_viewport, "viewport"); + // If there is a point to it, show all CCCC features. + // We also do this this soon so that set_size_and_pos can hide them all later, if needed. + if (ao_app->cccc_ic_support_enabled) + { + ui_pair_button->show(); + ui_pre_non_interrupt->show(); + ui_showname_enable->show(); + ui_ic_chat_name->show(); + ui_ic_chat_name->setEnabled(true); + } + else + { + ui_pair_button->hide(); + ui_pre_non_interrupt->hide(); + ui_showname_enable->hide(); + ui_ic_chat_name->hide(); + ui_ic_chat_name->setEnabled(false); + } + + if (ao_app->casing_alerts_enabled) + { + ui_announce_casing->show(); + } + else + { + ui_announce_casing->hide(); + } + + // We also show the non-server-dependent client additions. + // Once again, if the theme can't display it, set_move_and_pos will catch them. + ui_settings->show(); + ui_log_limit_label->show(); + ui_log_limit_spinbox->show(); + ui_vp_background->move(0, 0); ui_vp_background->resize(ui_viewport->width(), ui_viewport->height()); @@ -312,6 +446,9 @@ void Courtroom::set_widgets() ui_vp_player_char->move(0, 0); ui_vp_player_char->combo_resize(ui_viewport->width(), ui_viewport->height()); + ui_vp_sideplayer_char->move(0, 0); + ui_vp_sideplayer_char->combo_resize(ui_viewport->width(), ui_viewport->height()); + //the AO2 desk element ui_vp_desk->move(0, 0); ui_vp_desk->resize(ui_viewport->width(), ui_viewport->height()); @@ -358,8 +495,15 @@ void Courtroom::set_widgets() set_size_and_pos(ui_mute_list, "mute_list"); ui_mute_list->hide(); - //set_size_and_pos(ui_area_list, "area_list"); - //ui_area_list->setStyleSheet("background-color: rgba(0, 0, 0, 0);"); + set_size_and_pos(ui_pair_list, "pair_list"); + ui_pair_list->hide(); + set_size_and_pos(ui_pair_offset_spinbox, "pair_offset_spinbox"); + ui_pair_offset_spinbox->hide(); + set_size_and_pos(ui_pair_button, "pair_button"); + ui_pair_button->set_image("pair_button.png"); + + set_size_and_pos(ui_area_list, "music_list"); + ui_area_list->setStyleSheet("background-color: rgba(0, 0, 0, 0);"); set_size_and_pos(ui_music_list, "music_list"); @@ -367,14 +511,17 @@ void Courtroom::set_widgets() { set_size_and_pos(ui_ic_chat_message, "ao2_ic_chat_message"); set_size_and_pos(ui_vp_chatbox, "ao2_chatbox"); + set_size_and_pos(ui_ic_chat_name, "ao2_ic_chat_name"); } else { set_size_and_pos(ui_ic_chat_message, "ic_chat_message"); set_size_and_pos(ui_vp_chatbox, "chatbox"); + set_size_and_pos(ui_ic_chat_name, "ic_chat_name"); } ui_ic_chat_message->setStyleSheet("QLineEdit{background-color: rgba(100, 100, 100, 255);}"); + ui_ic_chat_name->setStyleSheet("QLineEdit{background-color: rgba(180, 180, 180, 255);}"); ui_vp_chatbox->set_image("chatmed.png"); ui_vp_chatbox->hide(); @@ -415,6 +562,9 @@ void Courtroom::set_widgets() set_size_and_pos(ui_blip_label, "blip_label"); ui_blip_label->setText("Blips"); + set_size_and_pos(ui_log_limit_label, "log_limit_label"); + ui_log_limit_label->setText("Log limit"); + set_size_and_pos(ui_hold_it, "hold_it"); ui_hold_it->set_image("holdit.png"); set_size_and_pos(ui_objection, "objection"); @@ -430,6 +580,11 @@ void Courtroom::set_widgets() set_size_and_pos(ui_cross_examination, "cross_examination"); ui_cross_examination->set_image("crossexamination.png"); + set_size_and_pos(ui_guilty, "guilty"); + ui_guilty->set_image("guilty.png"); + set_size_and_pos(ui_not_guilty, "not_guilty"); + ui_not_guilty->set_image("notguilty.png"); + set_size_and_pos(ui_change_character, "change_character"); ui_change_character->setText("Change character"); @@ -439,13 +594,27 @@ void Courtroom::set_widgets() set_size_and_pos(ui_call_mod, "call_mod"); ui_call_mod->setText("Call mod"); + set_size_and_pos(ui_settings, "settings"); + ui_settings->setText("Settings"); + + set_size_and_pos(ui_announce_casing, "casing_button"); + ui_announce_casing->setText("Casing"); + + set_size_and_pos(ui_switch_area_music, "switch_area_music"); + ui_switch_area_music->setText("A/M"); + set_size_and_pos(ui_pre, "pre"); ui_pre->setText("Pre"); + set_size_and_pos(ui_pre_non_interrupt, "pre_no_interrupt"); set_size_and_pos(ui_flip, "flip"); set_size_and_pos(ui_guard, "guard"); + set_size_and_pos(ui_casing, "casing"); + + set_size_and_pos(ui_showname_enable, "showname_enable"); + set_size_and_pos(ui_custom_objection, "custom_objection"); ui_custom_objection->set_image("custom.png"); @@ -473,6 +642,8 @@ void Courtroom::set_widgets() set_size_and_pos(ui_sfx_slider, "sfx_slider"); set_size_and_pos(ui_blip_slider, "blip_slider"); + set_size_and_pos(ui_log_limit_spinbox, "log_limit_spinbox"); + set_size_and_pos(ui_evidence_button, "evidence_button"); ui_evidence_button->set_image("evidencebutton.png"); @@ -534,6 +705,7 @@ void Courtroom::set_fonts() set_font(ui_ms_chatlog, "ms_chatlog"); set_font(ui_server_chatlog, "server_chatlog"); set_font(ui_music_list, "music_list"); + set_font(ui_area_list, "music_list"); } void Courtroom::set_font(QWidget *widget, QString p_identifier) @@ -607,6 +779,7 @@ void Courtroom::done_received() set_char_select_page(); set_mute_list(); + set_pair_list(); set_char_select(); @@ -646,14 +819,15 @@ void Courtroom::enter_courtroom(int p_cid) if (m_cid == -1) { - if(ao_app->is_discord_enabled()) + if (ao_app->is_discord_enabled()) ao_app->discord->state_spectate(); f_char = ""; } else { f_char = ao_app->get_char_name(char_list.at(m_cid).name); - if(ao_app->is_discord_enabled()) + + if (ao_app->is_discord_enabled()) ao_app->discord->state_character(f_char.toStdString()); } @@ -681,6 +855,8 @@ void Courtroom::enter_courtroom(int p_cid) { ui_witness_testimony->show(); ui_cross_examination->show(); + ui_not_guilty->show(); + ui_guilty->show(); ui_defense_minus->show(); ui_defense_plus->show(); ui_prosecution_minus->show(); @@ -690,6 +866,8 @@ void Courtroom::enter_courtroom(int p_cid) { ui_witness_testimony->hide(); ui_cross_examination->hide(); + ui_guilty->hide(); + ui_not_guilty->hide(); ui_defense_minus->hide(); ui_defense_plus->hide(); ui_prosecution_minus->hide(); @@ -710,7 +888,13 @@ void Courtroom::enter_courtroom(int p_cid) else ui_flip->hide(); + if (ao_app->casing_alerts_enabled) + ui_casing->show(); + else + ui_casing->hide(); + list_music(); + list_areas(); music_player->set_volume(ui_music_slider->value()); sfx_player->set_volume(ui_sfx_slider->value()); @@ -732,6 +916,7 @@ void Courtroom::enter_courtroom(int p_cid) void Courtroom::list_music() { ui_music_list->clear(); + music_row_to_number.clear(); QString f_file = "courtroom_design.ini"; @@ -743,10 +928,13 @@ void Courtroom::list_music() for (int n_song = 0 ; n_song < music_list.size() ; ++n_song) { QString i_song = music_list.at(n_song); + QString i_song_listname = i_song; + i_song_listname = i_song_listname.left(i_song_listname.lastIndexOf(".")); if (i_song.toLower().contains(ui_music_search->text().toLower())) { - ui_music_list->addItem(i_song); + ui_music_list->addItem(i_song_listname); + music_row_to_number.append(n_song); QString song_path = ao_app->get_base_path() + "sounds/music/" + i_song.toLower(); @@ -760,14 +948,100 @@ void Courtroom::list_music() } } -void Courtroom::append_ms_chatmessage(QString f_name, QString f_message) +void Courtroom::list_areas() { - ui_ms_chatlog->append_chatmessage(f_name, f_message); + ui_area_list->clear(); + area_row_to_number.clear(); + + QString f_file = "courtroom_design.ini"; + + QBrush free_brush(ao_app->get_color("area_free_color", f_file)); + QBrush lfp_brush(ao_app->get_color("area_lfp_color", f_file)); + QBrush casing_brush(ao_app->get_color("area_casing_color", f_file)); + QBrush recess_brush(ao_app->get_color("area_recess_color", f_file)); + QBrush rp_brush(ao_app->get_color("area_rp_color", f_file)); + QBrush gaming_brush(ao_app->get_color("area_gaming_color", f_file)); + QBrush locked_brush(ao_app->get_color("area_locked_color", f_file)); + + int n_listed_areas = 0; + + for (int n_area = 0 ; n_area < area_list.size() ; ++n_area) + { + QString i_area = ""; + i_area.append("["); + i_area.append(QString::number(n_area)); + i_area.append("] "); + + i_area.append(area_list.at(n_area)); + + if (ao_app->arup_enabled) + { + i_area.append("\n "); + + i_area.append(arup_statuses.at(n_area)); + i_area.append(" | CM: "); + i_area.append(arup_cms.at(n_area)); + + i_area.append("\n "); + + i_area.append(QString::number(arup_players.at(n_area))); + i_area.append(" users | "); + + i_area.append(arup_locks.at(n_area)); + } + + if (i_area.toLower().contains(ui_music_search->text().toLower())) + { + ui_area_list->addItem(i_area); + area_row_to_number.append(n_area); + + if (ao_app->arup_enabled) + { + // Colouring logic here. + ui_area_list->item(n_listed_areas)->setBackground(free_brush); + if (arup_locks.at(n_area) == "LOCKED") + { + ui_area_list->item(n_listed_areas)->setBackground(locked_brush); + } + else + { + if (arup_statuses.at(n_area) == "LOOKING-FOR-PLAYERS") + ui_area_list->item(n_listed_areas)->setBackground(lfp_brush); + else if (arup_statuses.at(n_area) == "CASING") + ui_area_list->item(n_listed_areas)->setBackground(casing_brush); + else if (arup_statuses.at(n_area) == "RECESS") + ui_area_list->item(n_listed_areas)->setBackground(recess_brush); + else if (arup_statuses.at(n_area) == "RP") + ui_area_list->item(n_listed_areas)->setBackground(rp_brush); + else if (arup_statuses.at(n_area) == "GAMING") + ui_area_list->item(n_listed_areas)->setBackground(gaming_brush); + } + } + else + { + ui_area_list->item(n_listed_areas)->setBackground(free_brush); + } + + ++n_listed_areas; + } + } } -void Courtroom::append_server_chatmessage(QString p_name, QString p_message) +void Courtroom::append_ms_chatmessage(QString f_name, QString f_message) { - ui_server_chatlog->append_chatmessage(p_name, p_message); + ui_ms_chatlog->append_chatmessage(f_name, f_message, ao_app->get_color("ooc_default_color", "courtroom_design.ini").name()); +} + +void Courtroom::append_server_chatmessage(QString p_name, QString p_message, QString p_colour) +{ + QString colour = "#000000"; + + if (p_colour == "0") + colour = ao_app->get_color("ooc_default_color", "courtroom_design.ini").name(); + if (p_colour == "1") + colour = ao_app->get_color("ooc_server_color", "courtroom_design.ini").name(); + + ui_server_chatlog->append_chatmessage(p_name, p_message, colour); } void Courtroom::on_chat_return_pressed() @@ -796,6 +1070,13 @@ void Courtroom::on_chat_return_pressed() //realization# //text_color#% + // Additionally, in our case: + + //showname# + //other_charid# + //self_offset# + //noninterrupting_preanim#% + QStringList packet_contents; QString f_side = ao_app->get_char_side(current_char); @@ -828,12 +1109,15 @@ void Courtroom::on_chat_return_pressed() //needed or else legacy won't understand what we're saying if (objection_state > 0) { - if (f_emote_mod == 5) - f_emote_mod = 6; - else - f_emote_mod = 2; + if (ui_pre->isChecked()) + { + if (f_emote_mod == 5) + f_emote_mod = 6; + else + f_emote_mod = 2; + } } - else if (ui_pre->isChecked()) + else if (ui_pre->isChecked() and !ui_pre_non_interrupt->isChecked()) { if (f_emote_mod == 0) f_emote_mod = 1; @@ -890,24 +1174,78 @@ void Courtroom::on_chat_return_pressed() if (text_color < 0) f_text_color = "0"; - else if (text_color > 4 && !ao_app->yellow_text_enabled) + else if (text_color > 8) f_text_color = "0"; else f_text_color = QString::number(text_color); packet_contents.append(f_text_color); + // If the server we're on supports CCCC stuff, we should use it! + if (ao_app->cccc_ic_support_enabled) + { + // If there is a showname entered, use that -- else, just send an empty packet-part. + if (!ui_ic_chat_name->text().isEmpty()) + { + packet_contents.append(ui_ic_chat_name->text()); + } + else + { + packet_contents.append(""); + } + + // Similarly, we send over whom we're paired with, unless we have chosen ourselves. + // Or a charid of -1 or lower, through some means. + if (other_charid > -1 && other_charid != m_cid) + { + packet_contents.append(QString::number(other_charid)); + packet_contents.append(QString::number(offset_with_pair)); + } + else + { + packet_contents.append("-1"); + packet_contents.append("0"); + } + + // Finally, we send over if we want our pres to not interrupt. + if (ui_pre_non_interrupt->isChecked() && ui_pre->isChecked()) + { + packet_contents.append("1"); + } + else + { + packet_contents.append("0"); + } + } + ao_app->send_server_packet(new AOPacket("MS", packet_contents)); } void Courtroom::handle_chatmessage(QStringList *p_contents) { - if (p_contents->size() < chatmessage_size) + // Instead of checking for whether a message has at least chatmessage_size + // amount of packages, we'll check if it has at least 15. + // That was the original chatmessage_size. + if (p_contents->size() < 15) return; for (int n_string = 0 ; n_string < chatmessage_size ; ++n_string) { - m_chatmessage[n_string] = p_contents->at(n_string); + //m_chatmessage[n_string] = p_contents->at(n_string); + + // Note that we have added stuff that vanilla clients and servers simply won't send. + // So now, we have to check if the thing we want even exists amongst the packet's content. + // We also have to check if the server even supports CCCC's IC features, or if it's just japing us. + // Also, don't forget! A size 15 message will have indices from 0 to 14. + if (n_string < p_contents->size() && + (n_string < 15 || ao_app->cccc_ic_support_enabled)) + { + m_chatmessage[n_string] = p_contents->at(n_string); + } + else + { + m_chatmessage[n_string] = ""; + } } int f_char_id = m_chatmessage[CHAR_ID].toInt(); @@ -918,7 +1256,16 @@ void Courtroom::handle_chatmessage(QStringList *p_contents) if (mute_map.value(m_chatmessage[CHAR_ID].toInt())) return; - QString f_showname = ao_app->get_showname(char_list.at(f_char_id).name); + QString f_showname; + if (m_chatmessage[SHOWNAME].isEmpty() || !ui_showname_enable->isChecked()) + { + f_showname = ao_app->get_showname(char_list.at(f_char_id).name); + } + else + { + f_showname = m_chatmessage[SHOWNAME]; + } + QString f_message = f_showname + ": " + m_chatmessage[MESSAGE] + '\n'; @@ -949,6 +1296,14 @@ void Courtroom::handle_chatmessage(QStringList *p_contents) ui_evidence_present->set_image("present_disabled.png"); } + chatlogpiece* temp = new chatlogpiece(ao_app->get_showname(char_list.at(f_char_id).name), f_showname, ": " + m_chatmessage[MESSAGE], false); + ic_chatlog_history.append(*temp); + + while(ic_chatlog_history.size() > log_maximum_blocks) + { + ic_chatlog_history.removeFirst(); + } + append_ic_text(": " + m_chatmessage[MESSAGE], f_showname); previous_ic_message = f_message; @@ -964,20 +1319,20 @@ void Courtroom::handle_chatmessage(QStringList *p_contents) { case 1: ui_vp_objection->play("holdit", f_char, f_custom_theme); - objection_player->play("holdit.wav", f_char); + objection_player->play("holdit.wav", f_char, f_custom_theme); break; case 2: ui_vp_objection->play("objection", f_char, f_custom_theme); - objection_player->play("objection.wav", f_char); + objection_player->play("objection.wav", f_char, f_custom_theme); break; case 3: ui_vp_objection->play("takethat", f_char, f_custom_theme); - objection_player->play("takethat.wav", f_char); + objection_player->play("takethat.wav", f_char, f_custom_theme); break; //case 4 is AO2 only case 4: ui_vp_objection->play("custom", f_char, f_custom_theme); - objection_player->play("custom.wav", f_char); + objection_player->play("custom.wav", f_char, f_custom_theme); break; default: qDebug() << "W: Logic error in objection switch statement!"; @@ -1002,11 +1357,18 @@ void Courtroom::handle_chatmessage_2() ui_vp_speedlines->stop(); ui_vp_player_char->stop(); - QString real_name = char_list.at(m_chatmessage[CHAR_ID].toInt()).name; + if (m_chatmessage[SHOWNAME].isEmpty() || !ui_showname_enable->isChecked()) + { + QString real_name = char_list.at(m_chatmessage[CHAR_ID].toInt()).name; - QString f_showname = ao_app->get_showname(real_name); + QString f_showname = ao_app->get_showname(real_name); - ui_vp_showname->setText(f_showname); + ui_vp_showname->setText(f_showname); + } + else + { + ui_vp_showname->setText(m_chatmessage[SHOWNAME]); + } ui_vp_message->clear(); ui_vp_chatbox->hide(); @@ -1017,13 +1379,34 @@ void Courtroom::handle_chatmessage_2() ui_vp_chatbox->set_image("chatmed.png"); else { - QString chatbox_path = ao_app->get_base_path() + "misc/" + chatbox + ".png"; + QString chatbox_path = ao_app->get_base_path() + "misc/" + chatbox + "/chatbox.png"; ui_vp_chatbox->set_image_from_path(chatbox_path); } + ui_vp_showname->setStyleSheet("QLabel { color : " + get_text_color("_showname").name() + "; }"); + set_scene(); set_text_color(); + // Check if the message needs to be centered. + QString f_message = m_chatmessage[MESSAGE]; + if (f_message.size() >= 2) + { + if (f_message.startsWith("~~")) + { + message_is_centered = true; + } + else + { + message_is_centered = false; + } + } + else + { + ui_vp_message->setAlignment(Qt::AlignLeft); + } + + int emote_mod = m_chatmessage[EMOTE_MOD].toInt(); if (ao_app->flipping_enabled && m_chatmessage[FLIP].toInt() == 1) @@ -1031,6 +1414,143 @@ void Courtroom::handle_chatmessage_2() else ui_vp_player_char->set_flipped(false); + QString side = m_chatmessage[SIDE]; + + // Making the second character appear. + if (m_chatmessage[OTHER_CHARID].isEmpty()) + { + // If there is no second character, hide 'em, and center the first. + ui_vp_sideplayer_char->hide(); + ui_vp_sideplayer_char->move(0,0); + + ui_vp_player_char->move(0,0); + } + else + { + bool ok; + int got_other_charid = m_chatmessage[OTHER_CHARID].toInt(&ok); + if (ok) + { + if (got_other_charid > -1) + { + // If there is, show them! + ui_vp_sideplayer_char->show(); + + // Depending on where we are, we offset the characters, and reorder their stacking. + if (side == "def") + { + // We also move the character down depending on how far the are to the right. + int hor_offset = m_chatmessage[SELF_OFFSET].toInt(); + int vert_offset = 0; + if (hor_offset > 0) + { + vert_offset = hor_offset / 10; + } + ui_vp_player_char->move(ui_viewport->width() * hor_offset / 100, ui_viewport->height() * vert_offset / 100); + + // We do the same with the second character. + int hor2_offset = m_chatmessage[OTHER_OFFSET].toInt(); + int vert2_offset = 0; + if (hor2_offset > 0) + { + vert2_offset = hor2_offset / 10; + } + ui_vp_sideplayer_char->move(ui_viewport->width() * hor2_offset / 100, ui_viewport->height() * vert2_offset / 100); + + // Finally, we reorder them based on who is more to the left. + // The person more to the left is more in the front. + if (hor2_offset >= hor_offset) + { + ui_vp_sideplayer_char->raise(); + ui_vp_player_char->raise(); + } + else + { + ui_vp_player_char->raise(); + ui_vp_sideplayer_char->raise(); + } + ui_vp_desk->raise(); + ui_vp_legacy_desk->raise(); + } + else if (side == "pro") + { + // Almost the same thing happens here, but in reverse. + int hor_offset = m_chatmessage[SELF_OFFSET].toInt(); + int vert_offset = 0; + if (hor_offset < 0) + { + // We don't want to RAISE the char off the floor. + vert_offset = -1 * hor_offset / 10; + } + ui_vp_player_char->move(ui_viewport->width() * hor_offset / 100, ui_viewport->height() * vert_offset / 100); + + // We do the same with the second character. + int hor2_offset = m_chatmessage[OTHER_OFFSET].toInt(); + int vert2_offset = 0; + if (hor2_offset < 0) + { + vert2_offset = -1 * hor2_offset / 10; + } + ui_vp_sideplayer_char->move(ui_viewport->width() * hor2_offset / 100, ui_viewport->height() * vert2_offset / 100); + + // Finally, we reorder them based on who is more to the right. + if (hor2_offset <= hor_offset) + { + ui_vp_sideplayer_char->raise(); + ui_vp_player_char->raise(); + } + else + { + ui_vp_player_char->raise(); + ui_vp_sideplayer_char->raise(); + } + ui_vp_desk->raise(); + ui_vp_legacy_desk->raise(); + } + else + { + // In every other case, the person more to the left is on top. + // These cases also don't move the characters down. + int hor_offset = m_chatmessage[SELF_OFFSET].toInt(); + ui_vp_player_char->move(ui_viewport->width() * hor_offset / 100, 0); + + // We do the same with the second character. + int hor2_offset = m_chatmessage[OTHER_OFFSET].toInt(); + ui_vp_sideplayer_char->move(ui_viewport->width() * hor2_offset / 100, 0); + + // Finally, we reorder them based on who is more to the left. + // The person more to the left is more in the front. + if (hor2_offset >= hor_offset) + { + ui_vp_sideplayer_char->raise(); + ui_vp_player_char->raise(); + } + else + { + ui_vp_player_char->raise(); + ui_vp_sideplayer_char->raise(); + } + ui_vp_desk->raise(); + ui_vp_legacy_desk->raise(); + } + // We should probably also play the other character's idle emote. + if (ao_app->flipping_enabled && m_chatmessage[OTHER_FLIP].toInt() == 1) + ui_vp_sideplayer_char->set_flipped(true); + else + ui_vp_sideplayer_char->set_flipped(false); + ui_vp_sideplayer_char->play_idle(m_chatmessage[OTHER_NAME], m_chatmessage[OTHER_EMOTE]); + } + else + { + // If the server understands other characters, but there + // really is no second character, hide 'em, and center the first. + ui_vp_sideplayer_char->hide(); + ui_vp_sideplayer_char->move(0,0); + + ui_vp_player_char->move(0,0); + } + } + } switch (emote_mod) { @@ -1041,7 +1561,10 @@ void Courtroom::handle_chatmessage_2() qDebug() << "W: invalid emote mod: " << QString::number(emote_mod); //intentional fallthru case 0: case 5: - handle_chatmessage_3(); + if (m_chatmessage[NONINTERRUPTING_PRE].toInt() == 0) + handle_chatmessage_3(); + else + play_noninterrupting_preanim(); } } @@ -1049,6 +1572,13 @@ void Courtroom::handle_chatmessage_3() { start_chat_ticking(); + if (m_chatmessage[REALIZATION] == "1") + { + realization_timer->start(60); + ui_vp_realization->show(); + sfx_player->play(ao_app->get_custom_realization(m_chatmessage[CHAR_NAME])); + } + int f_evi_id = m_chatmessage[EVIDENCE_ID].toInt(); QString f_side = m_chatmessage[SIDE]; @@ -1057,19 +1587,24 @@ void Courtroom::handle_chatmessage_3() //shifted by 1 because 0 is no evidence per legacy standards QString f_image = local_evidence_list.at(f_evi_id - 1).image; //def jud and hlp should display the evidence icon on the RIGHT side - bool is_left_side = !(f_side == "def" || f_side == "hlp" || f_side == "jud"); + bool is_left_side = !(f_side == "def" || f_side == "hlp" || f_side == "jud" || f_side == "jur"); ui_vp_evidence_display->show_evidence(f_image, is_left_side, ui_sfx_slider->value()); } int emote_mod = m_chatmessage[EMOTE_MOD].toInt(); + QString side = m_chatmessage[SIDE]; + if (emote_mod == 5 || emote_mod == 6) { - QString side = m_chatmessage[SIDE]; ui_vp_desk->hide(); ui_vp_legacy_desk->hide(); + // Since we're zooming, hide the second character, and centre the first. + ui_vp_sideplayer_char->hide(); + ui_vp_player_char->move(0,0); + if (side == "pro" || side == "hlp" || side == "wit") @@ -1084,11 +1619,17 @@ void Courtroom::handle_chatmessage_3() bool text_is_blue = m_chatmessage[TEXT_COLOR].toInt() == BLUE; if (!text_is_blue && text_state == 1) + { //talking f_anim_state = 2; + entire_message_is_blue = false; + } else + { //idle f_anim_state = 3; + entire_message_is_blue = true; + } if (f_anim_state <= anim_state) return; @@ -1105,18 +1646,12 @@ void Courtroom::handle_chatmessage_3() break; default: qDebug() << "W: invalid anim_state: " << f_anim_state; + // fall through case 3: ui_vp_player_char->play_idle(f_char, f_emote); anim_state = 3; } - if (m_chatmessage[REALIZATION] == "1") - { - realization_timer->start(60); - ui_vp_realization->show(); - sfx_player->play(ao_app->get_sfx("realization")); - } - QString f_message = m_chatmessage[MESSAGE]; QStringList call_words = ao_app->get_call_words(); @@ -1141,39 +1676,302 @@ void Courtroom::append_ic_text(QString p_text, QString p_name) normal.setFontWeight(QFont::Normal); const QTextCursor old_cursor = ui_ic_chatlog->textCursor(); const int old_scrollbar_value = ui_ic_chatlog->verticalScrollBar()->value(); - - int scrollbar_limit; - - if(ao_app->ic_scroll_down_enabled()) { - scrollbar_limit = ui_ic_chatlog->verticalScrollBar()->maximum(); - ui_ic_chatlog->moveCursor(QTextCursor::End); - } - else { - scrollbar_limit = ui_ic_chatlog->verticalScrollBar()->minimum(); - ui_ic_chatlog->moveCursor(QTextCursor::Start); - } - - const bool is_fully_scrolled = old_scrollbar_value == scrollbar_limit; - ui_ic_chatlog->textCursor().insertText(p_name, bold); - ui_ic_chatlog->textCursor().insertText(p_text + '\n', normal); - - if (old_cursor.hasSelection() || !is_fully_scrolled) + // Get rid of centering. + if(p_text.startsWith(": ~~")) { - // The user has selected text or scrolled away from the top: maintain position. - ui_ic_chatlog->setTextCursor(old_cursor); - ui_ic_chatlog->verticalScrollBar()->setValue(old_scrollbar_value); + // Don't forget, the p_text part actually everything after the name! + // Hence why we check for ': ~~'. + + // Let's remove those two tildes, then. + // : _ ~ ~ + // 0 1 2 3 + p_text.remove(2,2); + } + + // Get rid of the inline-colouring. + // I know, I know, excessive code duplication. + // Nobody looks in here, I'm fine. + int trick_check_pos = 0; + bool ic_next_is_not_special = false; + QString f_character = p_text.at(trick_check_pos); + std::stack ic_colour_stack; + while (trick_check_pos < p_text.size()) + { + f_character = p_text.at(trick_check_pos); + + // Escape character. + if (f_character == "\\" and !ic_next_is_not_special) + { + ic_next_is_not_special = true; + p_text.remove(trick_check_pos,1); + } + + // Text speed modifier. + else if (f_character == "{" and !ic_next_is_not_special) + { + p_text.remove(trick_check_pos,1); + } + else if (f_character == "}" and !ic_next_is_not_special) + { + p_text.remove(trick_check_pos,1); + } + + // Orange inline colourisation. + else if (f_character == "|" and !ic_next_is_not_special) + { + if (!ic_colour_stack.empty()) + { + if (ic_colour_stack.top() == INLINE_ORANGE) + { + ic_colour_stack.pop(); + p_text.remove(trick_check_pos,1); + } + else + { + ic_colour_stack.push(INLINE_ORANGE); + p_text.remove(trick_check_pos,1); + } + } + else + { + ic_colour_stack.push(INLINE_ORANGE); + p_text.remove(trick_check_pos,1); + } + } + + // Blue inline colourisation. + else if (f_character == "(" and !ic_next_is_not_special) + { + ic_colour_stack.push(INLINE_BLUE); + trick_check_pos++; + } + else if (f_character == ")" and !ic_next_is_not_special + and !ic_colour_stack.empty()) + { + if (ic_colour_stack.top() == INLINE_BLUE) + { + ic_colour_stack.pop(); + trick_check_pos++; + } + else + { + ic_next_is_not_special = true; + } + } + + // Grey inline colourisation. + else if (f_character == "[" and !ic_next_is_not_special) + { + ic_colour_stack.push(INLINE_GREY); + trick_check_pos++; + } + else if (f_character == "]" and !ic_next_is_not_special + and !ic_colour_stack.empty()) + { + if (ic_colour_stack.top() == INLINE_GREY) + { + ic_colour_stack.pop(); + trick_check_pos++; + } + else + { + ic_next_is_not_special = true; + } + } + + // Green inline colourisation. + else if (f_character == "`" and !ic_next_is_not_special) + { + if (!ic_colour_stack.empty()) + { + if (ic_colour_stack.top() == INLINE_GREEN) + { + ic_colour_stack.pop(); + p_text.remove(trick_check_pos,1); + } + else + { + ic_colour_stack.push(INLINE_GREEN); + p_text.remove(trick_check_pos,1); + } + } + else + { + ic_colour_stack.push(INLINE_GREEN); + p_text.remove(trick_check_pos,1); + } + } + else + { + trick_check_pos++; + ic_next_is_not_special = false; + } + } + + // After all of that, let's jot down the message into the IC chatlog. + + if (log_goes_downwards) + { + const bool is_scrolled_down = old_scrollbar_value == ui_ic_chatlog->verticalScrollBar()->maximum(); + + ui_ic_chatlog->moveCursor(QTextCursor::End); + + if (!first_message_sent) + { + ui_ic_chatlog->textCursor().insertText(p_name, bold); + first_message_sent = true; + } + else + { + ui_ic_chatlog->textCursor().insertText('\n' + p_name, bold); + } + + ui_ic_chatlog->textCursor().insertText(p_text, normal); + + // If we got too many blocks in the current log, delete some from the top. + while (ui_ic_chatlog->document()->blockCount() > log_maximum_blocks && log_maximum_blocks > 0) + { + ui_ic_chatlog->moveCursor(QTextCursor::Start); + ui_ic_chatlog->textCursor().select(QTextCursor::BlockUnderCursor); + ui_ic_chatlog->textCursor().removeSelectedText(); + ui_ic_chatlog->textCursor().deleteChar(); + //qDebug() << ui_ic_chatlog->document()->blockCount() << " < " << log_maximum_blocks; + } + + if (old_cursor.hasSelection() || !is_scrolled_down) + { + // The user has selected text or scrolled away from the bottom: maintain position. + ui_ic_chatlog->setTextCursor(old_cursor); + ui_ic_chatlog->verticalScrollBar()->setValue(old_scrollbar_value); + } + else + { + // The user hasn't selected any text and the scrollbar is at the bottom: scroll to the bottom. + ui_ic_chatlog->moveCursor(QTextCursor::End); + ui_ic_chatlog->verticalScrollBar()->setValue(ui_ic_chatlog->verticalScrollBar()->maximum()); + } } else { - // The user hasn't selected any text and the scrollbar is at the top: scroll to the top. - if(ao_app->ic_scroll_down_enabled()) { - ui_ic_chatlog->moveCursor(QTextCursor::End); - ui_ic_chatlog->verticalScrollBar()->setValue(ui_ic_chatlog->verticalScrollBar()->maximum()); + const bool is_scrolled_up = old_scrollbar_value == ui_ic_chatlog->verticalScrollBar()->minimum(); + + ui_ic_chatlog->moveCursor(QTextCursor::Start); + + ui_ic_chatlog->textCursor().insertText(p_name, bold); + ui_ic_chatlog->textCursor().insertText(p_text + '\n', normal); + + // If we got too many blocks in the current log, delete some from the bottom. + while (ui_ic_chatlog->document()->blockCount() > log_maximum_blocks && log_maximum_blocks > 0) + { + ui_ic_chatlog->moveCursor(QTextCursor::End); + ui_ic_chatlog->textCursor().select(QTextCursor::BlockUnderCursor); + ui_ic_chatlog->textCursor().removeSelectedText(); + ui_ic_chatlog->textCursor().deletePreviousChar(); + //qDebug() << ui_ic_chatlog->document()->blockCount() << " < " << log_maximum_blocks; } - else { - ui_ic_chatlog->moveCursor(QTextCursor::Start); - ui_ic_chatlog->verticalScrollBar()->setValue(ui_ic_chatlog->verticalScrollBar()->minimum()); + + if (old_cursor.hasSelection() || !is_scrolled_up) + { + // The user has selected text or scrolled away from the top: maintain position. + ui_ic_chatlog->setTextCursor(old_cursor); + ui_ic_chatlog->verticalScrollBar()->setValue(old_scrollbar_value); + } + else + { + // The user hasn't selected any text and the scrollbar is at the top: scroll to the top. + ui_ic_chatlog->moveCursor(QTextCursor::Start); + ui_ic_chatlog->verticalScrollBar()->setValue(ui_ic_chatlog->verticalScrollBar()->minimum()); + } + } +} + +// Call it ugly, call it a hack, but I wanted to do something special with the songname changes. +void Courtroom::append_ic_songchange(QString p_songname, QString p_name) +{ + QTextCharFormat bold; + QTextCharFormat normal; + QTextCharFormat italics; + bold.setFontWeight(QFont::Bold); + normal.setFontWeight(QFont::Normal); + italics.setFontItalic(true); + const QTextCursor old_cursor = ui_ic_chatlog->textCursor(); + const int old_scrollbar_value = ui_ic_chatlog->verticalScrollBar()->value(); + + if (log_goes_downwards) + { + const bool is_scrolled_down = old_scrollbar_value == ui_ic_chatlog->verticalScrollBar()->maximum(); + + ui_ic_chatlog->moveCursor(QTextCursor::End); + + if (!first_message_sent) + { + ui_ic_chatlog->textCursor().insertText(p_name, bold); + first_message_sent = true; + } + else + { + ui_ic_chatlog->textCursor().insertText('\n' + p_name, bold); + } + + ui_ic_chatlog->textCursor().insertText(" has played a song: ", normal); + ui_ic_chatlog->textCursor().insertText(p_songname + ".", italics); + + // If we got too many blocks in the current log, delete some from the top. + while (ui_ic_chatlog->document()->blockCount() > log_maximum_blocks && log_maximum_blocks > 0) + { + ui_ic_chatlog->moveCursor(QTextCursor::Start); + ui_ic_chatlog->textCursor().select(QTextCursor::BlockUnderCursor); + ui_ic_chatlog->textCursor().removeSelectedText(); + ui_ic_chatlog->textCursor().deleteChar(); + //qDebug() << ui_ic_chatlog->document()->blockCount() << " < " << log_maximum_blocks; + } + + if (old_cursor.hasSelection() || !is_scrolled_down) + { + // The user has selected text or scrolled away from the bottom: maintain position. + ui_ic_chatlog->setTextCursor(old_cursor); + ui_ic_chatlog->verticalScrollBar()->setValue(old_scrollbar_value); + } + else + { + // The user hasn't selected any text and the scrollbar is at the bottom: scroll to the bottom. + ui_ic_chatlog->moveCursor(QTextCursor::End); + ui_ic_chatlog->verticalScrollBar()->setValue(ui_ic_chatlog->verticalScrollBar()->maximum()); + } + } + else + { + const bool is_scrolled_up = old_scrollbar_value == ui_ic_chatlog->verticalScrollBar()->minimum(); + + ui_ic_chatlog->moveCursor(QTextCursor::Start); + + ui_ic_chatlog->textCursor().insertText(p_name, bold); + + ui_ic_chatlog->textCursor().insertText(" has played a song: ", normal); + ui_ic_chatlog->textCursor().insertText(p_songname + "." + '\n', italics); + + // If we got too many blocks in the current log, delete some from the bottom. + while (ui_ic_chatlog->document()->blockCount() > log_maximum_blocks && log_maximum_blocks > 0) + { + ui_ic_chatlog->moveCursor(QTextCursor::End); + ui_ic_chatlog->textCursor().select(QTextCursor::BlockUnderCursor); + ui_ic_chatlog->textCursor().removeSelectedText(); + ui_ic_chatlog->textCursor().deletePreviousChar(); + //qDebug() << ui_ic_chatlog->document()->blockCount() << " < " << log_maximum_blocks; + } + + if (old_cursor.hasSelection() || !is_scrolled_up) + { + // The user has selected text or scrolled away from the top: maintain position. + ui_ic_chatlog->setTextCursor(old_cursor); + ui_ic_chatlog->verticalScrollBar()->setValue(old_scrollbar_value); + } + else + { + // The user hasn't selected any text and the scrollbar is at the top: scroll to the top. + ui_ic_chatlog->moveCursor(QTextCursor::Start); + ui_ic_chatlog->verticalScrollBar()->setValue(ui_ic_chatlog->verticalScrollBar()->minimum()); } } } @@ -1213,8 +2011,45 @@ void Courtroom::play_preanim() } +void Courtroom::play_noninterrupting_preanim() +{ + QString f_char = m_chatmessage[CHAR_NAME]; + QString f_preanim = m_chatmessage[PRE_EMOTE]; + + //all time values in char.inis are multiplied by a constant(time_mod) to get the actual time + int ao2_duration = ao_app->get_ao2_preanim_duration(f_char, f_preanim); + int text_delay = ao_app->get_text_delay(f_char, f_preanim) * time_mod; + int sfx_delay = m_chatmessage[SFX_DELAY].toInt() * 60; + + int preanim_duration; + + if (ao2_duration < 0) + preanim_duration = ao_app->get_preanim_duration(f_char, f_preanim); + else + preanim_duration = ao2_duration; + + sfx_delay_timer->start(sfx_delay); + + if (!file_exists(ao_app->get_character_path(f_char) + f_preanim.toLower() + ".gif") || + preanim_duration < 0) + { + anim_state = 4; + preanim_done(); + qDebug() << "could not find " + ao_app->get_character_path(f_char) + f_preanim.toLower() + ".gif"; + return; + } + + ui_vp_player_char->play_pre(f_char, f_preanim, preanim_duration); + anim_state = 4; + if (text_delay >= 0) + text_delay_timer->start(text_delay); + + handle_chatmessage_3(); +} + void Courtroom::preanim_done() { + anim_state = 1; handle_chatmessage_3(); } @@ -1225,13 +2060,14 @@ void Courtroom::realization_done() void Courtroom::start_chat_ticking() { - ui_vp_message->clear(); - set_text_color(); - rainbow_counter = 0; //we need to ensure that the text isn't already ticking because this function can be called by two logic paths if (text_state != 0) return; + ui_vp_message->clear(); + set_text_color(); + rainbow_counter = 0; + if (chatmessage_is_empty) { //since the message is empty, it's technically done ticking @@ -1239,11 +2075,25 @@ void Courtroom::start_chat_ticking() return; } + // At this point, we'd do well to clear the inline colour stack. + // This stops it from flowing into next messages. + while (!inline_colour_stack.empty()) + { + inline_colour_stack.pop(); + } + ui_vp_chatbox->show(); tick_pos = 0; blip_pos = 0; - chat_tick_timer->start(chat_tick_interval); + + // Just in case we somehow got inline blue text left over from a previous message, + // let's set it to false. + inline_blue_depth = 0; + + // At the start of every new message, we set the text speed to the default. + current_display_speed = 3; + chat_tick_timer->start(message_display_speed[current_display_speed]); QString f_gender = ao_app->get_gender(m_chatmessage[CHAR_NAME]); @@ -1260,12 +2110,27 @@ void Courtroom::chat_tick() QString f_message = m_chatmessage[MESSAGE]; + // Due to our new text speed system, we always need to stop the timer now. + chat_tick_timer->stop(); + + // Stops blips from playing when we have a formatting option. + bool formatting_char = false; + + // If previously, we have detected that the message is centered, now + // is the time to remove those two tildes at the start. + if (message_is_centered) + { + f_message.remove(0,2); + } + if (tick_pos >= f_message.size()) { text_state = 2; - chat_tick_timer->stop(); - anim_state = 3; - ui_vp_player_char->play_idle(m_chatmessage[CHAR_NAME], m_chatmessage[EMOTE]); + if (anim_state != 4) + { + anim_state = 3; + ui_vp_player_char->play_idle(m_chatmessage[CHAR_NAME], m_chatmessage[EMOTE]); + } } else @@ -1282,19 +2147,19 @@ void Courtroom::chat_tick() switch (rainbow_counter) { case 0: - html_color = "#FF0000"; + html_color = get_text_color(QString::number(RED)).name(); break; case 1: - html_color = "#FF7F00"; + html_color = get_text_color(QString::number(ORANGE)).name(); break; case 2: - html_color = "#FFFF00"; + html_color = get_text_color(QString::number(YELLOW)).name(); break; case 3: - html_color = "#00FF00"; + html_color = get_text_color(QString::number(GREEN)).name(); break; default: - html_color = "#2d96ff"; + html_color = get_text_color(QString::number(BLUE)).name(); rainbow_counter = -1; } @@ -1302,8 +2167,181 @@ void Courtroom::chat_tick() ui_vp_message->insertHtml("" + f_character + ""); } + + // Escape character. + else if (f_character == "\\" and !next_character_is_not_special) + { + next_character_is_not_special = true; + formatting_char = true; + } + + // Text speed modifier. + else if (f_character == "{" and !next_character_is_not_special) + { + // ++, because it INCREASES delay! + current_display_speed++; + formatting_char = true; + } + else if (f_character == "}" and !next_character_is_not_special) + { + current_display_speed--; + formatting_char = true; + } + + // Orange inline colourisation. + else if (f_character == "|" and !next_character_is_not_special) + { + if (!inline_colour_stack.empty()) + { + if (inline_colour_stack.top() == INLINE_ORANGE) + { + inline_colour_stack.pop(); + } + else + { + inline_colour_stack.push(INLINE_ORANGE); + } + } + else + { + inline_colour_stack.push(INLINE_ORANGE); + } + formatting_char = true; + } + + // Blue inline colourisation. + else if (f_character == "(" and !next_character_is_not_special) + { + inline_colour_stack.push(INLINE_BLUE); + ui_vp_message->insertHtml("" + f_character + ""); + + // Increase how deep we are in inline blues. + inline_blue_depth++; + + // Here, we check if the entire message is blue. + // If it isn't, we stop talking. + if (!entire_message_is_blue and anim_state != 4) + { + QString f_char = m_chatmessage[CHAR_NAME]; + QString f_emote = m_chatmessage[EMOTE]; + ui_vp_player_char->play_idle(f_char, f_emote); + } + } + else if (f_character == ")" and !next_character_is_not_special + and !inline_colour_stack.empty()) + { + if (inline_colour_stack.top() == INLINE_BLUE) + { + inline_colour_stack.pop(); + ui_vp_message->insertHtml("" + f_character + ""); + + // Decrease how deep we are in inline blues. + // Just in case, we do a check if we're above zero, but we should be. + if (inline_blue_depth > 0) + { + inline_blue_depth--; + // Here, we check if the entire message is blue. + // If it isn't, we start talking if we have completely climbed out of inline blues. + if (!entire_message_is_blue) + { + // We should only go back to talking if we're out of inline blues, not during a non. int. pre, and not on the last character. + if (inline_blue_depth == 0 and anim_state != 4 and !(tick_pos+1 >= f_message.size())) + { + QString f_char = m_chatmessage[CHAR_NAME]; + QString f_emote = m_chatmessage[EMOTE]; + ui_vp_player_char->play_talking(f_char, f_emote); + } + } + } + } + else + { + next_character_is_not_special = true; + tick_pos--; + } + } + + // Grey inline colourisation. + else if (f_character == "[" and !next_character_is_not_special) + { + inline_colour_stack.push(INLINE_GREY); + ui_vp_message->insertHtml("" + f_character + ""); + } + else if (f_character == "]" and !next_character_is_not_special + and !inline_colour_stack.empty()) + { + if (inline_colour_stack.top() == INLINE_GREY) + { + inline_colour_stack.pop(); + ui_vp_message->insertHtml("" + f_character + ""); + } + else + { + next_character_is_not_special = true; + tick_pos--; + } + } + + // Green inline colourisation. + else if (f_character == "`" and !next_character_is_not_special) + { + if (!inline_colour_stack.empty()) + { + if (inline_colour_stack.top() == INLINE_GREEN) + { + inline_colour_stack.pop(); + formatting_char = true; + } + else + { + inline_colour_stack.push(INLINE_GREEN); + formatting_char = true; + } + } + else + { + inline_colour_stack.push(INLINE_GREEN); + formatting_char = true; + } + } else - ui_vp_message->insertHtml(f_character); + { + next_character_is_not_special = false; + if (!inline_colour_stack.empty()) + { + switch (inline_colour_stack.top()) { + case INLINE_ORANGE: + ui_vp_message->insertHtml("" + f_character + ""); + break; + case INLINE_BLUE: + ui_vp_message->insertHtml("" + f_character + ""); + break; + case INLINE_GREEN: + ui_vp_message->insertHtml("" + f_character + ""); + break; + case INLINE_GREY: + ui_vp_message->insertHtml("" + f_character + ""); + break; + default: + ui_vp_message->insertHtml(f_character); + break; + } + + } + else + { + ui_vp_message->insertHtml(f_character); + } + + if (message_is_centered) + { + ui_vp_message->setAlignment(Qt::AlignCenter); + } + else + { + ui_vp_message->setAlignment(Qt::AlignLeft); + } + } QScrollBar *scroll = ui_vp_message->verticalScrollBar(); scroll->setValue(scroll->maximum()); @@ -1314,7 +2352,7 @@ void Courtroom::chat_tick() if (f_message.at(tick_pos) != ' ' || blank_blip) { - if (blip_pos % blip_rate == 0) + if (blip_pos % blip_rate == 0 && !formatting_char) { blip_pos = 0; blip_player->blip_tick(); @@ -1324,6 +2362,29 @@ void Courtroom::chat_tick() } ++tick_pos; + + // Restart the timer, but according to the newly set speeds, if there were any. + // Keep the speed at bay. + if (current_display_speed < 0) + { + current_display_speed = 0; + } + + if (current_display_speed > 6) + { + current_display_speed = 6; + } + + // If we had a formatting char, we shouldn't wait so long again, as it won't appear! + if (formatting_char) + { + chat_tick_timer->start(1); + } + else + { + chat_tick_timer->start(message_display_speed[current_display_speed]); + } + } } @@ -1399,6 +2460,16 @@ void Courtroom::set_scene() f_background = "prohelperstand"; f_desk_image = "prohelperdesk"; } + else if (f_side == "jur") + { + f_background = "jurystand"; + f_desk_image = "jurydesk"; + } + else if (f_side == "sea") + { + f_background = "seancestand"; + f_desk_image = "seancedesk"; + } else { if (is_ao2_bg) @@ -1443,35 +2514,26 @@ void Courtroom::set_scene() void Courtroom::set_text_color() { - switch (m_chatmessage[TEXT_COLOR].toInt()) - { - case GREEN: - ui_vp_message->setStyleSheet("background-color: rgba(0, 0, 0, 0);" - "color: rgb(0, 255, 0)"); - break; - case RED: - ui_vp_message->setStyleSheet("background-color: rgba(0, 0, 0, 0);" - "color: red"); - break; - case ORANGE: - ui_vp_message->setStyleSheet("background-color: rgba(0, 0, 0, 0);" - "color: orange"); - break; - case BLUE: - ui_vp_message->setStyleSheet("background-color: rgba(0, 0, 0, 0);" - "color: rgb(45, 150, 255)"); - break; - case YELLOW: - ui_vp_message->setStyleSheet("background-color: rgba(0, 0, 0, 0);" - "color: yellow"); - break; - default: - qDebug() << "W: undefined text color: " << m_chatmessage[TEXT_COLOR]; - case WHITE: - ui_vp_message->setStyleSheet("background-color: rgba(0, 0, 0, 0);" - "color: white"); + QColor textcolor = ao_app->get_chat_color(m_chatmessage[TEXT_COLOR], ao_app->get_chat(m_chatmessage[CHAR_NAME])); - } + ui_vp_message->setTextBackgroundColor(QColor(0,0,0,0)); + ui_vp_message->setTextColor(textcolor); + + QString style = "background-color: rgba(0, 0, 0, 0);"; + style.append("color: rgb("); + style.append(QString::number(textcolor.red())); + style.append(", "); + style.append(QString::number(textcolor.green())); + style.append(", "); + style.append(QString::number(textcolor.blue())); + style.append(")"); + + ui_vp_message->setStyleSheet(style); +} + +QColor Courtroom::get_text_color(QString color) +{ + return ao_app->get_chat_color(color, ao_app->get_chat(m_chatmessage[CHAR_NAME])); } void Courtroom::set_ip_list(QString p_list) @@ -1520,6 +2582,8 @@ void Courtroom::handle_song(QStringList *p_contents) return; QString f_song = f_contents.at(0); + QString f_song_clear = f_song; + f_song_clear = f_song_clear.left(f_song_clear.lastIndexOf(".")); int n_char = f_contents.at(1).toInt(); if (n_char < 0 || n_char >= char_list.size()) @@ -1529,16 +2593,30 @@ void Courtroom::handle_song(QStringList *p_contents) else { QString str_char = char_list.at(n_char).name; + QString str_show = char_list.at(n_char).name; + + if (p_contents->length() > 2) + { + str_show = p_contents->at(2); + } if (!mute_map.value(n_char)) { - append_ic_text(" has played a song: " + f_song, str_char); + chatlogpiece* temp = new chatlogpiece(str_char, str_show, f_song, true); + ic_chatlog_history.append(*temp); + + while(ic_chatlog_history.size() > log_maximum_blocks) + { + ic_chatlog_history.removeFirst(); + } + + append_ic_songchange(f_song_clear, str_show); music_player->play(f_song); } } } -void Courtroom::handle_wtce(QString p_wtce) +void Courtroom::handle_wtce(QString p_wtce, int variant) { QString sfx_file = "courtroom_sounds.ini"; @@ -1557,6 +2635,20 @@ void Courtroom::handle_wtce(QString p_wtce) ui_vp_wtce->play("crossexamination"); testimony_in_progress = false; } + else if (p_wtce == "judgeruling") + { + if (variant == 0) + { + sfx_player->play(ao_app->get_sfx("not_guilty")); + ui_vp_wtce->play("notguilty"); + testimony_in_progress = false; + } + else if (variant == 1) { + sfx_player->play(ao_app->get_sfx("guilty")); + ui_vp_wtce->play("guilty"); + testimony_in_progress = false; + } + } } void Courtroom::set_hp_bar(int p_bar, int p_state) @@ -1586,6 +2678,23 @@ void Courtroom::mod_called(QString p_ip) } } +void Courtroom::case_called(QString msg, bool def, bool pro, bool jud, bool jur, bool steno) +{ + if (ui_casing->isChecked()) + { + ui_server_chatlog->append(msg); + if ((ao_app->get_casing_defence_enabled() && def) || + (ao_app->get_casing_prosecution_enabled() && pro) || + (ao_app->get_casing_judge_enabled() && jud) || + (ao_app->get_casing_juror_enabled() && jur) || + (ao_app->get_casing_steno_enabled() && steno)) + { + modcall_player->play(ao_app->get_sfx("case_call")); + ao_app->alert(this); + } + } +} + void Courtroom::on_ooc_return_pressed() { QString ooc_message = ui_ooc_chat_message->text(); @@ -1599,6 +2708,8 @@ void Courtroom::on_ooc_return_pressed() { ui_witness_testimony->show(); ui_cross_examination->show(); + ui_guilty->show(); + ui_not_guilty->show(); ui_defense_minus->show(); ui_defense_plus->show(); ui_prosecution_minus->show(); @@ -1608,6 +2719,8 @@ void Courtroom::on_ooc_return_pressed() { ui_witness_testimony->hide(); ui_cross_examination->hide(); + ui_guilty->hide(); + ui_not_guilty->hide(); ui_defense_minus->hide(); ui_defense_plus->hide(); ui_prosecution_minus->hide(); @@ -1615,12 +2728,198 @@ void Courtroom::on_ooc_return_pressed() } } else if (ooc_message.startsWith("/login")) + { ui_guard->show(); + append_server_chatmessage("CLIENT", "You were granted the Guard button.", "1"); + } else if (ooc_message.startsWith("/rainbow") && ao_app->yellow_text_enabled && !rainbow_appended) { - ui_text_color->addItem("Rainbow"); + //ui_text_color->addItem("Rainbow"); + ui_ooc_chat_message->clear(); + //rainbow_appended = true; + append_server_chatmessage("CLIENT", "This does nohing, but there you go.", "1"); + return; + } + else if (ooc_message.startsWith("/settings")) + { + ui_ooc_chat_message->clear(); + ao_app->call_settings_menu(); + append_server_chatmessage("CLIENT", "You opened the settings menu.", "1"); + return; + } + else if (ooc_message.startsWith("/pair")) + { + ui_ooc_chat_message->clear(); + ooc_message.remove(0,6); + + bool ok; + int whom = ooc_message.toInt(&ok); + if (ok) + { + if (whom > -1) + { + other_charid = whom; + QString msg = "You will now pair up with "; + msg.append(char_list.at(whom).name); + msg.append(" if they also choose your character in return."); + append_server_chatmessage("CLIENT", msg, "1"); + } + else + { + append_server_chatmessage("CLIENT", "You are no longer paired with anyone.", "1"); + } + } + else + { + append_server_chatmessage("CLIENT", "Are you sure you typed that well? The char ID could not be recognised.", "1"); + } + return; + } + else if (ooc_message.startsWith("/offset")) + { + ui_ooc_chat_message->clear(); + ooc_message.remove(0,8); + + bool ok; + int off = ooc_message.toInt(&ok); + if (ok) + { + if (off >= -100 && off <= 100) + { + offset_with_pair = off; + QString msg = "You have set your offset to "; + msg.append(QString::number(off)); + msg.append("%."); + append_server_chatmessage("CLIENT", msg, "1"); + } + else + { + append_server_chatmessage("CLIENT", "Your offset must be between -100% and 100%!", "1"); + } + } + else + { + append_server_chatmessage("CLIENT", "That offset does not look like one.", "1"); + } + return; + } + else if (ooc_message.startsWith("/switch_am")) + { + append_server_chatmessage("CLIENT", "You switched your music and area list.", "1"); + on_switch_area_music_clicked(); + ui_ooc_chat_message->clear(); + return; + } + else if (ooc_message.startsWith("/enable_blocks")) + { + append_server_chatmessage("CLIENT", "You have forcefully enabled features that the server may not support. You may not be able to talk IC, or worse, because of this.", "1"); + ao_app->cccc_ic_support_enabled = true; + ao_app->arup_enabled = true; + ao_app->modcall_reason_enabled = true; + on_reload_theme_clicked(); + ui_ooc_chat_message->clear(); + return; + } + else if (ooc_message.startsWith("/non_int_pre")) + { + if (ui_pre_non_interrupt->isChecked()) + append_server_chatmessage("CLIENT", "Your pre-animations interrupt again.", "1"); + else + append_server_chatmessage("CLIENT", "Your pre-animations will not interrupt text.", "1"); + ui_pre_non_interrupt->setChecked(!ui_pre_non_interrupt->isChecked()); + ui_ooc_chat_message->clear(); + return; + } + else if (ooc_message.startsWith("/save_chatlog")) + { + QFile file("chatlog.txt"); + + if (!file.open(QIODevice::WriteOnly | QIODevice::Text | QIODevice::Truncate)) + { + append_server_chatmessage("CLIENT", "Couldn't open chatlog.txt to write into.", "1"); + ui_ooc_chat_message->clear(); + return; + } + + QTextStream out(&file); + + foreach (chatlogpiece item, ic_chatlog_history) { + out << item.get_full() << '\n'; + } + + file.close(); + + append_server_chatmessage("CLIENT", "The IC chatlog has been saved.", "1"); + ui_ooc_chat_message->clear(); + return; + } + else if (ooc_message.startsWith("/load_case")) + { + QStringList command = ooc_message.split(" ", QString::SkipEmptyParts); + + QDir casefolder("base/cases"); + if (!casefolder.exists()) + { + QDir::current().mkdir("base/" + casefolder.dirName()); + append_server_chatmessage("CLIENT", "You don't have a `base/cases/` folder! It was just made for you, but seeing as it WAS just made for you, it's likely the case file you're looking for can't be found in there.", "1"); + ui_ooc_chat_message->clear(); + return; + } + QStringList caseslist = casefolder.entryList(); + caseslist.removeOne("."); + caseslist.removeOne(".."); + caseslist.replaceInStrings(".ini",""); + + if (command.size() < 2) + { + append_server_chatmessage("CLIENT", "You need to give a filename to load (extension not needed)! Make sure that it is in the `base/cases/` folder, and that it is a correctly formatted ini.\nCases you can load: " + caseslist.join(", "), "1"); + ui_ooc_chat_message->clear(); + return; + } + + + if (command.size() > 2) + { + append_server_chatmessage("CLIENT", "Too many arguments to load a case! You only need one filename, without extension.", "1"); + ui_ooc_chat_message->clear(); + return; + } + + QSettings casefile("base/cases/" + command[1] + ".ini", QSettings::IniFormat); + + QString caseauth = casefile.value("author", "").value(); + QString casedoc = casefile.value("doc", "").value(); + QString cmdoc = casefile.value("cmdoc", "").value(); + QString casestatus = casefile.value("status", "").value(); + + if (!caseauth.isEmpty()) + append_server_chatmessage("CLIENT", "Case made by " + caseauth + ".", "1"); + if (!casedoc.isEmpty()) + ao_app->send_server_packet(new AOPacket("CT#" + ui_ooc_chat_name->text() + "#/doc " + casedoc + "#%")); + if (!casestatus.isEmpty()) + ao_app->send_server_packet(new AOPacket("CT#" + ui_ooc_chat_name->text() + "#/status " + casestatus + "#%")); + if (!cmdoc.isEmpty()) + append_server_chatmessage("CLIENT", "Navigate to " + cmdoc + " for the CM doc.", "1"); + + for (int i = local_evidence_list.size() - 1; i >= 0; i--) { + ao_app->send_server_packet(new AOPacket("DE#" + QString::number(i) + "#%")); + } + + foreach (QString evi, casefile.childGroups()) { + if (evi == "General") + continue; + + QStringList f_contents; + + f_contents.append(casefile.value(evi + "/name", "UNKNOWN").value()); + f_contents.append(casefile.value(evi + "/description", "UNKNOWN").value()); + f_contents.append(casefile.value(evi + "/image", "UNKNOWN.png").value()); + + ao_app->send_server_packet(new AOPacket("PE", f_contents)); + } + + append_server_chatmessage("CLIENT", "Your case \"" + command[1] + "\" was loaded!", "1"); ui_ooc_chat_message->clear(); - rainbow_appended = true; return; } @@ -1665,6 +2964,7 @@ void Courtroom::on_music_search_edited(QString p_text) //preventing compiler warnings p_text += "a"; list_music(); + list_areas(); } void Courtroom::on_pos_dropdown_changed(int p_index) @@ -1741,25 +3041,51 @@ void Courtroom::on_mute_list_clicked(QModelIndex p_index) mute_map.insert(f_cid, true); f_item->setText(real_char + " [x]"); } +} +void Courtroom::on_pair_list_clicked(QModelIndex p_index) +{ + QListWidgetItem *f_item = ui_pair_list->item(p_index.row()); + QString f_char = f_item->text(); + QString real_char; - - /* if (f_char.endsWith(" [x]")) { real_char = f_char.left(f_char.size() - 4); - mute_map.remove(real_char); - mute_map.insert(real_char, false); f_item->setText(real_char); } else - { real_char = f_char; - mute_map.remove(real_char); - mute_map.insert(real_char, true); - f_item->setText(real_char + " [x]"); + + int f_cid = -1; + + for (int n_char = 0 ; n_char < char_list.size() ; n_char++) + { + if (char_list.at(n_char).name == real_char) + f_cid = n_char; } - */ + + if (f_cid < 0 || f_cid >= char_list.size()) + { + qDebug() << "W: " << real_char << " not present in char_list"; + return; + } + + other_charid = f_cid; + + // Redo the character list. + QStringList sorted_pair_list; + + for (char_type i_char : char_list) + sorted_pair_list.append(i_char.name); + + sorted_pair_list.sort(); + + for (int i = 0; i < ui_pair_list->count(); i++) { + ui_pair_list->item(i)->setText(sorted_pair_list.at(i)); + } + + f_item->setText(real_char + " [x]"); } void Courtroom::on_music_list_double_clicked(QModelIndex p_model) @@ -1767,9 +3093,22 @@ void Courtroom::on_music_list_double_clicked(QModelIndex p_model) if (is_muted) return; - QString p_song = ui_music_list->item(p_model.row())->text(); + QString p_song = music_list.at(music_row_to_number.at(p_model.row())); - ao_app->send_server_packet(new AOPacket("MC#" + p_song + "#" + QString::number(m_cid) + "#%"), false); + if (!ui_ic_chat_name->text().isEmpty() && ao_app->cccc_ic_support_enabled) + { + ao_app->send_server_packet(new AOPacket("MC#" + p_song + "#" + QString::number(m_cid) + "#" + ui_ic_chat_name->text() + "#%"), false); + } + else + { + ao_app->send_server_packet(new AOPacket("MC#" + p_song + "#" + QString::number(m_cid) + "#%"), false); + } +} + +void Courtroom::on_area_list_double_clicked(QModelIndex p_model) +{ + QString p_area = area_list.at(area_row_to_number.at(p_model.row())); + ao_app->send_server_packet(new AOPacket("MC#" + p_area + "#" + QString::number(m_cid) + "#%"), false); } void Courtroom::on_hold_it_clicked() @@ -1873,6 +3212,9 @@ void Courtroom::on_mute_clicked() if (ui_mute_list->isHidden()) { ui_mute_list->show(); + ui_pair_list->hide(); + ui_pair_offset_spinbox->hide(); + ui_pair_button->set_image("pair_button.png"); ui_mute->set_image("mute_pressed.png"); } else @@ -1882,6 +3224,24 @@ void Courtroom::on_mute_clicked() } } +void Courtroom::on_pair_clicked() +{ + if (ui_pair_list->isHidden()) + { + ui_pair_list->show(); + ui_pair_offset_spinbox->show(); + ui_mute_list->hide(); + ui_mute->set_image("mute.png"); + ui_pair_button->set_image("pair_button_pressed.png"); + } + else + { + ui_pair_list->hide(); + ui_pair_offset_spinbox->hide(); + ui_pair_button->set_image("pair_button.png"); + } +} + void Courtroom::on_defense_minus_clicked() { int f_state = defense_bar_state - 1; @@ -1939,6 +3299,16 @@ void Courtroom::on_blip_slider_moved(int p_value) ui_ic_chat_message->setFocus(); } +void Courtroom::on_log_limit_changed(int value) +{ + log_maximum_blocks = value; +} + +void Courtroom::on_pair_offset_changed(int value) +{ + offset_with_pair = value; +} + void Courtroom::on_witness_testimony_clicked() { if (is_muted) @@ -1959,6 +3329,26 @@ void Courtroom::on_cross_examination_clicked() ui_ic_chat_message->setFocus(); } +void Courtroom::on_not_guilty_clicked() +{ + if (is_muted) + return; + + ao_app->send_server_packet(new AOPacket("RT#judgeruling#0#%")); + + ui_ic_chat_message->setFocus(); +} + +void Courtroom::on_guilty_clicked() +{ + if (is_muted) + return; + + ao_app->send_server_packet(new AOPacket("RT#judgeruling#1#%")); + + ui_ic_chat_message->setFocus(); +} + void Courtroom::on_change_character_clicked() { music_player->set_volume(0); @@ -2014,11 +3404,39 @@ void Courtroom::on_spectator_clicked() void Courtroom::on_call_mod_clicked() { - ao_app->send_server_packet(new AOPacket("ZZ#%")); + if (!ao_app->modcall_reason_enabled) + { + ao_app->send_server_packet(new AOPacket("ZZ#%")); + ui_ic_chat_message->setFocus(); + return; + } + + bool ok; + QString text = QInputDialog::getText(ui_viewport, "Call a mod", + "Reason for the modcall (optional):", QLineEdit::Normal, + "", &ok); + if (ok) + { + text = text.left(100); + if (!text.isEmpty()) + ao_app->send_server_packet(new AOPacket("ZZ#" + text + "#%")); + else + ao_app->send_server_packet(new AOPacket("ZZ#%")); + } ui_ic_chat_message->setFocus(); } +void Courtroom::on_settings_clicked() +{ + ao_app->call_settings_menu(); +} + +void Courtroom::on_announce_casing_clicked() +{ + ao_app->call_announce_menu(this); +} + void Courtroom::on_pre_clicked() { ui_ic_chat_message->setFocus(); @@ -2034,6 +3452,31 @@ void Courtroom::on_guard_clicked() ui_ic_chat_message->setFocus(); } +void Courtroom::on_showname_enable_clicked() +{ + ui_ic_chatlog->clear(); + first_message_sent = false; + + foreach (chatlogpiece item, ic_chatlog_history) { + if (ui_showname_enable->isChecked()) + { + if (item.get_is_song()) + append_ic_songchange(item.get_message(), item.get_showname()); + else + append_ic_text(item.get_message(), item.get_showname()); + } + else + { + if (item.get_is_song()) + append_ic_songchange(item.get_message(), item.get_name()); + else + append_ic_text(item.get_message(), item.get_name()); + } + } + + ui_ic_chat_message->setFocus(); +} + void Courtroom::on_evidence_button_clicked() { if (ui_evidence->isHidden()) @@ -2047,11 +3490,57 @@ void Courtroom::on_evidence_button_clicked() } } +void Courtroom::on_switch_area_music_clicked() +{ + if (ui_area_list->isHidden()) + { + ui_area_list->show(); + ui_music_list->hide(); + } + else + { + ui_area_list->hide(); + ui_music_list->show(); + } +} + void Courtroom::ping_server() { ao_app->send_server_packet(new AOPacket("CH#" + QString::number(m_cid) + "#%")); } +void Courtroom::on_casing_clicked() +{ + if (ao_app->casing_alerts_enabled) + { + if (ui_casing->isChecked()) + ao_app->send_server_packet(new AOPacket("CT#" + ui_ooc_chat_name->text() + "#/setcase" + + " \"" + ao_app->get_casing_can_host_cases() + "\"" + + " " + QString::number(ao_app->get_casing_cm_enabled()) + + " " + QString::number(ao_app->get_casing_defence_enabled()) + + " " + QString::number(ao_app->get_casing_prosecution_enabled()) + + " " + QString::number(ao_app->get_casing_judge_enabled()) + + " " + QString::number(ao_app->get_casing_juror_enabled()) + + " " + QString::number(ao_app->get_casing_steno_enabled()) + + "#%")); + else + ao_app->send_server_packet(new AOPacket("CT#" + ui_ooc_chat_name->text() + "#/setcase \"\" 0 0 0 0 0 0#%")); + } +} + +void Courtroom::announce_case(QString title, bool def, bool pro, bool jud, bool jur, bool steno) +{ + if (ao_app->casing_alerts_enabled) + ao_app->send_server_packet(new AOPacket("CT#" + ui_ooc_chat_name->text() + "#/anncase \"" + + title + "\" " + + QString::number(def) + " " + + QString::number(pro) + " " + + QString::number(jud) + " " + + QString::number(jur) + " " + + QString::number(steno) + + "#%")); +} + Courtroom::~Courtroom() { delete music_player; @@ -2059,3 +3548,17 @@ Courtroom::~Courtroom() delete objection_player; delete blip_player; } + +#if (defined (_WIN32) || defined (_WIN64)) +void Courtroom::load_bass_opus_plugin() +{ + BASS_PluginLoad("bassopus.dll", 0); +} +#elif (defined (LINUX) || defined (__linux__)) +void Courtroom::load_bass_opus_plugin() +{ + BASS_PluginLoad("libbassopus.so", 0); +} +#else +#error This operating system is unsupported for bass plugins. +#endif diff --git a/courtroom.h b/courtroom.h index 2cc099c..dc1c18d 100644 --- a/courtroom.h +++ b/courtroom.h @@ -24,13 +24,8 @@ #include "file_functions.h" #include "datatypes.h" #include "debug_functions.h" +#include "chatlogpiece.h" -#include -#include -#include -#include -#include -#include #include #include #include @@ -43,6 +38,18 @@ #include #include #include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#include class AOApplication; @@ -55,6 +62,49 @@ public: void append_char(char_type p_char){char_list.append(p_char);} void append_evidence(evi_type p_evi){evidence_list.append(p_evi);} void append_music(QString f_music){music_list.append(f_music);} + void append_area(QString f_area){area_list.append(f_area);} + + void fix_last_area() + { + QString malplaced = area_list.last(); + area_list.removeLast(); + append_music(malplaced); + } + + void arup_append(int players, QString status, QString cm, QString locked) + { + arup_players.append(players); + arup_statuses.append(status); + arup_cms.append(cm); + arup_locks.append(locked); + } + + void arup_modify(int type, int place, QString value) + { + if (type == 0) + { + if (arup_players.size() > place) + arup_players[place] = value.toInt(); + } + else if (type == 1) + { + if (arup_statuses.size() > place) + arup_statuses[place] = value; + } + else if (type == 2) + { + if (arup_cms.size() > place) + arup_cms[place] = value; + } + else if (type == 3) + { + if (arup_locks.size() > place) + arup_locks[place] = value; + } + list_areas(); + } + + void character_loading_finished(); //sets position of widgets based on theme ini files void set_widgets(); @@ -83,12 +133,18 @@ public: //sets the local mute list based on characters available on the server void set_mute_list(); + // Sets the local pair list based on the characters available on the server. + void set_pair_list(); + //sets desk and bg based on pos in chatmessage void set_scene(); //sets text color based on text color in chatmessage void set_text_color(); + // And gets the colour, too! + QColor get_text_color(QString color); + //takes in serverD-formatted IP list as prints a converted version to server OOC //admittedly poorly named void set_ip_list(QString p_list); @@ -113,10 +169,11 @@ public: //helper function that populates ui_music_list with the contents of music_list void list_music(); + void list_areas(); //these are for OOC chat void append_ms_chatmessage(QString f_name, QString f_message); - void append_server_chatmessage(QString p_name, QString p_message); + void append_server_chatmessage(QString p_name, QString p_message, QString p_colour); //these functions handle chatmessages sequentially. //The process itself is very convoluted and merits separate documentation @@ -130,19 +187,25 @@ public: // or the user isn't already scrolled to the top void append_ic_text(QString p_text, QString p_name = ""); + // This is essentially the same as the above, but specifically for song changes. + void append_ic_songchange(QString p_songname, QString p_name = ""); + //prints who played the song to IC chat and plays said song(if found on local filesystem) //takes in a list where the first element is the song name and the second is the char id of who played it void handle_song(QStringList *p_contents); void play_preanim(); + void play_noninterrupting_preanim(); //plays the witness testimony or cross examination animation based on argument - void handle_wtce(QString p_wtce); + void handle_wtce(QString p_wtce, int variant); //sets the hp bar of defense(p_bar 1) or pro(p_bar 2) //state is an number between 0 and 10 inclusive void set_hp_bar(int p_bar, int p_state); + void announce_case(QString title, bool def, bool pro, bool jud, bool jur, bool steno); + void check_connection_received(); ~Courtroom(); @@ -159,18 +222,67 @@ private: int m_viewport_width = 256; int m_viewport_height = 192; + bool first_message_sent = false; + int maximumMessages = 0; + + // This is for inline message-colouring. + + enum INLINE_COLOURS { + INLINE_BLUE, + INLINE_GREEN, + INLINE_ORANGE, + INLINE_GREY + }; + + // A stack of inline colours. + std::stack inline_colour_stack; + + bool next_character_is_not_special = false; // If true, write the + // next character as it is. + + bool message_is_centered = false; + + int current_display_speed = 3; + int message_display_speed[7] = {30, 40, 50, 60, 75, 100, 120}; + + // This is for checking if the character should start talking again + // when an inline blue text ends. + bool entire_message_is_blue = false; + + // And this is the inline 'talking checker'. Counts how 'deep' we are + // in inline blues. + int inline_blue_depth = 0; + + // The character ID of the character this user wants to appear alongside with. + int other_charid = -1; + + // The offset this user has given if they want to appear alongside someone. + int offset_with_pair = 0; + QVector char_list; QVector evidence_list; QVector music_list; + QVector area_list; + + QVector arup_players; + QVector arup_statuses; + QVector arup_cms; + QVector arup_locks; QSignalMapper *char_button_mapper; + QVector ic_chatlog_history; + + // These map music row items and area row items to their actual IDs. + QVector music_row_to_number; + QVector area_row_to_number; + //triggers ping_server() every 60 seconds QTimer *keepalive_timer; //determines how fast messages tick onto screen QTimer *chat_tick_timer; - int chat_tick_interval = 60; + //int chat_tick_interval = 60; //which tick position(character in chat message) we are at int tick_pos = 0; //used to determine how often blips sound @@ -180,6 +292,12 @@ private: bool rainbow_appended = false; bool blank_blip = false; + // Used for getting the current maximum blocks allowed in the IC chatlog. + int log_maximum_blocks = 0; + + // True, if the log should go downwards. + bool log_goes_downwards = false; + //delay before chat messages starts ticking QTimer *text_delay_timer; @@ -197,7 +315,7 @@ private: //every time point in char.inis times this equals the final time const int time_mod = 40; - static const int chatmessage_size = 15; + static const int chatmessage_size = 23; QString m_chatmessage[chatmessage_size]; bool chatmessage_is_empty = false; @@ -218,7 +336,7 @@ private: bool is_muted = false; - //state of animation, 0 = objecting, 1 = preanim, 2 = talking, 3 = idle + //state of animation, 0 = objecting, 1 = preanim, 2 = talking, 3 = idle, 4 = noniterrupting preanim int anim_state = 3; //state of text ticking, 0 = not yet ticking, 1 = ticking in progress, 2 = ticking done @@ -242,6 +360,9 @@ private: int char_rows = 9; int max_chars_on_page = 90; + const int button_width = 60; + const int button_height = 60; + int current_emote_page = 0; int current_emote = 0; int emote_columns = 5; @@ -277,6 +398,7 @@ private: AOScene *ui_vp_background; AOMovie *ui_vp_speedlines; AOCharMovie *ui_vp_player_char; + AOCharMovie *ui_vp_sideplayer_char; AOScene *ui_vp_desk; AOScene *ui_vp_legacy_desk; AOEvidenceDisplay *ui_vp_evidence_display; @@ -297,7 +419,12 @@ private: QListWidget *ui_area_list; QListWidget *ui_music_list; + AOButton *ui_pair_button; + QListWidget *ui_pair_list; + QSpinBox *ui_pair_offset_spinbox; + QLineEdit *ui_ic_chat_message; + QLineEdit *ui_ic_chat_name; QLineEdit *ui_ooc_chat_message; QLineEdit *ui_ooc_chat_name; @@ -328,14 +455,23 @@ private: AOButton *ui_witness_testimony; AOButton *ui_cross_examination; + AOButton *ui_guilty; + AOButton *ui_not_guilty; AOButton *ui_change_character; AOButton *ui_reload_theme; AOButton *ui_call_mod; + AOButton *ui_settings; + AOButton *ui_announce_casing; + AOButton *ui_switch_area_music; QCheckBox *ui_pre; QCheckBox *ui_flip; QCheckBox *ui_guard; + QCheckBox *ui_casing; + + QCheckBox *ui_pre_non_interrupt; + QCheckBox *ui_showname_enable; AOButton *ui_custom_objection; AOButton *ui_realization; @@ -355,6 +491,9 @@ private: AOImage *ui_muted; + QSpinBox *ui_log_limit_spinbox; + QLabel *ui_log_limit_label; + AOButton *ui_evidence_button; AOImage *ui_evidence; AOLineEdit *ui_evidence_name; @@ -376,6 +515,7 @@ private: QWidget *ui_char_buttons; QVector ui_char_button_list; + QVector ui_char_button_list_filtered; AOImage *ui_selector; AOButton *ui_back_to_lobby; @@ -387,9 +527,15 @@ private: AOButton *ui_spectator; + QLineEdit *ui_char_search; + QCheckBox *ui_char_passworded; + QCheckBox *ui_char_taken; + void construct_char_select(); void set_char_select(); void set_char_select_page(); + void put_button_in_place(int starting, int chars_on_this_page); + void filter_character_list(); void construct_emotes(); void set_emote_page(); @@ -398,8 +544,6 @@ private: void construct_evidence(); void set_evidence_page(); - - public slots: void objection_done(); void preanim_done(); @@ -411,6 +555,8 @@ public slots: void mod_called(QString p_ip); + void case_called(QString msg, bool def, bool pro, bool jud, bool jur, bool steno); + private slots: void start_chat_ticking(); void play_sfx(); @@ -418,6 +564,7 @@ private slots: void chat_tick(); void on_mute_list_clicked(QModelIndex p_index); + void on_pair_list_clicked(QModelIndex p_index); void on_chat_return_pressed(); @@ -425,6 +572,7 @@ private slots: void on_music_search_edited(QString p_text); void on_music_list_double_clicked(QModelIndex p_model); + void on_area_list_double_clicked(QModelIndex p_model); void select_emote(int p_id); @@ -456,6 +604,7 @@ private slots: void on_realization_clicked(); void on_mute_clicked(); + void on_pair_clicked(); void on_defense_minus_clicked(); void on_defense_plus_clicked(); @@ -468,19 +617,28 @@ private slots: void on_sfx_slider_moved(int p_value); void on_blip_slider_moved(int p_value); + void on_log_limit_changed(int value); + void on_pair_offset_changed(int value); + void on_ooc_toggle_clicked(); void on_witness_testimony_clicked(); void on_cross_examination_clicked(); + void on_not_guilty_clicked(); + void on_guilty_clicked(); void on_change_character_clicked(); void on_reload_theme_clicked(); void on_call_mod_clicked(); + void on_settings_clicked(); + void on_announce_casing_clicked(); void on_pre_clicked(); void on_flip_clicked(); void on_guard_clicked(); + void on_showname_enable_clicked(); + void on_evidence_button_clicked(); void on_evidence_delete_clicked(); @@ -490,12 +648,21 @@ private slots: void on_char_select_left_clicked(); void on_char_select_right_clicked(); + void on_char_search_changed(const QString& newtext); + void on_char_taken_clicked(int newstate); + void on_char_passworded_clicked(int newstate); void on_spectator_clicked(); void char_clicked(int n_char); + void on_switch_area_music_clicked(); + + void on_casing_clicked(); + void ping_server(); + + void load_bass_opus_plugin(); }; #endif // COURTROOM_H diff --git a/datatypes.h b/datatypes.h index 37d3e99..aaa5de5 100644 --- a/datatypes.h +++ b/datatypes.h @@ -92,7 +92,15 @@ enum CHAT_MESSAGE EVIDENCE_ID, FLIP, REALIZATION, - TEXT_COLOR + TEXT_COLOR, + SHOWNAME, + OTHER_CHARID, + OTHER_NAME, + OTHER_EMOTE, + SELF_OFFSET, + OTHER_OFFSET, + OTHER_FLIP, + NONINTERRUPTING_PRE }; enum COLOR @@ -103,7 +111,9 @@ enum COLOR ORANGE, BLUE, YELLOW, - RAINBOW + RAINBOW, + PINK, + CYAN }; #endif // DATATYPES_H diff --git a/discord_rich_presence.cpp b/discord_rich_presence.cpp index 10f5833..41d3e73 100644 --- a/discord_rich_presence.cpp +++ b/discord_rich_presence.cpp @@ -29,8 +29,8 @@ void Discord::state_lobby() { DiscordRichPresence presence; std::memset(&presence, 0, sizeof(presence)); - presence.largeImageKey = "ao2-logo"; - presence.largeImageText = "Objection!"; + presence.largeImageKey = "aa_cc_icon_new"; + presence.largeImageText = "Omit!"; presence.instance = 1; presence.state = "In Lobby"; @@ -44,8 +44,8 @@ void Discord::state_server(std::string name, std::string server_id) DiscordRichPresence presence; std::memset(&presence, 0, sizeof(presence)); - presence.largeImageKey = "ao2-logo"; - presence.largeImageText = "Objection!"; + presence.largeImageKey = "aa_cc_icon_new"; + presence.largeImageText = "Omit!"; presence.instance = 1; auto timestamp = static_cast(std::time(nullptr)); @@ -70,8 +70,8 @@ void Discord::state_character(std::string name) DiscordRichPresence presence; std::memset(&presence, 0, sizeof(presence)); - presence.largeImageKey = "ao2-logo"; - presence.largeImageText = "Objection!"; + presence.largeImageKey = "aa_cc_icon_new"; + presence.largeImageText = "Omit!"; presence.instance = 1; presence.details = this->server_name.c_str(); presence.matchSecret = this->server_id.c_str(); @@ -89,8 +89,8 @@ void Discord::state_spectate() DiscordRichPresence presence; std::memset(&presence, 0, sizeof(presence)); - presence.largeImageKey = "ao2-logo"; - presence.largeImageText = "Objection!"; + presence.largeImageKey = "aa_cc_icon_new"; + presence.largeImageText = "Omit!"; presence.instance = 1; presence.details = this->server_name.c_str(); presence.matchSecret = this->server_id.c_str(); diff --git a/discord_rich_presence.h b/discord_rich_presence.h index 348d36f..e96fd88 100644 --- a/discord_rich_presence.h +++ b/discord_rich_presence.h @@ -7,12 +7,17 @@ #include #include +#include +#include + +#include + namespace AttorneyOnline { class Discord { private: - const char* APPLICATION_ID = "399779271737868288"; + const char* APPLICATION_ID = "474362730397302823"; std::string server_name, server_id; int64_t timestamp; public: diff --git a/emotes.cpp b/emotes.cpp index 27a1a4f..b6a217e 100644 --- a/emotes.cpp +++ b/emotes.cpp @@ -2,8 +2,6 @@ #include "aoemotebutton.h" -#include - void Courtroom::construct_emotes() { ui_emotes = new QWidget(this); diff --git a/encryption_functions.cpp b/encryption_functions.cpp index 56b6e34..ffbe0cd 100644 --- a/encryption_functions.cpp +++ b/encryption_functions.cpp @@ -2,12 +2,6 @@ #include "hex_functions.h" -#include -#include -#include -#include -#include - QString fanta_encrypt(QString temp_input, unsigned int p_key) { //using standard stdlib types is actually easier here because of implicit char<->int conversion diff --git a/encryption_functions.h b/encryption_functions.h index b6ea1d7..dc67d12 100644 --- a/encryption_functions.h +++ b/encryption_functions.h @@ -3,6 +3,12 @@ #include +#include +#include +#include +#include +#include + QString fanta_encrypt(QString p_input, unsigned int key); QString fanta_decrypt(QString p_input, unsigned int key); diff --git a/evidence.cpp b/evidence.cpp index 19ffecf..e5ef490 100644 --- a/evidence.cpp +++ b/evidence.cpp @@ -1,8 +1,5 @@ #include "courtroom.h" -#include -#include - void Courtroom::construct_evidence() { ui_evidence = new AOImage(this, ao_app); diff --git a/file_functions.cpp b/file_functions.cpp index bc9185f..bf2a018 100644 --- a/file_functions.cpp +++ b/file_functions.cpp @@ -1,6 +1,3 @@ -#include -#include - #include "file_functions.h" bool file_exists(QString file_path) diff --git a/file_functions.h b/file_functions.h index 81a90ed..77e1c20 100644 --- a/file_functions.h +++ b/file_functions.h @@ -1,6 +1,8 @@ #ifndef FILE_FUNCTIONS_H #define FILE_FUNCTIONS_H +#include +#include #include bool file_exists(QString file_path); diff --git a/hex_functions.cpp b/hex_functions.cpp index 3bb535b..4a58d2b 100644 --- a/hex_functions.cpp +++ b/hex_functions.cpp @@ -9,7 +9,7 @@ namespace omni std::stringstream stream; stream << std::setfill('0') << std::setw(sizeof(char)*2) - << std::hex << input; + << std::hex << input; std::string result(stream.str()); std::transform(result.begin(), result.end(), result.begin(), ::toupper); diff --git a/include/discord_register.h b/include/discord_register.h new file mode 100644 index 0000000..4c16b68 --- /dev/null +++ b/include/discord_register.h @@ -0,0 +1,26 @@ +#pragma once + +#if defined(DISCORD_DYNAMIC_LIB) +# if defined(_WIN32) +# if defined(DISCORD_BUILDING_SDK) +# define DISCORD_EXPORT __declspec(dllexport) +# else +# define DISCORD_EXPORT __declspec(dllimport) +# endif +# else +# define DISCORD_EXPORT __attribute__((visibility("default"))) +# endif +#else +# define DISCORD_EXPORT +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +DISCORD_EXPORT void Discord_Register(const char* applicationId, const char* command); +DISCORD_EXPORT void Discord_RegisterSteamGame(const char* applicationId, const char* steamId); + +#ifdef __cplusplus +} +#endif diff --git a/include/discord_rpc.h b/include/discord_rpc.h new file mode 100644 index 0000000..3e1441e --- /dev/null +++ b/include/discord_rpc.h @@ -0,0 +1,87 @@ +#pragma once +#include + +// clang-format off + +#if defined(DISCORD_DYNAMIC_LIB) +# if defined(_WIN32) +# if defined(DISCORD_BUILDING_SDK) +# define DISCORD_EXPORT __declspec(dllexport) +# else +# define DISCORD_EXPORT __declspec(dllimport) +# endif +# else +# define DISCORD_EXPORT __attribute__((visibility("default"))) +# endif +#else +# define DISCORD_EXPORT +#endif + +// clang-format on + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct DiscordRichPresence { + const char* state; /* max 128 bytes */ + const char* details; /* max 128 bytes */ + int64_t startTimestamp; + int64_t endTimestamp; + const char* largeImageKey; /* max 32 bytes */ + const char* largeImageText; /* max 128 bytes */ + const char* smallImageKey; /* max 32 bytes */ + const char* smallImageText; /* max 128 bytes */ + const char* partyId; /* max 128 bytes */ + int partySize; + int partyMax; + const char* matchSecret; /* max 128 bytes */ + const char* joinSecret; /* max 128 bytes */ + const char* spectateSecret; /* max 128 bytes */ + int8_t instance; +} DiscordRichPresence; + +typedef struct DiscordUser { + const char* userId; + const char* username; + const char* discriminator; + const char* avatar; +} DiscordUser; + +typedef struct DiscordEventHandlers { + void (*ready)(const DiscordUser* request); + void (*disconnected)(int errorCode, const char* message); + void (*errored)(int errorCode, const char* message); + void (*joinGame)(const char* joinSecret); + void (*spectateGame)(const char* spectateSecret); + void (*joinRequest)(const DiscordUser* request); +} DiscordEventHandlers; + +#define DISCORD_REPLY_NO 0 +#define DISCORD_REPLY_YES 1 +#define DISCORD_REPLY_IGNORE 2 + +DISCORD_EXPORT void Discord_Initialize(const char* applicationId, + DiscordEventHandlers* handlers, + int autoRegister, + const char* optionalSteamId); +DISCORD_EXPORT void Discord_Shutdown(void); + +/* checks for incoming messages, dispatches callbacks */ +DISCORD_EXPORT void Discord_RunCallbacks(void); + +/* If you disable the lib starting its own io thread, you'll need to call this from your own */ +#ifdef DISCORD_DISABLE_IO_THREAD +DISCORD_EXPORT void Discord_UpdateConnection(void); +#endif + +DISCORD_EXPORT void Discord_UpdatePresence(const DiscordRichPresence* presence); +DISCORD_EXPORT void Discord_ClearPresence(void); + +DISCORD_EXPORT void Discord_Respond(const char* userid, /* DISCORD_REPLY_ */ int reply); + +DISCORD_EXPORT void Discord_UpdateHandlers(DiscordEventHandlers* handlers); + +#ifdef __cplusplus +} /* extern "C" */ +#endif diff --git a/lobby.cpp b/lobby.cpp index c0dbf0c..8c7ca8b 100644 --- a/lobby.cpp +++ b/lobby.cpp @@ -5,14 +5,11 @@ #include "networkmanager.h" #include "aosfxplayer.h" -#include -#include - Lobby::Lobby(AOApplication *p_ao_app) : QMainWindow() { ao_app = p_ao_app; - this->setWindowTitle("Attorney Online 2"); + this->setWindowTitle("Attorney Online 2 -- Case Café Custom Client"); ui_background = new AOImage(this, ao_app); ui_public_servers = new AOButton(this, ao_app); @@ -52,6 +49,8 @@ Lobby::Lobby(AOApplication *p_ao_app) : QMainWindow() connect(ui_chatmessage, SIGNAL(returnPressed()), this, SLOT(on_chatfield_return_pressed())); connect(ui_cancel, SIGNAL(clicked()), ao_app, SLOT(loading_cancelled())); + ui_connect->setEnabled(false); + set_widgets(); } @@ -99,7 +98,7 @@ void Lobby::set_widgets() ui_connect->set_image("connect.png"); set_size_and_pos(ui_version, "version"); - ui_version->setText("Version: " + ao_app->get_version_string()); + ui_version->setText("AO Version: " + ao_app->get_version_string() + " | CCCC Version: " + ao_app->get_cccc_version_string()); set_size_and_pos(ui_about, "about"); ui_about->set_image("about.png"); @@ -315,6 +314,8 @@ void Lobby::on_server_list_clicked(QModelIndex p_model) ui_player_count->setText("Offline"); + ui_connect->setEnabled(false); + ao_app->net_manager->connect_to_server(f_server); } @@ -361,7 +362,7 @@ void Lobby::list_favorites() void Lobby::append_chatmessage(QString f_name, QString f_message) { - ui_chatbox->append_chatmessage(f_name, f_message); + ui_chatbox->append_chatmessage(f_name, f_message, ao_app->get_color("ooc_default_color", "courtroom_design.ini").name()); } void Lobby::append_error(QString f_message) @@ -375,6 +376,11 @@ void Lobby::set_player_count(int players_online, int max_players) ui_player_count->setText(f_string); } +void Lobby::enable_connect_button() +{ + ui_connect->setEnabled(true); +} + Lobby::~Lobby() { diff --git a/lobby.h b/lobby.h index 2d3aee5..19276a7 100644 --- a/lobby.h +++ b/lobby.h @@ -14,6 +14,9 @@ #include #include +#include +#include + class AOApplication; class Lobby : public QMainWindow @@ -34,6 +37,7 @@ public: void hide_loading_overlay(){ui_loading_background->hide();} QString get_chatlog(); int get_selected_server(); + void enable_connect_button(); void set_loading_value(int p_value); diff --git a/misc_functions.cpp b/misc_functions.cpp index e767b2e..2352055 100644 --- a/misc_functions.cpp +++ b/misc_functions.cpp @@ -1,8 +1,5 @@ #include "misc_functions.h" -#include -#include - void delay(int p_milliseconds) { QTime dieTime = QTime::currentTime().addMSecs(p_milliseconds); diff --git a/misc_functions.h b/misc_functions.h index 0de2d8a..026c635 100644 --- a/misc_functions.h +++ b/misc_functions.h @@ -1,6 +1,9 @@ #ifndef MISC_FUNCTIONS_H #define MISC_FUNCTIONS_H +#include +#include + void delay(int p_milliseconds); #endif // MISC_FUNCTIONS_H diff --git a/networkmanager.cpp b/networkmanager.cpp index e7246fe..288a900 100644 --- a/networkmanager.cpp +++ b/networkmanager.cpp @@ -4,8 +4,6 @@ #include "debug_functions.h" #include "lobby.h" -#include - NetworkManager::NetworkManager(AOApplication *parent) : QObject(parent) { ao_app = parent; @@ -21,10 +19,9 @@ NetworkManager::NetworkManager(AOApplication *parent) : QObject(parent) QObject::connect(server_socket, SIGNAL(readyRead()), this, SLOT(handle_server_packet())); QObject::connect(server_socket, SIGNAL(disconnected()), ao_app, SLOT(server_disconnected())); - QString master_config = ao_app->read_config("master"); - if (master_config != "") { + QString master_config = ao_app->configini->value("master", "").value(); + if (master_config != "") ms_nosrv_hostname = master_config; - } } NetworkManager::~NetworkManager() diff --git a/networkmanager.h b/networkmanager.h index 99987f3..e28abfd 100644 --- a/networkmanager.h +++ b/networkmanager.h @@ -21,6 +21,7 @@ #include #include #include +#include class NetworkManager : public QObject { diff --git a/packet_distribution.cpp b/packet_distribution.cpp index 83faccf..718de2b 100644 --- a/packet_distribution.cpp +++ b/packet_distribution.cpp @@ -7,9 +7,6 @@ #include "hardware_functions.h" #include "debug_functions.h" -#include -#include - void AOApplication::ms_packet_received(AOPacket *p_packet) { p_packet->net_decode(); @@ -150,6 +147,10 @@ void AOApplication::server_packet_received(AOPacket *p_packet) improved_loading_enabled = false; desk_mod_enabled = false; evidence_enabled = false; + cccc_ic_support_enabled = false; + arup_enabled = false; + casing_alerts_enabled = false; + modcall_reason_enabled = false; //workaround for tsuserver4 if (f_contents.at(0) == "NOENCRYPT") @@ -177,7 +178,12 @@ void AOApplication::server_packet_received(AOPacket *p_packet) goto end; if (courtroom_constructed) - w_courtroom->append_server_chatmessage(f_contents.at(0), f_contents.at(1)); + { + if (f_contents.size() == 3) + w_courtroom->append_server_chatmessage(f_contents.at(0), f_contents.at(1), f_contents.at(2)); + else + w_courtroom->append_server_chatmessage(f_contents.at(0), f_contents.at(1), "0"); + } } else if (header == "FL") { @@ -195,6 +201,16 @@ void AOApplication::server_packet_received(AOPacket *p_packet) desk_mod_enabled = true; if (f_packet.contains("evidence",Qt::CaseInsensitive)) evidence_enabled = true; + if (f_packet.contains("cccc_ic_support",Qt::CaseInsensitive)) + cccc_ic_support_enabled = true; + if (f_packet.contains("arup",Qt::CaseInsensitive)) + arup_enabled = true; + if (f_packet.contains("casing_alerts",Qt::CaseInsensitive)) + casing_alerts_enabled = true; + if (f_packet.contains("modcall_reason",Qt::CaseInsensitive)) + modcall_reason_enabled = true; + + w_lobby->enable_connect_button(); } else if (header == "PN") { @@ -218,13 +234,14 @@ void AOApplication::server_packet_received(AOPacket *p_packet) loaded_chars = 0; loaded_evidence = 0; loaded_music = 0; + generated_chars = 0; destruct_courtroom(); construct_courtroom(); courtroom_loaded = false; - QString window_title = "Attorney Online 2"; + QString window_title = "Attorney Online 2 -- Case Café Custom Client"; int selected_server = w_lobby->get_selected_server(); QString server_address = "", server_name = ""; @@ -264,7 +281,7 @@ void AOApplication::server_packet_received(AOPacket *p_packet) QCryptographicHash hash(QCryptographicHash::Algorithm::Sha256); hash.addData(server_address.toUtf8()); - if(is_discord_enabled()) + if (is_discord_enabled()) discord->state_server(server_name.toStdString(), hash.result().toBase64().toStdString()); } else if (header == "CI") @@ -300,7 +317,8 @@ void AOApplication::server_packet_received(AOPacket *p_packet) w_courtroom->append_char(f_char); - int loading_value = (loaded_chars / static_cast(total_loading_size)) * 100; + int total_loading_size = char_list_size * 2 + evidence_list_size + music_list_size; + int loading_value = int(((loaded_chars + generated_chars + loaded_music + loaded_evidence) / static_cast(total_loading_size)) * 100); w_lobby->set_loading_value(loading_value); } @@ -343,8 +361,8 @@ void AOApplication::server_packet_received(AOPacket *p_packet) w_courtroom->append_evidence(f_evi); - int total_loading_size = char_list_size + evidence_list_size + music_list_size; - int loading_value = ((loaded_chars + loaded_evidence) / static_cast(total_loading_size)) * 100; + int total_loading_size = char_list_size * 2 + evidence_list_size + music_list_size; + int loading_value = int(((loaded_chars + generated_chars + loaded_music + loaded_evidence) / static_cast(total_loading_size)) * 100); w_lobby->set_loading_value(loading_value); QString next_packet_number = QString::number(loaded_evidence); @@ -356,7 +374,8 @@ void AOApplication::server_packet_received(AOPacket *p_packet) if (!courtroom_constructed) goto end; - int total_loading_size = char_list_size + evidence_list_size + music_list_size; + bool musics_time = false; + int areas = 0; for (int n_element = 0 ; n_element < f_contents.size() ; n_element += 2) { @@ -372,12 +391,40 @@ void AOApplication::server_packet_received(AOPacket *p_packet) w_lobby->set_loading_text("Loading music:\n" + QString::number(loaded_music) + "/" + QString::number(music_list_size)); - w_courtroom->append_music(f_music); + if (musics_time) + { + w_courtroom->append_music(f_music); + } + else + { + if (f_music.endsWith(".wav") || + f_music.endsWith(".mp3") || + f_music.endsWith(".mp4") || + f_music.endsWith(".ogg") || + f_music.endsWith(".opus")) + { + musics_time = true; + areas--; + w_courtroom->fix_last_area(); + w_courtroom->append_music(f_music); + } + else + { + w_courtroom->append_area(f_music); + areas++; + } + } - int loading_value = ((loaded_chars + loaded_evidence + loaded_music) / static_cast(total_loading_size)) * 100; + for (int area_n = 0; area_n < areas; area_n++) + { + w_courtroom->arup_append(0, "Unknown", "Unknown", "Unknown"); + } + + int total_loading_size = char_list_size * 2 + evidence_list_size + music_list_size; + int loading_value = int(((loaded_chars + generated_chars + loaded_music + loaded_evidence) / static_cast(total_loading_size)) * 100); w_lobby->set_loading_value(loading_value); - } + QString next_packet_number = QString::number(((loaded_music - 1) / 10) + 1); send_server_packet(new AOPacket("AM#" + next_packet_number + "#%")); } @@ -420,7 +467,8 @@ void AOApplication::server_packet_received(AOPacket *p_packet) w_courtroom->append_char(f_char); - int loading_value = ((loaded_chars + loaded_evidence + loaded_music) / static_cast(total_loading_size)) * 100; + int total_loading_size = char_list_size * 2 + evidence_list_size + music_list_size; + int loading_value = int(((loaded_chars + generated_chars + loaded_music + loaded_evidence) / static_cast(total_loading_size)) * 100); w_lobby->set_loading_value(loading_value); } @@ -432,6 +480,8 @@ void AOApplication::server_packet_received(AOPacket *p_packet) goto end; int total_loading_size = char_list_size + evidence_list_size + music_list_size; + bool musics_time = false; + int areas = 0; for (int n_element = 0 ; n_element < f_contents.size() ; ++n_element) { @@ -441,7 +491,37 @@ void AOApplication::server_packet_received(AOPacket *p_packet) w_courtroom->append_music(f_contents.at(n_element)); - int loading_value = ((loaded_chars + loaded_evidence + loaded_music) / static_cast(total_loading_size)) * 100; + if (musics_time) + { + w_courtroom->append_music(f_contents.at(n_element)); + } + else + { + if (f_contents.at(n_element).endsWith(".wav") || + f_contents.at(n_element).endsWith(".mp3") || + f_contents.at(n_element).endsWith(".mp4") || + f_contents.at(n_element).endsWith(".ogg") || + f_contents.at(n_element).endsWith(".opus")) + { + musics_time = true; + w_courtroom->fix_last_area(); + w_courtroom->append_music(f_contents.at(n_element)); + areas--; + } + else + { + w_courtroom->append_area(f_contents.at(n_element)); + areas++; + } + } + + for (int area_n = 0; area_n < areas; area_n++) + { + w_courtroom->arup_append(0, "Unknown", "Unknown", "Unknown"); + } + + int total_loading_size = char_list_size * 2 + evidence_list_size + music_list_size; + int loading_value = int(((loaded_chars + generated_chars + loaded_music + loaded_evidence) / static_cast(total_loading_size)) * 100); w_lobby->set_loading_value(loading_value); } @@ -455,6 +535,7 @@ void AOApplication::server_packet_received(AOPacket *p_packet) if (lobby_constructed) w_courtroom->append_ms_chatmessage("", w_lobby->get_chatlog()); + w_courtroom->character_loading_finished(); w_courtroom->done_received(); courtroom_loaded = true; @@ -493,7 +574,13 @@ void AOApplication::server_packet_received(AOPacket *p_packet) if (f_contents.size() < 1) goto end; if (courtroom_constructed) - w_courtroom->handle_wtce(f_contents.at(0)); + { + if (f_contents.size() == 1) + w_courtroom->handle_wtce(f_contents.at(0), 0); + else if (f_contents.size() == 2) { + w_courtroom->handle_wtce(f_contents.at(0), f_contents.at(1).toInt()); + } + } } else if (header == "HP") { @@ -524,6 +611,17 @@ void AOApplication::server_packet_received(AOPacket *p_packet) w_courtroom->set_evidence_list(f_evi_list); } } + else if (header == "ARUP") + { + if (courtroom_constructed) + { + int arup_type = f_contents.at(0).toInt(); + for (int n_element = 1 ; n_element < f_contents.size() ; n_element++) + { + w_courtroom->arup_modify(arup_type, n_element - 1, f_contents.at(n_element)); + } + } + } else if (header == "IL") { if (courtroom_constructed && f_contents.size() > 0) @@ -569,6 +667,11 @@ void AOApplication::server_packet_received(AOPacket *p_packet) if (courtroom_constructed && f_contents.size() > 0) w_courtroom->mod_called(f_contents.at(0)); } + else if (header == "CASEA") + { + if (courtroom_constructed && f_contents.size() > 6) + w_courtroom->case_called(f_contents.at(0), f_contents.at(1) == "1", f_contents.at(2) == "1", f_contents.at(3) == "1", f_contents.at(4) == "1", f_contents.at(5) == "1"); + } end: diff --git a/path_functions.cpp b/path_functions.cpp index 820c05a..d4238c9 100644 --- a/path_functions.cpp +++ b/path_functions.cpp @@ -1,9 +1,6 @@ #include "aoapplication.h" #include "courtroom.h" #include "file_functions.h" -#include -#include -#include #ifdef BASE_OVERRIDE #include "base_override.h" diff --git a/server/__init__.py b/server/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/server/aoprotocol.py b/server/aoprotocol.py new file mode 100644 index 0000000..2cf6fb4 --- /dev/null +++ b/server/aoprotocol.py @@ -0,0 +1,807 @@ +# tsuserver3, an Attorney Online server +# +# Copyright (C) 2016 argoneus +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +import asyncio +import re +from time import localtime, strftime +from enum import Enum + +from . import commands +from . import logger +from .exceptions import ClientError, AreaError, ArgumentError, ServerError +from .fantacrypt import fanta_decrypt +from .evidence import EvidenceList +from .websocket import WebSocket +import unicodedata + + +class AOProtocol(asyncio.Protocol): + """ + The main class that deals with the AO protocol. + """ + + class ArgType(Enum): + STR = 1, + STR_OR_EMPTY = 2, + INT = 3 + + def __init__(self, server): + super().__init__() + self.server = server + self.client = None + self.buffer = '' + self.ping_timeout = None + self.websocket = None + + def data_received(self, data): + """ Handles any data received from the network. + + Receives data, parses them into a command and passes it + to the command handler. + + :param data: bytes of data + """ + + + if self.websocket is None: + self.websocket = WebSocket(self.client, self) + if not self.websocket.handshake(data): + self.websocket = False + else: + self.client.websocket = self.websocket + + buf = data + + if not self.client.is_checked and self.server.ban_manager.is_banned(self.client.ipid): + self.client.transport.close() + else: + self.client.is_checked = True + + if self.websocket: + buf = self.websocket.handle(data) + + if buf is None: + buf = b'' + + if not isinstance(buf, str): + # try to decode as utf-8, ignore any erroneous characters + self.buffer += buf.decode('utf-8', 'ignore') + else: + self.buffer = buf + + if len(self.buffer) > 8192: + self.client.disconnect() + for msg in self.get_messages(): + if len(msg) < 2: + continue + # general netcode structure is not great + if msg[0] in ('#', '3', '4'): + if msg[0] == '#': + msg = msg[1:] + spl = msg.split('#', 1) + msg = '#'.join([fanta_decrypt(spl[0])] + spl[1:]) + logger.log_debug('[INC][RAW]{}'.format(msg), self.client) + try: + cmd, *args = msg.split('#') + self.net_cmd_dispatcher[cmd](self, args) + except KeyError: + logger.log_debug('[INC][UNK]{}'.format(msg), self.client) + + def connection_made(self, transport): + """ Called upon a new client connecting + + :param transport: the transport object + """ + self.client = self.server.new_client(transport) + self.ping_timeout = asyncio.get_event_loop().call_later(self.server.config['timeout'], self.client.disconnect) + asyncio.get_event_loop().call_later(0.25, self.client.send_command, 'decryptor', 34) # just fantacrypt things) + + def connection_lost(self, exc): + """ User disconnected + + :param exc: reason + """ + self.server.remove_client(self.client) + self.ping_timeout.cancel() + + def get_messages(self): + """ Parses out full messages from the buffer. + + :return: yields messages + """ + while '#%' in self.buffer: + spl = self.buffer.split('#%', 1) + self.buffer = spl[1] + yield spl[0] + # exception because bad netcode + askchar2 = '#615810BC07D12A5A#' + if self.buffer == askchar2: + self.buffer = '' + yield askchar2 + + def validate_net_cmd(self, args, *types, needs_auth=True): + """ Makes sure the net command's arguments match expectations. + + :param args: actual arguments to the net command + :param types: what kind of data types are expected + :param needs_auth: whether you need to have chosen a character + :return: returns True if message was validated + """ + if needs_auth and self.client.char_id == -1: + return False + if len(args) != len(types): + return False + for i, arg in enumerate(args): + if len(arg) == 0 and types[i] != self.ArgType.STR_OR_EMPTY: + return False + if types[i] == self.ArgType.INT: + try: + args[i] = int(arg) + except ValueError: + return False + return True + + def net_cmd_hi(self, args): + """ Handshake. + + HI##% + + :param args: a list containing all the arguments + """ + if not self.validate_net_cmd(args, self.ArgType.STR, needs_auth=False): + return + self.client.hdid = args[0] + if self.client.hdid not in self.client.server.hdid_list: + self.client.server.hdid_list[self.client.hdid] = [] + if self.client.ipid not in self.client.server.hdid_list[self.client.hdid]: + self.client.server.hdid_list[self.client.hdid].append(self.client.ipid) + self.client.server.dump_hdids() + for ipid in self.client.server.hdid_list[self.client.hdid]: + if self.server.ban_manager.is_banned(ipid): + self.client.send_command('BD') + self.client.disconnect() + return + logger.log_server('Connected. HDID: {}.'.format(self.client.hdid), self.client) + self.client.send_command('ID', self.client.id, self.server.software, self.server.get_version_string()) + self.client.send_command('PN', self.server.get_player_count() - 1, self.server.config['playerlimit']) + + def net_cmd_id(self, args): + """ Client version and PV + + ID####% + + """ + + self.client.is_ao2 = False + + if len(args) < 2: + return + + version_list = args[1].split('.') + + if len(version_list) < 3: + return + + release = int(version_list[0]) + major = int(version_list[1]) + minor = int(version_list[2]) + + if args[0] != 'AO2': + return + if release < 2: + return + elif release == 2: + if major < 2: + return + elif major == 2: + if minor < 5: + return + + self.client.is_ao2 = True + + self.client.send_command('FL', 'yellowtext', 'customobjections', 'flipping', 'fastloading', 'noencryption', 'deskmod', 'evidence', 'modcall_reason', 'cccc_ic_support', 'arup', 'casing_alerts') + + def net_cmd_ch(self, _): + """ Periodically checks the connection. + + CHECK#% + + """ + self.client.send_command('CHECK') + self.ping_timeout.cancel() + self.ping_timeout = asyncio.get_event_loop().call_later(self.server.config['timeout'], self.client.disconnect) + + def net_cmd_askchaa(self, _): + """ Ask for the counts of characters/evidence/music + + askchaa#% + + """ + char_cnt = len(self.server.char_list) + evi_cnt = 0 + music_cnt = sum([len(x) for x in self.server.music_pages_ao1]) + self.client.send_command('SI', char_cnt, evi_cnt, music_cnt) + + def net_cmd_askchar2(self, _): + """ Asks for the character list. + + askchar2#% + + """ + self.client.send_command('CI', *self.server.char_pages_ao1[0]) + + def net_cmd_an(self, args): + """ Asks for specific pages of the character list. + + AN##% + + """ + if not self.validate_net_cmd(args, self.ArgType.INT, needs_auth=False): + return + if len(self.server.char_pages_ao1) > args[0] >= 0: + self.client.send_command('CI', *self.server.char_pages_ao1[args[0]]) + else: + self.client.send_command('EM', *self.server.music_pages_ao1[0]) + + def net_cmd_ae(self, _): + """ Asks for specific pages of the evidence list. + + AE##% + + """ + pass # todo evidence maybe later + + def net_cmd_am(self, args): + """ Asks for specific pages of the music list. + + AM##% + + """ + if not self.validate_net_cmd(args, self.ArgType.INT, needs_auth=False): + return + if len(self.server.music_pages_ao1) > args[0] >= 0: + self.client.send_command('EM', *self.server.music_pages_ao1[args[0]]) + else: + self.client.send_done() + self.client.send_area_list() + self.client.send_motd() + + def net_cmd_rc(self, _): + """ Asks for the whole character list(AO2) + + AC#% + + """ + + self.client.send_command('SC', *self.server.char_list) + + def net_cmd_rm(self, _): + """ Asks for the whole music list(AO2) + + AM#% + + """ + + self.client.send_command('SM', *self.server.music_list_ao2) + + + def net_cmd_rd(self, _): + """ Asks for server metadata(charscheck, motd etc.) and a DONE#% signal(also best packet) + + RD#% + + """ + + self.client.send_done() + self.client.send_area_list() + self.client.send_motd() + + def net_cmd_cc(self, args): + """ Character selection. + + CC####% + + """ + if not self.validate_net_cmd(args, self.ArgType.INT, self.ArgType.INT, self.ArgType.STR, needs_auth=False): + return + cid = args[1] + try: + self.client.change_character(cid) + except ClientError: + return + + def net_cmd_ms(self, args): + """ IC message. + + Refer to the implementation for details. + + """ + if self.client.is_muted: # Checks to see if the client has been muted by a mod + self.client.send_host_message("You have been muted by a moderator") + return + if not self.client.area.can_send_message(self.client): + return + + target_area = [] + + if self.validate_net_cmd(args, self.ArgType.STR, self.ArgType.STR_OR_EMPTY, self.ArgType.STR, + self.ArgType.STR, + self.ArgType.STR, self.ArgType.STR, self.ArgType.STR, self.ArgType.INT, + self.ArgType.INT, self.ArgType.INT, self.ArgType.INT, self.ArgType.INT, + self.ArgType.INT, self.ArgType.INT, self.ArgType.INT): + # Vanilla validation monstrosity. + msg_type, pre, folder, anim, text, pos, sfx, anim_type, cid, sfx_delay, button, evidence, flip, ding, color = args + showname = "" + charid_pair = -1 + offset_pair = 0 + nonint_pre = 0 + elif self.validate_net_cmd(args, self.ArgType.STR, self.ArgType.STR_OR_EMPTY, self.ArgType.STR, + self.ArgType.STR, + self.ArgType.STR, self.ArgType.STR, self.ArgType.STR, self.ArgType.INT, + self.ArgType.INT, self.ArgType.INT, self.ArgType.INT, self.ArgType.INT, + self.ArgType.INT, self.ArgType.INT, self.ArgType.INT, self.ArgType.STR_OR_EMPTY): + # 1.3.0 validation monstrosity. + msg_type, pre, folder, anim, text, pos, sfx, anim_type, cid, sfx_delay, button, evidence, flip, ding, color, showname = args + charid_pair = -1 + offset_pair = 0 + nonint_pre = 0 + if len(showname) > 0 and not self.client.area.showname_changes_allowed: + self.client.send_host_message("Showname changes are forbidden in this area!") + return + elif self.validate_net_cmd(args, self.ArgType.STR, self.ArgType.STR_OR_EMPTY, self.ArgType.STR, + self.ArgType.STR, + self.ArgType.STR, self.ArgType.STR, self.ArgType.STR, self.ArgType.INT, + self.ArgType.INT, self.ArgType.INT, self.ArgType.INT, self.ArgType.INT, + self.ArgType.INT, self.ArgType.INT, self.ArgType.INT, self.ArgType.STR_OR_EMPTY, self.ArgType.INT, self.ArgType.INT): + # 1.3.5 validation monstrosity. + msg_type, pre, folder, anim, text, pos, sfx, anim_type, cid, sfx_delay, button, evidence, flip, ding, color, showname, charid_pair, offset_pair = args + nonint_pre = 0 + if len(showname) > 0 and not self.client.area.showname_changes_allowed: + self.client.send_host_message("Showname changes are forbidden in this area!") + return + elif self.validate_net_cmd(args, self.ArgType.STR, self.ArgType.STR_OR_EMPTY, self.ArgType.STR, + self.ArgType.STR, + self.ArgType.STR, self.ArgType.STR, self.ArgType.STR, self.ArgType.INT, + self.ArgType.INT, self.ArgType.INT, self.ArgType.INT, self.ArgType.INT, + self.ArgType.INT, self.ArgType.INT, self.ArgType.INT, self.ArgType.STR_OR_EMPTY, self.ArgType.INT, self.ArgType.INT, self.ArgType.INT): + # 1.4.0 validation monstrosity. + msg_type, pre, folder, anim, text, pos, sfx, anim_type, cid, sfx_delay, button, evidence, flip, ding, color, showname, charid_pair, offset_pair, nonint_pre = args + if len(showname) > 0 and not self.client.area.showname_changes_allowed: + self.client.send_host_message("Showname changes are forbidden in this area!") + return + else: + return + if self.client.area.is_iniswap(self.client, pre, anim, folder) and folder != self.client.get_char_name(): + self.client.send_host_message("Iniswap is blocked in this area") + return + if len(self.client.charcurse) > 0 and folder != self.client.get_char_name(): + self.client.send_host_message("You may not iniswap while you are charcursed!") + return + if not self.client.area.blankposting_allowed: + if text == ' ': + self.client.send_host_message("Blankposting is forbidden in this area!") + return + if text.isspace(): + self.client.send_host_message("Blankposting is forbidden in this area, and putting more spaces in does not make it not blankposting.") + return + if len(re.sub(r'[{}\\`|(~~)]','', text).replace(' ', '')) < 3 and text != '<' and text != '>': + self.client.send_host_message("While that is not a blankpost, it is still pretty spammy. Try forming sentences.") + return + if text.startswith('/a '): + part = text.split(' ') + try: + aid = int(part[1]) + if self.client in self.server.area_manager.get_area_by_id(aid).owners: + target_area.append(aid) + if not target_area: + self.client.send_host_message('You don\'t own {}!'.format(self.server.area_manager.get_area_by_id(aid).name)) + return + text = ' '.join(part[2:]) + except ValueError: + self.client.send_host_message("That does not look like a valid area ID!") + return + elif text.startswith('/s '): + part = text.split(' ') + for a in self.server.area_manager.areas: + if self.client in a.owners: + target_area.append(a.id) + if not target_area: + self.client.send_host_message('You don\'t any areas!') + return + text = ' '.join(part[1:]) + if msg_type not in ('chat', '0', '1'): + return + if anim_type not in (0, 1, 2, 5, 6): + return + if cid != self.client.char_id: + return + if sfx_delay < 0: + return + if button not in (0, 1, 2, 3, 4): + return + if evidence < 0: + return + if ding not in (0, 1): + return + if color not in (0, 1, 2, 3, 4, 5, 6, 7, 8): + return + if len(showname) > 15: + self.client.send_host_message("Your IC showname is way too long!") + return + if nonint_pre == 1: + if button in (1, 2, 3, 4, 23): + if anim_type == 1 or anim_type == 2: + anim_type = 0 + elif anim_type == 6: + anim_type = 5 + if self.client.area.non_int_pres_only: + if anim_type == 1 or anim_type == 2: + anim_type = 0 + nonint_pre = 1 + elif anim_type == 6: + anim_type = 5 + nonint_pre = 1 + if not self.client.area.shouts_allowed: + # Old clients communicate the objecting in anim_type. + if anim_type == 2: + anim_type = 1 + elif anim_type == 6: + anim_type = 5 + # New clients do it in a specific objection message area. + button = 0 + # Turn off the ding. + ding = 0 + if color == 2 and not (self.client.is_mod or self.client in self.client.area.owners): + color = 0 + if color == 6: + text = re.sub(r'[^\x00-\x7F]+',' ', text) #remove all unicode to prevent redtext abuse + if len(text.strip( ' ' )) == 1: + color = 0 + else: + if text.strip( ' ' ) in ('', '', '', ''): + color = 0 + if self.client.pos: + pos = self.client.pos + else: + if pos not in ('def', 'pro', 'hld', 'hlp', 'jud', 'wit', 'jur', 'sea'): + return + msg = text[:256] + if self.client.shaken: + msg = self.client.shake_message(msg) + if self.client.disemvowel: + msg = self.client.disemvowel_message(msg) + self.client.pos = pos + if evidence: + if self.client.area.evi_list.evidences[self.client.evi_list[evidence] - 1].pos != 'all': + self.client.area.evi_list.evidences[self.client.evi_list[evidence] - 1].pos = 'all' + self.client.area.broadcast_evidence_list() + + # Here, we check the pair stuff, and save info about it to the client. + # Notably, while we only get a charid_pair and an offset, we send back a chair_pair, an emote, a talker offset + # and an other offset. + self.client.charid_pair = charid_pair + self.client.offset_pair = offset_pair + if anim_type not in (5, 6): + self.client.last_sprite = anim + self.client.flip = flip + self.client.claimed_folder = folder + other_offset = 0 + other_emote = '' + other_flip = 0 + other_folder = '' + + confirmed = False + if charid_pair > -1: + for target in self.client.area.clients: + if target.char_id == self.client.charid_pair and target.charid_pair == self.client.char_id and target != self.client and target.pos == self.client.pos: + confirmed = True + other_offset = target.offset_pair + other_emote = target.last_sprite + other_flip = target.flip + other_folder = target.claimed_folder + break + + if not confirmed: + charid_pair = -1 + offset_pair = 0 + + self.client.area.send_command('MS', msg_type, pre, folder, anim, msg, pos, sfx, anim_type, cid, + sfx_delay, button, self.client.evi_list[evidence], flip, ding, color, showname, + charid_pair, other_folder, other_emote, offset_pair, other_offset, other_flip, nonint_pre) + + self.client.area.send_owner_command('MS', msg_type, pre, folder, anim, '[' + self.client.area.abbreviation + ']' + msg, pos, sfx, anim_type, cid, + sfx_delay, button, self.client.evi_list[evidence], flip, ding, color, showname, + charid_pair, other_folder, other_emote, offset_pair, other_offset, other_flip, nonint_pre) + + self.server.area_manager.send_remote_command(target_area, 'MS', msg_type, pre, folder, anim, msg, pos, sfx, anim_type, cid, + sfx_delay, button, self.client.evi_list[evidence], flip, ding, color, showname, + charid_pair, other_folder, other_emote, offset_pair, other_offset, other_flip, nonint_pre) + + self.client.area.set_next_msg_delay(len(msg)) + logger.log_server('[IC][{}][{}]{}'.format(self.client.area.abbreviation, self.client.get_char_name(), msg), self.client) + + if (self.client.area.is_recording): + self.client.area.recorded_messages.append(args) + + def net_cmd_ct(self, args): + """ OOC Message + + CT###% + + """ + if self.client.is_ooc_muted: # Checks to see if the client has been muted by a mod + self.client.send_host_message("You have been muted by a moderator") + return + if not self.validate_net_cmd(args, self.ArgType.STR, self.ArgType.STR): + return + if self.client.name != args[0] and self.client.fake_name != args[0]: + if self.client.is_valid_name(args[0]): + self.client.name = args[0] + self.client.fake_name = args[0] + else: + self.client.fake_name = args[0] + if self.client.name == '': + self.client.send_host_message('You must insert a name with at least one letter') + return + if len(self.client.name) > 30: + self.client.send_host_message('Your OOC name is too long! Limit it to 30 characters.') + return + for c in self.client.name: + if unicodedata.category(c) == 'Cf': + self.client.send_host_message('You cannot use format characters in your name!') + return + if self.client.name.startswith(self.server.config['hostname']) or self.client.name.startswith('G') or self.client.name.startswith('M'): + self.client.send_host_message('That name is reserved!') + return + if args[1].startswith(' /'): + self.client.send_host_message('Your message was not sent for safety reasons: you left a space before that slash.') + return + if args[1].startswith('/'): + spl = args[1][1:].split(' ', 1) + cmd = spl[0].lower() + arg = '' + if len(spl) == 2: + arg = spl[1][:256] + try: + called_function = 'ooc_cmd_{}'.format(cmd) + getattr(commands, called_function)(self.client, arg) + except AttributeError: + print('Attribute error with ' + called_function) + self.client.send_host_message('Invalid command.') + except (ClientError, AreaError, ArgumentError, ServerError) as ex: + self.client.send_host_message(ex) + else: + if self.client.shaken: + args[1] = self.client.shake_message(args[1]) + if self.client.disemvowel: + args[1] = self.client.disemvowel_message(args[1]) + self.client.area.send_command('CT', self.client.name, args[1]) + self.client.area.send_owner_command('CT', '[' + self.client.area.abbreviation + ']' + self.client.name, args[1]) + logger.log_server( + '[OOC][{}][{}]{}'.format(self.client.area.abbreviation, self.client.get_char_name(), + args[1]), self.client) + + def net_cmd_mc(self, args): + """ Play music. + + MC###% + + """ + try: + area = self.server.area_manager.get_area_by_name(args[0]) + self.client.change_area(area) + except AreaError: + if self.client.is_muted: # Checks to see if the client has been muted by a mod + self.client.send_host_message("You have been muted by a moderator") + return + if not self.client.is_dj: + self.client.send_host_message('You were blockdj\'d by a moderator.') + return + if self.client.area.cannot_ic_interact(self.client): + self.client.send_host_message("You are not on the area's invite list, and thus, you cannot change music!") + return + if not self.validate_net_cmd(args, self.ArgType.STR, self.ArgType.INT) and not self.validate_net_cmd(args, self.ArgType.STR, self.ArgType.INT, self.ArgType.STR): + return + if args[1] != self.client.char_id: + return + if self.client.change_music_cd(): + self.client.send_host_message('You changed song too many times. Please try again after {} seconds.'.format(int(self.client.change_music_cd()))) + return + try: + name, length = self.server.get_song_data(args[0]) + + if self.client.area.jukebox: + showname = '' + if len(args) > 2: + showname = args[2] + if len(showname) > 0 and not self.client.area.showname_changes_allowed: + self.client.send_host_message("Showname changes are forbidden in this area!") + return + self.client.area.add_jukebox_vote(self.client, name, length, showname) + logger.log_server('[{}][{}]Added a jukebox vote for {}.'.format(self.client.area.abbreviation, self.client.get_char_name(), name), self.client) + else: + if len(args) > 2: + showname = args[2] + if len(showname) > 0 and not self.client.area.showname_changes_allowed: + self.client.send_host_message("Showname changes are forbidden in this area!") + return + self.client.area.play_music_shownamed(name, self.client.char_id, showname, length) + self.client.area.add_music_playing_shownamed(self.client, showname, name) + else: + self.client.area.play_music(name, self.client.char_id, length) + self.client.area.add_music_playing(self.client, name) + logger.log_server('[{}][{}]Changed music to {}.' + .format(self.client.area.abbreviation, self.client.get_char_name(), name), self.client) + except ServerError: + return + except ClientError as ex: + self.client.send_host_message(ex) + + def net_cmd_rt(self, args): + """ Plays the Testimony/CE animation. + + RT##% + + """ + if not self.client.area.shouts_allowed: + self.client.send_host_message("You cannot use the testimony buttons here!") + return + if self.client.is_muted: # Checks to see if the client has been muted by a mod + self.client.send_host_message("You have been muted by a moderator") + return + if not self.client.can_wtce: + self.client.send_host_message('You were blocked from using judge signs by a moderator.') + return + if self.client.area.cannot_ic_interact(self.client): + self.client.send_host_message("You are not on the area's invite list, and thus, you cannot use the WTCE buttons!") + return + if not self.validate_net_cmd(args, self.ArgType.STR) and not self.validate_net_cmd(args, self.ArgType.STR, self.ArgType.INT): + return + if args[0] == 'testimony1': + sign = 'WT' + elif args[0] == 'testimony2': + sign = 'CE' + elif args[0] == 'judgeruling': + sign = 'JR' + else: + return + if self.client.wtce_mute(): + self.client.send_host_message('You used witness testimony/cross examination signs too many times. Please try again after {} seconds.'.format(int(self.client.wtce_mute()))) + return + if len(args) == 1: + self.client.area.send_command('RT', args[0]) + elif len(args) == 2: + self.client.area.send_command('RT', args[0], args[1]) + self.client.area.add_to_judgelog(self.client, 'used {}'.format(sign)) + logger.log_server("[{}]{} Used WT/CE".format(self.client.area.abbreviation, self.client.get_char_name()), self.client) + + def net_cmd_hp(self, args): + """ Sets the penalty bar. + + HP###% + + """ + if self.client.is_muted: # Checks to see if the client has been muted by a mod + self.client.send_host_message("You have been muted by a moderator") + return + if self.client.area.cannot_ic_interact(self.client): + self.client.send_host_message("You are not on the area's invite list, and thus, you cannot change the Confidence bars!") + return + if not self.validate_net_cmd(args, self.ArgType.INT, self.ArgType.INT): + return + try: + self.client.area.change_hp(args[0], args[1]) + self.client.area.add_to_judgelog(self.client, 'changed the penalties') + logger.log_server('[{}]{} changed HP ({}) to {}' + .format(self.client.area.abbreviation, self.client.get_char_name(), args[0], args[1]), self.client) + except AreaError: + return + + def net_cmd_pe(self, args): + """ Adds a piece of evidence. + + PE####% + + """ + if len(args) < 3: + return + #evi = Evidence(args[0], args[1], args[2], self.client.pos) + self.client.area.evi_list.add_evidence(self.client, args[0], args[1], args[2], 'all') + self.client.area.broadcast_evidence_list() + + def net_cmd_de(self, args): + """ Deletes a piece of evidence. + + DE##% + + """ + + self.client.area.evi_list.del_evidence(self.client, self.client.evi_list[int(args[0])]) + self.client.area.broadcast_evidence_list() + + def net_cmd_ee(self, args): + """ Edits a piece of evidence. + + EE#####% + + """ + + if len(args) < 4: + return + + evi = (args[1], args[2], args[3], 'all') + + self.client.area.evi_list.edit_evidence(self.client, self.client.evi_list[int(args[0])], evi) + self.client.area.broadcast_evidence_list() + + + def net_cmd_zz(self, args): + """ Sent on mod call. + + """ + if self.client.is_muted: # Checks to see if the client has been muted by a mod + self.client.send_host_message("You have been muted by a moderator") + return + + if not self.client.can_call_mod(): + self.client.send_host_message("You must wait 30 seconds between mod calls.") + return + + current_time = strftime("%H:%M", localtime()) + + if len(args) < 1: + self.server.send_all_cmd_pred('ZZ', '[{}] {} ({}) in {} without reason (not using the Case Café client?)' + .format(current_time, self.client.get_char_name(), self.client.get_ip(), self.client.area.name), pred=lambda c: c.is_mod) + self.client.set_mod_call_delay() + logger.log_server('[{}]{} called a moderator.'.format(self.client.area.abbreviation, self.client.get_char_name()), self.client) + else: + self.server.send_all_cmd_pred('ZZ', '[{}] {} ({}) in {} with reason: {}' + .format(current_time, self.client.get_char_name(), self.client.get_ip(), self.client.area.name, args[0][:100]), pred=lambda c: c.is_mod) + self.client.set_mod_call_delay() + logger.log_server('[{}]{} called a moderator: {}.'.format(self.client.area.abbreviation, self.client.get_char_name(), args[0]), self.client) + + def net_cmd_opKICK(self, args): + self.net_cmd_ct(['opkick', '/kick {}'.format(args[0])]) + + def net_cmd_opBAN(self, args): + self.net_cmd_ct(['opban', '/ban {}'.format(args[0])]) + + net_cmd_dispatcher = { + 'HI': net_cmd_hi, # handshake + 'ID': net_cmd_id, # client version + 'CH': net_cmd_ch, # keepalive + 'askchaa': net_cmd_askchaa, # ask for list lengths + 'askchar2': net_cmd_askchar2, # ask for list of characters + 'AN': net_cmd_an, # character list + 'AE': net_cmd_ae, # evidence list + 'AM': net_cmd_am, # music list + 'RC': net_cmd_rc, # AO2 character list + 'RM': net_cmd_rm, # AO2 music list + 'RD': net_cmd_rd, # AO2 done request, charscheck etc. + 'CC': net_cmd_cc, # select character + 'MS': net_cmd_ms, # IC message + 'CT': net_cmd_ct, # OOC message + 'MC': net_cmd_mc, # play song + 'RT': net_cmd_rt, # WT/CE buttons + 'HP': net_cmd_hp, # penalties + 'PE': net_cmd_pe, # add evidence + 'DE': net_cmd_de, # delete evidence + 'EE': net_cmd_ee, # edit evidence + 'ZZ': net_cmd_zz, # call mod button + 'opKICK': net_cmd_opKICK, # /kick with guard on + 'opBAN': net_cmd_opBAN, # /ban with guard on + } diff --git a/server/area_manager.py b/server/area_manager.py new file mode 100644 index 0000000..cfb2be0 --- /dev/null +++ b/server/area_manager.py @@ -0,0 +1,412 @@ +# tsuserver3, an Attorney Online server +# +# Copyright (C) 2016 argoneus +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +import asyncio +import random + +import time +import yaml + +from server.exceptions import AreaError +from server.evidence import EvidenceList +from enum import Enum + + +class AreaManager: + class Area: + def __init__(self, area_id, server, name, background, bg_lock, evidence_mod = 'FFA', locking_allowed = False, iniswap_allowed = True, showname_changes_allowed = False, shouts_allowed = True, jukebox = False, abbreviation = '', non_int_pres_only = False): + self.iniswap_allowed = iniswap_allowed + self.clients = set() + self.invite_list = {} + self.id = area_id + self.name = name + self.background = background + self.bg_lock = bg_lock + self.server = server + self.music_looper = None + self.next_message_time = 0 + self.hp_def = 10 + self.hp_pro = 10 + self.doc = 'No document.' + self.status = 'IDLE' + self.judgelog = [] + self.current_music = '' + self.current_music_player = '' + self.current_music_player_ipid = -1 + self.evi_list = EvidenceList() + self.is_recording = False + self.recorded_messages = [] + self.evidence_mod = evidence_mod + self.locking_allowed = locking_allowed + self.showname_changes_allowed = showname_changes_allowed + self.shouts_allowed = shouts_allowed + self.abbreviation = abbreviation + self.cards = dict() + + """ + #debug + self.evidence_list.append(Evidence("WOW", "desc", "1.png")) + self.evidence_list.append(Evidence("wewz", "desc2", "2.png")) + self.evidence_list.append(Evidence("weeeeeew", "desc3", "3.png")) + """ + + self.is_locked = self.Locked.FREE + self.blankposting_allowed = True + self.non_int_pres_only = non_int_pres_only + self.jukebox = jukebox + self.jukebox_votes = [] + self.jukebox_prev_char_id = -1 + + self.owners = [] + + class Locked(Enum): + FREE = 1, + SPECTATABLE = 2, + LOCKED = 3 + + def new_client(self, client): + self.clients.add(client) + self.server.area_manager.send_arup_players() + + def remove_client(self, client): + self.clients.remove(client) + if len(self.clients) == 0: + self.change_status('IDLE') + + def unlock(self): + self.is_locked = self.Locked.FREE + self.blankposting_allowed = True + self.invite_list = {} + self.server.area_manager.send_arup_lock() + self.send_host_message('This area is open now.') + + def spectator(self): + self.is_locked = self.Locked.SPECTATABLE + for i in self.clients: + self.invite_list[i.id] = None + for i in self.owners: + self.invite_list[i.id] = None + self.server.area_manager.send_arup_lock() + self.send_host_message('This area is spectatable now.') + + def lock(self): + self.is_locked = self.Locked.LOCKED + for i in self.clients: + self.invite_list[i.id] = None + for i in self.owners: + self.invite_list[i.id] = None + self.server.area_manager.send_arup_lock() + self.send_host_message('This area is locked now.') + + def is_char_available(self, char_id): + return char_id not in [x.char_id for x in self.clients] + + def get_rand_avail_char_id(self): + avail_set = set(range(len(self.server.char_list))) - set([x.char_id for x in self.clients]) + if len(avail_set) == 0: + raise AreaError('No available characters.') + return random.choice(tuple(avail_set)) + + def send_command(self, cmd, *args): + for c in self.clients: + c.send_command(cmd, *args) + + def send_owner_command(self, cmd, *args): + for c in self.owners: + if not c in self.clients: + c.send_command(cmd, *args) + + def send_host_message(self, msg): + self.send_command('CT', self.server.config['hostname'], msg, '1') + self.send_owner_command('CT', '[' + self.abbreviation + ']' + self.server.config['hostname'], msg, '1') + + def set_next_msg_delay(self, msg_length): + delay = min(3000, 100 + 60 * msg_length) + self.next_message_time = round(time.time() * 1000.0 + delay) + + def is_iniswap(self, client, anim1, anim2, char): + if self.iniswap_allowed: + return False + if '..' in anim1 or '..' in anim2: + return True + for char_link in self.server.allowed_iniswaps: + if client.get_char_name() in char_link and char in char_link: + return False + return True + + def add_jukebox_vote(self, client, music_name, length=-1, showname=''): + if not self.jukebox: + return + if length <= 0: + self.remove_jukebox_vote(client, False) + else: + self.remove_jukebox_vote(client, True) + self.jukebox_votes.append(self.JukeboxVote(client, music_name, length, showname)) + client.send_host_message('Your song was added to the jukebox.') + if len(self.jukebox_votes) == 1: + self.start_jukebox() + + def remove_jukebox_vote(self, client, silent): + if not self.jukebox: + return + for current_vote in self.jukebox_votes: + if current_vote.client.id == client.id: + self.jukebox_votes.remove(current_vote) + if not silent: + client.send_host_message('You removed your song from the jukebox.') + + def get_jukebox_picked(self): + if not self.jukebox: + return + if len(self.jukebox_votes) == 0: + return None + elif len(self.jukebox_votes) == 1: + return self.jukebox_votes[0] + else: + weighted_votes = [] + for current_vote in self.jukebox_votes: + i = 0 + while i < current_vote.chance: + weighted_votes.append(current_vote) + i += 1 + return random.choice(weighted_votes) + + def start_jukebox(self): + # There is a probability that the jukebox feature has been turned off since then, + # we should check that. + # We also do a check if we were the last to play a song, just in case. + if not self.jukebox: + if self.current_music_player == 'The Jukebox' and self.current_music_player_ipid == 'has no IPID': + self.current_music = '' + return + + vote_picked = self.get_jukebox_picked() + + if vote_picked is None: + self.current_music = '' + return + + if vote_picked.client.char_id != self.jukebox_prev_char_id or vote_picked.name != self.current_music or len(self.jukebox_votes) > 1: + self.jukebox_prev_char_id = vote_picked.client.char_id + if vote_picked.showname == '': + self.send_command('MC', vote_picked.name, vote_picked.client.char_id) + else: + self.send_command('MC', vote_picked.name, vote_picked.client.char_id, vote_picked.showname) + else: + self.send_command('MC', vote_picked.name, -1) + + self.current_music_player = 'The Jukebox' + self.current_music_player_ipid = 'has no IPID' + self.current_music = vote_picked.name + + for current_vote in self.jukebox_votes: + # Choosing the same song will get your votes down to 0, too. + # Don't want the same song twice in a row! + if current_vote.name == vote_picked.name: + current_vote.chance = 0 + else: + current_vote.chance += 1 + + if self.music_looper: + self.music_looper.cancel() + self.music_looper = asyncio.get_event_loop().call_later(vote_picked.length, lambda: self.start_jukebox()) + + def play_music(self, name, cid, length=-1): + self.send_command('MC', name, cid) + if self.music_looper: + self.music_looper.cancel() + if length > 0: + self.music_looper = asyncio.get_event_loop().call_later(length, + lambda: self.play_music(name, -1, length)) + + def play_music_shownamed(self, name, cid, showname, length=-1): + self.send_command('MC', name, cid, showname) + if self.music_looper: + self.music_looper.cancel() + if length > 0: + self.music_looper = asyncio.get_event_loop().call_later(length, + lambda: self.play_music(name, -1, length)) + + + def can_send_message(self, client): + if self.cannot_ic_interact(client): + client.send_host_message('This is a locked area - ask the CM to speak.') + return False + return (time.time() * 1000.0 - self.next_message_time) > 0 + + def cannot_ic_interact(self, client): + return self.is_locked != self.Locked.FREE and not client.is_mod and not client.id in self.invite_list + + def change_hp(self, side, val): + if not 0 <= val <= 10: + raise AreaError('Invalid penalty value.') + if not 1 <= side <= 2: + raise AreaError('Invalid penalty side.') + if side == 1: + self.hp_def = val + elif side == 2: + self.hp_pro = val + self.send_command('HP', side, val) + + def change_background(self, bg): + if bg.lower() not in (name.lower() for name in self.server.backgrounds): + raise AreaError('Invalid background name.') + self.background = bg + self.send_command('BN', self.background) + + def change_status(self, value): + allowed_values = ('idle', 'rp', 'casing', 'looking-for-players', 'lfp', 'recess', 'gaming') + if value.lower() not in allowed_values: + raise AreaError('Invalid status. Possible values: {}'.format(', '.join(allowed_values))) + if value.lower() == 'lfp': + value = 'looking-for-players' + self.status = value.upper() + self.server.area_manager.send_arup_status() + + def change_doc(self, doc='No document.'): + self.doc = doc + + def add_to_judgelog(self, client, msg): + if len(self.judgelog) >= 10: + self.judgelog = self.judgelog[1:] + self.judgelog.append('{} ({}) {}.'.format(client.get_char_name(), client.get_ip(), msg)) + + def add_music_playing(self, client, name): + self.current_music_player = client.get_char_name() + self.current_music_player_ipid = client.ipid + self.current_music = name + + def add_music_playing_shownamed(self, client, showname, name): + self.current_music_player = showname + " (" + client.get_char_name() + ")" + self.current_music_player_ipid = client.ipid + self.current_music = name + + def get_evidence_list(self, client): + client.evi_list, evi_list = self.evi_list.create_evi_list(client) + return evi_list + + def broadcast_evidence_list(self): + """ + LE#&&# + + """ + for client in self.clients: + client.send_command('LE', *self.get_evidence_list(client)) + + def get_cms(self): + msg = '' + for i in self.owners: + msg = msg + '[' + str(i.id) + '] ' + i.get_char_name() + ', ' + if len(msg) > 2: + msg = msg[:-2] + return msg + + class JukeboxVote: + def __init__(self, client, name, length, showname): + self.client = client + self.name = name + self.length = length + self.chance = 1 + self.showname = showname + + def __init__(self, server): + self.server = server + self.cur_id = 0 + self.areas = [] + self.load_areas() + + def load_areas(self): + with open('config/areas.yaml', 'r') as chars: + areas = yaml.load(chars) + for item in areas: + if 'evidence_mod' not in item: + item['evidence_mod'] = 'FFA' + if 'locking_allowed' not in item: + item['locking_allowed'] = False + if 'iniswap_allowed' not in item: + item['iniswap_allowed'] = True + if 'showname_changes_allowed' not in item: + item['showname_changes_allowed'] = False + if 'shouts_allowed' not in item: + item['shouts_allowed'] = True + if 'jukebox' not in item: + item['jukebox'] = False + if 'noninterrupting_pres' not in item: + item['noninterrupting_pres'] = False + if 'abbreviation' not in item: + item['abbreviation'] = self.get_generated_abbreviation(item['area']) + self.areas.append( + self.Area(self.cur_id, self.server, item['area'], item['background'], item['bglock'], item['evidence_mod'], item['locking_allowed'], item['iniswap_allowed'], item['showname_changes_allowed'], item['shouts_allowed'], item['jukebox'], item['abbreviation'], item['noninterrupting_pres'])) + self.cur_id += 1 + + def default_area(self): + return self.areas[0] + + def get_area_by_name(self, name): + for area in self.areas: + if area.name == name: + return area + raise AreaError('Area not found.') + + def get_area_by_id(self, num): + for area in self.areas: + if area.id == num: + return area + raise AreaError('Area not found.') + + def get_generated_abbreviation(self, name): + if name.lower().startswith("courtroom"): + return "CR" + name.split()[-1] + elif name.lower().startswith("area"): + return "A" + name.split()[-1] + elif len(name.split()) > 1: + return "".join(item[0].upper() for item in name.split()) + elif len(name) > 3: + return name[:3].upper() + else: + return name.upper() + + def send_remote_command(self, area_ids, cmd, *args): + for a_id in area_ids: + self.get_area_by_id(a_id).send_command(cmd, *args) + self.get_area_by_id(a_id).send_owner_command(cmd, *args) + + def send_arup_players(self): + players_list = [0] + for area in self.areas: + players_list.append(len(area.clients)) + self.server.send_arup(players_list) + + def send_arup_status(self): + status_list = [1] + for area in self.areas: + status_list.append(area.status) + self.server.send_arup(status_list) + + def send_arup_cms(self): + cms_list = [2] + for area in self.areas: + cm = 'FREE' + if len(area.owners) > 0: + cm = area.get_cms() + cms_list.append(cm) + self.server.send_arup(cms_list) + + def send_arup_lock(self): + lock_list = [3] + for area in self.areas: + lock_list.append(area.is_locked.name) + self.server.send_arup(lock_list) diff --git a/server/ban_manager.py b/server/ban_manager.py new file mode 100644 index 0000000..20c186f --- /dev/null +++ b/server/ban_manager.py @@ -0,0 +1,54 @@ +# tsuserver3, an Attorney Online server +# +# Copyright (C) 2016 argoneus +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +import json + +from server.exceptions import ServerError + + +class BanManager: + def __init__(self): + self.bans = [] + self.load_banlist() + + def load_banlist(self): + try: + with open('storage/banlist.json', 'r') as banlist_file: + self.bans = json.load(banlist_file) + except FileNotFoundError: + return + + def write_banlist(self): + with open('storage/banlist.json', 'w') as banlist_file: + json.dump(self.bans, banlist_file) + + def add_ban(self, ip): + if ip not in self.bans: + self.bans.append(ip) + else: + raise ServerError('This IPID is already banned.') + self.write_banlist() + + def remove_ban(self, ip): + if ip in self.bans: + self.bans.remove(ip) + else: + raise ServerError('This IPID is not banned.') + self.write_banlist() + + def is_banned(self, ipid): + return (ipid in self.bans) \ No newline at end of file diff --git a/server/client_manager.py b/server/client_manager.py new file mode 100644 index 0000000..432c39d --- /dev/null +++ b/server/client_manager.py @@ -0,0 +1,457 @@ +# tsuserver3, an Attorney Online server +# +# Copyright (C) 2016 argoneus +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +from server import fantacrypt +from server import logger +from server.exceptions import ClientError, AreaError +from enum import Enum +from server.constants import TargetType +from heapq import heappop, heappush + +import time +import re + + + +class ClientManager: + class Client: + def __init__(self, server, transport, user_id, ipid): + self.is_checked = False + self.transport = transport + self.hdid = '' + self.pm_mute = False + self.id = user_id + self.char_id = -1 + self.area = server.area_manager.default_area() + self.server = server + self.name = '' + self.fake_name = '' + self.is_mod = False + self.is_dj = True + self.can_wtce = True + self.pos = '' + self.evi_list = [] + self.disemvowel = False + self.shaken = False + self.charcurse = [] + self.muted_global = False + self.muted_adverts = False + self.is_muted = False + self.is_ooc_muted = False + self.pm_mute = False + self.mod_call_time = 0 + self.in_rp = False + self.ipid = ipid + self.websocket = None + + # Pairing stuff + self.charid_pair = -1 + self.offset_pair = 0 + self.last_sprite = '' + self.flip = 0 + self.claimed_folder = '' + + # Casing stuff + self.casing_cm = False + self.casing_cases = "" + self.casing_def = False + self.casing_pro = False + self.casing_jud = False + self.casing_jur = False + self.casing_steno = False + self.case_call_time = 0 + + #flood-guard stuff + self.mus_counter = 0 + self.mus_mute_time = 0 + self.mus_change_time = [x * self.server.config['music_change_floodguard']['interval_length'] for x in range(self.server.config['music_change_floodguard']['times_per_interval'])] + self.wtce_counter = 0 + self.wtce_mute_time = 0 + self.wtce_time = [x * self.server.config['wtce_floodguard']['interval_length'] for x in range(self.server.config['wtce_floodguard']['times_per_interval'])] + + def send_raw_message(self, msg): + if self.websocket: + self.websocket.send_text(msg.encode('utf-8')) + else: + self.transport.write(msg.encode('utf-8')) + + def send_command(self, command, *args): + if args: + if command == 'MS': + for evi_num in range(len(self.evi_list)): + if self.evi_list[evi_num] == args[11]: + lst = list(args) + lst[11] = evi_num + args = tuple(lst) + break + self.send_raw_message('{}#{}#%'.format(command, '#'.join([str(x) for x in args]))) + else: + self.send_raw_message('{}#%'.format(command)) + + def send_host_message(self, msg): + self.send_command('CT', self.server.config['hostname'], msg, '1') + + def send_motd(self): + self.send_host_message('=== MOTD ===\r\n{}\r\n============='.format(self.server.config['motd'])) + + def send_player_count(self): + self.send_host_message('{}/{} players online.'.format( + self.server.get_player_count(), + self.server.config['playerlimit'])) + + def is_valid_name(self, name): + name_ws = name.replace(' ', '') + if not name_ws or name_ws.isdigit(): + return False + for client in self.server.client_manager.clients: + print(client.name == name) + if client.name == name: + return False + return True + + def disconnect(self): + self.transport.close() + + def change_character(self, char_id, force=False): + if not self.server.is_valid_char_id(char_id): + raise ClientError('Invalid Character ID.') + if len(self.charcurse) > 0: + if not char_id in self.charcurse: + raise ClientError('Character not available.') + force = True + if not self.area.is_char_available(char_id): + if force: + for client in self.area.clients: + if client.char_id == char_id: + client.char_select() + else: + raise ClientError('Character not available.') + old_char = self.get_char_name() + self.char_id = char_id + self.pos = '' + self.send_command('PV', self.id, 'CID', self.char_id) + self.area.send_command('CharsCheck', *self.get_available_char_list()) + logger.log_server('[{}]Changed character from {} to {}.' + .format(self.area.abbreviation, old_char, self.get_char_name()), self) + + def change_music_cd(self): + if self.is_mod or self in self.area.owners: + return 0 + if self.mus_mute_time: + if time.time() - self.mus_mute_time < self.server.config['music_change_floodguard']['mute_length']: + return self.server.config['music_change_floodguard']['mute_length'] - (time.time() - self.mus_mute_time) + else: + self.mus_mute_time = 0 + times_per_interval = self.server.config['music_change_floodguard']['times_per_interval'] + interval_length = self.server.config['music_change_floodguard']['interval_length'] + if time.time() - self.mus_change_time[(self.mus_counter - times_per_interval + 1) % times_per_interval] < interval_length: + self.mus_mute_time = time.time() + return self.server.config['music_change_floodguard']['mute_length'] + self.mus_counter = (self.mus_counter + 1) % times_per_interval + self.mus_change_time[self.mus_counter] = time.time() + return 0 + + def wtce_mute(self): + if self.is_mod or self in self.area.owners: + return 0 + if self.wtce_mute_time: + if time.time() - self.wtce_mute_time < self.server.config['wtce_floodguard']['mute_length']: + return self.server.config['wtce_floodguard']['mute_length'] - (time.time() - self.wtce_mute_time) + else: + self.wtce_mute_time = 0 + times_per_interval = self.server.config['wtce_floodguard']['times_per_interval'] + interval_length = self.server.config['wtce_floodguard']['interval_length'] + if time.time() - self.wtce_time[(self.wtce_counter - times_per_interval + 1) % times_per_interval] < interval_length: + self.wtce_mute_time = time.time() + return self.server.config['music_change_floodguard']['mute_length'] + self.wtce_counter = (self.wtce_counter + 1) % times_per_interval + self.wtce_time[self.wtce_counter] = time.time() + return 0 + + def reload_character(self): + try: + self.change_character(self.char_id, True) + except ClientError: + raise + + def change_area(self, area): + if self.area == area: + raise ClientError('User already in specified area.') + if area.is_locked == area.Locked.LOCKED and not self.is_mod and not self.id in area.invite_list: + raise ClientError("That area is locked!") + if area.is_locked == area.Locked.SPECTATABLE and not self.is_mod and not self.id in area.invite_list: + self.send_host_message('This area is spectatable, but not free - you will be unable to send messages ICly unless invited.') + + if self.area.jukebox: + self.area.remove_jukebox_vote(self, True) + + old_area = self.area + if not area.is_char_available(self.char_id): + try: + new_char_id = area.get_rand_avail_char_id() + except AreaError: + raise ClientError('No available characters in that area.') + + self.change_character(new_char_id) + self.send_host_message('Character taken, switched to {}.'.format(self.get_char_name())) + + self.area.remove_client(self) + self.area = area + area.new_client(self) + + self.send_host_message('Changed area to {}.[{}]'.format(area.name, self.area.status)) + logger.log_server( + '[{}]Changed area from {} ({}) to {} ({}).'.format(self.get_char_name(), old_area.name, old_area.id, + self.area.name, self.area.id), self) + self.area.send_command('CharsCheck', *self.get_available_char_list()) + self.send_command('HP', 1, self.area.hp_def) + self.send_command('HP', 2, self.area.hp_pro) + self.send_command('BN', self.area.background) + self.send_command('LE', *self.area.get_evidence_list(self)) + + def send_area_list(self): + msg = '=== Areas ===' + for i, area in enumerate(self.server.area_manager.areas): + owner = 'FREE' + if len(area.owners) > 0: + owner = 'CM: {}'.format(area.get_cms()) + lock = {area.Locked.FREE: '', area.Locked.SPECTATABLE: '[SPECTATABLE]', area.Locked.LOCKED: '[LOCKED]'} + msg += '\r\nArea {}: {} (users: {}) [{}][{}]{}'.format(area.abbreviation, area.name, len(area.clients), area.status, owner, lock[area.is_locked]) + if self.area == area: + msg += ' [*]' + self.send_host_message(msg) + + def get_area_info(self, area_id, mods): + info = '\r\n' + try: + area = self.server.area_manager.get_area_by_id(area_id) + except AreaError: + raise + info += '=== {} ==='.format(area.name) + info += '\r\n' + + lock = {area.Locked.FREE: '', area.Locked.SPECTATABLE: '[SPECTATABLE]', area.Locked.LOCKED: '[LOCKED]'} + info += '[{}]: [{} users][{}]{}'.format(area.abbreviation, len(area.clients), area.status, lock[area.is_locked]) + + sorted_clients = [] + for client in area.clients: + if (not mods) or client.is_mod: + sorted_clients.append(client) + for owner in area.owners: + if not (mods or owner in area.clients): + sorted_clients.append(owner) + if not sorted_clients: + return '' + sorted_clients = sorted(sorted_clients, key=lambda x: x.get_char_name()) + for c in sorted_clients: + info += '\r\n' + if c in area.owners: + if not c in area.clients: + info += '[RCM]' + else: + info +='[CM]' + info += '[{}] {}'.format(c.id, c.get_char_name()) + if self.is_mod: + info += ' ({})'.format(c.ipid) + info += ': {}'.format(c.name) + + return info + + def send_area_info(self, area_id, mods): + #if area_id is -1 then return all areas. If mods is True then return only mods + info = '' + if area_id == -1: + # all areas info + cnt = 0 + info = '\n== Area List ==' + for i in range(len(self.server.area_manager.areas)): + if len(self.server.area_manager.areas[i].clients) > 0 or len(self.server.area_manager.areas[i].owners) > 0: + cnt += len(self.server.area_manager.areas[i].clients) + info += '{}'.format(self.get_area_info(i, mods)) + info = 'Current online: {}'.format(cnt) + info + else: + try: + info = 'People in this area: {}'.format(len(self.server.area_manager.areas[area_id].clients)) + self.get_area_info(area_id, mods) + except AreaError: + raise + self.send_host_message(info) + + def send_area_hdid(self, area_id): + try: + info = self.get_area_hdid(area_id) + except AreaError: + raise + self.send_host_message(info) + + def send_all_area_hdid(self): + info = '== HDID List ==' + for i in range (len(self.server.area_manager.areas)): + if len(self.server.area_manager.areas[i].clients) > 0: + info += '\r\n{}'.format(self.get_area_hdid(i)) + self.send_host_message(info) + + def send_all_area_ip(self): + info = '== IP List ==' + for i in range (len(self.server.area_manager.areas)): + if len(self.server.area_manager.areas[i].clients) > 0: + info += '\r\n{}'.format(self.get_area_ip(i)) + self.send_host_message(info) + + def send_done(self): + self.send_command('CharsCheck', *self.get_available_char_list()) + self.send_command('HP', 1, self.area.hp_def) + self.send_command('HP', 2, self.area.hp_pro) + self.send_command('BN', self.area.background) + self.send_command('LE', *self.area.get_evidence_list(self)) + self.send_command('MM', 1) + + self.server.area_manager.send_arup_players() + self.server.area_manager.send_arup_status() + self.server.area_manager.send_arup_cms() + self.server.area_manager.send_arup_lock() + + self.send_command('DONE') + + def char_select(self): + self.char_id = -1 + self.send_done() + + def get_available_char_list(self): + if len(self.charcurse) > 0: + avail_char_ids = set(range(len(self.server.char_list))) and set(self.charcurse) + else: + avail_char_ids = set(range(len(self.server.char_list))) - set([x.char_id for x in self.area.clients]) + char_list = [-1] * len(self.server.char_list) + for x in avail_char_ids: + char_list[x] = 0 + return char_list + + def auth_mod(self, password): + if self.is_mod: + raise ClientError('Already logged in.') + if password == self.server.config['modpass']: + self.is_mod = True + else: + raise ClientError('Invalid password.') + + def get_ip(self): + return self.ipid + + + + def get_char_name(self): + if self.char_id == -1: + return 'CHAR_SELECT' + return self.server.char_list[self.char_id] + + def change_position(self, pos=''): + if pos not in ('', 'def', 'pro', 'hld', 'hlp', 'jud', 'wit', 'jur', 'sea'): + raise ClientError('Invalid position. Possible values: def, pro, hld, hlp, jud, wit, jur, sea.') + self.pos = pos + + def set_mod_call_delay(self): + self.mod_call_time = round(time.time() * 1000.0 + 30000) + + def can_call_mod(self): + return (time.time() * 1000.0 - self.mod_call_time) > 0 + + def set_case_call_delay(self): + self.case_call_time = round(time.time() * 1000.0 + 60000) + + def can_call_case(self): + return (time.time() * 1000.0 - self.case_call_time) > 0 + + def disemvowel_message(self, message): + message = re.sub("[aeiou]", "", message, flags=re.IGNORECASE) + return re.sub(r"\s+", " ", message) + + def shake_message(self, message): + import random + parts = message.split() + random.shuffle(parts) + return ' '.join(parts) + + + def __init__(self, server): + self.clients = set() + self.server = server + self.cur_id = [i for i in range(self.server.config['playerlimit'])] + self.clients_list = [] + + def new_client(self, transport): + c = self.Client(self.server, transport, heappop(self.cur_id), self.server.get_ipid(transport.get_extra_info('peername')[0])) + self.clients.add(c) + return c + + + def remove_client(self, client): + if client.area.jukebox: + client.area.remove_jukebox_vote(client, True) + for a in self.server.area_manager.areas: + if client in a.owners: + a.owners.remove(client) + client.server.area_manager.send_arup_cms() + if len(a.owners) == 0: + if a.is_locked != a.Locked.FREE: + a.unlock() + heappush(self.cur_id, client.id) + self.clients.remove(client) + + def get_targets(self, client, key, value, local = False): + #possible keys: ip, OOC, id, cname, ipid, hdid + areas = None + if local: + areas = [client.area] + else: + areas = client.server.area_manager.areas + targets = [] + if key == TargetType.ALL: + for nkey in range(6): + targets += self.get_targets(client, nkey, value, local) + for area in areas: + for client in area.clients: + if key == TargetType.IP: + if value.lower().startswith(client.get_ip().lower()): + targets.append(client) + elif key == TargetType.OOC_NAME: + if value.lower().startswith(client.name.lower()) and client.name: + targets.append(client) + elif key == TargetType.CHAR_NAME: + if value.lower().startswith(client.get_char_name().lower()): + targets.append(client) + elif key == TargetType.ID: + if client.id == value: + targets.append(client) + elif key == TargetType.IPID: + if client.ipid == value: + targets.append(client) + return targets + + + def get_muted_clients(self): + clients = [] + for client in self.clients: + if client.is_muted: + clients.append(client) + return clients + + def get_ooc_muted_clients(self): + clients = [] + for client in self.clients: + if client.is_ooc_muted: + clients.append(client) + return clients diff --git a/server/commands.py b/server/commands.py new file mode 100644 index 0000000..d02eff2 --- /dev/null +++ b/server/commands.py @@ -0,0 +1,1255 @@ +# tsuserver3, an Attorney Online server +# +# Copyright (C) 2016 argoneus +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +#possible keys: ip, OOC, id, cname, ipid, hdid +import random +import re +import hashlib +import string +from server.constants import TargetType + +from server import logger +from server.exceptions import ClientError, ServerError, ArgumentError, AreaError + +def ooc_cmd_a(client, arg): + if len(arg) == 0: + raise ArgumentError('You must specify an area.') + arg = arg.split(' ') + + try: + area = client.server.area_manager.get_area_by_id(int(arg[0])) + except AreaError: + raise + + message_areas_cm(client, [area], ' '.join(arg[1:])) + +def ooc_cmd_s(client, arg): + areas = [] + for a in client.server.area_manager.areas: + if client in a.owners: + areas.append(a) + if not areas: + client.send_host_message('You aren\'t a CM in any area!') + return + message_areas_cm(client, areas, arg) + +def message_areas_cm(client, areas, message): + for a in areas: + if not client in a.owners: + client.send_host_message('You are not a CM in {}!'.format(a.name)) + return + a.send_command('CT', client.name, message) + a.send_owner_command('CT', client.name, message) + +def ooc_cmd_switch(client, arg): + if len(arg) == 0: + raise ArgumentError('You must specify a character name.') + try: + cid = client.server.get_char_id_by_name(arg) + except ServerError: + raise + try: + client.change_character(cid, client.is_mod) + except ClientError: + raise + client.send_host_message('Character changed.') + +def ooc_cmd_bg(client, arg): + if len(arg) == 0: + raise ArgumentError('You must specify a name. Use /bg .') + if not client.is_mod and client.area.bg_lock == "true": + raise AreaError("This area's background is locked") + try: + client.area.change_background(arg) + except AreaError: + raise + client.area.send_host_message('{} changed the background to {}.'.format(client.get_char_name(), arg)) + logger.log_server('[{}][{}]Changed background to {}'.format(client.area.abbreviation, client.get_char_name(), arg), client) + +def ooc_cmd_bglock(client,arg): + if not client.is_mod: + raise ClientError('You must be authorized to do that.') + if len(arg) != 0: + raise ArgumentError('This command has no arguments.') + if client.area.bg_lock == "true": + client.area.bg_lock = "false" + else: + client.area.bg_lock = "true" + client.area.send_host_message('{} [{}] has set the background lock to {}.'.format(client.get_char_name(), client.id, client.area.bg_lock)) + logger.log_server('[{}][{}]Changed bglock to {}'.format(client.area.abbreviation, client.get_char_name(), client.area.bg_lock), client) + +def ooc_cmd_evidence_mod(client, arg): + if not client.is_mod: + raise ClientError('You must be authorized to do that.') + if not arg: + client.send_host_message('current evidence mod: {}'.format(client.area.evidence_mod)) + return + if arg in ['FFA', 'Mods', 'CM', 'HiddenCM']: + if arg == client.area.evidence_mod: + client.send_host_message('current evidence mod: {}'.format(client.area.evidence_mod)) + return + if client.area.evidence_mod == 'HiddenCM': + for i in range(len(client.area.evi_list.evidences)): + client.area.evi_list.evidences[i].pos = 'all' + client.area.evidence_mod = arg + client.send_host_message('current evidence mod: {}'.format(client.area.evidence_mod)) + return + else: + raise ArgumentError('Wrong Argument. Use /evidence_mod . Possible values: FFA, CM, Mods, HiddenCM') + return + +def ooc_cmd_allow_iniswap(client, arg): + if not client.is_mod: + raise ClientError('You must be authorized to do that.') + client.area.iniswap_allowed = not client.area.iniswap_allowed + answer = {True: 'allowed', False: 'forbidden'} + client.send_host_message('iniswap is {}.'.format(answer[client.area.iniswap_allowed])) + return + +def ooc_cmd_allow_blankposting(client, arg): + if not client.is_mod and not client in client.area.owners: + raise ClientError('You must be authorized to do that.') + client.area.blankposting_allowed = not client.area.blankposting_allowed + answer = {True: 'allowed', False: 'forbidden'} + client.area.send_host_message('{} [{}] has set blankposting in the area to {}.'.format(client.get_char_name(), client.id, answer[client.area.blankposting_allowed])) + return + +def ooc_cmd_force_nonint_pres(client, arg): + if not client.is_mod and not client in client.area.owners: + raise ClientError('You must be authorized to do that.') + client.area.non_int_pres_only = not client.area.non_int_pres_only + answer = {True: 'non-interrupting only', False: 'non-interrupting or interrupting as you choose'} + client.area.send_host_message('{} [{}] has set pres in the area to be {}.'.format(client.get_char_name(), client.id, answer[client.area.non_int_pres_only])) + return + +def ooc_cmd_roll(client, arg): + roll_max = 11037 + if len(arg) != 0: + try: + val = list(map(int, arg.split(' '))) + if not 1 <= val[0] <= roll_max: + raise ArgumentError('Roll value must be between 1 and {}.'.format(roll_max)) + except ValueError: + raise ArgumentError('Wrong argument. Use /roll [] []') + else: + val = [6] + if len(val) == 1: + val.append(1) + if len(val) > 2: + raise ArgumentError('Too many arguments. Use /roll [] []') + if val[1] > 20 or val[1] < 1: + raise ArgumentError('Num of rolls must be between 1 and 20') + roll = '' + for i in range(val[1]): + roll += str(random.randint(1, val[0])) + ', ' + roll = roll[:-2] + if val[1] > 1: + roll = '(' + roll + ')' + client.area.send_host_message('{} rolled {} out of {}.'.format(client.get_char_name(), roll, val[0])) + logger.log_server( + '[{}][{}]Used /roll and got {} out of {}.'.format(client.area.abbreviation, client.get_char_name(), roll, val[0]), client) + +def ooc_cmd_rollp(client, arg): + roll_max = 11037 + if len(arg) != 0: + try: + val = list(map(int, arg.split(' '))) + if not 1 <= val[0] <= roll_max: + raise ArgumentError('Roll value must be between 1 and {}.'.format(roll_max)) + except ValueError: + raise ArgumentError('Wrong argument. Use /rollp [] []') + else: + val = [6] + if len(val) == 1: + val.append(1) + if len(val) > 2: + raise ArgumentError('Too many arguments. Use /rollp [] []') + if val[1] > 20 or val[1] < 1: + raise ArgumentError('Num of rolls must be between 1 and 20') + roll = '' + for i in range(val[1]): + roll += str(random.randint(1, val[0])) + ', ' + roll = roll[:-2] + if val[1] > 1: + roll = '(' + roll + ')' + client.send_host_message('{} rolled {} out of {}.'.format(client.get_char_name(), roll, val[0])) + + client.area.send_host_message('{} rolled in secret.'.format(client.get_char_name())) + for c in client.area.owners: + c.send_host_message('[{}]{} secretly rolled {} out of {}.'.format(client.area.abbreviation, client.get_char_name(), roll, val[0])) + + logger.log_server( + '[{}][{}]Used /rollp and got {} out of {}.'.format(client.area.abbreviation, client.get_char_name(), roll, val[0]), client) + +def ooc_cmd_currentmusic(client, arg): + if len(arg) != 0: + raise ArgumentError('This command has no arguments.') + if client.area.current_music == '': + raise ClientError('There is no music currently playing.') + if client.is_mod: + client.send_host_message('The current music is {} and was played by {} ({}).'.format(client.area.current_music, + client.area.current_music_player, client.area.current_music_player_ipid)) + else: + client.send_host_message('The current music is {} and was played by {}.'.format(client.area.current_music, + client.area.current_music_player)) + +def ooc_cmd_jukebox_toggle(client, arg): + if not client.is_mod and not client in client.area.owners: + raise ClientError('You must be authorized to do that.') + if len(arg) != 0: + raise ArgumentError('This command has no arguments.') + client.area.jukebox = not client.area.jukebox + client.area.jukebox_votes = [] + client.area.send_host_message('{} [{}] has set the jukebox to {}.'.format(client.get_char_name(), client.id, client.area.jukebox)) + +def ooc_cmd_jukebox_skip(client, arg): + if not client.is_mod and not client in client.area.owners: + raise ClientError('You must be authorized to do that.') + if len(arg) != 0: + raise ArgumentError('This command has no arguments.') + if not client.area.jukebox: + raise ClientError('This area does not have a jukebox.') + if len(client.area.jukebox_votes) == 0: + raise ClientError('There is no song playing right now, skipping is pointless.') + client.area.start_jukebox() + if len(client.area.jukebox_votes) == 1: + client.area.send_host_message('{} [{}] has forced a skip, restarting the only jukebox song.'.format(client.get_char_name(), client.id)) + else: + client.area.send_host_message('{} [{}] has forced a skip to the next jukebox song.'.format(client.get_char_name(), client.id)) + logger.log_server('[{}][{}]Skipped the current jukebox song.'.format(client.area.abbreviation, client.get_char_name()), client) + +def ooc_cmd_jukebox(client, arg): + if len(arg) != 0: + raise ArgumentError('This command has no arguments.') + if not client.area.jukebox: + raise ClientError('This area does not have a jukebox.') + if len(client.area.jukebox_votes) == 0: + client.send_host_message('The jukebox has no songs in it.') + else: + total = 0 + songs = [] + voters = dict() + chance = dict() + message = '' + + for current_vote in client.area.jukebox_votes: + if songs.count(current_vote.name) == 0: + songs.append(current_vote.name) + voters[current_vote.name] = [current_vote.client] + chance[current_vote.name] = current_vote.chance + else: + voters[current_vote.name].append(current_vote.client) + chance[current_vote.name] += current_vote.chance + total += current_vote.chance + + for song in songs: + message += '\n- ' + song + '\n' + message += '-- VOTERS: ' + + first = True + for voter in voters[song]: + if first: + first = False + else: + message += ', ' + message += voter.get_char_name() + ' [' + str(voter.id) + ']' + if client.is_mod: + message += '(' + str(voter.ipid) + ')' + message += '\n' + + if total == 0: + message += '-- CHANCE: 100' + else: + message += '-- CHANCE: ' + str(round(chance[song] / total * 100)) + + client.send_host_message('The jukebox has the following songs in it:{}'.format(message)) + +def ooc_cmd_coinflip(client, arg): + if len(arg) != 0: + raise ArgumentError('This command has no arguments.') + coin = ['heads', 'tails'] + flip = random.choice(coin) + client.area.send_host_message('{} flipped a coin and got {}.'.format(client.get_char_name(), flip)) + logger.log_server( + '[{}][{}]Used /coinflip and got {}.'.format(client.area.abbreviation, client.get_char_name(), flip), client) + +def ooc_cmd_motd(client, arg): + if len(arg) != 0: + raise ArgumentError("This command doesn't take any arguments") + client.send_motd() + +def ooc_cmd_pos(client, arg): + if len(arg) == 0: + client.change_position() + client.send_host_message('Position reset.') + else: + try: + client.change_position(arg) + except ClientError: + raise + client.area.broadcast_evidence_list() + client.send_host_message('Position changed.') + +def ooc_cmd_forcepos(client, arg): + if not client in client.area.owners and not client.is_mod: + raise ClientError('You must be authorized to do that.') + + args = arg.split() + + if len(args) < 1: + raise ArgumentError( + 'Not enough arguments. Use /forcepos . Target should be ID, OOC-name or char-name. Use /getarea for getting info like "[ID] char-name".') + + targets = [] + + pos = args[0] + if len(args) > 1: + targets = client.server.client_manager.get_targets( + client, TargetType.CHAR_NAME, " ".join(args[1:]), True) + if len(targets) == 0 and args[1].isdigit(): + targets = client.server.client_manager.get_targets( + client, TargetType.ID, int(arg[1]), True) + if len(targets) == 0: + targets = client.server.client_manager.get_targets( + client, TargetType.OOC_NAME, " ".join(args[1:]), True) + if len(targets) == 0: + raise ArgumentError('No targets found.') + else: + for c in client.area.clients: + targets.append(c) + + + + for t in targets: + try: + t.change_position(pos) + t.area.broadcast_evidence_list() + t.send_host_message('Forced into /pos {}.'.format(pos)) + except ClientError: + raise + + client.area.send_host_message( + '{} forced {} client(s) into /pos {}.'.format(client.get_char_name(), len(targets), pos)) + logger.log_server( + '[{}][{}]Used /forcepos {} for {} client(s).'.format(client.area.abbreviation, client.get_char_name(), pos, len(targets)), client) + +def ooc_cmd_help(client, arg): + if len(arg) != 0: + raise ArgumentError('This command has no arguments.') + help_url = 'http://casecafe.byethost14.com/commandlist' + help_msg = 'The commands available on this server can be found here: {}'.format(help_url) + client.send_host_message(help_msg) + +def ooc_cmd_kick(client, arg): + if not client.is_mod: + raise ClientError('You must be authorized to do that.') + if len(arg) == 0: + raise ArgumentError('You must specify a target. Use /kick ...') + args = list(arg.split(' ')) + client.send_host_message('Attempting to kick {} IPIDs.'.format(len(args))) + for raw_ipid in args: + try: + ipid = int(raw_ipid) + except: + raise ClientError('{} does not look like a valid IPID.'.format(raw_ipid)) + targets = client.server.client_manager.get_targets(client, TargetType.IPID, ipid, False) + if targets: + for c in targets: + logger.log_server('Kicked {} [{}]({}).'.format(c.get_char_name(), c.id, c.ipid), client) + logger.log_mod('Kicked {} [{}]({}).'.format(c.get_char_name(), c.id, c.ipid), client) + client.send_host_message("{} was kicked.".format(c.get_char_name())) + c.send_command('KK', c.char_id) + c.disconnect() + else: + client.send_host_message("No targets with the IPID {} were found.".format(ipid)) + +def ooc_cmd_ban(client, arg): + if not client.is_mod: + raise ClientError('You must be authorized to do that.') + if len(arg) == 0: + raise ArgumentError('You must specify a target. Use /ban ...') + args = list(arg.split(' ')) + client.send_host_message('Attempting to ban {} IPIDs.'.format(len(args))) + for raw_ipid in args: + try: + ipid = int(raw_ipid) + except: + raise ClientError('{} does not look like a valid IPID.'.format(raw_ipid)) + try: + client.server.ban_manager.add_ban(ipid) + except ServerError: + raise + if ipid != None: + targets = client.server.client_manager.get_targets(client, TargetType.IPID, ipid, False) + if targets: + for c in targets: + c.send_command('KB', c.char_id) + c.disconnect() + client.send_host_message('{} clients was kicked.'.format(len(targets))) + client.send_host_message('{} was banned.'.format(ipid)) + logger.log_server('Banned {}.'.format(ipid), client) + logger.log_mod('Banned {}.'.format(ipid), client) + +def ooc_cmd_unban(client, arg): + if not client.is_mod: + raise ClientError('You must be authorized to do that.') + if len(arg) == 0: + raise ArgumentError('You must specify a target. Use /unban ...') + args = list(arg.split(' ')) + client.send_host_message('Attempting to unban {} IPIDs.'.format(len(args))) + for raw_ipid in args: + try: + client.server.ban_manager.remove_ban(int(raw_ipid)) + except: + raise ClientError('{} does not look like a valid IPID.'.format(raw_ipid)) + logger.log_server('Unbanned {}.'.format(raw_ipid), client) + logger.log_mod('Unbanned {}.'.format(raw_ipid), client) + client.send_host_message('Unbanned {}'.format(raw_ipid)) + +def ooc_cmd_play(client, arg): + if not client.is_mod: + raise ClientError('You must be authorized to do that.') + if len(arg) == 0: + raise ArgumentError('You must specify a song.') + client.area.play_music(arg, client.char_id, -1) + client.area.add_music_playing(client, arg) + logger.log_server('[{}][{}]Changed music to {}.'.format(client.area.abbreviation, client.get_char_name(), arg), client) + +def ooc_cmd_mute(client, arg): + if not client.is_mod: + raise ClientError('You must be authorized to do that.') + if len(arg) == 0: + raise ArgumentError('You must specify a target. Use /mute .') + args = list(arg.split(' ')) + client.send_host_message('Attempting to mute {} IPIDs.'.format(len(args))) + for raw_ipid in args: + if raw_ipid.isdigit(): + ipid = int(raw_ipid) + clients = client.server.client_manager.get_targets(client, TargetType.IPID, ipid, False) + if (clients): + msg = 'Muted the IPID ' + str(ipid) + '\'s following clients:' + for c in clients: + c.is_muted = True + logger.log_server('Muted {} [{}]({}).'.format(c.get_char_name(), c.id, c.ipid), client) + logger.log_mod('Muted {} [{}]({}).'.format(c.get_char_name(), c.id, c.ipid), client) + msg += ' ' + c.get_char_name() + ' [' + str(c.id) + '],' + msg = msg[:-1] + msg += '.' + client.send_host_message('{}'.format(msg)) + else: + client.send_host_message("No targets found. Use /mute ... for mute.") + else: + client.send_host_message('{} does not look like a valid IPID.'.format(raw_ipid)) + +def ooc_cmd_unmute(client, arg): + if not client.is_mod: + raise ClientError('You must be authorized to do that.') + if len(arg) == 0: + raise ArgumentError('You must specify a target.') + args = list(arg.split(' ')) + client.send_host_message('Attempting to unmute {} IPIDs.'.format(len(args))) + for raw_ipid in args: + if raw_ipid.isdigit(): + ipid = int(raw_ipid) + clients = client.server.client_manager.get_targets(client, TargetType.IPID, ipid, False) + if (clients): + msg = 'Unmuted the IPID ' + str(ipid) + '\'s following clients::' + for c in clients: + c.is_muted = False + logger.log_server('Unmuted {} [{}]({}).'.format(c.get_char_name(), c.id, c.ipid), client) + logger.log_mod('Unmuted {} [{}]({}).'.format(c.get_char_name(), c.id, c.ipid), client) + msg += ' ' + c.get_char_name() + ' [' + str(c.id) + '],' + msg = msg[:-1] + msg += '.' + client.send_host_message('{}'.format(msg)) + else: + client.send_host_message("No targets found. Use /unmute ... for unmute.") + else: + client.send_host_message('{} does not look like a valid IPID.'.format(raw_ipid)) + +def ooc_cmd_login(client, arg): + if len(arg) == 0: + raise ArgumentError('You must specify the password.') + try: + client.auth_mod(arg) + except ClientError: + raise + if client.area.evidence_mod == 'HiddenCM': + client.area.broadcast_evidence_list() + client.send_host_message('Logged in as a moderator.') + logger.log_server('Logged in as moderator.', client) + logger.log_mod('Logged in as moderator.', client) + +def ooc_cmd_g(client, arg): + if client.muted_global: + raise ClientError('Global chat toggled off.') + if len(arg) == 0: + raise ArgumentError("You can't send an empty message.") + client.server.broadcast_global(client, arg) + logger.log_server('[{}][{}][GLOBAL]{}.'.format(client.area.abbreviation, client.get_char_name(), arg), client) + +def ooc_cmd_gm(client, arg): + if not client.is_mod: + raise ClientError('You must be authorized to do that.') + if client.muted_global: + raise ClientError('You have the global chat muted.') + if len(arg) == 0: + raise ArgumentError("Can't send an empty message.") + client.server.broadcast_global(client, arg, True) + logger.log_server('[{}][{}][GLOBAL-MOD]{}.'.format(client.area.abbreviation, client.get_char_name(), arg), client) + logger.log_mod('[{}][{}][GLOBAL-MOD]{}.'.format(client.area.abbreviation, client.get_char_name(), arg), client) + +def ooc_cmd_m(client, arg): + if not client.is_mod: + raise ClientError('You must be authorized to do that.') + if len(arg) == 0: + raise ArgumentError("You can't send an empty message.") + client.server.send_modchat(client, arg) + logger.log_server('[{}][{}][MODCHAT]{}.'.format(client.area.abbreviation, client.get_char_name(), arg), client) + logger.log_mod('[{}][{}][MODCHAT]{}.'.format(client.area.abbreviation, client.get_char_name(), arg), client) + +def ooc_cmd_lm(client, arg): + if not client.is_mod: + raise ClientError('You must be authorized to do that.') + if len(arg) == 0: + raise ArgumentError("Can't send an empty message.") + client.area.send_command('CT', '{}[MOD][{}]' + .format(client.server.config['hostname'], client.get_char_name()), arg) + logger.log_server('[{}][{}][LOCAL-MOD]{}.'.format(client.area.abbreviation, client.get_char_name(), arg), client) + logger.log_mod('[{}][{}][LOCAL-MOD]{}.'.format(client.area.abbreviation, client.get_char_name(), arg), client) + +def ooc_cmd_announce(client, arg): + if not client.is_mod: + raise ClientError('You must be authorized to do that.') + if len(arg) == 0: + raise ArgumentError("Can't send an empty message.") + client.server.send_all_cmd_pred('CT', '{}'.format(client.server.config['hostname']), + '=== Announcement ===\r\n{}\r\n=================='.format(arg), '1') + logger.log_server('[{}][{}][ANNOUNCEMENT]{}.'.format(client.area.abbreviation, client.get_char_name(), arg), client) + logger.log_mod('[{}][{}][ANNOUNCEMENT]{}.'.format(client.area.abbreviation, client.get_char_name(), arg), client) + +def ooc_cmd_toggleglobal(client, arg): + if len(arg) != 0: + raise ArgumentError("This command doesn't take any arguments") + client.muted_global = not client.muted_global + glob_stat = 'on' + if client.muted_global: + glob_stat = 'off' + client.send_host_message('Global chat turned {}.'.format(glob_stat)) + + +def ooc_cmd_need(client, arg): + if client.muted_adverts: + raise ClientError('You have advertisements muted.') + if len(arg) == 0: + raise ArgumentError("You must specify what you need.") + client.server.broadcast_need(client, arg) + logger.log_server('[{}][{}][NEED]{}.'.format(client.area.abbreviation, client.get_char_name(), arg), client) + +def ooc_cmd_toggleadverts(client, arg): + if len(arg) != 0: + raise ArgumentError("This command doesn't take any arguments") + client.muted_adverts = not client.muted_adverts + adv_stat = 'on' + if client.muted_adverts: + adv_stat = 'off' + client.send_host_message('Advertisements turned {}.'.format(adv_stat)) + +def ooc_cmd_doc(client, arg): + if len(arg) == 0: + client.send_host_message('Document: {}'.format(client.area.doc)) + logger.log_server( + '[{}][{}]Requested document. Link: {}'.format(client.area.abbreviation, client.get_char_name(), client.area.doc), client) + else: + client.area.change_doc(arg) + client.area.send_host_message('{} changed the doc link.'.format(client.get_char_name())) + logger.log_server('[{}][{}]Changed document to: {}'.format(client.area.abbreviation, client.get_char_name(), arg), client) + + +def ooc_cmd_cleardoc(client, arg): + if len(arg) != 0: + raise ArgumentError('This command has no arguments.') + client.area.send_host_message('{} cleared the doc link.'.format(client.get_char_name())) + logger.log_server('[{}][{}]Cleared document. Old link: {}' + .format(client.area.abbreviation, client.get_char_name(), client.area.doc), client) + client.area.change_doc() + + +def ooc_cmd_status(client, arg): + if len(arg) == 0: + client.send_host_message('Current status: {}'.format(client.area.status)) + else: + try: + client.area.change_status(arg) + client.area.send_host_message('{} changed status to {}.'.format(client.get_char_name(), client.area.status)) + logger.log_server( + '[{}][{}]Changed status to {}'.format(client.area.abbreviation, client.get_char_name(), client.area.status), client) + except AreaError: + raise + + +def ooc_cmd_online(client, _): + client.send_player_count() + + +def ooc_cmd_area(client, arg): + args = arg.split() + if len(args) == 0: + client.send_area_list() + elif len(args) == 1: + try: + area = client.server.area_manager.get_area_by_id(int(args[0])) + client.change_area(area) + except ValueError: + raise ArgumentError('Area ID must be a number.') + except (AreaError, ClientError): + raise + else: + raise ArgumentError('Too many arguments. Use /area .') + +def ooc_cmd_pm(client, arg): + args = arg.split() + key = '' + msg = None + if len(args) < 2: + raise ArgumentError('Not enough arguments. use /pm . Target should be ID, OOC-name or char-name. Use /getarea for getting info like "[ID] char-name".') + targets = client.server.client_manager.get_targets(client, TargetType.CHAR_NAME, arg, True) + key = TargetType.CHAR_NAME + if len(targets) == 0 and args[0].isdigit(): + targets = client.server.client_manager.get_targets(client, TargetType.ID, int(args[0]), False) + key = TargetType.ID + if len(targets) == 0: + targets = client.server.client_manager.get_targets(client, TargetType.OOC_NAME, arg, True) + key = TargetType.OOC_NAME + if len(targets) == 0: + raise ArgumentError('No targets found.') + try: + if key == TargetType.ID: + msg = ' '.join(args[1:]) + else: + if key == TargetType.CHAR_NAME: + msg = arg[len(targets[0].get_char_name()) + 1:] + if key == TargetType.OOC_NAME: + msg = arg[len(targets[0].name) + 1:] + except: + raise ArgumentError('Not enough arguments. Use /pm .') + c = targets[0] + if c.pm_mute: + raise ClientError('This user muted all pm conversation') + else: + if c.is_mod: + c.send_host_message('PM from {} (ID: {}, IPID: {}) in {} ({}): {}'.format(client.name, client.id, client.ipid, client.area.name, client.get_char_name(), msg)) + else: + c.send_host_message('PM from {} (ID: {}) in {} ({}): {}'.format(client.name, client.id, client.area.name, client.get_char_name(), msg)) + client.send_host_message('PM sent to {}. Message: {}'.format(args[0], msg)) + +def ooc_cmd_mutepm(client, arg): + if len(arg) != 0: + raise ArgumentError("This command doesn't take any arguments") + client.pm_mute = not client.pm_mute + client.send_host_message({True:'You stopped receiving PMs', False:'You are now receiving PMs'}[client.pm_mute]) + +def ooc_cmd_charselect(client, arg): + if not arg: + client.char_select() + else: + if client.is_mod: + try: + client.server.client_manager.get_targets(client, TargetType.ID, int(arg), False)[0].char_select() + except: + raise ArgumentError('Wrong arguments. Use /charselect ') + +def ooc_cmd_reload(client, arg): + if len(arg) != 0: + raise ArgumentError("This command doesn't take any arguments") + try: + client.reload_character() + except ClientError: + raise + client.send_host_message('Character reloaded.') + +def ooc_cmd_randomchar(client, arg): + if len(arg) != 0: + raise ArgumentError('This command has no arguments.') + if len(client.charcurse) > 0: + free_id = random.choice(client.charcurse) + else: + try: + free_id = client.area.get_rand_avail_char_id() + except AreaError: + raise + try: + client.change_character(free_id) + except ClientError: + raise + client.send_host_message('Randomly switched to {}'.format(client.get_char_name())) + +def ooc_cmd_getarea(client, arg): + client.send_area_info(client.area.id, False) + +def ooc_cmd_getareas(client, arg): + client.send_area_info(-1, False) + +def ooc_cmd_mods(client, arg): + client.send_area_info(-1, True) + +def ooc_cmd_evi_swap(client, arg): + args = list(arg.split(' ')) + if len(args) != 2: + raise ClientError("you must specify 2 numbers") + try: + client.area.evi_list.evidence_swap(client, int(args[0]), int(args[1])) + client.area.broadcast_evidence_list() + except: + raise ClientError("you must specify 2 numbers") + +def ooc_cmd_cm(client, arg): + if 'CM' not in client.area.evidence_mod: + raise ClientError('You can\'t become a CM in this area') + if len(client.area.owners) == 0: + if len(arg) > 0: + raise ArgumentError('You cannot \'nominate\' people to be CMs when you are not one.') + client.area.owners.append(client) + if client.area.evidence_mod == 'HiddenCM': + client.area.broadcast_evidence_list() + client.server.area_manager.send_arup_cms() + client.area.send_host_message('{} [{}] is CM in this area now.'.format(client.get_char_name(), client.id)) + elif client in client.area.owners: + if len(arg) > 0: + arg = arg.split(' ') + for id in arg: + try: + id = int(id) + c = client.server.client_manager.get_targets(client, TargetType.ID, id, False)[0] + if c in client.area.owners: + client.send_host_message('{} [{}] is already a CM here.'.format(c.get_char_name(), c.id)) + else: + client.area.owners.append(c) + if client.area.evidence_mod == 'HiddenCM': + client.area.broadcast_evidence_list() + client.server.area_manager.send_arup_cms() + client.area.send_host_message('{} [{}] is CM in this area now.'.format(c.get_char_name(), c.id)) + except: + client.send_host_message('{} does not look like a valid ID.'.format(id)) + else: + raise ClientError('You must be authorized to do that.') + + +def ooc_cmd_uncm(client, arg): + if client in client.area.owners: + if len(arg) > 0: + arg = arg.split(' ') + else: + arg = [client.id] + for id in arg: + try: + id = int(id) + c = client.server.client_manager.get_targets(client, TargetType.ID, id, False)[0] + if c in client.area.owners: + client.area.owners.remove(c) + client.server.area_manager.send_arup_cms() + client.area.send_host_message('{} [{}] is no longer CM in this area.'.format(c.get_char_name(), c.id)) + else: + client.send_host_message('You cannot remove someone from CMing when they aren\'t a CM.') + except: + client.send_host_message('{} does not look like a valid ID.'.format(id)) + else: + raise ClientError('You must be authorized to do that.') + +def ooc_cmd_setcase(client, arg): + args = re.findall(r'(?:[^\s,"]|"(?:\\.|[^"])*")+', arg) + if len(args) == 0: + raise ArgumentError('Please do not call this command manually!') + else: + client.casing_cases = args[0] + client.casing_cm = args[1] == "1" + client.casing_def = args[2] == "1" + client.casing_pro = args[3] == "1" + client.casing_jud = args[4] == "1" + client.casing_jur = args[5] == "1" + client.casing_steno = args[6] == "1" + +def ooc_cmd_anncase(client, arg): + if client in client.area.owners: + if not client.can_call_case(): + raise ClientError('Please wait 60 seconds between case announcements!') + args = re.findall(r'(?:[^\s,"]|"(?:\\.|[^"])*")+', arg) + if len(args) == 0: + raise ArgumentError('Please do not call this command manually!') + elif len(args) == 1: + raise ArgumentError('You should probably announce the case to at least one person.') + else: + if not args[1] == "1" and not args[2] == "1" and not args[3] == "1" and not args[4] == "1" and not args[5] == "1": + raise ArgumentError('You should probably announce the case to at least one person.') + msg = '=== Case Announcement ===\r\n{} [{}] is hosting {}, looking for '.format(client.get_char_name(), client.id, args[0]) + + lookingfor = [] + + if args[1] == "1": + lookingfor.append("defence") + if args[2] == "1": + lookingfor.append("prosecutor") + if args[3] == "1": + lookingfor.append("judge") + if args[4] == "1": + lookingfor.append("juror") + if args[5] == "1": + lookingfor.append("stenographer") + + msg = msg + ', '.join(lookingfor) + '.\r\n==================' + + client.server.send_all_cmd_pred('CASEA', msg, args[1], args[2], args[3], args[4], args[5], '1') + + client.set_case_call_delay() + + logger.log_server('[{}][{}][CASE_ANNOUNCEMENT]{}, DEF: {}, PRO: {}, JUD: {}, JUR: {}, STENO: {}.'.format(client.area.abbreviation, client.get_char_name(), args[0], args[1], args[2], args[3], args[4], args[5]), client) + else: + raise ClientError('You cannot announce a case in an area where you are not a CM!') + +def ooc_cmd_unmod(client, arg): + client.is_mod = False + if client.area.evidence_mod == 'HiddenCM': + client.area.broadcast_evidence_list() + client.send_host_message('you\'re not a mod now') + +def ooc_cmd_area_lock(client, arg): + if not client.area.locking_allowed: + client.send_host_message('Area locking is disabled in this area.') + return + if client.area.is_locked == client.area.Locked.LOCKED: + client.send_host_message('Area is already locked.') + if client in client.area.owners: + client.area.lock() + return + else: + raise ClientError('Only CM can lock the area.') + +def ooc_cmd_area_spectate(client, arg): + if not client.area.locking_allowed: + client.send_host_message('Area locking is disabled in this area.') + return + if client.area.is_locked == client.area.Locked.SPECTATABLE: + client.send_host_message('Area is already spectatable.') + if client in client.area.owners: + client.area.spectator() + return + else: + raise ClientError('Only CM can make the area spectatable.') + +def ooc_cmd_area_unlock(client, arg): + if client.area.is_locked == client.area.Locked.FREE: + raise ClientError('Area is already unlocked.') + if not client in client.area.owners: + raise ClientError('Only CM can unlock area.') + client.area.unlock() + client.send_host_message('Area is unlocked.') + +def ooc_cmd_invite(client, arg): + if not arg: + raise ClientError('You must specify a target. Use /invite ') + if client.area.is_locked == client.area.Locked.FREE: + raise ClientError('Area isn\'t locked.') + if not client in client.area.owners and not client.is_mod: + raise ClientError('You must be authorized to do that.') + try: + c = client.server.client_manager.get_targets(client, TargetType.ID, int(arg), False)[0] + client.area.invite_list[c.id] = None + client.send_host_message('{} is invited to your area.'.format(c.get_char_name())) + c.send_host_message('You were invited and given access to {}.'.format(client.area.name)) + except: + raise ClientError('You must specify a target. Use /invite ') + +def ooc_cmd_uninvite(client, arg): + if not client in client.area.owners and not client.is_mod: + raise ClientError('You must be authorized to do that.') + if client.area.is_locked == client.area.Locked.FREE: + raise ClientError('Area isn\'t locked.') + if not arg: + raise ClientError('You must specify a target. Use /uninvite ') + arg = arg.split(' ') + targets = client.server.client_manager.get_targets(client, TargetType.ID, int(arg[0]), True) + if targets: + try: + for c in targets: + client.send_host_message("You have removed {} from the whitelist.".format(c.get_char_name())) + c.send_host_message("You were removed from the area whitelist.") + if client.area.is_locked != client.area.Locked.FREE: + client.area.invite_list.pop(c.id) + except AreaError: + raise + except ClientError: + raise + else: + client.send_host_message("No targets found.") + +def ooc_cmd_area_kick(client, arg): + if not client.is_mod: + raise ClientError('You must be authorized to do that.') + if client.area.is_locked == client.area.Locked.FREE: + raise ClientError('Area isn\'t locked.') + if not arg: + raise ClientError('You must specify a target. Use /area_kick [destination #]') + arg = arg.split(' ') + targets = client.server.client_manager.get_targets(client, TargetType.ID, int(arg[0]), False) + if targets: + try: + for c in targets: + if len(arg) == 1: + area = client.server.area_manager.get_area_by_id(int(0)) + output = 0 + else: + try: + area = client.server.area_manager.get_area_by_id(int(arg[1])) + output = arg[1] + except AreaError: + raise + client.send_host_message("Attempting to kick {} to area {}.".format(c.get_char_name(), output)) + c.change_area(area) + c.send_host_message("You were kicked from the area to area {}.".format(output)) + if client.area.is_locked != client.area.Locked.FREE: + client.area.invite_list.pop(c.id) + except AreaError: + raise + except ClientError: + raise + else: + client.send_host_message("No targets found.") + + +def ooc_cmd_ooc_mute(client, arg): + if not client.is_mod: + raise ClientError('You must be authorized to do that.') + if len(arg) == 0: + raise ArgumentError('You must specify a target. Use /ooc_mute .') + targets = client.server.client_manager.get_targets(client, TargetType.OOC_NAME, arg, False) + if not targets: + raise ArgumentError('Targets not found. Use /ooc_mute .') + for target in targets: + target.is_ooc_muted = True + client.send_host_message('Muted {} existing client(s).'.format(len(targets))) + +def ooc_cmd_ooc_unmute(client, arg): + if not client.is_mod: + raise ClientError('You must be authorized to do that.') + if len(arg) == 0: + raise ArgumentError('You must specify a target. Use /ooc_unmute .') + targets = client.server.client_manager.get_ooc_muted_clients() + if not targets: + raise ArgumentError('Targets not found. Use /ooc_unmute .') + for target in targets: + target.is_ooc_muted = False + client.send_host_message('Unmuted {} existing client(s).'.format(len(targets))) + +def ooc_cmd_disemvowel(client, arg): + if not client.is_mod: + raise ClientError('You must be authorized to do that.') + elif len(arg) == 0: + raise ArgumentError('You must specify a target.') + try: + targets = client.server.client_manager.get_targets(client, TargetType.ID, int(arg), False) + except: + raise ArgumentError('You must specify a target. Use /disemvowel .') + if targets: + for c in targets: + logger.log_server('Disemvowelling {}.'.format(c.get_ip()), client) + logger.log_mod('Disemvowelling {}.'.format(c.get_ip()), client) + c.disemvowel = True + client.send_host_message('Disemvowelled {} existing client(s).'.format(len(targets))) + else: + client.send_host_message('No targets found.') + +def ooc_cmd_undisemvowel(client, arg): + if not client.is_mod: + raise ClientError('You must be authorized to do that.') + elif len(arg) == 0: + raise ArgumentError('You must specify a target.') + try: + targets = client.server.client_manager.get_targets(client, TargetType.ID, int(arg), False) + except: + raise ArgumentError('You must specify a target. Use /undisemvowel .') + if targets: + for c in targets: + logger.log_server('Undisemvowelling {}.'.format(c.get_ip()), client) + logger.log_mod('Undisemvowelling {}.'.format(c.get_ip()), client) + c.disemvowel = False + client.send_host_message('Undisemvowelled {} existing client(s).'.format(len(targets))) + else: + client.send_host_message('No targets found.') + +def ooc_cmd_shake(client, arg): + if not client.is_mod: + raise ClientError('You must be authorized to do that.') + elif len(arg) == 0: + raise ArgumentError('You must specify a target.') + try: + targets = client.server.client_manager.get_targets(client, TargetType.ID, int(arg), False) + except: + raise ArgumentError('You must specify a target. Use /shake .') + if targets: + for c in targets: + logger.log_server('Shaking {}.'.format(c.get_ip()), client) + logger.log_mod('Shaking {}.'.format(c.get_ip()), client) + c.shaken = True + client.send_host_message('Shook {} existing client(s).'.format(len(targets))) + else: + client.send_host_message('No targets found.') + +def ooc_cmd_unshake(client, arg): + if not client.is_mod: + raise ClientError('You must be authorized to do that.') + elif len(arg) == 0: + raise ArgumentError('You must specify a target.') + try: + targets = client.server.client_manager.get_targets(client, TargetType.ID, int(arg), False) + except: + raise ArgumentError('You must specify a target. Use /unshake .') + if targets: + for c in targets: + logger.log_server('Unshaking {}.'.format(c.get_ip()), client) + logger.log_mod('Unshaking {}.'.format(c.get_ip()), client) + c.shaken = False + client.send_host_message('Unshook {} existing client(s).'.format(len(targets))) + else: + client.send_host_message('No targets found.') + +def ooc_cmd_charcurse(client, arg): + if not client.is_mod: + raise ClientError('You must be authorized to do that.') + elif len(arg) == 0: + raise ArgumentError('You must specify a target (an ID) and at least one character ID. Consult /charids for the character IDs.') + elif len(arg) == 1: + raise ArgumentError('You must specific at least one character ID. Consult /charids for the character IDs.') + args = arg.split() + try: + targets = client.server.client_manager.get_targets(client, TargetType.ID, int(args[0]), False) + except: + raise ArgumentError('You must specify a valid target! Make sure it is a valid ID.') + if targets: + for c in targets: + log_msg = ' ' + str(c.get_ip()) + ' to' + part_msg = ' [' + str(c.id) + '] to' + for raw_cid in args[1:]: + try: + cid = int(raw_cid) + c.charcurse.append(cid) + part_msg += ' ' + str(client.server.char_list[cid]) + ',' + log_msg += ' ' + str(client.server.char_list[cid]) + ',' + except: + ArgumentError('' + str(raw_cid) + ' does not look like a valid character ID.') + part_msg = part_msg[:-1] + part_msg += '.' + log_msg = log_msg[:-1] + log_msg += '.' + c.char_select() + logger.log_server('Charcursing' + log_msg, client) + logger.log_mod('Charcursing' + log_msg, client) + client.send_host_message('Charcursed' + part_msg) + else: + client.send_host_message('No targets found.') + +def ooc_cmd_uncharcurse(client, arg): + if not client.is_mod: + raise ClientError('You must be authorized to do that.') + elif len(arg) == 0: + raise ArgumentError('You must specify a target (an ID).') + args = arg.split() + try: + targets = client.server.client_manager.get_targets(client, TargetType.ID, int(args[0]), False) + except: + raise ArgumentError('You must specify a valid target! Make sure it is a valid ID.') + if targets: + for c in targets: + if len(c.charcurse) > 0: + c.charcurse = [] + logger.log_server('Uncharcursing {}.'.format(c.get_ip()), client) + logger.log_mod('Uncharcursing {}.'.format(c.get_ip()), client) + client.send_host_message('Uncharcursed [{}].'.format(c.id)) + c.char_select() + else: + client.send_host_message('[{}] is not charcursed.'.format(c.id)) + else: + client.send_host_message('No targets found.') + +def ooc_cmd_charids(client, arg): + if not client.is_mod: + raise ClientError('You must be authorized to do that.') + if len(arg) != 0: + raise ArgumentError("This command doesn't take any arguments") + msg = 'Here is a list of all available characters on the server:' + for c in range(0, len(client.server.char_list)): + msg += '\n[' + str(c) + '] ' + client.server.char_list[c] + client.send_host_message(msg) + +def ooc_cmd_blockdj(client, arg): + if not client.is_mod: + raise ClientError('You must be authorized to do that.') + if len(arg) == 0: + raise ArgumentError('You must specify a target. Use /blockdj .') + try: + targets = client.server.client_manager.get_targets(client, TargetType.ID, int(arg), False) + except: + raise ArgumentError('You must enter a number. Use /blockdj .') + if not targets: + raise ArgumentError('Target not found. Use /blockdj .') + for target in targets: + target.is_dj = False + target.send_host_message('A moderator muted you from changing the music.') + logger.log_server('BlockDJ\'d {} [{}]({}).'.format(target.get_char_name(), target.id, target.get_ip()), client) + logger.log_mod('BlockDJ\'d {} [{}]({}).'.format(target.get_char_name(), target.id, target.get_ip()), client) + target.area.remove_jukebox_vote(target, True) + client.send_host_message('blockdj\'d {}.'.format(targets[0].get_char_name())) + +def ooc_cmd_unblockdj(client, arg): + if not client.is_mod: + raise ClientError('You must be authorized to do that.') + if len(arg) == 0: + raise ArgumentError('You must specify a target. Use /unblockdj .') + try: + targets = client.server.client_manager.get_targets(client, TargetType.ID, int(arg), False) + except: + raise ArgumentError('You must enter a number. Use /unblockdj .') + if not targets: + raise ArgumentError('Target not found. Use /blockdj .') + for target in targets: + target.is_dj = True + target.send_host_message('A moderator unmuted you from changing the music.') + logger.log_server('UnblockDJ\'d {} [{}]({}).'.format(target.get_char_name(), target.id, target.get_ip()), client) + logger.log_mod('UnblockDJ\'d {} [{}]({}).'.format(target.get_char_name(), target.id, target.get_ip()), client) + client.send_host_message('Unblockdj\'d {}.'.format(targets[0].get_char_name())) + +def ooc_cmd_blockwtce(client, arg): + if not client.is_mod: + raise ClientError('You must be authorized to do that.') + if len(arg) == 0: + raise ArgumentError('You must specify a target. Use /blockwtce .') + try: + targets = client.server.client_manager.get_targets(client, TargetType.ID, int(arg), False) + except: + raise ArgumentError('You must enter a number. Use /blockwtce .') + if not targets: + raise ArgumentError('Target not found. Use /blockwtce .') + for target in targets: + target.can_wtce = False + target.send_host_message('A moderator blocked you from using judge signs.') + logger.log_server('BlockWTCE\'d {} [{}]({}).'.format(target.get_char_name(), target.id, target.get_ip()), client) + logger.log_mod('BlockWTCE\'d {} [{}]({}).'.format(target.get_char_name(), target.id, target.get_ip()), client) + client.send_host_message('blockwtce\'d {}.'.format(targets[0].get_char_name())) + +def ooc_cmd_unblockwtce(client, arg): + if not client.is_mod: + raise ClientError('You must be authorized to do that.') + if len(arg) == 0: + raise ArgumentError('You must specify a target. Use /unblockwtce .') + try: + targets = client.server.client_manager.get_targets(client, TargetType.ID, int(arg), False) + except: + raise ArgumentError('You must enter a number. Use /unblockwtce .') + if not targets: + raise ArgumentError('Target not found. Use /unblockwtce .') + for target in targets: + target.can_wtce = True + target.send_host_message('A moderator unblocked you from using judge signs.') + logger.log_server('UnblockWTCE\'d {} [{}]({}).'.format(target.get_char_name(), target.id, target.get_ip()), client) + logger.log_mod('UnblockWTCE\'d {} [{}]({}).'.format(target.get_char_name(), target.id, target.get_ip()), client) + client.send_host_message('unblockwtce\'d {}.'.format(targets[0].get_char_name())) + +def ooc_cmd_notecard(client, arg): + if len(arg) == 0: + raise ArgumentError('You must specify the contents of the note card.') + client.area.cards[client.get_char_name()] = arg + client.area.send_host_message('{} wrote a note card.'.format(client.get_char_name())) + +def ooc_cmd_notecard_clear(client, arg): + try: + del client.area.cards[client.get_char_name()] + client.area.send_host_message('{} erased their note card.'.format(client.get_char_name())) + except KeyError: + raise ClientError('You do not have a note card.') + +def ooc_cmd_notecard_reveal(client, arg): + if not client in client.area.owners and not client.is_mod: + raise ClientError('You must be a CM or moderator to reveal cards.') + if len(client.area.cards) == 0: + raise ClientError('There are no cards to reveal in this area.') + msg = 'Note cards have been revealed.\n' + for card_owner, card_msg in client.area.cards.items(): + msg += '{}: {}\n'.format(card_owner, card_msg) + client.area.cards.clear() + client.area.send_host_message(msg) + +def ooc_cmd_rolla_reload(client, arg): + if not client.is_mod: + raise ClientError('You must be a moderator to load the ability dice configuration.') + rolla_reload(client.area) + client.send_host_message('Reloaded ability dice configuration.') + +def rolla_reload(area): + try: + import yaml + with open('config/dice.yaml', 'r') as dice: + area.ability_dice = yaml.load(dice) + except: + raise ServerError('There was an error parsing the ability dice configuration. Check your syntax.') + +def ooc_cmd_rolla_set(client, arg): + if not hasattr(client.area, 'ability_dice'): + rolla_reload(client.area) + available_sets = ', '.join(client.area.ability_dice.keys()) + if len(arg) == 0: + raise ArgumentError('You must specify the ability set name.\nAvailable sets: {}'.format(available_sets)) + if arg in client.area.ability_dice: + client.ability_dice_set = arg + client.send_host_message("Set ability set to {}.".format(arg)) + else: + raise ArgumentError('Invalid ability set \'{}\'.\nAvailable sets: {}'.format(arg, available_sets)) + +def ooc_cmd_rolla(client, arg): + if not hasattr(client.area, 'ability_dice'): + rolla_reload(client.area) + if not hasattr(client, 'ability_dice_set'): + raise ClientError('You must set your ability set using /rolla_set .') + ability_dice = client.area.ability_dice[client.ability_dice_set] + max_roll = ability_dice['max'] if 'max' in ability_dice else 6 + roll = random.randint(1, max_roll) + ability = ability_dice[roll] if roll in ability_dice else "Nothing happens" + client.area.send_host_message( + '{} rolled a {} (out of {}): {}.'.format(client.get_char_name(), roll, max_roll, ability)) + +def ooc_cmd_refresh(client, arg): + if not client.is_mod: + raise ClientError('You must be authorized to do that.') + if len (arg) > 0: + raise ClientError('This command does not take in any arguments!') + else: + try: + client.server.refresh() + client.send_host_message('You have reloaded the server.') + except ServerError: + raise + +def ooc_cmd_judgelog(client, arg): + if not client.is_mod: + raise ClientError('You must be authorized to do that.') + if len(arg) != 0: + raise ArgumentError('This command does not take any arguments.') + jlog = client.area.judgelog + if len(jlog) > 0: + jlog_msg = '== Judge Log ==' + for x in jlog: + jlog_msg += '\r\n{}'.format(x) + client.send_host_message(jlog_msg) + else: + raise ServerError('There have been no judge actions in this area since start of session.') diff --git a/server/constants.py b/server/constants.py new file mode 100644 index 0000000..fa07e8e --- /dev/null +++ b/server/constants.py @@ -0,0 +1,11 @@ +from enum import Enum + +class TargetType(Enum): + #possible keys: ip, OOC, id, cname, ipid, hdid + IP = 0 + OOC_NAME = 1 + ID = 2 + CHAR_NAME = 3 + IPID = 4 + HDID = 5 + ALL = 6 \ No newline at end of file diff --git a/server/districtclient.py b/server/districtclient.py new file mode 100644 index 0000000..c766ba5 --- /dev/null +++ b/server/districtclient.py @@ -0,0 +1,79 @@ +# tsuserver3, an Attorney Online server +# +# Copyright (C) 2016 argoneus +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +import asyncio + +from server import logger + + +class DistrictClient: + def __init__(self, server): + self.server = server + self.reader = None + self.writer = None + self.message_queue = [] + + async def connect(self): + loop = asyncio.get_event_loop() + while True: + try: + self.reader, self.writer = await asyncio.open_connection(self.server.config['district_ip'], + self.server.config['district_port'], loop=loop) + await self.handle_connection() + except (ConnectionRefusedError, TimeoutError): + pass + except (ConnectionResetError, asyncio.IncompleteReadError): + self.writer = None + self.reader = None + finally: + logger.log_debug("Couldn't connect to the district, retrying in 30 seconds.") + await asyncio.sleep(30) + + async def handle_connection(self): + logger.log_debug('District connected.') + self.send_raw_message('AUTH#{}'.format(self.server.config['district_password'])) + while True: + data = await self.reader.readuntil(b'\r\n') + if not data: + return + raw_msg = data.decode()[:-2] + logger.log_debug('[DISTRICT][INC][RAW]{}'.format(raw_msg)) + cmd, *args = raw_msg.split('#') + if cmd == 'GLOBAL': + glob_name = '{}[{}:{}][{}]'.format('G', args[1], args[2], args[3]) + if args[0] == '1': + glob_name += '[M]' + self.server.send_all_cmd_pred('CT', glob_name, args[4], pred=lambda x: not x.muted_global) + elif cmd == 'NEED': + need_msg = '=== Cross Advert ===\r\n{} at {} in {} [{}] needs {}\r\n====================' \ + .format(args[1], args[0], args[2], args[3], args[4]) + self.server.send_all_cmd_pred('CT', '{}'.format(self.server.config['hostname']), need_msg, '1', + pred=lambda x: not x.muted_adverts) + + async def write_queue(self): + while self.message_queue: + msg = self.message_queue.pop(0) + try: + self.writer.write(msg) + await self.writer.drain() + except ConnectionResetError: + return + + def send_raw_message(self, msg): + if not self.writer: + return + self.message_queue.append('{}\r\n'.format(msg).encode()) + asyncio.ensure_future(self.write_queue(), loop=asyncio.get_event_loop()) diff --git a/server/evidence.py b/server/evidence.py new file mode 100644 index 0000000..b34172a --- /dev/null +++ b/server/evidence.py @@ -0,0 +1,100 @@ +class EvidenceList: + limit = 35 + + class Evidence: + def __init__(self, name, desc, image, pos): + self.name = name + self.desc = desc + self.image = image + self.public = False + self.pos = pos + + def set_name(self, name): + self.name = name + + def set_desc(self, desc): + self.desc = desc + + def set_image(self, image): + self.image = image + + def to_string(self): + sequence = (self.name, self.desc, self.image) + return '&'.join(sequence) + + def __init__(self): + self.evidences = [] + self.poses = {'def':['def', 'hld'], + 'pro':['pro', 'hlp'], + 'wit':['wit', 'sea'], + 'sea':['sea', 'wit'], + 'hlp':['hlp', 'pro'], + 'hld':['hld', 'def'], + 'jud':['jud', 'jur'], + 'jur':['jur', 'jud'], + 'all':['hlp', 'hld', 'wit', 'jud', 'pro', 'def', 'jur', 'sea', ''], + 'pos':[]} + + def login(self, client): + if client.area.evidence_mod == 'FFA': + pass + if client.area.evidence_mod == 'Mods': + if not client in client.area.owners: + return False + if client.area.evidence_mod == 'CM': + if not client in client.area.owners and not client.is_mod: + return False + if client.area.evidence_mod == 'HiddenCM': + if not client in client.area.owners and not client.is_mod: + return False + return True + + def correct_format(self, client, desc): + if client.area.evidence_mod != 'HiddenCM': + return True + else: + #correct format: \ndesc + if desc[:9] == '\n': + return True + return False + + + def add_evidence(self, client, name, description, image, pos = 'all'): + if self.login(client): + if client.area.evidence_mod == 'HiddenCM': + pos = 'pos' + if len(self.evidences) >= self.limit: + client.send_host_message('You can\'t have more than {} evidence items at a time.'.format(self.limit)) + else: + self.evidences.append(self.Evidence(name, description, image, pos)) + + def evidence_swap(self, client, id1, id2): + if self.login(client): + self.evidences[id1], self.evidences[id2] = self.evidences[id2], self.evidences[id1] + + def create_evi_list(self, client): + evi_list = [] + nums_list = [0] + for i in range(len(self.evidences)): + if client.area.evidence_mod == 'HiddenCM' and self.login(client): + nums_list.append(i + 1) + evi = self.evidences[i] + evi_list.append(self.Evidence(evi.name, '\n{}'.format(evi.pos, evi.desc), evi.image, evi.pos).to_string()) + elif client.pos in self.poses[self.evidences[i].pos]: + nums_list.append(i + 1) + evi_list.append(self.evidences[i].to_string()) + return nums_list, evi_list + + def del_evidence(self, client, id): + if self.login(client): + self.evidences.pop(id) + + def edit_evidence(self, client, id, arg): + if self.login(client): + if client.area.evidence_mod == 'HiddenCM' and self.correct_format(client, arg[1]): + self.evidences[id] = self.Evidence(arg[0], arg[1][14:], arg[2], arg[1][9:12]) + return + if client.area.evidence_mod == 'HiddenCM': + client.send_host_message('You entered a wrong pos.') + return + self.evidences[id] = self.Evidence(arg[0], arg[1], arg[2], arg[3]) \ No newline at end of file diff --git a/server/exceptions.py b/server/exceptions.py new file mode 100644 index 0000000..d3503e9 --- /dev/null +++ b/server/exceptions.py @@ -0,0 +1,32 @@ +# tsuserver3, an Attorney Online server +# +# Copyright (C) 2016 argoneus +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + + +class ClientError(Exception): + pass + + +class AreaError(Exception): + pass + + +class ArgumentError(Exception): + pass + + +class ServerError(Exception): + pass diff --git a/server/fantacrypt.py b/server/fantacrypt.py new file mode 100644 index 0000000..e31548e --- /dev/null +++ b/server/fantacrypt.py @@ -0,0 +1,45 @@ +# tsuserver3, an Attorney Online server +# +# Copyright (C) 2016 argoneus +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +# fantacrypt was a mistake, just hardcoding some numbers is good enough + +import binascii + +CRYPT_CONST_1 = 53761 +CRYPT_CONST_2 = 32618 +CRYPT_KEY = 5 + + +def fanta_decrypt(data): + data_bytes = [int(data[x:x + 2], 16) for x in range(0, len(data), 2)] + key = CRYPT_KEY + ret = '' + for byte in data_bytes: + val = byte ^ ((key & 0xffff) >> 8) + ret += chr(val) + key = ((byte + key) * CRYPT_CONST_1) + CRYPT_CONST_2 + return ret + + +def fanta_encrypt(data): + key = CRYPT_KEY + ret = '' + for char in data: + val = ord(char) ^ ((key & 0xffff) >> 8) + ret += binascii.hexlify(val.to_bytes(1, byteorder='big')).decode().upper() + key = ((val + key) * CRYPT_CONST_1) + CRYPT_CONST_2 + return ret diff --git a/server/logger.py b/server/logger.py new file mode 100644 index 0000000..fb1b8b3 --- /dev/null +++ b/server/logger.py @@ -0,0 +1,78 @@ +# tsuserver3, an Attorney Online server +# +# Copyright (C) 2016 argoneus +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +import logging + +import time + + +def setup_logger(debug): + logging.Formatter.converter = time.gmtime + debug_formatter = logging.Formatter('[%(asctime)s UTC]%(message)s') + srv_formatter = logging.Formatter('[%(asctime)s UTC]%(message)s') + mod_formatter = logging.Formatter('[%(asctime)s UTC]%(message)s') + + debug_log = logging.getLogger('debug') + debug_log.setLevel(logging.DEBUG) + + debug_handler = logging.FileHandler('logs/debug.log', encoding='utf-8') + debug_handler.setLevel(logging.DEBUG) + debug_handler.setFormatter(debug_formatter) + debug_log.addHandler(debug_handler) + + if not debug: + debug_log.disabled = True + + server_log = logging.getLogger('server') + server_log.setLevel(logging.INFO) + + server_handler = logging.FileHandler('logs/server.log', encoding='utf-8') + server_handler.setLevel(logging.INFO) + server_handler.setFormatter(srv_formatter) + server_log.addHandler(server_handler) + + mod_log = logging.getLogger('mod') + mod_log.setLevel(logging.INFO) + + mod_handler = logging.FileHandler('logs/mod.log', encoding='utf-8') + mod_handler.setLevel(logging.INFO) + mod_handler.setFormatter(mod_formatter) + mod_log.addHandler(mod_handler) + + +def log_debug(msg, client=None): + msg = parse_client_info(client) + msg + logging.getLogger('debug').debug(msg) + + +def log_server(msg, client=None): + msg = parse_client_info(client) + msg + logging.getLogger('server').info(msg) + + +def log_mod(msg, client=None): + msg = parse_client_info(client) + msg + logging.getLogger('mod').info(msg) + + +def parse_client_info(client): + if client is None: + return '' + info = client.get_ip() + if client.is_mod: + return '[{:<15}][{:<3}][{}][MOD]'.format(info, client.id, client.name) + return '[{:<15}][{:<3}][{}]'.format(info, client.id, client.name) diff --git a/server/masterserverclient.py b/server/masterserverclient.py new file mode 100644 index 0000000..49af043 --- /dev/null +++ b/server/masterserverclient.py @@ -0,0 +1,89 @@ +# tsuserver3, an Attorney Online server +# +# Copyright (C) 2016 argoneus +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + + +import asyncio +import time +from server import logger + + +class MasterServerClient: + def __init__(self, server): + self.server = server + self.reader = None + self.writer = None + + async def connect(self): + loop = asyncio.get_event_loop() + while True: + try: + self.reader, self.writer = await asyncio.open_connection(self.server.config['masterserver_ip'], + self.server.config['masterserver_port'], + loop=loop) + await self.handle_connection() + except (ConnectionRefusedError, TimeoutError): + pass + except (ConnectionResetError, asyncio.IncompleteReadError): + self.writer = None + self.reader = None + finally: + logger.log_debug("Couldn't connect to the master server, retrying in 30 seconds.") + print("Couldn't connect to the master server, retrying in 30 seconds.") + await asyncio.sleep(30) + + async def handle_connection(self): + logger.log_debug('Master server connected.') + await self.send_server_info() + fl = False + lastping = time.time() - 20 + while True: + self.reader.feed_data(b'END') + full_data = await self.reader.readuntil(b'END') + full_data = full_data[:-3] + if len(full_data) > 0: + data_list = list(full_data.split(b'#%'))[:-1] + for data in data_list: + raw_msg = data.decode() + cmd, *args = raw_msg.split('#') + if cmd != 'CHECK' and cmd != 'PONG': + logger.log_debug('[MASTERSERVER][INC][RAW]{}'.format(raw_msg)) + elif cmd == 'CHECK': + await self.send_raw_message('PING#%') + elif cmd == 'PONG': + fl = False + elif cmd == 'NOSERV': + await self.send_server_info() + if time.time() - lastping > 5: + if fl: + return + lastping = time.time() + fl = True + await self.send_raw_message('PING#%') + await asyncio.sleep(1) + + async def send_server_info(self): + cfg = self.server.config + msg = 'SCC#{}#{}#{}#{}#%'.format(cfg['port'], cfg['masterserver_name'], cfg['masterserver_description'], + self.server.software) + await self.send_raw_message(msg) + + async def send_raw_message(self, msg): + try: + self.writer.write(msg.encode()) + await self.writer.drain() + except ConnectionResetError: + return diff --git a/server/tsuserver.py b/server/tsuserver.py new file mode 100644 index 0000000..5af8161 --- /dev/null +++ b/server/tsuserver.py @@ -0,0 +1,305 @@ +# tsuserver3, an Attorney Online server +# +# Copyright (C) 2016 argoneus +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +import asyncio + +import yaml +import json + +from server import logger +from server.aoprotocol import AOProtocol +from server.area_manager import AreaManager +from server.ban_manager import BanManager +from server.client_manager import ClientManager +from server.districtclient import DistrictClient +from server.exceptions import ServerError +from server.masterserverclient import MasterServerClient + +class TsuServer3: + def __init__(self): + self.config = None + self.allowed_iniswaps = None + self.load_config() + self.load_iniswaps() + self.client_manager = ClientManager(self) + self.area_manager = AreaManager(self) + self.ban_manager = BanManager() + self.software = 'tsuserver3' + self.version = 'tsuserver3dev' + self.release = 3 + self.major_version = 1 + self.minor_version = 1 + self.ipid_list = {} + self.hdid_list = {} + self.char_list = None + self.char_pages_ao1 = None + self.music_list = None + self.music_list_ao2 = None + self.music_pages_ao1 = None + self.backgrounds = None + self.load_characters() + self.load_music() + self.load_backgrounds() + self.load_ids() + self.district_client = None + self.ms_client = None + self.rp_mode = False + logger.setup_logger(debug=self.config['debug']) + + def start(self): + loop = asyncio.get_event_loop() + + bound_ip = '0.0.0.0' + if self.config['local']: + bound_ip = '127.0.0.1' + + ao_server_crt = loop.create_server(lambda: AOProtocol(self), bound_ip, self.config['port']) + ao_server = loop.run_until_complete(ao_server_crt) + + if self.config['use_district']: + self.district_client = DistrictClient(self) + asyncio.ensure_future(self.district_client.connect(), loop=loop) + + if self.config['use_masterserver']: + self.ms_client = MasterServerClient(self) + asyncio.ensure_future(self.ms_client.connect(), loop=loop) + + logger.log_debug('Server started.') + + try: + loop.run_forever() + except KeyboardInterrupt: + pass + + logger.log_debug('Server shutting down.') + + ao_server.close() + loop.run_until_complete(ao_server.wait_closed()) + loop.close() + + def get_version_string(self): + return str(self.release) + '.' + str(self.major_version) + '.' + str(self.minor_version) + + def new_client(self, transport): + c = self.client_manager.new_client(transport) + if self.rp_mode: + c.in_rp = True + c.server = self + c.area = self.area_manager.default_area() + c.area.new_client(c) + return c + + def remove_client(self, client): + client.area.remove_client(client) + self.client_manager.remove_client(client) + + def get_player_count(self): + return len(self.client_manager.clients) + + def load_config(self): + with open('config/config.yaml', 'r', encoding = 'utf-8') as cfg: + self.config = yaml.load(cfg) + self.config['motd'] = self.config['motd'].replace('\\n', ' \n') + if 'music_change_floodguard' not in self.config: + self.config['music_change_floodguard'] = {'times_per_interval': 1, 'interval_length': 0, 'mute_length': 0} + if 'wtce_floodguard' not in self.config: + self.config['wtce_floodguard'] = {'times_per_interval': 1, 'interval_length': 0, 'mute_length': 0} + + def load_characters(self): + with open('config/characters.yaml', 'r', encoding = 'utf-8') as chars: + self.char_list = yaml.load(chars) + self.build_char_pages_ao1() + + def load_music(self): + with open('config/music.yaml', 'r', encoding = 'utf-8') as music: + self.music_list = yaml.load(music) + self.build_music_pages_ao1() + self.build_music_list_ao2() + + def load_ids(self): + self.ipid_list = {} + self.hdid_list = {} + #load ipids + try: + with open('storage/ip_ids.json', 'r', encoding = 'utf-8') as whole_list: + self.ipid_list = json.loads(whole_list.read()) + except: + logger.log_debug('Failed to load ip_ids.json from ./storage. If ip_ids.json is exist then remove it.') + #load hdids + try: + with open('storage/hd_ids.json', 'r', encoding = 'utf-8') as whole_list: + self.hdid_list = json.loads(whole_list.read()) + except: + logger.log_debug('Failed to load hd_ids.json from ./storage. If hd_ids.json is exist then remove it.') + + def dump_ipids(self): + with open('storage/ip_ids.json', 'w') as whole_list: + json.dump(self.ipid_list, whole_list) + + def dump_hdids(self): + with open('storage/hd_ids.json', 'w') as whole_list: + json.dump(self.hdid_list, whole_list) + + def get_ipid(self, ip): + if not (ip in self.ipid_list): + self.ipid_list[ip] = len(self.ipid_list) + self.dump_ipids() + return self.ipid_list[ip] + + def load_backgrounds(self): + with open('config/backgrounds.yaml', 'r', encoding = 'utf-8') as bgs: + self.backgrounds = yaml.load(bgs) + + def load_iniswaps(self): + try: + with open('config/iniswaps.yaml', 'r', encoding = 'utf-8') as iniswaps: + self.allowed_iniswaps = yaml.load(iniswaps) + except: + logger.log_debug('cannot find iniswaps.yaml') + + + def build_char_pages_ao1(self): + self.char_pages_ao1 = [self.char_list[x:x + 10] for x in range(0, len(self.char_list), 10)] + for i in range(len(self.char_list)): + self.char_pages_ao1[i // 10][i % 10] = '{}#{}&&0&&&0&'.format(i, self.char_list[i]) + + def build_music_pages_ao1(self): + self.music_pages_ao1 = [] + index = 0 + # add areas first + for area in self.area_manager.areas: + self.music_pages_ao1.append('{}#{}'.format(index, area.name)) + index += 1 + # then add music + for item in self.music_list: + self.music_pages_ao1.append('{}#{}'.format(index, item['category'])) + index += 1 + for song in item['songs']: + self.music_pages_ao1.append('{}#{}'.format(index, song['name'])) + index += 1 + self.music_pages_ao1 = [self.music_pages_ao1[x:x + 10] for x in range(0, len(self.music_pages_ao1), 10)] + + def build_music_list_ao2(self): + self.music_list_ao2 = [] + # add areas first + for area in self.area_manager.areas: + self.music_list_ao2.append(area.name) + # then add music + for item in self.music_list: + self.music_list_ao2.append(item['category']) + for song in item['songs']: + self.music_list_ao2.append(song['name']) + + def is_valid_char_id(self, char_id): + return len(self.char_list) > char_id >= 0 + + def get_char_id_by_name(self, name): + for i, ch in enumerate(self.char_list): + if ch.lower() == name.lower(): + return i + raise ServerError('Character not found.') + + def get_song_data(self, music): + for item in self.music_list: + if item['category'] == music: + return item['category'], -1 + for song in item['songs']: + if song['name'] == music: + try: + return song['name'], song['length'] + except KeyError: + return song['name'], -1 + raise ServerError('Music not found.') + + def send_all_cmd_pred(self, cmd, *args, pred=lambda x: True): + for client in self.client_manager.clients: + if pred(client): + client.send_command(cmd, *args) + + def broadcast_global(self, client, msg, as_mod=False): + char_name = client.get_char_name() + ooc_name = '{}[{}][{}]'.format('G', client.area.abbreviation, char_name) + if as_mod: + ooc_name += '[M]' + self.send_all_cmd_pred('CT', ooc_name, msg, pred=lambda x: not x.muted_global) + if self.config['use_district']: + self.district_client.send_raw_message( + 'GLOBAL#{}#{}#{}#{}'.format(int(as_mod), client.area.id, char_name, msg)) + + def send_modchat(self, client, msg): + name = client.name + ooc_name = '{}[{}][{}]'.format('M', client.area.abbreviation, name) + self.send_all_cmd_pred('CT', ooc_name, msg, pred=lambda x: x.is_mod) + if self.config['use_district']: + self.district_client.send_raw_message( + 'MODCHAT#{}#{}#{}'.format(client.area.id, char_name, msg)) + + def broadcast_need(self, client, msg): + char_name = client.get_char_name() + area_name = client.area.name + area_id = client.area.abbreviation + self.send_all_cmd_pred('CT', '{}'.format(self.config['hostname']), + ['=== Advert ===\r\n{} in {} [{}] needs {}\r\n===============' + .format(char_name, area_name, area_id, msg), '1'], pred=lambda x: not x.muted_adverts) + if self.config['use_district']: + self.district_client.send_raw_message('NEED#{}#{}#{}#{}'.format(char_name, area_name, area_id, msg)) + + def send_arup(self, args): + """ Updates the area properties on the Case Café Custom Client. + + Playercount: + ARUP#0###... + Status: + ARUP#1#####... + CM: + ARUP#2#####... + Lockedness: + ARUP#3#####... + + """ + if len(args) < 2: + # An argument count smaller than 2 means we only got the identifier of ARUP. + return + if args[0] not in (0,1,2,3): + return + + if args[0] == 0: + for part_arg in args[1:]: + try: + sanitised = int(part_arg) + except: + return + elif args[0] in (1, 2, 3): + for part_arg in args[1:]: + try: + sanitised = str(part_arg) + except: + return + + self.send_all_cmd_pred('ARUP', *args, pred=lambda x: True) + + def refresh(self): + with open('config/config.yaml', 'r') as cfg: + self.config['motd'] = yaml.load(cfg)['motd'].replace('\\n', ' \n') + with open('config/characters.yaml', 'r') as chars: + self.char_list = yaml.load(chars) + with open('config/music.yaml', 'r') as music: + self.music_list = yaml.load(music) + self.build_music_pages_ao1() + self.build_music_list_ao2() + with open('config/backgrounds.yaml', 'r') as bgs: + self.backgrounds = yaml.load(bgs) diff --git a/server/websocket.py b/server/websocket.py new file mode 100644 index 0000000..ba4258f --- /dev/null +++ b/server/websocket.py @@ -0,0 +1,215 @@ +# tsuserver3, an Attorney Online server +# +# Copyright (C) 2017 argoneus +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +# Partly authored by Johan Hanssen Seferidis (MIT license): +# https://github.com/Pithikos/python-websocket-server + +import asyncio +import re +import struct +from base64 import b64encode +from hashlib import sha1 + +from server import logger + + +class Bitmasks: + FIN = 0x80 + OPCODE = 0x0f + MASKED = 0x80 + PAYLOAD_LEN = 0x7f + PAYLOAD_LEN_EXT16 = 0x7e + PAYLOAD_LEN_EXT64 = 0x7f + + +class Opcode: + CONTINUATION = 0x0 + TEXT = 0x1 + BINARY = 0x2 + CLOSE_CONN = 0x8 + PING = 0x9 + PONG = 0xA + + +class WebSocket: + """ + State data for clients that are connected via a WebSocket that wraps + over a conventional TCP connection. + """ + + def __init__(self, client, protocol): + self.client = client + self.transport = client.transport + self.protocol = protocol + self.keep_alive = True + self.handshake_done = False + self.valid = False + + def handle(self, data): + if not self.handshake_done: + return self.handshake(data) + return self.parse(data) + + def parse(self, data): + b1, b2 = 0, 0 + if len(data) >= 2: + b1, b2 = data[0], data[1] + + fin = b1 & Bitmasks.FIN + opcode = b1 & Bitmasks.OPCODE + masked = b2 & Bitmasks.MASKED + payload_length = b2 & Bitmasks.PAYLOAD_LEN + + if not b1: + # Connection closed + self.keep_alive = 0 + return + if opcode == Opcode.CLOSE_CONN: + # Connection close requested + self.keep_alive = 0 + return + if not masked: + # Client was not masked (spec violation) + logger.log_debug("ws: client was not masked.", self.client) + self.keep_alive = 0 + print(data) + return + if opcode == Opcode.CONTINUATION: + # No continuation frames supported + logger.log_debug("ws: client tried to send continuation frame.", self.client) + return + elif opcode == Opcode.BINARY: + # No binary frames supported + logger.log_debug("ws: client tried to send binary frame.", self.client) + return + elif opcode == Opcode.TEXT: + def opcode_handler(s, msg): + return msg + elif opcode == Opcode.PING: + opcode_handler = self.send_pong + elif opcode == Opcode.PONG: + opcode_handler = lambda s, msg: None + else: + # Unknown opcode + logger.log_debug("ws: unknown opcode!", self.client) + self.keep_alive = 0 + return + + mask_offset = 2 + if payload_length == 126: + payload_length = struct.unpack(">H", data[2:4])[0] + mask_offset = 4 + elif payload_length == 127: + payload_length = struct.unpack(">Q", data[2:10])[0] + mask_offset = 10 + + masks = data[mask_offset:mask_offset + 4] + decoded = "" + for char in data[mask_offset + 4:payload_length + mask_offset + 4]: + char ^= masks[len(decoded) % 4] + decoded += chr(char) + + return opcode_handler(self, decoded) + + def send_message(self, message): + self.send_text(message) + + def send_pong(self, message): + self.send_text(message, Opcode.PONG) + + def send_text(self, message, opcode=Opcode.TEXT): + """ + Important: Fragmented (continuation) messages are not supported since + their usage cases are limited - when we don't know the payload length. + """ + + # Validate message + if isinstance(message, bytes): + message = message.decode("utf-8") + elif isinstance(message, str): + pass + else: + raise TypeError("Message must be either str or bytes") + + header = bytearray() + payload = message.encode("utf-8") + payload_length = len(payload) + + # Normal payload + if payload_length <= 125: + header.append(Bitmasks.FIN | opcode) + header.append(payload_length) + + # Extended payload + elif payload_length >= 126 and payload_length <= 65535: + header.append(Bitmasks.FIN | opcode) + header.append(Bitmasks.PAYLOAD_LEN_EXT16) + header.extend(struct.pack(">H", payload_length)) + + # Huge extended payload + elif payload_length < (1 << 64): + header.append(Bitmasks.FIN | opcode) + header.append(Bitmasks.PAYLOAD_LEN_EXT64) + header.extend(struct.pack(">Q", payload_length)) + + else: + raise Exception("Message is too big") + + self.transport.write(header + payload) + + def handshake(self, data): + try: + message = data[0:1024].decode().strip() + except UnicodeDecodeError: + return False + + upgrade = re.search('\nupgrade[\s]*:[\s]*websocket', message.lower()) + if not upgrade: + self.keep_alive = False + return False + + key = re.search('\n[sS]ec-[wW]eb[sS]ocket-[kK]ey[\s]*:[\s]*(.*)\r\n', message) + if key: + key = key.group(1) + else: + logger.log_debug("Client tried to connect but was missing a key", self.client) + self.keep_alive = False + return False + + response = self.make_handshake_response(key) + print(response.encode()) + self.transport.write(response.encode()) + self.handshake_done = True + self.valid = True + return True + + def make_handshake_response(self, key): + return \ + 'HTTP/1.1 101 Switching Protocols\r\n'\ + 'Upgrade: websocket\r\n' \ + 'Connection: Upgrade\r\n' \ + 'Sec-WebSocket-Accept: %s\r\n' \ + '\r\n' % self.calculate_response_key(key) + + def calculate_response_key(self, key): + GUID = '258EAFA5-E914-47DA-95CA-C5AB0DC85B11' + hash = sha1(key.encode() + GUID.encode()) + response_key = b64encode(hash.digest()).strip() + return response_key.decode('ASCII') + + def finish(self): + self.protocol.connection_lost(self) diff --git a/text_file_functions.cpp b/text_file_functions.cpp index 1aebc35..abdd94d 100644 --- a/text_file_functions.cpp +++ b/text_file_functions.cpp @@ -1,98 +1,72 @@ -#include "aoapplication.h" - -#include "file_functions.h" - -#include -#include -#include -#include -#include - -QString AOApplication::read_config(QString searchline) -{ - QString return_value = ""; - - QFile config_file(get_base_path() + "config.ini"); - if (!config_file.open(QIODevice::ReadOnly)) - return return_value; - - QTextStream in(&config_file); - - while(!in.atEnd()) - { - QString f_line = in.readLine().trimmed(); - - if (!f_line.startsWith(searchline)) - continue; - - QStringList line_elements = f_line.split("="); - - if (line_elements.at(0).trimmed() != searchline) - continue; - - if (line_elements.size() < 2) - continue; - - return_value = line_elements.at(1).trimmed(); - break; - } - - config_file.close(); - - return return_value; -} +#include "text_file_functions.h" QString AOApplication::read_theme() { - QString result = read_config("theme"); - - if (result == "") - return "default"; - else - return result; -} - -QString AOApplication::get_ooc_name() -{ - return read_config("ooc_name"); + QString result = configini->value("theme", "default").value(); + return result; } int AOApplication::read_blip_rate() { - QString result = read_config("blip_rate"); + int result = configini->value("blip_rate", 1).toInt(); + return result; +} - //note: the empty string converted to int will return 0 - if (result.toInt() <= 0) - return 1; - else - return result.toInt(); +QString AOApplication::get_ooc_name() +{ + QString result = configini->value("ooc_name").value(); + return result; } int AOApplication::get_default_music() { - QString f_result = read_config("default_music"); - - if (f_result == "") - return 50; - else return f_result.toInt(); + int result = configini->value("default_music", 50).toInt(); + return result; } int AOApplication::get_default_sfx() { - QString f_result = read_config("default_sfx"); - - if (f_result == "") - return 50; - else return f_result.toInt(); + int result = configini->value("default_sfx", 50).toInt(); + return result; } int AOApplication::get_default_blip() { - QString f_result = read_config("default_blip"); + int result = configini->value("default_blip", 50).toInt(); + return result; +} - if (f_result == "") - return 50; - else return f_result.toInt(); +int AOApplication::get_max_log_size() +{ + int result = configini->value("log_maximum", 200).toInt(); + return result; +} + +bool AOApplication::get_log_goes_downwards() +{ + QString result = configini->value("log_goes_downwards", "false").value(); + return result.startsWith("true"); +} + +bool AOApplication::get_showname_enabled_by_default() +{ + QString result = configini->value("show_custom_shownames", "false").value(); + return result.startsWith("true"); +} + +QString AOApplication::get_default_username() +{ + QString result = configini->value("default_username", "").value(); + if (result.isEmpty()) + return get_ooc_name(); + else + return result; +} + +QString AOApplication::get_audio_output_device() +{ + QString result = configini->value("default_audio_device", "default").value(); + return result; } QStringList AOApplication::get_call_words() @@ -174,40 +148,13 @@ QVector AOApplication::read_serverlist_txt() QString AOApplication::read_design_ini(QString p_identifier, QString p_design_path) { - QFile design_ini; - - design_ini.setFileName(p_design_path); - - if (!design_ini.open(QIODevice::ReadOnly)) - { - return ""; + QSettings settings(p_design_path, QSettings::IniFormat); + QVariant value = settings.value(p_identifier); + if (value.type() == QVariant::StringList) { + return value.toStringList().join(","); + } else { + return value.toString(); } - QTextStream in(&design_ini); - - QString result = ""; - - while (!in.atEnd()) - { - QString f_line = in.readLine().trimmed(); - - if (!f_line.startsWith(p_identifier)) - continue; - - QStringList line_elements = f_line.split("="); - - if (line_elements.at(0).trimmed() != p_identifier) - continue; - - if (line_elements.size() < 2) - continue; - - result = line_elements.at(1).trimmed(); - break; - } - - design_ini.close(); - - return result; } QPoint AOApplication::get_button_spacing(QString p_identifier, QString p_file) @@ -319,6 +266,34 @@ QColor AOApplication::get_color(QString p_identifier, QString p_file) return return_color; } +QColor AOApplication::get_chat_color(QString p_identifier, QString p_chat) +{ + p_identifier = p_identifier.prepend("c"); + QString design_ini_path = get_base_path() + "misc/" + p_chat + "/config.ini"; + QString default_path = get_base_path() + "misc/default/config.ini"; + QString f_result = read_design_ini(p_identifier, design_ini_path); + + QColor return_color(255, 255, 255); + if (f_result == "") + { + f_result = read_design_ini(p_identifier, default_path); + + if (f_result == "") + return return_color; + } + + QStringList color_list = f_result.split(","); + + if (color_list.size() < 3) + return return_color; + + return_color.setRed(color_list.at(0).toInt()); + return_color.setGreen(color_list.at(1).toInt()); + return_color.setBlue(color_list.at(2).toInt()); + + return return_color; +} + QString AOApplication::get_sfx(QString p_identifier) { QString design_ini_path = get_theme_path() + "courtroom_sounds.ini"; @@ -342,59 +317,18 @@ QString AOApplication::get_sfx(QString p_identifier) //returns whatever is to the right of "search_line =" within target_tag and terminator_tag, trimmed //returns the empty string if the search line couldnt be found -QString AOApplication::read_char_ini(QString p_char, QString p_search_line, QString target_tag, QString terminator_tag) +QString AOApplication::read_char_ini(QString p_char, QString p_search_line, QString target_tag) { - QString char_ini_path = get_character_path(p_char) + "char.ini"; - - QFile char_ini; - - char_ini.setFileName(char_ini_path); - - if (!char_ini.open(QIODevice::ReadOnly)) - return ""; - - QTextStream in(&char_ini); - - bool tag_found = false; - - while(!in.atEnd()) - { - QString line = in.readLine(); - - if (QString::compare(line, terminator_tag, Qt::CaseInsensitive) == 0) - break; - - if (line.startsWith(target_tag, Qt::CaseInsensitive)) - { - tag_found = true; - continue; - } - - if (!line.startsWith(p_search_line, Qt::CaseInsensitive)) - continue; - - QStringList line_elements = line.split("="); - - if (QString::compare(line_elements.at(0).trimmed(), p_search_line, Qt::CaseInsensitive) != 0) - continue; - - if (line_elements.size() < 2) - continue; - - if (tag_found) - { - char_ini.close(); - return line_elements.at(1).trimmed(); - } - } - - char_ini.close(); - return ""; + QSettings settings(get_character_path(p_char) + "char.ini", QSettings::IniFormat); + settings.beginGroup(target_tag); + QString value = settings.value(p_search_line).toString(); + settings.endGroup(); + return value; } QString AOApplication::get_char_name(QString p_char) { - QString f_result = read_char_ini(p_char, "name", "[Options]", "[Time]"); + QString f_result = read_char_ini(p_char, "name", "Options"); if (f_result == "") return p_char; @@ -403,8 +337,11 @@ QString AOApplication::get_char_name(QString p_char) QString AOApplication::get_showname(QString p_char) { - QString f_result = read_char_ini(p_char, "showname", "[Options]", "[Time]"); + QString f_result = read_char_ini(p_char, "showname", "Options"); + QString f_needed = read_char_ini(p_char, "needs_showname", "Options"); + if (f_needed.startsWith("false")) + return ""; if (f_result == "") return p_char; else return f_result; @@ -412,7 +349,7 @@ QString AOApplication::get_showname(QString p_char) QString AOApplication::get_char_side(QString p_char) { - QString f_result = read_char_ini(p_char, "side", "[Options]", "[Time]"); + QString f_result = read_char_ini(p_char, "side", "Options"); if (f_result == "") return "wit"; @@ -421,7 +358,7 @@ QString AOApplication::get_char_side(QString p_char) QString AOApplication::get_gender(QString p_char) { - QString f_result = read_char_ini(p_char, "gender", "[Options]", "[Time]"); + QString f_result = read_char_ini(p_char, "gender", "Options"); if (f_result == "") return "male"; @@ -430,7 +367,7 @@ QString AOApplication::get_gender(QString p_char) QString AOApplication::get_chat(QString p_char) { - QString f_result = read_char_ini(p_char, "chat", "[Options]", "[Time]"); + QString f_result = read_char_ini(p_char, "chat", "Options"); //handling the correct order of chat is a bit complicated, we let the caller do it return f_result.toLower(); @@ -438,14 +375,14 @@ QString AOApplication::get_chat(QString p_char) QString AOApplication::get_char_shouts(QString p_char) { - QString f_result = read_char_ini(p_char, "shouts", "[Options]", "[Time]"); + QString f_result = read_char_ini(p_char, "shouts", "Options"); return f_result.toLower(); } int AOApplication::get_preanim_duration(QString p_char, QString p_emote) { - QString f_result = read_char_ini(p_char, p_emote, "[Time]", "[Emotions]"); + QString f_result = read_char_ini(p_char, p_emote, "Time"); if (f_result == "") return -1; @@ -454,7 +391,7 @@ int AOApplication::get_preanim_duration(QString p_char, QString p_emote) int AOApplication::get_ao2_preanim_duration(QString p_char, QString p_emote) { - QString f_result = read_char_ini(p_char, "%" + p_emote, "[Time]", "[Emotions]"); + QString f_result = read_char_ini(p_char, "%" + p_emote, "Time"); if (f_result == "") return -1; @@ -463,7 +400,7 @@ int AOApplication::get_ao2_preanim_duration(QString p_char, QString p_emote) int AOApplication::get_emote_number(QString p_char) { - QString f_result = read_char_ini(p_char, "number", "[Emotions]", "[SoundN]"); + QString f_result = read_char_ini(p_char, "number", "Emotions"); if (f_result == "") return 0; @@ -472,7 +409,7 @@ int AOApplication::get_emote_number(QString p_char) QString AOApplication::get_emote_comment(QString p_char, int p_emote) { - QString f_result = read_char_ini(p_char, QString::number(p_emote + 1), "[Emotions]", "[SoundN]"); + QString f_result = read_char_ini(p_char, QString::number(p_emote + 1), "Emotions"); QStringList result_contents = f_result.split("#"); @@ -486,7 +423,7 @@ QString AOApplication::get_emote_comment(QString p_char, int p_emote) QString AOApplication::get_pre_emote(QString p_char, int p_emote) { - QString f_result = read_char_ini(p_char, QString::number(p_emote + 1), "[Emotions]", "[SoundN]"); + QString f_result = read_char_ini(p_char, QString::number(p_emote + 1), "Emotions"); QStringList result_contents = f_result.split("#"); @@ -500,7 +437,7 @@ QString AOApplication::get_pre_emote(QString p_char, int p_emote) QString AOApplication::get_emote(QString p_char, int p_emote) { - QString f_result = read_char_ini(p_char, QString::number(p_emote + 1), "[Emotions]", "[SoundN]"); + QString f_result = read_char_ini(p_char, QString::number(p_emote + 1), "Emotions"); QStringList result_contents = f_result.split("#"); @@ -514,7 +451,7 @@ QString AOApplication::get_emote(QString p_char, int p_emote) int AOApplication::get_emote_mod(QString p_char, int p_emote) { - QString f_result = read_char_ini(p_char, QString::number(p_emote + 1), "[Emotions]", "[SoundN]"); + QString f_result = read_char_ini(p_char, QString::number(p_emote + 1), "Emotions"); QStringList result_contents = f_result.split("#"); @@ -528,7 +465,7 @@ int AOApplication::get_emote_mod(QString p_char, int p_emote) int AOApplication::get_desk_mod(QString p_char, int p_emote) { - QString f_result = read_char_ini(p_char, QString::number(p_emote + 1), "[Emotions]", "[SoundN]"); + QString f_result = read_char_ini(p_char, QString::number(p_emote + 1), "Emotions"); QStringList result_contents = f_result.split("#"); @@ -544,7 +481,7 @@ int AOApplication::get_desk_mod(QString p_char, int p_emote) QString AOApplication::get_sfx_name(QString p_char, int p_emote) { - QString f_result = read_char_ini(p_char, QString::number(p_emote + 1), "[SoundN]", "[SoundT]"); + QString f_result = read_char_ini(p_char, QString::number(p_emote + 1), "SoundN"); if (f_result == "") return "1"; @@ -553,7 +490,7 @@ QString AOApplication::get_sfx_name(QString p_char, int p_emote) int AOApplication::get_sfx_delay(QString p_char, int p_emote) { - QString f_result = read_char_ini(p_char, QString::number(p_emote + 1), "[SoundT]", "[TextDelay]"); + QString f_result = read_char_ini(p_char, QString::number(p_emote + 1), "SoundT"); if (f_result == "") return 1; @@ -562,28 +499,78 @@ int AOApplication::get_sfx_delay(QString p_char, int p_emote) int AOApplication::get_text_delay(QString p_char, QString p_emote) { - QString f_result = read_char_ini(p_char, p_emote, "[TextDelay]", "END_OF_FILE"); + QString f_result = read_char_ini(p_char, p_emote, "TextDelay"); if (f_result == "") return -1; else return f_result.toInt(); } +QString AOApplication::get_custom_realization(QString p_char) +{ + QString f_result = read_char_ini(p_char, "realization", "Options"); + + if (f_result == "") + return get_sfx("realization"); + else return f_result; +} + bool AOApplication::get_blank_blip() { - QString f_result = read_config("blank_blip"); - - return f_result.startsWith("true"); + QString result = configini->value("blank_blip", "false").value(); + return result.startsWith("true"); } bool AOApplication::is_discord_enabled() { - QString f_result = read_config("discord"); - return !f_result.startsWith("false"); + QString result = configini->value("discord", "true").value(); + return result.startsWith("true"); } -bool AOApplication::ic_scroll_down_enabled() +bool AOApplication::get_casing_enabled() { - QString f_result = read_config("ic_scroll_down"); - return f_result.startsWith("true"); -} \ No newline at end of file + QString result = configini->value("casing_enabled", "false").value(); + return result.startsWith("true"); +} + +bool AOApplication::get_casing_defence_enabled() +{ + QString result = configini->value("casing_defence_enabled", "false").value(); + return result.startsWith("true"); +} + +bool AOApplication::get_casing_prosecution_enabled() +{ + QString result = configini->value("casing_prosecution_enabled", "false").value(); + return result.startsWith("true"); +} + +bool AOApplication::get_casing_judge_enabled() +{ + QString result = configini->value("casing_judge_enabled", "false").value(); + return result.startsWith("true"); +} + +bool AOApplication::get_casing_juror_enabled() +{ + QString result = configini->value("casing_juror_enabled", "false").value(); + return result.startsWith("true"); +} + +bool AOApplication::get_casing_steno_enabled() +{ + QString result = configini->value("casing_steno_enabled", "false").value(); + return result.startsWith("true"); +} + +bool AOApplication::get_casing_cm_enabled() +{ + QString result = configini->value("casing_cm_enabled", "false").value(); + return result.startsWith("true"); +} + +QString AOApplication::get_casing_can_host_cases() +{ + QString result = configini->value("casing_can_host_casees", "Turnabout Check Your Settings").value(); + return result; +} diff --git a/text_file_functions.h b/text_file_functions.h new file mode 100644 index 0000000..119f38e --- /dev/null +++ b/text_file_functions.h @@ -0,0 +1,13 @@ +#ifndef TEXT_FILE_FUNCTIONS_H +#define TEXT_FILE_FUNCTIONS_H + +#include "aoapplication.h" +#include "file_functions.h" +#include +#include +#include +#include +#include +#include + +#endif // TEXT_FILE_FUNCTIONS_H