aboutsummaryrefslogtreecommitdiff
path: root/NorthstarDedicatedTest/masterserver.cpp
diff options
context:
space:
mode:
authorKawe Mazidjatari <48657826+Mauler125@users.noreply.github.com>2022-06-16 19:22:48 +0200
committerGitHub <noreply@github.com>2022-06-16 19:22:48 +0200
commit8e5b7802fb013fac614268809f03885454998d30 (patch)
treeffc844d2836831c5e538df2df82551753bf67dd9 /NorthstarDedicatedTest/masterserver.cpp
parent57e071fdd9c6b7e7d0172b68435a42be78074f86 (diff)
parent4487becdb849125d0161b0269070de7f395f688d (diff)
downloadNorthstarLauncher-8e5b7802fb013fac614268809f03885454998d30.tar.gz
NorthstarLauncher-8e5b7802fb013fac614268809f03885454998d30.zip
Merge branch 'main' into NetCon
Diffstat (limited to 'NorthstarDedicatedTest/masterserver.cpp')
-rw-r--r--NorthstarDedicatedTest/masterserver.cpp42
1 files changed, 42 insertions, 0 deletions
diff --git a/NorthstarDedicatedTest/masterserver.cpp b/NorthstarDedicatedTest/masterserver.cpp
index d351fc13..28d11d4f 100644
--- a/NorthstarDedicatedTest/masterserver.cpp
+++ b/NorthstarDedicatedTest/masterserver.cpp
@@ -12,6 +12,7 @@
#include "modmanager.h"
#include "misccommands.h"
#include "host_state.h"
+#include "version.h"
// NOTE for anyone reading this: we used to use httplib for requests here, but it had issues, so we're moving to curl now for masterserver
// requests so httplib is used exclusively for server stuff now
@@ -488,6 +489,10 @@ void MasterServerManager::RequestMainMenuPromos()
{
spdlog::error("Failed reading masterserver response: got fastify error response");
spdlog::error(readBuffer);
+ if (mainMenuPromoJson["error"].HasMember("enum"))
+ s_authfail_reason = std::string(mainMenuPromoJson["error"]["enum"].GetString());
+ else
+ s_authfail_reason = std::string("No error message provided");
goto REQUEST_END_CLEANUP;
}
@@ -608,6 +613,10 @@ void MasterServerManager::AuthenticateWithOwnServer(char* uid, char* playerToken
{
spdlog::error("Failed reading masterserver response: got fastify error response");
spdlog::error(readBuffer);
+ if (authInfoJson["error"].HasMember("enum"))
+ s_authfail_reason = std::string(authInfoJson["error"]["enum"].GetString());
+ else
+ s_authfail_reason = std::string("No error message provided");
goto REQUEST_END_CLEANUP;
}
@@ -755,6 +764,10 @@ void MasterServerManager::AuthenticateWithServer(char* uid, char* playerToken, c
{
spdlog::error("Failed reading masterserver response: got fastify error response");
spdlog::error(readBuffer);
+ if (connectionInfoJson["error"].HasMember("enum"))
+ s_authfail_reason = std::string(connectionInfoJson["error"]["enum"].GetString());
+ else
+ s_authfail_reason = std::string("No error message provided");
goto REQUEST_END_CLEANUP;
}
@@ -822,6 +835,10 @@ void MasterServerManager::AddSelfToServerList(
std::thread requestThread(
[this, port, authPort, strName, strDescription, strMap, strPlaylist, maxPlayers, strPassword]
{
+ // Keep track of attempted connects in case of DUPLICATE_SERVER response
+ int retry_counter = 0;
+
+ START_REQUEST:
m_ownServerId[0] = 0;
m_ownServerAuthToken[0] = 0;
@@ -901,6 +918,29 @@ void MasterServerManager::AddSelfToServerList(
{
spdlog::error("Failed reading masterserver response: got fastify error response");
spdlog::error(readBuffer);
+
+ // Check for enum member in JSON
+ if (serverAddedJson["error"].HasMember("enum"))
+ {
+ // Check for DUPLICATE_SERVER error response, stop if we tried 10 times
+ if (strncmp(serverAddedJson["error"]["enum"].GetString(), "DUPLICATE_SERVER", 17) == 0 && retry_counter < 10)
+ {
+
+ spdlog::info("Retrying request in 10 seconds.");
+ // Incremement retry counter
+ retry_counter++;
+
+ // Sleep for 10 seconds
+ std::this_thread::sleep_for(std::chrono::seconds(10));
+
+ // curl cleanup to retry request
+ curl_easy_cleanup(curl);
+ curl_mime_free(mime);
+
+ // go to beginning and retry
+ goto START_REQUEST;
+ }
+ }
goto REQUEST_END_CLEANUP;
}
@@ -923,6 +963,8 @@ void MasterServerManager::AddSelfToServerList(
strncpy(m_ownServerAuthToken, serverAddedJson["serverAuthToken"].GetString(), sizeof(m_ownServerAuthToken));
m_ownServerAuthToken[sizeof(m_ownServerAuthToken) - 1] = 0;
+ spdlog::info("Succesfully added server to the master server.");
+
// heartbeat thread
// ideally this should actually be done in main thread, rather than on it's own thread, so it'd stop if server freezes
std::thread heartbeatThread(