diff --git a/core/AdminCache.h b/core/AdminCache.h index 8e06549a..77949d33 100644 --- a/core/AdminCache.h +++ b/core/AdminCache.h @@ -180,8 +180,8 @@ public: //IAdminSystem FlagBits flags, bool override_only); bool FindFlagChar(AdminFlag flag, char *c); -public: bool IsValidAdmin(AdminId id); +public: void DumpCache(FILE *fp); AdminGroup *GetGroup(GroupId gid); AdminUser *GetUser(AdminId id); diff --git a/core/logic/intercom.h b/core/logic/intercom.h index 00d6ed3e..e5a10509 100644 --- a/core/logic/intercom.h +++ b/core/logic/intercom.h @@ -62,6 +62,7 @@ class IVEngineServer_Logic public: virtual bool IsMapValid(const char *map) = 0; virtual void ServerCommand(const char *cmd) = 0; + virtual const char *GetClientConVarValue(int clientIndex, const char *name) = 0; }; typedef void * FileHandle_t; @@ -108,6 +109,25 @@ class IFileSystem; class ConVar; class KeyValues; class SMGlobalClass; +class IPlayerInfo; + +class IPlayerInfo_Logic +{ +public: + virtual bool IsObserver(IPlayerInfo *pInfo) = 0; + virtual int GetTeamIndex(IPlayerInfo *pInfo) = 0; + virtual int GetFragCount(IPlayerInfo *pInfo) = 0; + virtual int GetDeathCount(IPlayerInfo *pInfo) = 0; + virtual int GetArmorValue(IPlayerInfo *pInfo) = 0; + virtual void GetAbsOrigin(IPlayerInfo *pInfo, float *x, float *y, float *z) = 0; + virtual void GetAbsAngles(IPlayerInfo *pInfo, float *x, float *y, float *z) = 0; + virtual void GetPlayerMins(IPlayerInfo *pInfo, float *x, float *y, float *z) = 0; + virtual void GetPlayerMaxs(IPlayerInfo *pInfo, float *x, float *y, float *z) = 0; + virtual const char *GetWeaponName(IPlayerInfo *pInfo) = 0; + virtual const char *GetModelName(IPlayerInfo *pInfo) = 0; + virtual int GetHealth(IPlayerInfo *pInfo) = 0; + virtual void ChangeTeam(IPlayerInfo *pInfo, int iTeamNum) = 0; +}; namespace SourceMod { @@ -236,6 +256,7 @@ struct sm_core_t ILibrarySys *libsys; IVEngineServer *engine; IFileSystem *filesystem; + IPlayerInfo_Logic *playerInfo; IRootConsole *rootmenu; ITimerSystem *timersys; IPlayerManager *playerhelpers; @@ -252,6 +273,7 @@ struct sm_core_t void (*Log)(const char*, ...); void (*LogToFile)(FILE *fp, const char*, ...); void (*LogToGame)(const char *message); + void (*ConPrint)(const char *message); const char * (*GetCvarString)(ConVar*); size_t (*Format)(char*, size_t, const char*, ...); size_t (*FormatArgs)(char*, size_t, const char*,va_list ap); @@ -273,6 +295,7 @@ struct sm_core_t bool (*AreConfigsExecuted)(); void (*ExecuteConfigs)(IPluginContext *ctx); DatabaseInfo (*GetDBInfoFromKeyValues)(KeyValues *); + int (*GetActivityFlags)(); const char *gamesuffix; /* Data */ ServerGlobals *serverGlobals; diff --git a/core/logic/smn_players.cpp b/core/logic/smn_players.cpp index 0f3b2155..42eec12d 100644 --- a/core/logic/smn_players.cpp +++ b/core/logic/smn_players.cpp @@ -32,6 +32,9 @@ #include "common_logic.h" #include #include +#include +#include +#include #include #include #include "CellArray.h" @@ -226,10 +229,1352 @@ RemoveMultiTargetFilter(IPluginContext *ctx, const cell_t *params) return 1; } +static cell_t sm_GetClientCount(IPluginContext *pCtx, const cell_t *params) +{ + if (params[1]) + { + return playerhelpers->GetNumPlayers(); + } + + int maxplayers = playerhelpers->GetMaxClients(); + int count = 0; + for (int i = 1; i <= maxplayers; ++i) + { + IGamePlayer *pPlayer = playerhelpers->GetGamePlayer(i); + if ((pPlayer->IsConnected()) && !(pPlayer->IsInGame())) + { + count++; + } + } + + return (playerhelpers->GetNumPlayers() + count); +} + +static cell_t sm_GetMaxClients(IPluginContext *pCtx, const cell_t *params) +{ + return playerhelpers->GetMaxClients(); +} + +static cell_t sm_GetClientName(IPluginContext *pCtx, const cell_t *params) +{ + int index = params[1]; + + if (index == 0) + { + static ConVar *hostname = NULL; + if (!hostname) + { + hostname = smcore.FindConVar("hostname"); + if (!hostname) + { + return pCtx->ThrowNativeError("Could not find \"hostname\" cvar"); + } + } + pCtx->StringToLocalUTF8(params[2], static_cast(params[3]), smcore.GetCvarString(hostname), NULL); + return 1; + } + + if ((index < 1) || (index > playerhelpers->GetMaxClients())) + { + return pCtx->ThrowNativeError("Client index %d is invalid", index); + } + + IGamePlayer *pPlayer = playerhelpers->GetGamePlayer(index); + if (!pPlayer->IsConnected()) + { + return pCtx->ThrowNativeError("Client %d is not connected", index); + } + + pCtx->StringToLocalUTF8(params[2], static_cast(params[3]), pPlayer->GetName(), NULL); + return 1; +} + +static cell_t sm_GetClientIP(IPluginContext *pCtx, const cell_t *params) +{ + int index = params[1]; + if ((index < 1) || (index > playerhelpers->GetMaxClients())) + { + return pCtx->ThrowNativeError("Client index %d is invalid", index); + } + + IGamePlayer *pPlayer = playerhelpers->GetGamePlayer(index); + if (!pPlayer->IsConnected()) + { + return pCtx->ThrowNativeError("Client %d is not connected", index); + } + + char buf[64], *ptr; + strcpy(buf, pPlayer->GetIPAddress()); + + if (params[4] && (ptr = strchr(buf, ':'))) + { + *ptr = '\0'; + } + + pCtx->StringToLocal(params[2], static_cast(params[3]), buf); + return 1; +} + +static cell_t sm_GetClientAuthStr(IPluginContext *pCtx, const cell_t *params) +{ + int index = params[1]; + if ((index < 1) || (index > playerhelpers->GetMaxClients())) + { + return pCtx->ThrowNativeError("Client index %d is invalid", index); + } + + IGamePlayer *pPlayer = playerhelpers->GetGamePlayer(index); + if (!pPlayer->IsConnected()) + { + return pCtx->ThrowNativeError("Client %d is not connected", index); + } + + bool validate = true; + if (params[0] > 3) + { + validate = !!params[4]; + } + + const char *authstr = pPlayer->GetAuthString(validate); + + if (!authstr || authstr[0] == '\0') + { + return 0; + } + + pCtx->StringToLocal(params[2], static_cast(params[3]), authstr); + + return 1; +} + +static cell_t sm_GetSteamAccountID(IPluginContext *pCtx, const cell_t *params) +{ + int index = params[1]; + if ((index < 1) || (index > playerhelpers->GetMaxClients())) + { + return pCtx->ThrowNativeError("Client index %d is invalid", index); + } + + IGamePlayer *pPlayer = playerhelpers->GetGamePlayer(index); + if (!pPlayer->IsConnected()) + { + return pCtx->ThrowNativeError("Client %d is not connected", index); + } + + return pPlayer->GetSteamAccountID(!!params[2]); +} + +static cell_t sm_IsClientConnected(IPluginContext *pCtx, const cell_t *params) +{ + int index = params[1]; + if ((index < 1) || (index > playerhelpers->GetMaxClients())) + { + return pCtx->ThrowNativeError("Client index %d is invalid", index); + } + + return (playerhelpers->GetGamePlayer(index)->IsConnected()) ? 1 : 0; +} + +static cell_t sm_IsClientInGame(IPluginContext *pCtx, const cell_t *params) +{ + int index = params[1]; + if ((index < 1) || (index > playerhelpers->GetMaxClients())) + { + return pCtx->ThrowNativeError("Client index %d is invalid", index); + } + + return (playerhelpers->GetGamePlayer(index)->IsInGame()) ? 1 : 0; +} + +static cell_t sm_IsClientAuthorized(IPluginContext *pCtx, const cell_t *params) +{ + int index = params[1]; + if ((index < 1) || (index > playerhelpers->GetMaxClients())) + { + return pCtx->ThrowNativeError("Client index %d is invalid", index); + } + + return (playerhelpers->GetGamePlayer(index)->IsAuthorized()) ? 1 : 0; +} + +static cell_t sm_IsClientFakeClient(IPluginContext *pCtx, const cell_t *params) +{ + int index = params[1]; + if ((index < 1) || (index > playerhelpers->GetMaxClients())) + { + return pCtx->ThrowNativeError("Client index %d is invalid", index); + } + + IGamePlayer *pPlayer = playerhelpers->GetGamePlayer(index); + if (!pPlayer->IsConnected()) + { + return pCtx->ThrowNativeError("Client %d is not connected", index); + } + + return (pPlayer->IsFakeClient()) ? 1 : 0; +} + +static cell_t sm_IsClientSourceTV(IPluginContext *pCtx, const cell_t *params) +{ + int index = params[1]; + if ((index < 1) || (index > playerhelpers->GetMaxClients())) + { + return pCtx->ThrowNativeError("Client index %d is invalid", index); + } + + IGamePlayer *pPlayer = playerhelpers->GetGamePlayer(index); + if (!pPlayer->IsConnected()) + { + return pCtx->ThrowNativeError("Client %d is not connected", index); + } + + return (pPlayer->IsSourceTV()) ? 1 : 0; +} + +static cell_t sm_IsClientReplay(IPluginContext *pCtx, const cell_t *params) +{ + int index = params[1]; + if ((index < 1) || (index > playerhelpers->GetMaxClients())) + { + return pCtx->ThrowNativeError("Client index %d is invalid", index); + } + + IGamePlayer *pPlayer = playerhelpers->GetGamePlayer(index); + if (!pPlayer->IsConnected()) + { + return pCtx->ThrowNativeError("Client %d is not connected", index); + } + + return (pPlayer->IsReplay()) ? 1 : 0; +} + +static cell_t sm_GetClientInfo(IPluginContext *pContext, const cell_t *params) +{ + int client = params[1]; + IGamePlayer *pPlayer = playerhelpers->GetGamePlayer(client); + if (!pPlayer) + { + return pContext->ThrowNativeError("Client index %d is invalid", client); + } + if (!pPlayer->IsConnected()) + { + return pContext->ThrowNativeError("Client %d is not connected", client); + } + + char *key; + pContext->LocalToString(params[2], &key); + + const char *val = engine->GetClientConVarValue(client, key); + if (!val) + { + return false; + } + + pContext->StringToLocalUTF8(params[3], params[4], val, NULL); + return 1; +} + +static cell_t SetUserAdmin(IPluginContext *pContext, const cell_t *params) +{ + int client = params[1]; + IGamePlayer *pPlayer = playerhelpers->GetGamePlayer(client); + if (!pPlayer) + { + return pContext->ThrowNativeError("Client index %d is invalid", client); + } + if (!pPlayer->IsConnected()) + { + return pContext->ThrowNativeError("Client %d is not connected", client); + } + if (!adminsys->IsValidAdmin(params[2]) && params[2] != INVALID_ADMIN_ID) + { + return pContext->ThrowNativeError("AdminId %x is invalid", params[2]); + } + + pPlayer->SetAdminId(params[2], params[3] ? true : false); + + return 1; +} + +static cell_t GetUserAdmin(IPluginContext *pContext, const cell_t *params) +{ + int client = params[1]; + IGamePlayer *pPlayer = playerhelpers->GetGamePlayer(client); + if (!pPlayer) + { + return pContext->ThrowNativeError("Client index %d is invalid", client); + } + if (!pPlayer->IsConnected()) + { + return pContext->ThrowNativeError("Client %d is not connected", client); + } + + return pPlayer->GetAdminId(); +} + +static cell_t AddUserFlags(IPluginContext *pContext, const cell_t *params) +{ + int client = params[1]; + IGamePlayer *pPlayer = playerhelpers->GetGamePlayer(client); + if (!pPlayer) + { + return pContext->ThrowNativeError("Client index %d is invalid", client); + } + if (!pPlayer->IsConnected()) + { + return pContext->ThrowNativeError("Client %d is not connected", client); + } + + AdminId id; + if ((id = pPlayer->GetAdminId()) == INVALID_ADMIN_ID) + { + id = adminsys->CreateAdmin(NULL); + pPlayer->SetAdminId(id, true); + } + + cell_t *addr; + for (int i = 2; i <= params[0]; i++) + { + pContext->LocalToPhysAddr(params[i], &addr); + adminsys->SetAdminFlag(id, (AdminFlag) *addr, true); + } + + return 1; +} + +static cell_t RemoveUserFlags(IPluginContext *pContext, const cell_t *params) +{ + int client = params[1]; + IGamePlayer *pPlayer = playerhelpers->GetGamePlayer(client); + if (!pPlayer) + { + return pContext->ThrowNativeError("Client index %d is invalid", client); + } + if (!pPlayer->IsConnected()) + { + return pContext->ThrowNativeError("Client %d is not connected", client); + } + + AdminId id; + if ((id = pPlayer->GetAdminId()) == INVALID_ADMIN_ID) + { + return 0; + } + + cell_t *addr; + for (int i = 2; i <= params[0]; i++) + { + pContext->LocalToPhysAddr(params[i], &addr); + adminsys->SetAdminFlag(id, (AdminFlag) *addr, false); + } + + return 1; +} + +static cell_t SetUserFlagBits(IPluginContext *pContext, const cell_t *params) +{ + int client = params[1]; + IGamePlayer *pPlayer = playerhelpers->GetGamePlayer(client); + if (!pPlayer) + { + return pContext->ThrowNativeError("Client index %d is invalid", client); + } + if (!pPlayer->IsConnected()) + { + return pContext->ThrowNativeError("Client %d is not connected", client); + } + + AdminId id; + if ((id = pPlayer->GetAdminId()) == INVALID_ADMIN_ID) + { + id = adminsys->CreateAdmin(NULL); + pPlayer->SetAdminId(id, true); + } + + adminsys->SetAdminFlags(id, Access_Effective, params[2]); + + return 1; +} + +static cell_t GetUserFlagBits(IPluginContext *pContext, const cell_t *params) +{ + int client = params[1]; + IGamePlayer *pPlayer = playerhelpers->GetGamePlayer(client); + if (!pPlayer) + { + return pContext->ThrowNativeError("Client index %d is invalid", client); + } + if (!pPlayer->IsConnected()) + { + return pContext->ThrowNativeError("Client %d is not connected", client); + } + + AdminId id; + if ((id = pPlayer->GetAdminId()) == INVALID_ADMIN_ID) + { + return 0; + } + + return adminsys->GetAdminFlags(id, Access_Effective); +} + +static cell_t GetClientUserId(IPluginContext *pContext, const cell_t *params) +{ + int client = params[1]; + IGamePlayer *pPlayer = playerhelpers->GetGamePlayer(client); + if (!pPlayer) + { + return pContext->ThrowNativeError("Client index %d is invalid", client); + } + if (!pPlayer->IsConnected()) + { + return pContext->ThrowNativeError("Client %d is not connected", client); + } + + return pPlayer->GetUserId(); +} + +static cell_t CanUserTarget(IPluginContext *pContext, const cell_t *params) +{ + int client = params[1]; + int target = params[2]; + + if (client == 0) + { + return 1; + } + + IGamePlayer *pPlayer = playerhelpers->GetGamePlayer(client); + if (!pPlayer) + { + return pContext->ThrowNativeError("Client index %d is invalid", client); + } + else if (!pPlayer->IsConnected()) { + return pContext->ThrowNativeError("Client %d is not connected", client); + } + + IGamePlayer *pTarget = playerhelpers->GetGamePlayer(target); + if (!pTarget) + { + return pContext->ThrowNativeError("Client index %d is invalid", target); + } + else if (!pTarget->IsConnected()) { + return pContext->ThrowNativeError("Client %d is not connected", target); + } + + return adminsys->CanAdminTarget(pPlayer->GetAdminId(), pTarget->GetAdminId()) ? 1 : 0; +} + +static cell_t IsClientObserver(IPluginContext *pContext, const cell_t *params) +{ + int client = params[1]; + + IGamePlayer *pPlayer = playerhelpers->GetGamePlayer(client); + if (!pPlayer) + { + return pContext->ThrowNativeError("Client index %d is invalid", client); + } + else if (!pPlayer->IsInGame()) { + return pContext->ThrowNativeError("Client %d is not in game", client); + } + + IPlayerInfo *pInfo = pPlayer->GetPlayerInfo(); + if (!pInfo) + { + return pContext->ThrowNativeError("IPlayerInfo not supported by game"); + } + + return smcore.playerInfo->IsObserver(pInfo) ? 1 : 0; +} + +static cell_t GetClientTeam(IPluginContext *pContext, const cell_t *params) +{ + int client = params[1]; + + IGamePlayer *pPlayer = playerhelpers->GetGamePlayer(client); + if (!pPlayer) + { + return pContext->ThrowNativeError("Client index %d is invalid", client); + } + else if (!pPlayer->IsInGame()) { + return pContext->ThrowNativeError("Client %d is not in game", client); + } + + IPlayerInfo *pInfo = pPlayer->GetPlayerInfo(); + if (!pInfo) + { + return pContext->ThrowNativeError("IPlayerInfo not supported by game"); + } + + return smcore.playerInfo->GetTeamIndex(pInfo); +} + +static cell_t GetFragCount(IPluginContext *pContext, const cell_t *params) +{ + int client = params[1]; + + IGamePlayer *pPlayer = playerhelpers->GetGamePlayer(client); + if (!pPlayer) + { + return pContext->ThrowNativeError("Client index %d is invalid", client); + } + else if (!pPlayer->IsInGame()) { + return pContext->ThrowNativeError("Client %d is not in game", client); + } + + IPlayerInfo *pInfo = pPlayer->GetPlayerInfo(); + if (!pInfo) + { + return pContext->ThrowNativeError("IPlayerInfo not supported by game"); + } + + return smcore.playerInfo->GetFragCount(pInfo); +} + +static cell_t GetDeathCount(IPluginContext *pContext, const cell_t *params) +{ + int client = params[1]; + + IGamePlayer *pPlayer = playerhelpers->GetGamePlayer(client); + if (!pPlayer) + { + return pContext->ThrowNativeError("Client index %d is invalid", client); + } + else if (!pPlayer->IsInGame()) { + return pContext->ThrowNativeError("Client %d is not in game", client); + } + + IPlayerInfo *pInfo = pPlayer->GetPlayerInfo(); + if (!pInfo) + { + return pContext->ThrowNativeError("IPlayerInfo not supported by game"); + } + + return smcore.playerInfo->GetDeathCount(pInfo); +} + +static cell_t GetArmorValue(IPluginContext *pContext, const cell_t *params) +{ + int client = params[1]; + + IGamePlayer *pPlayer = playerhelpers->GetGamePlayer(client); + if (!pPlayer) + { + return pContext->ThrowNativeError("Client index %d is invalid", client); + } + else if (!pPlayer->IsInGame()) { + return pContext->ThrowNativeError("Client %d is not in game", client); + } + + IPlayerInfo *pInfo = pPlayer->GetPlayerInfo(); + if (!pInfo) + { + return pContext->ThrowNativeError("IPlayerInfo not supported by game"); + } + + return smcore.playerInfo->GetArmorValue(pInfo); +} + +static cell_t GetAbsOrigin(IPluginContext *pContext, const cell_t *params) +{ + int client = params[1]; + + IGamePlayer *pPlayer = playerhelpers->GetGamePlayer(client); + if (!pPlayer) + { + return pContext->ThrowNativeError("Client index %d is invalid", client); + } + else if (!pPlayer->IsInGame()) { + return pContext->ThrowNativeError("Client %d is not in game", client); + } + + IPlayerInfo *pInfo = pPlayer->GetPlayerInfo(); + if (!pInfo) + { + return pContext->ThrowNativeError("IPlayerInfo not supported by game"); + } + + cell_t *pVec; + pContext->LocalToPhysAddr(params[2], &pVec); + + float x, y, z; + smcore.playerInfo->GetAbsOrigin(pInfo, &x, &y, &z); + pVec[0] = sp_ftoc(x); + pVec[1] = sp_ftoc(y); + pVec[2] = sp_ftoc(z); + + return 1; +} + +static cell_t GetAbsAngles(IPluginContext *pContext, const cell_t *params) +{ + int client = params[1]; + + IGamePlayer *pPlayer = playerhelpers->GetGamePlayer(client); + if (!pPlayer) + { + return pContext->ThrowNativeError("Client index %d is invalid", client); + } + else if (!pPlayer->IsInGame()) { + return pContext->ThrowNativeError("Client %d is not in game", client); + } + + IPlayerInfo *pInfo = pPlayer->GetPlayerInfo(); + if (!pInfo) + { + return pContext->ThrowNativeError("IPlayerInfo not supported by game"); + } + + cell_t *pAng; + pContext->LocalToPhysAddr(params[2], &pAng); + + float x, y, z; + smcore.playerInfo->GetAbsAngles(pInfo, &x, &y, &z); + pAng[0] = sp_ftoc(x); + pAng[1] = sp_ftoc(y); + pAng[2] = sp_ftoc(z); + + return 1; +} + +static cell_t GetPlayerMins(IPluginContext *pContext, const cell_t *params) +{ + int client = params[1]; + + IGamePlayer *pPlayer = playerhelpers->GetGamePlayer(client); + if (!pPlayer) + { + return pContext->ThrowNativeError("Client index %d is invalid", client); + } + else if (!pPlayer->IsInGame()) { + return pContext->ThrowNativeError("Client %d is not in game", client); + } + + IPlayerInfo *pInfo = pPlayer->GetPlayerInfo(); + if (!pInfo) + { + return pContext->ThrowNativeError("IPlayerInfo not supported by game"); + } + + cell_t *pVec; + pContext->LocalToPhysAddr(params[2], &pVec); + + float x, y, z; + smcore.playerInfo->GetPlayerMins(pInfo, &x, &y, &z); + pVec[0] = sp_ftoc(x); + pVec[1] = sp_ftoc(y); + pVec[2] = sp_ftoc(z); + + return 1; +} + +static cell_t GetPlayerMaxs(IPluginContext *pContext, const cell_t *params) +{ + int client = params[1]; + + IGamePlayer *pPlayer = playerhelpers->GetGamePlayer(client); + if (!pPlayer) + { + return pContext->ThrowNativeError("Client index %d is invalid", client); + } + else if (!pPlayer->IsInGame()) { + return pContext->ThrowNativeError("Client %d is not in game", client); + } + + IPlayerInfo *pInfo = pPlayer->GetPlayerInfo(); + if (!pInfo) + { + return pContext->ThrowNativeError("IPlayerInfo not supported by game"); + } + + cell_t *pVec; + pContext->LocalToPhysAddr(params[2], &pVec); + + float x, y, z; + smcore.playerInfo->GetPlayerMaxs(pInfo, &x, &y, &z); + pVec[0] = sp_ftoc(x); + pVec[1] = sp_ftoc(y); + pVec[2] = sp_ftoc(z); + + return 1; +} + +static cell_t GetWeaponName(IPluginContext *pContext, const cell_t *params) +{ + int client = params[1]; + + IGamePlayer *pPlayer = playerhelpers->GetGamePlayer(client); + if (!pPlayer) + { + return pContext->ThrowNativeError("Client index %d is invalid", client); + } + else if (!pPlayer->IsInGame()) { + return pContext->ThrowNativeError("Client %d is not in game", client); + } + + IPlayerInfo *pInfo = pPlayer->GetPlayerInfo(); + if (!pInfo) + { + return pContext->ThrowNativeError("IPlayerInfo not supported by game"); + } + + const char *weapon = smcore.playerInfo->GetWeaponName(pInfo); + pContext->StringToLocalUTF8(params[2], static_cast(params[3]), weapon ? weapon : "", NULL); + + return 1; +} + +static cell_t GetModelName(IPluginContext *pContext, const cell_t *params) +{ + int client = params[1]; + + IGamePlayer *pPlayer = playerhelpers->GetGamePlayer(client); + if (!pPlayer) + { + return pContext->ThrowNativeError("Client index %d is invalid", client); + } + else if (!pPlayer->IsInGame()) { + return pContext->ThrowNativeError("Client %d is not in game", client); + } + + IPlayerInfo *pInfo = pPlayer->GetPlayerInfo(); + if (!pInfo) + { + return pContext->ThrowNativeError("IPlayerInfo not supported by game"); + } + + const char *model = smcore.playerInfo->GetModelName(pInfo); + pContext->StringToLocalUTF8(params[2], static_cast(params[3]), model ? model : "", NULL); + + return 1; +} + +static cell_t GetHealth(IPluginContext *pContext, const cell_t *params) +{ + int client = params[1]; + + IGamePlayer *pPlayer = playerhelpers->GetGamePlayer(client); + if (!pPlayer) + { + return pContext->ThrowNativeError("Client index %d is invalid", client); + } + else if (!pPlayer->IsInGame()) { + return pContext->ThrowNativeError("Client %d is not in game", client); + } + + IPlayerInfo *pInfo = pPlayer->GetPlayerInfo(); + if (!pInfo) + { + return pContext->ThrowNativeError("IPlayerInfo not supported by game"); + } + + return smcore.playerInfo->GetHealth(pInfo); +} + +static cell_t GetClientOfUserId(IPluginContext *pContext, const cell_t *params) +{ + return playerhelpers->GetClientOfUserId(params[1]); +} + +static cell_t _ShowActivity(IPluginContext *pContext, + const cell_t *params, + const char *tag, + cell_t fmt_param) +{ + char message[255]; + char buffer[255]; + int value = smcore.GetActivityFlags(); + unsigned int replyto = playerhelpers->GetReplyTo(); + int client = params[1]; + + const char *name = "Console"; + const char *sign = "ADMIN"; + bool display_in_chat = false; + if (client != 0) + { + IGamePlayer *pPlayer = playerhelpers->GetGamePlayer(client); + if (!pPlayer || !pPlayer->IsConnected()) + { + return pContext->ThrowNativeError("Client index %d is invalid", client); + } + name = pPlayer->GetName(); + AdminId id = pPlayer->GetAdminId(); + if (id == INVALID_ADMIN_ID + || !adminsys->GetAdminFlag(id, Admin_Generic, Access_Effective)) + { + sign = "PLAYER"; + } + + /* Display the message to the client? */ + if (replyto == SM_REPLY_CONSOLE) + { + g_pSM->SetGlobalTarget(client); + g_pSM->FormatString(buffer, sizeof(buffer), pContext, params, fmt_param); + + if (pContext->GetLastNativeError() != SP_ERROR_NONE) + { + return 0; + } + + g_pSM->Format(message, sizeof(message), "%s%s\n", tag, buffer); + pPlayer->PrintToConsole(message); + display_in_chat = true; + } + } + else + { + g_pSM->SetGlobalTarget(SOURCEMOD_SERVER_LANGUAGE); + g_pSM->FormatString(buffer, sizeof(buffer), pContext, params, fmt_param); + + if (pContext->GetLastNativeError() != SP_ERROR_NONE) + { + return 0; + } + + g_pSM->Format(message, sizeof(message), "%s%s\n", tag, buffer); + smcore.ConPrint(message); + } + + if (!value) + { + return 1; + } + + int maxClients = playerhelpers->GetMaxClients(); + for (int i = 1; i <= maxClients; i++) + { + IGamePlayer *pPlayer = playerhelpers->GetGamePlayer(i); + if (!pPlayer->IsInGame() + || pPlayer->IsFakeClient() + || (display_in_chat && i == client)) + { + continue; + } + AdminId id = pPlayer->GetAdminId(); + g_pSM->SetGlobalTarget(i); + if (id == INVALID_ADMIN_ID + || !adminsys->GetAdminFlag(id, Admin_Generic, Access_Effective)) + { + /* Treat this as a normal user */ + if ((value & 1) || (value & 2)) + { + const char *newsign = sign; + if ((value & 2) || (i == client)) + { + newsign = name; + } + g_pSM->FormatString(buffer, sizeof(buffer), pContext, params, fmt_param); + + if (pContext->GetLastNativeError() != SP_ERROR_NONE) + { + return 0; + } + + g_pSM->Format(message, sizeof(message), "%s%s: %s", tag, newsign, buffer); + gamehelpers->TextMsg(i, TEXTMSG_DEST_CHAT, message); + } + } + else + { + /* Treat this as an admin user */ + bool is_root = adminsys->GetAdminFlag(id, Admin_Root, Access_Effective); + if ((value & 4) + || (value & 8) + || ((value & 16) && is_root)) + { + const char *newsign = sign; + if ((value & 8) || ((value & 16) && is_root) || (i == client)) + { + newsign = name; + } + g_pSM->FormatString(buffer, sizeof(buffer), pContext, params, fmt_param); + + if (pContext->GetLastNativeError() != SP_ERROR_NONE) + { + return 0; + } + + g_pSM->Format(message, sizeof(message), "%s%s: %s", tag, newsign, buffer); + gamehelpers->TextMsg(i, TEXTMSG_DEST_CHAT, message); + } + } + } + + return 1; +} + +static cell_t _ShowActivity2(IPluginContext *pContext, + const cell_t *params, + const char *tag, + cell_t fmt_param) +{ + char message[255]; + char buffer[255]; + int value = smcore.GetActivityFlags(); + unsigned int replyto = playerhelpers->GetReplyTo(); + int client = params[1]; + + const char *name = "Console"; + const char *sign = "ADMIN"; + if (client != 0) + { + IGamePlayer *pPlayer = playerhelpers->GetGamePlayer(client); + if (!pPlayer || !pPlayer->IsConnected()) + { + return pContext->ThrowNativeError("Client index %d is invalid", client); + } + name = pPlayer->GetName(); + AdminId id = pPlayer->GetAdminId(); + if (id == INVALID_ADMIN_ID + || !adminsys->GetAdminFlag(id, Admin_Generic, Access_Effective)) + { + sign = "PLAYER"; + } + + g_pSM->SetGlobalTarget(client); + g_pSM->FormatString(buffer, sizeof(buffer), pContext, params, fmt_param); + + if (pContext->GetLastNativeError() != SP_ERROR_NONE) + { + return 0; + } + + /* We don't display directly to the console because the chat text + * simply gets added to the console, so we don't want it to print + * twice. + */ + g_pSM->Format(message, sizeof(message), "%s%s", tag, buffer); + gamehelpers->TextMsg(client, TEXTMSG_DEST_CHAT, message); + } + else + { + g_pSM->SetGlobalTarget(SOURCEMOD_SERVER_LANGUAGE); + g_pSM->FormatString(buffer, sizeof(buffer), pContext, params, fmt_param); + + if (pContext->GetLastNativeError() != SP_ERROR_NONE) + { + return 0; + } + + g_pSM->Format(message, sizeof(message), "%s%s\n", tag, buffer); + smcore.ConPrint(message); + } + + if (!value) + { + return 1; + } + + int maxClients = playerhelpers->GetMaxClients(); + for (int i = 1; i <= maxClients; i++) + { + IGamePlayer *pPlayer = playerhelpers->GetGamePlayer(i); + if (!pPlayer->IsInGame() + || pPlayer->IsFakeClient() + || i == client) + { + continue; + } + AdminId id = pPlayer->GetAdminId(); + g_pSM->SetGlobalTarget(i); + if (id == INVALID_ADMIN_ID + || !adminsys->GetAdminFlag(id, Admin_Generic, Access_Effective)) + { + /* Treat this as a normal user */ + if ((value & 1) || (value & 2)) + { + const char *newsign = sign; + if ((value & 2)) + { + newsign = name; + } + g_pSM->FormatString(buffer, sizeof(buffer), pContext, params, fmt_param); + + if (pContext->GetLastNativeError() != SP_ERROR_NONE) + { + return 0; + } + + g_pSM->Format(message, sizeof(message), "%s%s: %s", tag, newsign, buffer); + gamehelpers->TextMsg(i, TEXTMSG_DEST_CHAT, message); + } + } + else + { + /* Treat this as an admin user */ + bool is_root = adminsys->GetAdminFlag(id, Admin_Root, Access_Effective); + if ((value & 4) + || (value & 8) + || ((value & 16) && is_root)) + { + const char *newsign = sign; + if ((value & 8) || ((value & 16) && is_root)) + { + newsign = name; + } + g_pSM->FormatString(buffer, sizeof(buffer), pContext, params, fmt_param); + + if (pContext->GetLastNativeError() != SP_ERROR_NONE) + { + return 0; + } + + g_pSM->Format(message, sizeof(message), "%s%s: %s", tag, newsign, buffer); + gamehelpers->TextMsg(i, TEXTMSG_DEST_CHAT, message); + } + } + } + + return 1; +} + +static cell_t ShowActivity(IPluginContext *pContext, const cell_t *params) +{ + return _ShowActivity(pContext, params, "[SM] ", 2); +} + +static cell_t ShowActivityEx(IPluginContext *pContext, const cell_t *params) +{ + char *str; + pContext->LocalToString(params[2], &str); + + return _ShowActivity(pContext, params, str, 3); +} + +static cell_t ShowActivity2(IPluginContext *pContext, const cell_t *params) +{ + char *str; + pContext->LocalToString(params[2], &str); + + return _ShowActivity2(pContext, params, str, 3); +} + +static cell_t KickClient(IPluginContext *pContext, const cell_t *params) +{ + int client = params[1]; + + IGamePlayer *pPlayer = playerhelpers->GetGamePlayer(client); + if (!pPlayer) + { + return pContext->ThrowNativeError("Client index %d is invalid", client); + } + else if (!pPlayer->IsConnected()) + { + return pContext->ThrowNativeError("Client %d is not connected", client); + } + + /* Ignore duplicate kicks */ + if (pPlayer->IsInKickQueue()) + { + return 1; + } + + g_pSM->SetGlobalTarget(client); + + char buffer[256]; + g_pSM->FormatString(buffer, sizeof(buffer), pContext, params, 2); + + if (pContext->GetLastNativeError() != SP_ERROR_NONE) + { + return 0; + } + + if (pPlayer->IsFakeClient()) + { + // Kick uses the kickid command for bots. It is already delayed + // until the next frame unless someone flushes command buffer + pPlayer->Kick(buffer); + return 1; + } + + gamehelpers->AddDelayedKick(client, pPlayer->GetUserId(), buffer); + + return 1; +} + +static cell_t KickClientEx(IPluginContext *pContext, const cell_t *params) +{ + int client = params[1]; + + IGamePlayer *pPlayer = playerhelpers->GetGamePlayer(client); + if (!pPlayer) + { + return pContext->ThrowNativeError("Client index %d is invalid", client); + } + else if (!pPlayer->IsConnected()) + { + return pContext->ThrowNativeError("Client %d is not connected", client); + } + + g_pSM->SetGlobalTarget(client); + + char buffer[256]; + g_pSM->FormatString(buffer, sizeof(buffer), pContext, params, 2); + + if (pContext->GetLastNativeError() != SP_ERROR_NONE) + { + return 0; + } + + pPlayer->Kick(buffer); + + return 1; +} + +static cell_t ChangeClientTeam(IPluginContext *pContext, const cell_t *params) +{ + int client = params[1]; + + IGamePlayer *pPlayer = playerhelpers->GetGamePlayer(client); + if (!pPlayer) + { + return pContext->ThrowNativeError("Client index %d is invalid", client); + } + else if (!pPlayer->IsInGame()) + { + return pContext->ThrowNativeError("Client %d is not in game", client); + } + + IPlayerInfo *pInfo = pPlayer->GetPlayerInfo(); + if (!pInfo) + { + return pContext->ThrowNativeError("IPlayerInfo not supported by game"); + } + + smcore.playerInfo->ChangeTeam(pInfo, params[2]); + + return 1; +} + +static cell_t NotifyPostAdminCheck(IPluginContext *pContext, const cell_t *params) +{ + int client = params[1]; + + IGamePlayer *pPlayer = playerhelpers->GetGamePlayer(client); + if (!pPlayer) + { + return pContext->ThrowNativeError("Client index %d is invalid", client); + } + else if (!pPlayer->IsInGame()) { + return pContext->ThrowNativeError("Client %d is not in game", client); + } + else if (!pPlayer->IsAuthorized()) + { + return pContext->ThrowNativeError("Client %d is not authorized", client); + } + + pPlayer->NotifyPostAdminChecks(); + + return 1; +} + +static cell_t IsClientInKickQueue(IPluginContext *pContext, const cell_t *params) +{ + int client = params[1]; + + IGamePlayer *pPlayer = playerhelpers->GetGamePlayer(client); + + if (!pPlayer) + { + return pContext->ThrowNativeError("Client index %d is invalid", client); + } + else if (!pPlayer->IsConnected()) + { + return pContext->ThrowNativeError("Client %d is not in game", client); + } + + return pPlayer->IsInKickQueue() ? 1 : 0; +} + +static cell_t ProcessTargetString(IPluginContext *pContext, const cell_t *params) +{ + cmd_target_info_t info; + + pContext->LocalToString(params[1], (char **) &info.pattern); + info.admin = params[2]; + pContext->LocalToPhysAddr(params[3], &info.targets); + info.max_targets = params[4]; + info.flags = params[5]; + pContext->LocalToString(params[6], &info.target_name); + info.target_name_maxlength = params[7]; + + cell_t *tn_is_ml; + pContext->LocalToPhysAddr(params[8], &tn_is_ml); + + playerhelpers->ProcessCommandTarget(&info); + + if (info.target_name_style == COMMAND_TARGETNAME_ML) + { + *tn_is_ml = 1; + } + else + { + *tn_is_ml = 0; + } + + if (info.num_targets == 0) + { + return info.reason; + } + else + { + return info.num_targets; + } +} + +static cell_t FormatActivitySource(IPluginContext *pContext, const cell_t *params) +{ + int value; + int client; + int target; + IGamePlayer *pTarget; + AdminId aidTarget; + const char *identity[2] = { "Console", "ADMIN" }; + + client = params[1]; + target = params[2]; + + if ((pTarget = playerhelpers->GetGamePlayer(target)) == NULL) + { + return pContext->ThrowNativeError("Invalid client index %d", target); + } + if (!pTarget->IsConnected()) + { + return pContext->ThrowNativeError("Client %d not connected", target); + } + + value = smcore.GetActivityFlags(); + + if (client != 0) + { + IGamePlayer *pPlayer; + + if ((pPlayer = playerhelpers->GetGamePlayer(client)) == NULL) + { + return pContext->ThrowNativeError("Invalid client index %d", client); + } + if (!pPlayer->IsConnected()) + { + return pContext->ThrowNativeError("Client %d not connected", client); + } + + identity[0] = pPlayer->GetName(); + + AdminId id = pPlayer->GetAdminId(); + if (id == INVALID_ADMIN_ID + || !adminsys->GetAdminFlag(id, Admin_Generic, Access_Effective)) + { + identity[1] = "PLAYER"; + } + } + + int mode = 1; + bool bShowActivity = false; + + if ((aidTarget = pTarget->GetAdminId()) == INVALID_ADMIN_ID + || !adminsys->GetAdminFlag(aidTarget, Admin_Generic, Access_Effective)) + { + /* Treat this as a normal user */ + if ((value & 1) || (value & 2)) + { + if ((value & 2) || (target == client)) + { + mode = 0; + } + bShowActivity = true; + } + } + else + { + /* Treat this as an admin user */ + bool is_root = adminsys->GetAdminFlag(aidTarget, Admin_Root, Access_Effective); + if ((value & 4) + || (value & 8) + || ((value & 16) && is_root)) + { + if ((value & 8) || ((value & 16) && is_root) || (target == client)) + { + mode = 0; + } + bShowActivity = true; + } + } + + /* Otherwise, send it back to the script. */ + pContext->StringToLocalUTF8(params[3], params[4], identity[mode], NULL); + + return bShowActivity ? 1 : 0; +} + +static cell_t sm_GetClientSerial(IPluginContext *pContext, const cell_t *params) +{ + int client = params[1]; + + IGamePlayer *pPlayer = playerhelpers->GetGamePlayer(client); + if (!pPlayer) + { + return pContext->ThrowNativeError("Client index %d is invalid", client); + } + + return pPlayer->GetSerial(); +} + +static cell_t sm_GetClientFromSerial(IPluginContext *pContext, const cell_t *params) +{ + return playerhelpers->GetClientFromSerial(params[1]); +} + + REGISTER_NATIVES(playernatives) { {"AddMultiTargetFilter", AddMultiTargetFilter}, {"RemoveMultiTargetFilter", RemoveMultiTargetFilter}, + { "AddUserFlags", AddUserFlags }, + { "CanUserTarget", CanUserTarget }, + { "ChangeClientTeam", ChangeClientTeam }, + { "GetClientAuthString", sm_GetClientAuthStr }, + { "GetSteamAccountID", sm_GetSteamAccountID }, + { "GetClientCount", sm_GetClientCount }, + { "GetClientInfo", sm_GetClientInfo }, + { "GetClientIP", sm_GetClientIP }, + { "GetClientName", sm_GetClientName }, + { "GetClientTeam", GetClientTeam }, + { "GetClientUserId", GetClientUserId }, + { "GetMaxClients", sm_GetMaxClients }, + { "GetUserAdmin", GetUserAdmin }, + { "GetUserFlagBits", GetUserFlagBits }, + { "IsClientAuthorized", sm_IsClientAuthorized }, + { "IsClientConnected", sm_IsClientConnected }, + { "IsFakeClient", sm_IsClientFakeClient }, + { "IsClientSourceTV", sm_IsClientSourceTV }, + { "IsClientReplay", sm_IsClientReplay }, + { "IsClientInGame", sm_IsClientInGame }, + { "IsClientObserver", IsClientObserver }, + { "RemoveUserFlags", RemoveUserFlags }, + { "SetUserAdmin", SetUserAdmin }, + { "SetUserFlagBits", SetUserFlagBits }, + { "GetClientDeaths", GetDeathCount }, + { "GetClientFrags", GetFragCount }, + { "GetClientArmor", GetArmorValue }, + { "GetClientAbsOrigin", GetAbsOrigin }, + { "GetClientAbsAngles", GetAbsAngles }, + { "GetClientMins", GetPlayerMins }, + { "GetClientMaxs", GetPlayerMaxs }, + { "GetClientWeapon", GetWeaponName }, + { "GetClientModel", GetModelName }, + { "GetClientHealth", GetHealth }, + { "GetClientOfUserId", GetClientOfUserId }, + { "ShowActivity", ShowActivity }, + { "ShowActivityEx", ShowActivityEx }, + { "ShowActivity2", ShowActivity2 }, + { "KickClient", KickClient }, + { "KickClientEx", KickClientEx }, + { "NotifyPostAdminCheck", NotifyPostAdminCheck }, + { "IsClientInKickQueue", IsClientInKickQueue }, + { "ProcessTargetString", ProcessTargetString }, + { "FormatActivitySource", FormatActivitySource }, + { "GetClientSerial", sm_GetClientSerial }, + { "GetClientFromSerial", sm_GetClientFromSerial }, {NULL, NULL} }; diff --git a/core/logic_bridge.cpp b/core/logic_bridge.cpp index 2e721213..47c7af4a 100644 --- a/core/logic_bridge.cpp +++ b/core/logic_bridge.cpp @@ -98,6 +98,11 @@ public: { engine->ServerCommand(cmd); } + + virtual const char *GetClientConVarValue(int clientIndex, const char *name) + { + return engine->GetClientConVarValue(clientIndex, name); + } }; static VEngineServer_Logic logic_engine; @@ -146,6 +151,78 @@ public: static VFileSystem_Logic logic_filesystem; +class VPlayerInfo_Logic : public IPlayerInfo_Logic +{ +public: + bool IsObserver(IPlayerInfo *pInfo) + { + return pInfo->IsObserver(); + } + int GetTeamIndex(IPlayerInfo *pInfo) + { + return pInfo->GetTeamIndex(); + } + int GetFragCount(IPlayerInfo *pInfo) + { + return pInfo->GetFragCount(); + } + int GetDeathCount(IPlayerInfo *pInfo) + { + return pInfo->GetDeathCount(); + } + int GetArmorValue(IPlayerInfo *pInfo) + { + return pInfo->GetArmorValue(); + } + void GetAbsOrigin(IPlayerInfo *pInfo, float *x, float *y, float *z) + { + Vector vec = pInfo->GetAbsOrigin(); + *x = vec.x; + *y = vec.y; + *z = vec.z; + } + void GetAbsAngles(IPlayerInfo *pInfo, float *x, float *y, float *z) + { + QAngle ang = pInfo->GetAbsAngles(); + *x = ang.x; + *y = ang.y; + *z = ang.z; + } + void GetPlayerMins(IPlayerInfo *pInfo, float *x, float *y, float *z) + { + Vector vec = pInfo->GetPlayerMins(); + *x = vec.x; + *y = vec.y; + *z = vec.z; + } + void GetPlayerMaxs(IPlayerInfo *pInfo, float *x, float *y, float *z) + { + Vector vec = pInfo->GetPlayerMaxs(); + *x = vec.x; + *y = vec.y; + *z = vec.z; + } + const char *GetWeaponName(IPlayerInfo *pInfo) + { + return pInfo->GetWeaponName(); + } + const char *GetModelName(IPlayerInfo *pInfo) + { + return pInfo->GetModelName(); + } + int GetHealth(IPlayerInfo *pInfo) + { + return pInfo->GetHealth(); + } + void ChangeTeam(IPlayerInfo *pInfo, int iTeamNum) + { + pInfo->ChangeTeam(iTeamNum); + } +}; + +static VPlayerInfo_Logic logic_playerinfo; + +static ConVar sm_show_activity("sm_show_activity", "13", FCVAR_SPONLY, "Activity display setting (see sourcemod.cfg)"); static ConVar *find_convar(const char *name) { @@ -191,6 +268,11 @@ static void log_to_game(const char *message) Engine_LogPrintWrapper(message); } +static void conprint(const char *message) +{ + META_CONPRINT(message); +} + static const char *get_cvar_string(ConVar* cvar) { return cvar->GetString(); @@ -314,6 +396,11 @@ static DatabaseInfo keyvalues_to_dbinfo(KeyValues *kv) return info; } +static int get_activity_flags() +{ + return sm_show_activity.GetInt(); +} + int read_cmd_argc(const CCommand &args) { return args.ArgC(); @@ -420,6 +507,7 @@ static sm_core_t core_bridge = &g_LibSys, reinterpret_cast(&logic_engine), reinterpret_cast(&logic_filesystem), + &logic_playerinfo, &g_RootMenu, &g_Timers, &g_Players, @@ -436,6 +524,7 @@ static sm_core_t core_bridge = log_message, log_to_file, log_to_game, + conprint, get_cvar_string, UTIL_Format, UTIL_FormatArgs, @@ -456,8 +545,9 @@ static sm_core_t core_bridge = SM_AreConfigsExecuted, SM_ExecuteForPlugin, keyvalues_to_dbinfo, + get_activity_flags, GAMEFIX, - &serverGlobals + &serverGlobals, }; void InitLogicBridge() diff --git a/core/smn_player.cpp b/core/smn_player.cpp index 1afae29c..1e75e69b 100644 --- a/core/smn_player.cpp +++ b/core/smn_player.cpp @@ -38,34 +38,6 @@ #include #include -ConVar sm_show_activity("sm_show_activity", "13", FCVAR_SPONLY, "Activity display setting (see sourcemod.cfg)"); - -static cell_t sm_GetClientCount(IPluginContext *pCtx, const cell_t *params) -{ - if (params[1]) - { - return g_Players.NumPlayers(); - } - - int maxplayers = g_Players.MaxClients(); - int count = 0; - for (int i=1; i<=maxplayers; ++i) - { - CPlayer *pPlayer = g_Players.GetPlayerByIndex(i); - if ((pPlayer->IsConnected()) && !(pPlayer->IsInGame())) - { - count++; - } - } - - return (g_Players.NumPlayers() + count); -} - -static cell_t sm_GetMaxClients(IPluginContext *pCtx, const cell_t *params) -{ - return g_Players.MaxClients(); -} - static cell_t sm_GetMaxHumanPlayers(IPluginContext *pCtx, const cell_t *params) { int maxHumans = -1; @@ -82,704 +54,6 @@ static cell_t sm_GetMaxHumanPlayers(IPluginContext *pCtx, const cell_t *params) return maxHumans; } -static cell_t sm_GetClientName(IPluginContext *pCtx, const cell_t *params) -{ - int index = params[1]; - - if (index == 0) - { - static ConVar *hostname = NULL; - if (!hostname) - { - hostname = icvar->FindVar("hostname"); - if (!hostname) - { - return pCtx->ThrowNativeError("Could not find \"hostname\" cvar"); - } - } - pCtx->StringToLocalUTF8(params[2], static_cast(params[3]), hostname->GetString(), NULL); - return 1; - } - - if ((index < 1) || (index > g_Players.GetMaxClients())) - { - return pCtx->ThrowNativeError("Client index %d is invalid", index); - } - - CPlayer *pPlayer = g_Players.GetPlayerByIndex(index); - if (!pPlayer->IsConnected()) - { - return pCtx->ThrowNativeError("Client %d is not connected", index); - } - - pCtx->StringToLocalUTF8(params[2], static_cast(params[3]), pPlayer->GetName(), NULL); - return 1; -} - -static cell_t sm_GetClientIP(IPluginContext *pCtx, const cell_t *params) -{ - int index = params[1]; - if ((index < 1) || (index > g_Players.GetMaxClients())) - { - return pCtx->ThrowNativeError("Client index %d is invalid", index); - } - - CPlayer *pPlayer = g_Players.GetPlayerByIndex(index); - if (!pPlayer->IsConnected()) - { - return pCtx->ThrowNativeError("Client %d is not connected", index); - } - - char buf[64], *ptr; - strcpy(buf, pPlayer->GetIPAddress()); - - if (params[4] && (ptr = strchr(buf, ':'))) - { - *ptr = '\0'; - } - - pCtx->StringToLocal(params[2], static_cast(params[3]), buf); - return 1; -} - -static cell_t sm_GetClientAuthStr(IPluginContext *pCtx, const cell_t *params) -{ - int index = params[1]; - if ((index < 1) || (index > g_Players.GetMaxClients())) - { - return pCtx->ThrowNativeError("Client index %d is invalid", index); - } - - CPlayer *pPlayer = g_Players.GetPlayerByIndex(index); - if (!pPlayer->IsConnected()) - { - return pCtx->ThrowNativeError("Client %d is not connected", index); - } - - bool validate = true; - if (params[0] > 3) - { - validate = !!params[4]; - } - - const char *authstr = pPlayer->GetAuthString(validate); - - if (!authstr || authstr[0] == '\0') - { - return 0; - } - - pCtx->StringToLocal(params[2], static_cast(params[3]), authstr); - - return 1; -} - -static cell_t sm_GetSteamAccountID(IPluginContext *pCtx, const cell_t *params) -{ - int index = params[1]; - if ((index < 1) || (index > g_Players.GetMaxClients())) - { - return pCtx->ThrowNativeError("Client index %d is invalid", index); - } - - CPlayer *pPlayer = g_Players.GetPlayerByIndex(index); - if (!pPlayer->IsConnected()) - { - return pCtx->ThrowNativeError("Client %d is not connected", index); - } - - return pPlayer->GetSteamAccountID(!!params[2]); -} - -static cell_t sm_IsClientConnected(IPluginContext *pCtx, const cell_t *params) -{ - int index = params[1]; - if ((index < 1) || (index > g_Players.GetMaxClients())) - { - return pCtx->ThrowNativeError("Client index %d is invalid", index); - } - - return (g_Players.GetPlayerByIndex(index)->IsConnected()) ? 1 : 0; -} - -static cell_t sm_IsClientInGame(IPluginContext *pCtx, const cell_t *params) -{ - int index = params[1]; - if ((index < 1) || (index > g_Players.GetMaxClients())) - { - return pCtx->ThrowNativeError("Client index %d is invalid", index); - } - - return (g_Players.GetPlayerByIndex(index)->IsInGame()) ? 1 : 0; -} - -static cell_t sm_IsClientAuthorized(IPluginContext *pCtx, const cell_t *params) -{ - int index = params[1]; - if ((index < 1) || (index > g_Players.GetMaxClients())) - { - return pCtx->ThrowNativeError("Client index %d is invalid", index); - } - - return (g_Players.GetPlayerByIndex(index)->IsAuthorized()) ? 1 : 0; -} - -static cell_t sm_IsClientFakeClient(IPluginContext *pCtx, const cell_t *params) -{ - int index = params[1]; - if ((index < 1) || (index > g_Players.GetMaxClients())) - { - return pCtx->ThrowNativeError("Client index %d is invalid", index); - } - - CPlayer *pPlayer = g_Players.GetPlayerByIndex(index); - if (!pPlayer->IsConnected()) - { - return pCtx->ThrowNativeError("Client %d is not connected", index); - } - - return (pPlayer->IsFakeClient()) ? 1 : 0; -} - -static cell_t sm_IsClientSourceTV(IPluginContext *pCtx, const cell_t *params) -{ - int index = params[1]; - if ((index < 1) || (index > g_Players.GetMaxClients())) - { - return pCtx->ThrowNativeError("Client index %d is invalid", index); - } - - CPlayer *pPlayer = g_Players.GetPlayerByIndex(index); - if (!pPlayer->IsConnected()) - { - return pCtx->ThrowNativeError("Client %d is not connected", index); - } - - return (pPlayer->IsSourceTV()) ? 1 : 0; -} - -static cell_t sm_IsClientReplay(IPluginContext *pCtx, const cell_t *params) -{ - int index = params[1]; - if ((index < 1) || (index > g_Players.GetMaxClients())) - { - return pCtx->ThrowNativeError("Client index %d is invalid", index); - } - - CPlayer *pPlayer = g_Players.GetPlayerByIndex(index); - if (!pPlayer->IsConnected()) - { - return pCtx->ThrowNativeError("Client %d is not connected", index); - } - - return (pPlayer->IsReplay()) ? 1 : 0; -} - -static cell_t IsClientObserver(IPluginContext *pContext, const cell_t *params) -{ - int client = params[1]; - - CPlayer *pPlayer = g_Players.GetPlayerByIndex(client); - if (!pPlayer) - { - return pContext->ThrowNativeError("Client index %d is invalid", client); - } else if (!pPlayer->IsInGame()) { - return pContext->ThrowNativeError("Client %d is not in game", client); - } - - IPlayerInfo *pInfo = pPlayer->GetPlayerInfo(); - if (!pInfo) - { - return pContext->ThrowNativeError("IPlayerInfo not supported by game"); - } - - return pInfo->IsObserver() ? 1 : 0; -} - -static cell_t sm_GetClientInfo(IPluginContext *pContext, const cell_t *params) -{ - int client = params[1]; - CPlayer *pPlayer = g_Players.GetPlayerByIndex(client); - if (!pPlayer) - { - return pContext->ThrowNativeError("Client index %d is invalid", client); - } - if (!pPlayer->IsConnected()) - { - return pContext->ThrowNativeError("Client %d is not connected", client); - } - - char *key; - pContext->LocalToString(params[2], &key); - - const char *val = engine->GetClientConVarValue(client, key); - if (!val) - { - return false; - } - - pContext->StringToLocalUTF8(params[3], params[4], val, NULL); - return 1; -} - -static cell_t SetUserAdmin(IPluginContext *pContext, const cell_t *params) -{ - int client = params[1]; - CPlayer *pPlayer = g_Players.GetPlayerByIndex(client); - if (!pPlayer) - { - return pContext->ThrowNativeError("Client index %d is invalid", client); - } - if (!pPlayer->IsConnected()) - { - return pContext->ThrowNativeError("Client %d is not connected", client); - } - if (!g_Admins.IsValidAdmin(params[2]) && params[2] != INVALID_ADMIN_ID) - { - return pContext->ThrowNativeError("AdminId %x is invalid", params[2]); - } - - pPlayer->SetAdminId(params[2], params[3] ? true : false); - - return 1; -} - -static cell_t GetUserAdmin(IPluginContext *pContext, const cell_t *params) -{ - int client = params[1]; - CPlayer *pPlayer = g_Players.GetPlayerByIndex(client); - if (!pPlayer) - { - return pContext->ThrowNativeError("Client index %d is invalid", client); - } - if (!pPlayer->IsConnected()) - { - return pContext->ThrowNativeError("Client %d is not connected", client); - } - - return pPlayer->GetAdminId(); -} - -static cell_t AddUserFlags(IPluginContext *pContext, const cell_t *params) -{ - int client = params[1]; - CPlayer *pPlayer = g_Players.GetPlayerByIndex(client); - if (!pPlayer) - { - return pContext->ThrowNativeError("Client index %d is invalid", client); - } - if (!pPlayer->IsConnected()) - { - return pContext->ThrowNativeError("Client %d is not connected", client); - } - - AdminId id; - if ((id=pPlayer->GetAdminId()) == INVALID_ADMIN_ID) - { - id = g_Admins.CreateAdmin(NULL); - pPlayer->SetAdminId(id, true); - } - - cell_t *addr; - for (int i=2; i<=params[0]; i++) - { - pContext->LocalToPhysAddr(params[i], &addr); - g_Admins.SetAdminFlag(id, (AdminFlag)*addr, true); - } - - return 1; -} - -static cell_t RemoveUserFlags(IPluginContext *pContext, const cell_t *params) -{ - int client = params[1]; - CPlayer *pPlayer = g_Players.GetPlayerByIndex(client); - if (!pPlayer) - { - return pContext->ThrowNativeError("Client index %d is invalid", client); - } - if (!pPlayer->IsConnected()) - { - return pContext->ThrowNativeError("Client %d is not connected", client); - } - - AdminId id; - if ((id=pPlayer->GetAdminId()) == INVALID_ADMIN_ID) - { - return 0; - } - - cell_t *addr; - for (int i=2; i<=params[0]; i++) - { - pContext->LocalToPhysAddr(params[i], &addr); - g_Admins.SetAdminFlag(id, (AdminFlag)*addr, false); - } - - return 1; -} - -static cell_t SetUserFlagBits(IPluginContext *pContext, const cell_t *params) -{ - int client = params[1]; - CPlayer *pPlayer = g_Players.GetPlayerByIndex(client); - if (!pPlayer) - { - return pContext->ThrowNativeError("Client index %d is invalid", client); - } - if (!pPlayer->IsConnected()) - { - return pContext->ThrowNativeError("Client %d is not connected", client); - } - - AdminId id; - if ((id=pPlayer->GetAdminId()) == INVALID_ADMIN_ID) - { - id = g_Admins.CreateAdmin(NULL); - pPlayer->SetAdminId(id, true); - } - - g_Admins.SetAdminFlags(id, Access_Effective, params[2]); - - return 1; -} - -static cell_t GetUserFlagBits(IPluginContext *pContext, const cell_t *params) -{ - int client = params[1]; - CPlayer *pPlayer = g_Players.GetPlayerByIndex(client); - if (!pPlayer) - { - return pContext->ThrowNativeError("Client index %d is invalid", client); - } - if (!pPlayer->IsConnected()) - { - return pContext->ThrowNativeError("Client %d is not connected", client); - } - - AdminId id; - if ((id=pPlayer->GetAdminId()) == INVALID_ADMIN_ID) - { - return 0; - } - - return g_Admins.GetAdminFlags(id, Access_Effective); -} - -static cell_t GetClientUserId(IPluginContext *pContext, const cell_t *params) -{ - int client = params[1]; - CPlayer *pPlayer = g_Players.GetPlayerByIndex(client); - if (!pPlayer) - { - return pContext->ThrowNativeError("Client index %d is invalid", client); - } - if (!pPlayer->IsConnected()) - { - return pContext->ThrowNativeError("Client %d is not connected", client); - } - - return GetPlayerUserId(pPlayer->GetEdict()); -} - -static cell_t CanUserTarget(IPluginContext *pContext, const cell_t *params) -{ - int client = params[1]; - int target = params[2]; - - if (client == 0) - { - return 1; - } - - CPlayer *pPlayer = g_Players.GetPlayerByIndex(client); - if (!pPlayer) - { - return pContext->ThrowNativeError("Client index %d is invalid", client); - } else if (!pPlayer->IsConnected()) { - return pContext->ThrowNativeError("Client %d is not connected", client); - } - - CPlayer *pTarget = g_Players.GetPlayerByIndex(target); - if (!pTarget) - { - return pContext->ThrowNativeError("Client index %d is invalid", target); - } else if (!pTarget->IsConnected()) { - return pContext->ThrowNativeError("Client %d is not connected", target); - } - - return g_Admins.CanAdminTarget(pPlayer->GetAdminId(), pTarget->GetAdminId()) ? 1 : 0; -} - -static cell_t GetClientTeam(IPluginContext *pContext, const cell_t *params) -{ - int client = params[1]; - - CPlayer *pPlayer = g_Players.GetPlayerByIndex(client); - if (!pPlayer) - { - return pContext->ThrowNativeError("Client index %d is invalid", client); - } else if (!pPlayer->IsInGame()) { - return pContext->ThrowNativeError("Client %d is not in game", client); - } - - IPlayerInfo *pInfo = pPlayer->GetPlayerInfo(); - if (!pInfo) - { - return pContext->ThrowNativeError("IPlayerInfo not supported by game"); - } - - return pInfo->GetTeamIndex(); -} - -static cell_t GetFragCount(IPluginContext *pContext, const cell_t *params) -{ - int client = params[1]; - - CPlayer *pPlayer = g_Players.GetPlayerByIndex(client); - if (!pPlayer) - { - return pContext->ThrowNativeError("Client index %d is invalid", client); - } else if (!pPlayer->IsInGame()) { - return pContext->ThrowNativeError("Client %d is not in game", client); - } - - IPlayerInfo *pInfo = pPlayer->GetPlayerInfo(); - if (!pInfo) - { - return pContext->ThrowNativeError("IPlayerInfo not supported by game"); - } - - return pInfo->GetFragCount(); -} - -static cell_t GetDeathCount(IPluginContext *pContext, const cell_t *params) -{ - int client = params[1]; - - CPlayer *pPlayer = g_Players.GetPlayerByIndex(client); - if (!pPlayer) - { - return pContext->ThrowNativeError("Client index %d is invalid", client); - } else if (!pPlayer->IsInGame()) { - return pContext->ThrowNativeError("Client %d is not in game", client); - } - - IPlayerInfo *pInfo = pPlayer->GetPlayerInfo(); - if (!pInfo) - { - return pContext->ThrowNativeError("IPlayerInfo not supported by game"); - } - - return pInfo->GetDeathCount(); -} - -static cell_t GetArmorValue(IPluginContext *pContext, const cell_t *params) -{ - int client = params[1]; - - CPlayer *pPlayer = g_Players.GetPlayerByIndex(client); - if (!pPlayer) - { - return pContext->ThrowNativeError("Client index %d is invalid", client); - } else if (!pPlayer->IsInGame()) { - return pContext->ThrowNativeError("Client %d is not in game", client); - } - - IPlayerInfo *pInfo = pPlayer->GetPlayerInfo(); - if (!pInfo) - { - return pContext->ThrowNativeError("IPlayerInfo not supported by game"); - } - - return pInfo->GetArmorValue(); -} - -static cell_t GetAbsOrigin(IPluginContext *pContext, const cell_t *params) -{ - int client = params[1]; - - CPlayer *pPlayer = g_Players.GetPlayerByIndex(client); - if (!pPlayer) - { - return pContext->ThrowNativeError("Client index %d is invalid", client); - } else if (!pPlayer->IsInGame()) { - return pContext->ThrowNativeError("Client %d is not in game", client); - } - - IPlayerInfo *pInfo = pPlayer->GetPlayerInfo(); - if (!pInfo) - { - return pContext->ThrowNativeError("IPlayerInfo not supported by game"); - } - - cell_t *pVec; - pContext->LocalToPhysAddr(params[2], &pVec); - - Vector vec = pInfo->GetAbsOrigin(); - pVec[0] = sp_ftoc(vec.x); - pVec[1] = sp_ftoc(vec.y); - pVec[2] = sp_ftoc(vec.z); - - return 1; -} - -static cell_t GetAbsAngles(IPluginContext *pContext, const cell_t *params) -{ - int client = params[1]; - - CPlayer *pPlayer = g_Players.GetPlayerByIndex(client); - if (!pPlayer) - { - return pContext->ThrowNativeError("Client index %d is invalid", client); - } else if (!pPlayer->IsInGame()) { - return pContext->ThrowNativeError("Client %d is not in game", client); - } - - IPlayerInfo *pInfo = pPlayer->GetPlayerInfo(); - if (!pInfo) - { - return pContext->ThrowNativeError("IPlayerInfo not supported by game"); - } - - cell_t *pAng; - pContext->LocalToPhysAddr(params[2], &pAng); - - QAngle ang = pInfo->GetAbsAngles(); - pAng[0] = sp_ftoc(ang.x); - pAng[1] = sp_ftoc(ang.y); - pAng[2] = sp_ftoc(ang.z); - - return 1; -} - -static cell_t GetPlayerMins(IPluginContext *pContext, const cell_t *params) -{ - int client = params[1]; - - CPlayer *pPlayer = g_Players.GetPlayerByIndex(client); - if (!pPlayer) - { - return pContext->ThrowNativeError("Client index %d is invalid", client); - } else if (!pPlayer->IsInGame()) { - return pContext->ThrowNativeError("Client %d is not in game", client); - } - - IPlayerInfo *pInfo = pPlayer->GetPlayerInfo(); - if (!pInfo) - { - return pContext->ThrowNativeError("IPlayerInfo not supported by game"); - } - - cell_t *pVec; - pContext->LocalToPhysAddr(params[2], &pVec); - - Vector vec = pInfo->GetPlayerMins(); - pVec[0] = sp_ftoc(vec.x); - pVec[1] = sp_ftoc(vec.y); - pVec[2] = sp_ftoc(vec.z); - - return 1; -} - -static cell_t GetPlayerMaxs(IPluginContext *pContext, const cell_t *params) -{ - int client = params[1]; - - CPlayer *pPlayer = g_Players.GetPlayerByIndex(client); - if (!pPlayer) - { - return pContext->ThrowNativeError("Client index %d is invalid", client); - } else if (!pPlayer->IsInGame()) { - return pContext->ThrowNativeError("Client %d is not in game", client); - } - - IPlayerInfo *pInfo = pPlayer->GetPlayerInfo(); - if (!pInfo) - { - return pContext->ThrowNativeError("IPlayerInfo not supported by game"); - } - - cell_t *pVec; - pContext->LocalToPhysAddr(params[2], &pVec); - - Vector vec = pInfo->GetPlayerMaxs(); - pVec[0] = sp_ftoc(vec.x); - pVec[1] = sp_ftoc(vec.y); - pVec[2] = sp_ftoc(vec.z); - - return 1; -} - -static cell_t GetWeaponName(IPluginContext *pContext, const cell_t *params) -{ - int client = params[1]; - - CPlayer *pPlayer = g_Players.GetPlayerByIndex(client); - if (!pPlayer) - { - return pContext->ThrowNativeError("Client index %d is invalid", client); - } else if (!pPlayer->IsInGame()) { - return pContext->ThrowNativeError("Client %d is not in game", client); - } - - IPlayerInfo *pInfo = pPlayer->GetPlayerInfo(); - if (!pInfo) - { - return pContext->ThrowNativeError("IPlayerInfo not supported by game"); - } - - const char *weapon = pInfo->GetWeaponName(); - pContext->StringToLocalUTF8(params[2], static_cast(params[3]), weapon ? weapon : "", NULL); - - return 1; -} - -static cell_t GetModelName(IPluginContext *pContext, const cell_t *params) -{ - int client = params[1]; - - CPlayer *pPlayer = g_Players.GetPlayerByIndex(client); - if (!pPlayer) - { - return pContext->ThrowNativeError("Client index %d is invalid", client); - } else if (!pPlayer->IsInGame()) { - return pContext->ThrowNativeError("Client %d is not in game", client); - } - - IPlayerInfo *pInfo = pPlayer->GetPlayerInfo(); - if (!pInfo) - { - return pContext->ThrowNativeError("IPlayerInfo not supported by game"); - } - - const char *model = pInfo->GetModelName(); - pContext->StringToLocalUTF8(params[2], static_cast(params[3]), model ? model : "", NULL); - - return 1; -} - -static cell_t GetHealth(IPluginContext *pContext, const cell_t *params) -{ - int client = params[1]; - - CPlayer *pPlayer = g_Players.GetPlayerByIndex(client); - if (!pPlayer) - { - return pContext->ThrowNativeError("Client index %d is invalid", client); - } else if (!pPlayer->IsInGame()) { - return pContext->ThrowNativeError("Client %d is not in game", client); - } - - IPlayerInfo *pInfo = pPlayer->GetPlayerInfo(); - if (!pInfo) - { - return pContext->ThrowNativeError("IPlayerInfo not supported by game"); - } - - return pInfo->GetHealth(); -} - static cell_t GetTimeConnected(IPluginContext *pContext, const cell_t *params) { int client = params[1]; @@ -1083,381 +357,6 @@ static cell_t GetAvgPackets(IPluginContext *pContext, const cell_t *params) return sp_ftoc(value); } -static cell_t GetClientOfUserId(IPluginContext *pContext, const cell_t *params) -{ - return g_Players.GetClientOfUserId(params[1]); -} - -static cell_t _ShowActivity(IPluginContext *pContext, - const cell_t *params, - const char *tag, - cell_t fmt_param) -{ - char message[255]; - char buffer[255]; - int value = sm_show_activity.GetInt(); - unsigned int replyto = g_ChatTriggers.GetReplyTo(); - int client = params[1]; - - const char *name = "Console"; - const char *sign = "ADMIN"; - bool display_in_chat = false; - if (client != 0) - { - CPlayer *pPlayer = g_Players.GetPlayerByIndex(client); - if (!pPlayer || !pPlayer->IsConnected()) - { - return pContext->ThrowNativeError("Client index %d is invalid", client); - } - name = pPlayer->GetName(); - AdminId id = pPlayer->GetAdminId(); - if (id == INVALID_ADMIN_ID - || !g_Admins.GetAdminFlag(id, Admin_Generic, Access_Effective)) - { - sign = "PLAYER"; - } - - /* Display the message to the client? */ - if (replyto == SM_REPLY_CONSOLE) - { - g_SourceMod.SetGlobalTarget(client); - g_SourceMod.FormatString(buffer, sizeof(buffer), pContext, params, fmt_param); - - if (pContext->GetLastNativeError() != SP_ERROR_NONE) - { - return 0; - } - - UTIL_Format(message, sizeof(message), "%s%s\n", tag, buffer); - pPlayer->PrintToConsole(message); - display_in_chat = true; - } - } - else - { - g_SourceMod.SetGlobalTarget(SOURCEMOD_SERVER_LANGUAGE); - g_SourceMod.FormatString(buffer, sizeof(buffer), pContext, params, fmt_param); - - if (pContext->GetLastNativeError() != SP_ERROR_NONE) - { - return 0; - } - - UTIL_Format(message, sizeof(message), "%s%s\n", tag, buffer); - META_CONPRINT(message); - } - - if (!value) - { - return 1; - } - - int maxClients = g_Players.GetMaxClients(); - for (int i=1; i<=maxClients; i++) - { - CPlayer *pPlayer = g_Players.GetPlayerByIndex(i); - if (!pPlayer->IsInGame() - || pPlayer->IsFakeClient() - || (display_in_chat && i == client)) - { - continue; - } - AdminId id = pPlayer->GetAdminId(); - g_SourceMod.SetGlobalTarget(i); - if (id == INVALID_ADMIN_ID - || !g_Admins.GetAdminFlag(id, Admin_Generic, Access_Effective)) - { - /* Treat this as a normal user */ - if ((value & 1) || (value & 2)) - { - const char *newsign = sign; - if ((value & 2) || (i == client)) - { - newsign = name; - } - g_SourceMod.FormatString(buffer, sizeof(buffer), pContext, params, fmt_param); - - if (pContext->GetLastNativeError() != SP_ERROR_NONE) - { - return 0; - } - - UTIL_Format(message, sizeof(message), "%s%s: %s", tag, newsign, buffer); - g_HL2.TextMsg(i, HUD_PRINTTALK, message); - } - } - else - { - /* Treat this as an admin user */ - bool is_root = g_Admins.GetAdminFlag(id, Admin_Root, Access_Effective); - if ((value & 4) - || (value & 8) - || ((value & 16) && is_root)) - { - const char *newsign = sign; - if ((value & 8) || ((value & 16) && is_root) || (i == client)) - { - newsign = name; - } - g_SourceMod.FormatString(buffer, sizeof(buffer), pContext, params, fmt_param); - - if (pContext->GetLastNativeError() != SP_ERROR_NONE) - { - return 0; - } - - UTIL_Format(message, sizeof(message), "%s%s: %s", tag, newsign, buffer); - g_HL2.TextMsg(i, HUD_PRINTTALK, message); - } - } - } - - return 1; -} - -static cell_t _ShowActivity2(IPluginContext *pContext, - const cell_t *params, - const char *tag, - cell_t fmt_param) -{ - char message[255]; - char buffer[255]; - int value = sm_show_activity.GetInt(); - unsigned int replyto = g_ChatTriggers.GetReplyTo(); - int client = params[1]; - - const char *name = "Console"; - const char *sign = "ADMIN"; - if (client != 0) - { - CPlayer *pPlayer = g_Players.GetPlayerByIndex(client); - if (!pPlayer || !pPlayer->IsConnected()) - { - return pContext->ThrowNativeError("Client index %d is invalid", client); - } - name = pPlayer->GetName(); - AdminId id = pPlayer->GetAdminId(); - if (id == INVALID_ADMIN_ID - || !g_Admins.GetAdminFlag(id, Admin_Generic, Access_Effective)) - { - sign = "PLAYER"; - } - - g_SourceMod.SetGlobalTarget(client); - g_SourceMod.FormatString(buffer, sizeof(buffer), pContext, params, fmt_param); - - if (pContext->GetLastNativeError() != SP_ERROR_NONE) - { - return 0; - } - - /* We don't display directly to the console because the chat text - * simply gets added to the console, so we don't want it to print - * twice. - */ - UTIL_Format(message, sizeof(message), "%s%s", tag, buffer); - g_HL2.TextMsg(client, HUD_PRINTTALK, message); - } - else - { - g_SourceMod.SetGlobalTarget(SOURCEMOD_SERVER_LANGUAGE); - g_SourceMod.FormatString(buffer, sizeof(buffer), pContext, params, fmt_param); - - if (pContext->GetLastNativeError() != SP_ERROR_NONE) - { - return 0; - } - - UTIL_Format(message, sizeof(message), "%s%s\n", tag, buffer); - META_CONPRINT(message); - } - - if (!value) - { - return 1; - } - - int maxClients = g_Players.GetMaxClients(); - for (int i=1; i<=maxClients; i++) - { - CPlayer *pPlayer = g_Players.GetPlayerByIndex(i); - if (!pPlayer->IsInGame() - || pPlayer->IsFakeClient() - || i == client) - { - continue; - } - AdminId id = pPlayer->GetAdminId(); - g_SourceMod.SetGlobalTarget(i); - if (id == INVALID_ADMIN_ID - || !g_Admins.GetAdminFlag(id, Admin_Generic, Access_Effective)) - { - /* Treat this as a normal user */ - if ((value & 1) || (value & 2)) - { - const char *newsign = sign; - if ((value & 2)) - { - newsign = name; - } - g_SourceMod.FormatString(buffer, sizeof(buffer), pContext, params, fmt_param); - - if (pContext->GetLastNativeError() != SP_ERROR_NONE) - { - return 0; - } - - UTIL_Format(message, sizeof(message), "%s%s: %s", tag, newsign, buffer); - g_HL2.TextMsg(i, HUD_PRINTTALK, message); - } - } - else - { - /* Treat this as an admin user */ - bool is_root = g_Admins.GetAdminFlag(id, Admin_Root, Access_Effective); - if ((value & 4) - || (value & 8) - || ((value & 16) && is_root)) - { - const char *newsign = sign; - if ((value & 8) || ((value & 16) && is_root)) - { - newsign = name; - } - g_SourceMod.FormatString(buffer, sizeof(buffer), pContext, params, fmt_param); - - if (pContext->GetLastNativeError() != SP_ERROR_NONE) - { - return 0; - } - - UTIL_Format(message, sizeof(message), "%s%s: %s", tag, newsign, buffer); - g_HL2.TextMsg(i, HUD_PRINTTALK, message); - } - } - } - - return 1; -} - -static cell_t ShowActivity(IPluginContext *pContext, const cell_t *params) -{ - return _ShowActivity(pContext, params, "[SM] ", 2); -} - -static cell_t ShowActivityEx(IPluginContext *pContext, const cell_t *params) -{ - char *str; - pContext->LocalToString(params[2], &str); - - return _ShowActivity(pContext, params, str, 3); -} - -static cell_t ShowActivity2(IPluginContext *pContext, const cell_t *params) -{ - char *str; - pContext->LocalToString(params[2], &str); - - return _ShowActivity2(pContext, params, str, 3); -} - -static cell_t KickClient(IPluginContext *pContext, const cell_t *params) -{ - int client = params[1]; - - CPlayer *pPlayer = g_Players.GetPlayerByIndex(client); - if (!pPlayer) - { - return pContext->ThrowNativeError("Client index %d is invalid", client); - } - else if (!pPlayer->IsConnected()) - { - return pContext->ThrowNativeError("Client %d is not connected", client); - } - - /* Ignore duplicate kicks */ - if (pPlayer->IsInKickQueue()) - { - return 1; - } - - g_SourceMod.SetGlobalTarget(client); - - char buffer[256]; - g_SourceMod.FormatString(buffer, sizeof(buffer), pContext, params, 2); - - if (pContext->GetLastNativeError() != SP_ERROR_NONE) - { - return 0; - } - - if (pPlayer->IsFakeClient()) - { - // Kick uses the kickid command for bots. It is already delayed - // until the next frame unless someone flushes command buffer - pPlayer->Kick(buffer); - return 1; - } - - g_HL2.AddDelayedKick(client, pPlayer->GetUserId(), buffer); - - return 1; -} - -static cell_t KickClientEx(IPluginContext *pContext, const cell_t *params) -{ - int client = params[1]; - - CPlayer *pPlayer = g_Players.GetPlayerByIndex(client); - if (!pPlayer) - { - return pContext->ThrowNativeError("Client index %d is invalid", client); - } - else if (!pPlayer->IsConnected()) - { - return pContext->ThrowNativeError("Client %d is not connected", client); - } - - g_SourceMod.SetGlobalTarget(client); - - char buffer[256]; - g_SourceMod.FormatString(buffer, sizeof(buffer), pContext, params, 2); - - if (pContext->GetLastNativeError() != SP_ERROR_NONE) - { - return 0; - } - - pPlayer->Kick(buffer); - - return 1; -} - -static cell_t ChangeClientTeam(IPluginContext *pContext, const cell_t *params) -{ - int client = params[1]; - - CPlayer *pPlayer = g_Players.GetPlayerByIndex(client); - if (!pPlayer) - { - return pContext->ThrowNativeError("Client index %d is invalid", client); - } - else if (!pPlayer->IsInGame()) - { - return pContext->ThrowNativeError("Client %d is not in game", client); - } - - IPlayerInfo *pInfo = pPlayer->GetPlayerInfo(); - if (!pInfo) - { - return pContext->ThrowNativeError("IPlayerInfo not supported by game"); - } - - pInfo->ChangeTeam(params[2]); - - return 1; -} - static cell_t RunAdminCacheChecks(IPluginContext *pContext, const cell_t *params) { int client = params[1]; @@ -1482,221 +381,9 @@ static cell_t RunAdminCacheChecks(IPluginContext *pContext, const cell_t *params return (id != pPlayer->GetAdminId()) ? 1 : 0; } -static cell_t NotifyPostAdminCheck(IPluginContext *pContext, const cell_t *params) -{ - int client = params[1]; - - CPlayer *pPlayer = g_Players.GetPlayerByIndex(client); - if (!pPlayer) - { - return pContext->ThrowNativeError("Client index %d is invalid", client); - } - else if (!pPlayer->IsInGame()) { - return pContext->ThrowNativeError("Client %d is not in game", client); - } - else if (!pPlayer->IsAuthorized()) - { - return pContext->ThrowNativeError("Client %d is not authorized", client); - } - - pPlayer->NotifyPostAdminChecks(); - - return 1; -} - -static cell_t IsClientInKickQueue(IPluginContext *pContext, const cell_t *params) -{ - int client = params[1]; - - CPlayer *pPlayer = g_Players.GetPlayerByIndex(client); - - if (!pPlayer) - { - return pContext->ThrowNativeError("Client index %d is invalid", client); - } - else if (!pPlayer->IsConnected()) - { - return pContext->ThrowNativeError("Client %d is not in game", client); - } - - return pPlayer->IsInKickQueue() ? 1 : 0; -} - -static cell_t ProcessTargetString(IPluginContext *pContext, const cell_t *params) -{ - cmd_target_info_t info; - - pContext->LocalToString(params[1], (char **)&info.pattern); - info.admin = params[2]; - pContext->LocalToPhysAddr(params[3], &info.targets); - info.max_targets = params[4]; - info.flags = params[5]; - pContext->LocalToString(params[6], &info.target_name); - info.target_name_maxlength = params[7]; - - cell_t *tn_is_ml; - pContext->LocalToPhysAddr(params[8], &tn_is_ml); - - g_Players.ProcessCommandTarget(&info); - - if (info.target_name_style == COMMAND_TARGETNAME_ML) - { - *tn_is_ml = 1; - } - else - { - *tn_is_ml = 0; - } - - if (info.num_targets == 0) - { - return info.reason; - } - else - { - return info.num_targets; - } -} - -static cell_t FormatActivitySource(IPluginContext *pContext, const cell_t *params) -{ - int value; - int client; - int target; - CPlayer *pTarget; - AdminId aidTarget; - const char *identity[2] = {"Console", "ADMIN"}; - - client = params[1]; - target = params[2]; - - if ((pTarget = g_Players.GetPlayerByIndex(target)) == NULL) - { - return pContext->ThrowNativeError("Invalid client index %d", target); - } - if (!pTarget->IsConnected()) - { - return pContext->ThrowNativeError("Client %d not connected", target); - } - - value = sm_show_activity.GetInt(); - - if (client != 0) - { - CPlayer *pPlayer; - - if ((pPlayer = g_Players.GetPlayerByIndex(client)) == NULL) - { - return pContext->ThrowNativeError("Invalid client index %d", client); - } - if (!pPlayer->IsConnected()) - { - return pContext->ThrowNativeError("Client %d not connected", client); - } - - identity[0] = pPlayer->GetName(); - - AdminId id = pPlayer->GetAdminId(); - if (id == INVALID_ADMIN_ID - || !g_Admins.GetAdminFlag(id, Admin_Generic, Access_Effective)) - { - identity[1] = "PLAYER"; - } - } - - int mode = 1; - bool bShowActivity = false; - - if ((aidTarget = pTarget->GetAdminId()) == INVALID_ADMIN_ID - || !g_Admins.GetAdminFlag(aidTarget, Admin_Generic, Access_Effective)) - { - /* Treat this as a normal user */ - if ((value & 1) || (value & 2)) - { - if ((value & 2) || (target == client)) - { - mode = 0; - } - bShowActivity = true; - } - } - else - { - /* Treat this as an admin user */ - bool is_root = g_Admins.GetAdminFlag(aidTarget, Admin_Root, Access_Effective); - if ((value & 4) - || (value & 8) - || ((value & 16) && is_root)) - { - if ((value & 8) || ((value & 16) && is_root) || (target == client)) - { - mode = 0; - } - bShowActivity = true; - } - } - - /* Otherwise, send it back to the script. */ - pContext->StringToLocalUTF8(params[3], params[4], identity[mode], NULL); - - return bShowActivity ? 1 : 0; -} - -static cell_t sm_GetClientSerial(IPluginContext *pContext, const cell_t *params) -{ - int client = params[1]; - - CPlayer *pPlayer = g_Players.GetPlayerByIndex(client); - if (!pPlayer) - { - return pContext->ThrowNativeError("Client index %d is invalid", client); - } - - return pPlayer->GetSerial(); -} - -static cell_t sm_GetClientFromSerial(IPluginContext *pContext, const cell_t *params) -{ - return g_Players.GetClientFromSerial(params[1]); -} - REGISTER_NATIVES(playernatives) { - {"AddUserFlags", AddUserFlags}, - {"CanUserTarget", CanUserTarget}, - {"ChangeClientTeam", ChangeClientTeam}, - {"GetClientAuthString", sm_GetClientAuthStr}, - {"GetSteamAccountID", sm_GetSteamAccountID}, - {"GetClientCount", sm_GetClientCount}, - {"GetClientInfo", sm_GetClientInfo}, - {"GetClientIP", sm_GetClientIP}, - {"GetClientName", sm_GetClientName}, - {"GetClientTeam", GetClientTeam}, - {"GetClientUserId", GetClientUserId}, - {"GetMaxClients", sm_GetMaxClients}, {"GetMaxHumanPlayers", sm_GetMaxHumanPlayers}, - {"GetUserAdmin", GetUserAdmin}, - {"GetUserFlagBits", GetUserFlagBits}, - {"IsClientAuthorized", sm_IsClientAuthorized}, - {"IsClientConnected", sm_IsClientConnected}, - {"IsFakeClient", sm_IsClientFakeClient}, - {"IsClientSourceTV", sm_IsClientSourceTV}, - {"IsClientReplay", sm_IsClientReplay}, - {"IsClientInGame", sm_IsClientInGame}, - {"IsClientObserver", IsClientObserver}, - {"RemoveUserFlags", RemoveUserFlags}, - {"SetUserAdmin", SetUserAdmin}, - {"SetUserFlagBits", SetUserFlagBits}, - {"GetClientDeaths", GetDeathCount}, - {"GetClientFrags", GetFragCount}, - {"GetClientArmor", GetArmorValue}, - {"GetClientAbsOrigin", GetAbsOrigin}, - {"GetClientAbsAngles", GetAbsAngles}, - {"GetClientMins", GetPlayerMins}, - {"GetClientMaxs", GetPlayerMaxs}, - {"GetClientWeapon", GetWeaponName}, - {"GetClientModel", GetModelName}, - {"GetClientHealth", GetHealth}, {"GetClientTime", GetTimeConnected}, {"GetClientDataRate", GetDataRate}, {"IsClientTimingOut", IsTimingOut}, @@ -1706,19 +393,7 @@ REGISTER_NATIVES(playernatives) {"GetClientAvgChoke", GetAvgChoke}, {"GetClientAvgData", GetAvgData}, {"GetClientAvgPackets", GetAvgPackets}, - {"GetClientOfUserId", GetClientOfUserId}, - {"ShowActivity", ShowActivity}, - {"ShowActivityEx", ShowActivityEx}, - {"ShowActivity2", ShowActivity2}, - {"KickClient", KickClient}, - {"KickClientEx", KickClientEx}, {"RunAdminCacheChecks", RunAdminCacheChecks}, - {"NotifyPostAdminCheck", NotifyPostAdminCheck}, - {"IsClientInKickQueue", IsClientInKickQueue}, - {"ProcessTargetString", ProcessTargetString}, - {"FormatActivitySource", FormatActivitySource}, - {"GetClientSerial", sm_GetClientSerial}, - {"GetClientFromSerial", sm_GetClientFromSerial}, {NULL, NULL} }; diff --git a/public/IAdminSystem.h b/public/IAdminSystem.h index 17317159..b5a06ae7 100644 --- a/public/IAdminSystem.h +++ b/public/IAdminSystem.h @@ -35,7 +35,7 @@ #include #define SMINTERFACE_ADMINSYS_NAME "IAdminSys" -#define SMINTERFACE_ADMINSYS_VERSION 6 +#define SMINTERFACE_ADMINSYS_VERSION 7 /** * @file IAdminSystem.h @@ -726,6 +726,14 @@ namespace SourceMod * @return True on success, false if not found. */ virtual bool FindFlagChar(AdminFlag flag, char *c) =0; + + /** + * brief Returns whether or not an admin id is valid. + * + * @param id Admin id to check. + * @return True if valid, otherwise false. + */ + virtual bool IsValidAdmin(AdminId id) =0; }; }