plugins/include/clients.inc
author David Anderson <dvander@alliedmods.net>
Sun Mar 02 18:01:49 2008 +0000 (2008-03-02)
changeset 1912 506170374d35
parent 1831 af5c93c936d7
child 1947 e73a1e51833b
permissions -rw-r--r--
added amb1377 - binary sql functions
     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 the game.
    60  *
    61  * Whether a client has a steamid is undefined until OnClientAuthorized
    62  * is called, which may occur either before or after OnClientPutInServer.
    63  * Similarly, use OnClientPostAdminCheck() if you need to verify whether 
    64  * connecting players are admins.
    65  *
    66  * GetClientCount() will include clients as they are passed through this 
    67  * function, as clients are already in game at this point.
    68  *
    69  * @param client		Client index.
    70  * @noreturn
    71  */
    72 forward OnClientPutInServer(client);
    73 
    74 /**
    75  * Called when a client is disconnecting from the server.
    76  *
    77  * @param client		Client index.
    78  * @noreturn
    79  */
    80 forward OnClientDisconnect(client);
    81 
    82 /**
    83  * Called when a client is disconnected from the server.
    84  *
    85  * @param client		Client index.
    86  * @noreturn
    87  */
    88 forward OnClientDisconnect_Post(client);
    89 
    90 /**
    91  * Called when a client is sending a command.
    92  *
    93  * @param client		Client index.
    94  * @param args			Number of arguments.
    95  * @noreturn
    96  */
    97 forward Action:OnClientCommand(client, args);
    98 
    99 /**
   100  * Called whenever the client's settings are changed.
   101  *
   102  * @param client		Client index.
   103  * @noreturn
   104  */
   105 forward OnClientSettingsChanged(client);
   106 
   107 /**
   108  * Called when a client receives a Steam ID.  The state of a client's 
   109  * authorization via Steam or as an admin is not guaranteed here.  
   110  * Use OnClientAuthorized() or OnClientPostAdminCheck() for those, 
   111  * respectively.
   112  *
   113  * This is called by bots, but the ID will be "BOT".
   114  *
   115  * @param client		Client index.
   116  * @param auth			Client auth string.
   117  * @noreturn
   118  */
   119 forward OnClientAuthorized(client, const String:auth[]);
   120 
   121 /**
   122  * Called once a client is authorized and fully in-game, but 
   123  * before admin checks are done.  This can be used to override 
   124  * the default admin checks for a client.  You should only use 
   125  * this for overriding; use OnClientPostAdminCheck() instead 
   126  * if you want notification.
   127  *
   128  * Note: If handled/blocked, PostAdminCheck must be signalled 
   129  * manually via NotifyPostAdminCheck().
   130  *
   131  * This callback is gauranteed to occur on all clients, and always 
   132  * after each OnClientPutInServer() call.
   133  *
   134  * @param client		Client index.
   135  * @return				Plugin_Handled to block admin checks.
   136  */
   137 forward Action:OnClientPreAdminCheck(client);
   138 
   139 /**
   140  * Called directly before OnClientPostAdminCheck() as a method to 
   141  * alter administrative permissions before plugins perform final 
   142  * post-connect operations.  
   143  *
   144  * In general, do not use this function unless you are specifically 
   145  * attempting to change access permissions.  Use OnClientPostAdminCheck() 
   146  * instead if you simply want to perform post-connect authorization 
   147  * routines.
   148  *
   149  * See OnClientPostAdminCheck() for more information.
   150  *
   151  * @param client		Client index.
   152  * @noreturn
   153  */
   154 forward OnClientPostAdminFilter(client);
   155 
   156 /**
   157  * Called once a client is authorized and fully in-game, and 
   158  * after all post-connection authorizations have been performed.  
   159  *
   160  * This callback is gauranteed to occur on all clients, and always 
   161  * after each OnClientPutInServer() call.
   162  *
   163  * @param client		Client index.
   164  * @noreturn
   165  */
   166 forward OnClientPostAdminCheck(client);
   167 
   168 /**
   169  * Returns the maximum number of clients allowed on the server.  This may 
   170  * return 0 if called before OnMapStart(), and thus should not be called 
   171  * in OnPluginStart().  
   172  *
   173  * @return				Maximum number of clients allowed.
   174  */
   175 native GetMaxClients();
   176 
   177 /**
   178  * Returns the client count put in the server.
   179  *
   180  * @param inGameOnly	If false connecting players are also counted.
   181  * @return				Client count in the server.
   182  */
   183 native GetClientCount(bool:inGameOnly=true);
   184 
   185 /**
   186  * Returns the client's name.
   187  *
   188  * @param client		Player index.
   189  * @param name			Buffer to store the client's name.
   190  * @param maxlen		Maximum length of string buffer (includes NULL terminator).
   191  * @return				True on success, false otherwise.
   192  * @error				If the client is not connected an error will be thrown.
   193  */
   194 native bool:GetClientName(client, String:name[], maxlen);
   195 
   196 /**
   197  * Retrieves a client's IP address.
   198  *
   199  * @param client		Player index.
   200  * @param name			Buffer to store the client's ip address.
   201  * @param maxlen		Maximum length of string buffer (includes NULL terminator).
   202  * @param remport		Remove client's port from the ip string (true by default).
   203  * @return				True on success, false otherwise.
   204  * @error				If the client is not connected or the index is invalid.
   205  */
   206 native bool:GetClientIP(client, String:ip[], maxlen, bool:remport=true);
   207 
   208 /**
   209  * Retrieves a client's authentication string (SteamID).
   210  *
   211  * @param client		Player index.
   212  * @param auth			Buffer to store the client's auth string.
   213  * @param maxlen		Maximum length of string buffer (includes NULL terminator).
   214  * @return				True on success, false otherwise.
   215  * @error				If the client is not connected or the index is invalid.
   216  */
   217 native bool:GetClientAuthString(client, String:auth[], maxlen);
   218 
   219 /**
   220  * Retrieves a client's user id, which is an index incremented for every client
   221  * that joins the server.
   222  *
   223  * @param client		Player index.
   224  * @return				User id of the client.
   225  * @error 				If the client is not connected or the index is invalid.
   226  */
   227 native GetClientUserId(client);
   228 
   229 /**
   230  * Returns if a certain player is connected.
   231  *
   232  * @param client		Player index.
   233  * @return				True if player is connected to the server, false otherwise.
   234  */
   235 native bool:IsClientConnected(client);
   236 
   237 /**
   238  * Returns if a certain player has entered the game.
   239  *
   240  * @param client		Player index (index does not have to be connected).
   241  * @return				True if player has entered the game, false otherwise.
   242  * @error				Invalid client index.
   243  */
   244 native bool:IsClientInGame(client);
   245 
   246 /**
   247  * Returns if a client is in the "kick queue" (i.e. the client will be kicked 
   248  * shortly and thus they should not appear as valid).
   249  *
   250  * @param client		Player index (must be connected).
   251  * @return				True if in the kick queue, false otherwise.
   252  * @error				Invalid client index.
   253  */
   254 native bool:IsClientInKickQueue(client);
   255 
   256 /**
   257  * Backwards compatibility stock - use IsClientInGame
   258  * @deprecated			Renamed to IsClientInGame
   259  */
   260 #pragma deprecated Use IsClientInGame() instead
   261 stock bool:IsPlayerInGame(client)
   262 {
   263 	return IsClientInGame(client);
   264 }
   265 
   266 /**
   267  * Returns if a certain player has been authenticated.
   268  *
   269  * @param client		Player index.
   270  * @return				True if player has been authenticated, false otherwise.
   271  */
   272 native bool:IsClientAuthorized(client);
   273 
   274 /**
   275  * Returns if a certain player is a fake client.
   276  *
   277  * @param client		Player index.
   278  * @return				True if player is a fake client, false otherwise.
   279  */
   280 native bool:IsFakeClient(client);
   281 
   282 /**
   283  * Returns if a certain player is an observer/spectator.
   284  *
   285  * @param client		Player index.
   286  * @return				True if player is an obverser, false otherwise.
   287  */
   288 native bool:IsClientObserver(client);
   289 
   290 /**
   291  * Returns if the client is alive or dead.
   292  *
   293  * Note: This function was originally in SDKTools and was moved to core.
   294  *
   295  * @param client		Player's index.
   296  * @return				True if the client is alive, false otherwise.
   297  * @error				Invalid client index, client not in game, or no mod support.
   298  */
   299 native bool:IsPlayerAlive(client);
   300 
   301 /**
   302  * Retrieves values from client replicated keys.
   303  *
   304  * @param client		Player's index.
   305  * @param key			Key string.
   306  * @param value			Buffer to store value.
   307  * @param maxlen		Maximum length of valve (UTF-8 safe).
   308  * @return 				True on success, false otherwise.
   309  * @error				Invalid client index, or client not connected.
   310  */
   311 native bool:GetClientInfo(client, const String:key[], String:value[], maxlen);
   312 
   313 /**
   314  * Retrieves a client's team index.
   315  *
   316  * @param client		Player's index.
   317  * @return				Team index the client is on (mod specific).
   318  * @error				Invalid client index, client not in game, or no mod support.
   319  */
   320 native GetClientTeam(client);
   321  
   322 /**
   323  * Sets a client's AdminId.  
   324  *
   325  * @param client		Player's index.
   326  * @param id			AdminId to set.  INVALID_ADMIN_ID removes admin permissions.
   327  * @param temp			True if the id should be freed on disconnect.
   328  * @noreturn
   329  * @error				Invalid client index, client not connected, or bogus AdminId.
   330  */
   331 native SetUserAdmin(client, AdminId:id, bool:temp=false);
   332 
   333 /**
   334  * Retrieves a client's AdminId.
   335  *
   336  * @param client		Player's index.
   337  * @return				AdminId of the client, or INVALID_ADMIN_ID if none.
   338  * @error				Invalid client index, or client not connected.
   339  */
   340 native AdminId:GetUserAdmin(client);
   341 
   342 /**
   343  * Sets access flags on a client.  If the client is not an admin,
   344  * a temporary, anonymous AdminId is given.
   345  *
   346  * @param client		Player's index.
   347  * @param ...			Flags to set on the client.
   348  * @noreturn
   349  * @error				Invalid client index, or client not connected.
   350  */
   351 native AddUserFlags(client, AdminFlag:...);
   352 
   353 /**
   354  * Removes flags from a client.  If the client is not an admin,
   355  * this has no effect.
   356  *
   357  * @param client		Player's index.
   358  * @param ...			Flags to remove from the client.
   359  * @noreturn
   360  * @error				Invalid client index, or client not connected.
   361  */
   362 native RemoveUserFlags(client, AdminFlag:...);
   363 
   364 /** 
   365  * Sets access flags on a client using bits instead of flags.  If the
   366  * client is not an admin, and flags not 0, a temporary, anonymous AdminId is given.
   367  *
   368  * @param client		Player's index.
   369  * @param flags			Bitstring of flags to set on client.
   370  * @noreturn
   371  */
   372 native SetUserFlagBits(client, flags);
   373 
   374 /**
   375  * Returns client access flags.  If the client is not an admin,
   376  * the result is always 0.
   377  * 
   378  * @param client		Player's index.
   379  * @return				Flags
   380  * @error				Invalid client index, or client not connected.
   381  */
   382 native GetUserFlagBits(client);
   383 
   384 /**
   385  * Returns whether a user can target another user.
   386  * This is a helper function for CanAdminTarget.
   387  *
   388  * @param client		Player's index.
   389  * @param target		Target player's index.
   390  * @return				True if target is targettable by the player, false otherwise.
   391  * @error				Invalid or unconnected player indexers.
   392  */
   393 native bool:CanUserTarget(client, target);
   394 
   395 /**
   396  * Runs through the Core-defined admin authorization checks on a player.
   397  * Has no effect if the player is already an admin.
   398  *
   399  * Note: This function is based on the internal cache only.
   400  *
   401  * @param client		Client index.
   402  * @return				True if access was changed, false if it did not.
   403  * @error				Invalid client index or client not in-game AND authorized.
   404  */
   405 native bool:RunAdminCacheChecks(client);
   406 
   407 /**
   408  * Signals that a player has completed post-connection admin checks.
   409  * Has no effect if the player has already had this event signalled.
   410  *
   411  * Note: This must be sent even if no admin id was assigned.
   412  *
   413  * @param client		Client index.
   414  * @noreturn
   415  * @error				Invalid client index or client not in-game AND authorized.
   416  */
   417 native NotifyPostAdminCheck(client);
   418 
   419 /** 
   420  * Creates a fake client.
   421  *
   422  * @param name			Name to use.
   423  * @return				Client index on success, 0 otherwise.
   424  */
   425 native CreateFakeClient(const String:name[]);
   426 
   427 /**
   428  * Sets a convar value on a fake client.
   429  *
   430  * @param client		Client index.
   431  * @param cvar			ConVar name.
   432  * @param value			ConVar value.
   433  * @noreturn
   434  * @error				Invalid client index, client not connected,
   435  *						or client not a fake client.
   436  */
   437 native SetFakeClientConVar(client, const String:cvar[], const String:value[]);
   438 
   439 /**
   440  * Returns the client's health.
   441  *
   442  * @param client		Player's index.
   443  * @return				Health value.
   444  * @error				Invalid client index, client not in game, or no mod support.
   445  */
   446 native GetClientHealth(client);
   447 
   448 /**
   449  * Returns the client's model name.
   450  *
   451  * @param client		Player's index.
   452  * @param model			Buffer to store the client's model name.
   453  * @param maxlen		Maximum length of string buffer (includes NULL terminator).
   454  * @noreturn
   455  * @error				Invalid client index, client not in game, or no mod support.
   456  */
   457 native GetClientModel(client, String:model[], maxlen);
   458 
   459 /**
   460  * Returns the client's weapon name.
   461  *
   462  * @param client		Player's index.
   463  * @param weapon		Buffer to store the client's weapon name.
   464  * @param maxlen		Maximum length of string buffer (includes NULL terminator).
   465  * @noreturn
   466  * @error				Invalid client index, client not in game, or no mod support.
   467  */
   468 native GetClientWeapon(client, String:weapon[], maxlen);
   469 
   470 /**
   471  * Returns the client's max size vector.
   472  *
   473  * @param client		Player's index.
   474  * @param vec			Destination vector to store the client's max size.
   475  * @noreturn
   476  * @error				Invalid client index, client not in game, or no mod support.
   477  */
   478 native GetClientMaxs(client, Float:vec[3]);
   479 
   480 /**
   481  * Returns the client's min size vector.
   482  *
   483  * @param client		Player's index.
   484  * @param vec			Destination vector to store the client's min size.
   485  * @noreturn
   486  * @error				Invalid client index, client not in game, or no mod support.
   487  */
   488 native GetClientMins(client, Float:vec[3]);
   489 
   490 /**
   491  * Returns the client's position angle.
   492  *
   493  * @param client		Player's index.
   494  * @param ang			Destination vector to store the client's position angle.
   495  * @noreturn
   496  * @error				Invalid client index, client not in game, or no mod support.
   497  */
   498 native GetClientAbsAngles(client, Float:ang[3]);
   499 
   500 /**
   501  * Returns the client's origin vector.
   502  *
   503  * @param client		Player's index.
   504  * @param vec			Destination vector to store the client's origin vector.
   505  * @noreturn
   506  * @error				Invalid client index, client not in game, or no mod support.
   507  */
   508 native GetClientAbsOrigin(client, Float:vec[3]);
   509 
   510 /**
   511  * Returns the client's armor.
   512  *
   513  * @param client		Player's index.
   514  * @return				Armor value.
   515  * @error				Invalid client index, client not in game, or no mod support.
   516  */
   517 native GetClientArmor(client);
   518 
   519 /**
   520  * Returns the client's death count.
   521  *
   522  * @param client		Player's index.
   523  * @return				Death count.
   524  * @error				Invalid client index, client not in game, or no mod support.
   525  */
   526 native GetClientDeaths(client);
   527 
   528 /**
   529  * Returns the client's frag count.
   530  *
   531  * @param client		Player's index.
   532  * @return				Frag count.
   533  * @error				Invalid client index, client not in game, or no mod support.
   534  */
   535 native GetClientFrags(client);
   536 
   537 /**
   538  * Returns the client's send data rate in bytes/sec.
   539  *
   540  * @param client		Player's index.
   541  * @return				Data rate.
   542  * @error				Invalid client index, client not in game, or fake client.
   543  */
   544 native GetClientDataRate(client);
   545 
   546 /**
   547  * Returns if a client is timing out
   548  *
   549  * @param client		Player's index.
   550  * @return				True if client is timing out, false otherwise.
   551  * @error				Invalid client index, client not in game, or fake client.
   552  */
   553 native bool:IsClientTimingOut(client);
   554 
   555 /**
   556  * Returns the client's connection time in seconds.
   557  *
   558  * @param client		Player's index.
   559  * @return				Connection time.
   560  * @error				Invalid client index, client not in game, or fake client.
   561  */
   562 native Float:GetClientTime(client);
   563 
   564 /**
   565  * Returns the client's current latency (RTT), more accurate than GetAvgLatency but jittering.
   566  *
   567  * @param client		Player's index.
   568  * @param flow			Traffic flowing direction.
   569  * @return				Latency.
   570  * @error				Invalid client index, client not in game, or fake client.
   571  */
   572 native Float:GetClientLatency(client, NetFlow:flow);
   573 
   574 /**
   575  * Returns the client's average packet latency in seconds.
   576  *
   577  * @param client		Player's index.
   578  * @param flow			Traffic flowing direction.
   579  * @return				Average latency.
   580  * @error				Invalid client index, client not in game, or fake client.
   581  */
   582 native Float:GetClientAvgLatency(client, NetFlow:flow);
   583 
   584 /**
   585  * Returns the client's average packet loss, values go from 0 to 1 (for percentages).
   586  *
   587  * @param client		Player's index.
   588  * @param flow			Traffic flowing direction.
   589  * @return				Average packet loss.
   590  * @error				Invalid client index, client not in game, or fake client.
   591  */
   592 native Float:GetClientAvgLoss(client, NetFlow:flow);
   593 
   594 /**
   595  * Returns the client's average packet choke, values go from 0 to 1 (for percentages).
   596  *
   597  * @param client		Player's index.
   598  * @param flow			Traffic flowing direction.
   599  * @return				Average packet choke.
   600  * @error				Invalid client index, client not in game, or fake client.
   601  */
   602 native Float:GetClientAvgChoke(client, NetFlow:flow);
   603 
   604 /**
   605  * Returns the client's data flow in bytes/sec.
   606  *
   607  * @param client		Player's index.
   608  * @param flow			Traffic flowing direction.
   609  * @return				Data flow.
   610  * @error				Invalid client index, client not in game, or fake client.
   611  */
   612 native Float:GetClientAvgData(client, NetFlow:flow);
   613 
   614 /**
   615  * Returns the client's average packet frequency in packets/sec.
   616  *
   617  * @param client		Player's index.
   618  * @param flow			Traffic flowing direction.
   619  * @return				Packet frequency.
   620  * @error				Invalid client index, client not in game, or fake client.
   621  */
   622 native Float:GetClientAvgPackets(client, NetFlow:flow);
   623 
   624 /**
   625  * Translates an userid index to the real player index.
   626  *
   627  * @param userid		Userid value.
   628  * @return				Client value.
   629  * @error				Returns 0 if invalid userid.
   630  */
   631 native GetClientOfUserId(userid);
   632 
   633 /**
   634  * Disconnects a client from the server.  
   635  *
   636  * Kicking clients from certain events or callbacks may cause crashes.  If in 
   637  * doubt, create a short (0.1 second) timer to kick the client in the next 
   638  * available frame.
   639  *
   640  * @param client		Client index.
   641  * @param format		Optional formatting rules for disconnect reason.
   642  *                      Note that a period is automatically appended to the string by the engine.
   643  * @param ...			Variable number of format parameters.
   644  * @noreturn
   645  * @error				Invalid client index, or client not connected.
   646  */
   647 native KickClient(client, const String:format[]="", any:...);
   648 
   649 /**
   650  * Changes a client's team through the mod's generic team changing function.
   651  * On CS:S, this will kill the player.
   652  *
   653  * @param client		Client index.
   654  * @param team			Mod-specific team index.
   655  * @noreturn
   656  * @error				Invalid client index, client not connected, or lack of 
   657  *						mod support.
   658  */
   659 native ChangeClientTeam(client, team);
   660