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