2008-03-30 09:00:22 +02:00
/**
2009-09-27 08:17:23 +02:00
* vim : set ts = 4 sw = 4 tw = 99 noet :
2008-03-30 09:00:22 +02:00
* = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
* SourceMod
2009-09-27 08:17:23 +02:00
* Copyright ( C ) 2004 - 2009 AlliedModders LLC . All rights reserved .
2008-03-30 09:00:22 +02:00
* = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
*
* This program is free software ; you can redistribute it and / or modify it under
* the terms of the GNU General Public License , version 3.0 , as published by the
* Free Software Foundation .
*
* This program is distributed in the hope that it will be useful , but WITHOUT
* ANY WARRANTY ; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE . See the GNU General Public License for more
* details .
*
* You should have received a copy of the GNU General Public License along with
* this program . If not , see < http : //www.gnu.org/licenses/>.
*
* As a special exception , AlliedModders LLC gives you permission to link the
* code of this program ( as well as its derivative works ) to " Half-Life 2, " the
* " Source Engine, " the " SourcePawn JIT, " and any Game MODs that run on software
* by the Valve Corporation . You must obey the GNU General Public License in
* all respects for all other code used . Additionally , AlliedModders LLC grants
* this exception to all derivative works . AlliedModders LLC defines further
* exceptions , found in LICENSE . txt ( as of this writing , version JULY - 31 - 2007 ) ,
* or < http : //www.sourcemod.net/license.php>.
*
* Version : $ Id $
*/
# include "PlayerManager.h"
2014-05-29 19:31:12 +02:00
# include "IAdminSystem.h"
2008-03-30 09:00:22 +02:00
# include "ConCmdManager.h"
# include "MenuStyle_Valve.h"
# include "MenuStyle_Radio.h"
# include "sm_stringutil.h"
# include "CoreConfig.h"
# include "TimerSys.h"
# include "Logger.h"
# include "ChatTriggers.h"
# include "HalfLife2.h"
# include <inetchannel.h>
# include <iclient.h>
2010-05-15 08:35:42 +02:00
# include <IGameConfigs.h>
2009-09-26 23:12:23 +02:00
# include "ConsoleDetours.h"
2010-05-15 04:28:10 +02:00
# include "logic_bridge.h"
2013-12-30 23:51:00 +01:00
# include <sourcemod_version.h>
2008-03-30 09:00:22 +02:00
PlayerManager g_Players ;
bool g_OnMapStarted = false ;
IForward * PreAdminCheck = NULL ;
IForward * PostAdminCheck = NULL ;
IForward * PostAdminFilter = NULL ;
2011-01-01 02:02:41 +01:00
2008-03-30 09:00:22 +02:00
const unsigned int * g_NumPlayersToAuth = NULL ;
int lifestate_offset = - 1 ;
List < ICommandTargetProcessor * > target_processors ;
2013-05-13 21:18:12 +02:00
# if SOURCE_ENGINE == SE_DOTA
2013-07-12 08:31:41 +02:00
SH_DECL_HOOK5 ( IServerGameClients , ClientConnect , SH_NOATTRIB , 0 , bool , CEntityIndex , const char * , const char * , char * , int ) ;
SH_DECL_HOOK2_void ( IServerGameClients , ClientPutInServer , SH_NOATTRIB , 0 , CEntityIndex , const char * ) ;
2014-04-06 23:03:29 +02:00
SH_DECL_HOOK2_void ( IServerGameClients , ClientDisconnect , SH_NOATTRIB , 0 , CEntityIndex , int ) ;
2013-07-12 08:31:41 +02:00
SH_DECL_HOOK2_void ( IServerGameClients , ClientCommand , SH_NOATTRIB , 0 , CEntityIndex , const CCommand & ) ;
SH_DECL_HOOK1_void ( IServerGameClients , ClientSettingsChanged , SH_NOATTRIB , 0 , CEntityIndex ) ;
2013-05-13 21:18:12 +02:00
# else
2008-03-30 09:00:22 +02:00
SH_DECL_HOOK5 ( IServerGameClients , ClientConnect , SH_NOATTRIB , 0 , bool , edict_t * , const char * , const char * , char * , int ) ;
SH_DECL_HOOK2_void ( IServerGameClients , ClientPutInServer , SH_NOATTRIB , 0 , edict_t * , const char * ) ;
SH_DECL_HOOK1_void ( IServerGameClients , ClientDisconnect , SH_NOATTRIB , 0 , edict_t * ) ;
2008-11-14 16:18:30 +01:00
# if SOURCE_ENGINE >= SE_ORANGEBOX
2008-03-30 09:00:22 +02:00
SH_DECL_HOOK2_void ( IServerGameClients , ClientCommand , SH_NOATTRIB , 0 , edict_t * , const CCommand & ) ;
# else
SH_DECL_HOOK1_void ( IServerGameClients , ClientCommand , SH_NOATTRIB , 0 , edict_t * ) ;
# endif
SH_DECL_HOOK1_void ( IServerGameClients , ClientSettingsChanged , SH_NOATTRIB , 0 , edict_t * ) ;
2013-05-13 21:18:12 +02:00
# endif // SE_DOTA
2013-05-08 15:21:40 +02:00
# if SOURCE_ENGINE == SE_DOTA
SH_DECL_HOOK0_void ( IServerGameDLL , ServerActivate , SH_NOATTRIB , 0 ) ;
# else
2008-03-30 09:00:22 +02:00
SH_DECL_HOOK3_void ( IServerGameDLL , ServerActivate , SH_NOATTRIB , 0 , edict_t * , int , int ) ;
2013-05-08 15:21:40 +02:00
# endif
2008-03-30 09:00:22 +02:00
2014-05-31 20:33:30 +02:00
# if SOURCE_ENGINE >= SE_LEFT4DEAD && SOURCE_ENGINE != SE_DOTA
SH_DECL_HOOK1_void ( IServerGameDLL , ServerHibernationUpdate , SH_NOATTRIB , 0 , bool ) ;
# elif SOURCE_ENGINE > SE_EYE // 2013/orangebox, but not original orangebox. +dota
SH_DECL_HOOK1_void ( IServerGameDLL , SetServerHibernation , SH_NOATTRIB , 0 , bool ) ;
# endif
2013-04-23 13:11:49 +02:00
# if SOURCE_ENGINE == SE_DOTA
2013-07-12 08:31:41 +02:00
SH_DECL_EXTERN2_void ( ConCommand , Dispatch , SH_NOATTRIB , false , const CCommandContext & , const CCommand & ) ;
2013-04-23 13:11:49 +02:00
# elif SOURCE_ENGINE >= SE_ORANGEBOX
2008-09-26 09:08:49 +02:00
SH_DECL_EXTERN1_void ( ConCommand , Dispatch , SH_NOATTRIB , false , const CCommand & ) ;
2009-02-18 09:19:22 +01:00
# elif SOURCE_ENGINE == SE_DARKMESSIAH
SH_DECL_EXTERN0_void ( ConCommand , Dispatch , SH_NOATTRIB , false ) ;
2008-09-26 09:08:49 +02:00
# else
2009-10-29 07:30:52 +01:00
# if SH_IMPL_VERSION >= 4
extern int __SourceHook_FHAddConCommandDispatch ( void * , bool , class fastdelegate : : FastDelegate0 < void > ) ;
# else
extern bool __SourceHook_FHAddConCommandDispatch ( void * , bool , class fastdelegate : : FastDelegate0 < void > ) ;
# endif
2008-09-26 09:08:49 +02:00
extern bool __SourceHook_FHRemoveConCommandDispatch ( void * , bool , class fastdelegate : : FastDelegate0 < void > ) ;
# endif
ConCommand * maxplayersCmd = NULL ;
2009-02-19 07:19:44 +01:00
unsigned int g_PlayerSerialCount = 0 ;
2008-03-30 09:00:22 +02:00
class KickPlayerTimer : public ITimedEvent
{
public :
ResultType OnTimer ( ITimer * pTimer , void * pData )
{
int userid = ( int ) pData ;
int client = g_Players . GetClientOfUserId ( userid ) ;
if ( client )
{
CPlayer * player = g_Players . GetPlayerByIndex ( client ) ;
player - > Kick ( " Your name is reserved by SourceMod; set your password to use it. " ) ;
}
return Pl_Stop ;
}
void OnTimerEnd ( ITimer * pTimer , void * pData )
{
}
} s_KickPlayerTimer ;
PlayerManager : : PlayerManager ( )
{
m_AuthQueue = NULL ;
m_FirstPass = false ;
2011-07-08 13:55:20 +02:00
m_maxClients = 0 ;
2008-03-30 09:00:22 +02:00
2011-10-21 03:39:57 +02:00
m_SourceTVUserId = - 1 ;
m_ReplayUserId = - 1 ;
2013-03-07 01:58:17 +01:00
m_bAuthstringValidation = true ; // use steam auth by default
2012-05-24 18:55:46 +02:00
2008-03-30 09:00:22 +02:00
m_UserIdLookUp = new int [ USHRT_MAX + 1 ] ;
memset ( m_UserIdLookUp , 0 , sizeof ( int ) * ( USHRT_MAX + 1 ) ) ;
}
PlayerManager : : ~ PlayerManager ( )
{
g_NumPlayersToAuth = NULL ;
delete [ ] m_AuthQueue ;
delete [ ] m_UserIdLookUp ;
}
void PlayerManager : : OnSourceModAllInitialized ( )
{
2013-03-17 03:15:25 +01:00
SH_ADD_HOOK ( IServerGameClients , ClientConnect , serverClients , SH_MEMBER ( this , & PlayerManager : : OnClientConnect ) , false ) ;
SH_ADD_HOOK ( IServerGameClients , ClientConnect , serverClients , SH_MEMBER ( this , & PlayerManager : : OnClientConnect_Post ) , true ) ;
SH_ADD_HOOK ( IServerGameClients , ClientPutInServer , serverClients , SH_MEMBER ( this , & PlayerManager : : OnClientPutInServer ) , true ) ;
SH_ADD_HOOK ( IServerGameClients , ClientDisconnect , serverClients , SH_MEMBER ( this , & PlayerManager : : OnClientDisconnect ) , false ) ;
SH_ADD_HOOK ( IServerGameClients , ClientDisconnect , serverClients , SH_MEMBER ( this , & PlayerManager : : OnClientDisconnect_Post ) , true ) ;
SH_ADD_HOOK ( IServerGameClients , ClientCommand , serverClients , SH_MEMBER ( this , & PlayerManager : : OnClientCommand ) , false ) ;
SH_ADD_HOOK ( IServerGameClients , ClientSettingsChanged , serverClients , SH_MEMBER ( this , & PlayerManager : : OnClientSettingsChanged ) , true ) ;
SH_ADD_HOOK ( IServerGameDLL , ServerActivate , gamedll , SH_MEMBER ( this , & PlayerManager : : OnServerActivate ) , true ) ;
2014-05-31 20:33:30 +02:00
# if SOURCE_ENGINE >= SE_LEFT4DEAD && SOURCE_ENGINE != SE_DOTA
SH_ADD_HOOK ( IServerGameDLL , ServerHibernationUpdate , gamedll , SH_MEMBER ( this , & PlayerManager : : OnServerHibernationUpdate ) , true ) ;
# elif SOURCE_ENGINE > SE_EYE // 2013/orangebox, but not original orangebox. +dota
SH_ADD_HOOK ( IServerGameDLL , SetServerHibernation , gamedll , SH_MEMBER ( this , & PlayerManager : : OnServerHibernationUpdate ) , true ) ;
# endif
2008-03-30 09:00:22 +02:00
2013-03-29 19:37:29 +01:00
sharesys - > AddInterface ( NULL , this ) ;
2008-03-30 09:00:22 +02:00
ParamType p1 [ ] = { Param_Cell , Param_String , Param_Cell } ;
ParamType p2 [ ] = { Param_Cell } ;
2013-10-09 14:43:08 +02:00
m_clconnect = forwardsys - > CreateForward ( " OnClientConnect " , ET_LowEvent , 3 , p1 ) ;
m_clconnect_post = forwardsys - > CreateForward ( " OnClientConnected " , ET_Ignore , 1 , p2 ) ;
m_clputinserver = forwardsys - > CreateForward ( " OnClientPutInServer " , ET_Ignore , 1 , p2 ) ;
m_cldisconnect = forwardsys - > CreateForward ( " OnClientDisconnect " , ET_Ignore , 1 , p2 ) ;
m_cldisconnect_post = forwardsys - > CreateForward ( " OnClientDisconnect_Post " , ET_Ignore , 1 , p2 ) ;
m_clcommand = forwardsys - > CreateForward ( " OnClientCommand " , ET_Hook , 2 , NULL , Param_Cell , Param_Cell ) ;
m_clinfochanged = forwardsys - > CreateForward ( " OnClientSettingsChanged " , ET_Ignore , 1 , p2 ) ;
m_clauth = forwardsys - > CreateForward ( " OnClientAuthorized " , ET_Ignore , 2 , NULL , Param_Cell , Param_String ) ;
m_onActivate = forwardsys - > CreateForward ( " OnServerLoad " , ET_Ignore , 0 , NULL ) ;
m_onActivate2 = forwardsys - > CreateForward ( " OnMapStart " , ET_Ignore , 0 , NULL ) ;
PreAdminCheck = forwardsys - > CreateForward ( " OnClientPreAdminCheck " , ET_Event , 1 , p1 ) ;
PostAdminCheck = forwardsys - > CreateForward ( " OnClientPostAdminCheck " , ET_Ignore , 1 , p1 ) ;
PostAdminFilter = forwardsys - > CreateForward ( " OnClientPostAdminFilter " , ET_Ignore , 1 , p1 ) ;
2008-04-12 04:18:03 +02:00
m_bIsListenServer = ! engine - > IsDedicatedServer ( ) ;
m_ListenClient = 0 ;
2008-09-26 09:08:49 +02:00
2008-11-14 16:18:30 +01:00
ConCommand * pCmd = FindCommand ( " maxplayers " ) ;
2008-09-26 09:08:49 +02:00
if ( pCmd ! = NULL )
{
2013-03-17 03:15:25 +01:00
SH_ADD_HOOK ( ConCommand , Dispatch , pCmd , SH_STATIC ( CmdMaxplayersCallback ) , true ) ;
2008-09-26 09:08:49 +02:00
maxplayersCmd = pCmd ;
}
2008-03-30 09:00:22 +02:00
}
void PlayerManager : : OnSourceModShutdown ( )
{
2013-03-17 03:15:25 +01:00
SH_REMOVE_HOOK ( IServerGameClients , ClientConnect , serverClients , SH_MEMBER ( this , & PlayerManager : : OnClientConnect ) , false ) ;
SH_REMOVE_HOOK ( IServerGameClients , ClientConnect , serverClients , SH_MEMBER ( this , & PlayerManager : : OnClientConnect_Post ) , true ) ;
SH_REMOVE_HOOK ( IServerGameClients , ClientPutInServer , serverClients , SH_MEMBER ( this , & PlayerManager : : OnClientPutInServer ) , true ) ;
SH_REMOVE_HOOK ( IServerGameClients , ClientDisconnect , serverClients , SH_MEMBER ( this , & PlayerManager : : OnClientDisconnect ) , false ) ;
SH_REMOVE_HOOK ( IServerGameClients , ClientDisconnect , serverClients , SH_MEMBER ( this , & PlayerManager : : OnClientDisconnect_Post ) , true ) ;
SH_REMOVE_HOOK ( IServerGameClients , ClientCommand , serverClients , SH_MEMBER ( this , & PlayerManager : : OnClientCommand ) , false ) ;
SH_REMOVE_HOOK ( IServerGameClients , ClientSettingsChanged , serverClients , SH_MEMBER ( this , & PlayerManager : : OnClientSettingsChanged ) , true ) ;
SH_REMOVE_HOOK ( IServerGameDLL , ServerActivate , gamedll , SH_MEMBER ( this , & PlayerManager : : OnServerActivate ) , true ) ;
2014-05-31 20:33:30 +02:00
# if SOURCE_ENGINE >= SE_LEFT4DEAD && SOURCE_ENGINE != SE_DOTA
SH_REMOVE_HOOK ( IServerGameDLL , ServerHibernationUpdate , gamedll , SH_MEMBER ( this , & PlayerManager : : OnServerHibernationUpdate ) , true ) ;
# elif SOURCE_ENGINE > SE_EYE // 2013/orangebox, but not original orangebox. +dota
SH_REMOVE_HOOK ( IServerGameDLL , SetServerHibernation , gamedll , SH_MEMBER ( this , & PlayerManager : : OnServerHibernationUpdate ) , true ) ;
# endif
2008-03-30 09:00:22 +02:00
/* Release forwards */
2013-10-09 14:43:08 +02:00
forwardsys - > ReleaseForward ( m_clconnect ) ;
forwardsys - > ReleaseForward ( m_clconnect_post ) ;
forwardsys - > ReleaseForward ( m_clputinserver ) ;
forwardsys - > ReleaseForward ( m_cldisconnect ) ;
forwardsys - > ReleaseForward ( m_cldisconnect_post ) ;
forwardsys - > ReleaseForward ( m_clcommand ) ;
forwardsys - > ReleaseForward ( m_clinfochanged ) ;
forwardsys - > ReleaseForward ( m_clauth ) ;
forwardsys - > ReleaseForward ( m_onActivate ) ;
forwardsys - > ReleaseForward ( m_onActivate2 ) ;
forwardsys - > ReleaseForward ( PreAdminCheck ) ;
forwardsys - > ReleaseForward ( PostAdminCheck ) ;
forwardsys - > ReleaseForward ( PostAdminFilter ) ;
2008-03-30 09:00:22 +02:00
delete [ ] m_Players ;
2008-09-26 09:08:49 +02:00
if ( maxplayersCmd ! = NULL )
{
2013-03-17 03:15:25 +01:00
SH_REMOVE_HOOK ( ConCommand , Dispatch , maxplayersCmd , SH_STATIC ( CmdMaxplayersCallback ) , true ) ;
2008-09-26 09:08:49 +02:00
}
2008-03-30 09:00:22 +02:00
}
ConfigResult PlayerManager : : OnSourceModConfigChanged ( const char * key ,
const char * value ,
ConfigSource source ,
char * error ,
size_t maxlength )
{
if ( strcmp ( key , " PassInfoVar " ) = = 0 )
{
if ( strcmp ( value , " _password " ) ! = 0 )
{
m_PassInfoVar . assign ( value ) ;
}
return ConfigResult_Accept ;
} else if ( strcmp ( key , " AllowClLanguageVar " ) = = 0 ) {
if ( strcasecmp ( value , " on " ) = = 0 )
{
m_QueryLang = true ;
} else if ( strcasecmp ( value , " off " ) = = 0 ) {
m_QueryLang = false ;
} else {
UTIL_Format ( error , maxlength , " Invalid value: must be \" on \" or \" off \" " ) ;
return ConfigResult_Reject ;
}
return ConfigResult_Accept ;
2012-05-24 18:55:46 +02:00
} else if ( strcmp ( key , " SteamAuthstringValidation " ) = = 0 ) {
if ( strcasecmp ( value , " yes " ) = = 0 )
{
2013-03-07 01:58:17 +01:00
m_bAuthstringValidation = true ;
2012-05-24 18:55:46 +02:00
} else if ( strcasecmp ( value , " no " ) = = 0 ) {
2013-03-07 01:58:17 +01:00
m_bAuthstringValidation = false ;
2012-05-24 18:55:46 +02:00
} else {
UTIL_Format ( error , maxlength , " Invalid value: must be \" yes \" or \" no \" " ) ;
return ConfigResult_Reject ;
}
return ConfigResult_Accept ;
2008-03-30 09:00:22 +02:00
}
return ConfigResult_Ignore ;
}
2013-05-08 15:21:40 +02:00
# if SOURCE_ENGINE == SE_DOTA
void PlayerManager : : OnServerActivate ( )
# else
2008-03-30 09:00:22 +02:00
void PlayerManager : : OnServerActivate ( edict_t * pEdictList , int edictCount , int clientMax )
2013-05-08 15:21:40 +02:00
# endif
2008-03-30 09:00:22 +02:00
{
2011-10-21 03:39:57 +02:00
static ConVar * tv_enable = icvar - > FindVar ( " tv_enable " ) ;
2013-07-21 17:53:56 +02:00
# if SOURCE_ENGINE == SE_TF2
2011-10-21 03:39:57 +02:00
static ConVar * replay_enable = icvar - > FindVar ( " replay_enable " ) ;
# endif
2011-07-13 02:06:08 +02:00
// clientMax will not necessarily be correct here (such as on late SourceTV enable)
m_maxClients = gpGlobals - > maxClients ;
2011-10-21 03:39:57 +02:00
2012-02-25 21:09:56 +01:00
ICommandLine * commandLine = g_HL2 . GetValveCommandLine ( ) ;
m_bIsSourceTVActive = ( tv_enable & & tv_enable - > GetBool ( ) & & ( ! commandLine | | commandLine - > FindParm ( " -nohltv " ) = = 0 ) ) ;
2011-10-21 03:39:57 +02:00
m_bIsReplayActive = false ;
2013-07-21 17:53:56 +02:00
# if SOURCE_ENGINE == SE_TF2
2011-10-21 03:39:57 +02:00
m_bIsReplayActive = ( replay_enable & & replay_enable - > GetBool ( ) ) ;
# endif
m_PlayersSinceActive = 0 ;
2011-07-13 02:06:08 +02:00
2008-03-30 09:00:22 +02:00
if ( ! m_FirstPass )
{
/* Initialize all players */
2011-05-25 14:31:12 +02:00
2008-03-30 09:00:22 +02:00
m_PlayerCount = 0 ;
2014-05-07 03:40:35 +02:00
m_Players = new CPlayer [ SM_MAXPLAYERS + 1 ] ;
m_AuthQueue = new unsigned int [ SM_MAXPLAYERS + 1 ] ;
2008-03-30 09:00:22 +02:00
m_FirstPass = true ;
2014-05-07 03:40:35 +02:00
memset ( m_AuthQueue , 0 , sizeof ( unsigned int ) * ( SM_MAXPLAYERS + 1 ) ) ;
2008-03-30 09:00:22 +02:00
g_NumPlayersToAuth = & m_AuthQueue [ 0 ] ;
}
2011-10-14 15:25:42 +02:00
2013-03-29 19:37:29 +01:00
scripts - > SyncMaxClients ( m_maxClients ) ;
2011-11-04 15:01:28 +01:00
2011-10-14 15:25:42 +02:00
g_OnMapStarted = true ;
2013-05-08 15:21:40 +02:00
# if SOURCE_ENGINE == SE_DOTA
extsys - > CallOnCoreMapStart ( gpGlobals - > pEdicts , gpGlobals - > maxEntities , gpGlobals - > maxClients ) ;
# else
2013-03-29 19:37:29 +01:00
extsys - > CallOnCoreMapStart ( pEdictList , edictCount , m_maxClients ) ;
2013-05-08 15:21:40 +02:00
# endif
2008-03-30 09:00:22 +02:00
m_onActivate - > Execute ( NULL ) ;
m_onActivate2 - > Execute ( NULL ) ;
List < IClientListener * > : : iterator iter ;
for ( iter = m_hooks . begin ( ) ; iter ! = m_hooks . end ( ) ; iter + + )
{
if ( ( * iter ) - > GetClientListenerVersion ( ) > = 5 )
{
2011-07-13 02:06:08 +02:00
( * iter ) - > OnServerActivated ( m_maxClients ) ;
2008-03-30 09:00:22 +02:00
}
}
2008-12-28 07:02:05 +01:00
SMGlobalClass * cls = SMGlobalClass : : head ;
while ( cls )
{
cls - > OnSourceModLevelActivated ( ) ;
cls = cls - > m_pGlobalClassNext ;
}
2008-03-30 09:00:22 +02:00
SM_ExecuteAllConfigs ( ) ;
}
2011-07-08 13:53:14 +02:00
bool PlayerManager : : IsServerActivated ( )
2008-03-30 09:00:22 +02:00
{
return m_FirstPass ;
}
bool PlayerManager : : CheckSetAdmin ( int index , CPlayer * pPlayer , AdminId id )
{
2014-05-29 19:31:12 +02:00
const char * password = adminsys - > GetAdminPassword ( id ) ;
2008-03-30 09:00:22 +02:00
if ( password ! = NULL )
{
if ( m_PassInfoVar . size ( ) < 1 )
{
return false ;
}
/* Whoa... the user needs a password! */
const char * given = engine - > GetClientConVarValue ( index , m_PassInfoVar . c_str ( ) ) ;
if ( ! given | | strcmp ( given , password ) ! = 0 )
{
return false ;
}
}
pPlayer - > SetAdminId ( id , false ) ;
return true ;
}
bool PlayerManager : : CheckSetAdminName ( int index , CPlayer * pPlayer , AdminId id )
{
2014-05-29 19:31:12 +02:00
const char * password = adminsys - > GetAdminPassword ( id ) ;
2008-03-30 09:00:22 +02:00
if ( password = = NULL )
{
return false ;
}
if ( m_PassInfoVar . size ( ) < 1 )
{
return false ;
}
/* Whoa... the user needs a password! */
const char * given = engine - > GetClientConVarValue ( index , m_PassInfoVar . c_str ( ) ) ;
if ( ! given | | strcmp ( given , password ) ! = 0 )
{
return false ;
}
pPlayer - > SetAdminId ( id , false ) ;
return true ;
}
void PlayerManager : : RunAuthChecks ( )
{
CPlayer * pPlayer ;
const char * authstr ;
unsigned int removed = 0 ;
for ( unsigned int i = 1 ; i < = m_AuthQueue [ 0 ] ; i + + )
{
2008-07-08 11:20:47 +02:00
pPlayer = & m_Players [ m_AuthQueue [ i ] ] ;
2013-05-13 21:18:12 +02:00
# if SOURCE_ENGINE == SE_DOTA
authstr = engine - > GetPlayerNetworkIDString ( pPlayer - > m_iIndex - 1 ) ;
# else
2008-03-30 09:00:22 +02:00
authstr = engine - > GetPlayerNetworkIDString ( pPlayer - > m_pEdict ) ;
2013-05-13 21:18:12 +02:00
# endif
2013-03-07 01:58:17 +01:00
pPlayer - > SetAuthString ( authstr ) ;
2012-05-24 18:55:46 +02:00
2013-03-07 01:58:17 +01:00
if ( ! pPlayer - > IsAuthStringValidated ( ) )
2012-05-24 18:55:46 +02:00
{
2013-03-07 01:58:17 +01:00
continue ; // we're using steam auth, and steam doesn't know about this player yet so we can't do anything about them for now
2012-05-24 18:55:46 +02:00
}
2008-03-30 09:00:22 +02:00
if ( authstr & & authstr [ 0 ] ! = ' \0 '
& & ( strcmp ( authstr , " STEAM_ID_PENDING " ) ! = 0 ) )
{
/* Set authorization */
2013-03-07 01:58:17 +01:00
pPlayer - > Authorize ( ) ;
2008-03-30 09:00:22 +02:00
/* Mark as removed from queue */
unsigned int client = m_AuthQueue [ i ] ;
m_AuthQueue [ i ] = 0 ;
removed + + ;
/* Send to extensions */
List < IClientListener * > : : iterator iter ;
IClientListener * pListener ;
for ( iter = m_hooks . begin ( ) ; iter ! = m_hooks . end ( ) ; iter + + )
{
pListener = ( * iter ) ;
pListener - > OnClientAuthorized ( client , authstr ) ;
if ( ! pPlayer - > IsConnected ( ) )
{
break ;
}
}
/* Send to plugins if player is still connected */
if ( pPlayer - > IsConnected ( ) & & m_clauth - > GetFunctionCount ( ) )
{
/* :TODO: handle the case of a player disconnecting in the middle */
m_clauth - > PushCell ( client ) ;
m_clauth - > PushString ( authstr ) ;
m_clauth - > Execute ( NULL ) ;
}
if ( pPlayer - > IsConnected ( ) )
{
pPlayer - > Authorize_Post ( ) ;
}
}
}
/* Clean up the queue */
if ( removed )
{
/* We don't have to compact the list if it's empty */
if ( removed ! = m_AuthQueue [ 0 ] )
{
unsigned int diff = 0 ;
for ( unsigned int i = 1 ; i < = m_AuthQueue [ 0 ] ; i + + )
{
/* If this member is removed... */
if ( m_AuthQueue [ i ] = = 0 )
{
/* Increase the differential */
diff + + ;
} else {
/* diff cannot increase faster than i+1 */
assert ( i > diff ) ;
assert ( i - diff > = 1 ) ;
/* move this index down */
m_AuthQueue [ i - diff ] = m_AuthQueue [ i ] ;
}
}
m_AuthQueue [ 0 ] - = removed ;
} else {
m_AuthQueue [ 0 ] = 0 ;
}
}
}
2013-05-13 21:18:12 +02:00
# if SOURCE_ENGINE == SE_DOTA
2013-07-12 08:31:41 +02:00
bool PlayerManager : : OnClientConnect ( CEntityIndex index , const char * pszName , const char * pszAddress , char * reject , int maxrejectlen )
2013-05-13 21:18:12 +02:00
{
2013-07-12 08:31:41 +02:00
int client = index . Get ( ) ;
2013-05-13 21:18:12 +02:00
edict_t * pEntity = PEntityOfEntIndex ( client ) ;
# else
2008-03-30 09:00:22 +02:00
bool PlayerManager : : OnClientConnect ( edict_t * pEntity , const char * pszName , const char * pszAddress , char * reject , int maxrejectlen )
{
2008-11-14 16:18:30 +01:00
int client = IndexOfEdict ( pEntity ) ;
2013-05-13 21:18:12 +02:00
# endif
2008-07-08 11:20:47 +02:00
CPlayer * pPlayer = & m_Players [ client ] ;
2011-10-21 03:39:57 +02:00
+ + m_PlayersSinceActive ;
2008-03-30 09:00:22 +02:00
2011-10-15 18:07:55 +02:00
pPlayer - > Initialize ( pszName , pszAddress , pEntity ) ;
/* Get the client's language */
if ( m_QueryLang )
{
const char * name ;
if ( ! pPlayer - > IsFakeClient ( ) & & ( name = engine - > GetClientConVarValue ( client , " cl_language " ) ) )
{
unsigned int langid ;
pPlayer - > m_LangId = ( translator - > GetLanguageByName ( name , & langid ) ) ? langid : translator - > GetServerLanguage ( ) ;
} else {
pPlayer - > m_LangId = translator - > GetServerLanguage ( ) ;
}
}
2008-03-30 09:00:22 +02:00
List < IClientListener * > : : iterator iter ;
IClientListener * pListener = NULL ;
for ( iter = m_hooks . begin ( ) ; iter ! = m_hooks . end ( ) ; iter + + )
{
pListener = ( * iter ) ;
if ( ! pListener - > InterceptClientConnect ( client , reject , maxrejectlen ) )
{
2012-08-27 05:33:04 +02:00
RETURN_META_VALUE ( MRES_SUPERCEDE , false ) ;
2008-03-30 09:00:22 +02:00
}
}
cell_t res = 1 ;
m_clconnect - > PushCell ( client ) ;
2009-04-14 01:39:53 +02:00
m_clconnect - > PushStringEx ( reject , maxrejectlen , SM_PARAM_STRING_UTF8 | SM_PARAM_STRING_COPY , SM_PARAM_COPYBACK ) ;
2008-03-30 09:00:22 +02:00
m_clconnect - > PushCell ( maxrejectlen ) ;
2008-07-08 11:20:47 +02:00
m_clconnect - > Execute ( & res ) ;
2008-03-30 09:00:22 +02:00
if ( res )
{
2008-07-08 11:20:47 +02:00
if ( ! pPlayer - > IsAuthorized ( ) )
2008-03-30 09:00:22 +02:00
{
m_AuthQueue [ + + m_AuthQueue [ 0 ] ] = client ;
}
2008-07-08 11:20:47 +02:00
2013-05-13 21:18:12 +02:00
m_UserIdLookUp [ GetPlayerUserId ( pEntity ) ] = client ;
2008-04-12 04:18:03 +02:00
}
else
{
2008-07-08 11:20:47 +02:00
if ( ! pPlayer - > IsFakeClient ( ) )
{
RETURN_META_VALUE ( MRES_SUPERCEDE , false ) ;
}
2008-03-30 09:00:22 +02:00
}
return true ;
}
2013-05-13 21:18:12 +02:00
# if SOURCE_ENGINE == SE_DOTA
2013-07-12 08:31:41 +02:00
bool PlayerManager : : OnClientConnect_Post ( CEntityIndex index , const char * pszName , const char * pszAddress , char * reject , int maxrejectlen )
2013-05-13 21:18:12 +02:00
{
2013-07-12 08:31:41 +02:00
int client = index . Get ( ) ;
2013-05-13 21:18:12 +02:00
edict_t * pEntity = PEntityOfEntIndex ( client ) ;
# else
2008-03-30 09:00:22 +02:00
bool PlayerManager : : OnClientConnect_Post ( edict_t * pEntity , const char * pszName , const char * pszAddress , char * reject , int maxrejectlen )
{
2008-11-14 16:18:30 +01:00
int client = IndexOfEdict ( pEntity ) ;
2013-05-13 21:18:12 +02:00
# endif
2008-03-30 09:00:22 +02:00
bool orig_value = META_RESULT_ORIG_RET ( bool ) ;
2008-07-08 11:20:47 +02:00
CPlayer * pPlayer = & m_Players [ client ] ;
2008-03-30 09:00:22 +02:00
if ( orig_value )
{
List < IClientListener * > : : iterator iter ;
IClientListener * pListener = NULL ;
for ( iter = m_hooks . begin ( ) ; iter ! = m_hooks . end ( ) ; iter + + )
{
pListener = ( * iter ) ;
pListener - > OnClientConnected ( client ) ;
if ( ! pPlayer - > IsConnected ( ) )
{
2010-06-06 23:53:38 +02:00
return true ;
2008-03-30 09:00:22 +02:00
}
}
2008-07-08 11:20:47 +02:00
if ( ! pPlayer - > IsFakeClient ( )
& & m_bIsListenServer
& & strncmp ( pszAddress , " 127.0.0.1 " , 9 ) = = 0 )
{
m_ListenClient = client ;
}
2008-10-19 05:14:13 +02:00
cell_t res ;
2011-01-01 02:02:41 +01:00
m_clconnect_post - > PushCell ( client ) ;
m_clconnect_post - > Execute ( & res , NULL ) ;
2008-07-08 11:20:47 +02:00
}
else
2008-04-12 04:18:03 +02:00
{
2008-07-08 11:20:47 +02:00
InvalidatePlayer ( pPlayer ) ;
2008-04-12 04:18:03 +02:00
}
2008-03-30 09:00:22 +02:00
return true ;
}
2013-05-13 21:18:12 +02:00
# if SOURCE_ENGINE == SE_DOTA
2013-07-12 08:31:41 +02:00
void PlayerManager : : OnClientPutInServer ( CEntityIndex index , const char * playername )
2013-05-13 21:18:12 +02:00
{
2013-07-12 08:31:41 +02:00
int client = index . Get ( ) ;
2013-05-13 21:18:12 +02:00
edict_t * pEntity = PEntityOfEntIndex ( client ) ;
# else
2008-03-30 09:00:22 +02:00
void PlayerManager : : OnClientPutInServer ( edict_t * pEntity , const char * playername )
{
2008-11-14 16:18:30 +01:00
int client = IndexOfEdict ( pEntity ) ;
2013-05-13 21:18:12 +02:00
# endif
cell_t res ;
2008-07-08 11:20:47 +02:00
CPlayer * pPlayer = & m_Players [ client ] ;
2008-03-30 09:00:22 +02:00
/* If they're not connected, they're a bot */
if ( ! pPlayer - > IsConnected ( ) )
{
/* Run manual connection routines */
char error [ 255 ] ;
2013-05-13 21:18:12 +02:00
const char * authid ;
# if SOURCE_ENGINE == SE_DOTA
authid = engine - > GetPlayerNetworkIDString ( client - 1 ) ;
# else
authid = engine - > GetPlayerNetworkIDString ( pEntity ) ;
# endif
2013-03-07 01:58:17 +01:00
pPlayer - > SetAuthString ( authid ) ;
pPlayer - > Authorize ( ) ;
2008-08-24 06:35:48 +02:00
pPlayer - > m_bFakeClient = true ;
2011-10-21 03:39:57 +02:00
/*
* While we ' re already filtered to just bots , we ' ll do other checks to
* make sure that the requisite services are enabled and that the bots
* have joined at the expected time .
*
* Checking playerinfo ' s IsHLTV and IsReplay would be better and less
* error - prone but will always show false until later in the frame ,
* after PutInServer and Activate , and we want it now !
2012-11-24 15:56:46 +01:00
*
* These checks are hairy as hell due to differences between engines and games .
*
* Most engines use " Replay " and " SourceTV " as bot names for these when they ' re
* created . EP2V , CSS and Nuclear Dawn ( but not L4D2 ) differ from this by now using
* replay_ / tv_name directly when creating the bot ( s ) . To complicate it slightly
* further , the cvar can be empty and the engine ' s fallback to " unnamed " will be used .
* We can maybe just rip out the name checks at some point and rely solely on whether
* they ' re enabled and the join order .
2011-10-21 03:39:57 +02:00
*/
// This doesn't actually get incremented until OnClientConnect. Fake it to check.
int newCount = m_PlayersSinceActive + 1 ;
2012-11-24 15:56:46 +01:00
2013-05-13 21:18:12 +02:00
int userId = GetPlayerUserId ( pEntity ) ;
2013-07-21 17:53:56 +02:00
# if (SOURCE_ENGINE == SE_CSS || SOURCE_ENGINE == SE_HL2DM || SOURCE_ENGINE == SE_DODS || SOURCE_ENGINE == SE_TF2 || SOURCE_ENGINE == SE_NUCLEARDAWN || SOURCE_ENGINE == SE_LEFT4DEAD2)
2012-11-03 19:58:40 +01:00
static ConVar * tv_name = icvar - > FindVar ( " tv_name " ) ;
# endif
2013-07-21 17:53:56 +02:00
# if SOURCE_ENGINE == SE_TF2
2012-11-24 15:56:46 +01:00
static ConVar * replay_name = icvar - > FindVar ( " replay_name " ) ;
# endif
2011-10-21 03:39:57 +02:00
2013-07-21 17:53:56 +02:00
# if SOURCE_ENGINE == SE_TF2
2011-10-21 03:39:57 +02:00
if ( m_bIsReplayActive & & newCount = = 1
2012-11-24 15:56:46 +01:00
& & ( m_ReplayUserId = = userId
| | ( replay_name & & strcmp ( playername , replay_name - > GetString ( ) ) = = 0 ) | | ( replay_name & & replay_name - > GetString ( ) [ 0 ] = = 0 & & strcmp ( playername , " unnamed " ) = = 0 )
)
)
2011-10-21 03:39:57 +02:00
{
pPlayer - > m_bIsReplay = true ;
m_ReplayUserId = userId ;
}
# endif
if ( m_bIsSourceTVActive
& & ( ( ! m_bIsReplayActive & & newCount = = 1 )
| | ( m_bIsReplayActive & & newCount = = 2 ) )
2012-11-24 15:56:46 +01:00
& & ( m_SourceTVUserId = = userId
2012-11-03 19:58:40 +01:00
# if SOURCE_ENGINE == SE_CSGO
2012-11-24 15:56:46 +01:00
| | strcmp ( playername , " GOTV " ) = = 0
2013-07-21 17:53:56 +02:00
# elif (SOURCE_ENGINE == SE_CSS || SOURCE_ENGINE == SE_HL2DM || SOURCE_ENGINE == SE_DODS || SOURCE_ENGINE == SE_TF2 || SOURCE_ENGINE == SE_NUCLEARDAWN)
2012-11-24 15:56:46 +01:00
| | ( tv_name & & strcmp ( playername , tv_name - > GetString ( ) ) = = 0 ) | | ( tv_name & & tv_name - > GetString ( ) [ 0 ] = = 0 & & strcmp ( playername , " unnamed " ) = = 0 )
2012-11-03 19:58:40 +01:00
# else
2012-11-24 15:56:46 +01:00
| | strcmp ( playername , " SourceTV " ) = = 0
2012-11-03 19:58:40 +01:00
# endif
2012-11-24 15:56:46 +01:00
)
2011-10-21 03:39:57 +02:00
)
{
pPlayer - > m_bIsSourceTV = true ;
m_SourceTVUserId = userId ;
}
2013-05-13 21:33:55 +02:00
# if SOURCE_ENGINE == SE_DOTA
if ( ! OnClientConnect ( client , playername , " 127.0.0.1 " , error , sizeof ( error ) ) )
# else
2008-03-30 09:00:22 +02:00
if ( ! OnClientConnect ( pEntity , playername , " 127.0.0.1 " , error , sizeof ( error ) ) )
2013-05-13 21:33:55 +02:00
# endif
2008-03-30 09:00:22 +02:00
{
/* :TODO: kick the bot if it's rejected */
return ;
}
List < IClientListener * > : : iterator iter ;
IClientListener * pListener = NULL ;
for ( iter = m_hooks . begin ( ) ; iter ! = m_hooks . end ( ) ; iter + + )
{
pListener = ( * iter ) ;
pListener - > OnClientConnected ( client ) ;
/* See if bot was kicked */
if ( ! pPlayer - > IsConnected ( ) )
{
return ;
}
}
2010-06-06 23:53:38 +02:00
cell_t res ;
2011-01-01 02:02:41 +01:00
m_clconnect_post - > PushCell ( client ) ;
m_clconnect_post - > Execute ( & res , NULL ) ;
2010-06-06 23:53:38 +02:00
2008-03-30 09:00:22 +02:00
/* Now do authorization */
for ( iter = m_hooks . begin ( ) ; iter ! = m_hooks . end ( ) ; iter + + )
{
pListener = ( * iter ) ;
pListener - > OnClientAuthorized ( client , authid ) ;
}
/* Finally, tell plugins */
if ( m_clauth - > GetFunctionCount ( ) )
{
m_clauth - > PushCell ( client ) ;
m_clauth - > PushString ( authid ) ;
m_clauth - > Execute ( NULL ) ;
}
pPlayer - > Authorize_Post ( ) ;
}
if ( playerinfo )
{
pPlayer - > m_Info = playerinfo - > GetPlayerInfo ( pEntity ) ;
}
2008-07-08 11:20:47 +02:00
pPlayer - > Connect ( ) ;
2008-03-30 09:00:22 +02:00
m_PlayerCount + + ;
List < IClientListener * > : : iterator iter ;
IClientListener * pListener = NULL ;
for ( iter = m_hooks . begin ( ) ; iter ! = m_hooks . end ( ) ; iter + + )
{
pListener = ( * iter ) ;
pListener - > OnClientPutInServer ( client ) ;
}
m_clputinserver - > PushCell ( client ) ;
m_clputinserver - > Execute ( & res , NULL ) ;
2008-07-08 11:20:47 +02:00
if ( pPlayer - > IsAuthorized ( ) )
2008-03-30 09:00:22 +02:00
{
2008-07-08 11:20:47 +02:00
pPlayer - > DoPostConnectAuthorization ( ) ;
2008-03-30 09:00:22 +02:00
}
}
void PlayerManager : : OnSourceModLevelEnd ( )
{
/* Disconnect all bots still in game */
2011-07-08 13:55:20 +02:00
for ( int i = 1 ; i < = m_maxClients ; i + + )
2008-03-30 09:00:22 +02:00
{
if ( m_Players [ i ] . IsConnected ( ) )
{
2013-05-13 21:33:55 +02:00
# if SOURCE_ENGINE == SE_DOTA
2014-04-06 23:03:29 +02:00
OnClientDisconnect ( m_Players [ i ] . GetIndex ( ) , 0 ) ;
2014-05-30 23:27:56 +02:00
OnClientDisconnect_Post ( m_Players [ i ] . GetIndex ( ) , 0 ) ;
2013-05-13 21:33:55 +02:00
# else
2008-03-30 09:00:22 +02:00
OnClientDisconnect ( m_Players [ i ] . GetEdict ( ) ) ;
2014-05-30 23:27:56 +02:00
OnClientDisconnect_Post ( m_Players [ i ] . GetEdict ( ) ) ;
2013-05-13 21:33:55 +02:00
# endif
2008-03-30 09:00:22 +02:00
}
}
m_PlayerCount = 0 ;
}
2014-05-31 20:33:30 +02:00
void PlayerManager : : OnServerHibernationUpdate ( bool bHibernating )
{
/* If bots were added at map start, but not fully inited before hibernation, there will
* be no OnClientDisconnect for them , despite them getting booted right before this .
*/
if ( bHibernating )
{
for ( int i = 1 ; i < = m_maxClients ; i + + )
{
CPlayer * pPlayer = & m_Players [ i ] ;
if ( pPlayer - > IsConnected ( ) & & pPlayer - > IsFakeClient ( ) )
{
# if SOURCE_ENGINE < SE_LEFT4DEAD || SOURCE_ENGINE >= SE_CSGO || SOURCE_ENGINE == SE_NUCLEARDAWN
// These games have the bug fixed where hltv/replay was getting kicked on hibernation
if ( pPlayer - > IsSourceTV ( ) | | pPlayer - > IsReplay ( ) )
continue ;
# endif
# if SOURCE_ENGINE == SE_DOTA
OnClientDisconnect ( m_Players [ i ] . GetIndex ( ) , 0 ) ;
OnClientDisconnect_Post ( m_Players [ i ] . GetIndex ( ) , 0 ) ;
# else
OnClientDisconnect ( m_Players [ i ] . GetEdict ( ) ) ;
OnClientDisconnect_Post ( m_Players [ i ] . GetEdict ( ) ) ;
# endif
}
}
}
}
2013-05-13 21:18:12 +02:00
# if SOURCE_ENGINE == SE_DOTA
2014-04-06 23:03:29 +02:00
void PlayerManager : : OnClientDisconnect ( CEntityIndex index , int reason )
2013-05-13 21:18:12 +02:00
{
2013-07-12 08:31:41 +02:00
int client = index . Get ( ) ;
2013-05-13 21:18:12 +02:00
edict_t * pEntity = PEntityOfEntIndex ( client ) ;
# else
2008-03-30 09:00:22 +02:00
void PlayerManager : : OnClientDisconnect ( edict_t * pEntity )
{
2008-11-14 16:18:30 +01:00
int client = IndexOfEdict ( pEntity ) ;
2013-05-13 21:18:12 +02:00
# endif
cell_t res ;
2008-07-08 11:20:47 +02:00
CPlayer * pPlayer = & m_Players [ client ] ;
2008-03-30 09:00:22 +02:00
2008-07-08 11:20:47 +02:00
if ( pPlayer - > IsConnected ( ) )
2008-03-30 09:00:22 +02:00
{
m_cldisconnect - > PushCell ( client ) ;
m_cldisconnect - > Execute ( & res , NULL ) ;
2008-04-12 04:18:03 +02:00
}
else
{
2008-03-30 09:00:22 +02:00
/* We don't care, prevent a double call */
return ;
}
2008-07-08 11:20:47 +02:00
if ( pPlayer - > WasCountedAsInGame ( ) )
2008-03-30 09:00:22 +02:00
{
m_PlayerCount - - ;
}
List < IClientListener * > : : iterator iter ;
IClientListener * pListener = NULL ;
for ( iter = m_hooks . begin ( ) ; iter ! = m_hooks . end ( ) ; iter + + )
{
pListener = ( * iter ) ;
pListener - > OnClientDisconnecting ( client ) ;
}
}
2013-05-13 21:18:12 +02:00
# if SOURCE_ENGINE == SE_DOTA
2014-04-06 23:03:29 +02:00
void PlayerManager : : OnClientDisconnect_Post ( CEntityIndex index , int reason )
2013-05-13 21:18:12 +02:00
{
2013-07-12 08:31:41 +02:00
int client = index . Get ( ) ;
2013-05-13 21:18:12 +02:00
edict_t * pEntity = PEntityOfEntIndex ( client ) ;
# else
2008-03-30 09:00:22 +02:00
void PlayerManager : : OnClientDisconnect_Post ( edict_t * pEntity )
{
2008-11-14 16:18:30 +01:00
int client = IndexOfEdict ( pEntity ) ;
2013-05-13 21:18:12 +02:00
# endif
2014-05-30 23:27:56 +02:00
CPlayer * pPlayer = & m_Players [ client ] ;
if ( ! pPlayer - > IsConnected ( ) )
{
/* We don't care, prevent a double call */
return ;
}
InvalidatePlayer ( pPlayer ) ;
if ( m_ListenClient = = client )
{
m_ListenClient = 0 ;
}
2013-05-13 21:18:12 +02:00
cell_t res ;
2008-03-30 09:00:22 +02:00
m_cldisconnect_post - > PushCell ( client ) ;
m_cldisconnect_post - > Execute ( & res , NULL ) ;
List < IClientListener * > : : iterator iter ;
IClientListener * pListener = NULL ;
for ( iter = m_hooks . begin ( ) ; iter ! = m_hooks . end ( ) ; iter + + )
{
pListener = ( * iter ) ;
pListener - > OnClientDisconnected ( client ) ;
}
}
2009-02-01 08:33:31 +01:00
void ClientConsolePrint ( edict_t * e , const char * fmt , . . . )
{
char buffer [ 512 ] ;
va_list ap ;
va_start ( ap , fmt ) ;
size_t len = vsnprintf ( buffer , sizeof ( buffer ) , fmt , ap ) ;
va_end ( ap ) ;
if ( len > = sizeof ( buffer ) - 1 )
{
2009-02-01 08:35:19 +01:00
buffer [ sizeof ( buffer ) - 2 ] = ' \n ' ;
buffer [ sizeof ( buffer ) - 1 ] = ' \0 ' ;
2009-02-01 08:33:31 +01:00
} else {
buffer [ len + + ] = ' \n ' ;
buffer [ len ] = ' \0 ' ;
}
2014-01-30 05:41:41 +01:00
CPlayer * pPlayer = g_Players . GetPlayerByIndex ( IndexOfEdict ( e ) ) ;
if ( ! pPlayer )
{
return ;
}
pPlayer - > PrintToConsole ( buffer ) ;
2009-02-01 08:33:31 +01:00
}
2013-03-29 19:37:29 +01:00
void ListExtensionsToClient ( CPlayer * player , const CCommand & args )
{
char buffer [ 256 ] ;
unsigned int id = 0 ;
unsigned int start = 0 ;
2013-03-31 22:30:22 +02:00
AutoExtensionList extensions ( extsys ) ;
if ( ! extensions - > size ( ) )
2013-03-29 19:37:29 +01:00
{
ClientConsolePrint ( player - > GetEdict ( ) , " [SM] No extensions found. " ) ;
return ;
}
if ( args . ArgC ( ) > 2 )
{
start = atoi ( args . Arg ( 2 ) ) ;
}
2013-03-31 22:30:22 +02:00
size_t i = 0 ;
for ( ; i < extensions - > size ( ) ; i + + )
2013-03-29 19:37:29 +01:00
{
2013-03-31 22:30:22 +02:00
IExtension * ext = extensions - > at ( i ) ;
2013-03-29 19:37:29 +01:00
char error [ 255 ] ;
if ( ! ext - > IsRunning ( error , sizeof ( error ) ) )
{
continue ;
}
id + + ;
if ( id < start )
{
continue ;
}
if ( id - start > 10 )
{
break ;
}
IExtensionInterface * api = ext - > GetAPI ( ) ;
const char * name = api - > GetExtensionName ( ) ;
const char * version = api - > GetExtensionVerString ( ) ;
const char * author = api - > GetExtensionAuthor ( ) ;
const char * description = api - > GetExtensionDescription ( ) ;
size_t len = UTIL_Format ( buffer , sizeof ( buffer ) , " \" %s \" " , name ) ;
if ( version ! = NULL & & version [ 0 ] )
{
len + = UTIL_Format ( & buffer [ len ] , sizeof ( buffer ) - len , " (%s) " , version ) ;
}
if ( author ! = NULL & & author [ 0 ] )
{
len + = UTIL_Format ( & buffer [ len ] , sizeof ( buffer ) - len , " by %s " , author ) ;
}
if ( description ! = NULL & & description [ 0 ] )
{
len + = UTIL_Format ( & buffer [ len ] , sizeof ( buffer ) - len , " : %s " , description ) ;
}
ClientConsolePrint ( player - > GetEdict ( ) , " %s " , buffer ) ;
}
2013-03-31 22:30:22 +02:00
for ( ; i < extensions - > size ( ) ; i + + )
2013-03-29 19:37:29 +01:00
{
char error [ 255 ] ;
2013-03-31 22:30:22 +02:00
if ( extensions - > at ( i ) - > IsRunning ( error , sizeof ( error ) ) )
2013-03-29 19:37:29 +01:00
{
break ;
}
}
2013-03-31 22:30:22 +02:00
if ( i < extensions - > size ( ) )
2013-03-29 19:37:29 +01:00
{
ClientConsolePrint ( player - > GetEdict ( ) , " To see more, type \" sm exts %d \" " , id ) ;
}
}
void ListPluginsToClient ( CPlayer * player , const CCommand & args )
{
char buffer [ 256 ] ;
unsigned int id = 0 ;
edict_t * e = player - > GetEdict ( ) ;
unsigned int start = 0 ;
2013-03-31 22:30:22 +02:00
AutoPluginList plugins ( scripts ) ;
if ( ! plugins - > size ( ) )
2013-03-29 19:37:29 +01:00
{
ClientConsolePrint ( e , " [SM] No plugins found. " ) ;
return ;
}
if ( args . ArgC ( ) > 2 )
{
start = atoi ( args . Arg ( 2 ) ) ;
}
SourceHook : : List < SMPlugin * > m_FailList ;
2013-03-31 22:30:22 +02:00
size_t i = 0 ;
for ( ; i < plugins - > size ( ) ; i + + )
2013-03-29 19:37:29 +01:00
{
2013-03-31 22:30:22 +02:00
SMPlugin * pl = plugins - > at ( i ) ;
2013-03-29 19:37:29 +01:00
if ( pl - > GetStatus ( ) ! = Plugin_Running )
{
continue ;
}
/* Count valid plugins */
id + + ;
if ( id < start )
{
continue ;
}
if ( id - start > 10 )
{
break ;
}
size_t len ;
const sm_plugininfo_t * info = pl - > GetPublicInfo ( ) ;
len = UTIL_Format ( buffer , sizeof ( buffer ) , " \" %s \" " , ( IS_STR_FILLED ( info - > name ) ) ? info - > name : pl - > GetFilename ( ) ) ;
if ( IS_STR_FILLED ( info - > version ) )
{
len + = UTIL_Format ( & buffer [ len ] , sizeof ( buffer ) - len , " (%s) " , info - > version ) ;
}
if ( IS_STR_FILLED ( info - > author ) )
{
UTIL_Format ( & buffer [ len ] , sizeof ( buffer ) - len , " by %s " , info - > author ) ;
}
else
{
UTIL_Format ( & buffer [ len ] , sizeof ( buffer ) - len , " %s " , pl - > GetFilename ( ) ) ;
}
ClientConsolePrint ( e , " %s " , buffer ) ;
}
/* See if we can get more plugins */
2013-03-31 22:30:22 +02:00
for ( ; i < plugins - > size ( ) ; i + + )
2013-03-29 19:37:29 +01:00
{
2013-03-31 22:30:22 +02:00
if ( plugins - > at ( i ) - > GetStatus ( ) = = Plugin_Running )
2013-03-29 19:37:29 +01:00
{
break ;
}
}
/* Do we actually have more plugins? */
2013-03-31 22:30:22 +02:00
if ( i < plugins - > size ( ) )
2013-03-29 19:37:29 +01:00
{
ClientConsolePrint ( e , " To see more, type \" sm plugins %d \" " , id ) ;
}
}
2013-05-13 21:18:12 +02:00
# if SOURCE_ENGINE == SE_DOTA
2013-07-12 08:31:41 +02:00
void PlayerManager : : OnClientCommand ( CEntityIndex index , const CCommand & args )
2013-05-13 21:18:12 +02:00
{
2013-07-12 08:31:41 +02:00
int client = index . Get ( ) ;
2013-05-13 21:18:12 +02:00
edict_t * pEntity = PEntityOfEntIndex ( client ) ;
# elif SOURCE_ENGINE >= SE_ORANGEBOX
2008-03-30 09:00:22 +02:00
void PlayerManager : : OnClientCommand ( edict_t * pEntity , const CCommand & args )
{
2013-05-13 21:18:12 +02:00
int client = IndexOfEdict ( pEntity ) ;
2008-03-30 09:00:22 +02:00
# else
void PlayerManager : : OnClientCommand ( edict_t * pEntity )
{
CCommand args ;
2013-05-13 21:18:12 +02:00
2008-11-14 16:18:30 +01:00
int client = IndexOfEdict ( pEntity ) ;
2013-05-13 21:18:12 +02:00
# endif
2008-03-30 09:00:22 +02:00
cell_t res = Pl_Continue ;
2008-07-08 11:20:47 +02:00
CPlayer * pPlayer = & m_Players [ client ] ;
2008-03-30 09:00:22 +02:00
2008-07-08 11:20:47 +02:00
if ( ! pPlayer - > IsConnected ( ) )
2008-03-30 09:00:22 +02:00
{
return ;
}
2009-02-01 08:33:31 +01:00
if ( strcmp ( args . Arg ( 0 ) , " sm " ) = = 0 )
{
if ( args . ArgC ( ) > 1 & & strcmp ( args . Arg ( 1 ) , " plugins " ) = = 0 )
{
2013-03-29 19:37:29 +01:00
ListPluginsToClient ( pPlayer , args ) ;
2009-02-01 08:33:31 +01:00
RETURN_META ( MRES_SUPERCEDE ) ;
}
2012-05-27 02:51:08 +02:00
else if ( args . ArgC ( ) > 1 & & strcmp ( args . Arg ( 1 ) , " exts " ) = = 0 )
{
2013-03-29 19:37:29 +01:00
ListExtensionsToClient ( pPlayer , args ) ;
2012-05-27 02:51:08 +02:00
RETURN_META ( MRES_SUPERCEDE ) ;
}
2009-02-01 08:33:31 +01:00
else if ( args . ArgC ( ) > 1 & & strcmp ( args . Arg ( 1 ) , " credits " ) = = 0 )
{
2012-08-22 19:39:16 +02:00
ClientConsolePrint ( pEntity ,
" SourceMod would not be possible without: " ) ;
ClientConsolePrint ( pEntity ,
" David \" BAILOPAN \" Anderson, Matt \" pRED \" Woodrow " ) ;
ClientConsolePrint ( pEntity ,
" Scott \" DS \" Ehlert, Fyren " ) ;
ClientConsolePrint ( pEntity ,
" Nicholas \" psychonic \" Hastings, Asher \" asherkin \" Baker " ) ;
2009-02-01 08:33:31 +01:00
ClientConsolePrint ( pEntity ,
2012-08-22 19:39:16 +02:00
" Borja \" faluco \" Ferrer, Pavol \" PM OnoTo \" Marko " ) ;
2009-02-01 08:33:31 +01:00
ClientConsolePrint ( pEntity ,
" SourceMod is open source under the GNU General Public License. " ) ;
RETURN_META ( MRES_SUPERCEDE ) ;
}
ClientConsolePrint ( pEntity ,
2013-12-30 23:51:00 +01:00
" SourceMod %s, by AlliedModders LLC " , SOURCEMOD_VERSION ) ;
2009-02-01 08:33:31 +01:00
ClientConsolePrint ( pEntity ,
" To see running plugins, type \" sm plugins \" " ) ;
ClientConsolePrint ( pEntity ,
" To see credits, type \" sm credits \" " ) ;
ClientConsolePrint ( pEntity ,
" Visit http://www.sourcemod.net/ " ) ;
RETURN_META ( MRES_SUPERCEDE ) ;
}
2008-03-30 09:00:22 +02:00
g_HL2 . PushCommandStack ( & args ) ;
int argcount = args . ArgC ( ) - 1 ;
const char * cmd = g_HL2 . CurrentCommandName ( ) ;
bool result = g_ValveMenuStyle . OnClientCommand ( client , cmd , args ) ;
if ( result )
{
res = Pl_Handled ;
} else {
result = g_RadioMenuStyle . OnClientCommand ( client , cmd , args ) ;
if ( result )
{
res = Pl_Handled ;
}
}
2009-09-26 23:12:23 +02:00
if ( g_ConsoleDetours . IsEnabled ( ) )
{
cell_t res2 = g_ConsoleDetours . InternalDispatch ( client , args ) ;
if ( res2 > = Pl_Stop )
{
g_HL2 . PopCommandStack ( ) ;
RETURN_META ( MRES_SUPERCEDE ) ;
}
else if ( res2 > res )
{
res = res2 ;
}
}
2008-03-30 09:00:22 +02:00
cell_t res2 = Pl_Continue ;
2009-10-27 07:51:39 +01:00
if ( pPlayer - > IsInGame ( ) )
{
m_clcommand - > PushCell ( client ) ;
m_clcommand - > PushCell ( argcount ) ;
m_clcommand - > Execute ( & res2 , NULL ) ;
}
2008-03-30 09:00:22 +02:00
if ( res2 > res )
{
res = res2 ;
}
if ( res > = Pl_Stop )
{
g_HL2 . PopCommandStack ( ) ;
RETURN_META ( MRES_SUPERCEDE ) ;
}
res = g_ConCmds . DispatchClientCommand ( client , cmd , argcount , ( ResultType ) res ) ;
g_HL2 . PopCommandStack ( ) ;
if ( res > = Pl_Handled )
{
RETURN_META ( MRES_SUPERCEDE ) ;
}
}
2013-05-13 21:18:12 +02:00
# if SOURCE_ENGINE == SE_DOTA
2013-07-12 08:31:41 +02:00
void PlayerManager : : OnClientSettingsChanged ( CEntityIndex index )
2013-05-13 21:18:12 +02:00
{
2013-07-12 08:31:41 +02:00
int client = index . Get ( ) ;
2013-05-13 21:18:12 +02:00
edict_t * pEntity = PEntityOfEntIndex ( client ) ;
# else
2008-03-30 09:00:22 +02:00
void PlayerManager : : OnClientSettingsChanged ( edict_t * pEntity )
{
2008-11-14 16:18:30 +01:00
int client = IndexOfEdict ( pEntity ) ;
2013-05-13 21:18:12 +02:00
# endif
cell_t res ;
2008-07-08 11:20:47 +02:00
CPlayer * pPlayer = & m_Players [ client ] ;
2008-03-30 09:00:22 +02:00
2008-07-08 11:20:47 +02:00
if ( ! pPlayer - > IsConnected ( ) )
2008-03-30 09:00:22 +02:00
{
return ;
}
2008-11-14 16:18:30 +01:00
m_clinfochanged - > PushCell ( client ) ;
2008-03-30 09:00:22 +02:00
m_clinfochanged - > Execute ( & res , NULL ) ;
2008-11-21 21:09:50 +01:00
if ( pPlayer - > IsFakeClient ( ) )
{
return ;
}
2008-07-08 11:20:47 +02:00
IPlayerInfo * info = pPlayer - > GetPlayerInfo ( ) ;
2008-03-30 09:00:22 +02:00
const char * new_name = info ? info - > GetName ( ) : engine - > GetClientConVarValue ( client , " name " ) ;
2008-07-08 11:20:47 +02:00
const char * old_name = pPlayer - > m_Name . c_str ( ) ;
2008-03-30 09:00:22 +02:00
2012-06-10 02:00:55 +02:00
# if SOURCE_ENGINE >= SE_LEFT4DEAD
const char * networkid_force ;
if ( ( networkid_force = engine - > GetClientConVarValue ( client , " networkid_force " ) ) & & networkid_force [ 0 ] ! = ' \0 ' )
{
2013-03-17 04:12:40 +01:00
unsigned int accountId = pPlayer - > GetSteamAccountID ( ) ;
2012-06-10 02:00:55 +02:00
g_Logger . LogMessage ( " \" %s<%d><STEAM_1:%d:%d><> \" has bad networkid (id \" %s \" ) (ip \" %s \" ) " ,
new_name , pPlayer - > GetUserId ( ) , accountId & 1 , accountId > > 1 , networkid_force , pPlayer - > GetIPAddress ( ) ) ;
pPlayer - > Kick ( " NetworkID spoofing detected. " ) ;
RETURN_META ( MRES_IGNORED ) ;
}
# endif
2008-03-30 09:00:22 +02:00
if ( strcmp ( old_name , new_name ) ! = 0 )
{
2014-05-29 19:31:12 +02:00
AdminId id = adminsys - > FindAdminByIdentity ( " name " , new_name ) ;
2008-07-08 11:20:47 +02:00
if ( id ! = INVALID_ADMIN_ID & & pPlayer - > GetAdminId ( ) ! = id )
2008-03-30 09:00:22 +02:00
{
2008-07-08 11:20:47 +02:00
if ( ! CheckSetAdminName ( client , pPlayer , id ) )
2008-03-30 09:00:22 +02:00
{
2013-04-08 14:00:13 +02:00
char kickMsg [ 128 ] ;
logicore . CoreTranslate ( kickMsg , sizeof ( kickMsg ) , " %T " , 2 , NULL , " Name Reserved " , & client ) ;
pPlayer - > Kick ( kickMsg ) ;
2008-03-30 09:00:22 +02:00
RETURN_META ( MRES_IGNORED ) ;
}
2014-05-29 19:31:12 +02:00
} else if ( ( id = adminsys - > FindAdminByIdentity ( " name " , old_name ) ) ! = INVALID_ADMIN_ID ) {
2008-07-08 11:20:47 +02:00
if ( id = = pPlayer - > GetAdminId ( ) )
2008-03-30 09:00:22 +02:00
{
/* This player is changing their name; force them to drop admin privileges! */
2008-07-08 11:20:47 +02:00
pPlayer - > SetAdminId ( INVALID_ADMIN_ID , false ) ;
2008-03-30 09:00:22 +02:00
}
}
2008-07-08 11:20:47 +02:00
pPlayer - > SetName ( new_name ) ;
2008-03-30 09:00:22 +02:00
}
if ( m_PassInfoVar . size ( ) > 0 )
{
/* Try for a password change */
2008-07-08 11:20:47 +02:00
const char * old_pass = pPlayer - > m_LastPassword . c_str ( ) ;
2008-03-30 09:00:22 +02:00
const char * new_pass = engine - > GetClientConVarValue ( client , m_PassInfoVar . c_str ( ) ) ;
if ( strcmp ( old_pass , new_pass ) ! = 0 )
{
2008-07-08 11:20:47 +02:00
pPlayer - > m_LastPassword . assign ( new_pass ) ;
if ( pPlayer - > IsInGame ( ) & & pPlayer - > IsAuthorized ( ) )
2008-03-30 09:00:22 +02:00
{
/* If there is already an admin id assigned, this will just bail out. */
2008-07-08 11:20:47 +02:00
pPlayer - > DoBasicAdminChecks ( ) ;
2008-03-30 09:00:22 +02:00
}
}
}
2011-03-08 21:59:42 +01:00
/* Notify Extensions */
List < IClientListener * > : : iterator iter ;
IClientListener * pListener = NULL ;
for ( iter = m_hooks . begin ( ) ; iter ! = m_hooks . end ( ) ; iter + + )
{
pListener = ( * iter ) ;
if ( pListener - > GetClientListenerVersion ( ) > = 13 )
{
pListener - > OnClientSettingsChanged ( client ) ;
}
}
2008-03-30 09:00:22 +02:00
}
int PlayerManager : : GetMaxClients ( )
{
2011-07-08 13:55:20 +02:00
return m_maxClients ;
2008-03-30 09:00:22 +02:00
}
CPlayer * PlayerManager : : GetPlayerByIndex ( int client ) const
{
2011-07-08 13:55:20 +02:00
if ( client > m_maxClients | | client < 1 )
2008-03-30 09:00:22 +02:00
{
return NULL ;
}
return & m_Players [ client ] ;
}
int PlayerManager : : GetNumPlayers ( )
{
return m_PlayerCount ;
}
int PlayerManager : : GetClientOfUserId ( int userid )
{
if ( userid < 0 | | userid > USHRT_MAX )
{
return 0 ;
}
int client = m_UserIdLookUp [ userid ] ;
/* Verify the userid. The cache can get messed up with older
* Valve engines . : TODO : If this gets fixed , do an old engine
* check before invoking this backwards compat code .
*/
if ( client )
{
CPlayer * player = GetPlayerByIndex ( client ) ;
if ( player & & player - > IsConnected ( ) )
{
2013-05-13 21:18:12 +02:00
int realUserId = GetPlayerUserId ( player - > GetEdict ( ) ) ;
2008-03-30 09:00:22 +02:00
if ( realUserId = = userid )
{
return client ;
}
}
}
/* If we can't verify the userid, we have to do a manual loop */
CPlayer * player ;
2011-07-08 13:55:20 +02:00
for ( int i = 1 ; i < = m_maxClients ; i + + )
2008-03-30 09:00:22 +02:00
{
player = GetPlayerByIndex ( i ) ;
if ( ! player | | ! player - > IsConnected ( ) )
{
continue ;
}
2013-05-13 21:18:12 +02:00
if ( GetPlayerUserId ( player - > GetEdict ( ) ) = = userid )
2008-03-30 09:00:22 +02:00
{
m_UserIdLookUp [ userid ] = i ;
return i ;
}
}
return 0 ;
}
void PlayerManager : : AddClientListener ( IClientListener * listener )
{
m_hooks . push_back ( listener ) ;
}
void PlayerManager : : RemoveClientListener ( IClientListener * listener )
{
m_hooks . remove ( listener ) ;
}
IGamePlayer * PlayerManager : : GetGamePlayer ( edict_t * pEdict )
{
2008-11-14 16:18:30 +01:00
int index = IndexOfEdict ( pEdict ) ;
2008-03-30 09:00:22 +02:00
return GetGamePlayer ( index ) ;
}
IGamePlayer * PlayerManager : : GetGamePlayer ( int client )
{
return GetPlayerByIndex ( client ) ;
}
void PlayerManager : : ClearAdminId ( AdminId id )
{
2011-07-08 13:55:20 +02:00
for ( int i = 1 ; i < = m_maxClients ; i + + )
2008-03-30 09:00:22 +02:00
{
if ( m_Players [ i ] . m_Admin = = id )
{
m_Players [ i ] . DumpAdmin ( true ) ;
}
}
}
const char * PlayerManager : : GetPassInfoVar ( )
{
return m_PassInfoVar . c_str ( ) ;
}
void PlayerManager : : RecheckAnyAdmins ( )
{
2011-07-08 13:55:20 +02:00
for ( int i = 1 ; i < = m_maxClients ; i + + )
2008-03-30 09:00:22 +02:00
{
if ( m_Players [ i ] . IsInGame ( ) & & m_Players [ i ] . IsAuthorized ( ) )
{
m_Players [ i ] . DoBasicAdminChecks ( ) ;
}
}
}
unsigned int PlayerManager : : GetReplyTo ( )
{
return g_ChatTriggers . GetReplyTo ( ) ;
}
unsigned int PlayerManager : : SetReplyTo ( unsigned int reply )
{
return g_ChatTriggers . SetReplyTo ( reply ) ;
}
int PlayerManager : : FilterCommandTarget ( IGamePlayer * pAdmin , IGamePlayer * pTarget , int flags )
{
return InternalFilterCommandTarget ( ( CPlayer * ) pAdmin , ( CPlayer * ) pTarget , flags ) ;
}
void PlayerManager : : RegisterCommandTargetProcessor ( ICommandTargetProcessor * pHandler )
{
target_processors . push_back ( pHandler ) ;
}
void PlayerManager : : UnregisterCommandTargetProcessor ( ICommandTargetProcessor * pHandler )
{
target_processors . remove ( pHandler ) ;
}
2008-07-08 11:20:47 +02:00
void PlayerManager : : InvalidatePlayer ( CPlayer * pPlayer )
{
/**
* Remove client from auth queue if necessary
*/
if ( ! pPlayer - > IsAuthorized ( ) )
{
for ( unsigned int i = 1 ; i < = m_AuthQueue [ 0 ] ; i + + )
{
if ( m_AuthQueue [ i ] = = ( unsigned ) pPlayer - > m_iIndex )
{
/* Move everything ahead of us back by one */
for ( unsigned int j = i + 1 ; j < = m_AuthQueue [ 0 ] ; j + + )
{
m_AuthQueue [ j - 1 ] = m_AuthQueue [ j ] ;
}
/* Remove us and break */
m_AuthQueue [ 0 ] - - ;
break ;
}
}
}
2013-05-13 21:18:12 +02:00
m_UserIdLookUp [ GetPlayerUserId ( pPlayer - > m_pEdict ) ] = 0 ;
2008-07-08 11:20:47 +02:00
pPlayer - > Disconnect ( ) ;
}
2008-03-30 09:00:22 +02:00
int PlayerManager : : InternalFilterCommandTarget ( CPlayer * pAdmin , CPlayer * pTarget , int flags )
{
if ( ( flags & COMMAND_FILTER_CONNECTED ) = = COMMAND_FILTER_CONNECTED
& & ! pTarget - > IsConnected ( ) )
{
return COMMAND_TARGET_NONE ;
}
else if ( ( flags & COMMAND_FILTER_CONNECTED ) ! = COMMAND_FILTER_CONNECTED & &
! pTarget - > IsInGame ( ) )
{
return COMMAND_TARGET_NOT_IN_GAME ;
}
if ( ( flags & COMMAND_FILTER_NO_BOTS ) = = COMMAND_FILTER_NO_BOTS
& & pTarget - > IsFakeClient ( ) )
{
return COMMAND_TARGET_NOT_HUMAN ;
}
if ( pAdmin ! = NULL )
{
if ( ( flags & COMMAND_FILTER_NO_IMMUNITY ) ! = COMMAND_FILTER_NO_IMMUNITY
2014-05-29 19:31:12 +02:00
& & ! adminsys - > CanAdminTarget ( pAdmin - > GetAdminId ( ) , pTarget - > GetAdminId ( ) ) )
2008-03-30 09:00:22 +02:00
{
return COMMAND_TARGET_IMMUNE ;
}
}
if ( ( flags & COMMAND_FILTER_ALIVE ) = = COMMAND_FILTER_ALIVE
& & pTarget - > GetLifeState ( ) ! = PLAYER_LIFE_ALIVE )
{
return COMMAND_TARGET_NOT_ALIVE ;
}
if ( ( flags & COMMAND_FILTER_DEAD ) = = COMMAND_FILTER_DEAD
& & pTarget - > GetLifeState ( ) ! = PLAYER_LIFE_DEAD )
{
return COMMAND_TARGET_NOT_DEAD ;
}
return COMMAND_TARGET_VALID ;
}
void PlayerManager : : ProcessCommandTarget ( cmd_target_info_t * info )
{
CPlayer * pTarget , * pAdmin ;
int max_clients , total = 0 ;
max_clients = GetMaxClients ( ) ;
if ( info - > max_targets < 1 )
{
info - > reason = COMMAND_TARGET_NONE ;
info - > num_targets = 0 ;
}
if ( info - > admin = = 0 )
{
pAdmin = NULL ;
}
else
{
pAdmin = GetPlayerByIndex ( info - > admin ) ;
}
if ( info - > pattern [ 0 ] = = ' # ' )
{
int userid = atoi ( & info - > pattern [ 1 ] ) ;
int client = GetClientOfUserId ( userid ) ;
/* See if a valid userid matched */
if ( client > 0 )
{
IGamePlayer * pTarget = GetPlayerByIndex ( client ) ;
if ( pTarget ! = NULL )
{
if ( ( info - > reason = FilterCommandTarget ( pAdmin , pTarget , info - > flags ) ) = = COMMAND_TARGET_VALID )
{
info - > targets [ 0 ] = client ;
info - > num_targets = 1 ;
strncopy ( info - > target_name , pTarget - > GetName ( ) , info - > target_name_maxlength ) ;
info - > target_name_style = COMMAND_TARGETNAME_RAW ;
}
else
{
info - > num_targets = 0 ;
}
return ;
}
}
/* Do we need to look for a steam id? */
if ( strncmp ( & info - > pattern [ 1 ] , " STEAM_ " , 6 ) = = 0 )
{
size_t p , len ;
char new_pattern [ 256 ] ;
strcpy ( new_pattern , " STEAM_ " ) ;
len = strlen ( & info - > pattern [ 7 ] ) ;
for ( p = 0 ; p < len ; p + + )
{
new_pattern [ 6 + p ] = info - > pattern [ 7 + p ] ;
if ( new_pattern [ 6 + p ] = = ' _ ' )
{
new_pattern [ 6 + p ] = ' : ' ;
}
}
new_pattern [ 6 + p ] = ' \0 ' ;
for ( int i = 1 ; i < = max_clients ; i + + )
{
if ( ( pTarget = GetPlayerByIndex ( i ) ) = = NULL )
{
continue ;
}
2013-03-07 01:58:17 +01:00
if ( ! pTarget - > IsConnected ( ) )
2008-03-30 09:00:22 +02:00
{
continue ;
}
2013-03-07 01:58:17 +01:00
const char * authstr = pTarget - > GetAuthString ( false ) ; // We want to make it easy for people to be kicked/banned, so don't require validation for command targets.
if ( authstr & & strcmp ( authstr , new_pattern ) = = 0 )
2008-03-30 09:00:22 +02:00
{
if ( ( info - > reason = FilterCommandTarget ( pAdmin , pTarget , info - > flags ) )
= = COMMAND_TARGET_VALID )
{
info - > targets [ 0 ] = i ;
info - > num_targets = 1 ;
strncopy ( info - > target_name , pTarget - > GetName ( ) , info - > target_name_maxlength ) ;
info - > target_name_style = COMMAND_TARGETNAME_RAW ;
}
else
{
info - > num_targets = 0 ;
}
return ;
}
}
}
/* See if an exact name matches */
for ( int i = 1 ; i < = max_clients ; i + + )
{
if ( ( pTarget = GetPlayerByIndex ( i ) ) = = NULL )
{
continue ;
}
if ( ! pTarget - > IsConnected ( ) )
{
continue ;
}
if ( strcmp ( pTarget - > GetName ( ) , & info - > pattern [ 1 ] ) = = 0 )
{
if ( ( info - > reason = FilterCommandTarget ( pAdmin , pTarget , info - > flags ) )
= = COMMAND_TARGET_VALID )
{
info - > targets [ 0 ] = i ;
info - > num_targets = 1 ;
strncopy ( info - > target_name , pTarget - > GetName ( ) , info - > target_name_maxlength ) ;
info - > target_name_style = COMMAND_TARGETNAME_RAW ;
}
else
{
info - > num_targets = 0 ;
}
return ;
}
}
}
if ( strcmp ( info - > pattern , " @me " ) = = 0 & & info - > admin ! = 0 )
{
2009-09-27 08:17:23 +02:00
info - > reason = FilterCommandTarget ( pAdmin , pAdmin , info - > flags ) ;
if ( info - > reason = = COMMAND_TARGET_VALID )
{
info - > targets [ 0 ] = info - > admin ;
info - > num_targets = 1 ;
strncopy ( info - > target_name , pAdmin - > GetName ( ) , info - > target_name_maxlength ) ;
info - > target_name_style = COMMAND_TARGETNAME_RAW ;
}
else
{
info - > num_targets = 0 ;
}
2008-03-30 09:00:22 +02:00
return ;
}
if ( ( info - > flags & COMMAND_FILTER_NO_MULTI ) ! = COMMAND_FILTER_NO_MULTI )
{
bool is_multi = false ;
bool bots_only = false ;
int skip_client = - 1 ;
if ( strcmp ( info - > pattern , " @all " ) = = 0 )
{
is_multi = true ;
strncopy ( info - > target_name , " all players " , info - > target_name_maxlength ) ;
info - > target_name_style = COMMAND_TARGETNAME_ML ;
}
else if ( strcmp ( info - > pattern , " @dead " ) = = 0 )
{
is_multi = true ;
if ( ( info - > flags & COMMAND_FILTER_ALIVE ) = = COMMAND_FILTER_ALIVE )
{
info - > num_targets = 0 ;
info - > reason = COMMAND_TARGET_NOT_ALIVE ;
return ;
}
info - > flags | = COMMAND_FILTER_DEAD ;
strncopy ( info - > target_name , " all dead players " , info - > target_name_maxlength ) ;
info - > target_name_style = COMMAND_TARGETNAME_ML ;
}
else if ( strcmp ( info - > pattern , " @alive " ) = = 0 )
{
is_multi = true ;
if ( ( info - > flags & COMMAND_FILTER_DEAD ) = = COMMAND_FILTER_DEAD )
{
info - > num_targets = 0 ;
info - > reason = COMMAND_TARGET_NOT_DEAD ;
return ;
}
strncopy ( info - > target_name , " all alive players " , info - > target_name_maxlength ) ;
info - > target_name_style = COMMAND_TARGETNAME_ML ;
info - > flags | = COMMAND_FILTER_ALIVE ;
}
else if ( strcmp ( info - > pattern , " @bots " ) = = 0 )
{
is_multi = true ;
if ( ( info - > flags & COMMAND_FILTER_NO_BOTS ) = = COMMAND_FILTER_NO_BOTS )
{
info - > num_targets = 0 ;
2013-03-10 04:20:31 +01:00
info - > reason = COMMAND_TARGET_NOT_HUMAN ;
2008-03-30 09:00:22 +02:00
return ;
}
strncopy ( info - > target_name , " all bots " , info - > target_name_maxlength ) ;
info - > target_name_style = COMMAND_TARGETNAME_ML ;
bots_only = true ;
}
else if ( strcmp ( info - > pattern , " @humans " ) = = 0 )
{
is_multi = true ;
strncopy ( info - > target_name , " all humans " , info - > target_name_maxlength ) ;
info - > target_name_style = COMMAND_TARGETNAME_ML ;
info - > flags | = COMMAND_FILTER_NO_BOTS ;
}
else if ( strcmp ( info - > pattern , " @!me " ) = = 0 )
{
is_multi = true ;
strncopy ( info - > target_name , " all players " , info - > target_name_maxlength ) ;
info - > target_name_style = COMMAND_TARGETNAME_ML ;
skip_client = info - > admin ;
}
if ( is_multi )
{
for ( int i = 1 ; i < = max_clients & & total < info - > max_targets ; i + + )
{
if ( ( pTarget = GetPlayerByIndex ( i ) ) = = NULL )
{
continue ;
}
if ( FilterCommandTarget ( pAdmin , pTarget , info - > flags ) > 0 )
{
if ( ( ! bots_only | | pTarget - > IsFakeClient ( ) )
& & skip_client ! = i )
{
info - > targets [ total + + ] = i ;
}
}
}
info - > num_targets = total ;
info - > reason = ( info - > num_targets ) ? COMMAND_TARGET_VALID : COMMAND_TARGET_EMPTY_FILTER ;
return ;
}
}
List < ICommandTargetProcessor * > : : iterator iter ;
for ( iter = target_processors . begin ( ) ; iter ! = target_processors . end ( ) ; iter + + )
{
ICommandTargetProcessor * pProcessor = ( * iter ) ;
if ( pProcessor - > ProcessCommandTarget ( info ) )
{
return ;
}
}
/* Check partial names */
int found_client = 0 ;
CPlayer * pFoundClient = NULL ;
for ( int i = 1 ; i < = max_clients ; i + + )
{
if ( ( pTarget = GetPlayerByIndex ( i ) ) = = NULL )
{
continue ;
}
2010-05-15 04:28:10 +02:00
if ( logicore . stristr ( pTarget - > GetName ( ) , info - > pattern ) ! = NULL )
2008-03-30 09:00:22 +02:00
{
if ( found_client )
{
info - > num_targets = 0 ;
info - > reason = COMMAND_TARGET_AMBIGUOUS ;
return ;
}
else
{
found_client = i ;
pFoundClient = pTarget ;
}
}
}
if ( found_client )
{
if ( ( info - > reason = FilterCommandTarget ( pAdmin , pFoundClient , info - > flags ) )
= = COMMAND_TARGET_VALID )
{
info - > targets [ 0 ] = found_client ;
info - > num_targets = 1 ;
strncopy ( info - > target_name , pFoundClient - > GetName ( ) , info - > target_name_maxlength ) ;
info - > target_name_style = COMMAND_TARGETNAME_RAW ;
}
else
{
info - > num_targets = 0 ;
}
}
else
{
info - > num_targets = 0 ;
info - > reason = COMMAND_TARGET_NONE ;
}
}
2011-07-08 13:55:20 +02:00
void PlayerManager : : OnSourceModMaxPlayersChanged ( int newvalue )
{
m_maxClients = newvalue ;
}
2008-09-26 09:08:49 +02:00
void PlayerManager : : MaxPlayersChanged ( int newvalue /*= -1*/ )
{
2009-05-12 23:27:45 +02:00
if ( ! m_FirstPass )
{
return ;
}
2008-09-26 09:08:49 +02:00
if ( newvalue = = - 1 )
{
newvalue = gpGlobals - > maxClients ;
}
if ( newvalue = = MaxClients ( ) )
{
return ;
}
/* Notify the rest of core */
SMGlobalClass * pBase = SMGlobalClass : : head ;
while ( pBase )
{
pBase - > OnSourceModMaxPlayersChanged ( newvalue ) ;
pBase = pBase - > m_pGlobalClassNext ;
}
/* Notify Extensions */
List < IClientListener * > : : iterator iter ;
IClientListener * pListener = NULL ;
for ( iter = m_hooks . begin ( ) ; iter ! = m_hooks . end ( ) ; iter + + )
{
pListener = ( * iter ) ;
if ( pListener - > GetClientListenerVersion ( ) > = 8 )
{
pListener - > OnMaxPlayersChanged ( newvalue ) ;
}
}
}
2009-02-19 07:19:44 +01:00
int PlayerManager : : GetClientFromSerial ( unsigned int serial )
{
serial_t s ;
s . value = serial ;
int client = s . bits . index ;
IGamePlayer * pPlayer = GetGamePlayer ( client ) ;
if ( ! pPlayer )
{
return 0 ;
}
if ( serial = = pPlayer - > GetSerial ( ) )
{
return client ;
}
return 0 ;
}
2013-04-23 13:11:49 +02:00
# if SOURCE_ENGINE == SE_DOTA
2013-07-12 08:31:41 +02:00
void CmdMaxplayersCallback ( const CCommandContext & context , const CCommand & command )
2013-04-23 13:11:49 +02:00
{
# elif SOURCE_ENGINE >= SE_ORANGEBOX
2008-09-26 09:08:49 +02:00
void CmdMaxplayersCallback ( const CCommand & command )
{
# else
void CmdMaxplayersCallback ( )
{
# endif
g_Players . MaxPlayersChanged ( ) ;
}
2008-03-30 09:00:22 +02:00
/*******************
* * * PLAYER CODE * * *
* * * * * * * * * * * * * * * * * * */
CPlayer : : CPlayer ( )
{
m_IsConnected = false ;
m_IsInGame = false ;
m_IsAuthorized = false ;
m_pEdict = NULL ;
m_Admin = INVALID_ADMIN_ID ;
m_TempAdmin = false ;
m_Info = NULL ;
m_bAdminCheckSignalled = false ;
2010-04-25 03:00:43 +02:00
m_UserId = - 1 ;
2008-03-30 09:00:22 +02:00
m_bIsInKickQueue = false ;
m_LastPassword . clear ( ) ;
2008-05-10 11:23:55 +02:00
m_LangId = SOURCEMOD_LANGUAGE_ENGLISH ;
2008-08-24 06:35:48 +02:00
m_bFakeClient = false ;
2011-10-21 03:39:57 +02:00
m_bIsSourceTV = false ;
m_bIsReplay = false ;
2011-10-12 06:51:58 +02:00
m_Serial . value = - 1 ;
2013-03-17 04:12:40 +01:00
m_SteamAccountID = 0 ;
2008-03-30 09:00:22 +02:00
}
void CPlayer : : Initialize ( const char * name , const char * ip , edict_t * pEntity )
{
m_IsConnected = true ;
m_Name . assign ( name ) ;
m_Ip . assign ( ip ) ;
m_pEdict = pEntity ;
2008-11-14 16:18:30 +01:00
m_iIndex = IndexOfEdict ( pEntity ) ;
2010-05-15 04:43:53 +02:00
m_LangId = translator - > GetServerLanguage ( ) ;
2008-03-30 09:00:22 +02:00
2009-02-19 07:19:44 +01:00
m_Serial . bits . index = m_iIndex ;
m_Serial . bits . serial = g_PlayerSerialCount + + ;
2008-03-30 09:00:22 +02:00
char ip2 [ 24 ] , * ptr ;
strncopy ( ip2 , ip , sizeof ( ip2 ) ) ;
if ( ( ptr = strchr ( ip2 , ' : ' ) ) ! = NULL )
{
* ptr = ' \0 ' ;
}
m_IpNoPort . assign ( ip2 ) ;
}
void CPlayer : : Connect ( )
{
if ( m_IsInGame )
{
return ;
}
m_IsInGame = true ;
const char * var = g_Players . GetPassInfoVar ( ) ;
2008-11-14 16:18:30 +01:00
int client = IndexOfEdict ( m_pEdict ) ;
2008-03-30 09:00:22 +02:00
if ( var [ 0 ] ! = ' \0 ' )
{
const char * pass = engine - > GetClientConVarValue ( client , var ) ;
m_LastPassword . assign ( pass ? pass : " " ) ;
}
else
{
m_LastPassword . assign ( " " ) ;
}
}
2013-03-07 01:58:17 +01:00
void CPlayer : : SetAuthString ( const char * steamid )
2008-03-30 09:00:22 +02:00
{
if ( m_IsAuthorized )
{
return ;
}
m_AuthID . assign ( steamid ) ;
}
2013-03-29 19:37:29 +01:00
// Ensure a valid AuthString is set before calling.
void CPlayer : : Authorize ( )
{
2013-03-07 01:58:17 +01:00
m_IsAuthorized = true ;
}
2008-03-30 09:00:22 +02:00
void CPlayer : : Disconnect ( )
{
DumpAdmin ( false ) ;
m_IsConnected = false ;
m_IsInGame = false ;
m_IsAuthorized = false ;
m_Name . clear ( ) ;
m_Ip . clear ( ) ;
m_AuthID . clear ( ) ;
m_pEdict = NULL ;
m_Info = NULL ;
m_bAdminCheckSignalled = false ;
m_UserId = - 1 ;
m_bIsInKickQueue = false ;
2008-08-24 06:35:48 +02:00
m_bFakeClient = false ;
2011-10-21 03:39:57 +02:00
m_bIsSourceTV = false ;
m_bIsReplay = false ;
2011-10-12 06:51:58 +02:00
m_Serial . value = - 1 ;
2013-03-17 04:12:40 +01:00
m_SteamAccountID = 0 ;
2008-03-30 09:00:22 +02:00
}
void CPlayer : : SetName ( const char * name )
{
m_Name . assign ( name ) ;
}
const char * CPlayer : : GetName ( )
{
if ( m_Info & & m_pEdict - > GetUnknown ( ) )
{
return m_Info - > GetName ( ) ;
}
return m_Name . c_str ( ) ;
}
const char * CPlayer : : GetIPAddress ( )
{
return m_Ip . c_str ( ) ;
}
2013-03-07 01:58:17 +01:00
const char * CPlayer : : GetAuthString ( bool validated )
2008-03-30 09:00:22 +02:00
{
2013-03-29 19:37:29 +01:00
if ( validated & & ! IsAuthStringValidated ( ) )
{
return NULL ;
2013-03-07 01:58:17 +01:00
}
2008-03-30 09:00:22 +02:00
return m_AuthID . c_str ( ) ;
}
2013-03-17 04:12:40 +01:00
unsigned int CPlayer : : GetSteamAccountID ( bool validated )
{
if ( IsFakeClient ( ) | | ( validated & & ! IsAuthStringValidated ( ) ) )
{
return 0 ;
}
if ( m_SteamAccountID ! = 0 )
{
return m_SteamAccountID ;
}
# if SOURCE_ENGINE < SE_ORANGEBOX
const char * pAuth = GetAuthString ( ) ;
/* STEAM_0:1:123123 | STEAM_ID_LAN | STEAM_ID_PENDING */
if ( pAuth & & ( strlen ( pAuth ) > 10 ) & & pAuth [ 8 ] ! = ' _ ' )
{
m_SteamAccountID = ( atoi ( & pAuth [ 8 ] ) | ( atoi ( & pAuth [ 10 ] ) < < 1 ) ) ;
}
# else
2013-05-13 21:18:12 +02:00
unsigned long long * steamId ;
# if SOURCE_ENGINE == SE_DOTA
steamId = ( unsigned long long * ) engine - > GetClientSteamID ( m_iIndex ) ;
# else
steamId = ( unsigned long long * ) engine - > GetClientSteamID ( m_pEdict ) ;
# endif
2013-03-17 04:12:40 +01:00
if ( steamId )
{
m_SteamAccountID = ( * steamId & 0xFFFFFFFF ) ;
}
# endif
return m_SteamAccountID ;
}
2008-03-30 09:00:22 +02:00
edict_t * CPlayer : : GetEdict ( )
{
return m_pEdict ;
}
2013-05-13 21:18:12 +02:00
int CPlayer : : GetIndex ( ) const
{
return m_iIndex ;
}
2008-03-30 09:00:22 +02:00
bool CPlayer : : IsInGame ( )
{
return m_IsInGame & & ( m_pEdict - > GetUnknown ( ) ! = NULL ) ;
}
bool CPlayer : : WasCountedAsInGame ( )
{
return m_IsInGame ;
}
bool CPlayer : : IsConnected ( )
{
return m_IsConnected ;
}
bool CPlayer : : IsAuthorized ( )
{
return m_IsAuthorized ;
}
2013-03-29 19:37:29 +01:00
bool CPlayer : : IsAuthStringValidated ( )
2013-03-07 01:58:17 +01:00
{
2012-05-24 18:55:46 +02:00
# if SOURCE_ENGINE >= SE_ORANGEBOX
2013-10-08 17:27:26 +02:00
if ( ! IsFakeClient ( ) & & g_Players . m_bAuthstringValidation & & ! g_HL2 . IsLANServer ( ) )
2013-03-29 19:37:29 +01:00
{
2013-05-13 21:18:12 +02:00
# if SOURCE_ENGINE == SE_DOTA
return engine - > IsClientFullyAuthenticated ( m_iIndex ) ;
# else
2013-03-29 19:37:29 +01:00
return engine - > IsClientFullyAuthenticated ( m_pEdict ) ;
2013-05-13 21:18:12 +02:00
# endif
2013-03-29 19:37:29 +01:00
}
# endif
2013-03-07 01:58:17 +01:00
return true ;
2012-05-24 18:55:46 +02:00
}
2008-03-30 09:00:22 +02:00
IPlayerInfo * CPlayer : : GetPlayerInfo ( )
{
if ( m_pEdict - > GetUnknown ( ) )
{
return m_Info ;
}
return NULL ;
}
bool CPlayer : : IsFakeClient ( )
{
2008-08-24 06:35:48 +02:00
return m_bFakeClient ;
2008-03-30 09:00:22 +02:00
}
2011-10-21 03:39:57 +02:00
bool CPlayer : : IsSourceTV ( ) const
{
return m_bIsSourceTV ;
}
bool CPlayer : : IsReplay ( ) const
{
return m_bIsReplay ;
}
2008-03-30 09:00:22 +02:00
void CPlayer : : SetAdminId ( AdminId id , bool temporary )
{
if ( ! m_IsConnected )
{
return ;
}
DumpAdmin ( false ) ;
m_Admin = id ;
m_TempAdmin = temporary ;
}
AdminId CPlayer : : GetAdminId ( )
{
return m_Admin ;
}
2014-05-29 19:31:12 +02:00
void CPlayer : : ClearAdmin ( )
{
DumpAdmin ( true ) ;
}
2008-03-30 09:00:22 +02:00
void CPlayer : : DumpAdmin ( bool deleting )
{
if ( m_Admin ! = INVALID_ADMIN_ID )
{
if ( m_TempAdmin & & ! deleting )
{
2014-05-29 19:31:12 +02:00
adminsys - > InvalidateAdmin ( m_Admin ) ;
2008-03-30 09:00:22 +02:00
}
m_Admin = INVALID_ADMIN_ID ;
m_TempAdmin = false ;
}
}
void CPlayer : : Kick ( const char * str )
{
MarkAsBeingKicked ( ) ;
INetChannel * pNetChan = static_cast < INetChannel * > ( engine - > GetPlayerNetInfo ( m_iIndex ) ) ;
2010-04-28 08:40:04 +02:00
if ( pNetChan = = NULL )
{
/* What does this even mean? Hell if I know. */
int userid = GetUserId ( ) ;
if ( userid > 0 )
{
char buffer [ 255 ] ;
UTIL_Format ( buffer , sizeof ( buffer ) , " kickid %d %s \n " , userid , str ) ;
engine - > ServerCommand ( buffer ) ;
}
}
else
{
IClient * pClient = static_cast < IClient * > ( pNetChan - > GetMsgHandler ( ) ) ;
2014-04-09 19:17:18 +02:00
# if SOURCE_ENGINE == SE_DOTA
// Including network_connection.pb.h (and .cpp) is overkill for just this. -p
// Copied from ENetworkDisconnectionReason enum
const int NETWORK_DISCONNECT_KICKED = 39 ;
pClient - > Disconnect ( NETWORK_DISCONNECT_KICKED ) ;
# elif SOURCE_ENGINE == SE_CSGO
2013-07-13 19:58:47 +02:00
pClient - > Disconnect ( str ) ;
# else
2010-04-28 08:40:04 +02:00
pClient - > Disconnect ( " %s " , str ) ;
2013-07-13 19:58:47 +02:00
# endif
2010-04-28 08:40:04 +02:00
}
2008-03-30 09:00:22 +02:00
}
void CPlayer : : Authorize_Post ( )
{
if ( m_IsInGame )
{
DoPostConnectAuthorization ( ) ;
}
}
void CPlayer : : DoPostConnectAuthorization ( )
{
bool delay = false ;
List < IClientListener * > : : iterator iter ;
for ( iter = g_Players . m_hooks . begin ( ) ;
iter ! = g_Players . m_hooks . end ( ) ;
iter + + )
{
IClientListener * pListener = ( * iter ) ;
# if defined MIN_API_FOR_ADMINCALLS
if ( pListener - > GetClientListenerVersion ( ) < MIN_API_FOR_ADMINCALLS )
{
continue ;
}
# endif
if ( ! pListener - > OnClientPreAdminCheck ( m_iIndex ) )
{
delay = true ;
}
}
cell_t result = 0 ;
PreAdminCheck - > PushCell ( m_iIndex ) ;
PreAdminCheck - > Execute ( & result ) ;
/* Defer, for better or worse */
if ( delay | | ( ResultType ) result > = Pl_Handled )
{
return ;
}
/* Sanity check */
if ( ! IsConnected ( ) )
{
return ;
}
/* Otherwise, go ahead and do admin checks */
DoBasicAdminChecks ( ) ;
/* Send the notification out */
NotifyPostAdminChecks ( ) ;
}
bool CPlayer : : RunAdminCacheChecks ( )
{
AdminId old_id = GetAdminId ( ) ;
DoBasicAdminChecks ( ) ;
return ( GetAdminId ( ) ! = old_id ) ;
}
void CPlayer : : NotifyPostAdminChecks ( )
{
if ( m_bAdminCheckSignalled )
{
return ;
}
/* Block beforehand so they can't double-call */
m_bAdminCheckSignalled = true ;
List < IClientListener * > : : iterator iter ;
for ( iter = g_Players . m_hooks . begin ( ) ;
iter ! = g_Players . m_hooks . end ( ) ;
iter + + )
{
IClientListener * pListener = ( * iter ) ;
# if defined MIN_API_FOR_ADMINCALLS
if ( pListener - > GetClientListenerVersion ( ) < MIN_API_FOR_ADMINCALLS )
{
continue ;
}
# endif
pListener - > OnClientPostAdminCheck ( m_iIndex ) ;
}
PostAdminFilter - > PushCell ( m_iIndex ) ;
PostAdminFilter - > Execute ( NULL ) ;
PostAdminCheck - > PushCell ( m_iIndex ) ;
PostAdminCheck - > Execute ( NULL ) ;
}
void CPlayer : : DoBasicAdminChecks ( )
{
if ( GetAdminId ( ) ! = INVALID_ADMIN_ID )
{
return ;
}
/* First check the name */
AdminId id ;
2008-11-14 16:18:30 +01:00
int client = IndexOfEdict ( m_pEdict ) ;
2008-03-30 09:00:22 +02:00
2014-05-29 19:31:12 +02:00
if ( ( id = adminsys - > FindAdminByIdentity ( " name " , GetName ( ) ) ) ! = INVALID_ADMIN_ID )
2008-03-30 09:00:22 +02:00
{
if ( ! g_Players . CheckSetAdminName ( client , this , id ) )
{
2013-05-13 21:18:12 +02:00
int userid = GetPlayerUserId ( m_pEdict ) ;
2008-03-30 09:00:22 +02:00
g_Timers . CreateTimer ( & s_KickPlayerTimer , 0.1f , ( void * ) userid , 0 ) ;
}
return ;
}
/* Check IP */
2014-05-29 19:31:12 +02:00
if ( ( id = adminsys - > FindAdminByIdentity ( " ip " , m_IpNoPort . c_str ( ) ) ) ! = INVALID_ADMIN_ID )
2008-03-30 09:00:22 +02:00
{
if ( g_Players . CheckSetAdmin ( client , this , id ) )
{
return ;
}
}
2008-11-25 07:13:08 +01:00
/* Check steam id */
2014-05-29 19:31:12 +02:00
if ( ( id = adminsys - > FindAdminByIdentity ( " steam " , m_AuthID . c_str ( ) ) ) ! = INVALID_ADMIN_ID )
2008-03-30 09:00:22 +02:00
{
if ( g_Players . CheckSetAdmin ( client , this , id ) )
{
return ;
}
}
}
unsigned int CPlayer : : GetLanguageId ( )
{
return m_LangId ;
}
2011-03-13 05:56:04 +01:00
void CPlayer : : SetLanguageId ( unsigned int id )
{
m_LangId = id ;
}
2008-03-30 09:00:22 +02:00
int CPlayer : : GetUserId ( )
{
if ( m_UserId = = - 1 )
{
2013-05-13 21:18:12 +02:00
m_UserId = GetPlayerUserId ( GetEdict ( ) ) ;
2008-03-30 09:00:22 +02:00
}
return m_UserId ;
}
bool CPlayer : : IsInKickQueue ( )
{
return m_bIsInKickQueue ;
}
void CPlayer : : MarkAsBeingKicked ( )
{
m_bIsInKickQueue = true ;
}
int CPlayer : : GetLifeState ( )
{
if ( lifestate_offset = = - 1 )
{
if ( ! g_pGameConf - > GetOffset ( " m_lifeState " , & lifestate_offset ) )
{
lifestate_offset = - 2 ;
}
}
if ( lifestate_offset < 0 )
{
IPlayerInfo * info = GetPlayerInfo ( ) ;
if ( info = = NULL )
{
return PLAYER_LIFE_UNKNOWN ;
}
return info - > IsDead ( ) ? PLAYER_LIFE_DEAD : PLAYER_LIFE_ALIVE ;
}
if ( m_pEdict = = NULL )
{
return PLAYER_LIFE_UNKNOWN ;
}
CBaseEntity * pEntity ;
IServerUnknown * pUnknown = m_pEdict - > GetUnknown ( ) ;
if ( pUnknown = = NULL | | ( pEntity = pUnknown - > GetBaseEntity ( ) ) = = NULL )
{
return PLAYER_LIFE_UNKNOWN ;
}
if ( * ( ( uint8_t * ) pEntity + lifestate_offset ) = = LIFE_ALIVE )
{
return PLAYER_LIFE_ALIVE ;
}
else
{
return PLAYER_LIFE_DEAD ;
}
}
2009-02-19 07:19:44 +01:00
unsigned int CPlayer : : GetSerial ( )
{
return m_Serial . value ;
2009-02-19 07:35:45 +01:00
}
2014-01-30 05:41:41 +01:00
void CPlayer : : PrintToConsole ( const char * pMsg )
{
if ( m_IsConnected = = false | | m_bFakeClient = = true )
{
return ;
}
INetChannel * pNetChan = static_cast < INetChannel * > ( engine - > GetPlayerNetInfo ( m_iIndex ) ) ;
if ( pNetChan = = NULL )
{
return ;
}
# if SOURCE_ENGINE == SE_DOTA
engine - > ClientPrintf ( m_iIndex , pMsg ) ;
# else
engine - > ClientPrintf ( m_pEdict , pMsg ) ;
# endif
}