From 3e1f9825ca03733a6f69561e36ffb758f6809a3a Mon Sep 17 00:00:00 2001 From: Salanto Date: Thu, 11 Mar 2021 22:42:47 +0100 Subject: [PATCH 1/3] motd. Can't get simpler than that. --- bin/config_sample/config.ini | 1 + include/aoclient.h | 4 +++- include/server.h | 1 + src/commands.cpp | 6 ++++++ src/packets.cpp | 1 + src/server.cpp | 9 +++++++++ 6 files changed, 21 insertions(+), 1 deletion(-) diff --git a/bin/config_sample/config.ini b/bin/config_sample/config.ini index a33f95d..65ed954 100644 --- a/bin/config_sample/config.ini +++ b/bin/config_sample/config.ini @@ -9,6 +9,7 @@ ms_port=27016 port=27016 server_description=This is a placeholder server description. Tell the world of AO who you are here! server_name=An Unnamed Server +motd=Sample MOTD. webao_enable=true webao_port=27017 auth=simple diff --git a/include/aoclient.h b/include/aoclient.h index a7d987f..fa8f91d 100644 --- a/include/aoclient.h +++ b/include/aoclient.h @@ -183,6 +183,7 @@ class AOClient : public QObject { //// Commands void cmdDefault(int argc, QStringList argv); void cmdHelp(int argc, QStringList argv); + void cmdMOTD(int argc, QStringList argv); // Authentication void cmdLogin(int argc, QStringList argv); void cmdChangeAuth(int argc, QStringList argv); @@ -298,7 +299,8 @@ class AOClient : public QObject { {"forcepos", {ACLFlags.value("CM"), 2, &AOClient::cmdForcePos}}, {"currentmusic", {ACLFlags.value("NONE"), 0, &AOClient::cmdCurrentMusic}}, {"pm", {ACLFlags.value("NONE"), 2, &AOClient::cmdPM}}, - {"evidence_mod", {ACLFlags.value("CHANGE_EVI_MOD"), 1, &AOClient::cmdEvidenceMod}} + {"evidence_mod", {ACLFlags.value("CHANGE_EVI_MOD"), 1, &AOClient::cmdEvidenceMod}}, + {"motd", {ACLFlags.value("NONE"), 0, &AOClient::cmdMOTD}} }; QString partial_packet; diff --git a/include/server.h b/include/server.h index 152fc37..cd003b3 100644 --- a/include/server.h +++ b/include/server.h @@ -52,6 +52,7 @@ class Server : public QObject { void broadcast(AOPacket packet, int area_index); void broadcast(AOPacket packet); QString getServerName(); + QString getMOTD(); int getDiceValue(QString value_type); int getCharID(QString char_name); diff --git a/src/commands.cpp b/src/commands.cpp index 1b173d9..cb213b8 100644 --- a/src/commands.cpp +++ b/src/commands.cpp @@ -857,6 +857,12 @@ void AOClient::cmdPM(int arc, QStringList argv) target_client->sendServerMessage("Message from " + ooc_name + " (" + QString::number(id) + "): " + message); } +void AOClient::cmdMOTD(int argc, QStringList argv) +{ + QString MOTD = server->getMOTD(); + sendServerMessage(MOTD); +} + QStringList AOClient::buildAreaList(int area_idx) { QStringList entries; diff --git a/src/packets.cpp b/src/packets.cpp index cabbb8c..6628b43 100644 --- a/src/packets.cpp +++ b/src/packets.cpp @@ -112,6 +112,7 @@ void AOClient::pktLoadingDone(AreaData* area, int argc, QStringList argv, AOPack sendPacket("BN", {area->background}); sendPacket("OPPASS", {"DEADBEEF"}); sendPacket("DONE"); + sendServerMessage(server->getMOTD()); } void AOClient::pktCharPassword(AreaData* area, int argc, QStringList argv, AOPacket packet) diff --git a/src/server.cpp b/src/server.cpp index 0f4d23a..5c036dc 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -182,6 +182,15 @@ int Server::getDiceValue(QString value_type) return value; } +QString Server::getMOTD() +{ + QSettings settings("config/config.ini", QSettings::IniFormat); + settings.beginGroup("Options"); + QString MOTD = settings.value("motd", "No MOTD has been set.").toString(); + QString f_MOTD = "=== MOTD ===\r\n" + MOTD + "\r\n============='"; + return f_MOTD; +} + AOClient* Server::getClient(QString ipid) { for (AOClient* client : clients) { From 06864e115a957e16b84cc4b56438045dcc43ce82 Mon Sep 17 00:00:00 2001 From: Salanto Date: Fri, 12 Mar 2021 00:44:27 +0100 Subject: [PATCH 2/3] Make MODT editable - Part 1 --- bin/config_sample/config.ini | 2 +- include/aoclient.h | 1 + include/server.h | 1 + src/commands.cpp | 15 +++++++++++++-- src/packets.cpp | 2 +- src/server.cpp | 11 ++--------- 6 files changed, 19 insertions(+), 13 deletions(-) diff --git a/bin/config_sample/config.ini b/bin/config_sample/config.ini index 65ed954..eaf63ba 100644 --- a/bin/config_sample/config.ini +++ b/bin/config_sample/config.ini @@ -9,7 +9,7 @@ ms_port=27016 port=27016 server_description=This is a placeholder server description. Tell the world of AO who you are here! server_name=An Unnamed Server -motd=Sample MOTD. +motd=MOTD is not set. webao_enable=true webao_port=27017 auth=simple diff --git a/include/aoclient.h b/include/aoclient.h index fa8f91d..42070e3 100644 --- a/include/aoclient.h +++ b/include/aoclient.h @@ -76,6 +76,7 @@ class AOClient : public QObject { {"CM", 1ULL << 4}, {"GLOBAL_TIMER", 1ULL << 5}, {"CHANGE_EVI_MOD", 1ULL << 6}, + {"CHANGE_MOTD", 1ULL << 7}, {"SUPER", ~0ULL} }; diff --git a/include/server.h b/include/server.h index cd003b3..14c4883 100644 --- a/include/server.h +++ b/include/server.h @@ -66,6 +66,7 @@ class Server : public QObject { QStringList backgrounds; DBManager* db_manager; QString server_name; + QString MOTD; QTimer* timer; diff --git a/src/commands.cpp b/src/commands.cpp index cb213b8..20af10c 100644 --- a/src/commands.cpp +++ b/src/commands.cpp @@ -859,8 +859,19 @@ void AOClient::cmdPM(int arc, QStringList argv) void AOClient::cmdMOTD(int argc, QStringList argv) { - QString MOTD = server->getMOTD(); - sendServerMessage(MOTD); + if (argc == 0) { + sendServerMessage("=== MOTD ===\r\n" + server->MOTD + "\r\n============="); + } + else if (argc == 1) { + unsigned long long user_acl = server->db_manager->getACL(moderator_name); + if ((user_acl & ACLFlags.value("MODIFY_USERS")) == 0) { + sendServerMessage("You do not have permission to change the MOTD"); + } + else { + server->MOTD = argv[0]; + } + + } } QStringList AOClient::buildAreaList(int area_idx) diff --git a/src/packets.cpp b/src/packets.cpp index 6628b43..745334c 100644 --- a/src/packets.cpp +++ b/src/packets.cpp @@ -112,7 +112,7 @@ void AOClient::pktLoadingDone(AreaData* area, int argc, QStringList argv, AOPack sendPacket("BN", {area->background}); sendPacket("OPPASS", {"DEADBEEF"}); sendPacket("DONE"); - sendServerMessage(server->getMOTD()); + sendServerMessage("=== MOTD ===\r\n" + server->MOTD + "\r\n============="); } void AOClient::pktCharPassword(AreaData* area, int argc, QStringList argv, AOPacket packet) diff --git a/src/server.cpp b/src/server.cpp index 5c036dc..e820950 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -51,6 +51,8 @@ void Server::start() qDebug() << "Server listening on" << port; } + MOTD = config.value("motd","MOTD is not set.").toString(); + proxy = new WSProxy(port, ws_port, this); if(ws_port != -1) proxy->start(); @@ -182,15 +184,6 @@ int Server::getDiceValue(QString value_type) return value; } -QString Server::getMOTD() -{ - QSettings settings("config/config.ini", QSettings::IniFormat); - settings.beginGroup("Options"); - QString MOTD = settings.value("motd", "No MOTD has been set.").toString(); - QString f_MOTD = "=== MOTD ===\r\n" + MOTD + "\r\n============='"; - return f_MOTD; -} - AOClient* Server::getClient(QString ipid) { for (AOClient* client : clients) { From f06537973b13900c640ab1c7de7a949ed71a0511 Mon Sep 17 00:00:00 2001 From: Salanto Date: Fri, 12 Mar 2021 00:56:54 +0100 Subject: [PATCH 3/3] Make permission check work; allow changed MOTD to be longer than one word --- src/commands.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/commands.cpp b/src/commands.cpp index 20af10c..e25bd8e 100644 --- a/src/commands.cpp +++ b/src/commands.cpp @@ -862,15 +862,15 @@ void AOClient::cmdMOTD(int argc, QStringList argv) if (argc == 0) { sendServerMessage("=== MOTD ===\r\n" + server->MOTD + "\r\n============="); } - else if (argc == 1) { - unsigned long long user_acl = server->db_manager->getACL(moderator_name); - if ((user_acl & ACLFlags.value("MODIFY_USERS")) == 0) { - sendServerMessage("You do not have permission to change the MOTD"); + else if (argc > 0) { + if (checkAuth(ACLFlags.value("CHANGE_MOTD"))) { + QString MOTD = argv.join(" "); + server->MOTD = MOTD; + sendServerMessage("MOTD has been changed."); } else { - server->MOTD = argv[0]; + sendServerMessage("You do not have permission to change the MOTD"); } - } }