aboutsummaryrefslogtreecommitdiff
path: root/NorthstarDedicatedTest
diff options
context:
space:
mode:
authorGeckoEidechse <40122905+GeckoEidechse@users.noreply.github.com>2022-06-16 01:37:29 +0200
committerGitHub <noreply@github.com>2022-06-16 01:37:29 +0200
commit76864937f3f72ac1fb7bc29ea92864d31c05227d (patch)
tree02aa3b9b30678bf9d8a027345014831861577def /NorthstarDedicatedTest
parent7f70a1e46b35f3e5731ada00040096be51ac05c6 (diff)
downloadNorthstarLauncher-76864937f3f72ac1fb7bc29ea92864d31c05227d.tar.gz
NorthstarLauncher-76864937f3f72ac1fb7bc29ea92864d31c05227d.zip
Attempt reconnect in case of DUPLICATE_SERVER (#187)
* Attempt reconnect in case of DUPLICATE_SERVER If gameserver receives DUPLICATE_SERVER response it will retry the auth request after a timeout of 10 seconds. Retries will stop after 10 attempts. Co-authored-by: Emma Miler <27428383+emma-miler@users.noreply.github.com> * Fix formatting * Move comment So that it refers to the right line * Retry 10 times instead of just once * Only check retrycounter for DUPLICATE_SERVER error Co-authored-by: Emma Miler <27428383+emma-miler@users.noreply.github.com>
Diffstat (limited to 'NorthstarDedicatedTest')
-rw-r--r--NorthstarDedicatedTest/masterserver.cpp30
1 files changed, 30 insertions, 0 deletions
diff --git a/NorthstarDedicatedTest/masterserver.cpp b/NorthstarDedicatedTest/masterserver.cpp
index 8bb74668..d5ef2d9f 100644
--- a/NorthstarDedicatedTest/masterserver.cpp
+++ b/NorthstarDedicatedTest/masterserver.cpp
@@ -14,6 +14,7 @@
#include <cstring>
#include <regex>
#include "version.h"
+#include <chrono>
// 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
@@ -836,6 +837,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;
@@ -915,6 +920,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;
}
@@ -937,6 +965,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(