3 * =============================================================================
4 * SourceMod (C)2004-2008 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
39 * Network flow directions.
43 NetFlow_Outgoing = 0, /**< Outgoing traffic */
44 NetFlow_Incoming, /**< Incoming traffic */
45 NetFlow_Both, /**< Both values added together */
49 * MAXPLAYERS is not the same as MaxClients.
50 * MAXPLAYERS is a hardcoded value as an upper limit. MaxClients changes based on the server.
52 * Both GetMaxClients() and MaxClients are only available once the map is loaded, and should
53 * not be used in OnPluginStart().
56 #define MAXPLAYERS 64 /**< Maximum number of players SourceMod supports */
57 #define MAX_NAME_LENGTH 32 /**< Maximum buffer required to store a client name */
59 public const MaxClients; /**< Maximum number of players the server supports (dynamic) */
62 * Called on client connection. If you return true, the client will be allowed in the server.
63 * If you return false (or return nothing), the client will be rejected. If the client is
64 * rejected by this forward or any other, OnClientDisconnect will not be called.
66 * Note: Do not write to rejectmsg if you plan on returning true. If multiple plugins write
67 * to the string buffer, it is not defined which plugin's string will be shown to the client,
68 * but it is guaranteed one of them will.
70 * @param client Client index.
71 * @param rejectmsg Buffer to store the rejection message when the connection is refused.
72 * @param maxlen Maximum number of characters for rejection buffer.
73 * @return True to validate client's connection, false to refuse it.
75 forward bool:OnClientConnect(client, String:rejectmsg[], maxlen);
78 * Called once a client successfully connects. This callback is paired with OnClientDisconnect.
80 * @param client Client index.
83 forward OnClientConnected(client);
86 * Called when a client is entering the game.
88 * Whether a client has a steamid is undefined until OnClientAuthorized
89 * is called, which may occur either before or after OnClientPutInServer.
90 * Similarly, use OnClientPostAdminCheck() if you need to verify whether
91 * connecting players are admins.
93 * GetClientCount() will include clients as they are passed through this
94 * function, as clients are already in game at this point.
96 * @param client Client index.
99 forward OnClientPutInServer(client);
102 * Called when a client is disconnecting from the server.
104 * @param client Client index.
107 forward OnClientDisconnect(client);
110 * Called when a client is disconnected from the server.
112 * @param client Client index.
115 forward OnClientDisconnect_Post(client);
118 * Called when a client is sending a command.
120 * @param client Client index.
121 * @param args Number of arguments.
124 forward Action:OnClientCommand(client, args);
127 * Called whenever the client's settings are changed.
129 * @param client Client index.
132 forward OnClientSettingsChanged(client);
135 * Called when a client receives a Steam ID. The state of a client's
136 * authorization as an admin is not guaranteed here. Use
137 * OnClientPostAdminCheck() if you need a client's admin status.
139 * This is called by bots, but the ID will be "BOT".
141 * @param client Client index.
142 * @param auth Client auth string.
145 forward OnClientAuthorized(client, const String:auth[]);
148 * Called once a client is authorized and fully in-game, but
149 * before admin checks are done. This can be used to override
150 * the default admin checks for a client. You should only use
151 * this for overriding; use OnClientPostAdminCheck() instead
152 * if you want notification.
154 * Note: If handled/blocked, PostAdminCheck must be signalled
155 * manually via NotifyPostAdminCheck().
157 * This callback is gauranteed to occur on all clients, and always
158 * after each OnClientPutInServer() call.
160 * @param client Client index.
161 * @return Plugin_Handled to block admin checks.
163 forward Action:OnClientPreAdminCheck(client);
166 * Called directly before OnClientPostAdminCheck() as a method to
167 * alter administrative permissions before plugins perform final
168 * post-connect operations.
170 * In general, do not use this function unless you are specifically
171 * attempting to change access permissions. Use OnClientPostAdminCheck()
172 * instead if you simply want to perform post-connect authorization
175 * See OnClientPostAdminCheck() for more information.
177 * @param client Client index.
180 forward OnClientPostAdminFilter(client);
183 * Called once a client is authorized and fully in-game, and
184 * after all post-connection authorizations have been performed.
186 * This callback is gauranteed to occur on all clients, and always
187 * after each OnClientPutInServer() call.
189 * @param client Client index.
192 forward OnClientPostAdminCheck(client);
195 * This function will be deprecated in a future release. Use the MaxClients variable instead.
197 * Returns the maximum number of clients allowed on the server. This may
198 * return 0 if called before OnMapStart(), and thus should not be called
199 * in OnPluginStart().
201 * You should not globally cache the value to GetMaxClients() because it can change from
202 * SourceTV or TF2's arena mode. Use the "MaxClients" dynamic variable documented at the
205 * @return Maximum number of clients allowed.
207 native GetMaxClients();
210 * Returns the client count put in the server.
212 * @param inGameOnly If false connecting players are also counted.
213 * @return Client count in the server.
215 native GetClientCount(bool:inGameOnly=true);
218 * Returns the client's name.
220 * @param client Player index.
221 * @param name Buffer to store the client's name.
222 * @param maxlen Maximum length of string buffer (includes NULL terminator).
223 * @return True on success, false otherwise.
224 * @error If the client is not connected an error will be thrown.
226 native bool:GetClientName(client, String:name[], maxlen);
229 * Retrieves a client's IP address.
231 * @param client Player index.
232 * @param name Buffer to store the client's ip address.
233 * @param maxlen Maximum length of string buffer (includes NULL terminator).
234 * @param remport Remove client's port from the ip string (true by default).
235 * @return True on success, false otherwise.
236 * @error If the client is not connected or the index is invalid.
238 native bool:GetClientIP(client, String:ip[], maxlen, bool:remport=true);
241 * Retrieves a client's authentication string (SteamID).
243 * @param client Player index.
244 * @param auth Buffer to store the client's auth string.
245 * @param maxlen Maximum length of string buffer (includes NULL terminator).
246 * @return True on success, false otherwise.
247 * @error If the client is not connected or the index is invalid.
249 native bool:GetClientAuthString(client, String:auth[], maxlen);
252 * Retrieves a client's user id, which is an index incremented for every client
253 * that joins the server.
255 * @param client Player index.
256 * @return User id of the client.
257 * @error If the client is not connected or the index is invalid.
259 native GetClientUserId(client);
262 * Returns if a certain player is connected.
264 * @param client Player index.
265 * @return True if player is connected to the server, false otherwise.
267 native bool:IsClientConnected(client);
270 * Returns if a certain player has entered the game.
272 * @param client Player index (index does not have to be connected).
273 * @return True if player has entered the game, false otherwise.
274 * @error Invalid client index.
276 native bool:IsClientInGame(client);
279 * Returns if a client is in the "kick queue" (i.e. the client will be kicked
280 * shortly and thus they should not appear as valid).
282 * @param client Player index (must be connected).
283 * @return True if in the kick queue, false otherwise.
284 * @error Invalid client index.
286 native bool:IsClientInKickQueue(client);
289 * Backwards compatibility stock - use IsClientInGame
290 * @deprecated Renamed to IsClientInGame
292 #pragma deprecated Use IsClientInGame() instead
293 stock bool:IsPlayerInGame(client)
295 return IsClientInGame(client);
299 * Returns if a certain player has been authenticated.
301 * @param client Player index.
302 * @return True if player has been authenticated, false otherwise.
304 native bool:IsClientAuthorized(client);
307 * Returns if a certain player is a fake client.
309 * @param client Player index.
310 * @return True if player is a fake client, false otherwise.
312 native bool:IsFakeClient(client);
315 * Returns if a certain player is an observer/spectator.
317 * @param client Player index.
318 * @return True if player is an obverser, false otherwise.
320 native bool:IsClientObserver(client);
323 * Returns if the client is alive or dead.
325 * Note: This function was originally in SDKTools and was moved to core.
327 * @param client Player's index.
328 * @return True if the client is alive, false otherwise.
329 * @error Invalid client index, client not in game, or no mod support.
331 native bool:IsPlayerAlive(client);
334 * Retrieves values from client replicated keys.
336 * @param client Player's index.
337 * @param key Key string.
338 * @param value Buffer to store value.
339 * @param maxlen Maximum length of valve (UTF-8 safe).
340 * @return True on success, false otherwise.
341 * @error Invalid client index, or client not connected.
343 native bool:GetClientInfo(client, const String:key[], String:value[], maxlen);
346 * Retrieves a client's team index.
348 * @param client Player's index.
349 * @return Team index the client is on (mod specific).
350 * @error Invalid client index, client not in game, or no mod support.
352 native GetClientTeam(client);
355 * Sets a client's AdminId.
357 * @param client Player's index.
358 * @param id AdminId to set. INVALID_ADMIN_ID removes admin permissions.
359 * @param temp True if the id should be freed on disconnect.
361 * @error Invalid client index, client not connected, or bogus AdminId.
363 native SetUserAdmin(client, AdminId:id, bool:temp=false);
366 * Retrieves a client's AdminId.
368 * @param client Player's index.
369 * @return AdminId of the client, or INVALID_ADMIN_ID if none.
370 * @error Invalid client index, or client not connected.
372 native AdminId:GetUserAdmin(client);
375 * Sets access flags on a client. If the client is not an admin,
376 * a temporary, anonymous AdminId is given.
378 * @param client Player's index.
379 * @param ... Flags to set on the client.
381 * @error Invalid client index, or client not connected.
383 native AddUserFlags(client, AdminFlag:...);
386 * Removes flags from a client. If the client is not an admin,
387 * this has no effect.
389 * @param client Player's index.
390 * @param ... Flags to remove from the client.
392 * @error Invalid client index, or client not connected.
394 native RemoveUserFlags(client, AdminFlag:...);
397 * Sets access flags on a client using bits instead of flags. If the
398 * client is not an admin, and flags not 0, a temporary, anonymous AdminId is given.
400 * @param client Player's index.
401 * @param flags Bitstring of flags to set on client.
404 native SetUserFlagBits(client, flags);
407 * Returns client access flags. If the client is not an admin,
408 * the result is always 0.
410 * @param client Player's index.
412 * @error Invalid client index, or client not connected.
414 native GetUserFlagBits(client);
417 * Returns whether a user can target another user.
418 * This is a helper function for CanAdminTarget.
420 * @param client Player's index.
421 * @param target Target player's index.
422 * @return True if target is targettable by the player, false otherwise.
423 * @error Invalid or unconnected player indexers.
425 native bool:CanUserTarget(client, target);
428 * Runs through the Core-defined admin authorization checks on a player.
429 * Has no effect if the player is already an admin.
431 * Note: This function is based on the internal cache only.
433 * @param client Client index.
434 * @return True if access was changed, false if it did not.
435 * @error Invalid client index or client not in-game AND authorized.
437 native bool:RunAdminCacheChecks(client);
440 * Signals that a player has completed post-connection admin checks.
441 * Has no effect if the player has already had this event signalled.
443 * Note: This must be sent even if no admin id was assigned.
445 * @param client Client index.
447 * @error Invalid client index or client not in-game AND authorized.
449 native NotifyPostAdminCheck(client);
452 * Creates a fake client.
454 * @param name Name to use.
455 * @return Client index on success, 0 otherwise.
457 native CreateFakeClient(const String:name[]);
460 * Sets a convar value on a fake client.
462 * @param client Client index.
463 * @param cvar ConVar name.
464 * @param value ConVar value.
466 * @error Invalid client index, client not connected,
467 * or client not a fake client.
469 native SetFakeClientConVar(client, const String:cvar[], const String:value[]);
472 * Returns the client's health.
474 * @param client Player's index.
475 * @return Health value.
476 * @error Invalid client index, client not in game, or no mod support.
478 native GetClientHealth(client);
481 * Returns the client's model name.
483 * @param client Player's index.
484 * @param model Buffer to store the client's model name.
485 * @param maxlen Maximum length of string buffer (includes NULL terminator).
487 * @error Invalid client index, client not in game, or no mod support.
489 native GetClientModel(client, String:model[], maxlen);
492 * Returns the client's weapon name.
494 * @param client Player's index.
495 * @param weapon Buffer to store the client's weapon name.
496 * @param maxlen Maximum length of string buffer (includes NULL terminator).
498 * @error Invalid client index, client not in game, or no mod support.
500 native GetClientWeapon(client, String:weapon[], maxlen);
503 * Returns the client's max size vector.
505 * @param client Player's index.
506 * @param vec Destination vector to store the client's max size.
508 * @error Invalid client index, client not in game, or no mod support.
510 native GetClientMaxs(client, Float:vec[3]);
513 * Returns the client's min size vector.
515 * @param client Player's index.
516 * @param vec Destination vector to store the client's min size.
518 * @error Invalid client index, client not in game, or no mod support.
520 native GetClientMins(client, Float:vec[3]);
523 * Returns the client's position angle.
525 * @param client Player's index.
526 * @param ang Destination vector to store the client's position angle.
528 * @error Invalid client index, client not in game, or no mod support.
530 native GetClientAbsAngles(client, Float:ang[3]);
533 * Returns the client's origin vector.
535 * @param client Player's index.
536 * @param vec Destination vector to store the client's origin vector.
538 * @error Invalid client index, client not in game, or no mod support.
540 native GetClientAbsOrigin(client, Float:vec[3]);
543 * Returns the client's armor.
545 * @param client Player's index.
546 * @return Armor value.
547 * @error Invalid client index, client not in game, or no mod support.
549 native GetClientArmor(client);
552 * Returns the client's death count.
554 * @param client Player's index.
555 * @return Death count.
556 * @error Invalid client index, client not in game, or no mod support.
558 native GetClientDeaths(client);
561 * Returns the client's frag count.
563 * @param client Player's index.
564 * @return Frag count.
565 * @error Invalid client index, client not in game, or no mod support.
567 native GetClientFrags(client);
570 * Returns the client's send data rate in bytes/sec.
572 * @param client Player's index.
574 * @error Invalid client index, client not in game, or fake client.
576 native GetClientDataRate(client);
579 * Returns if a client is timing out
581 * @param client Player's index.
582 * @return True if client is timing out, false otherwise.
583 * @error Invalid client index, client not in game, or fake client.
585 native bool:IsClientTimingOut(client);
588 * Returns the client's connection time in seconds.
590 * @param client Player's index.
591 * @return Connection time.
592 * @error Invalid client index, client not in game, or fake client.
594 native Float:GetClientTime(client);
597 * Returns the client's current latency (RTT), more accurate than GetAvgLatency but jittering.
599 * @param client Player's index.
600 * @param flow Traffic flowing direction.
602 * @error Invalid client index, client not in game, or fake client.
604 native Float:GetClientLatency(client, NetFlow:flow);
607 * Returns the client's average packet latency in seconds.
609 * @param client Player's index.
610 * @param flow Traffic flowing direction.
611 * @return Average latency.
612 * @error Invalid client index, client not in game, or fake client.
614 native Float:GetClientAvgLatency(client, NetFlow:flow);
617 * Returns the client's average packet loss, values go from 0 to 1 (for percentages).
619 * @param client Player's index.
620 * @param flow Traffic flowing direction.
621 * @return Average packet loss.
622 * @error Invalid client index, client not in game, or fake client.
624 native Float:GetClientAvgLoss(client, NetFlow:flow);
627 * Returns the client's average packet choke, values go from 0 to 1 (for percentages).
629 * @param client Player's index.
630 * @param flow Traffic flowing direction.
631 * @return Average packet choke.
632 * @error Invalid client index, client not in game, or fake client.
634 native Float:GetClientAvgChoke(client, NetFlow:flow);
637 * Returns the client's data flow in bytes/sec.
639 * @param client Player's index.
640 * @param flow Traffic flowing direction.
642 * @error Invalid client index, client not in game, or fake client.
644 native Float:GetClientAvgData(client, NetFlow:flow);
647 * Returns the client's average packet frequency in packets/sec.
649 * @param client Player's index.
650 * @param flow Traffic flowing direction.
651 * @return Packet frequency.
652 * @error Invalid client index, client not in game, or fake client.
654 native Float:GetClientAvgPackets(client, NetFlow:flow);
657 * Translates an userid index to the real player index.
659 * @param userid Userid value.
660 * @return Client value.
661 * @error Returns 0 if invalid userid.
663 native GetClientOfUserId(userid);
666 * Disconnects a client from the server as soon as the next frame starts.
668 * Note: Originally, KickClient() was immediate. The delay was introduced
669 * because despite warnings, plugins were using it in ways that would crash.
670 * The new safe version can break cases that rely on immediate disconnects,
671 * but ensures that plugins do not accidentally cause crashes.
673 * If you need immediate disconnects, use KickClientEx().
675 * Note: IsClientInKickQueue() will return true before the kick occurs.
677 * @param client Client index.
678 * @param format Optional formatting rules for disconnect reason.
679 * Note that a period is automatically appended to the string by the engine.
680 * @param ... Variable number of format parameters.
682 * @error Invalid client index, or client not connected.
684 native KickClient(client, const String:format[]="", any:...);
687 * Immediately disconnects a client from the server.
689 * Kicking clients from certain events or callbacks may cause crashes. If in
690 * doubt, create a short (0.1 second) timer to kick the client in the next
693 * @param client Client index.
694 * @param format Optional formatting rules for disconnect reason.
695 * Note that a period is automatically appended to the string by the engine.
696 * @param ... Variable number of format parameters.
698 * @error Invalid client index, or client not connected.
700 native KickClientEx(client, const String:format[]="", any:...);
703 * Changes a client's team through the mod's generic team changing function.
704 * On CS:S, this will kill the player.
706 * @param client Client index.
707 * @param team Mod-specific team index.
709 * @error Invalid client index, client not connected, or lack of
712 native ChangeClientTeam(client, team);
715 * Returns the clients unique serial identifier.
717 * @return Serial number.
719 native GetClientSerial(client);
722 * Returns the client index by its serial number.
724 * @return Client index, or 0 for invalid serial.
726 native GetClientFromSerial(serial);