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] 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(); }