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_
23 * @file IPlayerHelpers.h
24 * @brief Defines basic helper functions for Half-Life 2 clients
27 #include <IShareSys.h>
28 #include <IAdminSystem.h>
30 #define SMINTERFACE_PLAYERMANAGER_NAME "IPlayerManager"
31 #define SMINTERFACE_PLAYERMANAGER_VERSION 1
38 * @brief Abstracts some Half-Life 2 and SourceMod properties about clients.
44 * @brief Returns the player's name.
46 * @return String containing the player's name,
47 * or NULL if unavailable.
49 virtual const char *GetName() =0;
52 * @brief Returns the player's IP address.
54 * @return String containing the player's IP address,
55 * or NULL if unavailable.
57 virtual const char *GetIPAddress() =0;
60 * @brief Returns the player's authentication string.
62 * @return String containing the player's auth string.
63 * May be NULL if unavailable.
65 virtual const char *GetAuthString() =0;
68 * @brief Returns the player's edict_t structure.
70 * @return edict_t pointer, or NULL if unavailable.
72 virtual edict_t *GetEdict() =0;
75 * @brief Returns whether the player is in game (putinserver).
77 * @return True if in game, false otherwise.
79 virtual bool IsInGame() =0;
82 * @brief Returns whether the player is connected.
84 * Note: If this returns true, all above functions except for
85 * GetAuthString() should return non-NULL results.
87 * @return True if connected, false otherwise.
89 virtual bool IsConnected() =0;
92 * @brief Returns whether the player is a fake client.
94 * @return True if a fake client, false otherwise.
96 virtual bool IsFakeClient() =0;
99 * @brief Returns the client's AdminId, if any.
101 * @return AdminId, or INVALID_ADMIN_ID if none.
103 virtual AdminId GetAdminId() =0;
106 * @brief Sets the client's AdminId.
108 * @param id AdminId to set.
109 * @param temp If true, the id will be invalidated on disconnect.
111 virtual void SetAdminId(AdminId id, bool temp) =0;
115 * @brief Provides callbacks for important client events.
117 class IClientListener
121 * @brief Returns the current client listener version.
123 * @return Client listener version.
125 virtual unsigned int GetClientListenerVersion()
127 return SMINTERFACE_PLAYERMANAGER_VERSION;
131 * @brief Called when a client requests connection.
133 * @param client Index of the client.
134 * @param error Error buffer for a disconnect reason.
135 * @param maxlength Maximum length of error buffer.
136 * @return True to allow client, false to reject.
138 virtual bool InterceptClientConnect(int client, char *error, size_t maxlength)
144 * @brief Called when a client has connected.
146 * @param client Index of the client.
148 virtual void OnClientConnected(int client)
153 * @brief Called when a client is put in server.
155 * @param client Index of the client.
157 virtual void OnClientPutInServer(int client)
162 * @brief Called when a client is disconnecting (not fully disconnected yet).
164 * @param client Index of the client.
166 virtual void OnClientDisconnecting(int client)
171 * @brief Called when a client has fully disconnected.
173 * @param client Index of the client.
175 virtual void OnClientDisconnected(int client)
180 * @brief Called when a client has received authorization.
182 * @param client Index of the client.
183 * @param authstring Authorization string.
185 virtual void OnClientAuthorized(int client, const char *authstring)
190 class IPlayerManager : public SMInterface
193 const char *GetInterfaceName()
195 return SMINTERFACE_PLAYERMANAGER_NAME;
197 unsigned int GetInterfaceVersion()
199 return SMINTERFACE_PLAYERMANAGER_VERSION;
203 * @brief Adds a client listener.
205 * @param listener Pointer to an IClientListener.
207 virtual void AddClientListener(IClientListener *listener) =0;
210 * @brief Removes a client listener.
212 * @param listener Pointer to an IClientListener.
214 virtual void RemoveClientListener(IClientListener *listener) =0;
217 * @brief Retrieves an IGamePlayer object by its client index.
219 * Note: This will return a valid object for any player, connected or not.
220 * Note: Client indexes start at 1, not 0.
222 * @param client Index of the client.
223 * @return An IGamePlayer pointer, or NULL if out of range.
225 virtual IGamePlayer *GetGamePlayer(int client) =0;
228 * @brief Retrieves an IGamePlayer object by its edict_t pointer.
230 * @param pEdict Index of the client
231 * @return An IGamePlayer pointer, or NULL if out of range.
233 virtual IGamePlayer *GetGamePlayer(edict_t *pEdict) =0;
236 * @brief Returns the maximum number of clients.
238 * @return Maximum number of clients.
240 virtual int GetMaxClients() =0;
243 * @brief Returns the number of players currently connected.
245 * @return Current number of connected clients.
247 virtual int GetNumPlayers() =0;
250 * @brief Returns the client index by its userid.
252 * @param userid Userid of the client.
253 * @return Client index, or 0 if invalid userid passed.
255 virtual int GetClientOfUserId(int userid) =0;
259 #endif //_INCLUDE_SOURCEMOD_INTERFACE_IPLAYERHELPERS_H_