1.1 --- a/public/IPlayerHelpers.h Fri Jul 11 06:51:21 2008 +0000
1.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
1.3 @@ -1,478 +0,0 @@
1.4 -/**
1.5 - * vim: set ts=4 :
1.6 - * =============================================================================
1.7 - * SourceMod
1.8 - * Copyright (C) 2004-2008 AlliedModders LLC. All rights reserved.
1.9 - * =============================================================================
1.10 - *
1.11 - * This program is free software; you can redistribute it and/or modify it under
1.12 - * the terms of the GNU General Public License, version 3.0, as published by the
1.13 - * Free Software Foundation.
1.14 - *
1.15 - * This program is distributed in the hope that it will be useful, but WITHOUT
1.16 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
1.17 - * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
1.18 - * details.
1.19 - *
1.20 - * You should have received a copy of the GNU General Public License along with
1.21 - * this program. If not, see <http://www.gnu.org/licenses/>.
1.22 - *
1.23 - * As a special exception, AlliedModders LLC gives you permission to link the
1.24 - * code of this program (as well as its derivative works) to "Half-Life 2," the
1.25 - * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
1.26 - * by the Valve Corporation. You must obey the GNU General Public License in
1.27 - * all respects for all other code used. Additionally, AlliedModders LLC grants
1.28 - * this exception to all derivative works. AlliedModders LLC defines further
1.29 - * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
1.30 - * or <http://www.sourcemod.net/license.php>.
1.31 - *
1.32 - * Version: $Id$
1.33 - */
1.34 -
1.35 -#ifndef _INCLUDE_SOURCEMOD_INTERFACE_IPLAYERHELPERS_H_
1.36 -#define _INCLUDE_SOURCEMOD_INTERFACE_IPLAYERHELPERS_H_
1.37 -
1.38 -/**
1.39 - * @file IPlayerHelpers.h
1.40 - * @brief Defines basic helper functions for Half-Life 2 clients
1.41 - */
1.42 -
1.43 -#include <IShareSys.h>
1.44 -#include <IAdminSystem.h>
1.45 -
1.46 -#define SMINTERFACE_PLAYERMANAGER_NAME "IPlayerManager"
1.47 -#define SMINTERFACE_PLAYERMANAGER_VERSION 7
1.48 -
1.49 -struct edict_t;
1.50 -class IPlayerInfo;
1.51 -
1.52 -#define SM_REPLY_CONSOLE 0 /**< Reply to console. */
1.53 -#define SM_REPLY_CHAT 1 /**< Reply to chat. */
1.54 -
1.55 -namespace SourceMod
1.56 -{
1.57 - /**
1.58 - * @brief Abstracts some Half-Life 2 and SourceMod properties about clients.
1.59 - */
1.60 - class IGamePlayer
1.61 - {
1.62 - public:
1.63 - /**
1.64 - * @brief Returns the player's name.
1.65 - *
1.66 - * @return String containing the player's name,
1.67 - * or NULL if unavailable.
1.68 - */
1.69 - virtual const char *GetName() =0;
1.70 -
1.71 - /**
1.72 - * @brief Returns the player's IP address.
1.73 - *
1.74 - * @return String containing the player's IP address,
1.75 - * or NULL if unavailable.
1.76 - */
1.77 - virtual const char *GetIPAddress() =0;
1.78 -
1.79 - /**
1.80 - * @brief Returns the player's authentication string.
1.81 - *
1.82 - * @return String containing the player's auth string.
1.83 - * May be NULL if unavailable.
1.84 - */
1.85 - virtual const char *GetAuthString() =0;
1.86 -
1.87 - /**
1.88 - * @brief Returns the player's edict_t structure.
1.89 - *
1.90 - * @return edict_t pointer, or NULL if unavailable.
1.91 - */
1.92 - virtual edict_t *GetEdict() =0;
1.93 -
1.94 - /**
1.95 - * @brief Returns whether the player is in game (putinserver).
1.96 - *
1.97 - * @return True if in game, false otherwise.
1.98 - */
1.99 - virtual bool IsInGame() =0;
1.100 -
1.101 - /**
1.102 - * @brief Returns whether the player is connected.
1.103 - *
1.104 - * Note: If this returns true, all above functions except for
1.105 - * GetAuthString() should return non-NULL results.
1.106 - *
1.107 - * @return True if connected, false otherwise.
1.108 - */
1.109 - virtual bool IsConnected() =0;
1.110 -
1.111 - /**
1.112 - * @brief Returns whether the player is a fake client.
1.113 - *
1.114 - * @return True if a fake client, false otherwise.
1.115 - */
1.116 - virtual bool IsFakeClient() =0;
1.117 -
1.118 - /**
1.119 - * @brief Returns the client's AdminId, if any.
1.120 - *
1.121 - * @return AdminId, or INVALID_ADMIN_ID if none.
1.122 - */
1.123 - virtual AdminId GetAdminId() =0;
1.124 -
1.125 - /**
1.126 - * @brief Sets the client's AdminId.
1.127 - *
1.128 - * @param id AdminId to set.
1.129 - * @param temp If true, the id will be invalidated on disconnect.
1.130 - */
1.131 - virtual void SetAdminId(AdminId id, bool temp) =0;
1.132 -
1.133 - /**
1.134 - * @brief Returns the client's userid.
1.135 - *
1.136 - * @return Userid.
1.137 - */
1.138 - virtual int GetUserId() =0;
1.139 -
1.140 - /**
1.141 - * @brief Returns the client's language id.
1.142 - *
1.143 - * @return Language id.
1.144 - */
1.145 - virtual unsigned int GetLanguageId() =0;
1.146 -
1.147 - /**
1.148 - * @brief Returns a player's IPlayerInfo object, if any.
1.149 - *
1.150 - * @return IPlayerInfo pointer, or NULL if none.
1.151 - */
1.152 - virtual IPlayerInfo *GetPlayerInfo() =0;
1.153 -
1.154 - /**
1.155 - * @brief Runs through Core's admin authorization checks. If the
1.156 - * client is already an admin, no checks are performed.
1.157 - *
1.158 - * Note that this function operates solely against the in-memory admin
1.159 - * cache. It will check steamids, IPs, names, and verify a password
1.160 - * if one exists. To implement other authentication schemes, simply
1.161 - * don't call this function and use IGamePlayer::SetAdminId() instead.
1.162 - *
1.163 - * @return True if access changed, false otherwise.
1.164 - */
1.165 - virtual bool RunAdminCacheChecks() =0;
1.166 -
1.167 - /**
1.168 - * @brief Notifies all listeners that the client has completed
1.169 - * all of your post-connection (in-game, auth, admin) checks.
1.170 - *
1.171 - * If you returned "false" from OnClientPreAdminCheck(), you must
1.172 - * ALWAYS manually invoke this function, even if RunAdminCacheChecks()
1.173 - * failed or you did not assign an AdminId. Failure to call this
1.174 - * function could result in plugins (such as reservedslots) not
1.175 - * working properly.
1.176 - *
1.177 - * If you are implementing asynchronous fetches, and the client
1.178 - * disconnects during your fetching process, you should make sure to
1.179 - * recognize that case and not call this function. That is, do not
1.180 - * call this function on mismatched PreCheck calls, or on disconnected
1.181 - * clients. A good way to check this is to pass userids around, which
1.182 - * are unique per client connection.
1.183 - *
1.184 - * Calling this has no effect if it has already been called on the
1.185 - * given client (thus it is safe for multiple asynchronous plugins to
1.186 - * call it at various times).
1.187 - */
1.188 - virtual void NotifyPostAdminChecks() =0;
1.189 - };
1.190 -
1.191 - /**
1.192 - * @brief Provides callbacks for important client events.
1.193 - */
1.194 - class IClientListener
1.195 - {
1.196 - public:
1.197 - /**
1.198 - * @brief Returns the current client listener version.
1.199 - *
1.200 - * @return Client listener version.
1.201 - */
1.202 - virtual unsigned int GetClientListenerVersion()
1.203 - {
1.204 - return SMINTERFACE_PLAYERMANAGER_VERSION;
1.205 - }
1.206 - public:
1.207 - /**
1.208 - * @brief Called when a client requests connection.
1.209 - *
1.210 - * @param client Index of the client.
1.211 - * @param error Error buffer for a disconnect reason.
1.212 - * @param maxlength Maximum length of error buffer.
1.213 - * @return True to allow client, false to reject.
1.214 - */
1.215 - virtual bool InterceptClientConnect(int client, char *error, size_t maxlength)
1.216 - {
1.217 - return true;
1.218 - }
1.219 -
1.220 - /**
1.221 - * @brief Called when a client has connected.
1.222 - *
1.223 - * @param client Index of the client.
1.224 - */
1.225 - virtual void OnClientConnected(int client)
1.226 - {
1.227 - }
1.228 -
1.229 - /**
1.230 - * @brief Called when a client is put in server.
1.231 - *
1.232 - * @param client Index of the client.
1.233 - */
1.234 - virtual void OnClientPutInServer(int client)
1.235 - {
1.236 - }
1.237 -
1.238 - /**
1.239 - * @brief Called when a client is disconnecting (not fully disconnected yet).
1.240 - *
1.241 - * @param client Index of the client.
1.242 - */
1.243 - virtual void OnClientDisconnecting(int client)
1.244 - {
1.245 - }
1.246 -
1.247 - /**
1.248 - * @brief Called when a client has fully disconnected.
1.249 - *
1.250 - * @param client Index of the client.
1.251 - */
1.252 - virtual void OnClientDisconnected(int client)
1.253 - {
1.254 - }
1.255 -
1.256 - /**
1.257 - * @brief Called when a client has received authorization.
1.258 - *
1.259 - * @param client Index of the client.
1.260 - * @param authstring Authorization string.
1.261 - */
1.262 - virtual void OnClientAuthorized(int client, const char *authstring)
1.263 - {
1.264 - }
1.265 -
1.266 - /**
1.267 - * @brief Called when the server is activated.
1.268 - */
1.269 - virtual void OnServerActivated(int max_clients)
1.270 - {
1.271 - }
1.272 -
1.273 - /**
1.274 - * @brief Called once a client is authorized and fully in-game, but
1.275 - * before admin checks are done. This can be used to override the
1.276 - * default admin checks for a client.
1.277 - *
1.278 - * By default, this function allows the authentication process to
1.279 - * continue as normal. If you need to delay the cache searching
1.280 - * process in order to get asynchronous data, then return false here.
1.281 - *
1.282 - * If you return false, you must call IPlayerManager::NotifyPostAdminCheck
1.283 - * for the same client, or else the OnClientPostAdminCheck callback will
1.284 - * never be called.
1.285 - *
1.286 - * @param client Client index.
1.287 - * @return True to continue normally, false to override
1.288 - * the authentication process.
1.289 - */
1.290 - virtual bool OnClientPreAdminCheck(int client)
1.291 - {
1.292 - return true;
1.293 - }
1.294 -
1.295 - /**
1.296 - * @brief Called once a client is authorized and fully in-game, and
1.297 - * after all post-connection authorizations have been passed. If the
1.298 - * client does not have an AdminId by this stage, it means that no
1.299 - * admin entry was in the cache that matched, and the user could not
1.300 - * be authenticated as an admin.
1.301 - *
1.302 - * @param client Client index.
1.303 - */
1.304 - virtual void OnClientPostAdminCheck(int client)
1.305 - {
1.306 - }
1.307 - };
1.308 -
1.309 - #define COMMAND_FILTER_ALIVE (1<<0) /**< Only allow alive players */
1.310 - #define COMMAND_FILTER_DEAD (1<<1) /**< Only filter dead players */
1.311 - #define COMMAND_FILTER_CONNECTED (1<<2) /**< Allow players not fully in-game */
1.312 - #define COMMAND_FILTER_NO_IMMUNITY (1<<3) /**< Ignore immunity rules */
1.313 - #define COMMAND_FILTER_NO_MULTI (1<<4) /**< Do not allow multiple target patterns */
1.314 - #define COMMAND_FILTER_NO_BOTS (1<<5) /**< Do not allow bots to be targetted */
1.315 -
1.316 - #define COMMAND_TARGET_VALID 1 /**< Client passed the filter */
1.317 - #define COMMAND_TARGET_NONE 0 /**< No target was found */
1.318 - #define COMMAND_TARGET_NOT_ALIVE -1 /**< Single client is not alive */
1.319 - #define COMMAND_TARGET_NOT_DEAD -2 /**< Single client is not dead */
1.320 - #define COMMAND_TARGET_NOT_IN_GAME -3 /**< Single client is not in game */
1.321 - #define COMMAND_TARGET_IMMUNE -4 /**< Single client is immune */
1.322 - #define COMMAND_TARGET_EMPTY_FILTER -5 /**< A multi-filter (such as @all) had no targets */
1.323 - #define COMMAND_TARGET_NOT_HUMAN -6 /**< Target was not human */
1.324 - #define COMMAND_TARGET_AMBIGUOUS -7 /**< Partial name had too many targets */
1.325 -
1.326 - #define COMMAND_TARGETNAME_RAW 0 /**< Target name is a raw string */
1.327 - #define COMMAND_TARGETNAME_ML 1 /**< Target name is a multi-lingual phrase */
1.328 -
1.329 - /**
1.330 - * @brief Holds the many command target info parameters.
1.331 - */
1.332 - struct cmd_target_info_t
1.333 - {
1.334 - const char *pattern; /**< IN: Target pattern string. */
1.335 - int admin; /**< IN: Client admin index, or 0 if server .*/
1.336 - cell_t *targets; /**< IN: Array to store targets. */
1.337 - cell_t max_targets; /**< IN: Max targets (always >= 1) */
1.338 - int flags; /**< IN: COMMAND_FILTER flags. */
1.339 - char *target_name; /**< OUT: Buffer to store target name. */
1.340 - size_t target_name_maxlength; /**< IN: Maximum length of the target name buffer. */
1.341 - int target_name_style; /**< OUT: Target name style (COMMAND_TARGETNAME) */
1.342 - int reason; /**< OUT: COMMAND_TARGET reason. */
1.343 - unsigned int num_targets; /**< OUT: Number of targets. */
1.344 - };
1.345 -
1.346 - /**
1.347 - * @brief Intercepts a command target operation.
1.348 - */
1.349 - class ICommandTargetProcessor
1.350 - {
1.351 - public:
1.352 - /**
1.353 - * @brief Must process the command target and return a COMMAND_TARGET value.
1.354 - *
1.355 - * @param info Struct containing command target information.
1.356 - * Any members labelled OUT must be filled if processing
1.357 - * is to be completed (i.e. true returned).
1.358 - * @return True to end processing, false to let Core continue.
1.359 - */
1.360 - virtual bool ProcessCommandTarget(cmd_target_info_t *info) =0;
1.361 - };
1.362 -
1.363 - class IPlayerManager : public SMInterface
1.364 - {
1.365 - public:
1.366 - const char *GetInterfaceName()
1.367 - {
1.368 - return SMINTERFACE_PLAYERMANAGER_NAME;
1.369 - }
1.370 - unsigned int GetInterfaceVersion()
1.371 - {
1.372 - return SMINTERFACE_PLAYERMANAGER_VERSION;
1.373 - }
1.374 - public:
1.375 - /**
1.376 - * @brief Adds a client listener.
1.377 - *
1.378 - * @param listener Pointer to an IClientListener.
1.379 - */
1.380 - virtual void AddClientListener(IClientListener *listener) =0;
1.381 -
1.382 - /**
1.383 - * @brief Removes a client listener.
1.384 - *
1.385 - * @param listener Pointer to an IClientListener.
1.386 - */
1.387 - virtual void RemoveClientListener(IClientListener *listener) =0;
1.388 -
1.389 - /**
1.390 - * @brief Retrieves an IGamePlayer object by its client index.
1.391 - *
1.392 - * Note: This will return a valid object for any player, connected or not.
1.393 - * Note: Client indexes start at 1, not 0.
1.394 - *
1.395 - * @param client Index of the client.
1.396 - * @return An IGamePlayer pointer, or NULL if out of range.
1.397 - */
1.398 - virtual IGamePlayer *GetGamePlayer(int client) =0;
1.399 -
1.400 - /**
1.401 - * @brief Retrieves an IGamePlayer object by its edict_t pointer.
1.402 - *
1.403 - * @param pEdict Index of the client
1.404 - * @return An IGamePlayer pointer, or NULL if out of range.
1.405 - */
1.406 - virtual IGamePlayer *GetGamePlayer(edict_t *pEdict) =0;
1.407 -
1.408 - /**
1.409 - * @brief Returns the maximum number of clients.
1.410 - *
1.411 - * Note: this will not work until the server is activated.
1.412 - *
1.413 - * @return Maximum number of clients.
1.414 - */
1.415 - virtual int GetMaxClients() =0;
1.416 -
1.417 - /**
1.418 - * @brief Returns the number of players currently connected.
1.419 - *
1.420 - * @return Current number of connected clients.
1.421 - */
1.422 - virtual int GetNumPlayers() =0;
1.423 -
1.424 - /**
1.425 - * @brief Returns the client index by its userid.
1.426 - *
1.427 - * @param userid Userid of the client.
1.428 - * @return Client index, or 0 if invalid userid passed.
1.429 - */
1.430 - virtual int GetClientOfUserId(int userid) =0;
1.431 -
1.432 - /**
1.433 - * @brief Returns whether or not the server is activated.
1.434 - *
1.435 - * @return True if ServerActivate() has been called
1.436 - * at least once, false otherwise.
1.437 - */
1.438 - virtual bool IsServerActivated() =0;
1.439 -
1.440 - /**
1.441 - * @brief Gets SourceMod's reply source.
1.442 - *
1.443 - * @return ReplyTo source.
1.444 - */
1.445 - virtual unsigned int GetReplyTo() =0;
1.446 -
1.447 - /**
1.448 - * @brief Sets SourceMod's reply source.
1.449 - *
1.450 - * @param reply Reply source.
1.451 - * @return Old reply source.
1.452 - */
1.453 - virtual unsigned int SetReplyTo(unsigned int reply) =0;
1.454 -
1.455 - /**
1.456 - * @brief Tests if a player meets command filtering rules.
1.457 - *
1.458 - * @param pAdmin IGamePlayer of the admin, or NULL if the server.
1.459 - * @param pTarget IGamePlayer of the player being targeted.
1.460 - * @param flags COMMAND_FILTER flags.
1.461 - * @return COMMAND_TARGET value.
1.462 - */
1.463 - virtual int FilterCommandTarget(IGamePlayer *pAdmin, IGamePlayer *pTarget, int flags) =0;
1.464 -
1.465 - /**
1.466 - * @brief Registers a command target processor.
1.467 - *
1.468 - * @param pHandler Pointer to an ICommandTargetProcessor instance.
1.469 - */
1.470 - virtual void RegisterCommandTargetProcessor(ICommandTargetProcessor *pHandler) =0;
1.471 -
1.472 - /**
1.473 - * @brief Removes a command target processor.
1.474 - *
1.475 - * @param pHandler Pointer to an ICommandTargetProcessor instance.
1.476 - */
1.477 - virtual void UnregisterCommandTargetProcessor(ICommandTargetProcessor *pHandler) =0;
1.478 - };
1.479 -}
1.480 -
1.481 -#endif //_INCLUDE_SOURCEMOD_INTERFACE_IPLAYERHELPERS_H_