2008-03-30 09:00:22 +02:00
|
|
|
/**
|
|
|
|
* vim: set ts=4 :
|
|
|
|
* =============================================================================
|
|
|
|
* SourceMod Admin File Reader Plugin
|
|
|
|
* Reads overrides from the admin_levels.cfg file. Do not compile
|
|
|
|
* this directly.
|
|
|
|
*
|
|
|
|
* SourceMod (C)2004-2008 AlliedModders LLC. All rights reserved.
|
|
|
|
* =============================================================================
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify it under
|
|
|
|
* the terms of the GNU General Public License, version 3.0, as published by the
|
|
|
|
* Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
|
|
|
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
|
|
|
* details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along with
|
|
|
|
* this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
* As a special exception, AlliedModders LLC gives you permission to link the
|
|
|
|
* code of this program (as well as its derivative works) to "Half-Life 2," the
|
|
|
|
* "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
|
|
|
|
* by the Valve Corporation. You must obey the GNU General Public License in
|
|
|
|
* all respects for all other code used. Additionally, AlliedModders LLC grants
|
|
|
|
* this exception to all derivative works. AlliedModders LLC defines further
|
|
|
|
* exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
|
|
|
|
* or <http://www.sourcemod.net/license.php>.
|
|
|
|
*
|
|
|
|
* Version: $Id$
|
|
|
|
*/
|
|
|
|
|
2015-02-17 17:24:46 +01:00
|
|
|
enum OverrideState
|
|
|
|
{
|
|
|
|
OverrideState_None,
|
|
|
|
OverrideState_Levels,
|
|
|
|
OverrideState_Overrides,
|
|
|
|
}
|
2008-03-30 09:00:22 +02:00
|
|
|
|
2014-10-30 04:41:36 +01:00
|
|
|
static SMCParser g_hOldOverrideParser;
|
|
|
|
static SMCParser g_hNewOverrideParser;
|
2015-02-17 17:24:46 +01:00
|
|
|
static OverrideState g_OverrideState = OverrideState_None;
|
2008-03-30 09:00:22 +02:00
|
|
|
|
2014-10-30 04:41:36 +01:00
|
|
|
public SMCResult ReadOldOverrides_NewSection(SMCParser smc, const char[] name, bool opt_quotes)
|
2008-03-30 09:00:22 +02:00
|
|
|
{
|
|
|
|
if (g_IgnoreLevel)
|
|
|
|
{
|
|
|
|
g_IgnoreLevel++;
|
|
|
|
return SMCParse_Continue;
|
|
|
|
}
|
|
|
|
|
2015-02-17 17:24:46 +01:00
|
|
|
if (g_OverrideState == OverrideState_None)
|
2008-03-30 09:00:22 +02:00
|
|
|
{
|
|
|
|
if (StrEqual(name, "Levels"))
|
|
|
|
{
|
2015-02-17 17:24:46 +01:00
|
|
|
g_OverrideState = OverrideState_Levels;
|
2008-03-30 09:00:22 +02:00
|
|
|
} else {
|
|
|
|
g_IgnoreLevel++;
|
|
|
|
}
|
2015-02-17 17:24:46 +01:00
|
|
|
} else if (g_OverrideState == OverrideState_Levels) {
|
2008-03-30 09:00:22 +02:00
|
|
|
if (StrEqual(name, "Overrides"))
|
|
|
|
{
|
2015-02-17 17:24:46 +01:00
|
|
|
g_OverrideState = OverrideState_Overrides;
|
2008-03-30 09:00:22 +02:00
|
|
|
} else {
|
|
|
|
g_IgnoreLevel++;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
g_IgnoreLevel++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return SMCParse_Continue;
|
|
|
|
}
|
|
|
|
|
2014-10-30 04:41:36 +01:00
|
|
|
public SMCResult ReadNewOverrides_NewSection(SMCParser smc, const char[] name, bool opt_quotes)
|
2008-03-30 09:00:22 +02:00
|
|
|
{
|
|
|
|
if (g_IgnoreLevel)
|
|
|
|
{
|
|
|
|
g_IgnoreLevel++;
|
|
|
|
return SMCParse_Continue;
|
|
|
|
}
|
|
|
|
|
2015-02-17 17:24:46 +01:00
|
|
|
if (g_OverrideState == OverrideState_None)
|
2008-03-30 09:00:22 +02:00
|
|
|
{
|
|
|
|
if (StrEqual(name, "Overrides"))
|
|
|
|
{
|
2015-02-17 17:24:46 +01:00
|
|
|
g_OverrideState = OverrideState_Overrides;
|
2008-03-30 09:00:22 +02:00
|
|
|
} else {
|
|
|
|
g_IgnoreLevel++;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
g_IgnoreLevel++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return SMCParse_Continue;
|
|
|
|
}
|
|
|
|
|
2014-10-30 04:41:36 +01:00
|
|
|
public SMCResult ReadOverrides_KeyValue(SMCParser smc,
|
|
|
|
const char[] key,
|
|
|
|
const char[] value,
|
|
|
|
bool key_quotes,
|
|
|
|
bool value_quotes)
|
2008-03-30 09:00:22 +02:00
|
|
|
{
|
2015-02-17 17:24:46 +01:00
|
|
|
if (g_OverrideState != OverrideState_Overrides || g_IgnoreLevel)
|
2008-03-30 09:00:22 +02:00
|
|
|
{
|
|
|
|
return SMCParse_Continue;
|
|
|
|
}
|
|
|
|
|
2014-10-30 04:41:36 +01:00
|
|
|
int flags = ReadFlagString(value);
|
2008-03-30 09:00:22 +02:00
|
|
|
|
|
|
|
if (key[0] == '@')
|
|
|
|
{
|
|
|
|
AddCommandOverride(key[1], Override_CommandGroup, flags);
|
|
|
|
} else {
|
|
|
|
AddCommandOverride(key, Override_Command, flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
return SMCParse_Continue;
|
|
|
|
}
|
|
|
|
|
2014-10-30 04:41:36 +01:00
|
|
|
public SMCResult ReadOldOverrides_EndSection(SMCParser smc)
|
2008-03-30 09:00:22 +02:00
|
|
|
{
|
|
|
|
/* If we're ignoring, skip out */
|
|
|
|
if (g_IgnoreLevel)
|
|
|
|
{
|
|
|
|
g_IgnoreLevel--;
|
|
|
|
return SMCParse_Continue;
|
|
|
|
}
|
|
|
|
|
2015-02-17 17:24:46 +01:00
|
|
|
if (g_OverrideState == OverrideState_Levels)
|
2008-03-30 09:00:22 +02:00
|
|
|
{
|
2015-02-17 17:24:46 +01:00
|
|
|
g_OverrideState = OverrideState_None;
|
|
|
|
} else if (g_OverrideState == OverrideState_Overrides) {
|
2008-03-30 09:00:22 +02:00
|
|
|
/* We're totally done parsing */
|
2015-02-17 17:24:46 +01:00
|
|
|
g_OverrideState = OverrideState_Levels;
|
2008-03-30 09:00:22 +02:00
|
|
|
return SMCParse_Halt;
|
|
|
|
}
|
|
|
|
|
|
|
|
return SMCParse_Continue;
|
|
|
|
}
|
|
|
|
|
2014-10-30 04:41:36 +01:00
|
|
|
public SMCResult ReadNewOverrides_EndSection(SMCParser smc)
|
2008-03-30 09:00:22 +02:00
|
|
|
{
|
|
|
|
/* If we're ignoring, skip out */
|
|
|
|
if (g_IgnoreLevel)
|
|
|
|
{
|
|
|
|
g_IgnoreLevel--;
|
|
|
|
return SMCParse_Continue;
|
|
|
|
}
|
|
|
|
|
2015-02-17 17:24:46 +01:00
|
|
|
if (g_OverrideState == OverrideState_Overrides)
|
2008-03-30 09:00:22 +02:00
|
|
|
{
|
2015-02-17 17:24:46 +01:00
|
|
|
g_OverrideState = OverrideState_None;
|
2008-03-30 09:00:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return SMCParse_Continue;
|
|
|
|
}
|
|
|
|
|
2014-10-30 04:41:36 +01:00
|
|
|
public SMCResult ReadOverrides_CurrentLine(SMCParser smc, const char[] line, int lineno)
|
2008-03-30 09:00:22 +02:00
|
|
|
{
|
|
|
|
g_CurrentLine = lineno;
|
|
|
|
|
|
|
|
return SMCParse_Continue;
|
|
|
|
}
|
|
|
|
|
2015-02-17 17:24:46 +01:00
|
|
|
static void InitializeOverrideParsers()
|
2008-03-30 09:00:22 +02:00
|
|
|
{
|
2014-10-30 04:41:36 +01:00
|
|
|
if (!g_hOldOverrideParser)
|
2008-03-30 09:00:22 +02:00
|
|
|
{
|
2014-12-01 03:57:38 +01:00
|
|
|
g_hOldOverrideParser = new SMCParser();
|
2014-10-30 04:41:36 +01:00
|
|
|
g_hOldOverrideParser.OnEnterSection = ReadOldOverrides_NewSection;
|
|
|
|
g_hOldOverrideParser.OnKeyValue = ReadOverrides_KeyValue;
|
|
|
|
g_hOldOverrideParser.OnLeaveSection = ReadOldOverrides_EndSection;
|
|
|
|
g_hOldOverrideParser.OnRawLine = ReadOverrides_CurrentLine;
|
2008-03-30 09:00:22 +02:00
|
|
|
}
|
2014-10-30 04:41:36 +01:00
|
|
|
if (!g_hNewOverrideParser)
|
2008-03-30 09:00:22 +02:00
|
|
|
{
|
2014-12-01 03:57:38 +01:00
|
|
|
g_hNewOverrideParser = new SMCParser();
|
2014-10-30 04:41:36 +01:00
|
|
|
g_hNewOverrideParser.OnEnterSection = ReadNewOverrides_NewSection;
|
|
|
|
g_hNewOverrideParser.OnKeyValue = ReadOverrides_KeyValue;
|
|
|
|
g_hNewOverrideParser.OnLeaveSection = ReadNewOverrides_EndSection;
|
|
|
|
g_hNewOverrideParser.OnRawLine = ReadOverrides_CurrentLine;
|
2008-03-30 09:00:22 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-02-17 17:24:46 +01:00
|
|
|
void InternalReadOverrides(SMCParser parser, const char[] file)
|
2008-03-30 09:00:22 +02:00
|
|
|
{
|
|
|
|
BuildPath(Path_SM, g_Filename, sizeof(g_Filename), file);
|
|
|
|
|
|
|
|
/* Set states */
|
|
|
|
InitGlobalStates();
|
2015-02-17 17:24:46 +01:00
|
|
|
g_OverrideState = OverrideState_None;
|
2008-03-30 09:00:22 +02:00
|
|
|
|
2014-10-30 04:41:36 +01:00
|
|
|
SMCError err = parser.ParseFile(g_Filename);
|
2008-03-30 09:00:22 +02:00
|
|
|
if (err != SMCError_Okay)
|
|
|
|
{
|
2014-10-30 04:41:36 +01:00
|
|
|
char buffer[64];
|
|
|
|
if (parser.GetErrorString(err, buffer, sizeof(buffer)))
|
2008-03-30 09:00:22 +02:00
|
|
|
{
|
|
|
|
ParseError("%s", buffer);
|
|
|
|
} else {
|
|
|
|
ParseError("Fatal parse error");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-02-17 17:24:46 +01:00
|
|
|
void ReadOverrides()
|
2008-03-30 09:00:22 +02:00
|
|
|
{
|
|
|
|
InitializeOverrideParsers();
|
|
|
|
InternalReadOverrides(g_hOldOverrideParser, "configs/admin_levels.cfg");
|
|
|
|
InternalReadOverrides(g_hNewOverrideParser, "configs/admin_overrides.cfg");
|
|
|
|
}
|