diff --git a/configs/admin_groups.cfg b/configs/admin_groups.cfg index d450c5c2..ed4c4142 100644 --- a/configs/admin_groups.cfg +++ b/configs/admin_groups.cfg @@ -4,7 +4,6 @@ Groups * Allowed properties for a group: * * "flags" - Flag string. - * "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. * This key may be used multiple times. */ diff --git a/plugins/admin-base/admin-base.sp b/plugins/admin-base/admin-base.sp index a4f1a48a..af9ffb5e 100644 --- a/plugins/admin-base/admin-base.sp +++ b/plugins/admin-base/admin-base.sp @@ -17,6 +17,7 @@ new g_ErrorCount = 0; #include "admin-levels.sp" #include "admin-overrides.sp" +#include "admin-groups.sp" public OnRebuildAdminCache(cache_flags) { @@ -25,4 +26,8 @@ public OnRebuildAdminCache(cache_flags) { ReadOverrides(); } + if (cache_flags & ADMIN_CACHE_GROUPS) + { + ReadGroups(); + } } diff --git a/plugins/admin-base/admin-groups.sp b/plugins/admin-base/admin-groups.sp index 7f63c663..22e27f59 100644 --- a/plugins/admin-base/admin-groups.sp +++ b/plugins/admin-base/admin-groups.sp @@ -9,8 +9,13 @@ static Handle:g_hGroupParser = INVALID_HANDLE; static GroupId:g_CurGrp = INVALID_GROUP_ID; static g_GroupState = GROUP_STATE_NONE; static g_GroupPass = 0 +static bool:g_NeedReparse = false; -static LevelGroupError(const String:buffer[], {Handle,String,Float,_}:...) +//:TODO: immunity needs to self-check itself for redundancy in core +//:TODO: invalidating groups internally needs to check immunities +//:TODO: reparsing + +static LogGroupError(const String:fmt[], {Handle,String,Float,_}:...) { decl String:buffer[512]; @@ -20,7 +25,7 @@ static LevelGroupError(const String:buffer[], {Handle,String,Float,_}:...) g_LoggedFileName = true; } - VFormat(buffer, sizeof(buffer), format, 2); + VFormat(buffer, sizeof(buffer), fmt, 2); LogError(" (%d) %s", ++g_ErrorCount, buffer); } @@ -62,28 +67,71 @@ public SMCResult:ReadGroups_KeyValue(Handle:smc, new AdminFlag:flag; - if (StrEqual(key, "flags")) + if (g_GroupPass == GROUP_PASS_FIRST) { - new len = strlen(value); - for (new i=0; i 'z') + if (StrEqual(key, "flags")) { - continue; + 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 it's a value we know about, use it */ + if (StrEqual(value, "*")) + { + SetAdmGroupImmunity(g_CurGrp, Immunity_Global, true); + } else if (StrEqual(value, "$")) { + SetAdmGroupImmunity(g_CurGrp, Immunity_Default, true); + } else { + /* If we can't find the group, we'll need to schedule a reparse */ + new GroupId:id = FindAdmGroup(value); + if (id == INVALID_GROUP_ID) + { + SetAdmGroupImmuneFrom(g_CurGrp, id); + } else { + g_NeedReparse = true; + } + } } - flag = g_FlagLetters[value[i] - 'a']; - if (flag == Admin_None) + } else if (g_GroupState == GROUP_STATE_OVERRIDES) { + new OverrideRule:rule = Command_Deny; + + if (StrEqual(value, "allow", false)) { - continue; + rule = Command_Allow; + } + + if (key[0] == '@') + { + AddAdmGroupCmdOverride(g_CurGrp, key[1], Override_CommandGroup, rule); + } else { + AddAdmGroupCmdOverride(g_CurGrp, key, Override_Command, rule); } - SetAdmGroupAddFlag(g_CurGrp, flag, true); } - } else if (StrEqual(key, "immunity")) { - if (StrEqual(value, "*")) + } else if (g_GroupPass == GROUP_PASS_SECOND + && g_GroupState == GROUP_STATE_INGROUP) { + /* Check for immunity again, core should handle double inserts */ + if (StrEqual(key, "immunity")) { - SetAdmGroupImmunity(g_CurGrp, Immunity_Global, true); - } else if (StrEqual(value, "$")) { - SetAdmGroupImmunity(g_CurGrp, Immunity_Default, true); + new GroupId:id = FindAdmGroup(value); + if (id != INVALID_GROUP_ID) + { + SetAdmGroupImmuneFrom(g_CurGrp, id); + } else { + LogGroupError("Unable to find group: \"%s\"", value); + } } } @@ -111,9 +159,9 @@ static InitializeGroupParser() { g_hGroupParser = SMC_CreateParser(); SMC_SetReaders(g_hGroupParser, - ReadGroup_NewSection, - ReadGroup_KeyValue, - ReadGroup_EndSection); + ReadGroups_NewSection, + ReadGroups_KeyValue, + ReadGroups_EndSection); } } @@ -131,6 +179,7 @@ ReadGroups() g_ErrorCount = 0; g_CurGrp = INVALID_GROUP_ID; g_GroupPass = GROUP_PASS_FIRST; + g_NeedReparse = false; new SMCError:err = SMC_ParseFile(g_hGroupParser, path); if (err != SMCError_Okay) diff --git a/plugins/include/admin.inc b/plugins/include/admin.inc index bb184c74..465c35a8 100644 --- a/plugins/include/admin.inc +++ b/plugins/include/admin.inc @@ -133,7 +133,7 @@ native GroupId:CreateAdmGroup(const String:group_name[]); * @param group_name String containing the group name. * @return A group id, or INVALID_GROUP_ID if not found. */ -native FindAdmGroup(const String:group_name[]); +native GroupId:FindAdmGroup(const String:group_name[]); /** * Adds or removes a flag from a group's flag set.