3 * =============================================================================
5 * Copyright (C) 2004-2008 AlliedModders LLC. All rights reserved.
6 * =============================================================================
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.
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
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/>.
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>.
32 #ifndef _INCLUDE_SOURCEMOD_CPLAYERMANAGER_H_
33 #define _INCLUDE_SOURCEMOD_CPLAYERMANAGER_H_
35 #include "sm_globals.h"
37 #include "sourcemm_api.h"
38 #include <IForwardSys.h>
39 #include <IPlayerHelpers.h>
40 #include <IAdminSystem.h>
41 #include <sh_string.h>
43 #include <sh_vector.h>
44 #include "ConVarManager.h"
46 using namespace SourceHook;
48 #define PLAYER_LIFE_UNKNOWN 0
49 #define PLAYER_LIFE_ALIVE 1
50 #define PLAYER_LIFE_DEAD 2
52 #define MIN_API_FOR_ADMINCALLS 7
54 class CPlayer : public IGamePlayer
56 friend class PlayerManager;
60 const char *GetName();
61 const char *GetIPAddress();
62 const char *GetAuthString();
65 bool WasCountedAsInGame();
69 void SetAdminId(AdminId id, bool temporary);
71 void Kick(const char *str);
72 IPlayerInfo *GetPlayerInfo();
73 unsigned int GetLanguageId();
75 bool RunAdminCacheChecks();
76 void NotifyPostAdminChecks();
78 void DoBasicAdminChecks();
80 void MarkAsBeingKicked();
83 void Initialize(const char *name, const char *ip, edict_t *pEntity);
86 void SetName(const char *name);
87 void DumpAdmin(bool deleting);
88 void Authorize(const char *auth);
89 void Authorize_Post();
90 void DoPostConnectAuthorization();
95 bool m_bIsInKickQueue;
104 String m_LastPassword;
105 bool m_bAdminCheckSignalled;
107 unsigned int m_LangId;
112 class PlayerManager :
113 public SMGlobalClass,
114 public IPlayerManager,
115 public IConVarChangeListener
117 friend class CPlayer;
121 public: //SMGlobalClass
122 void OnSourceModAllInitialized();
123 void OnSourceModShutdown();
124 void OnSourceModLevelEnd();
125 ConfigResult OnSourceModConfigChanged(const char *key, const char *value, ConfigSource source, char *error, size_t maxlength);
126 void OnSourceModMaxPlayersChanged(int newvalue);
128 CPlayer *GetPlayerByIndex(int client) const;
129 void RunAuthChecks();
130 void ClearAdminId(AdminId id);
131 void ClearAllAdmins();
133 bool OnClientConnect(edict_t *pEntity, const char *pszName, const char *pszAddress, char *reject, int maxrejectlen);
134 bool OnClientConnect_Post(edict_t *pEntity, const char *pszName, const char *pszAddress, char *reject, int maxrejectlen);
135 void OnClientPutInServer(edict_t *pEntity, char const *playername);
136 void OnClientDisconnect(edict_t *pEntity);
137 void OnClientDisconnect_Post(edict_t *pEntity);
138 #if defined ORANGEBOX_BUILD
139 void OnClientCommand(edict_t *pEntity, const CCommand &args);
141 void OnClientCommand(edict_t *pEntity);
143 void OnClientSettingsChanged(edict_t *pEntity);
144 //void OnClientSettingsChanged_Pre(edict_t *pEntity);
145 public: //IPlayerManager
146 void AddClientListener(IClientListener *listener);
147 void RemoveClientListener(IClientListener *listener);
148 IGamePlayer *GetGamePlayer(int client);
149 IGamePlayer *GetGamePlayer(edict_t *pEdict);
152 int GetClientOfUserId(int userid);
153 bool IsServerActivated();
154 int FilterCommandTarget(IGamePlayer *pAdmin, IGamePlayer *pTarget, int flags);
155 int InternalFilterCommandTarget(CPlayer *pAdmin, CPlayer *pTarget, int flags);
156 void RegisterCommandTargetProcessor(ICommandTargetProcessor *pHandler);
157 void UnregisterCommandTargetProcessor(ICommandTargetProcessor *pHandler);
158 void ProcessCommandTarget(cmd_target_info_t *info);
159 public: // IConVarChangeListener
160 void OnConVarChanged(ConVar *pConVar, const char *oldValue, float flOldValue);
162 inline int MaxClients()
166 inline int NumPlayers()
168 return m_PlayerCount;
170 inline int ListenClient()
172 return m_ListenClient;
174 bool CheckSetAdmin(int index, CPlayer *pPlayer, AdminId id);
175 bool CheckSetAdminName(int index, CPlayer *pPlayer, AdminId id);
176 const char *GetPassInfoVar();
177 void RecheckAnyAdmins();
178 unsigned int GetReplyTo();
179 unsigned int SetReplyTo(unsigned int reply);
180 void MaxPlayersChanged(int newvalue = -1);
182 void OnServerActivate(edict_t *pEdictList, int edictCount, int clientMax);
183 void InvalidatePlayer(CPlayer *pPlayer);
185 List<IClientListener *> m_hooks;
186 IForward *m_clconnect;
187 IForward *m_cldisconnect;
188 IForward *m_cldisconnect_post;
189 IForward *m_clputinserver;
190 IForward *m_clcommand;
191 IForward *m_clinfochanged;
193 IForward *m_onActivate;
194 IForward *m_onActivate2;
200 unsigned int *m_AuthQueue;
201 String m_PassInfoVar;
203 bool m_bIsListenServer;
207 #if defined ORANGEBOX_BUILD
208 void CmdMaxplayersCallback(const CCommand &command);
210 void CmdMaxplayersCallback();
213 extern PlayerManager g_Players;
214 extern bool g_OnMapStarted;
215 extern const unsigned int *g_NumPlayersToAuth;
217 #endif //_INCLUDE_SOURCEMOD_CPLAYERMANAGER_H_