From d39f93926f64770c6f397d2a774ba9cc194312ae Mon Sep 17 00:00:00 2001 From: Salanto <62221668+Salanto@users.noreply.github.com> Date: Thu, 9 Jun 2022 23:55:18 +0200 Subject: [PATCH] Enable websocket port overwrite in advertiser *Advertises port 80 if the AO Server is behind a reverse proxy, like cloudflare tunnels. --- bin/config_sample/config.ini | 3 +++ core/include/config_manager.h | 6 ++++++ core/src/advertiser.cpp | 9 ++++++++- core/src/config_manager.cpp | 5 +++++ 4 files changed, 22 insertions(+), 1 deletion(-) diff --git a/bin/config_sample/config.ini b/bin/config_sample/config.ini index 9a3bae9..aa55025 100644 --- a/bin/config_sample/config.ini +++ b/bin/config_sample/config.ini @@ -73,6 +73,9 @@ ms_ip=https://servers.aceattorneyonline.com/servers ; Optional hostname of your server. Can either be an IP or a DNS name. Disables automatic IP detection of ms3. hostname= +; Wether or not the server overwrites the advertised webao port to port 80 in order to utilise Cloudflare tunnels. +cloudflare_enabled=false + [Dice] ; The maximum number of sides dice can be rolled with. max_value=100 diff --git a/core/include/config_manager.h b/core/include/config_manager.h index b4121f4..03b00a5 100644 --- a/core/include/config_manager.h +++ b/core/include/config_manager.h @@ -449,6 +449,12 @@ class ConfigManager */ static QString advertiserHostname(); + /** + * @brief Returns a dummy port instead of the real port + * @return + */ + static bool advertiserCloudflareMode(); + /** * @brief Returns the uptime of the server in miliseconds. */ diff --git a/core/src/advertiser.cpp b/core/src/advertiser.cpp index 488202a..424f007 100644 --- a/core/src/advertiser.cpp +++ b/core/src/advertiser.cpp @@ -29,7 +29,14 @@ Advertiser::Advertiser() m_hostname = ConfigManager::advertiserHostname(); m_description = ConfigManager::serverDescription(); m_port = ConfigManager::serverPort(); - m_ws_port = ConfigManager::webaoPort(); + + // Cheap workaround to correctly advertise when Cloudflare tunnel is used. + if (ConfigManager::advertiserCloudflareMode()) { + m_ws_port = 80; + } + else { + m_ws_port = ConfigManager::webaoPort(); + } m_masterserver = ConfigManager::advertiserIP(); m_debug = ConfigManager::advertiserDebug(); } diff --git a/core/src/config_manager.cpp b/core/src/config_manager.cpp index c81aceb..7536c8d 100644 --- a/core/src/config_manager.cpp +++ b/core/src/config_manager.cpp @@ -610,6 +610,11 @@ QString ConfigManager::advertiserHostname() return m_settings->value("Advertiser/hostname", "").toString(); } +bool ConfigManager::advertiserCloudflareMode() +{ + return m_settings->value("Advertiser/cloudflare_enabled", "false").toBool(); +} + qint64 ConfigManager::uptime() { return m_uptimeTimer->elapsed();