forked from SmileYzn/RePugMod
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ReAPI.cpp
143 lines (101 loc) · 3.71 KB
/
ReAPI.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#include "precompiled.h"
#include "sys_shared.cpp"
#include "interface.cpp"
IRehldsApi* g_RehldsApi;
const RehldsFuncs_t* g_RehldsFuncs;
IRehldsServerData* g_RehldsData;
IRehldsHookchains* g_RehldsHookchains;
IRehldsServerStatic* g_RehldsSvs;
bool ReAPI_Init()
{
if (!IS_DEDICATED_SERVER())
{
LOG_CONSOLE(PLID, "[%s] ReHLDS API Can only run on Half-Life Dedicated Server");
return false;
}
#ifdef WIN32
CSysModule* engineModule = Sys_LoadModule("swds.dll");
#else
CSysModule* engineModule = Sys_LoadModule("engine_i486.so");
#endif
if (!engineModule)
{
LOG_CONSOLE(PLID, "[%s] Failed to locate engine module", Plugin_info.logtag);
return false;
}
CreateInterfaceFn ifaceFactory = Sys_GetFactory(engineModule);
if (!ifaceFactory)
{
LOG_CONSOLE(PLID, "[%s] Failed to locate interface factory in engine module", Plugin_info.logtag);
return false;
}
int retCode = 0;
g_RehldsApi = (IRehldsApi*)ifaceFactory(VREHLDS_HLDS_API_VERSION, &retCode);
if (!g_RehldsApi)
{
LOG_CONSOLE(PLID, "[%s] Failed to locate retrieve rehlds api interface from engine module, return code is %d", Plugin_info.logtag, retCode);
return false;
}
int majorVersion = g_RehldsApi->GetMajorVersion();
int minorVersion = g_RehldsApi->GetMinorVersion();
if (majorVersion != REHLDS_API_VERSION_MAJOR)
{
LOG_CONSOLE(PLID, "[%s] ReHLDS API major version mismatch; expected %d, real %d", Plugin_info.logtag, REHLDS_API_VERSION_MAJOR, majorVersion);
if (majorVersion < REHLDS_API_VERSION_MAJOR)
{
LOG_CONSOLE(PLID, "[%s] Please update the ReHLDS up to a major version API >= %d", Plugin_info.logtag, REHLDS_API_VERSION_MAJOR);
}
else if (majorVersion > REHLDS_API_VERSION_MAJOR)
{
LOG_CONSOLE(PLID, "[%s] Please update the %s up to a major version API >= %d", Plugin_info.logtag, Plugin_info.logtag, majorVersion);
}
return false;
}
if (minorVersion < REHLDS_API_VERSION_MINOR)
{
LOG_CONSOLE(PLID, "[%s] ReHLDS API minor version mismatch; expected at least %d, real %d", Plugin_info.logtag, REHLDS_API_VERSION_MINOR, minorVersion);
LOG_CONSOLE(PLID, "[%s] Please update the ReHLDS up to a minor version API >= %d", Plugin_info.logtag, REHLDS_API_VERSION_MINOR);
return false;
}
g_RehldsFuncs = g_RehldsApi->GetFuncs();
g_RehldsData = g_RehldsApi->GetServerData();
g_RehldsHookchains = g_RehldsApi->GetHookchains();
g_RehldsSvs = g_RehldsApi->GetServerStatic();
LOG_CONSOLE(PLID, "[%s] Re-HLDS API successfully initialized.", Plugin_info.logtag);
g_RehldsHookchains->ClientConnected()->registerHook(ReAPI_ClientConnected);
g_RehldsHookchains->SV_DropClient()->registerHook(ReAPI_SV_DropClient);
return true;
}
bool ReAPI_Stop()
{
g_RehldsHookchains->ClientConnected()->unregisterHook(ReAPI_ClientConnected);
g_RehldsHookchains->SV_DropClient()->unregisterHook(ReAPI_SV_DropClient);
return true;
}
void ReAPI_ClientConnected(IRehldsHook_ClientConnected* chain, IGameClient* client)
{
chain->callNext(client);
gPugMod.ClientConnected(client->GetEdict());
gAntiRetry.ClientConnected(client->GetEdict());
gAuth.ClientConnected(client->GetEdict());
}
void ReAPI_SV_DropClient(IRehldsHook_SV_DropClient* chain, IGameClient* client, bool crash, const char* Reason)
{
auto pEntity = client->GetEdict();
if (!FNullEnt(pEntity))
{
auto EntityIndex = ENTINDEX(pEntity);
if (EntityIndex)
{
gReady.ClientDisconnected(EntityIndex);
gCaptain.ClientDisconnected(EntityIndex);
gVoteKick.ClientDisconnected(EntityIndex);
gVoteLevel.ClientDisconnected(EntityIndex);
gVotePause.ClientDisconnected(EntityIndex);
gVoteStop.ClientDisconnected(EntityIndex);
gAntiRetry.ClientDisconnected(pEntity, Reason);
gPugMod.ClientDisconnected(EntityIndex);
}
}
chain->callNext(client, crash, Reason);
}