ds@1952: /** ds@1952: * vim: set ts=4 : ds@1952: * ============================================================================= ds@1952: * SourceMod ds@1952: * Copyright (C) 2004-2008 AlliedModders LLC. All rights reserved. ds@1952: * ============================================================================= ds@1952: * ds@1952: * This program is free software; you can redistribute it and/or modify it under ds@1952: * the terms of the GNU General Public License, version 3.0, as published by the ds@1952: * Free Software Foundation. ds@1952: * ds@1952: * This program is distributed in the hope that it will be useful, but WITHOUT ds@1952: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS ds@1952: * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more ds@1952: * details. ds@1952: * ds@1952: * You should have received a copy of the GNU General Public License along with ds@1952: * this program. If not, see . ds@1952: * ds@1952: * As a special exception, AlliedModders LLC gives you permission to link the ds@1952: * code of this program (as well as its derivative works) to "Half-Life 2," the ds@1952: * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software ds@1952: * by the Valve Corporation. You must obey the GNU General Public License in ds@1952: * all respects for all other code used. Additionally, AlliedModders LLC grants ds@1952: * this exception to all derivative works. AlliedModders LLC defines further ds@1952: * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007), ds@1952: * or . ds@1952: * ds@1952: * Version: $Id$ ds@1952: */ ds@1952: ds@1952: #include "PlayerManager.h" ds@1952: #include "AdminCache.h" ds@1952: #include "sm_stringutil.h" ds@1952: #include "HalfLife2.h" ds@1952: #include "sourcemod.h" ds@1952: #include "ChatTriggers.h" ds@1952: #include ds@1952: #include ds@1952: ds@1952: ConVar sm_show_activity("sm_show_activity", "13", FCVAR_SPONLY, "Activity display setting (see sourcemod.cfg)"); ds@1952: ds@1952: static cell_t sm_GetClientCount(IPluginContext *pCtx, const cell_t *params) ds@1952: { ds@1952: if (params[1]) ds@1952: { ds@1952: return g_Players.NumPlayers(); ds@1952: } ds@1952: ds@1952: int maxplayers = g_Players.MaxClients(); ds@1952: int count = 0; ds@1952: for (int i=1; i<=maxplayers; ++i) ds@1952: { ds@1952: CPlayer *pPlayer = g_Players.GetPlayerByIndex(i); ds@1952: if ((pPlayer->IsConnected()) && !(pPlayer->IsInGame())) ds@1952: { ds@1952: count++; ds@1952: } ds@1952: } ds@1952: ds@1952: return (g_Players.NumPlayers() + count); ds@1952: } ds@1952: ds@1952: static cell_t sm_GetMaxClients(IPluginContext *pCtx, const cell_t *params) ds@1952: { ds@1952: return g_Players.MaxClients(); ds@1952: } ds@1952: ds@1952: static cell_t sm_GetClientName(IPluginContext *pCtx, const cell_t *params) ds@1952: { ds@1952: int index = params[1]; ds@1952: ds@1952: if (index == 0) ds@1952: { ds@1952: static ConVar *hostname = NULL; ds@1952: if (!hostname) ds@1952: { ds@1952: hostname = icvar->FindVar("hostname"); ds@1952: if (!hostname) ds@1952: { ds@1952: return pCtx->ThrowNativeError("Could not find \"hostname\" cvar"); ds@1952: } ds@1952: } ds@1952: pCtx->StringToLocalUTF8(params[2], static_cast(params[3]), hostname->GetString(), NULL); ds@1952: return 1; ds@1952: } ds@1952: ds@1952: if ((index < 1) || (index > g_Players.GetMaxClients())) ds@1952: { ds@1952: return pCtx->ThrowNativeError("Client index %d is invalid", index); ds@1952: } ds@1952: ds@1952: CPlayer *pPlayer = g_Players.GetPlayerByIndex(index); ds@1952: if (!pPlayer->IsConnected()) ds@1952: { ds@1952: return pCtx->ThrowNativeError("Client %d is not connected", index); ds@1952: } ds@1952: ds@1952: pCtx->StringToLocalUTF8(params[2], static_cast(params[3]), pPlayer->GetName(), NULL); ds@1952: return 1; ds@1952: } ds@1952: ds@1952: static cell_t sm_GetClientIP(IPluginContext *pCtx, const cell_t *params) ds@1952: { ds@1952: int index = params[1]; ds@1952: if ((index < 1) || (index > g_Players.GetMaxClients())) ds@1952: { ds@1952: return pCtx->ThrowNativeError("Client index %d is invalid", index); ds@1952: } ds@1952: ds@1952: CPlayer *pPlayer = g_Players.GetPlayerByIndex(index); ds@1952: if (!pPlayer->IsConnected()) ds@1952: { ds@1952: return pCtx->ThrowNativeError("Client %d is not connected", index); ds@1952: } ds@1952: ds@1952: char buf[64], *ptr; ds@1952: strcpy(buf, pPlayer->GetIPAddress()); ds@1952: ds@1952: if (params[4] && (ptr = strchr(buf, ':'))) ds@1952: { ds@1952: *ptr = '\0'; ds@1952: } ds@1952: ds@1952: pCtx->StringToLocal(params[2], static_cast(params[3]), buf); ds@1952: return 1; ds@1952: } ds@1952: ds@1952: static cell_t sm_GetClientAuthStr(IPluginContext *pCtx, const cell_t *params) ds@1952: { ds@1952: int index = params[1]; ds@1952: if ((index < 1) || (index > g_Players.GetMaxClients())) ds@1952: { ds@1952: return pCtx->ThrowNativeError("Client index %d is invalid", index); ds@1952: } ds@1952: ds@1952: CPlayer *pPlayer = g_Players.GetPlayerByIndex(index); ds@1952: if (!pPlayer->IsConnected()) ds@1952: { ds@1952: return pCtx->ThrowNativeError("Client %d is not connected", index); ds@1952: } ds@1952: ds@1952: if (!pPlayer->IsAuthorized()) ds@1952: { ds@1952: return 0; ds@1952: } ds@1952: ds@1952: pCtx->StringToLocal(params[2], static_cast(params[3]), pPlayer->GetAuthString()); ds@1952: ds@1952: return 1; ds@1952: } ds@1952: ds@1952: static cell_t sm_IsClientConnected(IPluginContext *pCtx, const cell_t *params) ds@1952: { ds@1952: int index = params[1]; ds@1952: if ((index < 1) || (index > g_Players.GetMaxClients())) ds@1952: { ds@1952: return pCtx->ThrowNativeError("Client index %d is invalid", index); ds@1952: } ds@1952: ds@1952: return (g_Players.GetPlayerByIndex(index)->IsConnected()) ? 1 : 0; ds@1952: } ds@1952: ds@1952: static cell_t sm_IsClientInGame(IPluginContext *pCtx, const cell_t *params) ds@1952: { ds@1952: int index = params[1]; ds@1952: if ((index < 1) || (index > g_Players.GetMaxClients())) ds@1952: { ds@1952: return pCtx->ThrowNativeError("Client index %d is invalid", index); ds@1952: } ds@1952: ds@1952: return (g_Players.GetPlayerByIndex(index)->IsInGame()) ? 1 : 0; ds@1952: } ds@1952: ds@1952: static cell_t sm_IsClientAuthorized(IPluginContext *pCtx, const cell_t *params) ds@1952: { ds@1952: int index = params[1]; ds@1952: if ((index < 1) || (index > g_Players.GetMaxClients())) ds@1952: { ds@1952: return pCtx->ThrowNativeError("Client index %d is invalid", index); ds@1952: } ds@1952: ds@1952: return (g_Players.GetPlayerByIndex(index)->IsAuthorized()) ? 1 : 0; ds@1952: } ds@1952: ds@1952: static cell_t sm_IsClientFakeClient(IPluginContext *pCtx, const cell_t *params) ds@1952: { ds@1952: int index = params[1]; ds@1952: if ((index < 1) || (index > g_Players.GetMaxClients())) ds@1952: { ds@1952: return pCtx->ThrowNativeError("Client index %d is invalid", index); ds@1952: } ds@1952: ds@1952: CPlayer *pPlayer = g_Players.GetPlayerByIndex(index); ds@1952: if (!pPlayer->IsConnected()) ds@1952: { ds@1952: return pCtx->ThrowNativeError("Client %d is not connected", index); ds@1952: } ds@1952: ds@1952: return (pPlayer->IsFakeClient()) ? 1 : 0; ds@1952: } ds@1952: ds@1952: static cell_t IsClientObserver(IPluginContext *pContext, const cell_t *params) ds@1952: { ds@1952: int client = params[1]; ds@1952: ds@1952: CPlayer *pPlayer = g_Players.GetPlayerByIndex(client); ds@1952: if (!pPlayer) ds@1952: { ds@1952: return pContext->ThrowNativeError("Client index %d is invalid", client); ds@1952: } else if (!pPlayer->IsInGame()) { ds@1952: return pContext->ThrowNativeError("Client %d is not in game", client); ds@1952: } ds@1952: ds@1952: IPlayerInfo *pInfo = pPlayer->GetPlayerInfo(); ds@1952: if (!pInfo) ds@1952: { ds@1952: return pContext->ThrowNativeError("IPlayerInfo not supported by game"); ds@1952: } ds@1952: ds@1952: return pInfo->IsObserver() ? 1 : 0; ds@1952: } ds@1952: ds@1952: static cell_t sm_GetClientInfo(IPluginContext *pContext, const cell_t *params) ds@1952: { ds@1952: int client = params[1]; ds@1952: CPlayer *pPlayer = g_Players.GetPlayerByIndex(client); ds@1952: if (!pPlayer) ds@1952: { ds@1952: return pContext->ThrowNativeError("Client index %d is invalid", client); ds@1952: } ds@1952: if (!pPlayer->IsConnected()) ds@1952: { ds@1952: return pContext->ThrowNativeError("Client %d is not connected", client); ds@1952: } ds@1952: ds@1952: char *key; ds@1952: pContext->LocalToString(params[2], &key); ds@1952: ds@1952: const char *val = engine->GetClientConVarValue(client, key); ds@1952: if (!val) ds@1952: { ds@1952: return false; ds@1952: } ds@1952: ds@1952: pContext->StringToLocalUTF8(params[3], params[4], val, NULL); ds@1952: return 1; ds@1952: } ds@1952: ds@1952: static cell_t SetUserAdmin(IPluginContext *pContext, const cell_t *params) ds@1952: { ds@1952: int client = params[1]; ds@1952: CPlayer *pPlayer = g_Players.GetPlayerByIndex(client); ds@1952: if (!pPlayer) ds@1952: { ds@1952: return pContext->ThrowNativeError("Client index %d is invalid", client); ds@1952: } ds@1952: if (!pPlayer->IsConnected()) ds@1952: { ds@1952: return pContext->ThrowNativeError("Client %d is not connected", client); ds@1952: } ds@1952: if (!g_Admins.IsValidAdmin(params[2]) && params[2] != INVALID_ADMIN_ID) ds@1952: { ds@1952: return pContext->ThrowNativeError("AdminId %x is invalid", params[2]); ds@1952: } ds@1952: ds@1952: pPlayer->SetAdminId(params[2], params[3] ? true : false); ds@1952: ds@1952: return 1; ds@1952: } ds@1952: ds@1952: static cell_t GetUserAdmin(IPluginContext *pContext, const cell_t *params) ds@1952: { ds@1952: int client = params[1]; ds@1952: CPlayer *pPlayer = g_Players.GetPlayerByIndex(client); ds@1952: if (!pPlayer) ds@1952: { ds@1952: return pContext->ThrowNativeError("Client index %d is invalid", client); ds@1952: } ds@1952: if (!pPlayer->IsConnected()) ds@1952: { ds@1952: return pContext->ThrowNativeError("Client %d is not connected", client); ds@1952: } ds@1952: ds@1952: return pPlayer->GetAdminId(); ds@1952: } ds@1952: ds@1952: static cell_t AddUserFlags(IPluginContext *pContext, const cell_t *params) ds@1952: { ds@1952: int client = params[1]; ds@1952: CPlayer *pPlayer = g_Players.GetPlayerByIndex(client); ds@1952: if (!pPlayer) ds@1952: { ds@1952: return pContext->ThrowNativeError("Client index %d is invalid", client); ds@1952: } ds@1952: if (!pPlayer->IsConnected()) ds@1952: { ds@1952: return pContext->ThrowNativeError("Client %d is not connected", client); ds@1952: } ds@1952: ds@1952: AdminId id; ds@1952: if ((id=pPlayer->GetAdminId()) == INVALID_ADMIN_ID) ds@1952: { ds@1952: id = g_Admins.CreateAdmin(NULL); ds@1952: pPlayer->SetAdminId(id, true); ds@1952: } ds@1952: ds@1952: cell_t *addr; ds@1952: for (int i=2; i<=params[0]; i++) ds@1952: { ds@1952: pContext->LocalToPhysAddr(params[i], &addr); ds@1952: g_Admins.SetAdminFlag(id, (AdminFlag)*addr, true); ds@1952: } ds@1952: ds@1952: return 1; ds@1952: } ds@1952: ds@1952: static cell_t RemoveUserFlags(IPluginContext *pContext, const cell_t *params) ds@1952: { ds@1952: int client = params[1]; ds@1952: CPlayer *pPlayer = g_Players.GetPlayerByIndex(client); ds@1952: if (!pPlayer) ds@1952: { ds@1952: return pContext->ThrowNativeError("Client index %d is invalid", client); ds@1952: } ds@1952: if (!pPlayer->IsConnected()) ds@1952: { ds@1952: return pContext->ThrowNativeError("Client %d is not connected", client); ds@1952: } ds@1952: ds@1952: AdminId id; ds@1952: if ((id=pPlayer->GetAdminId()) == INVALID_ADMIN_ID) ds@1952: { ds@1952: return 0; ds@1952: } ds@1952: ds@1952: cell_t *addr; ds@1952: for (int i=2; i<=params[0]; i++) ds@1952: { ds@1952: pContext->LocalToPhysAddr(params[i], &addr); ds@1952: g_Admins.SetAdminFlag(id, (AdminFlag)*addr, false); ds@1952: } ds@1952: ds@1952: return 1; ds@1952: } ds@1952: ds@1952: static cell_t SetUserFlagBits(IPluginContext *pContext, const cell_t *params) ds@1952: { ds@1952: int client = params[1]; ds@1952: CPlayer *pPlayer = g_Players.GetPlayerByIndex(client); ds@1952: if (!pPlayer) ds@1952: { ds@1952: return pContext->ThrowNativeError("Client index %d is invalid", client); ds@1952: } ds@1952: if (!pPlayer->IsConnected()) ds@1952: { ds@1952: return pContext->ThrowNativeError("Client %d is not connected", client); ds@1952: } ds@1952: ds@1952: AdminId id; ds@1952: if ((id=pPlayer->GetAdminId()) == INVALID_ADMIN_ID) ds@1952: { ds@1952: id = g_Admins.CreateAdmin(NULL); ds@1952: pPlayer->SetAdminId(id, true); ds@1952: } ds@1952: ds@1952: g_Admins.SetAdminFlags(id, Access_Effective, params[2]); ds@1952: ds@1952: return 1; ds@1952: } ds@1952: ds@1952: static cell_t GetUserFlagBits(IPluginContext *pContext, const cell_t *params) ds@1952: { ds@1952: int client = params[1]; ds@1952: CPlayer *pPlayer = g_Players.GetPlayerByIndex(client); ds@1952: if (!pPlayer) ds@1952: { ds@1952: return pContext->ThrowNativeError("Client index %d is invalid", client); ds@1952: } ds@1952: if (!pPlayer->IsConnected()) ds@1952: { ds@1952: return pContext->ThrowNativeError("Client %d is not connected", client); ds@1952: } ds@1952: ds@1952: AdminId id; ds@1952: if ((id=pPlayer->GetAdminId()) == INVALID_ADMIN_ID) ds@1952: { ds@1952: return 0; ds@1952: } ds@1952: ds@1952: return g_Admins.GetAdminFlags(id, Access_Effective); ds@1952: } ds@1952: ds@1952: static cell_t GetClientUserId(IPluginContext *pContext, const cell_t *params) ds@1952: { ds@1952: int client = params[1]; ds@1952: CPlayer *pPlayer = g_Players.GetPlayerByIndex(client); ds@1952: if (!pPlayer) ds@1952: { ds@1952: return pContext->ThrowNativeError("Client index %d is invalid", client); ds@1952: } ds@1952: if (!pPlayer->IsConnected()) ds@1952: { ds@1952: return pContext->ThrowNativeError("Client %d is not connected", client); ds@1952: } ds@1952: ds@1952: return engine->GetPlayerUserId(pPlayer->GetEdict()); ds@1952: } ds@1952: ds@1952: static cell_t CanUserTarget(IPluginContext *pContext, const cell_t *params) ds@1952: { ds@1952: int client = params[1]; ds@1952: int target = params[2]; ds@1952: ds@1952: if (client == 0) ds@1952: { ds@1952: return 1; ds@1952: } ds@1952: ds@1952: CPlayer *pPlayer = g_Players.GetPlayerByIndex(client); ds@1952: if (!pPlayer) ds@1952: { ds@1952: return pContext->ThrowNativeError("Client index %d is invalid", client); ds@1952: } else if (!pPlayer->IsConnected()) { ds@1952: return pContext->ThrowNativeError("Client %d is not connected", client); ds@1952: } ds@1952: ds@1952: CPlayer *pTarget = g_Players.GetPlayerByIndex(target); ds@1952: if (!pTarget) ds@1952: { ds@1952: return pContext->ThrowNativeError("Client index %d is invalid", target); ds@1952: } else if (!pTarget->IsConnected()) { ds@1952: return pContext->ThrowNativeError("Client %d is not connected", target); ds@1952: } ds@1952: ds@1952: return g_Admins.CanAdminTarget(pPlayer->GetAdminId(), pTarget->GetAdminId()) ? 1 : 0; ds@1952: } ds@1952: ds@1952: static cell_t GetClientTeam(IPluginContext *pContext, const cell_t *params) ds@1952: { ds@1952: int client = params[1]; ds@1952: ds@1952: CPlayer *pPlayer = g_Players.GetPlayerByIndex(client); ds@1952: if (!pPlayer) ds@1952: { ds@1952: return pContext->ThrowNativeError("Client index %d is invalid", client); ds@1952: } else if (!pPlayer->IsInGame()) { ds@1952: return pContext->ThrowNativeError("Client %d is not in game", client); ds@1952: } ds@1952: ds@1952: IPlayerInfo *pInfo = pPlayer->GetPlayerInfo(); ds@1952: if (!pInfo) ds@1952: { ds@1952: return pContext->ThrowNativeError("IPlayerInfo not supported by game"); ds@1952: } ds@1952: ds@1952: return pInfo->GetTeamIndex(); ds@1952: } ds@1952: ds@1952: static cell_t GetFragCount(IPluginContext *pContext, const cell_t *params) ds@1952: { ds@1952: int client = params[1]; ds@1952: ds@1952: CPlayer *pPlayer = g_Players.GetPlayerByIndex(client); ds@1952: if (!pPlayer) ds@1952: { ds@1952: return pContext->ThrowNativeError("Client index %d is invalid", client); ds@1952: } else if (!pPlayer->IsInGame()) { ds@1952: return pContext->ThrowNativeError("Client %d is not in game", client); ds@1952: } ds@1952: ds@1952: IPlayerInfo *pInfo = pPlayer->GetPlayerInfo(); ds@1952: if (!pInfo) ds@1952: { ds@1952: return pContext->ThrowNativeError("IPlayerInfo not supported by game"); ds@1952: } ds@1952: ds@1952: return pInfo->GetFragCount(); ds@1952: } ds@1952: ds@1952: static cell_t GetDeathCount(IPluginContext *pContext, const cell_t *params) ds@1952: { ds@1952: int client = params[1]; ds@1952: ds@1952: CPlayer *pPlayer = g_Players.GetPlayerByIndex(client); ds@1952: if (!pPlayer) ds@1952: { ds@1952: return pContext->ThrowNativeError("Client index %d is invalid", client); ds@1952: } else if (!pPlayer->IsInGame()) { ds@1952: return pContext->ThrowNativeError("Client %d is not in game", client); ds@1952: } ds@1952: ds@1952: IPlayerInfo *pInfo = pPlayer->GetPlayerInfo(); ds@1952: if (!pInfo) ds@1952: { ds@1952: return pContext->ThrowNativeError("IPlayerInfo not supported by game"); ds@1952: } ds@1952: ds@1952: return pInfo->GetDeathCount(); ds@1952: } ds@1952: ds@1952: static cell_t GetArmorValue(IPluginContext *pContext, const cell_t *params) ds@1952: { ds@1952: int client = params[1]; ds@1952: ds@1952: CPlayer *pPlayer = g_Players.GetPlayerByIndex(client); ds@1952: if (!pPlayer) ds@1952: { ds@1952: return pContext->ThrowNativeError("Client index %d is invalid", client); ds@1952: } else if (!pPlayer->IsInGame()) { ds@1952: return pContext->ThrowNativeError("Client %d is not in game", client); ds@1952: } ds@1952: ds@1952: IPlayerInfo *pInfo = pPlayer->GetPlayerInfo(); ds@1952: if (!pInfo) ds@1952: { ds@1952: return pContext->ThrowNativeError("IPlayerInfo not supported by game"); ds@1952: } ds@1952: ds@1952: return pInfo->GetArmorValue(); ds@1952: } ds@1952: ds@1952: static cell_t GetAbsOrigin(IPluginContext *pContext, const cell_t *params) ds@1952: { ds@1952: int client = params[1]; ds@1952: ds@1952: CPlayer *pPlayer = g_Players.GetPlayerByIndex(client); ds@1952: if (!pPlayer) ds@1952: { ds@1952: return pContext->ThrowNativeError("Client index %d is invalid", client); ds@1952: } else if (!pPlayer->IsInGame()) { ds@1952: return pContext->ThrowNativeError("Client %d is not in game", client); ds@1952: } ds@1952: ds@1952: IPlayerInfo *pInfo = pPlayer->GetPlayerInfo(); ds@1952: if (!pInfo) ds@1952: { ds@1952: return pContext->ThrowNativeError("IPlayerInfo not supported by game"); ds@1952: } ds@1952: ds@1952: cell_t *pVec; ds@1952: pContext->LocalToPhysAddr(params[2], &pVec); ds@1952: ds@1952: Vector vec = pInfo->GetAbsOrigin(); ds@1952: pVec[0] = sp_ftoc(vec.x); ds@1952: pVec[1] = sp_ftoc(vec.y); ds@1952: pVec[2] = sp_ftoc(vec.z); ds@1952: ds@1952: return 1; ds@1952: } ds@1952: ds@1952: static cell_t GetAbsAngles(IPluginContext *pContext, const cell_t *params) ds@1952: { ds@1952: int client = params[1]; ds@1952: ds@1952: CPlayer *pPlayer = g_Players.GetPlayerByIndex(client); ds@1952: if (!pPlayer) ds@1952: { ds@1952: return pContext->ThrowNativeError("Client index %d is invalid", client); ds@1952: } else if (!pPlayer->IsInGame()) { ds@1952: return pContext->ThrowNativeError("Client %d is not in game", client); ds@1952: } ds@1952: ds@1952: IPlayerInfo *pInfo = pPlayer->GetPlayerInfo(); ds@1952: if (!pInfo) ds@1952: { ds@1952: return pContext->ThrowNativeError("IPlayerInfo not supported by game"); ds@1952: } ds@1952: ds@1952: cell_t *pAng; ds@1952: pContext->LocalToPhysAddr(params[2], &pAng); ds@1952: ds@1952: QAngle ang = pInfo->GetAbsAngles(); ds@1952: pAng[0] = sp_ftoc(ang.x); ds@1952: pAng[1] = sp_ftoc(ang.y); ds@1952: pAng[2] = sp_ftoc(ang.z); ds@1952: ds@1952: return 1; ds@1952: } ds@1952: ds@1952: static cell_t GetPlayerMins(IPluginContext *pContext, const cell_t *params) ds@1952: { ds@1952: int client = params[1]; ds@1952: ds@1952: CPlayer *pPlayer = g_Players.GetPlayerByIndex(client); ds@1952: if (!pPlayer) ds@1952: { ds@1952: return pContext->ThrowNativeError("Client index %d is invalid", client); ds@1952: } else if (!pPlayer->IsInGame()) { ds@1952: return pContext->ThrowNativeError("Client %d is not in game", client); ds@1952: } ds@1952: ds@1952: IPlayerInfo *pInfo = pPlayer->GetPlayerInfo(); ds@1952: if (!pInfo) ds@1952: { ds@1952: return pContext->ThrowNativeError("IPlayerInfo not supported by game"); ds@1952: } ds@1952: ds@1952: cell_t *pVec; ds@1952: pContext->LocalToPhysAddr(params[2], &pVec); ds@1952: ds@1952: Vector vec = pInfo->GetPlayerMins(); ds@1952: pVec[0] = sp_ftoc(vec.x); ds@1952: pVec[1] = sp_ftoc(vec.y); ds@1952: pVec[2] = sp_ftoc(vec.z); ds@1952: ds@1952: return 1; ds@1952: } ds@1952: ds@1952: static cell_t GetPlayerMaxs(IPluginContext *pContext, const cell_t *params) ds@1952: { ds@1952: int client = params[1]; ds@1952: ds@1952: CPlayer *pPlayer = g_Players.GetPlayerByIndex(client); ds@1952: if (!pPlayer) ds@1952: { ds@1952: return pContext->ThrowNativeError("Client index %d is invalid", client); ds@1952: } else if (!pPlayer->IsInGame()) { ds@1952: return pContext->ThrowNativeError("Client %d is not in game", client); ds@1952: } ds@1952: ds@1952: IPlayerInfo *pInfo = pPlayer->GetPlayerInfo(); ds@1952: if (!pInfo) ds@1952: { ds@1952: return pContext->ThrowNativeError("IPlayerInfo not supported by game"); ds@1952: } ds@1952: ds@1952: cell_t *pVec; ds@1952: pContext->LocalToPhysAddr(params[2], &pVec); ds@1952: ds@1952: Vector vec = pInfo->GetPlayerMaxs(); ds@1952: pVec[0] = sp_ftoc(vec.x); ds@1952: pVec[1] = sp_ftoc(vec.y); ds@1952: pVec[2] = sp_ftoc(vec.z); ds@1952: ds@1952: return 1; ds@1952: } ds@1952: ds@1952: static cell_t GetWeaponName(IPluginContext *pContext, const cell_t *params) ds@1952: { ds@1952: int client = params[1]; ds@1952: ds@1952: CPlayer *pPlayer = g_Players.GetPlayerByIndex(client); ds@1952: if (!pPlayer) ds@1952: { ds@1952: return pContext->ThrowNativeError("Client index %d is invalid", client); ds@1952: } else if (!pPlayer->IsInGame()) { ds@1952: return pContext->ThrowNativeError("Client %d is not in game", client); ds@1952: } ds@1952: ds@1952: IPlayerInfo *pInfo = pPlayer->GetPlayerInfo(); ds@1952: if (!pInfo) ds@1952: { ds@1952: return pContext->ThrowNativeError("IPlayerInfo not supported by game"); ds@1952: } ds@1952: ds@1952: const char *weapon = pInfo->GetWeaponName(); ds@1952: pContext->StringToLocalUTF8(params[2], static_cast(params[3]), weapon ? weapon : "", NULL); ds@1952: ds@1952: return 1; ds@1952: } ds@1952: ds@1952: static cell_t GetModelName(IPluginContext *pContext, const cell_t *params) ds@1952: { ds@1952: int client = params[1]; ds@1952: ds@1952: CPlayer *pPlayer = g_Players.GetPlayerByIndex(client); ds@1952: if (!pPlayer) ds@1952: { ds@1952: return pContext->ThrowNativeError("Client index %d is invalid", client); ds@1952: } else if (!pPlayer->IsInGame()) { ds@1952: return pContext->ThrowNativeError("Client %d is not in game", client); ds@1952: } ds@1952: ds@1952: IPlayerInfo *pInfo = pPlayer->GetPlayerInfo(); ds@1952: if (!pInfo) ds@1952: { ds@1952: return pContext->ThrowNativeError("IPlayerInfo not supported by game"); ds@1952: } ds@1952: ds@1952: const char *model = pInfo->GetModelName(); ds@1952: pContext->StringToLocalUTF8(params[2], static_cast(params[3]), model ? model : "", NULL); ds@1952: ds@1952: return 1; ds@1952: } ds@1952: ds@1952: static cell_t GetHealth(IPluginContext *pContext, const cell_t *params) ds@1952: { ds@1952: int client = params[1]; ds@1952: ds@1952: CPlayer *pPlayer = g_Players.GetPlayerByIndex(client); ds@1952: if (!pPlayer) ds@1952: { ds@1952: return pContext->ThrowNativeError("Client index %d is invalid", client); ds@1952: } else if (!pPlayer->IsInGame()) { ds@1952: return pContext->ThrowNativeError("Client %d is not in game", client); ds@1952: } ds@1952: ds@1952: IPlayerInfo *pInfo = pPlayer->GetPlayerInfo(); ds@1952: if (!pInfo) ds@1952: { ds@1952: return pContext->ThrowNativeError("IPlayerInfo not supported by game"); ds@1952: } ds@1952: ds@1952: return pInfo->GetHealth(); ds@1952: } ds@1952: ds@1952: static cell_t GetTimeConnected(IPluginContext *pContext, const cell_t *params) ds@1952: { ds@1952: int client = params[1]; ds@1952: ds@1952: CPlayer *pPlayer = g_Players.GetPlayerByIndex(client); ds@1952: if (!pPlayer) ds@1952: { ds@1952: return pContext->ThrowNativeError("Client index %d is invalid", client); ds@1952: } else if (!pPlayer->IsInGame()) { ds@1952: return pContext->ThrowNativeError("Client %d is not in game", client); ds@1952: } else if (pPlayer->IsFakeClient()) { ds@1952: return pContext->ThrowNativeError("Client %d is a bot", client); ds@1952: } ds@1952: ds@1952: INetChannelInfo *pInfo = engine->GetPlayerNetInfo(client); ds@1952: ds@1952: return sp_ftoc(pInfo->GetTimeConnected()); ds@1952: } ds@1952: ds@1952: static cell_t GetDataRate(IPluginContext *pContext, const cell_t *params) ds@1952: { ds@1952: int client = params[1]; ds@1952: ds@1952: CPlayer *pPlayer = g_Players.GetPlayerByIndex(client); ds@1952: if (!pPlayer) ds@1952: { ds@1952: return pContext->ThrowNativeError("Client index %d is invalid", client); ds@1952: } else if (!pPlayer->IsInGame()) { ds@1952: return pContext->ThrowNativeError("Client %d is not in game", client); ds@1952: } else if (pPlayer->IsFakeClient()) { ds@1952: return pContext->ThrowNativeError("Client %d is a bot", client); ds@1952: } ds@1952: ds@1952: INetChannelInfo *pInfo = engine->GetPlayerNetInfo(client); ds@1952: ds@1952: return pInfo->GetDataRate(); ds@1952: } ds@1952: ds@1952: static cell_t IsTimingOut(IPluginContext *pContext, const cell_t *params) ds@1952: { ds@1952: int client = params[1]; ds@1952: ds@1952: CPlayer *pPlayer = g_Players.GetPlayerByIndex(client); ds@1952: if (!pPlayer) ds@1952: { ds@1952: return pContext->ThrowNativeError("Client index %d is invalid", client); ds@1952: } else if (!pPlayer->IsInGame()) { ds@1952: return pContext->ThrowNativeError("Client %d is not in game", client); ds@1952: } else if (pPlayer->IsFakeClient()) { ds@1952: return pContext->ThrowNativeError("Client %d is a bot", client); ds@1952: } ds@1952: ds@1952: INetChannelInfo *pInfo = engine->GetPlayerNetInfo(client); ds@1952: ds@1952: return pInfo->IsTimingOut() ? 1 : 0; ds@1952: } ds@1952: ds@1952: static cell_t GetLatency(IPluginContext *pContext, const cell_t *params) ds@1952: { ds@1952: int client = params[1]; dvander@2054: float value; ds@1952: ds@1952: CPlayer *pPlayer = g_Players.GetPlayerByIndex(client); ds@1952: if (!pPlayer) ds@1952: { ds@1952: return pContext->ThrowNativeError("Client index %d is invalid", client); dvander@2054: } dvander@2054: else if (!pPlayer->IsInGame()) dvander@2054: { ds@1952: return pContext->ThrowNativeError("Client %d is not in game", client); dvander@2054: } dvander@2054: else if (pPlayer->IsFakeClient()) dvander@2054: { ds@1952: return pContext->ThrowNativeError("Client %d is a bot", client); ds@1952: } ds@1952: ds@1952: INetChannelInfo *pInfo = engine->GetPlayerNetInfo(client); ds@1952: dvander@2054: if (params[2] == MAX_FLOWS) dvander@2054: { dvander@2054: value = pInfo->GetLatency(FLOW_INCOMING) + pInfo->GetLatency(FLOW_OUTGOING); dvander@2054: } dvander@2054: else dvander@2054: { dvander@2054: value = pInfo->GetLatency(params[2]); dvander@2054: } dvander@2054: dvander@2054: return sp_ftoc(value); ds@1952: } ds@1952: ds@1952: static cell_t GetAvgLatency(IPluginContext *pContext, const cell_t *params) ds@1952: { ds@1952: int client = params[1]; dvander@2054: float value; ds@1952: ds@1952: CPlayer *pPlayer = g_Players.GetPlayerByIndex(client); ds@1952: if (!pPlayer) ds@1952: { ds@1952: return pContext->ThrowNativeError("Client index %d is invalid", client); dvander@2054: } dvander@2054: else if (!pPlayer->IsInGame()) dvander@2054: { ds@1952: return pContext->ThrowNativeError("Client %d is not in game", client); dvander@2054: } dvander@2054: else if (pPlayer->IsFakeClient()) dvander@2054: { ds@1952: return pContext->ThrowNativeError("Client %d is a bot", client); ds@1952: } ds@1952: ds@1952: INetChannelInfo *pInfo = engine->GetPlayerNetInfo(client); ds@1952: dvander@2054: if (params[2] == MAX_FLOWS) dvander@2054: { dvander@2054: value = pInfo->GetAvgLatency(FLOW_INCOMING) + pInfo->GetAvgLatency(FLOW_OUTGOING); dvander@2054: } dvander@2054: else dvander@2054: { dvander@2054: value = pInfo->GetAvgLatency(params[2]); dvander@2054: } dvander@2054: dvander@2054: return sp_ftoc(value); ds@1952: } ds@1952: ds@1952: static cell_t GetAvgLoss(IPluginContext *pContext, const cell_t *params) ds@1952: { ds@1952: int client = params[1]; dvander@2054: float value; ds@1952: ds@1952: CPlayer *pPlayer = g_Players.GetPlayerByIndex(client); ds@1952: if (!pPlayer) ds@1952: { ds@1952: return pContext->ThrowNativeError("Client index %d is invalid", client); dvander@2054: } dvander@2054: else if (!pPlayer->IsInGame()) dvander@2054: { ds@1952: return pContext->ThrowNativeError("Client %d is not in game", client); dvander@2054: } dvander@2054: else if (pPlayer->IsFakeClient()) dvander@2054: { ds@1952: return pContext->ThrowNativeError("Client %d is a bot", client); ds@1952: } ds@1952: ds@1952: INetChannelInfo *pInfo = engine->GetPlayerNetInfo(client); ds@1952: dvander@2054: if (params[2] == MAX_FLOWS) dvander@2054: { dvander@2054: value = pInfo->GetAvgLoss(FLOW_INCOMING) + pInfo->GetAvgLoss(FLOW_OUTGOING); dvander@2054: } dvander@2054: else dvander@2054: { dvander@2054: value = pInfo->GetAvgLoss(params[2]); dvander@2054: } dvander@2054: dvander@2054: return sp_ftoc(value); ds@1952: } ds@1952: ds@1952: static cell_t GetAvgChoke(IPluginContext *pContext, const cell_t *params) ds@1952: { ds@1952: int client = params[1]; dvander@2054: float value; ds@1952: ds@1952: CPlayer *pPlayer = g_Players.GetPlayerByIndex(client); ds@1952: if (!pPlayer) ds@1952: { ds@1952: return pContext->ThrowNativeError("Client index %d is invalid", client); dvander@2054: } dvander@2054: else if (!pPlayer->IsInGame()) dvander@2054: { ds@1952: return pContext->ThrowNativeError("Client %d is not in game", client); dvander@2054: } dvander@2054: else if (pPlayer->IsFakeClient()) dvander@2054: { ds@1952: return pContext->ThrowNativeError("Client %d is a bot", client); ds@1952: } ds@1952: ds@1952: INetChannelInfo *pInfo = engine->GetPlayerNetInfo(client); ds@1952: dvander@2054: if (params[2] == MAX_FLOWS) dvander@2054: { dvander@2054: value = pInfo->GetAvgChoke(FLOW_INCOMING) + pInfo->GetAvgChoke(FLOW_OUTGOING); dvander@2054: } dvander@2054: else dvander@2054: { dvander@2054: value = pInfo->GetAvgChoke(params[2]); dvander@2054: } dvander@2054: dvander@2054: return sp_ftoc(value); ds@1952: } ds@1952: ds@1952: static cell_t GetAvgData(IPluginContext *pContext, const cell_t *params) ds@1952: { ds@1952: int client = params[1]; dvander@2054: float value; ds@1952: ds@1952: CPlayer *pPlayer = g_Players.GetPlayerByIndex(client); ds@1952: if (!pPlayer) ds@1952: { ds@1952: return pContext->ThrowNativeError("Client index %d is invalid", client); dvander@2054: } dvander@2054: else if (!pPlayer->IsInGame()) dvander@2054: { ds@1952: return pContext->ThrowNativeError("Client %d is not in game", client); dvander@2054: } dvander@2054: else if (pPlayer->IsFakeClient()) dvander@2054: { ds@1952: return pContext->ThrowNativeError("Client %d is a bot", client); ds@1952: } ds@1952: ds@1952: INetChannelInfo *pInfo = engine->GetPlayerNetInfo(client); ds@1952: dvander@2054: if (params[2] == MAX_FLOWS) dvander@2054: { dvander@2054: value = pInfo->GetAvgData(FLOW_INCOMING) + pInfo->GetAvgData(FLOW_OUTGOING); dvander@2054: } dvander@2054: else dvander@2054: { dvander@2054: value = pInfo->GetAvgData(params[2]); dvander@2054: } dvander@2054: dvander@2054: return sp_ftoc(value); ds@1952: } ds@1952: ds@1952: static cell_t GetAvgPackets(IPluginContext *pContext, const cell_t *params) ds@1952: { ds@1952: int client = params[1]; dvander@2054: float value; ds@1952: ds@1952: CPlayer *pPlayer = g_Players.GetPlayerByIndex(client); ds@1952: if (!pPlayer) ds@1952: { ds@1952: return pContext->ThrowNativeError("Client index %d is invalid", client); dvander@2054: } dvander@2054: else if (!pPlayer->IsInGame()) dvander@2054: { ds@1952: return pContext->ThrowNativeError("Client %d is not in game", client); dvander@2054: } dvander@2054: else if (pPlayer->IsFakeClient()) dvander@2054: { ds@1952: return pContext->ThrowNativeError("Client %d is a bot", client); ds@1952: } ds@1952: ds@1952: INetChannelInfo *pInfo = engine->GetPlayerNetInfo(client); ds@1952: dvander@2054: if (params[2] == MAX_FLOWS) dvander@2054: { dvander@2054: value = pInfo->GetAvgPackets(FLOW_INCOMING) + pInfo->GetAvgPackets(FLOW_OUTGOING); dvander@2054: } dvander@2054: else dvander@2054: { dvander@2054: value = pInfo->GetAvgPackets(params[2]); dvander@2054: } dvander@2054: dvander@2054: return sp_ftoc(value); ds@1952: } ds@1952: ds@1952: static cell_t GetClientOfUserId(IPluginContext *pContext, const cell_t *params) ds@1952: { ds@1952: return g_Players.GetClientOfUserId(params[1]); ds@1952: } ds@1952: ds@1952: static cell_t _ShowActivity(IPluginContext *pContext, ds@1952: const cell_t *params, ds@1952: const char *tag, ds@1952: cell_t fmt_param) ds@1952: { ds@1952: char message[255]; ds@1952: char buffer[255]; ds@1952: int value = sm_show_activity.GetInt(); ds@1952: unsigned int replyto = g_ChatTriggers.GetReplyTo(); ds@1952: int client = params[1]; ds@1952: ds@1952: const char *name = "Console"; ds@1952: const char *sign = "ADMIN"; ds@1952: bool display_in_chat = false; ds@1952: if (client != 0) ds@1952: { ds@1952: CPlayer *pPlayer = g_Players.GetPlayerByIndex(client); ds@1952: if (!pPlayer || !pPlayer->IsConnected()) ds@1952: { ds@1952: return pContext->ThrowNativeError("Client index %d is invalid", client); ds@1952: } ds@1952: name = pPlayer->GetName(); ds@1952: AdminId id = pPlayer->GetAdminId(); ds@1952: if (id == INVALID_ADMIN_ID ds@1952: || !g_Admins.GetAdminFlag(id, Admin_Generic, Access_Effective)) ds@1952: { ds@1952: sign = "PLAYER"; ds@1952: } ds@1952: ds@1952: /* Display the message to the client? */ ds@1952: if (replyto == SM_REPLY_CONSOLE) ds@1952: { ds@1952: g_SourceMod.SetGlobalTarget(client); ds@1952: g_SourceMod.FormatString(buffer, sizeof(buffer), pContext, params, fmt_param); ds@1952: ds@1952: if (pContext->GetContext()->n_err != SP_ERROR_NONE) ds@1952: { ds@1952: return 0; ds@1952: } ds@1952: ds@1952: UTIL_Format(message, sizeof(message), "%s%s\n", tag, buffer); ds@1952: engine->ClientPrintf(pPlayer->GetEdict(), message); ds@1952: display_in_chat = true; ds@1952: } ds@1952: } ds@1952: else ds@1952: { dvander@2042: g_SourceMod.SetGlobalTarget(SOURCEMOD_SERVER_LANGUAGE); ds@1952: g_SourceMod.FormatString(buffer, sizeof(buffer), pContext, params, fmt_param); ds@1952: ds@1952: if (pContext->GetContext()->n_err != SP_ERROR_NONE) ds@1952: { ds@1952: return 0; ds@1952: } ds@1952: ds@1952: UTIL_Format(message, sizeof(message), "%s%s\n", tag, buffer); ds@1952: META_CONPRINT(message); ds@1952: } ds@1952: ds@1952: if (!value) ds@1952: { ds@1952: return 1; ds@1952: } ds@1952: ds@1952: int maxClients = g_Players.GetMaxClients(); ds@1952: for (int i=1; i<=maxClients; i++) ds@1952: { ds@1952: CPlayer *pPlayer = g_Players.GetPlayerByIndex(i); ds@1952: if (!pPlayer->IsInGame() ds@1952: || pPlayer->IsFakeClient() ds@1952: || (display_in_chat && i == client)) ds@1952: { ds@1952: continue; ds@1952: } ds@1952: AdminId id = pPlayer->GetAdminId(); ds@1952: g_SourceMod.SetGlobalTarget(i); ds@1952: if (id == INVALID_ADMIN_ID ds@1952: || !g_Admins.GetAdminFlag(id, Admin_Generic, Access_Effective)) ds@1952: { ds@1952: /* Treat this as a normal user */ ds@1952: if ((value & 1) || (value & 2)) ds@1952: { ds@1952: const char *newsign = sign; ds@1952: if ((value & 2) || (i == client)) ds@1952: { ds@1952: newsign = name; ds@1952: } ds@1952: g_SourceMod.FormatString(buffer, sizeof(buffer), pContext, params, fmt_param); ds@1952: ds@1952: if (pContext->GetContext()->n_err != SP_ERROR_NONE) ds@1952: { ds@1952: return 0; ds@1952: } ds@1952: ds@1952: UTIL_Format(message, sizeof(message), "%s%s: %s", tag, newsign, buffer); ds@1952: g_HL2.TextMsg(i, HUD_PRINTTALK, message); ds@1952: } ds@1952: } ds@1952: else ds@1952: { ds@1952: /* Treat this as an admin user */ ds@1952: bool is_root = g_Admins.GetAdminFlag(id, Admin_Root, Access_Effective); ds@1952: if ((value & 4) ds@1952: || (value & 8) ds@1952: || ((value & 16) && is_root)) ds@1952: { ds@1952: const char *newsign = sign; ds@1952: if ((value & 8) || ((value & 16) && is_root) || (i == client)) ds@1952: { ds@1952: newsign = name; ds@1952: } ds@1952: g_SourceMod.FormatString(buffer, sizeof(buffer), pContext, params, fmt_param); ds@1952: ds@1952: if (pContext->GetContext()->n_err != SP_ERROR_NONE) ds@1952: { ds@1952: return 0; ds@1952: } ds@1952: ds@1952: UTIL_Format(message, sizeof(message), "%s%s: %s", tag, newsign, buffer); ds@1952: g_HL2.TextMsg(i, HUD_PRINTTALK, message); ds@1952: } ds@1952: } ds@1952: } ds@1952: ds@1952: return 1; ds@1952: } ds@1952: ds@1952: static cell_t _ShowActivity2(IPluginContext *pContext, ds@1952: const cell_t *params, ds@1952: const char *tag, ds@1952: cell_t fmt_param) ds@1952: { ds@1952: char message[255]; ds@1952: char buffer[255]; ds@1952: int value = sm_show_activity.GetInt(); ds@1952: unsigned int replyto = g_ChatTriggers.GetReplyTo(); ds@1952: int client = params[1]; ds@1952: ds@1952: const char *name = "Console"; ds@1952: const char *sign = "ADMIN"; ds@1952: if (client != 0) ds@1952: { ds@1952: CPlayer *pPlayer = g_Players.GetPlayerByIndex(client); ds@1952: if (!pPlayer || !pPlayer->IsConnected()) ds@1952: { ds@1952: return pContext->ThrowNativeError("Client index %d is invalid", client); ds@1952: } ds@1952: name = pPlayer->GetName(); ds@1952: AdminId id = pPlayer->GetAdminId(); ds@1952: if (id == INVALID_ADMIN_ID ds@1952: || !g_Admins.GetAdminFlag(id, Admin_Generic, Access_Effective)) ds@1952: { ds@1952: sign = "PLAYER"; ds@1952: } ds@1952: ds@1952: g_SourceMod.SetGlobalTarget(client); ds@1952: g_SourceMod.FormatString(buffer, sizeof(buffer), pContext, params, fmt_param); ds@1952: ds@1952: if (pContext->GetContext()->n_err != SP_ERROR_NONE) ds@1952: { ds@1952: return 0; ds@1952: } ds@1952: ds@1952: /* We don't display directly to the console because the chat text ds@1952: * simply gets added to the console, so we don't want it to print ds@1952: * twice. ds@1952: */ ds@1952: if (replyto == SM_REPLY_CONSOLE) ds@1952: { ds@1952: #if 0 ds@1952: UTIL_Format(message, sizeof(message), "%s%s\n", tag, buffer); ds@1952: engine->ClientPrintf(pPlayer->GetEdict(), message); ds@1952: #endif ds@1952: UTIL_Format(message, sizeof(message), "%s%s", tag, buffer); ds@1952: g_HL2.TextMsg(client, HUD_PRINTTALK, message); ds@1952: } ds@1952: else ds@1952: { ds@1952: UTIL_Format(message, sizeof(message), "%s%s", tag, buffer); ds@1952: g_HL2.TextMsg(client, HUD_PRINTTALK, message); ds@1952: } ds@1952: } ds@1952: else ds@1952: { dvander@2042: g_SourceMod.SetGlobalTarget(SOURCEMOD_SERVER_LANGUAGE); ds@1952: g_SourceMod.FormatString(buffer, sizeof(buffer), pContext, params, fmt_param); ds@1952: ds@1952: if (pContext->GetContext()->n_err != SP_ERROR_NONE) ds@1952: { ds@1952: return 0; ds@1952: } ds@1952: ds@1952: UTIL_Format(message, sizeof(message), "%s%s\n", tag, buffer); ds@1952: META_CONPRINT(message); ds@1952: } ds@1952: ds@1952: if (!value) ds@1952: { ds@1952: return 1; ds@1952: } ds@1952: ds@1952: int maxClients = g_Players.GetMaxClients(); ds@1952: for (int i=1; i<=maxClients; i++) ds@1952: { ds@1952: CPlayer *pPlayer = g_Players.GetPlayerByIndex(i); ds@1952: if (!pPlayer->IsInGame() ds@1952: || pPlayer->IsFakeClient() ds@1952: || i == client) ds@1952: { ds@1952: continue; ds@1952: } ds@1952: AdminId id = pPlayer->GetAdminId(); ds@1952: g_SourceMod.SetGlobalTarget(i); ds@1952: if (id == INVALID_ADMIN_ID ds@1952: || !g_Admins.GetAdminFlag(id, Admin_Generic, Access_Effective)) ds@1952: { ds@1952: /* Treat this as a normal user */ ds@1952: if ((value & 1) || (value & 2)) ds@1952: { ds@1952: const char *newsign = sign; ds@1952: if ((value & 2)) ds@1952: { ds@1952: newsign = name; ds@1952: } ds@1952: g_SourceMod.FormatString(buffer, sizeof(buffer), pContext, params, fmt_param); ds@1952: ds@1952: if (pContext->GetContext()->n_err != SP_ERROR_NONE) ds@1952: { ds@1952: return 0; ds@1952: } ds@1952: ds@1952: UTIL_Format(message, sizeof(message), "%s%s: %s", tag, newsign, buffer); ds@1952: g_HL2.TextMsg(i, HUD_PRINTTALK, message); ds@1952: } ds@1952: } ds@1952: else ds@1952: { ds@1952: /* Treat this as an admin user */ ds@1952: bool is_root = g_Admins.GetAdminFlag(id, Admin_Root, Access_Effective); ds@1952: if ((value & 4) ds@1952: || (value & 8) ds@1952: || ((value & 16) && is_root)) ds@1952: { ds@1952: const char *newsign = sign; ds@1952: if ((value & 8) || ((value & 16) && is_root)) ds@1952: { ds@1952: newsign = name; ds@1952: } ds@1952: g_SourceMod.FormatString(buffer, sizeof(buffer), pContext, params, fmt_param); ds@1952: ds@1952: if (pContext->GetContext()->n_err != SP_ERROR_NONE) ds@1952: { ds@1952: return 0; ds@1952: } ds@1952: ds@1952: UTIL_Format(message, sizeof(message), "%s%s: %s", tag, newsign, buffer); ds@1952: g_HL2.TextMsg(i, HUD_PRINTTALK, message); ds@1952: } ds@1952: } ds@1952: } ds@1952: ds@1952: return 1; ds@1952: } ds@1952: ds@1952: static cell_t ShowActivity(IPluginContext *pContext, const cell_t *params) ds@1952: { ds@1952: return _ShowActivity(pContext, params, "[SM] ", 2); ds@1952: } ds@1952: ds@1952: static cell_t ShowActivityEx(IPluginContext *pContext, const cell_t *params) ds@1952: { ds@1952: char *str; ds@1952: pContext->LocalToString(params[2], &str); ds@1952: ds@1952: return _ShowActivity(pContext, params, str, 3); ds@1952: } ds@1952: ds@1952: static cell_t ShowActivity2(IPluginContext *pContext, const cell_t *params) ds@1952: { ds@1952: char *str; ds@1952: pContext->LocalToString(params[2], &str); ds@1952: ds@1952: return _ShowActivity2(pContext, params, str, 3); ds@1952: } ds@1952: ds@1952: static cell_t KickClient(IPluginContext *pContext, const cell_t *params) ds@1952: { ds@1952: int client = params[1]; ds@1952: ds@1952: CPlayer *pPlayer = g_Players.GetPlayerByIndex(client); ds@1952: if (!pPlayer) ds@1952: { ds@1952: return pContext->ThrowNativeError("Client index %d is invalid", client); ds@1952: } else if (!pPlayer->IsConnected()) { ds@1952: return pContext->ThrowNativeError("Client %d is not connected", client); ds@1952: } ds@1952: ds@1952: pPlayer->MarkAsBeingKicked(); ds@1952: ds@1952: if (pPlayer->IsFakeClient()) ds@1952: { ds@1952: char kickcmd[40]; ds@1952: UTIL_Format(kickcmd, sizeof(kickcmd), "kick %s\n", pPlayer->GetName()); ds@1952: ds@1952: engine->ServerCommand(kickcmd); ds@1952: return 1; ds@1952: } ds@1952: ds@1952: g_SourceMod.SetGlobalTarget(client); ds@1952: ds@1952: char buffer[256]; ds@1952: g_SourceMod.FormatString(buffer, sizeof(buffer), pContext, params, 2); ds@1952: ds@1952: if (pContext->GetContext()->n_err != SP_ERROR_NONE) ds@1952: { ds@1952: return 0; ds@1952: } ds@1952: ds@1952: pPlayer->Kick(buffer); ds@1952: ds@1952: return 1; ds@1952: } ds@1952: ds@1952: static cell_t ChangeClientTeam(IPluginContext *pContext, const cell_t *params) ds@1952: { ds@1952: int client = params[1]; ds@1952: ds@1952: CPlayer *pPlayer = g_Players.GetPlayerByIndex(client); ds@1952: if (!pPlayer) ds@1952: { ds@1952: return pContext->ThrowNativeError("Client index %d is invalid", client); ds@1952: } ds@1952: else if (!pPlayer->IsInGame()) ds@1952: { ds@1952: return pContext->ThrowNativeError("Client %d is not in game", client); ds@1952: } ds@1952: ds@1952: IPlayerInfo *pInfo = pPlayer->GetPlayerInfo(); ds@1952: if (!pInfo) ds@1952: { ds@1952: return pContext->ThrowNativeError("IPlayerInfo not supported by game"); ds@1952: } ds@1952: ds@1952: pInfo->ChangeTeam(params[2]); ds@1952: ds@1952: return 1; ds@1952: } ds@1952: ds@1952: static cell_t RunAdminCacheChecks(IPluginContext *pContext, const cell_t *params) ds@1952: { ds@1952: int client = params[1]; ds@1952: ds@1952: CPlayer *pPlayer = g_Players.GetPlayerByIndex(client); ds@1952: if (!pPlayer) ds@1952: { ds@1952: return pContext->ThrowNativeError("Client index %d is invalid", client); ds@1952: } ds@1952: else if (!pPlayer->IsInGame()) ds@1952: { ds@1952: return pContext->ThrowNativeError("Client %d is not in game", client); ds@1952: } ds@1952: else if (!pPlayer->IsAuthorized()) ds@1952: { ds@1952: return pContext->ThrowNativeError("Client %d is not authorized", client); ds@1952: } ds@1952: ds@1952: AdminId id = pPlayer->GetAdminId(); ds@1952: pPlayer->DoBasicAdminChecks(); ds@1952: ds@1952: return (id != pPlayer->GetAdminId()) ? 1 : 0; ds@1952: } ds@1952: ds@1952: static cell_t NotifyPostAdminCheck(IPluginContext *pContext, const cell_t *params) ds@1952: { ds@1952: int client = params[1]; ds@1952: ds@1952: CPlayer *pPlayer = g_Players.GetPlayerByIndex(client); ds@1952: if (!pPlayer) ds@1952: { ds@1952: return pContext->ThrowNativeError("Client index %d is invalid", client); ds@1952: } ds@1952: else if (!pPlayer->IsInGame()) { ds@1952: return pContext->ThrowNativeError("Client %d is not in game", client); ds@1952: } ds@1952: else if (!pPlayer->IsAuthorized()) ds@1952: { ds@1952: return pContext->ThrowNativeError("Client %d is not authorized", client); ds@1952: } ds@1952: ds@1952: pPlayer->NotifyPostAdminChecks(); ds@1952: ds@1952: return 1; ds@1952: } ds@1952: ds@1952: static cell_t IsClientInKickQueue(IPluginContext *pContext, const cell_t *params) ds@1952: { ds@1952: int client = params[1]; ds@1952: ds@1952: CPlayer *pPlayer = g_Players.GetPlayerByIndex(client); ds@1952: ds@1952: if (!pPlayer) ds@1952: { ds@1952: return pContext->ThrowNativeError("Client index %d is invalid", client); ds@1952: } ds@1952: else if (!pPlayer->IsConnected()) ds@1952: { ds@1952: return pContext->ThrowNativeError("Client %d is not in game", client); ds@1952: } ds@1952: ds@1952: return pPlayer->IsInKickQueue() ? 1 : 0; ds@1952: } ds@1952: ds@1952: static cell_t ProcessTargetString(IPluginContext *pContext, const cell_t *params) ds@1952: { ds@1952: cmd_target_info_t info; ds@1952: ds@1952: pContext->LocalToString(params[1], (char **)&info.pattern); ds@1952: info.admin = params[2]; ds@1952: pContext->LocalToPhysAddr(params[3], &info.targets); ds@1952: info.max_targets = params[4]; ds@1952: info.flags = params[5]; ds@1952: pContext->LocalToString(params[6], &info.target_name); ds@1952: info.target_name_maxlength = params[7]; ds@1952: ds@1952: cell_t *tn_is_ml; ds@1952: pContext->LocalToPhysAddr(params[8], &tn_is_ml); ds@1952: ds@1952: g_Players.ProcessCommandTarget(&info); ds@1952: ds@1952: if (info.target_name_style == COMMAND_TARGETNAME_ML) ds@1952: { ds@1952: *tn_is_ml = 1; ds@1952: } ds@1952: else ds@1952: { ds@1952: *tn_is_ml = 0; ds@1952: } ds@1952: ds@1952: if (info.num_targets == 0) ds@1952: { ds@1952: return info.reason; ds@1952: } ds@1952: else ds@1952: { ds@1952: return info.num_targets; ds@1952: } ds@1952: } ds@1952: ds@1952: REGISTER_NATIVES(playernatives) ds@1952: { ds@1952: {"AddUserFlags", AddUserFlags}, ds@1952: {"CanUserTarget", CanUserTarget}, ds@1952: {"ChangeClientTeam", ChangeClientTeam}, ds@1952: {"GetClientAuthString", sm_GetClientAuthStr}, ds@1952: {"GetClientCount", sm_GetClientCount}, ds@1952: {"GetClientInfo", sm_GetClientInfo}, ds@1952: {"GetClientIP", sm_GetClientIP}, ds@1952: {"GetClientName", sm_GetClientName}, ds@1952: {"GetClientTeam", GetClientTeam}, ds@1952: {"GetClientUserId", GetClientUserId}, ds@1952: {"GetMaxClients", sm_GetMaxClients}, ds@1952: {"GetUserAdmin", GetUserAdmin}, ds@1952: {"GetUserFlagBits", GetUserFlagBits}, ds@1952: {"IsClientAuthorized", sm_IsClientAuthorized}, ds@1952: {"IsClientConnected", sm_IsClientConnected}, ds@1952: {"IsFakeClient", sm_IsClientFakeClient}, ds@1952: {"IsClientInGame", sm_IsClientInGame}, ds@1952: {"IsClientObserver", IsClientObserver}, ds@1952: {"RemoveUserFlags", RemoveUserFlags}, ds@1952: {"SetUserAdmin", SetUserAdmin}, ds@1952: {"SetUserFlagBits", SetUserFlagBits}, ds@1952: {"GetClientDeaths", GetDeathCount}, ds@1952: {"GetClientFrags", GetFragCount}, ds@1952: {"GetClientArmor", GetArmorValue}, ds@1952: {"GetClientAbsOrigin", GetAbsOrigin}, ds@1952: {"GetClientAbsAngles", GetAbsAngles}, ds@1952: {"GetClientMins", GetPlayerMins}, ds@1952: {"GetClientMaxs", GetPlayerMaxs}, ds@1952: {"GetClientWeapon", GetWeaponName}, ds@1952: {"GetClientModel", GetModelName}, ds@1952: {"GetClientHealth", GetHealth}, ds@1952: {"GetClientTime", GetTimeConnected}, ds@1952: {"GetClientDataRate", GetDataRate}, ds@1952: {"IsClentTimingOut", IsTimingOut}, ds@1952: {"GetClientLatency", GetLatency}, ds@1952: {"GetClientAvgLatency", GetAvgLatency}, ds@1952: {"GetClientAvgLoss", GetAvgLoss}, ds@1952: {"GetClientAvgChoke", GetAvgChoke}, ds@1952: {"GetClientAvgData", GetAvgData}, ds@1952: {"GetClientAvgPackets", GetAvgPackets}, ds@1952: {"GetClientOfUserId", GetClientOfUserId}, ds@1952: {"ShowActivity", ShowActivity}, ds@1952: {"ShowActivityEx", ShowActivityEx}, ds@1952: {"ShowActivity2", ShowActivity2}, ds@1952: {"KickClient", KickClient}, ds@1952: {"RunAdminCacheChecks", RunAdminCacheChecks}, ds@1952: {"NotifyPostAdminCheck", NotifyPostAdminCheck}, ds@1952: {"IsClientInKickQueue", IsClientInKickQueue}, ds@1952: {"ProcessTargetString", ProcessTargetString}, ds@1952: {NULL, NULL} ds@1952: }; ds@1952: