plugins/include/clients.inc
author Scott Ehlert <ds@alliedmods.net>
Thu Jun 07 07:36:41 2007 +0000 (2007-06-07)
changeset 915 62c6fb7c533b
parent 901 db978c2819e6
child 992 77133031b0d2
permissions -rw-r--r--
Whoa, bug. Hopefully fixed PrintToChatAll and PrintCenterTextAll once and for all...
     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  * Retrieves values from client replicated keys.
   192  *
   193  * @param client		Player's index.
   194  * @param key			Key string.
   195  * @param value			Buffer to store value.
   196  * @param maxlen		Maximum length of valve (UTF-8 safe).
   197  * @return 				True on success, false otherwise.
   198  * @error				Invalid client index, or client not connected.
   199  */
   200 native bool:GetClientInfo(client, const String:key[], String:value[], maxlen);
   201 
   202 /**
   203  * Retrieves a client's team index.
   204  *
   205  * @param client		Player's index.
   206  * @return				Team index the client is on (mod specific).
   207  * @error				Invalid client index, client not in game, or no mod support.
   208  */
   209 native GetClientTeam(client);
   210  
   211 /**
   212  * Sets a client's AdminId.  
   213  *
   214  * @param client		Player's index.
   215  * @param id			AdminId to set.  INVALID_ADMIN_ID removes admin permissions.
   216  * @param temp			True if the id should be freed on disconnect.
   217  * @noreturn
   218  * @error				Invalid client index, client not connected, or bogus AdminId.
   219  */
   220 native SetUserAdmin(client, AdminId:id, bool:temp=false);
   221 
   222 /**
   223  * Retrieves a client's AdminId.
   224  *
   225  * @param client		Player's index.
   226  * @return				AdminId of the client, or INVALID_ADMIN_ID if none.
   227  * @error				Invalid client index, or client not connected.
   228  */
   229 native AdminId:GetUserAdmin(client);
   230 
   231 /**
   232  * Sets access flags on a client.  If the client is not an admin,
   233  * a temporary, anonymous AdminId is given.
   234  *
   235  * @param client		Player's index.
   236  * @param ...			Flags to set on the client.
   237  * @noreturn
   238  * @error				Invalid client index, or client not connected.
   239  */
   240 native AddUserFlags(client, AdminFlag:...);
   241 
   242 /**
   243  * Removes flags from a client.  If the client is not an admin,
   244  * this has no effect.
   245  *
   246  * @param client		Player's index.
   247  * @param ...			Flags to remove from the client.
   248  * @noreturn
   249  * @error				Invalid client index, or client not connected.
   250  */
   251 native RemoveUserFlags(client, AdminFlag:...);
   252 
   253 /** 
   254  * Sets access flags on a client using bits instead of flags.  If the
   255  * client is not an admin, and flags not 0, a temporary, anonymous AdminId is given.
   256  *
   257  * @param client		Player's index.
   258  * @param flags			Bitstring of flags to set on client.
   259  * @noreturn
   260  */
   261 native SetUserFlagBits(client, flags);
   262 
   263 /**
   264  * Returns client access flags.  If the client is not an admin,
   265  * the result is always 0.
   266  * 
   267  * @param client		Player's index.
   268  * @return				Flags
   269  * @error				Invalid client index, or client not connected.
   270  */
   271 native GetUserFlagBits(client);
   272 
   273 /**
   274  * Returns whether a user can target another user.
   275  * This is a helper function for CanAdminTarget.
   276  *
   277  * @param client		Player's index.
   278  * @param target		Target player's index.
   279  * @return				True if target is targettable by the player, false otherwise.
   280  * @error				Invalid or unconnected player indexers.
   281  */
   282 native bool:CanUserTarget(client, target);
   283 
   284 /** 
   285  * Creates a fake client.
   286  *
   287  * @param name			Name to use.
   288  * @return				Client index on success, 0 otherwise.
   289  */
   290 native CreateFakeClient(const String:name[]);
   291 
   292 /**
   293  * Sets a convar value on a fake client.
   294  *
   295  * @param client		Client index.
   296  * @param cvar			ConVar name.
   297  * @param value			ConVar value.
   298  * @noreturn
   299  * @error				Invalid client index, client not connected,
   300  *						or client not a fake client.
   301  */
   302 native SetFakeClientConVar(client, const String:cvar[], const String:value[]);
   303 
   304 /**
   305  * Returns the client's health.
   306  *
   307  * @param client		Player's index.
   308  * @return				Health value.
   309  * @error				Invalid client index, client not in game, or no mod support.
   310  */
   311 native GetClientHealth(client);
   312 
   313 /**
   314  * Returns the client's model name.
   315  *
   316  * @param client		Player's index.
   317  * @param model			Buffer to store the client's model name.
   318  * @param maxlen		Maximum length of string buffer (includes NULL terminator).
   319  * @noreturn
   320  * @error				Invalid client index, client not in game, or no mod support.
   321  */
   322 native GetClientModel(client, String:model[], maxlen);
   323 
   324 /**
   325  * Returns the client's weapon name.
   326  *
   327  * @param client		Player's index.
   328  * @param weapon		Buffer to store the client's weapon name.
   329  * @param maxlen		Maximum length of string buffer (includes NULL terminator).
   330  * @noreturn
   331  * @error				Invalid client index, client not in game, or no mod support.
   332  */
   333 native GetClientWeapon(client, String:weapon[], maxlen);
   334 
   335 /**
   336  * Returns the client's max size vector.
   337  *
   338  * @param client		Player's index.
   339  * @param vec			Destination vector to store the client's max size.
   340  * @noreturn
   341  * @error				Invalid client index, client not in game, or no mod support.
   342  */
   343 native GetClientMaxs(client, Float:vec[3]);
   344 
   345 /**
   346  * Returns the client's min size vector.
   347  *
   348  * @param client		Player's index.
   349  * @param vec			Destination vector to store the client's min size.
   350  * @noreturn
   351  * @error				Invalid client index, client not in game, or no mod support.
   352  */
   353 native GetClientMins(client, Float:vec[3]);
   354 
   355 /**
   356  * Returns the client's position angle.
   357  *
   358  * @param client		Player's index.
   359  * @param ang			Destination vector to store the client's position angle.
   360  * @noreturn
   361  * @error				Invalid client index, client not in game, or no mod support.
   362  */
   363 native GetClientAbsAngles(client, Float:ang[3]);
   364 
   365 /**
   366  * Returns the client's origin vector.
   367  *
   368  * @param client		Player's index.
   369  * @param vec			Destination vector to store the client's origin vector.
   370  * @noreturn
   371  * @error				Invalid client index, client not in game, or no mod support.
   372  */
   373 native GetClientAbsOrigin(client, Float:vec[3]);
   374 
   375 /**
   376  * Returns the client's armor.
   377  *
   378  * @param client		Player's index.
   379  * @return				Armor value.
   380  * @error				Invalid client index, client not in game, or no mod support.
   381  */
   382 native GetClientArmor(client);
   383 
   384 /**
   385  * Returns the client's death count.
   386  *
   387  * @param client		Player's index.
   388  * @return				Death count.
   389  * @error				Invalid client index, client not in game, or no mod support.
   390  */
   391 native GetClientDeaths(client);
   392 
   393 /**
   394  * Returns the client's frag count.
   395  *
   396  * @param client		Player's index.
   397  * @return				Frag count.
   398  * @error				Invalid client index, client not in game, or no mod support.
   399  */
   400 native GetClientFrags(client);
   401 
   402 /**
   403  * Returns the client's send data rate in bytes/sec.
   404  *
   405  * @param client		Player's index.
   406  * @return				Data rate.
   407  * @error				Invalid client index, client not in game, or fake client.
   408  */
   409 native GetClientDataRate(client);
   410 
   411 /**
   412  * Returns if a client is timing out
   413  *
   414  * @param client		Player's index.
   415  * @return				True if client is timing out, false otherwise.
   416  * @error				Invalid client index, client not in game, or fake client.
   417  */
   418 native bool:IsClientTimingOut(client);
   419 
   420 /**
   421  * Returns the client's connection time in seconds.
   422  *
   423  * @param client		Player's index.
   424  * @return				Connection time.
   425  * @error				Invalid client index, client not in game, or fake client.
   426  */
   427 native Float:GetClientTime(client);
   428 
   429 /**
   430  * Returns the client's current latency (RTT), more accurate than GetAvgLatency but jittering.
   431  *
   432  * @param client		Player's index.
   433  * @param flow			Traffic flowing direction.
   434  * @return				Latency.
   435  * @error				Invalid client index, client not in game, or fake client.
   436  */
   437 native Float:GetClientLatency(client, NetFlow:flow);
   438 
   439 /**
   440  * Returns the client's average packet latency in seconds.
   441  *
   442  * @param client		Player's index.
   443  * @param flow			Traffic flowing direction.
   444  * @return				Average latency.
   445  * @error				Invalid client index, client not in game, or fake client.
   446  */
   447 native Float:GetClientAvgLatency(client, NetFlow:flow);
   448 
   449 /**
   450  * Returns the client's average packet loss, values go from 0 to 1 (for percentages).
   451  *
   452  * @param client		Player's index.
   453  * @param flow			Traffic flowing direction.
   454  * @return				Average packet loss.
   455  * @error				Invalid client index, client not in game, or fake client.
   456  */
   457 native Float:GetClientAvgLoss(client, NetFlow:flow);
   458 
   459 /**
   460  * Returns the client's average packet choke, values go from 0 to 1 (for percentages).
   461  *
   462  * @param client		Player's index.
   463  * @param flow			Traffic flowing direction.
   464  * @return				Average packet choke.
   465  * @error				Invalid client index, client not in game, or fake client.
   466  */
   467 native Float:GetClientAvgChoke(client, NetFlow:flow);
   468 
   469 /**
   470  * Returns the client's data flow in bytes/sec.
   471  *
   472  * @param client		Player's index.
   473  * @param flow			Traffic flowing direction.
   474  * @return				Data flow.
   475  * @error				Invalid client index, client not in game, or fake client.
   476  */
   477 native Float:GetClientAvgData(client, NetFlow:flow);
   478 
   479 /**
   480  * Returns the client's average packet frequency in packets/sec.
   481  *
   482  * @param client		Player's index.
   483  * @param flow			Traffic flowing direction.
   484  * @return				Packet frequency.
   485  * @error				Invalid client index, client not in game, or fake client.
   486  */
   487 native Float:GetClientAvgPackets(client, NetFlow:flow);
   488 
   489 /**
   490  * Translates an userid index to the real player index.
   491  *
   492  * @param userid		Userid value.
   493  * @return				Client value.
   494  * @error				Returns 0 if invalid userid.
   495  */
   496 native GetClientOfUserId(userid);