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