|
ds@1952
|
1 |
/** |
|
ds@1952
|
2 |
* vim: set ts=4 : |
|
ds@1952
|
3 |
* ============================================================================= |
|
ds@1952
|
4 |
* SourceMod |
|
ds@1952
|
5 |
* Copyright (C) 2004-2008 AlliedModders LLC. All rights reserved. |
|
ds@1952
|
6 |
* ============================================================================= |
|
ds@1952
|
7 |
* |
|
ds@1952
|
8 |
* This program is free software; you can redistribute it and/or modify it under |
|
ds@1952
|
9 |
* the terms of the GNU General Public License, version 3.0, as published by the |
|
ds@1952
|
10 |
* Free Software Foundation. |
|
ds@1952
|
11 |
* |
|
ds@1952
|
12 |
* This program is distributed in the hope that it will be useful, but WITHOUT |
|
ds@1952
|
13 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
|
ds@1952
|
14 |
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more |
|
ds@1952
|
15 |
* details. |
|
ds@1952
|
16 |
* |
|
ds@1952
|
17 |
* You should have received a copy of the GNU General Public License along with |
|
ds@1952
|
18 |
* this program. If not, see <http://www.gnu.org/licenses/>. |
|
ds@1952
|
19 |
* |
|
ds@1952
|
20 |
* As a special exception, AlliedModders LLC gives you permission to link the |
|
ds@1952
|
21 |
* code of this program (as well as its derivative works) to "Half-Life 2," the |
|
ds@1952
|
22 |
* "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software |
|
ds@1952
|
23 |
* by the Valve Corporation. You must obey the GNU General Public License in |
|
ds@1952
|
24 |
* all respects for all other code used. Additionally, AlliedModders LLC grants |
|
ds@1952
|
25 |
* this exception to all derivative works. AlliedModders LLC defines further |
|
ds@1952
|
26 |
* exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007), |
|
ds@1952
|
27 |
* or <http://www.sourcemod.net/license.php>. |
|
ds@1952
|
28 |
* |
|
ds@1952
|
29 |
* Version: $Id$ |
|
ds@1952
|
30 |
*/ |
|
ds@1952
|
31 |
|
|
ds@1952
|
32 |
#include "PlayerManager.h" |
|
ds@1952
|
33 |
#include "AdminCache.h" |
|
ds@1952
|
34 |
#include "sm_stringutil.h" |
|
ds@1952
|
35 |
#include "HalfLife2.h" |
|
ds@1952
|
36 |
#include "sourcemod.h" |
|
ds@1952
|
37 |
#include "ChatTriggers.h" |
|
ds@1952
|
38 |
#include <inetchannel.h> |
|
ds@1952
|
39 |
#include <iclient.h> |
|
ds@1952
|
40 |
|
|
ds@1952
|
41 |
ConVar sm_show_activity("sm_show_activity", "13", FCVAR_SPONLY, "Activity display setting (see sourcemod.cfg)"); |
|
ds@1952
|
42 |
|
|
ds@1952
|
43 |
static cell_t sm_GetClientCount(IPluginContext *pCtx, const cell_t *params) |
|
ds@1952
|
44 |
{ |
|
ds@1952
|
45 |
if (params[1]) |
|
ds@1952
|
46 |
{ |
|
ds@1952
|
47 |
return g_Players.NumPlayers(); |
|
ds@1952
|
48 |
} |
|
ds@1952
|
49 |
|
|
ds@1952
|
50 |
int maxplayers = g_Players.MaxClients(); |
|
ds@1952
|
51 |
int count = 0; |
|
ds@1952
|
52 |
for (int i=1; i<=maxplayers; ++i) |
|
ds@1952
|
53 |
{ |
|
ds@1952
|
54 |
CPlayer *pPlayer = g_Players.GetPlayerByIndex(i); |
|
ds@1952
|
55 |
if ((pPlayer->IsConnected()) && !(pPlayer->IsInGame())) |
|
ds@1952
|
56 |
{ |
|
ds@1952
|
57 |
count++; |
|
ds@1952
|
58 |
} |
|
ds@1952
|
59 |
} |
|
ds@1952
|
60 |
|
|
ds@1952
|
61 |
return (g_Players.NumPlayers() + count); |
|
ds@1952
|
62 |
} |
|
ds@1952
|
63 |
|
|
ds@1952
|
64 |
static cell_t sm_GetMaxClients(IPluginContext *pCtx, const cell_t *params) |
|
ds@1952
|
65 |
{ |
|
ds@1952
|
66 |
return g_Players.MaxClients(); |
|
ds@1952
|
67 |
} |
|
ds@1952
|
68 |
|
|
ds@1952
|
69 |
static cell_t sm_GetClientName(IPluginContext *pCtx, const cell_t *params) |
|
ds@1952
|
70 |
{ |
|
ds@1952
|
71 |
int index = params[1]; |
|
ds@1952
|
72 |
|
|
ds@1952
|
73 |
if (index == 0) |
|
ds@1952
|
74 |
{ |
|
ds@1952
|
75 |
static ConVar *hostname = NULL; |
|
ds@1952
|
76 |
if (!hostname) |
|
ds@1952
|
77 |
{ |
|
ds@1952
|
78 |
hostname = icvar->FindVar("hostname"); |
|
ds@1952
|
79 |
if (!hostname) |
|
ds@1952
|
80 |
{ |
|
ds@1952
|
81 |
return pCtx->ThrowNativeError("Could not find \"hostname\" cvar"); |
|
ds@1952
|
82 |
} |
|
ds@1952
|
83 |
} |
|
ds@1952
|
84 |
pCtx->StringToLocalUTF8(params[2], static_cast<size_t>(params[3]), hostname->GetString(), NULL); |
|
ds@1952
|
85 |
return 1; |
|
ds@1952
|
86 |
} |
|
ds@1952
|
87 |
|
|
ds@1952
|
88 |
if ((index < 1) || (index > g_Players.GetMaxClients())) |
|
ds@1952
|
89 |
{ |
|
ds@1952
|
90 |
return pCtx->ThrowNativeError("Client index %d is invalid", index); |
|
ds@1952
|
91 |
} |
|
ds@1952
|
92 |
|
|
ds@1952
|
93 |
CPlayer *pPlayer = g_Players.GetPlayerByIndex(index); |
|
ds@1952
|
94 |
if (!pPlayer->IsConnected()) |
|
ds@1952
|
95 |
{ |
|
ds@1952
|
96 |
return pCtx->ThrowNativeError("Client %d is not connected", index); |
|
ds@1952
|
97 |
} |
|
ds@1952
|
98 |
|
|
ds@1952
|
99 |
pCtx->StringToLocalUTF8(params[2], static_cast<size_t>(params[3]), pPlayer->GetName(), NULL); |
|
ds@1952
|
100 |
return 1; |
|
ds@1952
|
101 |
} |
|
ds@1952
|
102 |
|
|
ds@1952
|
103 |
static cell_t sm_GetClientIP(IPluginContext *pCtx, const cell_t *params) |
|
ds@1952
|
104 |
{ |
|
ds@1952
|
105 |
int index = params[1]; |
|
ds@1952
|
106 |
if ((index < 1) || (index > g_Players.GetMaxClients())) |
|
ds@1952
|
107 |
{ |
|
ds@1952
|
108 |
return pCtx->ThrowNativeError("Client index %d is invalid", index); |
|
ds@1952
|
109 |
} |
|
ds@1952
|
110 |
|
|
ds@1952
|
111 |
CPlayer *pPlayer = g_Players.GetPlayerByIndex(index); |
|
ds@1952
|
112 |
if (!pPlayer->IsConnected()) |
|
ds@1952
|
113 |
{ |
|
ds@1952
|
114 |
return pCtx->ThrowNativeError("Client %d is not connected", index); |
|
ds@1952
|
115 |
} |
|
ds@1952
|
116 |
|
|
ds@1952
|
117 |
char buf[64], *ptr; |
|
ds@1952
|
118 |
strcpy(buf, pPlayer->GetIPAddress()); |
|
ds@1952
|
119 |
|
|
ds@1952
|
120 |
if (params[4] && (ptr = strchr(buf, ':'))) |
|
ds@1952
|
121 |
{ |
|
ds@1952
|
122 |
*ptr = '\0'; |
|
ds@1952
|
123 |
} |
|
ds@1952
|
124 |
|
|
ds@1952
|
125 |
pCtx->StringToLocal(params[2], static_cast<size_t>(params[3]), buf); |
|
ds@1952
|
126 |
return 1; |
|
ds@1952
|
127 |
} |
|
ds@1952
|
128 |
|
|
ds@1952
|
129 |
static cell_t sm_GetClientAuthStr(IPluginContext *pCtx, const cell_t *params) |
|
ds@1952
|
130 |
{ |
|
ds@1952
|
131 |
int index = params[1]; |
|
ds@1952
|
132 |
if ((index < 1) || (index > g_Players.GetMaxClients())) |
|
ds@1952
|
133 |
{ |
|
ds@1952
|
134 |
return pCtx->ThrowNativeError("Client index %d is invalid", index); |
|
ds@1952
|
135 |
} |
|
ds@1952
|
136 |
|
|
ds@1952
|
137 |
CPlayer *pPlayer = g_Players.GetPlayerByIndex(index); |
|
ds@1952
|
138 |
if (!pPlayer->IsConnected()) |
|
ds@1952
|
139 |
{ |
|
ds@1952
|
140 |
return pCtx->ThrowNativeError("Client %d is not connected", index); |
|
ds@1952
|
141 |
} |
|
ds@1952
|
142 |
|
|
ds@1952
|
143 |
if (!pPlayer->IsAuthorized()) |
|
ds@1952
|
144 |
{ |
|
ds@1952
|
145 |
return 0; |
|
ds@1952
|
146 |
} |
|
ds@1952
|
147 |
|
|
ds@1952
|
148 |
pCtx->StringToLocal(params[2], static_cast<size_t>(params[3]), pPlayer->GetAuthString()); |
|
ds@1952
|
149 |
|
|
ds@1952
|
150 |
return 1; |
|
ds@1952
|
151 |
} |
|
ds@1952
|
152 |
|
|
ds@1952
|
153 |
static cell_t sm_IsClientConnected(IPluginContext *pCtx, const cell_t *params) |
|
ds@1952
|
154 |
{ |
|
ds@1952
|
155 |
int index = params[1]; |
|
ds@1952
|
156 |
if ((index < 1) || (index > g_Players.GetMaxClients())) |
|
ds@1952
|
157 |
{ |
|
ds@1952
|
158 |
return pCtx->ThrowNativeError("Client index %d is invalid", index); |
|
ds@1952
|
159 |
} |
|
ds@1952
|
160 |
|
|
ds@1952
|
161 |
return (g_Players.GetPlayerByIndex(index)->IsConnected()) ? 1 : 0; |
|
ds@1952
|
162 |
} |
|
ds@1952
|
163 |
|
|
ds@1952
|
164 |
static cell_t sm_IsClientInGame(IPluginContext *pCtx, const cell_t *params) |
|
ds@1952
|
165 |
{ |
|
ds@1952
|
166 |
int index = params[1]; |
|
ds@1952
|
167 |
if ((index < 1) || (index > g_Players.GetMaxClients())) |
|
ds@1952
|
168 |
{ |
|
ds@1952
|
169 |
return pCtx->ThrowNativeError("Client index %d is invalid", index); |
|
ds@1952
|
170 |
} |
|
ds@1952
|
171 |
|
|
ds@1952
|
172 |
return (g_Players.GetPlayerByIndex(index)->IsInGame()) ? 1 : 0; |
|
ds@1952
|
173 |
} |
|
ds@1952
|
174 |
|
|
ds@1952
|
175 |
static cell_t sm_IsClientAuthorized(IPluginContext *pCtx, const cell_t *params) |
|
ds@1952
|
176 |
{ |
|
ds@1952
|
177 |
int index = params[1]; |
|
ds@1952
|
178 |
if ((index < 1) || (index > g_Players.GetMaxClients())) |
|
ds@1952
|
179 |
{ |
|
ds@1952
|
180 |
return pCtx->ThrowNativeError("Client index %d is invalid", index); |
|
ds@1952
|
181 |
} |
|
ds@1952
|
182 |
|
|
ds@1952
|
183 |
return (g_Players.GetPlayerByIndex(index)->IsAuthorized()) ? 1 : 0; |
|
ds@1952
|
184 |
} |
|
ds@1952
|
185 |
|
|
ds@1952
|
186 |
static cell_t sm_IsClientFakeClient(IPluginContext *pCtx, const cell_t *params) |
|
ds@1952
|
187 |
{ |
|
ds@1952
|
188 |
int index = params[1]; |
|
ds@1952
|
189 |
if ((index < 1) || (index > g_Players.GetMaxClients())) |
|
ds@1952
|
190 |
{ |
|
ds@1952
|
191 |
return pCtx->ThrowNativeError("Client index %d is invalid", index); |
|
ds@1952
|
192 |
} |
|
ds@1952
|
193 |
|
|
ds@1952
|
194 |
CPlayer *pPlayer = g_Players.GetPlayerByIndex(index); |
|
ds@1952
|
195 |
if (!pPlayer->IsConnected()) |
|
ds@1952
|
196 |
{ |
|
ds@1952
|
197 |
return pCtx->ThrowNativeError("Client %d is not connected", index); |
|
ds@1952
|
198 |
} |
|
ds@1952
|
199 |
|
|
ds@1952
|
200 |
return (pPlayer->IsFakeClient()) ? 1 : 0; |
|
ds@1952
|
201 |
} |
|
ds@1952
|
202 |
|
|
ds@1952
|
203 |
static cell_t IsClientObserver(IPluginContext *pContext, const cell_t *params) |
|
ds@1952
|
204 |
{ |
|
ds@1952
|
205 |
int client = params[1]; |
|
ds@1952
|
206 |
|
|
ds@1952
|
207 |
CPlayer *pPlayer = g_Players.GetPlayerByIndex(client); |
|
ds@1952
|
208 |
if (!pPlayer) |
|
ds@1952
|
209 |
{ |
|
ds@1952
|
210 |
return pContext->ThrowNativeError("Client index %d is invalid", client); |
|
ds@1952
|
211 |
} else if (!pPlayer->IsInGame()) { |
|
ds@1952
|
212 |
return pContext->ThrowNativeError("Client %d is not in game", client); |
|
ds@1952
|
213 |
} |
|
ds@1952
|
214 |
|
|
ds@1952
|
215 |
IPlayerInfo *pInfo = pPlayer->GetPlayerInfo(); |
|
ds@1952
|
216 |
if (!pInfo) |
|
ds@1952
|
217 |
{ |
|
ds@1952
|
218 |
return pContext->ThrowNativeError("IPlayerInfo not supported by game"); |
|
ds@1952
|
219 |
} |
|
ds@1952
|
220 |
|
|
ds@1952
|
221 |
return pInfo->IsObserver() ? 1 : 0; |
|
ds@1952
|
222 |
} |
|
ds@1952
|
223 |
|
|
ds@1952
|
224 |
static cell_t sm_GetClientInfo(IPluginContext *pContext, const cell_t *params) |
|
ds@1952
|
225 |
{ |
|
ds@1952
|
226 |
int client = params[1]; |
|
ds@1952
|
227 |
CPlayer *pPlayer = g_Players.GetPlayerByIndex(client); |
|
ds@1952
|
228 |
if (!pPlayer) |
|
ds@1952
|
229 |
{ |
|
ds@1952
|
230 |
return pContext->ThrowNativeError("Client index %d is invalid", client); |
|
ds@1952
|
231 |
} |
|
ds@1952
|
232 |
if (!pPlayer->IsConnected()) |
|
ds@1952
|
233 |
{ |
|
ds@1952
|
234 |
return pContext->ThrowNativeError("Client %d is not connected", client); |
|
ds@1952
|
235 |
} |
|
ds@1952
|
236 |
|
|
ds@1952
|
237 |
char *key; |
|
ds@1952
|
238 |
pContext->LocalToString(params[2], &key); |
|
ds@1952
|
239 |
|
|
ds@1952
|
240 |
const char *val = engine->GetClientConVarValue(client, key); |
|
ds@1952
|
241 |
if (!val) |
|
ds@1952
|
242 |
{ |
|
ds@1952
|
243 |
return false; |
|
ds@1952
|
244 |
} |
|
ds@1952
|
245 |
|
|
ds@1952
|
246 |
pContext->StringToLocalUTF8(params[3], params[4], val, NULL); |
|
ds@1952
|
247 |
return 1; |
|
ds@1952
|
248 |
} |
|
ds@1952
|
249 |
|
|
ds@1952
|
250 |
static cell_t SetUserAdmin(IPluginContext *pContext, const cell_t *params) |
|
ds@1952
|
251 |
{ |
|
ds@1952
|
252 |
int client = params[1]; |
|
ds@1952
|
253 |
CPlayer *pPlayer = g_Players.GetPlayerByIndex(client); |
|
ds@1952
|
254 |
if (!pPlayer) |
|
ds@1952
|
255 |
{ |
|
ds@1952
|
256 |
return pContext->ThrowNativeError("Client index %d is invalid", client); |
|
ds@1952
|
257 |
} |
|
ds@1952
|
258 |
if (!pPlayer->IsConnected()) |
|
ds@1952
|
259 |
{ |
|
ds@1952
|
260 |
return pContext->ThrowNativeError("Client %d is not connected", client); |
|
ds@1952
|
261 |
} |
|
ds@1952
|
262 |
if (!g_Admins.IsValidAdmin(params[2]) && params[2] != INVALID_ADMIN_ID) |
|
ds@1952
|
263 |
{ |
|
ds@1952
|
264 |
return pContext->ThrowNativeError("AdminId %x is invalid", params[2]); |
|
ds@1952
|
265 |
} |
|
ds@1952
|
266 |
|
|
ds@1952
|
267 |
pPlayer->SetAdminId(params[2], params[3] ? true : false); |
|
ds@1952
|
268 |
|
|
ds@1952
|
269 |
return 1; |
|
ds@1952
|
270 |
} |
|
ds@1952
|
271 |
|
|
ds@1952
|
272 |
static cell_t GetUserAdmin(IPluginContext *pContext, const cell_t *params) |
|
ds@1952
|
273 |
{ |
|
ds@1952
|
274 |
int client = params[1]; |
|
ds@1952
|
275 |
CPlayer *pPlayer = g_Players.GetPlayerByIndex(client); |
|
ds@1952
|
276 |
if (!pPlayer) |
|
ds@1952
|
277 |
{ |
|
ds@1952
|
278 |
return pContext->ThrowNativeError("Client index %d is invalid", client); |
|
ds@1952
|
279 |
} |
|
ds@1952
|
280 |
if (!pPlayer->IsConnected()) |
|
ds@1952
|
281 |
{ |
|
ds@1952
|
282 |
return pContext->ThrowNativeError("Client %d is not connected", client); |
|
ds@1952
|
283 |
} |
|
ds@1952
|
284 |
|
|
ds@1952
|
285 |
return pPlayer->GetAdminId(); |
|
ds@1952
|
286 |
} |
|
ds@1952
|
287 |
|
|
ds@1952
|
288 |
static cell_t AddUserFlags(IPluginContext *pContext, const cell_t *params) |
|
ds@1952
|
289 |
{ |
|
ds@1952
|
290 |
int client = params[1]; |
|
ds@1952
|
291 |
CPlayer *pPlayer = g_Players.GetPlayerByIndex(client); |
|
ds@1952
|
292 |
if (!pPlayer) |
|
ds@1952
|
293 |
{ |
|
ds@1952
|
294 |
return pContext->ThrowNativeError("Client index %d is invalid", client); |
|
ds@1952
|
295 |
} |
|
ds@1952
|
296 |
if (!pPlayer->IsConnected()) |
|
ds@1952
|
297 |
{ |
|
ds@1952
|
298 |
return pContext->ThrowNativeError("Client %d is not connected", client); |
|
ds@1952
|
299 |
} |
|
ds@1952
|
300 |
|
|
ds@1952
|
301 |
AdminId id; |
|
ds@1952
|
302 |
if ((id=pPlayer->GetAdminId()) == INVALID_ADMIN_ID) |
|
ds@1952
|
303 |
{ |
|
ds@1952
|
304 |
id = g_Admins.CreateAdmin(NULL); |
|
ds@1952
|
305 |
pPlayer->SetAdminId(id, true); |
|
ds@1952
|
306 |
} |
|
ds@1952
|
307 |
|
|
ds@1952
|
308 |
cell_t *addr; |
|
ds@1952
|
309 |
for (int i=2; i<=params[0]; i++) |
|
ds@1952
|
310 |
{ |
|
ds@1952
|
311 |
pContext->LocalToPhysAddr(params[i], &addr); |
|
ds@1952
|
312 |
g_Admins.SetAdminFlag(id, (AdminFlag)*addr, true); |
|
ds@1952
|
313 |
} |
|
ds@1952
|
314 |
|
|
ds@1952
|
315 |
return 1; |
|
ds@1952
|
316 |
} |
|
ds@1952
|
317 |
|
|
ds@1952
|
318 |
static cell_t RemoveUserFlags(IPluginContext *pContext, const cell_t *params) |
|
ds@1952
|
319 |
{ |
|
ds@1952
|
320 |
int client = params[1]; |
|
ds@1952
|
321 |
CPlayer *pPlayer = g_Players.GetPlayerByIndex(client); |
|
ds@1952
|
322 |
if (!pPlayer) |
|
ds@1952
|
323 |
{ |
|
ds@1952
|
324 |
return pContext->ThrowNativeError("Client index %d is invalid", client); |
|
ds@1952
|
325 |
} |
|
ds@1952
|
326 |
if (!pPlayer->IsConnected()) |
|
ds@1952
|
327 |
{ |
|
ds@1952
|
328 |
return pContext->ThrowNativeError("Client %d is not connected", client); |
|
ds@1952
|
329 |
} |
|
ds@1952
|
330 |
|
|
ds@1952
|
331 |
AdminId id; |
|
ds@1952
|
332 |
if ((id=pPlayer->GetAdminId()) == INVALID_ADMIN_ID) |
|
ds@1952
|
333 |
{ |
|
ds@1952
|
334 |
return 0; |
|
ds@1952
|
335 |
} |
|
ds@1952
|
336 |
|
|
ds@1952
|
337 |
cell_t *addr; |
|
ds@1952
|
338 |
for (int i=2; i<=params[0]; i++) |
|
ds@1952
|
339 |
{ |
|
ds@1952
|
340 |
pContext->LocalToPhysAddr(params[i], &addr); |
|
ds@1952
|
341 |
g_Admins.SetAdminFlag(id, (AdminFlag)*addr, false); |
|
ds@1952
|
342 |
} |
|
ds@1952
|
343 |
|
|
ds@1952
|
344 |
return 1; |
|
ds@1952
|
345 |
} |
|
ds@1952
|
346 |
|
|
ds@1952
|
347 |
static cell_t SetUserFlagBits(IPluginContext *pContext, const cell_t *params) |
|
ds@1952
|
348 |
{ |
|
ds@1952
|
349 |
int client = params[1]; |
|
ds@1952
|
350 |
CPlayer *pPlayer = g_Players.GetPlayerByIndex(client); |
|
ds@1952
|
351 |
if (!pPlayer) |
|
ds@1952
|
352 |
{ |
|
ds@1952
|
353 |
return pContext->ThrowNativeError("Client index %d is invalid", client); |
|
ds@1952
|
354 |
} |
|
ds@1952
|
355 |
if (!pPlayer->IsConnected()) |
|
ds@1952
|
356 |
{ |
|
ds@1952
|
357 |
return pContext->ThrowNativeError("Client %d is not connected", client); |
|
ds@1952
|
358 |
} |
|
ds@1952
|
359 |
|
|
ds@1952
|
360 |
AdminId id; |
|
ds@1952
|
361 |
if ((id=pPlayer->GetAdminId()) == INVALID_ADMIN_ID) |
|
ds@1952
|
362 |
{ |
|
ds@1952
|
363 |
id = g_Admins.CreateAdmin(NULL); |
|
ds@1952
|
364 |
pPlayer->SetAdminId(id, true); |
|
ds@1952
|
365 |
} |
|
ds@1952
|
366 |
|
|
ds@1952
|
367 |
g_Admins.SetAdminFlags(id, Access_Effective, params[2]); |
|
ds@1952
|
368 |
|
|
ds@1952
|
369 |
return 1; |
|
ds@1952
|
370 |
} |
|
ds@1952
|
371 |
|
|
ds@1952
|
372 |
static cell_t GetUserFlagBits(IPluginContext *pContext, const cell_t *params) |
|
ds@1952
|
373 |
{ |
|
ds@1952
|
374 |
int client = params[1]; |
|
ds@1952
|
375 |
CPlayer *pPlayer = g_Players.GetPlayerByIndex(client); |
|
ds@1952
|
376 |
if (!pPlayer) |
|
ds@1952
|
377 |
{ |
|
ds@1952
|
378 |
return pContext->ThrowNativeError("Client index %d is invalid", client); |
|
ds@1952
|
379 |
} |
|
ds@1952
|
380 |
if (!pPlayer->IsConnected()) |
|
ds@1952
|
381 |
{ |
|
ds@1952
|
382 |
return pContext->ThrowNativeError("Client %d is not connected", client); |
|
ds@1952
|
383 |
} |
|
ds@1952
|
384 |
|
|
ds@1952
|
385 |
AdminId id; |
|
ds@1952
|
386 |
if ((id=pPlayer->GetAdminId()) == INVALID_ADMIN_ID) |
|
ds@1952
|
387 |
{ |
|
ds@1952
|
388 |
return 0; |
|
ds@1952
|
389 |
} |
|
ds@1952
|
390 |
|
|
ds@1952
|
391 |
return g_Admins.GetAdminFlags(id, Access_Effective); |
|
ds@1952
|
392 |
} |
|
ds@1952
|
393 |
|
|
ds@1952
|
394 |
static cell_t GetClientUserId(IPluginContext *pContext, const cell_t *params) |
|
ds@1952
|
395 |
{ |
|
ds@1952
|
396 |
int client = params[1]; |
|
ds@1952
|
397 |
CPlayer *pPlayer = g_Players.GetPlayerByIndex(client); |
|
ds@1952
|
398 |
if (!pPlayer) |
|
ds@1952
|
399 |
{ |
|
ds@1952
|
400 |
return pContext->ThrowNativeError("Client index %d is invalid", client); |
|
ds@1952
|
401 |
} |
|
ds@1952
|
402 |
if (!pPlayer->IsConnected()) |
|
ds@1952
|
403 |
{ |
|
ds@1952
|
404 |
return pContext->ThrowNativeError("Client %d is not connected", client); |
|
ds@1952
|
405 |
} |
|
ds@1952
|
406 |
|
|
ds@1952
|
407 |
return engine->GetPlayerUserId(pPlayer->GetEdict()); |
|
ds@1952
|
408 |
} |
|
ds@1952
|
409 |
|
|
ds@1952
|
410 |
static cell_t CanUserTarget(IPluginContext *pContext, const cell_t *params) |
|
ds@1952
|
411 |
{ |
|
ds@1952
|
412 |
int client = params[1]; |
|
ds@1952
|
413 |
int target = params[2]; |
|
ds@1952
|
414 |
|
|
ds@1952
|
415 |
if (client == 0) |
|
ds@1952
|
416 |
{ |
|
ds@1952
|
417 |
return 1; |
|
ds@1952
|
418 |
} |
|
ds@1952
|
419 |
|
|
ds@1952
|
420 |
CPlayer *pPlayer = g_Players.GetPlayerByIndex(client); |
|
ds@1952
|
421 |
if (!pPlayer) |
|
ds@1952
|
422 |
{ |
|
ds@1952
|
423 |
return pContext->ThrowNativeError("Client index %d is invalid", client); |
|
ds@1952
|
424 |
} else if (!pPlayer->IsConnected()) { |
|
ds@1952
|
425 |
return pContext->ThrowNativeError("Client %d is not connected", client); |
|
ds@1952
|
426 |
} |
|
ds@1952
|
427 |
|
|
ds@1952
|
428 |
CPlayer *pTarget = g_Players.GetPlayerByIndex(target); |
|
ds@1952
|
429 |
if (!pTarget) |
|
ds@1952
|
430 |
{ |
|
ds@1952
|
431 |
return pContext->ThrowNativeError("Client index %d is invalid", target); |
|
ds@1952
|
432 |
} else if (!pTarget->IsConnected()) { |
|
ds@1952
|
433 |
return pContext->ThrowNativeError("Client %d is not connected", target); |
|
ds@1952
|
434 |
} |
|
ds@1952
|
435 |
|
|
ds@1952
|
436 |
return g_Admins.CanAdminTarget(pPlayer->GetAdminId(), pTarget->GetAdminId()) ? 1 : 0; |
|
ds@1952
|
437 |
} |
|
ds@1952
|
438 |
|
|
ds@1952
|
439 |
static cell_t GetClientTeam(IPluginContext *pContext, const cell_t *params) |
|
ds@1952
|
440 |
{ |
|
ds@1952
|
441 |
int client = params[1]; |
|
ds@1952
|
442 |
|
|
ds@1952
|
443 |
CPlayer *pPlayer = g_Players.GetPlayerByIndex(client); |
|
ds@1952
|
444 |
if (!pPlayer) |
|
ds@1952
|
445 |
{ |
|
ds@1952
|
446 |
return pContext->ThrowNativeError("Client index %d is invalid", client); |
|
ds@1952
|
447 |
} else if (!pPlayer->IsInGame()) { |
|
ds@1952
|
448 |
return pContext->ThrowNativeError("Client %d is not in game", client); |
|
ds@1952
|
449 |
} |
|
ds@1952
|
450 |
|
|
ds@1952
|
451 |
IPlayerInfo *pInfo = pPlayer->GetPlayerInfo(); |
|
ds@1952
|
452 |
if (!pInfo) |
|
ds@1952
|
453 |
{ |
|
ds@1952
|
454 |
return pContext->ThrowNativeError("IPlayerInfo not supported by game"); |
|
ds@1952
|
455 |
} |
|
ds@1952
|
456 |
|
|
ds@1952
|
457 |
return pInfo->GetTeamIndex(); |
|
ds@1952
|
458 |
} |
|
ds@1952
|
459 |
|
|
ds@1952
|
460 |
static cell_t GetFragCount(IPluginContext *pContext, const cell_t *params) |
|
ds@1952
|
461 |
{ |
|
ds@1952
|
462 |
int client = params[1]; |
|
ds@1952
|
463 |
|
|
ds@1952
|
464 |
CPlayer *pPlayer = g_Players.GetPlayerByIndex(client); |
|
ds@1952
|
465 |
if (!pPlayer) |
|
ds@1952
|
466 |
{ |
|
ds@1952
|
467 |
return pContext->ThrowNativeError("Client index %d is invalid", client); |
|
ds@1952
|
468 |
} else if (!pPlayer->IsInGame()) { |
|
ds@1952
|
469 |
return pContext->ThrowNativeError("Client %d is not in game", client); |
|
ds@1952
|
470 |
} |
|
ds@1952
|
471 |
|
|
ds@1952
|
472 |
IPlayerInfo *pInfo = pPlayer->GetPlayerInfo(); |
|
ds@1952
|
473 |
if (!pInfo) |
|
ds@1952
|
474 |
{ |
|
ds@1952
|
475 |
return pContext->ThrowNativeError("IPlayerInfo not supported by game"); |
|
ds@1952
|
476 |
} |
|
ds@1952
|
477 |
|
|
ds@1952
|
478 |
return pInfo->GetFragCount(); |
|
ds@1952
|
479 |
} |
|
ds@1952
|
480 |
|
|
ds@1952
|
481 |
static cell_t GetDeathCount(IPluginContext *pContext, const cell_t *params) |
|
ds@1952
|
482 |
{ |
|
ds@1952
|
483 |
int client = params[1]; |
|
ds@1952
|
484 |
|
|
ds@1952
|
485 |
CPlayer *pPlayer = g_Players.GetPlayerByIndex(client); |
|
ds@1952
|
486 |
if (!pPlayer) |
|
ds@1952
|
487 |
{ |
|
ds@1952
|
488 |
return pContext->ThrowNativeError("Client index %d is invalid", client); |
|
ds@1952
|
489 |
} else if (!pPlayer->IsInGame()) { |
|
ds@1952
|
490 |
return pContext->ThrowNativeError("Client %d is not in game", client); |
|
ds@1952
|
491 |
} |
|
ds@1952
|
492 |
|
|
ds@1952
|
493 |
IPlayerInfo *pInfo = pPlayer->GetPlayerInfo(); |
|
ds@1952
|
494 |
if (!pInfo) |
|
ds@1952
|
495 |
{ |
|
ds@1952
|
496 |
return pContext->ThrowNativeError("IPlayerInfo not supported by game"); |
|
ds@1952
|
497 |
} |
|
ds@1952
|
498 |
|
|
ds@1952
|
499 |
return pInfo->GetDeathCount(); |
|
ds@1952
|
500 |
} |
|
ds@1952
|
501 |
|
|
ds@1952
|
502 |
static cell_t GetArmorValue(IPluginContext *pContext, const cell_t *params) |
|
ds@1952
|
503 |
{ |
|
ds@1952
|
504 |
int client = params[1]; |
|
ds@1952
|
505 |
|
|
ds@1952
|
506 |
CPlayer *pPlayer = g_Players.GetPlayerByIndex(client); |
|
ds@1952
|
507 |
if (!pPlayer) |
|
ds@1952
|
508 |
{ |
|
ds@1952
|
509 |
return pContext->ThrowNativeError("Client index %d is invalid", client); |
|
ds@1952
|
510 |
} else if (!pPlayer->IsInGame()) { |
|
ds@1952
|
511 |
return pContext->ThrowNativeError("Client %d is not in game", client); |
|
ds@1952
|
512 |
} |
|
ds@1952
|
513 |
|
|
ds@1952
|
514 |
IPlayerInfo *pInfo = pPlayer->GetPlayerInfo(); |
|
ds@1952
|
515 |
if (!pInfo) |
|
ds@1952
|
516 |
{ |
|
ds@1952
|
517 |
return pContext->ThrowNativeError("IPlayerInfo not supported by game"); |
|
ds@1952
|
518 |
} |
|
ds@1952
|
519 |
|
|
ds@1952
|
520 |
return pInfo->GetArmorValue(); |
|
ds@1952
|
521 |
} |
|
ds@1952
|
522 |
|
|
ds@1952
|
523 |
static cell_t GetAbsOrigin(IPluginContext *pContext, const cell_t *params) |
|
ds@1952
|
524 |
{ |
|
ds@1952
|
525 |
int client = params[1]; |
|
ds@1952
|
526 |
|
|
ds@1952
|
527 |
CPlayer *pPlayer = g_Players.GetPlayerByIndex(client); |
|
ds@1952
|
528 |
if (!pPlayer) |
|
ds@1952
|
529 |
{ |
|
ds@1952
|
530 |
return pContext->ThrowNativeError("Client index %d is invalid", client); |
|
ds@1952
|
531 |
} else if (!pPlayer->IsInGame()) { |
|
ds@1952
|
532 |
return pContext->ThrowNativeError("Client %d is not in game", client); |
|
ds@1952
|
533 |
} |
|
ds@1952
|
534 |
|
|
ds@1952
|
535 |
IPlayerInfo *pInfo = pPlayer->GetPlayerInfo(); |
|
ds@1952
|
536 |
if (!pInfo) |
|
ds@1952
|
537 |
{ |
|
ds@1952
|
538 |
return pContext->ThrowNativeError("IPlayerInfo not supported by game"); |
|
ds@1952
|
539 |
} |
|
ds@1952
|
540 |
|
|
ds@1952
|
541 |
cell_t *pVec; |
|
ds@1952
|
542 |
pContext->LocalToPhysAddr(params[2], &pVec); |
|
ds@1952
|
543 |
|
|
ds@1952
|
544 |
Vector vec = pInfo->GetAbsOrigin(); |
|
ds@1952
|
545 |
pVec[0] = sp_ftoc(vec.x); |
|
ds@1952
|
546 |
pVec[1] = sp_ftoc(vec.y); |
|
ds@1952
|
547 |
pVec[2] = sp_ftoc(vec.z); |
|
ds@1952
|
548 |
|
|
ds@1952
|
549 |
return 1; |
|
ds@1952
|
550 |
} |
|
ds@1952
|
551 |
|
|
ds@1952
|
552 |
static cell_t GetAbsAngles(IPluginContext *pContext, const cell_t *params) |
|
ds@1952
|
553 |
{ |
|
ds@1952
|
554 |
int client = params[1]; |
|
ds@1952
|
555 |
|
|
ds@1952
|
556 |
CPlayer *pPlayer = g_Players.GetPlayerByIndex(client); |
|
ds@1952
|
557 |
if (!pPlayer) |
|
ds@1952
|
558 |
{ |
|
ds@1952
|
559 |
return pContext->ThrowNativeError("Client index %d is invalid", client); |
|
ds@1952
|
560 |
} else if (!pPlayer->IsInGame()) { |
|
ds@1952
|
561 |
return pContext->ThrowNativeError("Client %d is not in game", client); |
|
ds@1952
|
562 |
} |
|
ds@1952
|
563 |
|
|
ds@1952
|
564 |
IPlayerInfo *pInfo = pPlayer->GetPlayerInfo(); |
|
ds@1952
|
565 |
if (!pInfo) |
|
ds@1952
|
566 |
{ |
|
ds@1952
|
567 |
return pContext->ThrowNativeError("IPlayerInfo not supported by game"); |
|
ds@1952
|
568 |
} |
|
ds@1952
|
569 |
|
|
ds@1952
|
570 |
cell_t *pAng; |
|
ds@1952
|
571 |
pContext->LocalToPhysAddr(params[2], &pAng); |
|
ds@1952
|
572 |
|
|
ds@1952
|
573 |
QAngle ang = pInfo->GetAbsAngles(); |
|
ds@1952
|
574 |
pAng[0] = sp_ftoc(ang.x); |
|
ds@1952
|
575 |
pAng[1] = sp_ftoc(ang.y); |
|
ds@1952
|
576 |
pAng[2] = sp_ftoc(ang.z); |
|
ds@1952
|
577 |
|
|
ds@1952
|
578 |
return 1; |
|
ds@1952
|
579 |
} |
|
ds@1952
|
580 |
|
|
ds@1952
|
581 |
static cell_t GetPlayerMins(IPluginContext *pContext, const cell_t *params) |
|
ds@1952
|
582 |
{ |
|
ds@1952
|
583 |
int client = params[1]; |
|
ds@1952
|
584 |
|
|
ds@1952
|
585 |
CPlayer *pPlayer = g_Players.GetPlayerByIndex(client); |
|
ds@1952
|
586 |
if (!pPlayer) |
|
ds@1952
|
587 |
{ |
|
ds@1952
|
588 |
return pContext->ThrowNativeError("Client index %d is invalid", client); |
|
ds@1952
|
589 |
} else if (!pPlayer->IsInGame()) { |
|
ds@1952
|
590 |
return pContext->ThrowNativeError("Client %d is not in game", client); |
|
ds@1952
|
591 |
} |
|
ds@1952
|
592 |
|
|
ds@1952
|
593 |
IPlayerInfo *pInfo = pPlayer->GetPlayerInfo(); |
|
ds@1952
|
594 |
if (!pInfo) |
|
ds@1952
|
595 |
{ |
|
ds@1952
|
596 |
return pContext->ThrowNativeError("IPlayerInfo not supported by game"); |
|
ds@1952
|
597 |
} |
|
ds@1952
|
598 |
|
|
ds@1952
|
599 |
cell_t *pVec; |
|
ds@1952
|
600 |
pContext->LocalToPhysAddr(params[2], &pVec); |
|
ds@1952
|
601 |
|
|
ds@1952
|
602 |
Vector vec = pInfo->GetPlayerMins(); |
|
ds@1952
|
603 |
pVec[0] = sp_ftoc(vec.x); |
|
ds@1952
|
604 |
pVec[1] = sp_ftoc(vec.y); |
|
ds@1952
|
605 |
pVec[2] = sp_ftoc(vec.z); |
|
ds@1952
|
606 |
|
|
ds@1952
|
607 |
return 1; |
|
ds@1952
|
608 |
} |
|
ds@1952
|
609 |
|
|
ds@1952
|
610 |
static cell_t GetPlayerMaxs(IPluginContext *pContext, const cell_t *params) |
|
ds@1952
|
611 |
{ |
|
ds@1952
|
612 |
int client = params[1]; |
|
ds@1952
|
613 |
|
|
ds@1952
|
614 |
CPlayer *pPlayer = g_Players.GetPlayerByIndex(client); |
|
ds@1952
|
615 |
if (!pPlayer) |
|
ds@1952
|
616 |
{ |
|
ds@1952
|
617 |
return pContext->ThrowNativeError("Client index %d is invalid", client); |
|
ds@1952
|
618 |
} else if (!pPlayer->IsInGame()) { |
|
ds@1952
|
619 |
return pContext->ThrowNativeError("Client %d is not in game", client); |
|
ds@1952
|
620 |
} |
|
ds@1952
|
621 |
|
|
ds@1952
|
622 |
IPlayerInfo *pInfo = pPlayer->GetPlayerInfo(); |
|
ds@1952
|
623 |
if (!pInfo) |
|
ds@1952
|
624 |
{ |
|
ds@1952
|
625 |
return pContext->ThrowNativeError("IPlayerInfo not supported by game"); |
|
ds@1952
|
626 |
} |
|
ds@1952
|
627 |
|
|
ds@1952
|
628 |
cell_t *pVec; |
|
ds@1952
|
629 |
pContext->LocalToPhysAddr(params[2], &pVec); |
|
ds@1952
|
630 |
|
|
ds@1952
|
631 |
Vector vec = pInfo->GetPlayerMaxs(); |
|
ds@1952
|
632 |
pVec[0] = sp_ftoc(vec.x); |
|
ds@1952
|
633 |
pVec[1] = sp_ftoc(vec.y); |
|
ds@1952
|
634 |
pVec[2] = sp_ftoc(vec.z); |
|
ds@1952
|
635 |
|
|
ds@1952
|
636 |
return 1; |
|
ds@1952
|
637 |
} |
|
ds@1952
|
638 |
|
|
ds@1952
|
639 |
static cell_t GetWeaponName(IPluginContext *pContext, const cell_t *params) |
|
ds@1952
|
640 |
{ |
|
ds@1952
|
641 |
int client = params[1]; |
|
ds@1952
|
642 |
|
|
ds@1952
|
643 |
CPlayer *pPlayer = g_Players.GetPlayerByIndex(client); |
|
ds@1952
|
644 |
if (!pPlayer) |
|
ds@1952
|
645 |
{ |
|
ds@1952
|
646 |
return pContext->ThrowNativeError("Client index %d is invalid", client); |
|
ds@1952
|
647 |
} else if (!pPlayer->IsInGame()) { |
|
ds@1952
|
648 |
return pContext->ThrowNativeError("Client %d is not in game", client); |
|
ds@1952
|
649 |
} |
|
ds@1952
|
650 |
|
|
ds@1952
|
651 |
IPlayerInfo *pInfo = pPlayer->GetPlayerInfo(); |
|
ds@1952
|
652 |
if (!pInfo) |
|
ds@1952
|
653 |
{ |
|
ds@1952
|
654 |
return pContext->ThrowNativeError("IPlayerInfo not supported by game"); |
|
ds@1952
|
655 |
} |
|
ds@1952
|
656 |
|
|
ds@1952
|
657 |
const char *weapon = pInfo->GetWeaponName(); |
|
ds@1952
|
658 |
pContext->StringToLocalUTF8(params[2], static_cast<size_t>(params[3]), weapon ? weapon : "", NULL); |
|
ds@1952
|
659 |
|
|
ds@1952
|
660 |
return 1; |
|
ds@1952
|
661 |
} |
|
ds@1952
|
662 |
|
|
ds@1952
|
663 |
static cell_t GetModelName(IPluginContext *pContext, const cell_t *params) |
|
ds@1952
|
664 |
{ |
|
ds@1952
|
665 |
int client = params[1]; |
|
ds@1952
|
666 |
|
|
ds@1952
|
667 |
CPlayer *pPlayer = g_Players.GetPlayerByIndex(client); |
|
ds@1952
|
668 |
if (!pPlayer) |
|
ds@1952
|
669 |
{ |
|
ds@1952
|
670 |
return pContext->ThrowNativeError("Client index %d is invalid", client); |
|
ds@1952
|
671 |
} else if (!pPlayer->IsInGame()) { |
|
ds@1952
|
672 |
return pContext->ThrowNativeError("Client %d is not in game", client); |
|
ds@1952
|
673 |
} |
|
ds@1952
|
674 |
|
|
ds@1952
|
675 |
IPlayerInfo *pInfo = pPlayer->GetPlayerInfo(); |
|
ds@1952
|
676 |
if (!pInfo) |
|
ds@1952
|
677 |
{ |
|
ds@1952
|
678 |
return pContext->ThrowNativeError("IPlayerInfo not supported by game"); |
|
ds@1952
|
679 |
} |
|
ds@1952
|
680 |
|
|
ds@1952
|
681 |
const char *model = pInfo->GetModelName(); |
|
ds@1952
|
682 |
pContext->StringToLocalUTF8(params[2], static_cast<size_t>(params[3]), model ? model : "", NULL); |
|
ds@1952
|
683 |
|
|
ds@1952
|
684 |
return 1; |
|
ds@1952
|
685 |
} |
|
ds@1952
|
686 |
|
|
ds@1952
|
687 |
static cell_t GetHealth(IPluginContext *pContext, const cell_t *params) |
|
ds@1952
|
688 |
{ |
|
ds@1952
|
689 |
int client = params[1]; |
|
ds@1952
|
690 |
|
|
ds@1952
|
691 |
CPlayer *pPlayer = g_Players.GetPlayerByIndex(client); |
|
ds@1952
|
692 |
if (!pPlayer) |
|
ds@1952
|
693 |
{ |
|
ds@1952
|
694 |
return pContext->ThrowNativeError("Client index %d is invalid", client); |
|
ds@1952
|
695 |
} else if (!pPlayer->IsInGame()) { |
|
ds@1952
|
696 |
return pContext->ThrowNativeError("Client %d is not in game", client); |
|
ds@1952
|
697 |
} |
|
ds@1952
|
698 |
|
|
ds@1952
|
699 |
IPlayerInfo *pInfo = pPlayer->GetPlayerInfo(); |
|
ds@1952
|
700 |
if (!pInfo) |
|
ds@1952
|
701 |
{ |
|
ds@1952
|
702 |
return pContext->ThrowNativeError("IPlayerInfo not supported by game"); |
|
ds@1952
|
703 |
} |
|
ds@1952
|
704 |
|
|
ds@1952
|
705 |
return pInfo->GetHealth(); |
|
ds@1952
|
706 |
} |
|
ds@1952
|
707 |
|
|
ds@1952
|
708 |
static cell_t GetTimeConnected(IPluginContext *pContext, const cell_t *params) |
|
ds@1952
|
709 |
{ |
|
ds@1952
|
710 |
int client = params[1]; |
|
ds@1952
|
711 |
|
|
ds@1952
|
712 |
CPlayer *pPlayer = g_Players.GetPlayerByIndex(client); |
|
ds@1952
|
713 |
if (!pPlayer) |
|
ds@1952
|
714 |
{ |
|
ds@1952
|
715 |
return pContext->ThrowNativeError("Client index %d is invalid", client); |
|
ds@1952
|
716 |
} else if (!pPlayer->IsInGame()) { |
|
ds@1952
|
717 |
return pContext->ThrowNativeError("Client %d is not in game", client); |
|
ds@1952
|
718 |
} else if (pPlayer->IsFakeClient()) { |
|
ds@1952
|
719 |
return pContext->ThrowNativeError("Client %d is a bot", client); |
|
ds@1952
|
720 |
} |
|
ds@1952
|
721 |
|
|
ds@1952
|
722 |
INetChannelInfo *pInfo = engine->GetPlayerNetInfo(client); |
|
ds@1952
|
723 |
|
|
ds@1952
|
724 |
return sp_ftoc(pInfo->GetTimeConnected()); |
|
ds@1952
|
725 |
} |
|
ds@1952
|
726 |
|
|
ds@1952
|
727 |
static cell_t GetDataRate(IPluginContext *pContext, const cell_t *params) |
|
ds@1952
|
728 |
{ |
|
ds@1952
|
729 |
int client = params[1]; |
|
ds@1952
|
730 |
|
|
ds@1952
|
731 |
CPlayer *pPlayer = g_Players.GetPlayerByIndex(client); |
|
ds@1952
|
732 |
if (!pPlayer) |
|
ds@1952
|
733 |
{ |
|
ds@1952
|
734 |
return pContext->ThrowNativeError("Client index %d is invalid", client); |
|
ds@1952
|
735 |
} else if (!pPlayer->IsInGame()) { |
|
ds@1952
|
736 |
return pContext->ThrowNativeError("Client %d is not in game", client); |
|
ds@1952
|
737 |
} else if (pPlayer->IsFakeClient()) { |
|
ds@1952
|
738 |
return pContext->ThrowNativeError("Client %d is a bot", client); |
|
ds@1952
|
739 |
} |
|
ds@1952
|
740 |
|
|
ds@1952
|
741 |
INetChannelInfo *pInfo = engine->GetPlayerNetInfo(client); |
|
ds@1952
|
742 |
|
|
ds@1952
|
743 |
return pInfo->GetDataRate(); |
|
ds@1952
|
744 |
} |
|
ds@1952
|
745 |
|
|
ds@1952
|
746 |
static cell_t IsTimingOut(IPluginContext *pContext, const cell_t *params) |
|
ds@1952
|
747 |
{ |
|
ds@1952
|
748 |
int client = params[1]; |
|
ds@1952
|
749 |
|
|
ds@1952
|
750 |
CPlayer *pPlayer = g_Players.GetPlayerByIndex(client); |
|
ds@1952
|
751 |
if (!pPlayer) |
|
ds@1952
|
752 |
{ |
|
ds@1952
|
753 |
return pContext->ThrowNativeError("Client index %d is invalid", client); |
|
ds@1952
|
754 |
} else if (!pPlayer->IsInGame()) { |
|
ds@1952
|
755 |
return pContext->ThrowNativeError("Client %d is not in game", client); |
|
ds@1952
|
756 |
} else if (pPlayer->IsFakeClient()) { |
|
ds@1952
|
757 |
return pContext->ThrowNativeError("Client %d is a bot", client); |
|
ds@1952
|
758 |
} |
|
ds@1952
|
759 |
|
|
ds@1952
|
760 |
INetChannelInfo *pInfo = engine->GetPlayerNetInfo(client); |
|
ds@1952
|
761 |
|
|
ds@1952
|
762 |
return pInfo->IsTimingOut() ? 1 : 0; |
|
ds@1952
|
763 |
} |
|
ds@1952
|
764 |
|
|
ds@1952
|
765 |
static cell_t GetLatency(IPluginContext *pContext, const cell_t *params) |
|
ds@1952
|
766 |
{ |
|
ds@1952
|
767 |
int client = params[1]; |
|
ds@1952
|
768 |
|
|
ds@1952
|
769 |
CPlayer *pPlayer = g_Players.GetPlayerByIndex(client); |
|
ds@1952
|
770 |
if (!pPlayer) |
|
ds@1952
|
771 |
{ |
|
ds@1952
|
772 |
return pContext->ThrowNativeError("Client index %d is invalid", client); |
|
ds@1952
|
773 |
} else if (!pPlayer->IsInGame()) { |
|
ds@1952
|
774 |
return pContext->ThrowNativeError("Client %d is not in game", client); |
|
ds@1952
|
775 |
} else if (pPlayer->IsFakeClient()) { |
|
ds@1952
|
776 |
return pContext->ThrowNativeError("Client %d is a bot", client); |
|
ds@1952
|
777 |
} |
|
ds@1952
|
778 |
|
|
ds@1952
|
779 |
INetChannelInfo *pInfo = engine->GetPlayerNetInfo(client); |
|
ds@1952
|
780 |
|
|
ds@1952
|
781 |
return sp_ftoc(pInfo->GetLatency(params[2])); |
|
ds@1952
|
782 |
} |
|
ds@1952
|
783 |
|
|
ds@1952
|
784 |
static cell_t GetAvgLatency(IPluginContext *pContext, const cell_t *params) |
|
ds@1952
|
785 |
{ |
|
ds@1952
|
786 |
int client = params[1]; |
|
ds@1952
|
787 |
|
|
ds@1952
|
788 |
CPlayer *pPlayer = g_Players.GetPlayerByIndex(client); |
|
ds@1952
|
789 |
if (!pPlayer) |
|
ds@1952
|
790 |
{ |
|
ds@1952
|
791 |
return pContext->ThrowNativeError("Client index %d is invalid", client); |
|
ds@1952
|
792 |
} else if (!pPlayer->IsInGame()) { |
|
ds@1952
|
793 |
return pContext->ThrowNativeError("Client %d is not in game", client); |
|
ds@1952
|
794 |
} else if (pPlayer->IsFakeClient()) { |
|
ds@1952
|
795 |
return pContext->ThrowNativeError("Client %d is a bot", client); |
|
ds@1952
|
796 |
} |
|
ds@1952
|
797 |
|
|
ds@1952
|
798 |
INetChannelInfo *pInfo = engine->GetPlayerNetInfo(client); |
|
ds@1952
|
799 |
|
|
ds@1952
|
800 |
return sp_ftoc(pInfo->GetAvgLatency(params[2])); |
|
ds@1952
|
801 |
} |
|
ds@1952
|
802 |
|
|
ds@1952
|
803 |
static cell_t GetAvgLoss(IPluginContext *pContext, const cell_t *params) |
|
ds@1952
|
804 |
{ |
|
ds@1952
|
805 |
int client = params[1]; |
|
ds@1952
|
806 |
|
|
ds@1952
|
807 |
CPlayer *pPlayer = g_Players.GetPlayerByIndex(client); |
|
ds@1952
|
808 |
if (!pPlayer) |
|
ds@1952
|
809 |
{ |
|
ds@1952
|
810 |
return pContext->ThrowNativeError("Client index %d is invalid", client); |
|
ds@1952
|
811 |
} else if (!pPlayer->IsInGame()) { |
|
ds@1952
|
812 |
return pContext->ThrowNativeError("Client %d is not in game", client); |
|
ds@1952
|
813 |
} else if (pPlayer->IsFakeClient()) { |
|
ds@1952
|
814 |
return pContext->ThrowNativeError("Client %d is a bot", client); |
|
ds@1952
|
815 |
} |
|
ds@1952
|
816 |
|
|
ds@1952
|
817 |
INetChannelInfo *pInfo = engine->GetPlayerNetInfo(client); |
|
ds@1952
|
818 |
|
|
ds@1952
|
819 |
return sp_ftoc(pInfo->GetAvgLoss(params[2])); |
|
ds@1952
|
820 |
} |
|
ds@1952
|
821 |
|
|
ds@1952
|
822 |
static cell_t GetAvgChoke(IPluginContext *pContext, const cell_t *params) |
|
ds@1952
|
823 |
{ |
|
ds@1952
|
824 |
int client = params[1]; |
|
ds@1952
|
825 |
|
|
ds@1952
|
826 |
CPlayer *pPlayer = g_Players.GetPlayerByIndex(client); |
|
ds@1952
|
827 |
if (!pPlayer) |
|
ds@1952
|
828 |
{ |
|
ds@1952
|
829 |
return pContext->ThrowNativeError("Client index %d is invalid", client); |
|
ds@1952
|
830 |
} else if (!pPlayer->IsInGame()) { |
|
ds@1952
|
831 |
return pContext->ThrowNativeError("Client %d is not in game", client); |
|
ds@1952
|
832 |
} else if (pPlayer->IsFakeClient()) { |
|
ds@1952
|
833 |
return pContext->ThrowNativeError("Client %d is a bot", client); |
|
ds@1952
|
834 |
} |
|
ds@1952
|
835 |
|
|
ds@1952
|
836 |
INetChannelInfo *pInfo = engine->GetPlayerNetInfo(client); |
|
ds@1952
|
837 |
|
|
ds@1952
|
838 |
return sp_ftoc(pInfo->GetAvgChoke(params[2])); |
|
ds@1952
|
839 |
} |
|
ds@1952
|
840 |
|
|
ds@1952
|
841 |
static cell_t GetAvgData(IPluginContext *pContext, const cell_t *params) |
|
ds@1952
|
842 |
{ |
|
ds@1952
|
843 |
int client = params[1]; |
|
ds@1952
|
844 |
|
|
ds@1952
|
845 |
CPlayer *pPlayer = g_Players.GetPlayerByIndex(client); |
|
ds@1952
|
846 |
if (!pPlayer) |
|
ds@1952
|
847 |
{ |
|
ds@1952
|
848 |
return pContext->ThrowNativeError("Client index %d is invalid", client); |
|
ds@1952
|
849 |
} else if (!pPlayer->IsInGame()) { |
|
ds@1952
|
850 |
return pContext->ThrowNativeError("Client %d is not in game", client); |
|
ds@1952
|
851 |
} else if (pPlayer->IsFakeClient()) { |
|
ds@1952
|
852 |
return pContext->ThrowNativeError("Client %d is a bot", client); |
|
ds@1952
|
853 |
} |
|
ds@1952
|
854 |
|
|
ds@1952
|
855 |
INetChannelInfo *pInfo = engine->GetPlayerNetInfo(client); |
|
ds@1952
|
856 |
|
|
ds@1952
|
857 |
return sp_ftoc(pInfo->GetAvgData(params[2])); |
|
ds@1952
|
858 |
} |
|
ds@1952
|
859 |
|
|
ds@1952
|
860 |
static cell_t GetAvgPackets(IPluginContext *pContext, const cell_t *params) |
|
ds@1952
|
861 |
{ |
|
ds@1952
|
862 |
int client = params[1]; |
|
ds@1952
|
863 |
|
|
ds@1952
|
864 |
CPlayer *pPlayer = g_Players.GetPlayerByIndex(client); |
|
ds@1952
|
865 |
if (!pPlayer) |
|
ds@1952
|
866 |
{ |
|
ds@1952
|
867 |
return pContext->ThrowNativeError("Client index %d is invalid", client); |
|
ds@1952
|
868 |
} else if (!pPlayer->IsInGame()) { |
|
ds@1952
|
869 |
return pContext->ThrowNativeError("Client %d is not in game", client); |
|
ds@1952
|
870 |
} else if (pPlayer->IsFakeClient()) { |
|
ds@1952
|
871 |
return pContext->ThrowNativeError("Client %d is a bot", client); |
|
ds@1952
|
872 |
} |
|
ds@1952
|
873 |
|
|
ds@1952
|
874 |
INetChannelInfo *pInfo = engine->GetPlayerNetInfo(client); |
|
ds@1952
|
875 |
|
|
ds@1952
|
876 |
return sp_ftoc(pInfo->GetAvgPackets(params[2])); |
|
ds@1952
|
877 |
} |
|
ds@1952
|
878 |
|
|
ds@1952
|
879 |
static cell_t GetClientOfUserId(IPluginContext *pContext, const cell_t *params) |
|
ds@1952
|
880 |
{ |
|
ds@1952
|
881 |
return g_Players.GetClientOfUserId(params[1]); |
|
ds@1952
|
882 |
} |
|
ds@1952
|
883 |
|
|
ds@1952
|
884 |
static cell_t _ShowActivity(IPluginContext *pContext, |
|
ds@1952
|
885 |
const cell_t *params, |
|
ds@1952
|
886 |
const char *tag, |
|
ds@1952
|
887 |
cell_t fmt_param) |
|
ds@1952
|
888 |
{ |
|
ds@1952
|
889 |
char message[255]; |
|
ds@1952
|
890 |
char buffer[255]; |
|
ds@1952
|
891 |
int value = sm_show_activity.GetInt(); |
|
ds@1952
|
892 |
unsigned int replyto = g_ChatTriggers.GetReplyTo(); |
|
ds@1952
|
893 |
int client = params[1]; |
|
ds@1952
|
894 |
|
|
ds@1952
|
895 |
const char *name = "Console"; |
|
ds@1952
|
896 |
const char *sign = "ADMIN"; |
|
ds@1952
|
897 |
bool display_in_chat = false; |
|
ds@1952
|
898 |
if (client != 0) |
|
ds@1952
|
899 |
{ |
|
ds@1952
|
900 |
CPlayer *pPlayer = g_Players.GetPlayerByIndex(client); |
|
ds@1952
|
901 |
if (!pPlayer || !pPlayer->IsConnected()) |
|
ds@1952
|
902 |
{ |
|
ds@1952
|
903 |
return pContext->ThrowNativeError("Client index %d is invalid", client); |
|
ds@1952
|
904 |
} |
|
ds@1952
|
905 |
name = pPlayer->GetName(); |
|
ds@1952
|
906 |
AdminId id = pPlayer->GetAdminId(); |
|
ds@1952
|
907 |
if (id == INVALID_ADMIN_ID |
|
ds@1952
|
908 |
|| !g_Admins.GetAdminFlag(id, Admin_Generic, Access_Effective)) |
|
ds@1952
|
909 |
{ |
|
ds@1952
|
910 |
sign = "PLAYER"; |
|
ds@1952
|
911 |
} |
|
ds@1952
|
912 |
|
|
ds@1952
|
913 |
/* Display the message to the client? */ |
|
ds@1952
|
914 |
if (replyto == SM_REPLY_CONSOLE) |
|
ds@1952
|
915 |
{ |
|
ds@1952
|
916 |
g_SourceMod.SetGlobalTarget(client); |
|
ds@1952
|
917 |
g_SourceMod.FormatString(buffer, sizeof(buffer), pContext, params, fmt_param); |
|
ds@1952
|
918 |
|
|
ds@1952
|
919 |
if (pContext->GetContext()->n_err != SP_ERROR_NONE) |
|
ds@1952
|
920 |
{ |
|
ds@1952
|
921 |
return 0; |
|
ds@1952
|
922 |
} |
|
ds@1952
|
923 |
|
|
ds@1952
|
924 |
UTIL_Format(message, sizeof(message), "%s%s\n", tag, buffer); |
|
ds@1952
|
925 |
engine->ClientPrintf(pPlayer->GetEdict(), message); |
|
ds@1952
|
926 |
display_in_chat = true; |
|
ds@1952
|
927 |
} |
|
ds@1952
|
928 |
} |
|
ds@1952
|
929 |
else |
|
ds@1952
|
930 |
{ |
|
ds@1952
|
931 |
g_SourceMod.SetGlobalTarget(LANG_SERVER); |
|
ds@1952
|
932 |
g_SourceMod.FormatString(buffer, sizeof(buffer), pContext, params, fmt_param); |
|
ds@1952
|
933 |
|
|
ds@1952
|
934 |
if (pContext->GetContext()->n_err != SP_ERROR_NONE) |
|
ds@1952
|
935 |
{ |
|
ds@1952
|
936 |
return 0; |
|
ds@1952
|
937 |
} |
|
ds@1952
|
938 |
|
|
ds@1952
|
939 |
UTIL_Format(message, sizeof(message), "%s%s\n", tag, buffer); |
|
ds@1952
|
940 |
META_CONPRINT(message); |
|
ds@1952
|
941 |
} |
|
ds@1952
|
942 |
|
|
ds@1952
|
943 |
if (!value) |
|
ds@1952
|
944 |
{ |
|
ds@1952
|
945 |
return 1; |
|
ds@1952
|
946 |
} |
|
ds@1952
|
947 |
|
|
ds@1952
|
948 |
int maxClients = g_Players.GetMaxClients(); |
|
ds@1952
|
949 |
for (int i=1; i<=maxClients; i++) |
|
ds@1952
|
950 |
{ |
|
ds@1952
|
951 |
CPlayer *pPlayer = g_Players.GetPlayerByIndex(i); |
|
ds@1952
|
952 |
if (!pPlayer->IsInGame() |
|
ds@1952
|
953 |
|| pPlayer->IsFakeClient() |
|
ds@1952
|
954 |
|| (display_in_chat && i == client)) |
|
ds@1952
|
955 |
{ |
|
ds@1952
|
956 |
continue; |
|
ds@1952
|
957 |
} |
|
ds@1952
|
958 |
AdminId id = pPlayer->GetAdminId(); |
|
ds@1952
|
959 |
g_SourceMod.SetGlobalTarget(i); |
|
ds@1952
|
960 |
if (id == INVALID_ADMIN_ID |
|
ds@1952
|
961 |
|| !g_Admins.GetAdminFlag(id, Admin_Generic, Access_Effective)) |
|
ds@1952
|
962 |
{ |
|
ds@1952
|
963 |
/* Treat this as a normal user */ |
|
ds@1952
|
964 |
if ((value & 1) || (value & 2)) |
|
ds@1952
|
965 |
{ |
|
ds@1952
|
966 |
const char *newsign = sign; |
|
ds@1952
|
967 |
if ((value & 2) || (i == client)) |
|
ds@1952
|
968 |
{ |
|
ds@1952
|
969 |
newsign = name; |
|
ds@1952
|
970 |
} |
|
ds@1952
|
971 |
g_SourceMod.FormatString(buffer, sizeof(buffer), pContext, params, fmt_param); |
|
ds@1952
|
972 |
|
|
ds@1952
|
973 |
if (pContext->GetContext()->n_err != SP_ERROR_NONE) |
|
ds@1952
|
974 |
{ |
|
ds@1952
|
975 |
return 0; |
|
ds@1952
|
976 |
} |
|
ds@1952
|
977 |
|
|
ds@1952
|
978 |
UTIL_Format(message, sizeof(message), "%s%s: %s", tag, newsign, buffer); |
|
ds@1952
|
979 |
g_HL2.TextMsg(i, HUD_PRINTTALK, message); |
|
ds@1952
|
980 |
} |
|
ds@1952
|
981 |
} |
|
ds@1952
|
982 |
else |
|
ds@1952
|
983 |
{ |
|
ds@1952
|
984 |
/* Treat this as an admin user */ |
|
ds@1952
|
985 |
bool is_root = g_Admins.GetAdminFlag(id, Admin_Root, Access_Effective); |
|
ds@1952
|
986 |
if ((value & 4) |
|
ds@1952
|
987 |
|| (value & 8) |
|
ds@1952
|
988 |
|| ((value & 16) && is_root)) |
|
ds@1952
|
989 |
{ |
|
ds@1952
|
990 |
const char *newsign = sign; |
|
ds@1952
|
991 |
if ((value & 8) || ((value & 16) && is_root) || (i == client)) |
|
ds@1952
|
992 |
{ |
|
ds@1952
|
993 |
newsign = name; |
|
ds@1952
|
994 |
} |
|
ds@1952
|
995 |
g_SourceMod.FormatString(buffer, sizeof(buffer), pContext, params, fmt_param); |
|
ds@1952
|
996 |
|
|
ds@1952
|
997 |
if (pContext->GetContext()->n_err != SP_ERROR_NONE) |
|
ds@1952
|
998 |
{ |
|
ds@1952
|
999 |
return 0; |
|
ds@1952
|
1000 |
} |
|
ds@1952
|
1001 |
|
|
ds@1952
|
1002 |
UTIL_Format(message, sizeof(message), "%s%s: %s", tag, newsign, buffer); |
|
ds@1952
|
1003 |
g_HL2.TextMsg(i, HUD_PRINTTALK, message); |
|
ds@1952
|
1004 |
} |
|
ds@1952
|
1005 |
} |
|
ds@1952
|
1006 |
} |
|
ds@1952
|
1007 |
|
|
ds@1952
|
1008 |
return 1; |
|
ds@1952
|
1009 |
} |
|
ds@1952
|
1010 |
|
|
ds@1952
|
1011 |
static cell_t _ShowActivity2(IPluginContext *pContext, |
|
ds@1952
|
1012 |
const cell_t *params, |
|
ds@1952
|
1013 |
const char *tag, |
|
ds@1952
|
1014 |
cell_t fmt_param) |
|
ds@1952
|
1015 |
{ |
|
ds@1952
|
1016 |
char message[255]; |
|
ds@1952
|
1017 |
char buffer[255]; |
|
ds@1952
|
1018 |
int value = sm_show_activity.GetInt(); |
|
ds@1952
|
1019 |
unsigned int replyto = g_ChatTriggers.GetReplyTo(); |
|
ds@1952
|
1020 |
int client = params[1]; |
|
ds@1952
|
1021 |
|
|
ds@1952
|
1022 |
const char *name = "Console"; |
|
ds@1952
|
1023 |
const char *sign = "ADMIN"; |
|
ds@1952
|
1024 |
if (client != 0) |
|
ds@1952
|
1025 |
{ |
|
ds@1952
|
1026 |
CPlayer *pPlayer = g_Players.GetPlayerByIndex(client); |
|
ds@1952
|
1027 |
if (!pPlayer || !pPlayer->IsConnected()) |
|
ds@1952
|
1028 |
{ |
|
ds@1952
|
1029 |
return pContext->ThrowNativeError("Client index %d is invalid", client); |
|
ds@1952
|
1030 |
} |
|
ds@1952
|
1031 |
name = pPlayer->GetName(); |
|
ds@1952
|
1032 |
AdminId id = pPlayer->GetAdminId(); |
|
ds@1952
|
1033 |
if (id == INVALID_ADMIN_ID |
|
ds@1952
|
1034 |
|| !g_Admins.GetAdminFlag(id, Admin_Generic, Access_Effective)) |
|
ds@1952
|
1035 |
{ |
|
ds@1952
|
1036 |
sign = "PLAYER"; |
|
ds@1952
|
1037 |
} |
|
ds@1952
|
1038 |
|
|
ds@1952
|
1039 |
g_SourceMod.SetGlobalTarget(client); |
|
ds@1952
|
1040 |
g_SourceMod.FormatString(buffer, sizeof(buffer), pContext, params, fmt_param); |
|
ds@1952
|
1041 |
|
|
ds@1952
|
1042 |
if (pContext->GetContext()->n_err != SP_ERROR_NONE) |
|
ds@1952
|
1043 |
{ |
|
ds@1952
|
1044 |
return 0; |
|
ds@1952
|
1045 |
} |
|
ds@1952
|
1046 |
|
|
ds@1952
|
1047 |
/* We don't display directly to the console because the chat text |
|
ds@1952
|
1048 |
* simply gets added to the console, so we don't want it to print |
|
ds@1952
|
1049 |
* twice. |
|
ds@1952
|
1050 |
*/ |
|
ds@1952
|
1051 |
if (replyto == SM_REPLY_CONSOLE) |
|
ds@1952
|
1052 |
{ |
|
ds@1952
|
1053 |
#if 0 |
|
ds@1952
|
1054 |
UTIL_Format(message, sizeof(message), "%s%s\n", tag, buffer); |
|
ds@1952
|
1055 |
engine->ClientPrintf(pPlayer->GetEdict(), message); |
|
ds@1952
|
1056 |
#endif |
|
ds@1952
|
1057 |
UTIL_Format(message, sizeof(message), "%s%s", tag, buffer); |
|
ds@1952
|
1058 |
g_HL2.TextMsg(client, HUD_PRINTTALK, message); |
|
ds@1952
|
1059 |
} |
|
ds@1952
|
1060 |
else |
|
ds@1952
|
1061 |
{ |
|
ds@1952
|
1062 |
UTIL_Format(message, sizeof(message), "%s%s", tag, buffer); |
|
ds@1952
|
1063 |
g_HL2.TextMsg(client, HUD_PRINTTALK, message); |
|
ds@1952
|
1064 |
} |
|
ds@1952
|
1065 |
} |
|
ds@1952
|
1066 |
else |
|
ds@1952
|
1067 |
{ |
|
ds@1952
|
1068 |
g_SourceMod.SetGlobalTarget(LANG_SERVER); |
|
ds@1952
|
1069 |
g_SourceMod.FormatString(buffer, sizeof(buffer), pContext, params, fmt_param); |
|
ds@1952
|
1070 |
|
|
ds@1952
|
1071 |
if (pContext->GetContext()->n_err != SP_ERROR_NONE) |
|
ds@1952
|
1072 |
{ |
|
ds@1952
|
1073 |
return 0; |
|
ds@1952
|
1074 |
} |
|
ds@1952
|
1075 |
|
|
ds@1952
|
1076 |
UTIL_Format(message, sizeof(message), "%s%s\n", tag, buffer); |
|
ds@1952
|
1077 |
META_CONPRINT(message); |
|
ds@1952
|
1078 |
} |
|
ds@1952
|
1079 |
|
|
ds@1952
|
1080 |
if (!value) |
|
ds@1952
|
1081 |
{ |
|
ds@1952
|
1082 |
return 1; |
|
ds@1952
|
1083 |
} |
|
ds@1952
|
1084 |
|
|
ds@1952
|
1085 |
int maxClients = g_Players.GetMaxClients(); |
|
ds@1952
|
1086 |
for (int i=1; i<=maxClients; i++) |
|
ds@1952
|
1087 |
{ |
|
ds@1952
|
1088 |
CPlayer *pPlayer = g_Players.GetPlayerByIndex(i); |
|
ds@1952
|
1089 |
if (!pPlayer->IsInGame() |
|
ds@1952
|
1090 |
|| pPlayer->IsFakeClient() |
|
ds@1952
|
1091 |
|| i == client) |
|
ds@1952
|
1092 |
{ |
|
ds@1952
|
1093 |
continue; |
|
ds@1952
|
1094 |
} |
|
ds@1952
|
1095 |
AdminId id = pPlayer->GetAdminId(); |
|
ds@1952
|
1096 |
g_SourceMod.SetGlobalTarget(i); |
|
ds@1952
|
1097 |
if (id == INVALID_ADMIN_ID |
|
ds@1952
|
1098 |
|| !g_Admins.GetAdminFlag(id, Admin_Generic, Access_Effective)) |
|
ds@1952
|
1099 |
{ |
|
ds@1952
|
1100 |
/* Treat this as a normal user */ |
|
ds@1952
|
1101 |
if ((value & 1) || (value & 2)) |
|
ds@1952
|
1102 |
{ |
|
ds@1952
|
1103 |
const char *newsign = sign; |
|
ds@1952
|
1104 |
if ((value & 2)) |
|
ds@1952
|
1105 |
{ |
|
ds@1952
|
1106 |
newsign = name; |
|
ds@1952
|
1107 |
} |
|
ds@1952
|
1108 |
g_SourceMod.FormatString(buffer, sizeof(buffer), pContext, params, fmt_param); |
|
ds@1952
|
1109 |
|
|
ds@1952
|
1110 |
if (pContext->GetContext()->n_err != SP_ERROR_NONE) |
|
ds@1952
|
1111 |
{ |
|
ds@1952
|
1112 |
return 0; |
|
ds@1952
|
1113 |
} |
|
ds@1952
|
1114 |
|
|
ds@1952
|
1115 |
UTIL_Format(message, sizeof(message), "%s%s: %s", tag, newsign, buffer); |
|
ds@1952
|
1116 |
g_HL2.TextMsg(i, HUD_PRINTTALK, message); |
|
ds@1952
|
1117 |
} |
|
ds@1952
|
1118 |
} |
|
ds@1952
|
1119 |
else |
|
ds@1952
|
1120 |
{ |
|
ds@1952
|
1121 |
/* Treat this as an admin user */ |
|
ds@1952
|
1122 |
bool is_root = g_Admins.GetAdminFlag(id, Admin_Root, Access_Effective); |
|
ds@1952
|
1123 |
if ((value & 4) |
|
ds@1952
|
1124 |
|| (value & 8) |
|
ds@1952
|
1125 |
|| ((value & 16) && is_root)) |
|
ds@1952
|
1126 |
{ |
|
ds@1952
|
1127 |
const char *newsign = sign; |
|
ds@1952
|
1128 |
if ((value & 8) || ((value & 16) && is_root)) |
|
ds@1952
|
1129 |
{ |
|
ds@1952
|
1130 |
newsign = name; |
|
ds@1952
|
1131 |
} |
|
ds@1952
|
1132 |
g_SourceMod.FormatString(buffer, sizeof(buffer), pContext, params, fmt_param); |
|
ds@1952
|
1133 |
|
|
ds@1952
|
1134 |
if (pContext->GetContext()->n_err != SP_ERROR_NONE) |
|
ds@1952
|
1135 |
{ |
|
ds@1952
|
1136 |
return 0; |
|
ds@1952
|
1137 |
} |
|
ds@1952
|
1138 |
|
|
ds@1952
|
1139 |
UTIL_Format(message, sizeof(message), "%s%s: %s", tag, newsign, buffer); |
|
ds@1952
|
1140 |
g_HL2.TextMsg(i, HUD_PRINTTALK, message); |
|
ds@1952
|
1141 |
} |
|
ds@1952
|
1142 |
} |
|
ds@1952
|
1143 |
} |
|
ds@1952
|
1144 |
|
|
ds@1952
|
1145 |
return 1; |
|
ds@1952
|
1146 |
} |
|
ds@1952
|
1147 |
|
|
ds@1952
|
1148 |
static cell_t ShowActivity(IPluginContext *pContext, const cell_t *params) |
|
ds@1952
|
1149 |
{ |
|
ds@1952
|
1150 |
return _ShowActivity(pContext, params, "[SM] ", 2); |
|
ds@1952
|
1151 |
} |
|
ds@1952
|
1152 |
|
|
ds@1952
|
1153 |
static cell_t ShowActivityEx(IPluginContext *pContext, const cell_t *params) |
|
ds@1952
|
1154 |
{ |
|
ds@1952
|
1155 |
char *str; |
|
ds@1952
|
1156 |
pContext->LocalToString(params[2], &str); |
|
ds@1952
|
1157 |
|
|
ds@1952
|
1158 |
return _ShowActivity(pContext, params, str, 3); |
|
ds@1952
|
1159 |
} |
|
ds@1952
|
1160 |
|
|
ds@1952
|
1161 |
static cell_t ShowActivity2(IPluginContext *pContext, const cell_t *params) |
|
ds@1952
|
1162 |
{ |
|
ds@1952
|
1163 |
char *str; |
|
ds@1952
|
1164 |
pContext->LocalToString(params[2], &str); |
|
ds@1952
|
1165 |
|
|
ds@1952
|
1166 |
return _ShowActivity2(pContext, params, str, 3); |
|
ds@1952
|
1167 |
} |
|
ds@1952
|
1168 |
|
|
ds@1952
|
1169 |
static cell_t KickClient(IPluginContext *pContext, const cell_t *params) |
|
ds@1952
|
1170 |
{ |
|
ds@1952
|
1171 |
int client = params[1]; |
|
ds@1952
|
1172 |
|
|
ds@1952
|
1173 |
CPlayer *pPlayer = g_Players.GetPlayerByIndex(client); |
|
ds@1952
|
1174 |
if (!pPlayer) |
|
ds@1952
|
1175 |
{ |
|
ds@1952
|
1176 |
return pContext->ThrowNativeError("Client index %d is invalid", client); |
|
ds@1952
|
1177 |
} else if (!pPlayer->IsConnected()) { |
|
ds@1952
|
1178 |
return pContext->ThrowNativeError("Client %d is not connected", client); |
|
ds@1952
|
1179 |
} |
|
ds@1952
|
1180 |
|
|
ds@1952
|
1181 |
pPlayer->MarkAsBeingKicked(); |
|
ds@1952
|
1182 |
|
|
ds@1952
|
1183 |
if (pPlayer->IsFakeClient()) |
|
ds@1952
|
1184 |
{ |
|
ds@1952
|
1185 |
char kickcmd[40]; |
|
ds@1952
|
1186 |
UTIL_Format(kickcmd, sizeof(kickcmd), "kick %s\n", pPlayer->GetName()); |
|
ds@1952
|
1187 |
|
|
ds@1952
|
1188 |
engine->ServerCommand(kickcmd); |
|
ds@1952
|
1189 |
return 1; |
|
ds@1952
|
1190 |
} |
|
ds@1952
|
1191 |
|
|
ds@1952
|
1192 |
g_SourceMod.SetGlobalTarget(client); |
|
ds@1952
|
1193 |
|
|
ds@1952
|
1194 |
char buffer[256]; |
|
ds@1952
|
1195 |
g_SourceMod.FormatString(buffer, sizeof(buffer), pContext, params, 2); |
|
ds@1952
|
1196 |
|
|
ds@1952
|
1197 |
if (pContext->GetContext()->n_err != SP_ERROR_NONE) |
|
ds@1952
|
1198 |
{ |
|
ds@1952
|
1199 |
return 0; |
|
ds@1952
|
1200 |
} |
|
ds@1952
|
1201 |
|
|
ds@1952
|
1202 |
pPlayer->Kick(buffer); |
|
ds@1952
|
1203 |
|
|
ds@1952
|
1204 |
return 1; |
|
ds@1952
|
1205 |
} |
|
ds@1952
|
1206 |
|
|
ds@1952
|
1207 |
static cell_t ChangeClientTeam(IPluginContext *pContext, const cell_t *params) |
|
ds@1952
|
1208 |
{ |
|
ds@1952
|
1209 |
int client = params[1]; |
|
ds@1952
|
1210 |
|
|
ds@1952
|
1211 |
CPlayer *pPlayer = g_Players.GetPlayerByIndex(client); |
|
ds@1952
|
1212 |
if (!pPlayer) |
|
ds@1952
|
1213 |
{ |
|
ds@1952
|
1214 |
return pContext->ThrowNativeError("Client index %d is invalid", client); |
|
ds@1952
|
1215 |
} |
|
ds@1952
|
1216 |
else if (!pPlayer->IsInGame()) |
|
ds@1952
|
1217 |
{ |
|
ds@1952
|
1218 |
return pContext->ThrowNativeError("Client %d is not in game", client); |
|
ds@1952
|
1219 |
} |
|
ds@1952
|
1220 |
|
|
ds@1952
|
1221 |
IPlayerInfo *pInfo = pPlayer->GetPlayerInfo(); |
|
ds@1952
|
1222 |
if (!pInfo) |
|
ds@1952
|
1223 |
{ |
|
ds@1952
|
1224 |
return pContext->ThrowNativeError("IPlayerInfo not supported by game"); |
|
ds@1952
|
1225 |
} |
|
ds@1952
|
1226 |
|
|
ds@1952
|
1227 |
pInfo->ChangeTeam(params[2]); |
|
ds@1952
|
1228 |
|
|
ds@1952
|
1229 |
return 1; |
|
ds@1952
|
1230 |
} |
|
ds@1952
|
1231 |
|
|
ds@1952
|
1232 |
static cell_t RunAdminCacheChecks(IPluginContext *pContext, const cell_t *params) |
|
ds@1952
|
1233 |
{ |
|
ds@1952
|
1234 |
int client = params[1]; |
|
ds@1952
|
1235 |
|
|
ds@1952
|
1236 |
CPlayer *pPlayer = g_Players.GetPlayerByIndex(client); |
|
ds@1952
|
1237 |
if (!pPlayer) |
|
ds@1952
|
1238 |
{ |
|
ds@1952
|
1239 |
return pContext->ThrowNativeError("Client index %d is invalid", client); |
|
ds@1952
|
1240 |
} |
|
ds@1952
|
1241 |
else if (!pPlayer->IsInGame()) |
|
ds@1952
|
1242 |
{ |
|
ds@1952
|
1243 |
return pContext->ThrowNativeError("Client %d is not in game", client); |
|
ds@1952
|
1244 |
} |
|
ds@1952
|
1245 |
else if (!pPlayer->IsAuthorized()) |
|
ds@1952
|
1246 |
{ |
|
ds@1952
|
1247 |
return pContext->ThrowNativeError("Client %d is not authorized", client); |
|
ds@1952
|
1248 |
} |
|
ds@1952
|
1249 |
|
|
ds@1952
|
1250 |
AdminId id = pPlayer->GetAdminId(); |
|
ds@1952
|
1251 |
pPlayer->DoBasicAdminChecks(); |
|
ds@1952
|
1252 |
|
|
ds@1952
|
1253 |
return (id != pPlayer->GetAdminId()) ? 1 : 0; |
|
ds@1952
|
1254 |
} |
|
ds@1952
|
1255 |
|
|
ds@1952
|
1256 |
static cell_t NotifyPostAdminCheck(IPluginContext *pContext, const cell_t *params) |
|
ds@1952
|
1257 |
{ |
|
ds@1952
|
1258 |
int client = params[1]; |
|
ds@1952
|
1259 |
|
|
ds@1952
|
1260 |
CPlayer *pPlayer = g_Players.GetPlayerByIndex(client); |
|
ds@1952
|
1261 |
if (!pPlayer) |
|
ds@1952
|
1262 |
{ |
|
ds@1952
|
1263 |
return pContext->ThrowNativeError("Client index %d is invalid", client); |
|
ds@1952
|
1264 |
} |
|
ds@1952
|
1265 |
else if (!pPlayer->IsInGame()) { |
|
ds@1952
|
1266 |
return pContext->ThrowNativeError("Client %d is not in game", client); |
|
ds@1952
|
1267 |
} |
|
ds@1952
|
1268 |
else if (!pPlayer->IsAuthorized()) |
|
ds@1952
|
1269 |
{ |
|
ds@1952
|
1270 |
return pContext->ThrowNativeError("Client %d is not authorized", client); |
|
ds@1952
|
1271 |
} |
|
ds@1952
|
1272 |
|
|
ds@1952
|
1273 |
pPlayer->NotifyPostAdminChecks(); |
|
ds@1952
|
1274 |
|
|
ds@1952
|
1275 |
return 1; |
|
ds@1952
|
1276 |
} |
|
ds@1952
|
1277 |
|
|
ds@1952
|
1278 |
static cell_t IsClientInKickQueue(IPluginContext *pContext, const cell_t *params) |
|
ds@1952
|
1279 |
{ |
|
ds@1952
|
1280 |
int client = params[1]; |
|
ds@1952
|
1281 |
|
|
ds@1952
|
1282 |
CPlayer *pPlayer = g_Players.GetPlayerByIndex(client); |
|
ds@1952
|
1283 |
|
|
ds@1952
|
1284 |
if (!pPlayer) |
|
ds@1952
|
1285 |
{ |
|
ds@1952
|
1286 |
return pContext->ThrowNativeError("Client index %d is invalid", client); |
|
ds@1952
|
1287 |
} |
|
ds@1952
|
1288 |
else if (!pPlayer->IsConnected()) |
|
ds@1952
|
1289 |
{ |
|
ds@1952
|
1290 |
return pContext->ThrowNativeError("Client %d is not in game", client); |
|
ds@1952
|
1291 |
} |
|
ds@1952
|
1292 |
|
|
ds@1952
|
1293 |
return pPlayer->IsInKickQueue() ? 1 : 0; |
|
ds@1952
|
1294 |
} |
|
ds@1952
|
1295 |
|
|
ds@1952
|
1296 |
static cell_t ProcessTargetString(IPluginContext *pContext, const cell_t *params) |
|
ds@1952
|
1297 |
{ |
|
ds@1952
|
1298 |
cmd_target_info_t info; |
|
ds@1952
|
1299 |
|
|
ds@1952
|
1300 |
pContext->LocalToString(params[1], (char **)&info.pattern); |
|
ds@1952
|
1301 |
info.admin = params[2]; |
|
ds@1952
|
1302 |
pContext->LocalToPhysAddr(params[3], &info.targets); |
|
ds@1952
|
1303 |
info.max_targets = params[4]; |
|
ds@1952
|
1304 |
info.flags = params[5]; |
|
ds@1952
|
1305 |
pContext->LocalToString(params[6], &info.target_name); |
|
ds@1952
|
1306 |
info.target_name_maxlength = params[7]; |
|
ds@1952
|
1307 |
|
|
ds@1952
|
1308 |
cell_t *tn_is_ml; |
|
ds@1952
|
1309 |
pContext->LocalToPhysAddr(params[8], &tn_is_ml); |
|
ds@1952
|
1310 |
|
|
ds@1952
|
1311 |
g_Players.ProcessCommandTarget(&info); |
|
ds@1952
|
1312 |
|
|
ds@1952
|
1313 |
if (info.target_name_style == COMMAND_TARGETNAME_ML) |
|
ds@1952
|
1314 |
{ |
|
ds@1952
|
1315 |
*tn_is_ml = 1; |
|
ds@1952
|
1316 |
} |
|
ds@1952
|
1317 |
else |
|
ds@1952
|
1318 |
{ |
|
ds@1952
|
1319 |
*tn_is_ml = 0; |
|
ds@1952
|
1320 |
} |
|
ds@1952
|
1321 |
|
|
ds@1952
|
1322 |
if (info.num_targets == 0) |
|
ds@1952
|
1323 |
{ |
|
ds@1952
|
1324 |
return info.reason; |
|
ds@1952
|
1325 |
} |
|
ds@1952
|
1326 |
else |
|
ds@1952
|
1327 |
{ |
|
ds@1952
|
1328 |
return info.num_targets; |
|
ds@1952
|
1329 |
} |
|
ds@1952
|
1330 |
} |
|
ds@1952
|
1331 |
|
|
ds@1952
|
1332 |
REGISTER_NATIVES(playernatives) |
|
ds@1952
|
1333 |
{ |
|
ds@1952
|
1334 |
{"AddUserFlags", AddUserFlags}, |
|
ds@1952
|
1335 |
{"CanUserTarget", CanUserTarget}, |
|
ds@1952
|
1336 |
{"ChangeClientTeam", ChangeClientTeam}, |
|
ds@1952
|
1337 |
{"GetClientAuthString", sm_GetClientAuthStr}, |
|
ds@1952
|
1338 |
{"GetClientCount", sm_GetClientCount}, |
|
ds@1952
|
1339 |
{"GetClientInfo", sm_GetClientInfo}, |
|
ds@1952
|
1340 |
{"GetClientIP", sm_GetClientIP}, |
|
ds@1952
|
1341 |
{"GetClientName", sm_GetClientName}, |
|
ds@1952
|
1342 |
{"GetClientTeam", GetClientTeam}, |
|
ds@1952
|
1343 |
{"GetClientUserId", GetClientUserId}, |
|
ds@1952
|
1344 |
{"GetMaxClients", sm_GetMaxClients}, |
|
ds@1952
|
1345 |
{"GetUserAdmin", GetUserAdmin}, |
|
ds@1952
|
1346 |
{"GetUserFlagBits", GetUserFlagBits}, |
|
ds@1952
|
1347 |
{"IsClientAuthorized", sm_IsClientAuthorized}, |
|
ds@1952
|
1348 |
{"IsClientConnected", sm_IsClientConnected}, |
|
ds@1952
|
1349 |
{"IsFakeClient", sm_IsClientFakeClient}, |
|
ds@1952
|
1350 |
{"IsClientInGame", sm_IsClientInGame}, |
|
ds@1952
|
1351 |
{"IsClientObserver", IsClientObserver}, |
|
ds@1952
|
1352 |
{"RemoveUserFlags", RemoveUserFlags}, |
|
ds@1952
|
1353 |
{"SetUserAdmin", SetUserAdmin}, |
|
ds@1952
|
1354 |
{"SetUserFlagBits", SetUserFlagBits}, |
|
ds@1952
|
1355 |
{"GetClientDeaths", GetDeathCount}, |
|
ds@1952
|
1356 |
{"GetClientFrags", GetFragCount}, |
|
ds@1952
|
1357 |
{"GetClientArmor", GetArmorValue}, |
|
ds@1952
|
1358 |
{"GetClientAbsOrigin", GetAbsOrigin}, |
|
ds@1952
|
1359 |
{"GetClientAbsAngles", GetAbsAngles}, |
|
ds@1952
|
1360 |
{"GetClientMins", GetPlayerMins}, |
|
ds@1952
|
1361 |
{"GetClientMaxs", GetPlayerMaxs}, |
|
ds@1952
|
1362 |
{"GetClientWeapon", GetWeaponName}, |
|
ds@1952
|
1363 |
{"GetClientModel", GetModelName}, |
|
ds@1952
|
1364 |
{"GetClientHealth", GetHealth}, |
|
ds@1952
|
1365 |
{"GetClientTime", GetTimeConnected}, |
|
ds@1952
|
1366 |
{"GetClientDataRate", GetDataRate}, |
|
ds@1952
|
1367 |
{"IsClentTimingOut", IsTimingOut}, |
|
ds@1952
|
1368 |
{"GetClientLatency", GetLatency}, |
|
ds@1952
|
1369 |
{"GetClientAvgLatency", GetAvgLatency}, |
|
ds@1952
|
1370 |
{"GetClientAvgLoss", GetAvgLoss}, |
|
ds@1952
|
1371 |
{"GetClientAvgChoke", GetAvgChoke}, |
|
ds@1952
|
1372 |
{"GetClientAvgData", GetAvgData}, |
|
ds@1952
|
1373 |
{"GetClientAvgPackets", GetAvgPackets}, |
|
ds@1952
|
1374 |
{"GetClientOfUserId", GetClientOfUserId}, |
|
ds@1952
|
1375 |
{"ShowActivity", ShowActivity}, |
|
ds@1952
|
1376 |
{"ShowActivityEx", ShowActivityEx}, |
|
ds@1952
|
1377 |
{"ShowActivity2", ShowActivity2}, |
|
ds@1952
|
1378 |
{"KickClient", KickClient}, |
|
ds@1952
|
1379 |
{"RunAdminCacheChecks", RunAdminCacheChecks}, |
|
ds@1952
|
1380 |
{"NotifyPostAdminCheck", NotifyPostAdminCheck}, |
|
ds@1952
|
1381 |
{"IsClientInKickQueue", IsClientInKickQueue}, |
|
ds@1952
|
1382 |
{"ProcessTargetString", ProcessTargetString}, |
|
ds@1952
|
1383 |
{NULL, NULL} |
|
ds@1952
|
1384 |
}; |
|
ds@1952
|
1385 |
|