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 "ForwardSys.h"
ds@1952: #include "ShareSys.h"
ds@1952: #include "AdminCache.h"
ds@1952: #include "ConCmdManager.h"
ds@1952: #include "MenuStyle_Valve.h"
ds@1952: #include "MenuStyle_Radio.h"
ds@1952: #include "sm_stringutil.h"
ds@1952: #include "CoreConfig.h"
ds@1952: #include "TimerSys.h"
ds@1952: #include "Translator.h"
ds@1952: #include "Logger.h"
ds@1952: #include "ChatTriggers.h"
ds@1952: #include "HalfLife2.h"
ds@1952: #include
ds@1952: #include
ds@1952: #include "GameConfigs.h"
faluco@1993: #include "systems/ExtensionSys.h"
ds@1952:
ds@1952: PlayerManager g_Players;
ds@1952: bool g_OnMapStarted = false;
ds@1952: IForward *PreAdminCheck = NULL;
ds@1952: IForward *PostAdminCheck = NULL;
ds@1952: IForward *PostAdminFilter = NULL;
ds@1952: const unsigned int *g_NumPlayersToAuth = NULL;
ds@1952: int lifestate_offset = -1;
ds@1952: List target_processors;
ds@1952:
ds@1952: SH_DECL_HOOK5(IServerGameClients, ClientConnect, SH_NOATTRIB, 0, bool, edict_t *, const char *, const char *, char *, int);
ds@1952: SH_DECL_HOOK2_void(IServerGameClients, ClientPutInServer, SH_NOATTRIB, 0, edict_t *, const char *);
ds@1952: SH_DECL_HOOK1_void(IServerGameClients, ClientDisconnect, SH_NOATTRIB, 0, edict_t *);
ds@1952: #if defined ORANGEBOX_BUILD
ds@1952: SH_DECL_HOOK2_void(IServerGameClients, ClientCommand, SH_NOATTRIB, 0, edict_t *, const CCommand &);
ds@1952: #else
ds@1952: SH_DECL_HOOK1_void(IServerGameClients, ClientCommand, SH_NOATTRIB, 0, edict_t *);
ds@1952: #endif
ds@1952: SH_DECL_HOOK1_void(IServerGameClients, ClientSettingsChanged, SH_NOATTRIB, 0, edict_t *);
ds@1952: SH_DECL_HOOK3_void(IServerGameDLL, ServerActivate, SH_NOATTRIB, 0, edict_t *, int, int);
ds@1952:
ds@1952: class KickPlayerTimer : public ITimedEvent
ds@1952: {
ds@1952: public:
ds@1952: ResultType OnTimer(ITimer *pTimer, void *pData)
ds@1952: {
ds@1952: int userid = (int)pData;
ds@1952: int client = g_Players.GetClientOfUserId(userid);
ds@1952: if (client)
ds@1952: {
ds@1952: CPlayer *player = g_Players.GetPlayerByIndex(client);
ds@1952: player->Kick("Your name is reserved by SourceMod; set your password to use it.");
ds@1952: }
ds@1952: return Pl_Stop;
ds@1952: }
ds@1952: void OnTimerEnd(ITimer *pTimer, void *pData)
ds@1952: {
ds@1952: }
ds@1952: } s_KickPlayerTimer;
ds@1952:
ds@1952: PlayerManager::PlayerManager()
ds@1952: {
ds@1952: m_AuthQueue = NULL;
ds@1952: m_FirstPass = false;
ds@1952: m_maxClients = 0;
ds@1952:
ds@1952: m_UserIdLookUp = new int[USHRT_MAX+1];
ds@1952: memset(m_UserIdLookUp, 0, sizeof(int) * (USHRT_MAX+1));
ds@1952: }
ds@1952:
ds@1952: PlayerManager::~PlayerManager()
ds@1952: {
ds@1952: g_NumPlayersToAuth = NULL;
ds@1952:
ds@1952: delete [] m_AuthQueue;
ds@1952: delete [] m_UserIdLookUp;
ds@1952: }
ds@1952:
ds@1952: void PlayerManager::OnSourceModAllInitialized()
ds@1952: {
ds@1952: SH_ADD_HOOK_MEMFUNC(IServerGameClients, ClientConnect, serverClients, this, &PlayerManager::OnClientConnect, false);
ds@1952: SH_ADD_HOOK_MEMFUNC(IServerGameClients, ClientConnect, serverClients, this, &PlayerManager::OnClientConnect_Post, true);
ds@1952: SH_ADD_HOOK_MEMFUNC(IServerGameClients, ClientPutInServer, serverClients, this, &PlayerManager::OnClientPutInServer, true);
ds@1952: SH_ADD_HOOK_MEMFUNC(IServerGameClients, ClientDisconnect, serverClients, this, &PlayerManager::OnClientDisconnect, false);
ds@1952: SH_ADD_HOOK_MEMFUNC(IServerGameClients, ClientDisconnect, serverClients, this, &PlayerManager::OnClientDisconnect_Post, true);
ds@1952: SH_ADD_HOOK_MEMFUNC(IServerGameClients, ClientCommand, serverClients, this, &PlayerManager::OnClientCommand, false);
ds@1952: SH_ADD_HOOK_MEMFUNC(IServerGameClients, ClientSettingsChanged, serverClients, this, &PlayerManager::OnClientSettingsChanged, true);
ds@1952: SH_ADD_HOOK_MEMFUNC(IServerGameDLL, ServerActivate, gamedll, this, &PlayerManager::OnServerActivate, true);
ds@1952:
ds@1952: g_ShareSys.AddInterface(NULL, this);
ds@1952:
ds@1952: ParamType p1[] = {Param_Cell, Param_String, Param_Cell};
ds@1952: ParamType p2[] = {Param_Cell};
ds@1952:
ds@2181: m_clconnect = g_Forwards.CreateForward("OnClientConnect", ET_LowEvent, 3, p1);
ds@1952: m_clputinserver = g_Forwards.CreateForward("OnClientPutInServer", ET_Ignore, 1, p2);
ds@1952: m_cldisconnect = g_Forwards.CreateForward("OnClientDisconnect", ET_Ignore, 1, p2);
ds@1952: m_cldisconnect_post = g_Forwards.CreateForward("OnClientDisconnect_Post", ET_Ignore, 1, p2);
ds@1952: m_clcommand = g_Forwards.CreateForward("OnClientCommand", ET_Hook, 2, NULL, Param_Cell, Param_Cell);
ds@1952: m_clinfochanged = g_Forwards.CreateForward("OnClientSettingsChanged", ET_Ignore, 1, p2);
ds@1952: m_clauth = g_Forwards.CreateForward("OnClientAuthorized", ET_Ignore, 2, NULL, Param_Cell, Param_String);
ds@1952: m_onActivate = g_Forwards.CreateForward("OnServerLoad", ET_Ignore, 0, NULL);
ds@1952: m_onActivate2 = g_Forwards.CreateForward("OnMapStart", ET_Ignore, 0, NULL);
ds@1952:
ds@1952: PreAdminCheck = g_Forwards.CreateForward("OnClientPreAdminCheck", ET_Event, 1, p1);
ds@1952: PostAdminCheck = g_Forwards.CreateForward("OnClientPostAdminCheck", ET_Ignore, 1, p1);
ds@1952: PostAdminFilter = g_Forwards.CreateForward("OnClientPostAdminFilter", ET_Ignore, 1, p1);
dvander@1996:
dvander@1996: m_bIsListenServer = !engine->IsDedicatedServer();
dvander@1996: m_ListenClient = 0;
ds@1952: }
ds@1952:
ds@1952: void PlayerManager::OnSourceModShutdown()
ds@1952: {
ds@1952: SH_REMOVE_HOOK_MEMFUNC(IServerGameClients, ClientConnect, serverClients, this, &PlayerManager::OnClientConnect, false);
ds@1952: SH_REMOVE_HOOK_MEMFUNC(IServerGameClients, ClientPutInServer, serverClients, this, &PlayerManager::OnClientPutInServer, true);
ds@1952: SH_REMOVE_HOOK_MEMFUNC(IServerGameClients, ClientDisconnect, serverClients, this, &PlayerManager::OnClientDisconnect, false);
ds@1952: SH_REMOVE_HOOK_MEMFUNC(IServerGameClients, ClientDisconnect, serverClients, this, &PlayerManager::OnClientDisconnect_Post, true);
ds@1952: SH_REMOVE_HOOK_MEMFUNC(IServerGameClients, ClientCommand, serverClients, this, &PlayerManager::OnClientCommand, false);
ds@1952: SH_REMOVE_HOOK_MEMFUNC(IServerGameClients, ClientSettingsChanged, serverClients, this, &PlayerManager::OnClientSettingsChanged, true);
ds@1952: SH_REMOVE_HOOK_MEMFUNC(IServerGameDLL, ServerActivate, gamedll, this, &PlayerManager::OnServerActivate, true);
ds@1952:
ds@1952: /* Release forwards */
ds@1952: g_Forwards.ReleaseForward(m_clconnect);
ds@1952: g_Forwards.ReleaseForward(m_clputinserver);
ds@1952: g_Forwards.ReleaseForward(m_cldisconnect);
ds@1952: g_Forwards.ReleaseForward(m_cldisconnect_post);
ds@1952: g_Forwards.ReleaseForward(m_clcommand);
ds@1952: g_Forwards.ReleaseForward(m_clinfochanged);
ds@1952: g_Forwards.ReleaseForward(m_clauth);
ds@1952: g_Forwards.ReleaseForward(m_onActivate);
ds@1952: g_Forwards.ReleaseForward(m_onActivate2);
ds@1952:
ds@1952: g_Forwards.ReleaseForward(PreAdminCheck);
ds@1952: g_Forwards.ReleaseForward(PostAdminCheck);
ds@1952: g_Forwards.ReleaseForward(PostAdminFilter);
ds@1952:
ds@1952: delete [] m_Players;
ds@1952: }
ds@1952:
ds@1952: ConfigResult PlayerManager::OnSourceModConfigChanged(const char *key,
ds@1952: const char *value,
ds@1952: ConfigSource source,
ds@1952: char *error,
ds@1952: size_t maxlength)
ds@1952: {
ds@1952: if (strcmp(key, "PassInfoVar") == 0)
ds@1952: {
ds@1952: if (strcmp(value, "_password") != 0)
ds@1952: {
ds@1952: m_PassInfoVar.assign(value);
ds@1952: }
ds@1952: return ConfigResult_Accept;
ds@1952: } else if (strcmp(key, "AllowClLanguageVar") == 0) {
ds@1952: if (strcasecmp(value, "on") == 0)
ds@1952: {
ds@1952: m_QueryLang = true;
ds@1952: } else if (strcasecmp(value, "off") == 0) {
ds@1952: m_QueryLang = false;
ds@1952: } else {
ds@1952: UTIL_Format(error, maxlength, "Invalid value: must be \"on\" or \"off\"");
ds@1952: return ConfigResult_Reject;
ds@1952: }
ds@1952: return ConfigResult_Accept;
ds@1952: }
ds@1952: return ConfigResult_Ignore;
ds@1952: }
ds@1952:
ds@1952: void PlayerManager::OnServerActivate(edict_t *pEdictList, int edictCount, int clientMax)
ds@1952: {
ds@1952: if (!m_FirstPass)
ds@1952: {
ds@1952: /* Initialize all players */
ds@1952: m_maxClients = clientMax;
ds@1952: m_PlayerCount = 0;
ds@1952: m_Players = new CPlayer[m_maxClients + 1];
ds@1952: m_AuthQueue = new unsigned int[m_maxClients + 1];
ds@1952: m_FirstPass = true;
ds@1952:
ds@1952: memset(m_AuthQueue, 0, sizeof(unsigned int) * (m_maxClients + 1));
ds@1952:
ds@1952: g_NumPlayersToAuth = &m_AuthQueue[0];
ds@1952: }
faluco@1993: g_Extensions.CallOnCoreMapStart(pEdictList, edictCount, clientMax);
ds@1952: m_onActivate->Execute(NULL);
ds@1952: m_onActivate2->Execute(NULL);
ds@1952:
ds@1952: List::iterator iter;
ds@1952: for (iter = m_hooks.begin(); iter != m_hooks.end(); iter++)
ds@1952: {
ds@1952: if ((*iter)->GetClientListenerVersion() >= 5)
ds@1952: {
ds@1952: (*iter)->OnServerActivated(clientMax);
ds@1952: }
ds@1952: }
ds@1952:
ds@1952: g_OnMapStarted = true;
ds@1952:
ds@1952: SM_ExecuteAllConfigs();
ds@1952: }
ds@1952:
ds@1952: bool PlayerManager::IsServerActivated()
ds@1952: {
ds@1952: return m_FirstPass;
ds@1952: }
ds@1952:
ds@1952: bool PlayerManager::CheckSetAdmin(int index, CPlayer *pPlayer, AdminId id)
ds@1952: {
ds@1952: const char *password = g_Admins.GetAdminPassword(id);
ds@1952: if (password != NULL)
ds@1952: {
ds@1952: if (m_PassInfoVar.size() < 1)
ds@1952: {
ds@1952: return false;
ds@1952: }
ds@1952:
ds@1952: /* Whoa... the user needs a password! */
ds@1952: const char *given = engine->GetClientConVarValue(index, m_PassInfoVar.c_str());
ds@1952: if (!given || strcmp(given, password) != 0)
ds@1952: {
ds@1952: return false;
ds@1952: }
ds@1952: }
ds@1952:
ds@1952: pPlayer->SetAdminId(id, false);
ds@1952:
ds@1952: return true;
ds@1952: }
ds@1952:
ds@1952: bool PlayerManager::CheckSetAdminName(int index, CPlayer *pPlayer, AdminId id)
ds@1952: {
ds@1952: const char *password = g_Admins.GetAdminPassword(id);
ds@1952: if (password == NULL)
ds@1952: {
ds@1952: return false;
ds@1952: }
ds@1952:
ds@1952: if (m_PassInfoVar.size() < 1)
ds@1952: {
ds@1952: return false;
ds@1952: }
ds@1952:
ds@1952: /* Whoa... the user needs a password! */
ds@1952: const char *given = engine->GetClientConVarValue(index, m_PassInfoVar.c_str());
ds@1952: if (!given || strcmp(given, password) != 0)
ds@1952: {
ds@1952: return false;
ds@1952: }
ds@1952:
ds@1952: pPlayer->SetAdminId(id, false);
ds@1952:
ds@1952: return true;
ds@1952: }
ds@1952:
ds@1952: void PlayerManager::RunAuthChecks()
ds@1952: {
ds@1952: CPlayer *pPlayer;
ds@1952: const char *authstr;
ds@1952: unsigned int removed = 0;
ds@1952: for (unsigned int i=1; i<=m_AuthQueue[0]; i++)
ds@1952: {
ds@2181: pPlayer = &m_Players[m_AuthQueue[i]];
ds@1952: authstr = engine->GetPlayerNetworkIDString(pPlayer->m_pEdict);
ds@1952: if (authstr && authstr[0] != '\0'
ds@1952: && (strcmp(authstr, "STEAM_ID_PENDING") != 0))
ds@1952: {
ds@1952: /* Set authorization */
ds@1952: pPlayer->Authorize(authstr);
ds@1952:
ds@1952: /* Mark as removed from queue */
ds@1952: unsigned int client = m_AuthQueue[i];
ds@1952: m_AuthQueue[i] = 0;
ds@1952: removed++;
ds@1952:
ds@1952: /* Send to extensions */
ds@1952: List::iterator iter;
ds@1952: IClientListener *pListener;
ds@1952: for (iter=m_hooks.begin(); iter!=m_hooks.end(); iter++)
ds@1952: {
ds@1952: pListener = (*iter);
ds@1952: pListener->OnClientAuthorized(client, authstr);
ds@1952: if (!pPlayer->IsConnected())
ds@1952: {
ds@1952: break;
ds@1952: }
ds@1952: }
ds@1952:
ds@1952: /* Send to plugins if player is still connected */
ds@1952: if (pPlayer->IsConnected() && m_clauth->GetFunctionCount())
ds@1952: {
ds@1952: /* :TODO: handle the case of a player disconnecting in the middle */
ds@1952: m_clauth->PushCell(client);
ds@1952: m_clauth->PushString(authstr);
ds@1952: m_clauth->Execute(NULL);
ds@1952: }
ds@1952:
ds@1952: if (pPlayer->IsConnected())
ds@1952: {
ds@1952: pPlayer->Authorize_Post();
ds@1952: }
ds@1952: }
ds@1952: }
ds@1952:
ds@1952: /* Clean up the queue */
ds@1952: if (removed)
ds@1952: {
ds@1952: /* We don't have to compact the list if it's empty */
ds@1952: if (removed != m_AuthQueue[0])
ds@1952: {
ds@1952: unsigned int diff = 0;
ds@1952: for (unsigned int i=1; i<=m_AuthQueue[0]; i++)
ds@1952: {
ds@1952: /* If this member is removed... */
ds@1952: if (m_AuthQueue[i] == 0)
ds@1952: {
ds@1952: /* Increase the differential */
ds@1952: diff++;
ds@1952: } else {
ds@1952: /* diff cannot increase faster than i+1 */
ds@1952: assert(i > diff);
ds@1952: assert(i - diff >= 1);
ds@1952: /* move this index down */
ds@1952: m_AuthQueue[i - diff] = m_AuthQueue[i];
ds@1952: }
ds@1952: }
ds@1952: m_AuthQueue[0] -= removed;
ds@1952: } else {
ds@1952: m_AuthQueue[0] = 0;
ds@1952: }
ds@1952: }
ds@1952: }
ds@1952:
ds@1952: bool PlayerManager::OnClientConnect(edict_t *pEntity, const char *pszName, const char *pszAddress, char *reject, int maxrejectlen)
ds@1952: {
ds@1952: int client = engine->IndexOfEdict(pEntity);
ds@2181: CPlayer *pPlayer = &m_Players[client];
ds@1952:
ds@1952: List::iterator iter;
ds@1952: IClientListener *pListener = NULL;
ds@1952: for (iter=m_hooks.begin(); iter!=m_hooks.end(); iter++)
ds@1952: {
ds@1952: pListener = (*iter);
ds@1952: if (!pListener->InterceptClientConnect(client, reject, maxrejectlen))
ds@1952: {
ds@1952: return false;
ds@1952: }
ds@1952: }
ds@1952:
ds@1952: cell_t res = 1;
ds@1952:
ds@2181: pPlayer->Initialize(pszName, pszAddress, pEntity);
ds@1952: m_clconnect->PushCell(client);
ds@1952: m_clconnect->PushStringEx(reject, maxrejectlen, SM_PARAM_STRING_UTF8, SM_PARAM_COPYBACK);
ds@1952: m_clconnect->PushCell(maxrejectlen);
ds@2181: m_clconnect->Execute(&res);
ds@1952:
ds@1952: if (res)
ds@1952: {
ds@2181: if (!pPlayer->IsAuthorized())
ds@1952: {
ds@1952: m_AuthQueue[++m_AuthQueue[0]] = client;
ds@1952: }
ds@2181:
ds@2181: m_UserIdLookUp[engine->GetPlayerUserId(pEntity)] = client;
dvander@1996: }
dvander@1996: else
dvander@1996: {
ds@2181: if (!pPlayer->IsFakeClient())
ds@2181: {
ds@2181: RETURN_META_VALUE(MRES_SUPERCEDE, false);
ds@2181: }
ds@1952: }
ds@1952:
ds@1952: return true;
ds@1952: }
ds@1952:
ds@1952: bool PlayerManager::OnClientConnect_Post(edict_t *pEntity, const char *pszName, const char *pszAddress, char *reject, int maxrejectlen)
ds@1952: {
ds@1952: int client = engine->IndexOfEdict(pEntity);
ds@1952: bool orig_value = META_RESULT_ORIG_RET(bool);
ds@2181: CPlayer *pPlayer = &m_Players[client];
ds@1952:
ds@1952: if (orig_value)
ds@1952: {
ds@1952: List::iterator iter;
ds@1952: IClientListener *pListener = NULL;
ds@1952: for (iter=m_hooks.begin(); iter!=m_hooks.end(); iter++)
ds@1952: {
ds@1952: pListener = (*iter);
ds@1952: pListener->OnClientConnected(client);
ds@1952: if (!pPlayer->IsConnected())
ds@1952: {
ds@1952: break;
ds@1952: }
ds@1952: }
ds@2181:
ds@2181: if (!pPlayer->IsFakeClient()
ds@2181: && m_bIsListenServer
ds@2181: && strncmp(pszAddress, "127.0.0.1", 9) == 0)
ds@2181: {
ds@2181: m_ListenClient = client;
ds@2181: }
ds@1952: }
ds@2181: else
dvander@1996: {
ds@2181: InvalidatePlayer(pPlayer);
dvander@1996: }
dvander@1996:
ds@1952: return true;
ds@1952: }
ds@1952:
ds@1952: void PlayerManager::OnClientPutInServer(edict_t *pEntity, const char *playername)
ds@1952: {
ds@1952: cell_t res;
ds@1952: int client = engine->IndexOfEdict(pEntity);
ds@2181: CPlayer *pPlayer = &m_Players[client];
ds@1952:
ds@1952: /* If they're not connected, they're a bot */
ds@1952: if (!pPlayer->IsConnected())
ds@1952: {
ds@1952: /* Run manual connection routines */
ds@1952: char error[255];
ds@1952: const char *authid = engine->GetPlayerNetworkIDString(pEntity);
ds@1952: pPlayer->Authorize(authid);
ds@2237: pPlayer->m_bFakeClient = true;
ds@1952: if (!OnClientConnect(pEntity, playername, "127.0.0.1", error, sizeof(error)))
ds@1952: {
ds@1952: /* :TODO: kick the bot if it's rejected */
ds@1952: return;
ds@1952: }
ds@1952: List::iterator iter;
ds@1952: IClientListener *pListener = NULL;
ds@1952: for (iter=m_hooks.begin(); iter!=m_hooks.end(); iter++)
ds@1952: {
ds@1952: pListener = (*iter);
ds@1952: pListener->OnClientConnected(client);
ds@1952: /* See if bot was kicked */
ds@1952: if (!pPlayer->IsConnected())
ds@1952: {
ds@1952: return;
ds@1952: }
ds@1952: }
ds@1952: /* Now do authorization */
ds@1952: for (iter=m_hooks.begin(); iter!=m_hooks.end(); iter++)
ds@1952: {
ds@1952: pListener = (*iter);
ds@1952: pListener->OnClientAuthorized(client, authid);
ds@1952: }
ds@1952: /* Finally, tell plugins */
ds@1952: if (m_clauth->GetFunctionCount())
ds@1952: {
ds@1952: m_clauth->PushCell(client);
ds@1952: m_clauth->PushString(authid);
ds@1952: m_clauth->Execute(NULL);
ds@1952: }
ds@1952: pPlayer->Authorize_Post();
ds@1952: }
ds@1952:
ds@1952: if (playerinfo)
ds@1952: {
ds@1952: pPlayer->m_Info = playerinfo->GetPlayerInfo(pEntity);
ds@1952: }
ds@1952:
ds@1952: /* Get the client's language */
ds@1952: if (m_QueryLang)
ds@1952: {
ds@1952: const char *name;
ds@1952: if (!pPlayer->IsFakeClient() && (name=engine->GetClientConVarValue(client, "cl_language")))
ds@1952: {
ds@1952: unsigned int langid;
ds@1952: pPlayer->m_LangId = (g_Translator.GetLanguageByName(name, &langid)) ? langid : g_Translator.GetServerLanguage();
ds@1952: } else {
ds@1952: pPlayer->m_LangId = g_Translator.GetServerLanguage();
ds@1952: }
ds@1952: }
ds@1952:
ds@2181: pPlayer->Connect();
ds@1952: m_PlayerCount++;
ds@1952:
ds@1952: List::iterator iter;
ds@1952: IClientListener *pListener = NULL;
ds@1952: for (iter=m_hooks.begin(); iter!=m_hooks.end(); iter++)
ds@1952: {
ds@1952: pListener = (*iter);
ds@1952: pListener->OnClientPutInServer(client);
ds@1952: }
ds@1952:
ds@1952: m_clputinserver->PushCell(client);
ds@1952: m_clputinserver->Execute(&res, NULL);
ds@1952:
ds@2181: if (pPlayer->IsAuthorized())
ds@1952: {
ds@2181: pPlayer->DoPostConnectAuthorization();
ds@1952: }
ds@1952: }
ds@1952:
ds@1952: void PlayerManager::OnSourceModLevelEnd()
ds@1952: {
ds@1952: /* Disconnect all bots still in game */
ds@1952: for (int i=1; i<=m_maxClients; i++)
ds@1952: {
ds@1952: if (m_Players[i].IsConnected())
ds@1952: {
ds@1952: OnClientDisconnect(m_Players[i].GetEdict());
ds@1952: }
ds@1952: }
ds@1952: m_PlayerCount = 0;
ds@1952: }
ds@1952:
ds@1952: void PlayerManager::OnClientDisconnect(edict_t *pEntity)
ds@1952: {
ds@1952: cell_t res;
ds@1952: int client = engine->IndexOfEdict(pEntity);
ds@2181: CPlayer *pPlayer = &m_Players[client];
ds@1952:
ds@2181: if (pPlayer->IsConnected())
ds@1952: {
ds@1952: m_cldisconnect->PushCell(client);
ds@1952: m_cldisconnect->Execute(&res, NULL);
dvander@1996: }
dvander@1996: else
dvander@1996: {
ds@1952: /* We don't care, prevent a double call */
ds@1952: return;
ds@1952: }
ds@1952:
ds@2181: if (pPlayer->WasCountedAsInGame())
ds@1952: {
ds@1952: m_PlayerCount--;
ds@1952: }
ds@1952:
ds@1952: List::iterator iter;
ds@1952: IClientListener *pListener = NULL;
ds@1952: for (iter=m_hooks.begin(); iter!=m_hooks.end(); iter++)
ds@1952: {
ds@1952: pListener = (*iter);
ds@1952: pListener->OnClientDisconnecting(client);
ds@1952: }
ds@1952:
ds@2181: InvalidatePlayer(pPlayer);
dvander@1996:
dvander@1996: if (m_ListenClient == client)
dvander@1996: {
dvander@1996: m_ListenClient = 0;
dvander@1996: }
ds@1952: }
ds@1952:
ds@1952: void PlayerManager::OnClientDisconnect_Post(edict_t *pEntity)
ds@1952: {
ds@1952: cell_t res;
ds@1952: int client = engine->IndexOfEdict(pEntity);
ds@1952:
ds@1952: m_cldisconnect_post->PushCell(client);
ds@1952: m_cldisconnect_post->Execute(&res, NULL);
ds@1952:
ds@1952: List::iterator iter;
ds@1952: IClientListener *pListener = NULL;
ds@1952: for (iter=m_hooks.begin(); iter!=m_hooks.end(); iter++)
ds@1952: {
ds@1952: pListener = (*iter);
ds@1952: pListener->OnClientDisconnected(client);
ds@1952: }
ds@1952: }
ds@1952:
ds@1952: #if defined ORANGEBOX_BUILD
ds@1952: void PlayerManager::OnClientCommand(edict_t *pEntity, const CCommand &args)
ds@1952: {
ds@1952: #else
ds@1952: void PlayerManager::OnClientCommand(edict_t *pEntity)
ds@1952: {
ds@1952: CCommand args;
ds@1952: #endif
ds@1952: int client = engine->IndexOfEdict(pEntity);
ds@1952: cell_t res = Pl_Continue;
ds@2181: CPlayer *pPlayer = &m_Players[client];
ds@1952:
ds@2181: if (!pPlayer->IsConnected())
ds@1952: {
ds@1952: return;
ds@1952: }
ds@1952:
ds@1952: g_HL2.PushCommandStack(&args);
ds@1952:
ds@1952: int argcount = args.ArgC() - 1;
ds@1952: const char *cmd = g_HL2.CurrentCommandName();
ds@1952:
ds@1952: bool result = g_ValveMenuStyle.OnClientCommand(client, cmd, args);
ds@1952: if (result)
ds@1952: {
ds@1952: res = Pl_Handled;
ds@1952: } else {
ds@1952: result = g_RadioMenuStyle.OnClientCommand(client, cmd, args);
ds@1952: if (result)
ds@1952: {
ds@1952: res = Pl_Handled;
ds@1952: }
ds@1952: }
ds@1952:
ds@1952: cell_t res2 = Pl_Continue;
ds@1952: m_clcommand->PushCell(client);
ds@1952: m_clcommand->PushCell(argcount);
ds@1952: m_clcommand->Execute(&res2, NULL);
ds@1952:
ds@1952: if (res2 > res)
ds@1952: {
ds@1952: res = res2;
ds@1952: }
ds@1952:
ds@1952: if (res >= Pl_Stop)
ds@1952: {
ds@1952: g_HL2.PopCommandStack();
ds@1952: RETURN_META(MRES_SUPERCEDE);
ds@1952: }
ds@1952:
ds@1952: res = g_ConCmds.DispatchClientCommand(client, cmd, argcount, (ResultType)res);
ds@1952:
ds@1952: g_HL2.PopCommandStack();
ds@1952:
ds@1952: if (res >= Pl_Handled)
ds@1952: {
ds@1952: RETURN_META(MRES_SUPERCEDE);
ds@1952: }
ds@1952: }
ds@1952:
ds@1952: void PlayerManager::OnClientSettingsChanged(edict_t *pEntity)
ds@1952: {
ds@1952: cell_t res;
ds@1952: int client = engine->IndexOfEdict(pEntity);
ds@2181: CPlayer *pPlayer = &m_Players[client];
ds@1952:
ds@2181: if (!pPlayer->IsConnected())
ds@1952: {
ds@1952: return;
ds@1952: }
ds@1952:
ds@1952: m_clinfochanged->PushCell(engine->IndexOfEdict(pEntity));
ds@1952: m_clinfochanged->Execute(&res, NULL);
ds@1952:
ds@2181: IPlayerInfo *info = pPlayer->GetPlayerInfo();
ds@1952: const char *new_name = info ? info->GetName() : engine->GetClientConVarValue(client, "name");
ds@2181: const char *old_name = pPlayer->m_Name.c_str();
ds@1952:
ds@1952: if (strcmp(old_name, new_name) != 0)
ds@1952: {
ds@1952: AdminId id = g_Admins.FindAdminByIdentity("name", new_name);
ds@2181: if (id != INVALID_ADMIN_ID && pPlayer->GetAdminId() != id)
ds@1952: {
ds@2181: if (!CheckSetAdminName(client, pPlayer, id))
ds@1952: {
ds@2181: pPlayer->Kick("Your name is reserved by SourceMod; set your password to use it.");
ds@1952: RETURN_META(MRES_IGNORED);
ds@1952: }
ds@1952: } else if ((id = g_Admins.FindAdminByIdentity("name", old_name)) != INVALID_ADMIN_ID) {
ds@2181: if (id == pPlayer->GetAdminId())
ds@1952: {
ds@1952: /* This player is changing their name; force them to drop admin privileges! */
ds@2181: pPlayer->SetAdminId(INVALID_ADMIN_ID, false);
ds@1952: }
ds@1952: }
ds@2181: pPlayer->SetName(new_name);
ds@1952: }
ds@1952:
ds@1952: if (m_PassInfoVar.size() > 0)
ds@1952: {
ds@1952: /* Try for a password change */
ds@2181: const char *old_pass = pPlayer->m_LastPassword.c_str();
ds@1952: const char *new_pass = engine->GetClientConVarValue(client, m_PassInfoVar.c_str());
ds@1952: if (strcmp(old_pass, new_pass) != 0)
ds@1952: {
ds@2181: pPlayer->m_LastPassword.assign(new_pass);
ds@2181: if (pPlayer->IsInGame() && pPlayer->IsAuthorized())
ds@1952: {
ds@1952: /* If there is already an admin id assigned, this will just bail out. */
ds@2181: pPlayer->DoBasicAdminChecks();
ds@1952: }
ds@1952: }
ds@1952: }
ds@1952: }
ds@1952:
ds@1952: int PlayerManager::GetMaxClients()
ds@1952: {
ds@1952: return m_maxClients;
ds@1952: }
ds@1952:
ds@1952: CPlayer *PlayerManager::GetPlayerByIndex(int client) const
ds@1952: {
ds@1952: if (client > m_maxClients || client < 1)
ds@1952: {
ds@1952: return NULL;
ds@1952: }
ds@1952: return &m_Players[client];
ds@1952: }
ds@1952:
ds@1952: int PlayerManager::GetNumPlayers()
ds@1952: {
ds@1952: return m_PlayerCount;
ds@1952: }
ds@1952:
ds@1952: int PlayerManager::GetClientOfUserId(int userid)
ds@1952: {
ds@1952: if (userid < 0 || userid > USHRT_MAX)
ds@1952: {
ds@1952: return 0;
ds@1952: }
ds@1952:
ds@1952: int client = m_UserIdLookUp[userid];
ds@1952:
ds@1952: /* Verify the userid. The cache can get messed up with older
ds@1952: * Valve engines. :TODO: If this gets fixed, do an old engine
ds@1952: * check before invoking this backwards compat code.
ds@1952: */
ds@1952: if (client)
ds@1952: {
ds@1952: CPlayer *player = GetPlayerByIndex(client);
ds@1952: if (player && player->IsConnected())
ds@1952: {
ds@1952: int realUserId = engine->GetPlayerUserId(player->GetEdict());
ds@1952: if (realUserId == userid)
ds@1952: {
ds@1952: return client;
ds@1952: }
ds@1952: }
ds@1952: }
ds@1952:
ds@1952: /* If we can't verify the userid, we have to do a manual loop */
ds@1952: CPlayer *player;
ds@1952: for (int i = 1; i <= m_maxClients; i++)
ds@1952: {
ds@1952: player = GetPlayerByIndex(i);
ds@1952: if (!player || !player->IsConnected())
ds@1952: {
ds@1952: continue;
ds@1952: }
ds@1952: if (engine->GetPlayerUserId(player->GetEdict()) == userid)
ds@1952: {
ds@1952: m_UserIdLookUp[userid] = i;
ds@1952: return i;
ds@1952: }
ds@1952: }
ds@1952:
ds@1952: return 0;
ds@1952: }
ds@1952:
ds@1952: void PlayerManager::AddClientListener(IClientListener *listener)
ds@1952: {
ds@1952: m_hooks.push_back(listener);
ds@1952: }
ds@1952:
ds@1952: void PlayerManager::RemoveClientListener(IClientListener *listener)
ds@1952: {
ds@1952: m_hooks.remove(listener);
ds@1952: }
ds@1952:
ds@1952: IGamePlayer *PlayerManager::GetGamePlayer(edict_t *pEdict)
ds@1952: {
ds@1952: int index = engine->IndexOfEdict(pEdict);
ds@1952: return GetGamePlayer(index);
ds@1952: }
ds@1952:
ds@1952: IGamePlayer *PlayerManager::GetGamePlayer(int client)
ds@1952: {
ds@1952: return GetPlayerByIndex(client);
ds@1952: }
ds@1952:
ds@1952: void PlayerManager::ClearAdminId(AdminId id)
ds@1952: {
ds@1952: for (int i=1; i<=m_maxClients; i++)
ds@1952: {
ds@1952: if (m_Players[i].m_Admin == id)
ds@1952: {
ds@1952: m_Players[i].DumpAdmin(true);
ds@1952: }
ds@1952: }
ds@1952: }
ds@1952:
ds@1952: void PlayerManager::ClearAllAdmins()
ds@1952: {
ds@1952: for (int i=1; i<=m_maxClients; i++)
ds@1952: {
ds@1952: m_Players[i].DumpAdmin(true);
ds@1952: }
ds@1952: }
ds@1952:
ds@1952: const char *PlayerManager::GetPassInfoVar()
ds@1952: {
ds@1952: return m_PassInfoVar.c_str();
ds@1952: }
ds@1952:
ds@1952: void PlayerManager::RecheckAnyAdmins()
ds@1952: {
ds@1952: for (int i=1; i<=m_maxClients; i++)
ds@1952: {
ds@1952: if (m_Players[i].IsInGame() && m_Players[i].IsAuthorized())
ds@1952: {
ds@1952: m_Players[i].DoBasicAdminChecks();
ds@1952: }
ds@1952: }
ds@1952: }
ds@1952:
ds@1952: unsigned int PlayerManager::GetReplyTo()
ds@1952: {
ds@1952: return g_ChatTriggers.GetReplyTo();
ds@1952: }
ds@1952:
ds@1952: unsigned int PlayerManager::SetReplyTo(unsigned int reply)
ds@1952: {
ds@1952: return g_ChatTriggers.SetReplyTo(reply);
ds@1952: }
ds@1952:
ds@1952: int PlayerManager::FilterCommandTarget(IGamePlayer *pAdmin, IGamePlayer *pTarget, int flags)
ds@1952: {
ds@1952: return InternalFilterCommandTarget((CPlayer *)pAdmin, (CPlayer *)pTarget, flags);
ds@1952: }
ds@1952:
ds@1952: void PlayerManager::RegisterCommandTargetProcessor(ICommandTargetProcessor *pHandler)
ds@1952: {
ds@1952: target_processors.push_back(pHandler);
ds@1952: }
ds@1952:
ds@1952: void PlayerManager::UnregisterCommandTargetProcessor(ICommandTargetProcessor *pHandler)
ds@1952: {
ds@1952: target_processors.remove(pHandler);
ds@1952: }
ds@1952:
ds@2181: void PlayerManager::InvalidatePlayer(CPlayer *pPlayer)
ds@2181: {
ds@2181: /**
ds@2181: * Remove client from auth queue if necessary
ds@2181: */
ds@2181: if (!pPlayer->IsAuthorized())
ds@2181: {
ds@2181: for (unsigned int i=1; i<=m_AuthQueue[0]; i++)
ds@2181: {
ds@2181: if (m_AuthQueue[i] == (unsigned)pPlayer->m_iIndex)
ds@2181: {
ds@2181: /* Move everything ahead of us back by one */
ds@2181: for (unsigned int j=i+1; j<=m_AuthQueue[0]; j++)
ds@2181: {
ds@2181: m_AuthQueue[j-1] = m_AuthQueue[j];
ds@2181: }
ds@2181: /* Remove us and break */
ds@2181: m_AuthQueue[0]--;
ds@2181: break;
ds@2181: }
ds@2181: }
ds@2181: }
ds@2181:
ds@2181: m_UserIdLookUp[engine->GetPlayerUserId(pPlayer->m_pEdict)] = 0;
ds@2181: pPlayer->Disconnect();
ds@2181: }
ds@2181:
ds@1952: int PlayerManager::InternalFilterCommandTarget(CPlayer *pAdmin, CPlayer *pTarget, int flags)
ds@1952: {
ds@1952: if ((flags & COMMAND_FILTER_CONNECTED) == COMMAND_FILTER_CONNECTED
ds@1952: && !pTarget->IsConnected())
ds@1952: {
ds@1952: return COMMAND_TARGET_NONE;
ds@1952: }
ds@1952: else if ((flags & COMMAND_FILTER_CONNECTED) != COMMAND_FILTER_CONNECTED &&
ds@1952: !pTarget->IsInGame())
ds@1952: {
ds@1952: return COMMAND_TARGET_NOT_IN_GAME;
ds@1952: }
ds@1952:
ds@1952: if ((flags & COMMAND_FILTER_NO_BOTS) == COMMAND_FILTER_NO_BOTS
ds@1952: && pTarget->IsFakeClient())
ds@1952: {
ds@1952: return COMMAND_TARGET_NOT_HUMAN;
ds@1952: }
ds@1952:
ds@1952: if (pAdmin != NULL)
ds@1952: {
ds@1952: if ((flags & COMMAND_FILTER_NO_IMMUNITY) != COMMAND_FILTER_NO_IMMUNITY
ds@1952: && !g_Admins.CanAdminTarget(pAdmin->GetAdminId(), pTarget->GetAdminId()))
ds@1952: {
ds@1952: return COMMAND_TARGET_IMMUNE;
ds@1952: }
ds@1952: }
ds@1952:
ds@1952: if ((flags & COMMAND_FILTER_ALIVE) == COMMAND_FILTER_ALIVE
ds@1952: && pTarget->GetLifeState() != PLAYER_LIFE_ALIVE)
ds@1952: {
ds@1952: return COMMAND_TARGET_NOT_ALIVE;
ds@1952: }
ds@1952:
ds@1952: if ((flags & COMMAND_FILTER_DEAD) == COMMAND_FILTER_DEAD
ds@1952: && pTarget->GetLifeState() != PLAYER_LIFE_DEAD)
ds@1952: {
ds@1952: return COMMAND_TARGET_NOT_DEAD;
ds@1952: }
ds@1952:
ds@1952: return COMMAND_TARGET_VALID;
ds@1952: }
ds@1952:
ds@1952: void PlayerManager::ProcessCommandTarget(cmd_target_info_t *info)
ds@1952: {
ds@1952: CPlayer *pTarget, *pAdmin;
ds@1952: int max_clients, total = 0;
ds@1952:
ds@1952: max_clients = GetMaxClients();
ds@1952:
ds@1952: if (info->max_targets < 1)
ds@1952: {
ds@1952: info->reason = COMMAND_TARGET_NONE;
ds@1952: info->num_targets = 0;
ds@1952: }
ds@1952:
ds@1952: if (info->admin == 0)
ds@1952: {
ds@1952: pAdmin = NULL;
ds@1952: }
ds@1952: else
ds@1952: {
ds@1952: pAdmin = GetPlayerByIndex(info->admin);
ds@1952: }
ds@1952:
ds@1952: if (info->pattern[0] == '#')
ds@1952: {
ds@1952: int userid = atoi(&info->pattern[1]);
ds@1952: int client = GetClientOfUserId(userid);
ds@1952:
ds@1952: /* See if a valid userid matched */
ds@1952: if (client > 0)
ds@1952: {
ds@1952: IGamePlayer *pTarget = GetPlayerByIndex(client);
ds@1952: if (pTarget != NULL)
ds@1952: {
ds@1952: if ((info->reason = FilterCommandTarget(pAdmin, pTarget, info->flags)) == COMMAND_TARGET_VALID)
ds@1952: {
ds@1952: info->targets[0] = client;
ds@1952: info->num_targets = 1;
ds@1952: strncopy(info->target_name, pTarget->GetName(), info->target_name_maxlength);
ds@1952: info->target_name_style = COMMAND_TARGETNAME_RAW;
ds@1952: }
ds@1952: else
ds@1952: {
ds@1952: info->num_targets = 0;
ds@1952: }
ds@1952: return;
ds@1952: }
ds@1952: }
ds@1952:
ds@1952: /* Do we need to look for a steam id? */
ds@1952: if (strncmp(&info->pattern[1], "STEAM_", 6) == 0)
ds@1952: {
ds@1952: size_t p, len;
ds@1952: char new_pattern[256];
ds@1952:
ds@1952: strcpy(new_pattern, "STEAM_");
ds@1952: len = strlen(&info->pattern[7]);
ds@1952: for (p = 0; p < len; p++)
ds@1952: {
ds@1952: new_pattern[6 + p] = info->pattern[7 + p];
ds@1952: if (new_pattern[6 + p] == '_')
ds@1952: {
ds@1952: new_pattern[6 + p] = ':';
ds@1952: }
ds@1952: }
ds@1952: new_pattern[6 + p] = '\0';
ds@1952:
ds@1952: for (int i = 1; i <= max_clients; i++)
ds@1952: {
ds@1952: if ((pTarget = GetPlayerByIndex(i)) == NULL)
ds@1952: {
ds@1952: continue;
ds@1952: }
ds@1952: if (!pTarget->IsConnected() || !pTarget->IsAuthorized())
ds@1952: {
ds@1952: continue;
ds@1952: }
ds@1952: if (strcmp(pTarget->GetAuthString(), new_pattern) == 0)
ds@1952: {
ds@1952: if ((info->reason = FilterCommandTarget(pAdmin, pTarget, info->flags))
ds@1952: == COMMAND_TARGET_VALID)
ds@1952: {
ds@1952: info->targets[0] = i;
ds@1952: info->num_targets = 1;
ds@1952: strncopy(info->target_name, pTarget->GetName(), info->target_name_maxlength);
ds@1952: info->target_name_style = COMMAND_TARGETNAME_RAW;
ds@1952: }
ds@1952: else
ds@1952: {
ds@1952: info->num_targets = 0;
ds@1952: }
ds@1952: return;
ds@1952: }
ds@1952: }
ds@1952: }
ds@1952:
ds@1952: /* See if an exact name matches */
ds@1952: for (int i = 1; i <= max_clients; i++)
ds@1952: {
ds@1952: if ((pTarget = GetPlayerByIndex(i)) == NULL)
ds@1952: {
ds@1952: continue;
ds@1952: }
ds@1952: if (!pTarget->IsConnected())
ds@1952: {
ds@1952: continue;
ds@1952: }
ds@1952: if (strcmp(pTarget->GetName(), &info->pattern[1]) == 0)
ds@1952: {
ds@1952: if ((info->reason = FilterCommandTarget(pAdmin, pTarget, info->flags))
ds@1952: == COMMAND_TARGET_VALID)
ds@1952: {
ds@1952: info->targets[0] = i;
ds@1952: info->num_targets = 1;
ds@1952: strncopy(info->target_name, pTarget->GetName(), info->target_name_maxlength);
ds@1952: info->target_name_style = COMMAND_TARGETNAME_RAW;
ds@1952: }
ds@1952: else
ds@1952: {
ds@1952: info->num_targets = 0;
ds@1952: }
ds@1952: return;
ds@1952: }
ds@1952: }
ds@1952: }
ds@1952:
ds@1952: if (strcmp(info->pattern, "@me") == 0 && info->admin != 0)
ds@1952: {
ds@1952: info->targets[0] = info->admin;
ds@1952: info->num_targets = 1;
ds@1952: strncopy(info->target_name, pAdmin->GetName(), info->target_name_maxlength);
ds@1952: info->target_name_style = COMMAND_TARGETNAME_RAW;
ds@1952: return;
ds@1952: }
ds@1952:
ds@1952: if ((info->flags & COMMAND_FILTER_NO_MULTI) != COMMAND_FILTER_NO_MULTI)
ds@1952: {
ds@1952: bool is_multi = false;
ds@1952: bool bots_only = false;
ds@1952: int skip_client = -1;
ds@1952:
ds@1952: if (strcmp(info->pattern, "@all") == 0)
ds@1952: {
ds@1952: is_multi = true;
ds@1952: strncopy(info->target_name, "all players", info->target_name_maxlength);
ds@1952: info->target_name_style = COMMAND_TARGETNAME_ML;
ds@1952: }
ds@1952: else if (strcmp(info->pattern, "@dead") == 0)
ds@1952: {
ds@1952: is_multi = true;
ds@1952: if ((info->flags & COMMAND_FILTER_ALIVE) == COMMAND_FILTER_ALIVE)
ds@1952: {
ds@1952: info->num_targets = 0;
ds@1952: info->reason = COMMAND_TARGET_NOT_ALIVE;
ds@1952: return;
ds@1952: }
ds@1952: info->flags |= COMMAND_FILTER_DEAD;
ds@1952: strncopy(info->target_name, "all dead players", info->target_name_maxlength);
ds@1952: info->target_name_style = COMMAND_TARGETNAME_ML;
ds@1952: }
ds@1952: else if (strcmp(info->pattern, "@alive") == 0)
ds@1952: {
ds@1952: is_multi = true;
ds@1952: if ((info->flags & COMMAND_FILTER_DEAD) == COMMAND_FILTER_DEAD)
ds@1952: {
ds@1952: info->num_targets = 0;
ds@1952: info->reason = COMMAND_TARGET_NOT_DEAD;
ds@1952: return;
ds@1952: }
ds@1952: strncopy(info->target_name, "all alive players", info->target_name_maxlength);
ds@1952: info->target_name_style = COMMAND_TARGETNAME_ML;
ds@1952: info->flags |= COMMAND_FILTER_ALIVE;
ds@1952: }
ds@1952: else if (strcmp(info->pattern, "@bots") == 0)
ds@1952: {
ds@1952: is_multi = true;
ds@1952: if ((info->flags & COMMAND_FILTER_NO_BOTS) == COMMAND_FILTER_NO_BOTS)
ds@1952: {
ds@1952: info->num_targets = 0;
ds@1952: info->reason = COMMAND_FILTER_NO_BOTS;
ds@1952: return;
ds@1952: }
ds@1952: strncopy(info->target_name, "all bots", info->target_name_maxlength);
ds@1952: info->target_name_style = COMMAND_TARGETNAME_ML;
ds@1952: bots_only = true;
ds@1952: }
ds@1952: else if (strcmp(info->pattern, "@humans") == 0)
ds@1952: {
ds@1952: is_multi = true;
ds@1952: strncopy(info->target_name, "all humans", info->target_name_maxlength);
ds@1952: info->target_name_style = COMMAND_TARGETNAME_ML;
ds@1952: info->flags |= COMMAND_FILTER_NO_BOTS;
ds@1952: }
ds@1952: else if (strcmp(info->pattern, "@!me") == 0)
ds@1952: {
ds@1952: is_multi = true;
ds@1952: strncopy(info->target_name, "all players", info->target_name_maxlength);
ds@1952: info->target_name_style = COMMAND_TARGETNAME_ML;
ds@1952: skip_client = info->admin;
ds@1952: }
ds@1952:
ds@1952: if (is_multi)
ds@1952: {
ds@1952: for (int i = 1; i <= max_clients && total < info->max_targets; i++)
ds@1952: {
ds@1952: if ((pTarget = GetPlayerByIndex(i)) == NULL)
ds@1952: {
ds@1952: continue;
ds@1952: }
ds@1952: if (FilterCommandTarget(pAdmin, pTarget, info->flags) > 0)
ds@1952: {
ds@1952: if ((!bots_only || pTarget->IsFakeClient())
ds@1952: && skip_client != i)
ds@1952: {
ds@1952: info->targets[total++] = i;
ds@1952: }
ds@1952: }
ds@1952: }
ds@1952:
ds@1952: info->num_targets = total;
ds@1952: info->reason = (info->num_targets) ? COMMAND_TARGET_VALID : COMMAND_TARGET_EMPTY_FILTER;
ds@1952: return;
ds@1952: }
ds@1952: }
ds@1952:
ds@1952: List::iterator iter;
ds@1952: for (iter = target_processors.begin(); iter != target_processors.end(); iter++)
ds@1952: {
ds@1952: ICommandTargetProcessor *pProcessor = (*iter);
ds@1952: if (pProcessor->ProcessCommandTarget(info))
ds@1952: {
ds@1952: return;
ds@1952: }
ds@1952: }
ds@1952:
ds@1952: /* Check partial names */
ds@1952: int found_client = 0;
ds@1952: CPlayer *pFoundClient = NULL;
ds@1952: for (int i = 1; i <= max_clients; i++)
ds@1952: {
ds@1952: if ((pTarget = GetPlayerByIndex(i)) == NULL)
ds@1952: {
ds@1952: continue;
ds@1952: }
ds@1952:
ds@1952: if (stristr(pTarget->GetName(), info->pattern) != NULL)
ds@1952: {
ds@1952: if (found_client)
ds@1952: {
ds@1952: info->num_targets = 0;
ds@1952: info->reason = COMMAND_TARGET_AMBIGUOUS;
ds@1952: return;
ds@1952: }
ds@1952: else
ds@1952: {
ds@1952: found_client = i;
ds@1952: pFoundClient = pTarget;
ds@1952: }
ds@1952: }
ds@1952: }
ds@1952:
ds@1952: if (found_client)
ds@1952: {
ds@1952: if ((info->reason = FilterCommandTarget(pAdmin, pFoundClient, info->flags))
ds@1952: == COMMAND_TARGET_VALID)
ds@1952: {
ds@1952: info->targets[0] = found_client;
ds@1952: info->num_targets = 1;
ds@1952: strncopy(info->target_name, pFoundClient->GetName(), info->target_name_maxlength);
ds@1952: info->target_name_style = COMMAND_TARGETNAME_RAW;
ds@1952: }
ds@1952: else
ds@1952: {
ds@1952: info->num_targets = 0;
ds@1952: }
ds@1952: }
ds@1952: else
ds@1952: {
ds@1952: info->num_targets = 0;
ds@1952: info->reason = COMMAND_TARGET_NONE;
ds@1952: }
ds@1952: }
ds@1952:
ds@1952: /*******************
ds@1952: *** PLAYER CODE ***
ds@1952: *******************/
ds@1952:
ds@1952: CPlayer::CPlayer()
ds@1952: {
ds@1952: m_IsConnected = false;
ds@1952: m_IsInGame = false;
ds@1952: m_IsAuthorized = false;
ds@1952: m_pEdict = NULL;
ds@1952: m_Admin = INVALID_ADMIN_ID;
ds@1952: m_TempAdmin = false;
ds@1952: m_Info = NULL;
ds@1952: m_bAdminCheckSignalled = false;
ds@1952: m_bIsInKickQueue = false;
ds@1952: m_LastPassword.clear();
dvander@2042: m_LangId = SOURCEMOD_LANGUAGE_ENGLISH;
ds@2237: m_bFakeClient = false;
ds@1952: }
ds@1952:
ds@1952: void CPlayer::Initialize(const char *name, const char *ip, edict_t *pEntity)
ds@1952: {
ds@1952: m_IsConnected = true;
ds@1952: m_Name.assign(name);
ds@1952: m_Ip.assign(ip);
ds@1952: m_pEdict = pEntity;
ds@1952: m_iIndex = engine->IndexOfEdict(pEntity);
ds@1952: m_LangId = g_Translator.GetServerLanguage();
ds@1952:
ds@1952: char ip2[24], *ptr;
ds@1952: strncopy(ip2, ip, sizeof(ip2));
ds@1952: if ((ptr = strchr(ip2, ':')) != NULL)
ds@1952: {
ds@1952: *ptr = '\0';
ds@1952: }
ds@1952: m_IpNoPort.assign(ip2);
ds@1952: }
ds@1952:
ds@1952: void CPlayer::Connect()
ds@1952: {
ds@1952: if (m_IsInGame)
ds@1952: {
ds@1952: return;
ds@1952: }
ds@1952:
ds@1952: m_IsInGame = true;
ds@1952:
ds@1952: const char *var = g_Players.GetPassInfoVar();
ds@1952: int client = engine->IndexOfEdict(m_pEdict);
ds@1952: if (var[0] != '\0')
ds@1952: {
ds@1952: const char *pass = engine->GetClientConVarValue(client, var);
ds@1952: m_LastPassword.assign(pass ? pass : "");
ds@1952: }
ds@1952: else
ds@1952: {
ds@1952: m_LastPassword.assign("");
ds@1952: }
ds@1952: }
ds@1952:
ds@1952: void CPlayer::Authorize(const char *steamid)
ds@1952: {
ds@1952: if (m_IsAuthorized)
ds@1952: {
ds@1952: return;
ds@1952: }
ds@1952:
ds@1952: m_IsAuthorized = true;
ds@1952: m_AuthID.assign(steamid);
ds@1952: }
ds@1952:
ds@1952: void CPlayer::Disconnect()
ds@1952: {
ds@1952: DumpAdmin(false);
ds@1952: m_IsConnected = false;
ds@1952: m_IsInGame = false;
ds@1952: m_IsAuthorized = false;
ds@1952: m_Name.clear();
ds@1952: m_Ip.clear();
ds@1952: m_AuthID.clear();
ds@1952: m_pEdict = NULL;
ds@1952: m_Info = NULL;
ds@1952: m_bAdminCheckSignalled = false;
ds@1952: m_UserId = -1;
ds@1952: m_bIsInKickQueue = false;
ds@2237: m_bFakeClient = false;
ds@1952: }
ds@1952:
ds@1952: void CPlayer::SetName(const char *name)
ds@1952: {
ds@1952: m_Name.assign(name);
ds@1952: }
ds@1952:
ds@1952: const char *CPlayer::GetName()
ds@1952: {
ds@1952: if (m_Info && m_pEdict->GetUnknown())
ds@1952: {
ds@1952: return m_Info->GetName();
ds@1952: }
ds@1952:
ds@1952: return m_Name.c_str();
ds@1952: }
ds@1952:
ds@1952: const char *CPlayer::GetIPAddress()
ds@1952: {
ds@1952: return m_Ip.c_str();
ds@1952: }
ds@1952:
ds@1952: const char *CPlayer::GetAuthString()
ds@1952: {
ds@1952: return m_AuthID.c_str();
ds@1952: }
ds@1952:
ds@1952: edict_t *CPlayer::GetEdict()
ds@1952: {
ds@1952: return m_pEdict;
ds@1952: }
ds@1952:
ds@1952: bool CPlayer::IsInGame()
ds@1952: {
ds@1952: return m_IsInGame && (m_pEdict->GetUnknown() != NULL);
ds@1952: }
ds@1952:
ds@1952: bool CPlayer::WasCountedAsInGame()
ds@1952: {
ds@1952: return m_IsInGame;
ds@1952: }
ds@1952:
ds@1952: bool CPlayer::IsConnected()
ds@1952: {
ds@1952: return m_IsConnected;
ds@1952: }
ds@1952:
ds@1952: bool CPlayer::IsAuthorized()
ds@1952: {
ds@1952: return m_IsAuthorized;
ds@1952: }
ds@1952:
ds@1952: IPlayerInfo *CPlayer::GetPlayerInfo()
ds@1952: {
ds@1952: if (m_pEdict->GetUnknown())
ds@1952: {
ds@1952: return m_Info;
ds@1952: }
ds@1952:
ds@1952: return NULL;
ds@1952: }
ds@1952:
ds@1952: bool CPlayer::IsFakeClient()
ds@1952: {
ds@2237: return m_bFakeClient;
ds@1952: }
ds@1952:
ds@1952: void CPlayer::SetAdminId(AdminId id, bool temporary)
ds@1952: {
ds@1952: if (!m_IsConnected)
ds@1952: {
ds@1952: return;
ds@1952: }
ds@1952:
ds@1952: DumpAdmin(false);
ds@1952:
ds@1952: m_Admin = id;
ds@1952: m_TempAdmin = temporary;
ds@1952: }
ds@1952:
ds@1952: AdminId CPlayer::GetAdminId()
ds@1952: {
ds@1952: return m_Admin;
ds@1952: }
ds@1952:
ds@1952: void CPlayer::DumpAdmin(bool deleting)
ds@1952: {
ds@1952: if (m_Admin != INVALID_ADMIN_ID)
ds@1952: {
ds@1952: if (m_TempAdmin && !deleting)
ds@1952: {
ds@1952: g_Admins.InvalidateAdmin(m_Admin);
ds@1952: }
ds@1952: m_Admin = INVALID_ADMIN_ID;
ds@1952: m_TempAdmin = false;
ds@1952: }
ds@1952: }
ds@1952:
ds@1952: void CPlayer::Kick(const char *str)
ds@1952: {
ds@1952: MarkAsBeingKicked();
ds@1952: INetChannel *pNetChan = static_cast(engine->GetPlayerNetInfo(m_iIndex));
ds@1952: IClient *pClient = static_cast(pNetChan->GetMsgHandler());
ds@1952: pClient->Disconnect("%s", str);
ds@1952: }
ds@1952:
ds@1952: void CPlayer::Authorize_Post()
ds@1952: {
ds@1952: if (m_IsInGame)
ds@1952: {
ds@1952: DoPostConnectAuthorization();
ds@1952: }
ds@1952: }
ds@1952:
ds@1952: void CPlayer::DoPostConnectAuthorization()
ds@1952: {
ds@1952: bool delay = false;
ds@1952:
ds@1952: List::iterator iter;
ds@1952: for (iter = g_Players.m_hooks.begin();
ds@1952: iter != g_Players.m_hooks.end();
ds@1952: iter++)
ds@1952: {
ds@1952: IClientListener *pListener = (*iter);
ds@1952: #if defined MIN_API_FOR_ADMINCALLS
ds@1952: if (pListener->GetClientListenerVersion() < MIN_API_FOR_ADMINCALLS)
ds@1952: {
ds@1952: continue;
ds@1952: }
ds@1952: #endif
ds@1952: if (!pListener->OnClientPreAdminCheck(m_iIndex))
ds@1952: {
ds@1952: delay = true;
ds@1952: }
ds@1952: }
ds@1952:
ds@1952: cell_t result = 0;
ds@1952: PreAdminCheck->PushCell(m_iIndex);
ds@1952: PreAdminCheck->Execute(&result);
ds@1952:
ds@1952: /* Defer, for better or worse */
ds@1952: if (delay || (ResultType)result >= Pl_Handled)
ds@1952: {
ds@1952: return;
ds@1952: }
ds@1952:
ds@1952: /* Sanity check */
ds@1952: if (!IsConnected())
ds@1952: {
ds@1952: return;
ds@1952: }
ds@1952:
ds@1952: /* Otherwise, go ahead and do admin checks */
ds@1952: DoBasicAdminChecks();
ds@1952:
ds@1952: /* Send the notification out */
ds@1952: NotifyPostAdminChecks();
ds@1952: }
ds@1952:
ds@1952: bool CPlayer::RunAdminCacheChecks()
ds@1952: {
ds@1952: AdminId old_id = GetAdminId();
ds@1952:
ds@1952: DoBasicAdminChecks();
ds@1952:
ds@1952: return (GetAdminId() != old_id);
ds@1952: }
ds@1952:
ds@1952: void CPlayer::NotifyPostAdminChecks()
ds@1952: {
ds@1952: if (m_bAdminCheckSignalled)
ds@1952: {
ds@1952: return;
ds@1952: }
ds@1952:
ds@1952: /* Block beforehand so they can't double-call */
ds@1952: m_bAdminCheckSignalled = true;
ds@1952:
ds@1952: List::iterator iter;
ds@1952: for (iter = g_Players.m_hooks.begin();
ds@1952: iter != g_Players.m_hooks.end();
ds@1952: iter++)
ds@1952: {
ds@1952: IClientListener *pListener = (*iter);
ds@1952: #if defined MIN_API_FOR_ADMINCALLS
ds@1952: if (pListener->GetClientListenerVersion() < MIN_API_FOR_ADMINCALLS)
ds@1952: {
ds@1952: continue;
ds@1952: }
ds@1952: #endif
ds@1952: pListener->OnClientPostAdminCheck(m_iIndex);
ds@1952: }
ds@1952:
ds@1952: PostAdminFilter->PushCell(m_iIndex);
ds@1952: PostAdminFilter->Execute(NULL);
ds@1952:
ds@1952: PostAdminCheck->PushCell(m_iIndex);
ds@1952: PostAdminCheck->Execute(NULL);
ds@1952: }
ds@1952:
ds@1952: void CPlayer::DoBasicAdminChecks()
ds@1952: {
ds@1952: if (GetAdminId() != INVALID_ADMIN_ID)
ds@1952: {
ds@1952: return;
ds@1952: }
ds@1952:
ds@1952: /* First check the name */
ds@1952: AdminId id;
ds@1952: int client = engine->IndexOfEdict(m_pEdict);
ds@1952:
ds@1952: if ((id = g_Admins.FindAdminByIdentity("name", GetName())) != INVALID_ADMIN_ID)
ds@1952: {
ds@1952: if (!g_Players.CheckSetAdminName(client, this, id))
ds@1952: {
ds@1952: int userid = engine->GetPlayerUserId(m_pEdict);
ds@1952: g_Timers.CreateTimer(&s_KickPlayerTimer, 0.1f, (void *)userid, 0);
ds@1952: }
ds@1952: return;
ds@1952: }
ds@1952:
ds@1952: /* Check IP */
ds@1952: if ((id = g_Admins.FindAdminByIdentity("ip", m_IpNoPort.c_str())) != INVALID_ADMIN_ID)
ds@1952: {
ds@1952: if (g_Players.CheckSetAdmin(client, this, id))
ds@1952: {
ds@1952: return;
ds@1952: }
ds@1952: }
ds@1952:
ds@1952: /* Check IP address */
ds@1952: if ((id = g_Admins.FindAdminByIdentity("steam", m_AuthID.c_str())) != INVALID_ADMIN_ID)
ds@1952: {
ds@1952: if (g_Players.CheckSetAdmin(client, this, id))
ds@1952: {
ds@1952: return;
ds@1952: }
ds@1952: }
ds@1952: }
ds@1952:
ds@1952: unsigned int CPlayer::GetLanguageId()
ds@1952: {
ds@1952: return m_LangId;
ds@1952: }
ds@1952:
ds@1952: int CPlayer::GetUserId()
ds@1952: {
ds@1952: if (m_UserId == -1)
ds@1952: {
ds@1952: m_UserId = engine->GetPlayerUserId(GetEdict());
ds@1952: }
ds@1952:
ds@1952: return m_UserId;
ds@1952: }
ds@1952:
ds@1952: bool CPlayer::IsInKickQueue()
ds@1952: {
ds@1952: return m_bIsInKickQueue;
ds@1952: }
ds@1952:
ds@1952: void CPlayer::MarkAsBeingKicked()
ds@1952: {
ds@1952: m_bIsInKickQueue = true;
ds@1952: }
ds@1952:
ds@1952: int CPlayer::GetLifeState()
ds@1952: {
ds@1952: if (lifestate_offset == -1)
ds@1952: {
ds@1952: if (!g_pGameConf->GetOffset("m_lifeState", &lifestate_offset))
ds@1952: {
ds@1952: lifestate_offset = -2;
ds@1952: }
ds@1952: }
ds@1952:
ds@1952: if (lifestate_offset < 0)
ds@1952: {
ds@1952: IPlayerInfo *info = GetPlayerInfo();
ds@1952: if (info == NULL)
ds@1952: {
ds@1952: return PLAYER_LIFE_UNKNOWN;
ds@1952: }
ds@1952: return info->IsDead() ? PLAYER_LIFE_DEAD : PLAYER_LIFE_ALIVE;
ds@1952: }
ds@1952:
ds@1952: if (m_pEdict == NULL)
ds@1952: {
ds@1952: return PLAYER_LIFE_UNKNOWN;
ds@1952: }
ds@1952:
ds@1952: CBaseEntity *pEntity;
ds@1952: IServerUnknown *pUnknown = m_pEdict->GetUnknown();
ds@1952: if (pUnknown == NULL || (pEntity = pUnknown->GetBaseEntity()) == NULL)
ds@1952: {
ds@1952: return PLAYER_LIFE_UNKNOWN;
ds@1952: }
ds@1952:
ds@1952: if (*((uint8_t *)pEntity + lifestate_offset) == LIFE_ALIVE)
ds@1952: {
ds@1952: return PLAYER_LIFE_ALIVE;
ds@1952: }
ds@1952: else
ds@1952: {
ds@1952: return PLAYER_LIFE_DEAD;
ds@1952: }
ds@1952: }