Added client_t<>index conversion functions to ReHLDS API.

This commit is contained in:
asmodai 2015-07-04 20:31:51 +03:00
parent b0e4e5fa4f
commit c1daf838c3
3 changed files with 27 additions and 0 deletions

View File

@ -85,6 +85,10 @@ public:
#endif
};
#ifndef REHLDS_SELF
struct client_t;
#endif
class IRehldsServerStatic {
public:
virtual ~IRehldsServerStatic() { }
@ -92,6 +96,8 @@ public:
virtual int GetMaxClients() = 0;
virtual bool IsLogActive() = 0;
virtual IGameClient* GetClient(int id) = 0;
virtual client_t* GetClient_t(int id) = 0;
virtual int GetIndexOfClient_t(client_t* client) = 0;
};
class IRehldsServerData {

View File

@ -136,6 +136,25 @@ IGameClient* EXT_FUNC CRehldsServerStatic::GetClient(int id)
return g_GameClients[id];
}
client_t* EXT_FUNC CRehldsServerStatic::GetClient_t(int id)
{
if (id < 0 || id >= g_psvs.maxclients)
Sys_Error(__FUNCTION__": invalid id provided: %d", id);
return &g_psvs.clients[id];
}
int EXT_FUNC CRehldsServerStatic::GetIndexOfClient_t(client_t* client)
{
if (client < g_psvs.clients || client >= &g_psvs.clients[g_psvs.maxclients])
return -1;
if (((size_t)client - (size_t)g_psvs.clients) % sizeof(client_t))
return -1;
return int(client - g_psvs.clients);
}
const char* EXT_FUNC CRehldsServerData::GetModelName() {

View File

@ -86,6 +86,8 @@ public:
virtual int GetMaxClients();
virtual bool IsLogActive();
virtual IGameClient* GetClient(int id);
virtual client_t* GetClient_t(int id);
virtual int GetIndexOfClient_t(client_t* client);
};
class CRehldsServerData : public IRehldsServerData {