plugins/include/clients.inc
author David Anderson <dvander@alliedmods.net>
Tue Oct 02 14:48:44 2007 +0000 (2007-10-02)
changeset 1525 bca151238f5e
parent 1509 cbb82af65663
child 1621 ac5d4c68a99a
permissions -rw-r--r--
- removed incorrect information about DrawOption, renamed to DisplayOption
- renamed DrawTitle to DisplayTitle
     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  * Retrieves values from client replicated keys.
   260  *
   261  * @param client		Player's index.
   262  * @param key			Key string.
   263  * @param value			Buffer to store value.
   264  * @param maxlen		Maximum length of valve (UTF-8 safe).
   265  * @return 				True on success, false otherwise.
   266  * @error				Invalid client index, or client not connected.
   267  */
   268 native bool:GetClientInfo(client, const String:key[], String:value[], maxlen);
   269 
   270 /**
   271  * Retrieves a client's team index.
   272  *
   273  * @param client		Player's index.
   274  * @return				Team index the client is on (mod specific).
   275  * @error				Invalid client index, client not in game, or no mod support.
   276  */
   277 native GetClientTeam(client);
   278  
   279 /**
   280  * Sets a client's AdminId.  
   281  *
   282  * @param client		Player's index.
   283  * @param id			AdminId to set.  INVALID_ADMIN_ID removes admin permissions.
   284  * @param temp			True if the id should be freed on disconnect.
   285  * @noreturn
   286  * @error				Invalid client index, client not connected, or bogus AdminId.
   287  */
   288 native SetUserAdmin(client, AdminId:id, bool:temp=false);
   289 
   290 /**
   291  * Retrieves a client's AdminId.
   292  *
   293  * @param client		Player's index.
   294  * @return				AdminId of the client, or INVALID_ADMIN_ID if none.
   295  * @error				Invalid client index, or client not connected.
   296  */
   297 native AdminId:GetUserAdmin(client);
   298 
   299 /**
   300  * Sets access flags on a client.  If the client is not an admin,
   301  * a temporary, anonymous AdminId is given.
   302  *
   303  * @param client		Player's index.
   304  * @param ...			Flags to set on the client.
   305  * @noreturn
   306  * @error				Invalid client index, or client not connected.
   307  */
   308 native AddUserFlags(client, AdminFlag:...);
   309 
   310 /**
   311  * Removes flags from a client.  If the client is not an admin,
   312  * this has no effect.
   313  *
   314  * @param client		Player's index.
   315  * @param ...			Flags to remove from the client.
   316  * @noreturn
   317  * @error				Invalid client index, or client not connected.
   318  */
   319 native RemoveUserFlags(client, AdminFlag:...);
   320 
   321 /** 
   322  * Sets access flags on a client using bits instead of flags.  If the
   323  * client is not an admin, and flags not 0, a temporary, anonymous AdminId is given.
   324  *
   325  * @param client		Player's index.
   326  * @param flags			Bitstring of flags to set on client.
   327  * @noreturn
   328  */
   329 native SetUserFlagBits(client, flags);
   330 
   331 /**
   332  * Returns client access flags.  If the client is not an admin,
   333  * the result is always 0.
   334  * 
   335  * @param client		Player's index.
   336  * @return				Flags
   337  * @error				Invalid client index, or client not connected.
   338  */
   339 native GetUserFlagBits(client);
   340 
   341 /**
   342  * Returns whether a user can target another user.
   343  * This is a helper function for CanAdminTarget.
   344  *
   345  * @param client		Player's index.
   346  * @param target		Target player's index.
   347  * @return				True if target is targettable by the player, false otherwise.
   348  * @error				Invalid or unconnected player indexers.
   349  */
   350 native bool:CanUserTarget(client, target);
   351 
   352 /**
   353  * Runs through the Core-defined admin authorization checks on a player.
   354  * Has no effect if the player is already an admin.
   355  *
   356  * Note: This function is based on the internal cache only.
   357  *
   358  * @param client		Client index.
   359  * @return				True if access was changed, false if it did not.
   360  * @error				Invalid client index or client not in-game AND authorized.
   361  */
   362 native bool:RunAdminCacheChecks(client);
   363 
   364 /**
   365  * Signals that a player has completed post-connection admin checks.
   366  * Has no effect if the player has already had this event signalled.
   367  *
   368  * Note: This must be sent even if no admin id was assigned.
   369  *
   370  * @param client		Client index.
   371  * @noreturn
   372  * @error				Invalid client index or client not in-game AND authorized.
   373  */
   374 native NotifyPostAdminCheck(client);
   375 
   376 /** 
   377  * Creates a fake client.
   378  *
   379  * @param name			Name to use.
   380  * @return				Client index on success, 0 otherwise.
   381  */
   382 native CreateFakeClient(const String:name[]);
   383 
   384 /**
   385  * Sets a convar value on a fake client.
   386  *
   387  * @param client		Client index.
   388  * @param cvar			ConVar name.
   389  * @param value			ConVar value.
   390  * @noreturn
   391  * @error				Invalid client index, client not connected,
   392  *						or client not a fake client.
   393  */
   394 native SetFakeClientConVar(client, const String:cvar[], const String:value[]);
   395 
   396 /**
   397  * Returns the client's health.
   398  *
   399  * @param client		Player's index.
   400  * @return				Health value.
   401  * @error				Invalid client index, client not in game, or no mod support.
   402  */
   403 native GetClientHealth(client);
   404 
   405 /**
   406  * Returns the client's model name.
   407  *
   408  * @param client		Player's index.
   409  * @param model			Buffer to store the client's model name.
   410  * @param maxlen		Maximum length of string buffer (includes NULL terminator).
   411  * @noreturn
   412  * @error				Invalid client index, client not in game, or no mod support.
   413  */
   414 native GetClientModel(client, String:model[], maxlen);
   415 
   416 /**
   417  * Returns the client's weapon name.
   418  *
   419  * @param client		Player's index.
   420  * @param weapon		Buffer to store the client's weapon 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 GetClientWeapon(client, String:weapon[], maxlen);
   426 
   427 /**
   428  * Returns the client's max size vector.
   429  *
   430  * @param client		Player's index.
   431  * @param vec			Destination vector to store the client's max size.
   432  * @noreturn
   433  * @error				Invalid client index, client not in game, or no mod support.
   434  */
   435 native GetClientMaxs(client, Float:vec[3]);
   436 
   437 /**
   438  * Returns the client's min size vector.
   439  *
   440  * @param client		Player's index.
   441  * @param vec			Destination vector to store the client's min size.
   442  * @noreturn
   443  * @error				Invalid client index, client not in game, or no mod support.
   444  */
   445 native GetClientMins(client, Float:vec[3]);
   446 
   447 /**
   448  * Returns the client's position angle.
   449  *
   450  * @param client		Player's index.
   451  * @param ang			Destination vector to store the client's position angle.
   452  * @noreturn
   453  * @error				Invalid client index, client not in game, or no mod support.
   454  */
   455 native GetClientAbsAngles(client, Float:ang[3]);
   456 
   457 /**
   458  * Returns the client's origin vector.
   459  *
   460  * @param client		Player's index.
   461  * @param vec			Destination vector to store the client's origin vector.
   462  * @noreturn
   463  * @error				Invalid client index, client not in game, or no mod support.
   464  */
   465 native GetClientAbsOrigin(client, Float:vec[3]);
   466 
   467 /**
   468  * Returns the client's armor.
   469  *
   470  * @param client		Player's index.
   471  * @return				Armor value.
   472  * @error				Invalid client index, client not in game, or no mod support.
   473  */
   474 native GetClientArmor(client);
   475 
   476 /**
   477  * Returns the client's death count.
   478  *
   479  * @param client		Player's index.
   480  * @return				Death count.
   481  * @error				Invalid client index, client not in game, or no mod support.
   482  */
   483 native GetClientDeaths(client);
   484 
   485 /**
   486  * Returns the client's frag count.
   487  *
   488  * @param client		Player's index.
   489  * @return				Frag count.
   490  * @error				Invalid client index, client not in game, or no mod support.
   491  */
   492 native GetClientFrags(client);
   493 
   494 /**
   495  * Returns the client's send data rate in bytes/sec.
   496  *
   497  * @param client		Player's index.
   498  * @return				Data rate.
   499  * @error				Invalid client index, client not in game, or fake client.
   500  */
   501 native GetClientDataRate(client);
   502 
   503 /**
   504  * Returns if a client is timing out
   505  *
   506  * @param client		Player's index.
   507  * @return				True if client is timing out, false otherwise.
   508  * @error				Invalid client index, client not in game, or fake client.
   509  */
   510 native bool:IsClientTimingOut(client);
   511 
   512 /**
   513  * Returns the client's connection time in seconds.
   514  *
   515  * @param client		Player's index.
   516  * @return				Connection time.
   517  * @error				Invalid client index, client not in game, or fake client.
   518  */
   519 native Float:GetClientTime(client);
   520 
   521 /**
   522  * Returns the client's current latency (RTT), more accurate than GetAvgLatency but jittering.
   523  *
   524  * @param client		Player's index.
   525  * @param flow			Traffic flowing direction.
   526  * @return				Latency.
   527  * @error				Invalid client index, client not in game, or fake client.
   528  */
   529 native Float:GetClientLatency(client, NetFlow:flow);
   530 
   531 /**
   532  * Returns the client's average packet latency in seconds.
   533  *
   534  * @param client		Player's index.
   535  * @param flow			Traffic flowing direction.
   536  * @return				Average latency.
   537  * @error				Invalid client index, client not in game, or fake client.
   538  */
   539 native Float:GetClientAvgLatency(client, NetFlow:flow);
   540 
   541 /**
   542  * Returns the client's average packet loss, values go from 0 to 1 (for percentages).
   543  *
   544  * @param client		Player's index.
   545  * @param flow			Traffic flowing direction.
   546  * @return				Average packet loss.
   547  * @error				Invalid client index, client not in game, or fake client.
   548  */
   549 native Float:GetClientAvgLoss(client, NetFlow:flow);
   550 
   551 /**
   552  * Returns the client's average packet choke, values go from 0 to 1 (for percentages).
   553  *
   554  * @param client		Player's index.
   555  * @param flow			Traffic flowing direction.
   556  * @return				Average packet choke.
   557  * @error				Invalid client index, client not in game, or fake client.
   558  */
   559 native Float:GetClientAvgChoke(client, NetFlow:flow);
   560 
   561 /**
   562  * Returns the client's data flow in bytes/sec.
   563  *
   564  * @param client		Player's index.
   565  * @param flow			Traffic flowing direction.
   566  * @return				Data flow.
   567  * @error				Invalid client index, client not in game, or fake client.
   568  */
   569 native Float:GetClientAvgData(client, NetFlow:flow);
   570 
   571 /**
   572  * Returns the client's average packet frequency in packets/sec.
   573  *
   574  * @param client		Player's index.
   575  * @param flow			Traffic flowing direction.
   576  * @return				Packet frequency.
   577  * @error				Invalid client index, client not in game, or fake client.
   578  */
   579 native Float:GetClientAvgPackets(client, NetFlow:flow);
   580 
   581 /**
   582  * Translates an userid index to the real player index.
   583  *
   584  * @param userid		Userid value.
   585  * @return				Client value.
   586  * @error				Returns 0 if invalid userid.
   587  */
   588 native GetClientOfUserId(userid);
   589 
   590 /**
   591  * Disconnects a client from the server.  
   592  *
   593  * Kicking clients from certain events or callbacks may cause crashes.  If in 
   594  * doubt, create a short (0.1 second) timer to kick the client in the next 
   595  * available frame.
   596  *
   597  * @param client		Client index.
   598  * @param format		Optional formatting rules for disconnect reason.
   599  *                      Note that a period is automatically appended to the string by the engine.
   600  * @param ...			Variable number of format parameters.
   601  * @noreturn
   602  * @error				Invalid client index, or client not connected.
   603  */
   604 native KickClient(client, const String:format[]="", any:...);
   605 
   606 /**
   607  * Changes a client's team through the mod's generic team changing function.
   608  * On CS:S, this will kill the player.
   609  *
   610  * @param client		Client index.
   611  * @param team			Mod-specific team index.
   612  * @noreturn
   613  * @error				Invalid client index, client not connected, or lack of 
   614  *						mod support.
   615  */
   616 native ChangeClientTeam(client, team);
   617