From 290862c50440e91be25d46b9fa54f6473607d6c9 Mon Sep 17 00:00:00 2001 From: MangosArentLiterature <58055358+MangosArentLiterature@users.noreply.github.com> Date: Thu, 8 Apr 2021 22:51:04 -0500 Subject: [PATCH 1/5] Add a new system of loading configuration files for commands. - Adds ConfigManager::verifyCommandConfig(), which verifies the command config files found in config/text/ exist and are files. - Adds Server::loadConfigFile(), which returns the contents of a txt file in config/text/ into a stringlist. - Adds Server::loadCommandConfig(), which loads stringlists for commands to utilize using loadConfigFile(). --- include/config_manager.h | 7 +++++++ include/server.h | 27 +++++++++++++++++++++++++++ src/config_manager.cpp | 16 ++++++++++++++++ src/server.cpp | 20 ++++++++++++++++++++ 4 files changed, 70 insertions(+) diff --git a/include/config_manager.h b/include/config_manager.h index 8c95af3..c5405c2 100644 --- a/include/config_manager.h +++ b/include/config_manager.h @@ -93,6 +93,13 @@ class ConfigManager { * @return See brief description. */ bool fileExists(QFileInfo *file); + + /** + * @brief Verifies the existence of the command configuration files found in config/text/. + * + * @return True if the config files exist, and are files. False otherwise. + */ + bool verifyCommandConfig(); }; #endif // CONFIG_MANAGER_H diff --git a/include/server.h b/include/server.h index 96cba1a..6ac60ad 100644 --- a/include/server.h +++ b/include/server.h @@ -216,6 +216,33 @@ class Server : public QObject { */ QTimer* timer; + /** + * @brief Loads the configuration files for commands into stringlists. + */ + void loadCommandConfig(); + + /** + * @brief Returns a stringlist with the contents of a .txt file from config/text/. + * + * @param Name of the file to load. + */ + QStringList loadConfigFile(QString filename); + + /** + * @brief List holding the contents of 8ball.txt, used by /8ball. + */ + QStringList magic_8ball_answers; + + /** + * @brief List holding the contents of praise.txt, used by AOClient::getReprimand. + */ + QStringList praise_list; + + /** + * @brief List holding the contents of reprimands.txt, used by AOClient::getReprimand. + */ + QStringList reprimands_list; + public slots: /** * @brief Handles a new connection. diff --git a/src/config_manager.cpp b/src/config_manager.cpp index d6893a8..016991e 100644 --- a/src/config_manager.cpp +++ b/src/config_manager.cpp @@ -91,6 +91,9 @@ bool ConfigManager::initConfig() qCritical() << "config.ini is invalid!"; return false; } + if (!(verifyCommandConfig())) { + return false; + } else { // Config is valid and up to date, so let's go ahead @@ -176,3 +179,16 @@ bool ConfigManager::fileExists(QFileInfo* file) { return (file->exists() && file->isFile()); } + +bool ConfigManager::verifyCommandConfig() +{ + QStringList filelist = {"8ball", "praise", "reprimands"}; + foreach (QString filename, filelist) { + QFileInfo file("config/text/" + filename + ".txt"); + if (!(fileExists(&file))) { + qCritical() << (filename + ".txt doesn't exist!"); + return false; + } + } + return true; +} diff --git a/src/server.cpp b/src/server.cpp index 5bf4403..99562c2 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -96,6 +96,7 @@ void Server::start() QString area_name = raw_area_names[i]; areas.insert(i, new AreaData(area_name, i)); } + loadCommandConfig(); } void Server::clientConnected() @@ -215,6 +216,25 @@ int Server::getCharID(QString char_name) return -1; // character does not exist } +void Server::loadCommandConfig() +{ + magic_8ball_answers.append(loadConfigFile("8ball")); + praise_list.append(loadConfigFile("praise")); + reprimands_list.append(loadConfigFile("reprimands")); +} + +QStringList Server::loadConfigFile(QString filename) +{ + QStringList stringlist; + QFile file("config/text/" + filename + ".txt"); + file.open(QIODevice::ReadOnly | QIODevice::Text); + while (!(file.atEnd())) { + stringlist.append(file.readLine().trimmed()); + } + file.close(); + return stringlist; +} + Server::~Server() { for (AOClient* client : clients) { From cff51674bb10365376f596c5a316a1e7e600e4d2 Mon Sep 17 00:00:00 2001 From: MangosArentLiterature <58055358+MangosArentLiterature@users.noreply.github.com> Date: Thu, 8 Apr 2021 22:51:51 -0500 Subject: [PATCH 2/5] Update /8ball and AOClient::getReprimands to use the new command config loader --- src/commands.cpp | 57 ++++++++++++++---------------------------------- 1 file changed, 16 insertions(+), 41 deletions(-) diff --git a/src/commands.cpp b/src/commands.cpp index 0947746..b642cba 100644 --- a/src/commands.cpp +++ b/src/commands.cpp @@ -1249,35 +1249,18 @@ void AOClient::cmdNoteCardReveal(int argc, QStringList argv) void AOClient::cmd8Ball(int argc, QStringList argv) { - QFileInfo magic8ball_info("config/text/8ball.txt"); - if (!(magic8ball_info.exists() && magic8ball_info.isFile())) { - qWarning() << "8ball.txt doesn't exist!"; - sendServerMessage("8ball.txt doesn't exist."); - } + if (server->magic_8ball_answers.isEmpty()) { + qWarning() << "8ball.txt is empty!"; + sendServerMessage("8ball.txt is empty."); + } else { - QStringList answers; - QFile file("config/text/8ball.txt"); - file.open(QIODevice::ReadOnly | QIODevice::Text); - while (!file.atEnd()) { - answers.append(file.readLine().trimmed()); + int answerindex = server->magic_8ball_answers.size(); + QString response = server->magic_8ball_answers[(genRand(1, answerindex))]; + QString sender_name = ooc_name; + QString sender_message = argv.join(" "); + + sendServerMessageArea(sender_name + " asked the magic 8-ball, \"" + sender_message + "\" and the answer is: " + response); } - file.close(); - - if (answers.isEmpty()) { - qWarning() << "8ball.txt is empty!"; - sendServerMessage("8ball.txt is empty."); - } - else { - int answerindex = answers.size(); - QString response = answers[(genRand(1, answerindex))]; - QString sender_name = ooc_name; - QString sender_message = argv.join(" "); - - sendServerMessageArea(sender_name + " asked the magic 8-ball, \"" + sender_message + "\" and the answer is: " + response); - } - - } - } void AOClient::cmdAllow_Blankposting(int argc, QStringList argv) @@ -1454,18 +1437,10 @@ long long AOClient::parseTime(QString input) QString AOClient::getReprimand(bool positive) { - QString filename = positive ? "praise" : "reprimands"; - QFileInfo reprimands_info("config/text/" + filename + ".txt"); - if (!(reprimands_info.exists() && reprimands_info.isFile())) { - qWarning() << filename + ".txt doesn't exist!"; - return ""; - } - QStringList reprimands; - QFile file("config/text/" + filename + ".txt"); - file.open(QIODevice::ReadOnly | QIODevice::Text); - while (!file.atEnd()) { - reprimands.append(file.readLine().trimmed()); - } - file.close(); - return reprimands[genRand(0, reprimands.size() - 1)]; + if (positive) { + return server->praise_list[genRand(0, server->praise_list.size() - 1)]; + } + else { + return server->reprimands_list[genRand(0, server->reprimands_list.size() - 1)]; + } } From 86c25555b2770fd1283fb9402b78fa28150ff6a1 Mon Sep 17 00:00:00 2001 From: MangosArentLiterature <58055358+MangosArentLiterature@users.noreply.github.com> Date: Fri, 9 Apr 2021 19:18:46 -0500 Subject: [PATCH 3/5] Add a new method of loading values from config.ini - Centralizes the loading of values from config.ini, loading them all in at server start and holding them in memory. - Removes all other methods of loading config.ini values and replaces them with references to these central values. - Removes getServerName() and getDiceValue() --- include/aoclient.h | 7 ++++++ include/area_data.h | 5 +++++ include/server.h | 54 ++++++++++++++++++++++++++++++--------------- src/aoclient.cpp | 13 +++++------ src/area_data.cpp | 1 + src/commands.cpp | 29 ++++++++---------------- src/logger.cpp | 25 +++++++++------------ src/packets.cpp | 18 ++++----------- src/server.cpp | 45 ++++++++++++++++++++----------------- 9 files changed, 103 insertions(+), 94 deletions(-) diff --git a/include/aoclient.h b/include/aoclient.h index e99d417..d01aff7 100644 --- a/include/aoclient.h +++ b/include/aoclient.h @@ -1399,6 +1399,13 @@ class AOClient : public QObject { */ void cmd8Ball(int argc, QStringList argv); + /** + * @brief Reloads all server configuration files. + * + * @details No arguments. + */ + void cmdReload(int argc, QStringList argv); + ///@} /** diff --git a/include/area_data.h b/include/area_data.h index 4ed538b..44a1cfb 100644 --- a/include/area_data.h +++ b/include/area_data.h @@ -282,6 +282,11 @@ class AreaData : public QObject { * @brief The last IC packet sent in an area. */ QStringList last_ic_message; + + /** + * @brief The value of logger in config.ini. + */ + QString log_type; }; #endif // AREA_DATA_H diff --git a/include/server.h b/include/server.h index 6ac60ad..65886c2 100644 --- a/include/server.h +++ b/include/server.h @@ -125,24 +125,6 @@ class Server : public QObject { */ void broadcast(AOPacket packet); - /** - * @brief Returns the server's name according to the configuration file. - * - * @return See brief description. - */ - QString getServerName(); - - /** - * @brief Returns some value regarding the @ref AOClient::diceThrower "dice thrower commands". - * - * @param value_type `max_value` for the maximum amount of faces a die may have, - * `max_dice` for the maximum amount of dice that may be thrown at once. - * - * @return The associated value if it is found in the configuration file under the "Dice" section, - * or `100` if not. - */ - int getDiceValue(QString value_type); - /** * @brief Returns the character's character ID (= their index in the character list). * @@ -199,6 +181,10 @@ class Server : public QObject { */ DBManager* db_manager; + /** + * @brief The max amount of players on the server. + */ + QString max_players; /** * @brief The user-facing server name. * @@ -211,11 +197,43 @@ class Server : public QObject { */ QString MOTD; + /** + * @brief The authorization type of the server. + * + * @details In simple mode, the modpass stored in config.ini is used for moderator logins. In advanced mode, logins found in the database are used. + */ + QString auth_type; + + /** + * @brief The modpass for moderator login with simple auth_type. + */ + QString modpass; + + /** + * @brief The amount of subscripts zalgo is stripped by. + */ + int zalgo_tolerance; + + /** + * @brief The highest value dice can have. + */ + uint dice_value; + + /** + * @brief The max amount of dice that can be rolled at once. + */ + int max_dice; + /** * @brief The server-wide global timer. */ QTimer* timer; + /** + * @brief Loads values from config.ini. + */ + void loadServerConfig(); + /** * @brief Loads the configuration files for commands into stringlists. */ diff --git a/src/aoclient.cpp b/src/aoclient.cpp index d9599b5..762d99f 100644 --- a/src/aoclient.cpp +++ b/src/aoclient.cpp @@ -276,17 +276,17 @@ void AOClient::calculateIpid() void AOClient::sendServerMessage(QString message) { - sendPacket("CT", {server->getServerName(), message, "1"}); + sendPacket("CT", {server->server_name, message, "1"}); } void AOClient::sendServerMessageArea(QString message) { - server->broadcast(AOPacket("CT", {server->getServerName(), message, "1"}), current_area); + server->broadcast(AOPacket("CT", {server->server_name, message, "1"}), current_area); } void AOClient::sendServerBroadcast(QString message) { - server->broadcast(AOPacket("CT", {server->getServerName(), message, "1"})); + server->broadcast(AOPacket("CT", {server->server_name, message, "1"})); } bool AOClient::checkAuth(unsigned long long acl_mask) @@ -300,14 +300,11 @@ bool AOClient::checkAuth(unsigned long long acl_mask) else if (!authenticated) { return false; } - QSettings settings("config/config.ini", QSettings::IniFormat); - settings.beginGroup("Options"); - QString auth_type = settings.value("auth", "simple").toString(); - if (auth_type == "advanced") { + if (server->auth_type == "advanced") { unsigned long long user_acl = server->db_manager->getACL(moderator_name); return (user_acl & acl_mask) != 0; } - else if (auth_type == "simple") { + else if (server->auth_type == "simple") { return authenticated; } } diff --git a/src/area_data.cpp b/src/area_data.cpp index 95926bb..40a84dc 100644 --- a/src/area_data.cpp +++ b/src/area_data.cpp @@ -42,6 +42,7 @@ AreaData::AreaData(QString p_name, int p_index) : QSettings config_ini("config/config.ini", QSettings::IniFormat); config_ini.beginGroup("Options"); int log_size = config_ini.value("logbuffer", 50).toInt(); + log_type = config_ini.value("logger","modcall").toString(); config_ini.endGroup(); if (log_size == 0) log_size = 500; diff --git a/src/commands.cpp b/src/commands.cpp index b642cba..80fb487 100644 --- a/src/commands.cpp +++ b/src/commands.cpp @@ -27,21 +27,16 @@ void AOClient::cmdDefault(int argc, QStringList argv) void AOClient::cmdLogin(int argc, QStringList argv) { - QSettings config("config/config.ini", QSettings::IniFormat); - config.beginGroup("Options"); - QString modpass = config.value("modpass", "default").toString(); - QString auth_type = config.value("auth", "simple").toString(); - if (authenticated) { sendServerMessage("You are already logged in!"); return; } - if (auth_type == "simple") { - if (modpass == "") { + if (server->auth_type == "simple") { + if (server->modpass == "") { sendServerMessage("No modpass is set! Please set a modpass before authenticating."); } - else if(argv[0] == modpass) { + else if(argv[0] == server->modpass) { sendPacket("AUTH", {"1"}); // Client: "You were granted the Disable Modcalls button." sendServerMessage("Logged in as a moderator."); // pre-2.9.1 clients are hardcoded to display the mod UI when this string is sent in OOC authenticated = true; @@ -52,7 +47,7 @@ void AOClient::cmdLogin(int argc, QStringList argv) } server->areas.value(current_area)->logger->logLogin(this, authenticated, "moderator"); } - else if (auth_type == "advanced") { + else if (server->auth_type == "advanced") { if (argc < 2) { sendServerMessage("You must specify a username and a password"); return; @@ -194,11 +189,7 @@ void AOClient::cmdKick(int argc, QStringList argv) void AOClient::cmdChangeAuth(int argc, QStringList argv) { - QSettings settings("config/config.ini", QSettings::IniFormat); - settings.beginGroup("Options"); - QString auth_type = settings.value("auth", "simple").toString(); - - if (auth_type == "simple") { + if (server->auth_type == "simple") { change_auth_started = true; sendServerMessage("WARNING!\nThis command will change how logging in as a moderator works.\nOnly proceed if you know what you are doing\nUse the command /rootpass to set the password for your root account."); } @@ -214,6 +205,7 @@ void AOClient::cmdSetRootPass(int argc, QStringList argv) QSettings settings("config/config.ini", QSettings::IniFormat); settings.beginGroup("Options"); settings.setValue("auth", "advanced"); + server->auth_type = "advanced"; #if QT_VERSION < QT_VERSION_CHECK(5, 10, 0) qsrand(QDateTime::currentMSecsSinceEpoch()); @@ -828,14 +820,11 @@ void AOClient::cmdToggleGlobal(int argc, QStringList argv) void AOClient::cmdMods(int argc, QStringList argv) { QStringList entries; - QSettings config("config/config.ini", QSettings::IniFormat); - config.beginGroup("Options"); - QString auth_type = config.value("auth", "simple").toString(); int online_count = 0; for (AOClient* client : server->clients) { if (client->authenticated) { entries << "---"; - if (auth_type != "simple") + if (server->auth_type != "simple") entries << "Moderator: " + client->moderator_name; entries << "OOC name: " + client->ooc_name; entries << "ID: " + QString::number(client->id); @@ -1325,8 +1314,8 @@ int AOClient::genRand(int min, int max) void AOClient::diceThrower(int argc, QStringList argv, RollType type) { QString sender_name = ooc_name; - int max_value = server->getDiceValue("max_value"); - int max_dice = server->getDiceValue("max_dice"); + int max_value = server->dice_value; + int max_dice = server->max_dice; int bounded_value; int bounded_amount; QString dice_results; diff --git a/src/logger.cpp b/src/logger.cpp index 4dca853..96ea2c6 100644 --- a/src/logger.cpp +++ b/src/logger.cpp @@ -77,13 +77,10 @@ QString Logger::buildEntry(AOClient *client, QString type, QString message) void Logger::addEntry(QString entry) { - QSettings config("config/config.ini", QSettings::IniFormat); - config.beginGroup("Options"); - QString log_type = config.value("logging", "modcall").toString(); if (buffer.length() < max_length) { buffer.enqueue(entry); - if (log_type == "full") { - flush(); + if (area->log_type == "full") { + flush(); } } else { @@ -99,20 +96,20 @@ void Logger::flush() dir.mkpath("."); } - QSettings config("config/config.ini", QSettings::IniFormat); - config.beginGroup("Options"); - QString log_type = config.value("logging", "modcall").toString(); QFile logfile; - if (log_type == "modcall") { + if (area->log_type == "modcall") { logfile.setFileName(QString("logs/report_%1_%2.log").arg((area->name), (QDateTime::currentDateTime().toString("yyyy-MM-dd_hhmmss")))); } - else if (log_type == "full") { + else if (area->log_type == "full") { logfile.setFileName(QString("logs/%1.log").arg(QDate::currentDate().toString("yyyy-MM-dd"))); } - if (logfile.open(QIODevice::WriteOnly | QIODevice::Append)) { - QTextStream file_stream(&logfile); - while (!buffer.isEmpty()) - file_stream << buffer.dequeue(); + else { + qCritical("Invalid logger set!"); + } + if (logfile.open(QIODevice::WriteOnly | QIODevice::Append)) { + QTextStream file_stream(&logfile); + while (!buffer.isEmpty()) + file_stream << buffer.dequeue(); } logfile.close(); } diff --git a/src/packets.cpp b/src/packets.cpp index dd4d225..727c47a 100644 --- a/src/packets.cpp +++ b/src/packets.cpp @@ -37,10 +37,7 @@ void AOClient::pktHardwareId(AreaData* area, int argc, QStringList argv, AOPacke void AOClient::pktSoftwareId(AreaData* area, int argc, QStringList argv, AOPacket packet) { - QSettings config("config/config.ini", QSettings::IniFormat); - config.beginGroup("Options"); - QString max_players = config.value("max_players").toString(); - config.endGroup(); + // Full feature list as of AO 2.8.5 // The only ones that are critical to ensuring the server works are @@ -64,7 +61,7 @@ void AOClient::pktSoftwareId(AreaData* area, int argc, QStringList argv, AOPacke version.minor = match.captured(3).toInt(); } - sendPacket("PN", {QString::number(server->player_count), max_players}); + sendPacket("PN", {QString::number(server->player_count), server->max_players}); sendPacket("FL", feature_list); } @@ -181,7 +178,7 @@ void AOClient::pktOocChat(AreaData* area, int argc, QStringList argv, AOPacket p } ooc_name = dezalgo(argv[0]).replace(QRegExp("\\[|\\]|\\{|\\}|\\#|\\$|\\%|\\&"), ""); // no fucky wucky shit here - if (ooc_name.isEmpty() || ooc_name == server->getServerName()) // impersonation & empty name protection + if (ooc_name.isEmpty() || ooc_name == server->server_name) // impersonation & empty name protection return; QString message = dezalgo(argv[1]); @@ -629,14 +626,7 @@ AOPacket AOClient::validateIcPacket(AOPacket packet) 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)) + ",})"); + QRegExp rxp("([\u0300-\u036f\u1ab0-\u1aff\u1dc0-\u1dff\u20d0-\u20ff\ufe20-\ufe2f\u115f\u1160\u3164]{" + QRegExp::escape(QString::number(server->zalgo_tolerance)) + ",})"); QString filtered = p_text.replace(rxp, ""); return filtered; } diff --git a/src/server.cpp b/src/server.cpp index 99562c2..daa828f 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -51,7 +51,8 @@ void Server::start() qDebug() << "Server listening on" << port; } - MOTD = config.value("motd","MOTD is not set.").toString(); + loadServerConfig(); + loadCommandConfig(); proxy = new WSProxy(port, ws_port, this); if(ws_port != -1) @@ -96,7 +97,6 @@ void Server::start() QString area_name = raw_area_names[i]; areas.insert(i, new AreaData(area_name, i)); } - loadCommandConfig(); } void Server::clientConnected() @@ -169,24 +169,6 @@ 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; -} - -int Server::getDiceValue(QString value_type) -{ - QSettings settings("config/config.ini", QSettings::IniFormat); - - settings.beginGroup("Dice"); - int value = settings.value(value_type, "100").toUInt(); - settings.endGroup(); - return value; -} - QList Server::getClientsByIpid(QString ipid) { QList return_clients; @@ -235,6 +217,29 @@ QStringList Server::loadConfigFile(QString filename) return stringlist; } +void Server::loadServerConfig() +{ + QSettings config("config/config.ini", QSettings::IniFormat); + config.beginGroup("Options"); + //Load config.ini values + max_players = config.value("max_players","100").toString(); + server_name = config.value("server_name","An Unnamed Server").toString(); + MOTD = config.value("motd","MOTD is not set.").toString(); + auth_type = config.value("auth","simple").toString(); + modpass = config.value("modpass","").toString(); + bool zalgo_tolerance_conversion_success; + zalgo_tolerance = config.value("zalgo_tolerance", "3").toInt(&zalgo_tolerance_conversion_success); + if (!zalgo_tolerance_conversion_success) + zalgo_tolerance = 3; + config.endGroup(); + + //Load dice values + config.beginGroup("Dice"); + dice_value = config.value("value_type", "100").toUInt(); + max_dice = config.value("max_dice","100").toInt(); + config.endGroup(); +} + Server::~Server() { for (AOClient* client : clients) { From e529086f21078e4c22574616e36317e7667fdc27 Mon Sep 17 00:00:00 2001 From: MangosArentLiterature <58055358+MangosArentLiterature@users.noreply.github.com> Date: Fri, 9 Apr 2021 19:48:21 -0500 Subject: [PATCH 4/5] Minor tweak of loading command configs --- src/server.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/server.cpp b/src/server.cpp index daa828f..eb4976c 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -200,9 +200,9 @@ int Server::getCharID(QString char_name) void Server::loadCommandConfig() { - magic_8ball_answers.append(loadConfigFile("8ball")); - praise_list.append(loadConfigFile("praise")); - reprimands_list.append(loadConfigFile("reprimands")); + magic_8ball_answers = (loadConfigFile("8ball")); + praise_list = (loadConfigFile("praise")); + reprimands_list = (loadConfigFile("reprimands")); } QStringList Server::loadConfigFile(QString filename) From 5f0cc8537f472baa1e5c2af7a5abe95fa39fba64 Mon Sep 17 00:00:00 2001 From: MangosArentLiterature <58055358+MangosArentLiterature@users.noreply.github.com> Date: Tue, 13 Apr 2021 16:43:50 -0500 Subject: [PATCH 5/5] Add /reload Ceraptor helped me figure this out. - Adds /reload to reload values from config.ini, command config files, and recontact the master server - Adds Server::requestReload and Advertiser::reloadRequested - Adds QString server_desc and some minor changes to config loading. --- include/advertiser.h | 8 ++++++++ include/aoclient.h | 1 + include/server.h | 17 +++++++++++++++-- src/advertiser.cpp | 7 +++++++ src/commands.cpp | 8 ++++++++ src/main.cpp | 1 + src/server.cpp | 3 ++- 7 files changed, 42 insertions(+), 3 deletions(-) diff --git a/include/advertiser.h b/include/advertiser.h index bdd834c..62ab1f6 100644 --- a/include/advertiser.h +++ b/include/advertiser.h @@ -89,6 +89,14 @@ class Advertiser : public QObject { */ void socketDisconnected(); + /** + * @brief Handles updating the advertiser and recontacting the master server. + * + * @param p_name The new server name. + * @param p_desc The new server description. + */ + void reloadRequested(QString p_name, QString p_desc); + private: /** * @copydoc ConfigManager::server_settings::ms_ip diff --git a/include/aoclient.h b/include/aoclient.h index 86230a5..a02f111 100644 --- a/include/aoclient.h +++ b/include/aoclient.h @@ -1625,6 +1625,7 @@ class AOClient : public QObject { {"judgelog", {ACLFlags.value("CM"), 0, &AOClient::cmdJudgeLog}}, {"allow_blankposting", {ACLFlags.value("MODCHAT"), 0, &AOClient::cmdAllow_Blankposting}}, {"baninfo", {ACLFlags.value("BAN"), 1, &AOClient::cmdBanInfo}}, + {"reload", {ACLFlags.value("SUPER"), 0, &AOClient::cmdReload}}, }; /** diff --git a/include/server.h b/include/server.h index 65886c2..4c98e87 100644 --- a/include/server.h +++ b/include/server.h @@ -187,11 +187,14 @@ class Server : public QObject { QString max_players; /** * @brief The user-facing server name. - * - * @note Unused. getServerName() serves its purpose instead. */ QString server_name; + /** + * @brief The server description. + */ + QString server_desc; + /** * @brief The Message Of The Day of the server, shown upon entry to the server and on request. */ @@ -270,6 +273,16 @@ class Server : public QObject { */ void clientConnected(); + signals: + + /** + * @brief Sends the server name and description, emitted by /reload. + * + * @param p_name The server name. + * @param p_desc The server description. + */ + void reloadRequest(QString p_name, QString p_desc); + private: /** * @brief The proxy used for WebSocket connections. diff --git a/src/advertiser.cpp b/src/advertiser.cpp index 5921b53..5bc8aec 100644 --- a/src/advertiser.cpp +++ b/src/advertiser.cpp @@ -64,6 +64,13 @@ void Advertiser::socketDisconnected() qDebug("Connection to master server lost"); } +void Advertiser::reloadRequested(QString p_name, QString p_desc) +{ + name = p_name; + description = p_desc; + socketConnected(); +} + Advertiser::~Advertiser() { socket->deleteLater(); diff --git a/src/commands.cpp b/src/commands.cpp index 9452f5a..b0bd83a 100644 --- a/src/commands.cpp +++ b/src/commands.cpp @@ -1328,6 +1328,14 @@ void AOClient::cmdBanInfo(int argc, QStringList argv) sendServerMessage(ban_info.join("\n")); } +void AOClient::cmdReload(int argc, QStringList argv) +{ + server->loadServerConfig(); + server->loadCommandConfig(); + emit server->reloadRequest(server->server_name, server->server_desc); + sendServerMessage("Reloaded configurations"); +} + QStringList AOClient::buildAreaList(int area_idx) { QStringList entries; diff --git a/src/main.cpp b/src/main.cpp index defcf23..8579592 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -62,6 +62,7 @@ int main(int argc, char* argv[]) } server = new Server(settings.port, settings.ws_port); + QObject::connect(server, &Server::reloadRequest, advertiser, &Advertiser::reloadRequested); server->start(); } } else { diff --git a/src/server.cpp b/src/server.cpp index eb4976c..2b44c7b 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -224,6 +224,7 @@ void Server::loadServerConfig() //Load config.ini values max_players = config.value("max_players","100").toString(); server_name = config.value("server_name","An Unnamed Server").toString(); + server_desc = config.value("server_description","This is a placeholder server description. Tell the world of AO who you are here!").toString(); MOTD = config.value("motd","MOTD is not set.").toString(); auth_type = config.value("auth","simple").toString(); modpass = config.value("modpass","").toString(); @@ -235,7 +236,7 @@ void Server::loadServerConfig() //Load dice values config.beginGroup("Dice"); - dice_value = config.value("value_type", "100").toUInt(); + dice_value = config.value("value_type", "100").toInt(); max_dice = config.value("max_dice","100").toInt(); config.endGroup(); }