From c5c29673c56a6745d9fb0b553f452fdd49aed882 Mon Sep 17 00:00:00 2001 From: Cerapter Date: Thu, 26 Jul 2018 14:41:14 +0200 Subject: [PATCH 001/174] Gitignore updated. --- .gitignore | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.gitignore b/.gitignore index 9a949cb..969523a 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,12 @@ base_override.h base-full/ bass.lib + +bins/ + +.qmake.stash + +Makefile* +object_script* +/Attorney_Online_remake_resource.rc +/attorney_online_remake_plugin_import.cpp From 5b0485965779abcdfd04b9a64849e52becacb810 Mon Sep 17 00:00:00 2001 From: Cerapter Date: Thu, 26 Jul 2018 14:41:59 +0200 Subject: [PATCH 002/174] Renamed window title. --- lobby.cpp | 2 +- packet_distribution.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lobby.cpp b/lobby.cpp index 13ef550..e68fdfb 100644 --- a/lobby.cpp +++ b/lobby.cpp @@ -12,7 +12,7 @@ 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); diff --git a/packet_distribution.cpp b/packet_distribution.cpp index 3908ffa..6e94f41 100644 --- a/packet_distribution.cpp +++ b/packet_distribution.cpp @@ -224,7 +224,7 @@ void AOApplication::server_packet_received(AOPacket *p_packet) 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 = ""; From 7b34f426e28ae72ef32abdd21d7505fad2200f2d Mon Sep 17 00:00:00 2001 From: Cerapter Date: Thu, 26 Jul 2018 14:42:32 +0200 Subject: [PATCH 003/174] Read log limit maximum from config.ini. --- aoapplication.h | 4 ++++ text_file_functions.cpp | 9 +++++++++ 2 files changed, 13 insertions(+) diff --git a/aoapplication.h b/aoapplication.h index 2a5c436..eb518f3 100644 --- a/aoapplication.h +++ b/aoapplication.h @@ -129,6 +129,10 @@ public: //Returns the value of default_blip in config.ini int get_default_blip(); + //Returns the value of the maximum amount of lines the IC chatlog + //may contain, from config.ini. + int get_max_log_size(); + //Returns the list of words in callwords.ini QStringList get_call_words(); diff --git a/text_file_functions.cpp b/text_file_functions.cpp index 90b10f5..f35de91 100644 --- a/text_file_functions.cpp +++ b/text_file_functions.cpp @@ -90,6 +90,15 @@ int AOApplication::get_default_blip() else return f_result.toInt(); } +int AOApplication::get_max_log_size() +{ + QString f_result = read_config("log_maximum"); + + if (f_result == "") + return 200; + else return f_result.toInt(); +} + QStringList AOApplication::get_call_words() { QStringList return_value; From f113f8fae8a258c5fa76f7d025bdb0c30d758fd8 Mon Sep 17 00:00:00 2001 From: Cerapter Date: Thu, 26 Jul 2018 14:46:02 +0200 Subject: [PATCH 004/174] Added a bunch of features. - The IC chatlog now goes from top to bottom. - The same chatlog can be set to a limit by putting 'log_maximum = 100', for example, into the config.ini file. - Reloading the theme checks for the log limit again. - If a message starts with '~~' (two tildes), it'll be centered (for testimony title usage). - Inline colour options: - Text between {curly braces} will appear orange. - Text between (parentheses) will appear blue. - Text between $dollar signs$ will appear green. - The symbols can still be got by putting a '\' in front of them. - I.e.: \{, \}, \(, \), \$, \\ --- courtroom.cpp | 140 +++++++++++++++++++++++++++++++++++++++++++++++--- courtroom.h | 22 ++++++++ 2 files changed, 154 insertions(+), 8 deletions(-) diff --git a/courtroom.cpp b/courtroom.cpp index ca94f43..decb772 100644 --- a/courtroom.cpp +++ b/courtroom.cpp @@ -83,6 +83,7 @@ Courtroom::Courtroom(AOApplication *p_ao_app) : QMainWindow() ui_ic_chatlog = new QTextEdit(this); ui_ic_chatlog->setReadOnly(true); + ui_ic_chatlog->document()->setMaximumBlockCount(ao_app->get_max_log_size()); ui_ms_chatlog = new AOTextArea(this); ui_ms_chatlog->setReadOnly(true); @@ -1039,6 +1040,25 @@ void Courtroom::handle_chatmessage_2() 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) @@ -1156,14 +1176,22 @@ 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(); - const bool is_scrolled_up = old_scrollbar_value == ui_ic_chatlog->verticalScrollBar()->minimum(); + const bool is_scrolled_down = old_scrollbar_value == ui_ic_chatlog->verticalScrollBar()->maximum(); - ui_ic_chatlog->moveCursor(QTextCursor::Start); + ui_ic_chatlog->moveCursor(QTextCursor::End); - ui_ic_chatlog->textCursor().insertText(p_name, bold); - ui_ic_chatlog->textCursor().insertText(p_text + '\n', normal); + 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 (old_cursor.hasSelection() || !is_scrolled_up) + if (old_cursor.hasSelection() || !is_scrolled_down) { // The user has selected text or scrolled away from the top: maintain position. ui_ic_chatlog->setTextCursor(old_cursor); @@ -1172,8 +1200,8 @@ void Courtroom::append_ic_text(QString p_text, QString p_name) 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()); + ui_ic_chatlog->moveCursor(QTextCursor::End); + ui_ic_chatlog->verticalScrollBar()->setValue(ui_ic_chatlog->verticalScrollBar()->maximum()); } } @@ -1238,6 +1266,13 @@ 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; @@ -1301,8 +1336,94 @@ void Courtroom::chat_tick() ui_vp_message->insertHtml("" + f_character + ""); } + + else if (f_character == "\\" and !next_character_is_not_special) + { + next_character_is_not_special = true; + } + + else if (f_character == "{" and !next_character_is_not_special) + { + inline_colour_stack.push(INLINE_ORANGE); + } + else if (f_character == "}" and !next_character_is_not_special + and !inline_colour_stack.empty()) + { + if (inline_colour_stack.top() == INLINE_ORANGE) + { + inline_colour_stack.pop(); + } + } + + else if (f_character == "(" and !next_character_is_not_special) + { + inline_colour_stack.push(INLINE_BLUE); + 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_BLUE) + { + inline_colour_stack.pop(); + ui_vp_message->insertHtml("" + f_character + ""); + } + } + + 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(); + } + else + { + inline_colour_stack.push(INLINE_GREEN); + } + } + else + { + inline_colour_stack.push(INLINE_GREEN); + } + } + 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; + 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()); @@ -1975,6 +2096,9 @@ void Courtroom::on_reload_theme_clicked() { ao_app->reload_theme(); + //Refresh IC chat limits. + ui_ic_chatlog->document()->setMaximumBlockCount(ao_app->get_max_log_size()); + //to update status on the background set_background(current_background); enter_courtroom(m_cid); diff --git a/courtroom.h b/courtroom.h index 85554a0..a4e08df 100644 --- a/courtroom.h +++ b/courtroom.h @@ -32,6 +32,8 @@ #include #include +#include + class AOApplication; class Courtroom : public QMainWindow @@ -147,6 +149,26 @@ 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 + }; + + // A stack of inline colours. + std::stack inline_colour_stack; + + bool centre_text = false; + + bool next_character_is_not_special = false; // If true, write the + // next character as it is. + + bool message_is_centered = false; + QVector char_list; QVector evidence_list; QVector music_list; From 958643505b2ab9cfa601f3d2d035579fbab6c747 Mon Sep 17 00:00:00 2001 From: Cerapter Date: Thu, 26 Jul 2018 20:30:43 +0200 Subject: [PATCH 005/174] IC chatlog filtering with awful code-duplication. --- courtroom.cpp | 91 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 91 insertions(+) diff --git a/courtroom.cpp b/courtroom.cpp index decb772..460c95c 100644 --- a/courtroom.cpp +++ b/courtroom.cpp @@ -1180,6 +1180,96 @@ void Courtroom::append_ic_text(QString p_text, QString p_name) ui_ic_chatlog->moveCursor(QTextCursor::End); + // Get rid of centering. + if(p_text.startsWith(": ~~")) + { + // Don't forget, the p_text part actually everything after the name! + // Hence why we check for ': ~~'. + + // If the user decided to put a space after the two tildes, remove that + // in one go. + p_text.remove("~~ "); + + // Remove all remaining ~~s. + p_text.remove("~~"); + } + + // 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); + if (f_character == "\\" and !ic_next_is_not_special) + { + ic_next_is_not_special = true; + p_text.remove(trick_check_pos,1); + } + + else if (f_character == "{" and !ic_next_is_not_special) + { + ic_colour_stack.push(INLINE_ORANGE); + p_text.remove(trick_check_pos,1); + } + else if (f_character == "}" and !ic_next_is_not_special + and !ic_colour_stack.empty()) + { + if (ic_colour_stack.top() == INLINE_ORANGE) + { + ic_colour_stack.pop(); + p_text.remove(trick_check_pos,1); + } + } + + else if (f_character == "(" and !ic_next_is_not_special) + { + ic_colour_stack.push(INLINE_BLUE); + p_text.remove(trick_check_pos,1); + } + 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(); + p_text.remove(trick_check_pos,1); + } + } + + 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 (!first_message_sent) { ui_ic_chatlog->textCursor().insertText(p_name, bold); @@ -1189,6 +1279,7 @@ void Courtroom::append_ic_text(QString p_text, QString p_name) { ui_ic_chatlog->textCursor().insertText('\n' + p_name, bold); } + ui_ic_chatlog->textCursor().insertText(p_text, normal); if (old_cursor.hasSelection() || !is_scrolled_down) From 68f6d5e27ae1cce6c576902f5209333b6f26eb36 Mon Sep 17 00:00:00 2001 From: Cerapter Date: Thu, 26 Jul 2018 22:20:48 +0200 Subject: [PATCH 006/174] Changed the green inline colour's symbol to backwards apostrophe. --- courtroom.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/courtroom.cpp b/courtroom.cpp index 460c95c..0818fca 100644 --- a/courtroom.cpp +++ b/courtroom.cpp @@ -1240,7 +1240,7 @@ void Courtroom::append_ic_text(QString p_text, QString p_name) } } - else if (f_character == "$" and !ic_next_is_not_special) + else if (f_character == "`" and !ic_next_is_not_special) { if (!ic_colour_stack.empty()) { @@ -1461,7 +1461,7 @@ void Courtroom::chat_tick() } } - else if (f_character == "$" and !next_character_is_not_special) + else if (f_character == "`" and !next_character_is_not_special) { if (!inline_colour_stack.empty()) { From 5aacfa8b486d6dcb9c8dee35605b1ec13c49a27a Mon Sep 17 00:00:00 2001 From: Cerapter Date: Thu, 26 Jul 2018 22:23:31 +0200 Subject: [PATCH 007/174] Fixed the parenthesis bug. --- courtroom.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/courtroom.cpp b/courtroom.cpp index 0818fca..984109d 100644 --- a/courtroom.cpp +++ b/courtroom.cpp @@ -1228,7 +1228,6 @@ void Courtroom::append_ic_text(QString p_text, QString p_name) else if (f_character == "(" and !ic_next_is_not_special) { ic_colour_stack.push(INLINE_BLUE); - p_text.remove(trick_check_pos,1); } else if (f_character == ")" and !ic_next_is_not_special and !ic_colour_stack.empty()) @@ -1236,7 +1235,6 @@ void Courtroom::append_ic_text(QString p_text, QString p_name) if (ic_colour_stack.top() == INLINE_BLUE) { ic_colour_stack.pop(); - p_text.remove(trick_check_pos,1); } } From 8c81a88e13560b08b5bac69f63a94800f9e42597 Mon Sep 17 00:00:00 2001 From: Cerapter Date: Thu, 26 Jul 2018 23:19:32 +0200 Subject: [PATCH 008/174] Fixed a bug with inline blue, added whispering. Furthermore, there are no longer any checks on the yellow and the rainbow colours, they are available from the getgo. --- courtroom.cpp | 55 ++++++++++++++++++++++++++++++++++++++++++++++----- courtroom.h | 3 ++- 2 files changed, 52 insertions(+), 6 deletions(-) diff --git a/courtroom.cpp b/courtroom.cpp index 984109d..3ea8793 100644 --- a/courtroom.cpp +++ b/courtroom.cpp @@ -174,8 +174,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("Purple"); ui_music_slider = new QSlider(Qt::Horizontal, this); ui_music_slider->setRange(0, 100); @@ -906,7 +908,7 @@ 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); @@ -1228,6 +1230,7 @@ void Courtroom::append_ic_text(QString p_text, QString p_name) 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()) @@ -1235,6 +1238,22 @@ void Courtroom::append_ic_text(QString p_text, QString p_name) if (ic_colour_stack.top() == INLINE_BLUE) { ic_colour_stack.pop(); + trick_check_pos++; + } + } + + 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++; } } @@ -1459,6 +1478,21 @@ void Courtroom::chat_tick() } } + 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 if (f_character == "`" and !next_character_is_not_special) { if (!inline_colour_stack.empty()) @@ -1493,6 +1527,9 @@ void Courtroom::chat_tick() 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; @@ -1674,6 +1711,14 @@ void Courtroom::set_text_color() ui_vp_message->setStyleSheet("background-color: rgba(0, 0, 0, 0);" "color: yellow"); break; + case PINK: + ui_vp_message->setStyleSheet("background-color: rgba(0, 0, 0, 0);" + "color: pink"); + break; + case PURPLE: + ui_vp_message->setStyleSheet("background-color: rgba(0, 0, 0, 0);" + "color: purple"); + break; default: qDebug() << "W: undefined text color: " << m_chatmessage[TEXT_COLOR]; case WHITE: @@ -1827,9 +1872,9 @@ void Courtroom::on_ooc_return_pressed() ui_guard->show(); 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; + //rainbow_appended = true; return; } diff --git a/courtroom.h b/courtroom.h index a4e08df..e1a32f0 100644 --- a/courtroom.h +++ b/courtroom.h @@ -156,7 +156,8 @@ private: enum INLINE_COLOURS { INLINE_BLUE, INLINE_GREEN, - INLINE_ORANGE + INLINE_ORANGE, + INLINE_GREY }; // A stack of inline colours. From 06bf4df1563954d99420e114a239119d10ff7632 Mon Sep 17 00:00:00 2001 From: Cerapter Date: Thu, 26 Jul 2018 23:19:41 +0200 Subject: [PATCH 009/174] Prepared alternate colours. --- datatypes.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/datatypes.h b/datatypes.h index 37d3e99..4439107 100644 --- a/datatypes.h +++ b/datatypes.h @@ -103,7 +103,9 @@ enum COLOR ORANGE, BLUE, YELLOW, - RAINBOW + RAINBOW, + PINK, + PURPLE }; #endif // DATATYPES_H From a8205986a4592056f2445f3b104e45a84f674ba9 Mon Sep 17 00:00:00 2001 From: Cerapter Date: Thu, 26 Jul 2018 23:35:21 +0200 Subject: [PATCH 010/174] Orange is now |, comments for text features. --- courtroom.cpp | 58 ++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 41 insertions(+), 17 deletions(-) diff --git a/courtroom.cpp b/courtroom.cpp index 3ea8793..24b63cd 100644 --- a/courtroom.cpp +++ b/courtroom.cpp @@ -1206,27 +1206,38 @@ void Courtroom::append_ic_text(QString p_text, QString p_name) 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); } - else if (f_character == "{" and !ic_next_is_not_special) + // Orange inline colourisation. + else if (f_character == "|" and !ic_next_is_not_special) { - ic_colour_stack.push(INLINE_ORANGE); - p_text.remove(trick_check_pos,1); - } - else if (f_character == "}" and !ic_next_is_not_special - and !ic_colour_stack.empty()) - { - if (ic_colour_stack.top() == INLINE_ORANGE) + if (!ic_colour_stack.empty()) { - ic_colour_stack.pop(); + 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); @@ -1242,6 +1253,7 @@ void Courtroom::append_ic_text(QString p_text, QString p_name) } } + // Grey inline colourisation. else if (f_character == "[" and !ic_next_is_not_special) { ic_colour_stack.push(INLINE_GREY); @@ -1257,6 +1269,7 @@ void Courtroom::append_ic_text(QString p_text, QString p_name) } } + // Green inline colourisation. else if (f_character == "`" and !ic_next_is_not_special) { if (!ic_colour_stack.empty()) @@ -1445,24 +1458,33 @@ 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; } - else if (f_character == "{" and !next_character_is_not_special) + // Orange inline colourisation. + else if (f_character == "|" and !next_character_is_not_special) { - inline_colour_stack.push(INLINE_ORANGE); - } - else if (f_character == "}" and !next_character_is_not_special - and !inline_colour_stack.empty()) - { - if (inline_colour_stack.top() == INLINE_ORANGE) + if (!inline_colour_stack.empty()) { - inline_colour_stack.pop(); + 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); } } + // Blue inline colourisation. else if (f_character == "(" and !next_character_is_not_special) { inline_colour_stack.push(INLINE_BLUE); @@ -1478,6 +1500,7 @@ void Courtroom::chat_tick() } } + // Grey inline colourisation. else if (f_character == "[" and !next_character_is_not_special) { inline_colour_stack.push(INLINE_GREY); @@ -1493,6 +1516,7 @@ void Courtroom::chat_tick() } } + // Green inline colourisation. else if (f_character == "`" and !next_character_is_not_special) { if (!inline_colour_stack.empty()) From 3295e5a78e55e1cc11b6ee705fff3ca54c2a02f6 Mon Sep 17 00:00:00 2001 From: Cerapter Date: Thu, 26 Jul 2018 23:51:47 +0200 Subject: [PATCH 011/174] Text speed modifier. - 7 different speeds. - `{` turns the speed down. - `}` turns the speed up! --- courtroom.cpp | 44 ++++++++++++++++++++++++++++++++++++++++++-- courtroom.h | 5 ++++- 2 files changed, 46 insertions(+), 3 deletions(-) diff --git a/courtroom.cpp b/courtroom.cpp index 24b63cd..264192d 100644 --- a/courtroom.cpp +++ b/courtroom.cpp @@ -1214,6 +1214,16 @@ void Courtroom::append_ic_text(QString p_text, QString p_name) 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) { @@ -1398,7 +1408,10 @@ void Courtroom::start_chat_ticking() tick_pos = 0; blip_pos = 0; - chat_tick_timer->start(chat_tick_interval); + + // 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]); @@ -1415,10 +1428,12 @@ 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(); + 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]); } @@ -1464,6 +1479,17 @@ void Courtroom::chat_tick() next_character_is_not_special = true; } + // Text speed modifier. + else if (f_character == "{" and !next_character_is_not_special) + { + // ++, because it INCREASES delay! + current_display_speed++; + } + else if (f_character == "}" and !next_character_is_not_special) + { + current_display_speed--; + } + // Orange inline colourisation. else if (f_character == "|" and !next_character_is_not_special) { @@ -1594,6 +1620,20 @@ 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; + } + + chat_tick_timer->start(message_display_speed[current_display_speed]); } } diff --git a/courtroom.h b/courtroom.h index e1a32f0..35171b4 100644 --- a/courtroom.h +++ b/courtroom.h @@ -170,6 +170,9 @@ private: bool message_is_centered = false; + int current_display_speed = 3; + int message_display_speed[7] = {30, 40, 50, 60, 75, 100, 120}; + QVector char_list; QVector evidence_list; QVector music_list; @@ -181,7 +184,7 @@ private: //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 From 977a88a2672ff9bd6ebec8b29eb37f7a120c1e1f Mon Sep 17 00:00:00 2001 From: Cerapter Date: Fri, 27 Jul 2018 22:06:09 +0200 Subject: [PATCH 012/174] Ability to set a default username added. - Done by adding a `default_username = whatever` to your `config.ini`. - `whatever` can be any string. - If nothing is given, it defaults to the, uh, default nothing. --- aoapplication.h | 3 +++ courtroom.cpp | 2 ++ text_file_functions.cpp | 6 ++++++ 3 files changed, 11 insertions(+) diff --git a/aoapplication.h b/aoapplication.h index eb518f3..947bb1d 100644 --- a/aoapplication.h +++ b/aoapplication.h @@ -133,6 +133,9 @@ public: //may contain, from config.ini. int get_max_log_size(); + // Returns the username the user may have set in config.ini. + QString get_default_username(); + //Returns the list of words in callwords.ini QStringList get_call_words(); diff --git a/courtroom.cpp b/courtroom.cpp index 264192d..d3e3728 100644 --- a/courtroom.cpp +++ b/courtroom.cpp @@ -111,6 +111,8 @@ Courtroom::Courtroom(AOApplication *p_ao_app) : QMainWindow() ui_ooc_chat_name->setFrame(false); ui_ooc_chat_name->setPlaceholderText("Name"); + ui_ooc_chat_name->setText(p_ao_app->get_default_username()); + //ui_area_password = new QLineEdit(this); //ui_area_password->setFrame(false); ui_music_search = new QLineEdit(this); diff --git a/text_file_functions.cpp b/text_file_functions.cpp index f35de91..db858cb 100644 --- a/text_file_functions.cpp +++ b/text_file_functions.cpp @@ -99,6 +99,12 @@ int AOApplication::get_max_log_size() else return f_result.toInt(); } +QString AOApplication::get_default_username() +{ + QString f_result = read_config("default_username"); + return f_result; +} + QStringList AOApplication::get_call_words() { QStringList return_value; From 7d476867cbc85ed72cb6d9faa286116e58010c4c Mon Sep 17 00:00:00 2001 From: Cerapter Date: Fri, 27 Jul 2018 23:09:41 +0200 Subject: [PATCH 013/174] 'Call mod' button now pops up a dialog. - Allows for cancelling calling a mod if it was a mistake. - Allows for giving a reason for the call, optionally. - **Obviously needs server-side support, too, to work.** --- courtroom.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/courtroom.cpp b/courtroom.cpp index d3e3728..4e1529b 100644 --- a/courtroom.cpp +++ b/courtroom.cpp @@ -13,6 +13,7 @@ #include #include #include +#include Courtroom::Courtroom(AOApplication *p_ao_app) : QMainWindow() { @@ -2337,7 +2338,14 @@ void Courtroom::on_spectator_clicked() void Courtroom::on_call_mod_clicked() { - ao_app->send_server_packet(new AOPacket("ZZ#%")); + bool ok; + QString text = QInputDialog::getText(ui_viewport, "Call a mod", + "Reason for the modcall (optional):", QLineEdit::Normal, + "", &ok); + if (ok) + { + ao_app->send_server_packet(new AOPacket("ZZ#" + text + "#%")); + } ui_ic_chat_message->setFocus(); } From 366389c6bc8c3bd52303e791e42966a1ef6455b0 Mon Sep 17 00:00:00 2001 From: Cerapter Date: Fri, 27 Jul 2018 23:39:56 +0200 Subject: [PATCH 014/174] The log now has an option to go both ways. - Due to the log's nature, this must be set manually in one's `config.ini`. --- aoapplication.h | 4 +++ courtroom.cpp | 74 ++++++++++++++++++++++++++++------------- text_file_functions.cpp | 12 +++++++ 3 files changed, 67 insertions(+), 23 deletions(-) diff --git a/aoapplication.h b/aoapplication.h index 947bb1d..d94cd2a 100644 --- a/aoapplication.h +++ b/aoapplication.h @@ -133,6 +133,10 @@ public: //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(); diff --git a/courtroom.cpp b/courtroom.cpp index 4e1529b..fda29ce 100644 --- a/courtroom.cpp +++ b/courtroom.cpp @@ -1175,15 +1175,14 @@ void Courtroom::handle_chatmessage_3() void Courtroom::append_ic_text(QString p_text, QString p_name) { + bool downwards = ao_app->get_log_goes_downwards(); + QTextCharFormat bold; QTextCharFormat normal; bold.setFontWeight(QFont::Bold); normal.setFontWeight(QFont::Normal); const QTextCursor old_cursor = ui_ic_chatlog->textCursor(); const int old_scrollbar_value = ui_ic_chatlog->verticalScrollBar()->value(); - const bool is_scrolled_down = old_scrollbar_value == ui_ic_chatlog->verticalScrollBar()->maximum(); - - ui_ic_chatlog->moveCursor(QTextCursor::End); // Get rid of centering. if(p_text.startsWith(": ~~")) @@ -1313,29 +1312,58 @@ void Courtroom::append_ic_text(QString p_text, QString p_name) // After all of that, let's jot down the message into the IC chatlog. - if (!first_message_sent) + if (downwards) { - ui_ic_chatlog->textCursor().insertText(p_name, bold); - first_message_sent = true; - } - else - { - ui_ic_chatlog->textCursor().insertText('\n' + p_name, bold); - } + const bool is_scrolled_down = old_scrollbar_value == ui_ic_chatlog->verticalScrollBar()->maximum(); - ui_ic_chatlog->textCursor().insertText(p_text, normal); - - if (old_cursor.hasSelection() || !is_scrolled_down) - { - // 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::End); - ui_ic_chatlog->verticalScrollBar()->setValue(ui_ic_chatlog->verticalScrollBar()->maximum()); + + 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 (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 top. + 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(p_text + '\n', normal); + + 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()); + } } } diff --git a/text_file_functions.cpp b/text_file_functions.cpp index db858cb..1389cf5 100644 --- a/text_file_functions.cpp +++ b/text_file_functions.cpp @@ -99,6 +99,18 @@ int AOApplication::get_max_log_size() else return f_result.toInt(); } +bool AOApplication::get_log_goes_downwards() +{ + QString f_result = read_config("log_goes_downwards"); + + if (f_result == "true") + return true; + else if (f_result == "false") + return false; + else + return true; +} + QString AOApplication::get_default_username() { QString f_result = read_config("default_username"); From 1b70d4d6dbc5090fde105ade1db57ed668d5e520 Mon Sep 17 00:00:00 2001 From: Cerapter Date: Sat, 28 Jul 2018 00:14:57 +0200 Subject: [PATCH 015/174] In-game log limit changer + enabling other full text colours. --- courtroom.cpp | 22 ++++++++++++++++++++-- courtroom.h | 6 ++++++ 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/courtroom.cpp b/courtroom.cpp index fda29ce..55a1784 100644 --- a/courtroom.cpp +++ b/courtroom.cpp @@ -140,6 +140,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); @@ -179,8 +181,8 @@ Courtroom::Courtroom(AOApplication *p_ao_app) : QMainWindow() ui_text_color->addItem("Blue"); ui_text_color->addItem("Yellow"); ui_text_color->addItem("Rainbow"); - //ui_text_color->addItem("Pink"); - //ui_text_color->addItem("Purple"); + ui_text_color->addItem("Pink"); + ui_text_color->addItem("Purple"); ui_music_slider = new QSlider(Qt::Horizontal, this); ui_music_slider->setRange(0, 100); @@ -194,6 +196,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(); @@ -249,6 +255,8 @@ 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))); @@ -438,6 +446,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"); @@ -496,6 +507,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"); @@ -2288,6 +2301,11 @@ void Courtroom::on_blip_slider_moved(int p_value) ui_ic_chat_message->setFocus(); } +void Courtroom::on_log_limit_changed(int value) +{ + ui_ic_chatlog->document()->setMaximumBlockCount(value); +} + void Courtroom::on_witness_testimony_clicked() { if (is_muted) diff --git a/courtroom.h b/courtroom.h index 35171b4..590de3d 100644 --- a/courtroom.h +++ b/courtroom.h @@ -31,6 +31,7 @@ #include #include #include +#include #include @@ -369,6 +370,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; @@ -482,6 +486,8 @@ 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_ooc_toggle_clicked(); void on_witness_testimony_clicked(); From c1807e0888c5851ab4fc2b419ec892a601792179 Mon Sep 17 00:00:00 2001 From: Cerapter Date: Sat, 28 Jul 2018 14:41:42 +0200 Subject: [PATCH 016/174] Max OOC name limited, unnecessary variable removed. --- courtroom.cpp | 1 + courtroom.h | 2 -- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/courtroom.cpp b/courtroom.cpp index 55a1784..70e3f66 100644 --- a/courtroom.cpp +++ b/courtroom.cpp @@ -111,6 +111,7 @@ 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->setMaxLength(30); ui_ooc_chat_name->setText(p_ao_app->get_default_username()); diff --git a/courtroom.h b/courtroom.h index 590de3d..4569156 100644 --- a/courtroom.h +++ b/courtroom.h @@ -164,8 +164,6 @@ private: // A stack of inline colours. std::stack inline_colour_stack; - bool centre_text = false; - bool next_character_is_not_special = false; // If true, write the // next character as it is. From e8f07c68c2aec19f65318d4aa6241ebcb0f1ccf5 Mon Sep 17 00:00:00 2001 From: Cerapter Date: Sat, 28 Jul 2018 16:09:54 +0200 Subject: [PATCH 017/174] Allow changing of shownames. Don't forget to set the size and position of the name input in a theme. --- charselect.cpp | 2 ++ courtroom.cpp | 59 +++++++++++++++++++++++++++++++++++++++++++++----- courtroom.h | 3 ++- datatypes.h | 3 ++- 4 files changed, 59 insertions(+), 8 deletions(-) diff --git a/charselect.cpp b/charselect.cpp index 4e4bccb..541f1e0 100644 --- a/charselect.cpp +++ b/charselect.cpp @@ -158,5 +158,7 @@ void Courtroom::char_clicked(int n_char) { ao_app->send_server_packet(new AOPacket("CC#" + QString::number(ao_app->s_pv) + "#" + QString::number(n_real_char) + "#" + get_hdid() + "#%")); } + + ui_ic_chat_name->setPlaceholderText(char_list.at(n_real_char).name); } diff --git a/courtroom.cpp b/courtroom.cpp index 70e3f66..b70ec0b 100644 --- a/courtroom.cpp +++ b/courtroom.cpp @@ -99,8 +99,13 @@ Courtroom::Courtroom(AOApplication *p_ao_app) : QMainWindow() //ui_area_list = new QListWidget(this); ui_music_list = new QListWidget(this); + 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(); @@ -399,14 +404,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(); @@ -932,17 +940,40 @@ void Courtroom::on_chat_return_pressed() packet_contents.append(f_text_color); + if (!ui_ic_chat_name->text().isEmpty()) + { + packet_contents.append(ui_ic_chat_name->text()); + } + 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; + //qDebug() << "A message was got. Its contents:"; 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. + // Also, don't forget! A size 15 message will have indices from 0 to 14. + if (n_string < p_contents->size()) + { + m_chatmessage[n_string] = p_contents->at(n_string); + //qDebug() << "- " << n_string << ": " << p_contents->at(n_string); + } + else + { + m_chatmessage[n_string] = ""; + //qDebug() << "- " << n_string << ": Nothing?"; + } } int f_char_id = m_chatmessage[CHAR_ID].toInt(); @@ -953,7 +984,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()) + { + 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'; @@ -1037,11 +1077,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()) + { + 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(); diff --git a/courtroom.h b/courtroom.h index 4569156..eb6638a 100644 --- a/courtroom.h +++ b/courtroom.h @@ -210,7 +210,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 = 16; QString m_chatmessage[chatmessage_size]; bool chatmessage_is_empty = false; @@ -311,6 +311,7 @@ private: QListWidget *ui_music_list; QLineEdit *ui_ic_chat_message; + QLineEdit *ui_ic_chat_name; QLineEdit *ui_ooc_chat_message; QLineEdit *ui_ooc_chat_name; diff --git a/datatypes.h b/datatypes.h index 4439107..ce1d651 100644 --- a/datatypes.h +++ b/datatypes.h @@ -92,7 +92,8 @@ enum CHAT_MESSAGE EVIDENCE_ID, FLIP, REALIZATION, - TEXT_COLOR + TEXT_COLOR, + SHOWNAME }; enum COLOR From cfc2d74d303787c8694f735f6fe3d1f989073c32 Mon Sep 17 00:00:00 2001 From: Cerapter Date: Sat, 28 Jul 2018 18:35:48 +0200 Subject: [PATCH 018/174] Limit modcall reason size to 100. --- courtroom.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/courtroom.cpp b/courtroom.cpp index b70ec0b..d0765b1 100644 --- a/courtroom.cpp +++ b/courtroom.cpp @@ -2438,6 +2438,7 @@ void Courtroom::on_call_mod_clicked() "", &ok); if (ok) { + text = text.chopped(100); ao_app->send_server_packet(new AOPacket("ZZ#" + text + "#%")); } From c5ef5b0e690a6a764d6c18338907d9dc56379afd Mon Sep 17 00:00:00 2001 From: Cerapter Date: Sat, 28 Jul 2018 18:54:29 +0200 Subject: [PATCH 019/174] The colour purple has been changed to cyan. --- courtroom.cpp | 6 +++--- datatypes.h | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/courtroom.cpp b/courtroom.cpp index d0765b1..2b72aad 100644 --- a/courtroom.cpp +++ b/courtroom.cpp @@ -188,7 +188,7 @@ Courtroom::Courtroom(AOApplication *p_ao_app) : QMainWindow() ui_text_color->addItem("Yellow"); ui_text_color->addItem("Rainbow"); ui_text_color->addItem("Pink"); - ui_text_color->addItem("Purple"); + ui_text_color->addItem("Cyan"); ui_music_slider = new QSlider(Qt::Horizontal, this); ui_music_slider->setRange(0, 100); @@ -1871,9 +1871,9 @@ void Courtroom::set_text_color() ui_vp_message->setStyleSheet("background-color: rgba(0, 0, 0, 0);" "color: pink"); break; - case PURPLE: + case CYAN: ui_vp_message->setStyleSheet("background-color: rgba(0, 0, 0, 0);" - "color: purple"); + "color: cyan"); break; default: qDebug() << "W: undefined text color: " << m_chatmessage[TEXT_COLOR]; diff --git a/datatypes.h b/datatypes.h index ce1d651..4cb54cb 100644 --- a/datatypes.h +++ b/datatypes.h @@ -106,7 +106,7 @@ enum COLOR YELLOW, RAINBOW, PINK, - PURPLE + CYAN }; #endif // DATATYPES_H From 5283bc68d26c63a637bbd60b11dc2c11a7635b76 Mon Sep 17 00:00:00 2001 From: Cerapter Date: Sat, 28 Jul 2018 21:56:56 +0200 Subject: [PATCH 020/174] Fixed a big stack bug that softlocked the game. --- courtroom.cpp | 41 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 39 insertions(+), 2 deletions(-) diff --git a/courtroom.cpp b/courtroom.cpp index 2b72aad..f9259b7 100644 --- a/courtroom.cpp +++ b/courtroom.cpp @@ -1324,6 +1324,10 @@ void Courtroom::append_ic_text(QString p_text, QString p_name) ic_colour_stack.pop(); trick_check_pos++; } + else + { + ic_next_is_not_special = true; + } } // Grey inline colourisation. @@ -1340,6 +1344,10 @@ void Courtroom::append_ic_text(QString p_text, QString p_name) ic_colour_stack.pop(); trick_check_pos++; } + else + { + ic_next_is_not_special = true; + } } // Green inline colourisation. @@ -1523,6 +1531,9 @@ void Courtroom::chat_tick() // 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 (tick_pos >= f_message.size()) { text_state = 2; @@ -1569,6 +1580,7 @@ void Courtroom::chat_tick() else if (f_character == "\\" and !next_character_is_not_special) { next_character_is_not_special = true; + formatting_char = true; } // Text speed modifier. @@ -1576,10 +1588,12 @@ void Courtroom::chat_tick() { // ++, 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. @@ -1600,6 +1614,7 @@ void Courtroom::chat_tick() { inline_colour_stack.push(INLINE_ORANGE); } + formatting_char = true; } // Blue inline colourisation. @@ -1616,6 +1631,11 @@ void Courtroom::chat_tick() inline_colour_stack.pop(); ui_vp_message->insertHtml("" + f_character + ""); } + else + { + next_character_is_not_special = true; + tick_pos--; + } } // Grey inline colourisation. @@ -1632,6 +1652,11 @@ void Courtroom::chat_tick() inline_colour_stack.pop(); ui_vp_message->insertHtml("" + f_character + ""); } + else + { + next_character_is_not_special = true; + tick_pos--; + } } // Green inline colourisation. @@ -1642,15 +1667,18 @@ void Courtroom::chat_tick() 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; } } @@ -1702,7 +1730,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(); @@ -1725,7 +1753,16 @@ void Courtroom::chat_tick() current_display_speed = 6; } - chat_tick_timer->start(message_display_speed[current_display_speed]); + // 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]); + } + } } From 0561ae7fd6458a310d29e5cde4dfa30877365fcb Mon Sep 17 00:00:00 2001 From: Cerapter Date: Sat, 28 Jul 2018 23:56:37 +0200 Subject: [PATCH 021/174] Allow the toggling of custom shownames. Don't forget to enable it in a theme. --- aoapplication.h | 3 +++ courtroom.cpp | 18 ++++++++++++++++-- courtroom.h | 4 ++++ text_file_functions.cpp | 12 ++++++------ 4 files changed, 29 insertions(+), 8 deletions(-) diff --git a/aoapplication.h b/aoapplication.h index d94cd2a..33d18c7 100644 --- a/aoapplication.h +++ b/aoapplication.h @@ -140,6 +140,9 @@ public: // Returns the username the user may have set in config.ini. QString get_default_username(); + // 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(); diff --git a/courtroom.cpp b/courtroom.cpp index f9259b7..ec1393b 100644 --- a/courtroom.cpp +++ b/courtroom.cpp @@ -169,6 +169,11 @@ Courtroom::Courtroom(AOApplication *p_ao_app) : QMainWindow() ui_guard->setText("Guard"); ui_guard->hide(); + ui_showname_enable = new QCheckBox(this); + ui_showname_enable->setChecked(ao_app->get_showname_enabled_by_default()); + ui_showname_enable->setText("Custom shownames"); + ui_showname_enable; + ui_custom_objection = new AOButton(this, ao_app); ui_realization = new AOButton(this, ao_app); ui_mute = new AOButton(this, ao_app); @@ -278,6 +283,8 @@ Courtroom::Courtroom(AOApplication *p_ao_app) : QMainWindow() connect(ui_flip, SIGNAL(clicked()), this, SLOT(on_flip_clicked())); connect(ui_guard, SIGNAL(clicked()), this, SLOT(on_guard_clicked())); + connect(ui_showname_enable, SIGNAL(clicked()), this, SLOT(on_showname_enable_clicked())); + connect(ui_evidence_button, SIGNAL(clicked()), this, SLOT(on_evidence_button_clicked())); set_widgets(); @@ -489,6 +496,8 @@ void Courtroom::set_widgets() set_size_and_pos(ui_guard, "guard"); + 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"); @@ -985,7 +994,7 @@ void Courtroom::handle_chatmessage(QStringList *p_contents) return; QString f_showname; - if (m_chatmessage[SHOWNAME].isEmpty()) + if (m_chatmessage[SHOWNAME].isEmpty() || !ui_showname_enable->isChecked()) { f_showname = ao_app->get_showname(char_list.at(f_char_id).name); } @@ -1077,7 +1086,7 @@ void Courtroom::handle_chatmessage_2() ui_vp_speedlines->stop(); ui_vp_player_char->stop(); - if (m_chatmessage[SHOWNAME].isEmpty()) + if (m_chatmessage[SHOWNAME].isEmpty() || !ui_showname_enable->isChecked()) { QString real_name = char_list.at(m_chatmessage[CHAR_ID].toInt()).name; @@ -2497,6 +2506,11 @@ void Courtroom::on_guard_clicked() ui_ic_chat_message->setFocus(); } +void Courtroom::on_showname_enable_clicked() +{ + ui_ic_chat_message->setFocus(); +} + void Courtroom::on_evidence_button_clicked() { if (ui_evidence->isHidden()) diff --git a/courtroom.h b/courtroom.h index eb6638a..4b47558 100644 --- a/courtroom.h +++ b/courtroom.h @@ -351,6 +351,8 @@ private: QCheckBox *ui_flip; QCheckBox *ui_guard; + QCheckBox *ui_showname_enable; + AOButton *ui_custom_objection; AOButton *ui_realization; AOButton *ui_mute; @@ -500,6 +502,8 @@ private slots: void on_flip_clicked(); void on_guard_clicked(); + void on_showname_enable_clicked(); + void on_evidence_button_clicked(); void on_evidence_delete_clicked(); diff --git a/text_file_functions.cpp b/text_file_functions.cpp index 1389cf5..8ddeb6c 100644 --- a/text_file_functions.cpp +++ b/text_file_functions.cpp @@ -102,13 +102,13 @@ int AOApplication::get_max_log_size() bool AOApplication::get_log_goes_downwards() { QString f_result = read_config("log_goes_downwards"); + return f_result.startsWith("true"); +} - if (f_result == "true") - return true; - else if (f_result == "false") - return false; - else - return true; +bool AOApplication::get_showname_enabled_by_default() +{ + QString f_result = read_config("show_custom_shownames"); + return f_result.startsWith("true"); } QString AOApplication::get_default_username() From 95d521de9eb64fb355be2db88bf7b47c368193b8 Mon Sep 17 00:00:00 2001 From: Cerapter Date: Sun, 29 Jul 2018 15:48:11 +0200 Subject: [PATCH 022/174] Modified the centering behaviour. Now only the two beginning tildes get removed. This is so that people can do location and time announcements. --- courtroom.cpp | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/courtroom.cpp b/courtroom.cpp index ec1393b..8f8bc37 100644 --- a/courtroom.cpp +++ b/courtroom.cpp @@ -1260,12 +1260,10 @@ void Courtroom::append_ic_text(QString p_text, QString p_name) // Don't forget, the p_text part actually everything after the name! // Hence why we check for ': ~~'. - // If the user decided to put a space after the two tildes, remove that - // in one go. - p_text.remove("~~ "); - - // Remove all remaining ~~s. - p_text.remove("~~"); + // Let's remove those two tildes, then. + // : _ ~ ~ + // 0 1 2 3 + p_text.remove(2,2); } // Get rid of the inline-colouring. @@ -1543,6 +1541,13 @@ void Courtroom::chat_tick() // 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; From f77381864e64e0c21b8db838daa62bbab2b58dc4 Mon Sep 17 00:00:00 2001 From: Cerapter Date: Mon, 30 Jul 2018 18:58:23 +0200 Subject: [PATCH 023/174] Removed the now unneeded reloading of log limits on theme reload. --- courtroom.cpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/courtroom.cpp b/courtroom.cpp index 8f8bc37..113a69a 100644 --- a/courtroom.cpp +++ b/courtroom.cpp @@ -2442,9 +2442,6 @@ void Courtroom::on_reload_theme_clicked() { ao_app->reload_theme(); - //Refresh IC chat limits. - ui_ic_chatlog->document()->setMaximumBlockCount(ao_app->get_max_log_size()); - //to update status on the background set_background(current_background); enter_courtroom(m_cid); From 374e939ac467cf98bd785442f28a4ec802f27dc6 Mon Sep 17 00:00:00 2001 From: Cerapter Date: Tue, 31 Jul 2018 00:44:41 +0200 Subject: [PATCH 024/174] Added the tsuserver3 files necessary to support this custom client. --- .gitignore | 2 + server/__init__.py | 0 server/aoprotocol.py | 641 ++++++++++++++++++++++++++ server/area_manager.py | 210 +++++++++ server/ban_manager.py | 54 +++ server/client_manager.py | 380 ++++++++++++++++ server/commands.py | 848 +++++++++++++++++++++++++++++++++++ server/constants.py | 11 + server/districtclient.py | 79 ++++ server/evidence.py | 91 ++++ server/exceptions.py | 32 ++ server/fantacrypt.py | 45 ++ server/logger.py | 64 +++ server/masterserverclient.py | 89 ++++ server/tsuserver.py | 263 +++++++++++ server/websocket.py | 212 +++++++++ 16 files changed, 3021 insertions(+) create mode 100644 server/__init__.py create mode 100644 server/aoprotocol.py create mode 100644 server/area_manager.py create mode 100644 server/ban_manager.py create mode 100644 server/client_manager.py create mode 100644 server/commands.py create mode 100644 server/constants.py create mode 100644 server/districtclient.py create mode 100644 server/evidence.py create mode 100644 server/exceptions.py create mode 100644 server/fantacrypt.py create mode 100644 server/logger.py create mode 100644 server/masterserverclient.py create mode 100644 server/tsuserver.py create mode 100644 server/websocket.py diff --git a/.gitignore b/.gitignore index 969523a..61060c0 100644 --- a/.gitignore +++ b/.gitignore @@ -16,3 +16,5 @@ Makefile* object_script* /Attorney_Online_remake_resource.rc /attorney_online_remake_plugin_import.cpp + +server/__pycache__ 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..e0c35e8 --- /dev/null +++ b/server/aoprotocol.py @@ -0,0 +1,641 @@ +# 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 + + +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: + self.client.disconnect() + return + # 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: + return + + 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.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') + + 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 + 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): + msg_type, pre, folder, anim, text, pos, sfx, anim_type, cid, sfx_delay, button, evidence, flip, ding, color = args + showname = self.client.get_char_name() + 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): + msg_type, pre, folder, anim, text, pos, sfx, anim_type, cid, sfx_delay, button, evidence, flip, ding, color, showname = args + if len(showname) > 0 and not self.client.area.showname_changes_allowed == "true": + self.client.send_host_message("Showname changes are forbidden in this area!") + return + else: + return + msg_type, pre, folder, anim, text, pos, sfx, anim_type, cid, sfx_delay, button, evidence, flip, ding, color = args + 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 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 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: + 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'): + return + msg = text[:256] + 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() + 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) + self.client.area.set_next_msg_delay(len(msg)) + logger.log_server('[IC][{}][{}]{}'.format(self.client.area.id, 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 + if self.client.name.startswith(self.server.config['hostname']) or self.client.name.startswith('G'): + self.client.send_host_message('That name is reserved!') + return + if args[1].startswith('/'): + spl = args[1][1:].split(' ', 1) + cmd = spl[0] + 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.disemvowel: + args[1] = self.client.disemvowel_message(args[1]) + self.client.area.send_command('CT', self.client.name, args[1]) + logger.log_server( + '[OOC][{}][{}][{}]{}'.format(self.client.area.id, self.client.get_char_name(), self.client.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 not self.validate_net_cmd(args, self.ArgType.STR, self.ArgType.INT): + 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]) + 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.id, 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 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 not self.validate_net_cmd(args, self.ArgType.STR): + return + if args[0] == 'testimony1': + sign = 'WT' + elif args[0] == 'testimony2': + sign = 'CE' + 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 + self.client.area.send_command('RT', args[0]) + self.client.area.add_to_judgelog(self.client, 'used {}'.format(sign)) + logger.log_server("[{}]{} Used WT/CE".format(self.client.area.id, 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 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.id, 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, + self.client.area.id), pred=lambda c: c.is_mod) + self.client.set_mod_call_delay() + logger.log_server('[{}][{}]{} called a moderator.'.format(self.client.get_ip(), self.client.area.id, self.client.get_char_name())) + 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, + self.client.area.id, args[0]), pred=lambda c: c.is_mod) + self.client.set_mod_call_delay() + logger.log_server('[{}][{}]{} called a moderator: {}.'.format(self.client.get_ip(), self.client.area.id, self.client.get_char_name(), args[0])) + + 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..6b6c939 --- /dev/null +++ b/server/area_manager.py @@ -0,0 +1,210 @@ +# 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 + + +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): + 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.evi_list = EvidenceList() + self.is_recording = False + self.recorded_messages = [] + self.evidence_mod = evidence_mod + self.locking_allowed = locking_allowed + self.owned = False + 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 = False + + def new_client(self, client): + self.clients.add(client) + + def remove_client(self, client): + self.clients.remove(client) + if client.is_cm: + client.is_cm = False + self.owned = False + if self.is_locked: + self.unlock() + + def unlock(self): + self.is_locked = False + self.invite_list = {} + self.send_host_message('This area is open 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_host_message(self, msg): + self.send_command('CT', self.server.config['hostname'], msg) + + 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 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 can_send_message(self, client): + if self.is_locked and not client.is_mod and not client.ipid in self.invite_list: + 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 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', 'building-open', 'building-full', 'casing-open', 'casing-full', 'recess') + if value.lower() not in allowed_values: + raise AreaError('Invalid status. Possible values: {}'.format(', '.join(allowed_values))) + self.status = value.upper() + + 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 = 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 __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 + 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'])) + 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.') diff --git a/server/ban_manager.py b/server/ban_manager.py new file mode 100644 index 0000000..24518b2 --- /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) diff --git a/server/client_manager.py b/server/client_manager.py new file mode 100644 index 0000000..6857269 --- /dev/null +++ b/server/client_manager.py @@ -0,0 +1,380 @@ +# 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.is_cm = False + self.evi_list = [] + self.disemvowel = False + 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 + + #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) + + 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 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) + logger.log_server('[{}]Changed character from {} to {}.' + .format(self.area.id, old_char, self.get_char_name()), self) + + def change_music_cd(self): + if self.is_mod or self.is_cm: + 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.is_cm: + 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 and not self.is_mod and not self.ipid in area.invite_list: + #self.send_host_message('This area is locked - you will be unable to send messages ICly.') + raise ClientError("That area is locked!") + 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.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 ===' + lock = {True: '[LOCKED]', False: ''} + for i, area in enumerate(self.server.area_manager.areas): + owner = 'FREE' + if area.owned: + for client in [x for x in area.clients if x.is_cm]: + owner = 'MASTER: {}'.format(client.get_char_name()) + break + msg += '\r\nArea {}: {} (users: {}) [{}][{}]{}'.format(i, 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 = '' + try: + area = self.server.area_manager.get_area_by_id(area_id) + except AreaError: + raise + info += '= Area {}: {} =='.format(area.id, area.name) + sorted_clients = [] + for client in area.clients: + if (not mods) or client.is_mod: + sorted_clients.append(client) + sorted_clients = sorted(sorted_clients, key=lambda x: x.get_char_name()) + for c in sorted_clients: + info += '\r\n[{}] {}'.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: + cnt += len(self.server.area_manager.areas[i].clients) + info += '\r\n{}'.format(self.get_area_info(i, mods)) + info = 'Current online: {}'.format(cnt) + info + else: + try: + info = 'People in this area: {}\n'.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): + 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 + self.send_command('CharsCheck', *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.send_command('DONE') + + def char_select(self): + self.char_id = -1 + self.send_done() + + 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'): + raise ClientError('Invalid position. Possible values: def, pro, hld, hlp, jud, wit.') + 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 disemvowel_message(self, message): + message = re.sub("[aeiou]", "", message, flags=re.IGNORECASE) + return re.sub(r"\s+", " ", message) + + 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): + 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..efcfe38 --- /dev/null +++ b/server/commands.py @@ -0,0 +1,848 @@ +# 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 hashlib +import string +from server.constants import TargetType + +from server import logger +from server.exceptions import ClientError, ServerError, ArgumentError, AreaError + + +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.id, 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('A mod has set the background lock to {}.'.format(client.area.bg_lock)) + logger.log_server('[{}][{}]Changed bglock to {}'.format(client.area.id, 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_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.id, client.get_char_name(), roll, val[0])) + +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 /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.send_host_message('{} rolled {} out of {}.'.format(client.get_char_name(), roll, val[0])) + client.area.send_host_message('{} rolled.'.format(client.get_char_name(), roll, val[0])) + SALT = ''.join(random.choices(string.ascii_uppercase + string.digits, k=16)) + logger.log_server( + '[{}][{}]Used /roll and got {} out of {}.'.format(client.area.id, client.get_char_name(), hashlib.sha1((str(roll) + SALT).encode('utf-8')).hexdigest() + '|' + SALT, val[0])) + +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.') + 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_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.id, client.get_char_name(), flip)) + +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.is_cm 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.id, client.get_char_name(), pos, len(targets))) + +def ooc_cmd_help(client, arg): + if len(arg) != 0: + raise ArgumentError('This command has no arguments.') + help_url = 'https://github.com/AttorneyOnline/tsuserver3/blob/master/README.md' + help_msg = 'Available commands, source code and issues 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 .') + targets = client.server.client_manager.get_targets(client, TargetType.IPID, int(arg), False) + if targets: + for c in targets: + logger.log_server('Kicked {}.'.format(c.ipid), client) + client.send_host_message("{} was kicked.".format(c.get_char_name())) + c.disconnect() + else: + client.send_host_message("No targets found.") + +def ooc_cmd_ban(client, arg): + if not client.is_mod: + raise ClientError('You must be authorized to do that.') + try: + ipid = int(arg.strip()) + except: + raise ClientError('You must specify 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.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) + +def ooc_cmd_unban(client, arg): + if not client.is_mod: + raise ClientError('You must be authorized to do that.') + try: + client.server.ban_manager.remove_ban(int(arg.strip())) + except: + raise ClientError('You must specify \'hdid\'') + logger.log_server('Unbanned {}.'.format(arg), client) + client.send_host_message('Unbanned {}'.format(arg)) + + +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.id, 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.') + try: + c = client.server.client_manager.get_targets(client, TargetType.IPID, int(arg), False)[0] + c.is_muted = True + client.send_host_message('{} existing client(s).'.format(c.get_char_name())) + except: + client.send_host_message("No targets found. Use /mute for mute") + +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.') + try: + c = client.server.client_manager.get_targets(client, TargetType.IPID, int(arg), False)[0] + c.is_muted = False + client.send_host_message('{} existing client(s).'.format(c.get_char_name())) + except: + client.send_host_message("No targets found. Use /mute for mute") + +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) + +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.id, 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.id, 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.id, 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)) + logger.log_server('[{}][{}][ANNOUNCEMENT]{}.'.format(client.area.id, 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.id, 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.id, client.get_char_name(), client.area.doc)) + 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.id, client.get_char_name(), arg)) + + +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.id, client.get_char_name(), client.area.doc)) + 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.id, client.get_char_name(), client.area.status)) + 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: + c.send_host_message('PM from {} in {} ({}): {}'.format(client.name, 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.') + 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 client.area.owned == False: + client.area.owned = True + client.is_cm = True + if client.area.evidence_mod == 'HiddenCM': + client.area.broadcast_evidence_list() + client.area.send_host_message('{} is CM in this area now.'.format(client.get_char_name())) + +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.send_host_message('Area is already locked.') + if client.is_cm: + client.area.is_locked = True + client.area.send_host_message('Area is locked.') + for i in client.area.clients: + client.area.invite_list[i.ipid] = None + return + else: + raise ClientError('Only CM can lock the area.') + +def ooc_cmd_area_unlock(client, arg): + if not client.area.is_locked: + raise ClientError('Area is already unlocked.') + if not client.is_cm: + 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 not client.area.is_locked: + raise ClientError('Area isn\'t locked.') + if not client.is_cm 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.ipid] = 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 area {}.'.format(client.area.id)) + except: + raise ClientError('You must specify a target. Use /invite ') + +def ooc_cmd_uninvite(client, arg): + if not client.is_cm and not client.is_mod: + raise ClientError('You must be authorized to do that.') + if not client.area.is_locked and not client.is_mod: + 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.invite_list.pop(c.ipid) + 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 not client.area.is_locked and not client.is_mod: + 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.invite_list.pop(c.ipid) + 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_mute .') + targets = client.server.client_manager.get_targets(client, TargetType.ID, arg, False) + if not targets: + raise ArgumentError('Target not found. Use /ooc_mute .') + 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) + 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 /disemvowel .') + if targets: + for c in targets: + logger.log_server('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_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.') + 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.') + 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.') + 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.') + 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.is_cm 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 = 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..adc29ec --- /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, + 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..ddd9ba3 --- /dev/null +++ b/server/evidence.py @@ -0,0 +1,91 @@ +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'], 'hlp':['hlp', 'pro'], 'hld':['hld', 'def'], 'jud':['jud'], 'all':['hlp', 'hld', 'wit', 'jud', 'pro', 'def', ''], 'pos':[]} + + def login(self, client): + if client.area.evidence_mod == 'FFA': + pass + if client.area.evidence_mod == 'Mods': + if not client.is_cm: + return False + if client.area.evidence_mod == 'CM': + if not client.is_cm and not client.is_mod: + return False + if client.area.evidence_mod == 'HiddenCM': + if not client.is_cm 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..675a359 --- /dev/null +++ b/server/logger.py @@ -0,0 +1,64 @@ +# 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') + + 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) + + +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 parse_client_info(client): + if client is None: + return '' + info = client.get_ip() + if client.is_mod: + return '[{:<15}][{}][MOD]'.format(info, client.id) + return '[{:<15}][{}]'.format(info, client.id) 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..14ad60b --- /dev/null +++ b/server/tsuserver.py @@ -0,0 +1,263 @@ +# 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.id, 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 broadcast_need(self, client, msg): + char_name = client.get_char_name() + area_name = client.area.name + area_id = client.area.id + 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), 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 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..d77f678 --- /dev/null +++ b/server/websocket.py @@ -0,0 +1,212 @@ +# 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 + + if payload_length == 126: + payload_length = struct.unpack(">H", data[2:4])[0] + elif payload_length == 127: + payload_length = struct.unpack(">Q", data[2:10])[0] + + masks = data[2:6] + decoded = "" + for char in data[6:payload_length + 6]: + 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) \ No newline at end of file From 651585f1912ee30d8940243186dbacac518458f8 Mon Sep 17 00:00:00 2001 From: Cerapter Date: Tue, 31 Jul 2018 03:24:44 +0200 Subject: [PATCH 025/174] Fixed a bug where shownames would always be forbidden. --- server/aoprotocol.py | 3 +-- server/area_manager.py | 2 ++ 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/server/aoprotocol.py b/server/aoprotocol.py index e0c35e8..d21a6a5 100644 --- a/server/aoprotocol.py +++ b/server/aoprotocol.py @@ -347,12 +347,11 @@ class AOProtocol(asyncio.Protocol): self.ArgType.INT, self.ArgType.INT, self.ArgType.INT, self.ArgType.INT, self.ArgType.INT, self.ArgType.INT, self.ArgType.INT, self.ArgType.STR): msg_type, pre, folder, anim, text, pos, sfx, anim_type, cid, sfx_delay, button, evidence, flip, ding, color, showname = args - if len(showname) > 0 and not self.client.area.showname_changes_allowed == "true": + 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 - msg_type, pre, folder, anim, text, pos, sfx, anim_type, cid, sfx_delay, button, evidence, flip, ding, color = args 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 diff --git a/server/area_manager.py b/server/area_manager.py index 6b6c939..3ed543d 100644 --- a/server/area_manager.py +++ b/server/area_manager.py @@ -49,6 +49,8 @@ class AreaManager: 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.owned = False self.cards = dict() From c460a5b795bc4c65d271db5b6f2af0a946cf6947 Mon Sep 17 00:00:00 2001 From: Cerapter Date: Fri, 3 Aug 2018 19:50:53 +0200 Subject: [PATCH 026/174] Static linking for Windows. --- .gitignore | 5 +++ README.md | 35 +++++++++++++++ courtroom.cpp | 2 +- include/discord_register.h | 26 ++++++++++++ include/discord_rpc.h | 87 ++++++++++++++++++++++++++++++++++++++ 5 files changed, 154 insertions(+), 1 deletion(-) create mode 100644 include/discord_register.h create mode 100644 include/discord_rpc.h diff --git a/.gitignore b/.gitignore index 61060c0..b3c3db4 100644 --- a/.gitignore +++ b/.gitignore @@ -9,6 +9,8 @@ base-full/ bass.lib bins/ +release/ +debug/ .qmake.stash @@ -18,3 +20,6 @@ object_script* /attorney_online_remake_plugin_import.cpp server/__pycache__ + +*.o +moc* \ No newline at end of file diff --git a/README.md b/README.md index 7c5bf5c..b78bdb2 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,38 @@ +# 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. +- **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. + +--- + # 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/courtroom.cpp b/courtroom.cpp index 113a69a..415c20e 100644 --- a/courtroom.cpp +++ b/courtroom.cpp @@ -2486,7 +2486,7 @@ void Courtroom::on_call_mod_clicked() "", &ok); if (ok) { - text = text.chopped(100); + text = text.left(100); ao_app->send_server_packet(new AOPacket("ZZ#" + text + "#%")); } 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 From 8e3922489095d83532b1c5273137c57a3a3ff3a8 Mon Sep 17 00:00:00 2001 From: Cerapter Date: Fri, 3 Aug 2018 19:52:32 +0200 Subject: [PATCH 027/174] Showname fix, case insensitive commands. - Fixed a problem wherein if you had 'Custom shownames' on, your client would display the foldernames of characters if their user hadn't given temselves a custom showname, instead of the character's showname. --- server/aoprotocol.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/server/aoprotocol.py b/server/aoprotocol.py index d21a6a5..1711eba 100644 --- a/server/aoprotocol.py +++ b/server/aoprotocol.py @@ -340,7 +340,7 @@ class AOProtocol(asyncio.Protocol): self.ArgType.INT, self.ArgType.INT, self.ArgType.INT, self.ArgType.INT, self.ArgType.INT, self.ArgType.INT, self.ArgType.INT): msg_type, pre, folder, anim, text, pos, sfx, anim_type, cid, sfx_delay, button, evidence, flip, ding, color = args - showname = self.client.get_char_name() + showname = "" 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, @@ -442,7 +442,7 @@ class AOProtocol(asyncio.Protocol): return if args[1].startswith('/'): spl = args[1][1:].split(' ', 1) - cmd = spl[0] + cmd = spl[0].lower() arg = '' if len(spl) == 2: arg = spl[1][:256] From f9baa0454d49d7da65a5c17afbb11aefa120e85a Mon Sep 17 00:00:00 2001 From: Cerapter Date: Tue, 7 Aug 2018 19:28:05 +0200 Subject: [PATCH 028/174] Log limit bugfixes. - Log limit is now correctly applied in both directions. - Log direction now cannot be changed by rewriting the ini mid-game. --- courtroom.cpp | 34 +++++++++++++++++++++++++++------- courtroom.h | 6 ++++++ 2 files changed, 33 insertions(+), 7 deletions(-) diff --git a/courtroom.cpp b/courtroom.cpp index 415c20e..7c11834 100644 --- a/courtroom.cpp +++ b/courtroom.cpp @@ -84,7 +84,9 @@ Courtroom::Courtroom(AOApplication *p_ao_app) : QMainWindow() ui_ic_chatlog = new QTextEdit(this); ui_ic_chatlog->setReadOnly(true); - ui_ic_chatlog->document()->setMaximumBlockCount(ao_app->get_max_log_size()); + + 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); @@ -172,7 +174,6 @@ Courtroom::Courtroom(AOApplication *p_ao_app) : QMainWindow() ui_showname_enable = new QCheckBox(this); ui_showname_enable->setChecked(ao_app->get_showname_enabled_by_default()); ui_showname_enable->setText("Custom shownames"); - ui_showname_enable; ui_custom_objection = new AOButton(this, ao_app); ui_realization = new AOButton(this, ao_app); @@ -1245,8 +1246,6 @@ void Courtroom::handle_chatmessage_3() void Courtroom::append_ic_text(QString p_text, QString p_name) { - bool downwards = ao_app->get_log_goes_downwards(); - QTextCharFormat bold; QTextCharFormat normal; bold.setFontWeight(QFont::Bold); @@ -1388,7 +1387,7 @@ void Courtroom::append_ic_text(QString p_text, QString p_name) // After all of that, let's jot down the message into the IC chatlog. - if (downwards) + if (log_goes_downwards) { const bool is_scrolled_down = old_scrollbar_value == ui_ic_chatlog->verticalScrollBar()->maximum(); @@ -1414,10 +1413,20 @@ void Courtroom::append_ic_text(QString p_text, QString p_name) } else { - // The user hasn't selected any text and the scrollbar is at the bottom: scroll to the top. + // 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()); } + + // Finally, if we got too many blocks in the current log, delete some from the top. + while (ui_ic_chatlog->document()->blockCount() > log_maximum_blocks) + { + 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; + } } else { @@ -1440,6 +1449,17 @@ void Courtroom::append_ic_text(QString p_text, QString p_name) ui_ic_chatlog->moveCursor(QTextCursor::Start); ui_ic_chatlog->verticalScrollBar()->setValue(ui_ic_chatlog->verticalScrollBar()->minimum()); } + + + // Finally, if we got too many blocks in the current log, delete some from the bottom. + while (ui_ic_chatlog->document()->blockCount() > log_maximum_blocks) + { + 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; + } } } @@ -2402,7 +2422,7 @@ void Courtroom::on_blip_slider_moved(int p_value) void Courtroom::on_log_limit_changed(int value) { - ui_ic_chatlog->document()->setMaximumBlockCount(value); + log_maximum_blocks = value; } void Courtroom::on_witness_testimony_clicked() diff --git a/courtroom.h b/courtroom.h index 4b47558..b3342db 100644 --- a/courtroom.h +++ b/courtroom.h @@ -193,6 +193,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; From 78be99422ecec29c07f221d0fcb690af5d472fd1 Mon Sep 17 00:00:00 2001 From: Cerapter Date: Tue, 7 Aug 2018 19:41:41 +0200 Subject: [PATCH 029/174] CCCC version now displayed ingame. --- aoapplication.cpp | 8 ++++++++ aoapplication.h | 9 +++++++++ lobby.cpp | 2 +- 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/aoapplication.cpp b/aoapplication.cpp index 12e540c..6e95a52 100644 --- a/aoapplication.cpp +++ b/aoapplication.cpp @@ -94,6 +94,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(); diff --git a/aoapplication.h b/aoapplication.h index 33d18c7..9252cdd 100644 --- a/aoapplication.h +++ b/aoapplication.h @@ -77,6 +77,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(); @@ -229,6 +234,10 @@ private: const int MAJOR_VERSION = 4; const int MINOR_VERSION = 8; + const int CCCC_RELEASE = 1; + const int CCCC_MAJOR_VERSION = 3; + const int CCCC_MINOR_VERSION = 0; + QString current_theme = "default"; QVector server_list; diff --git a/lobby.cpp b/lobby.cpp index e68fdfb..e642fae 100644 --- a/lobby.cpp +++ b/lobby.cpp @@ -98,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"); From e7cf1d7735aaa32adc0dc891ecaaff2bafe2a422 Mon Sep 17 00:00:00 2001 From: Cerapter Date: Tue, 7 Aug 2018 20:26:16 +0200 Subject: [PATCH 030/174] Discord Rich Presence updated. --- discord_rich_presence.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/discord_rich_presence.h b/discord_rich_presence.h index 3c9f2bd..35d5bec 100644 --- a/discord_rich_presence.h +++ b/discord_rich_presence.h @@ -9,7 +9,7 @@ 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: From eca2cd02f41ae5496a0cb1f393fe82c44e593603 Mon Sep 17 00:00:00 2001 From: Cerapter Date: Tue, 7 Aug 2018 21:10:47 +0200 Subject: [PATCH 031/174] Inline blue text now stops the character from talking. --- courtroom.cpp | 40 ++++++++++++++++++++++++++++++++++++++++ courtroom.h | 8 ++++++++ 2 files changed, 48 insertions(+) diff --git a/courtroom.cpp b/courtroom.cpp index 7c11834..3a5173c 100644 --- a/courtroom.cpp +++ b/courtroom.cpp @@ -1195,11 +1195,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; @@ -1536,6 +1542,10 @@ void Courtroom::start_chat_ticking() tick_pos = 0; blip_pos = 0; + // 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]); @@ -1656,6 +1666,18 @@ void Courtroom::chat_tick() { 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) + { + 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()) @@ -1664,6 +1686,24 @@ void Courtroom::chat_tick() { 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) + { + if (inline_blue_depth == 0) + { + QString f_char = m_chatmessage[CHAR_NAME]; + QString f_emote = m_chatmessage[EMOTE]; + ui_vp_player_char->play_talking(f_char, f_emote); + } + } + } } else { diff --git a/courtroom.h b/courtroom.h index b3342db..df0883c 100644 --- a/courtroom.h +++ b/courtroom.h @@ -172,6 +172,14 @@ private: 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; + QVector char_list; QVector evidence_list; QVector music_list; From 1524b88423964e2a58ac9e1ace184ab31bdd0d00 Mon Sep 17 00:00:00 2001 From: Cerapter Date: Wed, 8 Aug 2018 19:17:47 +0200 Subject: [PATCH 032/174] Discord Rich Presence logo update. --- discord_rich_presence.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/discord_rich_presence.cpp b/discord_rich_presence.cpp index bcc0d2a..dc06e12 100644 --- a/discord_rich_presence.cpp +++ b/discord_rich_presence.cpp @@ -34,8 +34,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_empty_png"; + presence.largeImageText = "Omit!"; presence.instance = 1; presence.state = "In Lobby"; @@ -49,8 +49,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_empty_png"; + presence.largeImageText = "Omit!"; presence.instance = 1; auto timestamp = static_cast(std::time(nullptr)); @@ -75,8 +75,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_empty_png"; + presence.largeImageText = "Omit!"; presence.instance = 1; presence.details = this->server_name.c_str(); presence.matchSecret = this->server_id.c_str(); @@ -94,8 +94,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_empty_png"; + presence.largeImageText = "Omit!"; presence.instance = 1; presence.details = this->server_name.c_str(); presence.matchSecret = this->server_id.c_str(); From c85244e38c5444a37d926e1d6284f6bea43341be Mon Sep 17 00:00:00 2001 From: Cerapter Date: Wed, 8 Aug 2018 19:19:53 +0200 Subject: [PATCH 033/174] config.ini functioning changed. - Now the program uses the QSettings class to manipulate the `config.ini`. - Support for multiple audio devices and options menu started. --- aoapplication.cpp | 22 +++++++++++++ aoapplication.h | 11 ++++++- courtroom.cpp | 2 ++ text_file_functions.cpp | 72 +++++++++++++++++------------------------ 4 files changed, 64 insertions(+), 43 deletions(-) diff --git a/aoapplication.cpp b/aoapplication.cpp index 6e95a52..cfa9648 100644 --- a/aoapplication.cpp +++ b/aoapplication.cpp @@ -15,6 +15,9 @@ AOApplication::AOApplication(int &argc, char **argv) : QApplication(argc, argv) discord = new AttorneyOnline::Discord(); QObject::connect(net_manager, SIGNAL(ms_connect_finished(bool, bool)), SLOT(ms_connect_finished(bool, bool))); + + // Create the QSettings class that points to the config.ini. + configini = new QSettings(get_base_path() + "config.ini", QSettings::IniFormat); } AOApplication::~AOApplication() @@ -43,6 +46,25 @@ void AOApplication::construct_lobby() discord->state_lobby(); w_lobby->show(); + + // 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; + + for (a = 1; BASS_GetDeviceInfo(a, &info); a++) + { + if (get_audio_output_device() == info.name) + { + BASS_SetDevice(a); + qDebug() << info.name << "was set as the default audio output device."; + break; + } + qDebug() << info.name; + } + + //AOOptionsDialog* test = new AOOptionsDialog(nullptr, this); + //test->exec(); } void AOApplication::destruct_lobby() diff --git a/aoapplication.h b/aoapplication.h index 9252cdd..a01ef81 100644 --- a/aoapplication.h +++ b/aoapplication.h @@ -8,6 +8,7 @@ #include #include #include +#include class NetworkManager; class Lobby; @@ -113,8 +114,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(); @@ -145,6 +151,9 @@ public: // 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(); diff --git a/courtroom.cpp b/courtroom.cpp index 3a5173c..b275b1f 100644 --- a/courtroom.cpp +++ b/courtroom.cpp @@ -1222,6 +1222,7 @@ 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; @@ -1988,6 +1989,7 @@ void Courtroom::set_text_color() break; default: qDebug() << "W: undefined text color: " << m_chatmessage[TEXT_COLOR]; + // fall through case WHITE: ui_vp_message->setStyleSheet("background-color: rgba(0, 0, 0, 0);" "color: white"); diff --git a/text_file_functions.cpp b/text_file_functions.cpp index 8ddeb6c..bacbe69 100644 --- a/text_file_functions.cpp +++ b/text_file_functions.cpp @@ -8,6 +8,9 @@ #include #include +/* + * This may no longer be necessary, if we use the QSettings class. + * QString AOApplication::read_config(QString searchline) { QString return_value = ""; @@ -41,80 +44,66 @@ QString AOApplication::read_config(QString searchline) return return_value; } +*/ QString AOApplication::read_theme() { - QString result = read_config("theme"); - - if (result == "") - return "default"; - else - return result; + QString result = configini->value("theme", "default").value(); + return result; } int AOApplication::read_blip_rate() { - QString result = read_config("blip_rate"); - - //note: the empty string converted to int will return 0 - if (result.toInt() <= 0) - return 1; - else - return result.toInt(); + int result = configini->value("blip_rate", 1).toInt(); + 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"); - - if (f_result == "") - return 50; - else return f_result.toInt(); + int result = configini->value("default_blip", 50).toInt(); + return result; } int AOApplication::get_max_log_size() { - QString f_result = read_config("log_maximum"); - - if (f_result == "") - return 200; - else return f_result.toInt(); + int result = configini->value("log_maximum", 200).toInt(); + return result; } bool AOApplication::get_log_goes_downwards() { - QString f_result = read_config("log_goes_downwards"); - return f_result.startsWith("true"); + QString result = configini->value("log_goes_downwards", "false").value(); + return result.startsWith("true"); } bool AOApplication::get_showname_enabled_by_default() { - QString f_result = read_config("show_custom_shownames"); - return f_result.startsWith("true"); + QString result = configini->value("show_custom_shownames", "false").value(); + return result.startsWith("true"); } QString AOApplication::get_default_username() { - QString f_result = read_config("default_username"); - return f_result; + QString result = configini->value("default_username", "").value(); + return result; +} + +QString AOApplication::get_audio_output_device() +{ + QString result = configini->value("default_username", "default").value(); + return result; } QStringList AOApplication::get_call_words() @@ -593,9 +582,8 @@ int AOApplication::get_text_delay(QString p_char, QString p_emote) 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"); } From 913939835a9b7bc141756b70e14880b02a46a791 Mon Sep 17 00:00:00 2001 From: Cerapter Date: Wed, 8 Aug 2018 21:48:00 +0200 Subject: [PATCH 034/174] Added a settings menu. - Cannot be called yet ingame. - Allows the setting of all `config.ini` variables. - Allows the setting of callwords. --- Attorney_Online_remake.pro | 6 +- aoapplication.cpp | 29 +++- aoapplication.h | 2 + aooptionsdialog.cpp | 328 +++++++++++++++++++++++++++++++++++++ aooptionsdialog.h | 81 +++++++++ text_file_functions.cpp | 2 +- 6 files changed, 440 insertions(+), 8 deletions(-) create mode 100644 aooptionsdialog.cpp create mode 100644 aooptionsdialog.h diff --git a/Attorney_Online_remake.pro b/Attorney_Online_remake.pro index cc9579a..b1a7d9c 100644 --- a/Attorney_Online_remake.pro +++ b/Attorney_Online_remake.pro @@ -48,7 +48,8 @@ SOURCES += main.cpp\ aolineedit.cpp \ aotextedit.cpp \ aoevidencedisplay.cpp \ - discord_rich_presence.cpp + discord_rich_presence.cpp \ + aooptionsdialog.cpp HEADERS += lobby.h \ aoimage.h \ @@ -79,7 +80,8 @@ HEADERS += lobby.h \ aotextedit.h \ aoevidencedisplay.h \ discord_rich_presence.h \ - discord-rpc.h + discord-rpc.h \ + aooptionsdialog.h # 1. You need to get BASS and put the x86 bass DLL/headers in the project root folder # AND the compilation output folder. If you want a static link, you'll probably diff --git a/aoapplication.cpp b/aoapplication.cpp index cfa9648..b8db52e 100644 --- a/aoapplication.cpp +++ b/aoapplication.cpp @@ -5,6 +5,8 @@ #include "networkmanager.h" #include "debug_functions.h" +#include "aooptionsdialog.h" + #include #include #include @@ -52,7 +54,7 @@ void AOApplication::construct_lobby() int a = 0; BASS_DEVICEINFO info; - for (a = 1; BASS_GetDeviceInfo(a, &info); a++) + for (a = 0; BASS_GetDeviceInfo(a, &info); a++) { if (get_audio_output_device() == info.name) { @@ -60,11 +62,7 @@ void AOApplication::construct_lobby() qDebug() << info.name << "was set as the default audio output device."; break; } - qDebug() << info.name; } - - //AOOptionsDialog* test = new AOOptionsDialog(nullptr, this); - //test->exec(); } void AOApplication::destruct_lobby() @@ -127,6 +125,20 @@ QString AOApplication::get_cccc_version_string() void AOApplication::reload_theme() { current_theme = read_theme(); + + // This may not be the best place for it, but let's read the audio output device just in case. + int a = 0; + BASS_DEVICEINFO info; + + for (a = 0; BASS_GetDeviceInfo(a, &info); a++) + { + if (get_audio_output_device() == info.name) + { + BASS_SetDevice(a); + qDebug() << info.name << "was set as the default audio output device."; + break; + } + } } void AOApplication::set_favorite_list() @@ -197,3 +209,10 @@ 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; +} diff --git a/aoapplication.h b/aoapplication.h index a01ef81..37a425f 100644 --- a/aoapplication.h +++ b/aoapplication.h @@ -42,6 +42,8 @@ public: void send_ms_packet(AOPacket *p_packet); void send_server_packet(AOPacket *p_packet, bool encoded = true); + void call_settings_menu(); + /////////////////server metadata////////////////// unsigned int s_decryptor = 5; diff --git a/aooptionsdialog.cpp b/aooptionsdialog.cpp new file mode 100644 index 0000000..6f325bb --- /dev/null +++ b/aooptionsdialog.cpp @@ -0,0 +1,328 @@ +#include "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 + +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); + + // 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); + + // And finally, 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; + + 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); + + // 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()); + + 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()); + + done(0); +} + +void AOOptionsDialog::discard_pressed() +{ + done(0); +} diff --git a/aooptionsdialog.h b/aooptionsdialog.h new file mode 100644 index 0000000..55dda9b --- /dev/null +++ b/aooptionsdialog.h @@ -0,0 +1,81 @@ +#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 + +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; + 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; + +signals: + +public slots: + void save_pressed(); + void discard_pressed(); +}; + +#endif // AOOPTIONSDIALOG_H diff --git a/text_file_functions.cpp b/text_file_functions.cpp index bacbe69..aa14068 100644 --- a/text_file_functions.cpp +++ b/text_file_functions.cpp @@ -102,7 +102,7 @@ QString AOApplication::get_default_username() QString AOApplication::get_audio_output_device() { - QString result = configini->value("default_username", "default").value(); + QString result = configini->value("default_audio_device", "default").value(); return result; } From 885df58ec92abcde5e8aec60535e1a04d10a4e4a Mon Sep 17 00:00:00 2001 From: Cerapter Date: Wed, 8 Aug 2018 22:28:20 +0200 Subject: [PATCH 035/174] Clientside now no longer displays '.mp3' at the end of every song mention. --- courtroom.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/courtroom.cpp b/courtroom.cpp index b275b1f..3e53867 100644 --- a/courtroom.cpp +++ b/courtroom.cpp @@ -796,10 +796,12 @@ 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.replace(".mp3",""); if (i_song.toLower().contains(ui_music_search->text().toLower())) { - ui_music_list->addItem(i_song); + ui_music_list->addItem(i_song_listname); QString song_path = ao_app->get_base_path() + "sounds/music/" + i_song.toLower(); @@ -2043,6 +2045,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.replace(".mp3", ""); int n_char = f_contents.at(1).toInt(); if (n_char < 0 || n_char >= char_list.size()) @@ -2055,7 +2059,7 @@ void Courtroom::handle_song(QStringList *p_contents) if (!mute_map.value(n_char)) { - append_ic_text(" has played a song: " + f_song, str_char); + append_ic_text(" has played a song: " + f_song_clear, str_char); music_player->play(f_song); } } @@ -2290,7 +2294,8 @@ 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 = ui_music_list->item(p_model.row())->text(); + QString p_song = music_list.at(p_model.row()); ao_app->send_server_packet(new AOPacket("MC#" + p_song + "#" + QString::number(m_cid) + "#%"), false); } From f9fd9a789af5587de40ee131ce709791ca81253b Mon Sep 17 00:00:00 2001 From: Cerapter Date: Thu, 9 Aug 2018 16:36:56 +0200 Subject: [PATCH 036/174] Limit mod call reason limit to 100 on serverside, too. --- server/aoprotocol.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/aoprotocol.py b/server/aoprotocol.py index 1711eba..9b8822b 100644 --- a/server/aoprotocol.py +++ b/server/aoprotocol.py @@ -603,7 +603,7 @@ class AOProtocol(asyncio.Protocol): 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, - self.client.area.id, args[0]), pred=lambda c: c.is_mod) + self.client.area.id, args[0][:100]), pred=lambda c: c.is_mod) self.client.set_mod_call_delay() logger.log_server('[{}][{}]{} called a moderator: {}.'.format(self.client.get_ip(), self.client.area.id, self.client.get_char_name(), args[0])) From 0f2665aabed04f0fe68b1104a0b5df05d0525d01 Mon Sep 17 00:00:00 2001 From: Cerapter Date: Thu, 9 Aug 2018 21:23:30 +0200 Subject: [PATCH 037/174] Settings menu avaiable through ingame means + IC beautification. - Changing songs is now done in italics. --- courtroom.cpp | 111 +++++++++++++++++++++++++++++++++++++++++++++++++- courtroom.h | 5 +++ 2 files changed, 115 insertions(+), 1 deletion(-) diff --git a/courtroom.cpp b/courtroom.cpp index 3e53867..040c5b4 100644 --- a/courtroom.cpp +++ b/courtroom.cpp @@ -161,6 +161,7 @@ Courtroom::Courtroom(AOApplication *p_ao_app) : QMainWindow() 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_pre = new QCheckBox(this); ui_pre->setText("Pre"); @@ -279,6 +280,7 @@ Courtroom::Courtroom(AOApplication *p_ao_app) : QMainWindow() 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_pre, SIGNAL(clicked()), this, SLOT(on_pre_clicked())); connect(ui_flip, SIGNAL(clicked()), this, SLOT(on_flip_clicked())); @@ -490,6 +492,9 @@ 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_pre, "pre"); ui_pre->setText("Pre"); @@ -1472,6 +1477,99 @@ void Courtroom::append_ic_text(QString p_text, QString p_name) } } +// 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); + ui_ic_chatlog->textCursor().insertText(".", normal); + + 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()); + } + + // Finally, if we got too many blocks in the current log, delete some from the top. + while (ui_ic_chatlog->document()->blockCount() > log_maximum_blocks) + { + 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; + } + } + 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, italics); + ui_ic_chatlog->textCursor().insertText(".", normal); + + 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()); + } + + + // Finally, if we got too many blocks in the current log, delete some from the bottom. + while (ui_ic_chatlog->document()->blockCount() > log_maximum_blocks) + { + 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; + } + } +} + void Courtroom::play_preanim() { QString f_char = m_chatmessage[CHAR_NAME]; @@ -2059,7 +2157,7 @@ void Courtroom::handle_song(QStringList *p_contents) if (!mute_map.value(n_char)) { - append_ic_text(" has played a song: " + f_song_clear, str_char); + append_ic_songchange(f_song_clear, str_char); music_player->play(f_song); } } @@ -2150,6 +2248,12 @@ void Courtroom::on_ooc_return_pressed() //rainbow_appended = true; return; } + else if (ooc_message.startsWith("/settings")) + { + ui_ooc_chat_message->clear(); + ao_app->call_settings_menu(); + return; + } QStringList packet_contents; packet_contents.append(ui_ooc_chat_name->text()); @@ -2560,6 +2664,11 @@ void Courtroom::on_call_mod_clicked() ui_ic_chat_message->setFocus(); } +void Courtroom::on_settings_clicked() +{ + ao_app->call_settings_menu(); +} + void Courtroom::on_pre_clicked() { ui_ic_chat_message->setFocus(); diff --git a/courtroom.h b/courtroom.h index df0883c..22d2586 100644 --- a/courtroom.h +++ b/courtroom.h @@ -121,6 +121,9 @@ 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); @@ -360,6 +363,7 @@ private: AOButton *ui_change_character; AOButton *ui_reload_theme; AOButton *ui_call_mod; + AOButton *ui_settings; QCheckBox *ui_pre; QCheckBox *ui_flip; @@ -511,6 +515,7 @@ private slots: void on_change_character_clicked(); void on_reload_theme_clicked(); void on_call_mod_clicked(); + void on_settings_clicked(); void on_pre_clicked(); void on_flip_clicked(); From 0280f42f6ea2443757f0aa483322d60a5b2c0b6f Mon Sep 17 00:00:00 2001 From: Cerapter Date: Thu, 9 Aug 2018 22:19:39 +0200 Subject: [PATCH 038/174] PMs now show ID (and IPID if you're a mod). --- server/commands.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/server/commands.py b/server/commands.py index efcfe38..b8a21b3 100644 --- a/server/commands.py +++ b/server/commands.py @@ -466,7 +466,10 @@ def ooc_cmd_pm(client, arg): if c.pm_mute: raise ClientError('This user muted all pm conversation') else: - c.send_host_message('PM from {} in {} ({}): {}'.format(client.name, client.area.name, client.get_char_name(), msg)) + 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): From 84da730bcef71aeb0d0944261a44dc289949a74d Mon Sep 17 00:00:00 2001 From: Cerapter Date: Fri, 10 Aug 2018 00:09:41 +0200 Subject: [PATCH 039/174] Music changing now shows your custom showname, if set. --- courtroom.cpp | 15 ++++++++++++++- server/aoprotocol.py | 11 ++++++++--- server/area_manager.py | 12 ++++++++++++ 3 files changed, 34 insertions(+), 4 deletions(-) diff --git a/courtroom.cpp b/courtroom.cpp index 040c5b4..1b24bd3 100644 --- a/courtroom.cpp +++ b/courtroom.cpp @@ -2155,6 +2155,12 @@ void Courtroom::handle_song(QStringList *p_contents) { QString str_char = char_list.at(n_char).name; + if (p_contents->length() > 2) + { + if (ui_showname_enable->isChecked()) + str_char = p_contents->at(2); + } + if (!mute_map.value(n_char)) { append_ic_songchange(f_song_clear, str_char); @@ -2401,7 +2407,14 @@ void Courtroom::on_music_list_double_clicked(QModelIndex p_model) //QString p_song = ui_music_list->item(p_model.row())->text(); QString p_song = music_list.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->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_hold_it_clicked() diff --git a/server/aoprotocol.py b/server/aoprotocol.py index 9b8822b..d26afc9 100644 --- a/server/aoprotocol.py +++ b/server/aoprotocol.py @@ -478,7 +478,7 @@ class AOProtocol(asyncio.Protocol): if not self.client.is_dj: self.client.send_host_message('You were blockdj\'d by a moderator.') return - if not self.validate_net_cmd(args, self.ArgType.STR, self.ArgType.INT): + 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 @@ -487,8 +487,13 @@ class AOProtocol(asyncio.Protocol): return try: name, length = self.server.get_song_data(args[0]) - self.client.area.play_music(name, self.client.char_id, length) - self.client.area.add_music_playing(self.client, name) + if len(args) > 2: + showname = args[2] + 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.id, self.client.get_char_name(), name), self.client) except ServerError: diff --git a/server/area_manager.py b/server/area_manager.py index 3ed543d..99b4efd 100644 --- a/server/area_manager.py +++ b/server/area_manager.py @@ -116,6 +116,14 @@ class AreaManager: 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): @@ -159,6 +167,10 @@ class AreaManager: self.current_music_player = client.get_char_name() 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 = name + def get_evidence_list(self, client): client.evi_list, evi_list = self.evi_list.create_evi_list(client) return evi_list From bf971f69d8a4317d511334727455f368906b9a21 Mon Sep 17 00:00:00 2001 From: Cerapter Date: Fri, 10 Aug 2018 00:30:05 +0200 Subject: [PATCH 040/174] Fixed a bug where showname change rules got ignored when changing songs. --- server/aoprotocol.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/server/aoprotocol.py b/server/aoprotocol.py index d26afc9..877b617 100644 --- a/server/aoprotocol.py +++ b/server/aoprotocol.py @@ -489,6 +489,9 @@ class AOProtocol(asyncio.Protocol): name, length = self.server.get_song_data(args[0]) 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: From 5c7b233f8c5266ec04830ac64a534765d01fc495 Mon Sep 17 00:00:00 2001 From: Cerapter Date: Fri, 10 Aug 2018 22:17:19 +0200 Subject: [PATCH 041/174] Area statuses updated. --- server/area_manager.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/server/area_manager.py b/server/area_manager.py index 99b4efd..3ee2b27 100644 --- a/server/area_manager.py +++ b/server/area_manager.py @@ -150,9 +150,11 @@ class AreaManager: self.send_command('BN', self.background) def change_status(self, value): - allowed_values = ('idle', 'building-open', 'building-full', 'casing-open', 'casing-full', 'recess') + 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() def change_doc(self, doc='No document.'): From 1add0108e8f592e471905d8391f1b8f8b5daea0c Mon Sep 17 00:00:00 2001 From: Cerapter Date: Sat, 11 Aug 2018 00:31:42 +0200 Subject: [PATCH 042/174] Added the ability to un-CM self. --- server/commands.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/server/commands.py b/server/commands.py index b8a21b3..701a82f 100644 --- a/server/commands.py +++ b/server/commands.py @@ -538,6 +538,16 @@ def ooc_cmd_cm(client, arg): if client.area.evidence_mod == 'HiddenCM': client.area.broadcast_evidence_list() client.area.send_host_message('{} is CM in this area now.'.format(client.get_char_name())) + +def ooc_cmd_uncm(client, arg): + if client.is_cm: + client.is_cm = False + client.area.owned = False + if client.area.is_locked: + client.area.unlock() + client.area.send_host_message('{} is no longer CM in this area.'.format(client.get_char_name())) + else: + raise ClientError('You cannot give up being the CM when you are not one') def ooc_cmd_unmod(client, arg): client.is_mod = False From c22606b5a70d8afa845e6f274521a89cd240a18e Mon Sep 17 00:00:00 2001 From: Cerapter Date: Sat, 11 Aug 2018 01:02:07 +0200 Subject: [PATCH 043/174] /currentmusic now tells you the IPID of the last music changer if you're a mod. --- server/area_manager.py | 3 +++ server/commands.py | 6 +++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/server/area_manager.py b/server/area_manager.py index 3ee2b27..374c529 100644 --- a/server/area_manager.py +++ b/server/area_manager.py @@ -44,6 +44,7 @@ class AreaManager: 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 = [] @@ -167,10 +168,12 @@ class AreaManager: 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): diff --git a/server/commands.py b/server/commands.py index 701a82f..14ae147 100644 --- a/server/commands.py +++ b/server/commands.py @@ -152,7 +152,11 @@ def ooc_cmd_currentmusic(client, arg): raise ArgumentError('This command has no arguments.') if client.area.current_music == '': raise ClientError('There is no music currently playing.') - client.send_host_message('The current music is {} and was played by {}.'.format(client.area.current_music, + 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_coinflip(client, arg): From 3759131a8f0c0d65e14fdda9748de300dc23670d Mon Sep 17 00:00:00 2001 From: Cerapter Date: Sun, 12 Aug 2018 00:12:09 +0200 Subject: [PATCH 044/174] Area numbers replaced by area abbreviations. --- server/aoprotocol.py | 10 ++++------ server/area_manager.py | 12 ++++++++++++ server/client_manager.py | 4 ++-- server/commands.py | 2 +- server/tsuserver.py | 4 ++-- 5 files changed, 21 insertions(+), 11 deletions(-) diff --git a/server/aoprotocol.py b/server/aoprotocol.py index 877b617..9bddb0a 100644 --- a/server/aoprotocol.py +++ b/server/aoprotocol.py @@ -603,15 +603,13 @@ class AOProtocol(asyncio.Protocol): 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, - self.client.area.id), pred=lambda c: c.is_mod) + 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.get_ip(), self.client.area.id, self.client.get_char_name())) 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, - self.client.area.id, args[0][:100]), pred=lambda c: c.is_mod) + 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.get_ip(), self.client.area.id, self.client.get_char_name(), args[0])) diff --git a/server/area_manager.py b/server/area_manager.py index 374c529..36ade64 100644 --- a/server/area_manager.py +++ b/server/area_manager.py @@ -187,6 +187,18 @@ class AreaManager: """ for client in self.clients: client.send_command('LE', *self.get_evidence_list(client)) + + def get_abbreviation(self): + if self.name.lower().startswith("courtroom"): + return "CR" + self.name.split()[-1] + elif self.name.lower().startswith("area"): + return "A" + self.name.split()[-1] + elif len(self.name.split()) > 1: + return "".join(item[0].upper() for item in self.name.split()) + elif len(self.name) > 3: + return self.name[:3].upper() + else: + return self.name.upper() def __init__(self, server): diff --git a/server/client_manager.py b/server/client_manager.py index 6857269..0030173 100644 --- a/server/client_manager.py +++ b/server/client_manager.py @@ -203,7 +203,7 @@ class ClientManager: for client in [x for x in area.clients if x.is_cm]: owner = 'MASTER: {}'.format(client.get_char_name()) break - msg += '\r\nArea {}: {} (users: {}) [{}][{}]{}'.format(i, area.name, len(area.clients), area.status, owner, lock[area.is_locked]) + msg += '\r\nArea {}: {} (users: {}) [{}][{}]{}'.format(area.get_abbreviation(), area.name, len(area.clients), area.status, owner, lock[area.is_locked]) if self.area == area: msg += ' [*]' self.send_host_message(msg) @@ -214,7 +214,7 @@ class ClientManager: area = self.server.area_manager.get_area_by_id(area_id) except AreaError: raise - info += '= Area {}: {} =='.format(area.id, area.name) + info += '=== {} ==='.format(area.name) sorted_clients = [] for client in area.clients: if (not mods) or client.is_mod: diff --git a/server/commands.py b/server/commands.py index 14ae147..f58dbea 100644 --- a/server/commands.py +++ b/server/commands.py @@ -593,7 +593,7 @@ def ooc_cmd_invite(client, arg): c = client.server.client_manager.get_targets(client, TargetType.ID, int(arg), False)[0] client.area.invite_list[c.ipid] = 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 area {}.'.format(client.area.id)) + 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 ') diff --git a/server/tsuserver.py b/server/tsuserver.py index 14ad60b..9438a35 100644 --- a/server/tsuserver.py +++ b/server/tsuserver.py @@ -232,7 +232,7 @@ class TsuServer3: def broadcast_global(self, client, msg, as_mod=False): char_name = client.get_char_name() - ooc_name = '{}[{}][{}]'.format('G', client.area.id, char_name) + ooc_name = '{}[{}][{}]'.format('G', client.area.get_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) @@ -243,7 +243,7 @@ class TsuServer3: def broadcast_need(self, client, msg): char_name = client.get_char_name() area_name = client.area.name - area_id = client.area.id + area_id = client.area.get_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), pred=lambda x: not x.muted_adverts) From d444eb6dceb47123940baed5a255572d24567dc8 Mon Sep 17 00:00:00 2001 From: Cerapter Date: Sun, 12 Aug 2018 00:32:43 +0200 Subject: [PATCH 045/174] Modchat for mods to chat secretly across areas. Called with `/m [message]`. --- server/commands.py | 8 ++++++++ server/tsuserver.py | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/server/commands.py b/server/commands.py index f58dbea..b8748ed 100644 --- a/server/commands.py +++ b/server/commands.py @@ -343,6 +343,14 @@ def ooc_cmd_gm(client, arg): client.server.broadcast_global(client, arg, True) logger.log_server('[{}][{}][GLOBAL-MOD]{}.'.format(client.area.id, 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.id, 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.') diff --git a/server/tsuserver.py b/server/tsuserver.py index 9438a35..a7aed5d 100644 --- a/server/tsuserver.py +++ b/server/tsuserver.py @@ -240,6 +240,14 @@ class TsuServer3: 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.get_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 From 00b5af9b60aaeeb26511f29a6f839210ee9c8234 Mon Sep 17 00:00:00 2001 From: Cerapter Date: Sun, 12 Aug 2018 02:17:07 +0200 Subject: [PATCH 046/174] Fixed the `/invite` and `/uninvite` commands so they work as they claim they do. - You can now invite and uninvite by IDs. --- server/client_manager.py | 2 +- server/commands.py | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/server/client_manager.py b/server/client_manager.py index 0030173..e127880 100644 --- a/server/client_manager.py +++ b/server/client_manager.py @@ -168,7 +168,7 @@ class ClientManager: def change_area(self, area): if self.area == area: raise ClientError('User already in specified area.') - if area.is_locked and not self.is_mod and not self.ipid in area.invite_list: + if area.is_locked and not self.is_mod and not self.id in area.invite_list: #self.send_host_message('This area is locked - you will be unable to send messages ICly.') raise ClientError("That area is locked!") old_area = self.area diff --git a/server/commands.py b/server/commands.py index b8748ed..853a37d 100644 --- a/server/commands.py +++ b/server/commands.py @@ -577,7 +577,7 @@ def ooc_cmd_area_lock(client, arg): client.area.is_locked = True client.area.send_host_message('Area is locked.') for i in client.area.clients: - client.area.invite_list[i.ipid] = None + client.area.invite_list[i.id] = None return else: raise ClientError('Only CM can lock the area.') @@ -599,7 +599,7 @@ def ooc_cmd_invite(client, arg): 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.ipid] = None + 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: @@ -620,7 +620,7 @@ def ooc_cmd_uninvite(client, arg): 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.invite_list.pop(c.ipid) + client.area.invite_list.pop(c.id) except AreaError: raise except ClientError: @@ -653,7 +653,7 @@ def ooc_cmd_area_kick(client, arg): 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.invite_list.pop(c.ipid) + client.area.invite_list.pop(c.id) except AreaError: raise except ClientError: From 37c0a709488d6d8b3d8191f321098ea996d9cf70 Mon Sep 17 00:00:00 2001 From: Cerapter Date: Mon, 13 Aug 2018 08:30:29 +0200 Subject: [PATCH 047/174] `/rolla_set`'s display fixed. --- server/commands.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/commands.py b/server/commands.py index 853a37d..eb42470 100644 --- a/server/commands.py +++ b/server/commands.py @@ -825,7 +825,7 @@ def rolla_reload(area): def ooc_cmd_rolla_set(client, arg): if not hasattr(client.area, 'ability_dice'): rolla_reload(client.area) - available_sets = client.area.ability_dice.keys() + 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: From 3712526ff0e4a715ea9548f331edfc43d1502eb9 Mon Sep 17 00:00:00 2001 From: Cerapter Date: Mon, 13 Aug 2018 14:39:09 +0200 Subject: [PATCH 048/174] Added a HDID-based banning system. --- server/aoprotocol.py | 5 ++++- server/ban_manager.py | 31 +++++++++++++++++++++++++++++++ server/commands.py | 33 +++++++++++++++++++++++++++++++-- 3 files changed, 66 insertions(+), 3 deletions(-) diff --git a/server/aoprotocol.py b/server/aoprotocol.py index 9bddb0a..75ee824 100644 --- a/server/aoprotocol.py +++ b/server/aoprotocol.py @@ -65,7 +65,7 @@ class AOProtocol(asyncio.Protocol): buf = data - if not self.client.is_checked and self.server.ban_manager.is_banned(self.client.ipid): + if not self.client.is_checked and (self.server.ban_manager.is_banned(self.client.ipid) or self.server.ban_manager.is_hdid_banned(self.client.hdid)): self.client.transport.close() else: self.client.is_checked = True @@ -165,6 +165,9 @@ class AOProtocol(asyncio.Protocol): if not self.validate_net_cmd(args, self.ArgType.STR, needs_auth=False): return self.client.hdid = args[0] + if self.server.ban_manager.is_hdid_banned(self.client.hdid): + self.client.disconnect() + return 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]: diff --git a/server/ban_manager.py b/server/ban_manager.py index 24518b2..b4f97b7 100644 --- a/server/ban_manager.py +++ b/server/ban_manager.py @@ -25,6 +25,9 @@ class BanManager: self.bans = [] self.load_banlist() + self.hdid_bans = [] + self.load_hdid_banlist() + def load_banlist(self): try: with open('storage/banlist.json', 'r') as banlist_file: @@ -52,3 +55,31 @@ class BanManager: def is_banned(self, ipid): return (ipid in self.bans) + + def load_hdid_banlist(self): + try: + with open('storage/banlist_hdid.json', 'r') as banlist_file: + self.hdid_bans = json.load(banlist_file) + except FileNotFoundError: + return + + def write_hdid_banlist(self): + with open('storage/banlist_hdid.json', 'w') as banlist_file: + json.dump(self.hdid_bans, banlist_file) + + def add_hdid_ban(self, hdid): + if hdid not in self.hdid_bans: + self.hdid_bans.append(hdid) + else: + raise ServerError('This HDID is already banned.') + self.write_hdid_banlist() + + def remove_hdid_ban(self, hdid): + if hdid in self.hdid_bans: + self.hdid_bans.remove(hdid) + else: + raise ServerError('This HDID is not banned.') + self.write_hdid_banlist() + + def is_hdid_banned(self, hdid): + return (hdid in self.hdid_bans) \ No newline at end of file diff --git a/server/commands.py b/server/commands.py index eb42470..c1143d2 100644 --- a/server/commands.py +++ b/server/commands.py @@ -275,10 +275,39 @@ def ooc_cmd_unban(client, arg): try: client.server.ban_manager.remove_ban(int(arg.strip())) except: - raise ClientError('You must specify \'hdid\'') + raise ClientError('You must specify ipid') + logger.log_server('Unbanned {}.'.format(arg), client) + client.send_host_message('Unbanned {}'.format(arg)) + +def ooc_cmd_ban_hdid(client, arg): + if not client.is_mod: + raise ClientError('You must be authorized to do that.') + try: + hdid = int(arg.strip()) + except: + raise ClientError('You must specify hdid') + try: + client.server.ban_manager.add_hdid_ban(hdid) + except ServerError: + raise + if hdid != None: + targets = client.server.client_manager.get_targets(client, TargetType.HDID, hdid, False) + if targets: + for c in targets: + c.disconnect() + client.send_host_message('{} clients was kicked.'.format(len(targets))) + client.send_host_message('{} was banned.'.format(hdid)) + logger.log_server('Banned {}.'.format(hdid), client) + +def ooc_cmd_unban_hdid(client, arg): + if not client.is_mod: + raise ClientError('You must be authorized to do that.') + try: + client.server.ban_manager.remove_hdid_ban(int(arg.strip())) + except: + raise ClientError('You must specify hdid') logger.log_server('Unbanned {}.'.format(arg), client) client.send_host_message('Unbanned {}'.format(arg)) - def ooc_cmd_play(client, arg): if not client.is_mod: From b8dc30a822c57a3e3ee1995423b161e0fec0a3e4 Mon Sep 17 00:00:00 2001 From: Cerapter Date: Mon, 13 Aug 2018 18:08:43 +0200 Subject: [PATCH 049/174] The game now keeps every character's icon in memory for a fast character sceen. Additionally, the loading at the beginning is smoother. --- charselect.cpp | 105 +++++++++++++++++++++++----------------- courtroom.h | 6 +++ packet_distribution.cpp | 36 +++++++------- 3 files changed, 86 insertions(+), 61 deletions(-) diff --git a/charselect.cpp b/charselect.cpp index 541f1e0..c075876 100644 --- a/charselect.cpp +++ b/charselect.cpp @@ -26,42 +26,8 @@ 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"); - - const int button_width = 60; - int x_spacing = f_spacing.x(); - int x_mod_count = 0; - - const int button_height = 60; - int y_spacing = f_spacing.y(); - int y_mod_count = 0; - 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())); @@ -97,7 +63,10 @@ void Courtroom::set_char_select_page() ui_char_select_right->hide(); for (AOCharButton *i_button : ui_char_button_list) + { i_button->hide(); + i_button->move(0,0); + } int total_pages = char_list.size() / max_chars_on_page; int chars_on_page = 0; @@ -121,26 +90,24 @@ 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) + put_button_in_place(current_char_page * max_chars_on_page, chars_on_page); + + /*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(); - } + }*/ } 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,15 +117,65 @@ 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_real_char).name); + ui_ic_chat_name->setPlaceholderText(char_list.at(n_char).name); } +void Courtroom::put_button_in_place(int starting, int chars_on_this_page) +{ + 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; + + 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.at(n)->move(x_pos, y_pos); + ui_char_button_list.at(n)->show(); + + ++x_mod_count; + + if (x_mod_count == char_columns) + { + ++y_mod_count; + x_mod_count = 0; + } + } +} + +void Courtroom::character_loading_finished() +{ + // We move them out of the reachable area, so they can't be accidentally clicked. + // First, we'll make all the character buttons in the very beginning. + // We hide them too, just in case. + for (int n = 0; n < char_list.size(); n++) + { + AOCharButton* character = new AOCharButton(ui_char_buttons, ao_app, 0, 0); + 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); + } + + put_button_in_place(0, max_chars_on_page); +} diff --git a/courtroom.h b/courtroom.h index 22d2586..eb8943e 100644 --- a/courtroom.h +++ b/courtroom.h @@ -47,6 +47,8 @@ public: void append_evidence(evi_type p_evi){evidence_list.append(p_evi);} void append_music(QString f_music){music_list.append(f_music);} + void character_loading_finished(); + //sets position of widgets based on theme ini files void set_widgets(); //sets font size based on theme ini files @@ -272,6 +274,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; @@ -427,6 +432,7 @@ private: 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 construct_emotes(); void set_emote_page(); diff --git a/packet_distribution.cpp b/packet_distribution.cpp index 6e94f41..fe5c534 100644 --- a/packet_distribution.cpp +++ b/packet_distribution.cpp @@ -296,11 +296,11 @@ void AOApplication::server_packet_received(AOPacket *p_packet) w_lobby->set_loading_text("Loading chars:\n" + QString::number(loaded_chars) + "/" + QString::number(char_list_size)); w_courtroom->append_char(f_char); - } - int total_loading_size = char_list_size + evidence_list_size + music_list_size; - int loading_value = (loaded_chars / static_cast(total_loading_size)) * 100; - w_lobby->set_loading_value(loading_value); + int total_loading_size = char_list_size + evidence_list_size + music_list_size; + int loading_value = int(((loaded_chars + loaded_music + loaded_evidence) / static_cast(total_loading_size)) * 100); + w_lobby->set_loading_value(loading_value); + } if (improved_loading_enabled) send_server_packet(new AOPacket("RE#%")); @@ -342,7 +342,7 @@ 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 loading_value = int(((loaded_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); @@ -369,11 +369,11 @@ 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); - } - int total_loading_size = char_list_size + evidence_list_size + music_list_size; - int loading_value = ((loaded_chars + loaded_evidence + loaded_music) / static_cast(total_loading_size)) * 100; - w_lobby->set_loading_value(loading_value); + int total_loading_size = char_list_size + evidence_list_size + music_list_size; + int loading_value = int(((loaded_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 + "#%")); @@ -414,11 +414,12 @@ void AOApplication::server_packet_received(AOPacket *p_packet) w_lobby->set_loading_text("Loading chars:\n" + QString::number(loaded_chars) + "/" + QString::number(char_list_size)); w_courtroom->append_char(f_char); - } - int total_loading_size = char_list_size + evidence_list_size + music_list_size; - int loading_value = (loaded_chars / static_cast(total_loading_size)) * 100; - w_lobby->set_loading_value(loading_value); + int total_loading_size = char_list_size + evidence_list_size + music_list_size; + int loading_value = int(((loaded_chars + loaded_music + loaded_evidence) / static_cast(total_loading_size)) * 100); + w_lobby->set_loading_value(loading_value); + } + w_courtroom->character_loading_finished(); send_server_packet(new AOPacket("RM#%")); } @@ -434,11 +435,11 @@ 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_contents.at(n_element)); - } - int total_loading_size = char_list_size + evidence_list_size + music_list_size; - int loading_value = (loaded_chars / static_cast(total_loading_size)) * 100; - w_lobby->set_loading_value(loading_value); + int total_loading_size = char_list_size + evidence_list_size + music_list_size; + int loading_value = int(((loaded_chars + loaded_music + loaded_evidence) / static_cast(total_loading_size)) * 100); + w_lobby->set_loading_value(loading_value); + } send_server_packet(new AOPacket("RD#%")); } @@ -450,6 +451,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; From 2aec9710e5c83fe45d643307bad0f6dcbdf2f831 Mon Sep 17 00:00:00 2001 From: Cerapter Date: Mon, 13 Aug 2018 21:56:02 +0200 Subject: [PATCH 050/174] Added character filtering options to the char. select. screen. - Filtering by name. - Filtering by availability. - Filtering by being passworded (though this is unimplemented in AO). --- charselect.cpp | 87 +++++++++++++++++++++++++++++++++++++++----------- courtroom.h | 9 ++++++ 2 files changed, 77 insertions(+), 19 deletions(-) diff --git a/charselect.cpp b/charselect.cpp index c075876..bfa5960 100644 --- a/charselect.cpp +++ b/charselect.cpp @@ -19,6 +19,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,6 +27,18 @@ void Courtroom::construct_char_select() ui_spectator = new AOButton(ui_char_select_background, ao_app); ui_spectator->setText("Spectator"); + ui_char_search = new QLineEdit(ui_char_select_background); + ui_char_search->setPlaceholderText("Search"); + set_size_and_pos(ui_char_search, "char_search"); + + ui_char_passworded = new QCheckBox(ui_char_select_background); + ui_char_passworded->setText("Passworded"); + set_size_and_pos(ui_char_passworded, "char_passworded"); + + ui_char_taken = new QCheckBox(ui_char_select_background); + ui_char_taken->setText("Taken"); + set_size_and_pos(ui_char_taken, "char_taken"); + set_size_and_pos(ui_char_buttons, "char_buttons"); connect (char_button_mapper, SIGNAL(mapped(int)), this, SLOT(char_clicked(int))); @@ -35,6 +48,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() @@ -68,17 +85,17 @@ void Courtroom::set_char_select_page() 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 @@ -91,18 +108,6 @@ void Courtroom::set_char_select_page() ui_char_select_left->show(); put_button_in_place(current_char_page * max_chars_on_page, chars_on_page); - - /*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->show(); - - if (char_list.at(n_real_char).taken) - f_button->set_taken(); - }*/ - } void Courtroom::char_clicked(int n_char) @@ -131,6 +136,9 @@ void Courtroom::char_clicked(int n_char) 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(); @@ -148,8 +156,8 @@ void Courtroom::put_button_in_place(int starting, int chars_on_this_page) int x_pos = (button_width + x_spacing) * x_mod_count; int y_pos = (button_height + y_spacing) * y_mod_count; - ui_char_button_list.at(n)->move(x_pos, y_pos); - ui_char_button_list.at(n)->show(); + ui_char_button_list_filtered.at(n)->move(x_pos, y_pos); + ui_char_button_list_filtered.at(n)->show(); ++x_mod_count; @@ -163,9 +171,9 @@ void Courtroom::put_button_in_place(int starting, int chars_on_this_page) void Courtroom::character_loading_finished() { - // We move them out of the reachable area, so they can't be accidentally clicked. // First, we'll make all the character buttons in the very beginning. - // We hide them too, just in case. + // 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); @@ -177,5 +185,46 @@ void Courtroom::character_loading_finished() char_button_mapper->setMapping(character, ui_char_button_list.size() - 1); } + filter_character_list(); put_button_in_place(0, max_chars_on_page); } + +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/courtroom.h b/courtroom.h index eb8943e..1cc2ed4 100644 --- a/courtroom.h +++ b/courtroom.h @@ -418,6 +418,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; @@ -429,10 +430,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(); @@ -538,6 +544,9 @@ 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(); From d36fdace38833ee468afff785e68e90b86b81a10 Mon Sep 17 00:00:00 2001 From: Cerapter Date: Mon, 13 Aug 2018 22:35:31 +0200 Subject: [PATCH 051/174] Fixed a bug where a server having less characters than you could fit on your screen would crash the game. --- charselect.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/charselect.cpp b/charselect.cpp index bfa5960..abc481d 100644 --- a/charselect.cpp +++ b/charselect.cpp @@ -186,7 +186,12 @@ void Courtroom::character_loading_finished() } filter_character_list(); - put_button_in_place(0, max_chars_on_page); + + int chars_on_page = max_chars_on_page; + if (ui_char_button_list_filtered.size() < max_chars_on_page) + chars_on_page = ui_char_button_list_filtered.size(); + put_button_in_place(0, chars_on_page); + } void Courtroom::filter_character_list() From 693eb81962a51a406834bfaeba934c04b5c2e374 Mon Sep 17 00:00:00 2001 From: Cerapter Date: Tue, 14 Aug 2018 01:37:53 +0200 Subject: [PATCH 052/174] Clearer loading screen that expands on what is being loaded + autofocus on search. --- aoapplication.h | 1 + charselect.cpp | 12 ++++++++++++ packet_distribution.cpp | 20 ++++++++++---------- 3 files changed, 23 insertions(+), 10 deletions(-) diff --git a/aoapplication.h b/aoapplication.h index 37a425f..d386811 100644 --- a/aoapplication.h +++ b/aoapplication.h @@ -66,6 +66,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; diff --git a/charselect.cpp b/charselect.cpp index abc481d..959a364 100644 --- a/charselect.cpp +++ b/charselect.cpp @@ -1,4 +1,5 @@ #include "courtroom.h" +#include "lobby.h" #include "file_functions.h" #include "debug_functions.h" @@ -29,6 +30,7 @@ void Courtroom::construct_char_select() 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"); ui_char_passworded = new QCheckBox(ui_char_select_background); @@ -70,6 +72,8 @@ 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"); + + ui_char_search->setFocus(); } void Courtroom::set_char_select_page() @@ -183,6 +187,14 @@ void Courtroom::character_loading_finished() 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. + 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(); diff --git a/packet_distribution.cpp b/packet_distribution.cpp index fe5c534..3dce5f8 100644 --- a/packet_distribution.cpp +++ b/packet_distribution.cpp @@ -297,8 +297,8 @@ void AOApplication::server_packet_received(AOPacket *p_packet) w_courtroom->append_char(f_char); - int total_loading_size = char_list_size + evidence_list_size + music_list_size; - int loading_value = int(((loaded_chars + loaded_music + 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); } @@ -341,8 +341,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 = int(((loaded_chars + loaded_music + 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); @@ -370,8 +370,8 @@ void AOApplication::server_packet_received(AOPacket *p_packet) w_courtroom->append_music(f_music); - int total_loading_size = char_list_size + evidence_list_size + music_list_size; - int loading_value = int(((loaded_chars + loaded_music + 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); } @@ -415,8 +415,8 @@ void AOApplication::server_packet_received(AOPacket *p_packet) w_courtroom->append_char(f_char); - int total_loading_size = char_list_size + evidence_list_size + music_list_size; - int loading_value = int(((loaded_chars + loaded_music + 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); } w_courtroom->character_loading_finished(); @@ -436,8 +436,8 @@ void AOApplication::server_packet_received(AOPacket *p_packet) w_courtroom->append_music(f_contents.at(n_element)); - int total_loading_size = char_list_size + evidence_list_size + music_list_size; - int loading_value = int(((loaded_chars + loaded_music + 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); } From b99e9c18b272d625ff6749c8924fd7b1c56821ce Mon Sep 17 00:00:00 2001 From: Cerapter Date: Tue, 14 Aug 2018 13:18:03 +0200 Subject: [PATCH 053/174] Changed the exe's official name to Attorney_Online_CC. --- .gitignore | 4 +++- Attorney_Online_remake.pro | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index b3c3db4..d18dfea 100644 --- a/.gitignore +++ b/.gitignore @@ -22,4 +22,6 @@ object_script* server/__pycache__ *.o -moc* \ No newline at end of file +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 b1a7d9c..f26d5ee 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_CC TEMPLATE = app VERSION = 2.4.8.0 From f81a9adc99cb03c63fc05689697dfac7f287dc07 Mon Sep 17 00:00:00 2001 From: Cerapter Date: Tue, 14 Aug 2018 16:33:35 +0200 Subject: [PATCH 054/174] Fixed a bug where the character selection screen would pile up charicons. - Also fixed the loading bar showing wrong values. --- charselect.cpp | 9 +++++++++ packet_distribution.cpp | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/charselect.cpp b/charselect.cpp index 959a364..822ea78 100644 --- a/charselect.cpp +++ b/charselect.cpp @@ -175,6 +175,15 @@ void Courtroom::put_button_in_place(int starting, int chars_on_this_page) void Courtroom::character_loading_finished() { + // Zeroeth, we'll clear any leftover characters from previous server visits. + 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. diff --git a/packet_distribution.cpp b/packet_distribution.cpp index 3dce5f8..19ae7bb 100644 --- a/packet_distribution.cpp +++ b/packet_distribution.cpp @@ -218,6 +218,7 @@ void AOApplication::server_packet_received(AOPacket *p_packet) loaded_chars = 0; loaded_evidence = 0; loaded_music = 0; + generated_chars = 0; destruct_courtroom(); construct_courtroom(); @@ -419,7 +420,6 @@ void AOApplication::server_packet_received(AOPacket *p_packet) 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); } - w_courtroom->character_loading_finished(); send_server_packet(new AOPacket("RM#%")); } From 0f8cb919e289d433d8a7e84b16b934c2b04c7dd2 Mon Sep 17 00:00:00 2001 From: Cerapter Date: Tue, 14 Aug 2018 17:06:23 +0200 Subject: [PATCH 055/174] Fixed a bug where the music being played would depend on the row selected. --- courtroom.cpp | 5 +++-- courtroom.h | 2 ++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/courtroom.cpp b/courtroom.cpp index 1b24bd3..8d50015 100644 --- a/courtroom.cpp +++ b/courtroom.cpp @@ -790,6 +790,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"; @@ -807,6 +808,7 @@ void Courtroom::list_music() if (i_song.toLower().contains(ui_music_search->text().toLower())) { 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(); @@ -2404,8 +2406,7 @@ 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(p_model.row()); + QString p_song = music_list.at(music_row_to_number.at(p_model.row())); if (!ui_ic_chat_name->text().isEmpty()) { diff --git a/courtroom.h b/courtroom.h index 1cc2ed4..8a93543 100644 --- a/courtroom.h +++ b/courtroom.h @@ -191,6 +191,8 @@ private: QSignalMapper *char_button_mapper; + QVector music_row_to_number; + //triggers ping_server() every 60 seconds QTimer *keepalive_timer; From af4a62b65d07d9afff137d55906e38cef6356300 Mon Sep 17 00:00:00 2001 From: Cerapter Date: Tue, 14 Aug 2018 18:32:41 +0200 Subject: [PATCH 056/174] Fixed chatlog not working properly. --- courtroom.cpp | 82 +++++++++++++++++++++++++-------------------------- 1 file changed, 40 insertions(+), 42 deletions(-) diff --git a/courtroom.cpp b/courtroom.cpp index 8d50015..293b39d 100644 --- a/courtroom.cpp +++ b/courtroom.cpp @@ -1421,6 +1421,16 @@ void Courtroom::append_ic_text(QString p_text, QString p_name) 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) + { + 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. @@ -1433,16 +1443,6 @@ void Courtroom::append_ic_text(QString p_text, QString p_name) ui_ic_chatlog->moveCursor(QTextCursor::End); ui_ic_chatlog->verticalScrollBar()->setValue(ui_ic_chatlog->verticalScrollBar()->maximum()); } - - // Finally, if we got too many blocks in the current log, delete some from the top. - while (ui_ic_chatlog->document()->blockCount() > log_maximum_blocks) - { - 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; - } } else { @@ -1453,6 +1453,16 @@ void Courtroom::append_ic_text(QString p_text, QString p_name) 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) + { + 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. @@ -1465,17 +1475,6 @@ void Courtroom::append_ic_text(QString p_text, QString p_name) ui_ic_chatlog->moveCursor(QTextCursor::Start); ui_ic_chatlog->verticalScrollBar()->setValue(ui_ic_chatlog->verticalScrollBar()->minimum()); } - - - // Finally, if we got too many blocks in the current log, delete some from the bottom. - while (ui_ic_chatlog->document()->blockCount() > log_maximum_blocks) - { - 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; - } } } @@ -1511,6 +1510,16 @@ void Courtroom::append_ic_songchange(QString p_songname, QString p_name) ui_ic_chatlog->textCursor().insertText(p_songname, italics); ui_ic_chatlog->textCursor().insertText(".", 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) + { + 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. @@ -1523,16 +1532,6 @@ void Courtroom::append_ic_songchange(QString p_songname, QString p_name) ui_ic_chatlog->moveCursor(QTextCursor::End); ui_ic_chatlog->verticalScrollBar()->setValue(ui_ic_chatlog->verticalScrollBar()->maximum()); } - - // Finally, if we got too many blocks in the current log, delete some from the top. - while (ui_ic_chatlog->document()->blockCount() > log_maximum_blocks) - { - 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; - } } else { @@ -1546,6 +1545,16 @@ void Courtroom::append_ic_songchange(QString p_songname, QString p_name) ui_ic_chatlog->textCursor().insertText(p_songname, italics); ui_ic_chatlog->textCursor().insertText(".", 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) + { + 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. @@ -1558,17 +1567,6 @@ void Courtroom::append_ic_songchange(QString p_songname, QString p_name) ui_ic_chatlog->moveCursor(QTextCursor::Start); ui_ic_chatlog->verticalScrollBar()->setValue(ui_ic_chatlog->verticalScrollBar()->minimum()); } - - - // Finally, if we got too many blocks in the current log, delete some from the bottom. - while (ui_ic_chatlog->document()->blockCount() > log_maximum_blocks) - { - 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; - } } } From b25b8019f03464d8dac0e8796aeee73cf6c45600 Mon Sep 17 00:00:00 2001 From: Cerapter Date: Tue, 14 Aug 2018 21:26:30 +0200 Subject: [PATCH 057/174] Fixed a minor linebreak bug in the IC chatlog. --- courtroom.cpp | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/courtroom.cpp b/courtroom.cpp index 293b39d..717ee9d 100644 --- a/courtroom.cpp +++ b/courtroom.cpp @@ -1507,8 +1507,7 @@ void Courtroom::append_ic_songchange(QString p_songname, QString p_name) } ui_ic_chatlog->textCursor().insertText(" has played a song: ", normal); - ui_ic_chatlog->textCursor().insertText(p_songname, italics); - ui_ic_chatlog->textCursor().insertText(".", normal); + ui_ic_chatlog->textCursor().insertText(p_songname + "." + '\n', 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) @@ -1539,11 +1538,10 @@ void Courtroom::append_ic_songchange(QString p_songname, QString p_name) ui_ic_chatlog->moveCursor(QTextCursor::Start); - ui_ic_chatlog->textCursor().insertText(p_name, bold); + 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); - ui_ic_chatlog->textCursor().insertText(".", normal); + ui_ic_chatlog->textCursor().insertText(p_songname + ".", 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) From 8c859398f1b1308633584103c334bb103bf6cf2c Mon Sep 17 00:00:00 2001 From: Cerapter Date: Wed, 15 Aug 2018 19:50:41 +0200 Subject: [PATCH 058/174] Blocking shouts now blocks the testimony buttons too. --- server/aoprotocol.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/server/aoprotocol.py b/server/aoprotocol.py index 75ee824..912c0e7 100644 --- a/server/aoprotocol.py +++ b/server/aoprotocol.py @@ -513,6 +513,9 @@ class AOProtocol(asyncio.Protocol): 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 From 9ce1d3fa40b48fb55ea94f7d833ee029e7d23a7b Mon Sep 17 00:00:00 2001 From: Cerapter Date: Wed, 15 Aug 2018 23:30:46 +0200 Subject: [PATCH 059/174] Jukebox + Area abbreviation finetuning. - An area can now have a custom `abbreviation: XXX` set in `areas.yaml`. - Areas can have jukebox mode on by `jukebox: true` in `areas.yaml`. - When this mode is on, music changing is actually voting for the next music. - If no music is playing, or there is only your vote in there, it behaves as normal music changing. - In case of multiple votes, your vote gets added to a list, and may have a chance of being picked. - Check this list with `/jukebox`. - If not your music is picked, your voting power increases, making your music being picked next more likely. - If yours is picked, your voting power is reset to 0. - No matter how many people select the same song, if the song gets picked, all of them will have their voting power reset to 0. - Leaving an area, or picking a not-really-a-song (like 'PRELUDE', which is a category marker, basically), will remove your vote. - If there are no votes left (because every left, for example), the jukebox stops playing songs. - Mods can force a skip by `/jukebox_skip`. - Mods can also toggle an area's jukebox with `/jukebox_toggle`. - Mods can also still play songs with `/play`, though they might get cucked by the Jukebox. --- server/aoprotocol.py | 27 ++++++---- server/area_manager.py | 106 +++++++++++++++++++++++++++++++++------ server/client_manager.py | 8 ++- server/commands.py | 70 ++++++++++++++++++++++++++ server/tsuserver.py | 6 +-- 5 files changed, 188 insertions(+), 29 deletions(-) diff --git a/server/aoprotocol.py b/server/aoprotocol.py index 912c0e7..b36aa61 100644 --- a/server/aoprotocol.py +++ b/server/aoprotocol.py @@ -490,18 +490,23 @@ class AOProtocol(asyncio.Protocol): return try: name, length = self.server.get_song_data(args[0]) - 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) + + if self.client.area.jukebox: + self.client.area.add_jukebox_vote(self.client, name, length) + logger.log_server('[{}][{}]Added a jukebox vote for {}.'.format(self.client.area.id, self.client.get_char_name(), name), self.client) 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.id, self.client.get_char_name(), name), self.client) + 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.id, self.client.get_char_name(), name), self.client) except ServerError: return except ClientError as ex: diff --git a/server/area_manager.py b/server/area_manager.py index 36ade64..d0ff1cb 100644 --- a/server/area_manager.py +++ b/server/area_manager.py @@ -26,7 +26,7 @@ from server.evidence import EvidenceList 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): + 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 = ''): self.iniswap_allowed = iniswap_allowed self.clients = set() self.invite_list = {} @@ -52,6 +52,7 @@ class AreaManager: self.locking_allowed = locking_allowed self.showname_changes_allowed = showname_changes_allowed self.shouts_allowed = shouts_allowed + self.abbreviation = abbreviation self.owned = False self.cards = dict() @@ -64,6 +65,9 @@ class AreaManager: self.is_locked = False + self.jukebox = jukebox + self.jukebox_votes = [] + def new_client(self, client): self.clients.add(client) @@ -109,6 +113,70 @@ class AreaManager: 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): + 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)) + 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): + 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 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 + + self.send_command('MC', vote_picked.name, vote_picked.client.char_id) + + 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) @@ -188,18 +256,12 @@ class AreaManager: for client in self.clients: client.send_command('LE', *self.get_evidence_list(client)) - def get_abbreviation(self): - if self.name.lower().startswith("courtroom"): - return "CR" + self.name.split()[-1] - elif self.name.lower().startswith("area"): - return "A" + self.name.split()[-1] - elif len(self.name.split()) > 1: - return "".join(item[0].upper() for item in self.name.split()) - elif len(self.name) > 3: - return self.name[:3].upper() - else: - return self.name.upper() - + class JukeboxVote: + def __init__(self, client, name, length): + self.client = client + self.name = name + self.length = length + self.chance = 1 def __init__(self, server): self.server = server @@ -221,8 +283,12 @@ class AreaManager: item['showname_changes_allowed'] = False if 'shouts_allowed' not in item: item['shouts_allowed'] = True + if 'jukebox' not in item: + item['jukebox'] = 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'])) + 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'])) self.cur_id += 1 def default_area(self): @@ -239,3 +305,15 @@ class AreaManager: 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() diff --git a/server/client_manager.py b/server/client_manager.py index e127880..62e141d 100644 --- a/server/client_manager.py +++ b/server/client_manager.py @@ -106,6 +106,8 @@ class ClientManager: return True def disconnect(self): + if self.area.jukebox: + self.area.remove_jukebox_vote(self, True) self.transport.close() def change_character(self, char_id, force=False): @@ -171,6 +173,10 @@ class ClientManager: if area.is_locked and not self.is_mod and not self.id in area.invite_list: #self.send_host_message('This area is locked - you will be unable to send messages ICly.') raise ClientError("That area is locked!") + + 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: @@ -203,7 +209,7 @@ class ClientManager: for client in [x for x in area.clients if x.is_cm]: owner = 'MASTER: {}'.format(client.get_char_name()) break - msg += '\r\nArea {}: {} (users: {}) [{}][{}]{}'.format(area.get_abbreviation(), area.name, len(area.clients), area.status, owner, lock[area.is_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) diff --git a/server/commands.py b/server/commands.py index c1143d2..d952d15 100644 --- a/server/commands.py +++ b/server/commands.py @@ -159,6 +159,76 @@ def ooc_cmd_currentmusic(client, arg): 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: + 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.send_host_message('A mod has set the jukebox to {}.'.format(client.area.jukebox)) + +def ooc_cmd_jukebox_skip(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 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('A mod has forced a skip, restarting the only jukebox song.') + else: + client.area.send_host_message('A mod has forced a skip to the next jukebox song.') + logger.log_server('[{}][{}]Skipped the current jukebox song.'.format(client.area.id, client.get_char_name())) + +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.') diff --git a/server/tsuserver.py b/server/tsuserver.py index a7aed5d..97b4b90 100644 --- a/server/tsuserver.py +++ b/server/tsuserver.py @@ -232,7 +232,7 @@ class TsuServer3: def broadcast_global(self, client, msg, as_mod=False): char_name = client.get_char_name() - ooc_name = '{}[{}][{}]'.format('G', client.area.get_abbreviation(), 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) @@ -242,7 +242,7 @@ class TsuServer3: def send_modchat(self, client, msg): name = client.name - ooc_name = '{}[{}][{}]'.format('M', client.area.get_abbreviation(), 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( @@ -251,7 +251,7 @@ class TsuServer3: def broadcast_need(self, client, msg): char_name = client.get_char_name() area_name = client.area.name - area_id = client.area.get_abbreviation() + 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), pred=lambda x: not x.muted_adverts) From 86bcb3d2952614c7bdf16fc2004607cee89dc741 Mon Sep 17 00:00:00 2001 From: Cerapter Date: Wed, 15 Aug 2018 23:42:00 +0200 Subject: [PATCH 060/174] Super minor fix: the character selector frame now works again. --- aocharbutton.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/aocharbutton.cpp b/aocharbutton.cpp index b32be01..d2190b2 100644 --- a/aocharbutton.cpp +++ b/aocharbutton.cpp @@ -75,6 +75,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(); From 956c3b50d6c813abc149b80c5abb03d6712d1e95 Mon Sep 17 00:00:00 2001 From: Cerapter Date: Thu, 16 Aug 2018 00:40:42 +0200 Subject: [PATCH 061/174] Added support for the jukebox to use the shownames of its users. --- server/aoprotocol.py | 8 +++++++- server/area_manager.py | 12 ++++++++---- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/server/aoprotocol.py b/server/aoprotocol.py index b36aa61..9c7c9ca 100644 --- a/server/aoprotocol.py +++ b/server/aoprotocol.py @@ -492,7 +492,13 @@ class AOProtocol(asyncio.Protocol): name, length = self.server.get_song_data(args[0]) if self.client.area.jukebox: - self.client.area.add_jukebox_vote(self.client, name, length) + showname = '' + if len(args) > 2: + if len(args[2]) > 0 and not self.client.area.showname_changes_allowed: + self.client.send_host_message("Showname changes are forbidden in this area!") + return + showname = args[2] + self.client.area.add_jukebox_vote(self.client, name, length, showname) logger.log_server('[{}][{}]Added a jukebox vote for {}.'.format(self.client.area.id, self.client.get_char_name(), name), self.client) else: if len(args) > 2: diff --git a/server/area_manager.py b/server/area_manager.py index d0ff1cb..e6b34a0 100644 --- a/server/area_manager.py +++ b/server/area_manager.py @@ -114,12 +114,12 @@ class AreaManager: return False return True - def add_jukebox_vote(self, client, music_name, length=-1): + def add_jukebox_vote(self, client, music_name, length=-1, showname=''): 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)) + 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() @@ -160,7 +160,10 @@ class AreaManager: self.current_music = '' return - self.send_command('MC', vote_picked.name, 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) self.current_music_player = 'The Jukebox' self.current_music_player_ipid = 'has no IPID' @@ -257,11 +260,12 @@ class AreaManager: client.send_command('LE', *self.get_evidence_list(client)) class JukeboxVote: - def __init__(self, client, name, length): + 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 From d6b6a03802e56e4e4ea06402846eb460d0cf5d00 Mon Sep 17 00:00:00 2001 From: Cerapter Date: Thu, 16 Aug 2018 00:44:32 +0200 Subject: [PATCH 062/174] Fixed extra linebreaks after songchange in IC. --- courtroom.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/courtroom.cpp b/courtroom.cpp index 717ee9d..9b579d5 100644 --- a/courtroom.cpp +++ b/courtroom.cpp @@ -1507,7 +1507,7 @@ void Courtroom::append_ic_songchange(QString p_songname, QString p_name) } ui_ic_chatlog->textCursor().insertText(" has played a song: ", normal); - ui_ic_chatlog->textCursor().insertText(p_songname + "." + '\n', italics); + 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) From 331bca5f7361ba239531faca070872ee8d44addb Mon Sep 17 00:00:00 2001 From: Cerapter Date: Thu, 16 Aug 2018 18:48:11 +0200 Subject: [PATCH 063/174] Fixed a bug regarding the log limit being zero. - This also returned the previous behaviour when the log limit is zero, that is, no log limit is applied then. --- courtroom.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/courtroom.cpp b/courtroom.cpp index 9b579d5..4ed4ffb 100644 --- a/courtroom.cpp +++ b/courtroom.cpp @@ -1422,7 +1422,7 @@ void Courtroom::append_ic_text(QString p_text, QString p_name) 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) + 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); @@ -1454,7 +1454,7 @@ void Courtroom::append_ic_text(QString p_text, QString p_name) 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) + 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); @@ -1510,7 +1510,7 @@ void Courtroom::append_ic_songchange(QString p_songname, QString p_name) 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) + 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); @@ -1538,13 +1538,13 @@ void Courtroom::append_ic_songchange(QString p_songname, QString p_name) ui_ic_chatlog->moveCursor(QTextCursor::Start); - ui_ic_chatlog->textCursor().insertText('\n' + p_name, bold); + 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 + ".", italics); + 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) + 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); From 0368e7dc459b3057f8c7d0e6e329de0d3cd7c424 Mon Sep 17 00:00:00 2001 From: Cerapter Date: Thu, 16 Aug 2018 20:04:19 +0200 Subject: [PATCH 064/174] Guilty / Not Guilty buttons for the judge position. --- courtroom.cpp | 49 ++++++++++++++++++++++++++++++++++++++++- courtroom.h | 6 ++++- packet_distribution.cpp | 8 ++++++- server/aoprotocol.py | 9 ++++++-- 4 files changed, 67 insertions(+), 5 deletions(-) diff --git a/courtroom.cpp b/courtroom.cpp index 4ed4ffb..2555e64 100644 --- a/courtroom.cpp +++ b/courtroom.cpp @@ -157,6 +157,8 @@ 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); @@ -276,6 +278,8 @@ Courtroom::Courtroom(AOApplication *p_ao_app) : QMainWindow() 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())); @@ -483,6 +487,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"); @@ -739,6 +748,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(); @@ -748,6 +759,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(); @@ -2167,7 +2180,7 @@ void Courtroom::handle_song(QStringList *p_contents) } } -void Courtroom::handle_wtce(QString p_wtce) +void Courtroom::handle_wtce(QString p_wtce, int variant) { QString sfx_file = "courtroom_sounds.ini"; @@ -2186,6 +2199,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) @@ -2606,6 +2633,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); diff --git a/courtroom.h b/courtroom.h index 8a93543..3cb3c10 100644 --- a/courtroom.h +++ b/courtroom.h @@ -133,7 +133,7 @@ public: void play_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 @@ -366,6 +366,8 @@ private: AOButton *ui_witness_testimony; AOButton *ui_cross_examination; + AOButton *ui_guilty; + AOButton *ui_not_guilty; AOButton *ui_change_character; AOButton *ui_reload_theme; @@ -525,6 +527,8 @@ private slots: 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(); diff --git a/packet_distribution.cpp b/packet_distribution.cpp index 19ae7bb..f98417d 100644 --- a/packet_distribution.cpp +++ b/packet_distribution.cpp @@ -490,7 +490,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") { diff --git a/server/aoprotocol.py b/server/aoprotocol.py index 9c7c9ca..211bcff 100644 --- a/server/aoprotocol.py +++ b/server/aoprotocol.py @@ -533,18 +533,23 @@ class AOProtocol(asyncio.Protocol): if not self.client.can_wtce: self.client.send_host_message('You were blocked from using judge signs by a moderator.') return - if not self.validate_net_cmd(args, self.ArgType.STR): + 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 - self.client.area.send_command('RT', args[0]) + 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.id, self.client.get_char_name()), self.client) From 572888a9dde7850fd618d6a14d303de31ae9161b Mon Sep 17 00:00:00 2001 From: Cerapter Date: Thu, 16 Aug 2018 20:56:26 +0200 Subject: [PATCH 065/174] Minor fix regarding the /pos command and the NG/G buttons. --- courtroom.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/courtroom.cpp b/courtroom.cpp index 2555e64..6e855f3 100644 --- a/courtroom.cpp +++ b/courtroom.cpp @@ -2255,6 +2255,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(); @@ -2264,6 +2266,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(); From c8b62267b9b4481e4dd458ed9a4f76feb9863e63 Mon Sep 17 00:00:00 2001 From: Cerapter Date: Thu, 16 Aug 2018 22:23:16 +0200 Subject: [PATCH 066/174] Fixed a bug where the character taken symbol wouldn't show. --- aocharbutton.cpp | 10 ++++++++-- aocharbutton.h | 5 ++++- charselect.cpp | 12 +++++------- 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/aocharbutton.cpp b/aocharbutton.cpp index d2190b2..4c0273f 100644 --- a/aocharbutton.cpp +++ b/aocharbutton.cpp @@ -4,12 +4,14 @@ #include -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); @@ -42,7 +44,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() diff --git a/aocharbutton.h b/aocharbutton.h index f715416..d3576fb 100644 --- a/aocharbutton.h +++ b/aocharbutton.h @@ -13,10 +13,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(); @@ -24,6 +25,8 @@ public: void set_image(QString p_character); private: + bool taken; + QWidget *m_parent; AOImage *ui_taken; diff --git a/charselect.cpp b/charselect.cpp index 822ea78..72b031c 100644 --- a/charselect.cpp +++ b/charselect.cpp @@ -85,6 +85,7 @@ void Courtroom::set_char_select_page() for (AOCharButton *i_button : ui_char_button_list) { + i_button->reset(); i_button->hide(); i_button->move(0,0); } @@ -163,6 +164,8 @@ void Courtroom::put_button_in_place(int starting, int chars_on_this_page) 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) @@ -189,7 +192,8 @@ void Courtroom::character_loading_finished() // 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); + 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); @@ -207,12 +211,6 @@ void Courtroom::character_loading_finished() } filter_character_list(); - - int chars_on_page = max_chars_on_page; - if (ui_char_button_list_filtered.size() < max_chars_on_page) - chars_on_page = ui_char_button_list_filtered.size(); - put_button_in_place(0, chars_on_page); - } void Courtroom::filter_character_list() From aee3099d9b1ce0fb1e2521612d8f4eb07b323e4a Mon Sep 17 00:00:00 2001 From: Cerapter Date: Thu, 16 Aug 2018 22:57:41 +0200 Subject: [PATCH 067/174] Added the command `/allow_blankposting` for CMs and mods to control blankposting. --- server/aoprotocol.py | 3 +++ server/area_manager.py | 2 +- server/commands.py | 11 ++++++++++- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/server/aoprotocol.py b/server/aoprotocol.py index 211bcff..11d2fbd 100644 --- a/server/aoprotocol.py +++ b/server/aoprotocol.py @@ -358,6 +358,9 @@ class AOProtocol(asyncio.Protocol): 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 not self.client.area.blankposting_allowed and text == ' ': + self.client.send_host_message("Blankposting is forbidden in this area!") + return if msg_type not in ('chat', '0', '1'): return if anim_type not in (0, 1, 2, 5, 6): diff --git a/server/area_manager.py b/server/area_manager.py index e6b34a0..583e149 100644 --- a/server/area_manager.py +++ b/server/area_manager.py @@ -64,7 +64,7 @@ class AreaManager: """ self.is_locked = False - + self.blankposting_allowed = True self.jukebox = jukebox self.jukebox_votes = [] diff --git a/server/commands.py b/server/commands.py index d952d15..d1f145d 100644 --- a/server/commands.py +++ b/server/commands.py @@ -89,7 +89,16 @@ def ooc_cmd_allow_iniswap(client, arg): 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.is_cm: + raise ClientError('You must be authorized to do that.') + client.area.blankposting_allowed = not client.area.blankposting_allowed + answer = {True: 'allowed', False: 'forbidden'} + if client.is_cm: + client.area.send_host_message('The CM has set blankposting in the area to {}.'.format(answer[client.area.blankposting_allowed])) + else: + client.area.send_host_message('A mod has set blankposting in the area to {}.'.format(answer[client.area.blankposting_allowed])) + return def ooc_cmd_roll(client, arg): roll_max = 11037 From eee682bf0d603b0afe9dc2e41bf971669cea225d Mon Sep 17 00:00:00 2001 From: Cerapter Date: Fri, 17 Aug 2018 01:34:22 +0200 Subject: [PATCH 068/174] Fixed an issue with the audio output change not registering. --- aoapplication.cpp | 29 ----------------------------- aoblipplayer.cpp | 1 + aomusicplayer.cpp | 1 + aosfxplayer.cpp | 1 + courtroom.cpp | 20 ++++++++++++++++++-- 5 files changed, 21 insertions(+), 31 deletions(-) diff --git a/aoapplication.cpp b/aoapplication.cpp index b8db52e..0133765 100644 --- a/aoapplication.cpp +++ b/aoapplication.cpp @@ -48,21 +48,6 @@ void AOApplication::construct_lobby() discord->state_lobby(); w_lobby->show(); - - // 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; - - for (a = 0; BASS_GetDeviceInfo(a, &info); a++) - { - if (get_audio_output_device() == info.name) - { - BASS_SetDevice(a); - qDebug() << info.name << "was set as the default audio output device."; - break; - } - } } void AOApplication::destruct_lobby() @@ -125,20 +110,6 @@ QString AOApplication::get_cccc_version_string() void AOApplication::reload_theme() { current_theme = read_theme(); - - // This may not be the best place for it, but let's read the audio output device just in case. - int a = 0; - BASS_DEVICEINFO info; - - for (a = 0; BASS_GetDeviceInfo(a, &info); a++) - { - if (get_audio_output_device() == info.name) - { - BASS_SetDevice(a); - qDebug() << info.name << "was set as the default audio output device."; - break; - } - } } void AOApplication::set_favorite_list() diff --git a/aoblipplayer.cpp b/aoblipplayer.cpp index f212453..5669a12 100644 --- a/aoblipplayer.cpp +++ b/aoblipplayer.cpp @@ -33,6 +33,7 @@ void AOBlipPlayer::blip_tick() HSTREAM f_stream = m_stream_list[f_cycle]; + BASS_ChannelSetDevice(f_stream, BASS_GetDevice()); BASS_ChannelPlay(f_stream, false); } diff --git a/aomusicplayer.cpp b/aomusicplayer.cpp index a9a9baf..3246fc2 100644 --- a/aomusicplayer.cpp +++ b/aomusicplayer.cpp @@ -25,6 +25,7 @@ void AOMusicPlayer::play(QString p_song) this->set_volume(m_volume); + BASS_ChannelSetDevice(m_stream, BASS_GetDevice()); BASS_ChannelPlay(m_stream, false); } diff --git a/aosfxplayer.cpp b/aosfxplayer.cpp index 6ad59ba..c090be1 100644 --- a/aosfxplayer.cpp +++ b/aosfxplayer.cpp @@ -27,6 +27,7 @@ void AOSfxPlayer::play(QString p_sfx, QString p_char) set_volume(m_volume); + BASS_ChannelSetDevice(m_stream, BASS_GetDevice()); BASS_ChannelPlay(m_stream, false); } diff --git a/courtroom.cpp b/courtroom.cpp index 6e855f3..3dd0c4f 100644 --- a/courtroom.cpp +++ b/courtroom.cpp @@ -20,8 +20,24 @@ Courtroom::Courtroom(AOApplication *p_ao_app) : QMainWindow() ao_app = p_ao_app; //initializing sound device - BASS_Init(-1, 48000, BASS_DEVICE_LATENCY, 0, NULL); - BASS_PluginLoad("bassopus.dll", BASS_UNICODE); + + + // 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; + + 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); + BASS_PluginLoad("bassopus.dll", BASS_UNICODE); + qDebug() << info.name << "was set as the default audio output device."; + break; + } + } keepalive_timer = new QTimer(this); keepalive_timer->start(60000); From 265b853337e6368afc2816a78a64a4d128f756e4 Mon Sep 17 00:00:00 2001 From: Cerapter Date: Fri, 17 Aug 2018 02:12:29 +0200 Subject: [PATCH 069/174] Removed HDID ban due to it not working. --- server/aoprotocol.py | 5 +---- server/ban_manager.py | 33 +-------------------------------- server/commands.py | 32 +------------------------------- 3 files changed, 3 insertions(+), 67 deletions(-) diff --git a/server/aoprotocol.py b/server/aoprotocol.py index 11d2fbd..5bc94bb 100644 --- a/server/aoprotocol.py +++ b/server/aoprotocol.py @@ -65,7 +65,7 @@ class AOProtocol(asyncio.Protocol): buf = data - if not self.client.is_checked and (self.server.ban_manager.is_banned(self.client.ipid) or self.server.ban_manager.is_hdid_banned(self.client.hdid)): + 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 @@ -165,9 +165,6 @@ class AOProtocol(asyncio.Protocol): if not self.validate_net_cmd(args, self.ArgType.STR, needs_auth=False): return self.client.hdid = args[0] - if self.server.ban_manager.is_hdid_banned(self.client.hdid): - self.client.disconnect() - return 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]: diff --git a/server/ban_manager.py b/server/ban_manager.py index b4f97b7..20c186f 100644 --- a/server/ban_manager.py +++ b/server/ban_manager.py @@ -25,9 +25,6 @@ class BanManager: self.bans = [] self.load_banlist() - self.hdid_bans = [] - self.load_hdid_banlist() - def load_banlist(self): try: with open('storage/banlist.json', 'r') as banlist_file: @@ -54,32 +51,4 @@ class BanManager: self.write_banlist() def is_banned(self, ipid): - return (ipid in self.bans) - - def load_hdid_banlist(self): - try: - with open('storage/banlist_hdid.json', 'r') as banlist_file: - self.hdid_bans = json.load(banlist_file) - except FileNotFoundError: - return - - def write_hdid_banlist(self): - with open('storage/banlist_hdid.json', 'w') as banlist_file: - json.dump(self.hdid_bans, banlist_file) - - def add_hdid_ban(self, hdid): - if hdid not in self.hdid_bans: - self.hdid_bans.append(hdid) - else: - raise ServerError('This HDID is already banned.') - self.write_hdid_banlist() - - def remove_hdid_ban(self, hdid): - if hdid in self.hdid_bans: - self.hdid_bans.remove(hdid) - else: - raise ServerError('This HDID is not banned.') - self.write_hdid_banlist() - - def is_hdid_banned(self, hdid): - return (hdid in self.hdid_bans) \ No newline at end of file + return (ipid in self.bans) \ No newline at end of file diff --git a/server/commands.py b/server/commands.py index d1f145d..a3c3ce8 100644 --- a/server/commands.py +++ b/server/commands.py @@ -357,37 +357,7 @@ def ooc_cmd_unban(client, arg): raise ClientError('You must specify ipid') logger.log_server('Unbanned {}.'.format(arg), client) client.send_host_message('Unbanned {}'.format(arg)) - -def ooc_cmd_ban_hdid(client, arg): - if not client.is_mod: - raise ClientError('You must be authorized to do that.') - try: - hdid = int(arg.strip()) - except: - raise ClientError('You must specify hdid') - try: - client.server.ban_manager.add_hdid_ban(hdid) - except ServerError: - raise - if hdid != None: - targets = client.server.client_manager.get_targets(client, TargetType.HDID, hdid, False) - if targets: - for c in targets: - c.disconnect() - client.send_host_message('{} clients was kicked.'.format(len(targets))) - client.send_host_message('{} was banned.'.format(hdid)) - logger.log_server('Banned {}.'.format(hdid), client) - -def ooc_cmd_unban_hdid(client, arg): - if not client.is_mod: - raise ClientError('You must be authorized to do that.') - try: - client.server.ban_manager.remove_hdid_ban(int(arg.strip())) - except: - raise ClientError('You must specify hdid') - logger.log_server('Unbanned {}.'.format(arg), client) - client.send_host_message('Unbanned {}'.format(arg)) - + def ooc_cmd_play(client, arg): if not client.is_mod: raise ClientError('You must be authorized to do that.') From b9f1998c93067d29e5b2cea4d30d95229c27a810 Mon Sep 17 00:00:00 2001 From: Cerapter Date: Sun, 19 Aug 2018 08:03:14 +0200 Subject: [PATCH 070/174] Minor fix: the default showname is now correctly the name of the character. --- .gitignore | 1 + courtroom.cpp | 1 + 2 files changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index d18dfea..9d5dcdb 100644 --- a/.gitignore +++ b/.gitignore @@ -20,6 +20,7 @@ object_script* /attorney_online_remake_plugin_import.cpp server/__pycache__ +discord/ *.o moc* diff --git a/courtroom.cpp b/courtroom.cpp index 3dd0c4f..5800f58 100644 --- a/courtroom.cpp +++ b/courtroom.cpp @@ -811,6 +811,7 @@ void Courtroom::enter_courtroom(int p_cid) //ui_server_chatlog->setHtml(ui_server_chatlog->toHtml()); ui_char_select_background->hide(); + ui_ic_chat_name->setPlaceholderText(ao_app->get_showname(f_char)); ui_ic_chat_message->setEnabled(m_cid != -1); ui_ic_chat_message->setFocus(); From 457a5e39fcb0f34477c7ac22c5ed8919f6522eec Mon Sep 17 00:00:00 2001 From: Cerapter Date: Sun, 19 Aug 2018 08:03:39 +0200 Subject: [PATCH 071/174] Jukebox fixes: check if jukebox exists + blockDJ removes vote. --- server/area_manager.py | 6 ++++++ server/commands.py | 1 + 2 files changed, 7 insertions(+) diff --git a/server/area_manager.py b/server/area_manager.py index 583e149..90229d0 100644 --- a/server/area_manager.py +++ b/server/area_manager.py @@ -115,6 +115,8 @@ class AreaManager: 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: @@ -125,6 +127,8 @@ class AreaManager: 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) @@ -132,6 +136,8 @@ class AreaManager: 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: diff --git a/server/commands.py b/server/commands.py index a3c3ce8..5dfe030 100644 --- a/server/commands.py +++ b/server/commands.py @@ -812,6 +812,7 @@ def ooc_cmd_blockdj(client, arg): for target in targets: target.is_dj = False target.send_host_message('A moderator muted you from changing the music.') + 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): From feee84588c1caa6307ea8bdfdc030936790eed35 Mon Sep 17 00:00:00 2001 From: Cerapter Date: Sun, 19 Aug 2018 08:37:01 +0200 Subject: [PATCH 072/174] Manual option for backup master server. Reimplementation of `7e4be0edd7756220dd8d7fbaaaf3d972db48df5e` from the old origin. --- aoapplication.cpp | 6 +++--- aooptionsdialog.cpp | 20 ++++++++++++++++++++ aooptionsdialog.h | 3 +++ networkmanager.cpp | 4 ++++ networkmanager.h | 4 ++-- 5 files changed, 32 insertions(+), 5 deletions(-) diff --git a/aoapplication.cpp b/aoapplication.cpp index 0133765..43af15f 100644 --- a/aoapplication.cpp +++ b/aoapplication.cpp @@ -13,13 +13,13 @@ 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)), SLOT(ms_connect_finished(bool, bool))); - - // Create the QSettings class that points to the config.ini. - configini = new QSettings(get_base_path() + "config.ini", QSettings::IniFormat); } AOApplication::~AOApplication() diff --git a/aooptionsdialog.cpp b/aooptionsdialog.cpp index 6f325bb..60d8a96 100644 --- a/aooptionsdialog.cpp +++ b/aooptionsdialog.cpp @@ -145,6 +145,24 @@ AOOptionsDialog::AOOptionsDialog(QWidget *parent, AOApplication *p_ao_app) : QDi 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); + // Here we start the callwords tab. CallwordsTab = new QWidget(); SettingsTabs->addTab(CallwordsTab, "Callwords"); @@ -298,6 +316,7 @@ void AOOptionsDialog::save_pressed() configini->setValue("log_maximum", LengthSpinbox->value()); configini->setValue("default_username", UsernameLineEdit->text()); configini->setValue("show_custom_shownames", ShownameCheckbox->isChecked()); + configini->setValue("master", MasterServerLineEdit->text()); QFile* callwordsini = new QFile(ao_app->get_base_path() + "callwords.ini"); @@ -319,6 +338,7 @@ void AOOptionsDialog::save_pressed() configini->setValue("blip_rate", BlipRateSpinbox->value()); configini->setValue("blank_blip", BlankBlipsCheckbox->isChecked()); + callwordsini->close(); done(0); } diff --git a/aooptionsdialog.h b/aooptionsdialog.h index 55dda9b..cc345ca 100644 --- a/aooptionsdialog.h +++ b/aooptionsdialog.h @@ -46,6 +46,9 @@ private: QLabel *UsernameLabel; QLabel *ShownameLabel; QCheckBox *ShownameCheckbox; + QFrame *NetDivider; + QLabel *MasterServerLabel; + QLineEdit *MasterServerLineEdit; QWidget *CallwordsTab; QWidget *verticalLayoutWidget; QVBoxLayout *CallwordsLayout; diff --git a/networkmanager.cpp b/networkmanager.cpp index 8c0eaa7..ea0d811 100644 --- a/networkmanager.cpp +++ b/networkmanager.cpp @@ -19,6 +19,10 @@ NetworkManager::NetworkManager(AOApplication *parent) : QObject(parent) QObject::connect(ms_socket, SIGNAL(readyRead()), this, SLOT(handle_ms_packet())); 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->configini->value("master", "").value(); + if (master_config != "") + ms_nosrv_hostname = master_config; } NetworkManager::~NetworkManager() diff --git a/networkmanager.h b/networkmanager.h index 32aef73..6954d19 100644 --- a/networkmanager.h +++ b/networkmanager.h @@ -38,9 +38,9 @@ public: const QString ms_srv_hostname = "_aoms._tcp.aceattorneyonline.com"; #ifdef LOCAL_MS - const QString ms_nosrv_hostname = "localhost"; + QString ms_nosrv_hostname = "localhost"; #else - const QString ms_nosrv_hostname = "master.aceattorneyonline.com"; + QString ms_nosrv_hostname = "master.aceattorneyonline.com"; #endif const int ms_port = 27016; From ed68084e08ace1e210a64a562fd6316fc06954a7 Mon Sep 17 00:00:00 2001 From: Cerapter Date: Sun, 19 Aug 2018 08:41:00 +0200 Subject: [PATCH 073/174] Segfault fix. Reimplementation of `0e15be73af266d5fbff3d83d731a7af2773ff532` from old origin. --- networkmanager.cpp | 12 ++++++++---- networkmanager.h | 1 + 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/networkmanager.cpp b/networkmanager.cpp index ea0d811..909c7da 100644 --- a/networkmanager.cpp +++ b/networkmanager.cpp @@ -4,6 +4,8 @@ #include "debug_functions.h" #include "lobby.h" +#include + NetworkManager::NetworkManager(AOApplication *parent) : QObject(parent) { @@ -79,8 +81,9 @@ void NetworkManager::ship_server_packet(QString p_packet) void NetworkManager::handle_ms_packet() { - char buffer[16384] = {0}; - ms_socket->read(buffer, ms_socket->bytesAvailable()); + char buffer[buffer_max_size]; + std::memset(buffer, 0, buffer_max_size); + ms_socket->read(buffer, buffer_max_size); QString in_data = buffer; @@ -217,8 +220,9 @@ void NetworkManager::retry_ms_connect() void NetworkManager::handle_server_packet() { - char buffer[16384] = {0}; - server_socket->read(buffer, server_socket->bytesAvailable()); + char buffer[buffer_max_size]; + std::memset(buffer, 0, buffer_max_size); + server_socket->read(buffer, buffer_max_size); QString in_data = buffer; diff --git a/networkmanager.h b/networkmanager.h index 6954d19..797950a 100644 --- a/networkmanager.h +++ b/networkmanager.h @@ -47,6 +47,7 @@ public: const int timeout_milliseconds = 2000; const int ms_reconnect_delay_ms = 7000; + const size_t buffer_max_size = 16384; bool ms_partial_packet = false; QString ms_temp_packet = ""; From 95b8bd72d3aa870c829fb3176a66cc1976a1762d Mon Sep 17 00:00:00 2001 From: Cerapter Date: Sun, 19 Aug 2018 09:17:48 +0200 Subject: [PATCH 074/174] Ability to toggle Discord RPC. Reimplementation of `bed0b55e70f13adf772584fc0d31ebfe59597115` from old origin. --- aoapplication.cpp | 3 ++- aoapplication.h | 8 ++++++-- aooptionsdialog.cpp | 12 ++++++++++++ aooptionsdialog.h | 2 ++ courtroom.cpp | 7 +++++-- 5 files changed, 27 insertions(+), 5 deletions(-) diff --git a/aoapplication.cpp b/aoapplication.cpp index 43af15f..65dcd54 100644 --- a/aoapplication.cpp +++ b/aoapplication.cpp @@ -45,7 +45,8 @@ void AOApplication::construct_lobby() int y = (screenGeometry.height()-w_lobby->height()) / 2; w_lobby->move(x, y); - discord->state_lobby(); + if (is_discord_enabled()) + discord->state_lobby(); w_lobby->show(); } diff --git a/aoapplication.h b/aoapplication.h index d386811..6e0ce8e 100644 --- a/aoapplication.h +++ b/aoapplication.h @@ -143,8 +143,12 @@ public: //Returns the value of default_blip in config.ini int get_default_blip(); - //Returns the value of the maximum amount of lines the IC chatlog - //may contain, from config.ini. + // Returns the value of whether Discord should be enabled on startup + // from the config.ini. + bool is_discord_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) diff --git a/aooptionsdialog.cpp b/aooptionsdialog.cpp index 60d8a96..3a4a34a 100644 --- a/aooptionsdialog.cpp +++ b/aooptionsdialog.cpp @@ -163,6 +163,17 @@ AOOptionsDialog::AOOptionsDialog(QWidget *parent, AOApplication *p_ao_app) : QDi 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"); @@ -317,6 +328,7 @@ void AOOptionsDialog::save_pressed() 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"); diff --git a/aooptionsdialog.h b/aooptionsdialog.h index cc345ca..f43e7b7 100644 --- a/aooptionsdialog.h +++ b/aooptionsdialog.h @@ -49,6 +49,8 @@ private: QFrame *NetDivider; QLabel *MasterServerLabel; QLineEdit *MasterServerLineEdit; + QLabel *DiscordLabel; + QCheckBox *DiscordCheckBox; QWidget *CallwordsTab; QWidget *verticalLayoutWidget; QVBoxLayout *CallwordsLayout; diff --git a/courtroom.cpp b/courtroom.cpp index 5800f58..f8c7c8a 100644 --- a/courtroom.cpp +++ b/courtroom.cpp @@ -731,13 +731,16 @@ void Courtroom::enter_courtroom(int p_cid) if (m_cid == -1) { - ao_app->discord->state_spectate(); + 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); - ao_app->discord->state_character(f_char.toStdString()); + + if (ao_app->is_discord_enabled()) + ao_app->discord->state_character(f_char.toStdString()); } current_char = f_char; From 7de64bd0c085216e7c88e15860d4e34cd79e6586 Mon Sep 17 00:00:00 2001 From: Cerapter Date: Sun, 19 Aug 2018 09:18:35 +0200 Subject: [PATCH 075/174] Discord toggle pt.2. Forgot these. --- packet_distribution.cpp | 3 ++- text_file_functions.cpp | 7 +++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/packet_distribution.cpp b/packet_distribution.cpp index f98417d..abc5848 100644 --- a/packet_distribution.cpp +++ b/packet_distribution.cpp @@ -265,7 +265,8 @@ void AOApplication::server_packet_received(AOPacket *p_packet) QCryptographicHash hash(QCryptographicHash::Algorithm::Sha256); hash.addData(server_address.toUtf8()); - discord->state_server(server_name.toStdString(), hash.result().toBase64().toStdString()); + if (is_discord_enabled()) + discord->state_server(server_name.toStdString(), hash.result().toBase64().toStdString()); } else if (header == "CI") { diff --git a/text_file_functions.cpp b/text_file_functions.cpp index aa14068..c784d1f 100644 --- a/text_file_functions.cpp +++ b/text_file_functions.cpp @@ -586,8 +586,11 @@ bool AOApplication::get_blank_blip() return result.startsWith("true"); } - - +bool AOApplication::is_discord_enabled() +{ + QString result = configini->value("discord", "true").value(); + return result.startsWith("true"); +} From c316e81e0c28a5f62e55f4a727f0ca152ab9874b Mon Sep 17 00:00:00 2001 From: Cerapter Date: Sun, 19 Aug 2018 09:19:18 +0200 Subject: [PATCH 076/174] Reset the default background to `default`. Reimplementation of `bed0b55e70f13adf772584fc0d31ebfe59597115` from old origin. --- courtroom.h | 2 +- path_functions.cpp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/courtroom.h b/courtroom.h index 3cb3c10..8dfa54a 100644 --- a/courtroom.h +++ b/courtroom.h @@ -299,7 +299,7 @@ private: //whether the ooc chat is server or master chat, true is server bool server_ooc = true; - QString current_background = "gs4"; + QString current_background = "default"; AOMusicPlayer *music_player; AOSfxPlayer *sfx_player; diff --git a/path_functions.cpp b/path_functions.cpp index 6e772db..51ddcfd 100644 --- a/path_functions.cpp +++ b/path_functions.cpp @@ -96,7 +96,7 @@ QString AOApplication::get_background_path() QString AOApplication::get_default_background_path() { - return get_base_path() + "background/gs4/"; + return get_base_path() + "background/default/"; } QString AOApplication::get_evidence_path() @@ -118,5 +118,5 @@ QString Courtroom::get_background_path() QString Courtroom::get_default_background_path() { - return ao_app->get_base_path() + "background/gs4/"; + return ao_app->get_base_path() + "background/default/"; } From e6eace9a39fe4d0f0755d86686650ccfdff81982 Mon Sep 17 00:00:00 2001 From: Cerapter Date: Sun, 19 Aug 2018 09:20:16 +0200 Subject: [PATCH 077/174] Better INT to HEX conversion. Reimplementation of `4e96a41b4ee6bbc920b7c5a5ec555d6d14e65b18`, `bb0b767ba40d189b97ffe371ab063c5380609b0c` and `e36dae20b7d1baba912c55ec55b82a380c4973da` from old origin. --- hex_functions.cpp | 35 ++++++++--------------------------- hex_functions.h | 6 +++++- 2 files changed, 13 insertions(+), 28 deletions(-) diff --git a/hex_functions.cpp b/hex_functions.cpp index 9db2b0a..d22719f 100644 --- a/hex_functions.cpp +++ b/hex_functions.cpp @@ -4,7 +4,7 @@ namespace omni { - char halfword_to_hex_char(unsigned int input) + /*char halfword_to_hex_char(unsigned int input) { if (input > 127) return 'F'; @@ -46,38 +46,19 @@ namespace omni default: return 'F'; } - } + }*/ std::string int_to_hex(unsigned int input) { if (input > 255) return "FF"; - std::bitset<8> whole_byte(input); - //240 represents 11110000, our needed bitmask - uint8_t left_mask_int = 240; - std::bitset<8> left_mask(left_mask_int); - std::bitset<8> left_halfword((whole_byte & left_mask) >> 4); - //likewise, 15 represents 00001111 - uint8_t right_mask_int = 15; - std::bitset<8> right_mask(right_mask_int); - std::bitset<8> right_halfword((whole_byte & right_mask)); + std::stringstream stream; + stream << std::setfill('0') << std::setw(sizeof(char)*2) + << std::hex << input; + std::string result(stream.str()); + std::transform(result.begin(), result.end(), result.begin(), ::toupper); - unsigned int left = left_halfword.to_ulong(); - unsigned int right = right_halfword.to_ulong(); - - //std::cout << "now have have " << left << " and " << right << '\n'; - - char a = halfword_to_hex_char(left); - char b = halfword_to_hex_char(right); - - std::string left_string(1, a); - std::string right_string(1, b); - - std::string final_byte = left_string + right_string; - - //std::string final_byte = halfword_to_hex_char(left) + "" + halfword_to_hex_char(right); - - return final_byte; + return result; } } //namespace omni diff --git a/hex_functions.h b/hex_functions.h index 47d9466..20c5cad 100644 --- a/hex_functions.h +++ b/hex_functions.h @@ -4,10 +4,14 @@ #include #include #include +#include +#include +#include +#include namespace omni { - char halfword_to_hex_char(unsigned int input); + //char halfword_to_hex_char(unsigned int input); std::string int_to_hex(unsigned int input); } From d314b8dd07f72d94724c3902258dfb2641d3435c Mon Sep 17 00:00:00 2001 From: Cerapter Date: Sun, 19 Aug 2018 09:37:34 +0200 Subject: [PATCH 078/174] Moved includes out of the CPP files into the header files. Reimplementation of `30a87d23c9c63bed072b3460e7482075dc530b2c` from the old origin. --- aoapplication.cpp | 4 ---- aoapplication.h | 13 +++++++++++++ aoblipplayer.cpp | 4 ---- aoblipplayer.h | 2 ++ aobutton.cpp | 2 -- aobutton.h | 1 + aocharbutton.cpp | 2 -- aocharbutton.h | 3 ++- aocharmovie.cpp | 3 --- aocharmovie.h | 2 ++ aoemotebutton.cpp | 1 - aoemotebutton.h | 5 +++-- aoevidencebutton.cpp | 2 -- aoevidencebutton.h | 1 + aoevidencedisplay.cpp | 2 -- aoevidencedisplay.h | 7 ++++--- aoimage.cpp | 2 -- aoimage.h | 1 + aomusicplayer.cpp | 4 ---- aomusicplayer.h | 2 ++ aooptionsdialog.cpp | 19 ------------------- aooptionsdialog.h | 3 +++ aopacket.cpp | 2 -- aopacket.h | 1 + aoscene.cpp | 2 -- aoscene.h | 1 + aosfxplayer.cpp | 4 ---- aosfxplayer.h | 2 ++ aotextarea.cpp | 5 ----- aotextarea.h | 4 ++++ charselect.cpp | 2 -- courtroom.cpp | 8 -------- courtroom.h | 9 +++++++++ debug_functions.cpp | 2 -- debug_functions.h | 1 + discord_rich_presence.cpp | 5 ----- discord_rich_presence.h | 5 +++++ emotes.cpp | 2 -- encryption_functions.cpp | 6 ------ encryption_functions.h | 6 ++++++ evidence.cpp | 3 --- file_functions.cpp | 3 --- file_functions.h | 2 ++ lobby.cpp | 3 --- lobby.h | 3 +++ misc_functions.cpp | 3 --- misc_functions.h | 3 +++ networkmanager.cpp | 3 --- networkmanager.h | 1 + packet_distribution.cpp | 3 --- path_functions.cpp | 3 --- text_file_functions.cpp | 6 ------ 52 files changed, 72 insertions(+), 116 deletions(-) diff --git a/aoapplication.cpp b/aoapplication.cpp index 65dcd54..03679a7 100644 --- a/aoapplication.cpp +++ b/aoapplication.cpp @@ -7,10 +7,6 @@ #include "aooptionsdialog.h" -#include -#include -#include - AOApplication::AOApplication(int &argc, char **argv) : QApplication(argc, argv) { // Create the QSettings class that points to the config.ini. diff --git a/aoapplication.h b/aoapplication.h index 6e0ce8e..abac7b9 100644 --- a/aoapplication.h +++ b/aoapplication.h @@ -10,6 +10,19 @@ #include #include +#include +#include +#include + +#include + +#include +#include + +#include +#include +#include + class NetworkManager; class Lobby; class Courtroom; diff --git a/aoblipplayer.cpp b/aoblipplayer.cpp index 5669a12..ed8a8d7 100644 --- a/aoblipplayer.cpp +++ b/aoblipplayer.cpp @@ -1,9 +1,5 @@ #include "aoblipplayer.h" -#include - -#include - AOBlipPlayer::AOBlipPlayer(QWidget *parent, AOApplication *p_ao_app) { m_parent = parent; diff --git a/aoblipplayer.h b/aoblipplayer.h index 430f702..aebba77 100644 --- a/aoblipplayer.h +++ b/aoblipplayer.h @@ -5,6 +5,8 @@ #include "aoapplication.h" #include +#include +#include class AOBlipPlayer { diff --git a/aobutton.cpp b/aobutton.cpp index 370eca9..ded35af 100644 --- a/aobutton.cpp +++ b/aobutton.cpp @@ -3,8 +3,6 @@ #include "debug_functions.h" #include "file_functions.h" -#include - AOButton::AOButton(QWidget *parent, AOApplication *p_ao_app) : QPushButton(parent) { ao_app = p_ao_app; diff --git a/aobutton.h b/aobutton.h index 0492375..4b7209a 100644 --- a/aobutton.h +++ b/aobutton.h @@ -4,6 +4,7 @@ #include "aoapplication.h" #include +#include class AOButton : public QPushButton { diff --git a/aocharbutton.cpp b/aocharbutton.cpp index 4c0273f..2d134b1 100644 --- a/aocharbutton.cpp +++ b/aocharbutton.cpp @@ -2,8 +2,6 @@ #include "file_functions.h" -#include - AOCharButton::AOCharButton(QWidget *parent, AOApplication *p_ao_app, int x_pos, int y_pos, bool is_taken) : QPushButton(parent) { m_parent = parent; diff --git a/aocharbutton.h b/aocharbutton.h index d3576fb..6e5e50e 100644 --- a/aocharbutton.h +++ b/aocharbutton.h @@ -2,11 +2,12 @@ #define AOCHARBUTTON_H #include "aoapplication.h" +#include "aoimage.h" #include #include #include -#include "aoimage.h" +#include class AOCharButton : public QPushButton { diff --git a/aocharmovie.cpp b/aocharmovie.cpp index 6ad2969..b591c22 100644 --- a/aocharmovie.cpp +++ b/aocharmovie.cpp @@ -4,9 +4,6 @@ #include "file_functions.h" #include "aoapplication.h" -#include -#include - AOCharMovie::AOCharMovie(QWidget *p_parent, AOApplication *p_ao_app) : QLabel(p_parent) { ao_app = p_ao_app; diff --git a/aocharmovie.h b/aocharmovie.h index 8bc0bc1..b26bada 100644 --- a/aocharmovie.h +++ b/aocharmovie.h @@ -4,6 +4,8 @@ #include #include #include +#include +#include class AOApplication; diff --git a/aoemotebutton.cpp b/aoemotebutton.cpp index d8f10c9..9e3c446 100644 --- a/aoemotebutton.cpp +++ b/aoemotebutton.cpp @@ -1,7 +1,6 @@ #include "aoemotebutton.h" #include "file_functions.h" -#include AOEmoteButton::AOEmoteButton(QWidget *p_parent, AOApplication *p_ao_app, int p_x, int p_y) : QPushButton(p_parent) { diff --git a/aoemotebutton.h b/aoemotebutton.h index cc3dfac..c99a73b 100644 --- a/aoemotebutton.h +++ b/aoemotebutton.h @@ -1,10 +1,11 @@ #ifndef AOEMOTEBUTTON_H #define AOEMOTEBUTTON_H -#include - #include "aoapplication.h" +#include +#include + class AOEmoteButton : public QPushButton { Q_OBJECT diff --git a/aoevidencebutton.cpp b/aoevidencebutton.cpp index 96bf553..573b8ef 100644 --- a/aoevidencebutton.cpp +++ b/aoevidencebutton.cpp @@ -2,8 +2,6 @@ #include "file_functions.h" -#include - AOEvidenceButton::AOEvidenceButton(QWidget *p_parent, AOApplication *p_ao_app, int p_x, int p_y) : QPushButton(p_parent) { ao_app = p_ao_app; diff --git a/aoevidencebutton.h b/aoevidencebutton.h index ee0a0f6..27fb84b 100644 --- a/aoevidencebutton.h +++ b/aoevidencebutton.h @@ -6,6 +6,7 @@ #include #include +#include class AOEvidenceButton : public QPushButton { diff --git a/aoevidencedisplay.cpp b/aoevidencedisplay.cpp index cbe37c0..5364ffb 100644 --- a/aoevidencedisplay.cpp +++ b/aoevidencedisplay.cpp @@ -1,5 +1,3 @@ -#include - #include "aoevidencedisplay.h" #include "file_functions.h" diff --git a/aoevidencedisplay.h b/aoevidencedisplay.h index b973a29..13ca00d 100644 --- a/aoevidencedisplay.h +++ b/aoevidencedisplay.h @@ -1,12 +1,13 @@ #ifndef AOEVIDENCEDISPLAY_H #define AOEVIDENCEDISPLAY_H -#include -#include - #include "aoapplication.h" #include "aosfxplayer.h" +#include +#include +#include + class AOEvidenceDisplay : public QLabel { Q_OBJECT diff --git a/aoimage.cpp b/aoimage.cpp index 4710a1f..935ba74 100644 --- a/aoimage.cpp +++ b/aoimage.cpp @@ -2,8 +2,6 @@ #include "aoimage.h" -#include - AOImage::AOImage(QWidget *parent, AOApplication *p_ao_app) : QLabel(parent) { m_parent = parent; diff --git a/aoimage.h b/aoimage.h index 3e87b1c..4713be0 100644 --- a/aoimage.h +++ b/aoimage.h @@ -6,6 +6,7 @@ #include "aoapplication.h" #include +#include class AOImage : public QLabel { diff --git a/aomusicplayer.cpp b/aomusicplayer.cpp index 3246fc2..f69128c 100644 --- a/aomusicplayer.cpp +++ b/aomusicplayer.cpp @@ -1,9 +1,5 @@ #include "aomusicplayer.h" -#include - -#include - AOMusicPlayer::AOMusicPlayer(QWidget *parent, AOApplication *p_ao_app) { m_parent = parent; diff --git a/aomusicplayer.h b/aomusicplayer.h index af8452b..560a7f9 100644 --- a/aomusicplayer.h +++ b/aomusicplayer.h @@ -5,6 +5,8 @@ #include "aoapplication.h" #include +#include +#include class AOMusicPlayer { diff --git a/aooptionsdialog.cpp b/aooptionsdialog.cpp index 3a4a34a..3d6d5d6 100644 --- a/aooptionsdialog.cpp +++ b/aooptionsdialog.cpp @@ -2,25 +2,6 @@ #include "aoapplication.h" #include "bass.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include - AOOptionsDialog::AOOptionsDialog(QWidget *parent, AOApplication *p_ao_app) : QDialog(parent) { ao_app = p_ao_app; diff --git a/aooptionsdialog.h b/aooptionsdialog.h index f43e7b7..7d09f21 100644 --- a/aooptionsdialog.h +++ b/aooptionsdialog.h @@ -20,6 +20,9 @@ #include #include +#include +#include + class AOOptionsDialog: public QDialog { Q_OBJECT diff --git a/aopacket.cpp b/aopacket.cpp index fa8f5be..b957efe 100644 --- a/aopacket.cpp +++ b/aopacket.cpp @@ -2,8 +2,6 @@ #include "encryption_functions.h" -#include - AOPacket::AOPacket(QString p_packet_string) { QStringList packet_contents = p_packet_string.split("#"); diff --git a/aopacket.h b/aopacket.h index 40dd3ec..21f6e0f 100644 --- a/aopacket.h +++ b/aopacket.h @@ -3,6 +3,7 @@ #include #include +#include class AOPacket { diff --git a/aoscene.cpp b/aoscene.cpp index 61cd342..a2e2cea 100644 --- a/aoscene.cpp +++ b/aoscene.cpp @@ -4,8 +4,6 @@ #include "file_functions.h" -#include - AOScene::AOScene(QWidget *parent, AOApplication *p_ao_app) : QLabel(parent) { m_parent = parent; diff --git a/aoscene.h b/aoscene.h index 8c96445..08c286e 100644 --- a/aoscene.h +++ b/aoscene.h @@ -2,6 +2,7 @@ #define AOSCENE_H #include +#include class Courtroom; class AOApplication; diff --git a/aosfxplayer.cpp b/aosfxplayer.cpp index c090be1..667005d 100644 --- a/aosfxplayer.cpp +++ b/aosfxplayer.cpp @@ -1,9 +1,5 @@ #include "aosfxplayer.h" -#include - -#include - AOSfxPlayer::AOSfxPlayer(QWidget *parent, AOApplication *p_ao_app) { m_parent = parent; diff --git a/aosfxplayer.h b/aosfxplayer.h index 5065c61..4fd597c 100644 --- a/aosfxplayer.h +++ b/aosfxplayer.h @@ -5,6 +5,8 @@ #include "aoapplication.h" #include +#include +#include class AOSfxPlayer { diff --git a/aotextarea.cpp b/aotextarea.cpp index 40cc314..16add10 100644 --- a/aotextarea.cpp +++ b/aotextarea.cpp @@ -1,10 +1,5 @@ #include "aotextarea.h" -#include -#include -#include -#include - AOTextArea::AOTextArea(QWidget *p_parent) : QTextBrowser(p_parent) { diff --git a/aotextarea.h b/aotextarea.h index 32635fd..9f01f15 100644 --- a/aotextarea.h +++ b/aotextarea.h @@ -2,6 +2,10 @@ #define AOTEXTAREA_H #include +#include +#include +#include +#include class AOTextArea : public QTextBrowser { diff --git a/charselect.cpp b/charselect.cpp index 72b031c..a58225f 100644 --- a/charselect.cpp +++ b/charselect.cpp @@ -5,8 +5,6 @@ #include "debug_functions.h" #include "hardware_functions.h" -#include - void Courtroom::construct_char_select() { ui_char_select_background = new AOImage(this, ao_app); diff --git a/courtroom.cpp b/courtroom.cpp index f8c7c8a..dce4186 100644 --- a/courtroom.cpp +++ b/courtroom.cpp @@ -7,14 +7,6 @@ #include "datatypes.h" #include "debug_functions.h" -#include -#include -#include -#include -#include -#include -#include - Courtroom::Courtroom(AOApplication *p_ao_app) : QMainWindow() { ao_app = p_ao_app; diff --git a/courtroom.h b/courtroom.h index 8dfa54a..d618862 100644 --- a/courtroom.h +++ b/courtroom.h @@ -33,6 +33,15 @@ #include #include +#include +#include +#include +#include +#include +#include +#include +#include + #include class AOApplication; diff --git a/debug_functions.cpp b/debug_functions.cpp index 848667d..77f2f35 100644 --- a/debug_functions.cpp +++ b/debug_functions.cpp @@ -1,5 +1,3 @@ -#include - #include "debug_functions.h" void call_error(QString p_message) diff --git a/debug_functions.h b/debug_functions.h index 6feaf90..160274c 100644 --- a/debug_functions.h +++ b/debug_functions.h @@ -2,6 +2,7 @@ #define DEBUG_FUNCTIONS_H #include +#include void call_error(QString message); void call_notice(QString message); diff --git a/discord_rich_presence.cpp b/discord_rich_presence.cpp index dc06e12..af94f3a 100644 --- a/discord_rich_presence.cpp +++ b/discord_rich_presence.cpp @@ -1,10 +1,5 @@ #include "discord_rich_presence.h" -#include -#include - -#include - namespace AttorneyOnline { Discord::Discord() diff --git a/discord_rich_presence.h b/discord_rich_presence.h index 35d5bec..fd2c481 100644 --- a/discord_rich_presence.h +++ b/discord_rich_presence.h @@ -4,6 +4,11 @@ #include #include +#include +#include + +#include + namespace AttorneyOnline { class Discord 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/lobby.cpp b/lobby.cpp index e642fae..5d2d6de 100644 --- a/lobby.cpp +++ b/lobby.cpp @@ -5,9 +5,6 @@ #include "networkmanager.h" #include "aosfxplayer.h" -#include -#include - Lobby::Lobby(AOApplication *p_ao_app) : QMainWindow() { ao_app = p_ao_app; diff --git a/lobby.h b/lobby.h index 2d3aee5..49d3d80 100644 --- a/lobby.h +++ b/lobby.h @@ -14,6 +14,9 @@ #include #include +#include +#include + class AOApplication; class Lobby : public QMainWindow 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 909c7da..d44c84c 100644 --- a/networkmanager.cpp +++ b/networkmanager.cpp @@ -4,9 +4,6 @@ #include "debug_functions.h" #include "lobby.h" -#include - - NetworkManager::NetworkManager(AOApplication *parent) : QObject(parent) { ao_app = parent; diff --git a/networkmanager.h b/networkmanager.h index 797950a..ea64814 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 abc5848..d2bdcdd 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(); diff --git a/path_functions.cpp b/path_functions.cpp index 51ddcfd..5c3d7f3 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/text_file_functions.cpp b/text_file_functions.cpp index c784d1f..175339d 100644 --- a/text_file_functions.cpp +++ b/text_file_functions.cpp @@ -2,12 +2,6 @@ #include "file_functions.h" -#include -#include -#include -#include -#include - /* * This may no longer be necessary, if we use the QSettings class. * From 6bb9dbcc4a2f24370ff0525625b96f2681de8c7e Mon Sep 17 00:00:00 2001 From: Cerapter Date: Sun, 19 Aug 2018 09:40:09 +0200 Subject: [PATCH 079/174] Version bump. --- Attorney_Online_remake.pro | 2 +- aoapplication.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Attorney_Online_remake.pro b/Attorney_Online_remake.pro index f26d5ee..599531c 100644 --- a/Attorney_Online_remake.pro +++ b/Attorney_Online_remake.pro @@ -13,7 +13,7 @@ RC_ICONS = logo.ico TARGET = Attorney_Online_CC TEMPLATE = app -VERSION = 2.4.8.0 +VERSION = 2.4.10.0 SOURCES += main.cpp\ lobby.cpp \ diff --git a/aoapplication.h b/aoapplication.h index abac7b9..c5ab2bc 100644 --- a/aoapplication.h +++ b/aoapplication.h @@ -261,7 +261,7 @@ public: private: const int RELEASE = 2; const int MAJOR_VERSION = 4; - const int MINOR_VERSION = 8; + const int MINOR_VERSION = 10; const int CCCC_RELEASE = 1; const int CCCC_MAJOR_VERSION = 3; From 61875eb088de82d47082727ae51fec6bb9b92920 Mon Sep 17 00:00:00 2001 From: Cerapter Date: Sun, 19 Aug 2018 14:04:25 +0200 Subject: [PATCH 080/174] Icon change. --- discord_rich_presence.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/discord_rich_presence.cpp b/discord_rich_presence.cpp index af94f3a..41d3e73 100644 --- a/discord_rich_presence.cpp +++ b/discord_rich_presence.cpp @@ -29,7 +29,7 @@ void Discord::state_lobby() { DiscordRichPresence presence; std::memset(&presence, 0, sizeof(presence)); - presence.largeImageKey = "aa_cc_icon_empty_png"; + presence.largeImageKey = "aa_cc_icon_new"; presence.largeImageText = "Omit!"; presence.instance = 1; @@ -44,7 +44,7 @@ void Discord::state_server(std::string name, std::string server_id) DiscordRichPresence presence; std::memset(&presence, 0, sizeof(presence)); - presence.largeImageKey = "aa_cc_icon_empty_png"; + presence.largeImageKey = "aa_cc_icon_new"; presence.largeImageText = "Omit!"; presence.instance = 1; @@ -70,7 +70,7 @@ void Discord::state_character(std::string name) DiscordRichPresence presence; std::memset(&presence, 0, sizeof(presence)); - presence.largeImageKey = "aa_cc_icon_empty_png"; + presence.largeImageKey = "aa_cc_icon_new"; presence.largeImageText = "Omit!"; presence.instance = 1; presence.details = this->server_name.c_str(); @@ -89,7 +89,7 @@ void Discord::state_spectate() DiscordRichPresence presence; std::memset(&presence, 0, sizeof(presence)); - presence.largeImageKey = "aa_cc_icon_empty_png"; + presence.largeImageKey = "aa_cc_icon_new"; presence.largeImageText = "Omit!"; presence.instance = 1; presence.details = this->server_name.c_str(); From 9ce2ec9de23c12729896c494ff6c42689664d08d Mon Sep 17 00:00:00 2001 From: Cerapter Date: Tue, 21 Aug 2018 14:53:22 +0200 Subject: [PATCH 081/174] Added the command list link to `/help`. --- server/commands.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/server/commands.py b/server/commands.py index 5dfe030..16a4a3b 100644 --- a/server/commands.py +++ b/server/commands.py @@ -310,8 +310,8 @@ def ooc_cmd_forcepos(client, arg): def ooc_cmd_help(client, arg): if len(arg) != 0: raise ArgumentError('This command has no arguments.') - help_url = 'https://github.com/AttorneyOnline/tsuserver3/blob/master/README.md' - help_msg = 'Available commands, source code and issues can be found here: {}'.format(help_url) + 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): From 4ee565591f4e4bd278336ca182c1b516236829cf Mon Sep 17 00:00:00 2001 From: Cerapter Date: Fri, 24 Aug 2018 12:58:59 +0200 Subject: [PATCH 082/174] Jukebox and area locking bugfixes. --- server/area_manager.py | 2 +- server/client_manager.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/server/area_manager.py b/server/area_manager.py index 90229d0..372195b 100644 --- a/server/area_manager.py +++ b/server/area_manager.py @@ -205,7 +205,7 @@ class AreaManager: def can_send_message(self, client): - if self.is_locked and not client.is_mod and not client.ipid in self.invite_list: + if self.is_locked and not client.is_mod and not client.id in self.invite_list: 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 diff --git a/server/client_manager.py b/server/client_manager.py index 62e141d..709e0d8 100644 --- a/server/client_manager.py +++ b/server/client_manager.py @@ -106,8 +106,6 @@ class ClientManager: return True def disconnect(self): - if self.area.jukebox: - self.area.remove_jukebox_vote(self, True) self.transport.close() def change_character(self, char_id, force=False): @@ -337,6 +335,8 @@ class ClientManager: def remove_client(self, client): + if client.area.jukebox: + client.area.remove_jukebox_vote(client, True) heappush(self.cur_id, client.id) self.clients.remove(client) From 91ad46eea043673b188f5b5d4be49d66e0b7ba0d Mon Sep 17 00:00:00 2001 From: Cerapter Date: Fri, 24 Aug 2018 15:51:28 +0200 Subject: [PATCH 083/174] Fixed a Windows bug where there was no way to get back to the default audio device. --- aoapplication.h | 2 +- aoblipplayer.cpp | 3 ++- aomusicplayer.cpp | 3 ++- aooptionsdialog.cpp | 19 +++++++++++++++++++ aooptionsdialog.h | 2 ++ aosfxplayer.cpp | 3 ++- courtroom.cpp | 22 +++++++++++++++------- 7 files changed, 43 insertions(+), 11 deletions(-) diff --git a/aoapplication.h b/aoapplication.h index c5ab2bc..fe5a478 100644 --- a/aoapplication.h +++ b/aoapplication.h @@ -265,7 +265,7 @@ private: const int CCCC_RELEASE = 1; const int CCCC_MAJOR_VERSION = 3; - const int CCCC_MINOR_VERSION = 0; + const int CCCC_MINOR_VERSION = 1; QString current_theme = "default"; diff --git a/aoblipplayer.cpp b/aoblipplayer.cpp index ed8a8d7..0ea0897 100644 --- a/aoblipplayer.cpp +++ b/aoblipplayer.cpp @@ -29,7 +29,8 @@ void AOBlipPlayer::blip_tick() HSTREAM f_stream = m_stream_list[f_cycle]; - BASS_ChannelSetDevice(f_stream, BASS_GetDevice()); + if (ao_app->get_audio_output_device() != "Default") + BASS_ChannelSetDevice(f_stream, BASS_GetDevice()); BASS_ChannelPlay(f_stream, false); } diff --git a/aomusicplayer.cpp b/aomusicplayer.cpp index f69128c..9e76358 100644 --- a/aomusicplayer.cpp +++ b/aomusicplayer.cpp @@ -21,7 +21,8 @@ void AOMusicPlayer::play(QString p_song) this->set_volume(m_volume); - BASS_ChannelSetDevice(m_stream, BASS_GetDevice()); + if (ao_app->get_audio_output_device() != "Default") + BASS_ChannelSetDevice(m_stream, BASS_GetDevice()); BASS_ChannelPlay(m_stream, false); } diff --git a/aooptionsdialog.cpp b/aooptionsdialog.cpp index 3d6d5d6..7d307dd 100644 --- a/aooptionsdialog.cpp +++ b/aooptionsdialog.cpp @@ -211,6 +211,11 @@ AOOptionsDialog::AOOptionsDialog(QWidget *parent, AOApplication *p_ao_app) : QDi 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); @@ -339,3 +344,17 @@ 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 index 7d09f21..a48bff9 100644 --- a/aooptionsdialog.h +++ b/aooptionsdialog.h @@ -79,6 +79,8 @@ private: QLabel *BlankBlipsLabel; QDialogButtonBox *SettingsButtons; + bool needs_default_audiodev(); + signals: public slots: diff --git a/aosfxplayer.cpp b/aosfxplayer.cpp index 667005d..df26ddf 100644 --- a/aosfxplayer.cpp +++ b/aosfxplayer.cpp @@ -23,7 +23,8 @@ void AOSfxPlayer::play(QString p_sfx, QString p_char) set_volume(m_volume); - BASS_ChannelSetDevice(m_stream, BASS_GetDevice()); + if (ao_app->get_audio_output_device() != "Default") + BASS_ChannelSetDevice(m_stream, BASS_GetDevice()); BASS_ChannelPlay(m_stream, false); } diff --git a/courtroom.cpp b/courtroom.cpp index dce4186..3b9930b 100644 --- a/courtroom.cpp +++ b/courtroom.cpp @@ -19,15 +19,23 @@ Courtroom::Courtroom(AOApplication *p_ao_app) : QMainWindow() int a = 0; BASS_DEVICEINFO info; - for (a = 0; BASS_GetDeviceInfo(a, &info); a++) + if (ao_app->get_audio_output_device() == "Default") { - if (ao_app->get_audio_output_device() == info.name) + BASS_Init(-1, 48000, BASS_DEVICE_LATENCY, 0, NULL); + BASS_PluginLoad("bassopus.dll", BASS_UNICODE); + } + else + { + for (a = 0; BASS_GetDeviceInfo(a, &info); a++) { - BASS_SetDevice(a); - BASS_Init(a, 48000, BASS_DEVICE_LATENCY, 0, NULL); - BASS_PluginLoad("bassopus.dll", BASS_UNICODE); - qDebug() << info.name << "was set as the default audio output device."; - break; + if (ao_app->get_audio_output_device() == info.name) + { + BASS_SetDevice(a); + BASS_Init(a, 48000, BASS_DEVICE_LATENCY, 0, NULL); + BASS_PluginLoad("bassopus.dll", BASS_UNICODE); + qDebug() << info.name << "was set as the default audio output device."; + break; + } } } From 6d278330a2299fb00937622ad40725f23898794c Mon Sep 17 00:00:00 2001 From: Cerapter Date: Fri, 24 Aug 2018 18:48:13 +0200 Subject: [PATCH 084/174] `/getarea` now shows the CM, `/jukebox_toggle` and `/jukebox_skip` are now CM commands as well. --- server/client_manager.py | 5 ++++- server/commands.py | 20 +++++++++++++++----- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/server/client_manager.py b/server/client_manager.py index 709e0d8..c5e0b10 100644 --- a/server/client_manager.py +++ b/server/client_manager.py @@ -225,7 +225,10 @@ class ClientManager: sorted_clients.append(client) sorted_clients = sorted(sorted_clients, key=lambda x: x.get_char_name()) for c in sorted_clients: - info += '\r\n[{}] {}'.format(c.id, c.get_char_name()) + info += '\r\n' + if c.is_cm: + info +='[CM]' + info += '[{}] {}'.format(c.id, c.get_char_name()) if self.is_mod: info += ' ({})'.format(c.ipid) info += ': {}'.format(c.name) diff --git a/server/commands.py b/server/commands.py index 16a4a3b..6d34338 100644 --- a/server/commands.py +++ b/server/commands.py @@ -169,15 +169,20 @@ def ooc_cmd_currentmusic(client, arg): client.area.current_music_player)) def ooc_cmd_jukebox_toggle(client, arg): - if not client.is_mod: + if not client.is_mod and not client.is_cm: 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.send_host_message('A mod has set the jukebox to {}.'.format(client.area.jukebox)) + changer = 'Unknown' + if client.is_cm: + changer = 'The CM' + elif client.is_mod: + changer = 'A mod' + client.area.send_host_message('{} has set the jukebox to {}.'.format(changer, client.area.jukebox)) def ooc_cmd_jukebox_skip(client, arg): - if not client.is_mod: + if not client.is_mod and not client.is_cm: raise ClientError('You must be authorized to do that.') if len(arg) != 0: raise ArgumentError('This command has no arguments.') @@ -186,10 +191,15 @@ def ooc_cmd_jukebox_skip(client, arg): if len(client.area.jukebox_votes) == 0: raise ClientError('There is no song playing right now, skipping is pointless.') client.area.start_jukebox() + changer = 'Unknown' + if client.is_cm: + changer = 'The CM' + elif client.is_mod: + changer = 'A mod' if len(client.area.jukebox_votes) == 1: - client.area.send_host_message('A mod has forced a skip, restarting the only jukebox song.') + client.area.send_host_message('{} has forced a skip, restarting the only jukebox song.'.format(changer)) else: - client.area.send_host_message('A mod has forced a skip to the next jukebox song.') + client.area.send_host_message('{} has forced a skip to the next jukebox song.'.format(changer)) logger.log_server('[{}][{}]Skipped the current jukebox song.'.format(client.area.id, client.get_char_name())) def ooc_cmd_jukebox(client, arg): From 34da56eea66b015c9ed3debc694821748e7e3ec9 Mon Sep 17 00:00:00 2001 From: Cerapter Date: Fri, 24 Aug 2018 19:14:22 +0200 Subject: [PATCH 085/174] Blankposting is allowed again if an area loses its CM somehow. --- server/area_manager.py | 1 + server/commands.py | 1 + 2 files changed, 2 insertions(+) diff --git a/server/area_manager.py b/server/area_manager.py index 372195b..15dddd6 100644 --- a/server/area_manager.py +++ b/server/area_manager.py @@ -81,6 +81,7 @@ class AreaManager: def unlock(self): self.is_locked = False + self.blankposting_allowed = True self.invite_list = {} self.send_host_message('This area is open now.') diff --git a/server/commands.py b/server/commands.py index 6d34338..7c212ba 100644 --- a/server/commands.py +++ b/server/commands.py @@ -643,6 +643,7 @@ def ooc_cmd_uncm(client, arg): if client.is_cm: client.is_cm = False client.area.owned = False + client.area.blankposting_allowed = True if client.area.is_locked: client.area.unlock() client.area.send_host_message('{} is no longer CM in this area.'.format(client.get_char_name())) From ce73d268011fe3d0f410c1fe99b3dbb97bdbff91 Mon Sep 17 00:00:00 2001 From: Cerapter Date: Sun, 26 Aug 2018 11:08:11 +0200 Subject: [PATCH 086/174] Updated the readme to 1.3.1 features. --- README.md | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 54 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index b78bdb2..913b174 100644 --- a/README.md +++ b/README.md @@ -23,13 +23,66 @@ Alternatively, you may wait till I make some stuff, and release a compiled execu 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. + - 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`. +- **Features not mentioned in here?** + - Check the link given by the `/help` function. + +## 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'. +- **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. + - 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`. + - 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. --- From c01857063b72f4b5bff21b78ce4a28d463a6d5d2 Mon Sep 17 00:00:00 2001 From: Cerapter Date: Sun, 26 Aug 2018 21:04:05 +0200 Subject: [PATCH 087/174] Support for animated backgrounds. --- aoscene.cpp | 20 +++++++++++++++++--- aoscene.h | 2 ++ 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/aoscene.cpp b/aoscene.cpp index a2e2cea..fef6b8f 100644 --- a/aoscene.cpp +++ b/aoscene.cpp @@ -8,6 +8,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) @@ -17,18 +18,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; }; From 0fb3b7edbfdc712710347aba05ce51316660a891 Mon Sep 17 00:00:00 2001 From: Cerapter Date: Mon, 27 Aug 2018 16:04:53 +0200 Subject: [PATCH 088/174] Jukebox fixes: clear on toggle, don't show 'has played' with one person. --- server/area_manager.py | 11 ++++++++--- server/commands.py | 1 + 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/server/area_manager.py b/server/area_manager.py index 15dddd6..07c6073 100644 --- a/server/area_manager.py +++ b/server/area_manager.py @@ -67,6 +67,7 @@ class AreaManager: self.blankposting_allowed = True self.jukebox = jukebox self.jukebox_votes = [] + self.jukebox_prev_char_id = -1 def new_client(self, client): self.clients.add(client) @@ -167,10 +168,14 @@ class AreaManager: self.current_music = '' return - if vote_picked.showname == '': - self.send_command('MC', vote_picked.name, vote_picked.client.char_id) + if vote_picked.char_id != self.jukebox_prev_char_id or len(self.jukebox_votes) > 1: + self.jukebox_prev_char_id = vote_picked.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, vote_picked.client.char_id, vote_picked.showname) + self.send_command('MC', vote_picked.name, -1) self.current_music_player = 'The Jukebox' self.current_music_player_ipid = 'has no IPID' diff --git a/server/commands.py b/server/commands.py index 7c212ba..bf1cc7e 100644 --- a/server/commands.py +++ b/server/commands.py @@ -174,6 +174,7 @@ def ooc_cmd_jukebox_toggle(client, arg): if len(arg) != 0: raise ArgumentError('This command has no arguments.') client.area.jukebox = not client.area.jukebox + client.area.jukebox_votes = [] changer = 'Unknown' if client.is_cm: changer = 'The CM' From 7aac266b9bf0eb622e23c84306dbe095ef99871c Mon Sep 17 00:00:00 2001 From: Cerapter Date: Mon, 27 Aug 2018 16:09:11 +0200 Subject: [PATCH 089/174] Additional jukebox check just in case someone is alone, but is choosing different songs. --- server/area_manager.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/area_manager.py b/server/area_manager.py index 07c6073..e1b7e55 100644 --- a/server/area_manager.py +++ b/server/area_manager.py @@ -168,7 +168,7 @@ class AreaManager: self.current_music = '' return - if vote_picked.char_id != self.jukebox_prev_char_id or len(self.jukebox_votes) > 1: + if vote_picked.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.char_id if vote_picked.showname == '': self.send_command('MC', vote_picked.name, vote_picked.client.char_id) From 712b683fd51ff11c619e97f0d7a2bd6ab5730028 Mon Sep 17 00:00:00 2001 From: Cerapter Date: Tue, 28 Aug 2018 21:35:36 +0200 Subject: [PATCH 090/174] Fixed a crash caused by `/charselect`. --- charselect.cpp | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/charselect.cpp b/charselect.cpp index a58225f..961c090 100644 --- a/charselect.cpp +++ b/charselect.cpp @@ -177,6 +177,7 @@ void Courtroom::put_button_in_place(int starting, int chars_on_this_page) 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) { @@ -201,11 +202,14 @@ void Courtroom::character_loading_finished() // 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. - 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)); + 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(); From 46e64d6077c6a9aa10f8331f43b7d8e34ba8d82f Mon Sep 17 00:00:00 2001 From: Cerapter Date: Wed, 29 Aug 2018 00:40:43 +0200 Subject: [PATCH 091/174] `/ban`, `/kick`, `/mute`, `/unmute`, `/unban` now allow for multiple people. Their IPIDs should be appended after one another with a space inbetween, so: `/ban 45123 42130 39212` for example. Further, they now all lead through the user as to what they're doing. --- server/commands.py | 127 ++++++++++++++++++++++++++++++--------------- 1 file changed, 84 insertions(+), 43 deletions(-) diff --git a/server/commands.py b/server/commands.py index bf1cc7e..4c79c29 100644 --- a/server/commands.py +++ b/server/commands.py @@ -330,44 +330,61 @@ def ooc_cmd_kick(client, arg): raise ClientError('You must be authorized to do that.') if len(arg) == 0: raise ArgumentError('You must specify a target. Use /kick .') - targets = client.server.client_manager.get_targets(client, TargetType.IPID, int(arg), False) - if targets: - for c in targets: - logger.log_server('Kicked {}.'.format(c.ipid), client) - client.send_host_message("{} was kicked.".format(c.get_char_name())) - c.disconnect() - else: - client.send_host_message("No targets found.") - -def ooc_cmd_ban(client, arg): - if not client.is_mod: - raise ClientError('You must be authorized to do that.') - try: - ipid = int(arg.strip()) - except: - raise ClientError('You must specify ipid') - try: - client.server.ban_manager.add_ban(ipid) - except ServerError: - raise - if ipid != None: + 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)) targets = client.server.client_manager.get_targets(client, TargetType.IPID, ipid, False) if targets: for c in targets: + logger.log_server('Kicked {}.'.format(c.ipid), client) + client.send_host_message("{} was kicked.".format(c.get_char_name())) 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) + 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.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) def ooc_cmd_unban(client, arg): if not client.is_mod: raise ClientError('You must be authorized to do that.') - try: - client.server.ban_manager.remove_ban(int(arg.strip())) - except: - raise ClientError('You must specify ipid') - logger.log_server('Unbanned {}.'.format(arg), client) - client.send_host_message('Unbanned {}'.format(arg)) + 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) + client.send_host_message('Unbanned {}'.format(raw_ipid)) def ooc_cmd_play(client, arg): if not client.is_mod: @@ -382,25 +399,49 @@ 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.') - try: - c = client.server.client_manager.get_targets(client, TargetType.IPID, int(arg), False)[0] - c.is_muted = True - client.send_host_message('{} existing client(s).'.format(c.get_char_name())) - except: - client.send_host_message("No targets found. Use /mute for mute") + 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: + try: + ipid = int(raw_ipid) + except: + raise ClientError('{} does not look like a valid IPID.'.format(raw_ipid)) + try: + clients = client.server.client_manager.get_targets(client, TargetType.IPID, int(ipid), False) + msg = 'Muted ' + str(ipid) + ' clients' + for c in clients: + c.is_muted = True + msg += ' ' + c.get_char_name() + ' [' + c.id + '],' + msg = msg[:-1] + msg += '.' + client.send_host_message('{}'.format(msg)) + except: + client.send_host_message("No targets found. Use /mute for mute.") 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.') - try: - c = client.server.client_manager.get_targets(client, TargetType.IPID, int(arg), False)[0] - c.is_muted = False - client.send_host_message('{} existing client(s).'.format(c.get_char_name())) - except: - client.send_host_message("No targets found. Use /mute for mute") + args = list(arg.split(' ')) + client.send_host_message('Attempting to unmute {} 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: + clients = client.server.client_manager.get_targets(client, TargetType.IPID, int(ipid), False) + msg = 'Unmuted ' + str(ipid) + ' clients' + for c in clients: + c.is_muted = True + msg += ' ' + c.get_char_name() + ' [' + c.id + '],' + msg = msg[:-1] + msg += '.' + client.send_host_message('{}'.format(msg)) + except: + client.send_host_message("No targets found. Use /unmute for unmute.") def ooc_cmd_login(client, arg): if len(arg) == 0: From 57fd4b9b9dcf81fb2d607ef11495acf11906fe01 Mon Sep 17 00:00:00 2001 From: Cerapter Date: Wed, 29 Aug 2018 16:13:11 +0200 Subject: [PATCH 092/174] Fixed jukebox not emptying on toggle, and mod actions on multiple IPIDs. --- server/area_manager.py | 4 +-- server/commands.py | 64 +++++++++++++++++++++--------------------- 2 files changed, 34 insertions(+), 34 deletions(-) diff --git a/server/area_manager.py b/server/area_manager.py index e1b7e55..ad36362 100644 --- a/server/area_manager.py +++ b/server/area_manager.py @@ -168,8 +168,8 @@ class AreaManager: self.current_music = '' return - if vote_picked.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.char_id + 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: diff --git a/server/commands.py b/server/commands.py index 4c79c29..f951ca6 100644 --- a/server/commands.py +++ b/server/commands.py @@ -329,9 +329,9 @@ 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 .') + raise ArgumentError('You must specify a target. Use /kick ...') args = list(arg.split(' ')) - client.send_host_message('Attempting to ban {} IPIDs.'.format(len(args))) + client.send_host_message('Attempting to kick {} IPIDs.'.format(len(args))) for raw_ipid in args: try: ipid = int(raw_ipid) @@ -350,7 +350,7 @@ 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 .') + 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: @@ -375,7 +375,7 @@ 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 .') + 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: @@ -403,21 +403,21 @@ def ooc_cmd_mute(client, arg): args = list(arg.split(' ')) client.send_host_message('Attempting to mute {} IPIDs.'.format(len(args))) for raw_ipid in args: - try: + if raw_ipid.isdigit(): ipid = int(raw_ipid) - except: - raise ClientError('{} does not look like a valid IPID.'.format(raw_ipid)) - try: - clients = client.server.client_manager.get_targets(client, TargetType.IPID, int(ipid), False) - msg = 'Muted ' + str(ipid) + ' clients' - for c in clients: - c.is_muted = True - msg += ' ' + c.get_char_name() + ' [' + c.id + '],' - msg = msg[:-1] - msg += '.' - client.send_host_message('{}'.format(msg)) - except: - client.send_host_message("No targets found. Use /mute for mute.") + clients = client.server.client_manager.get_targets(client, TargetType.IPID, ipid, False) + if (clients): + msg = 'Muted ' + str(ipid) + ' clients' + for c in clients: + c.is_muted = True + 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: @@ -427,21 +427,21 @@ def ooc_cmd_unmute(client, arg): args = list(arg.split(' ')) client.send_host_message('Attempting to unmute {} IPIDs.'.format(len(args))) for raw_ipid in args: - try: + if raw_ipid.isdigit(): ipid = int(raw_ipid) - except: - raise ClientError('{} does not look like a valid IPID.'.format(raw_ipid)) - try: - clients = client.server.client_manager.get_targets(client, TargetType.IPID, int(ipid), False) - msg = 'Unmuted ' + str(ipid) + ' clients' - for c in clients: - c.is_muted = True - msg += ' ' + c.get_char_name() + ' [' + c.id + '],' - msg = msg[:-1] - msg += '.' - client.send_host_message('{}'.format(msg)) - except: - client.send_host_message("No targets found. Use /unmute for unmute.") + clients = client.server.client_manager.get_targets(client, TargetType.IPID, ipid, False) + if (clients): + msg = 'Unmuted ' + str(ipid) + ' clients' + for c in clients: + c.is_muted = False + 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: From 85ceb708f755aeacc6721dcaab2f791b60ccc04b Mon Sep 17 00:00:00 2001 From: Cerapter Date: Wed, 29 Aug 2018 16:20:47 +0200 Subject: [PATCH 093/174] Added the ability to have a character not have a showname at all on clientside. It can be done by adding `needs_showname = false` into the character's `char.ini` file. --- text_file_functions.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/text_file_functions.cpp b/text_file_functions.cpp index 175339d..50e7af2 100644 --- a/text_file_functions.cpp +++ b/text_file_functions.cpp @@ -409,7 +409,10 @@ 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_needed = read_char_ini(p_char, "needs_showname", "[Options]", "[Time]"); + if (f_needed.startsWith("false")) + return ""; if (f_result == "") return p_char; else return f_result; From c3e29d685079dd1090c305b84172983ed347a63c Mon Sep 17 00:00:00 2001 From: Cerapter Date: Thu, 30 Aug 2018 13:32:09 +0200 Subject: [PATCH 094/174] Stopped people from using Unicode format characters to pretend to be the server. --- server/aoprotocol.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/server/aoprotocol.py b/server/aoprotocol.py index 5bc94bb..8313a36 100644 --- a/server/aoprotocol.py +++ b/server/aoprotocol.py @@ -26,6 +26,7 @@ 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): @@ -440,6 +441,10 @@ class AOProtocol(asyncio.Protocol): 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'): self.client.send_host_message('That name is reserved!') return From dffd48711a1bd68421832867d69f589da64e972b Mon Sep 17 00:00:00 2001 From: Cerapter Date: Sat, 1 Sep 2018 21:54:36 +0200 Subject: [PATCH 095/174] Character selection enhancements. - Changing areas or switching characters updates the character availability list for everyone. - Taken and passworded on by default. --- charselect.cpp | 5 +++++ server/client_manager.py | 15 ++++++++++----- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/charselect.cpp b/charselect.cpp index 961c090..ac73ac2 100644 --- a/charselect.cpp +++ b/charselect.cpp @@ -39,6 +39,9 @@ void Courtroom::construct_char_select() 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"); connect (char_button_mapper, SIGNAL(mapped(int)), this, SLOT(char_clicked(int))); @@ -71,6 +74,8 @@ 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(); } diff --git a/server/client_manager.py b/server/client_manager.py index c5e0b10..8323299 100644 --- a/server/client_manager.py +++ b/server/client_manager.py @@ -122,6 +122,7 @@ class ClientManager: 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.id, old_char, self.get_char_name()), self) @@ -193,6 +194,7 @@ class ClientManager: 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) @@ -276,11 +278,7 @@ class ClientManager: self.send_host_message(info) def send_done(self): - 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 - self.send_command('CharsCheck', *char_list) + 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) @@ -292,6 +290,13 @@ class ClientManager: self.char_id = -1 self.send_done() + def get_available_char_list(self): + 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.') From 69c58694ed033ed7a5fac44e2c701341210a9498 Mon Sep 17 00:00:00 2001 From: Cerapter Date: Sat, 1 Sep 2018 22:06:56 +0200 Subject: [PATCH 096/174] `/getarea` expanded to show info from `/area`. --- server/client_manager.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/server/client_manager.py b/server/client_manager.py index 8323299..292af2a 100644 --- a/server/client_manager.py +++ b/server/client_manager.py @@ -207,7 +207,7 @@ class ClientManager: owner = 'FREE' if area.owned: for client in [x for x in area.clients if x.is_cm]: - owner = 'MASTER: {}'.format(client.get_char_name()) + owner = 'CM: {}'.format(client.get_char_name()) break msg += '\r\nArea {}: {} (users: {}) [{}][{}]{}'.format(area.abbreviation, area.name, len(area.clients), area.status, owner, lock[area.is_locked]) if self.area == area: @@ -221,6 +221,16 @@ class ClientManager: except AreaError: raise info += '=== {} ==='.format(area.name) + info += '\r\n' + + lock = {True: '[LOCKED]', False: ''} + owner = 'FREE' + if area.owned: + for client in [x for x in area.clients if x.is_cm]: + owner = 'CM: {}'.format(client.get_char_name()) + break + info += '[{}]: [{} users][{}][{}]{}'.format(area.abbreviation, len(area.clients), area.status, owner, lock[area.is_locked]) + sorted_clients = [] for client in area.clients: if (not mods) or client.is_mod: From 7d207208dc94a47bdce9fd1ff682372eeb914b32 Mon Sep 17 00:00:00 2001 From: Cerapter Date: Sat, 1 Sep 2018 22:27:05 +0200 Subject: [PATCH 097/174] Unmute fix, `/getarea` prettying. --- server/client_manager.py | 7 +------ server/commands.py | 6 +++--- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/server/client_manager.py b/server/client_manager.py index 292af2a..7395217 100644 --- a/server/client_manager.py +++ b/server/client_manager.py @@ -224,12 +224,7 @@ class ClientManager: info += '\r\n' lock = {True: '[LOCKED]', False: ''} - owner = 'FREE' - if area.owned: - for client in [x for x in area.clients if x.is_cm]: - owner = 'CM: {}'.format(client.get_char_name()) - break - info += '[{}]: [{} users][{}][{}]{}'.format(area.abbreviation, len(area.clients), area.status, owner, lock[area.is_locked]) + info += '[{}]: [{} users][{}]{}'.format(area.abbreviation, len(area.clients), area.status, lock[area.is_locked]) sorted_clients = [] for client in area.clients: diff --git a/server/commands.py b/server/commands.py index f951ca6..a0dd295 100644 --- a/server/commands.py +++ b/server/commands.py @@ -809,10 +809,10 @@ 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_mute .') - targets = client.server.client_manager.get_targets(client, TargetType.ID, arg, False) + raise ArgumentError('You must specify a target. Use /ooc_unmute .') + targets = client.server.client_manager.get_ooc_muted_clients() if not targets: - raise ArgumentError('Target not found. Use /ooc_mute .') + 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))) From a21dd24380a128bfdfa8ebca95d891aca94e1ef4 Mon Sep 17 00:00:00 2001 From: Cerapter Date: Sun, 2 Sep 2018 00:56:42 +0200 Subject: [PATCH 098/174] Logging update. --- server/aoprotocol.py | 16 +++++------ server/client_manager.py | 2 +- server/commands.py | 60 +++++++++++++++++++++++++++------------- server/logger.py | 18 ++++++++++-- 4 files changed, 66 insertions(+), 30 deletions(-) diff --git a/server/aoprotocol.py b/server/aoprotocol.py index 8313a36..757eaa6 100644 --- a/server/aoprotocol.py +++ b/server/aoprotocol.py @@ -413,7 +413,7 @@ class AOProtocol(asyncio.Protocol): 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) self.client.area.set_next_msg_delay(len(msg)) - logger.log_server('[IC][{}][{}]{}'.format(self.client.area.id, self.client.get_char_name(), msg), self.client) + 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) @@ -467,7 +467,7 @@ class AOProtocol(asyncio.Protocol): args[1] = self.client.disemvowel_message(args[1]) self.client.area.send_command('CT', self.client.name, args[1]) logger.log_server( - '[OOC][{}][{}][{}]{}'.format(self.client.area.id, self.client.get_char_name(), self.client.name, + '[OOC][{}][{}]{}'.format(self.client.area.abbreviation, self.client.get_char_name(), args[1]), self.client) def net_cmd_mc(self, args): @@ -504,7 +504,7 @@ class AOProtocol(asyncio.Protocol): return showname = args[2] self.client.area.add_jukebox_vote(self.client, name, length, showname) - logger.log_server('[{}][{}]Added a jukebox vote for {}.'.format(self.client.area.id, self.client.get_char_name(), name), self.client) + 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] @@ -517,7 +517,7 @@ class AOProtocol(asyncio.Protocol): 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.id, self.client.get_char_name(), name), self.client) + .format(self.client.area.abbreviation, self.client.get_char_name(), name), self.client) except ServerError: return except ClientError as ex: @@ -556,7 +556,7 @@ class AOProtocol(asyncio.Protocol): 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.id, self.client.get_char_name()), self.client) + 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. @@ -573,7 +573,7 @@ class AOProtocol(asyncio.Protocol): 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.id, self.client.get_char_name(), args[0], args[1]), self.client) + .format(self.client.area.abbreviation, self.client.get_char_name(), args[0], args[1]), self.client) except AreaError: return @@ -633,12 +633,12 @@ class AOProtocol(asyncio.Protocol): 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.get_ip(), self.client.area.id, self.client.get_char_name())) + 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.get_ip(), self.client.area.id, self.client.get_char_name(), args[0])) + 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])]) diff --git a/server/client_manager.py b/server/client_manager.py index 7395217..37d6f5b 100644 --- a/server/client_manager.py +++ b/server/client_manager.py @@ -124,7 +124,7 @@ class ClientManager: 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.id, old_char, self.get_char_name()), self) + .format(self.area.abbreviation, old_char, self.get_char_name()), self) def change_music_cd(self): if self.is_mod or self.is_cm: diff --git a/server/commands.py b/server/commands.py index a0dd295..fab23d1 100644 --- a/server/commands.py +++ b/server/commands.py @@ -47,7 +47,7 @@ def ooc_cmd_bg(client, 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.id, client.get_char_name(), arg), client) + 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: @@ -59,7 +59,7 @@ def ooc_cmd_bglock(client,arg): else: client.area.bg_lock = "true" client.area.send_host_message('A mod has set the background lock to {}.'.format(client.area.bg_lock)) - logger.log_server('[{}][{}]Changed bglock to {}'.format(client.area.id, client.get_char_name(), client.area.bg_lock), client) + 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: @@ -125,7 +125,7 @@ def ooc_cmd_roll(client, arg): 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.id, client.get_char_name(), roll, val[0])) + '[{}][{}]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 @@ -154,7 +154,7 @@ def ooc_cmd_rollp(client, arg): client.area.send_host_message('{} rolled.'.format(client.get_char_name(), roll, val[0])) SALT = ''.join(random.choices(string.ascii_uppercase + string.digits, k=16)) logger.log_server( - '[{}][{}]Used /roll and got {} out of {}.'.format(client.area.id, client.get_char_name(), hashlib.sha1((str(roll) + SALT).encode('utf-8')).hexdigest() + '|' + SALT, val[0])) + '[{}][{}]Used /roll and got {} out of {}.'.format(client.area.abbreviation, client.get_char_name(), hashlib.sha1((str(roll) + SALT).encode('utf-8')).hexdigest() + '|' + SALT, val[0]), client) def ooc_cmd_currentmusic(client, arg): if len(arg) != 0: @@ -201,7 +201,7 @@ def ooc_cmd_jukebox_skip(client, arg): client.area.send_host_message('{} has forced a skip, restarting the only jukebox song.'.format(changer)) else: client.area.send_host_message('{} has forced a skip to the next jukebox song.'.format(changer)) - logger.log_server('[{}][{}]Skipped the current jukebox song.'.format(client.area.id, client.get_char_name())) + 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: @@ -256,7 +256,7 @@ def ooc_cmd_coinflip(client, arg): 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.id, client.get_char_name(), flip)) + '[{}][{}]Used /coinflip and got {}.'.format(client.area.abbreviation, client.get_char_name(), flip), client) def ooc_cmd_motd(client, arg): if len(arg) != 0: @@ -316,7 +316,7 @@ def ooc_cmd_forcepos(client, arg): 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.id, client.get_char_name(), pos, len(targets))) + '[{}][{}]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: @@ -340,7 +340,8 @@ def ooc_cmd_kick(client, arg): targets = client.server.client_manager.get_targets(client, TargetType.IPID, ipid, False) if targets: for c in targets: - logger.log_server('Kicked {}.'.format(c.ipid), client) + 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.disconnect() else: @@ -370,6 +371,7 @@ def ooc_cmd_ban(client, arg): 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: @@ -384,6 +386,7 @@ def ooc_cmd_unban(client, arg): 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): @@ -393,7 +396,7 @@ def ooc_cmd_play(client, arg): 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.id, client.get_char_name(), arg), client) + 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: @@ -410,6 +413,8 @@ def ooc_cmd_mute(client, arg): msg = 'Muted ' + str(ipid) + ' 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 += '.' @@ -434,6 +439,8 @@ def ooc_cmd_unmute(client, arg): msg = 'Unmuted ' + str(ipid) + ' 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 += '.' @@ -454,6 +461,7 @@ def ooc_cmd_login(client, arg): 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: @@ -461,7 +469,7 @@ def ooc_cmd_g(client, arg): 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.id, client.get_char_name(), arg), client) + 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: @@ -471,7 +479,8 @@ def ooc_cmd_gm(client, arg): 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.id, client.get_char_name(), arg), client) + 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: @@ -479,7 +488,8 @@ def ooc_cmd_m(client, arg): 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.id, client.get_char_name(), arg), client) + 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: @@ -488,7 +498,8 @@ def ooc_cmd_lm(client, arg): 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.id, client.get_char_name(), arg), client) + 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: @@ -497,7 +508,8 @@ def ooc_cmd_announce(client, arg): 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)) - logger.log_server('[{}][{}][ANNOUNCEMENT]{}.'.format(client.area.id, client.get_char_name(), arg), client) + 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: @@ -515,7 +527,7 @@ def ooc_cmd_need(client, arg): 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.id, client.get_char_name(), arg), client) + logger.log_server('[{}][{}][NEED]{}.'.format(client.area.abbreviation, client.get_char_name(), arg), client) def ooc_cmd_toggleadverts(client, arg): if len(arg) != 0: @@ -530,11 +542,11 @@ 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.id, client.get_char_name(), client.area.doc)) + '[{}][{}]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.id, client.get_char_name(), arg)) + logger.log_server('[{}][{}]Changed document to: {}'.format(client.area.abbreviation, client.get_char_name(), arg), client) def ooc_cmd_cleardoc(client, arg): @@ -542,7 +554,7 @@ def ooc_cmd_cleardoc(client, arg): 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.id, client.get_char_name(), client.area.doc)) + .format(client.area.abbreviation, client.get_char_name(), client.area.doc), client) client.area.change_doc() @@ -554,7 +566,7 @@ def ooc_cmd_status(client, arg): 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.id, client.get_char_name(), client.area.status)) + '[{}][{}]Changed status to {}'.format(client.area.abbreviation, client.get_char_name(), client.area.status), client) except AreaError: raise @@ -829,6 +841,7 @@ def ooc_cmd_disemvowel(client, arg): 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: @@ -846,6 +859,7 @@ def ooc_cmd_undisemvowel(client, arg): 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: @@ -865,6 +879,8 @@ def ooc_cmd_blockdj(client, arg): 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())) @@ -882,6 +898,8 @@ def ooc_cmd_unblockdj(client, arg): 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): @@ -898,6 +916,8 @@ def ooc_cmd_blockwtce(client, arg): 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): @@ -914,6 +934,8 @@ def ooc_cmd_unblockwtce(client, arg): 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): diff --git a/server/logger.py b/server/logger.py index 675a359..fb1b8b3 100644 --- a/server/logger.py +++ b/server/logger.py @@ -24,6 +24,7 @@ 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) @@ -44,6 +45,14 @@ def setup_logger(debug): 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 @@ -55,10 +64,15 @@ def log_server(msg, client=None): 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}][{}][MOD]'.format(info, client.id) - return '[{:<15}][{}]'.format(info, client.id) + return '[{:<15}][{:<3}][{}][MOD]'.format(info, client.id, client.name) + return '[{:<15}][{:<3}][{}]'.format(info, client.id, client.name) From 34d6f6fa544ca90140e138c557fa651c74d76d4a Mon Sep 17 00:00:00 2001 From: Cerapter Date: Sun, 2 Sep 2018 10:49:55 +0200 Subject: [PATCH 099/174] Stopped people from pretending to say a modchat message. --- server/aoprotocol.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/aoprotocol.py b/server/aoprotocol.py index 757eaa6..5dbb192 100644 --- a/server/aoprotocol.py +++ b/server/aoprotocol.py @@ -445,7 +445,7 @@ class AOProtocol(asyncio.Protocol): 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'): + 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('/'): From c8142f3f53ba926b4e5ab729ed1ca8c47998d4df Mon Sep 17 00:00:00 2001 From: Cerapter Date: Sun, 2 Sep 2018 22:51:20 +0200 Subject: [PATCH 100/174] Curse added: `/shake id`, `/unshake id`. Randomises word order in IC and OOC chat. --- server/aoprotocol.py | 4 ++++ server/client_manager.py | 8 ++++++++ server/commands.py | 38 +++++++++++++++++++++++++++++++++++++- 3 files changed, 49 insertions(+), 1 deletion(-) diff --git a/server/aoprotocol.py b/server/aoprotocol.py index 5dbb192..8516c9f 100644 --- a/server/aoprotocol.py +++ b/server/aoprotocol.py @@ -403,6 +403,8 @@ class AOProtocol(asyncio.Protocol): if pos not in ('def', 'pro', 'hld', 'hlp', 'jud', 'wit'): 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 @@ -463,6 +465,8 @@ class AOProtocol(asyncio.Protocol): 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]) diff --git a/server/client_manager.py b/server/client_manager.py index 37d6f5b..b11937c 100644 --- a/server/client_manager.py +++ b/server/client_manager.py @@ -47,6 +47,7 @@ class ClientManager: self.is_cm = False self.evi_list = [] self.disemvowel = False + self.shaken = False self.muted_global = False self.muted_adverts = False self.is_muted = False @@ -334,6 +335,13 @@ class ClientManager: 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() diff --git a/server/commands.py b/server/commands.py index fab23d1..c1d5ba8 100644 --- a/server/commands.py +++ b/server/commands.py @@ -855,7 +855,7 @@ def ooc_cmd_undisemvowel(client, arg): try: targets = client.server.client_manager.get_targets(client, TargetType.ID, int(arg), False) except: - raise ArgumentError('You must specify a target. Use /disemvowel .') + raise ArgumentError('You must specify a target. Use /undisemvowel .') if targets: for c in targets: logger.log_server('Undisemvowelling {}.'.format(c.get_ip()), client) @@ -865,6 +865,42 @@ def ooc_cmd_undisemvowel(client, arg): 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_blockdj(client, arg): if not client.is_mod: raise ClientError('You must be authorized to do that.') From 21f489a26194befb9398a4b53f1f06ffdccb75fd Mon Sep 17 00:00:00 2001 From: Cerapter Date: Sun, 2 Sep 2018 22:57:54 +0200 Subject: [PATCH 101/174] Fixed `/mods` showing all the areas that don't have mods. --- server/client_manager.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/server/client_manager.py b/server/client_manager.py index b11937c..29caff0 100644 --- a/server/client_manager.py +++ b/server/client_manager.py @@ -216,7 +216,7 @@ class ClientManager: self.send_host_message(msg) def get_area_info(self, area_id, mods): - info = '' + info = '\r\n' try: area = self.server.area_manager.get_area_by_id(area_id) except AreaError: @@ -231,6 +231,8 @@ class ClientManager: for client in area.clients: if (not mods) or client.is_mod: sorted_clients.append(client) + 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' @@ -253,7 +255,7 @@ class ClientManager: for i in range(len(self.server.area_manager.areas)): if len(self.server.area_manager.areas[i].clients) > 0: cnt += len(self.server.area_manager.areas[i].clients) - info += '\r\n{}'.format(self.get_area_info(i, mods)) + info += '{}'.format(self.get_area_info(i, mods)) info = 'Current online: {}'.format(cnt) + info else: try: From 00bfa025a20025d06ac43eaf036ad76ac373b21b Mon Sep 17 00:00:00 2001 From: Cerapter Date: Sun, 2 Sep 2018 23:00:53 +0200 Subject: [PATCH 102/174] Mate `/mute` and `/unmute` clearer. --- server/commands.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/server/commands.py b/server/commands.py index c1d5ba8..0bd9c55 100644 --- a/server/commands.py +++ b/server/commands.py @@ -410,7 +410,7 @@ def ooc_cmd_mute(client, arg): ipid = int(raw_ipid) clients = client.server.client_manager.get_targets(client, TargetType.IPID, ipid, False) if (clients): - msg = 'Muted ' + str(ipid) + ' 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) @@ -436,7 +436,7 @@ def ooc_cmd_unmute(client, arg): ipid = int(raw_ipid) clients = client.server.client_manager.get_targets(client, TargetType.IPID, ipid, False) if (clients): - msg = 'Unmuted ' + str(ipid) + ' 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) From 739142f8ddd194b7f4ed42fe813979655d04262a Mon Sep 17 00:00:00 2001 From: Cerapter Date: Mon, 3 Sep 2018 03:52:16 +0200 Subject: [PATCH 103/174] Dual characters on screen Part I The basics have been laid out. - Communication about the second character established. - Pairing sytem made. - Placement system of the second character implemented. Needs: - More testing. - A workable UI. - Fix for zooms. --- courtroom.cpp | 180 ++++++++++++++++++++++++++++++++++++++- courtroom.h | 9 +- datatypes.h | 7 +- server/aoprotocol.py | 35 +++++++- server/client_manager.py | 6 ++ 5 files changed, 228 insertions(+), 9 deletions(-) diff --git a/courtroom.cpp b/courtroom.cpp index 3b9930b..c02f94e 100644 --- a/courtroom.cpp +++ b/courtroom.cpp @@ -80,6 +80,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); @@ -379,6 +381,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()); @@ -891,6 +896,12 @@ void Courtroom::on_chat_return_pressed() //realization# //text_color#% + // Additionally, in our case: + + //showname# + //other_charid# + //self_offset#% + QStringList packet_contents; QString f_side = ao_app->get_char_side(current_char); @@ -997,6 +1008,19 @@ void Courtroom::on_chat_return_pressed() packet_contents.append(ui_ic_chat_name->text()); } + // If there is someone this user would like to appear with. + if (other_charid > -1) + { + // First, we'll add a filler in case we haven't set an IC showname. + if (ui_ic_chat_name->text().isEmpty()) + { + packet_contents.append(""); + } + + packet_contents.append(QString::number(other_charid)); + packet_contents.append(QString::number(offset_with_pair)); + } + ao_app->send_server_packet(new AOPacket("MS", packet_contents)); } @@ -1184,6 +1208,125 @@ 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 / 20; + } + 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 / 20; + } + 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 / 20; + } + 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 / 20; + } + ui_vp_sideplayer_char->move(ui_viewport->width() * hor2_offset, ui_viewport->height() * vert2_offset); + + // 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 talker is on top. + ui_vp_sideplayer_char->raise(); + ui_vp_player_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(char_list.at(got_other_charid).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) { @@ -1216,10 +1359,11 @@ void Courtroom::handle_chatmessage_3() 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(); @@ -2305,9 +2449,37 @@ void Courtroom::on_ooc_return_pressed() } else if (ooc_message.startsWith("/settings")) { - ui_ooc_chat_message->clear(); - ao_app->call_settings_menu(); - return; + ui_ooc_chat_message->clear(); + ao_app->call_settings_menu(); + 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; + } + 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; + } + return; } QStringList packet_contents; diff --git a/courtroom.h b/courtroom.h index d618862..ad00b72 100644 --- a/courtroom.h +++ b/courtroom.h @@ -194,6 +194,12 @@ private: // 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; @@ -240,7 +246,7 @@ private: //every time point in char.inis times this equals the final time const int time_mod = 40; - static const int chatmessage_size = 16; + static const int chatmessage_size = 21; QString m_chatmessage[chatmessage_size]; bool chatmessage_is_empty = false; @@ -323,6 +329,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; diff --git a/datatypes.h b/datatypes.h index 4cb54cb..fdf91bd 100644 --- a/datatypes.h +++ b/datatypes.h @@ -93,7 +93,12 @@ enum CHAT_MESSAGE FLIP, REALIZATION, TEXT_COLOR, - SHOWNAME + SHOWNAME, + OTHER_CHARID, + OTHER_EMOTE, + SELF_OFFSET, + OTHER_OFFSET, + OTHER_FLIP }; enum COLOR diff --git a/server/aoprotocol.py b/server/aoprotocol.py index 8516c9f..800ae6a 100644 --- a/server/aoprotocol.py +++ b/server/aoprotocol.py @@ -342,12 +342,14 @@ class AOProtocol(asyncio.Protocol): self.ArgType.INT, self.ArgType.INT, self.ArgType.INT): 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 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): - msg_type, pre, folder, anim, text, pos, sfx, anim_type, cid, sfx_delay, button, evidence, flip, ding, color, showname = args + self.ArgType.INT, self.ArgType.INT, self.ArgType.INT, self.ArgType.STR_OR_EMPTY, self.ArgType.INT, self.ArgType.INT): + msg_type, pre, folder, anim, text, pos, sfx, anim_type, cid, sfx_delay, button, evidence, flip, ding, color, showname, charid_pair, offset_pair = 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 @@ -412,8 +414,35 @@ class AOProtocol(asyncio.Protocol): 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 + self.client.last_sprite = anim + self.client.flip = flip + other_offset = 0 + other_emote = '' + other_flip = 0 + + 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 + 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) + sfx_delay, button, self.client.evi_list[evidence], flip, ding, color, showname, + charid_pair, other_emote, offset_pair, other_offset, other_flip) 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) diff --git a/server/client_manager.py b/server/client_manager.py index 29caff0..ec9a26a 100644 --- a/server/client_manager.py +++ b/server/client_manager.py @@ -57,6 +57,12 @@ class ClientManager: 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 #flood-guard stuff self.mus_counter = 0 From 22e0cb8e1a97e57a6235c23afc6508f5e441aefc Mon Sep 17 00:00:00 2001 From: Cerapter Date: Mon, 3 Sep 2018 12:55:57 +0200 Subject: [PATCH 104/174] Dual characters on screen Part 2. - UI option to change pairup. - Fixed a bug on the prosecution side. - Dual characters now allow for iniswapped characters. - Zooming now doesn't stay on the field, instead, the game defaults to the last emote. --- courtroom.cpp | 136 ++++++++++++++++++++++++++++++++++----- courtroom.h | 12 +++- datatypes.h | 1 + server/aoprotocol.py | 8 ++- server/client_manager.py | 1 + 5 files changed, 140 insertions(+), 18 deletions(-) diff --git a/courtroom.cpp b/courtroom.cpp index c02f94e..dd03212 100644 --- a/courtroom.cpp +++ b/courtroom.cpp @@ -119,6 +119,12 @@ Courtroom::Courtroom(AOApplication *p_ao_app) : QMainWindow() //ui_area_list = new QListWidget(this); 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"); @@ -310,6 +316,10 @@ Courtroom::Courtroom(AOApplication *p_ao_app) : QMainWindow() 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())); set_widgets(); @@ -341,6 +351,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(); @@ -430,6 +455,13 @@ void Courtroom::set_widgets() set_size_and_pos(ui_mute_list, "mute_list"); ui_mute_list->hide(); + 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, "area_list"); //ui_area_list->setStyleSheet("background-color: rgba(0, 0, 0, 0);"); @@ -697,6 +729,7 @@ void Courtroom::done_received() set_char_select_page(); set_mute_list(); + set_pair_list(); set_char_select(); @@ -1009,7 +1042,8 @@ void Courtroom::on_chat_return_pressed() } // If there is someone this user would like to appear with. - if (other_charid > -1) + // And said someone is not ourselves! + if (other_charid > -1 && other_charid != m_cid) { // First, we'll add a filler in case we haven't set an IC showname. if (ui_ic_chat_name->text().isEmpty()) @@ -1285,7 +1319,7 @@ void Courtroom::handle_chatmessage_2() { vert2_offset = -1 * hor2_offset / 20; } - ui_vp_sideplayer_char->move(ui_viewport->width() * hor2_offset, ui_viewport->height() * vert2_offset); + 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) @@ -1303,9 +1337,28 @@ void Courtroom::handle_chatmessage_2() } else { - // In every other case, the talker is on top. - ui_vp_sideplayer_char->raise(); - ui_vp_player_char->raise(); + // In every other case, the person more to the left is on top. + // With one exception, hlp. + // 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(); } @@ -1314,7 +1367,7 @@ void Courtroom::handle_chatmessage_2() ui_vp_sideplayer_char->set_flipped(true); else ui_vp_sideplayer_char->set_flipped(false); - ui_vp_sideplayer_char->play_idle(char_list.at(got_other_charid).name, m_chatmessage[OTHER_EMOTE]); + ui_vp_sideplayer_char->play_idle(m_chatmessage[OTHER_NAME], m_chatmessage[OTHER_EMOTE]); } else { @@ -1366,6 +1419,7 @@ void Courtroom::handle_chatmessage_3() { ui_vp_desk->hide(); ui_vp_legacy_desk->hide(); + ui_vp_sideplayer_char->hide(); // Hide the second character if we're zooming! if (side == "pro" || side == "hlp" || @@ -2599,25 +2653,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) @@ -2738,6 +2818,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 @@ -2747,6 +2830,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; @@ -2809,6 +2910,11 @@ 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) diff --git a/courtroom.h b/courtroom.h index ad00b72..194298f 100644 --- a/courtroom.h +++ b/courtroom.h @@ -85,6 +85,9 @@ 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(); @@ -246,7 +249,7 @@ private: //every time point in char.inis times this equals the final time const int time_mod = 40; - static const int chatmessage_size = 21; + static const int chatmessage_size = 22; QString m_chatmessage[chatmessage_size]; bool chatmessage_is_empty = false; @@ -350,6 +353,10 @@ 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; @@ -487,6 +494,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(); @@ -525,6 +533,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(); @@ -538,6 +547,7 @@ private slots: 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(); diff --git a/datatypes.h b/datatypes.h index fdf91bd..63ad836 100644 --- a/datatypes.h +++ b/datatypes.h @@ -95,6 +95,7 @@ enum CHAT_MESSAGE TEXT_COLOR, SHOWNAME, OTHER_CHARID, + OTHER_NAME, OTHER_EMOTE, SELF_OFFSET, OTHER_OFFSET, diff --git a/server/aoprotocol.py b/server/aoprotocol.py index 800ae6a..31b45d9 100644 --- a/server/aoprotocol.py +++ b/server/aoprotocol.py @@ -420,11 +420,14 @@ class AOProtocol(asyncio.Protocol): # and an other offset. self.client.charid_pair = charid_pair self.client.offset_pair = offset_pair - self.client.last_sprite = anim + 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: @@ -434,6 +437,7 @@ class AOProtocol(asyncio.Protocol): other_offset = target.offset_pair other_emote = target.last_sprite other_flip = target.flip + other_folder = target.claimed_folder break if not confirmed: @@ -442,7 +446,7 @@ class AOProtocol(asyncio.Protocol): 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_emote, offset_pair, other_offset, other_flip) + charid_pair, other_folder, other_emote, offset_pair, other_offset, other_flip) 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) diff --git a/server/client_manager.py b/server/client_manager.py index ec9a26a..bb2bcd9 100644 --- a/server/client_manager.py +++ b/server/client_manager.py @@ -63,6 +63,7 @@ class ClientManager: self.offset_pair = 0 self.last_sprite = '' self.flip = 0 + self.claimed_folder = '' #flood-guard stuff self.mus_counter = 0 From e45e138fb5c8856e3047b5c60c957782a90f5598 Mon Sep 17 00:00:00 2001 From: Cerapter Date: Mon, 3 Sep 2018 13:03:02 +0200 Subject: [PATCH 105/174] 'Call mod' button can now send argumentless modcalls again. This stopped the client from being able to call a mod in vanilla servers before. --- courtroom.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/courtroom.cpp b/courtroom.cpp index dd03212..15d5025 100644 --- a/courtroom.cpp +++ b/courtroom.cpp @@ -3017,7 +3017,10 @@ void Courtroom::on_call_mod_clicked() if (ok) { text = text.left(100); - ao_app->send_server_packet(new AOPacket("ZZ#" + text + "#%")); + 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(); From becf58dd4f9432364a64dc7af006b3938245127b Mon Sep 17 00:00:00 2001 From: Cerapter Date: Mon, 3 Sep 2018 15:55:34 +0200 Subject: [PATCH 106/174] Area list added. - Accessible with the ingame A/M button, or by `/switch_am`. - The music list now only lists music. - The area list lists the areas. - It describes general area properties (playercount, status, CM, locked). - Automatically updates as these change. - Clicking on an area behaves the same way as clicking on an area in the music list previously did. --- courtroom.cpp | 106 +++++++++++++++++++++++++++++++++++++-- courtroom.h | 50 ++++++++++++++++++ packet_distribution.cpp | 75 ++++++++++++++++++++++++++- server/area_manager.py | 32 ++++++++++++ server/client_manager.py | 6 +++ server/commands.py | 3 ++ server/tsuserver.py | 34 +++++++++++++ 7 files changed, 301 insertions(+), 5 deletions(-) diff --git a/courtroom.cpp b/courtroom.cpp index 15d5025..28540de 100644 --- a/courtroom.cpp +++ b/courtroom.cpp @@ -116,7 +116,8 @@ 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); @@ -188,6 +189,7 @@ Courtroom::Courtroom(AOApplication *p_ao_app) : QMainWindow() ui_reload_theme = new AOButton(this, ao_app); ui_call_mod = new AOButton(this, ao_app); ui_settings = new AOButton(this, ao_app); + ui_switch_area_music = new AOButton(this, ao_app); ui_pre = new QCheckBox(this); ui_pre->setText("Pre"); @@ -273,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())); @@ -309,6 +312,7 @@ Courtroom::Courtroom(AOApplication *p_ao_app) : QMainWindow() 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_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())); @@ -462,8 +466,8 @@ void Courtroom::set_widgets() set_size_and_pos(ui_pair_button, "pair_button"); ui_pair_button->set_image("pair_button.png"); - //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_area_list, "music_list"); + ui_area_list->setStyleSheet("background-color: rgba(0, 0, 0, 0);"); set_size_and_pos(ui_music_list, "music_list"); @@ -557,6 +561,9 @@ void Courtroom::set_widgets() set_size_and_pos(ui_settings, "settings"); ui_settings->setText("Settings"); + 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"); @@ -656,6 +663,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) @@ -839,6 +847,7 @@ void Courtroom::enter_courtroom(int p_cid) ui_flip->hide(); list_music(); + list_areas(); music_player->set_volume(ui_music_slider->value()); sfx_player->set_volume(ui_sfx_slider->value()); @@ -893,6 +902,71 @@ void Courtroom::list_music() } } +void Courtroom::list_areas() +{ + 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 = area_list.at(n_area); + 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 | "); + if (arup_locks.at(n_area) == true) + i_area.append("LOCKED"); + else + i_area.append("OPEN"); + + if (i_area.toLower().contains(ui_music_search->text().toLower())) + { + ui_area_list->addItem(i_area); + area_row_to_number.append(n_area); + + // Colouring logic here. + ui_area_list->item(n_listed_areas)->setBackground(free_brush); + if (arup_locks.at(n_area)) + { + 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); + } + + ++n_listed_areas; + } + } +} + void Courtroom::append_ms_chatmessage(QString f_name, QString f_message) { ui_ms_chatlog->append_chatmessage(f_name, f_message); @@ -2535,6 +2609,11 @@ void Courtroom::on_ooc_return_pressed() } return; } + else if (ooc_message.startsWith("/switch_am")) + { + on_switch_area_music_clicked(); + return; + } QStringList packet_contents; packet_contents.append(ui_ooc_chat_name->text()); @@ -2577,6 +2656,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) @@ -2717,6 +2797,12 @@ void Courtroom::on_music_list_double_clicked(QModelIndex p_model) } } +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() { if (objection_state == 1) @@ -3064,6 +3150,20 @@ 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) + "#%")); diff --git a/courtroom.h b/courtroom.h index 194298f..90cf21f 100644 --- a/courtroom.h +++ b/courtroom.h @@ -55,6 +55,43 @@ 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, bool 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) + { + arup_players[place] = value.toInt(); + } + else if (type == 1) + { + arup_statuses[place] = value; + } + else if (type == 2) + { + arup_cms[place] = value; + } + else if (type == 3) + { + arup_locks[place] = (value == "True"); + } + list_areas(); + } void character_loading_finished(); @@ -118,6 +155,7 @@ 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); @@ -206,10 +244,18 @@ private: 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; + // 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; @@ -396,6 +442,7 @@ private: AOButton *ui_reload_theme; AOButton *ui_call_mod; AOButton *ui_settings; + AOButton *ui_switch_area_music; QCheckBox *ui_pre; QCheckBox *ui_flip; @@ -502,6 +549,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); @@ -584,6 +632,8 @@ private slots: void char_clicked(int n_char); + void on_switch_area_music_clicked(); + void ping_server(); }; diff --git a/packet_distribution.cpp b/packet_distribution.cpp index d2bdcdd..9de0dfe 100644 --- a/packet_distribution.cpp +++ b/packet_distribution.cpp @@ -353,6 +353,9 @@ void AOApplication::server_packet_received(AOPacket *p_packet) if (!courtroom_constructed) goto end; + bool musics_time = false; + int areas = 0; + for (int n_element = 0 ; n_element < f_contents.size() ; n_element += 2) { if (f_contents.at(n_element).toInt() != loaded_music) @@ -367,7 +370,34 @@ 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++; + } + } + + for (int area_n = 0; area_n < areas; area_n++) + { + w_courtroom->arup_append(0, "Unknown", "Unknown", false); + } 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); @@ -426,13 +456,43 @@ void AOApplication::server_packet_received(AOPacket *p_packet) if (!courtroom_constructed) goto end; + bool musics_time = false; + int areas = 0; + for (int n_element = 0 ; n_element < f_contents.size() ; ++n_element) { ++loaded_music; w_lobby->set_loading_text("Loading music:\n" + QString::number(loaded_music) + "/" + QString::number(music_list_size)); - w_courtroom->append_music(f_contents.at(n_element)); + 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", false); + } 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); @@ -525,6 +585,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) diff --git a/server/area_manager.py b/server/area_manager.py index ad36362..6e024f6 100644 --- a/server/area_manager.py +++ b/server/area_manager.py @@ -71,12 +71,14 @@ class AreaManager: 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 client.is_cm: client.is_cm = False self.owned = False + self.server.area_manager.send_arup_cms() if self.is_locked: self.unlock() @@ -84,6 +86,7 @@ class AreaManager: self.is_locked = False self.blankposting_allowed = True self.invite_list = {} + self.server.area_manager.send_arup_lock() self.send_host_message('This area is open now.') def is_char_available(self, char_id): @@ -240,6 +243,7 @@ class AreaManager: 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 @@ -333,3 +337,31 @@ class AreaManager: return name[:3].upper() else: return name.upper() + + 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' + for client in area.clients: + if client.is_cm: + cm = client.get_char_name() + 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) + self.server.send_arup(lock_list) diff --git a/server/client_manager.py b/server/client_manager.py index bb2bcd9..b1f8785 100644 --- a/server/client_manager.py +++ b/server/client_manager.py @@ -299,6 +299,12 @@ class ClientManager: 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): diff --git a/server/commands.py b/server/commands.py index 0bd9c55..134b685 100644 --- a/server/commands.py +++ b/server/commands.py @@ -691,6 +691,7 @@ def ooc_cmd_cm(client, arg): client.is_cm = True 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())) def ooc_cmd_uncm(client, arg): @@ -700,6 +701,7 @@ def ooc_cmd_uncm(client, arg): client.area.blankposting_allowed = True if client.area.is_locked: client.area.unlock() + client.server.area_manager.send_arup_cms() client.area.send_host_message('{} is no longer CM in this area.'.format(client.get_char_name())) else: raise ClientError('You cannot give up being the CM when you are not one') @@ -718,6 +720,7 @@ def ooc_cmd_area_lock(client, arg): client.send_host_message('Area is already locked.') if client.is_cm: client.area.is_locked = True + client.server.area_manager.send_arup_lock() client.area.send_host_message('Area is locked.') for i in client.area.clients: client.area.invite_list[i.id] = None diff --git a/server/tsuserver.py b/server/tsuserver.py index 97b4b90..8f5bf85 100644 --- a/server/tsuserver.py +++ b/server/tsuserver.py @@ -258,6 +258,40 @@ class TsuServer3: 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] in (0, 3): + for part_arg in args[1:]: + try: + sanitised = int(part_arg) + except: + return + elif args[0] in (1, 2): + 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') From c395b9132eeccb10652f749866f40685ab7a14f5 Mon Sep 17 00:00:00 2001 From: Cerapter Date: Mon, 3 Sep 2018 19:15:59 +0200 Subject: [PATCH 107/174] `/charcurse`, `/uncharcurse` and `/charids` commands. Curses a player to only be able to use the given characters. --- server/aoprotocol.py | 3 ++ server/client_manager.py | 10 +++++- server/commands.py | 67 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 79 insertions(+), 1 deletion(-) diff --git a/server/aoprotocol.py b/server/aoprotocol.py index 31b45d9..3887678 100644 --- a/server/aoprotocol.py +++ b/server/aoprotocol.py @@ -358,6 +358,9 @@ class AOProtocol(asyncio.Protocol): 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 and text == ' ': self.client.send_host_message("Blankposting is forbidden in this area!") return diff --git a/server/client_manager.py b/server/client_manager.py index b1f8785..2310298 100644 --- a/server/client_manager.py +++ b/server/client_manager.py @@ -48,6 +48,7 @@ class ClientManager: self.evi_list = [] self.disemvowel = False self.shaken = False + self.charcurse = [] self.muted_global = False self.muted_adverts = False self.is_muted = False @@ -119,6 +120,10 @@ class ClientManager: 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: @@ -312,7 +317,10 @@ class ClientManager: self.send_done() def get_available_char_list(self): - avail_char_ids = set(range(len(self.server.char_list))) - set([x.char_id for x in self.area.clients]) + 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 diff --git a/server/commands.py b/server/commands.py index 134b685..8c223eb 100644 --- a/server/commands.py +++ b/server/commands.py @@ -904,6 +904,73 @@ def ooc_cmd_unshake(client, arg): 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.') + try: + targets = client.server.client_manager.get_targets(client, TargetType.ID, int(arg[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' + args = arg[1:].split() + for raw_cid in args: + 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).') + try: + targets = client.server.client_manager.get_targets(client, TargetType.ID, int(arg[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.') From 2fe5d440f419b3bfad71345350458181c9164033 Mon Sep 17 00:00:00 2001 From: Cerapter Date: Mon, 3 Sep 2018 21:51:58 +0200 Subject: [PATCH 108/174] Validation nightmare. --- server/aoprotocol.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/server/aoprotocol.py b/server/aoprotocol.py index 3887678..e9131a5 100644 --- a/server/aoprotocol.py +++ b/server/aoprotocol.py @@ -335,20 +335,35 @@ class AOProtocol(asyncio.Protocol): return if not self.client.area.can_send_message(self.client): return + 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 + 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 + 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.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 = 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!") From fe955d692350cd3bac192721c09d8fdd445afc5d Mon Sep 17 00:00:00 2001 From: Cerapter Date: Tue, 4 Sep 2018 17:32:20 +0200 Subject: [PATCH 109/174] Removed the dependency on `bass.dll`. This is merely a reimplementation of Gameboyprinter's changes on the main thing. The only thing that's different from that one is that the options menu has had its audio device removed, too. --- Attorney_Online_remake.pro | 14 +++----- README.md | 6 ---- aoapplication.h | 2 +- aoblipplayer.cpp | 36 ++++++-------------- aoblipplayer.h | 5 +-- aomusicplayer.cpp | 22 ++++-------- aomusicplayer.h | 4 +-- aooptionsdialog.cpp | 69 ++++++-------------------------------- aooptionsdialog.h | 9 ++--- aosfxplayer.cpp | 26 +++++++------- aosfxplayer.h | 5 +-- courtroom.cpp | 28 ---------------- 12 files changed, 57 insertions(+), 169 deletions(-) diff --git a/Attorney_Online_remake.pro b/Attorney_Online_remake.pro index 599531c..8c06480 100644 --- a/Attorney_Online_remake.pro +++ b/Attorney_Online_remake.pro @@ -70,7 +70,6 @@ HEADERS += lobby.h \ misc_functions.h \ aocharmovie.h \ aoemotebutton.h \ - bass.h \ aosfxplayer.h \ aomusicplayer.h \ aoblipplayer.h \ @@ -83,15 +82,10 @@ HEADERS += lobby.h \ discord-rpc.h \ aooptionsdialog.h -# 1. You need to get BASS and put the x86 bass DLL/headers in the project root folder -# AND the compilation output folder. If you want a static link, you'll probably -# need the .lib file too. MinGW-GCC is really finicky finding BASS, it seems. -# 2. You need to compile the Discord Rich Presence SDK separately and add the lib/headers -# in the same way as BASS. Discord RPC uses CMake, which does not play nicely with -# QMake, so this step must be manual. -unix:LIBS += -L$$PWD -lbass -ldiscord-rpc -win32:LIBS += -L$$PWD "$$PWD/bass.dll" -ldiscord-rpc #"$$PWD/discord-rpc.dll" -android:LIBS += -L$$PWD\android\libs\armeabi-v7a\ -lbass +# 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 +win32:LIBS += -L$$PWD -ldiscord-rpc #"$$PWD/discord-rpc.dll" CONFIG += c++11 diff --git a/README.md b/README.md index 913b174..828d329 100644 --- a/README.md +++ b/README.md @@ -103,9 +103,3 @@ Modifications copyright (c) 2017-2018 oldmud0 This project uses Qt 5, which is licensed under the [GNU Lesser General Public License](https://www.gnu.org/licenses/lgpl-3.0.txt) with [certain licensing restrictions and exceptions](https://www.qt.io/qt-licensing-terms/). To comply with licensing requirements for static linking, object code is available if you would like to relink with an alternative version of Qt, and the source code for Qt may be found at https://github.com/qt/qtbase, http://code.qt.io/cgit/, or at https://qt.io. Copyright (c) 2016 The Qt Company Ltd. - -## BASS - -This project depends on the BASS shared library. Get it here: http://www.un4seen.com/ - -Copyright (c) 1999-2016 Un4seen Developments Ltd. All rights reserved. diff --git a/aoapplication.h b/aoapplication.h index fe5a478..2d70041 100644 --- a/aoapplication.h +++ b/aoapplication.h @@ -265,7 +265,7 @@ private: const int CCCC_RELEASE = 1; const int CCCC_MAJOR_VERSION = 3; - const int CCCC_MINOR_VERSION = 1; + const int CCCC_MINOR_VERSION = 5; QString current_theme = "default"; diff --git a/aoblipplayer.cpp b/aoblipplayer.cpp index 0ea0897..5e3929e 100644 --- a/aoblipplayer.cpp +++ b/aoblipplayer.cpp @@ -2,46 +2,32 @@ 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(); - - 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); - } - + m_sfxplayer->setSource(QUrl::fromLocalFile(f_path)); set_volume(m_volume); } void AOBlipPlayer::blip_tick() { - 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); + m_sfxplayer->play(); } void AOBlipPlayer::set_volume(int p_value) { m_volume = p_value; - - 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); - } + m_sfxplayer->setVolume(p_value / 100.0); } diff --git a/aoblipplayer.h b/aoblipplayer.h index aebba77..c8a8cb6 100644 --- a/aoblipplayer.h +++ b/aoblipplayer.h @@ -1,17 +1,18 @@ #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(); @@ -22,9 +23,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/aomusicplayer.cpp b/aomusicplayer.cpp index 9e76358..62aa730 100644 --- a/aomusicplayer.cpp +++ b/aomusicplayer.cpp @@ -4,34 +4,24 @@ AOMusicPlayer::AOMusicPlayer(QWidget *parent, AOApplication *p_ao_app) { m_parent = parent; ao_app = p_ao_app; + m_player = new QMediaPlayer(); } AOMusicPlayer::~AOMusicPlayer() { - BASS_ChannelStop(m_stream); + m_player->stop(); + m_player->deleteLater(); } void AOMusicPlayer::play(QString 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); - + m_player->setMedia(QUrl::fromLocalFile(ao_app->get_music_path(p_song))); this->set_volume(m_volume); - - if (ao_app->get_audio_output_device() != "Default") - BASS_ChannelSetDevice(m_stream, BASS_GetDevice()); - BASS_ChannelPlay(m_stream, false); + m_player->play(); } void AOMusicPlayer::set_volume(int p_value) { m_volume = p_value; - - float volume = m_volume / 100.0f; - - BASS_ChannelSetAttribute(m_stream, BASS_ATTRIB_VOL, volume); - + m_player->setVolume(p_value); } diff --git a/aomusicplayer.h b/aomusicplayer.h index 560a7f9..7716ea9 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 { @@ -20,9 +20,9 @@ public: 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 index 7d307dd..e79c6f6 100644 --- a/aooptionsdialog.cpp +++ b/aooptionsdialog.cpp @@ -199,105 +199,73 @@ AOOptionsDialog::AOOptionsDialog(QWidget *parent, AOApplication *p_ao_app) : QDi 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); + AudioForm->setWidget(1, 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); + AudioForm->setWidget(1, 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); + AudioForm->setWidget(2, 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); + AudioForm->setWidget(2, 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); + AudioForm->setWidget(3, 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); + AudioForm->setWidget(3, QFormLayout::FieldRole, BlipsVolumeSpinbox); VolumeBlipDivider = new QFrame(formLayoutWidget_2); VolumeBlipDivider->setFrameShape(QFrame::HLine); VolumeBlipDivider->setFrameShadow(QFrame::Sunken); - AudioForm->setWidget(5, QFormLayout::FieldRole, VolumeBlipDivider); + AudioForm->setWidget(4, 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); + AudioForm->setWidget(5, 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); + AudioForm->setWidget(5, 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); + AudioForm->setWidget(6, QFormLayout::LabelRole, BlankBlipsLabel); BlankBlipsCheckbox = new QCheckBox(formLayoutWidget_2); BlankBlipsCheckbox->setChecked(p_ao_app->get_blank_blip()); - AudioForm->setWidget(7, QFormLayout::FieldRole, BlankBlipsCheckbox); + AudioForm->setWidget(6, QFormLayout::FieldRole, BlankBlipsCheckbox); // When we're done, we should continue the updates! setUpdatesEnabled(true); @@ -329,7 +297,6 @@ void AOOptionsDialog::save_pressed() 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()); @@ -344,17 +311,3 @@ 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 index a48bff9..0401a59 100644 --- a/aooptionsdialog.h +++ b/aooptionsdialog.h @@ -2,7 +2,6 @@ #define AOOPTIONSDIALOG_H #include "aoapplication.h" -#include "bass.h" #include #include @@ -63,9 +62,9 @@ private: QWidget *AudioTab; QWidget *formLayoutWidget_2; QFormLayout *AudioForm; - QLabel *AudioDevideLabel; - QComboBox *AudioDeviceCombobox; - QFrame *DeviceVolumeDivider; + //QLabel *AudioDevideLabel; + //QComboBox *AudioDeviceCombobox; + //QFrame *DeviceVolumeDivider; QSpinBox *MusicVolumeSpinbox; QLabel *MusicVolumeLabel; QSpinBox *SFXVolumeSpinbox; @@ -79,8 +78,6 @@ private: QLabel *BlankBlipsLabel; QDialogButtonBox *SettingsButtons; - bool needs_default_audiodev(); - signals: public slots: diff --git a/aosfxplayer.cpp b/aosfxplayer.cpp index df26ddf..972cd74 100644 --- a/aosfxplayer.cpp +++ b/aosfxplayer.cpp @@ -4,12 +4,19 @@ AOSfxPlayer::AOSfxPlayer(QWidget *parent, AOApplication *p_ao_app) { m_parent = parent; ao_app = p_ao_app; + m_sfxplayer = new QSoundEffect(); } +AOSfxPlayer::~AOSfxPlayer() +{ + m_sfxplayer->stop(); + m_sfxplayer->deleteLater(); +} + + void AOSfxPlayer::play(QString p_sfx, QString p_char) { - BASS_ChannelStop(m_stream); - + m_sfxplayer->stop(); p_sfx = p_sfx.toLower(); QString f_path; @@ -19,26 +26,19 @@ void AOSfxPlayer::play(QString p_sfx, QString p_char) else f_path = ao_app->get_sounds_path() + p_sfx; - m_stream = BASS_StreamCreateFile(FALSE, f_path.utf16(), 0, 0, BASS_STREAM_AUTOFREE | BASS_UNICODE | BASS_ASYNCFILE); - + m_sfxplayer->setSource(QUrl::fromLocalFile(f_path)); set_volume(m_volume); - if (ao_app->get_audio_output_device() != "Default") - BASS_ChannelSetDevice(m_stream, BASS_GetDevice()); - BASS_ChannelPlay(m_stream, false); + m_sfxplayer->play(); } void AOSfxPlayer::stop() { - BASS_ChannelStop(m_stream); + m_sfxplayer->stop(); } void AOSfxPlayer::set_volume(int p_value) { m_volume = p_value; - - float volume = p_value / 100.0f; - - BASS_ChannelSetAttribute(m_stream, BASS_ATTRIB_VOL, volume); - + m_sfxplayer->setVolume(p_value / 100.0); } diff --git a/aosfxplayer.h b/aosfxplayer.h index 4fd597c..1b73e49 100644 --- a/aosfxplayer.h +++ b/aosfxplayer.h @@ -1,17 +1,18 @@ #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 stop(); @@ -20,9 +21,9 @@ public: private: QWidget *m_parent; AOApplication *ao_app; + QSoundEffect *m_sfxplayer; int m_volume = 0; - HSTREAM m_stream; }; #endif // AOSFXPLAYER_H diff --git a/courtroom.cpp b/courtroom.cpp index 28540de..64afd4d 100644 --- a/courtroom.cpp +++ b/courtroom.cpp @@ -11,34 +11,6 @@ Courtroom::Courtroom(AOApplication *p_ao_app) : QMainWindow() { ao_app = p_ao_app; - //initializing sound device - - - // 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); - BASS_PluginLoad("bassopus.dll", BASS_UNICODE); - } - 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); - BASS_PluginLoad("bassopus.dll", BASS_UNICODE); - qDebug() << info.name << "was set as the default audio output device."; - break; - } - } - } - keepalive_timer = new QTimer(this); keepalive_timer->start(60000); From 956a10c3791ed507b54259cd866929ccd47f20e6 Mon Sep 17 00:00:00 2001 From: Cerapter Date: Tue, 4 Sep 2018 17:37:37 +0200 Subject: [PATCH 110/174] Fixed an argument reading error regarding `/charcurse` + `/randomchar` support for it. --- server/commands.py | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/server/commands.py b/server/commands.py index 8c223eb..6f2beb0 100644 --- a/server/commands.py +++ b/server/commands.py @@ -654,10 +654,13 @@ def ooc_cmd_reload(client, arg): def ooc_cmd_randomchar(client, arg): if len(arg) != 0: raise ArgumentError('This command has no arguments.') - try: - free_id = client.area.get_rand_avail_char_id() - except AreaError: - raise + 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: @@ -911,16 +914,16 @@ def ooc_cmd_charcurse(client, arg): 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(arg[0]), False) + 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' - args = arg[1:].split() - for raw_cid in args: + for raw_cid in args[1:]: try: cid = int(raw_cid) c.charcurse.append(cid) @@ -944,8 +947,9 @@ def ooc_cmd_uncharcurse(client, arg): 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(arg[0]), False) + 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: From a88de1563b5699ef16d73cbcdfd867da9d887795 Mon Sep 17 00:00:00 2001 From: Cerapter Date: Tue, 4 Sep 2018 17:44:13 +0200 Subject: [PATCH 111/174] Removed android. --- android/AndroidManifest.xml | 79 ------------------------------------- android/project.properties | 1 - 2 files changed, 80 deletions(-) delete mode 100644 android/AndroidManifest.xml delete mode 100644 android/project.properties 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 From cf87d39150a5a6ba850f77a8467ab21e00f1f8db Mon Sep 17 00:00:00 2001 From: Cerapter Date: Tue, 4 Sep 2018 18:15:39 +0200 Subject: [PATCH 112/174] Finished the moving of ini handling to QSettings. Though this was started before anything on our end, still, this finish is once again 100% Gameboyprinter's work, it's just reimplemented here to match our client. --- Attorney_Online_remake.pro | 3 +- aoapplication.h | 2 +- text_file_functions.cpp | 170 +++++++------------------------------ text_file_functions.h | 12 +++ 4 files changed, 46 insertions(+), 141 deletions(-) create mode 100644 text_file_functions.h diff --git a/Attorney_Online_remake.pro b/Attorney_Online_remake.pro index 8c06480..f3ab090 100644 --- a/Attorney_Online_remake.pro +++ b/Attorney_Online_remake.pro @@ -80,7 +80,8 @@ HEADERS += lobby.h \ aoevidencedisplay.h \ discord_rich_presence.h \ discord-rpc.h \ - aooptionsdialog.h + aooptionsdialog.h \ + text_file_functions.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. diff --git a/aoapplication.h b/aoapplication.h index 2d70041..f1e25eb 100644 --- a/aoapplication.h +++ b/aoapplication.h @@ -205,7 +205,7 @@ public: 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); diff --git a/text_file_functions.cpp b/text_file_functions.cpp index 50e7af2..b3f2a2d 100644 --- a/text_file_functions.cpp +++ b/text_file_functions.cpp @@ -1,44 +1,4 @@ -#include "aoapplication.h" - -#include "file_functions.h" - -/* - * This may no longer be necessary, if we use the QSettings class. - * -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() { @@ -179,40 +139,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) @@ -347,59 +280,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; @@ -408,8 +300,8 @@ 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_needed = read_char_ini(p_char, "needs_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 ""; @@ -420,7 +312,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"; @@ -429,7 +321,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"; @@ -438,7 +330,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(); @@ -446,14 +338,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; @@ -462,7 +354,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; @@ -471,7 +363,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; @@ -480,7 +372,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("#"); @@ -494,7 +386,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("#"); @@ -508,7 +400,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("#"); @@ -522,7 +414,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("#"); @@ -536,7 +428,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("#"); @@ -552,7 +444,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"; @@ -561,7 +453,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; @@ -570,7 +462,7 @@ 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; diff --git a/text_file_functions.h b/text_file_functions.h new file mode 100644 index 0000000..c5c9b14 --- /dev/null +++ b/text_file_functions.h @@ -0,0 +1,12 @@ +#ifndef TEXT_FILE_FUNCTIONS_H +#define TEXT_FILE_FUNCTIONS_H +#endif // TEXT_FILE_FUNCTIONS_H + +#include "aoapplication.h" +#include "file_functions.h" +#include +#include +#include +#include +#include +#include From adb32a0dca1a0d811da01704168421538aedbfc2 Mon Sep 17 00:00:00 2001 From: Cerapter Date: Tue, 4 Sep 2018 18:31:17 +0200 Subject: [PATCH 113/174] I should probably remove bass for real. --- aooptionsdialog.cpp | 1 - bass.h | 1051 ------------------------------------------- 2 files changed, 1052 deletions(-) delete mode 100644 bass.h diff --git a/aooptionsdialog.cpp b/aooptionsdialog.cpp index e79c6f6..31303da 100644 --- a/aooptionsdialog.cpp +++ b/aooptionsdialog.cpp @@ -1,6 +1,5 @@ #include "aooptionsdialog.h" #include "aoapplication.h" -#include "bass.h" AOOptionsDialog::AOOptionsDialog(QWidget *parent, AOApplication *p_ao_app) : QDialog(parent) { diff --git a/bass.h b/bass.h deleted file mode 100644 index 06195de..0000000 --- a/bass.h +++ /dev/null @@ -1,1051 +0,0 @@ -/* - BASS 2.4 C/C++ header file - Copyright (c) 1999-2016 Un4seen Developments Ltd. - - See the BASS.CHM file for more detailed documentation -*/ - -#ifndef BASS_H -#define BASS_H - -#ifdef _WIN32 -#include -typedef unsigned __int64 QWORD; -#else -#include -#define WINAPI -#define CALLBACK -typedef uint8_t BYTE; -typedef uint16_t WORD; -typedef uint32_t DWORD; -typedef uint64_t QWORD; -#ifndef __OBJC__ -typedef int BOOL; -#endif -#ifndef TRUE -#define TRUE 1 -#define FALSE 0 -#endif -#define LOBYTE(a) (BYTE)(a) -#define HIBYTE(a) (BYTE)((a)>>8) -#define LOWORD(a) (WORD)(a) -#define HIWORD(a) (WORD)((a)>>16) -#define MAKEWORD(a,b) (WORD)(((a)&0xff)|((b)<<8)) -#define MAKELONG(a,b) (DWORD)(((a)&0xffff)|((b)<<16)) -#endif - -#ifdef __cplusplus -extern "C" { -#endif - -#define BASSVERSION 0x204 // API version -#define BASSVERSIONTEXT "2.4" - -#ifndef BASSDEF -#define BASSDEF(f) WINAPI f -#else -#define NOBASSOVERLOADS -#endif - -typedef DWORD HMUSIC; // MOD music handle -typedef DWORD HSAMPLE; // sample handle -typedef DWORD HCHANNEL; // playing sample's channel handle -typedef DWORD HSTREAM; // sample stream handle -typedef DWORD HRECORD; // recording handle -typedef DWORD HSYNC; // synchronizer handle -typedef DWORD HDSP; // DSP handle -typedef DWORD HFX; // DX8 effect handle -typedef DWORD HPLUGIN; // Plugin handle - -// Error codes returned by BASS_ErrorGetCode -#define BASS_OK 0 // all is OK -#define BASS_ERROR_MEM 1 // memory error -#define BASS_ERROR_FILEOPEN 2 // can't open the file -#define BASS_ERROR_DRIVER 3 // can't find a free/valid driver -#define BASS_ERROR_BUFLOST 4 // the sample buffer was lost -#define BASS_ERROR_HANDLE 5 // invalid handle -#define BASS_ERROR_FORMAT 6 // unsupported sample format -#define BASS_ERROR_POSITION 7 // invalid position -#define BASS_ERROR_INIT 8 // BASS_Init has not been successfully called -#define BASS_ERROR_START 9 // BASS_Start has not been successfully called -#define BASS_ERROR_SSL 10 // SSL/HTTPS support isn't available -#define BASS_ERROR_ALREADY 14 // already initialized/paused/whatever -#define BASS_ERROR_NOCHAN 18 // can't get a free channel -#define BASS_ERROR_ILLTYPE 19 // an illegal type was specified -#define BASS_ERROR_ILLPARAM 20 // an illegal parameter was specified -#define BASS_ERROR_NO3D 21 // no 3D support -#define BASS_ERROR_NOEAX 22 // no EAX support -#define BASS_ERROR_DEVICE 23 // illegal device number -#define BASS_ERROR_NOPLAY 24 // not playing -#define BASS_ERROR_FREQ 25 // illegal sample rate -#define BASS_ERROR_NOTFILE 27 // the stream is not a file stream -#define BASS_ERROR_NOHW 29 // no hardware voices available -#define BASS_ERROR_EMPTY 31 // the MOD music has no sequence data -#define BASS_ERROR_NONET 32 // no internet connection could be opened -#define BASS_ERROR_CREATE 33 // couldn't create the file -#define BASS_ERROR_NOFX 34 // effects are not available -#define BASS_ERROR_NOTAVAIL 37 // requested data is not available -#define BASS_ERROR_DECODE 38 // the channel is/isn't a "decoding channel" -#define BASS_ERROR_DX 39 // a sufficient DirectX version is not installed -#define BASS_ERROR_TIMEOUT 40 // connection timedout -#define BASS_ERROR_FILEFORM 41 // unsupported file format -#define BASS_ERROR_SPEAKER 42 // unavailable speaker -#define BASS_ERROR_VERSION 43 // invalid BASS version (used by add-ons) -#define BASS_ERROR_CODEC 44 // codec is not available/supported -#define BASS_ERROR_ENDED 45 // the channel/file has ended -#define BASS_ERROR_BUSY 46 // the device is busy -#define BASS_ERROR_UNKNOWN -1 // some other mystery problem - -// BASS_SetConfig options -#define BASS_CONFIG_BUFFER 0 -#define BASS_CONFIG_UPDATEPERIOD 1 -#define BASS_CONFIG_GVOL_SAMPLE 4 -#define BASS_CONFIG_GVOL_STREAM 5 -#define BASS_CONFIG_GVOL_MUSIC 6 -#define BASS_CONFIG_CURVE_VOL 7 -#define BASS_CONFIG_CURVE_PAN 8 -#define BASS_CONFIG_FLOATDSP 9 -#define BASS_CONFIG_3DALGORITHM 10 -#define BASS_CONFIG_NET_TIMEOUT 11 -#define BASS_CONFIG_NET_BUFFER 12 -#define BASS_CONFIG_PAUSE_NOPLAY 13 -#define BASS_CONFIG_NET_PREBUF 15 -#define BASS_CONFIG_NET_PASSIVE 18 -#define BASS_CONFIG_REC_BUFFER 19 -#define BASS_CONFIG_NET_PLAYLIST 21 -#define BASS_CONFIG_MUSIC_VIRTUAL 22 -#define BASS_CONFIG_VERIFY 23 -#define BASS_CONFIG_UPDATETHREADS 24 -#define BASS_CONFIG_DEV_BUFFER 27 -#define BASS_CONFIG_VISTA_TRUEPOS 30 -#define BASS_CONFIG_IOS_MIXAUDIO 34 -#define BASS_CONFIG_DEV_DEFAULT 36 -#define BASS_CONFIG_NET_READTIMEOUT 37 -#define BASS_CONFIG_VISTA_SPEAKERS 38 -#define BASS_CONFIG_IOS_SPEAKER 39 -#define BASS_CONFIG_MF_DISABLE 40 -#define BASS_CONFIG_HANDLES 41 -#define BASS_CONFIG_UNICODE 42 -#define BASS_CONFIG_SRC 43 -#define BASS_CONFIG_SRC_SAMPLE 44 -#define BASS_CONFIG_ASYNCFILE_BUFFER 45 -#define BASS_CONFIG_OGG_PRESCAN 47 -#define BASS_CONFIG_MF_VIDEO 48 -#define BASS_CONFIG_AIRPLAY 49 -#define BASS_CONFIG_DEV_NONSTOP 50 -#define BASS_CONFIG_IOS_NOCATEGORY 51 -#define BASS_CONFIG_VERIFY_NET 52 -#define BASS_CONFIG_DEV_PERIOD 53 -#define BASS_CONFIG_FLOAT 54 -#define BASS_CONFIG_NET_SEEK 56 - -// BASS_SetConfigPtr options -#define BASS_CONFIG_NET_AGENT 16 -#define BASS_CONFIG_NET_PROXY 17 -#define BASS_CONFIG_IOS_NOTIFY 46 - -// BASS_Init flags -#define BASS_DEVICE_8BITS 1 // 8 bit -#define BASS_DEVICE_MONO 2 // mono -#define BASS_DEVICE_3D 4 // enable 3D functionality -#define BASS_DEVICE_16BITS 8 // limit output to 16 bit -#define BASS_DEVICE_LATENCY 0x100 // calculate device latency (BASS_INFO struct) -#define BASS_DEVICE_CPSPEAKERS 0x400 // detect speakers via Windows control panel -#define BASS_DEVICE_SPEAKERS 0x800 // force enabling of speaker assignment -#define BASS_DEVICE_NOSPEAKER 0x1000 // ignore speaker arrangement -#define BASS_DEVICE_DMIX 0x2000 // use ALSA "dmix" plugin -#define BASS_DEVICE_FREQ 0x4000 // set device sample rate -#define BASS_DEVICE_STEREO 0x8000 // limit output to stereo - -// DirectSound interfaces (for use with BASS_GetDSoundObject) -#define BASS_OBJECT_DS 1 // IDirectSound -#define BASS_OBJECT_DS3DL 2 // IDirectSound3DListener - -// Device info structure -typedef struct { -#if defined(_WIN32_WCE) || (WINAPI_FAMILY && WINAPI_FAMILY!=WINAPI_FAMILY_DESKTOP_APP) - const wchar_t *name; // description - const wchar_t *driver; // driver -#else - const char *name; // description - const char *driver; // driver -#endif - DWORD flags; -} BASS_DEVICEINFO; - -// BASS_DEVICEINFO flags -#define BASS_DEVICE_ENABLED 1 -#define BASS_DEVICE_DEFAULT 2 -#define BASS_DEVICE_INIT 4 - -#define BASS_DEVICE_TYPE_MASK 0xff000000 -#define BASS_DEVICE_TYPE_NETWORK 0x01000000 -#define BASS_DEVICE_TYPE_SPEAKERS 0x02000000 -#define BASS_DEVICE_TYPE_LINE 0x03000000 -#define BASS_DEVICE_TYPE_HEADPHONES 0x04000000 -#define BASS_DEVICE_TYPE_MICROPHONE 0x05000000 -#define BASS_DEVICE_TYPE_HEADSET 0x06000000 -#define BASS_DEVICE_TYPE_HANDSET 0x07000000 -#define BASS_DEVICE_TYPE_DIGITAL 0x08000000 -#define BASS_DEVICE_TYPE_SPDIF 0x09000000 -#define BASS_DEVICE_TYPE_HDMI 0x0a000000 -#define BASS_DEVICE_TYPE_DISPLAYPORT 0x40000000 - -// BASS_GetDeviceInfo flags -#define BASS_DEVICES_AIRPLAY 0x1000000 - -typedef struct { - DWORD flags; // device capabilities (DSCAPS_xxx flags) - DWORD hwsize; // size of total device hardware memory - DWORD hwfree; // size of free device hardware memory - DWORD freesam; // number of free sample slots in the hardware - DWORD free3d; // number of free 3D sample slots in the hardware - DWORD minrate; // min sample rate supported by the hardware - DWORD maxrate; // max sample rate supported by the hardware - BOOL eax; // device supports EAX? (always FALSE if BASS_DEVICE_3D was not used) - DWORD minbuf; // recommended minimum buffer length in ms (requires BASS_DEVICE_LATENCY) - DWORD dsver; // DirectSound version - DWORD latency; // delay (in ms) before start of playback (requires BASS_DEVICE_LATENCY) - DWORD initflags; // BASS_Init "flags" parameter - DWORD speakers; // number of speakers available - DWORD freq; // current output rate -} BASS_INFO; - -// BASS_INFO flags (from DSOUND.H) -#define DSCAPS_CONTINUOUSRATE 0x00000010 // supports all sample rates between min/maxrate -#define DSCAPS_EMULDRIVER 0x00000020 // device does NOT have hardware DirectSound support -#define DSCAPS_CERTIFIED 0x00000040 // device driver has been certified by Microsoft -#define DSCAPS_SECONDARYMONO 0x00000100 // mono -#define DSCAPS_SECONDARYSTEREO 0x00000200 // stereo -#define DSCAPS_SECONDARY8BIT 0x00000400 // 8 bit -#define DSCAPS_SECONDARY16BIT 0x00000800 // 16 bit - -// Recording device info structure -typedef struct { - DWORD flags; // device capabilities (DSCCAPS_xxx flags) - DWORD formats; // supported standard formats (WAVE_FORMAT_xxx flags) - DWORD inputs; // number of inputs - BOOL singlein; // TRUE = only 1 input can be set at a time - DWORD freq; // current input rate -} BASS_RECORDINFO; - -// BASS_RECORDINFO flags (from DSOUND.H) -#define DSCCAPS_EMULDRIVER DSCAPS_EMULDRIVER // device does NOT have hardware DirectSound recording support -#define DSCCAPS_CERTIFIED DSCAPS_CERTIFIED // device driver has been certified by Microsoft - -// defines for formats field of BASS_RECORDINFO (from MMSYSTEM.H) -#ifndef WAVE_FORMAT_1M08 -#define WAVE_FORMAT_1M08 0x00000001 /* 11.025 kHz, Mono, 8-bit */ -#define WAVE_FORMAT_1S08 0x00000002 /* 11.025 kHz, Stereo, 8-bit */ -#define WAVE_FORMAT_1M16 0x00000004 /* 11.025 kHz, Mono, 16-bit */ -#define WAVE_FORMAT_1S16 0x00000008 /* 11.025 kHz, Stereo, 16-bit */ -#define WAVE_FORMAT_2M08 0x00000010 /* 22.05 kHz, Mono, 8-bit */ -#define WAVE_FORMAT_2S08 0x00000020 /* 22.05 kHz, Stereo, 8-bit */ -#define WAVE_FORMAT_2M16 0x00000040 /* 22.05 kHz, Mono, 16-bit */ -#define WAVE_FORMAT_2S16 0x00000080 /* 22.05 kHz, Stereo, 16-bit */ -#define WAVE_FORMAT_4M08 0x00000100 /* 44.1 kHz, Mono, 8-bit */ -#define WAVE_FORMAT_4S08 0x00000200 /* 44.1 kHz, Stereo, 8-bit */ -#define WAVE_FORMAT_4M16 0x00000400 /* 44.1 kHz, Mono, 16-bit */ -#define WAVE_FORMAT_4S16 0x00000800 /* 44.1 kHz, Stereo, 16-bit */ -#endif - -// Sample info structure -typedef struct { - DWORD freq; // default playback rate - float volume; // default volume (0-1) - float pan; // default pan (-1=left, 0=middle, 1=right) - DWORD flags; // BASS_SAMPLE_xxx flags - DWORD length; // length (in bytes) - DWORD max; // maximum simultaneous playbacks - DWORD origres; // original resolution bits - DWORD chans; // number of channels - DWORD mingap; // minimum gap (ms) between creating channels - DWORD mode3d; // BASS_3DMODE_xxx mode - float mindist; // minimum distance - float maxdist; // maximum distance - DWORD iangle; // angle of inside projection cone - DWORD oangle; // angle of outside projection cone - float outvol; // delta-volume outside the projection cone - DWORD vam; // voice allocation/management flags (BASS_VAM_xxx) - DWORD priority; // priority (0=lowest, 0xffffffff=highest) -} BASS_SAMPLE; - -#define BASS_SAMPLE_8BITS 1 // 8 bit -#define BASS_SAMPLE_FLOAT 256 // 32 bit floating-point -#define BASS_SAMPLE_MONO 2 // mono -#define BASS_SAMPLE_LOOP 4 // looped -#define BASS_SAMPLE_3D 8 // 3D functionality -#define BASS_SAMPLE_SOFTWARE 16 // not using hardware mixing -#define BASS_SAMPLE_MUTEMAX 32 // mute at max distance (3D only) -#define BASS_SAMPLE_VAM 64 // DX7 voice allocation & management -#define BASS_SAMPLE_FX 128 // old implementation of DX8 effects -#define BASS_SAMPLE_OVER_VOL 0x10000 // override lowest volume -#define BASS_SAMPLE_OVER_POS 0x20000 // override longest playing -#define BASS_SAMPLE_OVER_DIST 0x30000 // override furthest from listener (3D only) - -#define BASS_STREAM_PRESCAN 0x20000 // enable pin-point seeking/length (MP3/MP2/MP1) -#define BASS_MP3_SETPOS BASS_STREAM_PRESCAN -#define BASS_STREAM_AUTOFREE 0x40000 // automatically free the stream when it stop/ends -#define BASS_STREAM_RESTRATE 0x80000 // restrict the download rate of internet file streams -#define BASS_STREAM_BLOCK 0x100000 // download/play internet file stream in small blocks -#define BASS_STREAM_DECODE 0x200000 // don't play the stream, only decode (BASS_ChannelGetData) -#define BASS_STREAM_STATUS 0x800000 // give server status info (HTTP/ICY tags) in DOWNLOADPROC - -#define BASS_MUSIC_FLOAT BASS_SAMPLE_FLOAT -#define BASS_MUSIC_MONO BASS_SAMPLE_MONO -#define BASS_MUSIC_LOOP BASS_SAMPLE_LOOP -#define BASS_MUSIC_3D BASS_SAMPLE_3D -#define BASS_MUSIC_FX BASS_SAMPLE_FX -#define BASS_MUSIC_AUTOFREE BASS_STREAM_AUTOFREE -#define BASS_MUSIC_DECODE BASS_STREAM_DECODE -#define BASS_MUSIC_PRESCAN BASS_STREAM_PRESCAN // calculate playback length -#define BASS_MUSIC_CALCLEN BASS_MUSIC_PRESCAN -#define BASS_MUSIC_RAMP 0x200 // normal ramping -#define BASS_MUSIC_RAMPS 0x400 // sensitive ramping -#define BASS_MUSIC_SURROUND 0x800 // surround sound -#define BASS_MUSIC_SURROUND2 0x1000 // surround sound (mode 2) -#define BASS_MUSIC_FT2PAN 0x2000 // apply FastTracker 2 panning to XM files -#define BASS_MUSIC_FT2MOD 0x2000 // play .MOD as FastTracker 2 does -#define BASS_MUSIC_PT1MOD 0x4000 // play .MOD as ProTracker 1 does -#define BASS_MUSIC_NONINTER 0x10000 // non-interpolated sample mixing -#define BASS_MUSIC_SINCINTER 0x800000 // sinc interpolated sample mixing -#define BASS_MUSIC_POSRESET 0x8000 // stop all notes when moving position -#define BASS_MUSIC_POSRESETEX 0x400000 // stop all notes and reset bmp/etc when moving position -#define BASS_MUSIC_STOPBACK 0x80000 // stop the music on a backwards jump effect -#define BASS_MUSIC_NOSAMPLE 0x100000 // don't load the samples - -// Speaker assignment flags -#define BASS_SPEAKER_FRONT 0x1000000 // front speakers -#define BASS_SPEAKER_REAR 0x2000000 // rear/side speakers -#define BASS_SPEAKER_CENLFE 0x3000000 // center & LFE speakers (5.1) -#define BASS_SPEAKER_REAR2 0x4000000 // rear center speakers (7.1) -#define BASS_SPEAKER_N(n) ((n)<<24) // n'th pair of speakers (max 15) -#define BASS_SPEAKER_LEFT 0x10000000 // modifier: left -#define BASS_SPEAKER_RIGHT 0x20000000 // modifier: right -#define BASS_SPEAKER_FRONTLEFT BASS_SPEAKER_FRONT|BASS_SPEAKER_LEFT -#define BASS_SPEAKER_FRONTRIGHT BASS_SPEAKER_FRONT|BASS_SPEAKER_RIGHT -#define BASS_SPEAKER_REARLEFT BASS_SPEAKER_REAR|BASS_SPEAKER_LEFT -#define BASS_SPEAKER_REARRIGHT BASS_SPEAKER_REAR|BASS_SPEAKER_RIGHT -#define BASS_SPEAKER_CENTER BASS_SPEAKER_CENLFE|BASS_SPEAKER_LEFT -#define BASS_SPEAKER_LFE BASS_SPEAKER_CENLFE|BASS_SPEAKER_RIGHT -#define BASS_SPEAKER_REAR2LEFT BASS_SPEAKER_REAR2|BASS_SPEAKER_LEFT -#define BASS_SPEAKER_REAR2RIGHT BASS_SPEAKER_REAR2|BASS_SPEAKER_RIGHT - -#define BASS_ASYNCFILE 0x40000000 -#define BASS_UNICODE 0x80000000 - -#define BASS_RECORD_PAUSE 0x8000 // start recording paused -#define BASS_RECORD_ECHOCANCEL 0x2000 -#define BASS_RECORD_AGC 0x4000 - -// DX7 voice allocation & management flags -#define BASS_VAM_HARDWARE 1 -#define BASS_VAM_SOFTWARE 2 -#define BASS_VAM_TERM_TIME 4 -#define BASS_VAM_TERM_DIST 8 -#define BASS_VAM_TERM_PRIO 16 - -// Channel info structure -typedef struct { - DWORD freq; // default playback rate - DWORD chans; // channels - DWORD flags; // BASS_SAMPLE/STREAM/MUSIC/SPEAKER flags - DWORD ctype; // type of channel - DWORD origres; // original resolution - HPLUGIN plugin; // plugin - HSAMPLE sample; // sample - const char *filename; // filename -} BASS_CHANNELINFO; - -// BASS_CHANNELINFO types -#define BASS_CTYPE_SAMPLE 1 -#define BASS_CTYPE_RECORD 2 -#define BASS_CTYPE_STREAM 0x10000 -#define BASS_CTYPE_STREAM_OGG 0x10002 -#define BASS_CTYPE_STREAM_MP1 0x10003 -#define BASS_CTYPE_STREAM_MP2 0x10004 -#define BASS_CTYPE_STREAM_MP3 0x10005 -#define BASS_CTYPE_STREAM_AIFF 0x10006 -#define BASS_CTYPE_STREAM_CA 0x10007 -#define BASS_CTYPE_STREAM_MF 0x10008 -#define BASS_CTYPE_STREAM_WAV 0x40000 // WAVE flag, LOWORD=codec -#define BASS_CTYPE_STREAM_WAV_PCM 0x50001 -#define BASS_CTYPE_STREAM_WAV_FLOAT 0x50003 -#define BASS_CTYPE_MUSIC_MOD 0x20000 -#define BASS_CTYPE_MUSIC_MTM 0x20001 -#define BASS_CTYPE_MUSIC_S3M 0x20002 -#define BASS_CTYPE_MUSIC_XM 0x20003 -#define BASS_CTYPE_MUSIC_IT 0x20004 -#define BASS_CTYPE_MUSIC_MO3 0x00100 // MO3 flag - -typedef struct { - DWORD ctype; // channel type -#if defined(_WIN32_WCE) || (WINAPI_FAMILY && WINAPI_FAMILY!=WINAPI_FAMILY_DESKTOP_APP) - const wchar_t *name; // format description - const wchar_t *exts; // file extension filter (*.ext1;*.ext2;etc...) -#else - const char *name; // format description - const char *exts; // file extension filter (*.ext1;*.ext2;etc...) -#endif -} BASS_PLUGINFORM; - -typedef struct { - DWORD version; // version (same form as BASS_GetVersion) - DWORD formatc; // number of formats - const BASS_PLUGINFORM *formats; // the array of formats -} BASS_PLUGININFO; - -// 3D vector (for 3D positions/velocities/orientations) -typedef struct BASS_3DVECTOR { -#ifdef __cplusplus - BASS_3DVECTOR() {}; - BASS_3DVECTOR(float _x, float _y, float _z) : x(_x), y(_y), z(_z) {}; -#endif - float x; // +=right, -=left - float y; // +=up, -=down - float z; // +=front, -=behind -} BASS_3DVECTOR; - -// 3D channel modes -#define BASS_3DMODE_NORMAL 0 // normal 3D processing -#define BASS_3DMODE_RELATIVE 1 // position is relative to the listener -#define BASS_3DMODE_OFF 2 // no 3D processing - -// software 3D mixing algorithms (used with BASS_CONFIG_3DALGORITHM) -#define BASS_3DALG_DEFAULT 0 -#define BASS_3DALG_OFF 1 -#define BASS_3DALG_FULL 2 -#define BASS_3DALG_LIGHT 3 - -// EAX environments, use with BASS_SetEAXParameters -enum -{ - EAX_ENVIRONMENT_GENERIC, - EAX_ENVIRONMENT_PADDEDCELL, - EAX_ENVIRONMENT_ROOM, - EAX_ENVIRONMENT_BATHROOM, - EAX_ENVIRONMENT_LIVINGROOM, - EAX_ENVIRONMENT_STONEROOM, - EAX_ENVIRONMENT_AUDITORIUM, - EAX_ENVIRONMENT_CONCERTHALL, - EAX_ENVIRONMENT_CAVE, - EAX_ENVIRONMENT_ARENA, - EAX_ENVIRONMENT_HANGAR, - EAX_ENVIRONMENT_CARPETEDHALLWAY, - EAX_ENVIRONMENT_HALLWAY, - EAX_ENVIRONMENT_STONECORRIDOR, - EAX_ENVIRONMENT_ALLEY, - EAX_ENVIRONMENT_FOREST, - EAX_ENVIRONMENT_CITY, - EAX_ENVIRONMENT_MOUNTAINS, - EAX_ENVIRONMENT_QUARRY, - EAX_ENVIRONMENT_PLAIN, - EAX_ENVIRONMENT_PARKINGLOT, - EAX_ENVIRONMENT_SEWERPIPE, - EAX_ENVIRONMENT_UNDERWATER, - EAX_ENVIRONMENT_DRUGGED, - EAX_ENVIRONMENT_DIZZY, - EAX_ENVIRONMENT_PSYCHOTIC, - - EAX_ENVIRONMENT_COUNT // total number of environments -}; - -// EAX presets, usage: BASS_SetEAXParameters(EAX_PRESET_xxx) -#define EAX_PRESET_GENERIC EAX_ENVIRONMENT_GENERIC,0.5F,1.493F,0.5F -#define EAX_PRESET_PADDEDCELL EAX_ENVIRONMENT_PADDEDCELL,0.25F,0.1F,0.0F -#define EAX_PRESET_ROOM EAX_ENVIRONMENT_ROOM,0.417F,0.4F,0.666F -#define EAX_PRESET_BATHROOM EAX_ENVIRONMENT_BATHROOM,0.653F,1.499F,0.166F -#define EAX_PRESET_LIVINGROOM EAX_ENVIRONMENT_LIVINGROOM,0.208F,0.478F,0.0F -#define EAX_PRESET_STONEROOM EAX_ENVIRONMENT_STONEROOM,0.5F,2.309F,0.888F -#define EAX_PRESET_AUDITORIUM EAX_ENVIRONMENT_AUDITORIUM,0.403F,4.279F,0.5F -#define EAX_PRESET_CONCERTHALL EAX_ENVIRONMENT_CONCERTHALL,0.5F,3.961F,0.5F -#define EAX_PRESET_CAVE EAX_ENVIRONMENT_CAVE,0.5F,2.886F,1.304F -#define EAX_PRESET_ARENA EAX_ENVIRONMENT_ARENA,0.361F,7.284F,0.332F -#define EAX_PRESET_HANGAR EAX_ENVIRONMENT_HANGAR,0.5F,10.0F,0.3F -#define EAX_PRESET_CARPETEDHALLWAY EAX_ENVIRONMENT_CARPETEDHALLWAY,0.153F,0.259F,2.0F -#define EAX_PRESET_HALLWAY EAX_ENVIRONMENT_HALLWAY,0.361F,1.493F,0.0F -#define EAX_PRESET_STONECORRIDOR EAX_ENVIRONMENT_STONECORRIDOR,0.444F,2.697F,0.638F -#define EAX_PRESET_ALLEY EAX_ENVIRONMENT_ALLEY,0.25F,1.752F,0.776F -#define EAX_PRESET_FOREST EAX_ENVIRONMENT_FOREST,0.111F,3.145F,0.472F -#define EAX_PRESET_CITY EAX_ENVIRONMENT_CITY,0.111F,2.767F,0.224F -#define EAX_PRESET_MOUNTAINS EAX_ENVIRONMENT_MOUNTAINS,0.194F,7.841F,0.472F -#define EAX_PRESET_QUARRY EAX_ENVIRONMENT_QUARRY,1.0F,1.499F,0.5F -#define EAX_PRESET_PLAIN EAX_ENVIRONMENT_PLAIN,0.097F,2.767F,0.224F -#define EAX_PRESET_PARKINGLOT EAX_ENVIRONMENT_PARKINGLOT,0.208F,1.652F,1.5F -#define EAX_PRESET_SEWERPIPE EAX_ENVIRONMENT_SEWERPIPE,0.652F,2.886F,0.25F -#define EAX_PRESET_UNDERWATER EAX_ENVIRONMENT_UNDERWATER,1.0F,1.499F,0.0F -#define EAX_PRESET_DRUGGED EAX_ENVIRONMENT_DRUGGED,0.875F,8.392F,1.388F -#define EAX_PRESET_DIZZY EAX_ENVIRONMENT_DIZZY,0.139F,17.234F,0.666F -#define EAX_PRESET_PSYCHOTIC EAX_ENVIRONMENT_PSYCHOTIC,0.486F,7.563F,0.806F - -typedef DWORD (CALLBACK STREAMPROC)(HSTREAM handle, void *buffer, DWORD length, void *user); -/* User stream callback function. NOTE: A stream function should obviously be as quick -as possible, other streams (and MOD musics) can't be mixed until it's finished. -handle : The stream that needs writing -buffer : Buffer to write the samples in -length : Number of bytes to write -user : The 'user' parameter value given when calling BASS_StreamCreate -RETURN : Number of bytes written. Set the BASS_STREAMPROC_END flag to end - the stream. */ - -#define BASS_STREAMPROC_END 0x80000000 // end of user stream flag - -// special STREAMPROCs -#define STREAMPROC_DUMMY (STREAMPROC*)0 // "dummy" stream -#define STREAMPROC_PUSH (STREAMPROC*)-1 // push stream - -// BASS_StreamCreateFileUser file systems -#define STREAMFILE_NOBUFFER 0 -#define STREAMFILE_BUFFER 1 -#define STREAMFILE_BUFFERPUSH 2 - -// User file stream callback functions -typedef void (CALLBACK FILECLOSEPROC)(void *user); -typedef QWORD (CALLBACK FILELENPROC)(void *user); -typedef DWORD (CALLBACK FILEREADPROC)(void *buffer, DWORD length, void *user); -typedef BOOL (CALLBACK FILESEEKPROC)(QWORD offset, void *user); - -typedef struct { - FILECLOSEPROC *close; - FILELENPROC *length; - FILEREADPROC *read; - FILESEEKPROC *seek; -} BASS_FILEPROCS; - -// BASS_StreamPutFileData options -#define BASS_FILEDATA_END 0 // end & close the file - -// BASS_StreamGetFilePosition modes -#define BASS_FILEPOS_CURRENT 0 -#define BASS_FILEPOS_DECODE BASS_FILEPOS_CURRENT -#define BASS_FILEPOS_DOWNLOAD 1 -#define BASS_FILEPOS_END 2 -#define BASS_FILEPOS_START 3 -#define BASS_FILEPOS_CONNECTED 4 -#define BASS_FILEPOS_BUFFER 5 -#define BASS_FILEPOS_SOCKET 6 -#define BASS_FILEPOS_ASYNCBUF 7 -#define BASS_FILEPOS_SIZE 8 - -typedef void (CALLBACK DOWNLOADPROC)(const void *buffer, DWORD length, void *user); -/* Internet stream download callback function. -buffer : Buffer containing the downloaded data... NULL=end of download -length : Number of bytes in the buffer -user : The 'user' parameter value given when calling BASS_StreamCreateURL */ - -// BASS_ChannelSetSync types -#define BASS_SYNC_POS 0 -#define BASS_SYNC_END 2 -#define BASS_SYNC_META 4 -#define BASS_SYNC_SLIDE 5 -#define BASS_SYNC_STALL 6 -#define BASS_SYNC_DOWNLOAD 7 -#define BASS_SYNC_FREE 8 -#define BASS_SYNC_SETPOS 11 -#define BASS_SYNC_MUSICPOS 10 -#define BASS_SYNC_MUSICINST 1 -#define BASS_SYNC_MUSICFX 3 -#define BASS_SYNC_OGG_CHANGE 12 -#define BASS_SYNC_MIXTIME 0x40000000 // flag: sync at mixtime, else at playtime -#define BASS_SYNC_ONETIME 0x80000000 // flag: sync only once, else continuously - -typedef void (CALLBACK SYNCPROC)(HSYNC handle, DWORD channel, DWORD data, void *user); -/* Sync callback function. NOTE: a sync callback function should be very -quick as other syncs can't be processed until it has finished. If the sync -is a "mixtime" sync, then other streams and MOD musics can't be mixed until -it's finished either. -handle : The sync that has occured -channel: Channel that the sync occured in -data : Additional data associated with the sync's occurance -user : The 'user' parameter given when calling BASS_ChannelSetSync */ - -typedef void (CALLBACK DSPPROC)(HDSP handle, DWORD channel, void *buffer, DWORD length, void *user); -/* DSP callback function. NOTE: A DSP function should obviously be as quick as -possible... other DSP functions, streams and MOD musics can not be processed -until it's finished. -handle : The DSP handle -channel: Channel that the DSP is being applied to -buffer : Buffer to apply the DSP to -length : Number of bytes in the buffer -user : The 'user' parameter given when calling BASS_ChannelSetDSP */ - -typedef BOOL (CALLBACK RECORDPROC)(HRECORD handle, const void *buffer, DWORD length, void *user); -/* Recording callback function. -handle : The recording handle -buffer : Buffer containing the recorded sample data -length : Number of bytes -user : The 'user' parameter value given when calling BASS_RecordStart -RETURN : TRUE = continue recording, FALSE = stop */ - -// BASS_ChannelIsActive return values -#define BASS_ACTIVE_STOPPED 0 -#define BASS_ACTIVE_PLAYING 1 -#define BASS_ACTIVE_STALLED 2 -#define BASS_ACTIVE_PAUSED 3 - -// Channel attributes -#define BASS_ATTRIB_FREQ 1 -#define BASS_ATTRIB_VOL 2 -#define BASS_ATTRIB_PAN 3 -#define BASS_ATTRIB_EAXMIX 4 -#define BASS_ATTRIB_NOBUFFER 5 -#define BASS_ATTRIB_VBR 6 -#define BASS_ATTRIB_CPU 7 -#define BASS_ATTRIB_SRC 8 -#define BASS_ATTRIB_NET_RESUME 9 -#define BASS_ATTRIB_SCANINFO 10 -#define BASS_ATTRIB_NORAMP 11 -#define BASS_ATTRIB_BITRATE 12 -#define BASS_ATTRIB_MUSIC_AMPLIFY 0x100 -#define BASS_ATTRIB_MUSIC_PANSEP 0x101 -#define BASS_ATTRIB_MUSIC_PSCALER 0x102 -#define BASS_ATTRIB_MUSIC_BPM 0x103 -#define BASS_ATTRIB_MUSIC_SPEED 0x104 -#define BASS_ATTRIB_MUSIC_VOL_GLOBAL 0x105 -#define BASS_ATTRIB_MUSIC_ACTIVE 0x106 -#define BASS_ATTRIB_MUSIC_VOL_CHAN 0x200 // + channel # -#define BASS_ATTRIB_MUSIC_VOL_INST 0x300 // + instrument # - -// BASS_ChannelGetData flags -#define BASS_DATA_AVAILABLE 0 // query how much data is buffered -#define BASS_DATA_FIXED 0x20000000 // flag: return 8.24 fixed-point data -#define BASS_DATA_FLOAT 0x40000000 // flag: return floating-point sample data -#define BASS_DATA_FFT256 0x80000000 // 256 sample FFT -#define BASS_DATA_FFT512 0x80000001 // 512 FFT -#define BASS_DATA_FFT1024 0x80000002 // 1024 FFT -#define BASS_DATA_FFT2048 0x80000003 // 2048 FFT -#define BASS_DATA_FFT4096 0x80000004 // 4096 FFT -#define BASS_DATA_FFT8192 0x80000005 // 8192 FFT -#define BASS_DATA_FFT16384 0x80000006 // 16384 FFT -#define BASS_DATA_FFT32768 0x80000007 // 32768 FFT -#define BASS_DATA_FFT_INDIVIDUAL 0x10 // FFT flag: FFT for each channel, else all combined -#define BASS_DATA_FFT_NOWINDOW 0x20 // FFT flag: no Hanning window -#define BASS_DATA_FFT_REMOVEDC 0x40 // FFT flag: pre-remove DC bias -#define BASS_DATA_FFT_COMPLEX 0x80 // FFT flag: return complex data - -// BASS_ChannelGetLevelEx flags -#define BASS_LEVEL_MONO 1 -#define BASS_LEVEL_STEREO 2 -#define BASS_LEVEL_RMS 4 - -// BASS_ChannelGetTags types : what's returned -#define BASS_TAG_ID3 0 // ID3v1 tags : TAG_ID3 structure -#define BASS_TAG_ID3V2 1 // ID3v2 tags : variable length block -#define BASS_TAG_OGG 2 // OGG comments : series of null-terminated UTF-8 strings -#define BASS_TAG_HTTP 3 // HTTP headers : series of null-terminated ANSI strings -#define BASS_TAG_ICY 4 // ICY headers : series of null-terminated ANSI strings -#define BASS_TAG_META 5 // ICY metadata : ANSI string -#define BASS_TAG_APE 6 // APE tags : series of null-terminated UTF-8 strings -#define BASS_TAG_MP4 7 // MP4/iTunes metadata : series of null-terminated UTF-8 strings -#define BASS_TAG_WMA 8 // WMA tags : series of null-terminated UTF-8 strings -#define BASS_TAG_VENDOR 9 // OGG encoder : UTF-8 string -#define BASS_TAG_LYRICS3 10 // Lyric3v2 tag : ASCII string -#define BASS_TAG_CA_CODEC 11 // CoreAudio codec info : TAG_CA_CODEC structure -#define BASS_TAG_MF 13 // Media Foundation tags : series of null-terminated UTF-8 strings -#define BASS_TAG_WAVEFORMAT 14 // WAVE format : WAVEFORMATEEX structure -#define BASS_TAG_RIFF_INFO 0x100 // RIFF "INFO" tags : series of null-terminated ANSI strings -#define BASS_TAG_RIFF_BEXT 0x101 // RIFF/BWF "bext" tags : TAG_BEXT structure -#define BASS_TAG_RIFF_CART 0x102 // RIFF/BWF "cart" tags : TAG_CART structure -#define BASS_TAG_RIFF_DISP 0x103 // RIFF "DISP" text tag : ANSI string -#define BASS_TAG_APE_BINARY 0x1000 // + index #, binary APE tag : TAG_APE_BINARY structure -#define BASS_TAG_MUSIC_NAME 0x10000 // MOD music name : ANSI string -#define BASS_TAG_MUSIC_MESSAGE 0x10001 // MOD message : ANSI string -#define BASS_TAG_MUSIC_ORDERS 0x10002 // MOD order list : BYTE array of pattern numbers -#define BASS_TAG_MUSIC_AUTH 0x10003 // MOD author : UTF-8 string -#define BASS_TAG_MUSIC_INST 0x10100 // + instrument #, MOD instrument name : ANSI string -#define BASS_TAG_MUSIC_SAMPLE 0x10300 // + sample #, MOD sample name : ANSI string - -// ID3v1 tag structure -typedef struct { - char id[3]; - char title[30]; - char artist[30]; - char album[30]; - char year[4]; - char comment[30]; - BYTE genre; -} TAG_ID3; - -// Binary APE tag structure -typedef struct { - const char *key; - const void *data; - DWORD length; -} TAG_APE_BINARY; - -// BWF "bext" tag structure -#ifdef _MSC_VER -#pragma warning(push) -#pragma warning(disable:4200) -#endif -#pragma pack(push,1) -typedef struct { - char Description[256]; // description - char Originator[32]; // name of the originator - char OriginatorReference[32]; // reference of the originator - char OriginationDate[10]; // date of creation (yyyy-mm-dd) - char OriginationTime[8]; // time of creation (hh-mm-ss) - QWORD TimeReference; // first sample count since midnight (little-endian) - WORD Version; // BWF version (little-endian) - BYTE UMID[64]; // SMPTE UMID - BYTE Reserved[190]; -#if defined(__GNUC__) && __GNUC__<3 - char CodingHistory[0]; // history -#elif 1 // change to 0 if compiler fails the following line - char CodingHistory[]; // history -#else - char CodingHistory[1]; // history -#endif -} TAG_BEXT; -#pragma pack(pop) - -// BWF "cart" tag structures -typedef struct -{ - DWORD dwUsage; // FOURCC timer usage ID - DWORD dwValue; // timer value in samples from head -} TAG_CART_TIMER; - -typedef struct -{ - char Version[4]; // version of the data structure - char Title[64]; // title of cart audio sequence - char Artist[64]; // artist or creator name - char CutID[64]; // cut number identification - char ClientID[64]; // client identification - char Category[64]; // category ID, PSA, NEWS, etc - char Classification[64]; // classification or auxiliary key - char OutCue[64]; // out cue text - char StartDate[10]; // yyyy-mm-dd - char StartTime[8]; // hh:mm:ss - char EndDate[10]; // yyyy-mm-dd - char EndTime[8]; // hh:mm:ss - char ProducerAppID[64]; // name of vendor or application - char ProducerAppVersion[64]; // version of producer application - char UserDef[64]; // user defined text - DWORD dwLevelReference; // sample value for 0 dB reference - TAG_CART_TIMER PostTimer[8]; // 8 time markers after head - char Reserved[276]; - char URL[1024]; // uniform resource locator -#if defined(__GNUC__) && __GNUC__<3 - char TagText[0]; // free form text for scripts or tags -#elif 1 // change to 0 if compiler fails the following line - char TagText[]; // free form text for scripts or tags -#else - char TagText[1]; // free form text for scripts or tags -#endif -} TAG_CART; -#ifdef _MSC_VER -#pragma warning(pop) -#endif - -// CoreAudio codec info structure -typedef struct { - DWORD ftype; // file format - DWORD atype; // audio format - const char *name; // description -} TAG_CA_CODEC; - -#ifndef _WAVEFORMATEX_ -#define _WAVEFORMATEX_ -#pragma pack(push,1) -typedef struct tWAVEFORMATEX -{ - WORD wFormatTag; - WORD nChannels; - DWORD nSamplesPerSec; - DWORD nAvgBytesPerSec; - WORD nBlockAlign; - WORD wBitsPerSample; - WORD cbSize; -} WAVEFORMATEX, *PWAVEFORMATEX, *LPWAVEFORMATEX; -typedef const WAVEFORMATEX *LPCWAVEFORMATEX; -#pragma pack(pop) -#endif - -// BASS_ChannelGetLength/GetPosition/SetPosition modes -#define BASS_POS_BYTE 0 // byte position -#define BASS_POS_MUSIC_ORDER 1 // order.row position, MAKELONG(order,row) -#define BASS_POS_OGG 3 // OGG bitstream number -#define BASS_POS_INEXACT 0x8000000 // flag: allow seeking to inexact position -#define BASS_POS_DECODE 0x10000000 // flag: get the decoding (not playing) position -#define BASS_POS_DECODETO 0x20000000 // flag: decode to the position instead of seeking -#define BASS_POS_SCAN 0x40000000 // flag: scan to the position - -// BASS_RecordSetInput flags -#define BASS_INPUT_OFF 0x10000 -#define BASS_INPUT_ON 0x20000 - -#define BASS_INPUT_TYPE_MASK 0xff000000 -#define BASS_INPUT_TYPE_UNDEF 0x00000000 -#define BASS_INPUT_TYPE_DIGITAL 0x01000000 -#define BASS_INPUT_TYPE_LINE 0x02000000 -#define BASS_INPUT_TYPE_MIC 0x03000000 -#define BASS_INPUT_TYPE_SYNTH 0x04000000 -#define BASS_INPUT_TYPE_CD 0x05000000 -#define BASS_INPUT_TYPE_PHONE 0x06000000 -#define BASS_INPUT_TYPE_SPEAKER 0x07000000 -#define BASS_INPUT_TYPE_WAVE 0x08000000 -#define BASS_INPUT_TYPE_AUX 0x09000000 -#define BASS_INPUT_TYPE_ANALOG 0x0a000000 - -// DX8 effect types, use with BASS_ChannelSetFX -enum -{ - BASS_FX_DX8_CHORUS, - BASS_FX_DX8_COMPRESSOR, - BASS_FX_DX8_DISTORTION, - BASS_FX_DX8_ECHO, - BASS_FX_DX8_FLANGER, - BASS_FX_DX8_GARGLE, - BASS_FX_DX8_I3DL2REVERB, - BASS_FX_DX8_PARAMEQ, - BASS_FX_DX8_REVERB -}; - -typedef struct { - float fWetDryMix; - float fDepth; - float fFeedback; - float fFrequency; - DWORD lWaveform; // 0=triangle, 1=sine - float fDelay; - DWORD lPhase; // BASS_DX8_PHASE_xxx -} BASS_DX8_CHORUS; - -typedef struct { - float fGain; - float fAttack; - float fRelease; - float fThreshold; - float fRatio; - float fPredelay; -} BASS_DX8_COMPRESSOR; - -typedef struct { - float fGain; - float fEdge; - float fPostEQCenterFrequency; - float fPostEQBandwidth; - float fPreLowpassCutoff; -} BASS_DX8_DISTORTION; - -typedef struct { - float fWetDryMix; - float fFeedback; - float fLeftDelay; - float fRightDelay; - BOOL lPanDelay; -} BASS_DX8_ECHO; - -typedef struct { - float fWetDryMix; - float fDepth; - float fFeedback; - float fFrequency; - DWORD lWaveform; // 0=triangle, 1=sine - float fDelay; - DWORD lPhase; // BASS_DX8_PHASE_xxx -} BASS_DX8_FLANGER; - -typedef struct { - DWORD dwRateHz; // Rate of modulation in hz - DWORD dwWaveShape; // 0=triangle, 1=square -} BASS_DX8_GARGLE; - -typedef struct { - int lRoom; // [-10000, 0] default: -1000 mB - int lRoomHF; // [-10000, 0] default: 0 mB - float flRoomRolloffFactor; // [0.0, 10.0] default: 0.0 - float flDecayTime; // [0.1, 20.0] default: 1.49s - float flDecayHFRatio; // [0.1, 2.0] default: 0.83 - int lReflections; // [-10000, 1000] default: -2602 mB - float flReflectionsDelay; // [0.0, 0.3] default: 0.007 s - int lReverb; // [-10000, 2000] default: 200 mB - float flReverbDelay; // [0.0, 0.1] default: 0.011 s - float flDiffusion; // [0.0, 100.0] default: 100.0 % - float flDensity; // [0.0, 100.0] default: 100.0 % - float flHFReference; // [20.0, 20000.0] default: 5000.0 Hz -} BASS_DX8_I3DL2REVERB; - -typedef struct { - float fCenter; - float fBandwidth; - float fGain; -} BASS_DX8_PARAMEQ; - -typedef struct { - float fInGain; // [-96.0,0.0] default: 0.0 dB - float fReverbMix; // [-96.0,0.0] default: 0.0 db - float fReverbTime; // [0.001,3000.0] default: 1000.0 ms - float fHighFreqRTRatio; // [0.001,0.999] default: 0.001 -} BASS_DX8_REVERB; - -#define BASS_DX8_PHASE_NEG_180 0 -#define BASS_DX8_PHASE_NEG_90 1 -#define BASS_DX8_PHASE_ZERO 2 -#define BASS_DX8_PHASE_90 3 -#define BASS_DX8_PHASE_180 4 - -typedef void (CALLBACK IOSNOTIFYPROC)(DWORD status); -/* iOS notification callback function. -status : The notification (BASS_IOSNOTIFY_xxx) */ - -#define BASS_IOSNOTIFY_INTERRUPT 1 // interruption started -#define BASS_IOSNOTIFY_INTERRUPT_END 2 // interruption ended - -BOOL BASSDEF(BASS_SetConfig)(DWORD option, DWORD value); -DWORD BASSDEF(BASS_GetConfig)(DWORD option); -BOOL BASSDEF(BASS_SetConfigPtr)(DWORD option, const void *value); -void *BASSDEF(BASS_GetConfigPtr)(DWORD option); -DWORD BASSDEF(BASS_GetVersion)(); -int BASSDEF(BASS_ErrorGetCode)(); -BOOL BASSDEF(BASS_GetDeviceInfo)(DWORD device, BASS_DEVICEINFO *info); -#if defined(_WIN32) && !defined(_WIN32_WCE) && !(WINAPI_FAMILY && WINAPI_FAMILY!=WINAPI_FAMILY_DESKTOP_APP) -BOOL BASSDEF(BASS_Init)(int device, DWORD freq, DWORD flags, HWND win, const GUID *dsguid); -#else -BOOL BASSDEF(BASS_Init)(int device, DWORD freq, DWORD flags, void *win, void *dsguid); -#endif -BOOL BASSDEF(BASS_SetDevice)(DWORD device); -DWORD BASSDEF(BASS_GetDevice)(); -BOOL BASSDEF(BASS_Free)(); -#if defined(_WIN32) && !defined(_WIN32_WCE) && !(WINAPI_FAMILY && WINAPI_FAMILY!=WINAPI_FAMILY_DESKTOP_APP) -void *BASSDEF(BASS_GetDSoundObject)(DWORD object); -#endif -BOOL BASSDEF(BASS_GetInfo)(BASS_INFO *info); -BOOL BASSDEF(BASS_Update)(DWORD length); -float BASSDEF(BASS_GetCPU)(); -BOOL BASSDEF(BASS_Start)(); -BOOL BASSDEF(BASS_Stop)(); -BOOL BASSDEF(BASS_Pause)(); -BOOL BASSDEF(BASS_SetVolume)(float volume); -float BASSDEF(BASS_GetVolume)(); - -HPLUGIN BASSDEF(BASS_PluginLoad)(const char *file, DWORD flags); -BOOL BASSDEF(BASS_PluginFree)(HPLUGIN handle); -const BASS_PLUGININFO *BASSDEF(BASS_PluginGetInfo)(HPLUGIN handle); - -BOOL BASSDEF(BASS_Set3DFactors)(float distf, float rollf, float doppf); -BOOL BASSDEF(BASS_Get3DFactors)(float *distf, float *rollf, float *doppf); -BOOL BASSDEF(BASS_Set3DPosition)(const BASS_3DVECTOR *pos, const BASS_3DVECTOR *vel, const BASS_3DVECTOR *front, const BASS_3DVECTOR *top); -BOOL BASSDEF(BASS_Get3DPosition)(BASS_3DVECTOR *pos, BASS_3DVECTOR *vel, BASS_3DVECTOR *front, BASS_3DVECTOR *top); -void BASSDEF(BASS_Apply3D)(); -#if defined(_WIN32) && !defined(_WIN32_WCE) && !(WINAPI_FAMILY && WINAPI_FAMILY!=WINAPI_FAMILY_DESKTOP_APP) -BOOL BASSDEF(BASS_SetEAXParameters)(int env, float vol, float decay, float damp); -BOOL BASSDEF(BASS_GetEAXParameters)(DWORD *env, float *vol, float *decay, float *damp); -#endif - -HMUSIC BASSDEF(BASS_MusicLoad)(BOOL mem, const void *file, QWORD offset, DWORD length, DWORD flags, DWORD freq); -BOOL BASSDEF(BASS_MusicFree)(HMUSIC handle); - -HSAMPLE BASSDEF(BASS_SampleLoad)(BOOL mem, const void *file, QWORD offset, DWORD length, DWORD max, DWORD flags); -HSAMPLE BASSDEF(BASS_SampleCreate)(DWORD length, DWORD freq, DWORD chans, DWORD max, DWORD flags); -BOOL BASSDEF(BASS_SampleFree)(HSAMPLE handle); -BOOL BASSDEF(BASS_SampleSetData)(HSAMPLE handle, const void *buffer); -BOOL BASSDEF(BASS_SampleGetData)(HSAMPLE handle, void *buffer); -BOOL BASSDEF(BASS_SampleGetInfo)(HSAMPLE handle, BASS_SAMPLE *info); -BOOL BASSDEF(BASS_SampleSetInfo)(HSAMPLE handle, const BASS_SAMPLE *info); -HCHANNEL BASSDEF(BASS_SampleGetChannel)(HSAMPLE handle, BOOL onlynew); -DWORD BASSDEF(BASS_SampleGetChannels)(HSAMPLE handle, HCHANNEL *channels); -BOOL BASSDEF(BASS_SampleStop)(HSAMPLE handle); - -HSTREAM BASSDEF(BASS_StreamCreate)(DWORD freq, DWORD chans, DWORD flags, STREAMPROC *proc, void *user); -HSTREAM BASSDEF(BASS_StreamCreateFile)(BOOL mem, const void *file, QWORD offset, QWORD length, DWORD flags); -HSTREAM BASSDEF(BASS_StreamCreateURL)(const char *url, DWORD offset, DWORD flags, DOWNLOADPROC *proc, void *user); -HSTREAM BASSDEF(BASS_StreamCreateFileUser)(DWORD system, DWORD flags, const BASS_FILEPROCS *proc, void *user); -BOOL BASSDEF(BASS_StreamFree)(HSTREAM handle); -QWORD BASSDEF(BASS_StreamGetFilePosition)(HSTREAM handle, DWORD mode); -DWORD BASSDEF(BASS_StreamPutData)(HSTREAM handle, const void *buffer, DWORD length); -DWORD BASSDEF(BASS_StreamPutFileData)(HSTREAM handle, const void *buffer, DWORD length); - -BOOL BASSDEF(BASS_RecordGetDeviceInfo)(DWORD device, BASS_DEVICEINFO *info); -BOOL BASSDEF(BASS_RecordInit)(int device); -BOOL BASSDEF(BASS_RecordSetDevice)(DWORD device); -DWORD BASSDEF(BASS_RecordGetDevice)(); -BOOL BASSDEF(BASS_RecordFree)(); -BOOL BASSDEF(BASS_RecordGetInfo)(BASS_RECORDINFO *info); -const char *BASSDEF(BASS_RecordGetInputName)(int input); -BOOL BASSDEF(BASS_RecordSetInput)(int input, DWORD flags, float volume); -DWORD BASSDEF(BASS_RecordGetInput)(int input, float *volume); -HRECORD BASSDEF(BASS_RecordStart)(DWORD freq, DWORD chans, DWORD flags, RECORDPROC *proc, void *user); - -double BASSDEF(BASS_ChannelBytes2Seconds)(DWORD handle, QWORD pos); -QWORD BASSDEF(BASS_ChannelSeconds2Bytes)(DWORD handle, double pos); -DWORD BASSDEF(BASS_ChannelGetDevice)(DWORD handle); -BOOL BASSDEF(BASS_ChannelSetDevice)(DWORD handle, DWORD device); -DWORD BASSDEF(BASS_ChannelIsActive)(DWORD handle); -BOOL BASSDEF(BASS_ChannelGetInfo)(DWORD handle, BASS_CHANNELINFO *info); -const char *BASSDEF(BASS_ChannelGetTags)(DWORD handle, DWORD tags); -DWORD BASSDEF(BASS_ChannelFlags)(DWORD handle, DWORD flags, DWORD mask); -BOOL BASSDEF(BASS_ChannelUpdate)(DWORD handle, DWORD length); -BOOL BASSDEF(BASS_ChannelLock)(DWORD handle, BOOL lock); -BOOL BASSDEF(BASS_ChannelPlay)(DWORD handle, BOOL restart); -BOOL BASSDEF(BASS_ChannelStop)(DWORD handle); -BOOL BASSDEF(BASS_ChannelPause)(DWORD handle); -BOOL BASSDEF(BASS_ChannelSetAttribute)(DWORD handle, DWORD attrib, float value); -BOOL BASSDEF(BASS_ChannelGetAttribute)(DWORD handle, DWORD attrib, float *value); -BOOL BASSDEF(BASS_ChannelSlideAttribute)(DWORD handle, DWORD attrib, float value, DWORD time); -BOOL BASSDEF(BASS_ChannelIsSliding)(DWORD handle, DWORD attrib); -BOOL BASSDEF(BASS_ChannelSetAttributeEx)(DWORD handle, DWORD attrib, void *value, DWORD size); -DWORD BASSDEF(BASS_ChannelGetAttributeEx)(DWORD handle, DWORD attrib, void *value, DWORD size); -BOOL BASSDEF(BASS_ChannelSet3DAttributes)(DWORD handle, int mode, float min, float max, int iangle, int oangle, float outvol); -BOOL BASSDEF(BASS_ChannelGet3DAttributes)(DWORD handle, DWORD *mode, float *min, float *max, DWORD *iangle, DWORD *oangle, float *outvol); -BOOL BASSDEF(BASS_ChannelSet3DPosition)(DWORD handle, const BASS_3DVECTOR *pos, const BASS_3DVECTOR *orient, const BASS_3DVECTOR *vel); -BOOL BASSDEF(BASS_ChannelGet3DPosition)(DWORD handle, BASS_3DVECTOR *pos, BASS_3DVECTOR *orient, BASS_3DVECTOR *vel); -QWORD BASSDEF(BASS_ChannelGetLength)(DWORD handle, DWORD mode); -BOOL BASSDEF(BASS_ChannelSetPosition)(DWORD handle, QWORD pos, DWORD mode); -QWORD BASSDEF(BASS_ChannelGetPosition)(DWORD handle, DWORD mode); -DWORD BASSDEF(BASS_ChannelGetLevel)(DWORD handle); -BOOL BASSDEF(BASS_ChannelGetLevelEx)(DWORD handle, float *levels, float length, DWORD flags); -DWORD BASSDEF(BASS_ChannelGetData)(DWORD handle, void *buffer, DWORD length); -HSYNC BASSDEF(BASS_ChannelSetSync)(DWORD handle, DWORD type, QWORD param, SYNCPROC *proc, void *user); -BOOL BASSDEF(BASS_ChannelRemoveSync)(DWORD handle, HSYNC sync); -HDSP BASSDEF(BASS_ChannelSetDSP)(DWORD handle, DSPPROC *proc, void *user, int priority); -BOOL BASSDEF(BASS_ChannelRemoveDSP)(DWORD handle, HDSP dsp); -BOOL BASSDEF(BASS_ChannelSetLink)(DWORD handle, DWORD chan); -BOOL BASSDEF(BASS_ChannelRemoveLink)(DWORD handle, DWORD chan); -HFX BASSDEF(BASS_ChannelSetFX)(DWORD handle, DWORD type, int priority); -BOOL BASSDEF(BASS_ChannelRemoveFX)(DWORD handle, HFX fx); - -BOOL BASSDEF(BASS_FXSetParameters)(HFX handle, const void *params); -BOOL BASSDEF(BASS_FXGetParameters)(HFX handle, void *params); -BOOL BASSDEF(BASS_FXReset)(HFX handle); -BOOL BASSDEF(BASS_FXSetPriority)(HFX handle, int priority); - -#ifdef __cplusplus -} - -#if defined(_WIN32) && !defined(NOBASSOVERLOADS) -static inline HPLUGIN BASS_PluginLoad(const WCHAR *file, DWORD flags) -{ - return BASS_PluginLoad((const char*)file, flags|BASS_UNICODE); -} - -static inline HMUSIC BASS_MusicLoad(BOOL mem, const WCHAR *file, QWORD offset, DWORD length, DWORD flags, DWORD freq) -{ - return BASS_MusicLoad(mem, (const void*)file, offset, length, flags|BASS_UNICODE, freq); -} - -static inline HSAMPLE BASS_SampleLoad(BOOL mem, const WCHAR *file, QWORD offset, DWORD length, DWORD max, DWORD flags) -{ - return BASS_SampleLoad(mem, (const void*)file, offset, length, max, flags|BASS_UNICODE); -} - -static inline HSTREAM BASS_StreamCreateFile(BOOL mem, const WCHAR *file, QWORD offset, QWORD length, DWORD flags) -{ - return BASS_StreamCreateFile(mem, (const void*)file, offset, length, flags|BASS_UNICODE); -} - -static inline HSTREAM BASS_StreamCreateURL(const WCHAR *url, DWORD offset, DWORD flags, DOWNLOADPROC *proc, void *user) -{ - return BASS_StreamCreateURL((const char*)url, offset, flags|BASS_UNICODE, proc, user); -} - -static inline BOOL BASS_SetConfigPtr(DWORD option, const WCHAR *value) -{ - return BASS_SetConfigPtr(option|BASS_UNICODE, (const void*)value); -} -#endif -#endif - -#endif From 0ef34d6354712558dd06e36693bd10009b2ab81d Mon Sep 17 00:00:00 2001 From: Cerapter Date: Tue, 4 Sep 2018 20:20:11 +0200 Subject: [PATCH 114/174] Fixed the zoom and the `hld` pos with double characters. --- courtroom.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/courtroom.cpp b/courtroom.cpp index 64afd4d..844de29 100644 --- a/courtroom.cpp +++ b/courtroom.cpp @@ -1384,7 +1384,6 @@ void Courtroom::handle_chatmessage_2() else { // In every other case, the person more to the left is on top. - // With one exception, hlp. // 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); @@ -1395,7 +1394,8 @@ void Courtroom::handle_chatmessage_2() // 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) + if (((hor2_offset >= hor_offset) && !(side == "hld")) || + ((hor2_offset <= hor_offset) && (side == "hld"))) { ui_vp_sideplayer_char->raise(); ui_vp_player_char->raise(); @@ -1465,7 +1465,10 @@ void Courtroom::handle_chatmessage_3() { ui_vp_desk->hide(); ui_vp_legacy_desk->hide(); - ui_vp_sideplayer_char->hide(); // Hide the second character if we're zooming! + + // 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" || From ecade0dc13465059c93932fe863aa1e3f1f7e16c Mon Sep 17 00:00:00 2001 From: Cerapter Date: Tue, 4 Sep 2018 20:36:11 +0200 Subject: [PATCH 115/174] Removed the specific check on `hld` in pairs. Perhaps a better solution may present itself later. --- courtroom.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/courtroom.cpp b/courtroom.cpp index 844de29..7fa25df 100644 --- a/courtroom.cpp +++ b/courtroom.cpp @@ -1394,8 +1394,7 @@ void Courtroom::handle_chatmessage_2() // 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) && !(side == "hld")) || - ((hor2_offset <= hor_offset) && (side == "hld"))) + if (hor2_offset >= hor_offset) { ui_vp_sideplayer_char->raise(); ui_vp_player_char->raise(); From 1124d6b073546bacd58bce640bbcc08db4f8b341 Mon Sep 17 00:00:00 2001 From: Cerapter Date: Tue, 4 Sep 2018 20:39:08 +0200 Subject: [PATCH 116/174] `QMediaPlayer` instead of `QSoundEffect` for SFX and blips. Maybe temporary. --- aoblipplayer.cpp | 7 ++++--- aoblipplayer.h | 4 ++-- aosfxplayer.cpp | 6 +++--- aosfxplayer.h | 4 ++-- 4 files changed, 11 insertions(+), 10 deletions(-) diff --git a/aoblipplayer.cpp b/aoblipplayer.cpp index 5e3929e..c58e2cc 100644 --- a/aoblipplayer.cpp +++ b/aoblipplayer.cpp @@ -2,9 +2,9 @@ AOBlipPlayer::AOBlipPlayer(QWidget *parent, AOApplication *p_ao_app) { - m_sfxplayer = new QSoundEffect; m_parent = parent; ao_app = p_ao_app; + m_sfxplayer = new QMediaPlayer(m_parent, QMediaPlayer::Flag::LowLatency); } AOBlipPlayer::~AOBlipPlayer() @@ -17,17 +17,18 @@ 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)); + m_sfxplayer->setMedia(QUrl::fromLocalFile(f_path)); set_volume(m_volume); } void AOBlipPlayer::blip_tick() { + //m_sfxplayer->stop(); m_sfxplayer->play(); } void AOBlipPlayer::set_volume(int p_value) { m_volume = p_value; - m_sfxplayer->setVolume(p_value / 100.0); + m_sfxplayer->setVolume(p_value); } diff --git a/aoblipplayer.h b/aoblipplayer.h index c8a8cb6..b460196 100644 --- a/aoblipplayer.h +++ b/aoblipplayer.h @@ -6,7 +6,7 @@ #include #include #include -#include +#include class AOBlipPlayer { @@ -23,7 +23,7 @@ public: private: QWidget *m_parent; AOApplication *ao_app; - QSoundEffect *m_sfxplayer; + QMediaPlayer *m_sfxplayer; int m_volume; }; diff --git a/aosfxplayer.cpp b/aosfxplayer.cpp index 972cd74..9089aec 100644 --- a/aosfxplayer.cpp +++ b/aosfxplayer.cpp @@ -4,7 +4,7 @@ AOSfxPlayer::AOSfxPlayer(QWidget *parent, AOApplication *p_ao_app) { m_parent = parent; ao_app = p_ao_app; - m_sfxplayer = new QSoundEffect(); + m_sfxplayer = new QMediaPlayer(m_parent, QMediaPlayer::Flag::LowLatency); } AOSfxPlayer::~AOSfxPlayer() @@ -26,7 +26,7 @@ void AOSfxPlayer::play(QString p_sfx, QString p_char) else f_path = ao_app->get_sounds_path() + p_sfx; - m_sfxplayer->setSource(QUrl::fromLocalFile(f_path)); + m_sfxplayer->setMedia(QUrl::fromLocalFile(f_path)); set_volume(m_volume); m_sfxplayer->play(); @@ -40,5 +40,5 @@ void AOSfxPlayer::stop() void AOSfxPlayer::set_volume(int p_value) { m_volume = p_value; - m_sfxplayer->setVolume(p_value / 100.0); + m_sfxplayer->setVolume(p_value); } diff --git a/aosfxplayer.h b/aosfxplayer.h index 1b73e49..ab9fd97 100644 --- a/aosfxplayer.h +++ b/aosfxplayer.h @@ -6,7 +6,7 @@ #include #include #include -#include +#include class AOSfxPlayer { @@ -21,7 +21,7 @@ public: private: QWidget *m_parent; AOApplication *ao_app; - QSoundEffect *m_sfxplayer; + QMediaPlayer *m_sfxplayer; int m_volume = 0; }; From 4f30afa51d84be5ea16911b7e4fbd545a87e24b3 Mon Sep 17 00:00:00 2001 From: Cerapter Date: Tue, 4 Sep 2018 21:19:10 +0200 Subject: [PATCH 117/174] The server now announces what features it has. I'm not sure why I did this. --- aoapplication.h | 4 ++ courtroom.cpp | 90 +++++++++++++++++++++++++++++------------ packet_distribution.cpp | 12 ++++++ server/aoprotocol.py | 2 +- 4 files changed, 81 insertions(+), 27 deletions(-) diff --git a/aoapplication.h b/aoapplication.h index f1e25eb..8340323 100644 --- a/aoapplication.h +++ b/aoapplication.h @@ -69,6 +69,10 @@ public: bool improved_loading_enabled = false; bool desk_mod_enabled = false; bool evidence_enabled = false; + bool shownames_enabled = false; + bool charpairs_enabled = false; + bool arup_enabled = false; + bool modcall_reason_enabled = false; ///////////////loading info/////////////////// diff --git a/courtroom.cpp b/courtroom.cpp index 7fa25df..c4d9074 100644 --- a/courtroom.cpp +++ b/courtroom.cpp @@ -437,6 +437,16 @@ void Courtroom::set_widgets() ui_pair_offset_spinbox->hide(); set_size_and_pos(ui_pair_button, "pair_button"); ui_pair_button->set_image("pair_button.png"); + if (ao_app->charpairs_enabled) + { + ui_pair_button->setEnabled(true); + ui_pair_button->show(); + } + else + { + ui_pair_button->setEnabled(false); + ui_pair_button->hide(); + } set_size_and_pos(ui_area_list, "music_list"); ui_area_list->setStyleSheet("background-color: rgba(0, 0, 0, 0);"); @@ -833,7 +843,16 @@ void Courtroom::enter_courtroom(int p_cid) //ui_server_chatlog->setHtml(ui_server_chatlog->toHtml()); ui_char_select_background->hide(); - ui_ic_chat_name->setPlaceholderText(ao_app->get_showname(f_char)); + if (ao_app->shownames_enabled) + { + ui_ic_chat_name->setPlaceholderText(ao_app->get_showname(f_char)); + ui_ic_chat_name->setEnabled(true); + } + else + { + ui_ic_chat_name->setPlaceholderText("---"); + ui_ic_chat_name->setEnabled(false); + } ui_ic_chat_message->setEnabled(m_cid != -1); ui_ic_chat_message->setFocus(); @@ -894,44 +913,56 @@ void Courtroom::list_areas() for (int n_area = 0 ; n_area < area_list.size() ; ++n_area) { QString i_area = area_list.at(n_area); - i_area.append("\n "); - i_area.append(arup_statuses.at(n_area)); - i_area.append(" | CM: "); - i_area.append(arup_cms.at(n_area)); + if (ao_app->arup_enabled) + { + i_area.append("\n "); - 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(QString::number(arup_players.at(n_area))); - i_area.append(" users | "); - if (arup_locks.at(n_area) == true) - i_area.append("LOCKED"); - else - i_area.append("OPEN"); + i_area.append("\n "); + + i_area.append(QString::number(arup_players.at(n_area))); + i_area.append(" users | "); + + if (arup_locks.at(n_area) == true) + i_area.append("LOCKED"); + else + i_area.append("OPEN"); + } if (i_area.toLower().contains(ui_music_search->text().toLower())) { ui_area_list->addItem(i_area); area_row_to_number.append(n_area); - // Colouring logic here. - ui_area_list->item(n_listed_areas)->setBackground(free_brush); - if (arup_locks.at(n_area)) + if (ao_app->arup_enabled) { - ui_area_list->item(n_listed_areas)->setBackground(locked_brush); + // Colouring logic here. + ui_area_list->item(n_listed_areas)->setBackground(free_brush); + if (arup_locks.at(n_area)) + { + 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 { - 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); + ui_area_list->item(n_listed_areas)->setBackground(free_brush); } ++n_listed_areas; @@ -3070,6 +3101,13 @@ void Courtroom::on_spectator_clicked() void Courtroom::on_call_mod_clicked() { + 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, diff --git a/packet_distribution.cpp b/packet_distribution.cpp index 9de0dfe..8a515e0 100644 --- a/packet_distribution.cpp +++ b/packet_distribution.cpp @@ -147,6 +147,10 @@ void AOApplication::server_packet_received(AOPacket *p_packet) improved_loading_enabled = false; desk_mod_enabled = false; evidence_enabled = false; + shownames_enabled = false; + charpairs_enabled = false; + arup_enabled = false; + modcall_reason_enabled = false; //workaround for tsuserver4 if (f_contents.at(0) == "NOENCRYPT") @@ -192,6 +196,14 @@ 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("cc_customshownames",Qt::CaseInsensitive)) + shownames_enabled = true; + if (f_packet.contains("characterpairs",Qt::CaseInsensitive)) + charpairs_enabled = true; + if (f_packet.contains("arup",Qt::CaseInsensitive)) + arup_enabled = true; + if (f_packet.contains("modcall_reason",Qt::CaseInsensitive)) + modcall_reason_enabled = true; } else if (header == "PN") { diff --git a/server/aoprotocol.py b/server/aoprotocol.py index e9131a5..21b0daa 100644 --- a/server/aoprotocol.py +++ b/server/aoprotocol.py @@ -213,7 +213,7 @@ class AOProtocol(asyncio.Protocol): self.client.is_ao2 = True - self.client.send_command('FL', 'yellowtext', 'customobjections', 'flipping', 'fastloading', 'noencryption', 'deskmod', 'evidence') + self.client.send_command('FL', 'yellowtext', 'customobjections', 'flipping', 'fastloading', 'noencryption', 'deskmod', 'evidence', 'modcall_reason', 'cc_customshownames', 'characterpairs', 'arup') def net_cmd_ch(self, _): """ Periodically checks the connection. From d0a6e081de9df220a1575bcd81056a04d79e9b42 Mon Sep 17 00:00:00 2001 From: Cerapter Date: Tue, 4 Sep 2018 21:57:20 +0200 Subject: [PATCH 118/174] Blankpost filter is now more agressive + check for typing ' /' in OOC. --- server/aoprotocol.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/server/aoprotocol.py b/server/aoprotocol.py index 21b0daa..4e725d0 100644 --- a/server/aoprotocol.py +++ b/server/aoprotocol.py @@ -376,9 +376,16 @@ class AOProtocol(asyncio.Protocol): 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 and text == ' ': - self.client.send_host_message("Blankposting is forbidden in this area!") - 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(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 msg_type not in ('chat', '0', '1'): return if anim_type not in (0, 1, 2, 5, 6): @@ -501,6 +508,9 @@ class AOProtocol(asyncio.Protocol): 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() From adfe21afd6e5f4efc9c60b45590f4c086b9e0e52 Mon Sep 17 00:00:00 2001 From: Cerapter Date: Tue, 4 Sep 2018 22:45:07 +0200 Subject: [PATCH 119/174] Added `jur` and `sea` positions. --- courtroom.cpp | 14 +++++++++++++- server/aoprotocol.py | 2 +- server/client_manager.py | 4 ++-- server/evidence.py | 11 ++++++++++- 4 files changed, 26 insertions(+), 5 deletions(-) diff --git a/courtroom.cpp b/courtroom.cpp index c4d9074..6df5f9f 100644 --- a/courtroom.cpp +++ b/courtroom.cpp @@ -137,6 +137,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); @@ -1482,7 +1484,7 @@ 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()); } @@ -2321,6 +2323,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) diff --git a/server/aoprotocol.py b/server/aoprotocol.py index 4e725d0..d7a2c6c 100644 --- a/server/aoprotocol.py +++ b/server/aoprotocol.py @@ -427,7 +427,7 @@ class AOProtocol(asyncio.Protocol): if self.client.pos: pos = self.client.pos else: - if pos not in ('def', 'pro', 'hld', 'hlp', 'jud', 'wit'): + if pos not in ('def', 'pro', 'hld', 'hlp', 'jud', 'wit', 'jur', 'sea'): return msg = text[:256] if self.client.shaken: diff --git a/server/client_manager.py b/server/client_manager.py index 2310298..5e6825b 100644 --- a/server/client_manager.py +++ b/server/client_manager.py @@ -345,8 +345,8 @@ class ClientManager: return self.server.char_list[self.char_id] def change_position(self, pos=''): - if pos not in ('', 'def', 'pro', 'hld', 'hlp', 'jud', 'wit'): - raise ClientError('Invalid position. Possible values: def, pro, hld, hlp, jud, wit.') + 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): diff --git a/server/evidence.py b/server/evidence.py index ddd9ba3..efa2e25 100644 --- a/server/evidence.py +++ b/server/evidence.py @@ -24,7 +24,16 @@ class EvidenceList: def __init__(self): self.evidences = [] - self.poses = {'def':['def', 'hld'], 'pro':['pro', 'hlp'], 'wit':['wit'], 'hlp':['hlp', 'pro'], 'hld':['hld', 'def'], 'jud':['jud'], 'all':['hlp', 'hld', 'wit', 'jud', 'pro', 'def', ''], 'pos':[]} + 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': From 12727fcf7f0684f916290113da4a76c331fadce9 Mon Sep 17 00:00:00 2001 From: Cerapter Date: Wed, 5 Sep 2018 02:07:23 +0200 Subject: [PATCH 120/174] `misc` folder given purpose as the 'default' for shouts and chatboxes. - Default bubbles. - Default shout sounds. - Custom chatbox. - Custom colours for the chatbox. - No need to have duplicate files of bubbles and shouts all over the character folders. --- aoapplication.h | 3 +++ aomovie.cpp | 5 ++++- aosfxplayer.cpp | 20 ++++++++++++++++---- aosfxplayer.h | 2 +- courtroom.cpp | 41 ++++++++++++++++++++++++++++++++++------- text_file_functions.cpp | 28 ++++++++++++++++++++++++++++ 6 files changed, 86 insertions(+), 13 deletions(-) diff --git a/aoapplication.h b/aoapplication.h index 8340323..fc81d13 100644 --- a/aoapplication.h +++ b/aoapplication.h @@ -205,6 +205,9 @@ 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); 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/aosfxplayer.cpp b/aosfxplayer.cpp index 9089aec..c8e1593 100644 --- a/aosfxplayer.cpp +++ b/aosfxplayer.cpp @@ -1,4 +1,5 @@ #include "aosfxplayer.h" +#include "file_functions.h" AOSfxPlayer::AOSfxPlayer(QWidget *parent, AOApplication *p_ao_app) { @@ -14,17 +15,28 @@ AOSfxPlayer::~AOSfxPlayer() } -void AOSfxPlayer::play(QString p_sfx, QString p_char) +void AOSfxPlayer::play(QString p_sfx, QString p_char, QString shout) { m_sfxplayer->stop(); p_sfx = p_sfx.toLower(); + 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 (p_char != "") - f_path = ao_app->get_character_path(p_char) + p_sfx; + if (file_exists(char_path)) + f_path = char_path; + else if (file_exists(misc_path)) + f_path = misc_path; else - f_path = ao_app->get_sounds_path() + p_sfx; + f_path = sound_path; m_sfxplayer->setMedia(QUrl::fromLocalFile(f_path)); set_volume(m_volume); diff --git a/aosfxplayer.h b/aosfxplayer.h index ab9fd97..4494b3e 100644 --- a/aosfxplayer.h +++ b/aosfxplayer.h @@ -14,7 +14,7 @@ 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); diff --git a/courtroom.cpp b/courtroom.cpp index 6df5f9f..bf3d2d2 100644 --- a/courtroom.cpp +++ b/courtroom.cpp @@ -1228,20 +1228,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!"; @@ -1288,7 +1288,7 @@ 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); } @@ -2377,7 +2377,23 @@ void Courtroom::set_scene() void Courtroom::set_text_color() { - switch (m_chatmessage[TEXT_COLOR].toInt()) + 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); + + /*switch (m_chatmessage[TEXT_COLOR].toInt()) { case GREEN: ui_vp_message->setStyleSheet("background-color: rgba(0, 0, 0, 0);" @@ -2414,7 +2430,7 @@ void Courtroom::set_text_color() ui_vp_message->setStyleSheet("background-color: rgba(0, 0, 0, 0);" "color: white"); - } + }*/ } void Courtroom::set_ip_list(QString p_list) @@ -2629,8 +2645,19 @@ void Courtroom::on_ooc_return_pressed() else if (ooc_message.startsWith("/switch_am")) { on_switch_area_music_clicked(); + ui_ooc_chat_message->clear(); return; } + else if (ooc_message.startsWith("/enable_blocks")) + { + ao_app->shownames_enabled = true; + ao_app->charpairs_enabled = true; + ao_app->arup_enabled = true; + ao_app->modcall_reason_enabled = true; + on_reload_theme_clicked(); + ui_ooc_chat_message->clear(); + return; + } QStringList packet_contents; packet_contents.append(ui_ooc_chat_name->text()); diff --git a/text_file_functions.cpp b/text_file_functions.cpp index b3f2a2d..35d2788 100644 --- a/text_file_functions.cpp +++ b/text_file_functions.cpp @@ -257,6 +257,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"; From 78c339869d64295da3d6aef5577a16f7fdc49b78 Mon Sep 17 00:00:00 2001 From: Cerapter Date: Wed, 5 Sep 2018 02:25:04 +0200 Subject: [PATCH 121/174] Inline text now also obey `misc` rules. --- courtroom.cpp | 68 +++++++++++++-------------------------------------- courtroom.h | 3 +++ 2 files changed, 20 insertions(+), 51 deletions(-) diff --git a/courtroom.cpp b/courtroom.cpp index bf3d2d2..435dcd3 100644 --- a/courtroom.cpp +++ b/courtroom.cpp @@ -2010,19 +2010,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; } @@ -2076,7 +2076,7 @@ void Courtroom::chat_tick() else if (f_character == "(" and !next_character_is_not_special) { inline_colour_stack.push(INLINE_BLUE); - ui_vp_message->insertHtml("" + f_character + ""); + ui_vp_message->insertHtml("" + f_character + ""); // Increase how deep we are in inline blues. inline_blue_depth++; @@ -2096,7 +2096,7 @@ void Courtroom::chat_tick() if (inline_colour_stack.top() == INLINE_BLUE) { inline_colour_stack.pop(); - ui_vp_message->insertHtml("" + f_character + ""); + 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. @@ -2127,7 +2127,7 @@ void Courtroom::chat_tick() else if (f_character == "[" and !next_character_is_not_special) { inline_colour_stack.push(INLINE_GREY); - ui_vp_message->insertHtml("" + f_character + ""); + ui_vp_message->insertHtml("" + f_character + ""); } else if (f_character == "]" and !next_character_is_not_special and !inline_colour_stack.empty()) @@ -2135,7 +2135,7 @@ void Courtroom::chat_tick() if (inline_colour_stack.top() == INLINE_GREY) { inline_colour_stack.pop(); - ui_vp_message->insertHtml("" + f_character + ""); + ui_vp_message->insertHtml("" + f_character + ""); } else { @@ -2174,16 +2174,16 @@ void Courtroom::chat_tick() { switch (inline_colour_stack.top()) { case INLINE_ORANGE: - ui_vp_message->insertHtml("" + f_character + ""); + ui_vp_message->insertHtml("" + f_character + ""); break; case INLINE_BLUE: - ui_vp_message->insertHtml("" + f_character + ""); + ui_vp_message->insertHtml("" + f_character + ""); break; case INLINE_GREEN: - ui_vp_message->insertHtml("" + f_character + ""); + ui_vp_message->insertHtml("" + f_character + ""); break; case INLINE_GREY: - ui_vp_message->insertHtml("" + f_character + ""); + ui_vp_message->insertHtml("" + f_character + ""); break; default: ui_vp_message->insertHtml(f_character); @@ -2392,45 +2392,11 @@ void Courtroom::set_text_color() style.append(")"); ui_vp_message->setStyleSheet(style); +} - /*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; - case PINK: - ui_vp_message->setStyleSheet("background-color: rgba(0, 0, 0, 0);" - "color: pink"); - break; - case CYAN: - ui_vp_message->setStyleSheet("background-color: rgba(0, 0, 0, 0);" - "color: cyan"); - break; - default: - qDebug() << "W: undefined text color: " << m_chatmessage[TEXT_COLOR]; - // fall through - case WHITE: - ui_vp_message->setStyleSheet("background-color: rgba(0, 0, 0, 0);" - "color: white"); - - }*/ +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) diff --git a/courtroom.h b/courtroom.h index 90cf21f..19a19ea 100644 --- a/courtroom.h +++ b/courtroom.h @@ -131,6 +131,9 @@ public: //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); From 93cd2ad3747ff609e0aa2175a2622afe9ef6b56d Mon Sep 17 00:00:00 2001 From: Cerapter Date: Wed, 5 Sep 2018 17:21:27 +0200 Subject: [PATCH 122/174] Non-interrupting pres. --- courtroom.cpp | 132 +++++++++++++++++++++++++++++++++++++---- courtroom.h | 6 +- datatypes.h | 3 +- server/aoprotocol.py | 26 +++++++- server/area_manager.py | 7 ++- 5 files changed, 156 insertions(+), 18 deletions(-) diff --git a/courtroom.cpp b/courtroom.cpp index 435dcd3..dd6c160 100644 --- a/courtroom.cpp +++ b/courtroom.cpp @@ -178,6 +178,9 @@ Courtroom::Courtroom(AOApplication *p_ao_app) : QMainWindow() ui_showname_enable->setChecked(ao_app->get_showname_enabled_by_default()); ui_showname_enable->setText("Custom shownames"); + ui_pre_non_interrupt = new QCheckBox(this); + ui_pre_non_interrupt->setText("No Intrpt"); + ui_custom_objection = new AOButton(this, ao_app); ui_realization = new AOButton(this, ao_app); ui_mute = new AOButton(this, ao_app); @@ -551,6 +554,9 @@ void Courtroom::set_widgets() set_size_and_pos(ui_pre, "pre"); ui_pre->setText("Pre"); + set_size_and_pos(ui_pre_non_interrupt, "pre_no_interrupt"); + ui_pre_non_interrupt->setText("No Intrpt"); + set_size_and_pos(ui_flip, "flip"); set_size_and_pos(ui_guard, "guard"); @@ -1012,7 +1018,8 @@ void Courtroom::on_chat_return_pressed() //showname# //other_charid# - //self_offset#% + //self_offset# + //noninterrupting_preanim#% QStringList packet_contents; @@ -1051,7 +1058,7 @@ void Courtroom::on_chat_return_pressed() 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; @@ -1134,6 +1141,22 @@ void Courtroom::on_chat_return_pressed() packet_contents.append(QString::number(offset_with_pair)); } + if (ui_pre_non_interrupt->isChecked() and ui_pre->isChecked()) + { + if (ui_ic_chat_name->text().isEmpty()) + { + packet_contents.append(""); + } + + if (!(other_charid > -1 && other_charid != m_cid)) + { + packet_contents.append("-1"); + packet_contents.append("0"); + } + + packet_contents.append("1"); + } + ao_app->send_server_packet(new AOPacket("MS", packet_contents)); } @@ -1468,7 +1491,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].isEmpty()) + handle_chatmessage_3(); + else + play_noninterrupting_preanim(); } } @@ -1915,8 +1941,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(); } @@ -1927,13 +1990,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 @@ -1992,8 +2056,11 @@ void Courtroom::chat_tick() if (tick_pos >= f_message.size()) { text_state = 2; - 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 @@ -2083,7 +2150,7 @@ void Courtroom::chat_tick() // Here, we check if the entire message is blue. // If it isn't, we stop talking. - if (!entire_message_is_blue) + if (!entire_message_is_blue and anim_state != 4) { QString f_char = m_chatmessage[CHAR_NAME]; QString f_emote = m_chatmessage[EMOTE]; @@ -2107,7 +2174,7 @@ void Courtroom::chat_tick() // If it isn't, we start talking if we have completely climbed out of inline blues. if (!entire_message_is_blue) { - if (inline_blue_depth == 0) + if (inline_blue_depth == 0 and anim_state != 4) { QString f_char = m_chatmessage[CHAR_NAME]; QString f_emote = m_chatmessage[EMOTE]; @@ -2566,18 +2633,23 @@ 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."); + } else if (ooc_message.startsWith("/rainbow") && ao_app->yellow_text_enabled && !rainbow_appended) { //ui_text_color->addItem("Rainbow"); ui_ooc_chat_message->clear(); //rainbow_appended = true; + append_server_chatmessage("CLIENT", "This does nohing, but there you go."); 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."); return; } else if (ooc_message.startsWith("/pair")) @@ -2590,7 +2662,21 @@ void Courtroom::on_ooc_return_pressed() 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); + } + else + { + append_server_chatmessage("CLIENT", "You are no longer paired with anyone."); + } + } + else + { + append_server_chatmessage("CLIENT", "Are you sure you typed that well? The char ID could not be recognised."); } return; } @@ -2604,18 +2690,34 @@ void Courtroom::on_ooc_return_pressed() 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); + } + else + { + append_server_chatmessage("CLIENT", "Your offset must be between -100% and 100%!"); + } + } + else + { + append_server_chatmessage("CLIENT", "That offset does not look like one."); } return; } else if (ooc_message.startsWith("/switch_am")) { + append_server_chatmessage("CLIENT", "You switched your music and area list."); 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."); ao_app->shownames_enabled = true; ao_app->charpairs_enabled = true; ao_app->arup_enabled = true; @@ -2624,6 +2726,16 @@ void Courtroom::on_ooc_return_pressed() 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."); + else + append_server_chatmessage("CLIENT", "Your pre-animations will not interrupt text."); + ui_pre_non_interrupt->setChecked(!ui_pre_non_interrupt->isChecked()); + ui_ooc_chat_message->clear(); + return; + } QStringList packet_contents; packet_contents.append(ui_ooc_chat_name->text()); diff --git a/courtroom.h b/courtroom.h index 19a19ea..d15dde0 100644 --- a/courtroom.h +++ b/courtroom.h @@ -184,6 +184,7 @@ public: 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, int variant); @@ -298,7 +299,7 @@ private: //every time point in char.inis times this equals the final time const int time_mod = 40; - static const int chatmessage_size = 22; + static const int chatmessage_size = 23; QString m_chatmessage[chatmessage_size]; bool chatmessage_is_empty = false; @@ -319,7 +320,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 @@ -451,6 +452,7 @@ private: QCheckBox *ui_flip; QCheckBox *ui_guard; + QCheckBox *ui_pre_non_interrupt; QCheckBox *ui_showname_enable; AOButton *ui_custom_objection; diff --git a/datatypes.h b/datatypes.h index 63ad836..aaa5de5 100644 --- a/datatypes.h +++ b/datatypes.h @@ -99,7 +99,8 @@ enum CHAT_MESSAGE OTHER_EMOTE, SELF_OFFSET, OTHER_OFFSET, - OTHER_FLIP + OTHER_FLIP, + NONINTERRUPTING_PRE }; enum COLOR diff --git a/server/aoprotocol.py b/server/aoprotocol.py index d7a2c6c..d8d91d2 100644 --- a/server/aoprotocol.py +++ b/server/aoprotocol.py @@ -346,6 +346,7 @@ class AOProtocol(asyncio.Protocol): showname = "" charid_pair = -1 offset_pair = 0 + nonint_pre = '' 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, @@ -355,6 +356,7 @@ class AOProtocol(asyncio.Protocol): 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 = '' 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 @@ -363,8 +365,19 @@ class AOProtocol(asyncio.Protocol): 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.4.0 validation monstrosity. + # 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 = '' + 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 @@ -383,7 +396,7 @@ class AOProtocol(asyncio.Protocol): 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(text.replace(' ', '')) < 3 and text != '<' and text != '>': + 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 msg_type not in ('chat', '0', '1'): @@ -405,6 +418,13 @@ class AOProtocol(asyncio.Protocol): if len(showname) > 15: self.client.send_host_message("Your IC showname is way too long!") return + 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: @@ -471,7 +491,7 @@ class AOProtocol(asyncio.Protocol): 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) + 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) diff --git a/server/area_manager.py b/server/area_manager.py index 6e024f6..23c4339 100644 --- a/server/area_manager.py +++ b/server/area_manager.py @@ -26,7 +26,7 @@ from server.evidence import EvidenceList 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 = ''): + 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 = {} @@ -65,6 +65,7 @@ class AreaManager: self.is_locked = False 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 @@ -305,10 +306,12 @@ class AreaManager: 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'])) + 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): From d0503eeb6ee783e571b7369edbdcc6710bee7ee7 Mon Sep 17 00:00:00 2001 From: Cerapter Date: Thu, 6 Sep 2018 20:41:49 +0200 Subject: [PATCH 123/174] `/allow_blankposting` now catches ~~ too + CMs can use redtext now as well. --- server/aoprotocol.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/server/aoprotocol.py b/server/aoprotocol.py index d8d91d2..44b4612 100644 --- a/server/aoprotocol.py +++ b/server/aoprotocol.py @@ -396,7 +396,7 @@ class AOProtocol(asyncio.Protocol): 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 != '>': + 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 msg_type not in ('chat', '0', '1'): @@ -435,7 +435,7 @@ class AOProtocol(asyncio.Protocol): button = 0 # Turn off the ding. ding = 0 - if color == 2 and not self.client.is_mod: + if color == 2 and not (self.client.is_mod or self.client.is_cm): color = 0 if color == 6: text = re.sub(r'[^\x00-\x7F]+',' ', text) #remove all unicode to prevent redtext abuse From a08b254077288232058af09de9bac86f6a6865de Mon Sep 17 00:00:00 2001 From: Cerapter Date: Thu, 6 Sep 2018 22:29:23 +0200 Subject: [PATCH 124/174] Added the ability for mods and CMs to force non-interrupting pres in areas. --- server/commands.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/server/commands.py b/server/commands.py index 6f2beb0..125ca80 100644 --- a/server/commands.py +++ b/server/commands.py @@ -100,6 +100,17 @@ def ooc_cmd_allow_blankposting(client, arg): client.area.send_host_message('A mod has set blankposting in the area to {}.'.format(answer[client.area.blankposting_allowed])) return +def ooc_cmd_force_nonint_pres(client, arg): + if not client.is_mod and not client.is_cm: + 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'} + if client.is_cm: + client.area.send_host_message('The CM has set pres in the area to be {}.'.format(answer[client.area.non_int_pres_only])) + else: + client.area.send_host_message('A mod has set pres in the area to be {}.'.format(answer[client.area.non_int_pres_only])) + return + def ooc_cmd_roll(client, arg): roll_max = 11037 if len(arg) != 0: From b33d0b0a3c9311fc43d5d00d56d7b6c8d706adcd Mon Sep 17 00:00:00 2001 From: Cerapter Date: Fri, 7 Sep 2018 10:02:35 +0200 Subject: [PATCH 125/174] Lowered the prosecutor / defence characters, so they don't float above some desks. --- courtroom.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/courtroom.cpp b/courtroom.cpp index dd6c160..7c6b7fb 100644 --- a/courtroom.cpp +++ b/courtroom.cpp @@ -1374,7 +1374,7 @@ void Courtroom::handle_chatmessage_2() int vert_offset = 0; if (hor_offset > 0) { - vert_offset = hor_offset / 20; + vert_offset = hor_offset / 10; } ui_vp_player_char->move(ui_viewport->width() * hor_offset / 100, ui_viewport->height() * vert_offset / 100); @@ -1383,7 +1383,7 @@ void Courtroom::handle_chatmessage_2() int vert2_offset = 0; if (hor2_offset > 0) { - vert2_offset = hor2_offset / 20; + vert2_offset = hor2_offset / 10; } ui_vp_sideplayer_char->move(ui_viewport->width() * hor2_offset / 100, ui_viewport->height() * vert2_offset / 100); @@ -1410,7 +1410,7 @@ void Courtroom::handle_chatmessage_2() if (hor_offset < 0) { // We don't want to RAISE the char off the floor. - vert_offset = -1 * hor_offset / 20; + vert_offset = -1 * hor_offset / 10; } ui_vp_player_char->move(ui_viewport->width() * hor_offset / 100, ui_viewport->height() * vert_offset / 100); @@ -1419,7 +1419,7 @@ void Courtroom::handle_chatmessage_2() int vert2_offset = 0; if (hor2_offset < 0) { - vert2_offset = -1 * hor2_offset / 20; + vert2_offset = -1 * hor2_offset / 10; } ui_vp_sideplayer_char->move(ui_viewport->width() * hor2_offset / 100, ui_viewport->height() * vert2_offset / 100); From 8006d40d1495a848b07a59bf514100648c82459c Mon Sep 17 00:00:00 2001 From: Cerapter Date: Sat, 15 Sep 2018 01:16:28 +0200 Subject: [PATCH 126/174] Fixed bugs regarding noninterrupting pres. - They are now actually non-interrupting when an interjection is played. - Realisation now happens at the start of the message if the pre is non-interrupting. --- courtroom.cpp | 16 ++++++++-------- server/aoprotocol.py | 6 ++++++ 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/courtroom.cpp b/courtroom.cpp index 7c6b7fb..5eb2c56 100644 --- a/courtroom.cpp +++ b/courtroom.cpp @@ -1141,7 +1141,7 @@ void Courtroom::on_chat_return_pressed() packet_contents.append(QString::number(offset_with_pair)); } - if (ui_pre_non_interrupt->isChecked() and ui_pre->isChecked()) + if (ui_pre_non_interrupt->isChecked()) { if (ui_ic_chat_name->text().isEmpty()) { @@ -1502,6 +1502,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_sfx("realization")); + } + int f_evi_id = m_chatmessage[EVIDENCE_ID].toInt(); QString f_side = m_chatmessage[SIDE]; @@ -1575,13 +1582,6 @@ void Courtroom::handle_chatmessage_3() 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(); diff --git a/server/aoprotocol.py b/server/aoprotocol.py index 44b4612..4712656 100644 --- a/server/aoprotocol.py +++ b/server/aoprotocol.py @@ -418,6 +418,12 @@ class AOProtocol(asyncio.Protocol): if len(showname) > 15: self.client.send_host_message("Your IC showname is way too long!") return + if nonint_pre != '': + 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 From 3a1d202363df5a6d5c5e2148736ec0308aed5d7e Mon Sep 17 00:00:00 2001 From: Cerapter Date: Sat, 15 Sep 2018 01:37:11 +0200 Subject: [PATCH 127/174] Revert "`QMediaPlayer` instead of `QSoundEffect` for SFX and blips." This reverts commit 1124d6b073546bacd58bce640bbcc08db4f8b341. --- aoblipplayer.cpp | 7 +++---- aoblipplayer.h | 4 ++-- aosfxplayer.cpp | 6 +++--- aosfxplayer.h | 4 ++-- 4 files changed, 10 insertions(+), 11 deletions(-) diff --git a/aoblipplayer.cpp b/aoblipplayer.cpp index c58e2cc..5e3929e 100644 --- a/aoblipplayer.cpp +++ b/aoblipplayer.cpp @@ -2,9 +2,9 @@ AOBlipPlayer::AOBlipPlayer(QWidget *parent, AOApplication *p_ao_app) { + m_sfxplayer = new QSoundEffect; m_parent = parent; ao_app = p_ao_app; - m_sfxplayer = new QMediaPlayer(m_parent, QMediaPlayer::Flag::LowLatency); } AOBlipPlayer::~AOBlipPlayer() @@ -17,18 +17,17 @@ void AOBlipPlayer::set_blips(QString p_sfx) { m_sfxplayer->stop(); QString f_path = ao_app->get_sounds_path() + p_sfx.toLower(); - m_sfxplayer->setMedia(QUrl::fromLocalFile(f_path)); + m_sfxplayer->setSource(QUrl::fromLocalFile(f_path)); set_volume(m_volume); } void AOBlipPlayer::blip_tick() { - //m_sfxplayer->stop(); m_sfxplayer->play(); } void AOBlipPlayer::set_volume(int p_value) { m_volume = p_value; - m_sfxplayer->setVolume(p_value); + m_sfxplayer->setVolume(p_value / 100.0); } diff --git a/aoblipplayer.h b/aoblipplayer.h index b460196..c8a8cb6 100644 --- a/aoblipplayer.h +++ b/aoblipplayer.h @@ -6,7 +6,7 @@ #include #include #include -#include +#include class AOBlipPlayer { @@ -23,7 +23,7 @@ public: private: QWidget *m_parent; AOApplication *ao_app; - QMediaPlayer *m_sfxplayer; + QSoundEffect *m_sfxplayer; int m_volume; }; diff --git a/aosfxplayer.cpp b/aosfxplayer.cpp index c8e1593..69c1171 100644 --- a/aosfxplayer.cpp +++ b/aosfxplayer.cpp @@ -5,7 +5,7 @@ AOSfxPlayer::AOSfxPlayer(QWidget *parent, AOApplication *p_ao_app) { m_parent = parent; ao_app = p_ao_app; - m_sfxplayer = new QMediaPlayer(m_parent, QMediaPlayer::Flag::LowLatency); + m_sfxplayer = new QSoundEffect(); } AOSfxPlayer::~AOSfxPlayer() @@ -38,7 +38,7 @@ void AOSfxPlayer::play(QString p_sfx, QString p_char, QString shout) else f_path = sound_path; - m_sfxplayer->setMedia(QUrl::fromLocalFile(f_path)); + m_sfxplayer->setSource(QUrl::fromLocalFile(f_path)); set_volume(m_volume); m_sfxplayer->play(); @@ -52,5 +52,5 @@ void AOSfxPlayer::stop() void AOSfxPlayer::set_volume(int p_value) { m_volume = p_value; - m_sfxplayer->setVolume(p_value); + m_sfxplayer->setVolume(p_value / 100.0); } diff --git a/aosfxplayer.h b/aosfxplayer.h index 4494b3e..ab398e0 100644 --- a/aosfxplayer.h +++ b/aosfxplayer.h @@ -6,7 +6,7 @@ #include #include #include -#include +#include class AOSfxPlayer { @@ -21,7 +21,7 @@ public: private: QWidget *m_parent; AOApplication *ao_app; - QMediaPlayer *m_sfxplayer; + QSoundEffect *m_sfxplayer; int m_volume = 0; }; From 6fad08521abc86fac81d023c6ae871f2fdddc031 Mon Sep 17 00:00:00 2001 From: Cerapter Date: Sat, 15 Sep 2018 01:39:27 +0200 Subject: [PATCH 128/174] Revert "I should probably remove bass for real." This reverts commit adb32a0dca1a0d811da01704168421538aedbfc2. --- aooptionsdialog.cpp | 1 + bass.h | 1051 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 1052 insertions(+) create mode 100644 bass.h diff --git a/aooptionsdialog.cpp b/aooptionsdialog.cpp index 31303da..e79c6f6 100644 --- a/aooptionsdialog.cpp +++ b/aooptionsdialog.cpp @@ -1,5 +1,6 @@ #include "aooptionsdialog.h" #include "aoapplication.h" +#include "bass.h" AOOptionsDialog::AOOptionsDialog(QWidget *parent, AOApplication *p_ao_app) : QDialog(parent) { diff --git a/bass.h b/bass.h new file mode 100644 index 0000000..06195de --- /dev/null +++ b/bass.h @@ -0,0 +1,1051 @@ +/* + BASS 2.4 C/C++ header file + Copyright (c) 1999-2016 Un4seen Developments Ltd. + + See the BASS.CHM file for more detailed documentation +*/ + +#ifndef BASS_H +#define BASS_H + +#ifdef _WIN32 +#include +typedef unsigned __int64 QWORD; +#else +#include +#define WINAPI +#define CALLBACK +typedef uint8_t BYTE; +typedef uint16_t WORD; +typedef uint32_t DWORD; +typedef uint64_t QWORD; +#ifndef __OBJC__ +typedef int BOOL; +#endif +#ifndef TRUE +#define TRUE 1 +#define FALSE 0 +#endif +#define LOBYTE(a) (BYTE)(a) +#define HIBYTE(a) (BYTE)((a)>>8) +#define LOWORD(a) (WORD)(a) +#define HIWORD(a) (WORD)((a)>>16) +#define MAKEWORD(a,b) (WORD)(((a)&0xff)|((b)<<8)) +#define MAKELONG(a,b) (DWORD)(((a)&0xffff)|((b)<<16)) +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +#define BASSVERSION 0x204 // API version +#define BASSVERSIONTEXT "2.4" + +#ifndef BASSDEF +#define BASSDEF(f) WINAPI f +#else +#define NOBASSOVERLOADS +#endif + +typedef DWORD HMUSIC; // MOD music handle +typedef DWORD HSAMPLE; // sample handle +typedef DWORD HCHANNEL; // playing sample's channel handle +typedef DWORD HSTREAM; // sample stream handle +typedef DWORD HRECORD; // recording handle +typedef DWORD HSYNC; // synchronizer handle +typedef DWORD HDSP; // DSP handle +typedef DWORD HFX; // DX8 effect handle +typedef DWORD HPLUGIN; // Plugin handle + +// Error codes returned by BASS_ErrorGetCode +#define BASS_OK 0 // all is OK +#define BASS_ERROR_MEM 1 // memory error +#define BASS_ERROR_FILEOPEN 2 // can't open the file +#define BASS_ERROR_DRIVER 3 // can't find a free/valid driver +#define BASS_ERROR_BUFLOST 4 // the sample buffer was lost +#define BASS_ERROR_HANDLE 5 // invalid handle +#define BASS_ERROR_FORMAT 6 // unsupported sample format +#define BASS_ERROR_POSITION 7 // invalid position +#define BASS_ERROR_INIT 8 // BASS_Init has not been successfully called +#define BASS_ERROR_START 9 // BASS_Start has not been successfully called +#define BASS_ERROR_SSL 10 // SSL/HTTPS support isn't available +#define BASS_ERROR_ALREADY 14 // already initialized/paused/whatever +#define BASS_ERROR_NOCHAN 18 // can't get a free channel +#define BASS_ERROR_ILLTYPE 19 // an illegal type was specified +#define BASS_ERROR_ILLPARAM 20 // an illegal parameter was specified +#define BASS_ERROR_NO3D 21 // no 3D support +#define BASS_ERROR_NOEAX 22 // no EAX support +#define BASS_ERROR_DEVICE 23 // illegal device number +#define BASS_ERROR_NOPLAY 24 // not playing +#define BASS_ERROR_FREQ 25 // illegal sample rate +#define BASS_ERROR_NOTFILE 27 // the stream is not a file stream +#define BASS_ERROR_NOHW 29 // no hardware voices available +#define BASS_ERROR_EMPTY 31 // the MOD music has no sequence data +#define BASS_ERROR_NONET 32 // no internet connection could be opened +#define BASS_ERROR_CREATE 33 // couldn't create the file +#define BASS_ERROR_NOFX 34 // effects are not available +#define BASS_ERROR_NOTAVAIL 37 // requested data is not available +#define BASS_ERROR_DECODE 38 // the channel is/isn't a "decoding channel" +#define BASS_ERROR_DX 39 // a sufficient DirectX version is not installed +#define BASS_ERROR_TIMEOUT 40 // connection timedout +#define BASS_ERROR_FILEFORM 41 // unsupported file format +#define BASS_ERROR_SPEAKER 42 // unavailable speaker +#define BASS_ERROR_VERSION 43 // invalid BASS version (used by add-ons) +#define BASS_ERROR_CODEC 44 // codec is not available/supported +#define BASS_ERROR_ENDED 45 // the channel/file has ended +#define BASS_ERROR_BUSY 46 // the device is busy +#define BASS_ERROR_UNKNOWN -1 // some other mystery problem + +// BASS_SetConfig options +#define BASS_CONFIG_BUFFER 0 +#define BASS_CONFIG_UPDATEPERIOD 1 +#define BASS_CONFIG_GVOL_SAMPLE 4 +#define BASS_CONFIG_GVOL_STREAM 5 +#define BASS_CONFIG_GVOL_MUSIC 6 +#define BASS_CONFIG_CURVE_VOL 7 +#define BASS_CONFIG_CURVE_PAN 8 +#define BASS_CONFIG_FLOATDSP 9 +#define BASS_CONFIG_3DALGORITHM 10 +#define BASS_CONFIG_NET_TIMEOUT 11 +#define BASS_CONFIG_NET_BUFFER 12 +#define BASS_CONFIG_PAUSE_NOPLAY 13 +#define BASS_CONFIG_NET_PREBUF 15 +#define BASS_CONFIG_NET_PASSIVE 18 +#define BASS_CONFIG_REC_BUFFER 19 +#define BASS_CONFIG_NET_PLAYLIST 21 +#define BASS_CONFIG_MUSIC_VIRTUAL 22 +#define BASS_CONFIG_VERIFY 23 +#define BASS_CONFIG_UPDATETHREADS 24 +#define BASS_CONFIG_DEV_BUFFER 27 +#define BASS_CONFIG_VISTA_TRUEPOS 30 +#define BASS_CONFIG_IOS_MIXAUDIO 34 +#define BASS_CONFIG_DEV_DEFAULT 36 +#define BASS_CONFIG_NET_READTIMEOUT 37 +#define BASS_CONFIG_VISTA_SPEAKERS 38 +#define BASS_CONFIG_IOS_SPEAKER 39 +#define BASS_CONFIG_MF_DISABLE 40 +#define BASS_CONFIG_HANDLES 41 +#define BASS_CONFIG_UNICODE 42 +#define BASS_CONFIG_SRC 43 +#define BASS_CONFIG_SRC_SAMPLE 44 +#define BASS_CONFIG_ASYNCFILE_BUFFER 45 +#define BASS_CONFIG_OGG_PRESCAN 47 +#define BASS_CONFIG_MF_VIDEO 48 +#define BASS_CONFIG_AIRPLAY 49 +#define BASS_CONFIG_DEV_NONSTOP 50 +#define BASS_CONFIG_IOS_NOCATEGORY 51 +#define BASS_CONFIG_VERIFY_NET 52 +#define BASS_CONFIG_DEV_PERIOD 53 +#define BASS_CONFIG_FLOAT 54 +#define BASS_CONFIG_NET_SEEK 56 + +// BASS_SetConfigPtr options +#define BASS_CONFIG_NET_AGENT 16 +#define BASS_CONFIG_NET_PROXY 17 +#define BASS_CONFIG_IOS_NOTIFY 46 + +// BASS_Init flags +#define BASS_DEVICE_8BITS 1 // 8 bit +#define BASS_DEVICE_MONO 2 // mono +#define BASS_DEVICE_3D 4 // enable 3D functionality +#define BASS_DEVICE_16BITS 8 // limit output to 16 bit +#define BASS_DEVICE_LATENCY 0x100 // calculate device latency (BASS_INFO struct) +#define BASS_DEVICE_CPSPEAKERS 0x400 // detect speakers via Windows control panel +#define BASS_DEVICE_SPEAKERS 0x800 // force enabling of speaker assignment +#define BASS_DEVICE_NOSPEAKER 0x1000 // ignore speaker arrangement +#define BASS_DEVICE_DMIX 0x2000 // use ALSA "dmix" plugin +#define BASS_DEVICE_FREQ 0x4000 // set device sample rate +#define BASS_DEVICE_STEREO 0x8000 // limit output to stereo + +// DirectSound interfaces (for use with BASS_GetDSoundObject) +#define BASS_OBJECT_DS 1 // IDirectSound +#define BASS_OBJECT_DS3DL 2 // IDirectSound3DListener + +// Device info structure +typedef struct { +#if defined(_WIN32_WCE) || (WINAPI_FAMILY && WINAPI_FAMILY!=WINAPI_FAMILY_DESKTOP_APP) + const wchar_t *name; // description + const wchar_t *driver; // driver +#else + const char *name; // description + const char *driver; // driver +#endif + DWORD flags; +} BASS_DEVICEINFO; + +// BASS_DEVICEINFO flags +#define BASS_DEVICE_ENABLED 1 +#define BASS_DEVICE_DEFAULT 2 +#define BASS_DEVICE_INIT 4 + +#define BASS_DEVICE_TYPE_MASK 0xff000000 +#define BASS_DEVICE_TYPE_NETWORK 0x01000000 +#define BASS_DEVICE_TYPE_SPEAKERS 0x02000000 +#define BASS_DEVICE_TYPE_LINE 0x03000000 +#define BASS_DEVICE_TYPE_HEADPHONES 0x04000000 +#define BASS_DEVICE_TYPE_MICROPHONE 0x05000000 +#define BASS_DEVICE_TYPE_HEADSET 0x06000000 +#define BASS_DEVICE_TYPE_HANDSET 0x07000000 +#define BASS_DEVICE_TYPE_DIGITAL 0x08000000 +#define BASS_DEVICE_TYPE_SPDIF 0x09000000 +#define BASS_DEVICE_TYPE_HDMI 0x0a000000 +#define BASS_DEVICE_TYPE_DISPLAYPORT 0x40000000 + +// BASS_GetDeviceInfo flags +#define BASS_DEVICES_AIRPLAY 0x1000000 + +typedef struct { + DWORD flags; // device capabilities (DSCAPS_xxx flags) + DWORD hwsize; // size of total device hardware memory + DWORD hwfree; // size of free device hardware memory + DWORD freesam; // number of free sample slots in the hardware + DWORD free3d; // number of free 3D sample slots in the hardware + DWORD minrate; // min sample rate supported by the hardware + DWORD maxrate; // max sample rate supported by the hardware + BOOL eax; // device supports EAX? (always FALSE if BASS_DEVICE_3D was not used) + DWORD minbuf; // recommended minimum buffer length in ms (requires BASS_DEVICE_LATENCY) + DWORD dsver; // DirectSound version + DWORD latency; // delay (in ms) before start of playback (requires BASS_DEVICE_LATENCY) + DWORD initflags; // BASS_Init "flags" parameter + DWORD speakers; // number of speakers available + DWORD freq; // current output rate +} BASS_INFO; + +// BASS_INFO flags (from DSOUND.H) +#define DSCAPS_CONTINUOUSRATE 0x00000010 // supports all sample rates between min/maxrate +#define DSCAPS_EMULDRIVER 0x00000020 // device does NOT have hardware DirectSound support +#define DSCAPS_CERTIFIED 0x00000040 // device driver has been certified by Microsoft +#define DSCAPS_SECONDARYMONO 0x00000100 // mono +#define DSCAPS_SECONDARYSTEREO 0x00000200 // stereo +#define DSCAPS_SECONDARY8BIT 0x00000400 // 8 bit +#define DSCAPS_SECONDARY16BIT 0x00000800 // 16 bit + +// Recording device info structure +typedef struct { + DWORD flags; // device capabilities (DSCCAPS_xxx flags) + DWORD formats; // supported standard formats (WAVE_FORMAT_xxx flags) + DWORD inputs; // number of inputs + BOOL singlein; // TRUE = only 1 input can be set at a time + DWORD freq; // current input rate +} BASS_RECORDINFO; + +// BASS_RECORDINFO flags (from DSOUND.H) +#define DSCCAPS_EMULDRIVER DSCAPS_EMULDRIVER // device does NOT have hardware DirectSound recording support +#define DSCCAPS_CERTIFIED DSCAPS_CERTIFIED // device driver has been certified by Microsoft + +// defines for formats field of BASS_RECORDINFO (from MMSYSTEM.H) +#ifndef WAVE_FORMAT_1M08 +#define WAVE_FORMAT_1M08 0x00000001 /* 11.025 kHz, Mono, 8-bit */ +#define WAVE_FORMAT_1S08 0x00000002 /* 11.025 kHz, Stereo, 8-bit */ +#define WAVE_FORMAT_1M16 0x00000004 /* 11.025 kHz, Mono, 16-bit */ +#define WAVE_FORMAT_1S16 0x00000008 /* 11.025 kHz, Stereo, 16-bit */ +#define WAVE_FORMAT_2M08 0x00000010 /* 22.05 kHz, Mono, 8-bit */ +#define WAVE_FORMAT_2S08 0x00000020 /* 22.05 kHz, Stereo, 8-bit */ +#define WAVE_FORMAT_2M16 0x00000040 /* 22.05 kHz, Mono, 16-bit */ +#define WAVE_FORMAT_2S16 0x00000080 /* 22.05 kHz, Stereo, 16-bit */ +#define WAVE_FORMAT_4M08 0x00000100 /* 44.1 kHz, Mono, 8-bit */ +#define WAVE_FORMAT_4S08 0x00000200 /* 44.1 kHz, Stereo, 8-bit */ +#define WAVE_FORMAT_4M16 0x00000400 /* 44.1 kHz, Mono, 16-bit */ +#define WAVE_FORMAT_4S16 0x00000800 /* 44.1 kHz, Stereo, 16-bit */ +#endif + +// Sample info structure +typedef struct { + DWORD freq; // default playback rate + float volume; // default volume (0-1) + float pan; // default pan (-1=left, 0=middle, 1=right) + DWORD flags; // BASS_SAMPLE_xxx flags + DWORD length; // length (in bytes) + DWORD max; // maximum simultaneous playbacks + DWORD origres; // original resolution bits + DWORD chans; // number of channels + DWORD mingap; // minimum gap (ms) between creating channels + DWORD mode3d; // BASS_3DMODE_xxx mode + float mindist; // minimum distance + float maxdist; // maximum distance + DWORD iangle; // angle of inside projection cone + DWORD oangle; // angle of outside projection cone + float outvol; // delta-volume outside the projection cone + DWORD vam; // voice allocation/management flags (BASS_VAM_xxx) + DWORD priority; // priority (0=lowest, 0xffffffff=highest) +} BASS_SAMPLE; + +#define BASS_SAMPLE_8BITS 1 // 8 bit +#define BASS_SAMPLE_FLOAT 256 // 32 bit floating-point +#define BASS_SAMPLE_MONO 2 // mono +#define BASS_SAMPLE_LOOP 4 // looped +#define BASS_SAMPLE_3D 8 // 3D functionality +#define BASS_SAMPLE_SOFTWARE 16 // not using hardware mixing +#define BASS_SAMPLE_MUTEMAX 32 // mute at max distance (3D only) +#define BASS_SAMPLE_VAM 64 // DX7 voice allocation & management +#define BASS_SAMPLE_FX 128 // old implementation of DX8 effects +#define BASS_SAMPLE_OVER_VOL 0x10000 // override lowest volume +#define BASS_SAMPLE_OVER_POS 0x20000 // override longest playing +#define BASS_SAMPLE_OVER_DIST 0x30000 // override furthest from listener (3D only) + +#define BASS_STREAM_PRESCAN 0x20000 // enable pin-point seeking/length (MP3/MP2/MP1) +#define BASS_MP3_SETPOS BASS_STREAM_PRESCAN +#define BASS_STREAM_AUTOFREE 0x40000 // automatically free the stream when it stop/ends +#define BASS_STREAM_RESTRATE 0x80000 // restrict the download rate of internet file streams +#define BASS_STREAM_BLOCK 0x100000 // download/play internet file stream in small blocks +#define BASS_STREAM_DECODE 0x200000 // don't play the stream, only decode (BASS_ChannelGetData) +#define BASS_STREAM_STATUS 0x800000 // give server status info (HTTP/ICY tags) in DOWNLOADPROC + +#define BASS_MUSIC_FLOAT BASS_SAMPLE_FLOAT +#define BASS_MUSIC_MONO BASS_SAMPLE_MONO +#define BASS_MUSIC_LOOP BASS_SAMPLE_LOOP +#define BASS_MUSIC_3D BASS_SAMPLE_3D +#define BASS_MUSIC_FX BASS_SAMPLE_FX +#define BASS_MUSIC_AUTOFREE BASS_STREAM_AUTOFREE +#define BASS_MUSIC_DECODE BASS_STREAM_DECODE +#define BASS_MUSIC_PRESCAN BASS_STREAM_PRESCAN // calculate playback length +#define BASS_MUSIC_CALCLEN BASS_MUSIC_PRESCAN +#define BASS_MUSIC_RAMP 0x200 // normal ramping +#define BASS_MUSIC_RAMPS 0x400 // sensitive ramping +#define BASS_MUSIC_SURROUND 0x800 // surround sound +#define BASS_MUSIC_SURROUND2 0x1000 // surround sound (mode 2) +#define BASS_MUSIC_FT2PAN 0x2000 // apply FastTracker 2 panning to XM files +#define BASS_MUSIC_FT2MOD 0x2000 // play .MOD as FastTracker 2 does +#define BASS_MUSIC_PT1MOD 0x4000 // play .MOD as ProTracker 1 does +#define BASS_MUSIC_NONINTER 0x10000 // non-interpolated sample mixing +#define BASS_MUSIC_SINCINTER 0x800000 // sinc interpolated sample mixing +#define BASS_MUSIC_POSRESET 0x8000 // stop all notes when moving position +#define BASS_MUSIC_POSRESETEX 0x400000 // stop all notes and reset bmp/etc when moving position +#define BASS_MUSIC_STOPBACK 0x80000 // stop the music on a backwards jump effect +#define BASS_MUSIC_NOSAMPLE 0x100000 // don't load the samples + +// Speaker assignment flags +#define BASS_SPEAKER_FRONT 0x1000000 // front speakers +#define BASS_SPEAKER_REAR 0x2000000 // rear/side speakers +#define BASS_SPEAKER_CENLFE 0x3000000 // center & LFE speakers (5.1) +#define BASS_SPEAKER_REAR2 0x4000000 // rear center speakers (7.1) +#define BASS_SPEAKER_N(n) ((n)<<24) // n'th pair of speakers (max 15) +#define BASS_SPEAKER_LEFT 0x10000000 // modifier: left +#define BASS_SPEAKER_RIGHT 0x20000000 // modifier: right +#define BASS_SPEAKER_FRONTLEFT BASS_SPEAKER_FRONT|BASS_SPEAKER_LEFT +#define BASS_SPEAKER_FRONTRIGHT BASS_SPEAKER_FRONT|BASS_SPEAKER_RIGHT +#define BASS_SPEAKER_REARLEFT BASS_SPEAKER_REAR|BASS_SPEAKER_LEFT +#define BASS_SPEAKER_REARRIGHT BASS_SPEAKER_REAR|BASS_SPEAKER_RIGHT +#define BASS_SPEAKER_CENTER BASS_SPEAKER_CENLFE|BASS_SPEAKER_LEFT +#define BASS_SPEAKER_LFE BASS_SPEAKER_CENLFE|BASS_SPEAKER_RIGHT +#define BASS_SPEAKER_REAR2LEFT BASS_SPEAKER_REAR2|BASS_SPEAKER_LEFT +#define BASS_SPEAKER_REAR2RIGHT BASS_SPEAKER_REAR2|BASS_SPEAKER_RIGHT + +#define BASS_ASYNCFILE 0x40000000 +#define BASS_UNICODE 0x80000000 + +#define BASS_RECORD_PAUSE 0x8000 // start recording paused +#define BASS_RECORD_ECHOCANCEL 0x2000 +#define BASS_RECORD_AGC 0x4000 + +// DX7 voice allocation & management flags +#define BASS_VAM_HARDWARE 1 +#define BASS_VAM_SOFTWARE 2 +#define BASS_VAM_TERM_TIME 4 +#define BASS_VAM_TERM_DIST 8 +#define BASS_VAM_TERM_PRIO 16 + +// Channel info structure +typedef struct { + DWORD freq; // default playback rate + DWORD chans; // channels + DWORD flags; // BASS_SAMPLE/STREAM/MUSIC/SPEAKER flags + DWORD ctype; // type of channel + DWORD origres; // original resolution + HPLUGIN plugin; // plugin + HSAMPLE sample; // sample + const char *filename; // filename +} BASS_CHANNELINFO; + +// BASS_CHANNELINFO types +#define BASS_CTYPE_SAMPLE 1 +#define BASS_CTYPE_RECORD 2 +#define BASS_CTYPE_STREAM 0x10000 +#define BASS_CTYPE_STREAM_OGG 0x10002 +#define BASS_CTYPE_STREAM_MP1 0x10003 +#define BASS_CTYPE_STREAM_MP2 0x10004 +#define BASS_CTYPE_STREAM_MP3 0x10005 +#define BASS_CTYPE_STREAM_AIFF 0x10006 +#define BASS_CTYPE_STREAM_CA 0x10007 +#define BASS_CTYPE_STREAM_MF 0x10008 +#define BASS_CTYPE_STREAM_WAV 0x40000 // WAVE flag, LOWORD=codec +#define BASS_CTYPE_STREAM_WAV_PCM 0x50001 +#define BASS_CTYPE_STREAM_WAV_FLOAT 0x50003 +#define BASS_CTYPE_MUSIC_MOD 0x20000 +#define BASS_CTYPE_MUSIC_MTM 0x20001 +#define BASS_CTYPE_MUSIC_S3M 0x20002 +#define BASS_CTYPE_MUSIC_XM 0x20003 +#define BASS_CTYPE_MUSIC_IT 0x20004 +#define BASS_CTYPE_MUSIC_MO3 0x00100 // MO3 flag + +typedef struct { + DWORD ctype; // channel type +#if defined(_WIN32_WCE) || (WINAPI_FAMILY && WINAPI_FAMILY!=WINAPI_FAMILY_DESKTOP_APP) + const wchar_t *name; // format description + const wchar_t *exts; // file extension filter (*.ext1;*.ext2;etc...) +#else + const char *name; // format description + const char *exts; // file extension filter (*.ext1;*.ext2;etc...) +#endif +} BASS_PLUGINFORM; + +typedef struct { + DWORD version; // version (same form as BASS_GetVersion) + DWORD formatc; // number of formats + const BASS_PLUGINFORM *formats; // the array of formats +} BASS_PLUGININFO; + +// 3D vector (for 3D positions/velocities/orientations) +typedef struct BASS_3DVECTOR { +#ifdef __cplusplus + BASS_3DVECTOR() {}; + BASS_3DVECTOR(float _x, float _y, float _z) : x(_x), y(_y), z(_z) {}; +#endif + float x; // +=right, -=left + float y; // +=up, -=down + float z; // +=front, -=behind +} BASS_3DVECTOR; + +// 3D channel modes +#define BASS_3DMODE_NORMAL 0 // normal 3D processing +#define BASS_3DMODE_RELATIVE 1 // position is relative to the listener +#define BASS_3DMODE_OFF 2 // no 3D processing + +// software 3D mixing algorithms (used with BASS_CONFIG_3DALGORITHM) +#define BASS_3DALG_DEFAULT 0 +#define BASS_3DALG_OFF 1 +#define BASS_3DALG_FULL 2 +#define BASS_3DALG_LIGHT 3 + +// EAX environments, use with BASS_SetEAXParameters +enum +{ + EAX_ENVIRONMENT_GENERIC, + EAX_ENVIRONMENT_PADDEDCELL, + EAX_ENVIRONMENT_ROOM, + EAX_ENVIRONMENT_BATHROOM, + EAX_ENVIRONMENT_LIVINGROOM, + EAX_ENVIRONMENT_STONEROOM, + EAX_ENVIRONMENT_AUDITORIUM, + EAX_ENVIRONMENT_CONCERTHALL, + EAX_ENVIRONMENT_CAVE, + EAX_ENVIRONMENT_ARENA, + EAX_ENVIRONMENT_HANGAR, + EAX_ENVIRONMENT_CARPETEDHALLWAY, + EAX_ENVIRONMENT_HALLWAY, + EAX_ENVIRONMENT_STONECORRIDOR, + EAX_ENVIRONMENT_ALLEY, + EAX_ENVIRONMENT_FOREST, + EAX_ENVIRONMENT_CITY, + EAX_ENVIRONMENT_MOUNTAINS, + EAX_ENVIRONMENT_QUARRY, + EAX_ENVIRONMENT_PLAIN, + EAX_ENVIRONMENT_PARKINGLOT, + EAX_ENVIRONMENT_SEWERPIPE, + EAX_ENVIRONMENT_UNDERWATER, + EAX_ENVIRONMENT_DRUGGED, + EAX_ENVIRONMENT_DIZZY, + EAX_ENVIRONMENT_PSYCHOTIC, + + EAX_ENVIRONMENT_COUNT // total number of environments +}; + +// EAX presets, usage: BASS_SetEAXParameters(EAX_PRESET_xxx) +#define EAX_PRESET_GENERIC EAX_ENVIRONMENT_GENERIC,0.5F,1.493F,0.5F +#define EAX_PRESET_PADDEDCELL EAX_ENVIRONMENT_PADDEDCELL,0.25F,0.1F,0.0F +#define EAX_PRESET_ROOM EAX_ENVIRONMENT_ROOM,0.417F,0.4F,0.666F +#define EAX_PRESET_BATHROOM EAX_ENVIRONMENT_BATHROOM,0.653F,1.499F,0.166F +#define EAX_PRESET_LIVINGROOM EAX_ENVIRONMENT_LIVINGROOM,0.208F,0.478F,0.0F +#define EAX_PRESET_STONEROOM EAX_ENVIRONMENT_STONEROOM,0.5F,2.309F,0.888F +#define EAX_PRESET_AUDITORIUM EAX_ENVIRONMENT_AUDITORIUM,0.403F,4.279F,0.5F +#define EAX_PRESET_CONCERTHALL EAX_ENVIRONMENT_CONCERTHALL,0.5F,3.961F,0.5F +#define EAX_PRESET_CAVE EAX_ENVIRONMENT_CAVE,0.5F,2.886F,1.304F +#define EAX_PRESET_ARENA EAX_ENVIRONMENT_ARENA,0.361F,7.284F,0.332F +#define EAX_PRESET_HANGAR EAX_ENVIRONMENT_HANGAR,0.5F,10.0F,0.3F +#define EAX_PRESET_CARPETEDHALLWAY EAX_ENVIRONMENT_CARPETEDHALLWAY,0.153F,0.259F,2.0F +#define EAX_PRESET_HALLWAY EAX_ENVIRONMENT_HALLWAY,0.361F,1.493F,0.0F +#define EAX_PRESET_STONECORRIDOR EAX_ENVIRONMENT_STONECORRIDOR,0.444F,2.697F,0.638F +#define EAX_PRESET_ALLEY EAX_ENVIRONMENT_ALLEY,0.25F,1.752F,0.776F +#define EAX_PRESET_FOREST EAX_ENVIRONMENT_FOREST,0.111F,3.145F,0.472F +#define EAX_PRESET_CITY EAX_ENVIRONMENT_CITY,0.111F,2.767F,0.224F +#define EAX_PRESET_MOUNTAINS EAX_ENVIRONMENT_MOUNTAINS,0.194F,7.841F,0.472F +#define EAX_PRESET_QUARRY EAX_ENVIRONMENT_QUARRY,1.0F,1.499F,0.5F +#define EAX_PRESET_PLAIN EAX_ENVIRONMENT_PLAIN,0.097F,2.767F,0.224F +#define EAX_PRESET_PARKINGLOT EAX_ENVIRONMENT_PARKINGLOT,0.208F,1.652F,1.5F +#define EAX_PRESET_SEWERPIPE EAX_ENVIRONMENT_SEWERPIPE,0.652F,2.886F,0.25F +#define EAX_PRESET_UNDERWATER EAX_ENVIRONMENT_UNDERWATER,1.0F,1.499F,0.0F +#define EAX_PRESET_DRUGGED EAX_ENVIRONMENT_DRUGGED,0.875F,8.392F,1.388F +#define EAX_PRESET_DIZZY EAX_ENVIRONMENT_DIZZY,0.139F,17.234F,0.666F +#define EAX_PRESET_PSYCHOTIC EAX_ENVIRONMENT_PSYCHOTIC,0.486F,7.563F,0.806F + +typedef DWORD (CALLBACK STREAMPROC)(HSTREAM handle, void *buffer, DWORD length, void *user); +/* User stream callback function. NOTE: A stream function should obviously be as quick +as possible, other streams (and MOD musics) can't be mixed until it's finished. +handle : The stream that needs writing +buffer : Buffer to write the samples in +length : Number of bytes to write +user : The 'user' parameter value given when calling BASS_StreamCreate +RETURN : Number of bytes written. Set the BASS_STREAMPROC_END flag to end + the stream. */ + +#define BASS_STREAMPROC_END 0x80000000 // end of user stream flag + +// special STREAMPROCs +#define STREAMPROC_DUMMY (STREAMPROC*)0 // "dummy" stream +#define STREAMPROC_PUSH (STREAMPROC*)-1 // push stream + +// BASS_StreamCreateFileUser file systems +#define STREAMFILE_NOBUFFER 0 +#define STREAMFILE_BUFFER 1 +#define STREAMFILE_BUFFERPUSH 2 + +// User file stream callback functions +typedef void (CALLBACK FILECLOSEPROC)(void *user); +typedef QWORD (CALLBACK FILELENPROC)(void *user); +typedef DWORD (CALLBACK FILEREADPROC)(void *buffer, DWORD length, void *user); +typedef BOOL (CALLBACK FILESEEKPROC)(QWORD offset, void *user); + +typedef struct { + FILECLOSEPROC *close; + FILELENPROC *length; + FILEREADPROC *read; + FILESEEKPROC *seek; +} BASS_FILEPROCS; + +// BASS_StreamPutFileData options +#define BASS_FILEDATA_END 0 // end & close the file + +// BASS_StreamGetFilePosition modes +#define BASS_FILEPOS_CURRENT 0 +#define BASS_FILEPOS_DECODE BASS_FILEPOS_CURRENT +#define BASS_FILEPOS_DOWNLOAD 1 +#define BASS_FILEPOS_END 2 +#define BASS_FILEPOS_START 3 +#define BASS_FILEPOS_CONNECTED 4 +#define BASS_FILEPOS_BUFFER 5 +#define BASS_FILEPOS_SOCKET 6 +#define BASS_FILEPOS_ASYNCBUF 7 +#define BASS_FILEPOS_SIZE 8 + +typedef void (CALLBACK DOWNLOADPROC)(const void *buffer, DWORD length, void *user); +/* Internet stream download callback function. +buffer : Buffer containing the downloaded data... NULL=end of download +length : Number of bytes in the buffer +user : The 'user' parameter value given when calling BASS_StreamCreateURL */ + +// BASS_ChannelSetSync types +#define BASS_SYNC_POS 0 +#define BASS_SYNC_END 2 +#define BASS_SYNC_META 4 +#define BASS_SYNC_SLIDE 5 +#define BASS_SYNC_STALL 6 +#define BASS_SYNC_DOWNLOAD 7 +#define BASS_SYNC_FREE 8 +#define BASS_SYNC_SETPOS 11 +#define BASS_SYNC_MUSICPOS 10 +#define BASS_SYNC_MUSICINST 1 +#define BASS_SYNC_MUSICFX 3 +#define BASS_SYNC_OGG_CHANGE 12 +#define BASS_SYNC_MIXTIME 0x40000000 // flag: sync at mixtime, else at playtime +#define BASS_SYNC_ONETIME 0x80000000 // flag: sync only once, else continuously + +typedef void (CALLBACK SYNCPROC)(HSYNC handle, DWORD channel, DWORD data, void *user); +/* Sync callback function. NOTE: a sync callback function should be very +quick as other syncs can't be processed until it has finished. If the sync +is a "mixtime" sync, then other streams and MOD musics can't be mixed until +it's finished either. +handle : The sync that has occured +channel: Channel that the sync occured in +data : Additional data associated with the sync's occurance +user : The 'user' parameter given when calling BASS_ChannelSetSync */ + +typedef void (CALLBACK DSPPROC)(HDSP handle, DWORD channel, void *buffer, DWORD length, void *user); +/* DSP callback function. NOTE: A DSP function should obviously be as quick as +possible... other DSP functions, streams and MOD musics can not be processed +until it's finished. +handle : The DSP handle +channel: Channel that the DSP is being applied to +buffer : Buffer to apply the DSP to +length : Number of bytes in the buffer +user : The 'user' parameter given when calling BASS_ChannelSetDSP */ + +typedef BOOL (CALLBACK RECORDPROC)(HRECORD handle, const void *buffer, DWORD length, void *user); +/* Recording callback function. +handle : The recording handle +buffer : Buffer containing the recorded sample data +length : Number of bytes +user : The 'user' parameter value given when calling BASS_RecordStart +RETURN : TRUE = continue recording, FALSE = stop */ + +// BASS_ChannelIsActive return values +#define BASS_ACTIVE_STOPPED 0 +#define BASS_ACTIVE_PLAYING 1 +#define BASS_ACTIVE_STALLED 2 +#define BASS_ACTIVE_PAUSED 3 + +// Channel attributes +#define BASS_ATTRIB_FREQ 1 +#define BASS_ATTRIB_VOL 2 +#define BASS_ATTRIB_PAN 3 +#define BASS_ATTRIB_EAXMIX 4 +#define BASS_ATTRIB_NOBUFFER 5 +#define BASS_ATTRIB_VBR 6 +#define BASS_ATTRIB_CPU 7 +#define BASS_ATTRIB_SRC 8 +#define BASS_ATTRIB_NET_RESUME 9 +#define BASS_ATTRIB_SCANINFO 10 +#define BASS_ATTRIB_NORAMP 11 +#define BASS_ATTRIB_BITRATE 12 +#define BASS_ATTRIB_MUSIC_AMPLIFY 0x100 +#define BASS_ATTRIB_MUSIC_PANSEP 0x101 +#define BASS_ATTRIB_MUSIC_PSCALER 0x102 +#define BASS_ATTRIB_MUSIC_BPM 0x103 +#define BASS_ATTRIB_MUSIC_SPEED 0x104 +#define BASS_ATTRIB_MUSIC_VOL_GLOBAL 0x105 +#define BASS_ATTRIB_MUSIC_ACTIVE 0x106 +#define BASS_ATTRIB_MUSIC_VOL_CHAN 0x200 // + channel # +#define BASS_ATTRIB_MUSIC_VOL_INST 0x300 // + instrument # + +// BASS_ChannelGetData flags +#define BASS_DATA_AVAILABLE 0 // query how much data is buffered +#define BASS_DATA_FIXED 0x20000000 // flag: return 8.24 fixed-point data +#define BASS_DATA_FLOAT 0x40000000 // flag: return floating-point sample data +#define BASS_DATA_FFT256 0x80000000 // 256 sample FFT +#define BASS_DATA_FFT512 0x80000001 // 512 FFT +#define BASS_DATA_FFT1024 0x80000002 // 1024 FFT +#define BASS_DATA_FFT2048 0x80000003 // 2048 FFT +#define BASS_DATA_FFT4096 0x80000004 // 4096 FFT +#define BASS_DATA_FFT8192 0x80000005 // 8192 FFT +#define BASS_DATA_FFT16384 0x80000006 // 16384 FFT +#define BASS_DATA_FFT32768 0x80000007 // 32768 FFT +#define BASS_DATA_FFT_INDIVIDUAL 0x10 // FFT flag: FFT for each channel, else all combined +#define BASS_DATA_FFT_NOWINDOW 0x20 // FFT flag: no Hanning window +#define BASS_DATA_FFT_REMOVEDC 0x40 // FFT flag: pre-remove DC bias +#define BASS_DATA_FFT_COMPLEX 0x80 // FFT flag: return complex data + +// BASS_ChannelGetLevelEx flags +#define BASS_LEVEL_MONO 1 +#define BASS_LEVEL_STEREO 2 +#define BASS_LEVEL_RMS 4 + +// BASS_ChannelGetTags types : what's returned +#define BASS_TAG_ID3 0 // ID3v1 tags : TAG_ID3 structure +#define BASS_TAG_ID3V2 1 // ID3v2 tags : variable length block +#define BASS_TAG_OGG 2 // OGG comments : series of null-terminated UTF-8 strings +#define BASS_TAG_HTTP 3 // HTTP headers : series of null-terminated ANSI strings +#define BASS_TAG_ICY 4 // ICY headers : series of null-terminated ANSI strings +#define BASS_TAG_META 5 // ICY metadata : ANSI string +#define BASS_TAG_APE 6 // APE tags : series of null-terminated UTF-8 strings +#define BASS_TAG_MP4 7 // MP4/iTunes metadata : series of null-terminated UTF-8 strings +#define BASS_TAG_WMA 8 // WMA tags : series of null-terminated UTF-8 strings +#define BASS_TAG_VENDOR 9 // OGG encoder : UTF-8 string +#define BASS_TAG_LYRICS3 10 // Lyric3v2 tag : ASCII string +#define BASS_TAG_CA_CODEC 11 // CoreAudio codec info : TAG_CA_CODEC structure +#define BASS_TAG_MF 13 // Media Foundation tags : series of null-terminated UTF-8 strings +#define BASS_TAG_WAVEFORMAT 14 // WAVE format : WAVEFORMATEEX structure +#define BASS_TAG_RIFF_INFO 0x100 // RIFF "INFO" tags : series of null-terminated ANSI strings +#define BASS_TAG_RIFF_BEXT 0x101 // RIFF/BWF "bext" tags : TAG_BEXT structure +#define BASS_TAG_RIFF_CART 0x102 // RIFF/BWF "cart" tags : TAG_CART structure +#define BASS_TAG_RIFF_DISP 0x103 // RIFF "DISP" text tag : ANSI string +#define BASS_TAG_APE_BINARY 0x1000 // + index #, binary APE tag : TAG_APE_BINARY structure +#define BASS_TAG_MUSIC_NAME 0x10000 // MOD music name : ANSI string +#define BASS_TAG_MUSIC_MESSAGE 0x10001 // MOD message : ANSI string +#define BASS_TAG_MUSIC_ORDERS 0x10002 // MOD order list : BYTE array of pattern numbers +#define BASS_TAG_MUSIC_AUTH 0x10003 // MOD author : UTF-8 string +#define BASS_TAG_MUSIC_INST 0x10100 // + instrument #, MOD instrument name : ANSI string +#define BASS_TAG_MUSIC_SAMPLE 0x10300 // + sample #, MOD sample name : ANSI string + +// ID3v1 tag structure +typedef struct { + char id[3]; + char title[30]; + char artist[30]; + char album[30]; + char year[4]; + char comment[30]; + BYTE genre; +} TAG_ID3; + +// Binary APE tag structure +typedef struct { + const char *key; + const void *data; + DWORD length; +} TAG_APE_BINARY; + +// BWF "bext" tag structure +#ifdef _MSC_VER +#pragma warning(push) +#pragma warning(disable:4200) +#endif +#pragma pack(push,1) +typedef struct { + char Description[256]; // description + char Originator[32]; // name of the originator + char OriginatorReference[32]; // reference of the originator + char OriginationDate[10]; // date of creation (yyyy-mm-dd) + char OriginationTime[8]; // time of creation (hh-mm-ss) + QWORD TimeReference; // first sample count since midnight (little-endian) + WORD Version; // BWF version (little-endian) + BYTE UMID[64]; // SMPTE UMID + BYTE Reserved[190]; +#if defined(__GNUC__) && __GNUC__<3 + char CodingHistory[0]; // history +#elif 1 // change to 0 if compiler fails the following line + char CodingHistory[]; // history +#else + char CodingHistory[1]; // history +#endif +} TAG_BEXT; +#pragma pack(pop) + +// BWF "cart" tag structures +typedef struct +{ + DWORD dwUsage; // FOURCC timer usage ID + DWORD dwValue; // timer value in samples from head +} TAG_CART_TIMER; + +typedef struct +{ + char Version[4]; // version of the data structure + char Title[64]; // title of cart audio sequence + char Artist[64]; // artist or creator name + char CutID[64]; // cut number identification + char ClientID[64]; // client identification + char Category[64]; // category ID, PSA, NEWS, etc + char Classification[64]; // classification or auxiliary key + char OutCue[64]; // out cue text + char StartDate[10]; // yyyy-mm-dd + char StartTime[8]; // hh:mm:ss + char EndDate[10]; // yyyy-mm-dd + char EndTime[8]; // hh:mm:ss + char ProducerAppID[64]; // name of vendor or application + char ProducerAppVersion[64]; // version of producer application + char UserDef[64]; // user defined text + DWORD dwLevelReference; // sample value for 0 dB reference + TAG_CART_TIMER PostTimer[8]; // 8 time markers after head + char Reserved[276]; + char URL[1024]; // uniform resource locator +#if defined(__GNUC__) && __GNUC__<3 + char TagText[0]; // free form text for scripts or tags +#elif 1 // change to 0 if compiler fails the following line + char TagText[]; // free form text for scripts or tags +#else + char TagText[1]; // free form text for scripts or tags +#endif +} TAG_CART; +#ifdef _MSC_VER +#pragma warning(pop) +#endif + +// CoreAudio codec info structure +typedef struct { + DWORD ftype; // file format + DWORD atype; // audio format + const char *name; // description +} TAG_CA_CODEC; + +#ifndef _WAVEFORMATEX_ +#define _WAVEFORMATEX_ +#pragma pack(push,1) +typedef struct tWAVEFORMATEX +{ + WORD wFormatTag; + WORD nChannels; + DWORD nSamplesPerSec; + DWORD nAvgBytesPerSec; + WORD nBlockAlign; + WORD wBitsPerSample; + WORD cbSize; +} WAVEFORMATEX, *PWAVEFORMATEX, *LPWAVEFORMATEX; +typedef const WAVEFORMATEX *LPCWAVEFORMATEX; +#pragma pack(pop) +#endif + +// BASS_ChannelGetLength/GetPosition/SetPosition modes +#define BASS_POS_BYTE 0 // byte position +#define BASS_POS_MUSIC_ORDER 1 // order.row position, MAKELONG(order,row) +#define BASS_POS_OGG 3 // OGG bitstream number +#define BASS_POS_INEXACT 0x8000000 // flag: allow seeking to inexact position +#define BASS_POS_DECODE 0x10000000 // flag: get the decoding (not playing) position +#define BASS_POS_DECODETO 0x20000000 // flag: decode to the position instead of seeking +#define BASS_POS_SCAN 0x40000000 // flag: scan to the position + +// BASS_RecordSetInput flags +#define BASS_INPUT_OFF 0x10000 +#define BASS_INPUT_ON 0x20000 + +#define BASS_INPUT_TYPE_MASK 0xff000000 +#define BASS_INPUT_TYPE_UNDEF 0x00000000 +#define BASS_INPUT_TYPE_DIGITAL 0x01000000 +#define BASS_INPUT_TYPE_LINE 0x02000000 +#define BASS_INPUT_TYPE_MIC 0x03000000 +#define BASS_INPUT_TYPE_SYNTH 0x04000000 +#define BASS_INPUT_TYPE_CD 0x05000000 +#define BASS_INPUT_TYPE_PHONE 0x06000000 +#define BASS_INPUT_TYPE_SPEAKER 0x07000000 +#define BASS_INPUT_TYPE_WAVE 0x08000000 +#define BASS_INPUT_TYPE_AUX 0x09000000 +#define BASS_INPUT_TYPE_ANALOG 0x0a000000 + +// DX8 effect types, use with BASS_ChannelSetFX +enum +{ + BASS_FX_DX8_CHORUS, + BASS_FX_DX8_COMPRESSOR, + BASS_FX_DX8_DISTORTION, + BASS_FX_DX8_ECHO, + BASS_FX_DX8_FLANGER, + BASS_FX_DX8_GARGLE, + BASS_FX_DX8_I3DL2REVERB, + BASS_FX_DX8_PARAMEQ, + BASS_FX_DX8_REVERB +}; + +typedef struct { + float fWetDryMix; + float fDepth; + float fFeedback; + float fFrequency; + DWORD lWaveform; // 0=triangle, 1=sine + float fDelay; + DWORD lPhase; // BASS_DX8_PHASE_xxx +} BASS_DX8_CHORUS; + +typedef struct { + float fGain; + float fAttack; + float fRelease; + float fThreshold; + float fRatio; + float fPredelay; +} BASS_DX8_COMPRESSOR; + +typedef struct { + float fGain; + float fEdge; + float fPostEQCenterFrequency; + float fPostEQBandwidth; + float fPreLowpassCutoff; +} BASS_DX8_DISTORTION; + +typedef struct { + float fWetDryMix; + float fFeedback; + float fLeftDelay; + float fRightDelay; + BOOL lPanDelay; +} BASS_DX8_ECHO; + +typedef struct { + float fWetDryMix; + float fDepth; + float fFeedback; + float fFrequency; + DWORD lWaveform; // 0=triangle, 1=sine + float fDelay; + DWORD lPhase; // BASS_DX8_PHASE_xxx +} BASS_DX8_FLANGER; + +typedef struct { + DWORD dwRateHz; // Rate of modulation in hz + DWORD dwWaveShape; // 0=triangle, 1=square +} BASS_DX8_GARGLE; + +typedef struct { + int lRoom; // [-10000, 0] default: -1000 mB + int lRoomHF; // [-10000, 0] default: 0 mB + float flRoomRolloffFactor; // [0.0, 10.0] default: 0.0 + float flDecayTime; // [0.1, 20.0] default: 1.49s + float flDecayHFRatio; // [0.1, 2.0] default: 0.83 + int lReflections; // [-10000, 1000] default: -2602 mB + float flReflectionsDelay; // [0.0, 0.3] default: 0.007 s + int lReverb; // [-10000, 2000] default: 200 mB + float flReverbDelay; // [0.0, 0.1] default: 0.011 s + float flDiffusion; // [0.0, 100.0] default: 100.0 % + float flDensity; // [0.0, 100.0] default: 100.0 % + float flHFReference; // [20.0, 20000.0] default: 5000.0 Hz +} BASS_DX8_I3DL2REVERB; + +typedef struct { + float fCenter; + float fBandwidth; + float fGain; +} BASS_DX8_PARAMEQ; + +typedef struct { + float fInGain; // [-96.0,0.0] default: 0.0 dB + float fReverbMix; // [-96.0,0.0] default: 0.0 db + float fReverbTime; // [0.001,3000.0] default: 1000.0 ms + float fHighFreqRTRatio; // [0.001,0.999] default: 0.001 +} BASS_DX8_REVERB; + +#define BASS_DX8_PHASE_NEG_180 0 +#define BASS_DX8_PHASE_NEG_90 1 +#define BASS_DX8_PHASE_ZERO 2 +#define BASS_DX8_PHASE_90 3 +#define BASS_DX8_PHASE_180 4 + +typedef void (CALLBACK IOSNOTIFYPROC)(DWORD status); +/* iOS notification callback function. +status : The notification (BASS_IOSNOTIFY_xxx) */ + +#define BASS_IOSNOTIFY_INTERRUPT 1 // interruption started +#define BASS_IOSNOTIFY_INTERRUPT_END 2 // interruption ended + +BOOL BASSDEF(BASS_SetConfig)(DWORD option, DWORD value); +DWORD BASSDEF(BASS_GetConfig)(DWORD option); +BOOL BASSDEF(BASS_SetConfigPtr)(DWORD option, const void *value); +void *BASSDEF(BASS_GetConfigPtr)(DWORD option); +DWORD BASSDEF(BASS_GetVersion)(); +int BASSDEF(BASS_ErrorGetCode)(); +BOOL BASSDEF(BASS_GetDeviceInfo)(DWORD device, BASS_DEVICEINFO *info); +#if defined(_WIN32) && !defined(_WIN32_WCE) && !(WINAPI_FAMILY && WINAPI_FAMILY!=WINAPI_FAMILY_DESKTOP_APP) +BOOL BASSDEF(BASS_Init)(int device, DWORD freq, DWORD flags, HWND win, const GUID *dsguid); +#else +BOOL BASSDEF(BASS_Init)(int device, DWORD freq, DWORD flags, void *win, void *dsguid); +#endif +BOOL BASSDEF(BASS_SetDevice)(DWORD device); +DWORD BASSDEF(BASS_GetDevice)(); +BOOL BASSDEF(BASS_Free)(); +#if defined(_WIN32) && !defined(_WIN32_WCE) && !(WINAPI_FAMILY && WINAPI_FAMILY!=WINAPI_FAMILY_DESKTOP_APP) +void *BASSDEF(BASS_GetDSoundObject)(DWORD object); +#endif +BOOL BASSDEF(BASS_GetInfo)(BASS_INFO *info); +BOOL BASSDEF(BASS_Update)(DWORD length); +float BASSDEF(BASS_GetCPU)(); +BOOL BASSDEF(BASS_Start)(); +BOOL BASSDEF(BASS_Stop)(); +BOOL BASSDEF(BASS_Pause)(); +BOOL BASSDEF(BASS_SetVolume)(float volume); +float BASSDEF(BASS_GetVolume)(); + +HPLUGIN BASSDEF(BASS_PluginLoad)(const char *file, DWORD flags); +BOOL BASSDEF(BASS_PluginFree)(HPLUGIN handle); +const BASS_PLUGININFO *BASSDEF(BASS_PluginGetInfo)(HPLUGIN handle); + +BOOL BASSDEF(BASS_Set3DFactors)(float distf, float rollf, float doppf); +BOOL BASSDEF(BASS_Get3DFactors)(float *distf, float *rollf, float *doppf); +BOOL BASSDEF(BASS_Set3DPosition)(const BASS_3DVECTOR *pos, const BASS_3DVECTOR *vel, const BASS_3DVECTOR *front, const BASS_3DVECTOR *top); +BOOL BASSDEF(BASS_Get3DPosition)(BASS_3DVECTOR *pos, BASS_3DVECTOR *vel, BASS_3DVECTOR *front, BASS_3DVECTOR *top); +void BASSDEF(BASS_Apply3D)(); +#if defined(_WIN32) && !defined(_WIN32_WCE) && !(WINAPI_FAMILY && WINAPI_FAMILY!=WINAPI_FAMILY_DESKTOP_APP) +BOOL BASSDEF(BASS_SetEAXParameters)(int env, float vol, float decay, float damp); +BOOL BASSDEF(BASS_GetEAXParameters)(DWORD *env, float *vol, float *decay, float *damp); +#endif + +HMUSIC BASSDEF(BASS_MusicLoad)(BOOL mem, const void *file, QWORD offset, DWORD length, DWORD flags, DWORD freq); +BOOL BASSDEF(BASS_MusicFree)(HMUSIC handle); + +HSAMPLE BASSDEF(BASS_SampleLoad)(BOOL mem, const void *file, QWORD offset, DWORD length, DWORD max, DWORD flags); +HSAMPLE BASSDEF(BASS_SampleCreate)(DWORD length, DWORD freq, DWORD chans, DWORD max, DWORD flags); +BOOL BASSDEF(BASS_SampleFree)(HSAMPLE handle); +BOOL BASSDEF(BASS_SampleSetData)(HSAMPLE handle, const void *buffer); +BOOL BASSDEF(BASS_SampleGetData)(HSAMPLE handle, void *buffer); +BOOL BASSDEF(BASS_SampleGetInfo)(HSAMPLE handle, BASS_SAMPLE *info); +BOOL BASSDEF(BASS_SampleSetInfo)(HSAMPLE handle, const BASS_SAMPLE *info); +HCHANNEL BASSDEF(BASS_SampleGetChannel)(HSAMPLE handle, BOOL onlynew); +DWORD BASSDEF(BASS_SampleGetChannels)(HSAMPLE handle, HCHANNEL *channels); +BOOL BASSDEF(BASS_SampleStop)(HSAMPLE handle); + +HSTREAM BASSDEF(BASS_StreamCreate)(DWORD freq, DWORD chans, DWORD flags, STREAMPROC *proc, void *user); +HSTREAM BASSDEF(BASS_StreamCreateFile)(BOOL mem, const void *file, QWORD offset, QWORD length, DWORD flags); +HSTREAM BASSDEF(BASS_StreamCreateURL)(const char *url, DWORD offset, DWORD flags, DOWNLOADPROC *proc, void *user); +HSTREAM BASSDEF(BASS_StreamCreateFileUser)(DWORD system, DWORD flags, const BASS_FILEPROCS *proc, void *user); +BOOL BASSDEF(BASS_StreamFree)(HSTREAM handle); +QWORD BASSDEF(BASS_StreamGetFilePosition)(HSTREAM handle, DWORD mode); +DWORD BASSDEF(BASS_StreamPutData)(HSTREAM handle, const void *buffer, DWORD length); +DWORD BASSDEF(BASS_StreamPutFileData)(HSTREAM handle, const void *buffer, DWORD length); + +BOOL BASSDEF(BASS_RecordGetDeviceInfo)(DWORD device, BASS_DEVICEINFO *info); +BOOL BASSDEF(BASS_RecordInit)(int device); +BOOL BASSDEF(BASS_RecordSetDevice)(DWORD device); +DWORD BASSDEF(BASS_RecordGetDevice)(); +BOOL BASSDEF(BASS_RecordFree)(); +BOOL BASSDEF(BASS_RecordGetInfo)(BASS_RECORDINFO *info); +const char *BASSDEF(BASS_RecordGetInputName)(int input); +BOOL BASSDEF(BASS_RecordSetInput)(int input, DWORD flags, float volume); +DWORD BASSDEF(BASS_RecordGetInput)(int input, float *volume); +HRECORD BASSDEF(BASS_RecordStart)(DWORD freq, DWORD chans, DWORD flags, RECORDPROC *proc, void *user); + +double BASSDEF(BASS_ChannelBytes2Seconds)(DWORD handle, QWORD pos); +QWORD BASSDEF(BASS_ChannelSeconds2Bytes)(DWORD handle, double pos); +DWORD BASSDEF(BASS_ChannelGetDevice)(DWORD handle); +BOOL BASSDEF(BASS_ChannelSetDevice)(DWORD handle, DWORD device); +DWORD BASSDEF(BASS_ChannelIsActive)(DWORD handle); +BOOL BASSDEF(BASS_ChannelGetInfo)(DWORD handle, BASS_CHANNELINFO *info); +const char *BASSDEF(BASS_ChannelGetTags)(DWORD handle, DWORD tags); +DWORD BASSDEF(BASS_ChannelFlags)(DWORD handle, DWORD flags, DWORD mask); +BOOL BASSDEF(BASS_ChannelUpdate)(DWORD handle, DWORD length); +BOOL BASSDEF(BASS_ChannelLock)(DWORD handle, BOOL lock); +BOOL BASSDEF(BASS_ChannelPlay)(DWORD handle, BOOL restart); +BOOL BASSDEF(BASS_ChannelStop)(DWORD handle); +BOOL BASSDEF(BASS_ChannelPause)(DWORD handle); +BOOL BASSDEF(BASS_ChannelSetAttribute)(DWORD handle, DWORD attrib, float value); +BOOL BASSDEF(BASS_ChannelGetAttribute)(DWORD handle, DWORD attrib, float *value); +BOOL BASSDEF(BASS_ChannelSlideAttribute)(DWORD handle, DWORD attrib, float value, DWORD time); +BOOL BASSDEF(BASS_ChannelIsSliding)(DWORD handle, DWORD attrib); +BOOL BASSDEF(BASS_ChannelSetAttributeEx)(DWORD handle, DWORD attrib, void *value, DWORD size); +DWORD BASSDEF(BASS_ChannelGetAttributeEx)(DWORD handle, DWORD attrib, void *value, DWORD size); +BOOL BASSDEF(BASS_ChannelSet3DAttributes)(DWORD handle, int mode, float min, float max, int iangle, int oangle, float outvol); +BOOL BASSDEF(BASS_ChannelGet3DAttributes)(DWORD handle, DWORD *mode, float *min, float *max, DWORD *iangle, DWORD *oangle, float *outvol); +BOOL BASSDEF(BASS_ChannelSet3DPosition)(DWORD handle, const BASS_3DVECTOR *pos, const BASS_3DVECTOR *orient, const BASS_3DVECTOR *vel); +BOOL BASSDEF(BASS_ChannelGet3DPosition)(DWORD handle, BASS_3DVECTOR *pos, BASS_3DVECTOR *orient, BASS_3DVECTOR *vel); +QWORD BASSDEF(BASS_ChannelGetLength)(DWORD handle, DWORD mode); +BOOL BASSDEF(BASS_ChannelSetPosition)(DWORD handle, QWORD pos, DWORD mode); +QWORD BASSDEF(BASS_ChannelGetPosition)(DWORD handle, DWORD mode); +DWORD BASSDEF(BASS_ChannelGetLevel)(DWORD handle); +BOOL BASSDEF(BASS_ChannelGetLevelEx)(DWORD handle, float *levels, float length, DWORD flags); +DWORD BASSDEF(BASS_ChannelGetData)(DWORD handle, void *buffer, DWORD length); +HSYNC BASSDEF(BASS_ChannelSetSync)(DWORD handle, DWORD type, QWORD param, SYNCPROC *proc, void *user); +BOOL BASSDEF(BASS_ChannelRemoveSync)(DWORD handle, HSYNC sync); +HDSP BASSDEF(BASS_ChannelSetDSP)(DWORD handle, DSPPROC *proc, void *user, int priority); +BOOL BASSDEF(BASS_ChannelRemoveDSP)(DWORD handle, HDSP dsp); +BOOL BASSDEF(BASS_ChannelSetLink)(DWORD handle, DWORD chan); +BOOL BASSDEF(BASS_ChannelRemoveLink)(DWORD handle, DWORD chan); +HFX BASSDEF(BASS_ChannelSetFX)(DWORD handle, DWORD type, int priority); +BOOL BASSDEF(BASS_ChannelRemoveFX)(DWORD handle, HFX fx); + +BOOL BASSDEF(BASS_FXSetParameters)(HFX handle, const void *params); +BOOL BASSDEF(BASS_FXGetParameters)(HFX handle, void *params); +BOOL BASSDEF(BASS_FXReset)(HFX handle); +BOOL BASSDEF(BASS_FXSetPriority)(HFX handle, int priority); + +#ifdef __cplusplus +} + +#if defined(_WIN32) && !defined(NOBASSOVERLOADS) +static inline HPLUGIN BASS_PluginLoad(const WCHAR *file, DWORD flags) +{ + return BASS_PluginLoad((const char*)file, flags|BASS_UNICODE); +} + +static inline HMUSIC BASS_MusicLoad(BOOL mem, const WCHAR *file, QWORD offset, DWORD length, DWORD flags, DWORD freq) +{ + return BASS_MusicLoad(mem, (const void*)file, offset, length, flags|BASS_UNICODE, freq); +} + +static inline HSAMPLE BASS_SampleLoad(BOOL mem, const WCHAR *file, QWORD offset, DWORD length, DWORD max, DWORD flags) +{ + return BASS_SampleLoad(mem, (const void*)file, offset, length, max, flags|BASS_UNICODE); +} + +static inline HSTREAM BASS_StreamCreateFile(BOOL mem, const WCHAR *file, QWORD offset, QWORD length, DWORD flags) +{ + return BASS_StreamCreateFile(mem, (const void*)file, offset, length, flags|BASS_UNICODE); +} + +static inline HSTREAM BASS_StreamCreateURL(const WCHAR *url, DWORD offset, DWORD flags, DOWNLOADPROC *proc, void *user) +{ + return BASS_StreamCreateURL((const char*)url, offset, flags|BASS_UNICODE, proc, user); +} + +static inline BOOL BASS_SetConfigPtr(DWORD option, const WCHAR *value) +{ + return BASS_SetConfigPtr(option|BASS_UNICODE, (const void*)value); +} +#endif +#endif + +#endif From c1c042b93d0d0550bd1dfb3cc17f3209135a26c0 Mon Sep 17 00:00:00 2001 From: Cerapter Date: Sat, 15 Sep 2018 01:42:44 +0200 Subject: [PATCH 129/174] Revert "Removed the dependency on `bass.dll`." This reverts commit fe955d692350cd3bac192721c09d8fdd445afc5d. --- Attorney_Online_remake.pro | 14 +++++--- README.md | 6 ++++ aoapplication.h | 2 +- aoblipplayer.cpp | 36 ++++++++++++++------ aoblipplayer.h | 5 ++- aomusicplayer.cpp | 22 ++++++++---- aomusicplayer.h | 4 +-- aooptionsdialog.cpp | 69 ++++++++++++++++++++++++++++++++------ aooptionsdialog.h | 9 +++-- aosfxplayer.cpp | 26 +++++++------- aosfxplayer.h | 5 ++- courtroom.cpp | 28 ++++++++++++++++ 12 files changed, 169 insertions(+), 57 deletions(-) diff --git a/Attorney_Online_remake.pro b/Attorney_Online_remake.pro index f3ab090..71c14d9 100644 --- a/Attorney_Online_remake.pro +++ b/Attorney_Online_remake.pro @@ -70,6 +70,7 @@ HEADERS += lobby.h \ misc_functions.h \ aocharmovie.h \ aoemotebutton.h \ + bass.h \ aosfxplayer.h \ aomusicplayer.h \ aoblipplayer.h \ @@ -83,10 +84,15 @@ HEADERS += lobby.h \ aooptionsdialog.h \ text_file_functions.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 -win32:LIBS += -L$$PWD -ldiscord-rpc #"$$PWD/discord-rpc.dll" +# 1. You need to get BASS and put the x86 bass DLL/headers in the project root folder +# AND the compilation output folder. If you want a static link, you'll probably +# need the .lib file too. MinGW-GCC is really finicky finding BASS, it seems. +# 2. You need to compile the Discord Rich Presence SDK separately and add the lib/headers +# in the same way as BASS. Discord RPC uses CMake, which does not play nicely with +# QMake, so this step must be manual. +unix:LIBS += -L$$PWD -lbass -ldiscord-rpc +win32:LIBS += -L$$PWD "$$PWD/bass.dll" -ldiscord-rpc #"$$PWD/discord-rpc.dll" +android:LIBS += -L$$PWD\android\libs\armeabi-v7a\ -lbass CONFIG += c++11 diff --git a/README.md b/README.md index 828d329..913b174 100644 --- a/README.md +++ b/README.md @@ -103,3 +103,9 @@ Modifications copyright (c) 2017-2018 oldmud0 This project uses Qt 5, which is licensed under the [GNU Lesser General Public License](https://www.gnu.org/licenses/lgpl-3.0.txt) with [certain licensing restrictions and exceptions](https://www.qt.io/qt-licensing-terms/). To comply with licensing requirements for static linking, object code is available if you would like to relink with an alternative version of Qt, and the source code for Qt may be found at https://github.com/qt/qtbase, http://code.qt.io/cgit/, or at https://qt.io. Copyright (c) 2016 The Qt Company Ltd. + +## BASS + +This project depends on the BASS shared library. Get it here: http://www.un4seen.com/ + +Copyright (c) 1999-2016 Un4seen Developments Ltd. All rights reserved. diff --git a/aoapplication.h b/aoapplication.h index fc81d13..c7066d9 100644 --- a/aoapplication.h +++ b/aoapplication.h @@ -272,7 +272,7 @@ private: const int CCCC_RELEASE = 1; const int CCCC_MAJOR_VERSION = 3; - const int CCCC_MINOR_VERSION = 5; + const int CCCC_MINOR_VERSION = 1; QString current_theme = "default"; 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/aomusicplayer.cpp b/aomusicplayer.cpp index 62aa730..9e76358 100644 --- a/aomusicplayer.cpp +++ b/aomusicplayer.cpp @@ -4,24 +4,34 @@ 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 7716ea9..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 { @@ -20,9 +20,9 @@ public: 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 index e79c6f6..7d307dd 100644 --- a/aooptionsdialog.cpp +++ b/aooptionsdialog.cpp @@ -199,73 +199,105 @@ AOOptionsDialog::AOOptionsDialog(QWidget *parent, AOApplication *p_ao_app) : QDi 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(1, QFormLayout::LabelRole, MusicVolumeLabel); + 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(1, QFormLayout::FieldRole, MusicVolumeSpinbox); + 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(2, QFormLayout::LabelRole, SFXVolumeLabel); + 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(2, QFormLayout::FieldRole, SFXVolumeSpinbox); + 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(3, QFormLayout::LabelRole, BlipsVolumeLabel); + 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(3, QFormLayout::FieldRole, BlipsVolumeSpinbox); + AudioForm->setWidget(4, QFormLayout::FieldRole, BlipsVolumeSpinbox); VolumeBlipDivider = new QFrame(formLayoutWidget_2); VolumeBlipDivider->setFrameShape(QFrame::HLine); VolumeBlipDivider->setFrameShadow(QFrame::Sunken); - AudioForm->setWidget(4, QFormLayout::FieldRole, VolumeBlipDivider); + 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(5, QFormLayout::LabelRole, BlipRateLabel); + AudioForm->setWidget(6, QFormLayout::LabelRole, BlipRateLabel); BlipRateSpinbox = new QSpinBox(formLayoutWidget_2); BlipRateSpinbox->setValue(p_ao_app->read_blip_rate()); BlipRateSpinbox->setMinimum(1); - AudioForm->setWidget(5, QFormLayout::FieldRole, BlipRateSpinbox); + 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(6, QFormLayout::LabelRole, BlankBlipsLabel); + AudioForm->setWidget(7, QFormLayout::LabelRole, BlankBlipsLabel); BlankBlipsCheckbox = new QCheckBox(formLayoutWidget_2); BlankBlipsCheckbox->setChecked(p_ao_app->get_blank_blip()); - AudioForm->setWidget(6, QFormLayout::FieldRole, BlankBlipsCheckbox); + AudioForm->setWidget(7, QFormLayout::FieldRole, BlankBlipsCheckbox); // When we're done, we should continue the updates! setUpdatesEnabled(true); @@ -297,6 +329,7 @@ void AOOptionsDialog::save_pressed() 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()); @@ -311,3 +344,17 @@ 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 index 0401a59..a48bff9 100644 --- a/aooptionsdialog.h +++ b/aooptionsdialog.h @@ -2,6 +2,7 @@ #define AOOPTIONSDIALOG_H #include "aoapplication.h" +#include "bass.h" #include #include @@ -62,9 +63,9 @@ private: QWidget *AudioTab; QWidget *formLayoutWidget_2; QFormLayout *AudioForm; - //QLabel *AudioDevideLabel; - //QComboBox *AudioDeviceCombobox; - //QFrame *DeviceVolumeDivider; + QLabel *AudioDevideLabel; + QComboBox *AudioDeviceCombobox; + QFrame *DeviceVolumeDivider; QSpinBox *MusicVolumeSpinbox; QLabel *MusicVolumeLabel; QSpinBox *SFXVolumeSpinbox; @@ -78,6 +79,8 @@ private: QLabel *BlankBlipsLabel; QDialogButtonBox *SettingsButtons; + bool needs_default_audiodev(); + signals: public slots: diff --git a/aosfxplayer.cpp b/aosfxplayer.cpp index 69c1171..65da686 100644 --- a/aosfxplayer.cpp +++ b/aosfxplayer.cpp @@ -5,19 +5,12 @@ AOSfxPlayer::AOSfxPlayer(QWidget *parent, AOApplication *p_ao_app) { m_parent = parent; ao_app = p_ao_app; - m_sfxplayer = new QSoundEffect(); } -AOSfxPlayer::~AOSfxPlayer() -{ - m_sfxplayer->stop(); - m_sfxplayer->deleteLater(); -} - - void AOSfxPlayer::play(QString p_sfx, QString p_char, QString shout) { - m_sfxplayer->stop(); + BASS_ChannelStop(m_stream); + p_sfx = p_sfx.toLower(); QString misc_path = ""; @@ -38,19 +31,26 @@ void AOSfxPlayer::play(QString p_sfx, QString p_char, QString shout) else f_path = sound_path; - m_sfxplayer->setSource(QUrl::fromLocalFile(f_path)); + m_stream = BASS_StreamCreateFile(FALSE, f_path.utf16(), 0, 0, BASS_STREAM_AUTOFREE | BASS_UNICODE | BASS_ASYNCFILE); + 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 ab398e0..30cbe9d 100644 --- a/aosfxplayer.h +++ b/aosfxplayer.h @@ -1,18 +1,17 @@ #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 = "", QString shout = ""); void stop(); @@ -21,9 +20,9 @@ public: private: QWidget *m_parent; AOApplication *ao_app; - QSoundEffect *m_sfxplayer; int m_volume = 0; + HSTREAM m_stream; }; #endif // AOSFXPLAYER_H diff --git a/courtroom.cpp b/courtroom.cpp index 5eb2c56..4e759a3 100644 --- a/courtroom.cpp +++ b/courtroom.cpp @@ -11,6 +11,34 @@ Courtroom::Courtroom(AOApplication *p_ao_app) : QMainWindow() { ao_app = p_ao_app; + //initializing sound device + + + // 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); + BASS_PluginLoad("bassopus.dll", BASS_UNICODE); + } + 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); + BASS_PluginLoad("bassopus.dll", BASS_UNICODE); + qDebug() << info.name << "was set as the default audio output device."; + break; + } + } + } + keepalive_timer = new QTimer(this); keepalive_timer->start(60000); From 86f91ba3e862b683becbc2d35539bc06a636c925 Mon Sep 17 00:00:00 2001 From: Cerapter Date: Sat, 15 Sep 2018 01:56:22 +0200 Subject: [PATCH 130/174] Public-facing area commands now announce who used them. --- server/commands.py | 28 ++++++---------------------- 1 file changed, 6 insertions(+), 22 deletions(-) diff --git a/server/commands.py b/server/commands.py index 125ca80..925eac3 100644 --- a/server/commands.py +++ b/server/commands.py @@ -58,7 +58,7 @@ def ooc_cmd_bglock(client,arg): client.area.bg_lock = "false" else: client.area.bg_lock = "true" - client.area.send_host_message('A mod has set the background lock to {}.'.format(client.area.bg_lock)) + 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): @@ -94,10 +94,7 @@ def ooc_cmd_allow_blankposting(client, arg): raise ClientError('You must be authorized to do that.') client.area.blankposting_allowed = not client.area.blankposting_allowed answer = {True: 'allowed', False: 'forbidden'} - if client.is_cm: - client.area.send_host_message('The CM has set blankposting in the area to {}.'.format(answer[client.area.blankposting_allowed])) - else: - client.area.send_host_message('A mod has set blankposting in the area to {}.'.format(answer[client.area.blankposting_allowed])) + 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): @@ -105,10 +102,7 @@ def ooc_cmd_force_nonint_pres(client, arg): 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'} - if client.is_cm: - client.area.send_host_message('The CM has set pres in the area to be {}.'.format(answer[client.area.non_int_pres_only])) - else: - client.area.send_host_message('A mod has set pres in the area to be {}.'.format(answer[client.area.non_int_pres_only])) + 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): @@ -186,12 +180,7 @@ def ooc_cmd_jukebox_toggle(client, arg): raise ArgumentError('This command has no arguments.') client.area.jukebox = not client.area.jukebox client.area.jukebox_votes = [] - changer = 'Unknown' - if client.is_cm: - changer = 'The CM' - elif client.is_mod: - changer = 'A mod' - client.area.send_host_message('{} has set the jukebox to {}.'.format(changer, client.area.jukebox)) + 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.is_cm: @@ -203,15 +192,10 @@ def ooc_cmd_jukebox_skip(client, arg): if len(client.area.jukebox_votes) == 0: raise ClientError('There is no song playing right now, skipping is pointless.') client.area.start_jukebox() - changer = 'Unknown' - if client.is_cm: - changer = 'The CM' - elif client.is_mod: - changer = 'A mod' if len(client.area.jukebox_votes) == 1: - client.area.send_host_message('{} has forced a skip, restarting the only jukebox song.'.format(changer)) + 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(changer)) + 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): From fcd8f5b5abb2329aded120007319d581908c8a69 Mon Sep 17 00:00:00 2001 From: Cerapter Date: Sat, 15 Sep 2018 02:33:18 +0200 Subject: [PATCH 131/174] Areas can now be spectatable, too. - Makes it so that people can join, but can't type IC unless invited. - The CM can set it with `/area_spectate`. --- courtroom.cpp | 7 ++----- courtroom.h | 6 +++--- packet_distribution.cpp | 4 ++-- server/area_manager.py | 30 +++++++++++++++++++++++++----- server/client_manager.py | 9 +++++---- server/commands.py | 24 ++++++++++++++++-------- server/tsuserver.py | 6 +++--- 7 files changed, 56 insertions(+), 30 deletions(-) diff --git a/courtroom.cpp b/courtroom.cpp index 4e759a3..d6ac56c 100644 --- a/courtroom.cpp +++ b/courtroom.cpp @@ -963,10 +963,7 @@ void Courtroom::list_areas() i_area.append(QString::number(arup_players.at(n_area))); i_area.append(" users | "); - if (arup_locks.at(n_area) == true) - i_area.append("LOCKED"); - else - i_area.append("OPEN"); + i_area.append(arup_locks.at(n_area)); } if (i_area.toLower().contains(ui_music_search->text().toLower())) @@ -978,7 +975,7 @@ void Courtroom::list_areas() { // Colouring logic here. ui_area_list->item(n_listed_areas)->setBackground(free_brush); - if (arup_locks.at(n_area)) + if (arup_locks.at(n_area) == "Locked") { ui_area_list->item(n_listed_areas)->setBackground(locked_brush); } diff --git a/courtroom.h b/courtroom.h index d15dde0..3e1b269 100644 --- a/courtroom.h +++ b/courtroom.h @@ -64,7 +64,7 @@ public: append_music(malplaced); } - void arup_append(int players, QString status, QString cm, bool locked) + void arup_append(int players, QString status, QString cm, QString locked) { arup_players.append(players); arup_statuses.append(status); @@ -88,7 +88,7 @@ public: } else if (type == 3) { - arup_locks[place] = (value == "True"); + arup_locks[place] = value; } list_areas(); } @@ -253,7 +253,7 @@ private: QVector arup_players; QVector arup_statuses; QVector arup_cms; - QVector arup_locks; + QVector arup_locks; QSignalMapper *char_button_mapper; diff --git a/packet_distribution.cpp b/packet_distribution.cpp index 8a515e0..c81ba80 100644 --- a/packet_distribution.cpp +++ b/packet_distribution.cpp @@ -408,7 +408,7 @@ void AOApplication::server_packet_received(AOPacket *p_packet) for (int area_n = 0; area_n < areas; area_n++) { - w_courtroom->arup_append(0, "Unknown", "Unknown", false); + w_courtroom->arup_append(0, "Unknown", "Unknown", "Unknown"); } int total_loading_size = char_list_size * 2 + evidence_list_size + music_list_size; @@ -503,7 +503,7 @@ void AOApplication::server_packet_received(AOPacket *p_packet) for (int area_n = 0; area_n < areas; area_n++) { - w_courtroom->arup_append(0, "Unknown", "Unknown", false); + w_courtroom->arup_append(0, "Unknown", "Unknown", "Unknown"); } int total_loading_size = char_list_size * 2 + evidence_list_size + music_list_size; diff --git a/server/area_manager.py b/server/area_manager.py index 23c4339..d8e60d0 100644 --- a/server/area_manager.py +++ b/server/area_manager.py @@ -22,6 +22,7 @@ import yaml from server.exceptions import AreaError from server.evidence import EvidenceList +from enum import Enum class AreaManager: @@ -63,13 +64,18 @@ class AreaManager: self.evidence_list.append(Evidence("weeeeeew", "desc3", "3.png")) """ - self.is_locked = False + 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 + 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() @@ -80,15 +86,29 @@ class AreaManager: client.is_cm = False self.owned = False self.server.area_manager.send_arup_cms() - if self.is_locked: + if self.is_locked != self.Locked.FREE: self.unlock() def unlock(self): - self.is_locked = False + 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 + 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 + 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] @@ -215,7 +235,7 @@ class AreaManager: def can_send_message(self, client): - if self.is_locked and not client.is_mod and not client.id in self.invite_list: + if self.is_locked != self.Locked.FREE and not client.is_mod and not client.id in self.invite_list: 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 @@ -366,5 +386,5 @@ class AreaManager: def send_arup_lock(self): lock_list = [3] for area in self.areas: - lock_list.append(area.is_locked) + lock_list.append(area.is_locked.name) self.server.send_arup(lock_list) diff --git a/server/client_manager.py b/server/client_manager.py index 5e6825b..617bb69 100644 --- a/server/client_manager.py +++ b/server/client_manager.py @@ -182,9 +182,10 @@ class ClientManager: def change_area(self, area): if self.area == area: raise ClientError('User already in specified area.') - if area.is_locked and not self.is_mod and not self.id in area.invite_list: - #self.send_host_message('This area is locked - you will be unable to send messages ICly.') + 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) @@ -215,13 +216,13 @@ class ClientManager: def send_area_list(self): msg = '=== Areas ===' - lock = {True: '[LOCKED]', False: ''} for i, area in enumerate(self.server.area_manager.areas): owner = 'FREE' if area.owned: for client in [x for x in area.clients if x.is_cm]: owner = 'CM: {}'.format(client.get_char_name()) break + 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 += ' [*]' @@ -236,7 +237,7 @@ class ClientManager: info += '=== {} ==='.format(area.name) info += '\r\n' - lock = {True: '[LOCKED]', False: ''} + 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 = [] diff --git a/server/commands.py b/server/commands.py index 925eac3..c84d8b7 100644 --- a/server/commands.py +++ b/server/commands.py @@ -697,7 +697,7 @@ def ooc_cmd_uncm(client, arg): client.is_cm = False client.area.owned = False client.area.blankposting_allowed = True - if client.area.is_locked: + if client.area.is_locked != client.area.Locked.FREE: client.area.unlock() client.server.area_manager.send_arup_cms() client.area.send_host_message('{} is no longer CM in this area.'.format(client.get_char_name())) @@ -714,20 +714,28 @@ 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: + if client.area.is_locked == client.area.Locked.LOCKED: client.send_host_message('Area is already locked.') if client.is_cm: - client.area.is_locked = True - client.server.area_manager.send_arup_lock() - client.area.send_host_message('Area is locked.') - for i in client.area.clients: - client.area.invite_list[i.id] = None + 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.is_cm: + client.area.spectator() + return + else: + raise ClientError('Only CM can make the area spectatable.') def ooc_cmd_area_unlock(client, arg): - if not client.area.is_locked: + if client.area.is_locked == client.area.Locked.FREE: raise ClientError('Area is already unlocked.') if not client.is_cm: raise ClientError('Only CM can unlock area.') diff --git a/server/tsuserver.py b/server/tsuserver.py index 8f5bf85..7ef4f5e 100644 --- a/server/tsuserver.py +++ b/server/tsuserver.py @@ -268,7 +268,7 @@ class TsuServer3: CM: ARUP#2#####... Lockedness: - ARUP#3#####... + ARUP#3#####... """ if len(args) < 2: @@ -277,13 +277,13 @@ class TsuServer3: if args[0] not in (0,1,2,3): return - if args[0] in (0, 3): + if args[0] == 0: for part_arg in args[1:]: try: sanitised = int(part_arg) except: return - elif args[0] in (1, 2): + elif args[0] in (1, 2, 3): for part_arg in args[1:]: try: sanitised = str(part_arg) From d54064d892c26a26641e6ed67412b33d7db3f6c2 Mon Sep 17 00:00:00 2001 From: Cerapter Date: Sat, 15 Sep 2018 03:33:10 +0200 Subject: [PATCH 132/174] Server messages are now coloured differently. --- aotextarea.cpp | 4 ++-- aotextarea.h | 2 +- courtroom.cpp | 39 +++++++++++++++++++++++---------------- courtroom.h | 2 +- lobby.cpp | 2 +- packet_distribution.cpp | 7 ++++++- server/area_manager.py | 2 +- server/client_manager.py | 4 ++-- server/commands.py | 2 +- server/districtclient.py | 2 +- server/tsuserver.py | 4 ++-- 11 files changed, 41 insertions(+), 29 deletions(-) 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/courtroom.cpp b/courtroom.cpp index d6ac56c..6c66c3f 100644 --- a/courtroom.cpp +++ b/courtroom.cpp @@ -1005,12 +1005,19 @@ void Courtroom::list_areas() void Courtroom::append_ms_chatmessage(QString f_name, QString f_message) { - ui_ms_chatlog->append_chatmessage(f_name, f_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) +void Courtroom::append_server_chatmessage(QString p_name, QString p_message, QString p_colour) { - ui_server_chatlog->append_chatmessage(p_name, p_message); + 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() @@ -2660,21 +2667,21 @@ 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."); + 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_ooc_chat_message->clear(); //rainbow_appended = true; - append_server_chatmessage("CLIENT", "This does nohing, but there you go."); + 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."); + append_server_chatmessage("CLIENT", "You opened the settings menu.", "1"); return; } else if (ooc_message.startsWith("/pair")) @@ -2692,16 +2699,16 @@ void Courtroom::on_ooc_return_pressed() 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); + append_server_chatmessage("CLIENT", msg, "1"); } else { - append_server_chatmessage("CLIENT", "You are no longer paired with anyone."); + 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."); + append_server_chatmessage("CLIENT", "Are you sure you typed that well? The char ID could not be recognised.", "1"); } return; } @@ -2720,29 +2727,29 @@ void Courtroom::on_ooc_return_pressed() QString msg = "You have set your offset to "; msg.append(QString::number(off)); msg.append("%."); - append_server_chatmessage("CLIENT", msg); + append_server_chatmessage("CLIENT", msg, "1"); } else { - append_server_chatmessage("CLIENT", "Your offset must be between -100% and 100%!"); + 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."); + 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."); + 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."); + 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->shownames_enabled = true; ao_app->charpairs_enabled = true; ao_app->arup_enabled = true; @@ -2754,9 +2761,9 @@ void Courtroom::on_ooc_return_pressed() else if (ooc_message.startsWith("/non_int_pre")) { if (ui_pre_non_interrupt->isChecked()) - append_server_chatmessage("CLIENT", "Your pre-animations interrupt again."); + append_server_chatmessage("CLIENT", "Your pre-animations interrupt again.", "1"); else - append_server_chatmessage("CLIENT", "Your pre-animations will not interrupt text."); + 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; diff --git a/courtroom.h b/courtroom.h index 3e1b269..341d6df 100644 --- a/courtroom.h +++ b/courtroom.h @@ -162,7 +162,7 @@ public: //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 diff --git a/lobby.cpp b/lobby.cpp index 5d2d6de..9a649be 100644 --- a/lobby.cpp +++ b/lobby.cpp @@ -357,7 +357,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) diff --git a/packet_distribution.cpp b/packet_distribution.cpp index c81ba80..8d23fe5 100644 --- a/packet_distribution.cpp +++ b/packet_distribution.cpp @@ -178,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") { diff --git a/server/area_manager.py b/server/area_manager.py index d8e60d0..942ad63 100644 --- a/server/area_manager.py +++ b/server/area_manager.py @@ -124,7 +124,7 @@ class AreaManager: c.send_command(cmd, *args) def send_host_message(self, msg): - self.send_command('CT', self.server.config['hostname'], msg) + self.send_command('CT', self.server.config['hostname'], msg, '1') def set_next_msg_delay(self, msg_length): delay = min(3000, 100 + 60 * msg_length) diff --git a/server/client_manager.py b/server/client_manager.py index 617bb69..e7655bd 100644 --- a/server/client_manager.py +++ b/server/client_manager.py @@ -94,7 +94,7 @@ class ClientManager: self.send_raw_message('{}#%'.format(command)) def send_host_message(self, msg): - self.send_command('CT', self.server.config['hostname'], 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'])) @@ -272,7 +272,7 @@ class ClientManager: info = 'Current online: {}'.format(cnt) + info else: try: - info = 'People in this area: {}\n'.format(len(self.server.area_manager.areas[area_id].clients)) + self.get_area_info(area_id, mods) + 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) diff --git a/server/commands.py b/server/commands.py index c84d8b7..a6e2999 100644 --- a/server/commands.py +++ b/server/commands.py @@ -502,7 +502,7 @@ def ooc_cmd_announce(client, arg): 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)) + '=== 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) diff --git a/server/districtclient.py b/server/districtclient.py index adc29ec..c766ba5 100644 --- a/server/districtclient.py +++ b/server/districtclient.py @@ -60,7 +60,7 @@ class DistrictClient: 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, + 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): diff --git a/server/tsuserver.py b/server/tsuserver.py index 7ef4f5e..5af8161 100644 --- a/server/tsuserver.py +++ b/server/tsuserver.py @@ -253,8 +253,8 @@ class TsuServer3: 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), pred=lambda x: not x.muted_adverts) + ['=== 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)) From 0032c36822e149705efa975cd658b1661be2904d Mon Sep 17 00:00:00 2001 From: Cerapter Date: Sat, 15 Sep 2018 03:40:23 +0200 Subject: [PATCH 133/174] Auto-reset an area's status to idle if it empties out. --- server/area_manager.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/server/area_manager.py b/server/area_manager.py index 942ad63..328a231 100644 --- a/server/area_manager.py +++ b/server/area_manager.py @@ -82,6 +82,8 @@ class AreaManager: def remove_client(self, client): self.clients.remove(client) + if len(self.clients) == 0: + self.change_status('IDLE') if client.is_cm: client.is_cm = False self.owned = False From 29c91e63ea44a5e27b90fcf409ad9e4dc1f3f5c2 Mon Sep 17 00:00:00 2001 From: Cerapter Date: Sat, 15 Sep 2018 12:35:01 +0200 Subject: [PATCH 134/174] The IC chatlog can now show both name and showname, and can be exported. - Toggle the 'Custom shownames' tickbox to switch between real names and custom shownames. - Type `/save_chatlog` in the OOC to export your IC chatlog into a file. - Exporting the chatlog will append the date and time of the message, too. --- Attorney_Online_remake.pro | 6 ++- chatlogpiece.cpp | 76 ++++++++++++++++++++++++++++++++++++++ chatlogpiece.h | 31 ++++++++++++++++ courtroom.cpp | 65 ++++++++++++++++++++++++++++++-- courtroom.h | 3 ++ 5 files changed, 176 insertions(+), 5 deletions(-) create mode 100644 chatlogpiece.cpp create mode 100644 chatlogpiece.h diff --git a/Attorney_Online_remake.pro b/Attorney_Online_remake.pro index 71c14d9..9e31fa0 100644 --- a/Attorney_Online_remake.pro +++ b/Attorney_Online_remake.pro @@ -49,7 +49,8 @@ SOURCES += main.cpp\ aotextedit.cpp \ aoevidencedisplay.cpp \ discord_rich_presence.cpp \ - aooptionsdialog.cpp + aooptionsdialog.cpp \ + chatlogpiece.cpp HEADERS += lobby.h \ aoimage.h \ @@ -82,7 +83,8 @@ HEADERS += lobby.h \ discord_rich_presence.h \ discord-rpc.h \ aooptionsdialog.h \ - text_file_functions.h + text_file_functions.h \ + chatlogpiece.h # 1. You need to get BASS and put the x86 bass DLL/headers in the project root folder # AND the compilation output folder. If you want a static link, you'll probably 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 6c66c3f..2eb7d94 100644 --- a/courtroom.cpp +++ b/courtroom.cpp @@ -1268,6 +1268,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; @@ -2555,16 +2563,24 @@ 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) { - if (ui_showname_enable->isChecked()) - str_char = p_contents->at(2); + str_show = p_contents->at(2); } if (!mute_map.value(n_char)) { - append_ic_songchange(f_song_clear, 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); } } @@ -2768,6 +2784,29 @@ void Courtroom::on_ooc_return_pressed() 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; + } QStringList packet_contents; packet_contents.append(ui_ooc_chat_name->text()); @@ -3295,6 +3334,26 @@ void Courtroom::on_guard_clicked() 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(); } diff --git a/courtroom.h b/courtroom.h index 341d6df..1115e36 100644 --- a/courtroom.h +++ b/courtroom.h @@ -18,6 +18,7 @@ #include "aotextedit.h" #include "aoevidencedisplay.h" #include "datatypes.h" +#include "chatlogpiece.h" #include #include @@ -257,6 +258,8 @@ private: 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; From f3e9d691afbf70ec992fe4726865c9b9e83fac1b Mon Sep 17 00:00:00 2001 From: Cerapter Date: Sat, 15 Sep 2018 15:00:41 +0200 Subject: [PATCH 135/174] Forbade spectators from interacting IC. --- server/aoprotocol.py | 9 +++++++++ server/area_manager.py | 5 ++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/server/aoprotocol.py b/server/aoprotocol.py index 4712656..f07571d 100644 --- a/server/aoprotocol.py +++ b/server/aoprotocol.py @@ -577,6 +577,9 @@ class AOProtocol(asyncio.Protocol): if not self.client.is_dj: self.client.send_host_message('You were blockdj\'d by a moderator.') return + if 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: @@ -629,6 +632,9 @@ class AOProtocol(asyncio.Protocol): 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': @@ -658,6 +664,9 @@ class AOProtocol(asyncio.Protocol): 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: diff --git a/server/area_manager.py b/server/area_manager.py index 328a231..68eea42 100644 --- a/server/area_manager.py +++ b/server/area_manager.py @@ -237,11 +237,14 @@ class AreaManager: def can_send_message(self, client): - if self.is_locked != self.Locked.FREE and not client.is_mod and not client.id in self.invite_list: + 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.') From cc854adb51ab14ad65b645bb91c71780fe940c91 Mon Sep 17 00:00:00 2001 From: Cerapter Date: Sat, 15 Sep 2018 18:38:30 +0200 Subject: [PATCH 136/174] Too big sprites now get scaled down smoothly, while too small ones keep their sharpness as they're expanded. --- aocharmovie.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/aocharmovie.cpp b/aocharmovie.cpp index b591c22..56912a4 100644 --- a/aocharmovie.cpp +++ b/aocharmovie.cpp @@ -152,7 +152,10 @@ void AOCharMovie::frame_change(int n_frame) { QPixmap f_pixmap = QPixmap::fromImage(movie_frames.at(n_frame)); - this->setPixmap(f_pixmap.scaled(this->width(), this->height())); + if (f_pixmap.size().width() > this->size().width() || f_pixmap.size().height() > this->size().height()) + this->setPixmap(f_pixmap.scaled(this->width(), this->height(), Qt::KeepAspectRatioByExpanding, Qt::SmoothTransformation)); + else + this->setPixmap(f_pixmap.scaled(this->width(), this->height(), Qt::KeepAspectRatioByExpanding, Qt::FastTransformation)); } if (m_movie->frameCount() - 1 == n_frame && play_once) From 54dc437f5ddab385d1f4cb9d8f1052b924620da4 Mon Sep 17 00:00:00 2001 From: Cerapter Date: Sat, 15 Sep 2018 18:39:37 +0200 Subject: [PATCH 137/174] Changed how `/rollp` works, now announces the results to CM too. --- server/commands.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/server/commands.py b/server/commands.py index a6e2999..57b0c3f 100644 --- a/server/commands.py +++ b/server/commands.py @@ -140,13 +140,13 @@ def ooc_cmd_rollp(client, arg): 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 [] []') + 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 /roll [] []') + 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 = '' @@ -156,10 +156,15 @@ def ooc_cmd_rollp(client, arg): 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.'.format(client.get_char_name(), roll, val[0])) - SALT = ''.join(random.choices(string.ascii_uppercase + string.digits, k=16)) + + for c in client.area.clients: + if c.is_cm: + c.send_host_message('{} secretly rolled {} out of {}.'.format(client.get_char_name(), roll, val[0])) + else: + c.send_host_message('{} rolled in secret.'.format(client.get_char_name())) + logger.log_server( - '[{}][{}]Used /roll and got {} out of {}.'.format(client.area.abbreviation, client.get_char_name(), hashlib.sha1((str(roll) + SALT).encode('utf-8')).hexdigest() + '|' + SALT, val[0]), client) + '[{}][{}]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: From 41e12d304e7c4dd294c147eebd87f2a478ea84b7 Mon Sep 17 00:00:00 2001 From: Cerapter Date: Sat, 15 Sep 2018 20:37:17 +0200 Subject: [PATCH 138/174] `/load_case` command to quickly load cases. --- courtroom.cpp | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/courtroom.cpp b/courtroom.cpp index 2eb7d94..fcb4781 100644 --- a/courtroom.cpp +++ b/courtroom.cpp @@ -2807,6 +2807,62 @@ void Courtroom::on_ooc_return_pressed() ui_ooc_chat_message->clear(); return; } + else if (ooc_message.startsWith("/load_case")) + { + QStringList command = ooc_message.split(" ", QString::SkipEmptyParts); + + 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.", "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; + } + + 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; + } + + QSettings casefile("base/cases/" + command[1] + ".ini", QSettings::IniFormat); + + QString casedoc = casefile.value("doc", "UNKNOWN").value(); + + ao_app->send_server_packet(new AOPacket("CT#" + ui_ooc_chat_name->text() + "#/doc " + casedoc + "#%")); + ao_app->send_server_packet(new AOPacket("CT#" + ui_ooc_chat_name->text() + "#/status lfp#%")); + + 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(); + return; + } QStringList packet_contents; packet_contents.append(ui_ooc_chat_name->text()); From 851d1de1be6db6bcddfcc6a501e9eadc49b4f548 Mon Sep 17 00:00:00 2001 From: Cerapter Date: Sun, 16 Sep 2018 20:50:22 +0200 Subject: [PATCH 139/174] Websocket update. --- server/aoprotocol.py | 5 ++--- server/websocket.py | 9 ++++++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/server/aoprotocol.py b/server/aoprotocol.py index f07571d..2adfc91 100644 --- a/server/aoprotocol.py +++ b/server/aoprotocol.py @@ -87,8 +87,7 @@ class AOProtocol(asyncio.Protocol): self.client.disconnect() for msg in self.get_messages(): if len(msg) < 2: - self.client.disconnect() - return + continue # general netcode structure is not great if msg[0] in ('#', '3', '4'): if msg[0] == '#': @@ -100,7 +99,7 @@ class AOProtocol(asyncio.Protocol): cmd, *args = msg.split('#') self.net_cmd_dispatcher[cmd](self, args) except KeyError: - return + logger.log_debug('[INC][UNK]{}'.format(msg), self.client) def connection_made(self, transport): """ Called upon a new client connecting diff --git a/server/websocket.py b/server/websocket.py index d77f678..ba4258f 100644 --- a/server/websocket.py +++ b/server/websocket.py @@ -109,14 +109,17 @@ class WebSocket: 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[2:6] + masks = data[mask_offset:mask_offset + 4] decoded = "" - for char in data[6:payload_length + 6]: + for char in data[mask_offset + 4:payload_length + mask_offset + 4]: char ^= masks[len(decoded) % 4] decoded += chr(char) @@ -209,4 +212,4 @@ class WebSocket: return response_key.decode('ASCII') def finish(self): - self.protocol.connection_lost(self) \ No newline at end of file + self.protocol.connection_lost(self) From 99d2894ab3a391cdb63f8158f90d62c28fcb4ed9 Mon Sep 17 00:00:00 2001 From: Cerapter Date: Mon, 17 Sep 2018 17:52:27 +0200 Subject: [PATCH 140/174] Added the ability to set a default status and a CM doc for loaded cases. --- courtroom.cpp | 36 +++++++++++++++++++++++------------- 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/courtroom.cpp b/courtroom.cpp index fcb4781..dea4fb0 100644 --- a/courtroom.cpp +++ b/courtroom.cpp @@ -2811,9 +2811,22 @@ void Courtroom::on_ooc_return_pressed() { 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.", "1"); + 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; } @@ -2826,21 +2839,18 @@ void Courtroom::on_ooc_return_pressed() return; } - 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; - } - QSettings casefile("base/cases/" + command[1] + ".ini", QSettings::IniFormat); - QString casedoc = casefile.value("doc", "UNKNOWN").value(); + QString casedoc = casefile.value("doc", "").value(); + QString cmdoc = casefile.value("cmdoc", "").value(); + QString casestatus = casefile.value("status", "").value(); - ao_app->send_server_packet(new AOPacket("CT#" + ui_ooc_chat_name->text() + "#/doc " + casedoc + "#%")); - ao_app->send_server_packet(new AOPacket("CT#" + ui_ooc_chat_name->text() + "#/status lfp#%")); + 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) + "#%")); From c8ae7746b78b818b103ebc4ccecc0a21dec1c7a0 Mon Sep 17 00:00:00 2001 From: Cerapter Date: Mon, 17 Sep 2018 19:12:01 +0200 Subject: [PATCH 141/174] Added the ability to name an author / authors for loaded cases. --- courtroom.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/courtroom.cpp b/courtroom.cpp index dea4fb0..461de38 100644 --- a/courtroom.cpp +++ b/courtroom.cpp @@ -2841,10 +2841,13 @@ void Courtroom::on_ooc_return_pressed() 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()) From ce05b587481acea35751b12091e01b5de4bcba87 Mon Sep 17 00:00:00 2001 From: Cerapter Date: Mon, 17 Sep 2018 20:53:07 +0200 Subject: [PATCH 142/174] Send the banned package to banned users. --- server/aoprotocol.py | 1 + 1 file changed, 1 insertion(+) diff --git a/server/aoprotocol.py b/server/aoprotocol.py index 2adfc91..bea9e35 100644 --- a/server/aoprotocol.py +++ b/server/aoprotocol.py @@ -172,6 +172,7 @@ class AOProtocol(asyncio.Protocol): 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) From 3de7e346babbfbb856a2a08f01cea2f431899eb5 Mon Sep 17 00:00:00 2001 From: Cerapter Date: Tue, 18 Sep 2018 19:01:13 +0200 Subject: [PATCH 143/174] Minor fix regarding area's being locked. --- courtroom.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/courtroom.cpp b/courtroom.cpp index 461de38..347e889 100644 --- a/courtroom.cpp +++ b/courtroom.cpp @@ -948,7 +948,12 @@ void Courtroom::list_areas() for (int n_area = 0 ; n_area < area_list.size() ; ++n_area) { - QString i_area = area_list.at(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) { @@ -975,7 +980,7 @@ void Courtroom::list_areas() { // Colouring logic here. ui_area_list->item(n_listed_areas)->setBackground(free_brush); - if (arup_locks.at(n_area) == "Locked") + if (arup_locks.at(n_area) == "LOCKED") { ui_area_list->item(n_listed_areas)->setBackground(locked_brush); } From 0156849cc28c2cf1f32847beef6a0b27db6b5747 Mon Sep 17 00:00:00 2001 From: Cerapter Date: Tue, 18 Sep 2018 19:51:20 +0200 Subject: [PATCH 144/174] BEGINNINGS! of the multi-CM system. - Allows people to become CMs of multiple areas. - Allows people to appoint CMs besides themselves using `/cm id]`. - CMs can now freely leave the areas they CM in without losing CM status. - CMs that own an area, but aren't there, still show up in them when using `/getarea` with the `[RCM]` = Remote Case Manager tag. - CMs get all IC and OOC messages from their areas. - CMs can use `/s` to send a message to all the areas they own, or `/a [area_id]` to send a message only to a specific area. This is usable both IC and OOC. --- server/aoprotocol.py | 36 +++++++++++- server/area_manager.py | 37 +++++++++---- server/client_manager.py | 30 ++++++---- server/commands.py | 116 +++++++++++++++++++++++++++++---------- server/evidence.py | 6 +- 5 files changed, 172 insertions(+), 53 deletions(-) diff --git a/server/aoprotocol.py b/server/aoprotocol.py index bea9e35..bd022a4 100644 --- a/server/aoprotocol.py +++ b/server/aoprotocol.py @@ -335,6 +335,8 @@ class AOProtocol(asyncio.Protocol): 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, @@ -399,6 +401,28 @@ class AOProtocol(asyncio.Protocol): 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): @@ -441,7 +465,7 @@ class AOProtocol(asyncio.Protocol): button = 0 # Turn off the ding. ding = 0 - if color == 2 and not (self.client.is_mod or self.client.is_cm): + 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 @@ -498,6 +522,15 @@ class AOProtocol(asyncio.Protocol): 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) @@ -557,6 +590,7 @@ class AOProtocol(asyncio.Protocol): 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) diff --git a/server/area_manager.py b/server/area_manager.py index 68eea42..cfb2be0 100644 --- a/server/area_manager.py +++ b/server/area_manager.py @@ -54,7 +54,6 @@ class AreaManager: self.showname_changes_allowed = showname_changes_allowed self.shouts_allowed = shouts_allowed self.abbreviation = abbreviation - self.owned = False self.cards = dict() """ @@ -71,6 +70,8 @@ class AreaManager: self.jukebox_votes = [] self.jukebox_prev_char_id = -1 + self.owners = [] + class Locked(Enum): FREE = 1, SPECTATABLE = 2, @@ -84,12 +85,6 @@ class AreaManager: self.clients.remove(client) if len(self.clients) == 0: self.change_status('IDLE') - if client.is_cm: - client.is_cm = False - self.owned = False - self.server.area_manager.send_arup_cms() - if self.is_locked != self.Locked.FREE: - self.unlock() def unlock(self): self.is_locked = self.Locked.FREE @@ -102,6 +97,8 @@ class AreaManager: 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.') @@ -109,6 +106,8 @@ class AreaManager: 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.') @@ -124,9 +123,15 @@ class AreaManager: 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) @@ -300,6 +305,14 @@ class AreaManager: """ 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): @@ -365,6 +378,11 @@ class AreaManager: 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] @@ -382,9 +400,8 @@ class AreaManager: cms_list = [2] for area in self.areas: cm = 'FREE' - for client in area.clients: - if client.is_cm: - cm = client.get_char_name() + if len(area.owners) > 0: + cm = area.get_cms() cms_list.append(cm) self.server.send_arup(cms_list) diff --git a/server/client_manager.py b/server/client_manager.py index e7655bd..f5ef4ef 100644 --- a/server/client_manager.py +++ b/server/client_manager.py @@ -44,7 +44,6 @@ class ClientManager: self.is_dj = True self.can_wtce = True self.pos = '' - self.is_cm = False self.evi_list = [] self.disemvowel = False self.shaken = False @@ -140,7 +139,7 @@ class ClientManager: .format(self.area.abbreviation, old_char, self.get_char_name()), self) def change_music_cd(self): - if self.is_mod or self.is_cm: + 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']: @@ -157,7 +156,7 @@ class ClientManager: return 0 def wtce_mute(self): - if self.is_mod or self.is_cm: + 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']: @@ -218,10 +217,8 @@ class ClientManager: msg = '=== Areas ===' for i, area in enumerate(self.server.area_manager.areas): owner = 'FREE' - if area.owned: - for client in [x for x in area.clients if x.is_cm]: - owner = 'CM: {}'.format(client.get_char_name()) - break + 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: @@ -244,13 +241,19 @@ class ClientManager: 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.is_cm: - info +='[CM]' + 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) @@ -266,7 +269,7 @@ class ClientManager: 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: + 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 @@ -382,6 +385,13 @@ class ClientManager: 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) diff --git a/server/commands.py b/server/commands.py index 57b0c3f..992d0c7 100644 --- a/server/commands.py +++ b/server/commands.py @@ -23,6 +23,34 @@ 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) def ooc_cmd_switch(client, arg): if len(arg) == 0: @@ -90,7 +118,7 @@ def ooc_cmd_allow_iniswap(client, arg): return def ooc_cmd_allow_blankposting(client, arg): - if not client.is_mod and not client.is_cm: + 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'} @@ -98,7 +126,7 @@ def ooc_cmd_allow_blankposting(client, arg): return def ooc_cmd_force_nonint_pres(client, arg): - if not client.is_mod and not client.is_cm: + 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'} @@ -179,7 +207,7 @@ def ooc_cmd_currentmusic(client, arg): client.area.current_music_player)) def ooc_cmd_jukebox_toggle(client, arg): - if not client.is_mod and not client.is_cm: + 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.') @@ -188,7 +216,7 @@ def ooc_cmd_jukebox_toggle(client, arg): 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.is_cm: + 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.') @@ -276,7 +304,7 @@ def ooc_cmd_pos(client, arg): client.send_host_message('Position changed.') def ooc_cmd_forcepos(client, arg): - if not client.is_cm and not client.is_mod: + if not client in client.area.owners and not client.is_mod: raise ClientError('You must be authorized to do that.') args = arg.split() @@ -689,25 +717,55 @@ def ooc_cmd_evi_swap(client, arg): 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 client.area.owned == False: - client.area.owned = True - client.is_cm = True + 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.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.is_cm: - client.is_cm = False - client.area.owned = False - client.area.blankposting_allowed = True - if client.area.is_locked != client.area.Locked.FREE: - client.area.unlock() - client.server.area_manager.send_arup_cms() - client.area.send_host_message('{} is no longer CM in this area.'.format(client.get_char_name())) + 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 cannot give up being the CM when you are not one') + raise ClientError('You must be authorized to do that.') def ooc_cmd_unmod(client, arg): client.is_mod = False @@ -721,7 +779,7 @@ def ooc_cmd_area_lock(client, arg): return if client.area.is_locked == client.area.Locked.LOCKED: client.send_host_message('Area is already locked.') - if client.is_cm: + if client in client.area.owners: client.area.lock() return else: @@ -733,7 +791,7 @@ def ooc_cmd_area_spectate(client, arg): return if client.area.is_locked == client.area.Locked.SPECTATABLE: client.send_host_message('Area is already spectatable.') - if client.is_cm: + if client in client.area.owners: client.area.spectator() return else: @@ -742,7 +800,7 @@ def ooc_cmd_area_spectate(client, arg): 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.is_cm: + if not client in client.area.owners: raise ClientError('Only CM can unlock area.') client.area.unlock() client.send_host_message('Area is unlocked.') @@ -750,9 +808,9 @@ def ooc_cmd_area_unlock(client, arg): def ooc_cmd_invite(client, arg): if not arg: raise ClientError('You must specify a target. Use /invite ') - if not client.area.is_locked: + if client.area.is_locked == client.area.Locked.FREE: raise ClientError('Area isn\'t locked.') - if not client.is_cm and not client.is_mod: + 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] @@ -763,9 +821,9 @@ def ooc_cmd_invite(client, arg): raise ClientError('You must specify a target. Use /invite ') def ooc_cmd_uninvite(client, arg): - if not client.is_cm and not client.is_mod: + if not client in client.area.owners and not client.is_mod: raise ClientError('You must be authorized to do that.') - if not client.area.is_locked and not client.is_mod: + 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 ') @@ -776,7 +834,7 @@ def ooc_cmd_uninvite(client, arg): 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: + if client.area.is_locked != client.area.Locked.FREE: client.area.invite_list.pop(c.id) except AreaError: raise @@ -788,7 +846,7 @@ def ooc_cmd_uninvite(client, arg): def ooc_cmd_area_kick(client, arg): if not client.is_mod: raise ClientError('You must be authorized to do that.') - if not client.area.is_locked and not client.is_mod: + 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 #]') @@ -809,7 +867,7 @@ def ooc_cmd_area_kick(client, arg): 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: + if client.area.is_locked != client.area.Locked.FREE: client.area.invite_list.pop(c.id) except AreaError: raise @@ -1070,7 +1128,7 @@ def ooc_cmd_notecard_clear(client, arg): raise ClientError('You do not have a note card.') def ooc_cmd_notecard_reveal(client, arg): - if not client.is_cm and not client.is_mod: + 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.') diff --git a/server/evidence.py b/server/evidence.py index efa2e25..b34172a 100644 --- a/server/evidence.py +++ b/server/evidence.py @@ -39,13 +39,13 @@ class EvidenceList: if client.area.evidence_mod == 'FFA': pass if client.area.evidence_mod == 'Mods': - if not client.is_cm: + if not client in client.area.owners: return False if client.area.evidence_mod == 'CM': - if not client.is_cm and not client.is_mod: + if not client in client.area.owners and not client.is_mod: return False if client.area.evidence_mod == 'HiddenCM': - if not client.is_cm and not client.is_mod: + if not client in client.area.owners and not client.is_mod: return False return True From c68c9daf27294698c6b4ae249f1ba7d817f10f89 Mon Sep 17 00:00:00 2001 From: Cerapter Date: Tue, 18 Sep 2018 21:17:57 +0200 Subject: [PATCH 145/174] CMs now get `/rollp` results + KK and KB package. --- server/commands.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/server/commands.py b/server/commands.py index 992d0c7..5f0128a 100644 --- a/server/commands.py +++ b/server/commands.py @@ -185,11 +185,9 @@ def ooc_cmd_rollp(client, arg): roll = '(' + roll + ')' client.send_host_message('{} rolled {} out of {}.'.format(client.get_char_name(), roll, val[0])) - for c in client.area.clients: - if c.is_cm: - c.send_host_message('{} secretly rolled {} out of {}.'.format(client.get_char_name(), roll, val[0])) - else: - c.send_host_message('{} rolled in secret.'.format(client.get_char_name())) + 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) @@ -371,6 +369,7 @@ def ooc_cmd_kick(client, arg): 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)) @@ -395,6 +394,7 @@ def ooc_cmd_ban(client, arg): 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)) From ee5b4b92de11dafbabb2f9b7c695d174e2a13694 Mon Sep 17 00:00:00 2001 From: Cerapter Date: Tue, 18 Sep 2018 21:58:39 +0200 Subject: [PATCH 146/174] Fixed a typo. --- server/aoprotocol.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/aoprotocol.py b/server/aoprotocol.py index bd022a4..1c6146e 100644 --- a/server/aoprotocol.py +++ b/server/aoprotocol.py @@ -611,7 +611,7 @@ class AOProtocol(asyncio.Protocol): if not self.client.is_dj: self.client.send_host_message('You were blockdj\'d by a moderator.') return - if area.cannot_ic_interact(self.client): + 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): From 34465189a34975f6eed125bce4c4faee501c57d5 Mon Sep 17 00:00:00 2001 From: Cerapter Date: Tue, 18 Sep 2018 22:21:40 +0200 Subject: [PATCH 147/174] Fixed OOC messages they sent not showing for the CM in other areas. --- server/commands.py | 1 + 1 file changed, 1 insertion(+) diff --git a/server/commands.py b/server/commands.py index 5f0128a..aae12de 100644 --- a/server/commands.py +++ b/server/commands.py @@ -51,6 +51,7 @@ def message_areas_cm(client, areas, message): 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: From 83d29ff2c94f7ef9420c302c1dc114d0b5b8041d Mon Sep 17 00:00:00 2001 From: Cerapter Date: Wed, 19 Sep 2018 18:21:51 +0200 Subject: [PATCH 148/174] Bumed version to 1.4.0 --- aoapplication.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/aoapplication.h b/aoapplication.h index c7066d9..dc8071e 100644 --- a/aoapplication.h +++ b/aoapplication.h @@ -271,8 +271,8 @@ private: const int MINOR_VERSION = 10; const int CCCC_RELEASE = 1; - const int CCCC_MAJOR_VERSION = 3; - const int CCCC_MINOR_VERSION = 1; + const int CCCC_MAJOR_VERSION = 4; + const int CCCC_MINOR_VERSION = 0; QString current_theme = "default"; From b73036724aea682c3860a04968e71f911a08ea18 Mon Sep 17 00:00:00 2001 From: Cerapter Date: Thu, 20 Sep 2018 16:41:32 +0200 Subject: [PATCH 149/174] Rolled all the special IC stuff into one FL packet piece. So now, a standard CCCC server uses three bonus packets: `modcall_reason`, `cccc_ic_support` and `arup`. --- aoapplication.h | 3 +- courtroom.cpp | 65 ++++++++++++++++++++++------------------- packet_distribution.cpp | 9 ++---- server/aoprotocol.py | 10 +++---- 4 files changed, 44 insertions(+), 43 deletions(-) diff --git a/aoapplication.h b/aoapplication.h index dc8071e..ecb33fb 100644 --- a/aoapplication.h +++ b/aoapplication.h @@ -69,8 +69,7 @@ public: bool improved_loading_enabled = false; bool desk_mod_enabled = false; bool evidence_enabled = false; - bool shownames_enabled = false; - bool charpairs_enabled = false; + bool cccc_ic_support_enabled = false; bool arup_enabled = false; bool modcall_reason_enabled = false; diff --git a/courtroom.cpp b/courtroom.cpp index 347e889..0a9baef 100644 --- a/courtroom.cpp +++ b/courtroom.cpp @@ -208,6 +208,7 @@ Courtroom::Courtroom(AOApplication *p_ao_app) : QMainWindow() 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); @@ -470,7 +471,7 @@ void Courtroom::set_widgets() ui_pair_offset_spinbox->hide(); set_size_and_pos(ui_pair_button, "pair_button"); ui_pair_button->set_image("pair_button.png"); - if (ao_app->charpairs_enabled) + if (ao_app->cccc_ic_support_enabled) { ui_pair_button->setEnabled(true); ui_pair_button->show(); @@ -583,7 +584,6 @@ void Courtroom::set_widgets() ui_pre->setText("Pre"); set_size_and_pos(ui_pre_non_interrupt, "pre_no_interrupt"); - ui_pre_non_interrupt->setText("No Intrpt"); set_size_and_pos(ui_flip, "flip"); @@ -864,6 +864,11 @@ void Courtroom::enter_courtroom(int p_cid) else ui_flip->hide(); + if (ao_app->cccc_ic_support_enabled) + ui_pre_non_interrupt->show(); + else + ui_pre_non_interrupt->hide(); + list_music(); list_areas(); @@ -879,7 +884,7 @@ void Courtroom::enter_courtroom(int p_cid) //ui_server_chatlog->setHtml(ui_server_chatlog->toHtml()); ui_char_select_background->hide(); - if (ao_app->shownames_enabled) + if (ao_app->cccc_ic_support_enabled) { ui_ic_chat_name->setPlaceholderText(ao_app->get_showname(f_char)); ui_ic_chat_name->setEnabled(true); @@ -1159,39 +1164,41 @@ void Courtroom::on_chat_return_pressed() packet_contents.append(f_text_color); - if (!ui_ic_chat_name->text().isEmpty()) + // If the server we're on supports CCCC stuff, we should use it! + if (ao_app->cccc_ic_support_enabled) { - packet_contents.append(ui_ic_chat_name->text()); - } - - // If there is someone this user would like to appear with. - // And said someone is not ourselves! - if (other_charid > -1 && other_charid != m_cid) - { - // First, we'll add a filler in case we haven't set an IC showname. - if (ui_ic_chat_name->text().isEmpty()) + // 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(""); } - packet_contents.append(QString::number(other_charid)); - packet_contents.append(QString::number(offset_with_pair)); - } - - if (ui_pre_non_interrupt->isChecked()) - { - if (ui_ic_chat_name->text().isEmpty()) + // 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(""); + packet_contents.append(QString::number(other_charid)); + packet_contents.append(QString::number(offset_with_pair)); } - - if (!(other_charid > -1 && other_charid != m_cid)) + else { packet_contents.append("-1"); packet_contents.append("0"); } - packet_contents.append("1"); + // Finally, we send over if we want our pres to not interrupt. + if (ui_pre_non_interrupt->isChecked()) + { + packet_contents.append("1"); + } + else + { + packet_contents.append("0"); + } } ao_app->send_server_packet(new AOPacket("MS", packet_contents)); @@ -1205,23 +1212,22 @@ void Courtroom::handle_chatmessage(QStringList *p_contents) if (p_contents->size() < 15) return; - //qDebug() << "A message was got. Its contents:"; for (int n_string = 0 ; n_string < chatmessage_size ; ++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()) + if (n_string < p_contents->size() && + (n_string < 15 || ao_app->cccc_ic_support_enabled)) { m_chatmessage[n_string] = p_contents->at(n_string); - //qDebug() << "- " << n_string << ": " << p_contents->at(n_string); } else { m_chatmessage[n_string] = ""; - //qDebug() << "- " << n_string << ": Nothing?"; } } @@ -2771,8 +2777,7 @@ void Courtroom::on_ooc_return_pressed() 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->shownames_enabled = true; - ao_app->charpairs_enabled = true; + ao_app->cccc_ic_support_enabled = true; ao_app->arup_enabled = true; ao_app->modcall_reason_enabled = true; on_reload_theme_clicked(); diff --git a/packet_distribution.cpp b/packet_distribution.cpp index 8d23fe5..a0d3cca 100644 --- a/packet_distribution.cpp +++ b/packet_distribution.cpp @@ -147,8 +147,7 @@ void AOApplication::server_packet_received(AOPacket *p_packet) improved_loading_enabled = false; desk_mod_enabled = false; evidence_enabled = false; - shownames_enabled = false; - charpairs_enabled = false; + cccc_ic_support_enabled = false; arup_enabled = false; modcall_reason_enabled = false; @@ -201,10 +200,8 @@ 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("cc_customshownames",Qt::CaseInsensitive)) - shownames_enabled = true; - if (f_packet.contains("characterpairs",Qt::CaseInsensitive)) - charpairs_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("modcall_reason",Qt::CaseInsensitive)) diff --git a/server/aoprotocol.py b/server/aoprotocol.py index 1c6146e..18f688b 100644 --- a/server/aoprotocol.py +++ b/server/aoprotocol.py @@ -213,7 +213,7 @@ class AOProtocol(asyncio.Protocol): self.client.is_ao2 = True - self.client.send_command('FL', 'yellowtext', 'customobjections', 'flipping', 'fastloading', 'noencryption', 'deskmod', 'evidence', 'modcall_reason', 'cc_customshownames', 'characterpairs', 'arup') + self.client.send_command('FL', 'yellowtext', 'customobjections', 'flipping', 'fastloading', 'noencryption', 'deskmod', 'evidence', 'modcall_reason', 'cccc_ic_support', 'arup') def net_cmd_ch(self, _): """ Periodically checks the connection. @@ -348,7 +348,7 @@ class AOProtocol(asyncio.Protocol): showname = "" charid_pair = -1 offset_pair = 0 - nonint_pre = '' + 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, @@ -358,7 +358,7 @@ class AOProtocol(asyncio.Protocol): 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 = '' + 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 @@ -369,7 +369,7 @@ class AOProtocol(asyncio.Protocol): 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 = '' + 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 @@ -442,7 +442,7 @@ class AOProtocol(asyncio.Protocol): if len(showname) > 15: self.client.send_host_message("Your IC showname is way too long!") return - if nonint_pre != '': + if nonint_pre == 1: if button in (1, 2, 3, 4, 23): if anim_type == 1 or anim_type == 2: anim_type = 0 From 75cc04225bf5814623a6f2d0a197a75684760873 Mon Sep 17 00:00:00 2001 From: Cerapter Date: Thu, 20 Sep 2018 17:58:44 +0200 Subject: [PATCH 150/174] Updated the readme. --- README.md | 158 +++++++++++++++++++++++++++++++++--------------------- 1 file changed, 97 insertions(+), 61 deletions(-) diff --git a/README.md b/README.md index 913b174..3cdd5ec 100644 --- a/README.md +++ b/README.md @@ -9,80 +9,116 @@ Alternatively, you may wait till I make some stuff, and release a compiled execu ## 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. + - `()` (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. + - 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. + - 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. + - 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`. + - 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. +- **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. + - 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 `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. - - 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`. - - 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. + - 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`. + - 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. --- From 1ddfdb34b1e158f4de790b63385b4e9cbebdbefe Mon Sep 17 00:00:00 2001 From: Cerapter Date: Thu, 20 Sep 2018 18:41:40 +0200 Subject: [PATCH 151/174] Fixed a small bug regarding music changes while shownamed. --- server/aoprotocol.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/server/aoprotocol.py b/server/aoprotocol.py index 18f688b..1bf9001 100644 --- a/server/aoprotocol.py +++ b/server/aoprotocol.py @@ -627,10 +627,10 @@ class AOProtocol(asyncio.Protocol): if self.client.area.jukebox: showname = '' if len(args) > 2: - if len(args[2]) > 0 and not self.client.area.showname_changes_allowed: + 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 - showname = args[2] 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: From 1ea16339e086dc6cf3ade9cc3080b7c9d2b907ee Mon Sep 17 00:00:00 2001 From: Cerapter Date: Thu, 20 Sep 2018 18:46:21 +0200 Subject: [PATCH 152/174] ...And the same with the client, too! --- courtroom.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/courtroom.cpp b/courtroom.cpp index 0a9baef..14a2d58 100644 --- a/courtroom.cpp +++ b/courtroom.cpp @@ -3059,7 +3059,7 @@ void Courtroom::on_music_list_double_clicked(QModelIndex p_model) QString p_song = music_list.at(music_row_to_number.at(p_model.row())); - if (!ui_ic_chat_name->text().isEmpty()) + 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); } From ab49e69067bf0d6f0c9591602f03ed61b21214c7 Mon Sep 17 00:00:00 2001 From: Cerapter Date: Thu, 20 Sep 2018 22:13:03 +0200 Subject: [PATCH 153/174] Added the ability to give characters custom realisation sounds. --- aoapplication.h | 3 +++ courtroom.cpp | 2 +- text_file_functions.cpp | 9 +++++++++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/aoapplication.h b/aoapplication.h index ecb33fb..dc77014 100644 --- a/aoapplication.h +++ b/aoapplication.h @@ -234,6 +234,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); diff --git a/courtroom.cpp b/courtroom.cpp index 14a2d58..418bacd 100644 --- a/courtroom.cpp +++ b/courtroom.cpp @@ -1557,7 +1557,7 @@ void Courtroom::handle_chatmessage_3() { realization_timer->start(60); ui_vp_realization->show(); - sfx_player->play(ao_app->get_sfx("realization")); + sfx_player->play(ao_app->get_custom_realization(m_chatmessage[CHAR_NAME])); } int f_evi_id = m_chatmessage[EVIDENCE_ID].toInt(); diff --git a/text_file_functions.cpp b/text_file_functions.cpp index 35d2788..be3d7a7 100644 --- a/text_file_functions.cpp +++ b/text_file_functions.cpp @@ -497,6 +497,15 @@ int AOApplication::get_text_delay(QString p_char, QString p_emote) 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 result = configini->value("blank_blip", "false").value(); From ff0f8c268a36129635a8d9f459a9e511b599260f Mon Sep 17 00:00:00 2001 From: Cerapter Date: Thu, 20 Sep 2018 23:14:32 +0200 Subject: [PATCH 154/174] Full stops force the idle anim to play. --- courtroom.cpp | 34 +++++++++++++++++++++++++++++++++- courtroom.h | 2 ++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/courtroom.cpp b/courtroom.cpp index 418bacd..48e456f 100644 --- a/courtroom.cpp +++ b/courtroom.cpp @@ -2072,6 +2072,9 @@ void Courtroom::start_chat_ticking() // let's set it to false. inline_blue_depth = 0; + // And also, reset the fullstop bool. + previous_character_is_fullstop = false; + // 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]); @@ -2225,7 +2228,8 @@ void Courtroom::chat_tick() // If it isn't, we start talking if we have completely climbed out of inline blues. if (!entire_message_is_blue) { - if (inline_blue_depth == 0 and anim_state != 4) + // 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]; @@ -2285,6 +2289,20 @@ void Courtroom::chat_tick() } } + // Silencing the character during long times of ellipses. + else if (f_character == "." and !next_character_is_not_special and !previous_character_is_fullstop) + { + if (!previous_character_is_fullstop && inline_blue_depth == 0 && !entire_message_is_blue) + { + QString f_char = m_chatmessage[CHAR_NAME]; + QString f_emote = m_chatmessage[EMOTE]; + ui_vp_player_char->play_idle(f_char, f_emote); + } + previous_character_is_fullstop = true; + next_character_is_not_special = true; + formatting_char = true; + tick_pos--; + } else { next_character_is_not_special = false; @@ -2324,6 +2342,20 @@ void Courtroom::chat_tick() } } + // Basically only go back to talkin if: + // - This character is not a fullstop + // - But the previous character was + // - And we're out of inline blues + // - And the entire messages isn't blue + // - And this isn't the last character. + if (f_character != "." && previous_character_is_fullstop && inline_blue_depth == 0 && !entire_message_is_blue && 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); + previous_character_is_fullstop = false; + } + QScrollBar *scroll = ui_vp_message->verticalScrollBar(); scroll->setValue(scroll->maximum()); diff --git a/courtroom.h b/courtroom.h index 1115e36..4aa4f00 100644 --- a/courtroom.h +++ b/courtroom.h @@ -227,6 +227,8 @@ private: bool next_character_is_not_special = false; // If true, write the // next character as it is. + bool previous_character_is_fullstop = false; // Used for silencing the character during long ellipses. + bool message_is_centered = false; int current_display_speed = 3; From 21aaa90c44408942ec77236cfc1a721f08ad7b55 Mon Sep 17 00:00:00 2001 From: Cerapter Date: Thu, 20 Sep 2018 23:32:32 +0200 Subject: [PATCH 155/174] Made objections not necessarily play a pre, unless you have Pre ticked. --- courtroom.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/courtroom.cpp b/courtroom.cpp index 48e456f..109ffa6 100644 --- a/courtroom.cpp +++ b/courtroom.cpp @@ -1095,10 +1095,13 @@ 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() and !ui_pre_non_interrupt->isChecked()) { From 3c07f27be79f1f72eec731218ba7dd3fd6470153 Mon Sep 17 00:00:00 2001 From: Cerapter Date: Sun, 23 Sep 2018 11:19:14 +0200 Subject: [PATCH 156/174] Generalised the music extension remover. --- courtroom.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/courtroom.cpp b/courtroom.cpp index 109ffa6..3547532 100644 --- a/courtroom.cpp +++ b/courtroom.cpp @@ -915,7 +915,7 @@ void Courtroom::list_music() { QString i_song = music_list.at(n_song); QString i_song_listname = i_song; - i_song_listname.replace(".mp3",""); + i_song_listname = i_song_listname.left(i_song_listname.lastIndexOf(".")); if (i_song.toLower().contains(ui_music_search->text().toLower())) { @@ -2599,7 +2599,7 @@ void Courtroom::handle_song(QStringList *p_contents) QString f_song = f_contents.at(0); QString f_song_clear = f_song; - f_song_clear.replace(".mp3", ""); + 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()) From 795dea1ad2b0e69c212ef174e17a63b34f3fde37 Mon Sep 17 00:00:00 2001 From: Cerapter Date: Sun, 23 Sep 2018 14:09:10 +0200 Subject: [PATCH 157/174] Some UI bugfixes in regards to custom client features shown + nonint-pre fixes. --- courtroom.cpp | 54 +++++++++++++++++++++++++-------------------------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/courtroom.cpp b/courtroom.cpp index 3547532..b8b5e5a 100644 --- a/courtroom.cpp +++ b/courtroom.cpp @@ -407,6 +407,31 @@ 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); + } + + // 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()); @@ -471,16 +496,6 @@ void Courtroom::set_widgets() ui_pair_offset_spinbox->hide(); set_size_and_pos(ui_pair_button, "pair_button"); ui_pair_button->set_image("pair_button.png"); - if (ao_app->cccc_ic_support_enabled) - { - ui_pair_button->setEnabled(true); - ui_pair_button->show(); - } - else - { - ui_pair_button->setEnabled(false); - ui_pair_button->hide(); - } set_size_and_pos(ui_area_list, "music_list"); ui_area_list->setStyleSheet("background-color: rgba(0, 0, 0, 0);"); @@ -864,11 +879,6 @@ void Courtroom::enter_courtroom(int p_cid) else ui_flip->hide(); - if (ao_app->cccc_ic_support_enabled) - ui_pre_non_interrupt->show(); - else - ui_pre_non_interrupt->hide(); - list_music(); list_areas(); @@ -884,16 +894,6 @@ void Courtroom::enter_courtroom(int p_cid) //ui_server_chatlog->setHtml(ui_server_chatlog->toHtml()); ui_char_select_background->hide(); - if (ao_app->cccc_ic_support_enabled) - { - ui_ic_chat_name->setPlaceholderText(ao_app->get_showname(f_char)); - ui_ic_chat_name->setEnabled(true); - } - else - { - ui_ic_chat_name->setPlaceholderText("---"); - ui_ic_chat_name->setEnabled(false); - } ui_ic_chat_message->setEnabled(m_cid != -1); ui_ic_chat_message->setFocus(); @@ -1194,7 +1194,7 @@ void Courtroom::on_chat_return_pressed() } // Finally, we send over if we want our pres to not interrupt. - if (ui_pre_non_interrupt->isChecked()) + if (ui_pre_non_interrupt->isChecked() && ui_pre->isChecked()) { packet_contents.append("1"); } @@ -1545,7 +1545,7 @@ void Courtroom::handle_chatmessage_2() qDebug() << "W: invalid emote mod: " << QString::number(emote_mod); //intentional fallthru case 0: case 5: - if (m_chatmessage[NONINTERRUPTING_PRE].isEmpty()) + if (m_chatmessage[NONINTERRUPTING_PRE].toInt() == 0) handle_chatmessage_3(); else play_noninterrupting_preanim(); From c17fe46e769878de97303f11a990809f27e8212b Mon Sep 17 00:00:00 2001 From: Cerapter Date: Mon, 24 Sep 2018 22:00:16 +0200 Subject: [PATCH 158/174] Added the ability to change the showname's colour. --- courtroom.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/courtroom.cpp b/courtroom.cpp index b8b5e5a..3323b6f 100644 --- a/courtroom.cpp +++ b/courtroom.cpp @@ -1369,6 +1369,8 @@ void Courtroom::handle_chatmessage_2() 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(); From 5930bf569b7e1c4e51034a072fe3436465812a86 Mon Sep 17 00:00:00 2001 From: Cerapter Date: Fri, 28 Sep 2018 16:14:44 +0200 Subject: [PATCH 159/174] Made it so that AOCharMovie accepts both excessively wide and excessively tall sprites. They are resized and centered appropriately. --- aocharmovie.cpp | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/aocharmovie.cpp b/aocharmovie.cpp index 56912a4..4170855 100644 --- a/aocharmovie.cpp +++ b/aocharmovie.cpp @@ -146,17 +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; + + 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(), Qt::KeepAspectRatioByExpanding, Qt::SmoothTransformation)); + this->setPixmap(f_pixmap.scaled(this->width(), this->height(), aspect_ratio, Qt::SmoothTransformation)); else - this->setPixmap(f_pixmap.scaled(this->width(), this->height(), Qt::KeepAspectRatioByExpanding, Qt::FastTransformation)); - } + 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) { From 8138068d51cbff955de457c242c391bec5d0f163 Mon Sep 17 00:00:00 2001 From: Cerapter Date: Sun, 30 Sep 2018 00:11:42 +0200 Subject: [PATCH 160/174] I totally forgot this, it seems. --- aocharmovie.h | 6 ++++++ 1 file changed, 6 insertions(+) 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; From 265714d9d5312e5981ed71f2d5eae20078e5b633 Mon Sep 17 00:00:00 2001 From: Cerapter Date: Wed, 3 Oct 2018 21:24:13 +0200 Subject: [PATCH 161/174] Added support for opus files on Linux. --- courtroom.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/courtroom.cpp b/courtroom.cpp index 3323b6f..c38a607 100644 --- a/courtroom.cpp +++ b/courtroom.cpp @@ -23,6 +23,7 @@ Courtroom::Courtroom(AOApplication *p_ao_app) : QMainWindow() { BASS_Init(-1, 48000, BASS_DEVICE_LATENCY, 0, NULL); BASS_PluginLoad("bassopus.dll", BASS_UNICODE); + BASS_PluginLoad("libbassopus.so", 0); } else { @@ -33,6 +34,7 @@ Courtroom::Courtroom(AOApplication *p_ao_app) : QMainWindow() BASS_SetDevice(a); BASS_Init(a, 48000, BASS_DEVICE_LATENCY, 0, NULL); BASS_PluginLoad("bassopus.dll", BASS_UNICODE); + BASS_PluginLoad("libbassopus.so", 0); qDebug() << info.name << "was set as the default audio output device."; break; } From 546d3c897031d2b6f1c36c4b9cd94e3b9e0e62b9 Mon Sep 17 00:00:00 2001 From: Cerapter Date: Tue, 23 Oct 2018 09:33:58 +0200 Subject: [PATCH 162/174] Moved bassopus stuff to its own function. Not that it works, so whatever. --- courtroom.cpp | 20 ++++++++++++++++---- courtroom.h | 2 ++ 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/courtroom.cpp b/courtroom.cpp index c38a607..2d5468e 100644 --- a/courtroom.cpp +++ b/courtroom.cpp @@ -22,8 +22,7 @@ Courtroom::Courtroom(AOApplication *p_ao_app) : QMainWindow() if (ao_app->get_audio_output_device() == "Default") { BASS_Init(-1, 48000, BASS_DEVICE_LATENCY, 0, NULL); - BASS_PluginLoad("bassopus.dll", BASS_UNICODE); - BASS_PluginLoad("libbassopus.so", 0); + load_bass_opus_plugin(); } else { @@ -33,8 +32,7 @@ Courtroom::Courtroom(AOApplication *p_ao_app) : QMainWindow() { BASS_SetDevice(a); BASS_Init(a, 48000, BASS_DEVICE_LATENCY, 0, NULL); - BASS_PluginLoad("bassopus.dll", BASS_UNICODE); - BASS_PluginLoad("libbassopus.so", 0); + load_bass_opus_plugin(); qDebug() << info.name << "was set as the default audio output device."; break; } @@ -3514,3 +3512,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 4aa4f00..1ee09cd 100644 --- a/courtroom.h +++ b/courtroom.h @@ -645,6 +645,8 @@ private slots: void on_switch_area_music_clicked(); void ping_server(); + + void load_bass_opus_plugin(); }; #endif // COURTROOM_H From 3f41ed134121bfcf6e1bbbbac9fcd1aad49fbd6b Mon Sep 17 00:00:00 2001 From: Cerapter Date: Tue, 23 Oct 2018 09:51:53 +0200 Subject: [PATCH 163/174] Fixed the fullstop-silence bug. Made it so that characters correctly switch to-and-fro idle / talking anims during full stops, and don't interrupt non-interrupting pres. --- courtroom.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/courtroom.cpp b/courtroom.cpp index 2d5468e..bd206cf 100644 --- a/courtroom.cpp +++ b/courtroom.cpp @@ -2297,7 +2297,7 @@ void Courtroom::chat_tick() // Silencing the character during long times of ellipses. else if (f_character == "." and !next_character_is_not_special and !previous_character_is_fullstop) { - if (!previous_character_is_fullstop && inline_blue_depth == 0 && !entire_message_is_blue) + if (!previous_character_is_fullstop && inline_blue_depth == 0 && !entire_message_is_blue && anim_state != 4) { QString f_char = m_chatmessage[CHAR_NAME]; QString f_emote = m_chatmessage[EMOTE]; @@ -2352,8 +2352,9 @@ void Courtroom::chat_tick() // - But the previous character was // - And we're out of inline blues // - And the entire messages isn't blue + // - And we aren't still in a non-interrupting pre // - And this isn't the last character. - if (f_character != "." && previous_character_is_fullstop && inline_blue_depth == 0 && !entire_message_is_blue && tick_pos+1 >= f_message.size()) + if (f_character != "." && previous_character_is_fullstop && inline_blue_depth == 0 && !entire_message_is_blue && anim_state != 4 && tick_pos+1 <= f_message.size()) { QString f_char = m_chatmessage[CHAR_NAME]; QString f_emote = m_chatmessage[EMOTE]; From bed38e0b7f42629c373e6a78b482541f1b3a4294 Mon Sep 17 00:00:00 2001 From: Cerapter Date: Tue, 23 Oct 2018 10:06:04 +0200 Subject: [PATCH 164/174] Fixed charselect showing the wrong amount of characters on its list, version bump. --- aoapplication.h | 2 +- charselect.cpp | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/aoapplication.h b/aoapplication.h index dc77014..aa34f13 100644 --- a/aoapplication.h +++ b/aoapplication.h @@ -274,7 +274,7 @@ private: const int CCCC_RELEASE = 1; const int CCCC_MAJOR_VERSION = 4; - const int CCCC_MINOR_VERSION = 0; + const int CCCC_MINOR_VERSION = 1; QString current_theme = "default"; diff --git a/charselect.cpp b/charselect.cpp index ac73ac2..54286b2 100644 --- a/charselect.cpp +++ b/charselect.cpp @@ -158,6 +158,8 @@ void Courtroom::put_button_in_place(int starting, int chars_on_this_page) 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) { From fc72ff42345fdda694cd6cf62a77c6cc99a59bc5 Mon Sep 17 00:00:00 2001 From: Cerapter Date: Tue, 23 Oct 2018 10:39:54 +0200 Subject: [PATCH 165/174] The connect button is disabled until you get an FL package from a server. --- lobby.cpp | 9 +++++++++ lobby.h | 1 + packet_distribution.cpp | 2 ++ 3 files changed, 12 insertions(+) diff --git a/lobby.cpp b/lobby.cpp index 9a649be..8a98632 100644 --- a/lobby.cpp +++ b/lobby.cpp @@ -48,6 +48,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(); } @@ -311,6 +313,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); } @@ -371,6 +375,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 49d3d80..19276a7 100644 --- a/lobby.h +++ b/lobby.h @@ -37,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/packet_distribution.cpp b/packet_distribution.cpp index a0d3cca..6a11958 100644 --- a/packet_distribution.cpp +++ b/packet_distribution.cpp @@ -206,6 +206,8 @@ void AOApplication::server_packet_received(AOPacket *p_packet) arup_enabled = true; if (f_packet.contains("modcall_reason",Qt::CaseInsensitive)) modcall_reason_enabled = true; + + w_lobby->enable_connect_button(); } else if (header == "PN") { From bbf8d103b31d5bddc277b28c0245c2ab3e399fe6 Mon Sep 17 00:00:00 2001 From: Cerapter Date: Tue, 23 Oct 2018 10:52:59 +0200 Subject: [PATCH 166/174] Changed dropdown menus so they activate even if you click an item in them. --- courtroom.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/courtroom.cpp b/courtroom.cpp index bd206cf..b71c97b 100644 --- a/courtroom.cpp +++ b/courtroom.cpp @@ -271,8 +271,8 @@ Courtroom::Courtroom(AOApplication *p_ao_app) : QMainWindow() connect(ui_emote_left, SIGNAL(clicked()), this, SLOT(on_emote_left_clicked())); 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_emote_dropdown, SIGNAL(currentIndexChanged(int)), this, SLOT(on_emote_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))); From 3844827724f5a65fff87ce861700471283317e47 Mon Sep 17 00:00:00 2001 From: Cerapter Date: Tue, 23 Oct 2018 11:49:31 +0200 Subject: [PATCH 167/174] Fixed a bug regarding ARUP that caused crashes. --- courtroom.h | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/courtroom.h b/courtroom.h index 1ee09cd..46a23d8 100644 --- a/courtroom.h +++ b/courtroom.h @@ -77,19 +77,23 @@ public: { if (type == 0) { - arup_players[place] = value.toInt(); + if (arup_players.size() > place) + arup_players[place] = value.toInt(); } else if (type == 1) { - arup_statuses[place] = value; + if (arup_statuses.size() > place) + arup_statuses[place] = value; } else if (type == 2) { - arup_cms[place] = value; + if (arup_cms.size() > place) + arup_cms[place] = value; } else if (type == 3) { - arup_locks[place] = value; + if (arup_locks.size() > place) + arup_locks[place] = value; } list_areas(); } From 660daf9922e68eb5f5f6bb00eb3bc51d0c460de7 Mon Sep 17 00:00:00 2001 From: Cerapter Date: Tue, 23 Oct 2018 14:54:36 +0200 Subject: [PATCH 168/174] Client can now accept case alerts. - Settings has a new tab with casing settings. - Can set when the game should alert of cases. - In game tickbox to toggle if you should be alerted of cases. --- aoapplication.h | 26 +++++++++ aooptionsdialog.cpp | 125 +++++++++++++++++++++++++++++++++++++++- aooptionsdialog.h | 22 +++++++ courtroom.cpp | 49 +++++++++++++++- courtroom.h | 5 ++ packet_distribution.cpp | 10 ++++ text_file_functions.cpp | 39 +++++++++++++ 7 files changed, 273 insertions(+), 3 deletions(-) diff --git a/aoapplication.h b/aoapplication.h index aa34f13..e106bcc 100644 --- a/aoapplication.h +++ b/aoapplication.h @@ -71,6 +71,7 @@ public: 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/////////////////// @@ -267,6 +268,31 @@ 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 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; diff --git a/aooptionsdialog.cpp b/aooptionsdialog.cpp index 7d307dd..813c8cd 100644 --- a/aooptionsdialog.cpp +++ b/aooptionsdialog.cpp @@ -186,7 +186,7 @@ AOOptionsDialog::AOOptionsDialog(QWidget *parent, AOApplication *p_ao_app) : QDi CallwordsLayout->addWidget(CallwordsExplainLabel); - // And finally, the Audio tab. + // The audio tab. AudioTab = new QWidget(); SettingsTabs->addTab(AudioTab, "Audio"); @@ -299,6 +299,121 @@ AOOptionsDialog::AOOptionsDialog(QWidget *parent, AOApplication *p_ao_app) : QDi 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); + + // -- 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(6, QFormLayout::LabelRole, CMLabel); + + CMCheckbox = new QCheckBox(formLayoutWidget_3); + CMCheckbox->setChecked(ao_app->get_casing_cm_enabled()); + + CasingForm->setWidget(6, 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(7, QFormLayout::LabelRole, CMCasesLabel); + + CMCasesLineEdit = new QLineEdit(formLayoutWidget_3); + CMCasesLineEdit->setText(ao_app->get_casing_can_host_cases()); + + CasingForm->setWidget(7, QFormLayout::FieldRole, CMCasesLineEdit); + // When we're done, we should continue the updates! setUpdatesEnabled(true); } @@ -336,6 +451,14 @@ void AOOptionsDialog::save_pressed() 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_cm_enabled", CMCheckbox->isChecked()); + configini->setValue("casing_can_host_casees", CMCasesLineEdit->text()); + callwordsini->close(); done(0); } diff --git a/aooptionsdialog.h b/aooptionsdialog.h index a48bff9..bbc81ed 100644 --- a/aooptionsdialog.h +++ b/aooptionsdialog.h @@ -34,6 +34,7 @@ private: QVBoxLayout *verticalLayout; QTabWidget *SettingsTabs; + QWidget *GameplayTab; QWidget *formLayoutWidget; QFormLayout *GameplayForm; @@ -54,12 +55,14 @@ private: 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; @@ -79,6 +82,25 @@ private: 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 *CMLabel; + QCheckBox *CMCheckbox; + QLabel *CMCasesLabel; + QLineEdit *CMCasesLineEdit; + bool needs_default_audiodev(); signals: diff --git a/courtroom.cpp b/courtroom.cpp index b71c97b..4426caa 100644 --- a/courtroom.cpp +++ b/courtroom.cpp @@ -201,10 +201,14 @@ 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_showname_enable->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("Custom shownames"); + ui_showname_enable->setText("Shownames"); ui_pre_non_interrupt = new QCheckBox(this); ui_pre_non_interrupt->setText("No Intrpt"); @@ -323,6 +327,7 @@ Courtroom::Courtroom(AOApplication *p_ao_app) : QMainWindow() 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())); @@ -599,11 +604,12 @@ void Courtroom::set_widgets() 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"); @@ -879,6 +885,11 @@ 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(); @@ -2697,6 +2708,22 @@ void Courtroom::mod_called(QString p_ip) } } +void Courtroom::case_called(QString msg, bool def, bool pro, bool jud, bool jur) +{ + 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)) + { + 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(); @@ -3506,6 +3533,24 @@ 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()) + + "#%")); + else + ao_app->send_server_packet(new AOPacket("CT#" + ui_ooc_chat_name->text() + "#/setcase \"\" 0 0 0 0 0#%")); + } +} + Courtroom::~Courtroom() { delete music_player; diff --git a/courtroom.h b/courtroom.h index 46a23d8..2b60db5 100644 --- a/courtroom.h +++ b/courtroom.h @@ -460,6 +460,7 @@ private: QCheckBox *ui_pre; QCheckBox *ui_flip; QCheckBox *ui_guard; + QCheckBox *ui_casing; QCheckBox *ui_pre_non_interrupt; QCheckBox *ui_showname_enable; @@ -548,6 +549,8 @@ public slots: void mod_called(QString p_ip); + void case_called(QString msg, bool def, bool pro, bool jud, bool jur); + private slots: void start_chat_ticking(); void play_sfx(); @@ -648,6 +651,8 @@ private slots: void on_switch_area_music_clicked(); + void on_casing_clicked(); + void ping_server(); void load_bass_opus_plugin(); diff --git a/packet_distribution.cpp b/packet_distribution.cpp index 6a11958..2abcd16 100644 --- a/packet_distribution.cpp +++ b/packet_distribution.cpp @@ -149,6 +149,7 @@ void AOApplication::server_packet_received(AOPacket *p_packet) evidence_enabled = false; cccc_ic_support_enabled = false; arup_enabled = false; + casing_alerts_enabled = false; modcall_reason_enabled = false; //workaround for tsuserver4 @@ -204,6 +205,8 @@ void AOApplication::server_packet_received(AOPacket *p_packet) 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; @@ -657,6 +660,13 @@ 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() > 0) + 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"); + qDebug() << f_contents; + qDebug() << (f_contents.at(1) == "1"); + } end: diff --git a/text_file_functions.cpp b/text_file_functions.cpp index be3d7a7..835a105 100644 --- a/text_file_functions.cpp +++ b/text_file_functions.cpp @@ -518,5 +518,44 @@ bool AOApplication::is_discord_enabled() return result.startsWith("true"); } +bool AOApplication::get_casing_enabled() +{ + 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_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; +} From de8badc9a6e74ca29cbc04ab5438d6eed2eb8984 Mon Sep 17 00:00:00 2001 From: Cerapter Date: Tue, 23 Oct 2018 16:15:15 +0200 Subject: [PATCH 169/174] Support for case alerts serverside. - Users can use an ingame button to alert people of cases. --- Attorney_Online_remake.pro | 6 ++- aoapplication.cpp | 9 +++++ aoapplication.h | 1 + aocaseannouncerdialog.cpp | 77 ++++++++++++++++++++++++++++++++++++++ aocaseannouncerdialog.h | 44 ++++++++++++++++++++++ courtroom.cpp | 33 +++++++++++++++- courtroom.h | 7 +++- server/aoprotocol.py | 2 +- server/client_manager.py | 15 ++++++++ server/commands.py | 48 ++++++++++++++++++++++++ 10 files changed, 236 insertions(+), 6 deletions(-) create mode 100644 aocaseannouncerdialog.cpp create mode 100644 aocaseannouncerdialog.h diff --git a/Attorney_Online_remake.pro b/Attorney_Online_remake.pro index 9e31fa0..756a25b 100644 --- a/Attorney_Online_remake.pro +++ b/Attorney_Online_remake.pro @@ -50,7 +50,8 @@ SOURCES += main.cpp\ aoevidencedisplay.cpp \ discord_rich_presence.cpp \ aooptionsdialog.cpp \ - chatlogpiece.cpp + chatlogpiece.cpp \ + aocaseannouncerdialog.cpp HEADERS += lobby.h \ aoimage.h \ @@ -84,7 +85,8 @@ HEADERS += lobby.h \ discord-rpc.h \ aooptionsdialog.h \ text_file_functions.h \ - chatlogpiece.h + chatlogpiece.h \ + aocaseannouncerdialog.h # 1. You need to get BASS and put the x86 bass DLL/headers in the project root folder # AND the compilation output folder. If you want a static link, you'll probably diff --git a/aoapplication.cpp b/aoapplication.cpp index 03679a7..67807ff 100644 --- a/aoapplication.cpp +++ b/aoapplication.cpp @@ -6,6 +6,7 @@ #include "debug_functions.h" #include "aooptionsdialog.h" +#include "aocaseannouncerdialog.h" AOApplication::AOApplication(int &argc, char **argv) : QApplication(argc, argv) { @@ -184,3 +185,11 @@ void AOApplication::call_settings_menu() 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 e106bcc..eafb2b7 100644 --- a/aoapplication.h +++ b/aoapplication.h @@ -56,6 +56,7 @@ public: void send_server_packet(AOPacket *p_packet, bool encoded = true); void call_settings_menu(); + void call_announce_menu(Courtroom *court); /////////////////server metadata////////////////// diff --git a/aocaseannouncerdialog.cpp b/aocaseannouncerdialog.cpp new file mode 100644 index 0000000..aa37353 --- /dev/null +++ b/aocaseannouncerdialog.cpp @@ -0,0 +1,77 @@ +#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"); + + FormLayout->setWidget(1, QFormLayout::FieldRole, DefenceNeeded); + FormLayout->setWidget(2, QFormLayout::FieldRole, ProsecutorNeeded); + FormLayout->setWidget(3, QFormLayout::FieldRole, JudgeNeeded); + FormLayout->setWidget(4, QFormLayout::FieldRole, JurorNeeded); + + setUpdatesEnabled(true); +} + +void AOCaseAnnouncerDialog::ok_pressed() +{ + court->announce_case(CaseTitleLineEdit->text(), + DefenceNeeded->isChecked(), + ProsecutorNeeded->isChecked(), + JudgeNeeded->isChecked(), + JurorNeeded->isChecked()); + + done(0); +} + +void AOCaseAnnouncerDialog::cancel_pressed() +{ + done(0); +} diff --git a/aocaseannouncerdialog.h b/aocaseannouncerdialog.h new file mode 100644 index 0000000..b98f4d7 --- /dev/null +++ b/aocaseannouncerdialog.h @@ -0,0 +1,44 @@ +#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; + +public slots: + void ok_pressed(); + void cancel_pressed(); +}; + +#endif // AOCASEANNOUNCERDIALOG_H diff --git a/courtroom.cpp b/courtroom.cpp index 4426caa..9cf074a 100644 --- a/courtroom.cpp +++ b/courtroom.cpp @@ -191,6 +191,7 @@ Courtroom::Courtroom(AOApplication *p_ao_app) : QMainWindow() 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); @@ -202,7 +203,7 @@ Courtroom::Courtroom(AOApplication *p_ao_app) : QMainWindow() ui_guard->setText("Guard"); ui_guard->hide(); ui_casing = new QCheckBox(this); - ui_showname_enable->setChecked(ao_app->get_casing_enabled()); + ui_casing->setChecked(ao_app->get_casing_enabled()); ui_casing->setText("Casing"); ui_casing->hide(); @@ -322,6 +323,7 @@ Courtroom::Courtroom(AOApplication *p_ao_app) : QMainWindow() 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())); @@ -431,6 +433,15 @@ void Courtroom::set_widgets() 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(); @@ -597,6 +608,9 @@ void Courtroom::set_widgets() 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"); @@ -3461,6 +3475,11 @@ 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(); @@ -3551,6 +3570,18 @@ void Courtroom::on_casing_clicked() } } +void Courtroom::announce_case(QString title, bool def, bool pro, bool jud, bool jur) +{ + 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) + + "#%")); +} + Courtroom::~Courtroom() { delete music_player; diff --git a/courtroom.h b/courtroom.h index 2b60db5..0dc7ba4 100644 --- a/courtroom.h +++ b/courtroom.h @@ -198,6 +198,8 @@ public: //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); + void check_connection_received(); ~Courtroom(); @@ -218,6 +220,7 @@ private: int maximumMessages = 0; // This is for inline message-colouring. + enum INLINE_COLOURS { INLINE_BLUE, INLINE_GREEN, @@ -455,6 +458,7 @@ private: AOButton *ui_reload_theme; AOButton *ui_call_mod; AOButton *ui_settings; + AOButton *ui_announce_casing; AOButton *ui_switch_area_music; QCheckBox *ui_pre; @@ -536,8 +540,6 @@ private: void construct_evidence(); void set_evidence_page(); - - public slots: void objection_done(); void preanim_done(); @@ -625,6 +627,7 @@ private slots: 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(); diff --git a/server/aoprotocol.py b/server/aoprotocol.py index 1bf9001..0af8f67 100644 --- a/server/aoprotocol.py +++ b/server/aoprotocol.py @@ -213,7 +213,7 @@ class AOProtocol(asyncio.Protocol): self.client.is_ao2 = True - self.client.send_command('FL', 'yellowtext', 'customobjections', 'flipping', 'fastloading', 'noencryption', 'deskmod', 'evidence', 'modcall_reason', 'cccc_ic_support', 'arup') + 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. diff --git a/server/client_manager.py b/server/client_manager.py index f5ef4ef..4a5c1ef 100644 --- a/server/client_manager.py +++ b/server/client_manager.py @@ -65,6 +65,15 @@ class ClientManager: 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.case_call_time = 0 + #flood-guard stuff self.mus_counter = 0 self.mus_mute_time = 0 @@ -359,6 +368,12 @@ class ClientManager: 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) diff --git a/server/commands.py b/server/commands.py index aae12de..49fd979 100644 --- a/server/commands.py +++ b/server/commands.py @@ -16,6 +16,7 @@ # 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 @@ -767,6 +768,53 @@ def ooc_cmd_uncm(client, arg): 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" + +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": + 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") + + msg = msg + ', '.join(lookingfor) + '.\r\n==================' + + client.server.send_all_cmd_pred('CASEA', msg, args[1], args[2], args[3], args[4], '1') + + client.set_case_call_delay() + + logger.log_server('[{}][{}][CASE_ANNOUNCEMENT]{}, DEF: {}, PRO: {}, JUD: {}, JUR: {}.'.format(client.area.abbreviation, client.get_char_name(), args[0], args[1], args[2], args[3], args[4]), 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 From 962289793d97357b69e228a0b52737681d2ea0b0 Mon Sep 17 00:00:00 2001 From: Cerapter Date: Tue, 23 Oct 2018 16:34:39 +0200 Subject: [PATCH 170/174] Added support for the stenographer role in case alerts. --- aoapplication.h | 3 +++ aocaseannouncerdialog.cpp | 6 +++++- aocaseannouncerdialog.h | 1 + aooptionsdialog.cpp | 22 ++++++++++++++++++---- aooptionsdialog.h | 2 ++ courtroom.cpp | 13 ++++++++----- courtroom.h | 4 ++-- packet_distribution.cpp | 6 ++---- server/client_manager.py | 1 + server/commands.py | 9 ++++++--- text_file_functions.cpp | 6 ++++++ 11 files changed, 54 insertions(+), 19 deletions(-) diff --git a/aoapplication.h b/aoapplication.h index eafb2b7..fa57ad8 100644 --- a/aoapplication.h +++ b/aoapplication.h @@ -288,6 +288,9 @@ public: // Same for juror. bool get_casing_juror_enabled(); + // Same for steno. + bool get_casing_steno_enabled(); + // Same for CM. bool get_casing_cm_enabled(); diff --git a/aocaseannouncerdialog.cpp b/aocaseannouncerdialog.cpp index aa37353..6544833 100644 --- a/aocaseannouncerdialog.cpp +++ b/aocaseannouncerdialog.cpp @@ -51,11 +51,14 @@ AOCaseAnnouncerDialog::AOCaseAnnouncerDialog(QWidget *parent, AOApplication *p_a 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); } @@ -66,7 +69,8 @@ void AOCaseAnnouncerDialog::ok_pressed() DefenceNeeded->isChecked(), ProsecutorNeeded->isChecked(), JudgeNeeded->isChecked(), - JurorNeeded->isChecked()); + JurorNeeded->isChecked(), + StenographerNeeded->isChecked()); done(0); } diff --git a/aocaseannouncerdialog.h b/aocaseannouncerdialog.h index b98f4d7..78e94f3 100644 --- a/aocaseannouncerdialog.h +++ b/aocaseannouncerdialog.h @@ -35,6 +35,7 @@ private: QCheckBox *ProsecutorNeeded; QCheckBox *JudgeNeeded; QCheckBox *JurorNeeded; + QCheckBox *StenographerNeeded; public slots: void ok_pressed(); diff --git a/aooptionsdialog.cpp b/aooptionsdialog.cpp index 813c8cd..b459923 100644 --- a/aooptionsdialog.cpp +++ b/aooptionsdialog.cpp @@ -388,18 +388,31 @@ AOOptionsDialog::AOOptionsDialog(QWidget *parent, AOApplication *p_ao_app) : QDi 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(6, QFormLayout::LabelRole, CMLabel); + CasingForm->setWidget(7, QFormLayout::LabelRole, CMLabel); CMCheckbox = new QCheckBox(formLayoutWidget_3); CMCheckbox->setChecked(ao_app->get_casing_cm_enabled()); - CasingForm->setWidget(6, QFormLayout::FieldRole, CMCheckbox); + CasingForm->setWidget(7, QFormLayout::FieldRole, CMCheckbox); // -- CM CASES ANNOUNCEMENTS @@ -407,12 +420,12 @@ AOOptionsDialog::AOOptionsDialog(QWidget *parent, AOApplication *p_ao_app) : QDi CMCasesLabel->setText("Hosting cases:"); CMCasesLabel->setToolTip("If you're a CM, enter what cases are you willing to host."); - CasingForm->setWidget(7, QFormLayout::LabelRole, CMCasesLabel); + CasingForm->setWidget(8, QFormLayout::LabelRole, CMCasesLabel); CMCasesLineEdit = new QLineEdit(formLayoutWidget_3); CMCasesLineEdit->setText(ao_app->get_casing_can_host_cases()); - CasingForm->setWidget(7, QFormLayout::FieldRole, CMCasesLineEdit); + CasingForm->setWidget(8, QFormLayout::FieldRole, CMCasesLineEdit); // When we're done, we should continue the updates! setUpdatesEnabled(true); @@ -456,6 +469,7 @@ void AOOptionsDialog::save_pressed() 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()); diff --git a/aooptionsdialog.h b/aooptionsdialog.h index bbc81ed..0480eb8 100644 --- a/aooptionsdialog.h +++ b/aooptionsdialog.h @@ -96,6 +96,8 @@ private: QCheckBox *JudgeCheckbox; QLabel *JurorLabel; QCheckBox *JurorCheckbox; + QLabel *StenographerLabel; + QCheckBox *StenographerCheckbox; QLabel *CMLabel; QCheckBox *CMCheckbox; QLabel *CMCasesLabel; diff --git a/courtroom.cpp b/courtroom.cpp index 9cf074a..e81d4fd 100644 --- a/courtroom.cpp +++ b/courtroom.cpp @@ -2722,7 +2722,7 @@ void Courtroom::mod_called(QString p_ip) } } -void Courtroom::case_called(QString msg, bool def, bool pro, bool jud, bool jur) +void Courtroom::case_called(QString msg, bool def, bool pro, bool jud, bool jur, bool steno) { if (ui_casing->isChecked()) { @@ -2730,7 +2730,8 @@ void Courtroom::case_called(QString msg, bool def, bool pro, bool jud, bool jur) 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_juror_enabled() && jur) || + (ao_app->get_casing_steno_enabled() && steno)) { modcall_player->play(ao_app->get_sfx("case_call")); ao_app->alert(this); @@ -3564,13 +3565,14 @@ void Courtroom::on_casing_clicked() + " " + 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#%")); + 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) +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 \"" @@ -3578,7 +3580,8 @@ void Courtroom::announce_case(QString title, bool def, bool pro, bool jud, bool + QString::number(def) + " " + QString::number(pro) + " " + QString::number(jud) + " " - + QString::number(jur) + + QString::number(jur) + " " + + QString::number(steno) + "#%")); } diff --git a/courtroom.h b/courtroom.h index 0dc7ba4..a27d902 100644 --- a/courtroom.h +++ b/courtroom.h @@ -198,7 +198,7 @@ public: //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); + void announce_case(QString title, bool def, bool pro, bool jud, bool jur, bool steno); void check_connection_received(); @@ -551,7 +551,7 @@ public slots: void mod_called(QString p_ip); - void case_called(QString msg, bool def, bool pro, bool jud, bool jur); + void case_called(QString msg, bool def, bool pro, bool jud, bool jur, bool steno); private slots: void start_chat_ticking(); diff --git a/packet_distribution.cpp b/packet_distribution.cpp index 2abcd16..93ea5f1 100644 --- a/packet_distribution.cpp +++ b/packet_distribution.cpp @@ -662,10 +662,8 @@ void AOApplication::server_packet_received(AOPacket *p_packet) } else if (header == "CASEA") { - if (courtroom_constructed && f_contents.size() > 0) - 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"); - qDebug() << f_contents; - qDebug() << (f_contents.at(1) == "1"); + 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/server/client_manager.py b/server/client_manager.py index 4a5c1ef..432c39d 100644 --- a/server/client_manager.py +++ b/server/client_manager.py @@ -72,6 +72,7 @@ class ClientManager: self.casing_pro = False self.casing_jud = False self.casing_jur = False + self.casing_steno = False self.case_call_time = 0 #flood-guard stuff diff --git a/server/commands.py b/server/commands.py index 49fd979..d02eff2 100644 --- a/server/commands.py +++ b/server/commands.py @@ -780,6 +780,7 @@ def ooc_cmd_setcase(client, arg): 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: @@ -791,7 +792,7 @@ def ooc_cmd_anncase(client, arg): 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": + 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]) @@ -805,14 +806,16 @@ def ooc_cmd_anncase(client, arg): 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], '1') + 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: {}.'.format(client.area.abbreviation, client.get_char_name(), args[0], args[1], args[2], args[3], args[4]), client) + 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!') diff --git a/text_file_functions.cpp b/text_file_functions.cpp index 835a105..a14db38 100644 --- a/text_file_functions.cpp +++ b/text_file_functions.cpp @@ -548,6 +548,12 @@ bool AOApplication::get_casing_juror_enabled() 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(); From a7fa843bd3895a2be5e3f2fb573434c849f02f2d Mon Sep 17 00:00:00 2001 From: Cerapter Date: Fri, 2 Nov 2018 15:08:39 +0100 Subject: [PATCH 171/174] Don't fix what's doubly broken: Emote dropdown. Made it so that emote dropdown only responds to activation, instead of index changing, i.e., reverted to previous behaviour. Emote changing already had a failsafe for the emote dropdown index changing, which activated even when you clicked on the emotes. That made it so that you'd get the Pre button ticked on emotes that didn't have 'em, and vice versa. --- courtroom.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/courtroom.cpp b/courtroom.cpp index e81d4fd..82aebcd 100644 --- a/courtroom.cpp +++ b/courtroom.cpp @@ -276,7 +276,7 @@ Courtroom::Courtroom(AOApplication *p_ao_app) : QMainWindow() connect(ui_emote_left, SIGNAL(clicked()), this, SLOT(on_emote_left_clicked())); connect(ui_emote_right, SIGNAL(clicked()), this, SLOT(on_emote_right_clicked())); - connect(ui_emote_dropdown, SIGNAL(currentIndexChanged(int)), this, SLOT(on_emote_dropdown_changed(int))); + connect(ui_emote_dropdown, SIGNAL(activated(int)), this, SLOT(on_emote_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))); From e8bb1f1e490e52bbfad2bbf75c56f20109a28926 Mon Sep 17 00:00:00 2001 From: Cerapter Date: Fri, 2 Nov 2018 15:15:07 +0100 Subject: [PATCH 172/174] Reverted the full stop silence feature. With 3D characters, it made the game lag too much -- really wasn't worth it. --- courtroom.cpp | 33 --------------------------------- courtroom.h | 2 -- 2 files changed, 35 deletions(-) diff --git a/courtroom.cpp b/courtroom.cpp index 82aebcd..120b82f 100644 --- a/courtroom.cpp +++ b/courtroom.cpp @@ -2102,9 +2102,6 @@ void Courtroom::start_chat_ticking() // let's set it to false. inline_blue_depth = 0; - // And also, reset the fullstop bool. - previous_character_is_fullstop = false; - // 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]); @@ -2318,21 +2315,6 @@ void Courtroom::chat_tick() formatting_char = true; } } - - // Silencing the character during long times of ellipses. - else if (f_character == "." and !next_character_is_not_special and !previous_character_is_fullstop) - { - if (!previous_character_is_fullstop && inline_blue_depth == 0 && !entire_message_is_blue && 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); - } - previous_character_is_fullstop = true; - next_character_is_not_special = true; - formatting_char = true; - tick_pos--; - } else { next_character_is_not_special = false; @@ -2372,21 +2354,6 @@ void Courtroom::chat_tick() } } - // Basically only go back to talkin if: - // - This character is not a fullstop - // - But the previous character was - // - And we're out of inline blues - // - And the entire messages isn't blue - // - And we aren't still in a non-interrupting pre - // - And this isn't the last character. - if (f_character != "." && previous_character_is_fullstop && inline_blue_depth == 0 && !entire_message_is_blue && anim_state != 4 && 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); - previous_character_is_fullstop = false; - } - QScrollBar *scroll = ui_vp_message->verticalScrollBar(); scroll->setValue(scroll->maximum()); diff --git a/courtroom.h b/courtroom.h index a27d902..264470c 100644 --- a/courtroom.h +++ b/courtroom.h @@ -234,8 +234,6 @@ private: bool next_character_is_not_special = false; // If true, write the // next character as it is. - bool previous_character_is_fullstop = false; // Used for silencing the character during long ellipses. - bool message_is_centered = false; int current_display_speed = 3; From 1f8b4944ca3a4a95b1f73c9275facee12f637c14 Mon Sep 17 00:00:00 2001 From: Cerapter Date: Fri, 2 Nov 2018 15:28:31 +0100 Subject: [PATCH 173/174] A safety measure regarding the IC commands `/a` and `/s`. Made it so they actually require the command plus a space, so that things like `/area` in IC don't get caught. --- server/aoprotocol.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/server/aoprotocol.py b/server/aoprotocol.py index 0af8f67..2cf6fb4 100644 --- a/server/aoprotocol.py +++ b/server/aoprotocol.py @@ -401,7 +401,7 @@ class AOProtocol(asyncio.Protocol): 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'): + if text.startswith('/a '): part = text.split(' ') try: aid = int(part[1]) @@ -414,7 +414,7 @@ class AOProtocol(asyncio.Protocol): except ValueError: self.client.send_host_message("That does not look like a valid area ID!") return - elif text.startswith('/s'): + elif text.startswith('/s '): part = text.split(' ') for a in self.server.area_manager.areas: if self.client in a.owners: From 57736ad24b63962424afba16edfe792427b223d6 Mon Sep 17 00:00:00 2001 From: Cerapter Date: Fri, 2 Nov 2018 17:01:21 +0100 Subject: [PATCH 174/174] Updated README to talk about the 1.4.1 update. --- README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.md b/README.md index 3cdd5ec..58e7dd2 100644 --- a/README.md +++ b/README.md @@ -60,6 +60,8 @@ Alternatively, you may wait till I make some stuff, and release a compiled execu - 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. @@ -91,6 +93,7 @@ Since this custom client, and the server files supplied with it, add a few featu - 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. @@ -119,6 +122,8 @@ Since this custom client, and the server files supplied with it, add a few featu - `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'!) ---