core/PlayerManager.h
author David Anderson <dvander@alliedmods.net>
Wed Aug 01 02:12:47 2007 +0000 (2007-08-01)
changeset 1231 17badaf66ce4
parent 1162 7c42828c9c0f
child 1273 9afc766f8e9c
permissions -rw-r--r--
updated more header files (mostly internal now)
     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 
     9  * modify it under the terms of the GNU General Public License, 
    10  * version 3.0, as published by the Free Software Foundation.
    11  * 
    12  * This program is distributed in the hope that it will be useful,
    13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
    14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    15  * GNU General Public License for more details.
    16  *
    17  * You should have received a copy of the GNU General Public License
    18  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
    19  *
    20  * As a special exception, AlliedModders LLC gives you permission to 
    21  * link the code of this program (as well as its derivative works) to 
    22  * "Half-Life 2," the "Source Engine," the "SourcePawn JIT," and any 
    23  * Game MODs that run on software by the Valve Corporation.  You must 
    24  * obey the GNU General Public License in all respects for all other 
    25  * code used. Additionally, AlliedModders LLC grants this exception 
    26  * to all derivative works. AlliedModders LLC defines further 
    27  * exceptions, found in LICENSE.txt (as of this writing, version 
    28  * JULY-31-2007), or <http://www.sourcemod.net/license.php>.
    29  *
    30  * Version: $Id$
    31  */
    32 
    33 #ifndef _INCLUDE_SOURCEMOD_CPLAYERMANAGER_H_
    34 #define _INCLUDE_SOURCEMOD_CPLAYERMANAGER_H_
    35 
    36 #include "sm_globals.h"
    37 #include <eiface.h>
    38 #include "sourcemm_api.h"
    39 #include <IForwardSys.h>
    40 #include <IPlayerHelpers.h>
    41 #include <IAdminSystem.h>
    42 #include <sh_string.h>
    43 #include <sh_list.h>
    44 #include <sh_vector.h>
    45 
    46 using namespace SourceHook;
    47 
    48 class CPlayer : public IGamePlayer
    49 {
    50 	friend class PlayerManager;
    51 public:
    52 	CPlayer();
    53 public:
    54 	const char *GetName();
    55 	const char *GetIPAddress();
    56 	const char *GetAuthString();
    57 	edict_t *GetEdict();
    58 	bool IsInGame();
    59 	bool IsConnected();
    60 	bool IsAuthorized();
    61 	bool IsFakeClient();
    62 	void SetAdminId(AdminId id, bool temporary);
    63 	AdminId GetAdminId();
    64 	void Kick(const char *str);
    65 public:
    66 	IPlayerInfo *GetPlayerInfo();
    67 private:
    68 	void Initialize(const char *name, const char *ip, edict_t *pEntity);
    69 	void Connect();
    70 	void Disconnect();
    71 	void SetName(const char *name);
    72 	void DumpAdmin(bool deleting);
    73 	void Authorize(const char *auth);
    74 	void Authorize_Post();
    75 	void DoBasicAdminChecks();
    76 private:
    77 	bool m_IsConnected;
    78 	bool m_IsInGame;
    79 	bool m_IsAuthorized;
    80 	String m_Name;
    81 	String m_Ip;
    82 	String m_IpNoPort;
    83 	String m_AuthID;
    84 	AdminId m_Admin;
    85 	bool m_TempAdmin;
    86 	edict_t *m_pEdict;
    87 	IPlayerInfo *m_Info;
    88 	String m_LastPassword;
    89 };
    90 
    91 class PlayerManager : 
    92 	public SMGlobalClass,
    93 	public IPlayerManager
    94 {
    95 public:
    96 	PlayerManager();
    97 	~PlayerManager();
    98 public: //SMGlobalClass
    99 	void OnSourceModAllInitialized();
   100 	void OnSourceModShutdown();
   101 	void OnSourceModLevelEnd();
   102 	ConfigResult OnSourceModConfigChanged(const char *key, const char *value, ConfigSource source, char *error, size_t maxlength);
   103 public:
   104 	CPlayer *GetPlayerByIndex(int client) const;
   105 	void RunAuthChecks();
   106 	void ClearAdminId(AdminId id);
   107 	void ClearAllAdmins();
   108 public:
   109 	bool OnClientConnect(edict_t *pEntity, const char *pszName, const char *pszAddress, char *reject, int maxrejectlen);
   110 	bool OnClientConnect_Post(edict_t *pEntity, const char *pszName, const char *pszAddress, char *reject, int maxrejectlen);
   111 	void OnClientPutInServer(edict_t *pEntity, char const *playername);
   112 	void OnClientDisconnect(edict_t *pEntity);
   113 	void OnClientDisconnect_Post(edict_t *pEntity);
   114 	void OnClientCommand(edict_t *pEntity);
   115 	void OnClientSettingsChanged(edict_t *pEntity);
   116 	//void OnClientSettingsChanged_Pre(edict_t *pEntity);
   117 public: //IPlayerManager
   118 	void AddClientListener(IClientListener *listener);
   119 	void RemoveClientListener(IClientListener *listener);
   120 	IGamePlayer *GetGamePlayer(int client);
   121 	IGamePlayer *GetGamePlayer(edict_t *pEdict);
   122 	int GetMaxClients();
   123 	int GetNumPlayers();
   124 	int GetClientOfUserId(int userid);
   125 public:
   126 	inline int MaxClients()
   127 	{
   128 		return m_maxClients;
   129 	}
   130 	inline int NumPlayers()
   131 	{
   132 		return m_PlayerCount;
   133 	}
   134 	bool CheckSetAdmin(int index, CPlayer *pPlayer, AdminId id);
   135 	bool CheckSetAdminName(int index, CPlayer *pPlayer, AdminId id);
   136 	const char *GetPassInfoVar();
   137 	void RecheckAnyAdmins();
   138 private:
   139 	void OnServerActivate(edict_t *pEdictList, int edictCount, int clientMax);
   140 private:
   141 	List<IClientListener *> m_hooks;
   142 	IForward *m_clconnect;
   143 	IForward *m_cldisconnect;
   144 	IForward *m_cldisconnect_post;
   145 	IForward *m_clputinserver;
   146 	IForward *m_clcommand;
   147 	IForward *m_clinfochanged;
   148 	IForward *m_clauth;
   149 	IForward *m_onActivate;
   150 	IForward *m_onActivate2;
   151 	CPlayer *m_Players;
   152 	int *m_UserIdLookUp;
   153 	int m_maxClients;
   154 	int m_PlayerCount;
   155 	bool m_FirstPass;
   156 	unsigned int *m_AuthQueue;
   157 	String m_PassInfoVar;
   158 };
   159 
   160 extern PlayerManager g_Players;
   161 extern bool g_OnMapStarted;
   162 
   163 #endif //_INCLUDE_SOURCEMOD_CPLAYERMANAGER_H_