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 * @param client Client index.
67 * @param rejectmsg Buffer to store the rejection message when the connection is refused.
68 * @param maxlen Maximum number of characters for rejection buffer.
69 * @return True to validate client's connection, false to refuse it.
71 forward bool:OnClientConnect(client, String:rejectmsg[], maxlen);
74 * Called once a client successfully connects. This callback is paired with OnClientDisconnect.
76 * @param client Client index.
79 forward OnClientConnected(client);
82 * Called when a client is entering the game.
84 * Whether a client has a steamid is undefined until OnClientAuthorized
85 * is called, which may occur either before or after OnClientPutInServer.
86 * Similarly, use OnClientPostAdminCheck() if you need to verify whether
87 * connecting players are admins.
89 * GetClientCount() will include clients as they are passed through this
90 * function, as clients are already in game at this point.
92 * @param client Client index.
95 forward OnClientPutInServer(client);
98 * Called when a client is disconnecting from the server.
100 * @param client Client index.
103 forward OnClientDisconnect(client);
106 * Called when a client is disconnected from the server.
108 * @param client Client index.
111 forward OnClientDisconnect_Post(client);
114 * Called when a client is sending a command.
116 * @param client Client index.
117 * @param args Number of arguments.
120 forward Action:OnClientCommand(client, args);
123 * Called whenever the client's settings are changed.
125 * @param client Client index.
128 forward OnClientSettingsChanged(client);
131 * Called when a client receives a Steam ID. The state of a client's
132 * authorization via Steam or as an admin is not guaranteed here.
133 * Use OnClientAuthorized() or OnClientPostAdminCheck() for those,
136 * This is called by bots, but the ID will be "BOT".
138 * @param client Client index.
139 * @param auth Client auth string.
142 forward OnClientAuthorized(client, const String:auth[]);
145 * Called once a client is authorized and fully in-game, but
146 * before admin checks are done. This can be used to override
147 * the default admin checks for a client. You should only use
148 * this for overriding; use OnClientPostAdminCheck() instead
149 * if you want notification.
151 * Note: If handled/blocked, PostAdminCheck must be signalled
152 * manually via NotifyPostAdminCheck().
154 * This callback is gauranteed to occur on all clients, and always
155 * after each OnClientPutInServer() call.
157 * @param client Client index.
158 * @return Plugin_Handled to block admin checks.
160 forward Action:OnClientPreAdminCheck(client);
163 * Called directly before OnClientPostAdminCheck() as a method to
164 * alter administrative permissions before plugins perform final
165 * post-connect operations.
167 * In general, do not use this function unless you are specifically
168 * attempting to change access permissions. Use OnClientPostAdminCheck()
169 * instead if you simply want to perform post-connect authorization
172 * See OnClientPostAdminCheck() for more information.
174 * @param client Client index.
177 forward OnClientPostAdminFilter(client);
180 * Called once a client is authorized and fully in-game, and
181 * after all post-connection authorizations have been performed.
183 * This callback is gauranteed to occur on all clients, and always
184 * after each OnClientPutInServer() call.
186 * @param client Client index.
189 forward OnClientPostAdminCheck(client);
192 * This function will be deprecated in a future release. Use the MaxClients variable instead.
194 * Returns the maximum number of clients allowed on the server. This may
195 * return 0 if called before OnMapStart(), and thus should not be called
196 * in OnPluginStart().
198 * You should not globally cache the value to GetMaxClients() because it can change from
199 * SourceTV or TF2's arena mode. Use the "MaxClients" dynamic variable documented at the
202 * @return Maximum number of clients allowed.
204 native GetMaxClients();
207 * Returns the client count put in the server.
209 * @param inGameOnly If false connecting players are also counted.
210 * @return Client count in the server.
212 native GetClientCount(bool:inGameOnly=true);
215 * Returns the client's name.
217 * @param client Player index.
218 * @param name Buffer to store the client's name.
219 * @param maxlen Maximum length of string buffer (includes NULL terminator).
220 * @return True on success, false otherwise.
221 * @error If the client is not connected an error will be thrown.
223 native bool:GetClientName(client, String:name[], maxlen);
226 * Retrieves a client's IP address.
228 * @param client Player index.
229 * @param name Buffer to store the client's ip address.
230 * @param maxlen Maximum length of string buffer (includes NULL terminator).
231 * @param remport Remove client's port from the ip string (true by default).
232 * @return True on success, false otherwise.
233 * @error If the client is not connected or the index is invalid.
235 native bool:GetClientIP(client, String:ip[], maxlen, bool:remport=true);
238 * Retrieves a client's authentication string (SteamID).
240 * @param client Player index.
241 * @param auth Buffer to store the client's auth string.
242 * @param maxlen Maximum length of string buffer (includes NULL terminator).
243 * @return True on success, false otherwise.
244 * @error If the client is not connected or the index is invalid.
246 native bool:GetClientAuthString(client, String:auth[], maxlen);
249 * Retrieves a client's user id, which is an index incremented for every client
250 * that joins the server.
252 * @param client Player index.
253 * @return User id of the client.
254 * @error If the client is not connected or the index is invalid.
256 native GetClientUserId(client);
259 * Returns if a certain player is connected.
261 * @param client Player index.
262 * @return True if player is connected to the server, false otherwise.
264 native bool:IsClientConnected(client);
267 * Returns if a certain player has entered the game.
269 * @param client Player index (index does not have to be connected).
270 * @return True if player has entered the game, false otherwise.
271 * @error Invalid client index.
273 native bool:IsClientInGame(client);
276 * Returns if a client is in the "kick queue" (i.e. the client will be kicked
277 * shortly and thus they should not appear as valid).
279 * @param client Player index (must be connected).
280 * @return True if in the kick queue, false otherwise.
281 * @error Invalid client index.
283 native bool:IsClientInKickQueue(client);
286 * Backwards compatibility stock - use IsClientInGame
287 * @deprecated Renamed to IsClientInGame
289 #pragma deprecated Use IsClientInGame() instead
290 stock bool:IsPlayerInGame(client)
292 return IsClientInGame(client);
296 * Returns if a certain player has been authenticated.
298 * @param client Player index.
299 * @return True if player has been authenticated, false otherwise.
301 native bool:IsClientAuthorized(client);
304 * Returns if a certain player is a fake client.
306 * @param client Player index.
307 * @return True if player is a fake client, false otherwise.
309 native bool:IsFakeClient(client);
312 * Returns if a certain player is an observer/spectator.
314 * @param client Player index.
315 * @return True if player is an obverser, false otherwise.
317 native bool:IsClientObserver(client);
320 * Returns if the client is alive or dead.
322 * Note: This function was originally in SDKTools and was moved to core.
324 * @param client Player's index.
325 * @return True if the client is alive, false otherwise.
326 * @error Invalid client index, client not in game, or no mod support.
328 native bool:IsPlayerAlive(client);
331 * Retrieves values from client replicated keys.
333 * @param client Player's index.
334 * @param key Key string.
335 * @param value Buffer to store value.
336 * @param maxlen Maximum length of valve (UTF-8 safe).
337 * @return True on success, false otherwise.
338 * @error Invalid client index, or client not connected.
340 native bool:GetClientInfo(client, const String:key[], String:value[], maxlen);
343 * Retrieves a client's team index.
345 * @param client Player's index.
346 * @return Team index the client is on (mod specific).
347 * @error Invalid client index, client not in game, or no mod support.
349 native GetClientTeam(client);
352 * Sets a client's AdminId.
354 * @param client Player's index.
355 * @param id AdminId to set. INVALID_ADMIN_ID removes admin permissions.
356 * @param temp True if the id should be freed on disconnect.
358 * @error Invalid client index, client not connected, or bogus AdminId.
360 native SetUserAdmin(client, AdminId:id, bool:temp=false);
363 * Retrieves a client's AdminId.
365 * @param client Player's index.
366 * @return AdminId of the client, or INVALID_ADMIN_ID if none.
367 * @error Invalid client index, or client not connected.
369 native AdminId:GetUserAdmin(client);
372 * Sets access flags on a client. If the client is not an admin,
373 * a temporary, anonymous AdminId is given.
375 * @param client Player's index.
376 * @param ... Flags to set on the client.
378 * @error Invalid client index, or client not connected.
380 native AddUserFlags(client, AdminFlag:...);
383 * Removes flags from a client. If the client is not an admin,
384 * this has no effect.
386 * @param client Player's index.
387 * @param ... Flags to remove from the client.
389 * @error Invalid client index, or client not connected.
391 native RemoveUserFlags(client, AdminFlag:...);
394 * Sets access flags on a client using bits instead of flags. If the
395 * client is not an admin, and flags not 0, a temporary, anonymous AdminId is given.
397 * @param client Player's index.
398 * @param flags Bitstring of flags to set on client.
401 native SetUserFlagBits(client, flags);
404 * Returns client access flags. If the client is not an admin,
405 * the result is always 0.
407 * @param client Player's index.
409 * @error Invalid client index, or client not connected.
411 native GetUserFlagBits(client);
414 * Returns whether a user can target another user.
415 * This is a helper function for CanAdminTarget.
417 * @param client Player's index.
418 * @param target Target player's index.
419 * @return True if target is targettable by the player, false otherwise.
420 * @error Invalid or unconnected player indexers.
422 native bool:CanUserTarget(client, target);
425 * Runs through the Core-defined admin authorization checks on a player.
426 * Has no effect if the player is already an admin.
428 * Note: This function is based on the internal cache only.
430 * @param client Client index.
431 * @return True if access was changed, false if it did not.
432 * @error Invalid client index or client not in-game AND authorized.
434 native bool:RunAdminCacheChecks(client);
437 * Signals that a player has completed post-connection admin checks.
438 * Has no effect if the player has already had this event signalled.
440 * Note: This must be sent even if no admin id was assigned.
442 * @param client Client index.
444 * @error Invalid client index or client not in-game AND authorized.
446 native NotifyPostAdminCheck(client);
449 * Creates a fake client.
451 * @param name Name to use.
452 * @return Client index on success, 0 otherwise.
454 native CreateFakeClient(const String:name[]);
457 * Sets a convar value on a fake client.
459 * @param client Client index.
460 * @param cvar ConVar name.
461 * @param value ConVar value.
463 * @error Invalid client index, client not connected,
464 * or client not a fake client.
466 native SetFakeClientConVar(client, const String:cvar[], const String:value[]);
469 * Returns the client's health.
471 * @param client Player's index.
472 * @return Health value.
473 * @error Invalid client index, client not in game, or no mod support.
475 native GetClientHealth(client);
478 * Returns the client's model name.
480 * @param client Player's index.
481 * @param model Buffer to store the client's model name.
482 * @param maxlen Maximum length of string buffer (includes NULL terminator).
484 * @error Invalid client index, client not in game, or no mod support.
486 native GetClientModel(client, String:model[], maxlen);
489 * Returns the client's weapon name.
491 * @param client Player's index.
492 * @param weapon Buffer to store the client's weapon name.
493 * @param maxlen Maximum length of string buffer (includes NULL terminator).
495 * @error Invalid client index, client not in game, or no mod support.
497 native GetClientWeapon(client, String:weapon[], maxlen);
500 * Returns the client's max size vector.
502 * @param client Player's index.
503 * @param vec Destination vector to store the client's max size.
505 * @error Invalid client index, client not in game, or no mod support.
507 native GetClientMaxs(client, Float:vec[3]);
510 * Returns the client's min size vector.
512 * @param client Player's index.
513 * @param vec Destination vector to store the client's min size.
515 * @error Invalid client index, client not in game, or no mod support.
517 native GetClientMins(client, Float:vec[3]);
520 * Returns the client's position angle.
522 * @param client Player's index.
523 * @param ang Destination vector to store the client's position angle.
525 * @error Invalid client index, client not in game, or no mod support.
527 native GetClientAbsAngles(client, Float:ang[3]);
530 * Returns the client's origin vector.
532 * @param client Player's index.
533 * @param vec Destination vector to store the client's origin vector.
535 * @error Invalid client index, client not in game, or no mod support.
537 native GetClientAbsOrigin(client, Float:vec[3]);
540 * Returns the client's armor.
542 * @param client Player's index.
543 * @return Armor value.
544 * @error Invalid client index, client not in game, or no mod support.
546 native GetClientArmor(client);
549 * Returns the client's death count.
551 * @param client Player's index.
552 * @return Death count.
553 * @error Invalid client index, client not in game, or no mod support.
555 native GetClientDeaths(client);
558 * Returns the client's frag count.
560 * @param client Player's index.
561 * @return Frag count.
562 * @error Invalid client index, client not in game, or no mod support.
564 native GetClientFrags(client);
567 * Returns the client's send data rate in bytes/sec.
569 * @param client Player's index.
571 * @error Invalid client index, client not in game, or fake client.
573 native GetClientDataRate(client);
576 * Returns if a client is timing out
578 * @param client Player's index.
579 * @return True if client is timing out, false otherwise.
580 * @error Invalid client index, client not in game, or fake client.
582 native bool:IsClientTimingOut(client);
585 * Returns the client's connection time in seconds.
587 * @param client Player's index.
588 * @return Connection time.
589 * @error Invalid client index, client not in game, or fake client.
591 native Float:GetClientTime(client);
594 * Returns the client's current latency (RTT), more accurate than GetAvgLatency but jittering.
596 * @param client Player's index.
597 * @param flow Traffic flowing direction.
599 * @error Invalid client index, client not in game, or fake client.
601 native Float:GetClientLatency(client, NetFlow:flow);
604 * Returns the client's average packet latency in seconds.
606 * @param client Player's index.
607 * @param flow Traffic flowing direction.
608 * @return Average latency.
609 * @error Invalid client index, client not in game, or fake client.
611 native Float:GetClientAvgLatency(client, NetFlow:flow);
614 * Returns the client's average packet loss, values go from 0 to 1 (for percentages).
616 * @param client Player's index.
617 * @param flow Traffic flowing direction.
618 * @return Average packet loss.
619 * @error Invalid client index, client not in game, or fake client.
621 native Float:GetClientAvgLoss(client, NetFlow:flow);
624 * Returns the client's average packet choke, values go from 0 to 1 (for percentages).
626 * @param client Player's index.
627 * @param flow Traffic flowing direction.
628 * @return Average packet choke.
629 * @error Invalid client index, client not in game, or fake client.
631 native Float:GetClientAvgChoke(client, NetFlow:flow);
634 * Returns the client's data flow in bytes/sec.
636 * @param client Player's index.
637 * @param flow Traffic flowing direction.
639 * @error Invalid client index, client not in game, or fake client.
641 native Float:GetClientAvgData(client, NetFlow:flow);
644 * Returns the client's average packet frequency in packets/sec.
646 * @param client Player's index.
647 * @param flow Traffic flowing direction.
648 * @return Packet frequency.
649 * @error Invalid client index, client not in game, or fake client.
651 native Float:GetClientAvgPackets(client, NetFlow:flow);
654 * Translates an userid index to the real player index.
656 * @param userid Userid value.
657 * @return Client value.
658 * @error Returns 0 if invalid userid.
660 native GetClientOfUserId(userid);
663 * Disconnects a client from the server as soon as the next frame starts.
665 * Note: Originally, KickClient() was immediate. The delay was introduced
666 * because despite warnings, plugins were using it in ways that would crash.
667 * The new safe version can break cases that rely on immediate disconnects,
668 * but ensures that plugins do not accidentally cause crashes.
670 * If you need immediate disconnects, use KickClientEx().
672 * Note: IsClientInKickQueue() will return true before the kick occurs.
674 * @param client Client index.
675 * @param format Optional formatting rules for disconnect reason.
676 * Note that a period is automatically appended to the string by the engine.
677 * @param ... Variable number of format parameters.
679 * @error Invalid client index, or client not connected.
681 native KickClient(client, const String:format[]="", any:...);
684 * Immediately disconnects a client from the server.
686 * Kicking clients from certain events or callbacks may cause crashes. If in
687 * doubt, create a short (0.1 second) timer to kick the client in the next
690 * @param client Client index.
691 * @param format Optional formatting rules for disconnect reason.
692 * Note that a period is automatically appended to the string by the engine.
693 * @param ... Variable number of format parameters.
695 * @error Invalid client index, or client not connected.
697 native KickClientEx(client, const String:format[]="", any:...);
700 * Changes a client's team through the mod's generic team changing function.
701 * On CS:S, this will kill the player.
703 * @param client Client index.
704 * @param team Mod-specific team index.
706 * @error Invalid client index, client not connected, or lack of
709 native ChangeClientTeam(client, team);
712 * Returns the clients unique serial identifier.
714 * @return Serial number.
716 native GetClientSerial(client);
719 * Returns the client index by its serial number.
721 * @return Client index, or 0 for invalid serial.
723 native GetClientFromSerial(serial);