|
dvander@370
|
1 |
/** |
|
ds@653
|
2 |
* vim: set ts=4 : |
|
dvander@370
|
3 |
* =============================================================== |
|
dvander@370
|
4 |
* SourceMod (C)2004-2007 AlliedModders LLC. All rights reserved. |
|
dvander@370
|
5 |
* =============================================================== |
|
dvander@370
|
6 |
* |
|
dvander@370
|
7 |
* This file is not open source and may not be copied without explicit |
|
dvander@370
|
8 |
* written permission of AlliedModders LLC. This file may not be redistributed |
|
dvander@370
|
9 |
* in whole or significant part. |
|
dvander@370
|
10 |
* For information, see LICENSE.txt or http://www.sourcemod.net/license.php |
|
dvander@370
|
11 |
* |
|
dvander@370
|
12 |
* Version: $Id$ |
|
dvander@370
|
13 |
*/ |
|
dvander@370
|
14 |
|
|
dvander@591
|
15 |
#include "PlayerManager.h" |
|
dvander@458
|
16 |
#include "AdminCache.h" |
|
faluco@280
|
17 |
#include "sm_stringutil.h" |
|
faluco@682
|
18 |
#include <inetchannelinfo.h> |
|
faluco@242
|
19 |
|
|
faluco@260
|
20 |
static cell_t sm_GetClientCount(IPluginContext *pCtx, const cell_t *params) |
|
faluco@242
|
21 |
{ |
|
faluco@242
|
22 |
if (params[1]) |
|
faluco@242
|
23 |
{ |
|
dvander@448
|
24 |
return g_Players.NumPlayers(); |
|
faluco@242
|
25 |
} |
|
faluco@242
|
26 |
|
|
dvander@448
|
27 |
int maxplayers = g_Players.MaxClients(); |
|
faluco@242
|
28 |
int count = 0; |
|
faluco@242
|
29 |
for (int i=1; i<=maxplayers; ++i) |
|
faluco@242
|
30 |
{ |
|
dvander@448
|
31 |
CPlayer *pPlayer = g_Players.GetPlayerByIndex(i); |
|
dvander@435
|
32 |
if ((pPlayer->IsConnected()) && !(pPlayer->IsInGame())) |
|
faluco@242
|
33 |
{ |
|
faluco@242
|
34 |
count++; |
|
faluco@242
|
35 |
} |
|
faluco@242
|
36 |
} |
|
faluco@242
|
37 |
|
|
dvander@448
|
38 |
return (g_Players.NumPlayers() + count); |
|
faluco@242
|
39 |
} |
|
faluco@242
|
40 |
|
|
faluco@260
|
41 |
static cell_t sm_GetMaxClients(IPluginContext *pCtx, const cell_t *params) |
|
faluco@242
|
42 |
{ |
|
dvander@448
|
43 |
return g_Players.MaxClients(); |
|
faluco@242
|
44 |
} |
|
faluco@242
|
45 |
|
|
faluco@260
|
46 |
static cell_t sm_GetClientName(IPluginContext *pCtx, const cell_t *params) |
|
faluco@242
|
47 |
{ |
|
faluco@242
|
48 |
int index = params[1]; |
|
dvander@448
|
49 |
if ((index < 1) || (index > g_Players.GetMaxClients())) |
|
faluco@242
|
50 |
{ |
|
ds@470
|
51 |
return pCtx->ThrowNativeError("Invalid client index %d", index); |
|
faluco@242
|
52 |
} |
|
faluco@242
|
53 |
|
|
dvander@448
|
54 |
CPlayer *pPlayer = g_Players.GetPlayerByIndex(index); |
|
dvander@435
|
55 |
if (!pPlayer->IsConnected()) |
|
faluco@260
|
56 |
{ |
|
ds@470
|
57 |
return pCtx->ThrowNativeError("Client %d is not connected", index); |
|
faluco@260
|
58 |
} |
|
faluco@260
|
59 |
|
|
dvander@435
|
60 |
pCtx->StringToLocalUTF8(params[2], static_cast<size_t>(params[3]), pPlayer->GetName(), NULL); |
|
faluco@242
|
61 |
return 1; |
|
faluco@242
|
62 |
} |
|
faluco@242
|
63 |
|
|
faluco@260
|
64 |
static cell_t sm_GetClientIP(IPluginContext *pCtx, const cell_t *params) |
|
faluco@242
|
65 |
{ |
|
faluco@242
|
66 |
int index = params[1]; |
|
dvander@448
|
67 |
if ((index < 1) || (index > g_Players.GetMaxClients())) |
|
faluco@242
|
68 |
{ |
|
ds@470
|
69 |
return pCtx->ThrowNativeError("Invalid client index %d", index); |
|
faluco@242
|
70 |
} |
|
faluco@242
|
71 |
|
|
dvander@448
|
72 |
CPlayer *pPlayer = g_Players.GetPlayerByIndex(index); |
|
dvander@435
|
73 |
if (!pPlayer->IsConnected()) |
|
faluco@260
|
74 |
{ |
|
ds@470
|
75 |
return pCtx->ThrowNativeError("Client %d is not connected", index); |
|
faluco@260
|
76 |
} |
|
faluco@260
|
77 |
|
|
faluco@280
|
78 |
char buf[64], *ptr; |
|
dvander@435
|
79 |
strcpy(buf, pPlayer->GetIPAddress()); |
|
faluco@280
|
80 |
|
|
faluco@280
|
81 |
if (params[4] && (ptr = strchr(buf, ':'))) |
|
faluco@280
|
82 |
{ |
|
faluco@280
|
83 |
*ptr = '\0'; |
|
faluco@280
|
84 |
} |
|
faluco@280
|
85 |
|
|
faluco@280
|
86 |
pCtx->StringToLocal(params[2], static_cast<size_t>(params[3]), buf); |
|
faluco@242
|
87 |
return 1; |
|
faluco@242
|
88 |
} |
|
faluco@242
|
89 |
|
|
faluco@260
|
90 |
static cell_t sm_GetClientAuthStr(IPluginContext *pCtx, const cell_t *params) |
|
faluco@242
|
91 |
{ |
|
faluco@242
|
92 |
int index = params[1]; |
|
dvander@448
|
93 |
if ((index < 1) || (index > g_Players.GetMaxClients())) |
|
faluco@242
|
94 |
{ |
|
ds@470
|
95 |
return pCtx->ThrowNativeError("Invalid client index %d", index); |
|
faluco@242
|
96 |
} |
|
faluco@242
|
97 |
|
|
dvander@448
|
98 |
CPlayer *pPlayer = g_Players.GetPlayerByIndex(index); |
|
dvander@435
|
99 |
if (!pPlayer->IsConnected()) |
|
faluco@260
|
100 |
{ |
|
ds@470
|
101 |
return pCtx->ThrowNativeError("Client %d is not connected", index); |
|
faluco@260
|
102 |
} |
|
faluco@260
|
103 |
|
|
dvander@449
|
104 |
if (!pPlayer->IsAuthorized()) |
|
dvander@449
|
105 |
{ |
|
dvander@449
|
106 |
return 0; |
|
dvander@449
|
107 |
} |
|
dvander@449
|
108 |
|
|
dvander@435
|
109 |
pCtx->StringToLocal(params[2], static_cast<size_t>(params[3]), pPlayer->GetAuthString()); |
|
dvander@449
|
110 |
|
|
faluco@242
|
111 |
return 1; |
|
faluco@242
|
112 |
} |
|
faluco@242
|
113 |
|
|
faluco@260
|
114 |
static cell_t sm_IsPlayerConnected(IPluginContext *pCtx, const cell_t *params) |
|
faluco@242
|
115 |
{ |
|
faluco@242
|
116 |
int index = params[1]; |
|
dvander@448
|
117 |
if ((index < 1) || (index > g_Players.GetMaxClients())) |
|
faluco@242
|
118 |
{ |
|
ds@470
|
119 |
return pCtx->ThrowNativeError("Invalid client index %d", index); |
|
faluco@242
|
120 |
} |
|
faluco@242
|
121 |
|
|
dvander@448
|
122 |
return (g_Players.GetPlayerByIndex(index)->IsConnected()) ? 1 : 0; |
|
faluco@242
|
123 |
} |
|
faluco@242
|
124 |
|
|
faluco@260
|
125 |
static cell_t sm_IsPlayerIngame(IPluginContext *pCtx, const cell_t *params) |
|
faluco@242
|
126 |
{ |
|
faluco@242
|
127 |
int index = params[1]; |
|
dvander@448
|
128 |
if ((index < 1) || (index > g_Players.GetMaxClients())) |
|
faluco@242
|
129 |
{ |
|
ds@470
|
130 |
return pCtx->ThrowNativeError("Invalid client index %d", index); |
|
faluco@242
|
131 |
} |
|
faluco@242
|
132 |
|
|
dvander@448
|
133 |
return (g_Players.GetPlayerByIndex(index)->IsInGame()) ? 1 : 0; |
|
faluco@242
|
134 |
} |
|
faluco@242
|
135 |
|
|
faluco@260
|
136 |
static cell_t sm_IsPlayerAuthorized(IPluginContext *pCtx, const cell_t *params) |
|
faluco@242
|
137 |
{ |
|
faluco@242
|
138 |
int index = params[1]; |
|
dvander@448
|
139 |
if ((index < 1) || (index > g_Players.GetMaxClients())) |
|
faluco@242
|
140 |
{ |
|
ds@470
|
141 |
return pCtx->ThrowNativeError("Invalid client index %d", index); |
|
faluco@242
|
142 |
} |
|
faluco@242
|
143 |
|
|
dvander@448
|
144 |
return (g_Players.GetPlayerByIndex(index)->IsAuthorized()) ? 1 : 0; |
|
faluco@242
|
145 |
} |
|
faluco@242
|
146 |
|
|
faluco@260
|
147 |
static cell_t sm_IsPlayerFakeClient(IPluginContext *pCtx, const cell_t *params) |
|
faluco@242
|
148 |
{ |
|
faluco@242
|
149 |
int index = params[1]; |
|
dvander@448
|
150 |
if ((index < 1) || (index > g_Players.GetMaxClients())) |
|
faluco@242
|
151 |
{ |
|
ds@470
|
152 |
return pCtx->ThrowNativeError("Invalid client index %d", index); |
|
faluco@260
|
153 |
} |
|
faluco@260
|
154 |
|
|
dvander@448
|
155 |
CPlayer *pPlayer = g_Players.GetPlayerByIndex(index); |
|
dvander@435
|
156 |
if (!pPlayer->IsConnected()) |
|
faluco@260
|
157 |
{ |
|
ds@470
|
158 |
return pCtx->ThrowNativeError("Client %d is not connected", index); |
|
faluco@242
|
159 |
} |
|
faluco@242
|
160 |
|
|
dvander@435
|
161 |
return (pPlayer->IsFakeClient()) ? 1 : 0; |
|
faluco@260
|
162 |
} |
|
faluco@260
|
163 |
|
|
dvander@456
|
164 |
static cell_t sm_GetClientInfo(IPluginContext *pContext, const cell_t *params) |
|
dvander@456
|
165 |
{ |
|
dvander@456
|
166 |
int client = params[1]; |
|
dvander@456
|
167 |
CPlayer *pPlayer = g_Players.GetPlayerByIndex(client); |
|
dvander@456
|
168 |
if (!pPlayer) |
|
dvander@456
|
169 |
{ |
|
ds@470
|
170 |
return pContext->ThrowNativeError("Invalid client index %d", client); |
|
dvander@456
|
171 |
} |
|
dvander@456
|
172 |
if (!pPlayer->IsConnected()) |
|
dvander@456
|
173 |
{ |
|
ds@470
|
174 |
return pContext->ThrowNativeError("Client %d is not connected", client); |
|
dvander@456
|
175 |
} |
|
dvander@456
|
176 |
|
|
dvander@456
|
177 |
char *key; |
|
dvander@456
|
178 |
pContext->LocalToString(params[2], &key); |
|
dvander@456
|
179 |
|
|
dvander@456
|
180 |
const char *val = engine->GetClientConVarValue(client, key); |
|
dvander@456
|
181 |
if (!val) |
|
dvander@456
|
182 |
{ |
|
dvander@456
|
183 |
return false; |
|
dvander@456
|
184 |
} |
|
dvander@456
|
185 |
|
|
dvander@456
|
186 |
pContext->StringToLocalUTF8(params[3], params[4], val, NULL); |
|
dvander@456
|
187 |
return 1; |
|
dvander@456
|
188 |
} |
|
dvander@456
|
189 |
|
|
dvander@458
|
190 |
static cell_t SetUserAdmin(IPluginContext *pContext, const cell_t *params) |
|
dvander@458
|
191 |
{ |
|
dvander@458
|
192 |
int client = params[1]; |
|
dvander@458
|
193 |
CPlayer *pPlayer = g_Players.GetPlayerByIndex(client); |
|
dvander@458
|
194 |
if (!pPlayer) |
|
dvander@458
|
195 |
{ |
|
ds@470
|
196 |
return pContext->ThrowNativeError("Invalid client index %d", client); |
|
dvander@458
|
197 |
} |
|
dvander@458
|
198 |
if (!pPlayer->IsConnected()) |
|
dvander@458
|
199 |
{ |
|
ds@470
|
200 |
return pContext->ThrowNativeError("Client %d is not connected", client); |
|
dvander@458
|
201 |
} |
|
dvander@458
|
202 |
if (!g_Admins.IsValidAdmin(params[2])) |
|
dvander@458
|
203 |
{ |
|
ds@470
|
204 |
return pContext->ThrowNativeError("AdminId %x is not valid", params[2]); |
|
dvander@458
|
205 |
} |
|
dvander@458
|
206 |
|
|
dvander@458
|
207 |
pPlayer->SetAdminId(params[2], params[3] ? true : false); |
|
dvander@458
|
208 |
|
|
dvander@458
|
209 |
return 1; |
|
dvander@458
|
210 |
} |
|
dvander@458
|
211 |
|
|
dvander@458
|
212 |
static cell_t GetUserAdmin(IPluginContext *pContext, const cell_t *params) |
|
dvander@458
|
213 |
{ |
|
dvander@458
|
214 |
int client = params[1]; |
|
dvander@458
|
215 |
CPlayer *pPlayer = g_Players.GetPlayerByIndex(client); |
|
dvander@458
|
216 |
if (!pPlayer) |
|
dvander@458
|
217 |
{ |
|
ds@470
|
218 |
return pContext->ThrowNativeError("Invalid client index %d", client); |
|
dvander@458
|
219 |
} |
|
dvander@458
|
220 |
if (!pPlayer->IsConnected()) |
|
dvander@458
|
221 |
{ |
|
ds@470
|
222 |
return pContext->ThrowNativeError("Client %d is not connected", client); |
|
dvander@458
|
223 |
} |
|
dvander@458
|
224 |
|
|
dvander@458
|
225 |
return pPlayer->GetAdminId(); |
|
dvander@458
|
226 |
} |
|
dvander@458
|
227 |
|
|
dvander@458
|
228 |
static cell_t AddUserFlags(IPluginContext *pContext, const cell_t *params) |
|
dvander@458
|
229 |
{ |
|
dvander@458
|
230 |
int client = params[1]; |
|
dvander@458
|
231 |
CPlayer *pPlayer = g_Players.GetPlayerByIndex(client); |
|
dvander@458
|
232 |
if (!pPlayer) |
|
dvander@458
|
233 |
{ |
|
ds@470
|
234 |
return pContext->ThrowNativeError("Invalid client index %d", client); |
|
dvander@458
|
235 |
} |
|
dvander@458
|
236 |
if (!pPlayer->IsConnected()) |
|
dvander@458
|
237 |
{ |
|
ds@470
|
238 |
return pContext->ThrowNativeError("Client %d is not connected", client); |
|
dvander@458
|
239 |
} |
|
dvander@458
|
240 |
|
|
dvander@458
|
241 |
AdminId id; |
|
dvander@458
|
242 |
if ((id=pPlayer->GetAdminId()) == INVALID_ADMIN_ID) |
|
dvander@458
|
243 |
{ |
|
dvander@458
|
244 |
id = g_Admins.CreateAdmin(NULL); |
|
dvander@458
|
245 |
pPlayer->SetAdminId(id, true); |
|
dvander@458
|
246 |
} |
|
dvander@458
|
247 |
|
|
dvander@458
|
248 |
cell_t *addr; |
|
dvander@458
|
249 |
for (int i=2; i<=params[0]; i++) |
|
dvander@458
|
250 |
{ |
|
dvander@458
|
251 |
pContext->LocalToPhysAddr(params[i], &addr); |
|
dvander@458
|
252 |
g_Admins.SetAdminFlag(id, (AdminFlag)*addr, true); |
|
dvander@458
|
253 |
} |
|
dvander@458
|
254 |
|
|
dvander@458
|
255 |
return 1; |
|
dvander@458
|
256 |
} |
|
dvander@458
|
257 |
|
|
dvander@458
|
258 |
static cell_t RemoveUserFlags(IPluginContext *pContext, const cell_t *params) |
|
dvander@458
|
259 |
{ |
|
dvander@458
|
260 |
int client = params[1]; |
|
dvander@458
|
261 |
CPlayer *pPlayer = g_Players.GetPlayerByIndex(client); |
|
dvander@458
|
262 |
if (!pPlayer) |
|
dvander@458
|
263 |
{ |
|
ds@470
|
264 |
return pContext->ThrowNativeError("Invalid client index %d", client); |
|
dvander@458
|
265 |
} |
|
dvander@458
|
266 |
if (!pPlayer->IsConnected()) |
|
dvander@458
|
267 |
{ |
|
ds@470
|
268 |
return pContext->ThrowNativeError("Client %d is not connected", client); |
|
dvander@458
|
269 |
} |
|
dvander@458
|
270 |
|
|
dvander@458
|
271 |
AdminId id; |
|
dvander@458
|
272 |
if ((id=pPlayer->GetAdminId()) == INVALID_ADMIN_ID) |
|
dvander@458
|
273 |
{ |
|
dvander@458
|
274 |
return 0; |
|
dvander@458
|
275 |
} |
|
dvander@458
|
276 |
|
|
dvander@458
|
277 |
cell_t *addr; |
|
dvander@458
|
278 |
for (int i=2; i<=params[0]; i++) |
|
dvander@458
|
279 |
{ |
|
dvander@458
|
280 |
pContext->LocalToPhysAddr(params[i], &addr); |
|
dvander@458
|
281 |
g_Admins.SetAdminFlag(id, (AdminFlag)*addr, false); |
|
dvander@458
|
282 |
} |
|
dvander@458
|
283 |
|
|
dvander@458
|
284 |
return 1; |
|
dvander@458
|
285 |
} |
|
dvander@458
|
286 |
|
|
dvander@458
|
287 |
static cell_t SetUserFlagBits(IPluginContext *pContext, const cell_t *params) |
|
dvander@458
|
288 |
{ |
|
dvander@458
|
289 |
int client = params[1]; |
|
dvander@458
|
290 |
CPlayer *pPlayer = g_Players.GetPlayerByIndex(client); |
|
dvander@458
|
291 |
if (!pPlayer) |
|
dvander@458
|
292 |
{ |
|
ds@470
|
293 |
return pContext->ThrowNativeError("Invalid client index %d", client); |
|
dvander@458
|
294 |
} |
|
dvander@458
|
295 |
if (!pPlayer->IsConnected()) |
|
dvander@458
|
296 |
{ |
|
ds@470
|
297 |
return pContext->ThrowNativeError("Client %d is not connected", client); |
|
dvander@458
|
298 |
} |
|
dvander@458
|
299 |
|
|
dvander@458
|
300 |
AdminId id; |
|
dvander@458
|
301 |
if ((id=pPlayer->GetAdminId()) == INVALID_ADMIN_ID) |
|
dvander@458
|
302 |
{ |
|
dvander@458
|
303 |
id = g_Admins.CreateAdmin(NULL); |
|
dvander@458
|
304 |
pPlayer->SetAdminId(id, true); |
|
dvander@458
|
305 |
} |
|
dvander@458
|
306 |
|
|
dvander@458
|
307 |
g_Admins.SetAdminFlags(id, Access_Effective, params[2]); |
|
dvander@458
|
308 |
|
|
dvander@458
|
309 |
return 1; |
|
dvander@458
|
310 |
} |
|
dvander@458
|
311 |
|
|
dvander@458
|
312 |
static cell_t GetUserFlagBits(IPluginContext *pContext, const cell_t *params) |
|
dvander@458
|
313 |
{ |
|
dvander@458
|
314 |
int client = params[1]; |
|
dvander@458
|
315 |
CPlayer *pPlayer = g_Players.GetPlayerByIndex(client); |
|
dvander@458
|
316 |
if (!pPlayer) |
|
dvander@458
|
317 |
{ |
|
ds@470
|
318 |
return pContext->ThrowNativeError("Invalid client index %d", client); |
|
dvander@458
|
319 |
} |
|
dvander@458
|
320 |
if (!pPlayer->IsConnected()) |
|
dvander@458
|
321 |
{ |
|
ds@470
|
322 |
return pContext->ThrowNativeError("Client %d is not connected", client); |
|
dvander@458
|
323 |
} |
|
dvander@458
|
324 |
|
|
dvander@458
|
325 |
AdminId id; |
|
dvander@458
|
326 |
if ((id=pPlayer->GetAdminId()) == INVALID_ADMIN_ID) |
|
dvander@458
|
327 |
{ |
|
dvander@458
|
328 |
return 0; |
|
dvander@458
|
329 |
} |
|
dvander@458
|
330 |
|
|
dvander@458
|
331 |
return g_Admins.GetAdminFlags(id, Access_Effective); |
|
dvander@458
|
332 |
} |
|
dvander@458
|
333 |
|
|
dvander@460
|
334 |
static cell_t GetClientUserId(IPluginContext *pContext, const cell_t *params) |
|
dvander@460
|
335 |
{ |
|
dvander@460
|
336 |
int client = params[1]; |
|
dvander@460
|
337 |
CPlayer *pPlayer = g_Players.GetPlayerByIndex(client); |
|
dvander@460
|
338 |
if (!pPlayer) |
|
dvander@460
|
339 |
{ |
|
ds@470
|
340 |
return pContext->ThrowNativeError("Invalid client index %d", client); |
|
dvander@460
|
341 |
} |
|
dvander@460
|
342 |
if (!pPlayer->IsConnected()) |
|
dvander@460
|
343 |
{ |
|
ds@470
|
344 |
return pContext->ThrowNativeError("Client %d is not connected", client); |
|
dvander@460
|
345 |
} |
|
dvander@460
|
346 |
|
|
dvander@460
|
347 |
return engine->GetPlayerUserId(pPlayer->GetEdict()); |
|
dvander@460
|
348 |
} |
|
dvander@460
|
349 |
|
|
dvander@540
|
350 |
static cell_t CanUserTarget(IPluginContext *pContext, const cell_t *params) |
|
dvander@540
|
351 |
{ |
|
dvander@540
|
352 |
int client = params[1]; |
|
dvander@540
|
353 |
int target = params[2]; |
|
dvander@540
|
354 |
|
|
dvander@540
|
355 |
CPlayer *pPlayer = g_Players.GetPlayerByIndex(client); |
|
dvander@540
|
356 |
if (!pPlayer) |
|
dvander@540
|
357 |
{ |
|
dvander@540
|
358 |
return pContext->ThrowNativeError("Player %d is not a valid client", client); |
|
dvander@540
|
359 |
} else if (!pPlayer->IsConnected()) { |
|
dvander@540
|
360 |
return pContext->ThrowNativeError("Player %d is not connected", client); |
|
dvander@540
|
361 |
} |
|
dvander@540
|
362 |
|
|
dvander@540
|
363 |
CPlayer *pTarget = g_Players.GetPlayerByIndex(target); |
|
dvander@540
|
364 |
if (!pTarget) |
|
dvander@540
|
365 |
{ |
|
dvander@540
|
366 |
return pContext->ThrowNativeError("Player %d is not a valid client", target); |
|
dvander@540
|
367 |
} else if (!pTarget->IsConnected()) { |
|
dvander@540
|
368 |
return pContext->ThrowNativeError("Player %d is not connected", target); |
|
dvander@540
|
369 |
} |
|
dvander@540
|
370 |
|
|
dvander@540
|
371 |
return g_Admins.CanAdminTarget(pPlayer->GetAdminId(), pTarget->GetAdminId()) ? 1 : 0; |
|
dvander@540
|
372 |
} |
|
dvander@540
|
373 |
|
|
dvander@644
|
374 |
static cell_t GetClientTeam(IPluginContext *pContext, const cell_t *params) |
|
dvander@644
|
375 |
{ |
|
dvander@644
|
376 |
int client = params[1]; |
|
dvander@644
|
377 |
|
|
dvander@644
|
378 |
CPlayer *pPlayer = g_Players.GetPlayerByIndex(client); |
|
dvander@644
|
379 |
if (!pPlayer) |
|
dvander@644
|
380 |
{ |
|
dvander@644
|
381 |
return pContext->ThrowNativeError("Player %d is not a valid client", client); |
|
dvander@644
|
382 |
} else if (!pPlayer->IsInGame()) { |
|
dvander@644
|
383 |
return pContext->ThrowNativeError("Player %d is not in game", client); |
|
dvander@644
|
384 |
} |
|
dvander@644
|
385 |
|
|
dvander@644
|
386 |
IPlayerInfo *pInfo = pPlayer->GetPlayerInfo(); |
|
dvander@644
|
387 |
if (!pInfo) |
|
dvander@644
|
388 |
{ |
|
dvander@644
|
389 |
return pContext->ThrowNativeError("IPlayerInfo not supported by game"); |
|
dvander@644
|
390 |
} |
|
dvander@644
|
391 |
|
|
dvander@644
|
392 |
return pInfo->GetTeamIndex(); |
|
dvander@644
|
393 |
} |
|
dvander@644
|
394 |
|
|
faluco@658
|
395 |
static cell_t GetFragCount(IPluginContext *pContext, const cell_t *params) |
|
faluco@658
|
396 |
{ |
|
faluco@658
|
397 |
int client = params[1]; |
|
faluco@658
|
398 |
|
|
faluco@658
|
399 |
CPlayer *pPlayer = g_Players.GetPlayerByIndex(client); |
|
faluco@658
|
400 |
if (!pPlayer) |
|
faluco@658
|
401 |
{ |
|
faluco@658
|
402 |
return pContext->ThrowNativeError("Player %d is not a valid client", client); |
|
faluco@658
|
403 |
} else if (!pPlayer->IsInGame()) { |
|
faluco@658
|
404 |
return pContext->ThrowNativeError("Player %d is not in game", client); |
|
faluco@658
|
405 |
} |
|
faluco@658
|
406 |
|
|
faluco@658
|
407 |
IPlayerInfo *pInfo = pPlayer->GetPlayerInfo(); |
|
faluco@658
|
408 |
if (!pInfo) |
|
faluco@658
|
409 |
{ |
|
faluco@658
|
410 |
return pContext->ThrowNativeError("IPlayerInfo not supported by game"); |
|
faluco@658
|
411 |
} |
|
faluco@658
|
412 |
|
|
faluco@658
|
413 |
return pInfo->GetFragCount(); |
|
faluco@658
|
414 |
} |
|
faluco@658
|
415 |
|
|
faluco@658
|
416 |
static cell_t GetDeathCount(IPluginContext *pContext, const cell_t *params) |
|
faluco@658
|
417 |
{ |
|
faluco@658
|
418 |
int client = params[1]; |
|
faluco@658
|
419 |
|
|
faluco@658
|
420 |
CPlayer *pPlayer = g_Players.GetPlayerByIndex(client); |
|
faluco@658
|
421 |
if (!pPlayer) |
|
faluco@658
|
422 |
{ |
|
faluco@658
|
423 |
return pContext->ThrowNativeError("Player %d is not a valid client", client); |
|
faluco@658
|
424 |
} else if (!pPlayer->IsInGame()) { |
|
faluco@658
|
425 |
return pContext->ThrowNativeError("Player %d is not in game", client); |
|
faluco@658
|
426 |
} |
|
faluco@658
|
427 |
|
|
faluco@658
|
428 |
IPlayerInfo *pInfo = pPlayer->GetPlayerInfo(); |
|
faluco@658
|
429 |
if (!pInfo) |
|
faluco@658
|
430 |
{ |
|
faluco@658
|
431 |
return pContext->ThrowNativeError("IPlayerInfo not supported by game"); |
|
faluco@658
|
432 |
} |
|
faluco@658
|
433 |
|
|
faluco@658
|
434 |
return pInfo->GetDeathCount(); |
|
faluco@658
|
435 |
} |
|
faluco@658
|
436 |
|
|
faluco@658
|
437 |
static cell_t GetArmorValue(IPluginContext *pContext, const cell_t *params) |
|
faluco@658
|
438 |
{ |
|
faluco@658
|
439 |
int client = params[1]; |
|
faluco@658
|
440 |
|
|
faluco@658
|
441 |
CPlayer *pPlayer = g_Players.GetPlayerByIndex(client); |
|
faluco@658
|
442 |
if (!pPlayer) |
|
faluco@658
|
443 |
{ |
|
faluco@658
|
444 |
return pContext->ThrowNativeError("Player %d is not a valid client", client); |
|
faluco@658
|
445 |
} else if (!pPlayer->IsInGame()) { |
|
faluco@658
|
446 |
return pContext->ThrowNativeError("Player %d is not in game", client); |
|
faluco@658
|
447 |
} |
|
faluco@658
|
448 |
|
|
faluco@658
|
449 |
IPlayerInfo *pInfo = pPlayer->GetPlayerInfo(); |
|
faluco@658
|
450 |
if (!pInfo) |
|
faluco@658
|
451 |
{ |
|
faluco@658
|
452 |
return pContext->ThrowNativeError("IPlayerInfo not supported by game"); |
|
faluco@658
|
453 |
} |
|
faluco@658
|
454 |
|
|
faluco@658
|
455 |
return pInfo->GetArmorValue(); |
|
faluco@658
|
456 |
} |
|
faluco@658
|
457 |
|
|
faluco@658
|
458 |
static cell_t GetAbsOrigin(IPluginContext *pContext, const cell_t *params) |
|
faluco@658
|
459 |
{ |
|
faluco@658
|
460 |
int client = params[1]; |
|
faluco@658
|
461 |
|
|
faluco@658
|
462 |
CPlayer *pPlayer = g_Players.GetPlayerByIndex(client); |
|
faluco@658
|
463 |
if (!pPlayer) |
|
faluco@658
|
464 |
{ |
|
faluco@658
|
465 |
return pContext->ThrowNativeError("Player %d is not a valid client", client); |
|
faluco@658
|
466 |
} else if (!pPlayer->IsInGame()) { |
|
faluco@658
|
467 |
return pContext->ThrowNativeError("Player %d is not in game", client); |
|
faluco@658
|
468 |
} |
|
faluco@658
|
469 |
|
|
faluco@658
|
470 |
IPlayerInfo *pInfo = pPlayer->GetPlayerInfo(); |
|
faluco@658
|
471 |
if (!pInfo) |
|
faluco@658
|
472 |
{ |
|
faluco@658
|
473 |
return pContext->ThrowNativeError("IPlayerInfo not supported by game"); |
|
faluco@658
|
474 |
} |
|
faluco@658
|
475 |
|
|
faluco@658
|
476 |
cell_t *pVec; |
|
faluco@658
|
477 |
pContext->LocalToPhysAddr(params[2], &pVec); |
|
faluco@658
|
478 |
|
|
faluco@658
|
479 |
Vector vec = pInfo->GetAbsOrigin(); |
|
faluco@658
|
480 |
pVec[0] = sp_ftoc(vec.x); |
|
faluco@658
|
481 |
pVec[1] = sp_ftoc(vec.y); |
|
faluco@658
|
482 |
pVec[2] = sp_ftoc(vec.z); |
|
faluco@658
|
483 |
|
|
faluco@658
|
484 |
return 1; |
|
faluco@658
|
485 |
} |
|
faluco@658
|
486 |
|
|
faluco@658
|
487 |
static cell_t GetAbsAngles(IPluginContext *pContext, const cell_t *params) |
|
faluco@658
|
488 |
{ |
|
faluco@658
|
489 |
int client = params[1]; |
|
faluco@658
|
490 |
|
|
faluco@658
|
491 |
CPlayer *pPlayer = g_Players.GetPlayerByIndex(client); |
|
faluco@658
|
492 |
if (!pPlayer) |
|
faluco@658
|
493 |
{ |
|
faluco@658
|
494 |
return pContext->ThrowNativeError("Player %d is not a valid client", client); |
|
faluco@658
|
495 |
} else if (!pPlayer->IsInGame()) { |
|
faluco@658
|
496 |
return pContext->ThrowNativeError("Player %d is not in game", client); |
|
faluco@658
|
497 |
} |
|
faluco@658
|
498 |
|
|
faluco@658
|
499 |
IPlayerInfo *pInfo = pPlayer->GetPlayerInfo(); |
|
faluco@658
|
500 |
if (!pInfo) |
|
faluco@658
|
501 |
{ |
|
faluco@658
|
502 |
return pContext->ThrowNativeError("IPlayerInfo not supported by game"); |
|
faluco@658
|
503 |
} |
|
faluco@658
|
504 |
|
|
faluco@658
|
505 |
cell_t *pAng; |
|
faluco@658
|
506 |
pContext->LocalToPhysAddr(params[2], &pAng); |
|
faluco@658
|
507 |
|
|
faluco@658
|
508 |
QAngle ang = pInfo->GetAbsAngles(); |
|
faluco@658
|
509 |
pAng[0] = sp_ftoc(ang.x); |
|
faluco@658
|
510 |
pAng[1] = sp_ftoc(ang.y); |
|
faluco@658
|
511 |
pAng[2] = sp_ftoc(ang.z); |
|
faluco@658
|
512 |
|
|
faluco@658
|
513 |
return 1; |
|
faluco@658
|
514 |
} |
|
faluco@658
|
515 |
|
|
faluco@658
|
516 |
static cell_t GetPlayerMins(IPluginContext *pContext, const cell_t *params) |
|
faluco@658
|
517 |
{ |
|
faluco@658
|
518 |
int client = params[1]; |
|
faluco@658
|
519 |
|
|
faluco@658
|
520 |
CPlayer *pPlayer = g_Players.GetPlayerByIndex(client); |
|
faluco@658
|
521 |
if (!pPlayer) |
|
faluco@658
|
522 |
{ |
|
faluco@658
|
523 |
return pContext->ThrowNativeError("Player %d is not a valid client", client); |
|
faluco@658
|
524 |
} else if (!pPlayer->IsInGame()) { |
|
faluco@658
|
525 |
return pContext->ThrowNativeError("Player %d is not in game", client); |
|
faluco@658
|
526 |
} |
|
faluco@658
|
527 |
|
|
faluco@658
|
528 |
IPlayerInfo *pInfo = pPlayer->GetPlayerInfo(); |
|
faluco@658
|
529 |
if (!pInfo) |
|
faluco@658
|
530 |
{ |
|
faluco@658
|
531 |
return pContext->ThrowNativeError("IPlayerInfo not supported by game"); |
|
faluco@658
|
532 |
} |
|
faluco@658
|
533 |
|
|
faluco@658
|
534 |
cell_t *pVec; |
|
faluco@658
|
535 |
pContext->LocalToPhysAddr(params[2], &pVec); |
|
faluco@658
|
536 |
|
|
faluco@658
|
537 |
Vector vec = pInfo->GetPlayerMins(); |
|
faluco@658
|
538 |
pVec[0] = sp_ftoc(vec.x); |
|
faluco@658
|
539 |
pVec[1] = sp_ftoc(vec.y); |
|
faluco@658
|
540 |
pVec[2] = sp_ftoc(vec.z); |
|
faluco@658
|
541 |
|
|
faluco@658
|
542 |
return 1; |
|
faluco@658
|
543 |
} |
|
faluco@658
|
544 |
|
|
faluco@658
|
545 |
static cell_t GetPlayerMaxs(IPluginContext *pContext, const cell_t *params) |
|
faluco@658
|
546 |
{ |
|
faluco@658
|
547 |
int client = params[1]; |
|
faluco@658
|
548 |
|
|
faluco@658
|
549 |
CPlayer *pPlayer = g_Players.GetPlayerByIndex(client); |
|
faluco@658
|
550 |
if (!pPlayer) |
|
faluco@658
|
551 |
{ |
|
faluco@658
|
552 |
return pContext->ThrowNativeError("Player %d is not a valid client", client); |
|
faluco@658
|
553 |
} else if (!pPlayer->IsInGame()) { |
|
faluco@658
|
554 |
return pContext->ThrowNativeError("Player %d is not in game", client); |
|
faluco@658
|
555 |
} |
|
faluco@658
|
556 |
|
|
faluco@658
|
557 |
IPlayerInfo *pInfo = pPlayer->GetPlayerInfo(); |
|
faluco@658
|
558 |
if (!pInfo) |
|
faluco@658
|
559 |
{ |
|
faluco@658
|
560 |
return pContext->ThrowNativeError("IPlayerInfo not supported by game"); |
|
faluco@658
|
561 |
} |
|
faluco@658
|
562 |
|
|
faluco@658
|
563 |
cell_t *pVec; |
|
faluco@658
|
564 |
pContext->LocalToPhysAddr(params[2], &pVec); |
|
faluco@658
|
565 |
|
|
faluco@658
|
566 |
Vector vec = pInfo->GetPlayerMaxs(); |
|
faluco@658
|
567 |
pVec[0] = sp_ftoc(vec.x); |
|
faluco@658
|
568 |
pVec[1] = sp_ftoc(vec.y); |
|
faluco@658
|
569 |
pVec[2] = sp_ftoc(vec.z); |
|
faluco@658
|
570 |
|
|
faluco@658
|
571 |
return 1; |
|
faluco@658
|
572 |
} |
|
faluco@658
|
573 |
|
|
faluco@658
|
574 |
static cell_t GetWeaponName(IPluginContext *pContext, const cell_t *params) |
|
faluco@658
|
575 |
{ |
|
faluco@658
|
576 |
int client = params[1]; |
|
faluco@658
|
577 |
|
|
faluco@658
|
578 |
CPlayer *pPlayer = g_Players.GetPlayerByIndex(client); |
|
faluco@658
|
579 |
if (!pPlayer) |
|
faluco@658
|
580 |
{ |
|
faluco@658
|
581 |
return pContext->ThrowNativeError("Player %d is not a valid client", client); |
|
faluco@658
|
582 |
} else if (!pPlayer->IsInGame()) { |
|
faluco@658
|
583 |
return pContext->ThrowNativeError("Player %d is not in game", client); |
|
faluco@658
|
584 |
} |
|
faluco@658
|
585 |
|
|
faluco@658
|
586 |
IPlayerInfo *pInfo = pPlayer->GetPlayerInfo(); |
|
faluco@658
|
587 |
if (!pInfo) |
|
faluco@658
|
588 |
{ |
|
faluco@658
|
589 |
return pContext->ThrowNativeError("IPlayerInfo not supported by game"); |
|
faluco@658
|
590 |
} |
|
faluco@658
|
591 |
|
|
faluco@658
|
592 |
pContext->StringToLocalUTF8(params[2], static_cast<size_t>(params[3]), pInfo->GetWeaponName(), NULL); |
|
faluco@658
|
593 |
|
|
faluco@658
|
594 |
return 1; |
|
faluco@658
|
595 |
} |
|
faluco@658
|
596 |
|
|
faluco@658
|
597 |
static cell_t GetModelName(IPluginContext *pContext, const cell_t *params) |
|
faluco@658
|
598 |
{ |
|
faluco@658
|
599 |
int client = params[1]; |
|
faluco@658
|
600 |
|
|
faluco@658
|
601 |
CPlayer *pPlayer = g_Players.GetPlayerByIndex(client); |
|
faluco@658
|
602 |
if (!pPlayer) |
|
faluco@658
|
603 |
{ |
|
faluco@658
|
604 |
return pContext->ThrowNativeError("Player %d is not a valid client", client); |
|
faluco@658
|
605 |
} else if (!pPlayer->IsInGame()) { |
|
faluco@658
|
606 |
return pContext->ThrowNativeError("Player %d is not in game", client); |
|
faluco@658
|
607 |
} |
|
faluco@658
|
608 |
|
|
faluco@658
|
609 |
IPlayerInfo *pInfo = pPlayer->GetPlayerInfo(); |
|
faluco@658
|
610 |
if (!pInfo) |
|
faluco@658
|
611 |
{ |
|
faluco@658
|
612 |
return pContext->ThrowNativeError("IPlayerInfo not supported by game"); |
|
faluco@658
|
613 |
} |
|
faluco@658
|
614 |
|
|
faluco@658
|
615 |
pContext->StringToLocalUTF8(params[2], static_cast<size_t>(params[3]), pInfo->GetModelName(), NULL); |
|
faluco@658
|
616 |
|
|
faluco@658
|
617 |
return 1; |
|
faluco@658
|
618 |
} |
|
faluco@658
|
619 |
|
|
faluco@658
|
620 |
static cell_t GetHealth(IPluginContext *pContext, const cell_t *params) |
|
faluco@658
|
621 |
{ |
|
faluco@658
|
622 |
int client = params[1]; |
|
faluco@658
|
623 |
|
|
faluco@658
|
624 |
CPlayer *pPlayer = g_Players.GetPlayerByIndex(client); |
|
faluco@658
|
625 |
if (!pPlayer) |
|
faluco@658
|
626 |
{ |
|
faluco@658
|
627 |
return pContext->ThrowNativeError("Player %d is not a valid client", client); |
|
faluco@658
|
628 |
} else if (!pPlayer->IsInGame()) { |
|
faluco@658
|
629 |
return pContext->ThrowNativeError("Player %d is not in game", client); |
|
faluco@658
|
630 |
} |
|
faluco@658
|
631 |
|
|
faluco@658
|
632 |
IPlayerInfo *pInfo = pPlayer->GetPlayerInfo(); |
|
faluco@658
|
633 |
if (!pInfo) |
|
faluco@658
|
634 |
{ |
|
faluco@658
|
635 |
return pContext->ThrowNativeError("IPlayerInfo not supported by game"); |
|
faluco@658
|
636 |
} |
|
faluco@658
|
637 |
|
|
faluco@658
|
638 |
return pInfo->GetHealth(); |
|
faluco@658
|
639 |
} |
|
faluco@658
|
640 |
|
|
faluco@682
|
641 |
static cell_t GetTimeConnected(IPluginContext *pContext, const cell_t *params) |
|
faluco@682
|
642 |
{ |
|
faluco@682
|
643 |
int client = params[1]; |
|
faluco@682
|
644 |
|
|
faluco@682
|
645 |
CPlayer *pPlayer = g_Players.GetPlayerByIndex(client); |
|
faluco@682
|
646 |
if (!pPlayer) |
|
faluco@682
|
647 |
{ |
|
faluco@682
|
648 |
return pContext->ThrowNativeError("Player %d is not a valid client", client); |
|
faluco@682
|
649 |
} else if (!pPlayer->IsInGame()) { |
|
faluco@682
|
650 |
return pContext->ThrowNativeError("Player %d is not in game", client); |
|
faluco@682
|
651 |
} else if (pPlayer->IsFakeClient()) { |
|
faluco@682
|
652 |
return pContext->ThrowNativeError("Player %d is a bot", client); |
|
faluco@682
|
653 |
} |
|
faluco@682
|
654 |
|
|
faluco@682
|
655 |
INetChannelInfo *pInfo = engine->GetPlayerNetInfo(client); |
|
faluco@682
|
656 |
|
|
faluco@682
|
657 |
return sp_ftoc(pInfo->GetTimeConnected()); |
|
faluco@682
|
658 |
} |
|
faluco@682
|
659 |
|
|
faluco@682
|
660 |
static cell_t GetDataRate(IPluginContext *pContext, const cell_t *params) |
|
faluco@682
|
661 |
{ |
|
faluco@682
|
662 |
int client = params[1]; |
|
faluco@682
|
663 |
|
|
faluco@682
|
664 |
CPlayer *pPlayer = g_Players.GetPlayerByIndex(client); |
|
faluco@682
|
665 |
if (!pPlayer) |
|
faluco@682
|
666 |
{ |
|
faluco@682
|
667 |
return pContext->ThrowNativeError("Player %d is not a valid client", client); |
|
faluco@682
|
668 |
} else if (!pPlayer->IsInGame()) { |
|
faluco@682
|
669 |
return pContext->ThrowNativeError("Player %d is not in game", client); |
|
faluco@682
|
670 |
} else if (pPlayer->IsFakeClient()) { |
|
faluco@682
|
671 |
return pContext->ThrowNativeError("Player %d is a bot", client); |
|
faluco@682
|
672 |
} |
|
faluco@682
|
673 |
|
|
faluco@682
|
674 |
INetChannelInfo *pInfo = engine->GetPlayerNetInfo(client); |
|
faluco@682
|
675 |
|
|
faluco@682
|
676 |
return pInfo->GetDataRate(); |
|
faluco@682
|
677 |
} |
|
faluco@682
|
678 |
|
|
faluco@682
|
679 |
static cell_t IsTimingOut(IPluginContext *pContext, const cell_t *params) |
|
faluco@682
|
680 |
{ |
|
faluco@682
|
681 |
int client = params[1]; |
|
faluco@682
|
682 |
|
|
faluco@682
|
683 |
CPlayer *pPlayer = g_Players.GetPlayerByIndex(client); |
|
faluco@682
|
684 |
if (!pPlayer) |
|
faluco@682
|
685 |
{ |
|
faluco@682
|
686 |
return pContext->ThrowNativeError("Player %d is not a valid client", client); |
|
faluco@682
|
687 |
} else if (!pPlayer->IsInGame()) { |
|
faluco@682
|
688 |
return pContext->ThrowNativeError("Player %d is not in game", client); |
|
faluco@682
|
689 |
} else if (pPlayer->IsFakeClient()) { |
|
faluco@682
|
690 |
return pContext->ThrowNativeError("Player %d is a bot", client); |
|
faluco@682
|
691 |
} |
|
faluco@682
|
692 |
|
|
faluco@682
|
693 |
INetChannelInfo *pInfo = engine->GetPlayerNetInfo(client); |
|
faluco@682
|
694 |
|
|
faluco@682
|
695 |
return pInfo->IsTimingOut() ? 1 : 0; |
|
faluco@682
|
696 |
} |
|
faluco@682
|
697 |
|
|
faluco@682
|
698 |
static cell_t GetLatency(IPluginContext *pContext, const cell_t *params) |
|
faluco@682
|
699 |
{ |
|
faluco@682
|
700 |
int client = params[1]; |
|
faluco@682
|
701 |
|
|
faluco@682
|
702 |
CPlayer *pPlayer = g_Players.GetPlayerByIndex(client); |
|
faluco@682
|
703 |
if (!pPlayer) |
|
faluco@682
|
704 |
{ |
|
faluco@682
|
705 |
return pContext->ThrowNativeError("Player %d is not a valid client", client); |
|
faluco@682
|
706 |
} else if (!pPlayer->IsInGame()) { |
|
faluco@682
|
707 |
return pContext->ThrowNativeError("Player %d is not in game", client); |
|
faluco@682
|
708 |
} else if (pPlayer->IsFakeClient()) { |
|
faluco@682
|
709 |
return pContext->ThrowNativeError("Player %d is a bot", client); |
|
faluco@682
|
710 |
} |
|
faluco@682
|
711 |
|
|
faluco@682
|
712 |
INetChannelInfo *pInfo = engine->GetPlayerNetInfo(client); |
|
faluco@682
|
713 |
|
|
faluco@682
|
714 |
return sp_ftoc(pInfo->GetLatency(params[2])); |
|
faluco@682
|
715 |
} |
|
faluco@682
|
716 |
|
|
faluco@682
|
717 |
static cell_t GetAvgLatency(IPluginContext *pContext, const cell_t *params) |
|
faluco@682
|
718 |
{ |
|
faluco@682
|
719 |
int client = params[1]; |
|
faluco@682
|
720 |
|
|
faluco@682
|
721 |
CPlayer *pPlayer = g_Players.GetPlayerByIndex(client); |
|
faluco@682
|
722 |
if (!pPlayer) |
|
faluco@682
|
723 |
{ |
|
faluco@682
|
724 |
return pContext->ThrowNativeError("Player %d is not a valid client", client); |
|
faluco@682
|
725 |
} else if (!pPlayer->IsInGame()) { |
|
faluco@682
|
726 |
return pContext->ThrowNativeError("Player %d is not in game", client); |
|
faluco@682
|
727 |
} else if (pPlayer->IsFakeClient()) { |
|
faluco@682
|
728 |
return pContext->ThrowNativeError("Player %d is a bot", client); |
|
faluco@682
|
729 |
} |
|
faluco@682
|
730 |
|
|
faluco@682
|
731 |
INetChannelInfo *pInfo = engine->GetPlayerNetInfo(client); |
|
faluco@682
|
732 |
|
|
faluco@682
|
733 |
return sp_ftoc(pInfo->GetAvgLatency(params[2])); |
|
faluco@682
|
734 |
} |
|
faluco@682
|
735 |
|
|
faluco@682
|
736 |
static cell_t GetAvgLoss(IPluginContext *pContext, const cell_t *params) |
|
faluco@682
|
737 |
{ |
|
faluco@682
|
738 |
int client = params[1]; |
|
faluco@682
|
739 |
|
|
faluco@682
|
740 |
CPlayer *pPlayer = g_Players.GetPlayerByIndex(client); |
|
faluco@682
|
741 |
if (!pPlayer) |
|
faluco@682
|
742 |
{ |
|
faluco@682
|
743 |
return pContext->ThrowNativeError("Player %d is not a valid client", client); |
|
faluco@682
|
744 |
} else if (!pPlayer->IsInGame()) { |
|
faluco@682
|
745 |
return pContext->ThrowNativeError("Player %d is not in game", client); |
|
faluco@682
|
746 |
} else if (pPlayer->IsFakeClient()) { |
|
faluco@682
|
747 |
return pContext->ThrowNativeError("Player %d is a bot", client); |
|
faluco@682
|
748 |
} |
|
faluco@682
|
749 |
|
|
faluco@682
|
750 |
INetChannelInfo *pInfo = engine->GetPlayerNetInfo(client); |
|
faluco@682
|
751 |
|
|
faluco@682
|
752 |
return sp_ftoc(pInfo->GetAvgLoss(params[2])); |
|
faluco@682
|
753 |
} |
|
faluco@682
|
754 |
|
|
faluco@682
|
755 |
static cell_t GetAvgChoke(IPluginContext *pContext, const cell_t *params) |
|
faluco@682
|
756 |
{ |
|
faluco@682
|
757 |
int client = params[1]; |
|
faluco@682
|
758 |
|
|
faluco@682
|
759 |
CPlayer *pPlayer = g_Players.GetPlayerByIndex(client); |
|
faluco@682
|
760 |
if (!pPlayer) |
|
faluco@682
|
761 |
{ |
|
faluco@682
|
762 |
return pContext->ThrowNativeError("Player %d is not a valid client", client); |
|
faluco@682
|
763 |
} else if (!pPlayer->IsInGame()) { |
|
faluco@682
|
764 |
return pContext->ThrowNativeError("Player %d is not in game", client); |
|
faluco@682
|
765 |
} else if (pPlayer->IsFakeClient()) { |
|
faluco@682
|
766 |
return pContext->ThrowNativeError("Player %d is a bot", client); |
|
faluco@682
|
767 |
} |
|
faluco@682
|
768 |
|
|
faluco@682
|
769 |
INetChannelInfo *pInfo = engine->GetPlayerNetInfo(client); |
|
faluco@682
|
770 |
|
|
faluco@682
|
771 |
return sp_ftoc(pInfo->GetAvgChoke(params[2])); |
|
faluco@682
|
772 |
} |
|
faluco@682
|
773 |
|
|
faluco@682
|
774 |
static cell_t GetAvgData(IPluginContext *pContext, const cell_t *params) |
|
faluco@682
|
775 |
{ |
|
faluco@682
|
776 |
int client = params[1]; |
|
faluco@682
|
777 |
|
|
faluco@682
|
778 |
CPlayer *pPlayer = g_Players.GetPlayerByIndex(client); |
|
faluco@682
|
779 |
if (!pPlayer) |
|
faluco@682
|
780 |
{ |
|
faluco@682
|
781 |
return pContext->ThrowNativeError("Player %d is not a valid client", client); |
|
faluco@682
|
782 |
} else if (!pPlayer->IsInGame()) { |
|
faluco@682
|
783 |
return pContext->ThrowNativeError("Player %d is not in game", client); |
|
faluco@682
|
784 |
} else if (pPlayer->IsFakeClient()) { |
|
faluco@682
|
785 |
return pContext->ThrowNativeError("Player %d is a bot", client); |
|
faluco@682
|
786 |
} |
|
faluco@682
|
787 |
|
|
faluco@682
|
788 |
INetChannelInfo *pInfo = engine->GetPlayerNetInfo(client); |
|
faluco@682
|
789 |
|
|
faluco@682
|
790 |
return sp_ftoc(pInfo->GetAvgData(params[2])); |
|
faluco@682
|
791 |
} |
|
faluco@682
|
792 |
|
|
faluco@682
|
793 |
static cell_t GetAvgPackets(IPluginContext *pContext, const cell_t *params) |
|
faluco@682
|
794 |
{ |
|
faluco@682
|
795 |
int client = params[1]; |
|
faluco@682
|
796 |
|
|
faluco@682
|
797 |
CPlayer *pPlayer = g_Players.GetPlayerByIndex(client); |
|
faluco@682
|
798 |
if (!pPlayer) |
|
faluco@682
|
799 |
{ |
|
faluco@682
|
800 |
return pContext->ThrowNativeError("Player %d is not a valid client", client); |
|
faluco@682
|
801 |
} else if (!pPlayer->IsInGame()) { |
|
faluco@682
|
802 |
return pContext->ThrowNativeError("Player %d is not in game", client); |
|
faluco@682
|
803 |
} else if (pPlayer->IsFakeClient()) { |
|
faluco@682
|
804 |
return pContext->ThrowNativeError("Player %d is a bot", client); |
|
faluco@682
|
805 |
} |
|
faluco@682
|
806 |
|
|
faluco@682
|
807 |
INetChannelInfo *pInfo = engine->GetPlayerNetInfo(client); |
|
faluco@682
|
808 |
|
|
faluco@682
|
809 |
return sp_ftoc(pInfo->GetAvgPackets(params[2])); |
|
faluco@682
|
810 |
} |
|
faluco@682
|
811 |
|
|
faluco@682
|
812 |
static cell_t GetClientOfUserId(IPluginContext *pContext, const cell_t *params) |
|
faluco@682
|
813 |
{ |
|
faluco@682
|
814 |
return g_Players.GetClientOfUserId(params[1]); |
|
faluco@682
|
815 |
} |
|
faluco@682
|
816 |
|
|
faluco@260
|
817 |
REGISTER_NATIVES(playernatives) |
|
faluco@260
|
818 |
{ |
|
dvander@644
|
819 |
{"AddUserFlags", AddUserFlags}, |
|
dvander@644
|
820 |
{"CanUserTarget", CanUserTarget}, |
|
dvander@644
|
821 |
{"GetClientAuthString", sm_GetClientAuthStr}, |
|
faluco@260
|
822 |
{"GetClientCount", sm_GetClientCount}, |
|
dvander@644
|
823 |
{"GetClientInfo", sm_GetClientInfo}, |
|
faluco@260
|
824 |
{"GetClientIP", sm_GetClientIP}, |
|
dvander@644
|
825 |
{"GetClientName", sm_GetClientName}, |
|
dvander@644
|
826 |
{"GetClientTeam", GetClientTeam}, |
|
dvander@644
|
827 |
{"GetClientUserId", GetClientUserId}, |
|
dvander@644
|
828 |
{"GetMaxClients", sm_GetMaxClients}, |
|
dvander@644
|
829 |
{"GetUserAdmin", GetUserAdmin}, |
|
dvander@644
|
830 |
{"GetUserFlagBits", GetUserFlagBits}, |
|
dvander@644
|
831 |
{"IsClientAuthorized", sm_IsPlayerAuthorized}, |
|
dvander@492
|
832 |
{"IsClientConnected", sm_IsPlayerConnected}, |
|
dvander@492
|
833 |
{"IsFakeClient", sm_IsPlayerFakeClient}, |
|
dvander@644
|
834 |
{"IsPlayerInGame", sm_IsPlayerIngame}, |
|
dvander@458
|
835 |
{"RemoveUserFlags", RemoveUserFlags}, |
|
dvander@644
|
836 |
{"SetUserAdmin", SetUserAdmin}, |
|
dvander@458
|
837 |
{"SetUserFlagBits", SetUserFlagBits}, |
|
faluco@658
|
838 |
{"GetClientDeaths", GetDeathCount}, |
|
faluco@658
|
839 |
{"GetClientFrags", GetFragCount}, |
|
faluco@658
|
840 |
{"GetClientArmor", GetArmorValue}, |
|
faluco@658
|
841 |
{"GetClientAbsOrigin", GetAbsOrigin}, |
|
faluco@658
|
842 |
{"GetClientAbsAngles", GetAbsAngles}, |
|
faluco@658
|
843 |
{"GetClientMins", GetPlayerMins}, |
|
faluco@658
|
844 |
{"GetClientMaxs", GetPlayerMaxs}, |
|
faluco@658
|
845 |
{"GetClientWeapon", GetWeaponName}, |
|
faluco@658
|
846 |
{"GetClientModel", GetModelName}, |
|
faluco@658
|
847 |
{"GetClientHealth", GetHealth}, |
|
dvander@691
|
848 |
{"GetClientTime", GetTimeConnected}, |
|
dvander@691
|
849 |
{"GetClientDataRate", GetDataRate}, |
|
dvander@691
|
850 |
{"IsClentTimingOut", IsTimingOut}, |
|
dvander@691
|
851 |
{"GetClientLatency", GetLatency}, |
|
dvander@691
|
852 |
{"GetClientAvgLatency", GetAvgLatency}, |
|
dvander@691
|
853 |
{"GetClientAvgLoss", GetAvgLoss}, |
|
dvander@691
|
854 |
{"GetClientAvgChoke", GetAvgChoke}, |
|
dvander@691
|
855 |
{"GetClientAvgData", GetAvgData}, |
|
dvander@691
|
856 |
{"GetClientAvgPackets", GetAvgPackets}, |
|
faluco@682
|
857 |
{"GetClientOfUserId", GetClientOfUserId}, |
|
faluco@260
|
858 |
{NULL, NULL} |
|
dvander@351
|
859 |
}; |