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 _admin_included
36 #define _admin_included
39 * Access levels (flags) for admins.
43 Admin_Reservation = 0, /**< Reserved slot */
44 Admin_Generic, /**< Generic admin abilities */
45 Admin_Kick, /**< Kick another user */
46 Admin_Ban, /**< Ban another user */
47 Admin_Unban, /**< Unban another user */
48 Admin_Slay, /**< Slay/kill/damage another user */
49 Admin_Changemap, /**< Change the map */
50 Admin_Convars, /**< Change basic convars */
51 Admin_Config, /**< Change configuration */
52 Admin_Chat, /**< Special chat privileges */
53 Admin_Vote, /**< Special vote privileges */
54 Admin_Password, /**< Set a server password */
55 Admin_RCON, /**< Use RCON */
56 Admin_Cheats, /**< Change sv_cheats and use its commands */
57 Admin_Root, /**< All access by default */
58 Admin_Custom1, /**< First custom flag type */
59 Admin_Custom2, /**< Second custom flag type */
60 Admin_Custom3, /**< Third custom flag type */
61 Admin_Custom4, /**< Fourth custom flag type */
62 Admin_Custom5, /**< Fifth custom flag type */
63 Admin_Custom6, /**< Sixth custom flag type */
67 #define AdminFlags_TOTAL 21 /**< Total number of admin flags */
70 * @section Bitwise values definitions for admin flags.
72 #define ADMFLAG_RESERVATION (1<<0) /**< Convenience macro for Admin_Reservation as a FlagBit */
73 #define ADMFLAG_GENERIC (1<<1) /**< Convenience macro for Admin_Generic as a FlagBit */
74 #define ADMFLAG_KICK (1<<2) /**< Convenience macro for Admin_Kick as a FlagBit */
75 #define ADMFLAG_BAN (1<<3) /**< Convenience macro for Admin_Ban as a FlagBit */
76 #define ADMFLAG_UNBAN (1<<4) /**< Convenience macro for Admin_Unban as a FlagBit */
77 #define ADMFLAG_SLAY (1<<5) /**< Convenience macro for Admin_Slay as a FlagBit */
78 #define ADMFLAG_CHANGEMAP (1<<6) /**< Convenience macro for Admin_Changemap as a FlagBit */
79 #define ADMFLAG_CONVARS (1<<7) /**< Convenience macro for Admin_Convars as a FlagBit */
80 #define ADMFLAG_CONFIG (1<<8) /**< Convenience macro for Admin_Config as a FlagBit */
81 #define ADMFLAG_CHAT (1<<9) /**< Convenience macro for Admin_Chat as a FlagBit */
82 #define ADMFLAG_VOTE (1<<10) /**< Convenience macro for Admin_Vote as a FlagBit */
83 #define ADMFLAG_PASSWORD (1<<11) /**< Convenience macro for Admin_Password as a FlagBit */
84 #define ADMFLAG_RCON (1<<12) /**< Convenience macro for Admin_RCON as a FlagBit */
85 #define ADMFLAG_CHEATS (1<<13) /**< Convenience macro for Admin_Cheats as a FlagBit */
86 #define ADMFLAG_ROOT (1<<14) /**< Convenience macro for Admin_Root as a FlagBit */
87 #define ADMFLAG_CUSTOM1 (1<<15) /**< Convenience macro for Admin_Custom1 as a FlagBit */
88 #define ADMFLAG_CUSTOM2 (1<<16) /**< Convenience macro for Admin_Custom2 as a FlagBit */
89 #define ADMFLAG_CUSTOM3 (1<<17) /**< Convenience macro for Admin_Custom3 as a FlagBit */
90 #define ADMFLAG_CUSTOM4 (1<<18) /**< Convenience macro for Admin_Custom4 as a FlagBit */
91 #define ADMFLAG_CUSTOM5 (1<<19) /**< Convenience macro for Admin_Custom5 as a FlagBit */
92 #define ADMFLAG_CUSTOM6 (1<<20) /**< Convenience macro for Admin_Custom6 as a FlagBit */
99 * @section Hardcoded authentication methods
101 #define AUTHMETHOD_STEAM "steam" /**< SteamID based authentication */
102 #define AUTHMETHOD_IP "ip" /**< IP based authentication */
103 #define AUTHMETHOD_NAME "name" /**< Name based authentication */
110 * Access override types.
114 Override_Command = 1, /**< Command */
115 Override_CommandGroup, /**< Command group */
119 * Access override rules.
132 Immunity_Default = 1, /**< Immune from everyone with no immunity */
133 Immunity_Global, /**< Immune from everyone (except root admins) */
137 * Identifies a unique entry in the group permissions cache. These are not Handles.
141 INVALID_GROUP_ID = -1, /**< An invalid/nonexistant group */
145 * Identifies a unique entry in the admin permissions cache. These are not Handles.
149 INVALID_ADMIN_ID = -1, /**< An invalid/nonexistant admin */
153 * Methods of computing access permissions.
157 Access_Real, /**< Access the user has inherently */
158 Access_Effective, /**< Access the user has from their groups */
162 * Represents the various cache regions.
166 AdminCache_Overrides = 0, /**< Global overrides */
167 AdminCache_Groups = 1, /**< All groups (automatically invalidates admins too) */
168 AdminCache_Admins = 2, /**< All admins */
172 * Called when part of the cache which needs to be rebuilt.
174 * @param part Part of the admin cache to rebuild.
176 forward OnRebuildAdminCache(AdminCachePart:part);
179 * Tells the admin system to dump a portion of the cache.
181 * @param part Part of the cache to dump. Specifying groups also dumps admins.
182 * @param rebuild If true, the rebuild forwards will fire.
185 native DumpAdminCache(AdminCachePart:part, bool:rebuild);
188 * Adds a global command flag override. Any command registered with this name
189 * will assume the new flag. This is applied retroactively as well.
191 * @param cmd String containing command name (case sensitive).
192 * @param type Override type (specific command or group).
193 * @param flags New admin flag.
196 native AddCommandOverride(const String:cmd[], OverrideType:type, flags);
199 * Returns a command override.
201 * @param cmd String containing command name (case sensitive).
202 * @param type Override type (specific command or group).
203 * @param flags By-reference cell to store the flag (undefined if not found).
204 * @return True if there is an override, false otherwise.
206 native bool:GetCommandOverride(const String:cmd[], OverrideType:type, &flags);
209 * Unsets a command override.
211 * @param cmd String containing command name (case sensitive).
212 * @param type Override type (specific command or group).
215 native UnsetCommandOverride(const String:cmd[], OverrideType:type);
218 * Adds a new group. Name must be unique.
220 * @param group_name String containing the group name.
221 * @return A new group id, INVALID_GROUP_ID if it already exists.
223 native GroupId:CreateAdmGroup(const String:group_name[]);
226 * Finds a group by name.
228 * @param group_name String containing the group name.
229 * @return A group id, or INVALID_GROUP_ID if not found.
231 native GroupId:FindAdmGroup(const String:group_name[]);
234 * Adds or removes a flag from a group's flag set.
235 * @note These are called "add flags" because they add to a user's flags.
237 * @param id Group id.
238 * @param flag Admin flag to toggle.
239 * @param enabled True to set the flag, false to unset/disable.
242 native SetAdmGroupAddFlag(GroupId:id, AdminFlag:flag, bool:enabled);
245 * Gets the set value of an add flag on a group's flag set.
246 * @note These are called "add flags" because they add to a user's flags.
248 * @param id Group id.
249 * @param flag Admin flag to retrieve.
250 * @return True if enabled, false otherwise,
252 native bool:GetAdmGroupAddFlag(GroupId:id, AdminFlag:flag);
255 * Returns the flag set that is added to a user from their group.
256 * @note These are called "add flags" because they add to a user's flags.
258 * @param id GroupId of the group.
259 * @return Bitstring containing the flags enabled.
261 native GetAdmGroupAddFlags(GroupId:id);
264 * Toggles a generic immunity type.
266 * @param id Group id.
267 * @param type Generic immunity type.
268 * @param enabled True to enable, false otherwise.
271 native SetAdmGroupImmunity(GroupId:id, ImmunityType:type, bool:enabled);
274 * Returns whether or not a group has global immunity.
276 * @param id Group id.
277 * @param type Generic immunity type.
278 * @return True if the group has this immunity, false otherwise.
280 native bool:GetAdmGroupImmunity(GroupId:id, ImmunityType:type);
283 * Adds immunity to a specific group.
285 * @param id Group id.
286 * @param other_id Group id to receive immunity to.
289 native SetAdmGroupImmuneFrom(GroupId:id, GroupId:other_id);
292 * Returns the number of specific group immunities.
294 * @param id Group id.
295 * @return Number of group immunities.
297 native GetAdmGroupImmuneCount(GroupId:id);
300 * Returns a group that this group is immune to given an index.
302 * @param id Group id.
303 * @param number Index from 0 to N-1, from GetAdmGroupImmuneCount().
304 * @return GroupId that this group is immune to, or INVALID_GROUP_ID on failure.
306 native GroupId:GetAdmGroupImmuneFrom(GroupId:id, number);
309 * Adds a group-specific override type.
311 * @param id Group id.
312 * @param name String containing command name (case sensitive).
313 * @param type Override type (specific command or group).
314 * @param rule Override allow/deny setting.
317 native AddAdmGroupCmdOverride(GroupId:id, const String:name[], OverrideType:type, OverrideRule:rule);
320 * Retrieves a group-specific command override.
322 * @param id Group id.
323 * @param name String containing command name (case sensitive).
324 * @param type Override type (specific command or group).
325 * @param rule Optional pointer to store allow/deny setting.
326 * @return True if an override exists, false otherwise.
328 native bool:GetAdmGroupCmdOverride(GroupId:id, const String:name[], OverrideType:type, &OverrideRule:rule);
331 * Registers an authentication identity type. You normally never need to call this except for
332 * very specific systems.
334 * @param codename Codename to use for your authentication type.
337 native RegisterAuthIdentType(const String:name[]);
340 * Creates a new admin entry in the permissions cache.
342 * @param name Name for this entry (does not have to be unique).
343 * Specify an empty string for an anonymous admin.
345 native AdminId:CreateAdmin(const String:name[]="");
348 * Retrieves an admin's user name as made with CreateAdmin().
350 * @note This function can return UTF-8 strings, and will safely chop UTF-8 strings.
352 * @param id AdminId of the admin.
353 * @param name String buffer to store name.
354 * @param maxlength Maximum size of string buffer.
355 * @return Number of bytes written.
357 native GetAdminUsername(AdminId:id, const String:name[], maxlength);
360 * Binds an admin to an identity for fast lookup later on. The bind must be unique.
362 * @param id AdminId of the admin.
363 * @param auth Auth method to use, predefined or from RegisterAuthIdentType().
364 * @param ident String containing the arbitrary, unique identity.
365 * @return True on success, false if the auth method was not found,
366 * or ident was already taken.
368 native bool:BindAdminIdentity(AdminId:id, const String:auth[], const String:ident[]);
371 * Sets whether or not a flag is enabled on an admin.
373 * @param id AdminId index of the admin.
374 * @param flag Admin flag to use.
375 * @param enabled True to enable, false to disable.
378 native SetAdminFlag(AdminId:id, AdminFlag:flag, bool:enabled);
381 * Returns whether or not a flag is enabled on an admin.
383 * @param id AdminId index of the admin.
384 * @param flag Admin flag to use.
385 * @param mode Access mode to check.
386 * @return True if enabled, false otherwise.
388 native bool:GetAdminFlag(AdminId:id, AdminFlag:flag, AdmAccessMode:mode=Access_Effective);
391 * Returns the bitstring of access flags on an admin.
393 * @param id AdminId index of the admin.
394 * @param mode Access mode to use.
395 * @return A bitstring containing which flags are enabled.
397 native GetAdminFlags(AdminId:id, AdmAccessMode:mode);
400 * Adds a group to an admin's inherited group list. Any flags the group has
401 * will be added to the admin's effective flags.
403 * @param id AdminId index of the admin.
404 * @param gid GroupId index of the group.
405 * @return True on success, false on invalid input or duplicate membership.
407 native bool:AdminInheritGroup(AdminId:id, GroupId:gid);
410 * Returns the number of groups this admin is a member of.
412 * @param id AdminId index of the admin.
413 * @return Number of groups this admin is a member of.
415 native GetAdminGroupCount(AdminId:id);
418 * Returns group information from an admin.
420 * @param id AdminId index of the admin.
421 * @param index Group number to retrieve, from 0 to N-1, where N
422 * is the value of GetAdminGroupCount(id).
423 * @param name Buffer to store the group's name.
424 * Note: This will safely chop UTF-8 strings.
425 * @param maxlength Maximum size of the output name buffer.
426 * @return A GroupId index and a name pointer, or
427 * INVALID_GROUP_ID and NULL if an error occurred.
429 native GroupId:GetAdminGroup(AdminId:id, index, const String:name[], maxlength);
432 * Sets a password on an admin.
434 * @param id AdminId index of the admin.
435 * @param passwd String containing the password.
438 native SetAdminPassword(AdminId:id, const String:password[]);
441 * Gets an admin's password.
443 * @param id AdminId index of the admin.
444 * @param name Optional buffer to store the admin's password.
445 * @param maxlength Maximum size of the output name buffer.
446 * Note: This will safely chop UTF-8 strings.
447 * @return True if there was a password set, false otherwise.
449 native bool:GetAdminPassword(AdminId:id, const String:buffer[]="", maxlength=0);
452 * Attempts to find an admin by an auth method and an identity.
454 * @param auth Auth method to try.
455 * @param identity Identity string to look up.
456 * @return An AdminId index if found, INVALID_ADMIN_ID otherwise.
458 native AdminId:FindAdminByIdentity(const String:auth[], const String:identity[]);
461 * Removes an admin entry from the cache.
463 * @note This will remove any bindings to a specific user.
465 * @param id AdminId index to remove/invalidate.
466 * @return True on success, false otherwise.
468 native bool:RemoveAdmin(AdminId:id);
471 * Converts a flag bit string to a bit array.
473 * @param bits Bit string containing the flags.
474 * @param array Array to write the flags to. Enabled flags will be 'true'.
475 * @param maxSize Maximum number of flags the array can store.
476 * @return Number of flags written.
478 native FlagBitsToBitArray(bits, bool:array[], maxSize);
481 * Converts a flag array to a bit string.
483 * @param array Array containing true or false for each AdminFlag.
484 * @param maxSize Maximum size of the flag array.
485 * @return A bit string composed of the array bits.
487 native FlagBitArrayToBits(const bool:array[], maxSize);
490 * Converts an array of flags to bits.
492 * @param array Array containing flags that are enabled.
493 * @param numFlags Number of flags in the array.
494 * @return A bit string composed of the array flags.
496 native FlagArrayToBits(const AdminFlag:array[], numFlags);
499 * Converts a bit string to an array of flags.
501 * @param bits Bit string containing the flags.
502 * @param array Output array to write flags.
503 * @param maxSize Maximum size of the flag array.
504 * @return Number of flags written.
506 native FlagBitsToArray(bits, AdminFlag:array[], maxSize);
509 * Finds a flag by its string name.
511 * @param name Flag name (like "kick"), case sensitive.
512 * @param flag Variable to store flag in.
513 * @return True on success, false if not found.
515 native bool:FindFlagByName(const String:name[], &AdminFlag:flag);
518 * Finds a flag by a given character.
520 * @param c Flag ASCII character/token.
521 * @param flag Variable to store flag in.
522 * @return True on success, false if not found.
524 native bool:FindFlagByChar(c, &AdminFlag:flag);
527 * Converts a string of flag characters to a bit string.
529 * @param flags Flag ASCII string.
530 * @param numchars Optional variable to store the number of bytes read.
531 * @return Bit string of ADMFLAG values.
533 native ReadFlagString(const String:flags[], &numchars=0);
536 * Tests whether one admin can target another.
538 * @param admin Admin doing the targetting (may be INVALID_ADMIN_ID).
539 * @param target Target admin (may be INVALID_ADMIN_ID).
540 * @return True if targetable, false if immune.
542 native CanAdminTarget(AdminId:admin, AdminId:target);
545 * Creates an admin auth method. This does not need to be called more than once
548 * @param method Name of the authentication method.
549 * @return True on success, false on failure.
551 native bool:CreateAuthMethod(const String:method[]);
554 * Converts a flag to its single bit.
556 * @param flag Flag to convert.
557 * @return Bit representation of the flag.
559 stock FlagToBit(AdminFlag:flag)
565 * Converts a bit to an AdminFlag.
567 * @param bit Bit to convert.
568 * @param flag Stores the converted flag by reference.
569 * @return True on success, false otherwise.
571 stock bool:BitToFlag(bit, &AdminFlag:flag)
573 new AdminFlag:array[1];
575 if (FlagBitsToArray(bit, array, 1))