core/PlayerManager.h
changeset 591 86e97f3eda1f
child 615 c4aa259cca88
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/core/PlayerManager.h	Sat Mar 10 21:18:07 2007 +0000
     1.3 @@ -0,0 +1,123 @@
     1.4 +/**
     1.5 + * ===============================================================
     1.6 + * SourceMod (C)2004-2007 AlliedModders LLC.  All rights reserved.
     1.7 + * ===============================================================
     1.8 + *
     1.9 + * This file is not open source and may not be copied without explicit
    1.10 + * written permission of AlliedModders LLC.  This file may not be redistributed 
    1.11 + * in whole or significant part.
    1.12 + * For information, see LICENSE.txt or http://www.sourcemod.net/license.php
    1.13 + *
    1.14 + * Version: $Id$
    1.15 + */
    1.16 +
    1.17 +#ifndef _INCLUDE_SOURCEMOD_CPLAYERMANAGER_H_
    1.18 +#define _INCLUDE_SOURCEMOD_CPLAYERMANAGER_H_
    1.19 +
    1.20 +#include "sm_globals.h"
    1.21 +#include <eiface.h>
    1.22 +#include "sourcemm_api.h"
    1.23 +#include <IForwardSys.h>
    1.24 +#include <IPlayerHelpers.h>
    1.25 +#include <IAdminSystem.h>
    1.26 +#include <sh_string.h>
    1.27 +#include <sh_list.h>
    1.28 +#include <sh_vector.h>
    1.29 +
    1.30 +using namespace SourceHook;
    1.31 +
    1.32 +class CPlayer : public IGamePlayer
    1.33 +{
    1.34 +	friend class CPlayerManager;
    1.35 +public:
    1.36 +	CPlayer();
    1.37 +public:
    1.38 +	const char *GetName() const;
    1.39 +	const char *GetIPAddress() const;
    1.40 +	const char *GetAuthString() const;
    1.41 +	edict_t *GetEdict() const;
    1.42 +	bool IsInGame() const;
    1.43 +	bool IsConnected() const;
    1.44 +	bool IsAuthorized() const;
    1.45 +	bool IsFakeClient() const;
    1.46 +	void SetAdminId(AdminId id, bool temporary);
    1.47 +	AdminId GetAdminId() const;
    1.48 +private:
    1.49 +	void Initialize(const char *name, const char *ip, edict_t *pEntity);
    1.50 +	void Connect();
    1.51 +	void Authorize(const char *steamid);
    1.52 +	void Disconnect();
    1.53 +	void SetName(const char *name);
    1.54 +	void DumpAdmin(bool deleting);
    1.55 +private:
    1.56 +	bool m_IsConnected;
    1.57 +	bool m_IsInGame;
    1.58 +	bool m_IsAuthorized;
    1.59 +	String m_Name;
    1.60 +	String m_Ip;
    1.61 +	String m_AuthID;
    1.62 +	AdminId m_Admin;
    1.63 +	bool m_TempAdmin;
    1.64 +	edict_t *m_pEdict;
    1.65 +};
    1.66 +
    1.67 +class CPlayerManager : 
    1.68 +	public SMGlobalClass,
    1.69 +	public IPlayerManager
    1.70 +{
    1.71 +public:
    1.72 +	CPlayerManager();
    1.73 +	~CPlayerManager();
    1.74 +public: //SMGlobalClass
    1.75 +	void OnSourceModAllInitialized();
    1.76 +	void OnSourceModShutdown();
    1.77 +public:
    1.78 +	CPlayer *GetPlayerByIndex(int client) const;
    1.79 +	void RunAuthChecks();
    1.80 +	void ClearAdminId(AdminId id);
    1.81 +	void ClearAllAdmins();
    1.82 +public:
    1.83 +	bool OnClientConnect(edict_t *pEntity, const char *pszName, const char *pszAddress, char *reject, int maxrejectlen);
    1.84 +	bool OnClientConnect_Post(edict_t *pEntity, const char *pszName, const char *pszAddress, char *reject, int maxrejectlen);
    1.85 +	void OnClientPutInServer(edict_t *pEntity, char const *playername);
    1.86 +	void OnClientDisconnect(edict_t *pEntity);
    1.87 +	void OnClientDisconnect_Post(edict_t *pEntity);
    1.88 +	void OnClientCommand(edict_t *pEntity);
    1.89 +	void OnClientSettingsChanged(edict_t *pEntity);
    1.90 +public: //IPlayerManager
    1.91 +	void AddClientListener(IClientListener *listener);
    1.92 +	void RemoveClientListener(IClientListener *listener);
    1.93 +	IGamePlayer *GetGamePlayer(int client);
    1.94 +	IGamePlayer *GetGamePlayer(edict_t *pEdict);
    1.95 +	int GetMaxClients();
    1.96 +	int GetNumPlayers();
    1.97 +public:
    1.98 +	inline int MaxClients()
    1.99 +	{
   1.100 +		return m_maxClients;
   1.101 +	}
   1.102 +	inline int NumPlayers()
   1.103 +	{
   1.104 +		return m_PlayerCount;
   1.105 +	}
   1.106 +private:
   1.107 +	void OnServerActivate(edict_t *pEdictList, int edictCount, int clientMax);
   1.108 +private:
   1.109 +	List<IClientListener *> m_hooks;
   1.110 +	IForward *m_clconnect;
   1.111 +	IForward *m_cldisconnect;
   1.112 +	IForward *m_cldisconnect_post;
   1.113 +	IForward *m_clputinserver;
   1.114 +	IForward *m_clcommand;
   1.115 +	IForward *m_clinfochanged;
   1.116 +	IForward *m_clauth;
   1.117 +	CPlayer *m_Players;
   1.118 +	int m_maxClients;
   1.119 +	int m_PlayerCount;
   1.120 +	bool m_FirstPass;
   1.121 +	unsigned int *m_AuthQueue;
   1.122 +};
   1.123 +
   1.124 +extern CPlayerManager g_Players;
   1.125 +
   1.126 +#endif //_INCLUDE_SOURCEMOD_CPLAYERMANAGER_H_