plugins/include/clients.inc
author Scott Ehlert <ds@alliedmods.net>
Fri Mar 16 06:54:24 2007 +0000 (2007-03-16)
changeset 621 5a0f5014aac1
parent 619 6934bf39171e
child 634 85108309e453
permissions -rw-r--r--
Dear me, I should have committed this long ago...
1) Added natives to create and manipulate global and private forward
2) Added natives to call forwards and functions
3) Added an IChanageableForward::RemoveFunction overload for convenience or something
4) Added test suite plugins for functions and forwards
5) Some random touch-ups to some include files
     1 /**
     2  * vim: set ts=4 :
     3  * ===============================================================
     4  * SourceMod (C)2004-2007 AlliedModders LLC.  All rights reserved.
     5  * ===============================================================
     6  *
     7  *  This file is part of the SourceMod/SourcePawn SDK.  This file may only be used 
     8  * or modified under the Terms and Conditions of its License Agreement, which is found 
     9  * in LICENSE.txt.  The Terms and Conditions for making SourceMod extensions/plugins 
    10  * may change at any time.  To view the latest information, see:
    11  *   http://www.sourcemod.net/license.php
    12  *
    13  * Version: $Id$
    14  */
    15 
    16 #if defined _clients_included
    17  #endinput
    18 #endif
    19 #define _clients_included
    20 
    21 /**
    22  * Called on client connection.
    23  *
    24  * @param client		Player index.
    25  * @param rejectmsg		Buffer to store the rejection message when the connection is refused.
    26  * @param maxlen		Maximum number of characters for rejection buffer.
    27  * @return				True to validate client's connection, false to refuse it.
    28  */
    29 forward bool:OnClientConnect(client, String:rejectmsg[], maxlen);
    30 
    31 /**
    32  * Called when a client is entering to the game.
    33  *
    34  * @param client		Player index.
    35  * @noreturn
    36  */
    37 forward OnClientPutInServer(client);
    38 
    39 /**
    40  * Called when a client is disconnecting from the server.
    41  *
    42  * @param client		Player index.
    43  * @noreturn
    44  */
    45 forward OnClientDisconnect(client);
    46 
    47 /**
    48  * Called when a client is disconnected from the server.
    49  *
    50  * @param client		Player index.
    51  * @noreturn
    52  */
    53 forward OnClientDisconnect_Post(client);
    54 
    55 /**
    56  * Called when a client is sending a command.
    57  *
    58  * @param client		Player index.
    59  * @param args			Number of arguments.
    60  * @noreturn
    61  */
    62 forward Action:OnClientCommand(client, args);
    63 
    64 /**
    65  * Called whenever the client's settings are changed.
    66  *
    67  * @param client		Player index.
    68  * @noreturn
    69  */
    70 forward OnClientSettingsChanged(client);
    71 
    72 /**
    73  * Called when a client receives a Steam ID.
    74  * @note This is called by bots, but the ID will be "BOT"
    75  *
    76  * @param client		Player index.
    77  * @param auth			Player auth string.
    78  */
    79 forward OnClientAuthorized(client, const String:auth[]);
    80 
    81 /**
    82  * Returns the maximum number of clients allowed on the server.
    83  *
    84  * @return				Maximum number of clients allowed.
    85  */
    86 native GetMaxClients();
    87 
    88 /**
    89  * Returns the client count put in the server.
    90  *
    91  * @param inGameOnly	If false connecting players are also counted.
    92  * @return				Client count in the server.
    93  */
    94 native GetClientCount(bool:inGameOnly=true);
    95 
    96 /**
    97  * Returns the client's name.
    98  *
    99  * @param client		Player index.
   100  * @param name			Buffer to store the client's name.
   101  * @param maxlen		Maximum length of string buffer (includes NULL terminator).
   102  * @return				True on success, false otherwise.
   103  * @error				If the client is not connected an error will be thrown.
   104  */
   105 native bool:GetClientName(client, String:name[], maxlen);
   106 
   107 /**
   108  * Retrieves a client's IP address.
   109  *
   110  * @param client		Player index.
   111  * @param name			Buffer to store the client's ip address.
   112  * @param maxlen		Maximum length of string buffer (includes NULL terminator).
   113  * @param remport		Remove client's port from the ip string (true by default).
   114  * @return				True on success, false otherwise.
   115  * @error				If the client is not connected or the index is invalid.
   116  */
   117 native bool:GetClientIP(client, String:ip[], maxlen, bool:remport=true);
   118 
   119 /**
   120  * Retrieves a client's authentication string (SteamID).
   121  *
   122  * @param client		Player index.
   123  * @param auth			Buffer to store the client's auth string.
   124  * @param maxlen		Maximum length of string buffer (includes NULL terminator).
   125  * @return				True on success, false otherwise.
   126  * @error				If the client is not connected or the index is invalid.
   127  */
   128 native bool:GetClientAuthString(client, String:auth[], maxlen);
   129 
   130 /**
   131  * Retrieves a client's user id, which is an index incremented for every client
   132  * that joins the server.
   133  *
   134  * @param client		Player index.
   135  * @return				User id of the client.
   136  * @error 				If the client is not connected or the index is invalid.
   137  */
   138 native GetClientUserId(client);
   139 
   140 /**
   141  * Returns if a certain player is connected.
   142  *
   143  * @param client		Player index.
   144  * @return				True if player is connected to the server, false otherwise.
   145  */
   146 native bool:IsClientConnected(client);
   147 
   148 /**
   149  * Returns if a certain player has entered the game.
   150  *
   151  * @param client		Player index.
   152  * @return				True if player has entered the game, false otherwise.
   153  */
   154 native bool:IsPlayerInGame(client);
   155 
   156 /**
   157  * Returns if a certain player has been authenticated.
   158  *
   159  * @param client		Player index.
   160  * @return				True if player has been authenticated, false otherwise.
   161  */
   162 native bool:IsClientAuthorized(client);
   163 
   164 /**
   165  * Returns if a certain player is a fake client.
   166  *
   167  * @param client		Player index.
   168  * @return				True if player is a fake client, false otherwise.
   169  */
   170 native bool:IsFakeClient(client);
   171 
   172 /**
   173  * Retrieves values from client replicated keys.
   174  *
   175  * @param client		Player's index.
   176  * @param key			Key string.
   177  * @param value			Buffer to store value.
   178  * @param maxlen		Maximum length of valve (UTF-8 safe).
   179  * @return 				True on success, false otherwise.
   180  * @error				Invalid client index, or client not connected.
   181  */
   182 native bool:GetClientInfo(client, const String:key[], String:value[], maxlen);
   183 
   184 /**
   185  * Sets a client's AdminId.  
   186  *
   187  * @param client		Player's index.
   188  * @param id			AdminId to set.  INVALID_ADMIN_ID removes admin permissions.
   189  * @param temp			True if the id should be freed on disconnect.
   190  * @noreturn
   191  * @error				Invalid client index, client not connected, or bogus AdminId.
   192  */
   193 native SetUserAdmin(client, AdminId:id, bool:temp=false);
   194 
   195 /**
   196  * Retrieves a client's AdminId.
   197  *
   198  * @param client		Player's index.
   199  * @return				AdminId of the client, or INVALID_ADMIN_ID if none.
   200  * @error				Invalid client index, or client not connected.
   201  */
   202 native AdminId:GetUserAdmin(client);
   203 
   204 /**
   205  * Sets access flags on a client.  If the client is not an admin,
   206  * a temporary, anonymous AdminId is given.
   207  *
   208  * @param client		Player's index.
   209  * @param ...			Flags to set on the client.
   210  * @noreturn
   211  * @error				Invalid client index, or client not connected.
   212  */
   213 native AddUserFlags(client, {AdminFlag}:...);
   214 
   215 /**
   216  * Removes flags from a client.  If the client is not an admin,
   217  * this has no effect.
   218  *
   219  * @param client		Player's index.
   220  * @param ...			Flags to remove from the client.
   221  * @noreturn
   222  * @error				Invalid client index, or client not connected.
   223  */
   224 native RemoveUserFlags(client, {AdminFlag}:...);
   225 
   226 /** 
   227  * Sets access flags on a client using bits instead of flags.  If the
   228  * client is not an admin, and flags not 0, a temporary, anonymous AdminId is given.
   229  *
   230  * @param client		Player's index.
   231  * @param flags			Bitstring of flags to set on client.
   232  * @noreturn
   233  */
   234 native SetUserFlagBits(client, flags);
   235 
   236 /**
   237  * Returns client access flags.  If the client is not an admin,
   238  * the result is always 0.
   239  * 
   240  * @param client		Player's index.
   241  * @return				Flags
   242  * @error				Invalid client index, or client not connected.
   243  */
   244 native GetUserFlagBits(client);
   245 
   246 /**
   247  * Returns whether a user can target another user.
   248  * This is a helper function for CanAdminTarget.
   249  *
   250  * @param client		Player's index.
   251  * @param target		Target player's index.
   252  * @return				True if target is targettable by the player, false otherwise.
   253  * @error				Invalid or unconnected player indexers.
   254  */
   255 native bool:CanUserTarget(client, target);
   256 
   257 /** 
   258  * Creates a fake client.
   259  *
   260  * @param name			Name to use.
   261  * @return				Client index on success, 0 otherwise.
   262  */
   263 native CreateFakeClient(const String:name[]);
   264 
   265 /**
   266  * Sets a convar value on a fake client.
   267  *
   268  * @param client		Client index.
   269  * @param cvar			ConVar name.
   270  * @param value			ConVar value.
   271  * @noreturn
   272  * @error				Invalid client index, client not connected,
   273  *						or client not a fake client.
   274  */
   275 native SetFakeClientConVar(client, const String:cvar[], const String:value[]);