plugins/include/admin.inc
changeset 1952 b7aa2b626807
child 2289 44045ead61cd
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/plugins/include/admin.inc	Sun Mar 30 07:00:22 2008 +0000
     1.3 @@ -0,0 +1,622 @@
     1.4 +/**
     1.5 + * vim: set ts=4 :
     1.6 + * =============================================================================
     1.7 + * SourceMod (C)2004-2008 AlliedModders LLC.  All rights reserved.
     1.8 + * =============================================================================
     1.9 + *
    1.10 + * This file is part of the SourceMod/SourcePawn SDK.
    1.11 + *
    1.12 + * This program is free software; you can redistribute it and/or modify it under
    1.13 + * the terms of the GNU General Public License, version 3.0, as published by the
    1.14 + * Free Software Foundation.
    1.15 + * 
    1.16 + * This program is distributed in the hope that it will be useful, but WITHOUT
    1.17 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
    1.18 + * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
    1.19 + * details.
    1.20 + *
    1.21 + * You should have received a copy of the GNU General Public License along with
    1.22 + * this program.  If not, see <http://www.gnu.org/licenses/>.
    1.23 + *
    1.24 + * As a special exception, AlliedModders LLC gives you permission to link the
    1.25 + * code of this program (as well as its derivative works) to "Half-Life 2," the
    1.26 + * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
    1.27 + * by the Valve Corporation.  You must obey the GNU General Public License in
    1.28 + * all respects for all other code used.  Additionally, AlliedModders LLC grants
    1.29 + * this exception to all derivative works.  AlliedModders LLC defines further
    1.30 + * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
    1.31 + * or <http://www.sourcemod.net/license.php>.
    1.32 + *
    1.33 + * Version: $Id$
    1.34 + */
    1.35 + 
    1.36 +#if defined _admin_included
    1.37 + #endinput
    1.38 +#endif
    1.39 +#define _admin_included
    1.40 +
    1.41 +/**
    1.42 + * Access levels (flags) for admins.
    1.43 + */
    1.44 +enum AdminFlag
    1.45 +{
    1.46 +	Admin_Reservation = 0,	/**< Reserved slot */
    1.47 +	Admin_Generic,			/**< Generic admin abilities */
    1.48 +	Admin_Kick,				/**< Kick another user */
    1.49 +	Admin_Ban,				/**< Ban another user */
    1.50 +	Admin_Unban,			/**< Unban another user */
    1.51 +	Admin_Slay,				/**< Slay/kill/damage another user */
    1.52 +	Admin_Changemap,		/**< Change the map */
    1.53 +	Admin_Convars,			/**< Change basic convars */
    1.54 +	Admin_Config,			/**< Change configuration */
    1.55 +	Admin_Chat,				/**< Special chat privileges */
    1.56 +	Admin_Vote,				/**< Special vote privileges */
    1.57 +	Admin_Password,			/**< Set a server password */
    1.58 +	Admin_RCON,				/**< Use RCON */
    1.59 +	Admin_Cheats,			/**< Change sv_cheats and use its commands */
    1.60 +	Admin_Root,				/**< All access by default */
    1.61 +	Admin_Custom1,			/**< First custom flag type */
    1.62 +	Admin_Custom2,			/**< Second custom flag type */
    1.63 +	Admin_Custom3,			/**< Third custom flag type */
    1.64 +	Admin_Custom4,			/**< Fourth custom flag type */
    1.65 +	Admin_Custom5,			/**< Fifth custom flag type */
    1.66 +	Admin_Custom6,			/**< Sixth custom flag type */
    1.67 +	/* --- */
    1.68 +};
    1.69 +
    1.70 +#define AdminFlags_TOTAL	21		/**< Total number of admin flags */
    1.71 +
    1.72 +/**
    1.73 + * @section Bitwise values definitions for admin flags.
    1.74 + */
    1.75 +#define ADMFLAG_RESERVATION			(1<<0)		/**< Convenience macro for Admin_Reservation as a FlagBit */
    1.76 +#define ADMFLAG_GENERIC				(1<<1)		/**< Convenience macro for Admin_Generic as a FlagBit */
    1.77 +#define ADMFLAG_KICK				(1<<2)		/**< Convenience macro for Admin_Kick as a FlagBit */
    1.78 +#define ADMFLAG_BAN					(1<<3)		/**< Convenience macro for Admin_Ban as a FlagBit */
    1.79 +#define ADMFLAG_UNBAN				(1<<4)		/**< Convenience macro for Admin_Unban as a FlagBit */
    1.80 +#define ADMFLAG_SLAY				(1<<5)		/**< Convenience macro for Admin_Slay as a FlagBit */
    1.81 +#define ADMFLAG_CHANGEMAP			(1<<6)		/**< Convenience macro for Admin_Changemap as a FlagBit */
    1.82 +#define ADMFLAG_CONVARS				(1<<7)		/**< Convenience macro for Admin_Convars as a FlagBit */
    1.83 +#define ADMFLAG_CONFIG				(1<<8)		/**< Convenience macro for Admin_Config as a FlagBit */
    1.84 +#define ADMFLAG_CHAT				(1<<9)		/**< Convenience macro for Admin_Chat as a FlagBit */
    1.85 +#define ADMFLAG_VOTE				(1<<10)		/**< Convenience macro for Admin_Vote as a FlagBit */
    1.86 +#define ADMFLAG_PASSWORD			(1<<11)		/**< Convenience macro for Admin_Password as a FlagBit */
    1.87 +#define ADMFLAG_RCON				(1<<12)		/**< Convenience macro for Admin_RCON as a FlagBit */
    1.88 +#define ADMFLAG_CHEATS				(1<<13)		/**< Convenience macro for Admin_Cheats as a FlagBit */
    1.89 +#define ADMFLAG_ROOT				(1<<14)		/**< Convenience macro for Admin_Root as a FlagBit */
    1.90 +#define ADMFLAG_CUSTOM1				(1<<15)		/**< Convenience macro for Admin_Custom1 as a FlagBit */
    1.91 +#define ADMFLAG_CUSTOM2				(1<<16)		/**< Convenience macro for Admin_Custom2 as a FlagBit */
    1.92 +#define ADMFLAG_CUSTOM3				(1<<17)		/**< Convenience macro for Admin_Custom3 as a FlagBit */
    1.93 +#define ADMFLAG_CUSTOM4				(1<<18)		/**< Convenience macro for Admin_Custom4 as a FlagBit */
    1.94 +#define ADMFLAG_CUSTOM5				(1<<19)		/**< Convenience macro for Admin_Custom5 as a FlagBit */
    1.95 +#define ADMFLAG_CUSTOM6				(1<<20)		/**< Convenience macro for Admin_Custom6 as a FlagBit */
    1.96 +
    1.97 +/**
    1.98 + * @endsection
    1.99 + */
   1.100 +
   1.101 +/**
   1.102 + * @section Hardcoded authentication methods 
   1.103 + */
   1.104 +#define AUTHMETHOD_STEAM			"steam"		/**< SteamID based authentication */
   1.105 +#define AUTHMETHOD_IP				"ip"		/**< IP based authentication */
   1.106 +#define AUTHMETHOD_NAME				"name"		/**< Name based authentication */
   1.107 +
   1.108 +/**
   1.109 + * @endsection
   1.110 + */
   1.111 +
   1.112 +/**
   1.113 + * Access override types.
   1.114 + */
   1.115 +enum OverrideType
   1.116 +{
   1.117 +	Override_Command = 1,	/**< Command */
   1.118 +	Override_CommandGroup,	/**< Command group */
   1.119 +};
   1.120 +
   1.121 +/**
   1.122 + * Access override rules.
   1.123 + */
   1.124 +enum OverrideRule
   1.125 +{
   1.126 +	Command_Deny = 0,
   1.127 +	Command_Allow = 1,
   1.128 +};
   1.129 +
   1.130 +/**
   1.131 + * DEPRECATED, do not use.
   1.132 + */
   1.133 +enum ImmunityType
   1.134 +{
   1.135 +	Immunity_Default = 1,	/**< Deprecated. */
   1.136 +	Immunity_Global,		/**< Deprecated. */
   1.137 +};
   1.138 +
   1.139 +/** 
   1.140 + * Identifies a unique entry in the group permissions cache.  These are not Handles.
   1.141 + */
   1.142 +enum GroupId
   1.143 +{
   1.144 +	INVALID_GROUP_ID = -1,	/**< An invalid/nonexistant group */
   1.145 +};
   1.146 +
   1.147 +/** 
   1.148 + * Identifies a unique entry in the admin permissions cache.  These are not Handles.
   1.149 + */
   1.150 +enum AdminId
   1.151 +{
   1.152 +	INVALID_ADMIN_ID = -1,	/**< An invalid/nonexistant admin */
   1.153 +};
   1.154 +
   1.155 +/**
   1.156 + * Methods of computing access permissions.
   1.157 + */
   1.158 +enum AdmAccessMode
   1.159 +{
   1.160 +	Access_Real,		/**< Access the user has inherently */
   1.161 +	Access_Effective,	/**< Access the user has from their groups */
   1.162 +};
   1.163 +
   1.164 +/**
   1.165 + * Represents the various cache regions.
   1.166 + */
   1.167 +enum AdminCachePart
   1.168 +{
   1.169 +	AdminCache_Overrides = 0,		/**< Global overrides */
   1.170 +	AdminCache_Groups = 1,			/**< All groups (automatically invalidates admins too) */
   1.171 +	AdminCache_Admins = 2,			/**< All admins */
   1.172 +};
   1.173 +
   1.174 +/**
   1.175 + * Called when part of the cache which needs to be rebuilt.
   1.176 + *
   1.177 + * @param part			Part of the admin cache to rebuild.
   1.178 + */
   1.179 +forward OnRebuildAdminCache(AdminCachePart:part);
   1.180 +
   1.181 +/**
   1.182 + * Tells the admin system to dump a portion of the cache.
   1.183 + *
   1.184 + * @param part			Part of the cache to dump.  Specifying groups also dumps admins.
   1.185 + * @param rebuild		If true, the rebuild forwards will fire.
   1.186 + * @noreturn
   1.187 + */
   1.188 +native DumpAdminCache(AdminCachePart:part, bool:rebuild);
   1.189 +
   1.190 +/**
   1.191 + * Adds a global command flag override.  Any command registered with this name
   1.192 + * will assume the new flag.  This is applied retroactively as well.
   1.193 + *
   1.194 + * @param cmd			String containing command name (case sensitive).
   1.195 + * @param type			Override type (specific command or group).
   1.196 + * @param flags			New admin flag.
   1.197 + * @noreturn
   1.198 + */
   1.199 +native AddCommandOverride(const String:cmd[], OverrideType:type, flags);
   1.200 +
   1.201 +/**
   1.202 + * Returns a command override.
   1.203 + *
   1.204 + * @param cmd			String containing command name (case sensitive).
   1.205 + * @param type			Override type (specific command or group).
   1.206 + * @param flags			By-reference cell to store the flag (undefined if not found).
   1.207 + * @return				True if there is an override, false otherwise.
   1.208 + */
   1.209 +native bool:GetCommandOverride(const String:cmd[], OverrideType:type, &flags);
   1.210 +
   1.211 +/**
   1.212 + * Unsets a command override.
   1.213 + *
   1.214 + * @param cmd			String containing command name (case sensitive).
   1.215 + * @param type			Override type (specific command or group).
   1.216 + * @noreturn
   1.217 + */
   1.218 +native UnsetCommandOverride(const String:cmd[], OverrideType:type);
   1.219 +
   1.220 +/**
   1.221 + * Adds a new group.  Name must be unique.
   1.222 + *
   1.223 + * @param group_name	String containing the group name.
   1.224 + * @return				A new group id, INVALID_GROUP_ID if it already exists.
   1.225 + */
   1.226 +native GroupId:CreateAdmGroup(const String:group_name[]);
   1.227 +
   1.228 +/**
   1.229 + * Finds a group by name.
   1.230 + *
   1.231 + * @param group_name	String containing the group name.
   1.232 + * @return				A group id, or INVALID_GROUP_ID if not found.
   1.233 + */
   1.234 +native GroupId:FindAdmGroup(const String:group_name[]);
   1.235 +
   1.236 +/**
   1.237 + * Adds or removes a flag from a group's flag set.
   1.238 + * @note These are called "add flags" because they add to a user's flags.
   1.239 + *
   1.240 + * @param id			Group id.
   1.241 + * @param flag			Admin flag to toggle.
   1.242 + * @param enabled		True to set the flag, false to unset/disable.
   1.243 + * @noreturn
   1.244 + */
   1.245 +native SetAdmGroupAddFlag(GroupId:id, AdminFlag:flag, bool:enabled);
   1.246 +
   1.247 +/**
   1.248 + * Gets the set value of an add flag on a group's flag set.
   1.249 + * @note These are called "add flags" because they add to a user's flags.
   1.250 + *
   1.251 + * @param id			Group id.
   1.252 + * @param flag			Admin flag to retrieve.
   1.253 + * @return				True if enabled, false otherwise,
   1.254 + */
   1.255 +native bool:GetAdmGroupAddFlag(GroupId:id, AdminFlag:flag);
   1.256 +
   1.257 +/**
   1.258 + * Returns the flag set that is added to a user from their group.
   1.259 + * @note These are called "add flags" because they add to a user's flags.
   1.260 + *
   1.261 + * @param id			GroupId of the group.
   1.262 + * @return				Bitstring containing the flags enabled.
   1.263 + */
   1.264 +native GetAdmGroupAddFlags(GroupId:id);
   1.265 +
   1.266 +/**
   1.267 + * @deprecated			Functionality removed.
   1.268 + */
   1.269 +#pragma deprecated Use SetAdmGroupImmunityLevel() instead.
   1.270 +native SetAdmGroupImmunity(GroupId:id, ImmunityType:type, bool:enabled);
   1.271 +
   1.272 +/**
   1.273 + * @deprecated			Functionality removed.
   1.274 + */
   1.275 +#pragma deprecated Use GetAdmGroupImmunityLevel() instead.
   1.276 +native bool:GetAdmGroupImmunity(GroupId:id, ImmunityType:type);
   1.277 +
   1.278 +/**
   1.279 + * Adds immunity to a specific group.
   1.280 + *
   1.281 + * @param id			Group id.
   1.282 + * @param other_id		Group id to receive immunity to.
   1.283 + * @noreturn
   1.284 + */
   1.285 +native SetAdmGroupImmuneFrom(GroupId:id, GroupId:other_id);
   1.286 +
   1.287 +/**
   1.288 + * Returns the number of specific group immunities.
   1.289 + *
   1.290 + * @param id			Group id.
   1.291 + * @return				Number of group immunities.
   1.292 + */
   1.293 +native GetAdmGroupImmuneCount(GroupId:id);
   1.294 +
   1.295 +/**
   1.296 + * Returns a group that this group is immune to given an index.
   1.297 + *
   1.298 + * @param id			Group id.
   1.299 + * @param number		Index from 0 to N-1, from GetAdmGroupImmuneCount().
   1.300 + * @return				GroupId that this group is immune to, or INVALID_GROUP_ID on failure.
   1.301 + */
   1.302 +native GroupId:GetAdmGroupImmuneFrom(GroupId:id, number); 
   1.303 +
   1.304 +/**
   1.305 + * Adds a group-specific override type.
   1.306 + *
   1.307 + * @param id			Group id.
   1.308 + * @param name			String containing command name (case sensitive).
   1.309 + * @param type			Override type (specific command or group).
   1.310 + * @param rule			Override allow/deny setting.
   1.311 + * @noreturn
   1.312 + */
   1.313 +native AddAdmGroupCmdOverride(GroupId:id, const String:name[], OverrideType:type, OverrideRule:rule);
   1.314 +
   1.315 +/**
   1.316 + * Retrieves a group-specific command override.
   1.317 + *
   1.318 + * @param id			Group id.
   1.319 + * @param name			String containing command name (case sensitive).
   1.320 + * @param type			Override type (specific command or group).
   1.321 + * @param rule			Optional pointer to store allow/deny setting.
   1.322 + * @return				True if an override exists, false otherwise.
   1.323 + */
   1.324 +native bool:GetAdmGroupCmdOverride(GroupId:id, const String:name[], OverrideType:type, &OverrideRule:rule);
   1.325 +
   1.326 +/**
   1.327 + * Registers an authentication identity type.  You normally never need to call this except for 
   1.328 + * very specific systems.
   1.329 + *
   1.330 + * @param codename		Codename to use for your authentication type.
   1.331 + * @noreturn
   1.332 + */
   1.333 +native RegisterAuthIdentType(const String:name[]);
   1.334 +
   1.335 +/**
   1.336 + * Creates a new admin entry in the permissions cache.
   1.337 + *
   1.338 + * @param name			Name for this entry (does not have to be unique).
   1.339 + * 						Specify an empty string for an anonymous admin.
   1.340 + */
   1.341 +native AdminId:CreateAdmin(const String:name[]="");
   1.342 +
   1.343 +/**
   1.344 + * Retrieves an admin's user name as made with CreateAdmin().
   1.345 + *
   1.346 + * @note This function can return UTF-8 strings, and will safely chop UTF-8 strings.
   1.347 + *
   1.348 + * @param id			AdminId of the admin.
   1.349 + * @param name			String buffer to store name.
   1.350 + * @param maxlength		Maximum size of string buffer.
   1.351 + * @return				Number of bytes written.
   1.352 + */
   1.353 +native GetAdminUsername(AdminId:id, const String:name[], maxlength);
   1.354 +
   1.355 +/**
   1.356 + * Binds an admin to an identity for fast lookup later on.  The bind must be unique.
   1.357 + *
   1.358 + * @param id			AdminId of the admin.
   1.359 + * @param auth			Auth method to use, predefined or from RegisterAuthIdentType().
   1.360 + * @param ident			String containing the arbitrary, unique identity.
   1.361 + * @return				True on success, false if the auth method was not found,
   1.362 + *						or ident was already taken.
   1.363 + */
   1.364 +native bool:BindAdminIdentity(AdminId:id, const String:auth[], const String:ident[]);
   1.365 +
   1.366 +/**
   1.367 + * Sets whether or not a flag is enabled on an admin.
   1.368 + *
   1.369 + * @param id			AdminId index of the admin.
   1.370 + * @param flag			Admin flag to use.
   1.371 + * @param enabled		True to enable, false to disable.
   1.372 + * @noreturn
   1.373 + */
   1.374 +native SetAdminFlag(AdminId:id, AdminFlag:flag, bool:enabled);
   1.375 +
   1.376 +/**
   1.377 + * Returns whether or not a flag is enabled on an admin.
   1.378 + *
   1.379 + * @param id			AdminId index of the admin.
   1.380 + * @param flag			Admin flag to use.
   1.381 + * @param mode			Access mode to check.
   1.382 + * @return				True if enabled, false otherwise.
   1.383 + */
   1.384 +native bool:GetAdminFlag(AdminId:id, AdminFlag:flag, AdmAccessMode:mode=Access_Effective);
   1.385 +
   1.386 +/**
   1.387 + * Returns the bitstring of access flags on an admin.
   1.388 + *
   1.389 + * @param id			AdminId index of the admin.
   1.390 + * @param mode			Access mode to use.
   1.391 + * @return				A bitstring containing which flags are enabled.
   1.392 + */
   1.393 +native GetAdminFlags(AdminId:id, AdmAccessMode:mode);
   1.394 +
   1.395 +/**
   1.396 + * Adds a group to an admin's inherited group list.  Any flags the group has 
   1.397 + * will be added to the admin's effective flags.
   1.398 + *
   1.399 + * @param id			AdminId index of the admin.
   1.400 + * @param gid			GroupId index of the group.
   1.401 + * @return				True on success, false on invalid input or duplicate membership.
   1.402 + */
   1.403 +native bool:AdminInheritGroup(AdminId:id, GroupId:gid);
   1.404 +
   1.405 +/**
   1.406 + * Returns the number of groups this admin is a member of.
   1.407 + * 
   1.408 + * @param id			AdminId index of the admin.
   1.409 + * @return				Number of groups this admin is a member of.
   1.410 + */
   1.411 +native GetAdminGroupCount(AdminId:id);
   1.412 +
   1.413 +/**
   1.414 + * Returns group information from an admin.
   1.415 + *
   1.416 + * @param id        	AdminId index of the admin.
   1.417 + * @param index			Group number to retrieve, from 0 to N-1, where N
   1.418 + *						is the value of GetAdminGroupCount(id).
   1.419 + * @param name			Buffer to store the group's name.
   1.420 + *						Note: This will safely chop UTF-8 strings.
   1.421 + * @param maxlength		Maximum size of the output name buffer.
   1.422 + * @return				A GroupId index and a name pointer, or
   1.423 + *						INVALID_GROUP_ID and NULL if an error occurred.
   1.424 +*/
   1.425 +native GroupId:GetAdminGroup(AdminId:id, index, const String:name[], maxlength);
   1.426 +
   1.427 +/**
   1.428 + * Sets a password on an admin.
   1.429 + *
   1.430 + * @param id			AdminId index of the admin.
   1.431 + * @param passwd		String containing the password.
   1.432 + * @noreturn
   1.433 + */
   1.434 +native SetAdminPassword(AdminId:id, const String:password[]);
   1.435 +
   1.436 +/**
   1.437 + * Gets an admin's password.
   1.438 + *
   1.439 + * @param id			AdminId index of the admin.
   1.440 + * @param name			Optional buffer to store the admin's password.
   1.441 + * @param maxlength		Maximum size of the output name buffer.
   1.442 + *						Note: This will safely chop UTF-8 strings.
   1.443 + * @return				True if there was a password set, false otherwise.
   1.444 + */
   1.445 +native bool:GetAdminPassword(AdminId:id, const String:buffer[]="", maxlength=0);
   1.446 +
   1.447 +/**
   1.448 + * Attempts to find an admin by an auth method and an identity.
   1.449 + *
   1.450 + * @param auth			Auth method to try.
   1.451 + * @param identity		Identity string to look up.
   1.452 + * @return				An AdminId index if found, INVALID_ADMIN_ID otherwise.
   1.453 + */
   1.454 +native AdminId:FindAdminByIdentity(const String:auth[], const String:identity[]);
   1.455 +
   1.456 +/**
   1.457 + * Removes an admin entry from the cache.
   1.458 + *
   1.459 + * @note This will remove any bindings to a specific user.
   1.460 + *
   1.461 + * @param id			AdminId index to remove/invalidate.
   1.462 + * @return				True on success, false otherwise.
   1.463 + */
   1.464 +native bool:RemoveAdmin(AdminId:id);
   1.465 +
   1.466 +/**
   1.467 + * Converts a flag bit string to a bit array.
   1.468 + *
   1.469 + * @param bits			Bit string containing the flags.
   1.470 + * @param array			Array to write the flags to.  Enabled flags will be 'true'.
   1.471 + * @param maxSize		Maximum number of flags the array can store.
   1.472 + * @return				Number of flags written.
   1.473 + */
   1.474 +native FlagBitsToBitArray(bits, bool:array[], maxSize);
   1.475 +
   1.476 +/**
   1.477 + * Converts a flag array to a bit string.
   1.478 + *
   1.479 + * @param array			Array containing true or false for each AdminFlag.
   1.480 + * @param maxSize		Maximum size of the flag array.
   1.481 + * @return				A bit string composed of the array bits.
   1.482 + */
   1.483 +native FlagBitArrayToBits(const bool:array[], maxSize);
   1.484 +
   1.485 +/**
   1.486 + * Converts an array of flags to bits.
   1.487 + *
   1.488 + * @param array			Array containing flags that are enabled.
   1.489 + * @param numFlags		Number of flags in the array.
   1.490 + * @return				A bit string composed of the array flags.
   1.491 + */
   1.492 +native FlagArrayToBits(const AdminFlag:array[], numFlags);
   1.493 +
   1.494 +/**
   1.495 + * Converts a bit string to an array of flags.
   1.496 + *
   1.497 + * @param bits			Bit string containing the flags.
   1.498 + * @param array			Output array to write flags.
   1.499 + * @param maxSize		Maximum size of the flag array.
   1.500 + * @return				Number of flags written.
   1.501 + */
   1.502 +native FlagBitsToArray(bits, AdminFlag:array[], maxSize);
   1.503 +
   1.504 +/**
   1.505 + * Finds a flag by its string name.
   1.506 + *
   1.507 + * @param name			Flag name (like "kick"), case sensitive.
   1.508 + * @param flag			Variable to store flag in.
   1.509 + * @return				True on success, false if not found.
   1.510 + */
   1.511 +native bool:FindFlagByName(const String:name[], &AdminFlag:flag);
   1.512 +
   1.513 +/**
   1.514 + * Finds a flag by a given character.
   1.515 + *
   1.516 + * @param c				Flag ASCII character/token.
   1.517 + * @param flag			Variable to store flag in.
   1.518 + * @return				True on success, false if not found.
   1.519 + */
   1.520 +native bool:FindFlagByChar(c, &AdminFlag:flag);
   1.521 +
   1.522 +/**
   1.523 + * Converts a string of flag characters to a bit string.
   1.524 + *
   1.525 + * @param flags			Flag ASCII string.
   1.526 + * @param numchars		Optional variable to store the number of bytes read.
   1.527 + * @return				Bit string of ADMFLAG values.
   1.528 + */
   1.529 +native ReadFlagString(const String:flags[], &numchars=0);
   1.530 +
   1.531 +/**
   1.532 + * Tests whether one admin can target another.
   1.533 + *
   1.534 + * The hueristics for this check are as follows:
   1.535 + * 0. If the targeting AdminId is INVALID_ADMIN_ID, targeting fails.
   1.536 + * 1. If the targeted AdminId is INVALID_ADMIN_ID, targeting succeeds.
   1.537 + * 2. If the targeted AdminId is the same as the targeting AdminId,
   1.538 + *    (self) targeting succeeds.
   1.539 + * 3. If the targeting admin is root, targeting succeeds.
   1.540 + * 4. If the targeted admin has access higher (as interpreted by 
   1.541 + *    (sm_immunity_mode) than the targeting admin, then targeting fails.
   1.542 + * 5. If the targeted admin has specific immunity from the
   1.543 + *    targeting admin via group immunities, targeting fails.
   1.544 + * 6. Targeting succeeds.
   1.545 + *
   1.546 + * @param admin			Admin doing the targetting (may be INVALID_ADMIN_ID).
   1.547 + * @param target		Target admin (may be INVALID_ADMIN_ID).
   1.548 + * @return				True if targetable, false if immune.
   1.549 + */
   1.550 +native CanAdminTarget(AdminId:admin, AdminId:target);
   1.551 +
   1.552 +/**
   1.553 + * Creates an admin auth method.  This does not need to be called more than once
   1.554 + * per method, ever.
   1.555 + *
   1.556 + * @param method		Name of the authentication method.
   1.557 + * @return				True on success, false on failure.
   1.558 + */
   1.559 +native bool:CreateAuthMethod(const String:method[]);
   1.560 +
   1.561 +/**
   1.562 + * Sets a group's immunity level.
   1.563 + *
   1.564 + * @param gid			Group Id.
   1.565 + * @param level			Immunity level value.
   1.566 + * @return				Old immunity level value.
   1.567 + */
   1.568 +native SetAdmGroupImmunityLevel(GroupId:gid, level);
   1.569 +
   1.570 +/**
   1.571 + * Gets a group's immunity level (defaults to 0).
   1.572 + *
   1.573 + * @param gid			Group Id.
   1.574 + * @return				Immunity level value.
   1.575 + */
   1.576 +native GetAdmGroupImmunityLevel(GroupId:gid);
   1.577 +
   1.578 +/**
   1.579 + * Sets an admin's immunity level.
   1.580 + *
   1.581 + * @param id			Admin Id.
   1.582 + * @param level			Immunity level value.
   1.583 + * @return				Old immunity level value.
   1.584 + */
   1.585 +native SetAdminImmunityLevel(AdminId:id, level);
   1.586 +
   1.587 +/**
   1.588 + * Gets an admin's immunity level.
   1.589 + *
   1.590 + * @param id			Admin Id.
   1.591 + * @return				Immunity level value.
   1.592 + */
   1.593 +native GetAdminImmunityLevel(AdminId:id);
   1.594 +
   1.595 +/**
   1.596 + * Converts a flag to its single bit.
   1.597 + * 
   1.598 + * @param flag			Flag to convert.
   1.599 + * @return				Bit representation of the flag.
   1.600 + */
   1.601 +stock FlagToBit(AdminFlag:flag)
   1.602 +{
   1.603 +	return (1<<_:flag);
   1.604 +}
   1.605 +
   1.606 +/**
   1.607 + * Converts a bit to an AdminFlag.
   1.608 + *
   1.609 + * @param bit			Bit to convert.
   1.610 + * @param flag			Stores the converted flag by reference.
   1.611 + * @return				True on success, false otherwise.
   1.612 + */
   1.613 +stock bool:BitToFlag(bit, &AdminFlag:flag)
   1.614 +{
   1.615 +	new AdminFlag:array[1];
   1.616 +	
   1.617 +	if (FlagBitsToArray(bit, array, 1))
   1.618 +	{
   1.619 +		flag = array[0];
   1.620 +		return true;
   1.621 +	}
   1.622 +	
   1.623 +	return false;
   1.624 +}
   1.625 +