core/PlayerManager.h
author David Anderson <dvander@alliedmods.net>
Mon Oct 01 18:41:39 2007 +0000 (2007-10-01)
changeset 1509 cbb82af65663
parent 1485 bc5a17fec5da
child 1519 c325cd4b060a
permissions -rw-r--r--
added IsClientInKickQueue() to deal with a bot issue
     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 	void OnClientCommand(edict_t *pEntity);
   126 	void OnClientSettingsChanged(edict_t *pEntity);
   127 	//void OnClientSettingsChanged_Pre(edict_t *pEntity);
   128 public: //IPlayerManager
   129 	void AddClientListener(IClientListener *listener);
   130 	void RemoveClientListener(IClientListener *listener);
   131 	IGamePlayer *GetGamePlayer(int client);
   132 	IGamePlayer *GetGamePlayer(edict_t *pEdict);
   133 	int GetMaxClients();
   134 	int GetNumPlayers();
   135 	int GetClientOfUserId(int userid);
   136 	bool IsServerActivated();
   137 public:
   138 	inline int MaxClients()
   139 	{
   140 		return m_maxClients;
   141 	}
   142 	inline int NumPlayers()
   143 	{
   144 		return m_PlayerCount;
   145 	}
   146 	bool CheckSetAdmin(int index, CPlayer *pPlayer, AdminId id);
   147 	bool CheckSetAdminName(int index, CPlayer *pPlayer, AdminId id);
   148 	const char *GetPassInfoVar();
   149 	void RecheckAnyAdmins();
   150 private:
   151 	void OnServerActivate(edict_t *pEdictList, int edictCount, int clientMax);
   152 private:
   153 	List<IClientListener *> m_hooks;
   154 	IForward *m_clconnect;
   155 	IForward *m_cldisconnect;
   156 	IForward *m_cldisconnect_post;
   157 	IForward *m_clputinserver;
   158 	IForward *m_clcommand;
   159 	IForward *m_clinfochanged;
   160 	IForward *m_clauth;
   161 	IForward *m_onActivate;
   162 	IForward *m_onActivate2;
   163 	CPlayer *m_Players;
   164 	int *m_UserIdLookUp;
   165 	int m_maxClients;
   166 	int m_PlayerCount;
   167 	bool m_FirstPass;
   168 	unsigned int *m_AuthQueue;
   169 	String m_PassInfoVar;
   170 	bool m_QueryLang;
   171 };
   172 
   173 extern PlayerManager g_Players;
   174 extern bool g_OnMapStarted;
   175 extern const unsigned int *g_NumPlayersToAuth;
   176 
   177 #endif //_INCLUDE_SOURCEMOD_CPLAYERMANAGER_H_