From 2c25fadc1935910f913526860eb318e55569d37b Mon Sep 17 00:00:00 2001 From: in1tiate Date: Tue, 9 Mar 2021 12:56:59 -0600 Subject: [PATCH 1/3] add dezalgo for IC and OOC chat --- include/aoclient.h | 2 ++ include/config_manager.h | 1 + src/config_manager.cpp | 3 +++ src/packets.cpp | 34 +++++++++++++++++++++++++--------- 4 files changed, 31 insertions(+), 9 deletions(-) diff --git a/include/aoclient.h b/include/aoclient.h index 2a549d5..63203ce 100644 --- a/include/aoclient.h +++ b/include/aoclient.h @@ -28,6 +28,7 @@ #include #include #include +#include #include #if QT_VERSION > QT_VERSION_CHECK(5, 10, 0) #include @@ -127,6 +128,7 @@ class AOClient : public QObject { // Packet helper functions void sendEvidenceList(AreaData* area); AOPacket validateIcPacket(AOPacket packet); + QString dezalgo(QString p_text); // Packet helper global variables int char_id = -1; diff --git a/include/config_manager.h b/include/config_manager.h index 9311fbb..7c5deb0 100644 --- a/include/config_manager.h +++ b/include/config_manager.h @@ -40,6 +40,7 @@ class ConfigManager { QString name; QString description; bool advertise_server; + int zalgo_tolerance; }; bool loadServerSettings(server_settings* settings); diff --git a/src/config_manager.cpp b/src/config_manager.cpp index e6cc088..7f0f93a 100644 --- a/src/config_manager.cpp +++ b/src/config_manager.cpp @@ -131,6 +131,7 @@ bool ConfigManager::loadServerSettings(server_settings* settings) bool port_conversion_success; bool ws_port_conversion_success; bool local_port_conversion_success; + bool zalgo_tolerance_conversion_success; config.beginGroup("Options"); settings->ms_ip = config.value("ms_ip", "master.aceattorneyonline.com").toString(); @@ -144,6 +145,8 @@ bool ConfigManager::loadServerSettings(server_settings* settings) settings->description = config.value("server_description", "This is my flashy new server") .toString(); + settings->zalgo_tolerance = + config.value("zalgo_tolerance", "3").toInt(&zalgo_tolerance_conversion_success); config.endGroup(); if (!port_conversion_success || !ws_port_conversion_success || !local_port_conversion_success) { diff --git a/src/packets.cpp b/src/packets.cpp index 619849d..7566407 100644 --- a/src/packets.cpp +++ b/src/packets.cpp @@ -177,20 +177,21 @@ void AOClient::pktIcChat(AreaData* area, int argc, QStringList argv, AOPacket pa void AOClient::pktOocChat(AreaData* area, int argc, QStringList argv, AOPacket packet) { - ooc_name = argv[0]; - if(argv[1].at(0) == '/') { - QStringList cmd_argv = argv[1].split(" ", QString::SplitBehavior::SkipEmptyParts); + ooc_name = dezalgo(argv[0]); + QString message = dezalgo(argv[1]); + AOPacket final_packet("CT", {ooc_name, message, "0"}); + if(message.at(0) == '/') { + QStringList cmd_argv = message.split(" ", QString::SplitBehavior::SkipEmptyParts); QString command = cmd_argv[0].trimmed().toLower(); command = command.right(command.length() - 1); cmd_argv.removeFirst(); int cmd_argc = cmd_argv.length(); - area->logger->logCmd(this, &packet, command, cmd_argv); + area->logger->logCmd(this, &final_packet, command, cmd_argv); handleCommand(command, cmd_argc, cmd_argv); } else { - // TODO: zalgo strip - server->broadcast(packet, current_area); - area->logger->logOOC(this, &packet); + server->broadcast(final_packet, current_area); + area->logger->logOOC(this, &final_packet); } } @@ -375,7 +376,7 @@ AOPacket AOClient::validateIcPacket(AOPacket packet) args.append(emote); // message text - QString incoming_msg = incoming_args[4].toString().trimmed(); + QString incoming_msg = dezalgo(incoming_args[4].toString().trimmed()); if (incoming_msg == last_message) return invalid; @@ -453,7 +454,8 @@ AOPacket AOClient::validateIcPacket(AOPacket packet) // 2.6 packet extensions if (incoming_args.length() > 15) { // showname - args.append(incoming_args[15].toString()); + QString showname = dezalgo(incoming_args[15].toString().trimmed()); + args.append(showname); // other char id // things get a bit hairy here @@ -534,3 +536,17 @@ AOPacket AOClient::validateIcPacket(AOPacket packet) return AOPacket("MS", args); } + +QString AOClient::dezalgo(QString p_text) +{ + QSettings config("config/config.ini", QSettings::IniFormat); + config.beginGroup("Options"); + bool zalgo_tolerance_conversion_success; + int zalgo_tolerance = config.value("zalgo_tolerance", "3").toInt(&zalgo_tolerance_conversion_success); + if (!zalgo_tolerance_conversion_success) + zalgo_tolerance = 3; + + QRegExp rxp("([\u0300-\u036f\u1ab0-\u1aff\u1dc0-\u1dff\u20d0-\u20ff\ufe20-\ufe2f\u115f\u1160\u3164]{" + QRegExp::escape(QString::number(zalgo_tolerance)) + ",})"); + QString filtered = p_text.replace(rxp, ""); + return filtered; +} From 5d4a3700ed9f35c0823e1db2f55113f68161fcf2 Mon Sep 17 00:00:00 2001 From: in1tiate Date: Tue, 9 Mar 2021 13:32:08 -0600 Subject: [PATCH 2/3] config bg lock, fail if modpass is empty --- src/area_data.cpp | 2 +- src/commands.cpp | 11 ++++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/area_data.cpp b/src/area_data.cpp index a2d9373..0036af3 100644 --- a/src/area_data.cpp +++ b/src/area_data.cpp @@ -28,13 +28,13 @@ AreaData::AreaData(QStringList characters, QString p_name, int p_index) areas_ini.beginGroup(p_name); background = areas_ini.value("background", "gs4").toString(); is_protected = areas_ini.value("protected_area").toBool(); + bg_locked = areas_ini.value("bg_locked", "false").toBool(); areas_ini.endGroup(); player_count = 0; locked = FREE; status = "FREE"; def_hp = 10; pro_hp = 10; - bg_locked = false; document = "No document."; QSettings config_ini("config/config.ini", QSettings::IniFormat); config_ini.beginGroup("Options"); diff --git a/src/commands.cpp b/src/commands.cpp index 6abee2f..dcbacf0 100644 --- a/src/commands.cpp +++ b/src/commands.cpp @@ -37,12 +37,15 @@ void AOClient::cmdLogin(int argc, QStringList argv) return; } - // TODO: tell the user if no modpass is set if (auth_type == "simple") { - if(argv[0] == modpass) { + if (modpass == "") { + sendServerMessage("No modpass is set! Please set a modpass before authenticating."); + } + else if(argv[0] == modpass) { sendServerMessage("Logged in as a moderator."); // This string has to be exactly this, because it is hardcoded in the client authenticated = true; - } else { + } + else { sendServerMessage("Incorrect password."); } server->areas.value(current_area)->logger->logLogin(this, authenticated, "moderator"); @@ -181,8 +184,6 @@ void AOClient::cmdSetRootPass(int argc, QStringList argv) void AOClient::cmdSetBackground(int argc, QStringList argv) { - // TODO: area locks in areas.ini - // TODO: sendServerMessage but area broadcast AreaData* area = server->areas[current_area]; if (authenticated || !area->bg_locked) { if (server->backgrounds.contains(argv[0])) { From 576b915828558998d808d46af74b3b5e74968441 Mon Sep 17 00:00:00 2001 From: in1tiate Date: Tue, 9 Mar 2021 13:40:01 -0600 Subject: [PATCH 3/3] send user id in hwid packet --- src/packets.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/packets.cpp b/src/packets.cpp index 619849d..9c7ce83 100644 --- a/src/packets.cpp +++ b/src/packets.cpp @@ -32,7 +32,7 @@ void AOClient::pktHardwareId(AreaData* area, int argc, QStringList argv, AOPacke socket->close(); return; } - sendPacket("ID", {"271828", "akashi", QCoreApplication::applicationVersion()}); + sendPacket("ID", {QString::number(id), "akashi", QCoreApplication::applicationVersion()}); } void AOClient::pktSoftwareId(AreaData* area, int argc, QStringList argv, AOPacket packet)