diff options
Diffstat (limited to 'primedev/masterserver/masterserver.cpp')
-rw-r--r-- | primedev/masterserver/masterserver.cpp | 128 |
1 files changed, 71 insertions, 57 deletions
diff --git a/primedev/masterserver/masterserver.cpp b/primedev/masterserver/masterserver.cpp index aa248464..a2d9f00e 100644 --- a/primedev/masterserver/masterserver.cpp +++ b/primedev/masterserver/masterserver.cpp @@ -7,6 +7,7 @@ #include "engine/r2engine.h" #include "mods/modmanager.h" #include "shared/misccommands.h" +#include "util/utils.h" #include "util/version.h" #include "server/auth/bansystem.h" #include "dedicated/dedicated.h" @@ -118,6 +119,13 @@ void MasterServerManager::AuthenticateOriginWithMasterServer(const char* uid, co curl_easy_setopt(curl, CURLOPT_WRITEDATA, &readBuffer); CURLcode result = curl_easy_perform(curl); + ScopeGuard cleanup( + [&] + { + m_bOriginAuthWithMasterServerInProgress = false; + m_bOriginAuthWithMasterServerDone = true; + curl_easy_cleanup(curl); + }); if (result == CURLcode::CURLE_OK) { @@ -131,13 +139,13 @@ void MasterServerManager::AuthenticateOriginWithMasterServer(const char* uid, co spdlog::error( "Failed reading origin auth info response: encountered parse error \"{}\"", rapidjson::GetParseError_En(originAuthInfo.GetParseError())); - goto REQUEST_END_CLEANUP; + return; } if (!originAuthInfo.IsObject() || !originAuthInfo.HasMember("success")) { spdlog::error("Failed reading origin auth info response: malformed response object {}", readBuffer); - goto REQUEST_END_CLEANUP; + return; } if (originAuthInfo["success"].IsTrue() && originAuthInfo.HasMember("token") && originAuthInfo["token"].IsString()) @@ -174,12 +182,6 @@ void MasterServerManager::AuthenticateOriginWithMasterServer(const char* uid, co spdlog::error("Failed performing northstar origin auth: error {}", curl_easy_strerror(result)); m_bSuccessfullyConnected = false; } - - // we goto this instead of returning so we always hit this - REQUEST_END_CLEANUP: - m_bOriginAuthWithMasterServerInProgress = false; - m_bOriginAuthWithMasterServerDone = true; - curl_easy_cleanup(curl); }); requestThread.detach(); @@ -213,6 +215,13 @@ void MasterServerManager::RequestServerList() curl_easy_setopt(curl, CURLOPT_WRITEDATA, &readBuffer); CURLcode result = curl_easy_perform(curl); + ScopeGuard cleanup( + [&] + { + m_bRequestingServerList = false; + m_bScriptRequestingServerList = false; + curl_easy_cleanup(curl); + }); if (result == CURLcode::CURLE_OK) { @@ -226,20 +235,20 @@ void MasterServerManager::RequestServerList() spdlog::error( "Failed reading masterserver response: encountered parse error \"{}\"", rapidjson::GetParseError_En(serverInfoJson.GetParseError())); - goto REQUEST_END_CLEANUP; + return; } if (serverInfoJson.IsObject() && serverInfoJson.HasMember("error")) { spdlog::error("Failed reading masterserver response: got fastify error response"); spdlog::error(readBuffer); - goto REQUEST_END_CLEANUP; + return; } if (!serverInfoJson.IsArray()) { spdlog::error("Failed reading masterserver response: root object is not an array"); - goto REQUEST_END_CLEANUP; + return; } rapidjson::GenericArray<false, rapidjson_document::GenericValue> serverArray = serverInfoJson.GetArray(); @@ -251,7 +260,7 @@ void MasterServerManager::RequestServerList() if (!serverObj.IsObject()) { spdlog::error("Failed reading masterserver response: member of server array is not an object"); - goto REQUEST_END_CLEANUP; + return; } // todo: verify json props are fine before adding to m_remoteServers @@ -342,12 +351,6 @@ void MasterServerManager::RequestServerList() spdlog::error("Failed requesting servers: error {}", curl_easy_strerror(result)); m_bSuccessfullyConnected = false; } - - // we goto this instead of returning so we always hit this - REQUEST_END_CLEANUP: - m_bRequestingServerList = false; - m_bScriptRequestingServerList = false; - curl_easy_cleanup(curl); }); requestThread.detach(); @@ -374,6 +377,7 @@ void MasterServerManager::RequestMainMenuPromos() curl_easy_setopt(curl, CURLOPT_WRITEDATA, &readBuffer); CURLcode result = curl_easy_perform(curl); + ScopeGuard cleanup([&] { curl_easy_cleanup(curl); }); if (result == CURLcode::CURLE_OK) { @@ -387,20 +391,20 @@ void MasterServerManager::RequestMainMenuPromos() spdlog::error( "Failed reading masterserver main menu promos response: encountered parse error \"{}\"", rapidjson::GetParseError_En(mainMenuPromoJson.GetParseError())); - goto REQUEST_END_CLEANUP; + return; } if (!mainMenuPromoJson.IsObject()) { spdlog::error("Failed reading masterserver main menu promos response: root object is not an object"); - goto REQUEST_END_CLEANUP; + return; } if (mainMenuPromoJson.HasMember("error")) { spdlog::error("Failed reading masterserver response: got fastify error response"); spdlog::error(readBuffer); - goto REQUEST_END_CLEANUP; + return; } if (!mainMenuPromoJson.HasMember("newInfo") || !mainMenuPromoJson["newInfo"].IsObject() || @@ -428,7 +432,7 @@ void MasterServerManager::RequestMainMenuPromos() !mainMenuPromoJson["smallButton2"]["ImageIndex"].IsNumber()) { spdlog::error("Failed reading masterserver main menu promos response: malformed json object"); - goto REQUEST_END_CLEANUP; + return; } m_sMainMenuPromoData.newInfoTitle1 = mainMenuPromoJson["newInfo"]["Title1"].GetString(); @@ -455,10 +459,6 @@ void MasterServerManager::RequestMainMenuPromos() spdlog::error("Failed requesting main menu promos: error {}", curl_easy_strerror(result)); m_bSuccessfullyConnected = false; } - - REQUEST_END_CLEANUP: - // nothing lol - curl_easy_cleanup(curl); }); requestThread.detach(); @@ -495,6 +495,21 @@ void MasterServerManager::AuthenticateWithOwnServer(const char* uid, const char* curl_easy_setopt(curl, CURLOPT_WRITEDATA, &readBuffer); CURLcode result = curl_easy_perform(curl); + ScopeGuard cleanup( + [&] + { + m_bAuthenticatingWithGameServer = false; + m_bScriptAuthenticatingWithGameServer = false; + + if (m_bNewgameAfterSelfAuth) + { + // pretty sure this is threadsafe? + Cbuf_AddText(Cbuf_GetCurrentPlayer(), "ns_end_reauth_and_leave_to_lobby", cmd_source_t::kCommandSrcCode); + m_bNewgameAfterSelfAuth = false; + } + + curl_easy_cleanup(curl); + }); if (result == CURLcode::CURLE_OK) { @@ -508,13 +523,13 @@ void MasterServerManager::AuthenticateWithOwnServer(const char* uid, const char* spdlog::error( "Failed reading masterserver authentication response: encountered parse error \"{}\"", rapidjson::GetParseError_En(authInfoJson.GetParseError())); - goto REQUEST_END_CLEANUP; + return; } if (!authInfoJson.IsObject()) { spdlog::error("Failed reading masterserver authentication response: root object is not an object"); - goto REQUEST_END_CLEANUP; + return; } if (authInfoJson.HasMember("error")) @@ -529,13 +544,13 @@ void MasterServerManager::AuthenticateWithOwnServer(const char* uid, const char* else m_sAuthFailureReason = "No error message provided"; - goto REQUEST_END_CLEANUP; + return; } if (!authInfoJson["success"].IsTrue()) { spdlog::error("Authentication with masterserver failed: \"success\" is not true"); - goto REQUEST_END_CLEANUP; + return; } if (!authInfoJson.HasMember("success") || !authInfoJson.HasMember("id") || !authInfoJson["id"].IsString() || @@ -543,7 +558,7 @@ void MasterServerManager::AuthenticateWithOwnServer(const char* uid, const char* !authInfoJson.HasMember("persistentData") || !authInfoJson["persistentData"].IsArray()) { spdlog::error("Failed reading masterserver authentication response: malformed json object"); - goto REQUEST_END_CLEANUP; + return; } RemoteAuthData newAuthData {}; @@ -561,7 +576,7 @@ void MasterServerManager::AuthenticateWithOwnServer(const char* uid, const char* if (!byte.IsUint() || byte.GetUint() > 255) { spdlog::error("Failed reading masterserver authentication response: malformed json object"); - goto REQUEST_END_CLEANUP; + return; } newAuthData.pdata[i++] = static_cast<char>(byte.GetUint()); @@ -581,19 +596,6 @@ void MasterServerManager::AuthenticateWithOwnServer(const char* uid, const char* m_bSuccessfullyAuthenticatedWithGameServer = false; m_bScriptAuthenticatingWithGameServer = false; } - - REQUEST_END_CLEANUP: - m_bAuthenticatingWithGameServer = false; - m_bScriptAuthenticatingWithGameServer = false; - - if (m_bNewgameAfterSelfAuth) - { - // pretty sure this is threadsafe? - Cbuf_AddText(Cbuf_GetCurrentPlayer(), "ns_end_reauth_and_leave_to_lobby", cmd_source_t::kCommandSrcCode); - m_bNewgameAfterSelfAuth = false; - } - - curl_easy_cleanup(curl); }); requestThread.detach(); @@ -633,7 +635,7 @@ void MasterServerManager::AuthenticateWithServer(const char* uid, const char* pl curl_easy_setopt(curl, CURLOPT_WRITEDATA, &readBuffer); { - char* escapedPassword = curl_easy_escape(curl, passwordStr.c_str(), passwordStr.length()); + char* escapedPassword = curl_easy_escape(curl, passwordStr.c_str(), (int)passwordStr.length()); curl_easy_setopt( curl, @@ -651,6 +653,13 @@ void MasterServerManager::AuthenticateWithServer(const char* uid, const char* pl } CURLcode result = curl_easy_perform(curl); + ScopeGuard cleanup( + [&] + { + m_bAuthenticatingWithGameServer = false; + m_bScriptAuthenticatingWithGameServer = false; + curl_easy_cleanup(curl); + }); if (result == CURLcode::CURLE_OK) { @@ -664,13 +673,13 @@ void MasterServerManager::AuthenticateWithServer(const char* uid, const char* pl spdlog::error( "Failed reading masterserver authentication response: encountered parse error \"{}\"", rapidjson::GetParseError_En(connectionInfoJson.GetParseError())); - goto REQUEST_END_CLEANUP; + return; } if (!connectionInfoJson.IsObject()) { spdlog::error("Failed reading masterserver authentication response: root object is not an object"); - goto REQUEST_END_CLEANUP; + return; } if (connectionInfoJson.HasMember("error")) @@ -685,13 +694,13 @@ void MasterServerManager::AuthenticateWithServer(const char* uid, const char* pl else m_sAuthFailureReason = "No error message provided"; - goto REQUEST_END_CLEANUP; + return; } if (!connectionInfoJson["success"].IsTrue()) { spdlog::error("Authentication with masterserver failed: \"success\" is not true"); - goto REQUEST_END_CLEANUP; + return; } if (!connectionInfoJson.HasMember("success") || !connectionInfoJson.HasMember("ip") || @@ -700,7 +709,7 @@ void MasterServerManager::AuthenticateWithServer(const char* uid, const char* pl !connectionInfoJson["authToken"].IsString()) { spdlog::error("Failed reading masterserver authentication response: malformed json object"); - goto REQUEST_END_CLEANUP; + return; } m_pendingConnectionInfo.ip.S_un.S_addr = inet_addr(connectionInfoJson["ip"].GetString()); @@ -725,11 +734,6 @@ void MasterServerManager::AuthenticateWithServer(const char* uid, const char* pl m_bSuccessfullyAuthenticatedWithGameServer = false; m_bScriptAuthenticatingWithGameServer = false; } - - REQUEST_END_CLEANUP: - m_bAuthenticatingWithGameServer = false; - m_bScriptAuthenticatingWithGameServer = false; - curl_easy_cleanup(curl); }); requestThread.detach(); @@ -920,7 +924,7 @@ void MasterServerManager::ProcessConnectionlessPacketSigreq1(std::string data) CURL* curl = curl_easy_init(); SetCommonHttpClientOptions(curl); - char* rejectEnc = curl_easy_escape(curl, reject.c_str(), reject.length()); + char* rejectEnc = curl_easy_escape(curl, reject.c_str(), (int)reject.length()); if (!rejectEnc) { spdlog::error("failed to handle Atlas connect request {}: failed to escape reject", token); @@ -1281,6 +1285,16 @@ void MasterServerPresenceReporter::InternalAddServer(const ServerPresence* pServ return ReturnCleanup(MasterServerReportPresenceResult::FailedNoRetry); } + // Log request id for easier debugging when combining with logs on masterserver + if (serverAddedJson.HasMember("id")) + { + spdlog::info("Request id: {}", serverAddedJson["id"].GetString()); + } + else + { + spdlog::error("Couldn't find request id in response"); + } + if (serverAddedJson.HasMember("error")) { if (shouldLogError) |