mirror of
https://github.com/rehlds/rehlds.git
synced 2025-01-04 02:55:50 +03:00
Merge pull request #107 from theAsmodai/master
Added API registration tool for plugins
This commit is contained in:
commit
65d5799edf
@ -459,16 +459,16 @@ void EXT_FUNC SV_DropClient_api(IGameClient* cl, bool crash, const char* fmt, ..
|
|||||||
g_RehldsHookchains.m_SV_DropClient.callChain(SV_DropClient_hook, cl, crash, buf);
|
g_RehldsHookchains.m_SV_DropClient.callChain(SV_DropClient_hook, cl, crash, buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SV_DropClient(client_t *cl, qboolean crash, const char *fmt, ...)
|
void SV_DropClient(client_t *cl, qboolean crash, const char *fmt, ...)
|
||||||
{
|
{
|
||||||
char buf[1024];
|
char buf[1024];
|
||||||
va_list argptr;
|
va_list argptr;
|
||||||
|
|
||||||
va_start(argptr, fmt);
|
va_start(argptr, fmt);
|
||||||
Q_vsnprintf(buf, ARRAYSIZE(buf) - 1, fmt, argptr);
|
Q_vsnprintf(buf, ARRAYSIZE(buf) - 1, fmt, argptr);
|
||||||
va_end(argptr);
|
va_end(argptr);
|
||||||
|
|
||||||
g_RehldsHookchains.m_SV_DropClient.callChain(SV_DropClient_hook, GetRehldsApiClient(cl), crash != FALSE, buf);
|
g_RehldsHookchains.m_SV_DropClient.callChain(SV_DropClient_hook, GetRehldsApiClient(cl), crash != FALSE, buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* <35f4e> ../engine/host.c:673 */
|
/* <35f4e> ../engine/host.c:673 */
|
||||||
|
@ -35,7 +35,7 @@
|
|||||||
#include "model.h"
|
#include "model.h"
|
||||||
|
|
||||||
#define REHLDS_API_VERSION_MAJOR 2
|
#define REHLDS_API_VERSION_MAJOR 2
|
||||||
#define REHLDS_API_VERSION_MINOR 3
|
#define REHLDS_API_VERSION_MINOR 4
|
||||||
|
|
||||||
//Steam_NotifyClientConnect hook
|
//Steam_NotifyClientConnect hook
|
||||||
typedef IHookChain<qboolean, IGameClient*, const void*, unsigned int> IRehldsHook_Steam_NotifyClientConnect;
|
typedef IHookChain<qboolean, IGameClient*, const void*, unsigned int> IRehldsHook_Steam_NotifyClientConnect;
|
||||||
@ -233,6 +233,8 @@ struct RehldsFuncs_t {
|
|||||||
void(*MSG_WriteByte)(sizebuf_t *sb, int c);
|
void(*MSG_WriteByte)(sizebuf_t *sb, int c);
|
||||||
void(*MSG_WriteShort)(sizebuf_t *sb, int c);
|
void(*MSG_WriteShort)(sizebuf_t *sb, int c);
|
||||||
void(*MSG_WriteString)(sizebuf_t *sb, const char *s);
|
void(*MSG_WriteString)(sizebuf_t *sb, const char *s);
|
||||||
|
void*(*GetPluginApi)(const char *name);
|
||||||
|
void(*RegisterPluginApi)(const char *name, void *impl);
|
||||||
};
|
};
|
||||||
|
|
||||||
class IRehldsApi {
|
class IRehldsApi {
|
||||||
|
@ -67,7 +67,7 @@ public:
|
|||||||
virtual bool IsConnected() = 0;
|
virtual bool IsConnected() = 0;
|
||||||
virtual void SetConnected(bool connected) = 0;
|
virtual void SetConnected(bool connected) = 0;
|
||||||
|
|
||||||
virtual uint32 GetVoiceStreams(int id) = 0;
|
virtual uint32 GetVoiceStream(int stream_id) = 0;
|
||||||
virtual void SetLastVoiceTime(double time) = 0;
|
virtual void SetLastVoiceTime(double time) = 0;
|
||||||
virtual double GetLastVoiceTime() = 0;
|
virtual double GetLastVoiceTime() = 0;
|
||||||
virtual bool GetLoopback() = 0;
|
virtual bool GetLoopback() = 0;
|
||||||
|
@ -27,6 +27,26 @@
|
|||||||
*/
|
*/
|
||||||
#include "precompiled.h"
|
#include "precompiled.h"
|
||||||
|
|
||||||
|
struct plugin_api_t
|
||||||
|
{
|
||||||
|
char name[32];
|
||||||
|
void *impl;
|
||||||
|
};
|
||||||
|
|
||||||
|
std::vector<plugin_api_t *> g_PluginApis;
|
||||||
|
|
||||||
|
plugin_api_t* FindPluginApiByName(const char *name) {
|
||||||
|
for (auto it = g_PluginApis.begin(), end = g_PluginApis.end(); it != end; ++it) {
|
||||||
|
auto api = *it;
|
||||||
|
|
||||||
|
if (!strcmp(api->name, name)) {
|
||||||
|
return api;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
char* EXT_FUNC GetClientFallback_api() {
|
char* EXT_FUNC GetClientFallback_api() {
|
||||||
return com_clientfallback;
|
return com_clientfallback;
|
||||||
}
|
}
|
||||||
@ -109,6 +129,23 @@ cvar_t* EXT_FUNC GetCvarVars_api() {
|
|||||||
return cvar_vars;
|
return cvar_vars;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void* EXT_FUNC Rehlds_GetPluginApi(const char *name) {
|
||||||
|
auto api = FindPluginApiByName(name);
|
||||||
|
return api ? api->impl : NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
void EXT_FUNC Rehlds_RegisterPluginApi(const char *name, void *impl) {
|
||||||
|
auto api = FindPluginApiByName(name);
|
||||||
|
|
||||||
|
if (!api) {
|
||||||
|
api = new plugin_api_t;
|
||||||
|
strncpy(api->name, name, sizeof api->name - 1);
|
||||||
|
g_PluginApis.push_back(api);
|
||||||
|
}
|
||||||
|
|
||||||
|
api->impl = impl;
|
||||||
|
}
|
||||||
|
|
||||||
CRehldsServerStatic g_RehldsServerStatic;
|
CRehldsServerStatic g_RehldsServerStatic;
|
||||||
CRehldsServerData g_RehldsServerData;
|
CRehldsServerData g_RehldsServerData;
|
||||||
CRehldsHookchains g_RehldsHookchains;
|
CRehldsHookchains g_RehldsHookchains;
|
||||||
@ -152,7 +189,9 @@ RehldsFuncs_t g_RehldsApiFuncs =
|
|||||||
&MSG_WriteBuf_api,
|
&MSG_WriteBuf_api,
|
||||||
&MSG_WriteByte_api,
|
&MSG_WriteByte_api,
|
||||||
&MSG_WriteShort_api,
|
&MSG_WriteShort_api,
|
||||||
&MSG_WriteString_api
|
&MSG_WriteString_api,
|
||||||
|
&Rehlds_GetPluginApi,
|
||||||
|
&Rehlds_RegisterPluginApi
|
||||||
};
|
};
|
||||||
|
|
||||||
sizebuf_t* EXT_FUNC GetNetMessage_api()
|
sizebuf_t* EXT_FUNC GetNetMessage_api()
|
||||||
|
@ -70,8 +70,10 @@ void EXT_FUNC CGameClient::SetConnected(bool connected) {
|
|||||||
m_pClient->connected = connected ? 1 : 0;
|
m_pClient->connected = connected ? 1 : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32 EXT_FUNC CGameClient::GetVoiceStreams(int id) {
|
uint32 EXT_FUNC CGameClient::GetVoiceStream(int stream_id) {
|
||||||
return m_pClient->m_VoiceStreams[id >> 5];
|
if (stream_id >= 0 && stream_id < ARRAYSIZE(m_pClient->m_VoiceStreams))
|
||||||
|
return m_pClient->m_VoiceStreams[stream_id];
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void EXT_FUNC CGameClient::SetLastVoiceTime(double time) {
|
void EXT_FUNC CGameClient::SetLastVoiceTime(double time) {
|
||||||
|
@ -76,7 +76,7 @@ public:
|
|||||||
virtual bool IsConnected();
|
virtual bool IsConnected();
|
||||||
virtual void SetConnected(bool connected);
|
virtual void SetConnected(bool connected);
|
||||||
|
|
||||||
virtual uint32 GetVoiceStreams(int id);
|
virtual uint32 GetVoiceStream(int stream_id);
|
||||||
virtual void SetLastVoiceTime(double time);
|
virtual void SetLastVoiceTime(double time);
|
||||||
virtual double GetLastVoiceTime();
|
virtual double GetLastVoiceTime();
|
||||||
virtual bool GetLoopback();
|
virtual bool GetLoopback();
|
||||||
|
Loading…
Reference in New Issue
Block a user