3 * =============================================================================
4 * SourceMod (C)2004-2007 AlliedModders LLC. All rights reserved.
5 * =============================================================================
7 * This file is part of the SourceMod/SourcePawn SDK.
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.
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
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/>.
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>.
33 #if defined _clients_included
36 #define _clients_included
40 NetFlow_Outgoing = 0, /**< Outgoing traffic */
41 NetFlow_Incoming, /**< Incoming traffic */
42 NetFlow_Both /**< Incoming and outgoing traffic */
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 */
49 * Called on client connection.
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.
56 forward bool:OnClientConnect(client, String:rejectmsg[], maxlen);
59 * Called when a client is entering to the game.
61 * @note Whether a client has a steamid is undefined until OnClientAuthorized
62 * is called, which may occur either before or after OnClientPutInServer.
64 * @param client Client index.
67 forward OnClientPutInServer(client);
70 * Called when a client is disconnecting from the server.
72 * @param client Client index.
75 forward OnClientDisconnect(client);
78 * Called when a client is disconnected from the server.
80 * @param client Client index.
83 forward OnClientDisconnect_Post(client);
86 * Called when a client is sending a command.
88 * @param client Client index.
89 * @param args Number of arguments.
92 forward Action:OnClientCommand(client, args);
95 * Called whenever the client's settings are changed.
97 * @param client Client index.
100 forward OnClientSettingsChanged(client);
103 * Called when a client receives a Steam ID.
105 * Admin properties are not assigned here, but on OnClientPostAdminCheck().
106 * This is called by bots, but the ID will be "BOT".
108 * @param client Client index.
109 * @param auth Client auth string.
112 forward OnClientAuthorized(client, const String:auth[]);
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.
119 * Note: If handled/blocked, PostAdminCheck must be signalled
120 * manually via NotifyPostAdminCheck().
122 * @param client Client index.
123 * @return Plugin_Handled to block admin checks.
125 forward Action:OnClientPreAdminCheck(client);
128 * Called once a client is authorized and fully in-game, and
129 * after all post-connection authorizations have been performed.
131 * @param client Client index.
134 forward OnClientPostAdminCheck(client);
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().
141 * @return Maximum number of clients allowed.
143 native GetMaxClients();
146 * Returns the client count put in the server.
148 * @param inGameOnly If false connecting players are also counted.
149 * @return Client count in the server.
151 native GetClientCount(bool:inGameOnly=true);
154 * Returns the client's name.
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.
162 native bool:GetClientName(client, String:name[], maxlen);
165 * Retrieves a client's IP address.
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.
174 native bool:GetClientIP(client, String:ip[], maxlen, bool:remport=true);
177 * Retrieves a client's authentication string (SteamID).
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.
185 native bool:GetClientAuthString(client, String:auth[], maxlen);
188 * Retrieves a client's user id, which is an index incremented for every client
189 * that joins the server.
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.
195 native GetClientUserId(client);
198 * Returns if a certain player is connected.
200 * @param client Player index.
201 * @return True if player is connected to the server, false otherwise.
203 native bool:IsClientConnected(client);
206 * Returns if a certain player has entered the game.
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.
212 native bool:IsClientInGame(client);
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).
218 * @param client Player index (must be connected).
219 * @return True if in the kick queue, false otherwise.
220 * @error Invalid client index.
222 native bool:IsClientInKickQueue(client);
225 * Backwards compatibility stock - use IsClientInGame
226 * @deprecated Renamed to IsClientInGame
228 #pragma deprecated Use IsClientInGame() instead
229 stock bool:IsPlayerInGame(client)
231 return IsClientInGame(client);
235 * Returns if a certain player has been authenticated.
237 * @param client Player index.
238 * @return True if player has been authenticated, false otherwise.
240 native bool:IsClientAuthorized(client);
243 * Returns if a certain player is a fake client.
245 * @param client Player index.
246 * @return True if player is a fake client, false otherwise.
248 native bool:IsFakeClient(client);
251 * Returns if a certain player is an observer/spectator.
253 * @param client Player index.
254 * @return True if player is an obverser, false otherwise.
256 native bool:IsClientObserver(client);
259 * Returns if the client is alive or dead.
261 * Note: This function was originally in SDKTools and was moved to core.
263 * @param client Player's index.
264 * @return True if the client is alive, false otherwise.
265 * @error Invalid client index, client not in game, or no mod support.
267 native bool:IsPlayerAlive(client);
270 * Retrieves values from client replicated keys.
272 * @param client Player's index.
273 * @param key Key string.
274 * @param value Buffer to store value.
275 * @param maxlen Maximum length of valve (UTF-8 safe).
276 * @return True on success, false otherwise.
277 * @error Invalid client index, or client not connected.
279 native bool:GetClientInfo(client, const String:key[], String:value[], maxlen);
282 * Retrieves a client's team index.
284 * @param client Player's index.
285 * @return Team index the client is on (mod specific).
286 * @error Invalid client index, client not in game, or no mod support.
288 native GetClientTeam(client);
291 * Sets a client's AdminId.
293 * @param client Player's index.
294 * @param id AdminId to set. INVALID_ADMIN_ID removes admin permissions.
295 * @param temp True if the id should be freed on disconnect.
297 * @error Invalid client index, client not connected, or bogus AdminId.
299 native SetUserAdmin(client, AdminId:id, bool:temp=false);
302 * Retrieves a client's AdminId.
304 * @param client Player's index.
305 * @return AdminId of the client, or INVALID_ADMIN_ID if none.
306 * @error Invalid client index, or client not connected.
308 native AdminId:GetUserAdmin(client);
311 * Sets access flags on a client. If the client is not an admin,
312 * a temporary, anonymous AdminId is given.
314 * @param client Player's index.
315 * @param ... Flags to set on the client.
317 * @error Invalid client index, or client not connected.
319 native AddUserFlags(client, AdminFlag:...);
322 * Removes flags from a client. If the client is not an admin,
323 * this has no effect.
325 * @param client Player's index.
326 * @param ... Flags to remove from the client.
328 * @error Invalid client index, or client not connected.
330 native RemoveUserFlags(client, AdminFlag:...);
333 * Sets access flags on a client using bits instead of flags. If the
334 * client is not an admin, and flags not 0, a temporary, anonymous AdminId is given.
336 * @param client Player's index.
337 * @param flags Bitstring of flags to set on client.
340 native SetUserFlagBits(client, flags);
343 * Returns client access flags. If the client is not an admin,
344 * the result is always 0.
346 * @param client Player's index.
348 * @error Invalid client index, or client not connected.
350 native GetUserFlagBits(client);
353 * Returns whether a user can target another user.
354 * This is a helper function for CanAdminTarget.
356 * @param client Player's index.
357 * @param target Target player's index.
358 * @return True if target is targettable by the player, false otherwise.
359 * @error Invalid or unconnected player indexers.
361 native bool:CanUserTarget(client, target);
364 * Runs through the Core-defined admin authorization checks on a player.
365 * Has no effect if the player is already an admin.
367 * Note: This function is based on the internal cache only.
369 * @param client Client index.
370 * @return True if access was changed, false if it did not.
371 * @error Invalid client index or client not in-game AND authorized.
373 native bool:RunAdminCacheChecks(client);
376 * Signals that a player has completed post-connection admin checks.
377 * Has no effect if the player has already had this event signalled.
379 * Note: This must be sent even if no admin id was assigned.
381 * @param client Client index.
383 * @error Invalid client index or client not in-game AND authorized.
385 native NotifyPostAdminCheck(client);
388 * Creates a fake client.
390 * @param name Name to use.
391 * @return Client index on success, 0 otherwise.
393 native CreateFakeClient(const String:name[]);
396 * Sets a convar value on a fake client.
398 * @param client Client index.
399 * @param cvar ConVar name.
400 * @param value ConVar value.
402 * @error Invalid client index, client not connected,
403 * or client not a fake client.
405 native SetFakeClientConVar(client, const String:cvar[], const String:value[]);
408 * Returns the client's health.
410 * @param client Player's index.
411 * @return Health value.
412 * @error Invalid client index, client not in game, or no mod support.
414 native GetClientHealth(client);
417 * Returns the client's model name.
419 * @param client Player's index.
420 * @param model Buffer to store the client's model name.
421 * @param maxlen Maximum length of string buffer (includes NULL terminator).
423 * @error Invalid client index, client not in game, or no mod support.
425 native GetClientModel(client, String:model[], maxlen);
428 * Returns the client's weapon name.
430 * @param client Player's index.
431 * @param weapon Buffer to store the client's weapon name.
432 * @param maxlen Maximum length of string buffer (includes NULL terminator).
434 * @error Invalid client index, client not in game, or no mod support.
436 native GetClientWeapon(client, String:weapon[], maxlen);
439 * Returns the client's max size vector.
441 * @param client Player's index.
442 * @param vec Destination vector to store the client's max size.
444 * @error Invalid client index, client not in game, or no mod support.
446 native GetClientMaxs(client, Float:vec[3]);
449 * Returns the client's min size vector.
451 * @param client Player's index.
452 * @param vec Destination vector to store the client's min size.
454 * @error Invalid client index, client not in game, or no mod support.
456 native GetClientMins(client, Float:vec[3]);
459 * Returns the client's position angle.
461 * @param client Player's index.
462 * @param ang Destination vector to store the client's position angle.
464 * @error Invalid client index, client not in game, or no mod support.
466 native GetClientAbsAngles(client, Float:ang[3]);
469 * Returns the client's origin vector.
471 * @param client Player's index.
472 * @param vec Destination vector to store the client's origin vector.
474 * @error Invalid client index, client not in game, or no mod support.
476 native GetClientAbsOrigin(client, Float:vec[3]);
479 * Returns the client's armor.
481 * @param client Player's index.
482 * @return Armor value.
483 * @error Invalid client index, client not in game, or no mod support.
485 native GetClientArmor(client);
488 * Returns the client's death count.
490 * @param client Player's index.
491 * @return Death count.
492 * @error Invalid client index, client not in game, or no mod support.
494 native GetClientDeaths(client);
497 * Returns the client's frag count.
499 * @param client Player's index.
500 * @return Frag count.
501 * @error Invalid client index, client not in game, or no mod support.
503 native GetClientFrags(client);
506 * Returns the client's send data rate in bytes/sec.
508 * @param client Player's index.
510 * @error Invalid client index, client not in game, or fake client.
512 native GetClientDataRate(client);
515 * Returns if a client is timing out
517 * @param client Player's index.
518 * @return True if client is timing out, false otherwise.
519 * @error Invalid client index, client not in game, or fake client.
521 native bool:IsClientTimingOut(client);
524 * Returns the client's connection time in seconds.
526 * @param client Player's index.
527 * @return Connection time.
528 * @error Invalid client index, client not in game, or fake client.
530 native Float:GetClientTime(client);
533 * Returns the client's current latency (RTT), more accurate than GetAvgLatency but jittering.
535 * @param client Player's index.
536 * @param flow Traffic flowing direction.
538 * @error Invalid client index, client not in game, or fake client.
540 native Float:GetClientLatency(client, NetFlow:flow);
543 * Returns the client's average packet latency in seconds.
545 * @param client Player's index.
546 * @param flow Traffic flowing direction.
547 * @return Average latency.
548 * @error Invalid client index, client not in game, or fake client.
550 native Float:GetClientAvgLatency(client, NetFlow:flow);
553 * Returns the client's average packet loss, values go from 0 to 1 (for percentages).
555 * @param client Player's index.
556 * @param flow Traffic flowing direction.
557 * @return Average packet loss.
558 * @error Invalid client index, client not in game, or fake client.
560 native Float:GetClientAvgLoss(client, NetFlow:flow);
563 * Returns the client's average packet choke, values go from 0 to 1 (for percentages).
565 * @param client Player's index.
566 * @param flow Traffic flowing direction.
567 * @return Average packet choke.
568 * @error Invalid client index, client not in game, or fake client.
570 native Float:GetClientAvgChoke(client, NetFlow:flow);
573 * Returns the client's data flow in bytes/sec.
575 * @param client Player's index.
576 * @param flow Traffic flowing direction.
578 * @error Invalid client index, client not in game, or fake client.
580 native Float:GetClientAvgData(client, NetFlow:flow);
583 * Returns the client's average packet frequency in packets/sec.
585 * @param client Player's index.
586 * @param flow Traffic flowing direction.
587 * @return Packet frequency.
588 * @error Invalid client index, client not in game, or fake client.
590 native Float:GetClientAvgPackets(client, NetFlow:flow);
593 * Translates an userid index to the real player index.
595 * @param userid Userid value.
596 * @return Client value.
597 * @error Returns 0 if invalid userid.
599 native GetClientOfUserId(userid);
602 * Disconnects a client from the server.
604 * Kicking clients from certain events or callbacks may cause crashes. If in
605 * doubt, create a short (0.1 second) timer to kick the client in the next
608 * @param client Client index.
609 * @param format Optional formatting rules for disconnect reason.
610 * Note that a period is automatically appended to the string by the engine.
611 * @param ... Variable number of format parameters.
613 * @error Invalid client index, or client not connected.
615 native KickClient(client, const String:format[]="", any:...);
618 * Changes a client's team through the mod's generic team changing function.
619 * On CS:S, this will kill the player.
621 * @param client Client index.
622 * @param team Mod-specific team index.
624 * @error Invalid client index, client not connected, or lack of
627 native ChangeClientTeam(client, team);