core/PlayerManager.h
author David Anderson <dvander@alliedmods.net>
Tue Jul 03 20:46:17 2007 +0000 (2007-07-03)
changeset 1036 2a073d5b3454
parent 916 39ae94ad60ce
child 1160 7d8b449edd60
permissions -rw-r--r--
added amb505
     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 	void OnSourceModLevelEnd();
    79 public:
    80 	CPlayer *GetPlayerByIndex(int client) const;
    81 	void RunAuthChecks();
    82 	void ClearAdminId(AdminId id);
    83 	void ClearAllAdmins();
    84 public:
    85 	bool OnClientConnect(edict_t *pEntity, const char *pszName, const char *pszAddress, char *reject, int maxrejectlen);
    86 	bool OnClientConnect_Post(edict_t *pEntity, const char *pszName, const char *pszAddress, char *reject, int maxrejectlen);
    87 	void OnClientPutInServer(edict_t *pEntity, char const *playername);
    88 	void OnClientDisconnect(edict_t *pEntity);
    89 	void OnClientDisconnect_Post(edict_t *pEntity);
    90 	void OnClientCommand(edict_t *pEntity);
    91 	void OnClientSettingsChanged(edict_t *pEntity);
    92 public: //IPlayerManager
    93 	void AddClientListener(IClientListener *listener);
    94 	void RemoveClientListener(IClientListener *listener);
    95 	IGamePlayer *GetGamePlayer(int client);
    96 	IGamePlayer *GetGamePlayer(edict_t *pEdict);
    97 	int GetMaxClients();
    98 	int GetNumPlayers();
    99 	int GetClientOfUserId(int userid);
   100 public:
   101 	inline int MaxClients()
   102 	{
   103 		return m_maxClients;
   104 	}
   105 	inline int NumPlayers()
   106 	{
   107 		return m_PlayerCount;
   108 	}
   109 private:
   110 	void OnServerActivate(edict_t *pEdictList, int edictCount, int clientMax);
   111 private:
   112 	List<IClientListener *> m_hooks;
   113 	IForward *m_clconnect;
   114 	IForward *m_cldisconnect;
   115 	IForward *m_cldisconnect_post;
   116 	IForward *m_clputinserver;
   117 	IForward *m_clcommand;
   118 	IForward *m_clinfochanged;
   119 	IForward *m_clauth;
   120 	IForward *m_onActivate;
   121 	IForward *m_onActivate2;
   122 	CPlayer *m_Players;
   123 	int *m_UserIdLookUp;
   124 	int m_maxClients;
   125 	int m_PlayerCount;
   126 	bool m_FirstPass;
   127 	unsigned int *m_AuthQueue;
   128 };
   129 
   130 extern PlayerManager g_Players;
   131 extern bool g_OnMapStarted;
   132 
   133 #endif //_INCLUDE_SOURCEMOD_CPLAYERMANAGER_H_