From 080e215fb3ac13733887790f58f6b2d2ba930885 Mon Sep 17 00:00:00 2001 From: in1tiate Date: Sun, 28 Feb 2021 18:12:42 -0600 Subject: [PATCH] cherrypick additional functionality from Salanto:Rolling-Rocks --- include/aoclient.h | 2 ++ include/server.h | 2 ++ src/aoclient.cpp | 12 +++++++++++- src/commands.cpp | 14 +++++++------- src/server.cpp | 8 ++++++++ 5 files changed, 30 insertions(+), 8 deletions(-) diff --git a/include/aoclient.h b/include/aoclient.h index 55b331f..a72f483 100644 --- a/include/aoclient.h +++ b/include/aoclient.h @@ -90,6 +90,8 @@ class AOClient : public QObject { void arup(ARUPType type, bool broadcast); void fullArup(); void sendServerMessage(QString message); + void sendServerMessageArea(QString message); + void sendServerBroadcast(QString message); bool checkAuth(unsigned long long acl_mask); // Packet headers diff --git a/include/server.h b/include/server.h index 38a97e1..2865c63 100644 --- a/include/server.h +++ b/include/server.h @@ -50,6 +50,7 @@ class Server : public QObject { void updateCharsTaken(AreaData* area); void broadcast(AOPacket packet, int area_index); void broadcast(AOPacket packet); + QString getServerName(); QVector clients; @@ -60,6 +61,7 @@ class Server : public QObject { QStringList music_list; QStringList backgrounds; DBManager* db_manager; + QString server_name; signals: diff --git a/src/aoclient.cpp b/src/aoclient.cpp index b238bc5..075caaa 100644 --- a/src/aoclient.cpp +++ b/src/aoclient.cpp @@ -248,7 +248,17 @@ void AOClient::setHwid(QString p_hwid) void AOClient::sendServerMessage(QString message) { - sendPacket("CT", {"Server", message, "1"}); + sendPacket("CT", {server->getServerName(), message, "1"}); +} + +void AOClient::sendServerMessageArea(QString message) +{ + server->broadcast(AOPacket("CT", {server->getServerName(), message, "1"}), current_area); +} + +void AOClient::sendServerBroadcast(QString message) +{ + server->broadcast(AOPacket("CT", {server->getServerName(), message, "1"})); } bool AOClient::checkAuth(unsigned long long acl_mask) diff --git a/src/commands.cpp b/src/commands.cpp index c9fdf43..46d19c0 100644 --- a/src/commands.cpp +++ b/src/commands.cpp @@ -399,7 +399,7 @@ void AOClient::cmdDoc(int argc, QStringList argv) } else { area->document = argv.join(" "); - sendServerMessage(sender_name + " changed the document."); // broadcast this! + sendServerMessageArea(sender_name + " changed the document."); } } @@ -408,7 +408,7 @@ void AOClient::cmdClearDoc(int argc, QStringList argv) QString sender_name = ooc_name; AreaData* area = server->areas[current_area]; area->document = "No document."; - sendServerMessage(sender_name + " cleared the document."); // broadcast this! + sendServerMessageArea(sender_name + " cleared the document."); } void AOClient::cmdCM(int argc, QStringList argv) @@ -418,7 +418,7 @@ void AOClient::cmdCM(int argc, QStringList argv) if (area->owners.isEmpty()) { area->owners.append(id); area->invited.append(id); - sendServerMessage(sender_name + " is now CM in this area."); // broadcast this! + sendServerMessageArea(sender_name + " is now CM in this area."); arup(ARUPType::CM, true); } else if (!area->owners.contains(id)) { @@ -436,7 +436,7 @@ void AOClient::cmdCM(int argc, QStringList argv) return; } area->owners.append(owner_candidate->id); - sendServerMessage(owner_candidate->ooc_name + " is now CM in this area."); // broadcast this! + sendServerMessageArea(owner_candidate->ooc_name + " is now CM in this area."); arup(ARUPType::CM, true); } else { @@ -512,7 +512,7 @@ void AOClient::cmdLock(int argc, QStringList argv) sendServerMessage("This area is already locked."); return; } - sendServerMessage("This area is now locked."); // broadcast me! + sendServerMessageArea("This area is now locked."); area->locked = AreaData::LockStatus::LOCKED; for (AOClient* client : server->clients) { if (client->current_area == current_area && client->joined) { @@ -532,7 +532,7 @@ void AOClient::cmdSpectatable(int argc, QStringList argv) sendServerMessage("This area is already in spectate mode."); return; } - sendServerMessage("This area is now spectatable."); // broadcast me! + sendServerMessageArea("This area is now spectatable."); area->locked = AreaData::LockStatus::SPECTATABLE; for (AOClient* client : server->clients) { if (client->current_area == current_area && client->joined) { @@ -552,7 +552,7 @@ void AOClient::cmdUnLock(int argc, QStringList argv) sendServerMessage("This area is not locked."); return; } - sendServerMessage("This area is now unlocked."); // broadcast me! + sendServerMessageArea("This area is now unlocked."); area->locked = AreaData::LockStatus::FREE; arup(ARUPType::LOCKED, true); } diff --git a/src/server.cpp b/src/server.cpp index e89e884..23392d2 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -158,6 +158,14 @@ void Server::broadcast(AOPacket packet) } } +QString Server::getServerName() +{ + QSettings settings("config/config.ini", QSettings::IniFormat); + settings.beginGroup("Options"); + QString server_name = settings.value("server_name", "Akashi").toString(); + return server_name; +} + AOClient* Server::getClient(QString ipid) { for (AOClient* client : clients) {