aboutsummaryrefslogtreecommitdiff
path: root/NorthstarDLL/masterserver.h
diff options
context:
space:
mode:
Diffstat (limited to 'NorthstarDLL/masterserver.h')
-rw-r--r--NorthstarDLL/masterserver.h94
1 files changed, 73 insertions, 21 deletions
diff --git a/NorthstarDLL/masterserver.h b/NorthstarDLL/masterserver.h
index 3d5f716c..0bbf7c76 100644
--- a/NorthstarDLL/masterserver.h
+++ b/NorthstarDLL/masterserver.h
@@ -1,8 +1,15 @@
#pragma once
+
#include "convar.h"
+#include "serverpresence.h"
#include <winsock2.h>
#include <string>
#include <cstring>
+#include <future>
+
+extern ConVar* Cvar_ns_masterserver_hostname;
+extern ConVar* Cvar_ns_curl_log_enable;
+
struct RemoteModInfo
{
public:
@@ -82,8 +89,6 @@ class MasterServerManager
char m_sOwnClientAuthToken[33];
std::string m_sOwnModInfoJson;
- std::string m_sUnicodeServerName; // Unicode unescaped version of Cvar_ns_auth_servername for support in cjk characters
- std::string m_sUnicodeServerDesc; // Unicode unescaped version of Cvar_ns_auth_serverdesc for support in cjk characters
bool m_bOriginAuthWithMasterServerDone = false;
bool m_bOriginAuthWithMasterServerInProgress = false;
@@ -97,8 +102,7 @@ class MasterServerManager
bool m_bNewgameAfterSelfAuth = false;
bool m_bScriptAuthenticatingWithGameServer = false;
bool m_bSuccessfullyAuthenticatedWithGameServer = false;
-
- std::string s_authfail_reason {};
+ std::string m_sAuthFailureReason {};
bool m_bHasPendingConnectionInfo = false;
RemoteServerConnectionInfo m_pendingConnectionInfo;
@@ -108,28 +112,76 @@ class MasterServerManager
bool m_bHasMainMenuPromoData = false;
MainMenuPromoData m_sMainMenuPromoData;
- private:
- void SetCommonHttpClientOptions(CURL* curl);
-
public:
MasterServerManager();
+
void ClearServerList();
void RequestServerList();
void RequestMainMenuPromos();
- void AuthenticateOriginWithMasterServer(char* uid, char* originToken);
- void AuthenticateWithOwnServer(char* uid, char* playerToken);
- void AuthenticateWithServer(char* uid, char* playerToken, char* serverId, char* password);
- void
- AddSelfToServerList(int port, int authPort, char* name, char* description, char* map, char* playlist, int maxPlayers, char* password);
- void UpdateServerMapAndPlaylist(char* map, char* playlist, int playerCount);
- void UpdateServerPlayerCount(int playerCount);
- void WritePlayerPersistentData(char* playerId, char* pdata, size_t pdataSize);
- void RemoveSelfFromServerList();
+ void AuthenticateOriginWithMasterServer(const char* uid, const char* originToken);
+ void AuthenticateWithOwnServer(const char* uid, const char* playerToken);
+ void AuthenticateWithServer(const char* uid, const char* playerToken, const char* serverId, const char* password);
+ void WritePlayerPersistentData(const char* playerId, const char* pdata, size_t pdataSize);
};
-std::string unescape_unicode(const std::string& str);
-void UpdateServerInfoFromUnicodeToUTF8();
-void InitialiseSharedMasterServer(HMODULE baseAddress);
-extern MasterServerManager* g_MasterServerManager;
+extern MasterServerManager* g_pMasterServerManager;
extern ConVar* Cvar_ns_masterserver_hostname;
-extern ConVar* Cvar_ns_server_password;
+
+/** Result returned in the std::future of a MasterServerPresenceReporter::ReportPresence() call. */
+enum class MasterServerReportPresenceResult
+{
+ // Adding this server to the MS was successful.
+ Success,
+ // We failed to add this server to the MS and should retry.
+ Failed,
+ // We failed to add this server to the MS and shouldn't retry.
+ FailedNoRetry,
+ // We failed to even reach the MS.
+ FailedNoConnect,
+ // We failed to add the server because an existing server with the same ip:port exists.
+ FailedDuplicateServer,
+};
+
+class MasterServerPresenceReporter : public ServerPresenceReporter
+{
+ public:
+ /** Full data returned in the std::future of a MasterServerPresenceReporter::ReportPresence() call. */
+ struct ReportPresenceResultData
+ {
+ MasterServerReportPresenceResult result;
+
+ std::optional<std::string> id;
+ std::optional<std::string> serverAuthToken;
+ };
+
+ const int MAX_REGISTRATION_ATTEMPTS = 5;
+
+ // Called to initialise the master server presence reporter's state.
+ void CreatePresence(const ServerPresence* pServerPresence) override;
+
+ // Run on an internal to either add the server to the MS or update it.
+ void ReportPresence(const ServerPresence* pServerPresence) override;
+
+ // Called when we need to remove the server from the master server.
+ void DestroyPresence(const ServerPresence* pServerPresence) override;
+
+ // Called every frame.
+ void RunFrame(double flCurrentTime, const ServerPresence* pServerPresence) override;
+
+ protected:
+ // Contains the async logic to add the server to the MS.
+ void InternalAddServer(const ServerPresence* pServerPresence);
+
+ // Contains the async logic to update the server on the MS.
+ void InternalUpdateServer(const ServerPresence* pServerPresence);
+
+ // The future used for InternalAddServer() calls.
+ std::future<ReportPresenceResultData> addServerFuture;
+
+ // The future used for InternalAddServer() calls.
+ std::future<ReportPresenceResultData> updateServerFuture;
+
+ int m_nNumRegistrationAttempts;
+
+ double m_fNextAddServerAttemptTime;
+};