r5sdk/r5dev/networksystem/hostmanager.h
Kawe Mazidjatari b8178e9299 NetworkSystem: fix numerous issues
This patch splits host logic from CServerListManager. CServerListManager is actually meant for the client to manage the server list to which the client could connect to. The hosting logic has been moved to the new CServerHostManager class.

Previously, we stored all the hosting details in CServerListManager, with connection criteria in CPylon, this data has been moved over to CServerHostManager as well.

Previously, we also needed a mutex to access the server host data, function HostState_KeepAlive() has been refactored to the point this mutex is no longer necessary as the only threaded process is the actual request, the rest is being applied in the main thread. We also now only construct a NetGameServer_t struct if we actually plan to host.

Access to CPylon::m_Language is now also protected by a mutex, as the change callback of cvar 'language' and the threaded method 'CPylon::QueryServer()' are competing for access.
2024-04-05 18:24:36 +02:00

56 lines
1.3 KiB
C++

#ifndef HOSTMANAGER_H
#define HOSTMANAGER_H
#include <networksystem/serverlisting.h>
enum HostStatus_e
{
NOT_HOSTING,
HOSTING
};
enum ServerVisibility_e
{
OFFLINE,
HIDDEN,
PUBLIC
};
class CServerHostManager
{
public:
CServerHostManager();
void LaunchServer(const bool changeLevel) const;
inline HostStatus_e GetHostStatus(void) const { return m_HostingStatus; }
inline void SetHostStatus(const HostStatus_e hostStatus) { m_HostingStatus = hostStatus; }
inline ServerVisibility_e GetVisibility(void) const { return m_ServerVisibility; }
inline void SetVisibility(const ServerVisibility_e visibility) { m_ServerVisibility = visibility; }
inline NetGameServer_t& GetDetails() { return m_Server; }
inline void SetCurrentToken(const string& token) { m_Token = token; }
inline const string& GetCurrentToken() const { return m_Token; }
inline void SetCurrentError(const string& error) { m_ErrorMsg = error; }
inline const string& GetCurrentError() const { return m_ErrorMsg; }
inline void SetHostIP(const string& ip) { m_HostIP = ip; };
inline const string& GetHostIP() const { return m_HostIP; };
private:
HostStatus_e m_HostingStatus;
ServerVisibility_e m_ServerVisibility;
NetGameServer_t m_Server;
string m_Token;
string m_ErrorMsg;
string m_HostIP;
};
extern CServerHostManager g_ServerHostManager;
#endif // HOSTMANAGER_H