aboutsummaryrefslogtreecommitdiff
path: root/primedev/server/serverpresence.h
diff options
context:
space:
mode:
authorJack <66967891+ASpoonPlaysGames@users.noreply.github.com>2023-12-27 00:32:01 +0000
committerGitHub <noreply@github.com>2023-12-27 01:32:01 +0100
commitf5ab6fb5e8be7b73e6003d4145081d5e0c0ce287 (patch)
tree90f2c6a4885dbd181799e2325cf33588697674e1 /primedev/server/serverpresence.h
parentbb8ed59f6891b1196c5f5bbe7346cd171c8215fa (diff)
downloadNorthstarLauncher-f5ab6fb5e8be7b73e6003d4145081d5e0c0ce287.tar.gz
NorthstarLauncher-f5ab6fb5e8be7b73e6003d4145081d5e0c0ce287.zip
Folder restructuring from primedev (#624)v1.21.2-rc3v1.21.2
Copies of over the primedev folder structure for easier cherry-picking of further changes Co-authored-by: F1F7Y <filip.bartos07@proton.me>
Diffstat (limited to 'primedev/server/serverpresence.h')
-rw-r--r--primedev/server/serverpresence.h94
1 files changed, 94 insertions, 0 deletions
diff --git a/primedev/server/serverpresence.h b/primedev/server/serverpresence.h
new file mode 100644
index 00000000..c644cc37
--- /dev/null
+++ b/primedev/server/serverpresence.h
@@ -0,0 +1,94 @@
+#pragma once
+#include "core/convar/convar.h"
+
+struct ServerPresence
+{
+public:
+ int m_iPort;
+
+ std::string m_sServerId;
+
+ std::string m_sServerName;
+ std::string m_sServerDesc;
+ char m_Password[256]; // probably bigger than will ever be used in practice, lol
+
+ char m_MapName[32];
+ char m_PlaylistName[64];
+ bool m_bIsSingleplayerServer; // whether the server started in sp
+
+ int m_iPlayerCount;
+ int m_iMaxPlayers;
+
+ ServerPresence()
+ {
+ memset(this, 0, sizeof(this));
+ }
+
+ ServerPresence(const ServerPresence* obj)
+ {
+ m_iPort = obj->m_iPort;
+
+ m_sServerId = obj->m_sServerId;
+
+ m_sServerName = obj->m_sServerName;
+ m_sServerDesc = obj->m_sServerDesc;
+ memcpy(m_Password, obj->m_Password, sizeof(m_Password));
+
+ memcpy(m_MapName, obj->m_MapName, sizeof(m_MapName));
+ memcpy(m_PlaylistName, obj->m_PlaylistName, sizeof(m_PlaylistName));
+
+ m_iPlayerCount = obj->m_iPlayerCount;
+ m_iMaxPlayers = obj->m_iMaxPlayers;
+ }
+};
+
+class ServerPresenceReporter
+{
+public:
+ virtual void CreatePresence(const ServerPresence* pServerPresence) {}
+ virtual void ReportPresence(const ServerPresence* pServerPresence) {}
+ virtual void DestroyPresence(const ServerPresence* pServerPresence) {}
+ virtual void RunFrame(double flCurrentTime, const ServerPresence* pServerPresence) {}
+};
+
+class ServerPresenceManager
+{
+private:
+ ServerPresence m_ServerPresence;
+
+ bool m_bHasPresence = false;
+ bool m_bFirstPresenceUpdate = false;
+
+ std::vector<ServerPresenceReporter*> m_vPresenceReporters;
+
+ double m_flLastPresenceUpdate = 0;
+ ConVar* Cvar_ns_server_presence_update_rate;
+
+ ConVar* Cvar_ns_server_name;
+ ConVar* Cvar_ns_server_desc;
+ ConVar* Cvar_ns_server_password;
+
+ ConVar* Cvar_ns_report_server_to_masterserver;
+ ConVar* Cvar_ns_report_sp_server_to_masterserver;
+
+public:
+ void AddPresenceReporter(ServerPresenceReporter* reporter);
+
+ void CreateConVars();
+
+ void CreatePresence();
+ void DestroyPresence();
+ void RunFrame(double flCurrentTime);
+
+ void SetPort(const int iPort);
+
+ void SetName(const std::string sServerNameUnicode);
+ void SetDescription(const std::string sServerDescUnicode);
+ void SetPassword(const char* pPassword);
+
+ void SetMap(const char* pMapName, bool isInitialising = false);
+ void SetPlaylist(const char* pPlaylistName);
+ void SetPlayerCount(const int iPlayerCount);
+};
+
+extern ServerPresenceManager* g_pServerPresence;