From 5085521b548d9aa703d70ccd86e25bc204a9cc90 Mon Sep 17 00:00:00 2001 From: David Anderson Date: Tue, 30 Jan 2007 05:42:57 +0000 Subject: [PATCH] initial import of group reader (unfinished) --HG-- extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%40426 --- configs/admin_groups.cfg | 6 +- plugins/admin-base/admin-groups.sp | 147 ++++++++++++++++++++++++++ plugins/admin-base/admin-overrides.sp | 2 +- plugins/include/admin.inc | 6 ++ 4 files changed, 157 insertions(+), 4 deletions(-) create mode 100644 plugins/admin-base/admin-groups.sp diff --git a/configs/admin_groups.cfg b/configs/admin_groups.cfg index d4505a72..d450c5c2 100644 --- a/configs/admin_groups.cfg +++ b/configs/admin_groups.cfg @@ -4,9 +4,9 @@ Groups * Allowed properties for a group: * * "flags" - Flag string. - * "inherit" - Inherits permissions from another group. + * "inherit" - Inherits permissions from another group. Use one group per instance of this key. * "immunity" - Specifies a group to be immune to. Use "*" for all or "$" for users with no group. - * NOTE: No one, even a root user, is immune from other root users. + * This key may be used multiple times. */ "Full Admins" { @@ -14,7 +14,7 @@ Groups * You can override commands and command groups here. * Specify a command name or group and either "allow" or "deny" * Examples: - * ":CSDM" "allow" + * ":CSDM" "allow" * "csdm_enable" "deny" */ Commands diff --git a/plugins/admin-base/admin-groups.sp b/plugins/admin-base/admin-groups.sp new file mode 100644 index 00000000..7f63c663 --- /dev/null +++ b/plugins/admin-base/admin-groups.sp @@ -0,0 +1,147 @@ +#define GROUP_STATE_NONE 0 +#define GROUP_STATE_GROUPS 1 +#define GROUP_STATE_INGROUP 2 +#define GROUP_STATE_OVERRIDES 3 +#define GROUP_PASS_FIRST 1 +#define GROUP_PASS_SECOND 2 + +static Handle:g_hGroupParser = INVALID_HANDLE; +static GroupId:g_CurGrp = INVALID_GROUP_ID; +static g_GroupState = GROUP_STATE_NONE; +static g_GroupPass = 0 + +static LevelGroupError(const String:buffer[], {Handle,String,Float,_}:...) +{ + decl String:buffer[512]; + + if (!g_LoggedFileName) + { + LogError("Error(s) detected parsing admin_groups.cfg:"); + g_LoggedFileName = true; + } + + VFormat(buffer, sizeof(buffer), format, 2); + + LogError(" (%d) %s", ++g_ErrorCount, buffer); +} + +public SMCResult:ReadGroups_NewSection(Handle:smc, const String:name[], bool:opt_quotes) +{ + if (g_GroupState == GROUP_STATE_NONE) + { + if (StrEqual(name, "Groups")) + { + g_GroupState = GROUP_STATE_GROUPS; + } + } else if (g_GroupState == GROUP_STATE_GROUPS) { + if ((g_CurGrp = CreateAdmGroup(name)) == INVALID_GROUP_ID) + { + g_CurGrp = FindAdmGroup(name); + } + g_GroupState = GROUP_STATE_INGROUP; + } else if (g_GroupState == GROUP_STATE_INGROUP) { + if (StrEqual(name, "Overrides")) + { + g_GroupState = GROUP_STATE_OVERRIDES; + } + } + + return SMCParse_Continue; +} + +public SMCResult:ReadGroups_KeyValue(Handle:smc, + const String:key[], + const String:value[], + bool:key_quotes, + bool:value_quotes) +{ + if (g_CurGrp == INVALID_GROUP_ID) + { + return SMCParse_Continue; + } + + new AdminFlag:flag; + + if (StrEqual(key, "flags")) + { + new len = strlen(value); + for (new i=0; i 'z') + { + continue; + } + flag = g_FlagLetters[value[i] - 'a']; + if (flag == Admin_None) + { + continue; + } + SetAdmGroupAddFlag(g_CurGrp, flag, true); + } + } else if (StrEqual(key, "immunity")) { + if (StrEqual(value, "*")) + { + SetAdmGroupImmunity(g_CurGrp, Immunity_Global, true); + } else if (StrEqual(value, "$")) { + SetAdmGroupImmunity(g_CurGrp, Immunity_Default, true); + } + } + + return SMCParse_Continue; +} + +public SMCResult:ReadGroups_EndSection(Handle:smc) +{ + if (g_GroupState == GROUP_STATE_OVERRIDES) + { + g_GroupState = GROUP_STATE_INGROUP; + } else if (g_GroupState == GROUP_STATE_INGROUP) { + g_GroupState = GROUP_STATE_GROUPS; + g_CurGrp = INVALID_GROUP_ID; + } else if (g_GroupState == GROUP_STATE_GROUPS) { + g_GroupState = GROUP_STATE_NONE; + } + + return SMCParse_Continue; +} + +static InitializeGroupParser() +{ + if (g_hGroupParser == INVALID_HANDLE) + { + g_hGroupParser = SMC_CreateParser(); + SMC_SetReaders(g_hGroupParser, + ReadGroup_NewSection, + ReadGroup_KeyValue, + ReadGroup_EndSection); + } +} + +ReadGroups() +{ + new String:path[PLATFORM_MAX_PATH]; + + InitializeGroupParser(); + + BuildPath(Path_SM, path, sizeof(path), "configs/admin_groups.cfg"); + + /* Set states */ + g_GroupState = GROUP_STATE_NONE; + g_LoggedFileName = false; + g_ErrorCount = 0; + g_CurGrp = INVALID_GROUP_ID; + g_GroupPass = GROUP_PASS_FIRST; + + new SMCError:err = SMC_ParseFile(g_hGroupParser, path); + if (err != SMCError_Okay) + { + decl String:buffer[64]; + if (SMC_GetErrorString(err, buffer, sizeof(buffer))) + { + LogGroupError("%s", buffer); + } else { + LogGroupError("Fatal parse error"); + } + } +} + diff --git a/plugins/admin-base/admin-overrides.sp b/plugins/admin-base/admin-overrides.sp index 14ccaa95..cd3a522f 100644 --- a/plugins/admin-base/admin-overrides.sp +++ b/plugins/admin-base/admin-overrides.sp @@ -5,7 +5,7 @@ static Handle:g_hOverrideParser = INVALID_HANDLE; static g_OverrideState = OVERRIDE_STATE_NONE; -LogOverrideError(const String:format[], {Handle,String,Float,_}:...) +static LogOverrideError(const String:format[], {Handle,String,Float,_}:...) { decl String:buffer[512]; diff --git a/plugins/include/admin.inc b/plugins/include/admin.inc index 23a9217b..bb184c74 100644 --- a/plugins/include/admin.inc +++ b/plugins/include/admin.inc @@ -62,6 +62,12 @@ enum GroupId INVALID_GROUP_ID = -1, }; +/** Note: These are not Handles */ +enum AdminId +{ + INVALID_ADMIN_ID = -1, +}; + #define ADMIN_CACHE_OVERRIDES (1<<0) #define ADMIN_CACHE_ADMINS (1<<1) #define ADMIN_CACHE_GROUPS ((1<<2)|ADMIN_CACHE_ADMINS)