public/IPlayerHelpers.h
changeset 435 3097c4ab9f8f
child 458 77520125ee67
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/public/IPlayerHelpers.h	Mon Feb 05 20:32:34 2007 +0000
     1.3 @@ -0,0 +1,229 @@
     1.4 +/**
     1.5 + * vim: set ts=4 :
     1.6 + * ===============================================================
     1.7 + * SourceMod, Copyright (C) 2004-2007 AlliedModders LLC. 
     1.8 + * All rights reserved.
     1.9 + * ===============================================================
    1.10 + *
    1.11 + *  This file is part of the SourceMod/SourcePawn SDK.  This file may only be 
    1.12 + * used or modified under the Terms and Conditions of its License Agreement, 
    1.13 + * which is found in public/licenses/LICENSE.txt.  As of this notice, derivative 
    1.14 + * works must be licensed under the GNU General Public License (version 2 or 
    1.15 + * greater).  A copy of the GPL is included under public/licenses/GPL.txt.
    1.16 + * 
    1.17 + * To view the latest information, see: http://www.sourcemod.net/license.php
    1.18 + *
    1.19 + * Version: $Id$
    1.20 + */
    1.21 +
    1.22 +#ifndef _INCLUDE_SOURCEMOD_INTERFACE_IPLAYERHELPERS_H_
    1.23 +#define _INCLUDE_SOURCEMOD_INTERFACE_IPLAYERHELPERS_H_
    1.24 +
    1.25 +#include <IShareSys.h>
    1.26 +
    1.27 +#define SMINTERFACE_PLAYERMANAGER_NAME		"IPlayerManager"
    1.28 +#define SMINTERFACE_PLAYERMANAGER_VERSION	1
    1.29 +
    1.30 +struct edict_t;
    1.31 +
    1.32 +/**
    1.33 + * @file IPlayerHelpers.h
    1.34 + * @brief Defines basic helper functions for Half-Life 2 clients
    1.35 + */
    1.36 +namespace SourceMod
    1.37 +{
    1.38 +	/**
    1.39 +	 * @brief Abstracts some Half-Life 2 and SourceMod properties about clients.
    1.40 +	 */
    1.41 +	class IGamePlayer
    1.42 +	{
    1.43 +	public:
    1.44 +		/**
    1.45 +		 * @brief Returns the player's name.
    1.46 +		 *
    1.47 +		 * @return		String containing the player's name,
    1.48 +		 *				or NULL if unavailable.
    1.49 +		 */
    1.50 +		virtual const char *GetName() const =0;
    1.51 +
    1.52 +		/**
    1.53 +		 * @brief Returns the player's IP address.
    1.54 +		 *
    1.55 +		 * @return		String containing the player's IP address,
    1.56 +		 *				or NULL if unavailable.
    1.57 +		 */
    1.58 +		virtual const char *GetIPAddress() const =0;
    1.59 +
    1.60 +		/**
    1.61 +		 * @brief Returns the player's authentication string.
    1.62 +		 *
    1.63 +		 * @return		String containing the player's auth string.
    1.64 +		 *				May be NULL if unavailable.
    1.65 +		 */
    1.66 +		virtual const char *GetAuthString() const =0;
    1.67 +
    1.68 +		/**
    1.69 +		 * @brief Returns the player's edict_t structure.
    1.70 +		 *
    1.71 +		 * @return		edict_t pointer, or NULL if unavailable.
    1.72 +		 */
    1.73 +		virtual edict_t *GetEdict() const =0;
    1.74 +
    1.75 +		/**
    1.76 +		 * @brief Returns whether the player is in game (putinserver).
    1.77 +		 *
    1.78 +		 * @return		True if in game, false otherwise.
    1.79 +		 */
    1.80 +		virtual bool IsInGame() const =0;
    1.81 +
    1.82 +		/**
    1.83 +		 * @brief Returns whether the player is connected.
    1.84 +		 *
    1.85 +		 * Note: If this returns true, all above functions except for
    1.86 +		 * GetAuthString() should return non-NULL results.
    1.87 +		 *
    1.88 +		 * @return		True if connected, false otherwise.
    1.89 +		 */
    1.90 +		virtual bool IsConnected() const =0;
    1.91 +
    1.92 +		/**
    1.93 +		 * @brief Returns whether the player is a fake client.
    1.94 +		 *
    1.95 +		 * @return		True if a fake client, false otherwise.
    1.96 +		 */
    1.97 +		virtual bool IsFakeClient() const =0;
    1.98 +	};
    1.99 +
   1.100 +	/**
   1.101 +	 * @brief Provides callbacks for important client events.
   1.102 +	 */
   1.103 +	class IClientListener
   1.104 +	{
   1.105 +	public:
   1.106 +		virtual unsigned int GetInterfaceVersion()
   1.107 +		{
   1.108 +			return SMINTERFACE_PLAYERMANAGER_VERSION;
   1.109 +		}
   1.110 +	public:
   1.111 +		/**
   1.112 +		 * @brief Called when a client requests connection.
   1.113 +		 *
   1.114 +		 * @param client		Index of the client.
   1.115 +		 * @param error			Error buffer for a disconnect reason.
   1.116 +		 * @param maxlength		Maximum length of error buffer.
   1.117 +		 * @return				True to allow client, false to reject.
   1.118 +		 */
   1.119 +		virtual bool InterceptClientConnect(int client, char *error, size_t maxlength)
   1.120 +		{
   1.121 +			return true;
   1.122 +		}
   1.123 +
   1.124 +		/**
   1.125 +		 * @brief Called when a client has connected.
   1.126 +		 *
   1.127 +		 * @param client		Index of the client.
   1.128 +		 */
   1.129 +		virtual void OnClientConnected(int client)
   1.130 +		{
   1.131 +		}
   1.132 +
   1.133 +		/**
   1.134 +		 * @brief Called when a client is put in server.
   1.135 +		 *
   1.136 +		 * @param client		Index of the client.
   1.137 +		 */
   1.138 +		virtual void OnClientPutInServer(int client)
   1.139 +		{
   1.140 +		}
   1.141 +
   1.142 +		/**
   1.143 +		 * @brief Called when a client is disconnecting (not fully disconnected yet).
   1.144 +		 *
   1.145 +		 * @param client		Index of the client.
   1.146 +		 */
   1.147 +		virtual void OnClientDisconnecting(int client)
   1.148 +		{
   1.149 +		}
   1.150 +
   1.151 +		/**
   1.152 +		 * @brief Called when a client has fully disconnected.
   1.153 +		 *
   1.154 +		 * @param client		Index of the client.
   1.155 +		 */
   1.156 +		virtual void OnClientDisconnected(int client)
   1.157 +		{
   1.158 +		}
   1.159 +
   1.160 +		/**
   1.161 +		 * @brief Called when a client has recieved authorization.
   1.162 +		 *
   1.163 +		 * @param client		Index of the client.
   1.164 +		 * @param authstring	Authorization string.
   1.165 +		 */
   1.166 +		virtual void OnClientAuthorized(int client, const char *authstring)
   1.167 +		{
   1.168 +		}
   1.169 +	};
   1.170 +
   1.171 +	class IPlayerManager : public SMInterface
   1.172 +	{
   1.173 +	public:
   1.174 +		const char *GetInterfaceName()
   1.175 +		{
   1.176 +			return SMINTERFACE_PLAYERMANAGER_NAME;
   1.177 +		}
   1.178 +		unsigned int GetInterfaceVersion()
   1.179 +		{
   1.180 +			return SMINTERFACE_PLAYERMANAGER_VERSION;
   1.181 +		}
   1.182 +	public:
   1.183 +		/**
   1.184 +		 * @brief Adds a client listener.
   1.185 +		 *
   1.186 +		 * @param listener		Pointer to an IClientListener.
   1.187 +		 */
   1.188 +		virtual void AddClientListener(IClientListener *listener) =0;
   1.189 +
   1.190 +		/**
   1.191 +		 * @brief Removes a client listener.
   1.192 +		 *
   1.193 +		 * @param listener		Pointer to an IClientListener.
   1.194 +		 */
   1.195 +		virtual void RemoveClientListener(IClientListener *listener) =0;
   1.196 +
   1.197 +		/**
   1.198 +		 * @brief Retrieves an IGamePlayer object by its client index.
   1.199 +		 *
   1.200 +		 * Note: This will return a valid object for any player, connected or not.
   1.201 +		 * Note: Client indexes start at 1, not 0.
   1.202 +		 *
   1.203 +		 * @param client		Index of the client.
   1.204 +		 * @return				An IGamePlayer pointer, or NULL if out of range.
   1.205 +		 */
   1.206 +		virtual IGamePlayer *GetGamePlayer(int client) =0;
   1.207 +
   1.208 +		/**
   1.209 +		 * @brief Retrieves an IGamePlayer object by its edict_t pointer.
   1.210 +		 *
   1.211 +		 * @param pEdict		Index of the client
   1.212 +		 * @return				An IGamePlayer pointer, or NULL if out of range.
   1.213 +		 */
   1.214 +		virtual IGamePlayer *GetGamePlayer(edict_t *pEdict) =0;
   1.215 +
   1.216 +		/**
   1.217 +		 * @brief Returns the maximum number of clients.
   1.218 +		 *
   1.219 +		 * @return				Maximum number of clients.
   1.220 +		 */
   1.221 +		virtual int GetMaxClients() =0;
   1.222 +
   1.223 +		/**
   1.224 +		 * @brief Returns the number of players currently connected.
   1.225 +		 *
   1.226 +		 * @return				Current number of connected clients.
   1.227 +		 */
   1.228 +		virtual int GetNumPlayers() =0;
   1.229 +	};
   1.230 +}
   1.231 +
   1.232 +#endif //_INCLUDE_SOURCEMOD_INTERFACE_IPLAYERHELPERS_H_