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