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.
This commit is contained in:
MangosArentLiterature 2021-04-13 16:43:50 -05:00
parent c2d1286e27
commit 5f0cc8537f
7 changed files with 42 additions and 3 deletions

View File

@ -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

View File

@ -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}},
};
/**

View File

@ -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.

View File

@ -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();

View File

@ -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;

View File

@ -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 {

View File

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