From 87bd14cbe83c0eca42a6c15f4712415627941df2 Mon Sep 17 00:00:00 2001 From: pg9182 <96569817+pg9182@users.noreply.github.com> Date: Mon, 6 Mar 2023 12:02:53 -0500 Subject: Replace HTTP auth server with Atlas connectionless packet --- NorthstarDLL/server/auth/serverauthentication.cpp | 103 +++------------------- NorthstarDLL/server/auth/serverauthentication.h | 9 +- 2 files changed, 15 insertions(+), 97 deletions(-) (limited to 'NorthstarDLL/server/auth') diff --git a/NorthstarDLL/server/auth/serverauthentication.cpp b/NorthstarDLL/server/auth/serverauthentication.cpp index 4d9eb19f..8f62e1dd 100644 --- a/NorthstarDLL/server/auth/serverauthentication.cpp +++ b/NorthstarDLL/server/auth/serverauthentication.cpp @@ -14,104 +14,30 @@ #include "client/r2client.h" #include "server/r2server.h" -#include "httplib.h" - #include #include +#include #include AUTOHOOK_INIT() -const char* AUTHSERVER_VERIFY_STRING = "I am a northstar server!"; - // global vars ServerAuthenticationManager* g_pServerAuthentication; CBaseServer__RejectConnectionType CBaseServer__RejectConnection; -void ServerAuthenticationManager::StartPlayerAuthServer() +void ServerAuthenticationManager::AddRemotePlayer(std::string token, uint64_t uid, std::string username, std::string pdata) { - if (m_bRunningPlayerAuthThread) - { - spdlog::warn("ServerAuthenticationManager::StartPlayerAuthServer was called while m_bRunningPlayerAuthThread is true"); - return; - } - - g_pServerPresence->SetAuthPort(Cvar_ns_player_auth_port->GetInt()); // set auth port for presence - m_bRunningPlayerAuthThread = true; - - // listen is a blocking call so thread this - std::thread serverThread( - [this] - { - // this is just a super basic way to verify that servers have ports open, masterserver will try to read this before ensuring - // server is legit - m_PlayerAuthServer.Get( - "/verify", - [](const httplib::Request& request, httplib::Response& response) - { response.set_content(AUTHSERVER_VERIFY_STRING, "text/plain"); }); - - m_PlayerAuthServer.Post( - "/authenticate_incoming_player", - [this](const httplib::Request& request, httplib::Response& response) - { - if (!request.has_param("id") || !request.has_param("authToken") || request.body.size() >= R2::PERSISTENCE_MAX_SIZE || - !request.has_param("serverAuthToken") || - strcmp(g_pMasterServerManager->m_sOwnServerAuthToken, request.get_param_value("serverAuthToken").c_str())) - { - response.set_content("{\"success\":false}", "application/json"); - return; - } - - uint64_t uid; - try - { - uid = std::strtoull(request.get_param_value("id").c_str(), nullptr, 10); - } - catch (std::exception const& ex) - { - response.set_content("{\"success\":false}", "application/json"); - return; - } - if (!g_pBanSystem->IsUIDAllowed(uid)) - { - response.set_content("{\"success\":false,\"reject\":\"Banned from this server.\"}", "application/json"); - return; - } - - RemoteAuthData newAuthData {}; - strncpy_s(newAuthData.uid, sizeof(newAuthData.uid), request.get_param_value("id").c_str(), sizeof(newAuthData.uid) - 1); - strncpy_s( - newAuthData.username, - sizeof(newAuthData.username), - request.get_param_value("username").c_str(), - sizeof(newAuthData.username) - 1); - - newAuthData.pdataSize = request.body.size(); - newAuthData.pdata = new char[newAuthData.pdataSize]; - memcpy(newAuthData.pdata, request.body.c_str(), newAuthData.pdataSize); - - std::lock_guard guard(m_AuthDataMutex); - m_RemoteAuthenticationData.insert(std::make_pair(request.get_param_value("authToken"), newAuthData)); - - response.set_content("{\"success\":true}", "application/json"); - }); - - m_PlayerAuthServer.listen("0.0.0.0", Cvar_ns_player_auth_port->GetInt()); - }); - - serverThread.detach(); -} + std::string uidS = std::to_string(uid); -void ServerAuthenticationManager::StopPlayerAuthServer() -{ - if (!m_bRunningPlayerAuthThread) - { - spdlog::warn("ServerAuthenticationManager::StopPlayerAuthServer was called while m_bRunningPlayerAuthThread is false"); - return; - } + RemoteAuthData newAuthData {}; + strncpy_s(newAuthData.uid, sizeof(newAuthData.uid), uidS.c_str(), uidS.length()); + strncpy_s(newAuthData.username, sizeof(newAuthData.username), username.c_str(), username.length()); + newAuthData.pdata = new char[pdata.length()]; + newAuthData.pdataSize = pdata.length(); + memcpy(newAuthData.pdata, pdata.c_str(), newAuthData.pdataSize); - m_bRunningPlayerAuthThread = false; - m_PlayerAuthServer.stop(); + std::lock_guard guard(m_AuthDataMutex); + m_RemoteAuthenticationData[token] = newAuthData; } void ServerAuthenticationManager::AddPlayer(R2::CBaseClient* pPlayer, const char* pToken) @@ -323,11 +249,11 @@ bool,, (R2::CBaseClient* self, char* pName, void* pNetChannel, char bFakePlayer, if (!bFakePlayer) { if (!g_pServerAuthentication->VerifyPlayerName(pNextPlayerToken, pName, pVerifiedName)) - pAuthenticationFailure = "Invalid name."; + pAuthenticationFailure = "Invalid Name."; else if (!g_pBanSystem->IsUIDAllowed(iNextPlayerUid)) - pAuthenticationFailure = "Banned from this server."; + pAuthenticationFailure = "Banned From server."; else if (!g_pServerAuthentication->CheckAuthentication(self, iNextPlayerUid, pNextPlayerToken)) - pAuthenticationFailure = "Authentication failed."; + pAuthenticationFailure = "Authentication Failed."; } else // need to copy name for bots still strncpy_s(pVerifiedName, pName, 63); @@ -423,7 +349,6 @@ ON_DLL_LOAD_RELIESON("engine.dll", ServerAuthentication, (ConCommand, ConVar), ( g_pServerAuthentication = new ServerAuthenticationManager; - g_pServerAuthentication->Cvar_ns_player_auth_port = new ConVar("ns_player_auth_port", "8081", FCVAR_GAMEDLL, ""); g_pServerAuthentication->Cvar_ns_erase_auth_info = new ConVar("ns_erase_auth_info", "1", FCVAR_GAMEDLL, "Whether auth info should be erased from this server on disconnect or crash"); g_pServerAuthentication->Cvar_ns_auth_allow_insecure = diff --git a/NorthstarDLL/server/auth/serverauthentication.h b/NorthstarDLL/server/auth/serverauthentication.h index 2ca07a8a..dd0e13af 100644 --- a/NorthstarDLL/server/auth/serverauthentication.h +++ b/NorthstarDLL/server/auth/serverauthentication.h @@ -1,6 +1,5 @@ #pragma once #include "core/convar/convar.h" -#include "httplib.h" #include "engine/r2engine.h" #include #include @@ -27,11 +26,7 @@ extern CBaseServer__RejectConnectionType CBaseServer__RejectConnection; class ServerAuthenticationManager { - private: - httplib::Server m_PlayerAuthServer; - public: - ConVar* Cvar_ns_player_auth_port; ConVar* Cvar_ns_erase_auth_info; ConVar* Cvar_ns_auth_allow_insecure; ConVar* Cvar_ns_auth_allow_insecure_write; @@ -41,14 +36,12 @@ class ServerAuthenticationManager std::unordered_map m_PlayerAuthenticationData; bool m_bAllowDuplicateAccounts = false; - bool m_bRunningPlayerAuthThread = false; bool m_bNeedLocalAuthForNewgame = false; bool m_bForceResetLocalPlayerPersistence = false; bool m_bStartingLocalSPGame = false; public: - void StartPlayerAuthServer(); - void StopPlayerAuthServer(); + void AddRemotePlayer(std::string token, uint64_t uid, std::string username, std::string pdata); void AddPlayer(R2::CBaseClient* pPlayer, const char* pAuthToken); void RemovePlayer(R2::CBaseClient* pPlayer); -- cgit v1.2.3