core/PlayerManager.cpp
author Borja Ferrer <faluco@alliedmods.net>
Sat Apr 12 01:35:45 2008 +0000 (2008-04-12)
changeset 1993 8c08aaff4d39
parent 1952 b7aa2b626807
child 1996 3f0cd604812b
permissions -rw-r--r--
experimental fix for amb1586 - team native crash
ds@1952
     1
/**
ds@1952
     2
 * vim: set ts=4 :
ds@1952
     3
 * =============================================================================
ds@1952
     4
 * SourceMod
ds@1952
     5
 * Copyright (C) 2004-2008 AlliedModders LLC.  All rights reserved.
ds@1952
     6
 * =============================================================================
ds@1952
     7
 *
ds@1952
     8
 * This program is free software; you can redistribute it and/or modify it under
ds@1952
     9
 * the terms of the GNU General Public License, version 3.0, as published by the
ds@1952
    10
 * Free Software Foundation.
ds@1952
    11
 * 
ds@1952
    12
 * This program is distributed in the hope that it will be useful, but WITHOUT
ds@1952
    13
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
ds@1952
    14
 * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
ds@1952
    15
 * details.
ds@1952
    16
 *
ds@1952
    17
 * You should have received a copy of the GNU General Public License along with
ds@1952
    18
 * this program.  If not, see <http://www.gnu.org/licenses/>.
ds@1952
    19
 *
ds@1952
    20
 * As a special exception, AlliedModders LLC gives you permission to link the
ds@1952
    21
 * code of this program (as well as its derivative works) to "Half-Life 2," the
ds@1952
    22
 * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
ds@1952
    23
 * by the Valve Corporation.  You must obey the GNU General Public License in
ds@1952
    24
 * all respects for all other code used.  Additionally, AlliedModders LLC grants
ds@1952
    25
 * this exception to all derivative works.  AlliedModders LLC defines further
ds@1952
    26
 * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
ds@1952
    27
 * or <http://www.sourcemod.net/license.php>.
ds@1952
    28
 *
ds@1952
    29
 * Version: $Id$
ds@1952
    30
 */
ds@1952
    31
ds@1952
    32
#include "PlayerManager.h"
ds@1952
    33
#include "ForwardSys.h"
ds@1952
    34
#include "ShareSys.h"
ds@1952
    35
#include "AdminCache.h"
ds@1952
    36
#include "ConCmdManager.h"
ds@1952
    37
#include "MenuStyle_Valve.h"
ds@1952
    38
#include "MenuStyle_Radio.h"
ds@1952
    39
#include "sm_stringutil.h"
ds@1952
    40
#include "CoreConfig.h"
ds@1952
    41
#include "TimerSys.h"
ds@1952
    42
#include "Translator.h"
ds@1952
    43
#include "Logger.h"
ds@1952
    44
#include "ChatTriggers.h"
ds@1952
    45
#include "HalfLife2.h"
ds@1952
    46
#include <inetchannel.h>
ds@1952
    47
#include <iclient.h>
ds@1952
    48
#include "GameConfigs.h"
faluco@1993
    49
#include "systems/ExtensionSys.h"
ds@1952
    50
ds@1952
    51
PlayerManager g_Players;
ds@1952
    52
bool g_OnMapStarted = false;
ds@1952
    53
IForward *PreAdminCheck = NULL;
ds@1952
    54
IForward *PostAdminCheck = NULL;
ds@1952
    55
IForward *PostAdminFilter = NULL;
ds@1952
    56
const unsigned int *g_NumPlayersToAuth = NULL;
ds@1952
    57
int lifestate_offset = -1;
ds@1952
    58
List<ICommandTargetProcessor *> target_processors;
ds@1952
    59
ds@1952
    60
SH_DECL_HOOK5(IServerGameClients, ClientConnect, SH_NOATTRIB, 0, bool, edict_t *, const char *, const char *, char *, int);
ds@1952
    61
SH_DECL_HOOK2_void(IServerGameClients, ClientPutInServer, SH_NOATTRIB, 0, edict_t *, const char *);
ds@1952
    62
SH_DECL_HOOK1_void(IServerGameClients, ClientDisconnect, SH_NOATTRIB, 0, edict_t *);
ds@1952
    63
#if defined ORANGEBOX_BUILD
ds@1952
    64
SH_DECL_HOOK2_void(IServerGameClients, ClientCommand, SH_NOATTRIB, 0, edict_t *, const CCommand &);
ds@1952
    65
#else
ds@1952
    66
SH_DECL_HOOK1_void(IServerGameClients, ClientCommand, SH_NOATTRIB, 0, edict_t *);
ds@1952
    67
#endif
ds@1952
    68
SH_DECL_HOOK1_void(IServerGameClients, ClientSettingsChanged, SH_NOATTRIB, 0, edict_t *);
ds@1952
    69
SH_DECL_HOOK3_void(IServerGameDLL, ServerActivate, SH_NOATTRIB, 0, edict_t *, int, int);
ds@1952
    70
ds@1952
    71
class KickPlayerTimer : public ITimedEvent
ds@1952
    72
{
ds@1952
    73
public:
ds@1952
    74
	ResultType OnTimer(ITimer *pTimer, void *pData)
ds@1952
    75
	{
ds@1952
    76
		int userid = (int)pData;
ds@1952
    77
		int client = g_Players.GetClientOfUserId(userid);
ds@1952
    78
		if (client)
ds@1952
    79
		{
ds@1952
    80
			CPlayer *player = g_Players.GetPlayerByIndex(client);
ds@1952
    81
			player->Kick("Your name is reserved by SourceMod; set your password to use it.");
ds@1952
    82
		}
ds@1952
    83
		return Pl_Stop;
ds@1952
    84
	}
ds@1952
    85
	void OnTimerEnd(ITimer *pTimer, void *pData)
ds@1952
    86
	{
ds@1952
    87
	}
ds@1952
    88
} s_KickPlayerTimer;
ds@1952
    89
ds@1952
    90
PlayerManager::PlayerManager()
ds@1952
    91
{
ds@1952
    92
	m_AuthQueue = NULL;
ds@1952
    93
	m_FirstPass = false;
ds@1952
    94
	m_maxClients = 0;
ds@1952
    95
ds@1952
    96
	m_UserIdLookUp = new int[USHRT_MAX+1];
ds@1952
    97
	memset(m_UserIdLookUp, 0, sizeof(int) * (USHRT_MAX+1));
ds@1952
    98
}
ds@1952
    99
ds@1952
   100
PlayerManager::~PlayerManager()
ds@1952
   101
{
ds@1952
   102
	g_NumPlayersToAuth = NULL;
ds@1952
   103
ds@1952
   104
	delete [] m_AuthQueue;
ds@1952
   105
	delete [] m_UserIdLookUp;
ds@1952
   106
}
ds@1952
   107
ds@1952
   108
void PlayerManager::OnSourceModAllInitialized()
ds@1952
   109
{
ds@1952
   110
	SH_ADD_HOOK_MEMFUNC(IServerGameClients, ClientConnect, serverClients, this, &PlayerManager::OnClientConnect, false);
ds@1952
   111
	SH_ADD_HOOK_MEMFUNC(IServerGameClients, ClientConnect, serverClients, this, &PlayerManager::OnClientConnect_Post, true);
ds@1952
   112
	SH_ADD_HOOK_MEMFUNC(IServerGameClients, ClientPutInServer, serverClients, this, &PlayerManager::OnClientPutInServer, true);
ds@1952
   113
	SH_ADD_HOOK_MEMFUNC(IServerGameClients, ClientDisconnect, serverClients, this, &PlayerManager::OnClientDisconnect, false);
ds@1952
   114
	SH_ADD_HOOK_MEMFUNC(IServerGameClients, ClientDisconnect, serverClients, this, &PlayerManager::OnClientDisconnect_Post, true);
ds@1952
   115
	SH_ADD_HOOK_MEMFUNC(IServerGameClients, ClientCommand, serverClients, this, &PlayerManager::OnClientCommand, false);
ds@1952
   116
	SH_ADD_HOOK_MEMFUNC(IServerGameClients, ClientSettingsChanged, serverClients, this, &PlayerManager::OnClientSettingsChanged, true);
ds@1952
   117
	SH_ADD_HOOK_MEMFUNC(IServerGameDLL, ServerActivate, gamedll, this, &PlayerManager::OnServerActivate, true);
ds@1952
   118
ds@1952
   119
	g_ShareSys.AddInterface(NULL, this);
ds@1952
   120
ds@1952
   121
	ParamType p1[] = {Param_Cell, Param_String, Param_Cell};
ds@1952
   122
	ParamType p2[] = {Param_Cell};
ds@1952
   123
ds@1952
   124
	m_clconnect = g_Forwards.CreateForward("OnClientConnect", ET_Event, 3, p1);
ds@1952
   125
	m_clputinserver = g_Forwards.CreateForward("OnClientPutInServer", ET_Ignore, 1, p2);
ds@1952
   126
	m_cldisconnect = g_Forwards.CreateForward("OnClientDisconnect", ET_Ignore, 1, p2);
ds@1952
   127
	m_cldisconnect_post = g_Forwards.CreateForward("OnClientDisconnect_Post", ET_Ignore, 1, p2);
ds@1952
   128
	m_clcommand = g_Forwards.CreateForward("OnClientCommand", ET_Hook, 2, NULL, Param_Cell, Param_Cell);
ds@1952
   129
	m_clinfochanged = g_Forwards.CreateForward("OnClientSettingsChanged", ET_Ignore, 1, p2);
ds@1952
   130
	m_clauth = g_Forwards.CreateForward("OnClientAuthorized", ET_Ignore, 2, NULL, Param_Cell, Param_String);
ds@1952
   131
	m_onActivate = g_Forwards.CreateForward("OnServerLoad", ET_Ignore, 0, NULL);
ds@1952
   132
	m_onActivate2 = g_Forwards.CreateForward("OnMapStart", ET_Ignore, 0, NULL);
ds@1952
   133
ds@1952
   134
	PreAdminCheck = g_Forwards.CreateForward("OnClientPreAdminCheck", ET_Event, 1, p1);
ds@1952
   135
	PostAdminCheck = g_Forwards.CreateForward("OnClientPostAdminCheck", ET_Ignore, 1, p1);
ds@1952
   136
	PostAdminFilter = g_Forwards.CreateForward("OnClientPostAdminFilter", ET_Ignore, 1, p1);
ds@1952
   137
}
ds@1952
   138
ds@1952
   139
