Merge pull request #175 from Salanto/updateModernAdvertiser

Properly reload modern advertiser config
This commit is contained in:
scatterflower 2021-08-02 16:44:42 -05:00 committed by GitHub
commit cbad7b92b2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 56 additions and 8 deletions

View File

@ -32,6 +32,14 @@ struct advertiser_config {
bool debug;
};
struct update_advertiser_config {
QString name;
QString description;
int players;
QUrl masterserver;
bool debug;
};
/**
* @brief Represents the advertiser of the server. Sends current server information to masterserver.
*/
@ -69,6 +77,12 @@ public slots:
*/
void setAdvertiserSettings(advertiser_config config);
/**
* @brief Sets the updated values being advertiser to masterserver.
* @param config Configuration struct for the advertiser. Only includes partial information, as ports can't be changed.
*/
void updateAdvertiserSettings(update_advertiser_config config);
private:
/**

View File

@ -141,7 +141,12 @@ class Server : public QObject {
/**
* @brief Creates an HTTP advertiser config struct and emits it using server::reloadHTTPRequest.
*/
void reloadHTTPAdvertiserConfig();
void setHTTPAdvertiserConfig();
/**
* @brief Updates the modern advertiser configuration on configuration reload.
*/
void updateHTTPAdvertiserConfig();
/**
* @brief The collection of all currently connected clients.
@ -234,10 +239,16 @@ class Server : public QObject {
void reloadRequest(QString p_name, QString p_desc);
/**
* @brief Sends all necessary info for the new advertiser.
* @brief Sends all necessary info for the modern advertiser.
* @param Struct that contains all configuration for the advertiser
*/
void reloadHTTPRequest(struct advertiser_config config);
void setHTTPConfiguration(struct advertiser_config config);
/**
* @brief Sends a partial update to the modern advertiser.
* @param Struct that contains partial information about the server to update the advertised information.
*/
void updateHTTPConfiguration(struct update_advertiser_config config);
/**
* @brief Sends a modcall webhook request, emitted by AOClient::pktModcall.

View File

@ -412,7 +412,7 @@ void AOClient::cmdReload(int argc, QStringList argv)
{
ConfigManager::reloadSettings();
emit server->reloadRequest(ConfigManager::serverName(), ConfigManager::serverDescription());
server->reloadHTTPAdvertiserConfig();
server->updateHTTPAdvertiserConfig();
sendServerMessage("Reloaded configurations");
}

View File

@ -79,4 +79,13 @@ void HTTPAdvertiser::setAdvertiserSettings(advertiser_config config)
msAdvertiseServer();
}
void HTTPAdvertiser::updateAdvertiserSettings(update_advertiser_config config)
{
m_name = config.name;
m_description = config.description;
m_players = config.players;
m_masterserver = config.masterserver;
m_debug = config.debug;
}

View File

@ -64,9 +64,11 @@ void Server::start()
connect(httpAdvertiserTimer, &QTimer::timeout,
httpAdvertiser, &HTTPAdvertiser::msAdvertiseServer);
connect(this, &Server::reloadHTTPRequest,
connect(this, &Server::setHTTPConfiguration,
httpAdvertiser, &HTTPAdvertiser::setAdvertiserSettings);
reloadHTTPAdvertiserConfig();
connect(this, &Server::updateHTTPConfiguration,
httpAdvertiser, &HTTPAdvertiser::updateAdvertiserSettings);
setHTTPAdvertiserConfig();
httpAdvertiserTimer->start(300000);
}
@ -255,7 +257,7 @@ int Server::getCharID(QString char_name)
return -1; // character does not exist
}
void Server::reloadHTTPAdvertiserConfig()
void Server::setHTTPAdvertiserConfig()
{
advertiser_config config;
config.name = ConfigManager::serverName();
@ -265,7 +267,19 @@ void Server::reloadHTTPAdvertiserConfig()
config.players = ConfigManager::maxPlayers();
config.masterserver = ConfigManager::advertiserHTTPIP();
config.debug = ConfigManager::advertiserHTTPDebug();
emit reloadHTTPRequest(config);
emit setHTTPConfiguration(config);
}
void Server::updateHTTPAdvertiserConfig()
{
update_advertiser_config config;
config.name = ConfigManager::serverName();
config.description = ConfigManager::serverDescription();
config.players = ConfigManager::maxPlayers();
config.masterserver = ConfigManager::advertiserHTTPIP();
config.debug = ConfigManager::advertiserHTTPDebug();
emit updateHTTPConfiguration(config);
}
void Server::allowMessage()