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