core/PlayerManager.h
author Nicholas Hastings <skamonkey@gmail.com>
Tue Apr 23 07:11:49 2013 -0400 (2013-04-23)
changeset 3899 fd4ec50a0d6c
parent 3825 ecd2382ca37e
child 3911 5fcb7681aebd
permissions -rw-r--r--
Build fixes for recent hl2sdk-dota updates.
     1 /**
     2  * vim: set ts=4 :
     3  * =============================================================================
     4  * SourceMod
     5  * Copyright (C) 2004-2008 AlliedModders LLC.  All rights reserved.
     6  * =============================================================================
     7  *
     8  * This program is free software; you can redistribute it and/or modify it under
     9  * the terms of the GNU General Public License, version 3.0, as published by the
    10  * Free Software Foundation.
    11  * 
    12  * This program is distributed in the hope that it will be useful, but WITHOUT
    13  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
    14  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
    15  * details.
    16  *
    17  * You should have received a copy of the GNU General Public License along with
    18  * this program.  If not, see <http://www.gnu.org/licenses/>.
    19  *
    20  * As a special exception, AlliedModders LLC gives you permission to link the
    21  * code of this program (as well as its derivative works) to "Half-Life 2," the
    22  * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
    23  * by the Valve Corporation.  You must obey the GNU General Public License in
    24  * all respects for all other code used.  Additionally, AlliedModders LLC grants
    25  * this exception to all derivative works.  AlliedModders LLC defines further
    26  * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
    27  * or <http://www.sourcemod.net/license.php>.
    28  *
    29  * Version: $Id$
    30  */
    31 
    32 #ifndef _INCLUDE_SOURCEMOD_CPLAYERMANAGER_H_
    33 #define _INCLUDE_SOURCEMOD_CPLAYERMANAGER_H_
    34 
    35 #include "sm_globals.h"
    36 #include <eiface.h>
    37 #include "sourcemm_api.h"
    38 #include <IForwardSys.h>
    39 #include <IPlayerHelpers.h>
    40 #include <IAdminSystem.h>
    41 #include <sh_string.h>
    42 #include <sh_list.h>
    43 #include <sh_vector.h>
    44 #include "ConVarManager.h"
    45 
    46 using namespace SourceHook;
    47 
    48 #define PLAYER_LIFE_UNKNOWN	0
    49 #define PLAYER_LIFE_ALIVE	1
    50 #define PLAYER_LIFE_DEAD	2
    51 
    52 #define MIN_API_FOR_ADMINCALLS		7
    53 
    54 union serial_t
    55 {
    56 	uint32_t   value;
    57 	struct
    58 	{
    59 		uint32_t index  :  8;
    60 		uint32_t serial : 24;
    61 	} bits;
    62 };
    63 
    64 class CPlayer : public IGamePlayer
    65 {
    66 	friend class PlayerManager;
    67 public:
    68 	CPlayer();
    69 public:
    70 	const char *GetName();
    71 	const char *GetIPAddress();
    72 	const char *GetAuthString(bool validated = true);
    73 	unsigned int GetSteamAccountID(bool validated = true);
    74 	edict_t *GetEdict();
    75 	bool IsInGame();
    76 	bool WasCountedAsInGame();
    77 	bool IsConnected();
    78 	bool IsAuthorized();
    79 	bool IsFakeClient();
    80 	bool IsSourceTV() const;
    81 	bool IsReplay() const;
    82 	void SetAdminId(AdminId id, bool temporary);
    83 	AdminId GetAdminId();
    84 	void Kick(const char *str);
    85 	bool IsInKickQueue();
    86 	IPlayerInfo *GetPlayerInfo();
    87 	unsigned int GetLanguageId();
    88 	void SetLanguageId(unsigned int id);
    89 	int GetUserId();
    90 	bool RunAdminCacheChecks();
    91 	void NotifyPostAdminChecks();
    92 	unsigned int GetSerial();
    93 public:
    94 	void DoBasicAdminChecks();
    95 	void MarkAsBeingKicked();
    96 	int GetLifeState();
    97 private:
    98 	void Initialize(const char *name, const char *ip, edict_t *pEntity);
    99 	void Connect();
   100 	void Disconnect();
   101 	void SetName(const char *name);
   102 	void DumpAdmin(bool deleting);
   103 	void SetAuthString(const char *auth);
   104 	void Authorize();
   105 	void Authorize_Post();
   106 	void DoPostConnectAuthorization();
   107 	bool IsAuthStringValidated();
   108 private:
   109 	bool m_IsConnected;
   110 	bool m_IsInGame;
   111 	bool m_IsAuthorized;
   112 	bool m_bIsInKickQueue;
   113 	String m_Name;
   114 	String m_Ip;
   115 	String m_IpNoPort;
   116 	String m_AuthID;
   117 	AdminId m_Admin;
   118 	bool m_TempAdmin;
   119 	edict_t *m_pEdict;
   120 	IPlayerInfo *m_Info;
   121 	String m_LastPassword;
   122 	bool m_bAdminCheckSignalled;
   123 	int m_iIndex;
   124 	unsigned int m_LangId;
   125 	int m_UserId;
   126 	bool m_bFakeClient;
   127 	bool m_bIsSourceTV;
   128 	bool m_bIsReplay;
   129 	serial_t m_Serial;
   130 	unsigned int m_SteamAccountID;
   131 };
   132 
   133 class PlayerManager : 
   134 	public SMGlobalClass,
   135 	public IPlayerManager
   136 {
   137 	friend class CPlayer;
   138 public:
   139 	PlayerManager();
   140 	~PlayerManager();
   141 public: //SMGlobalClass
   142 	void OnSourceModAllInitialized();
   143 	void OnSourceModShutdown();
   144 	void OnSourceModLevelEnd();
   145 	ConfigResult OnSourceModConfigChanged(const char *key, const char *value, ConfigSource source, char *error, size_t maxlength);
   146 	void OnSourceModMaxPlayersChanged(int newvalue);
   147 public:
   148 	CPlayer *GetPlayerByIndex(int client) const;
   149 	void RunAuthChecks();
   150 	void ClearAdminId(AdminId id);
   151 	void ClearAllAdmins();
   152 public:
   153 	bool OnClientConnect(edict_t *pEntity, const char *pszName, const char *pszAddress, char *reject, int maxrejectlen);
   154 	bool OnClientConnect_Post(edict_t *pEntity, const char *pszName, const char *pszAddress, char *reject, int maxrejectlen);
   155 	void OnClientPutInServer(edict_t *pEntity, char const *playername);
   156 	void OnClientDisconnect(edict_t *pEntity);
   157 	void OnClientDisconnect_Post(edict_t *pEntity);
   158 #if SOURCE_ENGINE >= SE_ORANGEBOX
   159 	void OnClientCommand(edict_t *pEntity, const CCommand &args);
   160 #else
   161 	void OnClientCommand(edict_t *pEntity);
   162 #endif
   163 	void OnClientSettingsChanged(edict_t *pEntity);
   164 	//void OnClientSettingsChanged_Pre(edict_t *pEntity);
   165 public: //IPlayerManager
   166 	void AddClientListener(IClientListener *listener);
   167 	void RemoveClientListener(IClientListener *listener);
   168 	IGamePlayer *GetGamePlayer(int client);
   169 	IGamePlayer *GetGamePlayer(edict_t *pEdict);
   170 	int GetMaxClients();
   171 	int GetNumPlayers();
   172 	int GetClientOfUserId(int userid);
   173 	bool IsServerActivated();
   174 	int FilterCommandTarget(IGamePlayer *pAdmin, IGamePlayer *pTarget, int flags);
   175 	int InternalFilterCommandTarget(CPlayer *pAdmin, CPlayer *pTarget, int flags);
   176 	void RegisterCommandTargetProcessor(ICommandTargetProcessor *pHandler);
   177 	void UnregisterCommandTargetProcessor(ICommandTargetProcessor *pHandler);
   178 	void ProcessCommandTarget(cmd_target_info_t *info);
   179 	int GetClientFromSerial(unsigned int serial);
   180 public:
   181 	inline int MaxClients()
   182 	{
   183 		return m_maxClients;
   184 	}
   185 	inline int NumPlayers()
   186 	{
   187 		return m_PlayerCount;
   188 	}
   189 	inline int ListenClient()
   190 	{
   191 		return m_ListenClient;
   192 	}
   193 	bool CheckSetAdmin(int index, CPlayer *pPlayer, AdminId id);
   194 	bool CheckSetAdminName(int index, CPlayer *pPlayer, AdminId id);
   195 	const char *GetPassInfoVar();
   196 	void RecheckAnyAdmins();
   197 	unsigned int GetReplyTo();
   198 	unsigned int SetReplyTo(unsigned int reply);
   199 	void MaxPlayersChanged(int newvalue = -1);
   200 private:
   201 	void OnServerActivate(edict_t *pEdictList, int edictCount, int clientMax);
   202 	void InvalidatePlayer(CPlayer *pPlayer);
   203 private:
   204 	List<IClientListener *> m_hooks;
   205 	IForward *m_clconnect;
   206 	IForward *m_clconnect_post;
   207 	IForward *m_cldisconnect;
   208 	IForward *m_cldisconnect_post;
   209 	IForward *m_clputinserver;
   210 	IForward *m_clcommand;
   211 	IForward *m_clinfochanged;
   212 	IForward *m_clauth;
   213 	IForward *m_onActivate;
   214 	IForward *m_onActivate2;
   215 	CPlayer *m_Players;
   216 	int *m_UserIdLookUp;
   217 	int m_maxClients;
   218 	int m_PlayerCount;
   219 	int m_PlayersSinceActive;
   220 	bool m_FirstPass;
   221 	unsigned int *m_AuthQueue;
   222 	String m_PassInfoVar;
   223 	bool m_QueryLang;
   224 	bool m_bAuthstringValidation; // are we validating admins with steam before authorizing?
   225 	bool m_bIsListenServer;
   226 	int m_ListenClient;
   227 	bool m_bIsSourceTVActive;
   228 	bool m_bIsReplayActive;
   229 	int m_SourceTVUserId;
   230 	int m_ReplayUserId;
   231 };
   232 
   233 #if SOURCE_ENGINE == SE_DOTA
   234 void CmdMaxplayersCallback(void *, const CCommand &command);
   235 #elif SOURCE_ENGINE >= SE_ORANGEBOX
   236 void CmdMaxplayersCallback(const CCommand &command);
   237 #else
   238 void CmdMaxplayersCallback();
   239 #endif
   240 
   241 extern void ClientConsolePrint(edict_t *e, const char *fmt, ...);
   242 
   243 extern PlayerManager g_Players;
   244 extern bool g_OnMapStarted;
   245 extern const unsigned int *g_NumPlayersToAuth;
   246 
   247 #endif //_INCLUDE_SOURCEMOD_CPLAYERMANAGER_H_