core/PlayerManager.h
author David Anderson <dvander@alliedmods.net>
Sat Mar 10 21:18:07 2007 +0000 (2007-03-10)
changeset 591 86e97f3eda1f
child 615 c4aa259cca88
permissions -rw-r--r--
part 1 of singleton renaming
     1 /**
     2  * ===============================================================
     3  * SourceMod (C)2004-2007 AlliedModders LLC.  All rights reserved.
     4  * ===============================================================
     5  *
     6  * This file is not open source and may not be copied without explicit
     7  * written permission of AlliedModders LLC.  This file may not be redistributed 
     8  * in whole or significant part.
     9  * For information, see LICENSE.txt or http://www.sourcemod.net/license.php
    10  *
    11  * Version: $Id$
    12  */
    13 
    14 #ifndef _INCLUDE_SOURCEMOD_CPLAYERMANAGER_H_
    15 #define _INCLUDE_SOURCEMOD_CPLAYERMANAGER_H_
    16 
    17 #include "sm_globals.h"
    18 #include <eiface.h>
    19 #include "sourcemm_api.h"
    20 #include <IForwardSys.h>
    21 #include <IPlayerHelpers.h>
    22 #include <IAdminSystem.h>
    23 #include <sh_string.h>
    24 #include <sh_list.h>
    25 #include <sh_vector.h>
    26 
    27 using namespace SourceHook;
    28 
    29 class CPlayer : public IGamePlayer
    30 {
    31 	friend class CPlayerManager;
    32 public:
    33 	CPlayer();
    34 public:
    35 	const char *GetName() const;
    36 	const char *GetIPAddress() const;
    37 	const char *GetAuthString() const;
    38 	edict_t *GetEdict() const;
    39 	bool IsInGame() const;
    40 	bool IsConnected() const;
    41 	bool IsAuthorized() const;
    42 	bool IsFakeClient() const;
    43 	void SetAdminId(AdminId id, bool temporary);
    44 	AdminId GetAdminId() const;
    45 private:
    46 	void Initialize(const char *name, const char *ip, edict_t *pEntity);
    47 	void Connect();
    48 	void Authorize(const char *steamid);
    49 	void Disconnect();
    50 	void SetName(const char *name);
    51 	void DumpAdmin(bool deleting);
    52 private:
    53 	bool m_IsConnected;
    54 	bool m_IsInGame;
    55 	bool m_IsAuthorized;
    56 	String m_Name;
    57 	String m_Ip;
    58 	String m_AuthID;
    59 	AdminId m_Admin;
    60 	bool m_TempAdmin;
    61 	edict_t *m_pEdict;
    62 };
    63 
    64 class CPlayerManager : 
    65 	public SMGlobalClass,
    66 	public IPlayerManager
    67 {
    68 public:
    69 	CPlayerManager();
    70 	~CPlayerManager();
    71 public: //SMGlobalClass
    72 	void OnSourceModAllInitialized();
    73 	void OnSourceModShutdown();
    74 public:
    75 	CPlayer *GetPlayerByIndex(int client) const;
    76 	void RunAuthChecks();
    77 	void ClearAdminId(AdminId id);
    78 	void ClearAllAdmins();
    79 public:
    80 	bool OnClientConnect(edict_t *pEntity, const char *pszName, const char *pszAddress, char *reject, int maxrejectlen);
    81 	bool OnClientConnect_Post(edict_t *pEntity, const char *pszName, const char *pszAddress, char *reject, int maxrejectlen);
    82 	void OnClientPutInServer(edict_t *pEntity, char const *playername);
    83 	void OnClientDisconnect(edict_t *pEntity);
    84 	void OnClientDisconnect_Post(edict_t *pEntity);
    85 	void OnClientCommand(edict_t *pEntity);
    86 	void OnClientSettingsChanged(edict_t *pEntity);
    87 public: //IPlayerManager
    88 	void AddClientListener(IClientListener *listener);
    89 	void RemoveClientListener(IClientListener *listener);
    90 	IGamePlayer *GetGamePlayer(int client);
    91 	IGamePlayer *GetGamePlayer(edict_t *pEdict);
    92 	int GetMaxClients();
    93 	int GetNumPlayers();
    94 public:
    95 	inline int MaxClients()
    96 	{
    97 		return m_maxClients;
    98 	}
    99 	inline int NumPlayers()
   100 	{
   101 		return m_PlayerCount;
   102 	}
   103 private:
   104 	void OnServerActivate(edict_t *pEdictList, int edictCount, int clientMax);
   105 private:
   106 	List<IClientListener *> m_hooks;
   107 	IForward *m_clconnect;
   108 	IForward *m_cldisconnect;
   109 	IForward *m_cldisconnect_post;
   110 	IForward *m_clputinserver;
   111 	IForward *m_clcommand;
   112 	IForward *m_clinfochanged;
   113 	IForward *m_clauth;
   114 	CPlayer *m_Players;
   115 	int m_maxClients;
   116 	int m_PlayerCount;
   117 	bool m_FirstPass;
   118 	unsigned int *m_AuthQueue;
   119 };
   120 
   121 extern CPlayerManager g_Players;
   122 
   123 #endif //_INCLUDE_SOURCEMOD_CPLAYERMANAGER_H_