1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/core/smn_player.cpp Sun Mar 30 07:00:22 2008 +0000
1.3 @@ -0,0 +1,1385 @@
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 +
1.772 + CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
1.773 + if (!pPlayer)
1.774 + {
1.775 + return pContext->ThrowNativeError("Client index %d is invalid", client);
1.776 + } else if (!pPlayer->IsInGame()) {
1.777 + return pContext->ThrowNativeError("Client %d is not in game", client);
1.778 + } else if (pPlayer->IsFakeClient()) {
1.779 + return pContext->ThrowNativeError("Client %d is a bot", client);
1.780 + }
1.781 +
1.782 + INetChannelInfo *pInfo = engine->GetPlayerNetInfo(client);
1.783 +
1.784 + return sp_ftoc(pInfo->GetLatency(params[2]));
1.785 +}
1.786 +
1.787 +static cell_t GetAvgLatency(IPluginContext *pContext, const cell_t *params)
1.788 +{
1.789 + int client = params[1];
1.790 +
1.791 + CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
1.792 + if (!pPlayer)
1.793 + {
1.794 + return pContext->ThrowNativeError("Client index %d is invalid", client);
1.795 + } else if (!pPlayer->IsInGame()) {
1.796 + return pContext->ThrowNativeError("Client %d is not in game", client);
1.797 + } else if (pPlayer->IsFakeClient()) {
1.798 + return pContext->ThrowNativeError("Client %d is a bot", client);
1.799 + }
1.800 +
1.801 + INetChannelInfo *pInfo = engine->GetPlayerNetInfo(client);
1.802 +
1.803 + return sp_ftoc(pInfo->GetAvgLatency(params[2]));
1.804 +}
1.805 +
1.806 +static cell_t GetAvgLoss(IPluginContext *pContext, const cell_t *params)
1.807 +{
1.808 + int client = params[1];
1.809 +
1.810 + CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
1.811 + if (!pPlayer)
1.812 + {
1.813 + return pContext->ThrowNativeError("Client index %d is invalid", client);
1.814 + } else if (!pPlayer->IsInGame()) {
1.815 + return pContext->ThrowNativeError("Client %d is not in game", client);
1.816 + } else if (pPlayer->IsFakeClient()) {
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 + return sp_ftoc(pInfo->GetAvgLoss(params[2]));
1.823 +}
1.824 +
1.825 +static cell_t GetAvgChoke(IPluginContext *pContext, const cell_t *params)
1.826 +{
1.827 + int client = params[1];
1.828 +
1.829 + CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
1.830 + if (!pPlayer)
1.831 + {
1.832 + return pContext->ThrowNativeError("Client index %d is invalid", client);
1.833 + } else if (!pPlayer->IsInGame()) {
1.834 + return pContext->ThrowNativeError("Client %d is not in game", client);
1.835 + } else if (pPlayer->IsFakeClient()) {
1.836 + return pContext->ThrowNativeError("Client %d is a bot", client);
1.837 + }
1.838 +
1.839 + INetChannelInfo *pInfo = engine->GetPlayerNetInfo(client);
1.840 +
1.841 + return sp_ftoc(pInfo->GetAvgChoke(params[2]));
1.842 +}
1.843 +
1.844 +static cell_t GetAvgData(IPluginContext *pContext, const cell_t *params)
1.845 +{
1.846 + int client = params[1];
1.847 +
1.848 + CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
1.849 + if (!pPlayer)
1.850 + {
1.851 + return pContext->ThrowNativeError("Client index %d is invalid", client);
1.852 + } else if (!pPlayer->IsInGame()) {
1.853 + return pContext->ThrowNativeError("Client %d is not in game", client);
1.854 + } else if (pPlayer->IsFakeClient()) {
1.855 + return pContext->ThrowNativeError("Client %d is a bot", client);
1.856 + }
1.857 +
1.858 + INetChannelInfo *pInfo = engine->GetPlayerNetInfo(client);
1.859 +
1.860 + return sp_ftoc(pInfo->GetAvgData(params[2]));
1.861 +}
1.862 +
1.863 +static cell_t GetAvgPackets(IPluginContext *pContext, const cell_t *params)
1.864 +{
1.865 + int client = params[1];
1.866 +
1.867 + CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
1.868 + if (!pPlayer)
1.869 + {
1.870 + return pContext->ThrowNativeError("Client index %d is invalid", client);
1.871 + } else if (!pPlayer->IsInGame()) {
1.872 + return pContext->ThrowNativeError("Client %d is not in game", client);
1.873 + } else if (pPlayer->IsFakeClient()) {
1.874 + return pContext->ThrowNativeError("Client %d is a bot", client);
1.875 + }
1.876 +
1.877 + INetChannelInfo *pInfo = engine->GetPlayerNetInfo(client);
1.878 +
1.879 + return sp_ftoc(pInfo->GetAvgPackets(params[2]));
1.880 +}
1.881 +
1.882 +static cell_t GetClientOfUserId(IPluginContext *pContext, const cell_t *params)
1.883 +{
1.884 + return g_Players.GetClientOfUserId(params[1]);
1.885 +}
1.886 +
1.887 +static cell_t _ShowActivity(IPluginContext *pContext,
1.888 + const cell_t *params,
1.889 + const char *tag,
1.890 + cell_t fmt_param)
1.891 +{
1.892 + char message[255];
1.893 + char buffer[255];
1.894 + int value = sm_show_activity.GetInt();
1.895 + unsigned int replyto = g_ChatTriggers.GetReplyTo();
1.896 + int client = params[1];
1.897 +
1.898 + const char *name = "Console";
1.899 + const char *sign = "ADMIN";
1.900 + bool display_in_chat = false;
1.901 + if (client != 0)
1.902 + {
1.903 + CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
1.904 + if (!pPlayer || !pPlayer->IsConnected())
1.905 + {
1.906 + return pContext->ThrowNativeError("Client index %d is invalid", client);
1.907 + }
1.908 + name = pPlayer->GetName();
1.909 + AdminId id = pPlayer->GetAdminId();
1.910 + if (id == INVALID_ADMIN_ID
1.911 + || !g_Admins.GetAdminFlag(id, Admin_Generic, Access_Effective))
1.912 + {
1.913 + sign = "PLAYER";
1.914 + }
1.915 +
1.916 + /* Display the message to the client? */
1.917 + if (replyto == SM_REPLY_CONSOLE)
1.918 + {
1.919 + g_SourceMod.SetGlobalTarget(client);
1.920 + g_SourceMod.FormatString(buffer, sizeof(buffer), pContext, params, fmt_param);
1.921 +
1.922 + if (pContext->GetContext()->n_err != SP_ERROR_NONE)
1.923 + {
1.924 + return 0;
1.925 + }
1.926 +
1.927 + UTIL_Format(message, sizeof(message), "%s%s\n", tag, buffer);
1.928 + engine->ClientPrintf(pPlayer->GetEdict(), message);
1.929 + display_in_chat = true;
1.930 + }
1.931 + }
1.932 + else
1.933 + {
1.934 + g_SourceMod.SetGlobalTarget(LANG_SERVER);
1.935 + g_SourceMod.FormatString(buffer, sizeof(buffer), pContext, params, fmt_param);
1.936 +
1.937 + if (pContext->GetContext()->n_err != SP_ERROR_NONE)
1.938 + {
1.939 + return 0;
1.940 + }
1.941 +
1.942 + UTIL_Format(message, sizeof(message), "%s%s\n", tag, buffer);
1.943 + META_CONPRINT(message);
1.944 + }
1.945 +
1.946 + if (!value)
1.947 + {
1.948 + return 1;
1.949 + }
1.950 +
1.951 + int maxClients = g_Players.GetMaxClients();
1.952 + for (int i=1; i<=maxClients; i++)
1.953 + {
1.954 + CPlayer *pPlayer = g_Players.GetPlayerByIndex(i);
1.955 + if (!pPlayer->IsInGame()
1.956 + || pPlayer->IsFakeClient()
1.957 + || (display_in_chat && i == client))
1.958 + {
1.959 + continue;
1.960 + }
1.961 + AdminId id = pPlayer->GetAdminId();
1.962 + g_SourceMod.SetGlobalTarget(i);
1.963 + if (id == INVALID_ADMIN_ID
1.964 + || !g_Admins.GetAdminFlag(id, Admin_Generic, Access_Effective))
1.965 + {
1.966 + /* Treat this as a normal user */
1.967 + if ((value & 1) || (value & 2))
1.968 + {
1.969 + const char *newsign = sign;
1.970 + if ((value & 2) || (i == client))
1.971 + {
1.972 + newsign = name;
1.973 + }
1.974 + g_SourceMod.FormatString(buffer, sizeof(buffer), pContext, params, fmt_param);
1.975 +
1.976 + if (pContext->GetContext()->n_err != SP_ERROR_NONE)
1.977 + {
1.978 + return 0;
1.979 + }
1.980 +
1.981 + UTIL_Format(message, sizeof(message), "%s%s: %s", tag, newsign, buffer);
1.982 + g_HL2.TextMsg(i, HUD_PRINTTALK, message);
1.983 + }
1.984 + }
1.985 + else
1.986 + {
1.987 + /* Treat this as an admin user */
1.988 + bool is_root = g_Admins.GetAdminFlag(id, Admin_Root, Access_Effective);
1.989 + if ((value & 4)
1.990 + || (value & 8)
1.991 + || ((value & 16) && is_root))
1.992 + {
1.993 + const char *newsign = sign;
1.994 + if ((value & 8) || ((value & 16) && is_root) || (i == client))
1.995 + {
1.996 + newsign = name;
1.997 + }
1.998 + g_SourceMod.FormatString(buffer, sizeof(buffer), pContext, params, fmt_param);
1.999 +
1.1000 + if (pContext->GetContext()->n_err != SP_ERROR_NONE)
1.1001 + {
1.1002 + return 0;
1.1003 + }
1.1004 +
1.1005 + UTIL_Format(message, sizeof(message), "%s%s: %s", tag, newsign, buffer);
1.1006 + g_HL2.TextMsg(i, HUD_PRINTTALK, message);
1.1007 + }
1.1008 + }
1.1009 + }
1.1010 +
1.1011 + return 1;
1.1012 +}
1.1013 +
1.1014 +static cell_t _ShowActivity2(IPluginContext *pContext,
1.1015 + const cell_t *params,
1.1016 + const char *tag,
1.1017 + cell_t fmt_param)
1.1018 +{
1.1019 + char message[255];
1.1020 + char buffer[255];
1.1021 + int value = sm_show_activity.GetInt();
1.1022 + unsigned int replyto = g_ChatTriggers.GetReplyTo();
1.1023 + int client = params[1];
1.1024 +
1.1025 + const char *name = "Console";
1.1026 + const char *sign = "ADMIN";
1.1027 + if (client != 0)
1.1028 + {
1.1029 + CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
1.1030 + if (!pPlayer || !pPlayer->IsConnected())
1.1031 + {
1.1032 + return pContext->ThrowNativeError("Client index %d is invalid", client);
1.1033 + }
1.1034 + name = pPlayer->GetName();
1.1035 + AdminId id = pPlayer->GetAdminId();
1.1036 + if (id == INVALID_ADMIN_ID
1.1037 + || !g_Admins.GetAdminFlag(id, Admin_Generic, Access_Effective))
1.1038 + {
1.1039 + sign = "PLAYER";
1.1040 + }
1.1041 +
1.1042 + g_SourceMod.SetGlobalTarget(client);
1.1043 + g_SourceMod.FormatString(buffer, sizeof(buffer), pContext, params, fmt_param);
1.1044 +
1.1045 + if (pContext->GetContext()->n_err != SP_ERROR_NONE)
1.1046 + {
1.1047 + return 0;
1.1048 + }
1.1049 +
1.1050 + /* We don't display directly to the console because the chat text
1.1051 + * simply gets added to the console, so we don't want it to print
1.1052 + * twice.
1.1053 + */
1.1054 + if (replyto == SM_REPLY_CONSOLE)
1.1055 + {
1.1056 +#if 0
1.1057 + UTIL_Format(message, sizeof(message), "%s%s\n", tag, buffer);
1.1058 + engine->ClientPrintf(pPlayer->GetEdict(), message);
1.1059 +#endif
1.1060 + UTIL_Format(message, sizeof(message), "%s%s", tag, buffer);
1.1061 + g_HL2.TextMsg(client, HUD_PRINTTALK, message);
1.1062 + }
1.1063 + else
1.1064 + {
1.1065 + UTIL_Format(message, sizeof(message), "%s%s", tag, buffer);
1.1066 + g_HL2.TextMsg(client, HUD_PRINTTALK, message);
1.1067 + }
1.1068 + }
1.1069 + else
1.1070 + {
1.1071 + g_SourceMod.SetGlobalTarget(LANG_SERVER);
1.1072 + g_SourceMod.FormatString(buffer, sizeof(buffer), pContext, params, fmt_param);
1.1073 +
1.1074 + if (pContext->GetContext()->n_err != SP_ERROR_NONE)
1.1075 + {
1.1076 + return 0;
1.1077 + }
1.1078 +
1.1079 + UTIL_Format(message, sizeof(message), "%s%s\n", tag, buffer);
1.1080 + META_CONPRINT(message);
1.1081 + }
1.1082 +
1.1083 + if (!value)
1.1084 + {
1.1085 + return 1;
1.1086 + }
1.1087 +
1.1088 + int maxClients = g_Players.GetMaxClients();
1.1089 + for (int i=1; i<=maxClients; i++)
1.1090 + {
1.1091 + CPlayer *pPlayer = g_Players.GetPlayerByIndex(i);
1.1092 + if (!pPlayer->IsInGame()
1.1093 + || pPlayer->IsFakeClient()
1.1094 + || i == client)
1.1095 + {
1.1096 + continue;
1.1097 + }
1.1098 + AdminId id = pPlayer->GetAdminId();
1.1099 + g_SourceMod.SetGlobalTarget(i);
1.1100 + if (id == INVALID_ADMIN_ID
1.1101 + || !g_Admins.GetAdminFlag(id, Admin_Generic, Access_Effective))
1.1102 + {
1.1103 + /* Treat this as a normal user */
1.1104 + if ((value & 1) || (value & 2))
1.1105 + {
1.1106 + const char *newsign = sign;
1.1107 + if ((value & 2))
1.1108 + {
1.1109 + newsign = name;
1.1110 + }
1.1111 + g_SourceMod.FormatString(buffer, sizeof(buffer), pContext, params, fmt_param);
1.1112 +
1.1113 + if (pContext->GetContext()->n_err != SP_ERROR_NONE)
1.1114 + {
1.1115 + return 0;
1.1116 + }
1.1117 +
1.1118 + UTIL_Format(message, sizeof(message), "%s%s: %s", tag, newsign, buffer);
1.1119 + g_HL2.TextMsg(i, HUD_PRINTTALK, message);
1.1120 + }
1.1121 + }
1.1122 + else
1.1123 + {
1.1124 + /* Treat this as an admin user */
1.1125 + bool is_root = g_Admins.GetAdminFlag(id, Admin_Root, Access_Effective);
1.1126 + if ((value & 4)
1.1127 + || (value & 8)
1.1128 + || ((value & 16) && is_root))
1.1129 + {
1.1130 + const char *newsign = sign;
1.1131 + if ((value & 8) || ((value & 16) && is_root))
1.1132 + {
1.1133 + newsign = name;
1.1134 + }
1.1135 + g_SourceMod.FormatString(buffer, sizeof(buffer), pContext, params, fmt_param);
1.1136 +
1.1137 + if (pContext->GetContext()->n_err != SP_ERROR_NONE)
1.1138 + {
1.1139 + return 0;
1.1140 + }
1.1141 +
1.1142 + UTIL_Format(message, sizeof(message), "%s%s: %s", tag, newsign, buffer);
1.1143 + g_HL2.TextMsg(i, HUD_PRINTTALK, message);
1.1144 + }
1.1145 + }
1.1146 + }
1.1147 +
1.1148 + return 1;
1.1149 +}
1.1150 +
1.1151 +static cell_t ShowActivity(IPluginContext *pContext, const cell_t *params)
1.1152 +{
1.1153 + return _ShowActivity(pContext, params, "[SM] ", 2);
1.1154 +}
1.1155 +
1.1156 +static cell_t ShowActivityEx(IPluginContext *pContext, const cell_t *params)
1.1157 +{
1.1158 + char *str;
1.1159 + pContext->LocalToString(params[2], &str);
1.1160 +
1.1161 + return _ShowActivity(pContext, params, str, 3);
1.1162 +}
1.1163 +
1.1164 +static cell_t ShowActivity2(IPluginContext *pContext, const cell_t *params)
1.1165 +{
1.1166 + char *str;
1.1167 + pContext->LocalToString(params[2], &str);
1.1168 +
1.1169 + return _ShowActivity2(pContext, params, str, 3);
1.1170 +}
1.1171 +
1.1172 +static cell_t KickClient(IPluginContext *pContext, const cell_t *params)
1.1173 +{
1.1174 + int client = params[1];
1.1175 +
1.1176 + CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
1.1177 + if (!pPlayer)
1.1178 + {
1.1179 + return pContext->ThrowNativeError("Client index %d is invalid", client);
1.1180 + } else if (!pPlayer->IsConnected()) {
1.1181 + return pContext->ThrowNativeError("Client %d is not connected", client);
1.1182 + }
1.1183 +
1.1184 + pPlayer->MarkAsBeingKicked();
1.1185 +
1.1186 + if (pPlayer->IsFakeClient())
1.1187 + {
1.1188 + char kickcmd[40];
1.1189 + UTIL_Format(kickcmd, sizeof(kickcmd), "kick %s\n", pPlayer->GetName());
1.1190 +
1.1191 + engine->ServerCommand(kickcmd);
1.1192 + return 1;
1.1193 + }
1.1194 +
1.1195 + g_SourceMod.SetGlobalTarget(client);
1.1196 +
1.1197 + char buffer[256];
1.1198 + g_SourceMod.FormatString(buffer, sizeof(buffer), pContext, params, 2);
1.1199 +
1.1200 + if (pContext->GetContext()->n_err != SP_ERROR_NONE)
1.1201 + {
1.1202 + return 0;
1.1203 + }
1.1204 +
1.1205 + pPlayer->Kick(buffer);
1.1206 +
1.1207 + return 1;
1.1208 +}
1.1209 +
1.1210 +static cell_t ChangeClientTeam(IPluginContext *pContext, const cell_t *params)
1.1211 +{
1.1212 + int client = params[1];
1.1213 +
1.1214 + CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
1.1215 + if (!pPlayer)
1.1216 + {
1.1217 + return pContext->ThrowNativeError("Client index %d is invalid", client);
1.1218 + }
1.1219 + else if (!pPlayer->IsInGame())
1.1220 + {
1.1221 + return pContext->ThrowNativeError("Client %d is not in game", client);
1.1222 + }
1.1223 +
1.1224 + IPlayerInfo *pInfo = pPlayer->GetPlayerInfo();
1.1225 + if (!pInfo)
1.1226 + {
1.1227 + return pContext->ThrowNativeError("IPlayerInfo not supported by game");
1.1228 + }
1.1229 +
1.1230 + pInfo->ChangeTeam(params[2]);
1.1231 +
1.1232 + return 1;
1.1233 +}
1.1234 +
1.1235 +static cell_t RunAdminCacheChecks(IPluginContext *pContext, const cell_t *params)
1.1236 +{
1.1237 + int client = params[1];
1.1238 +
1.1239 + CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
1.1240 + if (!pPlayer)
1.1241 + {
1.1242 + return pContext->ThrowNativeError("Client index %d is invalid", client);
1.1243 + }
1.1244 + else if (!pPlayer->IsInGame())
1.1245 + {
1.1246 + return pContext->ThrowNativeError("Client %d is not in game", client);
1.1247 + }
1.1248 + else if (!pPlayer->IsAuthorized())
1.1249 + {
1.1250 + return pContext->ThrowNativeError("Client %d is not authorized", client);
1.1251 + }
1.1252 +
1.1253 + AdminId id = pPlayer->GetAdminId();
1.1254 + pPlayer->DoBasicAdminChecks();
1.1255 +
1.1256 + return (id != pPlayer->GetAdminId()) ? 1 : 0;
1.1257 +}
1.1258 +
1.1259 +static cell_t NotifyPostAdminCheck(IPluginContext *pContext, const cell_t *params)
1.1260 +{
1.1261 + int client = params[1];
1.1262 +
1.1263 + CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
1.1264 + if (!pPlayer)
1.1265 + {
1.1266 + return pContext->ThrowNativeError("Client index %d is invalid", client);
1.1267 + }
1.1268 + else if (!pPlayer->IsInGame()) {
1.1269 + return pContext->ThrowNativeError("Client %d is not in game", client);
1.1270 + }
1.1271 + else if (!pPlayer->IsAuthorized())
1.1272 + {
1.1273 + return pContext->ThrowNativeError("Client %d is not authorized", client);
1.1274 + }
1.1275 +
1.1276 + pPlayer->NotifyPostAdminChecks();
1.1277 +
1.1278 + return 1;
1.1279 +}
1.1280 +
1.1281 +static cell_t IsClientInKickQueue(IPluginContext *pContext, const cell_t *params)
1.1282 +{
1.1283 + int client = params[1];
1.1284 +
1.1285 + CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
1.1286 +
1.1287 + if (!pPlayer)
1.1288 + {
1.1289 + return pContext->ThrowNativeError("Client index %d is invalid", client);
1.1290 + }
1.1291 + else if (!pPlayer->IsConnected())
1.1292 + {
1.1293 + return pContext->ThrowNativeError("Client %d is not in game", client);
1.1294 + }
1.1295 +
1.1296 + return pPlayer->IsInKickQueue() ? 1 : 0;
1.1297 +}
1.1298 +
1.1299 +static cell_t ProcessTargetString(IPluginContext *pContext, const cell_t *params)
1.1300 +{
1.1301 + cmd_target_info_t info;
1.1302 +
1.1303 + pContext->LocalToString(params[1], (char **)&info.pattern);
1.1304 + info.admin = params[2];
1.1305 + pContext->LocalToPhysAddr(params[3], &info.targets);
1.1306 + info.max_targets = params[4];
1.1307 + info.flags = params[5];
1.1308 + pContext->LocalToString(params[6], &info.target_name);
1.1309 + info.target_name_maxlength = params[7];
1.1310 +
1.1311 + cell_t *tn_is_ml;
1.1312 + pContext->LocalToPhysAddr(params[8], &tn_is_ml);
1.1313 +
1.1314 + g_Players.ProcessCommandTarget(&info);
1.1315 +
1.1316 + if (info.target_name_style == COMMAND_TARGETNAME_ML)
1.1317 + {
1.1318 + *tn_is_ml = 1;
1.1319 + }
1.1320 + else
1.1321 + {
1.1322 + *tn_is_ml = 0;
1.1323 + }
1.1324 +
1.1325 + if (info.num_targets == 0)
1.1326 + {
1.1327 + return info.reason;
1.1328 + }
1.1329 + else
1.1330 + {
1.1331 + return info.num_targets;
1.1332 + }
1.1333 +}
1.1334 +
1.1335 +REGISTER_NATIVES(playernatives)
1.1336 +{
1.1337 + {"AddUserFlags", AddUserFlags},
1.1338 + {"CanUserTarget", CanUserTarget},
1.1339 + {"ChangeClientTeam", ChangeClientTeam},
1.1340 + {"GetClientAuthString", sm_GetClientAuthStr},
1.1341 + {"GetClientCount", sm_GetClientCount},
1.1342 + {"GetClientInfo", sm_GetClientInfo},
1.1343 + {"GetClientIP", sm_GetClientIP},
1.1344 + {"GetClientName", sm_GetClientName},
1.1345 + {"GetClientTeam", GetClientTeam},
1.1346 + {"GetClientUserId", GetClientUserId},
1.1347 + {"GetMaxClients", sm_GetMaxClients},
1.1348 + {"GetUserAdmin", GetUserAdmin},
1.1349 + {"GetUserFlagBits", GetUserFlagBits},
1.1350 + {"IsClientAuthorized", sm_IsClientAuthorized},
1.1351 + {"IsClientConnected", sm_IsClientConnected},
1.1352 + {"IsFakeClient", sm_IsClientFakeClient},
1.1353 + {"IsClientInGame", sm_IsClientInGame},
1.1354 + {"IsClientObserver", IsClientObserver},
1.1355 + {"RemoveUserFlags", RemoveUserFlags},
1.1356 + {"SetUserAdmin", SetUserAdmin},
1.1357 + {"SetUserFlagBits", SetUserFlagBits},
1.1358 + {"GetClientDeaths", GetDeathCount},
1.1359 + {"GetClientFrags", GetFragCount},
1.1360 + {"GetClientArmor", GetArmorValue},
1.1361 + {"GetClientAbsOrigin", GetAbsOrigin},
1.1362 + {"GetClientAbsAngles", GetAbsAngles},
1.1363 + {"GetClientMins", GetPlayerMins},
1.1364 + {"GetClientMaxs", GetPlayerMaxs},
1.1365 + {"GetClientWeapon", GetWeaponName},
1.1366 + {"GetClientModel", GetModelName},
1.1367 + {"GetClientHealth", GetHealth},
1.1368 + {"GetClientTime", GetTimeConnected},
1.1369 + {"GetClientDataRate", GetDataRate},
1.1370 + {"IsClentTimingOut", IsTimingOut},
1.1371 + {"GetClientLatency", GetLatency},
1.1372 + {"GetClientAvgLatency", GetAvgLatency},
1.1373 + {"GetClientAvgLoss", GetAvgLoss},
1.1374 + {"GetClientAvgChoke", GetAvgChoke},
1.1375 + {"GetClientAvgData", GetAvgData},
1.1376 + {"GetClientAvgPackets", GetAvgPackets},
1.1377 + {"GetClientOfUserId", GetClientOfUserId},
1.1378 + {"ShowActivity", ShowActivity},
1.1379 + {"ShowActivityEx", ShowActivityEx},
1.1380 + {"ShowActivity2", ShowActivity2},
1.1381 + {"KickClient", KickClient},
1.1382 + {"RunAdminCacheChecks", RunAdminCacheChecks},
1.1383 + {"NotifyPostAdminCheck", NotifyPostAdminCheck},
1.1384 + {"IsClientInKickQueue", IsClientInKickQueue},
1.1385 + {"ProcessTargetString", ProcessTargetString},
1.1386 + {NULL, NULL}
1.1387 +};
1.1388 +