public/IPlayerHelpers.h
author David Anderson <dvander@alliedmods.net>
Fri Feb 16 03:47:10 2007 +0000 (2007-02-16)
changeset 501 e209a7296936
parent 458 77520125ee67
child 541 43e600fc2aa7
permissions -rw-r--r--
removed this potential feature, not useful enough
     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() const =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() const =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() const =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() const =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() const =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() const =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() const =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() const =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 		virtual unsigned int GetInterfaceVersion()
   120 		{
   121 			return SMINTERFACE_PLAYERMANAGER_VERSION;
   122 		}
   123 	public:
   124 		/**
   125 		 * @brief Called when a client requests connection.
   126 		 *
   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.
   131 		 */
   132 		virtual bool InterceptClientConnect(int client, char *error, size_t maxlength)
   133 		{
   134 			return true;
   135 		}
   136 
   137 		/**
   138 		 * @brief Called when a client has connected.
   139 		 *
   140 		 * @param client		Index of the client.
   141 		 */
   142 		virtual void OnClientConnected(int client)
   143 		{
   144 		}
   145 
   146 		/**
   147 		 * @brief Called when a client is put in server.
   148 		 *
   149 		 * @param client		Index of the client.
   150 		 */
   151 		virtual void OnClientPutInServer(int client)
   152 		{
   153 		}
   154 
   155 		/**
   156 		 * @brief Called when a client is disconnecting (not fully disconnected yet).
   157 		 *
   158 		 * @param client		Index of the client.
   159 		 */
   160 		virtual void OnClientDisconnecting(int client)
   161 		{
   162 		}
   163 
   164 		/**
   165 		 * @brief Called when a client has fully disconnected.
   166 		 *
   167 		 * @param client		Index of the client.
   168 		 */
   169 		virtual void OnClientDisconnected(int client)
   170 		{
   171 		}
   172 
   173 		/**
   174 		 * @brief Called when a client has recieved authorization.
   175 		 *
   176 		 * @param client		Index of the client.
   177 		 * @param authstring	Authorization string.
   178 		 */
   179 		virtual void OnClientAuthorized(int client, const char *authstring)
   180 		{
   181 		}
   182 	};
   183 
   184 	class IPlayerManager : public SMInterface
   185 	{
   186 	public:
   187 		const char *GetInterfaceName()
   188 		{
   189 			return SMINTERFACE_PLAYERMANAGER_NAME;
   190 		}
   191 		unsigned int GetInterfaceVersion()
   192 		{
   193 			return SMINTERFACE_PLAYERMANAGER_VERSION;
   194 		}
   195 	public:
   196 		/**
   197 		 * @brief Adds a client listener.
   198 		 *
   199 		 * @param listener		Pointer to an IClientListener.
   200 		 */
   201 		virtual void AddClientListener(IClientListener *listener) =0;
   202 
   203 		/**
   204 		 * @brief Removes a client listener.
   205 		 *
   206 		 * @param listener		Pointer to an IClientListener.
   207 		 */
   208 		virtual void RemoveClientListener(IClientListener *listener) =0;
   209 
   210 		/**
   211 		 * @brief Retrieves an IGamePlayer object by its client index.
   212 		 *
   213 		 * Note: This will return a valid object for any player, connected or not.
   214 		 * Note: Client indexes start at 1, not 0.
   215 		 *
   216 		 * @param client		Index of the client.
   217 		 * @return				An IGamePlayer pointer, or NULL if out of range.
   218 		 */
   219 		virtual IGamePlayer *GetGamePlayer(int client) =0;
   220 
   221 		/**
   222 		 * @brief Retrieves an IGamePlayer object by its edict_t pointer.
   223 		 *
   224 		 * @param pEdict		Index of the client
   225 		 * @return				An IGamePlayer pointer, or NULL if out of range.
   226 		 */
   227 		virtual IGamePlayer *GetGamePlayer(edict_t *pEdict) =0;
   228 
   229 		/**
   230 		 * @brief Returns the maximum number of clients.
   231 		 *
   232 		 * @return				Maximum number of clients.
   233 		 */
   234 		virtual int GetMaxClients() =0;
   235 
   236 		/**
   237 		 * @brief Returns the number of players currently connected.
   238 		 *
   239 		 * @return				Current number of connected clients.
   240 		 */
   241 		virtual int GetNumPlayers() =0;
   242 	};
   243 }
   244 
   245 #endif //_INCLUDE_SOURCEMOD_INTERFACE_IPLAYERHELPERS_H_