void PlayerManager::OnSourceModShutdown()
ds@1952
   140
{
ds@1952
   141
	SH_REMOVE_HOOK_MEMFUNC(IServerGameClients, ClientConnect, serverClients, this, &PlayerManager::OnClientConnect, false);
ds@1952
   142
	SH_REMOVE_HOOK_MEMFUNC(IServerGameClients, ClientPutInServer, serverClients, this, &PlayerManager::OnClientPutInServer, true);
ds@1952
   143
	SH_REMOVE_HOOK_MEMFUNC(IServerGameClients, ClientDisconnect, serverClients, this, &PlayerManager::OnClientDisconnect, false);
ds@1952
   144
	SH_REMOVE_HOOK_MEMFUNC(IServerGameClients, ClientDisconnect, serverClients, this, &PlayerManager::OnClientDisconnect_Post, true);
ds@1952
   145
	SH_REMOVE_HOOK_MEMFUNC(IServerGameClients, ClientCommand, serverClients, this, &PlayerManager::OnClientCommand, false);
ds@1952
   146
	SH_REMOVE_HOOK_MEMFUNC(IServerGameClients, ClientSettingsChanged, serverClients, this, &PlayerManager::OnClientSettingsChanged, true);
ds@1952
   147
	SH_REMOVE_HOOK_MEMFUNC(IServerGameDLL, ServerActivate, gamedll, this, &PlayerManager::OnServerActivate, true);
ds@1952
   148
ds@1952
   149
	/* Release forwards */
ds@1952
   150
	g_Forwards.ReleaseForward(m_clconnect);
ds@1952
   151
	g_Forwards.ReleaseForward(m_clputinserver);
ds@1952
   152
	g_Forwards.ReleaseForward(m_cldisconnect);
ds@1952
   153
	g_Forwards.ReleaseForward(m_cldisconnect_post);
ds@1952
   154
	g_Forwards.ReleaseForward(m_clcommand);
ds@1952
   155
	g_Forwards.ReleaseForward(m_clinfochanged);
ds@1952
   156
	g_Forwards.ReleaseForward(m_clauth);
ds@1952
   157
	g_Forwards.ReleaseForward(m_onActivate);
ds@1952
   158
	g_Forwards.ReleaseForward(m_onActivate2);
ds@1952
   159
ds@1952
   160
	g_Forwards.ReleaseForward(PreAdminCheck);
ds@1952
   161
	g_Forwards.ReleaseForward(PostAdminCheck);
ds@1952
   162
	g_Forwards.ReleaseForward(PostAdminFilter);
ds@1952
   163
ds@1952
   164
	delete [] m_Players;
ds@1952
   165
}
ds@1952
   166
ds@1952
   167
ConfigResult PlayerManager::OnSourceModConfigChanged(const char *key, 
ds@1952
   168
												 const char *value, 
ds@1952
   169
												 ConfigSource source, 
ds@1952
   170
												 char *error, 
ds@1952
   171
												 size_t maxlength)
ds@1952
   172
{
ds@1952
   173
	if (strcmp(key, "PassInfoVar") == 0)
ds@1952
   174
	{
ds@1952
   175
		if (strcmp(value, "_password") != 0)
ds@1952
   176
		{
ds@1952
   177
			m_PassInfoVar.assign(value);
ds@1952
   178
		}
ds@1952
   179
		return ConfigResult_Accept;
ds@1952
   180
	} else if (strcmp(key, "AllowClLanguageVar") == 0) {
ds@1952
   181
		if (strcasecmp(value, "on") == 0)
ds@1952
   182
		{
ds@1952
   183
			m_QueryLang = true;
ds@1952
   184
		} else if (strcasecmp(value, "off") == 0) {
ds@1952
   185
			m_QueryLang = false;
ds@1952
   186
		} else {
ds@1952
   187
			UTIL_Format(error, maxlength, "Invalid value: must be \"on\" or \"off\"");
ds@1952
   188
			return ConfigResult_Reject;
ds@1952
   189
		}
ds@1952
   190
		return ConfigResult_Accept;
ds@1952
   191
	}
ds@1952
   192
	return ConfigResult_Ignore;
ds@1952
   193
}
ds@1952
   194
ds@1952
   195
void PlayerManager::OnServerActivate(edict_t *pEdictList, int edictCount, int clientMax)
ds@1952
   196
{
ds@1952
   197
	if (!m_FirstPass)
ds@1952
   198
	{
ds@1952
   199
		/* Initialize all players */
ds@1952
   200
		m_maxClients = clientMax;
ds@1952
   201
		m_PlayerCount = 0;
ds@1952
   202
		m_Players = new CPlayer[m_maxClients + 1];
ds@1952
   203
		m_AuthQueue = new unsigned int[m_maxClients + 1];
ds@1952
   204
		m_FirstPass = true;
ds@1952
   205
ds@1952
   206
		memset(m_AuthQueue, 0, sizeof(unsigned int) * (m_maxClients + 1));
ds@1952
   207
ds@1952
   208
		g_NumPlayersToAuth = &m_AuthQueue[0];
ds@1952
   209
	}
faluco@1993
   210
	g_Extensions.CallOnCoreMapStart(pEdictList, edictCount, clientMax);
ds@1952
   211
	m_onActivate->Execute(NULL);
ds@1952
   212
	m_onActivate2->Execute(NULL);
ds@1952
   213
ds@1952
   214
	List<IClientListener *>::iterator iter;
ds@1952
   215
	for (iter = m_hooks.begin(); iter != m_hooks.end(); iter++)
ds@1952
   216
	{
ds@1952
   217
		if ((*iter)->GetClientListenerVersion() >= 5)
ds@1952
   218
		{
ds@1952
   219
			(*iter)->OnServerActivated(clientMax);
ds@1952
   220
		}
ds@1952
   221
	}
ds@1952
   222
ds@1952
   223
	g_OnMapStarted = true;
ds@1952
   224
ds@1952
   225
	SM_ExecuteAllConfigs();
ds@1952
   226
}
ds@1952
   227
ds@1952
   228
bool PlayerManager::IsServerActivated()
ds@1952
   229
{
ds@1952
   230
	return m_FirstPass;
ds@1952
   231
}
ds@1952
   232
ds@1952
   233
bool PlayerManager::CheckSetAdmin(int index, CPlayer *pPlayer, AdminId id)
ds@1952
   234
{
ds@1952
   235
	const char *password = g_Admins.GetAdminPassword(id);
ds@1952
   236
	if (password != NULL)
ds@1952
   237
	{
ds@1952
   238
		if (m_PassInfoVar.size() < 1)
ds@1952
   239
		{
ds@1952
   240
			return false;
ds@1952
   241
		}
ds@1952
   242
ds@1952
   243
		/* Whoa... the user needs a password! */
ds@1952
   244
		const char *given = engine->GetClientConVarValue(index, m_PassInfoVar.c_str());
ds@1952
   245
		if (!given || strcmp(given, password) != 0)
ds@1952
   246
		{
ds@1952
   247
			return false;
ds@1952
   248
		}
ds@1952
   249
	}
ds@1952
   250
ds@1952
   251
	pPlayer->SetAdminId(id, false);
ds@1952
   252
ds@1952
   253
	return true;
ds@1952
   254
}
ds@1952
   255
ds@1952
   256
bool PlayerManager::CheckSetAdminName(int index, CPlayer *pPlayer, AdminId id)
ds@1952
   257
{
ds@1952
   258
	const char *password = g_Admins.GetAdminPassword(id);
ds@1952
   259
	if (password == NULL)
ds@1952
   260
	{
ds@1952
   261
		return false;
ds@1952
   262
	}
ds@1952
   263
ds@1952
   264
	if (m_PassInfoVar.size() < 1)
ds@1952
   265
	{
ds@1952
   266
		return false;
ds@1952
   267
	}
ds@1952
   268
ds@1952
   269
	/* Whoa... the user needs a password! */
ds@1952
   270
	const char *given = engine->GetClientConVarValue(index, m_PassInfoVar.c_str());
ds@1952
   271
	if (!given || strcmp(given, password) != 0)
ds@1952
   272
	{
ds@1952
   273
		return false;
ds@1952
   274
	}
ds@1952
   275
ds@1952
   276
	pPlayer->SetAdminId(id, false);
ds@1952
   277
ds@1952
   278
	return true;
ds@1952
   279
}
ds@1952
   280
ds@1952
   281
void PlayerManager::RunAuthChecks()
ds@1952
   282
{
ds@1952
   283
	CPlayer *pPlayer;
ds@1952
   284
	const char *authstr;
ds@1952
   285
	unsigned int removed = 0;
ds@1952
   286
	for (unsigned int i=1; i<=m_AuthQueue[0]; i++)
ds@1952
   287
	{
ds@1952
   288
		pPlayer = GetPlayerByIndex(m_AuthQueue[i]);
ds@1952
   289
		authstr = engine->GetPlayerNetworkIDString(pPlayer->m_pEdict);
ds@1952
   290
		if (authstr && authstr[0] != '\0'
ds@1952
   291
			&& (strcmp(authstr, "STEAM_ID_PENDING") != 0))
ds@1952
   292
		{
ds@1952
   293
			/* Set authorization */
ds@1952
   294
			pPlayer->Authorize(authstr);
ds@1952
   295
ds@1952
   296
			/* Mark as removed from queue */
ds@1952
   297
			unsigned int client = m_AuthQueue[i];
ds@1952
   298
			m_AuthQueue[i] = 0;
ds@1952
   299
			removed++;
ds@1952
   300
ds@1952
   301
			/* Send to extensions */
ds@1952
   302
			List<IClientListener *>::iterator iter;
ds@1952
   303
			IClientListener *pListener;
ds@1952
   304
			for (iter=m_hooks.begin(); iter!=m_hooks.end(); iter++)
ds@1952
   305
			{
ds@1952
   306
				pListener = (*iter);
ds@1952
   307
				pListener->OnClientAuthorized(client, authstr);
ds@1952
   308
				if (!pPlayer->IsConnected())
ds@1952
   309
				{
ds@1952
   310
					break;
ds@1952
   311
				}
ds@1952
   312
			}
ds@1952
   313
ds@1952
   314
			/* Send to plugins if player is still connected */
ds@1952
   315
			if (pPlayer->IsConnected() && m_clauth->GetFunctionCount())
ds@1952
   316
			{
ds@1952
   317
				/* :TODO: handle the case of a player disconnecting in the middle */
ds@1952
   318
				m_clauth->PushCell(client);
ds@1952
   319
				m_clauth->PushString(authstr);
ds@1952
   320
				m_clauth->Execute(NULL);
ds@1952
   321
			}
ds@1952
   322
ds@1952
   323
			if (pPlayer->IsConnected())
ds@1952
   324
			{
ds@1952
   325
				pPlayer->Authorize_Post();
ds@1952
   326
			}
ds@1952
   327
		}
ds@1952
   328
	}
ds@1952
   329
ds@1952
   330
	/* Clean up the queue */
ds@1952
   331
	if (removed)
ds@1952
   332
	{
ds@1952
   333
		/* We don't have to compact the list if it's empty */
ds@1952
   334
		if (removed != m_AuthQueue[0])
ds@1952
   335
		{
ds@1952
   336
			unsigned int diff = 0;
ds@1952
   337
			for (unsigned int i=1; i<=m_AuthQueue[0]; i++)
ds@1952
   338
			{
ds@1952
   339
				/* If this member is removed... */
ds@1952
   340
				if (m_AuthQueue[i] == 0)
ds@1952
   341
				{
ds@1952
   342
					/* Increase the differential */
ds@1952
   343
					diff++;
ds@1952
   344
				} else {
ds@1952
   345
					/* diff cannot increase faster than i+1 */
ds@1952
   346
					assert(i > diff);
ds@1952
   347
					assert(i - diff >= 1);
ds@1952
   348
					/* move this index down */
ds@1952
   349
					m_AuthQueue[i - diff] = m_AuthQueue[i];
ds@1952
   350
				}
ds@1952
   351
			}
ds@1952
   352
			m_AuthQueue[0] -= removed;
ds@1952
   353
		} else {
ds@1952
   354
			m_AuthQueue[0] = 0;
ds@1952
   355
		}
ds@1952
   356
	}
ds@1952
   357
}
ds@1952
   358
