core/PlayerManager.h
author Borja Ferrer <faluco@alliedmods.net>
Sun Oct 14 00:04:21 2007 +0000 (2007-10-14)
changeset 1541 e46ad208b9b4
parent 1519 c325cd4b060a
child 1621 ac5d4c68a99a
permissions -rw-r--r--
ported SM's core to Orange Box
build is broken now in purpose
     1 /**
     2  * vim: set ts=4 :
     3  * =============================================================================
     4  * SourceMod
     5  * Copyright (C) 2004-2007 AlliedModders LLC.  All rights reserved.
     6  * =============================================================================
     7  *
     8  * This program is free software; you can redistribute it and/or modify it under
     9  * the terms of the GNU General Public License, version 3.0, as published by the
    10  * Free Software Foundation.
    11  * 
    12  * This program is distributed in the hope that it will be useful, but WITHOUT
    13  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
    14  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
    15  * details.
    16  *
    17  * You should have received a copy of the GNU General Public License along with
    18  * this program.  If not, see <http://www.gnu.org/licenses/>.
    19  *
    20  * As a special exception, AlliedModders LLC gives you permission to link the
    21  * code of this program (as well as its derivative works) to "Half-Life 2," the
    22  * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
    23  * by the Valve Corporation.  You must obey the GNU General Public License in
    24  * all respects for all other code used.  Additionally, AlliedModders LLC grants
    25  * this exception to all derivative works.  AlliedModders LLC defines further
    26  * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
    27  * or <http://www.sourcemod.net/license.php>.
    28  *
    29  * Version: $Id$
    30  */
    31 
    32 #ifndef _INCLUDE_SOURCEMOD_CPLAYERMANAGER_H_
    33 #define _INCLUDE_SOURCEMOD_CPLAYERMANAGER_H_
    34 
    35 #include "sm_globals.h"
    36 #include <eiface.h>
    37 #include "sourcemm_api.h"
    38 #include <IForwardSys.h>
    39 #include <IPlayerHelpers.h>
    40 #include <IAdminSystem.h>
    41 #include <sh_string.h>
    42 #include <sh_list.h>
    43 #include <sh_vector.h>
    44 
    45 using namespace SourceHook;
    46 
    47 class CPlayer : public IGamePlayer
    48 {
    49 	friend class PlayerManager;
    50 public:
    51 	CPlayer();
    52 public:
    53 	const char *GetName();
    54 	const char *GetIPAddress();
    55 	const char *GetAuthString();
    56 	edict_t *GetEdict();
    57 	bool IsInGame();
    58 	bool WasCountedAsInGame();
    59 	bool IsConnected();
    60 	bool IsAuthorized();
    61 	bool IsFakeClient();
    62 	void SetAdminId(AdminId id, bool temporary);
    63 	AdminId GetAdminId();
    64 	void Kick(const char *str);
    65 	IPlayerInfo *GetPlayerInfo();
    66 	unsigned int GetLanguageId();
    67 	int GetUserId();
    68 public:
    69 	void NotifyPostAdminChecks();
    70 	void DoBasicAdminChecks();
    71 	bool IsInKickQueue();
    72 	void MarkAsBeingKicked();
    73 private:
    74 	void Initialize(const char *name, const char *ip, edict_t *pEntity);
    75 	void Connect();
    76 	void Disconnect();
    77 	void SetName(const char *name);
    78 	void DumpAdmin(bool deleting);
    79 	void Authorize(const char *auth);
    80 	void Authorize_Post();
    81 	void DoPostConnectAuthorization();
    82 private:
    83 	bool m_IsConnected;
    84 	bool m_IsInGame;
    85 	bool m_IsAuthorized;
    86 	bool m_bIsInKickQueue;
    87 	String m_Name;
    88 	String m_Ip;
    89 	String m_IpNoPort;
    90 	String m_AuthID;
    91 	AdminId m_Admin;
    92 	bool m_TempAdmin;
    93 	edict_t *m_pEdict;
    94 	IPlayerInfo *m_Info;
    95 	String m_LastPassword;
    96 	bool m_bAdminCheckSignalled;
    97 	int m_iIndex;
    98 	unsigned int m_LangId;
    99 	int m_UserId;
   100 };
   101 
   102 class PlayerManager : 
   103 	public SMGlobalClass,
   104 	public IPlayerManager
   105 {
   106 public:
   107 	PlayerManager();
   108 	~PlayerManager();
   109 public: //SMGlobalClass
   110 	void OnSourceModAllInitialized();
   111 	void OnSourceModShutdown();
   112 	void OnSourceModLevelEnd();
   113 	ConfigResult OnSourceModConfigChanged(const char *key, const char *value, ConfigSource source, char *error, size_t maxlength);
   114 public:
   115 	CPlayer *GetPlayerByIndex(int client) const;
   116 	void RunAuthChecks();
   117 	void ClearAdminId(AdminId id);
   118 	void ClearAllAdmins();
   119 public:
   120 	bool OnClientConnect(edict_t *pEntity, const char *pszName, const char *pszAddress, char *reject, int maxrejectlen);
   121 	bool OnClientConnect_Post(edict_t *pEntity, const char *pszName, const char *pszAddress, char *reject, int maxrejectlen);
   122 	void OnClientPutInServer(edict_t *pEntity, char const *playername);
   123 	void OnClientDisconnect(edict_t *pEntity);
   124 	void OnClientDisconnect_Post(edict_t *pEntity);
   125 #if defined ORANGEBOX_BUILD
   126 	void OnClientCommand(edict_t *pEntity, const CCommand &args);
   127 #else
   128 	void OnClientCommand(edict_t *pEntity);
   129 #endif
   130 	void OnClientSettingsChanged(edict_t *pEntity);
   131 	//void OnClientSettingsChanged_Pre(edict_t *pEntity);
   132 public: //IPlayerManager
   133 	void AddClientListener(IClientListener *listener);
   134 	void RemoveClientListener(IClientListener *listener);
   135 	IGamePlayer *GetGamePlayer(int client);
   136 	IGamePlayer *GetGamePlayer(edict_t *pEdict);
   137 	int GetMaxClients();
   138 	int GetNumPlayers();
   139 	int GetClientOfUserId(int userid);
   140 	bool IsServerActivated();
   141 public:
   142 	inline int MaxClients()
   143 	{
   144 		return m_maxClients;
   145 	}
   146 	inline int NumPlayers()
   147 	{
   148 		return m_PlayerCount;
   149 	}
   150 	bool CheckSetAdmin(int index, CPlayer *pPlayer, AdminId id);
   151 	bool CheckSetAdminName(int index, CPlayer *pPlayer, AdminId id);
   152 	const char *GetPassInfoVar();
   153 	void RecheckAnyAdmins();
   154 	unsigned int GetReplyTo();
   155 	unsigned int SetReplyTo(unsigned int reply);
   156 private:
   157 	void OnServerActivate(edict_t *pEdictList, int edictCount, int clientMax);
   158 private:
   159 	List<IClientListener *> m_hooks;
   160 	IForward *m_clconnect;
   161 	IForward *m_cldisconnect;
   162 	IForward *m_cldisconnect_post;
   163 	IForward *m_clputinserver;
   164 	IForward *m_clcommand;
   165 	IForward *m_clinfochanged;
   166 	IForward *m_clauth;
   167 	IForward *m_onActivate;
   168 	IForward *m_onActivate2;
   169 	CPlayer *m_Players;
   170 	int *m_UserIdLookUp;
   171 	int m_maxClients;
   172 	int m_PlayerCount;
   173 	bool m_FirstPass;
   174 	unsigned int *m_AuthQueue;
   175 	String m_PassInfoVar;
   176 	bool m_QueryLang;
   177 };
   178 
   179 extern PlayerManager g_Players;
   180 extern bool g_OnMapStarted;
   181 extern const unsigned int *g_NumPlayersToAuth;
   182 
   183 #endif //_INCLUDE_SOURCEMOD_CPLAYERMANAGER_H_