plugins/include/clients.inc
author David Anderson <dvander@alliedmods.net>
Tue Nov 27 22:50:52 2007 +0000 (2007-11-27)
changeset 1731 5b179e6d5d30
parent 1621 ac5d4c68a99a
child 1813 372939c88bc7
permissions -rw-r--r--
added DS's patch from amb1179
     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.
     8  *
     9  * This program is free software; you can redistribute it and/or modify it under
    10  * the terms of the GNU General Public License, version 3.0, as published by the
    11  * Free Software Foundation.
    12  * 
    13  * This program is distributed in the hope that it will be useful, but WITHOUT
    14  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
    15  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
    16  * details.
    17  *
    18  * You should have received a copy of the GNU General Public License along with
    19  * this program.  If not, see <http://www.gnu.org/licenses/>.
    20  *
    21  * As a special exception, AlliedModders LLC gives you permission to link the
    22  * code of this program (as well as its derivative works) to "Half-Life 2," the
    23  * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
    24  * by the Valve Corporation.  You must obey the GNU General Public License in
    25  * all respects for all other code used.  Additionally, AlliedModders LLC grants
    26  * this exception to all derivative works.  AlliedModders LLC defines further
    27  * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
    28  * or <http://www.sourcemod.net/license.php>.
    29  *
    30  * Version: $Id$
    31  */
    32 
    33 #if defined _clients_included
    34  #endinput
    35 #endif
    36 #define _clients_included
    37 
    38 enum NetFlow
    39 {
    40 	NetFlow_Outgoing = 0,	/**< Outgoing traffic */
    41 	NetFlow_Incoming,		/**< Incoming traffic */
    42 	NetFlow_Both			/**< Incoming and outgoing traffic */
    43 };
    44 
    45 #define MAXPLAYERS		64	/**< Maximum number of players that can be in server */
    46 #define MAX_NAME_LENGTH 32	/**< Maximum buffer required to store a client name */
    47 
    48 /**
    49  * Called on client connection.
    50  *
    51  * @param client		Client index.
    52  * @param rejectmsg		Buffer to store the rejection message when the connection is refused.
    53  * @param maxlen		Maximum number of characters for rejection buffer.
    54  * @return				True to validate client's connection, false to refuse it.
    55  */
    56 forward bool:OnClientConnect(client, String:rejectmsg[], maxlen);
    57 
    58 /**
    59  * Called when a client is entering to the game.
    60  *
    61  * @note Whether a client has a steamid is undefined until OnClientAuthorized
    62  * is called, which may occur either before or after OnClientPutInServer.
    63  *
    64  * @param client		Client index.
    65  * @noreturn
    66  */
    67 forward OnClientPutInServer(client);
    68 
    69 /**
    70  * Called when a client is disconnecting from the server.
    71  *
    72  * @param client		Client index.
    73  * @noreturn
    74  */
    75 forward OnClientDisconnect(client);
    76 
    77 /**
    78  * Called when a client is disconnected from the server.
    79  *
    80  * @param client		Client index.
    81  * @noreturn
    82  */
    83 forward OnClientDisconnect_Post(client);
    84 
    85 /**
    86  * Called when a client is sending a command.
    87  *
    88  * @param client		Client index.
    89  * @param args			Number of arguments.
    90  * @noreturn
    91  */
    92 forward Action:OnClientCommand(client, args);
    93 
    94 /**
    95  * Called whenever the client's settings are changed.
    96  *
    97  * @param client		Client index.
    98  * @noreturn
    99  */
   100 forward OnClientSettingsChanged(client);
   101 
   102 /**
   103  * Called when a client receives a Steam ID.
   104  
   105  * Admin properties are not assigned here, but on OnClientPostAdminCheck().
   106  * This is called by bots, but the ID will be "BOT".
   107  *
   108  * @param client		Client index.
   109  * @param auth			Client auth string.
   110  * @noreturn
   111  */
   112 forward OnClientAuthorized(client, const String:auth[]);
   113 
   114 /**
   115  * Called once a client is authorized and fully in-game, but 
   116  * before admin checks are done.  This can be used to override 
   117  * the default admin checks for a client.
   118  *
   119  * Note: If handled/blocked, PostAdminCheck must be signalled 
   120  * manually via NotifyPostAdminCheck().
   121  *
   122  * @param client		Client index.
   123  * @return				Plugin_Handled to block admin checks.
   124  */
   125 forward Action:OnClientPreAdminCheck(client);
   126 
   127 /**
   128  * Called once a client is authorized and fully in-game, and 
   129  * after all post-connection authorizations have been performed.
   130  *
   131  * @param client		Client index.
   132  * @noreturn
   133  */
   134 forward OnClientPostAdminCheck(client);
   135 
   136 /**
   137  * Returns the maximum number of clients allowed on the server.  This may 
   138  * return 0 if called before OnMapStart(), and thus should not be called 
   139  * in OnPluginStart().  
   140  *
   141  * @return				Maximum number of clients allowed.
   142  */
   143 native GetMaxClients();
   144 
   145 /**
   146  * Returns the client count put in the server.
   147  *
   148  * @param inGameOnly	If false connecting players are also counted.
   149  * @return				Client count in the server.
   150  */
   151 native GetClientCount(bool:inGameOnly=true);
   152 
   153 /**
   154  * Returns the client's name.
   155  *
   156  * @param client		Player index.
   157  * @param name			Buffer to store the client's name.
   158  * @param maxlen		Maximum length of string buffer (includes NULL terminator).
   159  * @return				True on success, false otherwise.
   160  * @error				If the client is not connected an error will be thrown.
   161  */
   162 native bool:GetClientName(client, String:name[], maxlen);
   163 
   164 /**
   165  * Retrieves a client's IP address.
   166  *
   167  * @param client		Player index.
   168  * @param name			Buffer to store the client's ip address.
   169  * @param maxlen		Maximum length of string buffer (includes NULL terminator).
   170  * @param remport		Remove client's port from the ip string (true by default).
   171  * @return				True on success, false otherwise.
   172  * @error				If the client is not connected or the index is invalid.
   173  */
   174 native bool:GetClientIP(client, String:ip[], maxlen, bool:remport=true);
   175 
   176 /**
   177  * Retrieves a client's authentication string (SteamID).
   178  *
   179  * @param client		Player index.
   180  * @param auth			Buffer to store the client's auth string.
   181  * @param maxlen		Maximum length of string buffer (includes NULL terminator).
   182  * @return				True on success, false otherwise.
   183  * @error				If the client is not connected or the index is invalid.
   184  */
   185 native bool:GetClientAuthString(client, String:auth[], maxlen);
   186 
   187 /**
   188  * Retrieves a client's user id, which is an index incremented for every client
   189  * that joins the server.
   190  *
   191  * @param client		Player index.
   192  * @return				User id of the client.
   193  * @error 				If the client is not connected or the index is invalid.
   194  */
   195 native GetClientUserId(client);
   196 
   197 /**
   198  * Returns if a certain player is connected.
   199  *
   200  * @param client		Player index.
   201  * @return				True if player is connected to the server, false otherwise.
   202  */
   203 native bool:IsClientConnected(client);
   204 
   205 /**
   206  * Returns if a certain player has entered the game.
   207  *
   208  * @param client		Player index (index does not have to be connected).
   209  * @return				True if player has entered the game, false otherwise.
   210  * @error				Invalid client index.
   211  */
   212 native bool:IsClientInGame(client);
   213 
   214 /**
   215  * Returns if a client is in the "kick queue" (i.e. the client will be kicked 
   216  * shortly and thus they should not appear as valid).
   217  *
   218  * @param client		Player index (must be connected).
   219  * @return				True if in the kick queue, false otherwise.
   220  * @error				Invalid client index.
   221  */
   222 native bool:IsClientInKickQueue(client);
   223 
   224 /**
   225  * Backwards compatibility stock - use IsClientInGame
   226  * @deprecated			Renamed to IsClientInGame
   227  */
   228 #pragma deprecated Use IsClientInGame() instead
   229 stock bool:IsPlayerInGame(client)
   230 {
   231 	return IsClientInGame(client);
   232 }
   233 
   234 /**
   235  * Returns if a certain player has been authenticated.
   236  *
   237  * @param client		Player index.
   238  * @return				True if player has been authenticated, false otherwise.
   239  */
   240 native bool:IsClientAuthorized(client);
   241 
   242 /**
   243  * Returns if a certain player is a fake client.
   244  *
   245  * @param client		Player index.
   246  * @return				True if player is a fake client, false otherwise.
   247  */
   248 native bool:IsFakeClient(client);
   249 
   250 /**
   251  * Returns if a certain player is an observer/spectator.
   252  *
   253  * @param client		Player index.
   254  * @return				True if player is an obverser, false otherwise.
   255  */
   256 native bool:IsClientObserver(client);
   257 
   258 /**
   259  * Returns if the client is alive or dead.
   260  *
   261  * Note: This function was originally in SDKTools and was moved to core.
   262  *
   263  * @param client		Player's index.
   264  * @return				True if the client is alive, false otherwise.
   265  * @error				Invalid client index, client not in game, or no mod support.
   266  */
   267 native bool:IsPlayerAlive(client);
   268 
   269 /**
   270  * Retrieves values from client replicated keys.
   271  *
   272  * @param client		Player's index.
   273  * @param key			Key string.
   274  * @param value			Buffer to store value.
   275  * @param maxlen		Maximum length of valve (UTF-8 safe).
   276  * @return 				True on success, false otherwise.
   277  * @error				Invalid client index, or client not connected.
   278  */
   279 native bool:GetClientInfo(client, const String:key[], String:value[], maxlen);
   280 
   281 /**
   282  * Retrieves a client's team index.
   283  *
   284  * @param client		Player's index.
   285  * @return				Team index the client is on (mod specific).
   286  * @error				Invalid client index, client not in game, or no mod support.
   287  */
   288 native GetClientTeam(client);
   289  
   290 /**
   291  * Sets a client's AdminId.  
   292  *
   293  * @param client		Player's index.
   294  * @param id			AdminId to set.  INVALID_ADMIN_ID removes admin permissions.
   295  * @param temp			True if the id should be freed on disconnect.
   296  * @noreturn
   297  * @error				Invalid client index, client not connected, or bogus AdminId.
   298  */
   299 native SetUserAdmin(client, AdminId:id, bool:temp=false);
   300 
   301 /**
   302  * Retrieves a client's AdminId.
   303  *
   304  * @param client		Player's index.
   305  * @return				AdminId of the client, or INVALID_ADMIN_ID if none.
   306  * @error				Invalid client index, or client not connected.
   307  */
   308 native AdminId:GetUserAdmin(client);
   309 
   310 /**
   311  * Sets access flags on a client.  If the client is not an admin,
   312  * a temporary, anonymous AdminId is given.
   313  *
   314  * @param client		Player's index.
   315  * @param ...			Flags to set on the client.
   316  * @noreturn
   317  * @error				Invalid client index, or client not connected.
   318  */
   319 native AddUserFlags(client, AdminFlag:...);
   320 
   321 /**
   322  * Removes flags from a client.  If the client is not an admin,
   323  * this has no effect.
   324  *
   325  * @param client		Player's index.
   326  * @param ...			Flags to remove from the client.
   327  * @noreturn
   328  * @error				Invalid client index, or client not connected.
   329  */
   330 native RemoveUserFlags(client, AdminFlag:...);
   331 
   332 /** 
   333  * Sets access flags on a client using bits instead of flags.  If the
   334  * client is not an admin, and flags not 0, a temporary, anonymous AdminId is given.
   335  *
   336  * @param client		Player's index.
   337  * @param flags			Bitstring of flags to set on client.
   338  * @noreturn
   339  */
   340 native SetUserFlagBits(client, flags);
   341 
   342 /**
   343  * Returns client access flags.  If the client is not an admin,
   344  * the result is always 0.
   345  * 
   346  * @param client		Player's index.
   347  * @return				Flags
   348  * @error				Invalid client index, or client not connected.
   349  */
   350 native GetUserFlagBits(client);
   351 
   352 /**
   353  * Returns whether a user can target another user.
   354  * This is a helper function for CanAdminTarget.
   355  *
   356  * @param client		Player's index.
   357  * @param target		Target player's index.
   358  * @return				True if target is targettable by the player, false otherwise.
   359  * @error				Invalid or unconnected player indexers.
   360  */
   361 native bool:CanUserTarget(client, target);
   362 
   363 /**
   364  * Runs through the Core-defined admin authorization checks on a player.
   365  * Has no effect if the player is already an admin.
   366  *
   367  * Note: This function is based on the internal cache only.
   368  *
   369  * @param client		Client index.
   370  * @return				True if access was changed, false if it did not.
   371  * @error				Invalid client index or client not in-game AND authorized.
   372  */
   373 native bool:RunAdminCacheChecks(client);
   374 
   375 /**
   376  * Signals that a player has completed post-connection admin checks.
   377  * Has no effect if the player has already had this event signalled.
   378  *
   379  * Note: This must be sent even if no admin id was assigned.
   380  *
   381  * @param client		Client index.
   382  * @noreturn
   383  * @error				Invalid client index or client not in-game AND authorized.
   384  */
   385 native NotifyPostAdminCheck(client);
   386 
   387 /** 
   388  * Creates a fake client.
   389  *
   390  * @param name			Name to use.
   391  * @return				Client index on success, 0 otherwise.
   392  */
   393 native CreateFakeClient(const String:name[]);
   394 
   395 /**
   396  * Sets a convar value on a fake client.
   397  *
   398  * @param client		Client index.
   399  * @param cvar			ConVar name.
   400  * @param value			ConVar value.
   401  * @noreturn
   402  * @error				Invalid client index, client not connected,
   403  *						or client not a fake client.
   404  */
   405 native SetFakeClientConVar(client, const String:cvar[], const String:value[]);
   406 
   407 /**
   408  * Returns the client's health.
   409  *
   410  * @param client		Player's index.
   411  * @return				Health value.
   412  * @error				Invalid client index, client not in game, or no mod support.
   413  */
   414 native GetClientHealth(client);
   415 
   416 /**
   417  * Returns the client's model name.
   418  *
   419  * @param client		Player's index.
   420  * @param model			Buffer to store the client's model name.
   421  * @param maxlen		Maximum length of string buffer (includes NULL terminator).
   422  * @noreturn
   423  * @error				Invalid client index, client not in game, or no mod support.
   424  */
   425 native GetClientModel(client, String:model[], maxlen);
   426 
   427 /**
   428  * Returns the client's weapon name.
   429  *
   430  * @param client		Player's index.
   431  * @param weapon		Buffer to store the client's weapon name.
   432  * @param maxlen		Maximum length of string buffer (includes NULL terminator).
   433  * @noreturn
   434  * @error				Invalid client index, client not in game, or no mod support.
   435  */
   436 native GetClientWeapon(client, String:weapon[], maxlen);
   437 
   438 /**
   439  * Returns the client's max size vector.
   440  *
   441  * @param client		Player's index.
   442  * @param vec			Destination vector to store the client's max size.
   443  * @noreturn
   444  * @error				Invalid client index, client not in game, or no mod support.
   445  */
   446 native GetClientMaxs(client, Float:vec[3]);
   447 
   448 /**
   449  * Returns the client's min size vector.
   450  *
   451  * @param client		Player's index.
   452  * @param vec			Destination vector to store the client's min size.
   453  * @noreturn
   454  * @error				Invalid client index, client not in game, or no mod support.
   455  */
   456 native GetClientMins(client, Float:vec[3]);
   457 
   458 /**
   459  * Returns the client's position angle.
   460  *
   461  * @param client		Player's index.
   462  * @param ang			Destination vector to store the client's position angle.
   463  * @noreturn
   464  * @error				Invalid client index, client not in game, or no mod support.
   465  */
   466 native GetClientAbsAngles(client, Float:ang[3]);
   467 
   468 /**
   469  * Returns the client's origin vector.
   470  *
   471  * @param client		Player's index.
   472  * @param vec			Destination vector to store the client's origin vector.
   473  * @noreturn
   474  * @error				Invalid client index, client not in game, or no mod support.
   475  */
   476 native GetClientAbsOrigin(client, Float:vec[3]);
   477 
   478 /**
   479  * Returns the client's armor.
   480  *
   481  * @param client		Player's index.
   482  * @return				Armor value.
   483  * @error				Invalid client index, client not in game, or no mod support.
   484  */
   485 native GetClientArmor(client);
   486 
   487 /**
   488  * Returns the client's death count.
   489  *
   490  * @param client		Player's index.
   491  * @return				Death count.
   492  * @error				Invalid client index, client not in game, or no mod support.
   493  */
   494 native GetClientDeaths(client);
   495 
   496 /**
   497  * Returns the client's frag count.
   498  *
   499  * @param client		Player's index.
   500  * @return				Frag count.
   501  * @error				Invalid client index, client not in game, or no mod support.
   502  */
   503 native GetClientFrags(client);
   504 
   505 /**
   506  * Returns the client's send data rate in bytes/sec.
   507  *
   508  * @param client		Player's index.
   509  * @return				Data rate.
   510  * @error				Invalid client index, client not in game, or fake client.
   511  */
   512 native GetClientDataRate(client);
   513 
   514 /**
   515  * Returns if a client is timing out
   516  *
   517  * @param client		Player's index.
   518  * @return				True if client is timing out, false otherwise.
   519  * @error				Invalid client index, client not in game, or fake client.
   520  */
   521 native bool:IsClientTimingOut(client);
   522 
   523 /**
   524  * Returns the client's connection time in seconds.
   525  *
   526  * @param client		Player's index.
   527  * @return				Connection time.
   528  * @error				Invalid client index, client not in game, or fake client.
   529  */
   530 native Float:GetClientTime(client);
   531 
   532 /**
   533  * Returns the client's current latency (RTT), more accurate than GetAvgLatency but jittering.
   534  *
   535  * @param client		Player's index.
   536  * @param flow			Traffic flowing direction.
   537  * @return				Latency.
   538  * @error				Invalid client index, client not in game, or fake client.
   539  */
   540 native Float:GetClientLatency(client, NetFlow:flow);
   541 
   542 /**
   543  * Returns the client's average packet latency in seconds.
   544  *
   545  * @param client		Player's index.
   546  * @param flow			Traffic flowing direction.
   547  * @return				Average latency.
   548  * @error				Invalid client index, client not in game, or fake client.
   549  */
   550 native Float:GetClientAvgLatency(client, NetFlow:flow);
   551 
   552 /**
   553  * Returns the client's average packet loss, values go from 0 to 1 (for percentages).
   554  *
   555  * @param client		Player's index.
   556  * @param flow			Traffic flowing direction.
   557  * @return				Average packet loss.
   558  * @error				Invalid client index, client not in game, or fake client.
   559  */
   560 native Float:GetClientAvgLoss(client, NetFlow:flow);
   561 
   562 /**
   563  * Returns the client's average packet choke, values go from 0 to 1 (for percentages).
   564  *
   565  * @param client		Player's index.
   566  * @param flow			Traffic flowing direction.
   567  * @return				Average packet choke.
   568  * @error				Invalid client index, client not in game, or fake client.
   569  */
   570 native Float:GetClientAvgChoke(client, NetFlow:flow);
   571 
   572 /**
   573  * Returns the client's data flow in bytes/sec.
   574  *
   575  * @param client		Player's index.
   576  * @param flow			Traffic flowing direction.
   577  * @return				Data flow.
   578  * @error				Invalid client index, client not in game, or fake client.
   579  */
   580 native Float:GetClientAvgData(client, NetFlow:flow);
   581 
   582 /**
   583  * Returns the client's average packet frequency in packets/sec.
   584  *
   585  * @param client		Player's index.
   586  * @param flow			Traffic flowing direction.
   587  * @return				Packet frequency.
   588  * @error				Invalid client index, client not in game, or fake client.
   589  */
   590 native Float:GetClientAvgPackets(client, NetFlow:flow);
   591 
   592 /**
   593  * Translates an userid index to the real player index.
   594  *
   595  * @param userid		Userid value.
   596  * @return				Client value.
   597  * @error				Returns 0 if invalid userid.
   598  */
   599 native GetClientOfUserId(userid);
   600 
   601 /**
   602  * Disconnects a client from the server.  
   603  *
   604  * Kicking clients from certain events or callbacks may cause crashes.  If in 
   605  * doubt, create a short (0.1 second) timer to kick the client in the next 
   606  * available frame.
   607  *
   608  * @param client		Client index.
   609  * @param format		Optional formatting rules for disconnect reason.
   610  *                      Note that a period is automatically appended to the string by the engine.
   611  * @param ...			Variable number of format parameters.
   612  * @noreturn
   613  * @error				Invalid client index, or client not connected.
   614  */
   615 native KickClient(client, const String:format[]="", any:...);
   616 
   617 /**
   618  * Changes a client's team through the mod's generic team changing function.
   619  * On CS:S, this will kill the player.
   620  *
   621  * @param client		Client index.
   622  * @param team			Mod-specific team index.
   623  * @noreturn
   624  * @error				Invalid client index, client not connected, or lack of 
   625  *						mod support.
   626  */
   627 native ChangeClientTeam(client, team);
   628