ds@1952
   359
bool PlayerManager::OnClientConnect(edict_t *pEntity, const char *pszName, const char *pszAddress, char *reject, int maxrejectlen)
ds@1952
   360
{
ds@1952
   361
	int client = engine->IndexOfEdict(pEntity);
ds@1952
   362
ds@1952
   363
	List<IClientListener *>::iterator iter;
ds@1952
   364
	IClientListener *pListener = NULL;
ds@1952
   365
	for (iter=m_hooks.begin(); iter!=m_hooks.end(); iter++)
ds@1952
   366
	{
ds@1952
   367
		pListener = (*iter);
ds@1952
   368
		if (!pListener->InterceptClientConnect(client, reject, maxrejectlen))
ds@1952
   369
		{
ds@1952
   370
			return false;
ds@1952
   371
		}
ds@1952
   372
	}
ds@1952
   373
ds@1952
   374
	cell_t res = 1;
ds@1952
   375
ds@1952
   376
	m_Players[client].Initialize(pszName, pszAddress, pEntity);
ds@1952
   377
	m_clconnect->PushCell(client);
ds@1952
   378
	m_clconnect->PushStringEx(reject, maxrejectlen, SM_PARAM_STRING_UTF8, SM_PARAM_COPYBACK);
ds@1952
   379
	m_clconnect->PushCell(maxrejectlen);
ds@1952
   380
	m_clconnect->Execute(&res, NULL);
ds@1952
   381
ds@1952
   382
	if (res)
ds@1952
   383
	{
ds@1952
   384
		if (!m_Players[client].IsAuthorized())
ds@1952
   385
		{
ds@1952
   386
			m_AuthQueue[++m_AuthQueue[0]] = client;
ds@1952
   387
		}
ds@1952
   388
	} else {
ds@1952
   389
		RETURN_META_VALUE(MRES_SUPERCEDE, false);
ds@1952
   390
	}
ds@1952
   391
ds@1952
   392
	m_UserIdLookUp[engine->GetPlayerUserId(pEntity)] = client;
ds@1952
   393
ds@1952
   394
	return true;
ds@1952
   395
}
ds@1952
   396
ds@1952
   397
bool PlayerManager::OnClientConnect_Post(edict_t *pEntity, const char *pszName, const char *pszAddress, char *reject, int maxrejectlen)
ds@1952
   398
{
ds@1952
   399
	int client = engine->IndexOfEdict(pEntity);
ds@1952
   400
	bool orig_value = META_RESULT_ORIG_RET(bool);
ds@1952
   401
	CPlayer *pPlayer = GetPlayerByIndex(client);
ds@1952
   402
ds@1952
   403
	if (orig_value)
ds@1952
   404
	{
ds@1952
   405
		List<IClientListener *>::iterator iter;
ds@1952
   406
		IClientListener *pListener = NULL;
ds@1952
   407
		for (iter=m_hooks.begin(); iter!=m_hooks.end(); iter++)
ds@1952
   408
		{
ds@1952
   409
			pListener = (*iter);
ds@1952
   410
			pListener->OnClientConnected(client);
ds@1952
   411
			if (!pPlayer->IsConnected())
ds@1952
   412
			{
ds@1952
   413
				break;
ds@1952
   414
			}
ds@1952
   415
		}
ds@1952
   416
	}
ds@1952
   417
ds@1952
   418
	return true;
ds@1952
   419
}
ds@1952
   420
ds@1952
   421
void PlayerManager::OnClientPutInServer(edict_t *pEntity, const char *playername)
ds@1952
   422
{
ds@1952
   423
	cell_t res;
ds@1952
   424
	int client = engine->IndexOfEdict(pEntity);
ds@1952
   425
ds@1952
   426
	CPlayer *pPlayer = GetPlayerByIndex(client);
ds@1952
   427
	/* If they're not connected, they're a bot */
ds@1952
   428
	if (!pPlayer->IsConnected())
ds@1952
   429
	{
ds@1952
   430
		/* Run manual connection routines */
ds@1952
   431
		char error[255];
ds@1952
   432
		const char *authid = engine->GetPlayerNetworkIDString(pEntity);
ds@1952
   433
		pPlayer->Authorize(authid);
ds@1952
   434
		if (!OnClientConnect(pEntity, playername, "127.0.0.1", error, sizeof(error)))
ds@1952
   435
		{
ds@1952
   436
			/* :TODO: kick the bot if it's rejected */
ds@1952
   437
			return;
ds@1952
   438
		}
ds@1952
   439
		List<IClientListener *>::iterator iter;
ds@1952
   440
		IClientListener *pListener = NULL;
ds@1952
   441
		for (iter=m_hooks.begin(); iter!=m_hooks.end(); iter++)
ds@1952
   442
		{
ds@1952
   443
			pListener = (*iter);
ds@1952
   444
			pListener->OnClientConnected(client);
ds@1952
   445
			/* See if bot was kicked */
ds@1952
   446
			if (!pPlayer->IsConnected())
ds@1952
   447
			{
ds@1952
   448
				return;
ds@1952
   449
			}
ds@1952
   450
		}
ds@1952
   451
		/* Now do authorization */
ds@1952
   452
		for (iter=m_hooks.begin(); iter!=m_hooks.end(); iter++)
ds@1952
   453
		{
ds@1952
   454
			pListener = (*iter);
ds@1952
   455
			pListener->OnClientAuthorized(client, authid);
ds@1952
   456
		}
ds@1952
   457
		/* Finally, tell plugins */
ds@1952
   458
		if (m_clauth->GetFunctionCount())
ds@1952
   459
		{
ds@1952
   460
			m_clauth->PushCell(client);
ds@1952
   461
			m_clauth->PushString(authid);
ds@1952
   462
			m_clauth->Execute(NULL);
ds@1952
   463
		}
ds@1952
   464
		pPlayer->Authorize_Post();
ds@1952
   465
	}
ds@1952
   466
ds@1952
   467
	if (playerinfo)
ds@1952
   468
	{
ds@1952
   469
		pPlayer->m_Info = playerinfo->GetPlayerInfo(pEntity);
ds@1952
   470
	}
ds@1952
   471
ds@1952
   472
	/* Get the client's language */
ds@1952
   473
	if (m_QueryLang)
ds@1952
   474
	{
ds@1952
   475
		const char *name;
ds@1952
   476
		if (!pPlayer->IsFakeClient() && (name=engine->GetClientConVarValue(client, "cl_language")))
ds@1952
   477
		{
ds@1952
   478
			unsigned int langid;
ds@1952
   479
			pPlayer->m_LangId = (g_Translator.GetLanguageByName(name, &langid)) ? langid : g_Translator.GetServerLanguage();
ds@1952
   480
		} else {
ds@1952
   481
			pPlayer->m_LangId = g_Translator.GetServerLanguage();
ds@1952
   482
		}
ds@1952
   483
	}
ds@1952
   484
ds@1952
   485
	m_Players[client].Connect();
ds@1952
   486
	m_PlayerCount++;
ds@1952
   487
ds@1952
   488
	List<IClientListener *>::iterator iter;
ds@1952
   489
	IClientListener *pListener = NULL;
ds@1952
   490
	for (iter=m_hooks.begin(); iter!=m_hooks.end(); iter++)
ds@1952
   491
	{
ds@1952
   492
		pListener = (*iter);
ds@1952
   493
		pListener->OnClientPutInServer(client);
ds@1952
   494
	}
ds@1952
   495
ds@1952
   496
	m_clputinserver->PushCell(client);
ds@1952
   497
	m_clputinserver->Execute(&res, NULL);
ds@1952
   498
ds@1952
   499
	if (m_Players[client].IsAuthorized())
ds@1952
   500
	{
ds@1952
   501
		m_Players[client].DoPostConnectAuthorization();
ds@1952
   502
	}
ds@1952
   503
}
ds@1952
   504
ds@1952
   505
void PlayerManager::OnSourceModLevelEnd()
ds@1952
   506
{
ds@1952
   507
	/* Disconnect all bots still in game */
ds@1952
   508
	for (int i=1; i<=m_maxClients; i++)
ds@1952
   509
	{
ds@1952
   510
		if (m_Players[i].IsConnected())
ds@1952
   511
		{
ds@1952
   512
			OnClientDisconnect(m_Players[i].GetEdict());
ds@1952
   513
		}
ds@1952
   514
	}
ds@1952
   515
	m_PlayerCount = 0;
ds@1952
   516
}
ds@1952
   517
ds@1952
   518
