ignores bad groups safely now
cleaned up code a bit, removed redundancy --HG-- extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%40448
This commit is contained in:
parent
9969243266
commit
d2a3c7f0f7
@ -10,11 +10,13 @@ public Plugin:myinfo =
|
||||
url = "http://www.sourcemod.net/"
|
||||
};
|
||||
|
||||
/** Various globals */
|
||||
/** Various parsing globals */
|
||||
new bool:g_FlagsSet[26]; /* Maps whether flags are set */
|
||||
new AdminFlag:g_FlagLetters[26]; /* Maps the flag letters */
|
||||
new bool:g_LoggedFileName = false; /* Whether or not the file name has been logged */
|
||||
new g_ErrorCount = 0;
|
||||
new g_ErrorCount = 0; /* Current error count */
|
||||
new g_IgnoreLevel = 0; /* Nested ignored section count, so users can screw up files safely */
|
||||
new String:g_Filename[PLATFORM_MAX_PATH]; /* Used for error messages */
|
||||
|
||||
#include "admin-levels.sp"
|
||||
#include "admin-overrides.sp"
|
||||
@ -31,3 +33,25 @@ public OnRebuildAdminCache(AdminCachePart:part)
|
||||
ReadGroups();
|
||||
}
|
||||
}
|
||||
|
||||
ParseError(const String:format[], {Handle,String,Float,_}:...)
|
||||
{
|
||||
decl String:buffer[512];
|
||||
|
||||
if (!g_LoggedFileName)
|
||||
{
|
||||
LogError("Error(s) detected parsing admin_levels.cfg:");
|
||||
g_LoggedFileName = true;
|
||||
}
|
||||
|
||||
VFormat(buffer, sizeof(buffer), format, 2);
|
||||
|
||||
LogError(" (%d) %s", ++g_ErrorCount, buffer);
|
||||
}
|
||||
|
||||
InitGlobalStates()
|
||||
{
|
||||
g_ErrorCount = 0;
|
||||
g_IgnoreLevel = 0;
|
||||
g_LoggedFileName = false;
|
||||
}
|
||||
|
@ -11,32 +11,23 @@ static g_GroupState = GROUP_STATE_NONE;
|
||||
static g_GroupPass = 0
|
||||
static bool:g_NeedReparse = false;
|
||||
|
||||
//: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];
|
||||
|
||||
if (!g_LoggedFileName)
|
||||
{
|
||||
LogError("Error(s) detected parsing admin_groups.cfg:");
|
||||
g_LoggedFileName = true;
|
||||
}
|
||||
|
||||
VFormat(buffer, sizeof(buffer), fmt, 2);
|
||||
|
||||
LogError(" (%d) %s", ++g_ErrorCount, buffer);
|
||||
}
|
||||
|
||||
public SMCResult:ReadGroups_NewSection(Handle:smc, const String:name[], bool:opt_quotes)
|
||||
{
|
||||
if (g_IgnoreLevel)
|
||||
{
|
||||
g_IgnoreLevel++;
|
||||
return SMCParse_Continue;
|
||||
}
|
||||
|
||||
if (g_GroupState == GROUP_STATE_NONE)
|
||||
{
|
||||
if (StrEqual(name, "Groups"))
|
||||
{
|
||||
g_GroupState = GROUP_STATE_GROUPS;
|
||||
} else {
|
||||
g_IgnoreLevel++;
|
||||
}
|
||||
} else if (g_GroupState == GROUP_STATE_GROUPS) {
|
||||
if ((g_CurGrp = CreateAdmGroup(name)) == INVALID_GROUP_ID)
|
||||
@ -48,7 +39,11 @@ public SMCResult:ReadGroups_NewSection(Handle:smc, const String:name[], bool:opt
|
||||
if (StrEqual(name, "Overrides"))
|
||||
{
|
||||
g_GroupState = GROUP_STATE_OVERRIDES;
|
||||
} else {
|
||||
g_IgnoreLevel++;
|
||||
}
|
||||
} else {
|
||||
g_IgnoreLevel++;
|
||||
}
|
||||
|
||||
return SMCParse_Continue;
|
||||
@ -60,7 +55,8 @@ public SMCResult:ReadGroups_KeyValue(Handle:smc,
|
||||
bool:key_quotes,
|
||||
bool:value_quotes)
|
||||
{
|
||||
if (g_CurGrp == INVALID_GROUP_ID)
|
||||
if (g_CurGrp == INVALID_GROUP_ID
|
||||
|| g_IgnoreLevel)
|
||||
{
|
||||
return SMCParse_Continue;
|
||||
}
|
||||
@ -130,7 +126,7 @@ public SMCResult:ReadGroups_KeyValue(Handle:smc,
|
||||
{
|
||||
SetAdmGroupImmuneFrom(g_CurGrp, id);
|
||||
} else {
|
||||
LogGroupError("Unable to find group: \"%s\"", value);
|
||||
ParseError("Unable to find group: \"%s\"", value);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -140,6 +136,13 @@ public SMCResult:ReadGroups_KeyValue(Handle:smc,
|
||||
|
||||
public SMCResult:ReadGroups_EndSection(Handle:smc)
|
||||
{
|
||||
/* If we're ignoring, skip out */
|
||||
if (g_IgnoreLevel)
|
||||
{
|
||||
g_IgnoreLevel--;
|
||||
return SMCParse_Continue;
|
||||
}
|
||||
|
||||
if (g_GroupState == GROUP_STATE_OVERRIDES)
|
||||
{
|
||||
g_GroupState = GROUP_STATE_INGROUP;
|
||||
@ -165,20 +168,13 @@ static InitializeGroupParser()
|
||||
}
|
||||
}
|
||||
|
||||
ReadGroups()
|
||||
InternalReadGroups(const String:path[], pass)
|
||||
{
|
||||
new String:path[PLATFORM_MAX_PATH];
|
||||
|
||||
InitializeGroupParser();
|
||||
|
||||
BuildPath(Path_SM, path, sizeof(path), "configs/admin_groups.cfg");
|
||||
|
||||
/* Set states */
|
||||
InitGlobalStates();
|
||||
g_GroupState = GROUP_STATE_NONE;
|
||||
g_LoggedFileName = false;
|
||||
g_ErrorCount = 0;
|
||||
g_CurGrp = INVALID_GROUP_ID;
|
||||
g_GroupPass = GROUP_PASS_FIRST;
|
||||
g_GroupPass = pass;
|
||||
g_NeedReparse = false;
|
||||
|
||||
new SMCError:err = SMC_ParseFile(g_hGroupParser, path);
|
||||
@ -187,10 +183,23 @@ ReadGroups()
|
||||
decl String:buffer[64];
|
||||
if (SMC_GetErrorString(err, buffer, sizeof(buffer)))
|
||||
{
|
||||
LogGroupError("%s", buffer);
|
||||
ParseError("%s", buffer);
|
||||
} else {
|
||||
LogGroupError("Fatal parse error");
|
||||
ParseError("Fatal parse error");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ReadGroups()
|
||||
{
|
||||
InitializeGroupParser();
|
||||
|
||||
BuildPath(Path_SM, g_Filename, sizeof(g_Filename), "configs/admin_groups.cfg");
|
||||
|
||||
InternalReadGroups(g_Filename, GROUP_PASS_FIRST);
|
||||
if (g_NeedReparse)
|
||||
{
|
||||
InternalReadGroups(g_Filename, GROUP_PASS_SECOND);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -36,34 +36,31 @@ LoadDefaultLetters()
|
||||
g_FlagLetters['z'-'a'] = Admin_Root;
|
||||
}
|
||||
|
||||
static LogLevelError(const String:format[], {Handle,String,Float,_}:...)
|
||||
{
|
||||
decl String:buffer[512];
|
||||
|
||||
if (!g_LoggedFileName)
|
||||
{
|
||||
LogError("Error(s) detected parsing admin_levels.cfg:");
|
||||
g_LoggedFileName = true;
|
||||
}
|
||||
|
||||
VFormat(buffer, sizeof(buffer), format, 2);
|
||||
|
||||
LogError(" (%d) %s", ++g_ErrorCount, buffer);
|
||||
}
|
||||
|
||||
public SMCResult:ReadLevels_NewSection(Handle:smc, const String:name[], bool:opt_quotes)
|
||||
{
|
||||
if (g_IgnoreLevel)
|
||||
{
|
||||
g_IgnoreLevel++;
|
||||
return SMCParse_Continue;
|
||||
}
|
||||
|
||||
if (g_LevelState == LEVEL_STATE_NONE)
|
||||
{
|
||||
if (StrEqual(name, "Levels"))
|
||||
{
|
||||
g_LevelState = LEVEL_STATE_LEVELS;
|
||||
} else {
|
||||
g_IgnoreLevel++;
|
||||
}
|
||||
} else if (g_LevelState == LEVEL_STATE_LEVELS) {
|
||||
if (StrEqual(name, "Flags"))
|
||||
{
|
||||
g_LevelState = LEVEL_STATE_FLAGS;
|
||||
} else {
|
||||
g_IgnoreLevel++;
|
||||
}
|
||||
} else {
|
||||
g_IgnoreLevel++;
|
||||
}
|
||||
|
||||
return SMCParse_Continue;
|
||||
@ -71,13 +68,13 @@ public SMCResult:ReadLevels_NewSection(Handle:smc, const String:name[], bool:opt
|
||||
|
||||
public SMCResult:ReadLevels_KeyValue(Handle:smc, const String:key[], const String:value[], bool:key_quotes, bool:value_quotes)
|
||||
{
|
||||
if (g_LevelState == LEVEL_STATE_FLAGS)
|
||||
if (g_LevelState == LEVEL_STATE_FLAGS && !g_IgnoreLevel)
|
||||
{
|
||||
new chr = value[0];
|
||||
|
||||
if (chr < 'a' || chr > 'z')
|
||||
{
|
||||
LogLevelError("Unrecognized character: \"%s\"", value);
|
||||
ParseError("Unrecognized character: \"%s\"", value);
|
||||
return SMCParse_Continue;
|
||||
}
|
||||
|
||||
@ -127,7 +124,7 @@ public SMCResult:ReadLevels_KeyValue(Handle:smc, const String:key[], const Strin
|
||||
} else if (StrEqual(key, "custom6")) {
|
||||
flag = Admin_Custom6;
|
||||
} else {
|
||||
LogLevelError("Unrecognized flag type: %s", key);
|
||||
ParseError("Unrecognized flag type: %s", key);
|
||||
}
|
||||
|
||||
g_FlagLetters[chr] = flag;
|
||||
@ -139,6 +136,13 @@ public SMCResult:ReadLevels_KeyValue(Handle:smc, const String:key[], const Strin
|
||||
|
||||
public SMCResult:ReadLevels_EndSection(Handle:smc)
|
||||
{
|
||||
/* If we're ignoring, skip out */
|
||||
if (g_IgnoreLevel)
|
||||
{
|
||||
g_IgnoreLevel--;
|
||||
return SMCParse_Continue;
|
||||
}
|
||||
|
||||
if (g_LevelState == LEVEL_STATE_FLAGS)
|
||||
{
|
||||
/* We're totally done parsing */
|
||||
@ -165,27 +169,24 @@ static InitializeLevelParser()
|
||||
|
||||
RefreshLevels()
|
||||
{
|
||||
new String:path[PLATFORM_MAX_PATH];
|
||||
|
||||
LoadDefaultLetters();
|
||||
InitializeLevelParser();
|
||||
|
||||
BuildPath(Path_SM, path, sizeof(path), "configs/admin_levels.cfg");
|
||||
BuildPath(Path_SM, g_Filename, sizeof(g_Filename), "configs/admin_levels.cfg");
|
||||
|
||||
/* Set states */
|
||||
InitGlobalStates();
|
||||
g_LevelState = LEVEL_STATE_NONE;
|
||||
g_LoggedFileName = false;
|
||||
g_ErrorCount = 0;
|
||||
|
||||
new SMCError:err = SMC_ParseFile(g_hLevelParser, path);
|
||||
new SMCError:err = SMC_ParseFile(g_hLevelParser, g_Filename);
|
||||
if (err != SMCError_Okay)
|
||||
{
|
||||
decl String:buffer[64];
|
||||
if (SMC_GetErrorString(err, buffer, sizeof(buffer)))
|
||||
{
|
||||
LogLevelError("%s", buffer);
|
||||
ParseError("%s", buffer);
|
||||
} else {
|
||||
LogLevelError("Fatal parse error");
|
||||
ParseError("Fatal parse error");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -5,35 +5,31 @@
|
||||
static Handle:g_hOverrideParser = INVALID_HANDLE;
|
||||
static g_OverrideState = OVERRIDE_STATE_NONE;
|
||||
|
||||
static LogOverrideError(const String:format[], {Handle,String,Float,_}:...)
|
||||
{
|
||||
decl String:buffer[512];
|
||||
|
||||
if (!g_LoggedFileName)
|
||||
{
|
||||
LogError("Error(s) detected parsing admin_levels.cfg:");
|
||||
g_LoggedFileName = true;
|
||||
}
|
||||
|
||||
VFormat(buffer, sizeof(buffer), format, 2);
|
||||
|
||||
LogError(" (%d) %s", ++g_ErrorCount, buffer);
|
||||
}
|
||||
|
||||
|
||||
public SMCResult:ReadOverrides_NewSection(Handle:smc, const String:name[], bool:opt_quotes)
|
||||
{
|
||||
if (g_IgnoreLevel)
|
||||
{
|
||||
g_IgnoreLevel++;
|
||||
return SMCParse_Continue;
|
||||
}
|
||||
|
||||
if (g_OverrideState == OVERRIDE_STATE_NONE)
|
||||
{
|
||||
if (StrEqual(name, "Levels"))
|
||||
{
|
||||
g_OverrideState = OVERRIDE_STATE_LEVELS;
|
||||
} else {
|
||||
g_IgnoreLevel++;
|
||||
}
|
||||
} else if (g_OverrideState == OVERRIDE_STATE_LEVELS) {
|
||||
if (StrEqual(name, "Overrides"))
|
||||
{
|
||||
g_OverrideState = OVERRIDE_STATE_OVERRIDES;
|
||||
} else {
|
||||
g_IgnoreLevel++;
|
||||
}
|
||||
} else {
|
||||
g_IgnoreLevel++;
|
||||
}
|
||||
|
||||
return SMCParse_Continue;
|
||||
@ -45,7 +41,8 @@ public SMCResult:ReadOverrides_KeyValue(Handle:smc,
|
||||
bool:key_quotes,
|
||||
bool:value_quotes)
|
||||
{
|
||||
if (g_OverrideState != OVERRIDE_STATE_OVERRIDES)
|
||||
if (g_OverrideState != OVERRIDE_STATE_OVERRIDES
|
||||
|| g_IgnoreLevel)
|
||||
{
|
||||
return SMCParse_Continue;
|
||||
}
|
||||
@ -58,13 +55,13 @@ public SMCResult:ReadOverrides_KeyValue(Handle:smc,
|
||||
{
|
||||
if (value[i] < 'a' || value[i] > 'z')
|
||||
{
|
||||
LogOverrideError("Invalid flag detected: %c", value[i]);
|
||||
ParseError("Invalid flag detected: %c", value[i]);
|
||||
continue;
|
||||
}
|
||||
new val = value[i] - 'a';
|
||||
if (!g_FlagsSet[val])
|
||||
{
|
||||
LogOverrideError("Invalid flag detected: %c", value[i]);
|
||||
ParseError("Invalid flag detected: %c", value[i]);
|
||||
continue;
|
||||
}
|
||||
array[flags_total++] = g_FlagLetters[val];
|
||||
@ -84,6 +81,13 @@ public SMCResult:ReadOverrides_KeyValue(Handle:smc,
|
||||
|
||||
public SMCResult:ReadOverrides_EndSection(Handle:smc)
|
||||
{
|
||||
/* If we're ignoring, skip out */
|
||||
if (g_IgnoreLevel)
|
||||
{
|
||||
g_IgnoreLevel--;
|
||||
return SMCParse_Continue;
|
||||
}
|
||||
|
||||
if (g_OverrideState == OVERRIDE_STATE_LEVELS)
|
||||
{
|
||||
g_OverrideState = OVERRIDE_STATE_NONE;
|
||||
@ -110,27 +114,23 @@ static InitializeOverrideParser()
|
||||
|
||||
ReadOverrides()
|
||||
{
|
||||
new String:path[PLATFORM_MAX_PATH];
|
||||
|
||||
InitializeOverrideParser();
|
||||
|
||||
BuildPath(Path_SM, path, sizeof(path), "configs/admin_levels.cfg");
|
||||
BuildPath(Path_SM, g_Filename, sizeof(g_Filename), "configs/admin_levels.cfg");
|
||||
|
||||
/* Set states */
|
||||
InitGlobalStates();
|
||||
g_OverrideState = OVERRIDE_STATE_NONE;
|
||||
g_LoggedFileName = false;
|
||||
g_ErrorCount = 0;
|
||||
|
||||
new SMCError:err = SMC_ParseFile(g_hOverrideParser, path);
|
||||
new SMCError:err = SMC_ParseFile(g_hOverrideParser, g_Filename);
|
||||
if (err != SMCError_Okay)
|
||||
{
|
||||
decl String:buffer[64];
|
||||
if (SMC_GetErrorString(err, buffer, sizeof(buffer)))
|
||||
{
|
||||
LogOverrideError("%s", buffer);
|
||||
ParseError("%s", buffer);
|
||||
} else {
|
||||
LogOverrideError("Fatal parse error");
|
||||
ParseError("Fatal parse error");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user