Skip to content

Commit

Permalink
[Cleanup] Overhaul Server Advertiser/Publisher (#369)
Browse files Browse the repository at this point in the history
* Overhaul advertiser to suck less

* Remove stray QDebug
  • Loading branch information
Salanto authored Jul 20, 2024
1 parent d2b378b commit d8ec4cc
Show file tree
Hide file tree
Showing 12 changed files with 199 additions and 285 deletions.
3 changes: 0 additions & 3 deletions bin/config_sample/config.ini
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,6 @@ asset_url=http://attorneyoffline.de/base/
; Whether or not the server should appear on the master server.
advertise=true

; Wether the advertiser prints additional debug info
debug=false

; The IP address of the master server. Unless something happens to the default one, you shouldn't change this.
ms_ip=https://servers.aceattorneyonline.com/servers

Expand Down
4 changes: 2 additions & 2 deletions core.pro
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ SOURCES += \
src/packets.cpp \
src/playerstateobserver.cpp \
src/server.cpp \
src/serverpublisher.cpp \
src/testimony_recorder.cpp \
src/advertiser.cpp \
src/logger/u_logger.cpp \
src/logger/writer_modcall.cpp \
src/logger/writer_full.cpp \
Expand Down Expand Up @@ -95,8 +95,8 @@ HEADERS += src/aoclient.h \
src/packet/packet_pr.h \
src/playerstateobserver.h \
src/server.h \
src/serverpublisher.h \
src/typedefs.h \
src/advertiser.h \
src/logger/u_logger.h \
src/logger/writer_modcall.h \
src/logger/writer_full.h \
Expand Down
121 changes: 0 additions & 121 deletions src/advertiser.cpp

This file was deleted.

112 changes: 0 additions & 112 deletions src/advertiser.h

This file was deleted.

14 changes: 4 additions & 10 deletions src/config_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -626,28 +626,22 @@ QStringList ConfigManager::cdnList()
return m_commands->cdns;
}

bool ConfigManager::advertiseServer()
bool ConfigManager::publishServerEnabled()
{
return m_settings->value("Advertiser/advertise", "true").toBool();
}

bool ConfigManager::advertiserDebug()
QUrl ConfigManager::serverlistURL()
{
return m_settings->value("Advertiser/debug", "true").toBool();
}

QUrl ConfigManager::advertiserIP()
{
qDebug() << m_settings->value("Advertiser/ms_ip", "").toUrl();
return m_settings->value("Advertiser/ms_ip", "").toUrl();
}

QString ConfigManager::advertiserHostname()
QString ConfigManager::serverDomainName()
{
return m_settings->value("Advertiser/hostname", "").toString();
}

bool ConfigManager::advertiserCloudflareMode()
bool ConfigManager::advertiseWSProxy()
{
return m_settings->value("Advertiser/cloudflare_enabled", "false").toBool();
}
Expand Down
13 changes: 4 additions & 9 deletions src/config_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -431,29 +431,24 @@ class ConfigManager
/**
* @brief Returns if the advertiser is enabled to advertise on ms3.
*/
static bool advertiseServer();

/**
* @brief Returns if the advertiser prints debug info to console.
*/
static bool advertiserDebug();
static bool publishServerEnabled();

/**
* @brief Returns the IP or URL of the masterserver.
*/
static QUrl advertiserIP();
static QUrl serverlistURL();

/**
* @brief Returns an optional hostname paramemter for the advertiser.
* If used allows user to set a custom IP or domain name.
*/
static QString advertiserHostname();
static QString serverDomainName();

/**
* @brief Returns a dummy port instead of the real port
* @return
*/
static bool advertiserCloudflareMode();
static bool advertiseWSProxy();

/**
* @brief Returns the uptime of the server in miliseconds.
Expand Down
2 changes: 1 addition & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ int main(int argc, char *argv[])
QCoreApplication::quit();
}
else {
server = new Server(ConfigManager::serverPort());
server = new Server(ConfigManager::serverPort(), &app);
server->start();
}

Expand Down
14 changes: 2 additions & 12 deletions src/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
#include "server.h"

#include "acl_roles_handler.h"
#include "advertiser.h"
#include "aoclient.h"
#include "area_data.h"
#include "command_extension.h"
Expand All @@ -29,6 +28,7 @@
#include "music_manager.h"
#include "network/network_socket.h"
#include "packet/packet_factory.h"
#include "serverpublisher.h"

Server::Server(int p_ws_port, QObject *parent) :
QObject(parent),
Expand Down Expand Up @@ -81,17 +81,7 @@ void Server::start()
handleDiscordIntegration();

// Construct modern advertiser if enabled in config
if (ConfigManager::advertiseServer()) {
AdvertiserTimer = new QTimer(this);
ms3_Advertiser = new Advertiser(server->serverPort());

connect(AdvertiserTimer, &QTimer::timeout, ms3_Advertiser, &Advertiser::msAdvertiseServer);
connect(this, &Server::playerCountUpdated, ms3_Advertiser, &Advertiser::updatePlayerCount);
connect(this, &Server::updateHTTPConfiguration, ms3_Advertiser, &Advertiser::updateAdvertiserSettings);
emit playerCountUpdated(m_player_count);
ms3_Advertiser->msAdvertiseServer();
AdvertiserTimer->start(300000);
}
server_publisher = new ServerPublisher(server->serverPort(), &m_player_count, this);

// Get characters from config file
m_characters = ConfigManager::charlist();
Expand Down
9 changes: 2 additions & 7 deletions src/server.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
#include "playerstateobserver.h"

class ACLRolesHandler;
class Advertiser;
class ServerPublisher;
class AOClient;
class AreaData;
class CommandExtensionCollection;
Expand Down Expand Up @@ -421,12 +421,7 @@ class Server : public QObject
/**
* @brief Handles HTTP server advertising.
*/
Advertiser *ms3_Advertiser;

/**
* @brief Advertises the server in a regular intervall.
*/
QTimer *AdvertiserTimer;
ServerPublisher *server_publisher;

/**
* @brief Handles the universal log framework.
Expand Down
Loading

0 comments on commit d8ec4cc

Please sign in to comment.