3 * =============================================================================
5 * Copyright (C) 2004-2007 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>
45 using namespace SourceHook;
47 class CPlayer : public IGamePlayer
49 friend class PlayerManager;
53 const char *GetName();
54 const char *GetIPAddress();
55 const char *GetAuthString();
58 bool WasCountedAsInGame();
62 void SetAdminId(AdminId id, bool temporary);
64 void Kick(const char *str);
65 IPlayerInfo *GetPlayerInfo();
66 unsigned int GetLanguageId();
69 void NotifyPostAdminChecks();
70 void DoBasicAdminChecks();
72 void MarkAsBeingKicked();
74 void Initialize(const char *name, const char *ip, edict_t *pEntity);
77 void SetName(const char *name);
78 void DumpAdmin(bool deleting);
79 void Authorize(const char *auth);
80 void Authorize_Post();
81 void DoPostConnectAuthorization();
86 bool m_bIsInKickQueue;
95 String m_LastPassword;
96 bool m_bAdminCheckSignalled;
98 unsigned int m_LangId;
102 class PlayerManager :
103 public SMGlobalClass,
104 public IPlayerManager
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);
115 CPlayer *GetPlayerByIndex(int client) const;
116 void RunAuthChecks();
117 void ClearAdminId(AdminId id);
118 void ClearAllAdmins();
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);
135 int GetClientOfUserId(int userid);
136 bool IsServerActivated();
138 inline int MaxClients()
142 inline int NumPlayers()
144 return m_PlayerCount;
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();
151 void OnServerActivate(edict_t *pEdictList, int edictCount, int clientMax);
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;
161 IForward *m_onActivate;
162 IForward *m_onActivate2;
168 unsigned int *m_AuthQueue;
169 String m_PassInfoVar;
173 extern PlayerManager g_Players;
174 extern bool g_OnMapStarted;
175 extern const unsigned int *g_NumPlayersToAuth;
177 #endif //_INCLUDE_SOURCEMOD_CPLAYERMANAGER_H_