3 * ===============================================================
4 * SourceMod, Copyright (C) 2004-2007 AlliedModders LLC.
6 * ===============================================================
8 * This file is part of the SourceMod/SourcePawn SDK. This file may only be
9 * used or modified under the Terms and Conditions of its License Agreement,
10 * which is found in public/licenses/LICENSE.txt. As of this notice, derivative
11 * works must be licensed under the GNU General Public License (version 2 or
12 * greater). A copy of the GPL is included under public/licenses/GPL.txt.
14 * To view the latest information, see: http://www.sourcemod.net/license.php
19 #ifndef _INCLUDE_SOURCEMOD_INTERFACE_IPLAYERHELPERS_H_
20 #define _INCLUDE_SOURCEMOD_INTERFACE_IPLAYERHELPERS_H_
22 #include <IShareSys.h>
23 #include <IAdminSystem.h>
25 #define SMINTERFACE_PLAYERMANAGER_NAME "IPlayerManager"
26 #define SMINTERFACE_PLAYERMANAGER_VERSION 1
31 * @file IPlayerHelpers.h
32 * @brief Defines basic helper functions for Half-Life 2 clients
37 * @brief Abstracts some Half-Life 2 and SourceMod properties about clients.
43 * @brief Returns the player's name.
45 * @return String containing the player's name,
46 * or NULL if unavailable.
48 virtual const char *GetName() const =0;
51 * @brief Returns the player's IP address.
53 * @return String containing the player's IP address,
54 * or NULL if unavailable.
56 virtual const char *GetIPAddress() const =0;
59 * @brief Returns the player's authentication string.
61 * @return String containing the player's auth string.
62 * May be NULL if unavailable.
64 virtual const char *GetAuthString() const =0;
67 * @brief Returns the player's edict_t structure.
69 * @return edict_t pointer, or NULL if unavailable.
71 virtual edict_t *GetEdict() const =0;
74 * @brief Returns whether the player is in game (putinserver).
76 * @return True if in game, false otherwise.
78 virtual bool IsInGame() const =0;
81 * @brief Returns whether the player is connected.
83 * Note: If this returns true, all above functions except for
84 * GetAuthString() should return non-NULL results.
86 * @return True if connected, false otherwise.
88 virtual bool IsConnected() const =0;
91 * @brief Returns whether the player is a fake client.
93 * @return True if a fake client, false otherwise.
95 virtual bool IsFakeClient() const =0;
98 * @brief Returns the client's AdminId, if any.
100 * @return AdminId, or INVALID_ADMIN_ID if none.
102 virtual AdminId GetAdminId() const =0;
105 * @brief Sets the client's AdminId.
107 * @param id AdminId to set.
108 * @param temp If true, the id will be invalidated on disconnect.
110 virtual void SetAdminId(AdminId id, bool temp) =0;
114 * @brief Provides callbacks for important client events.
116 class IClientListener
119 virtual unsigned int GetInterfaceVersion()
121 return SMINTERFACE_PLAYERMANAGER_VERSION;
125 * @brief Called when a client requests connection.
127 * @param client Index of the client.
128 * @param error Error buffer for a disconnect reason.
129 * @param maxlength Maximum length of error buffer.
130 * @return True to allow client, false to reject.
132 virtual bool InterceptClientConnect(int client, char *error, size_t maxlength)
138 * @brief Called when a client has connected.
140 * @param client Index of the client.
142 virtual void OnClientConnected(int client)
147 * @brief Called when a client is put in server.
149 * @param client Index of the client.
151 virtual void OnClientPutInServer(int client)
156 * @brief Called when a client is disconnecting (not fully disconnected yet).
158 * @param client Index of the client.
160 virtual void OnClientDisconnecting(int client)
165 * @brief Called when a client has fully disconnected.
167 * @param client Index of the client.
169 virtual void OnClientDisconnected(int client)
174 * @brief Called when a client has recieved authorization.
176 * @param client Index of the client.
177 * @param authstring Authorization string.
179 virtual void OnClientAuthorized(int client, const char *authstring)
184 class IPlayerManager : public SMInterface
187 const char *GetInterfaceName()
189 return SMINTERFACE_PLAYERMANAGER_NAME;
191 unsigned int GetInterfaceVersion()
193 return SMINTERFACE_PLAYERMANAGER_VERSION;
197 * @brief Adds a client listener.
199 * @param listener Pointer to an IClientListener.
201 virtual void AddClientListener(IClientListener *listener) =0;
204 * @brief Removes a client listener.
206 * @param listener Pointer to an IClientListener.
208 virtual void RemoveClientListener(IClientListener *listener) =0;
211 * @brief Retrieves an IGamePlayer object by its client index.
213 * Note: This will return a valid object for any player, connected or not.
214 * Note: Client indexes start at 1, not 0.
216 * @param client Index of the client.
217 * @return An IGamePlayer pointer, or NULL if out of range.
219 virtual IGamePlayer *GetGamePlayer(int client) =0;
222 * @brief Retrieves an IGamePlayer object by its edict_t pointer.
224 * @param pEdict Index of the client
225 * @return An IGamePlayer pointer, or NULL if out of range.
227 virtual IGamePlayer *GetGamePlayer(edict_t *pEdict) =0;
230 * @brief Returns the maximum number of clients.
232 * @return Maximum number of clients.
234 virtual int GetMaxClients() =0;
237 * @brief Returns the number of players currently connected.
239 * @return Current number of connected clients.
241 virtual int GetNumPlayers() =0;
245 #endif //_INCLUDE_SOURCEMOD_INTERFACE_IPLAYERHELPERS_H_