From e6109c98bd0d23b1e189dc3f28cf471662ddd0f7 Mon Sep 17 00:00:00 2001 From: Lion Kortlepel Date: Thu, 18 Mar 2021 23:30:52 +0100 Subject: [PATCH] Application: Move some string literal URLs to functions --- include/Common.h | 4 ++++ src/SocketIO.cpp | 2 +- src/THeartbeatThread.cpp | 4 ++-- src/TNetwork.cpp | 2 +- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/include/Common.h b/include/Common.h index 41ed62f..89df249 100644 --- a/include/Common.h +++ b/include/Common.h @@ -49,6 +49,10 @@ public: static inline TSettings Settings {}; + static std::string GetBackendUrlForAuth() { return "auth.beammp.com"; } + static std::string GetBackendHostname() { return "beammp.com"; } + static std::string GetBackendUrlForSocketIO() { return "https://backend.beammp.com"; } + private: static inline std::string mPPS; static std::unique_ptr mConsole; diff --git a/src/SocketIO.cpp b/src/SocketIO.cpp index 137c24e..2c10f6f 100644 --- a/src/SocketIO.cpp +++ b/src/SocketIO.cpp @@ -27,7 +27,7 @@ SocketIO::SocketIO() noexcept mClient.set_logs_quiet(); mClient.set_reconnect_delay(10000); - mClient.connect("https://backend.beammp.com"); + mClient.connect(Application::GetBackendUrlForSocketIO()); } SocketIO::~SocketIO() { diff --git a/src/THeartbeatThread.cpp b/src/THeartbeatThread.cpp index 579dd86..99458ee 100644 --- a/src/THeartbeatThread.cpp +++ b/src/THeartbeatThread.cpp @@ -36,12 +36,12 @@ void THeartbeatThread::operator()() { Body += "&pps=" + Application::PPS(); - T = Http::POST("beammp.com", "/heartbeatv2", {}, Body, false); + T = Http::POST(Application::GetBackendHostname(), "/heartbeatv2", {}, Body, false); if (T.substr(0, 2) != "20") { //Backend system refused server startup! std::this_thread::sleep_for(std::chrono::milliseconds(500)); - T = Http::POST("beammp.com", "/heartbeatv2", {}, Body, false); + T = Http::POST(Application::GetBackendHostname(), "/heartbeatv2", {}, Body, false); // TODO backup2 + HTTP flag (no TSL) if (T.substr(0, 2) != "20") { warn("Backend system refused server! Server might not show in the public list"); diff --git a/src/TNetwork.cpp b/src/TNetwork.cpp index 38b9ec8..600f32b 100644 --- a/src/TNetwork.cpp +++ b/src/TNetwork.cpp @@ -261,7 +261,7 @@ void TNetwork::Authentication(SOCKET TCPSock) { } if (!Rc.empty()) { - Rc = Http::POST("auth.beammp.com", "/pkToUser", {}, R"({"key":")" + Rc + "\"}", true); + Rc = Http::POST(Application::GetBackendUrlForAuth(), "/pkToUser", {}, R"({"key":")" + Rc + "\"}", true); } debug("Auth response: " + Rc);