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
64 class CPlayer : public IGamePlayer
66 friend class PlayerManager;
70 const char *GetName();
71 const char *GetIPAddress();
72 const char *GetAuthString();
75 bool WasCountedAsInGame();
79 void SetAdminId(AdminId id, bool temporary);
81 void Kick(const char *str);
83 IPlayerInfo *GetPlayerInfo();
84 unsigned int GetLanguageId();
85 void SetLanguageId(unsigned int id);
87 bool RunAdminCacheChecks();
88 void NotifyPostAdminChecks();
89 unsigned int GetSerial();
91 void DoBasicAdminChecks();
92 void MarkAsBeingKicked();
95 void Initialize(const char *name, const char *ip, edict_t *pEntity);
98 void SetName(const char *name);
99 void DumpAdmin(bool deleting);
100 void Authorize(const char *auth);
101 void Authorize_Post();
102 void DoPostConnectAuthorization();
107 bool m_bIsInKickQueue;
116 String m_LastPassword;
117 bool m_bAdminCheckSignalled;
119 unsigned int m_LangId;
125 class PlayerManager :
126 public SMGlobalClass,
127 public IPlayerManager
129 friend class CPlayer;
133 public: //SMGlobalClass
134 void OnSourceModAllInitialized();
135 void OnSourceModShutdown();
136 void OnSourceModLevelEnd();
137 ConfigResult OnSourceModConfigChanged(const char *key, const char *value, ConfigSource source, char *error, size_t maxlength);
139 CPlayer *GetPlayerByIndex(int client) const;
140 void RunAuthChecks();
141 void ClearAdminId(AdminId id);
142 void ClearAllAdmins();
144 bool OnClientConnect(edict_t *pEntity, const char *pszName, const char *pszAddress, char *reject, int maxrejectlen);
145 bool OnClientConnect_Post(edict_t *pEntity, const char *pszName, const char *pszAddress, char *reject, int maxrejectlen);
146 void OnClientPutInServer(edict_t *pEntity, char const *playername);
147 void OnClientDisconnect(edict_t *pEntity);
148 void OnClientDisconnect_Post(edict_t *pEntity);
149 #if SOURCE_ENGINE >= SE_ORANGEBOX
150 void OnClientCommand(edict_t *pEntity, const CCommand &args);
152 void OnClientCommand(edict_t *pEntity);
154 void OnClientSettingsChanged(edict_t *pEntity);
155 //void OnClientSettingsChanged_Pre(edict_t *pEntity);
156 public: //IPlayerManager
157 void AddClientListener(IClientListener *listener);
158 void RemoveClientListener(IClientListener *listener);
159 IGamePlayer *GetGamePlayer(int client);
160 IGamePlayer *GetGamePlayer(edict_t *pEdict);
163 int GetClientOfUserId(int userid);
164 bool IsServerActivated();
165 int FilterCommandTarget(IGamePlayer *pAdmin, IGamePlayer *pTarget, int flags);
166 int InternalFilterCommandTarget(CPlayer *pAdmin, CPlayer *pTarget, int flags);
167 void RegisterCommandTargetProcessor(ICommandTargetProcessor *pHandler);
168 void UnregisterCommandTargetProcessor(ICommandTargetProcessor *pHandler);
169 void ProcessCommandTarget(cmd_target_info_t *info);
170 int GetClientFromSerial(unsigned int serial);
172 inline int MaxClients()
174 return gpGlobals->maxClients;
176 inline int NumPlayers()
178 return m_PlayerCount;
180 inline int ListenClient()
182 return m_ListenClient;
184 bool CheckSetAdmin(int index, CPlayer *pPlayer, AdminId id);
185 bool CheckSetAdminName(int index, CPlayer *pPlayer, AdminId id);
186 const char *GetPassInfoVar();
187 void RecheckAnyAdmins();
188 unsigned int GetReplyTo();
189 unsigned int SetReplyTo(unsigned int reply);
190 void MaxPlayersChanged(int newvalue = -1);
192 void OnServerActivate(edict_t *pEdictList, int edictCount, int clientMax);
193 void InvalidatePlayer(CPlayer *pPlayer);
195 List<IClientListener *> m_hooks;
196 IForward *m_clconnect;
197 IForward *m_clconnect_post;
198 IForward *m_cldisconnect;
199 IForward *m_cldisconnect_post;
200 IForward *m_clputinserver;
201 IForward *m_clcommand;
202 IForward *m_clinfochanged;
204 IForward *m_onActivate;
205 IForward *m_onActivate2;
210 unsigned int *m_AuthQueue;
211 String m_PassInfoVar;
213 bool m_bIsListenServer;
217 #if SOURCE_ENGINE >= SE_ORANGEBOX
218 void CmdMaxplayersCallback(const CCommand &command);
220 void CmdMaxplayersCallback();
223 extern void ClientConsolePrint(edict_t *e, const char *fmt, ...);
225 extern PlayerManager g_Players;
226 extern bool g_OnMapStarted;
227 extern const unsigned int *g_NumPlayersToAuth;
229 #endif //_INCLUDE_SOURCEMOD_CPLAYERMANAGER_H_