void PlayerManager::OnClientDisconnect(edict_t *pEntity)
ds@1952
   519
{
ds@1952
   520
	cell_t res;
ds@1952
   521
	int client = engine->IndexOfEdict(pEntity);
ds@1952
   522
ds@1952
   523
	if (m_Players[client].IsConnected())
ds@1952
   524
	{
ds@1952
   525
		m_cldisconnect->PushCell(client);
ds@1952
   526
		m_cldisconnect->Execute(&res, NULL);
ds@1952
   527
	} else {
ds@1952
   528
		/* We don't care, prevent a double call */
ds@1952
   529
		return;
ds@1952
   530
	}
ds@1952
   531
ds@1952
   532
	if (m_Players[client].WasCountedAsInGame())
ds@1952
   533
	{
ds@1952
   534
		m_PlayerCount--;
ds@1952
   535
	}
ds@1952
   536
ds@1952
   537
	List<IClientListener *>::iterator iter;
ds@1952
   538
	IClientListener *pListener = NULL;
ds@1952
   539
	for (iter=m_hooks.begin(); iter!=m_hooks.end(); iter++)
ds@1952
   540
	{
ds@1952
   541
		pListener = (*iter);
ds@1952
   542
		pListener->OnClientDisconnecting(client);
ds@1952
   543
	}
ds@1952
   544
ds@1952
   545
	/**
ds@1952
   546
	 * Remove client from auth queue if necessary
ds@1952
   547
	 */
ds@1952
   548
	if (!m_Players[client].IsAuthorized())
ds@1952
   549
	{
ds@1952
   550
		for (unsigned int i=1; i<=m_AuthQueue[0]; i++)
ds@1952
   551
		{
ds@1952
   552
			if (m_AuthQueue[i] == (unsigned)client)
ds@1952
   553
			{
ds@1952
   554
				/* Move everything ahead of us back by one */
ds@1952
   555
				for (unsigned int j=i+1; j<=m_AuthQueue[0]; j++)
ds@1952
   556
				{
ds@1952
   557
					m_AuthQueue[j-1] = m_AuthQueue[j];
ds@1952
   558
				}
ds@1952
   559
				/* Remove us and break */
ds@1952
   560
				m_AuthQueue[0]--;
ds@1952
   561
				break;
ds@1952
   562
			}
ds@1952
   563
		}
ds@1952
   564
	}
ds@1952
   565
ds@1952
   566
	m_Players[client].Disconnect();
ds@1952
   567
	m_UserIdLookUp[engine->GetPlayerUserId(pEntity)] = 0;
ds@1952
   568
}
ds@1952
   569
ds@1952
   570
void PlayerManager::OnClientDisconnect_Post(edict_t *pEntity)
ds@1952
   571
{
ds@1952
   572
	cell_t res;
ds@1952
   573
	int client = engine->IndexOfEdict(pEntity);
ds@1952
   574
ds@1952
   575
	m_cldisconnect_post->PushCell(client);
ds@1952
   576
	m_cldisconnect_post->Execute(&res, NULL);
ds@1952
   577
ds@1952
   578
	List<IClientListener *>::iterator iter;
ds@1952
   579
	IClientListener *pListener = NULL;
ds@1952
   580
	for (iter=m_hooks.begin(); iter!=m_hooks.end(); iter++)
ds@1952
   581
	{
ds@1952
   582
		pListener = (*iter);
ds@1952
   583
		pListener->OnClientDisconnected(client);
ds@1952
   584
	}
ds@1952
   585
}
ds@1952
   586
ds@1952
   587
#if defined ORANGEBOX_BUILD
ds@1952
   588
