Fixed a bug where natives with no owner could be bound (crashing).
Fixed a bug where FakeNative entries were leaked.
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 _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.
128 * DEPRECATED, do not use.
132 Immunity_Default = 1, /**< Deprecated. */
133 Immunity_Global, /**< Deprecated. */
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 * @deprecated Functionality removed.
266 #pragma deprecated Use SetAdmGroupImmunityLevel() instead.
267 native SetAdmGroupImmunity(GroupId:id, ImmunityType:type, bool:enabled);
270 * @deprecated Functionality removed.
272 #pragma deprecated Use GetAdmGroupImmunityLevel() instead.
273 native bool:GetAdmGroupImmunity(GroupId:id, ImmunityType:type);
276 * Adds immunity to a specific group.
278 * @param id Group id.
279 * @param other_id Group id to receive immunity to.
282 native SetAdmGroupImmuneFrom(GroupId:id, GroupId:other_id);
285 * Returns the number of specific group immunities.
287 * @param id Group id.
288 * @return Number of group immunities.
290 native GetAdmGroupImmuneCount(GroupId:id);
293 * Returns a group that this group is immune to given an index.
295 * @param id Group id.
296 * @param number Index from 0 to N-1, from GetAdmGroupImmuneCount().
297 * @return GroupId that this group is immune to, or INVALID_GROUP_ID on failure.
299 native GroupId:GetAdmGroupImmuneFrom(GroupId:id, number);
302 * Adds a group-specific override type.
304 * @param id Group id.
305 * @param name String containing command name (case sensitive).
306 * @param type Override type (specific command or group).
307 * @param rule Override allow/deny setting.
310 native AddAdmGroupCmdOverride(GroupId:id, const String:name[], OverrideType:type, OverrideRule:rule);
313 * Retrieves a group-specific command override.
315 * @param id Group id.
316 * @param name String containing command name (case sensitive).
317 * @param type Override type (specific command or group).
318 * @param rule Optional pointer to store allow/deny setting.
319 * @return True if an override exists, false otherwise.
321 native bool:GetAdmGroupCmdOverride(GroupId:id, const String:name[], OverrideType:type, &OverrideRule:rule);
324 * Registers an authentication identity type. You normally never need to call this except for
325 * very specific systems.
327 * @param codename Codename to use for your authentication type.
330 native RegisterAuthIdentType(const String:name[]);
333 * Creates a new admin entry in the permissions cache.
335 * @param name Name for this entry (does not have to be unique).
336 * Specify an empty string for an anonymous admin.
338 native AdminId:CreateAdmin(const String:name[]="");
341 * Retrieves an admin's user name as made with CreateAdmin().
343 * @note This function can return UTF-8 strings, and will safely chop UTF-8 strings.
345 * @param id AdminId of the admin.
346 * @param name String buffer to store name.
347 * @param maxlength Maximum size of string buffer.
348 * @return Number of bytes written.
350 native GetAdminUsername(AdminId:id, const String:name[], maxlength);
353 * Binds an admin to an identity for fast lookup later on. The bind must be unique.
355 * @param id AdminId of the admin.
356 * @param auth Auth method to use, predefined or from RegisterAuthIdentType().
357 * @param ident String containing the arbitrary, unique identity.
358 * @return True on success, false if the auth method was not found,
359 * or ident was already taken.
361 native bool:BindAdminIdentity(AdminId:id, const String:auth[], const String:ident[]);
364 * Sets whether or not a flag is enabled on an admin.
366 * @param id AdminId index of the admin.
367 * @param flag Admin flag to use.
368 * @param enabled True to enable, false to disable.
371 native SetAdminFlag(AdminId:id, AdminFlag:flag, bool:enabled);
374 * Returns whether or not a flag is enabled on an admin.
376 * @param id AdminId index of the admin.
377 * @param flag Admin flag to use.
378 * @param mode Access mode to check.
379 * @return True if enabled, false otherwise.
381 native bool:GetAdminFlag(AdminId:id, AdminFlag:flag, AdmAccessMode:mode=Access_Effective);
384 * Returns the bitstring of access flags on an admin.
386 * @param id AdminId index of the admin.
387 * @param mode Access mode to use.
388 * @return A bitstring containing which flags are enabled.
390 native GetAdminFlags(AdminId:id, AdmAccessMode:mode);
393 * Adds a group to an admin's inherited group list. Any flags the group has
394 * will be added to the admin's effective flags.
396 * @param id AdminId index of the admin.
397 * @param gid GroupId index of the group.
398 * @return True on success, false on invalid input or duplicate membership.
400 native bool:AdminInheritGroup(AdminId:id, GroupId:gid);
403 * Returns the number of groups this admin is a member of.
405 * @param id AdminId index of the admin.
406 * @return Number of groups this admin is a member of.
408 native GetAdminGroupCount(AdminId:id);
411 * Returns group information from an admin.
413 * @param id AdminId index of the admin.
414 * @param index Group number to retrieve, from 0 to N-1, where N
415 * is the value of GetAdminGroupCount(id).
416 * @param name Buffer to store the group's name.
417 * Note: This will safely chop UTF-8 strings.
418 * @param maxlength Maximum size of the output name buffer.
419 * @return A GroupId index and a name pointer, or
420 * INVALID_GROUP_ID and NULL if an error occurred.
422 native GroupId:GetAdminGroup(AdminId:id, index, const String:name[], maxlength);
425 * Sets a password on an admin.
427 * @param id AdminId index of the admin.
428 * @param passwd String containing the password.
431 native SetAdminPassword(AdminId:id, const String:password[]);
434 * Gets an admin's password.
436 * @param id AdminId index of the admin.
437 * @param name Optional buffer to store the admin's password.
438 * @param maxlength Maximum size of the output name buffer.
439 * Note: This will safely chop UTF-8 strings.
440 * @return True if there was a password set, false otherwise.
442 native bool:GetAdminPassword(AdminId:id, const String:buffer[]="", maxlength=0);
445 * Attempts to find an admin by an auth method and an identity.
447 * @param auth Auth method to try.
448 * @param identity Identity string to look up.
449 * @return An AdminId index if found, INVALID_ADMIN_ID otherwise.
451 native AdminId:FindAdminByIdentity(const String:auth[], const String:identity[]);
454 * Removes an admin entry from the cache.
456 * @note This will remove any bindings to a specific user.
458 * @param id AdminId index to remove/invalidate.
459 * @return True on success, false otherwise.
461 native bool:RemoveAdmin(AdminId:id);
464 * Converts a flag bit string to a bit array.
466 * @param bits Bit string containing the flags.
467 * @param array Array to write the flags to. Enabled flags will be 'true'.
468 * @param maxSize Maximum number of flags the array can store.
469 * @return Number of flags written.
471 native FlagBitsToBitArray(bits, bool:array[], maxSize);
474 * Converts a flag array to a bit string.
476 * @param array Array containing true or false for each AdminFlag.
477 * @param maxSize Maximum size of the flag array.
478 * @return A bit string composed of the array bits.
480 native FlagBitArrayToBits(const bool:array[], maxSize);
483 * Converts an array of flags to bits.
485 * @param array Array containing flags that are enabled.
486 * @param numFlags Number of flags in the array.
487 * @return A bit string composed of the array flags.
489 native FlagArrayToBits(const AdminFlag:array[], numFlags);
492 * Converts a bit string to an array of flags.
494 * @param bits Bit string containing the flags.
495 * @param array Output array to write flags.
496 * @param maxSize Maximum size of the flag array.
497 * @return Number of flags written.
499 native FlagBitsToArray(bits, AdminFlag:array[], maxSize);
502 * Finds a flag by its string name.
504 * @param name Flag name (like "kick"), case sensitive.
505 * @param flag Variable to store flag in.
506 * @return True on success, false if not found.
508 native bool:FindFlagByName(const String:name[], &AdminFlag:flag);
511 * Finds a flag by a given character.
513 * @param c Flag ASCII character/token.
514 * @param flag Variable to store flag in.
515 * @return True on success, false if not found.
517 native bool:FindFlagByChar(c, &AdminFlag:flag);
520 * Converts a string of flag characters to a bit string.
522 * @param flags Flag ASCII string.
523 * @param numchars Optional variable to store the number of bytes read.
524 * @return Bit string of ADMFLAG values.
526 native ReadFlagString(const String:flags[], &numchars=0);
529 * Tests whether one admin can target another.
531 * The hueristics for this check are as follows:
532 * 0. If the targeting AdminId is INVALID_ADMIN_ID, targeting fails.
533 * 1. If the targeted AdminId is INVALID_ADMIN_ID, targeting succeeds.
534 * 2. If the targeted AdminId is the same as the targeting AdminId,
535 * (self) targeting succeeds.
536 * 3. If the targeting admin is root, targeting succeeds.
537 * 4. If the targeted admin has access higher (as interpreted by
538 * (sm_immunity_mode) than the targeting admin, then targeting fails.
539 * 5. If the targeted admin has specific immunity from the
540 * targeting admin via group immunities, targeting fails.
541 * 6. Targeting succeeds.
543 * @param admin Admin doing the targetting (may be INVALID_ADMIN_ID).
544 * @param target Target admin (may be INVALID_ADMIN_ID).
545 * @return True if targetable, false if immune.
547 native CanAdminTarget(AdminId:admin, AdminId:target);
550 * Creates an admin auth method. This does not need to be called more than once
553 * @param method Name of the authentication method.
554 * @return True on success, false on failure.
556 native bool:CreateAuthMethod(const String:method[]);
559 * Sets a group's immunity level.
561 * @param gid Group Id.
562 * @param level Immunity level value.
563 * @return Old immunity level value.
565 native SetAdmGroupImmunityLevel(GroupId:gid, level);
568 * Gets a group's immunity level (defaults to 0).
570 * @param gid Group Id.
571 * @return Immunity level value.
573 native GetAdmGroupImmunityLevel(GroupId:gid);
576 * Sets an admin's immunity level.
578 * @param id Admin Id.
579 * @param level Immunity level value.
580 * @return Old immunity level value.
582 native SetAdminImmunityLevel(AdminId:id, level);
585 * Gets an admin's immunity level.
587 * @param id Admin Id.
588 * @return Immunity level value.
590 native GetAdminImmunityLevel(AdminId:id);
593 * Converts a flag to its single bit.
595 * @param flag Flag to convert.
596 * @return Bit representation of the flag.
598 stock FlagToBit(AdminFlag:flag)
604 * Converts a bit to an AdminFlag.
606 * @param bit Bit to convert.
607 * @param flag Stores the converted flag by reference.
608 * @return True on success, false otherwise.
610 stock bool:BitToFlag(bit, &AdminFlag:flag)
612 new AdminFlag:array[1];
614 if (FlagBitsToArray(bit, array, 1))