2007-01-30 00:54:04 +01:00
|
|
|
#define OVERRIDE_STATE_NONE 0
|
|
|
|
#define OVERRIDE_STATE_LEVELS 1
|
|
|
|
#define OVERRIDE_STATE_OVERRIDES 2
|
|
|
|
|
|
|
|
static Handle:g_hOverrideParser = INVALID_HANDLE;
|
|
|
|
static g_OverrideState = OVERRIDE_STATE_NONE;
|
|
|
|
|
2007-02-07 00:30:50 +01:00
|
|
|
public SMCResult:ReadOverrides_NewSection(Handle:smc, const String:name[], bool:opt_quotes)
|
2007-01-30 00:54:04 +01:00
|
|
|
{
|
2007-02-07 00:30:50 +01:00
|
|
|
if (g_IgnoreLevel)
|
2007-01-30 00:54:04 +01:00
|
|
|
{
|
2007-02-07 00:30:50 +01:00
|
|
|
g_IgnoreLevel++;
|
|
|
|
return SMCParse_Continue;
|
2007-01-30 00:54:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (g_OverrideState == OVERRIDE_STATE_NONE)
|
|
|
|
{
|
|
|
|
if (StrEqual(name, "Levels"))
|
|
|
|
{
|
|
|
|
g_OverrideState = OVERRIDE_STATE_LEVELS;
|
2007-02-07 00:30:50 +01:00
|
|
|
} else {
|
|
|
|
g_IgnoreLevel++;
|
2007-01-30 00:54:04 +01:00
|
|
|
}
|
|
|
|
} else if (g_OverrideState == OVERRIDE_STATE_LEVELS) {
|
|
|
|
if (StrEqual(name, "Overrides"))
|
|
|
|
{
|
|
|
|
g_OverrideState = OVERRIDE_STATE_OVERRIDES;
|
2007-02-07 00:30:50 +01:00
|
|
|
} else {
|
|
|
|
g_IgnoreLevel++;
|
2007-01-30 00:54:04 +01:00
|
|
|
}
|
2007-02-07 00:30:50 +01:00
|
|
|
} else {
|
|
|
|
g_IgnoreLevel++;
|
2007-01-30 00:54:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return SMCParse_Continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
public SMCResult:ReadOverrides_KeyValue(Handle:smc,
|
|
|
|
const String:key[],
|
|
|
|
const String:value[],
|
|
|
|
bool:key_quotes,
|
|
|
|
bool:value_quotes)
|
|
|
|
{
|
2007-02-07 00:30:50 +01:00
|
|
|
if (g_OverrideState != OVERRIDE_STATE_OVERRIDES
|
|
|
|
|| g_IgnoreLevel)
|
2007-01-30 00:54:04 +01:00
|
|
|
{
|
|
|
|
return SMCParse_Continue;
|
|
|
|
}
|
|
|
|
|
2007-02-06 06:48:52 +01:00
|
|
|
new AdminFlag:array[AdminFlags_TOTAL];
|
|
|
|
new flags_total;
|
2007-01-30 00:54:04 +01:00
|
|
|
|
2007-02-06 06:48:52 +01:00
|
|
|
new len = strlen(value);
|
|
|
|
for (new i=0; i<len; i++)
|
2007-01-30 01:38:15 +01:00
|
|
|
{
|
2007-02-06 06:48:52 +01:00
|
|
|
if (value[i] < 'a' || value[i] > 'z')
|
|
|
|
{
|
2007-02-07 00:30:50 +01:00
|
|
|
ParseError("Invalid flag detected: %c", value[i]);
|
2007-02-06 06:48:52 +01:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
new val = value[i] - 'a';
|
|
|
|
if (!g_FlagsSet[val])
|
|
|
|
{
|
2007-02-07 00:30:50 +01:00
|
|
|
ParseError("Invalid flag detected: %c", value[i]);
|
2007-02-06 06:48:52 +01:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
array[flags_total++] = g_FlagLetters[val];
|
2007-01-30 01:38:15 +01:00
|
|
|
}
|
|
|
|
|
2007-02-06 06:48:52 +01:00
|
|
|
new flags = FlagArrayToBits(array, flags_total);
|
2007-01-30 00:54:04 +01:00
|
|
|
|
|
|
|
if (key[0] == '@')
|
|
|
|
{
|
2007-02-06 06:48:52 +01:00
|
|
|
AddCommandOverride(key[1], Override_CommandGroup, flags);
|
2007-01-30 00:54:04 +01:00
|
|
|
} else {
|
2007-02-06 06:48:52 +01:00
|
|
|
AddCommandOverride(key, Override_Command, flags);
|
2007-01-30 00:54:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return SMCParse_Continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
public SMCResult:ReadOverrides_EndSection(Handle:smc)
|
|
|
|
{
|
2007-02-07 00:30:50 +01:00
|
|
|
/* If we're ignoring, skip out */
|
|
|
|
if (g_IgnoreLevel)
|
|
|
|
{
|
|
|
|
g_IgnoreLevel--;
|
|
|
|
return SMCParse_Continue;
|
|
|
|
}
|
|
|
|
|
2007-01-30 00:54:04 +01:00
|
|
|
if (g_OverrideState == OVERRIDE_STATE_LEVELS)
|
|
|
|
{
|
|
|
|
g_OverrideState = OVERRIDE_STATE_NONE;
|
|
|
|
} else if (g_OverrideState == OVERRIDE_STATE_OVERRIDES) {
|
|
|
|
/* We're totally done parsing */
|
|
|
|
g_OverrideState = OVERRIDE_STATE_LEVELS;
|
|
|
|
return SMCParse_Halt;
|
|
|
|
}
|
|
|
|
|
|
|
|
return SMCParse_Continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
static InitializeOverrideParser()
|
|
|
|
{
|
|
|
|
if (g_hOverrideParser == INVALID_HANDLE)
|
|
|
|
{
|
|
|
|
g_hOverrideParser = SMC_CreateParser();
|
|
|
|
SMC_SetReaders(g_hOverrideParser,
|
|
|
|
ReadOverrides_NewSection,
|
|
|
|
ReadOverrides_KeyValue,
|
|
|
|
ReadOverrides_EndSection);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ReadOverrides()
|
|
|
|
{
|
|
|
|
InitializeOverrideParser();
|
|
|
|
|
2007-02-07 00:30:50 +01:00
|
|
|
BuildPath(Path_SM, g_Filename, sizeof(g_Filename), "configs/admin_levels.cfg");
|
2007-01-30 00:54:04 +01:00
|
|
|
|
|
|
|
/* Set states */
|
2007-02-07 00:30:50 +01:00
|
|
|
InitGlobalStates();
|
2007-01-30 00:54:04 +01:00
|
|
|
g_OverrideState = OVERRIDE_STATE_NONE;
|
|
|
|
|
2007-02-07 00:30:50 +01:00
|
|
|
new SMCError:err = SMC_ParseFile(g_hOverrideParser, g_Filename);
|
2007-01-30 00:54:04 +01:00
|
|
|
if (err != SMCError_Okay)
|
|
|
|
{
|
|
|
|
decl String:buffer[64];
|
|
|
|
if (SMC_GetErrorString(err, buffer, sizeof(buffer)))
|
|
|
|
{
|
2007-02-07 00:30:50 +01:00
|
|
|
ParseError("%s", buffer);
|
2007-01-30 00:54:04 +01:00
|
|
|
} else {
|
2007-02-07 00:30:50 +01:00
|
|
|
ParseError("Fatal parse error");
|
2007-01-30 00:54:04 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|