void PlayerManager::OnClientCommand(edict_t *pEntity, const CCommand &args)
ds@1952
   589
{
ds@1952
   590
#else
ds@1952
   591
void PlayerManager::OnClientCommand(edict_t *pEntity)
ds@1952
   592
{
ds@1952
   593
	CCommand args;
ds@1952
   594
#endif
ds@1952
   595
	int client = engine->IndexOfEdict(pEntity);
ds@1952
   596
	cell_t res = Pl_Continue;
ds@1952
   597
ds@1952
   598
	CPlayer *pPlayer = GetPlayerByIndex(client);
ds@1952
   599
	if (!pPlayer || !pPlayer->IsConnected())
ds@1952
   600
	{
ds@1952
   601
		return;
ds@1952
   602
	}
ds@1952
   603
ds@1952
   604
	g_HL2.PushCommandStack(&args);
ds@1952
   605
ds@1952
   606
	int argcount = args.ArgC() - 1;
ds@1952
   607
	const char *cmd = g_HL2.CurrentCommandName();
ds@1952
   608
ds@1952
   609
	bool result = g_ValveMenuStyle.OnClientCommand(client, cmd, args);
ds@1952
   610
	if (result)
ds@1952
   611
	{
ds@1952
   612
		res = Pl_Handled;
ds@1952
   613
	} else {
ds@1952
   614
		result = g_RadioMenuStyle.OnClientCommand(client, cmd, args);
ds@1952
   615
		if (result)
ds@1952
   616
		{
ds@1952
   617
			res = Pl_Handled;
ds@1952
   618
		}
ds@1952
   619
	}
ds@1952
   620
ds@1952
   621
	cell_t res2 = Pl_Continue;
ds@1952
   622
	m_clcommand->PushCell(client);
ds@1952
   623
	m_clcommand->PushCell(argcount);
ds@1952
   624
	m_clcommand->Execute(&res2, NULL);
ds@1952
   625
ds@1952
   626
	if (res2 > res)
ds@1952
   627
	{
ds@1952
   628
		res = res2;
ds@1952
   629
	}
ds@1952
   630
ds@1952
   631
	if (res >= Pl_Stop)
ds@1952
   632
	{
ds@1952
   633
		g_HL2.PopCommandStack();
ds@1952
   634
		RETURN_META(MRES_SUPERCEDE);
ds@1952
   635
	}
ds@1952
   636
ds@1952
   637
	res = g_ConCmds.DispatchClientCommand(client, cmd, argcount, (ResultType)res);
ds@1952
   638
ds@1952
   639
	g_HL2.PopCommandStack();
ds@1952
   640
ds@1952
   641
	if (res >= Pl_Handled)
ds@1952
   642
	{
ds@1952
   643
		RETURN_META(MRES_SUPERCEDE);
ds@1952
   644
	}
ds@1952
   645
}
ds@1952
   646
ds@1952
   647
void PlayerManager::OnClientSettingsChanged(edict_t *pEntity)
ds@1952
   648
{
ds@1952
   649
	cell_t res;
ds@1952
   650
	int client = engine->IndexOfEdict(pEntity);
ds@1952
   651
ds@1952
   652
	if (!m_Players[client].IsConnected())
ds@1952
   653
	{
ds@1952
   654
		return;
ds@1952
   655
	}
ds@1952
   656
ds@1952
   657
	m_clinfochanged->PushCell(engine->IndexOfEdict(pEntity));
ds@1952
   658
	m_clinfochanged->Execute(&res, NULL);
ds@1952
   659
ds@1952
   660
	IPlayerInfo *info = m_Players[client].GetPlayerInfo();
ds@1952
   661
	const char *new_name = info ? info->GetName() : engine->GetClientConVarValue(client, "name");
ds@1952
   662
	const char *old_name = m_Players[client].m_Name.c_str();
ds@1952
   663
ds@1952
   664
	if (strcmp(old_name, new_name) != 0)
ds@1952
   665
	{
ds@1952
   666
		AdminId id = g_Admins.FindAdminByIdentity("name", new_name);
ds@1952
   667
		if (id != INVALID_ADMIN_ID && m_Players[client].GetAdminId() != id)
ds@1952
   668
		{
ds@1952
   669
			if (!CheckSetAdminName(client, &m_Players[client], id))
ds@1952
   670
			{
ds@1952
   671
				m_Players[client].Kick("Your name is reserved by SourceMod; set your password to use it.");
ds@1952
   672
				RETURN_META(MRES_IGNORED);
ds@1952
   673
			}
ds@1952
   674
		} else if ((id = g_Admins.FindAdminByIdentity("name", old_name)) != INVALID_ADMIN_ID) {
ds@1952
   675
			if (id == m_Players[client].GetAdminId())
ds@1952
   676
			{
ds@1952
   677
				/* This player is changing their name; force them to drop admin privileges! */
ds@1952
   678
				m_Players[client].SetAdminId(INVALID_ADMIN_ID, false);
ds@1952
   679
			}
ds@1952
   680
		}
ds@1952
   681
		m_Players[client].SetName(new_name);
ds@1952
   682
	}
ds@1952
   683
	
ds@1952
   684
	if (m_PassInfoVar.size() > 0)
ds@1952
   685
	{
ds@1952
   686
		/* Try for a password change */
ds@1952
   687
		const char *old_pass = m_Players[client].m_LastPassword.c_str();
ds@1952
   688
		const char *new_pass = engine->GetClientConVarValue(client, m_PassInfoVar.c_str());
ds@1952
   689
		if (strcmp(old_pass, new_pass) != 0)
ds@1952
   690
		{
ds@1952
   691
			m_Players[client].m_LastPassword.assign(new_pass);
ds@1952
   692
			if (m_Players[client].IsInGame() && m_Players[client].IsAuthorized())
ds@1952
   693
			{
ds@1952
   694
				/* If there is already an admin id assigned, this will just bail out. */
ds@1952
   695
				m_Players[client].DoBasicAdminChecks();
ds@1952
   696
			}
ds@1952
   697
		}
ds@1952
   698
	}
ds@1952
   699
}
ds@1952
   700
ds@1952
   701
int PlayerManager::GetMaxClients()
ds@1952
   702
{
ds@1952
   703
	return m_maxClients;
ds@1952
   704
}
ds@1952
   705
ds@1952
   706
CPlayer *PlayerManager::GetPlayerByIndex(int client) const
ds@1952
   707
{
ds@1952
   708
	if (client > m_maxClients || client < 1)
ds@1952
   709
	{
ds@1952
   710
		return NULL;
ds@1952
   711
	}
ds@1952
   712
	return &m_Players[client];
ds@1952
   713
}
ds@1952
   714
ds@1952
   715
int PlayerManager::GetNumPlayers()
ds@1952
   716
{
ds@1952
   717
	return m_PlayerCount;
ds@1952
   718
}
ds@1952
   719
ds@1952
   720
int PlayerManager::GetClientOfUserId(int userid)
ds@1952
   721
{
ds@1952
   722
	if (userid < 0 || userid > USHRT_MAX)
ds@1952
   723
	{
ds@1952
   724
		return 0;
ds@1952
   725
	}
ds@1952
   726
	
ds@1952
   727
	int client = m_UserIdLookUp[userid];
ds@1952
   728
ds@1952
   729
	/* Verify the userid.  The cache can get messed up with older
ds@1952
   730
	 * Valve engines.  :TODO: If this gets fixed, do an old engine 
ds@1952
   731
	 * check before invoking this backwards compat code.
ds@1952
   732
	 */
ds@1952
   733
	if (client)
ds@1952
   734
	{
ds@1952
   735
		CPlayer *player = GetPlayerByIndex(client);
ds@1952
   736
		if (player && player->IsConnected())
ds@1952
   737
		{
ds@1952
   738
			int realUserId = engine->GetPlayerUserId(player->GetEdict());
ds@1952
   739
			if (realUserId == userid)
ds@1952
   740
			{
ds@1952
   741
				return client;
ds@1952
   742
			}
ds@1952
   743
		}
ds@1952
   744
	}
ds@1952
   745
ds@1952
   746
	/* If we can't verify the userid, we have to do a manual loop */
ds@1952
   747
	CPlayer *player;
ds@1952
   748
	for (int i = 1; i <= m_maxClients; i++)
ds@1952
   749
	{
ds@1952
   750
		player = GetPlayerByIndex(i);
ds@1952
   751
		if (!player || !player->IsConnected())
ds@1952
   752
		{
ds@1952
   753
			continue;
ds@1952
   754
		}
ds@1952
   755
		if (engine->GetPlayerUserId(player->GetEdict()) == userid)
ds@1952
   756
		{
ds@1952
   757
			m_UserIdLookUp[userid] = i;
ds@1952
   758
			return i;
ds@1952
   759
		}
ds@1952
   760
	}
ds@1952
   761
ds@1952
   762
	return 0;
ds@1952
   763
}
ds@1952
   764
ds@1952
   765
void PlayerManager::AddClientListener(IClientListener *listener)
ds@1952
   766
{
ds@1952
   767
	m_hooks.push_back(listener);
ds@1952
   768
}
ds@1952
   769
ds@1952
   770
void PlayerManager::RemoveClientListener(IClientListener *listener)
ds@1952
   771
{
ds@1952
   772
	m_hooks.remove(listener);
ds@1952
   773
}
ds@1952
   774
ds@1952
   775
IGamePlayer *PlayerManager::GetGamePlayer(edict_t *pEdict)
ds@1952
   776
{
ds@1952
   777
	int index = engine->IndexOfEdict(pEdict);
ds@1952
   778
	return GetGamePlayer(index);
ds@1952
   779
}
ds@1952
   780
ds@1952
   781
IGamePlayer *PlayerManager::GetGamePlayer(int client)
ds@1952
   782
{
ds@1952
   783
	return GetPlayerByIndex(client);
ds@1952
   784
}
ds@1952
   785
ds@1952
   786
void PlayerManager::ClearAdminId(AdminId id)
ds@1952
   787
{
ds@1952
   788
	for (int i=1; i<=m_maxClients; i++)
ds@1952
   789
	{
ds@1952
   790
		if (m_Players[i].m_Admin == id)
ds@1952
   791
		{
ds@1952
   792
			m_Players[i].DumpAdmin(true);
ds@1952
   793
		}
ds@1952
   794
	}
ds@1952
   795
}
ds@1952
   796
ds@1952
   797
void PlayerManager::ClearAllAdmins()
ds@1952
   798
{
ds@1952
   799
	for (int i=1; i<=m_maxClients; i++)
ds@1952
   800
	{
ds@1952
   801
		m_Players[i].DumpAdmin(true);
ds@1952
   802
	}
ds@1952
   803
}
ds@1952
   804
ds@1952
   805
const char *PlayerManager::GetPassInfoVar()
ds@1952
   806
{
ds@1952
   807
	return m_PassInfoVar.c_str();
ds@1952
   808
}
ds@1952
   809
ds@1952
   810
void PlayerManager::RecheckAnyAdmins()
ds@1952
   811
{
ds@1952
   812
	for (int i=1; i<=m_maxClients; i++)
ds@1952
   813
	{
ds@1952
   814
		if (m_Players[i].IsInGame() && m_Players[i].IsAuthorized())
ds@1952
   815
		{
ds@1952
   816
			m_Players[i].DoBasicAdminChecks();
ds@1952
   817
		}
ds@1952
   818
	}
ds@1952
   819
}
ds@1952
   820
ds@1952
   821
unsigned int PlayerManager::GetReplyTo()
ds@1952
   822
{
ds@1952
   823
	return g_ChatTriggers.GetReplyTo();
ds@1952
   824
}
ds@1952
   825
ds@1952
   826
unsigned int PlayerManager::SetReplyTo(unsigned int reply)
ds@1952
   827
{
ds@1952
   828
	return g_ChatTriggers.SetReplyTo(reply);
ds@1952
   829
}
ds@1952
   830
ds@1952
   831
int PlayerManager::FilterCommandTarget(IGamePlayer *pAdmin, IGamePlayer *pTarget, int flags)
ds@1952
   832
{
ds@1952
   833
	return InternalFilterCommandTarget((CPlayer *)pAdmin, (CPlayer *)pTarget, flags);
ds@1952
   834
}
ds@1952
   835
ds@1952
   836
void PlayerManager::RegisterCommandTargetProcessor(ICommandTargetProcessor *pHandler)
ds@1952
   837
{
ds@1952
   838
	target_processors.push_back(pHandler);
ds@1952
   839
}
ds@1952
   840
ds@1952
   841
void PlayerManager::UnregisterCommandTargetProcessor(ICommandTargetProcessor *pHandler)
ds@1952
   842
{
ds@1952
   843
	target_processors.remove(pHandler);
ds@1952
   844
}
ds@1952
   845
ds@1952
   846
int PlayerManager::InternalFilterCommandTarget(CPlayer *pAdmin, CPlayer *pTarget, int flags)
ds@1952
   847
{
ds@1952
   848
	if ((flags & COMMAND_FILTER_CONNECTED) == COMMAND_FILTER_CONNECTED
ds@1952
   849
		&& !pTarget->IsConnected())
ds@1952
   850
	{
ds@1952
   851
		return COMMAND_TARGET_NONE;
ds@1952
   852
	}
ds@1952
   853
	else if ((flags & COMMAND_FILTER_CONNECTED) != COMMAND_FILTER_CONNECTED && 
ds@1952
   854
		!pTarget->IsInGame())
ds@1952
   855
	{
ds@1952
   856
		return COMMAND_TARGET_NOT_IN_GAME;
ds@1952
   857
	}
ds@1952
   858
ds@1952
   859
	if ((flags & COMMAND_FILTER_NO_BOTS) == COMMAND_FILTER_NO_BOTS
ds@1952
   860
		&& pTarget->IsFakeClient())
ds@1952
   861
	{
ds@1952
   862
		return COMMAND_TARGET_NOT_HUMAN;
ds@1952
   863
	}
ds@1952
   864
ds@1952
   865
	if (pAdmin != NULL)
ds@1952
   866
	{
ds@1952
   867
		if ((flags & COMMAND_FILTER_NO_IMMUNITY) != COMMAND_FILTER_NO_IMMUNITY
ds@1952
   868
			&& !g_Admins.CanAdminTarget(pAdmin->GetAdminId(), pTarget->GetAdminId()))
ds@1952
   869
		{
ds@1952
   870
			return COMMAND_TARGET_IMMUNE;
ds@1952
   871
		}
ds@1952
   872
	}
ds@1952
   873
ds@1952
   874
	if ((flags & COMMAND_FILTER_ALIVE) == COMMAND_FILTER_ALIVE 
ds@1952
   875
		&& pTarget->GetLifeState() != PLAYER_LIFE_ALIVE)
ds@1952
   876
	{
ds@1952
   877
		return COMMAND_TARGET_NOT_ALIVE;
ds@1952
   878
	}
ds@1952
   879
ds@1952
   880
	if ((flags & COMMAND_FILTER_DEAD) == COMMAND_FILTER_DEAD
ds@1952
   881
		&& pTarget->GetLifeState() != PLAYER_LIFE_DEAD)
ds@1952
   882
	{
ds@1952
   883
		return COMMAND_TARGET_NOT_DEAD;
ds@1952
   884
	}
ds@1952
   885
ds@1952
   886
	return COMMAND_TARGET_VALID;
ds@1952
   887
}
ds@1952
   888
ds@1952
   889
void PlayerManager::ProcessCommandTarget(cmd_target_info_t *info)
ds@1952
   890
{
ds@1952
   891
	CPlayer *pTarget, *pAdmin;
ds@1952
   892
	int max_clients, total = 0;
ds@1952
   893
ds@1952
   894
	max_clients = GetMaxClients();
ds@1952
   895
ds@1952
   896
	if (info->max_targets < 1)
ds@1952
   897
	{
ds@1952
   898
		info->reason = COMMAND_TARGET_NONE;
ds@1952
   899
		info->num_targets = 0;
ds@1952
   900
	}
ds@1952
   901
ds@1952
   902
	if (info->admin == 0)
ds@1952
   903
	{
ds@1952
   904
		pAdmin = NULL;
ds@1952
   905
	}
ds@1952
   906
	else
ds@1952
   907
	{
ds@1952
   908
		pAdmin = GetPlayerByIndex(info->admin);
ds@1952
   909
	}
ds@1952
   910
ds@1952
   911
	if (info->pattern[0] == '#')
ds@1952
   912
	{
ds@1952
   913
		int userid = atoi(&info->pattern[1]);
ds@1952
   914
		int client = GetClientOfUserId(userid);
ds@1952
   915
ds@1952
   916
		/* See if a valid userid matched */
ds@1952
   917
		if (client > 0)
ds@1952
   918
		{
ds@1952
   919
			IGamePlayer *pTarget = GetPlayerByIndex(client);
ds@1952
   920
			if (pTarget != NULL)
ds@1952
   921
			{
ds@1952
   922
				if ((info->reason = FilterCommandTarget(pAdmin, pTarget, info->flags)) == COMMAND_TARGET_VALID)
ds@1952
   923
				{
ds@1952
   924
					info->targets[0] = client;
ds@1952
   925
					info->num_targets = 1;
ds@1952
   926
					strncopy(info->target_name, pTarget->GetName(), info->target_name_maxlength);
ds@1952
   927
					info->target_name_style = COMMAND_TARGETNAME_RAW;
ds@1952
   928
				}
ds@1952
   929
				else
ds@1952
   930
				{
ds@1952
   931
					info->num_targets = 0;
ds@1952
   932
				}
ds@1952
   933
				return;
ds@1952
   934
			}
ds@1952
   935
		}
ds@1952
   936
ds@1952
   937
		/* Do we need to look for a steam id? */
ds@1952
   938
		if (strncmp(&info->pattern[1], "STEAM_", 6) == 0)
ds@1952
   939
		{
ds@1952
   940
			size_t p, len;
ds@1952
   941
			char new_pattern[256];
ds@1952
   942
ds@1952
   943
			strcpy(new_pattern, "STEAM_");
ds@1952
   944
			len = strlen(&info->pattern[7]);
ds@1952
   945
			for (p = 0; p < len; p++)
ds@1952
   946
			{
ds@1952
   947
				new_pattern[6 + p] = info->pattern[7 + p];
ds@1952
   948
				if (new_pattern[6 + p] == '_')
ds@1952
   949
				{
ds@1952
   950
					new_pattern[6 + p] = ':';
ds@1952
   951
				}
ds@1952
   952
			}
ds@1952
   953
			new_pattern[6 + p] = '\0';
ds@1952
   954
ds@1952
   955
			for (int i = 1; i <= max_clients; i++)
ds@1952
   956
			{
ds@1952
   957
				if ((pTarget = GetPlayerByIndex(i)) == NULL)
ds@1952
   958
				{
ds@1952
   959
					continue;
ds@1952
   960
				}
ds@1952
   961
				if (!pTarget->IsConnected() || !pTarget->IsAuthorized())
ds@1952
   962
				{
ds@1952
   963
					continue;
ds@1952
   964
				}
ds@1952
   965
				if (strcmp(pTarget->GetAuthString(), new_pattern) == 0)
ds@1952
   966
				{
ds@1952
   967
					if ((info->reason = FilterCommandTarget(pAdmin, pTarget, info->flags))
ds@1952
   968
						== COMMAND_TARGET_VALID)
ds@1952
   969
					{
ds@1952
   970
						info->targets[0] = i;
ds@1952
   971
						info->num_targets = 1;
ds@1952
   972
						strncopy(info->target_name, pTarget->GetName(), info->target_name_maxlength);
ds@1952
   973
						info->target_name_style = COMMAND_TARGETNAME_RAW;
ds@1952
   974
					}
ds@1952
   975
					else
ds@1952
   976
					{
ds@1952
   977
						info->num_targets = 0;
ds@1952
   978
					}
ds@1952
   979
					return;
ds@1952
   980
				}
ds@1952
   981
			}
ds@1952
   982
		}
ds@1952
   983
ds@1952
   984
		/* See if an exact name matches */
ds@1952
   985
		for (int i = 1; i <= max_clients; i++)
ds@1952
   986
		{
ds@1952
   987
			if ((pTarget = GetPlayerByIndex(i)) == NULL)
ds@1952
   988
			{
ds@1952
   989
				continue;
ds@1952
   990
			}
ds@1952
   991
			if  (!pTarget->IsConnected())
ds@1952
   992
			{
ds@1952
   993
				continue;
ds@1952
   994
			}
ds@1952
   995
			if (strcmp(pTarget->GetName(), &info->pattern[1]) == 0)
ds@1952
   996
			{
ds@1952
   997
				if ((info->reason = FilterCommandTarget(pAdmin, pTarget, info->flags))
ds@1952
   998
					== COMMAND_TARGET_VALID)
ds@1952
   999
				{
ds@1952
  1000
					info->targets[0] = i;
ds@1952
  1001
					info->num_targets = 1;
ds@1952
  1002
					strncopy(info->target_name, pTarget->GetName(), info->target_name_maxlength);
ds@1952
  1003
					info->target_name_style = COMMAND_TARGETNAME_RAW;
ds@1952
  1004
				}
ds@1952
  1005
				else
ds@1952
  1006
				{
ds@1952
  1007
					info->num_targets = 0;
ds@1952
  1008
				}
ds@1952
  1009
				return;
ds@1952
  1010
			}
ds@1952
  1011
		}
ds@1952
  1012
	}
ds@1952
  1013
ds@1952
  1014
	if (strcmp(info->pattern, "@me") == 0 && info->admin != 0)
ds@1952
  1015
	{
ds@1952
  1016
		info->targets[0] = info->admin;
ds@1952
  1017
		info->num_targets = 1;
ds@1952
  1018
		strncopy(info->target_name, pAdmin->GetName(), info->target_name_maxlength);
ds@1952
  1019
		info->target_name_style = COMMAND_TARGETNAME_RAW;
ds@1952
  1020
		return;
ds@1952
  1021
	}
ds@1952
  1022
ds@1952
  1023
	if ((info->flags & COMMAND_FILTER_NO_MULTI) != COMMAND_FILTER_NO_MULTI)
ds@1952
  1024
	{
ds@1952
  1025
		bool is_multi = false;
ds@1952
  1026
		bool bots_only = false;
ds@1952
  1027
		int skip_client = -1;
ds@1952
  1028
ds@1952
  1029
		if (strcmp(info->pattern, "@all") == 0)
ds@1952
  1030
		{
ds@1952
  1031
			is_multi = true;
ds@1952
  1032
			strncopy(info->target_name, "all players", info->target_name_maxlength);
ds@1952
  1033
			info->target_name_style = COMMAND_TARGETNAME_ML;
ds@1952
  1034
		}
ds@1952
  1035
		else if (strcmp(info->pattern, "@dead") == 0)
ds@1952
  1036
		{
ds@1952
  1037
			is_multi = true;
ds@1952
  1038
			if ((info->flags & COMMAND_FILTER_ALIVE) == COMMAND_FILTER_ALIVE)
ds@1952
  1039
			{
ds@1952
  1040
				info->num_targets = 0;
ds@1952
  1041
				info->reason = COMMAND_TARGET_NOT_ALIVE;
ds@1952
  1042
				return;
ds@1952
  1043
			}
ds@1952
  1044
			info->flags |= COMMAND_FILTER_DEAD;
ds@1952
  1045
			strncopy(info->target_name, "all dead players", info->target_name_maxlength);
ds@1952
  1046
			info->target_name_style = COMMAND_TARGETNAME_ML;
ds@1952
  1047
		}
ds@1952
  1048
		else if (strcmp(info->pattern, "@alive") == 0)
ds@1952
  1049
		{
ds@1952
  1050
			is_multi = true;
ds@1952
  1051
			if ((info->flags & COMMAND_FILTER_DEAD) == COMMAND_FILTER_DEAD)
ds@1952
  1052
			{
ds@1952
  1053
				info->num_targets = 0;
ds@1952
  1054
				info->reason = COMMAND_TARGET_NOT_DEAD;
ds@1952
  1055
				return;
ds@1952
  1056
			}
ds@1952
  1057
			strncopy(info->target_name, "all alive players", info->target_name_maxlength);
ds@1952
  1058
			info->target_name_style = COMMAND_TARGETNAME_ML;
ds@1952
  1059
			info->flags |= COMMAND_FILTER_ALIVE;
ds@1952
  1060
		}
ds@1952
  1061
		else if (strcmp(info->pattern, "@bots") == 0)
ds@1952
  1062
		{
ds@1952
  1063
			is_multi = true;
ds@1952
  1064
			if ((info->flags & COMMAND_FILTER_NO_BOTS) == COMMAND_FILTER_NO_BOTS)
ds@1952
  1065
			{
ds@1952
  1066
				info->num_targets = 0;
ds@1952
  1067
				info->reason = COMMAND_FILTER_NO_BOTS;
ds@1952
  1068
				return;
ds@1952
  1069
			}
ds@1952
  1070
			strncopy(info->target_name, "all bots", info->target_name_maxlength);
ds@1952
  1071
			info->target_name_style = COMMAND_TARGETNAME_ML;
ds@1952
  1072
			bots_only = true;
ds@1952
  1073
		}
ds@1952
  1074
		else if (strcmp(info->pattern, "@humans") == 0)
ds@1952
  1075
		{
ds@1952
  1076
			is_multi = true;
ds@1952
  1077
			strncopy(info->target_name, "all humans", info->target_name_maxlength);
ds@1952
  1078
			info->target_name_style = COMMAND_TARGETNAME_ML;
ds@1952
  1079
			info->flags |= COMMAND_FILTER_NO_BOTS;
ds@1952
  1080
		}
ds@1952
  1081
		else if (strcmp(info->pattern, "@!me") == 0)
ds@1952
  1082
		{
ds@1952
  1083
			is_multi = true;
ds@1952
  1084
			strncopy(info->target_name, "all players", info->target_name_maxlength);
ds@1952
  1085
			info->target_name_style = COMMAND_TARGETNAME_ML;
ds@1952
  1086
			skip_client = info->admin;
ds@1952
  1087
		}
ds@1952
  1088
ds@1952
  1089
		if (is_multi)
ds@1952
  1090
		{
ds@1952
  1091
			for (int i = 1; i <= max_clients && total < info->max_targets; i++)
ds@1952
  1092
			{
ds@1952
  1093
				if ((pTarget = GetPlayerByIndex(i)) == NULL)
ds@1952
  1094
				{
ds@1952
  1095
					continue;
ds@1952
  1096
				}
ds@1952
  1097
				if (FilterCommandTarget(pAdmin, pTarget, info->flags) > 0)
ds@1952
  1098
				{
ds@1952
  1099
					if ((!bots_only || pTarget->IsFakeClient())
ds@1952
  1100
						&& skip_client != i)
ds@1952
  1101
					{
ds@1952
  1102
						info->targets[total++] = i;
ds@1952
  1103
					}
ds@1952
  1104
				}
ds@1952
  1105
			}
ds@1952
  1106
ds@1952
  1107
			info->num_targets = total;
ds@1952
  1108
			info->reason = (info->num_targets) ? COMMAND_TARGET_VALID : COMMAND_TARGET_EMPTY_FILTER;
ds@1952
  1109
			return;
ds@1952
  1110
		}
ds@1952
  1111
	}
ds@1952
  1112
ds@1952
  1113
	List<ICommandTargetProcessor *>::iterator iter;
ds@1952
  1114
	for (iter = target_processors.begin(); iter != target_processors.end(); iter++)
ds@1952
  1115
	{
ds@1952
  1116
		ICommandTargetProcessor *pProcessor = (*iter);
ds@1952
  1117
		if (pProcessor->ProcessCommandTarget(info))
ds@1952
  1118
		{
ds@1952
  1119
			return;
ds@1952
  1120
		}
ds@1952
  1121
	}
ds@1952
  1122
ds@1952
  1123
	/* Check partial names */
ds@1952
  1124
	int found_client = 0;
ds@1952
  1125
	CPlayer *pFoundClient = NULL;
ds@1952
  1126
	for (int i = 1; i <= max_clients; i++)
ds@1952
  1127
	{
ds@1952
  1128
		if ((pTarget = GetPlayerByIndex(i)) == NULL)
ds@1952
  1129
		{
ds@1952
  1130
			continue;
ds@1952
  1131
		}
ds@1952
  1132
ds@1952
  1133
		if (stristr(pTarget->GetName(), info->pattern) != NULL)
ds@1952
  1134
		{
ds@1952
  1135
			if (found_client)
ds@1952
  1136
			{
ds@1952
  1137
				info->num_targets = 0;
ds@1952
  1138
				info->reason = COMMAND_TARGET_AMBIGUOUS;
ds@1952
  1139
				return;
ds@1952
  1140
			}
ds@1952
  1141
			else
ds@1952
  1142
			{
ds@1952
  1143
				found_client = i;
ds@1952
  1144
				pFoundClient = pTarget;
ds@1952
  1145
			}
ds@1952
  1146
		}
ds@1952
  1147
	}
ds@1952
  1148
ds@1952
  1149
	if (found_client)
ds@1952
  1150
	{
ds@1952
  1151
		if ((info->reason = FilterCommandTarget(pAdmin, pFoundClient, info->flags)) 
ds@1952
  1152
			== COMMAND_TARGET_VALID)
ds@1952
  1153
		{
ds@1952
  1154
			info->targets[0] = found_client;
ds@1952
  1155
			info->num_targets = 1;
ds@1952
  1156
			strncopy(info->target_name, pFoundClient->GetName(), info->target_name_maxlength);
ds@1952
  1157
			info->target_name_style = COMMAND_TARGETNAME_RAW;
ds@1952
  1158
		}
ds@1952
  1159
		else
ds@1952
  1160
		{
ds@1952
  1161
			info->num_targets = 0;
ds@1952
  1162
		}
ds@1952
  1163
	}
ds@1952
  1164
	else
ds@1952
  1165
	{
ds@1952
  1166
		info->num_targets = 0;
ds@1952
  1167
		info->reason = COMMAND_TARGET_NONE;
ds@1952
  1168
	}
ds@1952
  1169
}
ds@1952
  1170
ds@1952
  1171
/*******************
ds@1952
  1172
 *** PLAYER CODE ***
ds@1952
  1173
 *******************/
ds@1952
  1174
ds@1952
  1175
CPlayer::CPlayer()
ds@1952
  1176
{
ds@1952
  1177
	m_IsConnected = false;
ds@1952
  1178
	m_IsInGame = false;
ds@1952
  1179
	m_IsAuthorized = false;
ds@1952
  1180
	m_pEdict = NULL;
ds@1952
  1181
	m_Admin = INVALID_ADMIN_ID;
ds@1952
  1182
	m_TempAdmin = false;
ds@1952
  1183
	m_Info = NULL;
ds@1952
  1184
	m_bAdminCheckSignalled = false;
ds@1952
  1185
	m_bIsInKickQueue = false;
ds@1952
  1186
	m_LastPassword.clear();
ds@1952
  1187
	m_LangId = LANGUAGE_ENGLISH;
ds@1952
  1188
}
ds@1952
  1189
ds@1952
  1190
void CPlayer::Initialize(const char *name, const char *ip, edict_t *pEntity)
ds@1952
  1191
{
ds@1952
  1192
	m_IsConnected = true;
ds@1952
  1193
	m_Name.assign(name);
ds@1952
  1194
	m_Ip.assign(ip);
ds@1952
  1195
	m_pEdict = pEntity;
ds@1952
  1196
	m_iIndex = engine->IndexOfEdict(pEntity);
ds@1952
  1197
	m_LangId = g_Translator.GetServerLanguage();
ds@1952
  1198
ds@1952
  1199
	char ip2[24], *ptr;
ds@1952
  1200
	strncopy(ip2, ip, sizeof(ip2));
ds@1952
  1201
	if ((ptr = strchr(ip2, ':')) != NULL)
ds@1952
  1202
	{
ds@1952
  1203
		*ptr = '\0';
ds@1952
  1204
	}
ds@1952
  1205
	m_IpNoPort.assign(ip2);
ds@1952
  1206
}
ds@1952
  1207
ds@1952
  1208
void CPlayer::Connect()
ds@1952
  1209
{
ds@1952
  1210
	if (m_IsInGame)
ds@1952
  1211
	{
ds@1952
  1212
		return;
ds@1952
  1213
	}
ds@1952
  1214
ds@1952
  1215
	m_IsInGame = true;
ds@1952
  1216
ds@1952
  1217
	const char *var = g_Players.GetPassInfoVar();
ds@1952
  1218
	int client = engine->IndexOfEdict(m_pEdict);
ds@1952
  1219
	if (var[0] != '\0')
ds@1952
  1220
	{
ds@1952
  1221
		const char *pass = engine->GetClientConVarValue(client, var);
ds@1952
  1222
		m_LastPassword.assign(pass ? pass : "");
ds@1952
  1223
	}
ds@1952
  1224
	else
ds@1952
  1225
	{
ds@1952
  1226
		m_LastPassword.assign("");
ds@1952
  1227
	}
ds@1952
  1228
}
ds@1952
  1229
ds@1952
  1230
void CPlayer::Authorize(const char *steamid)
ds@1952
  1231
{
ds@1952
  1232
	if (m_IsAuthorized)
ds@1952
  1233
	{
ds@1952
  1234
		return;
ds@1952
  1235
	}
ds@1952
  1236
ds@1952
  1237
	m_IsAuthorized = true;
ds@1952
  1238
	m_AuthID.assign(steamid);
ds@1952
  1239
}
ds@1952
  1240
ds@1952
  1241
void CPlayer::Disconnect()
ds@1952
  1242
{
ds@1952
  1243
	DumpAdmin(false);
ds@1952
  1244
	m_IsConnected = false;
ds@1952
  1245
	m_IsInGame = false;
ds@1952
  1246
	m_IsAuthorized = false;
ds@1952
  1247
	m_Name.clear();
ds@1952
  1248
	m_Ip.clear();
ds@1952
  1249
	m_AuthID.clear();
ds@1952
  1250
	m_pEdict = NULL;
ds@1952
  1251
	m_Info = NULL;
ds@1952
  1252
	m_bAdminCheckSignalled = false;
ds@1952
  1253
	m_UserId = -1;
ds@1952
  1254
	m_bIsInKickQueue = false;
ds@1952
  1255
}
ds@1952
  1256
ds@1952
  1257
void CPlayer::SetName(const char *name)
ds@1952
  1258
{
ds@1952
  1259
	m_Name.assign(name);
ds@1952
  1260
}
ds@1952
  1261
ds@1952
  1262
const char *CPlayer::GetName()
ds@1952
  1263
{
ds@1952
  1264
	if (m_Info && m_pEdict->GetUnknown())
ds@1952
  1265
	{
ds@1952
  1266
		return m_Info->GetName();
ds@1952
  1267
	}
ds@1952
  1268
	
ds@1952
  1269
	return m_Name.c_str();
ds@1952
  1270
}
ds@1952
  1271
ds@1952
  1272
const char *CPlayer::GetIPAddress()
ds@1952
  1273
{
ds@1952
  1274
	return m_Ip.c_str();
ds@1952
  1275
}
ds@1952
  1276
ds@1952
  1277
const char *CPlayer::GetAuthString()
ds@1952
  1278
{
ds@1952
  1279
	return m_AuthID.c_str();
ds@1952
  1280
}
ds@1952
  1281
ds@1952
  1282
edict_t *CPlayer::GetEdict()
ds@1952
  1283
{
ds@1952
  1284
	return m_pEdict;
ds@1952
  1285
}
ds@1952
  1286
ds@1952
  1287
bool CPlayer::IsInGame()
ds@1952
  1288
{
ds@1952
  1289
	return m_IsInGame && (m_pEdict->GetUnknown() != NULL);
ds@1952
  1290
}
ds@1952
  1291
ds@1952
  1292
bool CPlayer::WasCountedAsInGame()
ds@1952
  1293
{
ds@1952
  1294
	return m_IsInGame;
ds@1952
  1295
}
ds@1952
  1296
ds@1952
  1297
bool CPlayer::IsConnected()
ds@1952
  1298
{
ds@1952
  1299
	return m_IsConnected;
ds@1952
  1300
}
ds@1952
  1301
ds@1952
  1302
bool CPlayer::IsAuthorized()
ds@1952
  1303
{
ds@1952
  1304
	return m_IsAuthorized;
ds@1952
  1305
}
ds@1952
  1306
ds@1952
  1307
IPlayerInfo *CPlayer::GetPlayerInfo()
ds@1952
  1308
{
ds@1952
  1309
	if (m_pEdict->GetUnknown())
ds@1952
  1310
	{
ds@1952
  1311
		return m_Info;
ds@1952
  1312
	}
ds@1952
  1313
ds@1952
  1314
	return NULL;
ds@1952
  1315
}
ds@1952
  1316
ds@1952
  1317
bool CPlayer::IsFakeClient()
ds@1952
  1318
{
ds@1952
  1319
	return (strcmp(m_AuthID.c_str(), "BOT") == 0);
ds@1952
  1320
}
ds@1952
  1321
ds@1952
  1322
void CPlayer::SetAdminId(AdminId id, bool temporary)
ds@1952
  1323
{
ds@1952
  1324
	if (!m_IsConnected)
ds@1952
  1325
	{
ds@1952
  1326
		return;
ds@1952
  1327
	}
ds@1952
  1328
ds@1952
  1329
	DumpAdmin(false);
ds@1952
  1330
ds@1952
  1331
	m_Admin = id;
ds@1952
  1332
	m_TempAdmin = temporary;
ds@1952
  1333
}
ds@1952
  1334
ds@1952
  1335
AdminId CPlayer::GetAdminId()
ds@1952
  1336
{
ds@1952
  1337
	return m_Admin;
ds@1952
  1338
}
ds@1952
  1339
ds@1952
  1340
void CPlayer::DumpAdmin(bool deleting)
ds@1952
  1341
{
ds@1952
  1342
	if (m_Admin != INVALID_ADMIN_ID)
ds@1952
  1343
	{
ds@1952
  1344
		if (m_TempAdmin && !deleting)
ds@1952
  1345
		{
ds@1952
  1346
			g_Admins.InvalidateAdmin(m_Admin);
ds@1952
  1347
		}
ds@1952
  1348
		m_Admin = INVALID_ADMIN_ID;
ds@1952
  1349
		m_TempAdmin = false;
ds@1952
  1350
	}
ds@1952
  1351
}
ds@1952
  1352
ds@1952
  1353
void CPlayer::Kick(const char *str)
ds@1952
  1354
{
ds@1952
  1355
	MarkAsBeingKicked();
ds@1952
  1356
	INetChannel *pNetChan = static_cast<INetChannel *>(engine->GetPlayerNetInfo(m_iIndex));
ds@1952
  1357
	IClient *pClient = static_cast<IClient *>(pNetChan->GetMsgHandler());
ds@1952
  1358
	pClient->Disconnect("%s", str);
ds@1952
  1359
}
ds@1952
  1360
ds@1952
  1361
void CPlayer::Authorize_Post()
ds@1952
  1362
{
ds@1952
  1363
	if (m_IsInGame)
ds@1952
  1364
	{
ds@1952
  1365
		DoPostConnectAuthorization();
ds@1952
  1366
	}
ds@1952
  1367
}
ds@1952
  1368
ds@1952
  1369
void CPlayer::DoPostConnectAuthorization()
ds@1952
  1370
{
ds@1952
  1371
	bool delay = false;
ds@1952
  1372
ds@1952
  1373
	List<IClientListener *>::iterator iter;
ds@1952
  1374
	for (iter = g_Players.m_hooks.begin();
ds@1952
  1375
		 iter != g_Players.m_hooks.end();
ds@1952
  1376
		 iter++)
ds@1952
  1377
	{
ds@1952
  1378
		IClientListener *pListener = (*iter);
ds@1952
  1379
#if defined MIN_API_FOR_ADMINCALLS
ds@1952
  1380
		if (pListener->GetClientListenerVersion() < MIN_API_FOR_ADMINCALLS)
ds@1952
  1381
		{
ds@1952
  1382
			continue;
ds@1952
  1383
		}
ds@1952
  1384
#endif
ds@1952
  1385
		if (!pListener->OnClientPreAdminCheck(m_iIndex))
ds@1952
  1386
		{
ds@1952
  1387
			delay = true;
ds@1952
  1388
		}
ds@1952
  1389
	}
ds@1952
  1390
	
ds@1952
  1391
	cell_t result = 0;
ds@1952
  1392
	PreAdminCheck->PushCell(m_iIndex);
ds@1952
  1393
	PreAdminCheck->Execute(&result);
ds@1952
  1394
ds@1952
  1395
	/* Defer, for better or worse */
ds@1952
  1396
	if (delay || (ResultType)result >= Pl_Handled)
ds@1952
  1397
	{
ds@1952
  1398
		return;
ds@1952
  1399
	}
ds@1952
  1400
ds@1952
  1401
	/* Sanity check */
ds@1952
  1402
	if (!IsConnected())
ds@1952
  1403
	{
ds@1952
  1404
		return;
ds@1952
  1405
	}
ds@1952
  1406
ds@1952
  1407
	/* Otherwise, go ahead and do admin checks */
ds@1952
  1408
	DoBasicAdminChecks();
ds@1952
  1409
ds@1952
  1410
	/* Send the notification out */
ds@1952
  1411
	NotifyPostAdminChecks();
ds@1952
  1412
}
ds@1952
  1413
ds@1952
  1414
bool CPlayer::RunAdminCacheChecks()
ds@1952
  1415
{
ds@1952
  1416
	AdminId old_id = GetAdminId();
ds@1952
  1417
ds@1952
  1418
	DoBasicAdminChecks();
ds@1952
  1419
ds@1952
  1420
	return (GetAdminId() != old_id);
ds@1952
  1421
}
ds@1952
  1422
ds@1952
  1423
void CPlayer::NotifyPostAdminChecks()
ds@1952
  1424
{
ds@1952
  1425
	if (m_bAdminCheckSignalled)
ds@1952
  1426
	{
ds@1952
  1427
		return;
ds@1952
  1428
	}
ds@1952
  1429
ds@1952
  1430
	/* Block beforehand so they can't double-call */
ds@1952
  1431
	m_bAdminCheckSignalled = true;
ds@1952
  1432
ds@1952
  1433
	List<IClientListener *>::iterator iter;
ds@1952
  1434
	for (iter = g_Players.m_hooks.begin();
ds@1952
  1435
		iter != g_Players.m_hooks.end();
ds@1952
  1436
		iter++)
ds@1952
  1437
	{
ds@1952
  1438
		IClientListener *pListener = (*iter);
ds@1952
  1439
#if defined MIN_API_FOR_ADMINCALLS
ds@1952
  1440
		if (pListener->GetClientListenerVersion() < MIN_API_FOR_ADMINCALLS)
ds@1952
  1441
		{
ds@1952
  1442
			continue;
ds@1952
  1443
		}
ds@1952
  1444
#endif
ds@1952
  1445
		pListener->OnClientPostAdminCheck(m_iIndex);
ds@1952
  1446
	}
ds@1952
  1447
ds@1952
  1448
	PostAdminFilter->PushCell(m_iIndex);
ds@1952
  1449
	PostAdminFilter->Execute(NULL);
ds@1952
  1450
ds@1952
  1451
	PostAdminCheck->PushCell(m_iIndex);
ds@1952
  1452
	PostAdminCheck->Execute(NULL);
ds@1952
  1453
}
ds@1952
  1454
ds@1952
  1455
void CPlayer::DoBasicAdminChecks()
ds@1952
  1456
{
ds@1952
  1457
	if (GetAdminId() != INVALID_ADMIN_ID)
ds@1952
  1458
	{
ds@1952
  1459
		return;
ds@1952
  1460
	}
ds@1952
  1461
ds@1952
  1462
	/* First check the name */
ds@1952
  1463
	AdminId id;
ds@1952
  1464
	int client = engine->IndexOfEdict(m_pEdict);
ds@1952
  1465
ds@1952
  1466
	if ((id = g_Admins.FindAdminByIdentity("name", GetName())) != INVALID_ADMIN_ID)
ds@1952
  1467
	{
ds@1952
  1468
		if (!g_Players.CheckSetAdminName(client, this, id))
ds@1952
  1469
		{
ds@1952
  1470
			int userid = engine->GetPlayerUserId(m_pEdict);
ds@1952
  1471
			g_Timers.CreateTimer(&s_KickPlayerTimer, 0.1f, (void *)userid, 0);
ds@1952
  1472
		}
ds@1952
  1473
		return;
ds@1952
  1474
	}
ds@1952
  1475
	
ds@1952
  1476
	/* Check IP */
ds@1952
  1477
	if ((id = g_Admins.FindAdminByIdentity("ip", m_IpNoPort.c_str())) != INVALID_ADMIN_ID)
ds@1952
  1478
	{
ds@1952
  1479
		if (g_Players.CheckSetAdmin(client, this, id))
ds@1952
  1480
		{
ds@1952
  1481
			return;
ds@1952
  1482
		}
ds@1952
  1483
	}
ds@1952
  1484
ds@1952
  1485
	/* Check IP address */
ds@1952
  1486
	if ((id = g_Admins.FindAdminByIdentity("steam", m_AuthID.c_str())) != INVALID_ADMIN_ID)
ds@1952
  1487
	{
ds@1952
  1488
		if (g_Players.CheckSetAdmin(client, this, id))
ds@1952
  1489
		{
ds@1952
  1490
			return;
ds@1952
  1491
		}
ds@1952
  1492
	}
ds@1952
  1493
}
ds@1952
  1494
ds@1952
  1495
unsigned int CPlayer::GetLanguageId()
ds@1952
  1496
{
ds@1952
  1497
	return m_LangId;
ds@1952
  1498
}
ds@1952
  1499
ds@1952
  1500
int CPlayer::GetUserId()
ds@1952
  1501
{
ds@1952
  1502
	if (m_UserId == -1)
ds@1952
  1503
	{
ds@1952
  1504
		m_UserId = engine->GetPlayerUserId(GetEdict());
ds@1952
  1505
	}
ds@1952
  1506
ds@1952
  1507
	return m_UserId;
ds@1952
  1508
}
ds@1952
  1509
ds@1952
  1510
bool CPlayer::IsInKickQueue()
ds@1952
  1511
{
ds@1952
  1512
	return m_bIsInKickQueue;
ds@1952
  1513
}
ds@1952
  1514
ds@1952
  1515
void CPlayer::MarkAsBeingKicked()
ds@1952
  1516
{
ds@1952
  1517
	m_bIsInKickQueue = true;
ds@1952
  1518
}
ds@1952
  1519
ds@1952
  1520
int CPlayer::GetLifeState()
ds@1952
  1521
{
ds@1952
  1522
	if (lifestate_offset == -1)
ds@1952
  1523
	{
ds@1952
  1524
		if (!g_pGameConf->GetOffset("m_lifeState", &lifestate_offset))
ds@1952
  1525
		{
ds@1952
  1526
			lifestate_offset = -2;
ds@1952
  1527
		}
ds@1952
  1528
	}
ds@1952
  1529
ds@1952
  1530
	if (lifestate_offset < 0)
ds@1952
  1531
	{
ds@1952
  1532
		IPlayerInfo *info = GetPlayerInfo();
ds@1952
  1533
		if (info == NULL)
ds@1952
  1534
		{
ds@1952
  1535
			return PLAYER_LIFE_UNKNOWN;
ds@1952
  1536
		}
ds@1952
  1537
		return info->IsDead() ? PLAYER_LIFE_DEAD : PLAYER_LIFE_ALIVE;
ds@1952
  1538
	}
ds@1952
  1539
ds@1952
  1540
	if (m_pEdict == NULL)
ds@1952
  1541
	{
ds@1952
  1542
		return PLAYER_LIFE_UNKNOWN;
ds@1952
  1543
	}
ds@1952
  1544
ds@1952
  1545
	CBaseEntity *pEntity;
ds@1952
  1546
	IServerUnknown *pUnknown = m_pEdict->GetUnknown();
ds@1952
  1547
	if (pUnknown == NULL || (pEntity = pUnknown->GetBaseEntity()) == NULL)
ds@1952
  1548
	{
ds@1952
  1549
		return PLAYER_LIFE_UNKNOWN;
ds@1952
  1550
	}
ds@1952
  1551
ds@1952
  1552
	if (*((uint8_t *)pEntity + lifestate_offset) == LIFE_ALIVE)
ds@1952
  1553
	{
ds@1952
  1554
		return PLAYER_LIFE_ALIVE;
ds@1952
  1555
	}
ds@1952
  1556
	else
ds@1952
  1557
	{
ds@1952
  1558
		return PLAYER_LIFE_DEAD;
ds@1952
  1559
	}
ds@1952
  1560
}