plugins/include/clients.inc
author Phong Dang <teame06@gmail.com>
Wed Aug 01 06:55:55 2007 +0000 (2007-08-01)
changeset 1239 eed86aca8fae
parent 1033 05c922aae9af
child 1268 9360f5ea2289
permissions -rw-r--r--
Implemented IsPlayerAlive native.
     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 enum NetFlow
    22 {
    23 	NetFlow_Outgoing = 0,	/**< Outgoing traffic */
    24 	NetFlow_Incoming,		/**< Incoming traffic */
    25 	NetFlow_Both			/**< Incoming and outgoing traffic */
    26 };
    27 
    28 #define MAXPLAYERS		64	/**< Maximum number of players that can be in server */
    29 
    30 /**
    31  * Called on client connection.
    32  *
    33  * @param client		Player index.
    34  * @param rejectmsg		Buffer to store the rejection message when the connection is refused.
    35  * @param maxlen		Maximum number of characters for rejection buffer.
    36  * @return				True to validate client's connection, false to refuse it.
    37  */
    38 forward bool:OnClientConnect(client, String:rejectmsg[], maxlen);
    39 
    40 /**
    41  * Called when a client is entering to the game.
    42  *
    43  * @param client		Player index.
    44  * @noreturn
    45  */
    46 forward OnClientPutInServer(client);
    47 
    48 /**
    49  * Called when a client is disconnecting from the server.
    50  *
    51  * @param client		Player index.
    52  * @noreturn
    53  */
    54 forward OnClientDisconnect(client);
    55 
    56 /**
    57  * Called when a client is disconnected from the server.
    58  *
    59  * @param client		Player index.
    60  * @noreturn
    61  */
    62 forward OnClientDisconnect_Post(client);
    63 
    64 /**
    65  * Called when a client is sending a command.
    66  *
    67  * @param client		Player index.
    68  * @param args			Number of arguments.
    69  * @noreturn
    70  */
    71 forward Action:OnClientCommand(client, args);
    72 
    73 /**
    74  * Called whenever the client's settings are changed.
    75  *
    76  * @param client		Player index.
    77  * @noreturn
    78  */
    79 forward OnClientSettingsChanged(client);
    80 
    81 /**
    82  * Called when a client receives a Steam ID.
    83  * @note This is called by bots, but the ID will be "BOT"
    84  *
    85  * @param client		Player index.
    86  * @param auth			Player auth string.
    87  */
    88 forward OnClientAuthorized(client, const String:auth[]);
    89 
    90 /**
    91  * Returns the maximum number of clients allowed on the server.
    92  *
    93  * @return				Maximum number of clients allowed.
    94  */
    95 native GetMaxClients();
    96 
    97 /**
    98  * Returns the client count put in the server.
    99  *
   100  * @param inGameOnly	If false connecting players are also counted.
   101  * @return				Client count in the server.
   102  */
   103 native GetClientCount(bool:inGameOnly=true);
   104 
   105 /**
   106  * Returns the client's name.
   107  *
   108  * @param client		Player index.
   109  * @param name			Buffer to store the client's name.
   110  * @param maxlen		Maximum length of string buffer (includes NULL terminator).
   111  * @return				True on success, false otherwise.
   112  * @error				If the client is not connected an error will be thrown.
   113  */
   114 native bool:GetClientName(client, String:name[], maxlen);
   115 
   116 /**
   117  * Retrieves a client's IP address.
   118  *
   119  * @param client		Player index.
   120  * @param name			Buffer to store the client's ip address.
   121  * @param maxlen		Maximum length of string buffer (includes NULL terminator).
   122  * @param remport		Remove client's port from the ip string (true by default).
   123  * @return				True on success, false otherwise.
   124  * @error				If the client is not connected or the index is invalid.
   125  */
   126 native bool:GetClientIP(client, String:ip[], maxlen, bool:remport=true);
   127 
   128 /**
   129  * Retrieves a client's authentication string (SteamID).
   130  *
   131  * @param client		Player index.
   132  * @param auth			Buffer to store the client's auth string.
   133  * @param maxlen		Maximum length of string buffer (includes NULL terminator).
   134  * @return				True on success, false otherwise.
   135  * @error				If the client is not connected or the index is invalid.
   136  */
   137 native bool:GetClientAuthString(client, String:auth[], maxlen);
   138 
   139 /**
   140  * Retrieves a client's user id, which is an index incremented for every client
   141  * that joins the server.
   142  *
   143  * @param client		Player index.
   144  * @return				User id of the client.
   145  * @error 				If the client is not connected or the index is invalid.
   146  */
   147 native GetClientUserId(client);
   148 
   149 /**
   150  * Returns if a certain player is connected.
   151  *
   152  * @param client		Player index.
   153  * @return				True if player is connected to the server, false otherwise.
   154  */
   155 native bool:IsClientConnected(client);
   156 
   157 /**
   158  * Returns if a certain player has entered the game.
   159  *
   160  * @param client		Player index.
   161  * @return				True if player has entered the game, false otherwise.
   162  */
   163 native bool:IsClientInGame(client);
   164 
   165 /**
   166  * Backwards compatibility stock - use IsClientInGame
   167  * @deprecated			Renamed to IsClientInGame
   168  */
   169 stock bool:IsPlayerInGame(client)
   170 {
   171 	return IsClientInGame(client);
   172 }
   173 
   174 /**
   175  * Returns if a certain player has been authenticated.
   176  *
   177  * @param client		Player index.
   178  * @return				True if player has been authenticated, false otherwise.
   179  */
   180 native bool:IsClientAuthorized(client);
   181 
   182 /**
   183  * Returns if a certain player is a fake client.
   184  *
   185  * @param client		Player index.
   186  * @return				True if player is a fake client, false otherwise.
   187  */
   188 native bool:IsFakeClient(client);
   189 
   190 /**
   191  * Returns if a certain player is an observer/spectator.
   192  *
   193  * @param client		Player index.
   194  * @return				True if player is an obverser, false otherwise.
   195  */
   196 native bool:IsClientObserver(client);
   197 
   198 /**
   199  * Retrieves values from client replicated keys.
   200  *
   201  * @param client		Player's index.
   202  * @param key			Key string.
   203  * @param value			Buffer to store value.
   204  * @param maxlen		Maximum length of valve (UTF-8 safe).
   205  * @return 				True on success, false otherwise.
   206  * @error				Invalid client index, or client not connected.
   207  */
   208 native bool:GetClientInfo(client, const String:key[], String:value[], maxlen);
   209 
   210 /**
   211  * Retrieves a client's team index.
   212  *
   213  * @param client		Player's index.
   214  * @return				Team index the client is on (mod specific).
   215  * @error				Invalid client index, client not in game, or no mod support.
   216  */
   217 native GetClientTeam(client);
   218  
   219 /**
   220  * Sets a client's AdminId.  
   221  *
   222  * @param client		Player's index.
   223  * @param id			AdminId to set.  INVALID_ADMIN_ID removes admin permissions.
   224  * @param temp			True if the id should be freed on disconnect.
   225  * @noreturn
   226  * @error				Invalid client index, client not connected, or bogus AdminId.
   227  */
   228 native SetUserAdmin(client, AdminId:id, bool:temp=false);
   229 
   230 /**
   231  * Retrieves a client's AdminId.
   232  *
   233  * @param client		Player's index.
   234  * @return				AdminId of the client, or INVALID_ADMIN_ID if none.
   235  * @error				Invalid client index, or client not connected.
   236  */
   237 native AdminId:GetUserAdmin(client);
   238 
   239 /**
   240  * Sets access flags on a client.  If the client is not an admin,
   241  * a temporary, anonymous AdminId is given.
   242  *
   243  * @param client		Player's index.
   244  * @param ...			Flags to set on the client.
   245  * @noreturn
   246  * @error				Invalid client index, or client not connected.
   247  */
   248 native AddUserFlags(client, AdminFlag:...);
   249 
   250 /**
   251  * Removes flags from a client.  If the client is not an admin,
   252  * this has no effect.
   253  *
   254  * @param client		Player's index.
   255  * @param ...			Flags to remove from the client.
   256  * @noreturn
   257  * @error				Invalid client index, or client not connected.
   258  */
   259 native RemoveUserFlags(client, AdminFlag:...);
   260 
   261 /** 
   262  * Sets access flags on a client using bits instead of flags.  If the
   263  * client is not an admin, and flags not 0, a temporary, anonymous AdminId is given.
   264  *
   265  * @param client		Player's index.
   266  * @param flags			Bitstring of flags to set on client.
   267  * @noreturn
   268  */
   269 native SetUserFlagBits(client, flags);
   270 
   271 /**
   272  * Returns client access flags.  If the client is not an admin,
   273  * the result is always 0.
   274  * 
   275  * @param client		Player's index.
   276  * @return				Flags
   277  * @error				Invalid client index, or client not connected.
   278  */
   279 native GetUserFlagBits(client);
   280 
   281 /**
   282  * Returns whether a user can target another user.
   283  * This is a helper function for CanAdminTarget.
   284  *
   285  * @param client		Player's index.
   286  * @param target		Target player's index.
   287  * @return				True if target is targettable by the player, false otherwise.
   288  * @error				Invalid or unconnected player indexers.
   289  */
   290 native bool:CanUserTarget(client, target);
   291 
   292 /** 
   293  * Creates a fake client.
   294  *
   295  * @param name			Name to use.
   296  * @return				Client index on success, 0 otherwise.
   297  */
   298 native CreateFakeClient(const String:name[]);
   299 
   300 /**
   301  * Sets a convar value on a fake client.
   302  *
   303  * @param client		Client index.
   304  * @param cvar			ConVar name.
   305  * @param value			ConVar value.
   306  * @noreturn
   307  * @error				Invalid client index, client not connected,
   308  *						or client not a fake client.
   309  */
   310 native SetFakeClientConVar(client, const String:cvar[], const String:value[]);
   311 
   312 /**
   313  * Returns the client's health.
   314  *
   315  * @param client		Player's index.
   316  * @return				Health value.
   317  * @error				Invalid client index, client not in game, or no mod support.
   318  */
   319 native GetClientHealth(client);
   320 
   321 /**
   322  * Returns the client's model name.
   323  *
   324  * @param client		Player's index.
   325  * @param model			Buffer to store the client's model name.
   326  * @param maxlen		Maximum length of string buffer (includes NULL terminator).
   327  * @noreturn
   328  * @error				Invalid client index, client not in game, or no mod support.
   329  */
   330 native GetClientModel(client, String:model[], maxlen);
   331 
   332 /**
   333  * Returns the client's weapon name.
   334  *
   335  * @param client		Player's index.
   336  * @param weapon		Buffer to store the client's weapon name.
   337  * @param maxlen		Maximum length of string buffer (includes NULL terminator).
   338  * @noreturn
   339  * @error				Invalid client index, client not in game, or no mod support.
   340  */
   341 native GetClientWeapon(client, String:weapon[], maxlen);
   342 
   343 /**
   344  * Returns the client's max size vector.
   345  *
   346  * @param client		Player's index.
   347  * @param vec			Destination vector to store the client's max size.
   348  * @noreturn
   349  * @error				Invalid client index, client not in game, or no mod support.
   350  */
   351 native GetClientMaxs(client, Float:vec[3]);
   352 
   353 /**
   354  * Returns the client's min size vector.
   355  *
   356  * @param client		Player's index.
   357  * @param vec			Destination vector to store the client's min size.
   358  * @noreturn
   359  * @error				Invalid client index, client not in game, or no mod support.
   360  */
   361 native GetClientMins(client, Float:vec[3]);
   362 
   363 /**
   364  * Returns the client's position angle.
   365  *
   366  * @param client		Player's index.
   367  * @param ang			Destination vector to store the client's position angle.
   368  * @noreturn
   369  * @error				Invalid client index, client not in game, or no mod support.
   370  */
   371 native GetClientAbsAngles(client, Float:ang[3]);
   372 
   373 /**
   374  * Returns the client's origin vector.
   375  *
   376  * @param client		Player's index.
   377  * @param vec			Destination vector to store the client's origin vector.
   378  * @noreturn
   379  * @error				Invalid client index, client not in game, or no mod support.
   380  */
   381 native GetClientAbsOrigin(client, Float:vec[3]);
   382 
   383 /**
   384  * Returns the client's armor.
   385  *
   386  * @param client		Player's index.
   387  * @return				Armor value.
   388  * @error				Invalid client index, client not in game, or no mod support.
   389  */
   390 native GetClientArmor(client);
   391 
   392 /**
   393  * Returns the client's death count.
   394  *
   395  * @param client		Player's index.
   396  * @return				Death count.
   397  * @error				Invalid client index, client not in game, or no mod support.
   398  */
   399 native GetClientDeaths(client);
   400 
   401 /**
   402  * Returns the client's frag count.
   403  *
   404  * @param client		Player's index.
   405  * @return				Frag count.
   406  * @error				Invalid client index, client not in game, or no mod support.
   407  */
   408 native GetClientFrags(client);
   409 
   410 /**
   411  * Returns the client's send data rate in bytes/sec.
   412  *
   413  * @param client		Player's index.
   414  * @return				Data rate.
   415  * @error				Invalid client index, client not in game, or fake client.
   416  */
   417 native GetClientDataRate(client);
   418 
   419 /**
   420  * Returns if a client is timing out
   421  *
   422  * @param client		Player's index.
   423  * @return				True if client is timing out, false otherwise.
   424  * @error				Invalid client index, client not in game, or fake client.
   425  */
   426 native bool:IsClientTimingOut(client);
   427 
   428 /**
   429  * Returns the client's connection time in seconds.
   430  *
   431  * @param client		Player's index.
   432  * @return				Connection time.
   433  * @error				Invalid client index, client not in game, or fake client.
   434  */
   435 native Float:GetClientTime(client);
   436 
   437 /**
   438  * Returns the client's current latency (RTT), more accurate than GetAvgLatency but jittering.
   439  *
   440  * @param client		Player's index.
   441  * @param flow			Traffic flowing direction.
   442  * @return				Latency.
   443  * @error				Invalid client index, client not in game, or fake client.
   444  */
   445 native Float:GetClientLatency(client, NetFlow:flow);
   446 
   447 /**
   448  * Returns the client's average packet latency in seconds.
   449  *
   450  * @param client		Player's index.
   451  * @param flow			Traffic flowing direction.
   452  * @return				Average latency.
   453  * @error				Invalid client index, client not in game, or fake client.
   454  */
   455 native Float:GetClientAvgLatency(client, NetFlow:flow);
   456 
   457 /**
   458  * Returns the client's average packet loss, values go from 0 to 1 (for percentages).
   459  *
   460  * @param client		Player's index.
   461  * @param flow			Traffic flowing direction.
   462  * @return				Average packet loss.
   463  * @error				Invalid client index, client not in game, or fake client.
   464  */
   465 native Float:GetClientAvgLoss(client, NetFlow:flow);
   466 
   467 /**
   468  * Returns the client's average packet choke, values go from 0 to 1 (for percentages).
   469  *
   470  * @param client		Player's index.
   471  * @param flow			Traffic flowing direction.
   472  * @return				Average packet choke.
   473  * @error				Invalid client index, client not in game, or fake client.
   474  */
   475 native Float:GetClientAvgChoke(client, NetFlow:flow);
   476 
   477 /**
   478  * Returns the client's data flow in bytes/sec.
   479  *
   480  * @param client		Player's index.
   481  * @param flow			Traffic flowing direction.
   482  * @return				Data flow.
   483  * @error				Invalid client index, client not in game, or fake client.
   484  */
   485 native Float:GetClientAvgData(client, NetFlow:flow);
   486 
   487 /**
   488  * Returns the client's average packet frequency in packets/sec.
   489  *
   490  * @param client		Player's index.
   491  * @param flow			Traffic flowing direction.
   492  * @return				Packet frequency.
   493  * @error				Invalid client index, client not in game, or fake client.
   494  */
   495 native Float:GetClientAvgPackets(client, NetFlow:flow);
   496 
   497 /**
   498  * Translates an userid index to the real player index.
   499  *
   500  * @param userid		Userid value.
   501  * @return				Client value.
   502  * @error				Returns 0 if invalid userid.
   503  */
   504 native GetClientOfUserId(userid);
   505 
   506 /**
   507  * Disconnects a client from the server.
   508  *
   509  * @param client		Client index.
   510  * @param format		Optional formatting rules for disconnect reason.
   511  *                      Note that a period is automatically appended to the string by the engine.
   512  * @param ...			Variable number of format parameters.
   513  * @noreturn
   514  * @error				Invalid client index, or client not connected.
   515  */
   516 native KickClient(client, const String:format[]="", any:...);
   517 
   518 /**
   519  * Changes a client's team through the mod's generic team changing function.
   520  * On CS:S, this will kill the player.
   521  *
   522  * @param client		Client index.
   523  * @param team			Mod-specific team index.
   524  * @noreturn
   525  * @error				Invalid client index, client not connected, or lack of 
   526  *						mod support.
   527  */
   528 native ChangeClientTeam(client, team);