From 63d1fa2d8ef459c31a25b44508b774df83a3f924 Mon Sep 17 00:00:00 2001 From: Nicholas Hastings Date: Tue, 17 Feb 2015 08:24:46 -0800 Subject: [PATCH] Convert admin-flatfile to use AdminId/GroupId methodmaps and newdecls. --- plugins/admin-flatfile/admin-flatfile.sp | 20 ++--- plugins/admin-flatfile/admin-groups.sp | 100 ++++++++++++---------- plugins/admin-flatfile/admin-overrides.sp | 45 +++++----- plugins/admin-flatfile/admin-simple.sp | 50 +++++------ plugins/admin-flatfile/admin-users.sp | 86 ++++++++++--------- 5 files changed, 158 insertions(+), 143 deletions(-) diff --git a/plugins/admin-flatfile/admin-flatfile.sp b/plugins/admin-flatfile/admin-flatfile.sp index 12f06711..6e9bccd0 100644 --- a/plugins/admin-flatfile/admin-flatfile.sp +++ b/plugins/admin-flatfile/admin-flatfile.sp @@ -36,7 +36,7 @@ #include -public Plugin:myinfo = +public Plugin myinfo = { name = "Admin File Reader", author = "AlliedModders LLC", @@ -46,18 +46,18 @@ public Plugin:myinfo = }; /** Various parsing globals */ -new bool:g_LoggedFileName = false; /* Whether or not the file name has been logged */ -new g_ErrorCount = 0; /* Current error count */ -new g_IgnoreLevel = 0; /* Nested ignored section count, so users can screw up files safely */ -new g_CurrentLine = 0; /* Current line we're on */ -new String:g_Filename[PLATFORM_MAX_PATH]; /* Used for error messages */ +bool g_LoggedFileName = false; /* Whether or not the file name has been logged */ +int g_ErrorCount = 0; /* Current error count */ +int g_IgnoreLevel = 0; /* Nested ignored section count, so users can screw up files safely */ +int g_CurrentLine = 0; /* Current line we're on */ +char g_Filename[PLATFORM_MAX_PATH]; /* Used for error messages */ #include "admin-overrides.sp" #include "admin-groups.sp" #include "admin-users.sp" #include "admin-simple.sp" -public OnRebuildAdminCache(AdminCachePart:part) +public void OnRebuildAdminCache(AdminCachePart part) { if (part == AdminCache_Overrides) { @@ -70,9 +70,9 @@ public OnRebuildAdminCache(AdminCachePart:part) } } -ParseError(const String:format[], any:...) +void ParseError(const char[] format, any ...) { - decl String:buffer[512]; + char buffer[512]; if (!g_LoggedFileName) { @@ -87,7 +87,7 @@ ParseError(const String:format[], any:...) g_ErrorCount++; } -InitGlobalStates() +void InitGlobalStates() { g_ErrorCount = 0; g_IgnoreLevel = 0; diff --git a/plugins/admin-flatfile/admin-groups.sp b/plugins/admin-flatfile/admin-groups.sp index 95277578..986907e6 100644 --- a/plugins/admin-flatfile/admin-groups.sp +++ b/plugins/admin-flatfile/admin-groups.sp @@ -31,18 +31,26 @@ * Version: $Id$ */ -#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 +enum GroupState +{ + GroupState_None, + GroupState_Groups, + GroupState_InGroup, + GroupState_Overrides, +} + +enum GroupPass +{ + GroupPass_Invalid, + GroupPass_First, + GroupPass_Second, +} static SMCParser g_hGroupParser; -static GroupId:g_CurGrp = INVALID_GROUP_ID; -static g_GroupState = GROUP_STATE_NONE; -static g_GroupPass = 0; -static bool:g_NeedReparse = false; +static GroupId g_CurGrp = INVALID_GROUP_ID; +static GroupState g_GroupState = GroupState_None; +static GroupPass g_GroupPass = GroupPass_Invalid; +static bool g_NeedReparse = false; public SMCResult ReadGroups_NewSection(SMCParser smc, const char[] name, bool opt_quotes) { @@ -52,24 +60,24 @@ public SMCResult ReadGroups_NewSection(SMCParser smc, const char[] name, bool op return SMCParse_Continue; } - if (g_GroupState == GROUP_STATE_NONE) + if (g_GroupState == GroupState_None) { if (StrEqual(name, "Groups")) { - g_GroupState = GROUP_STATE_GROUPS; + g_GroupState = GroupState_Groups; } else { g_IgnoreLevel++; } - } else if (g_GroupState == GROUP_STATE_GROUPS) { + } else if (g_GroupState == GroupState_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) { + g_GroupState = GroupState_InGroup; + } else if (g_GroupState == GroupState_InGroup) { if (StrEqual(name, "Overrides")) { - g_GroupState = GROUP_STATE_OVERRIDES; + g_GroupState = GroupState_Overrides; } else { g_IgnoreLevel++; } @@ -91,28 +99,28 @@ public SMCResult ReadGroups_KeyValue(SMCParser smc, return SMCParse_Continue; } - new AdminFlag:flag; + AdminFlag flag; - if (g_GroupPass == GROUP_PASS_FIRST) + if (g_GroupPass == GroupPass_First) { - if (g_GroupState == GROUP_STATE_INGROUP) + if (g_GroupState == GroupState_InGroup) { if (StrEqual(key, "flags")) { - new len = strlen(value); - for (new i=0; i 0) { - SetAdminImmunityLevel(admin, level); + admin.ImmunityLevel = level; if (flags[flag_idx] == ':') { flag_idx++; @@ -166,41 +166,41 @@ ReadAdminLine(const String:line[]) if (flags[flag_idx] == '@') { - new GroupId:gid = FindAdmGroup(flags[flag_idx + 1]); + GroupId gid = FindAdmGroup(flags[flag_idx + 1]); if (gid == INVALID_GROUP_ID) { ParseError("Invalid group detected: %s", flags[flag_idx + 1]); return; } - AdminInheritGroup(admin, gid); + admin.InheritGroup(gid); } else { - new len = strlen(flags[flag_idx]); - new bool:is_default = false; - for (new i=0; i