From 49071e693650c98604463befcdb042c60ea80a3e Mon Sep 17 00:00:00 2001 From: in1tiate Date: Tue, 9 Mar 2021 18:40:58 -0600 Subject: [PATCH] add global chat toggle --- include/aoclient.h | 3 +++ src/commands.cpp | 12 +++++++++++- src/packets.cpp | 6 +++++- 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/include/aoclient.h b/include/aoclient.h index 6b96979..3c6abbd 100644 --- a/include/aoclient.h +++ b/include/aoclient.h @@ -58,6 +58,7 @@ class AOClient : public QObject { QString moderator_name = ""; QString ooc_name = ""; QString showname = ""; + bool global_enabled = true; QMap ACLFlags { {"NONE", 0ULL}, @@ -212,6 +213,7 @@ class AOClient : public QObject { void cmdSwitch(int argc, QStringList argv); void cmdRandomChar(int argc, QStringList argv); void cmdG(int argc, QStringList argv); + void cmdToggleGlobal(int argc, QStringList argv); // Command helper functions QString getAreaTimer(int area_idx, QTimer* timer); @@ -267,6 +269,7 @@ class AOClient : public QObject { {"areakick", {ACLFlags.value("CM"), 1, &AOClient::cmdAreaKick}}, {"randomchar", {ACLFlags.value("NONE"), 0, &AOClient::cmdRandomChar}}, {"switch", {ACLFlags.value("NONE"), 1, &AOClient::cmdSwitch}}, + {"toggleglobal", {ACLFlags.value("NONE"), 0, &AOClient::cmdToggleGlobal}}, }; QString partial_packet; diff --git a/src/commands.cpp b/src/commands.cpp index 0590ba1..82500f0 100644 --- a/src/commands.cpp +++ b/src/commands.cpp @@ -373,7 +373,10 @@ void AOClient::cmdG(int argc, QStringList argv) QString sender_name = ooc_name; QString sender_area = server->area_names.value(current_area); QString sender_message = argv.join(" "); - server->broadcast(AOPacket("CT", {"[" + sender_area + "]" + sender_name, sender_message})); + for (AOClient* client : server->clients) { + if (client->global_enabled) + client->sendPacket("CT", {"[G][" + sender_area + "]" + sender_name, sender_message}); + } return; } @@ -682,6 +685,13 @@ void AOClient::cmdRandomChar(int argc, QStringList argv) changeCharacter(char_id); } +void AOClient::cmdToggleGlobal(int argc, QStringList argv) +{ + global_enabled = !global_enabled; + QString str_en = global_enabled ? "shown" : "hidden"; + sendServerMessage("Global chat set to " + str_en); +} + QStringList AOClient::buildAreaList(int area_idx) { QStringList entries; diff --git a/src/packets.cpp b/src/packets.cpp index 4d6c727..5b952b7 100644 --- a/src/packets.cpp +++ b/src/packets.cpp @@ -136,7 +136,11 @@ void AOClient::pktIcChat(AreaData* area, int argc, QStringList argv, AOPacket pa void AOClient::pktOocChat(AreaData* area, int argc, QStringList argv, AOPacket packet) { - ooc_name = dezalgo(argv[0]); + ooc_name = dezalgo(argv[0]).replace(QRegExp("\\[|\\]|\\{|\\}|\\#|\\$|\\%|\\&"), ""); // no fucky wucky shit here + + if (ooc_name == server->getServerName()) // impersonation prevention + return; + QString message = dezalgo(argv[1]); AOPacket final_packet("CT", {ooc_name, message, "0"}); if(message.at(0) == '/') {