From c1daf838c308ef972f429da69809fe2a3eb465fc Mon Sep 17 00:00:00 2001 From: asmodai Date: Sat, 4 Jul 2015 20:31:51 +0300 Subject: [PATCH] Added client_t<>index conversion functions to ReHLDS API. --- rehlds/public/rehlds/rehlds_interfaces.h | 6 ++++++ rehlds/rehlds/rehlds_interfaces_impl.cpp | 19 +++++++++++++++++++ rehlds/rehlds/rehlds_interfaces_impl.h | 2 ++ 3 files changed, 27 insertions(+) diff --git a/rehlds/public/rehlds/rehlds_interfaces.h b/rehlds/public/rehlds/rehlds_interfaces.h index f5bbfa5..6b841d5 100644 --- a/rehlds/public/rehlds/rehlds_interfaces.h +++ b/rehlds/public/rehlds/rehlds_interfaces.h @@ -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 { diff --git a/rehlds/rehlds/rehlds_interfaces_impl.cpp b/rehlds/rehlds/rehlds_interfaces_impl.cpp index 39e1bfe..c7de73b 100644 --- a/rehlds/rehlds/rehlds_interfaces_impl.cpp +++ b/rehlds/rehlds/rehlds_interfaces_impl.cpp @@ -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() { diff --git a/rehlds/rehlds/rehlds_interfaces_impl.h b/rehlds/rehlds/rehlds_interfaces_impl.h index 6023e9b..cc9cd2c 100644 --- a/rehlds/rehlds/rehlds_interfaces_impl.h +++ b/rehlds/rehlds/rehlds_interfaces_impl.h @@ -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 {