1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/core/smn_player.cpp Sun Jul 06 04:49:55 2008 +0000
1.3 @@ -0,0 +1,1524 @@
1.4 +/**
1.5 + * vim: set ts=4 :
1.6 + * =============================================================================
1.7 + * SourceMod
1.8 + * Copyright (C) 2004-2008 AlliedModders LLC. All rights reserved.
1.9 + * =============================================================================
1.10 + *
1.11 + * This program is free software; you can redistribute it and/or modify it under
1.12 + * the terms of the GNU General Public License, version 3.0, as published by the
1.13 + * Free Software Foundation.
1.14 + *
1.15 + * This program is distributed in the hope that it will be useful, but WITHOUT
1.16 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
1.17 + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
1.18 + * details.
1.19 + *
1.20 + * You should have received a copy of the GNU General Public License along with
1.21 + * this program. If not, see <http://www.gnu.org/licenses/>.
1.22 + *
1.23 + * As a special exception, AlliedModders LLC gives you permission to link the
1.24 + * code of this program (as well as its derivative works) to "Half-Life 2," the
1.25 + * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
1.26 + * by the Valve Corporation. You must obey the GNU General Public License in
1.27 + * all respects for all other code used. Additionally, AlliedModders LLC grants
1.28 + * this exception to all derivative works. AlliedModders LLC defines further
1.29 + * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
1.30 + * or <http://www.sourcemod.net/license.php>.
1.31 + *
1.32 + * Version: $Id$
1.33 + */
1.34 +
1.35 +#include "PlayerManager.h"
1.36 +#include "AdminCache.h"
1.37 +#include "sm_stringutil.h"
1.38 +#include "HalfLife2.h"
1.39 +#include "sourcemod.h"
1.40 +#include "ChatTriggers.h"
1.41 +#include <inetchannel.h>
1.42 +#include <iclient.h>
1.43 +
1.44 +ConVar sm_show_activity("sm_show_activity", "13", FCVAR_SPONLY, "Activity display setting (see sourcemod.cfg)");
1.45 +
1.46 +static cell_t sm_GetClientCount(IPluginContext *pCtx, const cell_t *params)
1.47 +{
1.48 + if (params[1])
1.49 + {
1.50 + return g_Players.NumPlayers();
1.51 + }
1.52 +
1.53 + int maxplayers = g_Players.MaxClients();
1.54 + int count = 0;
1.55 + for (int i=1; i<=maxplayers; ++i)
1.56 + {
1.57 + CPlayer *pPlayer = g_Players.GetPlayerByIndex(i);
1.58 + if ((pPlayer->IsConnected()) && !(pPlayer->IsInGame()))
1.59 + {
1.60 + count++;
1.61 + }
1.62 + }
1.63 +
1.64 + return (g_Players.NumPlayers() + count);
1.65 +}
1.66 +
1.67 +static cell_t sm_GetMaxClients(IPluginContext *pCtx, const cell_t *params)
1.68 +{
1.69 + return g_Players.MaxClients();
1.70 +}
1.71 +
1.72 +static cell_t sm_GetClientName(IPluginContext *pCtx, const cell_t *params)
1.73 +{
1.74 + int index = params[1];
1.75 +
1.76 + if (index == 0)
1.77 + {
1.78 + static ConVar *hostname = NULL;
1.79 + if (!hostname)
1.80 + {
1.81 + hostname = icvar->FindVar("hostname");
1.82 + if (!hostname)
1.83 + {
1.84 + return pCtx->ThrowNativeError("Could not find \"hostname\" cvar");
1.85 + }
1.86 + }
1.87 + pCtx->StringToLocalUTF8(params[2], static_cast<size_t>(params[3]), hostname->GetString(), NULL);
1.88 + return 1;
1.89 + }
1.90 +
1.91 + if ((index < 1) || (index > g_Players.GetMaxClients()))
1.92 + {
1.93 + return pCtx->ThrowNativeError("Client index %d is invalid", index);
1.94 + }
1.95 +
1.96 + CPlayer *pPlayer = g_Players.GetPlayerByIndex(index);
1.97 + if (!pPlayer->IsConnected())
1.98 + {
1.99 + return pCtx->ThrowNativeError("Client %d is not connected", index);
1.100 + }
1.101 +
1.102 + pCtx->StringToLocalUTF8(params[2], static_cast<size_t>(params[3]), pPlayer->GetName(), NULL);
1.103 + return 1;
1.104 +}
1.105 +
1.106 +static cell_t sm_GetClientIP(IPluginContext *pCtx, const cell_t *params)
1.107 +{
1.108 + int index = params[1];
1.109 + if ((index < 1) || (index > g_Players.GetMaxClients()))
1.110 + {
1.111 + return pCtx->ThrowNativeError("Client index %d is invalid", index);
1.112 + }
1.113 +
1.114 + CPlayer *pPlayer = g_Players.GetPlayerByIndex(index);
1.115 + if (!pPlayer->IsConnected())
1.116 + {
1.117 + return pCtx->ThrowNativeError("Client %d is not connected", index);
1.118 + }
1.119 +
1.120 + char buf[64], *ptr;
1.121 + strcpy(buf, pPlayer->GetIPAddress());
1.122 +
1.123 + if (params[4] && (ptr = strchr(buf, ':')))
1.124 + {
1.125 + *ptr = '\0';
1.126 + }
1.127 +
1.128 + pCtx->StringToLocal(params[2], static_cast<size_t>(params[3]), buf);
1.129 + return 1;
1.130 +}
1.131 +
1.132 +static cell_t sm_GetClientAuthStr(IPluginContext *pCtx, const cell_t *params)
1.133 +{
1.134 + int index = params[1];
1.135 + if ((index < 1) || (index > g_Players.GetMaxClients()))
1.136 + {
1.137 + return pCtx->ThrowNativeError("Client index %d is invalid", index);
1.138 + }
1.139 +
1.140 + CPlayer *pPlayer = g_Players.GetPlayerByIndex(index);
1.141 + if (!pPlayer->IsConnected())
1.142 + {
1.143 + return pCtx->ThrowNativeError("Client %d is not connected", index);
1.144 + }
1.145 +
1.146 + if (!pPlayer->IsAuthorized())
1.147 + {
1.148 + return 0;
1.149 + }
1.150 +
1.151 + pCtx->StringToLocal(params[2], static_cast<size_t>(params[3]), pPlayer->GetAuthString());
1.152 +
1.153 + return 1;
1.154 +}
1.155 +
1.156 +static cell_t sm_IsClientConnected(IPluginContext *pCtx, const cell_t *params)
1.157 +{
1.158 + int index = params[1];
1.159 + if ((index < 1) || (index > g_Players.GetMaxClients()))
1.160 + {
1.161 + return pCtx->ThrowNativeError("Client index %d is invalid", index);
1.162 + }
1.163 +
1.164 + return (g_Players.GetPlayerByIndex(index)->IsConnected()) ? 1 : 0;
1.165 +}
1.166 +
1.167 +static cell_t sm_IsClientInGame(IPluginContext *pCtx, const cell_t *params)
1.168 +{
1.169 + int index = params[1];
1.170 + if ((index < 1) || (index > g_Players.GetMaxClients()))
1.171 + {
1.172 + return pCtx->ThrowNativeError("Client index %d is invalid", index);
1.173 + }
1.174 +
1.175 + return (g_Players.GetPlayerByIndex(index)->IsInGame()) ? 1 : 0;
1.176 +}
1.177 +
1.178 +static cell_t sm_IsClientAuthorized(IPluginContext *pCtx, const cell_t *params)
1.179 +{
1.180 + int index = params[1];
1.181 + if ((index < 1) || (index > g_Players.GetMaxClients()))
1.182 + {
1.183 + return pCtx->ThrowNativeError("Client index %d is invalid", index);
1.184 + }
1.185 +
1.186 + return (g_Players.GetPlayerByIndex(index)->IsAuthorized()) ? 1 : 0;
1.187 +}
1.188 +
1.189 +static cell_t sm_IsClientFakeClient(IPluginContext *pCtx, const cell_t *params)
1.190 +{
1.191 + int index = params[1];
1.192 + if ((index < 1) || (index > g_Players.GetMaxClients()))
1.193 + {
1.194 + return pCtx->ThrowNativeError("Client index %d is invalid", index);
1.195 + }
1.196 +
1.197 + CPlayer *pPlayer = g_Players.GetPlayerByIndex(index);
1.198 + if (!pPlayer->IsConnected())
1.199 + {
1.200 + return pCtx->ThrowNativeError("Client %d is not connected", index);
1.201 + }
1.202 +
1.203 + return (pPlayer->IsFakeClient()) ? 1 : 0;
1.204 +}
1.205 +
1.206 +static cell_t IsClientObserver(IPluginContext *pContext, const cell_t *params)
1.207 +{
1.208 + int client = params[1];
1.209 +
1.210 + CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
1.211 + if (!pPlayer)
1.212 + {
1.213 + return pContext->ThrowNativeError("Client index %d is invalid", client);
1.214 + } else if (!pPlayer->IsInGame()) {
1.215 + return pContext->ThrowNativeError("Client %d is not in game", client);
1.216 + }
1.217 +
1.218 + IPlayerInfo *pInfo = pPlayer->GetPlayerInfo();
1.219 + if (!pInfo)
1.220 + {
1.221 + return pContext->ThrowNativeError("IPlayerInfo not supported by game");
1.222 + }
1.223 +
1.224 + return pInfo->IsObserver() ? 1 : 0;
1.225 +}
1.226 +
1.227 +static cell_t sm_GetClientInfo(IPluginContext *pContext, const cell_t *params)
1.228 +{
1.229 + int client = params[1];
1.230 + CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
1.231 + if (!pPlayer)
1.232 + {
1.233 + return pContext->ThrowNativeError("Client index %d is invalid", client);
1.234 + }
1.235 + if (!pPlayer->IsConnected())
1.236 + {
1.237 + return pContext->ThrowNativeError("Client %d is not connected", client);
1.238 + }
1.239 +
1.240 + char *key;
1.241 + pContext->LocalToString(params[2], &key);
1.242 +
1.243 + const char *val = engine->GetClientConVarValue(client, key);
1.244 + if (!val)
1.245 + {
1.246 + return false;
1.247 + }
1.248 +
1.249 + pContext->StringToLocalUTF8(params[3], params[4], val, NULL);
1.250 + return 1;
1.251 +}
1.252 +
1.253 +static cell_t SetUserAdmin(IPluginContext *pContext, const cell_t *params)
1.254 +{
1.255 + int client = params[1];
1.256 + CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
1.257 + if (!pPlayer)
1.258 + {
1.259 + return pContext->ThrowNativeError("Client index %d is invalid", client);
1.260 + }
1.261 + if (!pPlayer->IsConnected())
1.262 + {
1.263 + return pContext->ThrowNativeError("Client %d is not connected", client);
1.264 + }
1.265 + if (!g_Admins.IsValidAdmin(params[2]) && params[2] != INVALID_ADMIN_ID)
1.266 + {
1.267 + return pContext->ThrowNativeError("AdminId %x is invalid", params[2]);
1.268 + }
1.269 +
1.270 + pPlayer->SetAdminId(params[2], params[3] ? true : false);
1.271 +
1.272 + return 1;
1.273 +}
1.274 +
1.275 +static cell_t GetUserAdmin(IPluginContext *pContext, const cell_t *params)
1.276 +{
1.277 + int client = params[1];
1.278 + CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
1.279 + if (!pPlayer)
1.280 + {
1.281 + return pContext->ThrowNativeError("Client index %d is invalid", client);
1.282 + }
1.283 + if (!pPlayer->IsConnected())
1.284 + {
1.285 + return pContext->ThrowNativeError("Client %d is not connected", client);
1.286 + }
1.287 +
1.288 + return pPlayer->GetAdminId();
1.289 +}
1.290 +
1.291 +static cell_t AddUserFlags(IPluginContext *pContext, const cell_t *params)
1.292 +{
1.293 + int client = params[1];
1.294 + CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
1.295 + if (!pPlayer)
1.296 + {
1.297 + return pContext->ThrowNativeError("Client index %d is invalid", client);
1.298 + }
1.299 + if (!pPlayer->IsConnected())
1.300 + {
1.301 + return pContext->ThrowNativeError("Client %d is not connected", client);
1.302 + }
1.303 +
1.304 + AdminId id;
1.305 + if ((id=pPlayer->GetAdminId()) == INVALID_ADMIN_ID)
1.306 + {
1.307 + id = g_Admins.CreateAdmin(NULL);
1.308 + pPlayer->SetAdminId(id, true);
1.309 + }
1.310 +
1.311 + cell_t *addr;
1.312 + for (int i=2; i<=params[0]; i++)
1.313 + {
1.314 + pContext->LocalToPhysAddr(params[i], &addr);
1.315 + g_Admins.SetAdminFlag(id, (AdminFlag)*addr, true);
1.316 + }
1.317 +
1.318 + return 1;
1.319 +}
1.320 +
1.321 +static cell_t RemoveUserFlags(IPluginContext *pContext, const cell_t *params)
1.322 +{
1.323 + int client = params[1];
1.324 + CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
1.325 + if (!pPlayer)
1.326 + {
1.327 + return pContext->ThrowNativeError("Client index %d is invalid", client);
1.328 + }
1.329 + if (!pPlayer->IsConnected())
1.330 + {
1.331 + return pContext->ThrowNativeError("Client %d is not connected", client);
1.332 + }
1.333 +
1.334 + AdminId id;
1.335 + if ((id=pPlayer->GetAdminId()) == INVALID_ADMIN_ID)
1.336 + {
1.337 + return 0;
1.338 + }
1.339 +
1.340 + cell_t *addr;
1.341 + for (int i=2; i<=params[0]; i++)
1.342 + {
1.343 + pContext->LocalToPhysAddr(params[i], &addr);
1.344 + g_Admins.SetAdminFlag(id, (AdminFlag)*addr, false);
1.345 + }
1.346 +
1.347 + return 1;
1.348 +}
1.349 +
1.350 +static cell_t SetUserFlagBits(IPluginContext *pContext, const cell_t *params)
1.351 +{
1.352 + int client = params[1];
1.353 + CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
1.354 + if (!pPlayer)
1.355 + {
1.356 + return pContext->ThrowNativeError("Client index %d is invalid", client);
1.357 + }
1.358 + if (!pPlayer->IsConnected())
1.359 + {
1.360 + return pContext->ThrowNativeError("Client %d is not connected", client);
1.361 + }
1.362 +
1.363 + AdminId id;
1.364 + if ((id=pPlayer->GetAdminId()) == INVALID_ADMIN_ID)
1.365 + {
1.366 + id = g_Admins.CreateAdmin(NULL);
1.367 + pPlayer->SetAdminId(id, true);
1.368 + }
1.369 +
1.370 + g_Admins.SetAdminFlags(id, Access_Effective, params[2]);
1.371 +
1.372 + return 1;
1.373 +}
1.374 +
1.375 +static cell_t GetUserFlagBits(IPluginContext *pContext, const cell_t *params)
1.376 +{
1.377 + int client = params[1];
1.378 + CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
1.379 + if (!pPlayer)
1.380 + {
1.381 + return pContext->ThrowNativeError("Client index %d is invalid", client);
1.382 + }
1.383 + if (!pPlayer->IsConnected())
1.384 + {
1.385 + return pContext->ThrowNativeError("Client %d is not connected", client);
1.386 + }
1.387 +
1.388 + AdminId id;
1.389 + if ((id=pPlayer->GetAdminId()) == INVALID_ADMIN_ID)
1.390 + {
1.391 + return 0;
1.392 + }
1.393 +
1.394 + return g_Admins.GetAdminFlags(id, Access_Effective);
1.395 +}
1.396 +
1.397 +static cell_t GetClientUserId(IPluginContext *pContext, const cell_t *params)
1.398 +{
1.399 + int client = params[1];
1.400 + CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
1.401 + if (!pPlayer)
1.402 + {
1.403 + return pContext->ThrowNativeError("Client index %d is invalid", client);
1.404 + }
1.405 + if (!pPlayer->IsConnected())
1.406 + {
1.407 + return pContext->ThrowNativeError("Client %d is not connected", client);
1.408 + }
1.409 +
1.410 + return engine->GetPlayerUserId(pPlayer->GetEdict());
1.411 +}
1.412 +
1.413 +static cell_t CanUserTarget(IPluginContext *pContext, const cell_t *params)
1.414 +{
1.415 + int client = params[1];
1.416 + int target = params[2];
1.417 +
1.418 + if (client == 0)
1.419 + {
1.420 + return 1;
1.421 + }
1.422 +
1.423 + CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
1.424 + if (!pPlayer)
1.425 + {
1.426 + return pContext->ThrowNativeError("Client index %d is invalid", client);
1.427 + } else if (!pPlayer->IsConnected()) {
1.428 + return pContext->ThrowNativeError("Client %d is not connected", client);
1.429 + }
1.430 +
1.431 + CPlayer *pTarget = g_Players.GetPlayerByIndex(target);
1.432 + if (!pTarget)
1.433 + {
1.434 + return pContext->ThrowNativeError("Client index %d is invalid", target);
1.435 + } else if (!pTarget->IsConnected()) {
1.436 + return pContext->ThrowNativeError("Client %d is not connected", target);
1.437 + }
1.438 +
1.439 + return g_Admins.CanAdminTarget(pPlayer->GetAdminId(), pTarget->GetAdminId()) ? 1 : 0;
1.440 +}
1.441 +
1.442 +static cell_t GetClientTeam(IPluginContext *pContext, const cell_t *params)
1.443 +{
1.444 + int client = params[1];
1.445 +
1.446 + CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
1.447 + if (!pPlayer)
1.448 + {
1.449 + return pContext->ThrowNativeError("Client index %d is invalid", client);
1.450 + } else if (!pPlayer->IsInGame()) {
1.451 + return pContext->ThrowNativeError("Client %d is not in game", client);
1.452 + }
1.453 +
1.454 + IPlayerInfo *pInfo = pPlayer->GetPlayerInfo();
1.455 + if (!pInfo)
1.456 + {
1.457 + return pContext->ThrowNativeError("IPlayerInfo not supported by game");
1.458 + }
1.459 +
1.460 + return pInfo->GetTeamIndex();
1.461 +}
1.462 +
1.463 +static cell_t GetFragCount(IPluginContext *pContext, const cell_t *params)
1.464 +{
1.465 + int client = params[1];
1.466 +
1.467 + CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
1.468 + if (!pPlayer)
1.469 + {
1.470 + return pContext->ThrowNativeError("Client index %d is invalid", client);
1.471 + } else if (!pPlayer->IsInGame()) {
1.472 + return pContext->ThrowNativeError("Client %d is not in game", client);
1.473 + }
1.474 +
1.475 + IPlayerInfo *pInfo = pPlayer->GetPlayerInfo();
1.476 + if (!pInfo)
1.477 + {
1.478 + return pContext->ThrowNativeError("IPlayerInfo not supported by game");
1.479 + }
1.480 +
1.481 + return pInfo->GetFragCount();
1.482 +}
1.483 +
1.484 +static cell_t GetDeathCount(IPluginContext *pContext, const cell_t *params)
1.485 +{
1.486 + int client = params[1];
1.487 +
1.488 + CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
1.489 + if (!pPlayer)
1.490 + {
1.491 + return pContext->ThrowNativeError("Client index %d is invalid", client);
1.492 + } else if (!pPlayer->IsInGame()) {
1.493 + return pContext->ThrowNativeError("Client %d is not in game", client);
1.494 + }
1.495 +
1.496 + IPlayerInfo *pInfo = pPlayer->GetPlayerInfo();
1.497 + if (!pInfo)
1.498 + {
1.499 + return pContext->ThrowNativeError("IPlayerInfo not supported by game");
1.500 + }
1.501 +
1.502 + return pInfo->GetDeathCount();
1.503 +}
1.504 +
1.505 +static cell_t GetArmorValue(IPluginContext *pContext, const cell_t *params)
1.506 +{
1.507 + int client = params[1];
1.508 +
1.509 + CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
1.510 + if (!pPlayer)
1.511 + {
1.512 + return pContext->ThrowNativeError("Client index %d is invalid", client);
1.513 + } else if (!pPlayer->IsInGame()) {
1.514 + return pContext->ThrowNativeError("Client %d is not in game", client);
1.515 + }
1.516 +
1.517 + IPlayerInfo *pInfo = pPlayer->GetPlayerInfo();
1.518 + if (!pInfo)
1.519 + {
1.520 + return pContext->ThrowNativeError("IPlayerInfo not supported by game");
1.521 + }
1.522 +
1.523 + return pInfo->GetArmorValue();
1.524 +}
1.525 +
1.526 +static cell_t GetAbsOrigin(IPluginContext *pContext, const cell_t *params)
1.527 +{
1.528 + int client = params[1];
1.529 +
1.530 + CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
1.531 + if (!pPlayer)
1.532 + {
1.533 + return pContext->ThrowNativeError("Client index %d is invalid", client);
1.534 + } else if (!pPlayer->IsInGame()) {
1.535 + return pContext->ThrowNativeError("Client %d is not in game", client);
1.536 + }
1.537 +
1.538 + IPlayerInfo *pInfo = pPlayer->GetPlayerInfo();
1.539 + if (!pInfo)
1.540 + {
1.541 + return pContext->ThrowNativeError("IPlayerInfo not supported by game");
1.542 + }
1.543 +
1.544 + cell_t *pVec;
1.545 + pContext->LocalToPhysAddr(params[2], &pVec);
1.546 +
1.547 + Vector vec = pInfo->GetAbsOrigin();
1.548 + pVec[0] = sp_ftoc(vec.x);
1.549 + pVec[1] = sp_ftoc(vec.y);
1.550 + pVec[2] = sp_ftoc(vec.z);
1.551 +
1.552 + return 1;
1.553 +}
1.554 +
1.555 +static cell_t GetAbsAngles(IPluginContext *pContext, const cell_t *params)
1.556 +{
1.557 + int client = params[1];
1.558 +
1.559 + CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
1.560 + if (!pPlayer)
1.561 + {
1.562 + return pContext->ThrowNativeError("Client index %d is invalid", client);
1.563 + } else if (!pPlayer->IsInGame()) {
1.564 + return pContext->ThrowNativeError("Client %d is not in game", client);
1.565 + }
1.566 +
1.567 + IPlayerInfo *pInfo = pPlayer->GetPlayerInfo();
1.568 + if (!pInfo)
1.569 + {
1.570 + return pContext->ThrowNativeError("IPlayerInfo not supported by game");
1.571 + }
1.572 +
1.573 + cell_t *pAng;
1.574 + pContext->LocalToPhysAddr(params[2], &pAng);
1.575 +
1.576 + QAngle ang = pInfo->GetAbsAngles();
1.577 + pAng[0] = sp_ftoc(ang.x);
1.578 + pAng[1] = sp_ftoc(ang.y);
1.579 + pAng[2] = sp_ftoc(ang.z);
1.580 +
1.581 + return 1;
1.582 +}
1.583 +
1.584 +static cell_t GetPlayerMins(IPluginContext *pContext, const cell_t *params)
1.585 +{
1.586 + int client = params[1];
1.587 +
1.588 + CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
1.589 + if (!pPlayer)
1.590 + {
1.591 + return pContext->ThrowNativeError("Client index %d is invalid", client);
1.592 + } else if (!pPlayer->IsInGame()) {
1.593 + return pContext->ThrowNativeError("Client %d is not in game", client);
1.594 + }
1.595 +
1.596 + IPlayerInfo *pInfo = pPlayer->GetPlayerInfo();
1.597 + if (!pInfo)
1.598 + {
1.599 + return pContext->ThrowNativeError("IPlayerInfo not supported by game");
1.600 + }
1.601 +
1.602 + cell_t *pVec;
1.603 + pContext->LocalToPhysAddr(params[2], &pVec);
1.604 +
1.605 + Vector vec = pInfo->GetPlayerMins();
1.606 + pVec[0] = sp_ftoc(vec.x);
1.607 + pVec[1] = sp_ftoc(vec.y);
1.608 + pVec[2] = sp_ftoc(vec.z);
1.609 +
1.610 + return 1;
1.611 +}
1.612 +
1.613 +static cell_t GetPlayerMaxs(IPluginContext *pContext, const cell_t *params)
1.614 +{
1.615 + int client = params[1];
1.616 +
1.617 + CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
1.618 + if (!pPlayer)
1.619 + {
1.620 + return pContext->ThrowNativeError("Client index %d is invalid", client);
1.621 + } else if (!pPlayer->IsInGame()) {
1.622 + return pContext->ThrowNativeError("Client %d is not in game", client);
1.623 + }
1.624 +
1.625 + IPlayerInfo *pInfo = pPlayer->GetPlayerInfo();
1.626 + if (!pInfo)
1.627 + {
1.628 + return pContext->ThrowNativeError("IPlayerInfo not supported by game");
1.629 + }
1.630 +
1.631 + cell_t *pVec;
1.632 + pContext->LocalToPhysAddr(params[2], &pVec);
1.633 +
1.634 + Vector vec = pInfo->GetPlayerMaxs();
1.635 + pVec[0] = sp_ftoc(vec.x);
1.636 + pVec[1] = sp_ftoc(vec.y);
1.637 + pVec[2] = sp_ftoc(vec.z);
1.638 +
1.639 + return 1;
1.640 +}
1.641 +
1.642 +static cell_t GetWeaponName(IPluginContext *pContext, const cell_t *params)
1.643 +{
1.644 + int client = params[1];
1.645 +
1.646 + CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
1.647 + if (!pPlayer)
1.648 + {
1.649 + return pContext->ThrowNativeError("Client index %d is invalid", client);
1.650 + } else if (!pPlayer->IsInGame()) {
1.651 + return pContext->ThrowNativeError("Client %d is not in game", client);
1.652 + }
1.653 +
1.654 + IPlayerInfo *pInfo = pPlayer->GetPlayerInfo();
1.655 + if (!pInfo)
1.656 + {
1.657 + return pContext->ThrowNativeError("IPlayerInfo not supported by game");
1.658 + }
1.659 +
1.660 + const char *weapon = pInfo->GetWeaponName();
1.661 + pContext->StringToLocalUTF8(params[2], static_cast<size_t>(params[3]), weapon ? weapon : "", NULL);
1.662 +
1.663 + return 1;
1.664 +}
1.665 +
1.666 +static cell_t GetModelName(IPluginContext *pContext, const cell_t *params)
1.667 +{
1.668 + int client = params[1];
1.669 +
1.670 + CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
1.671 + if (!pPlayer)
1.672 + {
1.673 + return pContext->ThrowNativeError("Client index %d is invalid", client);
1.674 + } else if (!pPlayer->IsInGame()) {
1.675 + return pContext->ThrowNativeError("Client %d is not in game", client);
1.676 + }
1.677 +
1.678 + IPlayerInfo *pInfo = pPlayer->GetPlayerInfo();
1.679 + if (!pInfo)
1.680 + {
1.681 + return pContext->ThrowNativeError("IPlayerInfo not supported by game");
1.682 + }
1.683 +
1.684 + const char *model = pInfo->GetModelName();
1.685 + pContext->StringToLocalUTF8(params[2], static_cast<size_t>(params[3]), model ? model : "", NULL);
1.686 +
1.687 + return 1;
1.688 +}
1.689 +
1.690 +static cell_t GetHealth(IPluginContext *pContext, const cell_t *params)
1.691 +{
1.692 + int client = params[1];
1.693 +
1.694 + CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
1.695 + if (!pPlayer)
1.696 + {
1.697 + return pContext->ThrowNativeError("Client index %d is invalid", client);
1.698 + } else if (!pPlayer->IsInGame()) {
1.699 + return pContext->ThrowNativeError("Client %d is not in game", client);
1.700 + }
1.701 +
1.702 + IPlayerInfo *pInfo = pPlayer->GetPlayerInfo();
1.703 + if (!pInfo)
1.704 + {
1.705 + return pContext->ThrowNativeError("IPlayerInfo not supported by game");
1.706 + }
1.707 +
1.708 + return pInfo->GetHealth();
1.709 +}
1.710 +
1.711 +static cell_t GetTimeConnected(IPluginContext *pContext, const cell_t *params)
1.712 +{
1.713 + int client = params[1];
1.714 +
1.715 + CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
1.716 + if (!pPlayer)
1.717 + {
1.718 + return pContext->ThrowNativeError("Client index %d is invalid", client);
1.719 + } else if (!pPlayer->IsInGame()) {
1.720 + return pContext->ThrowNativeError("Client %d is not in game", client);
1.721 + } else if (pPlayer->IsFakeClient()) {
1.722 + return pContext->ThrowNativeError("Client %d is a bot", client);
1.723 + }
1.724 +
1.725 + INetChannelInfo *pInfo = engine->GetPlayerNetInfo(client);
1.726 +
1.727 + return sp_ftoc(pInfo->GetTimeConnected());
1.728 +}
1.729 +
1.730 +static cell_t GetDataRate(IPluginContext *pContext, const cell_t *params)
1.731 +{
1.732 + int client = params[1];
1.733 +
1.734 + CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
1.735 + if (!pPlayer)
1.736 + {
1.737 + return pContext->ThrowNativeError("Client index %d is invalid", client);
1.738 + } else if (!pPlayer->IsInGame()) {
1.739 + return pContext->ThrowNativeError("Client %d is not in game", client);
1.740 + } else if (pPlayer->IsFakeClient()) {
1.741 + return pContext->ThrowNativeError("Client %d is a bot", client);
1.742 + }
1.743 +
1.744 + INetChannelInfo *pInfo = engine->GetPlayerNetInfo(client);
1.745 +
1.746 + return pInfo->GetDataRate();
1.747 +}
1.748 +
1.749 +static cell_t IsTimingOut(IPluginContext *pContext, const cell_t *params)
1.750 +{
1.751 + int client = params[1];
1.752 +
1.753 + CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
1.754 + if (!pPlayer)
1.755 + {
1.756 + return pContext->ThrowNativeError("Client index %d is invalid", client);
1.757 + } else if (!pPlayer->IsInGame()) {
1.758 + return pContext->ThrowNativeError("Client %d is not in game", client);
1.759 + } else if (pPlayer->IsFakeClient()) {
1.760 + return pContext->ThrowNativeError("Client %d is a bot", client);
1.761 + }
1.762 +
1.763 + INetChannelInfo *pInfo = engine->GetPlayerNetInfo(client);
1.764 +
1.765 + return pInfo->IsTimingOut() ? 1 : 0;
1.766 +}
1.767 +
1.768 +static cell_t GetLatency(IPluginContext *pContext, const cell_t *params)
1.769 +{
1.770 + int client = params[1];
1.771 + float value;
1.772 +
1.773 + CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
1.774 + if (!pPlayer)
1.775 + {
1.776 + return pContext->ThrowNativeError("Client index %d is invalid", client);
1.777 + }
1.778 + else if (!pPlayer->IsInGame())
1.779 + {
1.780 + return pContext->ThrowNativeError("Client %d is not in game", client);
1.781 + }
1.782 + else if (pPlayer->IsFakeClient())
1.783 + {
1.784 + return pContext->ThrowNativeError("Client %d is a bot", client);
1.785 + }
1.786 +
1.787 + INetChannelInfo *pInfo = engine->GetPlayerNetInfo(client);
1.788 +
1.789 + if (params[2] == MAX_FLOWS)
1.790 + {
1.791 + value = pInfo->GetLatency(FLOW_INCOMING) + pInfo->GetLatency(FLOW_OUTGOING);
1.792 + }
1.793 + else
1.794 + {
1.795 + value = pInfo->GetLatency(params[2]);
1.796 + }
1.797 +
1.798 + return sp_ftoc(value);
1.799 +}
1.800 +
1.801 +static cell_t GetAvgLatency(IPluginContext *pContext, const cell_t *params)
1.802 +{
1.803 + int client = params[1];
1.804 + float value;
1.805 +
1.806 + CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
1.807 + if (!pPlayer)
1.808 + {
1.809 + return pContext->ThrowNativeError("Client index %d is invalid", client);
1.810 + }
1.811 + else if (!pPlayer->IsInGame())
1.812 + {
1.813 + return pContext->ThrowNativeError("Client %d is not in game", client);
1.814 + }
1.815 + else if (pPlayer->IsFakeClient())
1.816 + {
1.817 + return pContext->ThrowNativeError("Client %d is a bot", client);
1.818 + }
1.819 +
1.820 + INetChannelInfo *pInfo = engine->GetPlayerNetInfo(client);
1.821 +
1.822 + if (params[2] == MAX_FLOWS)
1.823 + {
1.824 + value = pInfo->GetAvgLatency(FLOW_INCOMING) + pInfo->GetAvgLatency(FLOW_OUTGOING);
1.825 + }
1.826 + else
1.827 + {
1.828 + value = pInfo->GetAvgLatency(params[2]);
1.829 + }
1.830 +
1.831 + return sp_ftoc(value);
1.832 +}
1.833 +
1.834 +static cell_t GetAvgLoss(IPluginContext *pContext, const cell_t *params)
1.835 +{
1.836 + int client = params[1];
1.837 + float value;
1.838 +
1.839 + CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
1.840 + if (!pPlayer)
1.841 + {
1.842 + return pContext->ThrowNativeError("Client index %d is invalid", client);
1.843 + }
1.844 + else if (!pPlayer->IsInGame())
1.845 + {
1.846 + return pContext->ThrowNativeError("Client %d is not in game", client);
1.847 + }
1.848 + else if (pPlayer->IsFakeClient())
1.849 + {
1.850 + return pContext->ThrowNativeError("Client %d is a bot", client);
1.851 + }
1.852 +
1.853 + INetChannelInfo *pInfo = engine->GetPlayerNetInfo(client);
1.854 +
1.855 + if (params[2] == MAX_FLOWS)
1.856 + {
1.857 + value = pInfo->GetAvgLoss(FLOW_INCOMING) + pInfo->GetAvgLoss(FLOW_OUTGOING);
1.858 + }
1.859 + else
1.860 + {
1.861 + value = pInfo->GetAvgLoss(params[2]);
1.862 + }
1.863 +
1.864 + return sp_ftoc(value);
1.865 +}
1.866 +
1.867 +static cell_t GetAvgChoke(IPluginContext *pContext, const cell_t *params)
1.868 +{
1.869 + int client = params[1];
1.870 + float value;
1.871 +
1.872 + CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
1.873 + if (!pPlayer)
1.874 + {
1.875 + return pContext->ThrowNativeError("Client index %d is invalid", client);
1.876 + }
1.877 + else if (!pPlayer->IsInGame())
1.878 + {
1.879 + return pContext->ThrowNativeError("Client %d is not in game", client);
1.880 + }
1.881 + else if (pPlayer->IsFakeClient())
1.882 + {
1.883 + return pContext->ThrowNativeError("Client %d is a bot", client);
1.884 + }
1.885 +
1.886 + INetChannelInfo *pInfo = engine->GetPlayerNetInfo(client);
1.887 +
1.888 + if (params[2] == MAX_FLOWS)
1.889 + {
1.890 + value = pInfo->GetAvgChoke(FLOW_INCOMING) + pInfo->GetAvgChoke(FLOW_OUTGOING);
1.891 + }
1.892 + else
1.893 + {
1.894 + value = pInfo->GetAvgChoke(params[2]);
1.895 + }
1.896 +
1.897 + return sp_ftoc(value);
1.898 +}
1.899 +
1.900 +static cell_t GetAvgData(IPluginContext *pContext, const cell_t *params)
1.901 +{
1.902 + int client = params[1];
1.903 + float value;
1.904 +
1.905 + CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
1.906 + if (!pPlayer)
1.907 + {
1.908 + return pContext->ThrowNativeError("Client index %d is invalid", client);
1.909 + }
1.910 + else if (!pPlayer->IsInGame())
1.911 + {
1.912 + return pContext->ThrowNativeError("Client %d is not in game", client);
1.913 + }
1.914 + else if (pPlayer->IsFakeClient())
1.915 + {
1.916 + return pContext->ThrowNativeError("Client %d is a bot", client);
1.917 + }
1.918 +
1.919 + INetChannelInfo *pInfo = engine->GetPlayerNetInfo(client);
1.920 +
1.921 + if (params[2] == MAX_FLOWS)
1.922 + {
1.923 + value = pInfo->GetAvgData(FLOW_INCOMING) + pInfo->GetAvgData(FLOW_OUTGOING);
1.924 + }
1.925 + else
1.926 + {
1.927 + value = pInfo->GetAvgData(params[2]);
1.928 + }
1.929 +
1.930 + return sp_ftoc(value);
1.931 +}
1.932 +
1.933 +static cell_t GetAvgPackets(IPluginContext *pContext, const cell_t *params)
1.934 +{
1.935 + int client = params[1];
1.936 + float value;
1.937 +
1.938 + CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
1.939 + if (!pPlayer)
1.940 + {
1.941 + return pContext->ThrowNativeError("Client index %d is invalid", client);
1.942 + }
1.943 + else if (!pPlayer->IsInGame())
1.944 + {
1.945 + return pContext->ThrowNativeError("Client %d is not in game", client);
1.946 + }
1.947 + else if (pPlayer->IsFakeClient())
1.948 + {
1.949 + return pContext->ThrowNativeError("Client %d is a bot", client);
1.950 + }
1.951 +
1.952 + INetChannelInfo *pInfo = engine->GetPlayerNetInfo(client);
1.953 +
1.954 + if (params[2] == MAX_FLOWS)
1.955 + {
1.956 + value = pInfo->GetAvgPackets(FLOW_INCOMING) + pInfo->GetAvgPackets(FLOW_OUTGOING);
1.957 + }
1.958 + else
1.959 + {
1.960 + value = pInfo->GetAvgPackets(params[2]);
1.961 + }
1.962 +
1.963 + return sp_ftoc(value);
1.964 +}
1.965 +
1.966 +static cell_t GetClientOfUserId(IPluginContext *pContext, const cell_t *params)
1.967 +{
1.968 + return g_Players.GetClientOfUserId(params[1]);
1.969 +}
1.970 +
1.971 +static cell_t _ShowActivity(IPluginContext *pContext,
1.972 + const cell_t *params,
1.973 + const char *tag,
1.974 + cell_t fmt_param)
1.975 +{
1.976 + char message[255];
1.977 + char buffer[255];
1.978 + int value = sm_show_activity.GetInt();
1.979 + unsigned int replyto = g_ChatTriggers.GetReplyTo();
1.980 + int client = params[1];
1.981 +
1.982 + const char *name = "Console";
1.983 + const char *sign = "ADMIN";
1.984 + bool display_in_chat = false;
1.985 + if (client != 0)
1.986 + {
1.987 + CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
1.988 + if (!pPlayer || !pPlayer->IsConnected())
1.989 + {
1.990 + return pContext->ThrowNativeError("Client index %d is invalid", client);
1.991 + }
1.992 + name = pPlayer->GetName();
1.993 + AdminId id = pPlayer->GetAdminId();
1.994 + if (id == INVALID_ADMIN_ID
1.995 + || !g_Admins.GetAdminFlag(id, Admin_Generic, Access_Effective))
1.996 + {
1.997 + sign = "PLAYER";
1.998 + }
1.999 +
1.1000 + /* Display the message to the client? */
1.1001 + if (replyto == SM_REPLY_CONSOLE)
1.1002 + {
1.1003 + g_SourceMod.SetGlobalTarget(client);
1.1004 + g_SourceMod.FormatString(buffer, sizeof(buffer), pContext, params, fmt_param);
1.1005 +
1.1006 + if (pContext->GetContext()->n_err != SP_ERROR_NONE)
1.1007 + {
1.1008 + return 0;
1.1009 + }
1.1010 +
1.1011 + UTIL_Format(message, sizeof(message), "%s%s\n", tag, buffer);
1.1012 + engine->ClientPrintf(pPlayer->GetEdict(), message);
1.1013 + display_in_chat = true;
1.1014 + }
1.1015 + }
1.1016 + else
1.1017 + {
1.1018 + g_SourceMod.SetGlobalTarget(SOURCEMOD_SERVER_LANGUAGE);
1.1019 + g_SourceMod.FormatString(buffer, sizeof(buffer), pContext, params, fmt_param);
1.1020 +
1.1021 + if (pContext->GetContext()->n_err != SP_ERROR_NONE)
1.1022 + {
1.1023 + return 0;
1.1024 + }
1.1025 +
1.1026 + UTIL_Format(message, sizeof(message), "%s%s\n", tag, buffer);
1.1027 + META_CONPRINT(message);
1.1028 + }
1.1029 +
1.1030 + if (!value)
1.1031 + {
1.1032 + return 1;
1.1033 + }
1.1034 +
1.1035 + int maxClients = g_Players.GetMaxClients();
1.1036 + for (int i=1; i<=maxClients; i++)
1.1037 + {
1.1038 + CPlayer *pPlayer = g_Players.GetPlayerByIndex(i);
1.1039 + if (!pPlayer->IsInGame()
1.1040 + || pPlayer->IsFakeClient()
1.1041 + || (display_in_chat && i == client))
1.1042 + {
1.1043 + continue;
1.1044 + }
1.1045 + AdminId id = pPlayer->GetAdminId();
1.1046 + g_SourceMod.SetGlobalTarget(i);
1.1047 + if (id == INVALID_ADMIN_ID
1.1048 + || !g_Admins.GetAdminFlag(id, Admin_Generic, Access_Effective))
1.1049 + {
1.1050 + /* Treat this as a normal user */
1.1051 + if ((value & 1) || (value & 2))
1.1052 + {
1.1053 + const char *newsign = sign;
1.1054 + if ((value & 2) || (i == client))
1.1055 + {
1.1056 + newsign = name;
1.1057 + }
1.1058 + g_SourceMod.FormatString(buffer, sizeof(buffer), pContext, params, fmt_param);
1.1059 +
1.1060 + if (pContext->GetContext()->n_err != SP_ERROR_NONE)
1.1061 + {
1.1062 + return 0;
1.1063 + }
1.1064 +
1.1065 + UTIL_Format(message, sizeof(message), "%s%s: %s", tag, newsign, buffer);
1.1066 + g_HL2.TextMsg(i, HUD_PRINTTALK, message);
1.1067 + }
1.1068 + }
1.1069 + else
1.1070 + {
1.1071 + /* Treat this as an admin user */
1.1072 + bool is_root = g_Admins.GetAdminFlag(id, Admin_Root, Access_Effective);
1.1073 + if ((value & 4)
1.1074 + || (value & 8)
1.1075 + || ((value & 16) && is_root))
1.1076 + {
1.1077 + const char *newsign = sign;
1.1078 + if ((value & 8) || ((value & 16) && is_root) || (i == client))
1.1079 + {
1.1080 + newsign = name;
1.1081 + }
1.1082 + g_SourceMod.FormatString(buffer, sizeof(buffer), pContext, params, fmt_param);
1.1083 +
1.1084 + if (pContext->GetContext()->n_err != SP_ERROR_NONE)
1.1085 + {
1.1086 + return 0;
1.1087 + }
1.1088 +
1.1089 + UTIL_Format(message, sizeof(message), "%s%s: %s", tag, newsign, buffer);
1.1090 + g_HL2.TextMsg(i, HUD_PRINTTALK, message);
1.1091 + }
1.1092 + }
1.1093 + }
1.1094 +
1.1095 + return 1;
1.1096 +}
1.1097 +
1.1098 +static cell_t _ShowActivity2(IPluginContext *pContext,
1.1099 + const cell_t *params,
1.1100 + const char *tag,
1.1101 + cell_t fmt_param)
1.1102 +{
1.1103 + char message[255];
1.1104 + char buffer[255];
1.1105 + int value = sm_show_activity.GetInt();
1.1106 + unsigned int replyto = g_ChatTriggers.GetReplyTo();
1.1107 + int client = params[1];
1.1108 +
1.1109 + const char *name = "Console";
1.1110 + const char *sign = "ADMIN";
1.1111 + if (client != 0)
1.1112 + {
1.1113 + CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
1.1114 + if (!pPlayer || !pPlayer->IsConnected())
1.1115 + {
1.1116 + return pContext->ThrowNativeError("Client index %d is invalid", client);
1.1117 + }
1.1118 + name = pPlayer->GetName();
1.1119 + AdminId id = pPlayer->GetAdminId();
1.1120 + if (id == INVALID_ADMIN_ID
1.1121 + || !g_Admins.GetAdminFlag(id, Admin_Generic, Access_Effective))
1.1122 + {
1.1123 + sign = "PLAYER";
1.1124 + }
1.1125 +
1.1126 + g_SourceMod.SetGlobalTarget(client);
1.1127 + g_SourceMod.FormatString(buffer, sizeof(buffer), pContext, params, fmt_param);
1.1128 +
1.1129 + if (pContext->GetContext()->n_err != SP_ERROR_NONE)
1.1130 + {
1.1131 + return 0;
1.1132 + }
1.1133 +
1.1134 + /* We don't display directly to the console because the chat text
1.1135 + * simply gets added to the console, so we don't want it to print
1.1136 + * twice.
1.1137 + */
1.1138 + if (replyto == SM_REPLY_CONSOLE)
1.1139 + {
1.1140 +#if 0
1.1141 + UTIL_Format(message, sizeof(message), "%s%s\n", tag, buffer);
1.1142 + engine->ClientPrintf(pPlayer->GetEdict(), message);
1.1143 +#endif
1.1144 + UTIL_Format(message, sizeof(message), "%s%s", tag, buffer);
1.1145 + g_HL2.TextMsg(client, HUD_PRINTTALK, message);
1.1146 + }
1.1147 + else
1.1148 + {
1.1149 + UTIL_Format(message, sizeof(message), "%s%s", tag, buffer);
1.1150 + g_HL2.TextMsg(client, HUD_PRINTTALK, message);
1.1151 + }
1.1152 + }
1.1153 + else
1.1154 + {
1.1155 + g_SourceMod.SetGlobalTarget(SOURCEMOD_SERVER_LANGUAGE);
1.1156 + g_SourceMod.FormatString(buffer, sizeof(buffer), pContext, params, fmt_param);
1.1157 +
1.1158 + if (pContext->GetContext()->n_err != SP_ERROR_NONE)
1.1159 + {
1.1160 + return 0;
1.1161 + }
1.1162 +
1.1163 + UTIL_Format(message, sizeof(message), "%s%s\n", tag, buffer);
1.1164 + META_CONPRINT(message);
1.1165 + }
1.1166 +
1.1167 + if (!value)
1.1168 + {
1.1169 + return 1;
1.1170 + }
1.1171 +
1.1172 + int maxClients = g_Players.GetMaxClients();
1.1173 + for (int i=1; i<=maxClients; i++)
1.1174 + {
1.1175 + CPlayer *pPlayer = g_Players.GetPlayerByIndex(i);
1.1176 + if (!pPlayer->IsInGame()
1.1177 + || pPlayer->IsFakeClient()
1.1178 + || i == client)
1.1179 + {
1.1180 + continue;
1.1181 + }
1.1182 + AdminId id = pPlayer->GetAdminId();
1.1183 + g_SourceMod.SetGlobalTarget(i);
1.1184 + if (id == INVALID_ADMIN_ID
1.1185 + || !g_Admins.GetAdminFlag(id, Admin_Generic, Access_Effective))
1.1186 + {
1.1187 + /* Treat this as a normal user */
1.1188 + if ((value & 1) || (value & 2))
1.1189 + {
1.1190 + const char *newsign = sign;
1.1191 + if ((value & 2))
1.1192 + {
1.1193 + newsign = name;
1.1194 + }
1.1195 + g_SourceMod.FormatString(buffer, sizeof(buffer), pContext, params, fmt_param);
1.1196 +
1.1197 + if (pContext->GetContext()->n_err != SP_ERROR_NONE)
1.1198 + {
1.1199 + return 0;
1.1200 + }
1.1201 +
1.1202 + UTIL_Format(message, sizeof(message), "%s%s: %s", tag, newsign, buffer);
1.1203 + g_HL2.TextMsg(i, HUD_PRINTTALK, message);
1.1204 + }
1.1205 + }
1.1206 + else
1.1207 + {
1.1208 + /* Treat this as an admin user */
1.1209 + bool is_root = g_Admins.GetAdminFlag(id, Admin_Root, Access_Effective);
1.1210 + if ((value & 4)
1.1211 + || (value & 8)
1.1212 + || ((value & 16) && is_root))
1.1213 + {
1.1214 + const char *newsign = sign;
1.1215 + if ((value & 8) || ((value & 16) && is_root))
1.1216 + {
1.1217 + newsign = name;
1.1218 + }
1.1219 + g_SourceMod.FormatString(buffer, sizeof(buffer), pContext, params, fmt_param);
1.1220 +
1.1221 + if (pContext->GetContext()->n_err != SP_ERROR_NONE)
1.1222 + {
1.1223 + return 0;
1.1224 + }
1.1225 +
1.1226 + UTIL_Format(message, sizeof(message), "%s%s: %s", tag, newsign, buffer);
1.1227 + g_HL2.TextMsg(i, HUD_PRINTTALK, message);
1.1228 + }
1.1229 + }
1.1230 + }
1.1231 +
1.1232 + return 1;
1.1233 +}
1.1234 +
1.1235 +static cell_t ShowActivity(IPluginContext *pContext, const cell_t *params)
1.1236 +{
1.1237 + return _ShowActivity(pContext, params, "[SM] ", 2);
1.1238 +}
1.1239 +
1.1240 +static cell_t ShowActivityEx(IPluginContext *pContext, const cell_t *params)
1.1241 +{
1.1242 + char *str;
1.1243 + pContext->LocalToString(params[2], &str);
1.1244 +
1.1245 + return _ShowActivity(pContext, params, str, 3);
1.1246 +}
1.1247 +
1.1248 +static cell_t ShowActivity2(IPluginContext *pContext, const cell_t *params)
1.1249 +{
1.1250 + char *str;
1.1251 + pContext->LocalToString(params[2], &str);
1.1252 +
1.1253 + return _ShowActivity2(pContext, params, str, 3);
1.1254 +}
1.1255 +
1.1256 +static cell_t KickClient(IPluginContext *pContext, const cell_t *params)
1.1257 +{
1.1258 + int client = params[1];
1.1259 +
1.1260 + CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
1.1261 + if (!pPlayer)
1.1262 + {
1.1263 + return pContext->ThrowNativeError("Client index %d is invalid", client);
1.1264 + }
1.1265 + else if (!pPlayer->IsConnected())
1.1266 + {
1.1267 + return pContext->ThrowNativeError("Client %d is not connected", client);
1.1268 + }
1.1269 +
1.1270 + /* Ignore duplicate kicks */
1.1271 + if (pPlayer->IsInKickQueue())
1.1272 + {
1.1273 + return 1;
1.1274 + }
1.1275 +
1.1276 + pPlayer->MarkAsBeingKicked();
1.1277 +
1.1278 + if (pPlayer->IsFakeClient())
1.1279 + {
1.1280 + char kickcmd[40];
1.1281 + UTIL_Format(kickcmd, sizeof(kickcmd), "kick %s\n", pPlayer->GetName());
1.1282 +
1.1283 + engine->ServerCommand(kickcmd);
1.1284 + return 1;
1.1285 + }
1.1286 +
1.1287 + g_SourceMod.SetGlobalTarget(client);
1.1288 +
1.1289 + char buffer[256];
1.1290 + g_SourceMod.FormatString(buffer, sizeof(buffer), pContext, params, 2);
1.1291 +
1.1292 + if (pContext->GetContext()->n_err != SP_ERROR_NONE)
1.1293 + {
1.1294 + return 0;
1.1295 + }
1.1296 +
1.1297 + g_HL2.AddDelayedKick(client, pPlayer->GetUserId(), buffer);
1.1298 +
1.1299 + return 1;
1.1300 +}
1.1301 +
1.1302 +static cell_t KickClientEx(IPluginContext *pContext, const cell_t *params)
1.1303 +{
1.1304 + int client = params[1];
1.1305 +
1.1306 + CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
1.1307 + if (!pPlayer)
1.1308 + {
1.1309 + return pContext->ThrowNativeError("Client index %d is invalid", client);
1.1310 + }
1.1311 + else if (!pPlayer->IsConnected())
1.1312 + {
1.1313 + return pContext->ThrowNativeError("Client %d is not connected", client);
1.1314 + }
1.1315 +
1.1316 + /* Ignore duplicate kicks */
1.1317 + if (pPlayer->IsInKickQueue())
1.1318 + {
1.1319 + return 1;
1.1320 + }
1.1321 +
1.1322 + pPlayer->MarkAsBeingKicked();
1.1323 +
1.1324 + if (pPlayer->IsFakeClient())
1.1325 + {
1.1326 + char kickcmd[40];
1.1327 + UTIL_Format(kickcmd, sizeof(kickcmd), "kick %s\n", pPlayer->GetName());
1.1328 +
1.1329 + engine->ServerCommand(kickcmd);
1.1330 + return 1;
1.1331 + }
1.1332 +
1.1333 + g_SourceMod.SetGlobalTarget(client);
1.1334 +
1.1335 + char buffer[256];
1.1336 + g_SourceMod.FormatString(buffer, sizeof(buffer), pContext, params, 2);
1.1337 +
1.1338 + if (pContext->GetContext()->n_err != SP_ERROR_NONE)
1.1339 + {
1.1340 + return 0;
1.1341 + }
1.1342 +
1.1343 + pPlayer->Kick(buffer);
1.1344 +
1.1345 + return 1;
1.1346 +}
1.1347 +
1.1348 +static cell_t ChangeClientTeam(IPluginContext *pContext, const cell_t *params)
1.1349 +{
1.1350 + int client = params[1];
1.1351 +
1.1352 + CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
1.1353 + if (!pPlayer)
1.1354 + {
1.1355 + return pContext->ThrowNativeError("Client index %d is invalid", client);
1.1356 + }
1.1357 + else if (!pPlayer->IsInGame())
1.1358 + {
1.1359 + return pContext->ThrowNativeError("Client %d is not in game", client);
1.1360 + }
1.1361 +
1.1362 + IPlayerInfo *pInfo = pPlayer->GetPlayerInfo();
1.1363 + if (!pInfo)
1.1364 + {
1.1365 + return pContext->ThrowNativeError("IPlayerInfo not supported by game");
1.1366 + }
1.1367 +
1.1368 + pInfo->ChangeTeam(params[2]);
1.1369 +
1.1370 + return 1;
1.1371 +}
1.1372 +
1.1373 +static cell_t RunAdminCacheChecks(IPluginContext *pContext, const cell_t *params)
1.1374 +{
1.1375 + int client = params[1];
1.1376 +
1.1377 + CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
1.1378 + if (!pPlayer)
1.1379 + {
1.1380 + return pContext->ThrowNativeError("Client index %d is invalid", client);
1.1381 + }
1.1382 + else if (!pPlayer->IsInGame())
1.1383 + {
1.1384 + return pContext->ThrowNativeError("Client %d is not in game", client);
1.1385 + }
1.1386 + else if (!pPlayer->IsAuthorized())
1.1387 + {
1.1388 + return pContext->ThrowNativeError("Client %d is not authorized", client);
1.1389 + }
1.1390 +
1.1391 + AdminId id = pPlayer->GetAdminId();
1.1392 + pPlayer->DoBasicAdminChecks();
1.1393 +
1.1394 + return (id != pPlayer->GetAdminId()) ? 1 : 0;
1.1395 +}
1.1396 +
1.1397 +static cell_t NotifyPostAdminCheck(IPluginContext *pContext, const cell_t *params)
1.1398 +{
1.1399 + int client = params[1];
1.1400 +
1.1401 + CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
1.1402 + if (!pPlayer)
1.1403 + {
1.1404 + return pContext->ThrowNativeError("Client index %d is invalid", client);
1.1405 + }
1.1406 + else if (!pPlayer->IsInGame()) {
1.1407 + return pContext->ThrowNativeError("Client %d is not in game", client);
1.1408 + }
1.1409 + else if (!pPlayer->IsAuthorized())
1.1410 + {
1.1411 + return pContext->ThrowNativeError("Client %d is not authorized", client);
1.1412 + }
1.1413 +
1.1414 + pPlayer->NotifyPostAdminChecks();
1.1415 +
1.1416 + return 1;
1.1417 +}
1.1418 +
1.1419 +static cell_t IsClientInKickQueue(IPluginContext *pContext, const cell_t *params)
1.1420 +{
1.1421 + int client = params[1];
1.1422 +
1.1423 + CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
1.1424 +
1.1425 + if (!pPlayer)
1.1426 + {
1.1427 + return pContext->ThrowNativeError("Client index %d is invalid", client);
1.1428 + }
1.1429 + else if (!pPlayer->IsConnected())
1.1430 + {
1.1431 + return pContext->ThrowNativeError("Client %d is not in game", client);
1.1432 + }
1.1433 +
1.1434 + return pPlayer->IsInKickQueue() ? 1 : 0;
1.1435 +}
1.1436 +
1.1437 +static cell_t ProcessTargetString(IPluginContext *pContext, const cell_t *params)
1.1438 +{
1.1439 + cmd_target_info_t info;
1.1440 +
1.1441 + pContext->LocalToString(params[1], (char **)&info.pattern);
1.1442 + info.admin = params[2];
1.1443 + pContext->LocalToPhysAddr(params[3], &info.targets);
1.1444 + info.max_targets = params[4];
1.1445 + info.flags = params[5];
1.1446 + pContext->LocalToString(params[6], &info.target_name);
1.1447 + info.target_name_maxlength = params[7];
1.1448 +
1.1449 + cell_t *tn_is_ml;
1.1450 + pContext->LocalToPhysAddr(params[8], &tn_is_ml);
1.1451 +
1.1452 + g_Players.ProcessCommandTarget(&info);
1.1453 +
1.1454 + if (info.target_name_style == COMMAND_TARGETNAME_ML)
1.1455 + {
1.1456 + *tn_is_ml = 1;
1.1457 + }
1.1458 + else
1.1459 + {
1.1460 + *tn_is_ml = 0;
1.1461 + }
1.1462 +
1.1463 + if (info.num_targets == 0)
1.1464 + {
1.1465 + return info.reason;
1.1466 + }
1.1467 + else
1.1468 + {
1.1469 + return info.num_targets;
1.1470 + }
1.1471 +}
1.1472 +
1.1473 +REGISTER_NATIVES(playernatives)
1.1474 +{
1.1475 + {"AddUserFlags", AddUserFlags},
1.1476 + {"CanUserTarget", CanUserTarget},
1.1477 + {"ChangeClientTeam", ChangeClientTeam},
1.1478 + {"GetClientAuthString", sm_GetClientAuthStr},
1.1479 + {"GetClientCount", sm_GetClientCount},
1.1480 + {"GetClientInfo", sm_GetClientInfo},
1.1481 + {"GetClientIP", sm_GetClientIP},
1.1482 + {"GetClientName", sm_GetClientName},
1.1483 + {"GetClientTeam", GetClientTeam},
1.1484 + {"GetClientUserId", GetClientUserId},
1.1485 + {"GetMaxClients", sm_GetMaxClients},
1.1486 + {"GetUserAdmin", GetUserAdmin},
1.1487 + {"GetUserFlagBits", GetUserFlagBits},
1.1488 + {"IsClientAuthorized", sm_IsClientAuthorized},
1.1489 + {"IsClientConnected", sm_IsClientConnected},
1.1490 + {"IsFakeClient", sm_IsClientFakeClient},
1.1491 + {"IsClientInGame", sm_IsClientInGame},
1.1492 + {"IsClientObserver", IsClientObserver},
1.1493 + {"RemoveUserFlags", RemoveUserFlags},
1.1494 + {"SetUserAdmin", SetUserAdmin},
1.1495 + {"SetUserFlagBits", SetUserFlagBits},
1.1496 + {"GetClientDeaths", GetDeathCount},
1.1497 + {"GetClientFrags", GetFragCount},
1.1498 + {"GetClientArmor", GetArmorValue},
1.1499 + {"GetClientAbsOrigin", GetAbsOrigin},
1.1500 + {"GetClientAbsAngles", GetAbsAngles},
1.1501 + {"GetClientMins", GetPlayerMins},
1.1502 + {"GetClientMaxs", GetPlayerMaxs},
1.1503 + {"GetClientWeapon", GetWeaponName},
1.1504 + {"GetClientModel", GetModelName},
1.1505 + {"GetClientHealth", GetHealth},
1.1506 + {"GetClientTime", GetTimeConnected},
1.1507 + {"GetClientDataRate", GetDataRate},
1.1508 + {"IsClentTimingOut", IsTimingOut},
1.1509 + {"GetClientLatency", GetLatency},
1.1510 + {"GetClientAvgLatency", GetAvgLatency},
1.1511 + {"GetClientAvgLoss", GetAvgLoss},
1.1512 + {"GetClientAvgChoke", GetAvgChoke},
1.1513 + {"GetClientAvgData", GetAvgData},
1.1514 + {"GetClientAvgPackets", GetAvgPackets},
1.1515 + {"GetClientOfUserId", GetClientOfUserId},
1.1516 + {"ShowActivity", ShowActivity},
1.1517 + {"ShowActivityEx", ShowActivityEx},
1.1518 + {"ShowActivity2", ShowActivity2},
1.1519 + {"KickClient", KickClient},
1.1520 + {"KickClientEx", KickClientEx},
1.1521 + {"RunAdminCacheChecks", RunAdminCacheChecks},
1.1522 + {"NotifyPostAdminCheck", NotifyPostAdminCheck},
1.1523 + {"IsClientInKickQueue", IsClientInKickQueue},
1.1524 + {"ProcessTargetString", ProcessTargetString},
1.1525 + {NULL, NULL}
1.1526 +};
1.1527 +