public/IPlayerHelpers.h
author David Anderson <dvander@alliedmods.net>
Thu Jul 19 23:42:10 2007 +0000 (2007-07-19)
changeset 1137 049e7c6bf36b
parent 729 110c14c99545
child 1226 478550a4d5ec
permissions -rw-r--r--
maybe dox won't barf on this now
     1 /**
     2  * vim: set ts=4 :
     3  * ===============================================================
     4  * SourceMod, Copyright (C) 2004-2007 AlliedModders LLC. 
     5  * All rights reserved.
     6  * ===============================================================
     7  *
     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.
    13  * 
    14  * To view the latest information, see: http://www.sourcemod.net/license.php
    15  *
    16  * Version: $Id$
    17  */
    18 
    19 #ifndef _INCLUDE_SOURCEMOD_INTERFACE_IPLAYERHELPERS_H_
    20 #define _INCLUDE_SOURCEMOD_INTERFACE_IPLAYERHELPERS_H_
    21 
    22 /**
    23  * @file IPlayerHelpers.h
    24  * @brief Defines basic helper functions for Half-Life 2 clients
    25  */
    26 
    27 #include <IShareSys.h>
    28 #include <IAdminSystem.h>
    29 
    30 #define SMINTERFACE_PLAYERMANAGER_NAME		"IPlayerManager"
    31 #define SMINTERFACE_PLAYERMANAGER_VERSION	1
    32 
    33 struct edict_t;
    34 
    35 namespace SourceMod
    36 {
    37 	/**
    38 	 * @brief Abstracts some Half-Life 2 and SourceMod properties about clients.
    39 	 */
    40 	class IGamePlayer
    41 	{
    42 	public:
    43 		/**
    44 		 * @brief Returns the player's name.
    45 		 *
    46 		 * @return		String containing the player's name,
    47 		 *				or NULL if unavailable.
    48 		 */
    49 		virtual const char *GetName() =0;
    50 
    51 		/**
    52 		 * @brief Returns the player's IP address.
    53 		 *
    54 		 * @return		String containing the player's IP address,
    55 		 *				or NULL if unavailable.
    56 		 */
    57 		virtual const char *GetIPAddress() =0;
    58 
    59 		/**
    60 		 * @brief Returns the player's authentication string.
    61 		 *
    62 		 * @return		String containing the player's auth string.
    63 		 *				May be NULL if unavailable.
    64 		 */
    65 		virtual const char *GetAuthString() =0;
    66 
    67 		/**
    68 		 * @brief Returns the player's edict_t structure.
    69 		 *
    70 		 * @return		edict_t pointer, or NULL if unavailable.
    71 		 */
    72 		virtual edict_t *GetEdict() =0;
    73 
    74 		/**
    75 		 * @brief Returns whether the player is in game (putinserver).
    76 		 *
    77 		 * @return		True if in game, false otherwise.
    78 		 */
    79 		virtual bool IsInGame() =0;
    80 
    81 		/**
    82 		 * @brief Returns whether the player is connected.
    83 		 *
    84 		 * Note: If this returns true, all above functions except for
    85 		 * GetAuthString() should return non-NULL results.
    86 		 *
    87 		 * @return		True if connected, false otherwise.
    88 		 */
    89 		virtual bool IsConnected() =0;
    90 
    91 		/**
    92 		 * @brief Returns whether the player is a fake client.
    93 		 *
    94 		 * @return		True if a fake client, false otherwise.
    95 		 */
    96 		virtual bool IsFakeClient() =0;
    97 
    98 		/**
    99 		 * @brief Returns the client's AdminId, if any.
   100 		 *
   101 		 * @return		AdminId, or INVALID_ADMIN_ID if none.
   102 		 */
   103 		virtual AdminId GetAdminId() =0;
   104 
   105 		/**
   106 		 * @brief Sets the client's AdminId.
   107 		 *
   108 		 * @param id	AdminId to set.
   109 		 * @param temp	If true, the id will be invalidated on disconnect.
   110 		 */
   111 		virtual void SetAdminId(AdminId id, bool temp) =0;
   112 	};
   113 
   114 	/**
   115 	 * @brief Provides callbacks for important client events.
   116 	 */
   117 	class IClientListener
   118 	{
   119 	public:
   120 	   /**
   121 		* @brief Returns the current client listener version.
   122 		*
   123 		* @return		Client listener version.
   124 		*/
   125 		virtual unsigned int GetClientListenerVersion()
   126 		{
   127 			return SMINTERFACE_PLAYERMANAGER_VERSION;
   128 		}
   129 	public:
   130 		/**
   131 		 * @brief Called when a client requests connection.
   132 		 *
   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.
   137 		 */
   138 		virtual bool InterceptClientConnect(int client, char *error, size_t maxlength)
   139 		{
   140 			return true;
   141 		}
   142 
   143 		/**
   144 		 * @brief Called when a client has connected.
   145 		 *
   146 		 * @param client		Index of the client.
   147 		 */
   148 		virtual void OnClientConnected(int client)
   149 		{
   150 		}
   151 
   152 		/**
   153 		 * @brief Called when a client is put in server.
   154 		 *
   155 		 * @param client		Index of the client.
   156 		 */
   157 		virtual void OnClientPutInServer(int client)
   158 		{
   159 		}
   160 
   161 		/**
   162 		 * @brief Called when a client is disconnecting (not fully disconnected yet).
   163 		 *
   164 		 * @param client		Index of the client.
   165 		 */
   166 		virtual void OnClientDisconnecting(int client)
   167 		{
   168 		}
   169 
   170 		/**
   171 		 * @brief Called when a client has fully disconnected.
   172 		 *
   173 		 * @param client		Index of the client.
   174 		 */
   175 		virtual void OnClientDisconnected(int client)
   176 		{
   177 		}
   178 
   179 		/**
   180 		 * @brief Called when a client has received authorization.
   181 		 *
   182 		 * @param client		Index of the client.
   183 		 * @param authstring	Authorization string.
   184 		 */
   185 		virtual void OnClientAuthorized(int client, const char *authstring)
   186 		{
   187 		}
   188 	};
   189 
   190 	class IPlayerManager : public SMInterface
   191 	{
   192 	public:
   193 		const char *GetInterfaceName()
   194 		{
   195 			return SMINTERFACE_PLAYERMANAGER_NAME;
   196 		}
   197 		unsigned int GetInterfaceVersion()
   198 		{
   199 			return SMINTERFACE_PLAYERMANAGER_VERSION;
   200 		}
   201 	public:
   202 		/**
   203 		 * @brief Adds a client listener.
   204 		 *
   205 		 * @param listener		Pointer to an IClientListener.
   206 		 */
   207 		virtual void AddClientListener(IClientListener *listener) =0;
   208 
   209 		/**
   210 		 * @brief Removes a client listener.
   211 		 *
   212 		 * @param listener		Pointer to an IClientListener.
   213 		 */
   214 		virtual void RemoveClientListener(IClientListener *listener) =0;
   215 
   216 		/**
   217 		 * @brief Retrieves an IGamePlayer object by its client index.
   218 		 *
   219 		 * Note: This will return a valid object for any player, connected or not.
   220 		 * Note: Client indexes start at 1, not 0.
   221 		 *
   222 		 * @param client		Index of the client.
   223 		 * @return				An IGamePlayer pointer, or NULL if out of range.
   224 		 */
   225 		virtual IGamePlayer *GetGamePlayer(int client) =0;
   226 
   227 		/**
   228 		 * @brief Retrieves an IGamePlayer object by its edict_t pointer.
   229 		 *
   230 		 * @param pEdict		Index of the client
   231 		 * @return				An IGamePlayer pointer, or NULL if out of range.
   232 		 */
   233 		virtual IGamePlayer *GetGamePlayer(edict_t *pEdict) =0;
   234 
   235 		/**
   236 		 * @brief Returns the maximum number of clients.
   237 		 *
   238 		 * @return				Maximum number of clients.
   239 		 */
   240 		virtual int GetMaxClients() =0;
   241 
   242 		/**
   243 		 * @brief Returns the number of players currently connected.
   244 		 *
   245 		 * @return				Current number of connected clients.
   246 		 */
   247 		virtual int GetNumPlayers() =0;
   248 
   249 		/**
   250 		 * @brief Returns the client index by its userid.
   251 		 *
   252 		 * @param userid		Userid of the client.
   253 		 * @return				Client index, or 0 if invalid userid passed.
   254 		 */
   255 		virtual int GetClientOfUserId(int userid) =0;
   256 	};
   257 }
   258 
   259 #endif //_INCLUDE_SOURCEMOD_INTERFACE_IPLAYERHELPERS_H_