1.1 --- a/plugins/include/admin.inc Mon Feb 05 20:32:34 2007 +0000
1.2 +++ b/plugins/include/admin.inc Tue Feb 06 01:14:32 2007 +0000
1.3 @@ -72,15 +72,9 @@
1.4 #define ADMFLAG_CUSTOM5 (1<<19) /**< Convenience macro for Admin_Custom5 as a FlagBit */
1.5 #define ADMFLAG_CUSTOM6 (1<<20) /**< Convenience macro for Admin_Custom6 as a FlagBit */
1.6
1.7 -stock FlagToBit(AdminFlag:flag)
1.8 -{
1.9 - return (1<<_:flag);
1.10 -}
1.11 -
1.12 -stock AdminFlag:BitToFlag(bit)
1.13 -{
1.14 - /* :TODO: implement */
1.15 -}
1.16 +#define AUTHMETHOD_STEAM "steam"
1.17 +#define AUTHMETHOD_IP "ip"
1.18 +#define AUTHMETHOD_NAME "name"
1.19
1.20 enum OverrideType
1.21 {
1.22 @@ -100,18 +94,25 @@
1.23 Immunity_Global, /* Immune from everyone (except root admins) */
1.24 };
1.25
1.26 -/** Note: Groups are not Handles, nor are they indexes */
1.27 +/** Identifies a unique entry in the group permissions cache. These are not Handles. */
1.28 enum GroupId
1.29 {
1.30 INVALID_GROUP_ID = -1,
1.31 };
1.32
1.33 -/** Note: These are not Handles */
1.34 +/** Identifies a unique entry in the admin permissions cache. These are not Handles. */
1.35 enum AdminId
1.36 {
1.37 INVALID_ADMIN_ID = -1,
1.38 };
1.39
1.40 +/** Defines user access modes. */
1.41 +enum AdmAccessMode
1.42 +{
1.43 + Access_Real, /**< Access the user has inherently */
1.44 + Access_Effective, /**< Access the user has from their groups */
1.45 +};
1.46 +
1.47 #define ADMIN_CACHE_OVERRIDES (1<<0)
1.48 #define ADMIN_CACHE_ADMINS (1<<1)
1.49 #define ADMIN_CACHE_GROUPS ((1<<2)|ADMIN_CACHE_ADMINS)
1.50 @@ -275,3 +276,200 @@
1.51 * @return True if an override exists, false otherwise.
1.52 */
1.53 native bool:GetAdmGroupCmdOverride(GroupId:id, const String:name[], OverrideType:type, &OverrideRule:rule);
1.54 +
1.55 +/**
1.56 + * Registers an authentication identity type. You normally never need to call this except for
1.57 + * very specific systems.
1.58 + *
1.59 + * @param codename Codename to use for your authentication type.
1.60 + * @noreturn
1.61 + */
1.62 +native RegisterAuthIdentType(const String:name[]);
1.63 +
1.64 +/**
1.65 + * Creates a new admin entry in the permissions cache.
1.66 + *
1.67 + * @param name Name for this entry (does not have to be unique).
1.68 + * Specify an empty string for an anonymous admin.
1.69 + */
1.70 +native AdminId:CreateAdmin(const String:name[]="");
1.71 +
1.72 +/**
1.73 + * Retrieves an admin's user name as made with CreateAdmin().
1.74 + *
1.75 + * NOTE: This function can return UTF-8 strings, and will safely chop UTF-8 strings.
1.76 + *
1.77 + * @param id AdminId of the admin.
1.78 + * @param name String buffer to store name.
1.79 + * @param maxlength Maximum size of string buffer.
1.80 + * @return Number of bytes written.
1.81 + */
1.82 +native GetAdminUsername(AdminId:id, const String:name[], maxlength);
1.83 +
1.84 +/**
1.85 + * Binds an admin to an identity for fast lookup later on. The bind must be unique.
1.86 + *
1.87 + * @param id AdminId of the admin.
1.88 + * @param auth Auth method to use, predefined or from RegisterAuthIdentType().
1.89 + * @param ident String containing the arbitrary, unique identity.
1.90 + * @return True on success, false if the auth method was not found,
1.91 + * or ident was already taken.
1.92 + */
1.93 +native bool:BindAdminIdentity(AdminId:id, const String:auth[], const String:ident[]);
1.94 +
1.95 +/**
1.96 + * Sets whether or not a flag is enabled on an admin.
1.97 + *
1.98 + * @param id AdminId index of the admin.
1.99 + * @param flag Admin flag to use.
1.100 + * @param enabled True to enable, false to disable.
1.101 + * @noreturn
1.102 + */
1.103 +native SetAdminFlag(AdminId:id, AdminFlag:flag, bool:enabled);
1.104 +
1.105 +/**
1.106 + * Returns whether or not a flag is enabled on an admin.
1.107 + *
1.108 + * @param id AdminId index of the admin.
1.109 + * @param flag Admin flag to use.
1.110 + * @param mode Access mode to check.
1.111 + * @return True if enabled, false otherwise.
1.112 + */
1.113 +native bool:GetAdminFlag(AdminId:id, AdminFlag:flag, AdmAccessMode:mode);
1.114 +
1.115 +/**
1.116 + * Returns the bitstring of access flags on an admin.
1.117 + *
1.118 + * @param id AdminId index of the admin.
1.119 + * @param mode Access mode to use.
1.120 + * @return A bitstring containing which flags are enabled.
1.121 + */
1.122 +native GetAdminFlags(AdminId:id, AdmAccessMode:mode);
1.123 +
1.124 +/**
1.125 + * Adds a group to an admin's inherited group list. Any flags the group has
1.126 + * will be added to the admin's effective flags.
1.127 + *
1.128 + * @param id AdminId index of the admin.
1.129 + * @param gid GroupId index of the group.
1.130 + * @return True on success, false on invalid input or duplicate membership.
1.131 + */
1.132 +native bool:AdminInheritGroup(AdminId:id, GroupId:gid);
1.133 +
1.134 +/**
1.135 + * Returns the number of groups this admin is a member of.
1.136 + *
1.137 + * @param id AdminId index of the admin.
1.138 + * @return Number of groups this admin is a member of.
1.139 + */
1.140 +native GetAdminGroupCount(AdminId:id);
1.141 +
1.142 +/**
1.143 + * Returns group information from an admin.
1.144 + *
1.145 + * @param id AdminId index of the admin.
1.146 + * @param index Group number to retrieve, from 0 to N-1, where N
1.147 + * is the value of GetAdminGroupCount(id).
1.148 + * @param name Buffer to store the group's name.
1.149 + * Note: This will safely chop UTF-8 strings.
1.150 + * @param maxlength Maximum size of the output name buffer.
1.151 + * @return A GroupId index and a name pointer, or
1.152 + * INVALID_GROUP_ID and NULL if an error occurred.
1.153 +*/
1.154 +native GroupId:GetAdminGroup(AdminId:id, index, const String:name[], maxlength) =0;
1.155 +
1.156 +/**
1.157 + * Sets a password on an admin.
1.158 + *
1.159 + * @param id AdminId index of the admin.
1.160 + * @param passwd String containing the password.
1.161 + * @noreturn
1.162 + */
1.163 +native SetAdminPassword(AdminId:id, const String:password[]);
1.164 +
1.165 +/**
1.166 + * Gets an admin's password.
1.167 + *
1.168 + * @param id AdminId index of the admin.
1.169 + * @param name Optional buffer to store the admin's password.
1.170 + * @param maxlength Maximum size of the output name buffer.
1.171 + * Note: This will safely chop UTF-8 strings.
1.172 + * @return True if there was a password set, false otherwise.
1.173 + */
1.174 +native bool:GetAdminPassword(AdminId:id, const String:buffer[]="", maxlength=0);
1.175 +
1.176 +/**
1.177 + * Attempts to find an admin by an auth method and an identity.
1.178 + *
1.179 + * @param auth Auth method to try.
1.180 + * @param identity Identity string to look up.
1.181 + * @return An AdminId index if found, INVALID_ADMIN_ID otherwise.
1.182 + */
1.183 +native AdminId:FindAdminByIdentity(const String:auth[], const String:identity[]);
1.184 +
1.185 +/**
1.186 + * Removes an admin entry from the cache.
1.187 + *
1.188 + * Note: This will remove any bindings to a specific user.
1.189 + *
1.190 + * @param id AdminId index to remove/invalidate.
1.191 + * @return True on success, false otherwise.
1.192 + */
1.193 +native bool:RemoveAdmin(AdminId:id);
1.194 +
1.195 +/**
1.196 + * Converts a flag bit string to a bit array.
1.197 + *
1.198 + * @param bits Bit string containing the flags.
1.199 + * @param array Array to write the flags to. Enabled flags will be 'true'.
1.200 + * @param maxSize Maximum number of flags the array can store.
1.201 + * @return Number of flags written.
1.202 + */
1.203 +native FlagBitsToBitArray(bits, bool:array[], maxSize);
1.204 +
1.205 +/**
1.206 + * Converts a flag array to a bit string.
1.207 + *
1.208 + * @param array Array containing true or false for each AdminFlag.
1.209 + * @param maxSize Maximum size of the flag array.
1.210 + * @return A bit string composed of the array bits.
1.211 + */
1.212 +native FlagBitArrayToBits(const bool:array[], maxSize);
1.213 +
1.214 +/**
1.215 + * Converts an array of flags to bits.
1.216 + *
1.217 + * @param array Array containing flags that are enabled.
1.218 + * @param numFlags Number of flags in the array.
1.219 + * @return A bit string composed of the array flags.
1.220 + */
1.221 +native FlagArrayToBits(const AdminFlag:array[], numFlags) =0;
1.222 +
1.223 +/**
1.224 + * Converts a bit string to an array of flags.
1.225 + *
1.226 + * @param bits Bit string containing the flags.
1.227 + * @param array Output array to write flags.
1.228 + * @param maxSize Maximum size of the flag array.
1.229 + * @return Number of flags written.
1.230 + */
1.231 +native FlagBitsToArray(bits, AdminFlag:array[], maxSize) =0;
1.232 +
1.233 +
1.234 +stock FlagToBit(AdminFlag:flag)
1.235 +{
1.236 + return (1<<_:flag);
1.237 +}
1.238 +
1.239 +stock bool:BitToFlag(bit, &AdminFlag:flag)
1.240 +{
1.241 + new AdminFlag:array[1];
1.242 +
1.243 + if (FlagBitsToArray(bit, array, 1))
1.244 + {
1.245 + flag = array[0];
1.246 + return true;
1.247 + }
1.248 +
1.249 + return false;
1.250 +}