core/CPlayerManager.h
author David Anderson <dvander@alliedmods.net>
Fri Feb 16 03:47:10 2007 +0000 (2007-02-16)
changeset 501 e209a7296936
parent 458 77520125ee67
child 516 0807e52b4e02
permissions -rw-r--r--
removed this potential feature, not useful enough
     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 OnClientAuthorized(); //:TODO: any args needed?
    86 	void OnClientCommand(edict_t *pEntity);
    87 	void OnClientSettingsChanged(edict_t *pEntity);
    88 public: //IPlayerManager
    89 	void AddClientListener(IClientListener *listener);
    90 	void RemoveClientListener(IClientListener *listener);
    91 	IGamePlayer *GetGamePlayer(int client);
    92 	IGamePlayer *GetGamePlayer(edict_t *pEdict);
    93 	int GetMaxClients();
    94 	int GetNumPlayers();
    95 public:
    96 	inline int MaxClients()
    97 	{
    98 		return m_maxClients;
    99 	}
   100 	inline int NumPlayers()
   101 	{
   102 		return m_PlayerCount;
   103 	}
   104 private:
   105 	void OnServerActivate(edict_t *pEdictList, int edictCount, int clientMax);
   106 private:
   107 	List<IClientListener *> m_hooks;
   108 	IForward *m_clconnect;
   109 	IForward *m_cldisconnect;
   110 	IForward *m_cldisconnect_post;
   111 	IForward *m_clputinserver;
   112 	IForward *m_clcommand;
   113 	IForward *m_clinfochanged;
   114 	IForward *m_clauth;
   115 	CPlayer *m_Players;
   116 	int m_maxClients;
   117 	int m_PlayerCount;
   118 	bool m_FirstPass;
   119 	unsigned int *m_AuthQueue;
   120 };
   121 
   122 extern CPlayerManager g_Players;
   123 
   124 #endif //_INCLUDE_SOURCEMOD_CPLAYERMANAGER_H_