core/PlayerManager.h
author Matt Woodrow <pred@alliedmods.net>
Tue Mar 11 23:52:56 2008 +0000 (2008-03-11)
changeset 1921 f993e100e5a3
parent 1688 513a3b2dd86d
child 1947 e73a1e51833b
permissions -rw-r--r--
Fixed bug in GetAdjustedTime()
     1 /**
     2  * vim: set ts=4 :
     3  * =============================================================================
     4  * SourceMod
     5  * Copyright (C) 2004-2007 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 
    45 using namespace SourceHook;
    46 
    47 #define PLAYER_LIFE_UNKNOWN	0
    48 #define PLAYER_LIFE_ALIVE	1
    49 #define PLAYER_LIFE_DEAD	2
    50 
    51 #define MIN_API_FOR_ADMINCALLS		7
    52 
    53 class CPlayer : public IGamePlayer
    54 {
    55 	friend class PlayerManager;
    56 public:
    57 	CPlayer();
    58 public:
    59 	const char *GetName();
    60 	const char *GetIPAddress();
    61 	const char *GetAuthString();
    62 	edict_t *GetEdict();
    63 	bool IsInGame();
    64 	bool WasCountedAsInGame();
    65 	bool IsConnected();
    66 	bool IsAuthorized();
    67 	bool IsFakeClient();
    68 	void SetAdminId(AdminId id, bool temporary);
    69 	AdminId GetAdminId();
    70 	void Kick(const char *str);
    71 	IPlayerInfo *GetPlayerInfo();
    72 	unsigned int GetLanguageId();
    73 	int GetUserId();
    74 	bool RunAdminCacheChecks();
    75 	void NotifyPostAdminChecks();
    76 public:
    77 	void DoBasicAdminChecks();
    78 	bool IsInKickQueue();
    79 	void MarkAsBeingKicked();
    80 	int GetLifeState();
    81 private:
    82 	void Initialize(const char *name, const char *ip, edict_t *pEntity);
    83 	void Connect();
    84 	void Disconnect();
    85 	void SetName(const char *name);
    86 	void DumpAdmin(bool deleting);
    87 	void Authorize(const char *auth);
    88 	void Authorize_Post();
    89 	void DoPostConnectAuthorization();
    90 private:
    91 	bool m_IsConnected;
    92 	bool m_IsInGame;
    93 	bool m_IsAuthorized;
    94 	bool m_bIsInKickQueue;
    95 	String m_Name;
    96 	String m_Ip;
    97 	String m_IpNoPort;
    98 	String m_AuthID;
    99 	AdminId m_Admin;
   100 	bool m_TempAdmin;
   101 	edict_t *m_pEdict;
   102 	IPlayerInfo *m_Info;
   103 	String m_LastPassword;
   104 	bool m_bAdminCheckSignalled;
   105 	int m_iIndex;
   106 	unsigned int m_LangId;
   107 	int m_UserId;
   108 };
   109 
   110 class PlayerManager : 
   111 	public SMGlobalClass,
   112 	public IPlayerManager
   113 {
   114 	friend class CPlayer;
   115 public:
   116 	PlayerManager();
   117 	~PlayerManager();
   118 public: //SMGlobalClass
   119 	void OnSourceModAllInitialized();
   120 	void OnSourceModShutdown();
   121 	void OnSourceModLevelEnd();
   122 	ConfigResult OnSourceModConfigChanged(const char *key, const char *value, ConfigSource source, char *error, size_t maxlength);
   123 public:
   124 	CPlayer *GetPlayerByIndex(int client) const;
   125 	void RunAuthChecks();
   126 	void ClearAdminId(AdminId id);
   127 	void ClearAllAdmins();
   128 public:
   129 	bool OnClientConnect(edict_t *pEntity, const char *pszName, const char *pszAddress, char *reject, int maxrejectlen);
   130 	bool OnClientConnect_Post(edict_t *pEntity, const char *pszName, const char *pszAddress, char *reject, int maxrejectlen);
   131 	void OnClientPutInServer(edict_t *pEntity, char const *playername);
   132 	void OnClientDisconnect(edict_t *pEntity);
   133 	void OnClientDisconnect_Post(edict_t *pEntity);
   134 #if defined ORANGEBOX_BUILD
   135 	void OnClientCommand(edict_t *pEntity, const CCommand &args);
   136 #else
   137 	void OnClientCommand(edict_t *pEntity);
   138 #endif
   139 	void OnClientSettingsChanged(edict_t *pEntity);
   140 	//void OnClientSettingsChanged_Pre(edict_t *pEntity);
   141 public: //IPlayerManager
   142 	void AddClientListener(IClientListener *listener);
   143 	void RemoveClientListener(IClientListener *listener);
   144 	IGamePlayer *GetGamePlayer(int client);
   145 	IGamePlayer *GetGamePlayer(edict_t *pEdict);
   146 	int GetMaxClients();
   147 	int GetNumPlayers();
   148 	int GetClientOfUserId(int userid);
   149 	bool IsServerActivated();
   150 	int FilterCommandTarget(IGamePlayer *pAdmin, IGamePlayer *pTarget, int flags);
   151 	int InternalFilterCommandTarget(CPlayer *pAdmin, CPlayer *pTarget, int flags);
   152 	void RegisterCommandTargetProcessor(ICommandTargetProcessor *pHandler);
   153 	void UnregisterCommandTargetProcessor(ICommandTargetProcessor *pHandler);
   154 	void ProcessCommandTarget(cmd_target_info_t *info);
   155 public:
   156 	inline int MaxClients()
   157 	{
   158 		return m_maxClients;
   159 	}
   160 	inline int NumPlayers()
   161 	{
   162 		return m_PlayerCount;
   163 	}
   164 	bool CheckSetAdmin(int index, CPlayer *pPlayer, AdminId id);
   165 	bool CheckSetAdminName(int index, CPlayer *pPlayer, AdminId id);
   166 	const char *GetPassInfoVar();
   167 	void RecheckAnyAdmins();
   168 	unsigned int GetReplyTo();
   169 	unsigned int SetReplyTo(unsigned int reply);
   170 private:
   171 	void OnServerActivate(edict_t *pEdictList, int edictCount, int clientMax);
   172 private:
   173 	List<IClientListener *> m_hooks;
   174 	IForward *m_clconnect;
   175 	IForward *m_cldisconnect;
   176 	IForward *m_cldisconnect_post;
   177 	IForward *m_clputinserver;
   178 	IForward *m_clcommand;
   179 	IForward *m_clinfochanged;
   180 	IForward *m_clauth;
   181 	IForward *m_onActivate;
   182 	IForward *m_onActivate2;
   183 	CPlayer *m_Players;
   184 	int *m_UserIdLookUp;
   185 	int m_maxClients;
   186 	int m_PlayerCount;
   187 	bool m_FirstPass;
   188 	unsigned int *m_AuthQueue;
   189 	String m_PassInfoVar;
   190 	bool m_QueryLang;
   191 };
   192 
   193 extern PlayerManager g_Players;
   194 extern bool g_OnMapStarted;
   195 extern const unsigned int *g_NumPlayersToAuth;
   196 
   197 #endif //_INCLUDE_SOURCEMOD_CPLAYERMANAGER_H_