diff --git a/bin/config_sample/config.ini b/bin/config_sample/config.ini index 2d342cf..0899989 100644 --- a/bin/config_sample/config.ini +++ b/bin/config_sample/config.ini @@ -74,7 +74,10 @@ advertise=false debug=false ; The IP address of the master server. Unless something happens to the default one, you shouldn't change this. -ms_ip=https://ms3.oldmud0.workers.dev/servers +ms_ip=https://servers.aceattorneyonline.com/servers + +; Optional hostname of your server. Can either be an IP or a DNS name. Disabled automatic IP detection of ms3. +hostname= [Dice] ; The maximum number of sides dice can be rolled with. diff --git a/core/include/config_manager.h b/core/include/config_manager.h index b228a68..6bd08a0 100644 --- a/core/include/config_manager.h +++ b/core/include/config_manager.h @@ -448,6 +448,12 @@ class ConfigManager { */ static QUrl advertiserHTTPIP(); + /** + * @brief Returns an optional hostname paramemter for the advertiser. + * If used allows user to set a custom IP or domain name. + */ + static QString advertiserHostname(); + /** * @brief Returns the uptime of the server in miliseconds. */ diff --git a/core/include/http_advertiser.h b/core/include/http_advertiser.h index b576047..d1a1f75 100644 --- a/core/include/http_advertiser.h +++ b/core/include/http_advertiser.h @@ -20,25 +20,7 @@ #include #include - -//Don't question this. It needs to be here for some reason. -struct advertiser_config { - QString name; - QString description; - int port; - int ws_port; - int players; - QUrl masterserver; - bool debug; -}; - -struct update_advertiser_config { - QString name; - QString description; - int players; - QUrl masterserver; - bool debug; -}; +#include "include/config_manager.h" /** * @brief Represents the advertiser of the server. Sends current server information to masterserver. @@ -72,16 +54,14 @@ public slots: void msRequestFinished(QNetworkReply *f_reply); /** - * @brief Sets the values being advertised to masterserver. - * @param config Configuration struct for the advertiser. Always includes ALL settings. + * @brief Updates the playercount of the server in the advertiser. */ - void setAdvertiserSettings(advertiser_config config); + void updatePlayerCount(int f_current_players); /** - * @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. + * @brief Updates advertisement values */ - void updateAdvertiserSettings(update_advertiser_config config); + void updateAdvertiserSettings(); private: @@ -95,6 +75,11 @@ private: */ QString m_name; + /** + * @brief Optional hostname of the server. Can either be an IP or a DNS name. Disabled automatic IP detection of ms3. + */ + QString m_hostname; + /** * @brief Description of the server that is displayed in the client when the server is selected. */ diff --git a/core/include/server.h b/core/include/server.h index 7afbb61..70e45f9 100644 --- a/core/include/server.h +++ b/core/include/server.h @@ -169,16 +169,6 @@ class Server : public QObject { */ int getCharID(QString char_name); - /** - * @brief Creates an HTTP advertiser config struct and emits it using server::reloadHTTPRequest. - */ - void setHTTPAdvertiserConfig(); - - /** - * @brief Updates the modern advertiser configuration on configuration reload. - */ - void updateHTTPAdvertiserConfig(); - /** * @brief Checks if an IP is in a subnet of the IPBanlist. **/ @@ -303,16 +293,15 @@ class Server : public QObject { void reloadRequest(QString p_name, QString p_desc); /** - * @brief Sends all necessary info for the modern advertiser. - * @param Struct that contains all configuration for the advertiser + * @brief Updates the playercount in the modern advertiser. */ - void setHTTPConfiguration(struct advertiser_config config); + void updatePlayerCount(int f_current_players); /** - * @brief Sends a partial update to the modern advertiser. - * @param Struct that contains partial information about the server to update the advertised information. + * @brief Triggers a partial update of the modern advertiser as some information, such as ports + * can't be updated while the server is running. */ - void updateHTTPConfiguration(struct update_advertiser_config config); + void updateHTTPConfiguration(); /** * @brief Sends a modcall webhook request, emitted by AOClient::pktModcall. diff --git a/core/src/aoclient.cpp b/core/src/aoclient.cpp index 96f6195..bc21d76 100644 --- a/core/src/aoclient.cpp +++ b/core/src/aoclient.cpp @@ -54,6 +54,7 @@ void AOClient::clientDisconnected() #endif if (m_joined) { server->m_player_count--; + emit server->updatePlayerCount(server->m_player_count); server->m_areas[m_current_area]->clientLeftArea(server->getCharID(m_current_char)); arup(ARUPType::PLAYER_COUNT, true); } diff --git a/core/src/config_manager.cpp b/core/src/config_manager.cpp index 601506e..a373a95 100644 --- a/core/src/config_manager.cpp +++ b/core/src/config_manager.cpp @@ -592,6 +592,11 @@ QUrl ConfigManager::advertiserHTTPIP() return m_settings->value("ModernAdvertiser/ms_ip","").toUrl(); } +QString ConfigManager::advertiserHostname() +{ + return m_settings->value("ModernAdvertiser/hostname","").toString(); +} + qint64 ConfigManager::uptime() { return m_uptimeTimer->elapsed(); diff --git a/core/src/http_advertiser.cpp b/core/src/http_advertiser.cpp index 94a504a..f723982 100644 --- a/core/src/http_advertiser.cpp +++ b/core/src/http_advertiser.cpp @@ -5,6 +5,15 @@ HTTPAdvertiser::HTTPAdvertiser() m_manager = new QNetworkAccessManager(); connect(m_manager, &QNetworkAccessManager::finished, this, &HTTPAdvertiser::msRequestFinished); + + + m_name = ConfigManager::serverName(); + m_hostname = ConfigManager::advertiserHostname(); + m_description = ConfigManager::serverDescription(); + m_port = ConfigManager::serverPort(); + m_ws_port = ConfigManager::webaoPort(); + m_masterserver = ConfigManager::advertiserHTTPIP(); + m_debug = ConfigManager::advertiserHTTPDebug(); } HTTPAdvertiser::~HTTPAdvertiser() @@ -21,6 +30,11 @@ void HTTPAdvertiser::msAdvertiseServer() request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json"); QJsonObject l_json; + + if (!m_hostname.isEmpty()) { + l_json["ip"] = m_hostname; + } + l_json["port"] = m_port; if (m_ws_port != -1) { l_json["ws_port"] = m_ws_port; @@ -66,26 +80,18 @@ void HTTPAdvertiser::msRequestFinished(QNetworkReply *f_reply) f_reply->deleteLater(); } -void HTTPAdvertiser::setAdvertiserSettings(advertiser_config config) +void HTTPAdvertiser::updatePlayerCount(int f_current_players) { - m_name = config.name; - m_description = config.description; - m_port = config.port; - m_ws_port = config.ws_port; - m_players = config.players; - m_masterserver = config.masterserver; - m_debug = config.debug; - - msAdvertiseServer(); + m_players = f_current_players; } -void HTTPAdvertiser::updateAdvertiserSettings(update_advertiser_config config) +void HTTPAdvertiser::updateAdvertiserSettings() { - m_name = config.name; - m_description = config.description; - m_players = config.players; - m_masterserver = config.masterserver; - m_debug = config.debug; + m_name = ConfigManager::serverName(); + m_hostname = ConfigManager::advertiserHostname(); + m_description = ConfigManager::serverDescription(); + m_masterserver = ConfigManager::advertiserHTTPIP(); + m_debug = ConfigManager::advertiserHTTPDebug(); } diff --git a/core/src/packets.cpp b/core/src/packets.cpp index b668ff5..0f78f18 100644 --- a/core/src/packets.cpp +++ b/core/src/packets.cpp @@ -133,6 +133,7 @@ void AOClient::pktLoadingDone(AreaData* area, int argc, QStringList argv, AOPack } server->m_player_count++; + emit server->updatePlayerCount(server->m_player_count); area->clientJoinedArea(); m_joined = true; server->updateCharsTaken(area); diff --git a/core/src/server.cpp b/core/src/server.cpp index e70246d..3080f5f 100644 --- a/core/src/server.cpp +++ b/core/src/server.cpp @@ -69,11 +69,12 @@ void Server::start() connect(httpAdvertiserTimer, &QTimer::timeout, httpAdvertiser, &HTTPAdvertiser::msAdvertiseServer); - connect(this, &Server::setHTTPConfiguration, - httpAdvertiser, &HTTPAdvertiser::setAdvertiserSettings); + connect(this, &Server::updatePlayerCount, + httpAdvertiser, &HTTPAdvertiser::updatePlayerCount); connect(this, &Server::updateHTTPConfiguration, httpAdvertiser, &HTTPAdvertiser::updateAdvertiserSettings); - setHTTPAdvertiserConfig(); + emit updatePlayerCount(m_player_count); + httpAdvertiser->msAdvertiseServer(); httpAdvertiserTimer->start(300000); } @@ -232,7 +233,7 @@ void Server::reloadSettings() { ConfigManager::reloadSettings(); emit reloadRequest(ConfigManager::serverName(), ConfigManager::serverDescription()); - updateHTTPAdvertiserConfig(); + emit updateHTTPConfiguration(); handleDiscordIntegration(); logger->loadLogtext(); m_music_list = ConfigManager::musiclist(); @@ -321,31 +322,6 @@ int Server::getCharID(QString char_name) return -1; // character does not exist } -void Server::setHTTPAdvertiserConfig() -{ - advertiser_config config; - config.name = ConfigManager::serverName(); - config.description = ConfigManager::serverDescription(); - config.port = ConfigManager::serverPort(); - config.ws_port = ConfigManager::webaoPort(); - config.players = ConfigManager::maxPlayers(); - config.masterserver = ConfigManager::advertiserHTTPIP(); - config.debug = ConfigManager::advertiserHTTPDebug(); - 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); - -} - QQueue Server::getAreaBuffer(const QString &f_areaName) { return logger->buffer(f_areaName);