admin plugin now reads overrides from separate file (but also admin_levels.cfg for backwards compatibility)

--HG--
extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%401320
This commit is contained in:
David Anderson 2007-08-13 00:19:46 +00:00
parent afb58cfd67
commit 1458a48f13
3 changed files with 86 additions and 33 deletions

View File

@ -1,6 +1,6 @@
/** /**
* Use this section to tweak admin permission levels and groupings. * There is no reason to edit this file. Core uses this to map each named
* You can also define admin roles in this section. * access type to a given ASCII character. The names are all pre-defined.
*/ */
Levels Levels
{ {
@ -45,21 +45,4 @@ Levels
*/ */
"root" "z" "root" "z"
} }
/**
* By default, commands are registered with three pieces of information:
* 1)Command Name (for example, "csdm_enable")
* 2)Command Group Name (for example, "CSDM")
* 3)Command Level (for example, "changemap")
* You can override the default flags assigned to individual commands or command groups in this way.
* To override a group, use the "@" character before the name. Example:
* Examples:
* "@CSDM" "b" // Override the CSDM group to 'b' flag
* "csdm_enable" "bgi" // Override the csdm_enable command to 'bgi' flags
* Note that for overrides, order is important. In the above example, csdm_enable overwrites
* any setting that csdm_enable previously had.
*/
Overrides
{
}
} }

View File

@ -0,0 +1,16 @@
Overrides
{
/**
* By default, commands are registered with three pieces of information:
* 1)Command Name (for example, "csdm_enable")
* 2)Command Group Name (for example, "CSDM")
* 3)Command Level (for example, "changemap")
* You can override the default flags assigned to individual commands or command groups in this way.
* To override a group, use the "@" character before the name. Example:
* Examples:
* "@CSDM" "b" // Override the CSDM group to 'b' flag
* "csdm_enable" "bgi" // Override the csdm_enable command to 'bgi' flags
* Note that for overrides, order is important. In the above example, csdm_enable overwrites
* any setting that csdm_enable previously had.
*/
}

View File

@ -24,10 +24,11 @@
#define OVERRIDE_STATE_LEVELS 1 #define OVERRIDE_STATE_LEVELS 1
#define OVERRIDE_STATE_OVERRIDES 2 #define OVERRIDE_STATE_OVERRIDES 2
static Handle:g_hOverrideParser = INVALID_HANDLE; static Handle:g_hOldOverrideParser = INVALID_HANDLE;
static Handle:g_hNewOverrideParser = INVALID_HANDLE;
static g_OverrideState = OVERRIDE_STATE_NONE; static g_OverrideState = OVERRIDE_STATE_NONE;
public SMCResult:ReadOverrides_NewSection(Handle:smc, const String:name[], bool:opt_quotes) public SMCResult:ReadOldOverrides_NewSection(Handle:smc, const String:name[], bool:opt_quotes)
{ {
if (g_IgnoreLevel) if (g_IgnoreLevel)
{ {
@ -57,6 +58,29 @@ public SMCResult:ReadOverrides_NewSection(Handle:smc, const String:name[], bool:
return SMCParse_Continue; return SMCParse_Continue;
} }
public SMCResult:ReadNewOverrides_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, "Overrides"))
{
g_OverrideState = OVERRIDE_STATE_OVERRIDES;
} else {
g_IgnoreLevel++;
}
} else {
g_IgnoreLevel++;
}
return SMCParse_Continue;
}
public SMCResult:ReadOverrides_KeyValue(Handle:smc, public SMCResult:ReadOverrides_KeyValue(Handle:smc,
const String:key[], const String:key[],
const String:value[], const String:value[],
@ -81,7 +105,7 @@ public SMCResult:ReadOverrides_KeyValue(Handle:smc,
return SMCParse_Continue; return SMCParse_Continue;
} }
public SMCResult:ReadOverrides_EndSection(Handle:smc) public SMCResult:ReadOldOverrides_EndSection(Handle:smc)
{ {
/* If we're ignoring, skip out */ /* If we're ignoring, skip out */
if (g_IgnoreLevel) if (g_IgnoreLevel)
@ -102,29 +126,52 @@ public SMCResult:ReadOverrides_EndSection(Handle:smc)
return SMCParse_Continue; return SMCParse_Continue;
} }
static InitializeOverrideParser() public SMCResult:ReadNewOverrides_EndSection(Handle:smc)
{ {
if (g_hOverrideParser == INVALID_HANDLE) /* If we're ignoring, skip out */
if (g_IgnoreLevel)
{ {
g_hOverrideParser = SMC_CreateParser(); g_IgnoreLevel--;
SMC_SetReaders(g_hOverrideParser, return SMCParse_Continue;
ReadOverrides_NewSection, }
if (g_OverrideState == OVERRIDE_STATE_OVERRIDES)
{
g_OverrideState = OVERRIDE_STATE_NONE;
}
return SMCParse_Continue;
}
static InitializeOverrideParsers()
{
if (g_hOldOverrideParser == INVALID_HANDLE)
{
g_hOldOverrideParser = SMC_CreateParser();
SMC_SetReaders(g_hOldOverrideParser,
ReadOldOverrides_NewSection,
ReadOverrides_KeyValue, ReadOverrides_KeyValue,
ReadOverrides_EndSection); ReadOldOverrides_EndSection);
}
if (g_hNewOverrideParser == INVALID_HANDLE)
{
g_hNewOverrideParser = SMC_CreateParser();
SMC_SetReaders(g_hNewOverrideParser,
ReadNewOverrides_NewSection,
ReadOverrides_KeyValue,
ReadNewOverrides_EndSection);
} }
} }
ReadOverrides() InternalReadOverrides(Handle:parser, const String:file[])
{ {
InitializeOverrideParser(); BuildPath(Path_SM, g_Filename, sizeof(g_Filename), file);
BuildPath(Path_SM, g_Filename, sizeof(g_Filename), "configs/admin_levels.cfg");
/* Set states */ /* Set states */
InitGlobalStates(); InitGlobalStates();
g_OverrideState = OVERRIDE_STATE_NONE; g_OverrideState = OVERRIDE_STATE_NONE;
new SMCError:err = SMC_ParseFile(g_hOverrideParser, g_Filename); new SMCError:err = SMC_ParseFile(parser, g_Filename);
if (err != SMCError_Okay) if (err != SMCError_Okay)
{ {
decl String:buffer[64]; decl String:buffer[64];
@ -136,3 +183,10 @@ ReadOverrides()
} }
} }
} }
ReadOverrides()
{
InitializeOverrideParsers();
InternalReadOverrides(g_hOldOverrideParser, "configs/admin_levels.cfg");
InternalReadOverrides(g_hNewOverrideParser, "configs/admin_overrides.cfg");
}