Initial commit

This commit is contained in:
2025-04-15 22:27:20 -04:00
parent 5b7b68f81f
commit 771d8fe8e8
597 changed files with 149544 additions and 0 deletions

View File

@@ -0,0 +1,96 @@
/**
* vim: set ts=4 :
* =============================================================================
* SourceMod Admin File Reader Plugin
* Manages the standard flat files for admins. This is the file to compile.
*
* 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$
*/
/* We like semicolons */
#pragma semicolon 1
#include <sourcemod>
public Plugin myinfo =
{
name = "Admin File Reader",
author = "AlliedModders LLC",
description = "Reads admin files",
version = SOURCEMOD_VERSION,
url = "http://www.sourcemod.net/"
};
/** Various parsing globals */
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 void OnRebuildAdminCache(AdminCachePart part)
{
if (part == AdminCache_Overrides)
{
ReadOverrides();
} else if (part == AdminCache_Groups) {
ReadGroups();
} else if (part == AdminCache_Admins) {
ReadUsers();
ReadSimpleUsers();
}
}
void ParseError(const char[] format, any ...)
{
char buffer[512];
if (!g_LoggedFileName)
{
LogError("Error(s) detected parsing %s", g_Filename);
g_LoggedFileName = true;
}
VFormat(buffer, sizeof(buffer), format, 2);
LogError(" (line %d) %s", g_CurrentLine, buffer);
g_ErrorCount++;
}
void InitGlobalStates()
{
g_ErrorCount = 0;
g_IgnoreLevel = 0;
g_CurrentLine = 0;
g_LoggedFileName = false;
}

View File

@@ -0,0 +1,249 @@
/**
* vim: set ts=4 sw=4 tw=99 noet :
* =============================================================================
* SourceMod Admin File Reader Plugin
* Reads the admin_groups.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$
*/
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 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)
{
if (g_IgnoreLevel)
{
g_IgnoreLevel++;
return SMCParse_Continue;
}
if (g_GroupState == GroupState_None)
{
if (StrEqual(name, "Groups"))
{
g_GroupState = GroupState_Groups;
} else {
g_IgnoreLevel++;
}
} else if (g_GroupState == GroupState_Groups) {
if ((g_CurGrp = CreateAdmGroup(name)) == INVALID_GROUP_ID)
{
g_CurGrp = FindAdmGroup(name);
}
g_GroupState = GroupState_InGroup;
} else if (g_GroupState == GroupState_InGroup) {
if (StrEqual(name, "Overrides"))
{
g_GroupState = GroupState_Overrides;
} else {
g_IgnoreLevel++;
}
} else {
g_IgnoreLevel++;
}
return SMCParse_Continue;
}
public SMCResult ReadGroups_KeyValue(SMCParser smc,
const char[] key,
const char[] value,
bool key_quotes,
bool value_quotes)
{
if (g_CurGrp == INVALID_GROUP_ID || g_IgnoreLevel)
{
return SMCParse_Continue;
}
AdminFlag flag;
if (g_GroupPass == GroupPass_First)
{
if (g_GroupState == GroupState_InGroup)
{
if (StrEqual(key, "flags"))
{
int len = strlen(value);
for (int i=0; i<len; i++)
{
if (!FindFlagByChar(value[i], flag))
{
continue;
}
g_CurGrp.SetFlag(flag, true);
}
} else if (StrEqual(key, "immunity")) {
g_NeedReparse = true;
}
} else if (g_GroupState == GroupState_Overrides) {
OverrideRule rule = Command_Deny;
if (StrEqual(value, "allow", false))
{
rule = Command_Allow;
}
if (key[0] == '@')
{
g_CurGrp.AddCommandOverride(key[1], Override_CommandGroup, rule);
} else {
g_CurGrp.AddCommandOverride(key, Override_Command, rule);
}
}
} else if (g_GroupPass == GroupPass_Second
&& g_GroupState == GroupState_InGroup) {
/* Check for immunity again, core should handle double inserts */
if (StrEqual(key, "immunity"))
{
/* If it's a value we know about, use it */
if (StrEqual(value, "*"))
{
g_CurGrp.ImmunityLevel = 2;
} else if (StrEqual(value, "$")) {
g_CurGrp.ImmunityLevel = 1;
} else {
int level;
if (StringToIntEx(value, level))
{
g_CurGrp.ImmunityLevel = level;
} else {
GroupId id;
if (value[0] == '@')
{
id = FindAdmGroup(value[1]);
} else {
id = FindAdmGroup(value);
}
if (id != INVALID_GROUP_ID)
{
g_CurGrp.AddGroupImmunity(id);
} else {
ParseError("Unable to find group: \"%s\"", value);
}
}
}
}
}
return SMCParse_Continue;
}
public SMCResult ReadGroups_EndSection(SMCParser smc)
{
/* If we're ignoring, skip out */
if (g_IgnoreLevel)
{
g_IgnoreLevel--;
return SMCParse_Continue;
}
if (g_GroupState == GroupState_Overrides)
{
g_GroupState = GroupState_InGroup;
} else if (g_GroupState == GroupState_InGroup) {
g_GroupState = GroupState_Groups;
g_CurGrp = INVALID_GROUP_ID;
} else if (g_GroupState == GroupState_Groups) {
g_GroupState = GroupState_None;
}
return SMCParse_Continue;
}
public SMCResult ReadGroups_CurrentLine(SMCParser smc, const char[] line, int lineno)
{
g_CurrentLine = lineno;
return SMCParse_Continue;
}
static void InitializeGroupParser()
{
if (!g_hGroupParser)
{
g_hGroupParser = new SMCParser();
g_hGroupParser.OnEnterSection = ReadGroups_NewSection;
g_hGroupParser.OnKeyValue = ReadGroups_KeyValue;
g_hGroupParser.OnLeaveSection = ReadGroups_EndSection;
g_hGroupParser.OnRawLine = ReadGroups_CurrentLine;
}
}
static void InternalReadGroups(const char[] path, GroupPass pass)
{
/* Set states */
InitGlobalStates();
g_GroupState = GroupState_None;
g_CurGrp = INVALID_GROUP_ID;
g_GroupPass = pass;
g_NeedReparse = false;
SMCError err = g_hGroupParser.ParseFile(path);
if (err != SMCError_Okay)
{
char buffer[64];
if (g_hGroupParser.GetErrorString(err, buffer, sizeof(buffer)))
{
ParseError("%s", buffer);
} else {
ParseError("Fatal parse error");
}
}
}
void ReadGroups()
{
InitializeGroupParser();
BuildPath(Path_SM, g_Filename, sizeof(g_Filename), "configs/admin_groups.cfg");
InternalReadGroups(g_Filename, GroupPass_First);
if (g_NeedReparse)
{
InternalReadGroups(g_Filename, GroupPass_Second);
}
}

View File

@@ -0,0 +1,213 @@
/**
* 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$
*/
enum OverrideState
{
OverrideState_None,
OverrideState_Levels,
OverrideState_Overrides,
}
static SMCParser g_hOldOverrideParser;
static SMCParser g_hNewOverrideParser;
static OverrideState g_OverrideState = OverrideState_None;
public SMCResult ReadOldOverrides_NewSection(SMCParser smc, const char[] name, bool opt_quotes)
{
if (g_IgnoreLevel)
{
g_IgnoreLevel++;
return SMCParse_Continue;
}
if (g_OverrideState == OverrideState_None)
{
if (StrEqual(name, "Levels"))
{
g_OverrideState = OverrideState_Levels;
} else {
g_IgnoreLevel++;
}
} else if (g_OverrideState == OverrideState_Levels) {
if (StrEqual(name, "Overrides"))
{
g_OverrideState = OverrideState_Overrides;
} else {
g_IgnoreLevel++;
}
} else {
g_IgnoreLevel++;
}
return SMCParse_Continue;
}
public SMCResult ReadNewOverrides_NewSection(SMCParser smc, const char[] name, bool opt_quotes)
{
if (g_IgnoreLevel)
{
g_IgnoreLevel++;
return SMCParse_Continue;
}
if (g_OverrideState == OverrideState_None)
{
if (StrEqual(name, "Overrides"))
{
g_OverrideState = OverrideState_Overrides;
} else {
g_IgnoreLevel++;
}
} else {
g_IgnoreLevel++;
}
return SMCParse_Continue;
}
public SMCResult ReadOverrides_KeyValue(SMCParser smc,
const char[] key,
const char[] value,
bool key_quotes,
bool value_quotes)
{
if (g_OverrideState != OverrideState_Overrides || g_IgnoreLevel)
{
return SMCParse_Continue;
}
int flags = ReadFlagString(value);
if (key[0] == '@')
{
AddCommandOverride(key[1], Override_CommandGroup, flags);
} else {
AddCommandOverride(key, Override_Command, flags);
}
return SMCParse_Continue;
}
public SMCResult ReadOldOverrides_EndSection(SMCParser smc)
{
/* If we're ignoring, skip out */
if (g_IgnoreLevel)
{
g_IgnoreLevel--;
return SMCParse_Continue;
}
if (g_OverrideState == OverrideState_Levels)
{
g_OverrideState = OverrideState_None;
} else if (g_OverrideState == OverrideState_Overrides) {
/* We're totally done parsing */
g_OverrideState = OverrideState_Levels;
return SMCParse_Halt;
}
return SMCParse_Continue;
}
public SMCResult ReadNewOverrides_EndSection(SMCParser smc)
{
/* If we're ignoring, skip out */
if (g_IgnoreLevel)
{
g_IgnoreLevel--;
return SMCParse_Continue;
}
if (g_OverrideState == OverrideState_Overrides)
{
g_OverrideState = OverrideState_None;
}
return SMCParse_Continue;
}
public SMCResult ReadOverrides_CurrentLine(SMCParser smc, const char[] line, int lineno)
{
g_CurrentLine = lineno;
return SMCParse_Continue;
}
static void InitializeOverrideParsers()
{
if (!g_hOldOverrideParser)
{
g_hOldOverrideParser = new SMCParser();
g_hOldOverrideParser.OnEnterSection = ReadOldOverrides_NewSection;
g_hOldOverrideParser.OnKeyValue = ReadOverrides_KeyValue;
g_hOldOverrideParser.OnLeaveSection = ReadOldOverrides_EndSection;
g_hOldOverrideParser.OnRawLine = ReadOverrides_CurrentLine;
}
if (!g_hNewOverrideParser)
{
g_hNewOverrideParser = new SMCParser();
g_hNewOverrideParser.OnEnterSection = ReadNewOverrides_NewSection;
g_hNewOverrideParser.OnKeyValue = ReadOverrides_KeyValue;
g_hNewOverrideParser.OnLeaveSection = ReadNewOverrides_EndSection;
g_hNewOverrideParser.OnRawLine = ReadOverrides_CurrentLine;
}
}
void InternalReadOverrides(SMCParser parser, const char[] file)
{
BuildPath(Path_SM, g_Filename, sizeof(g_Filename), file);
/* Set states */
InitGlobalStates();
g_OverrideState = OverrideState_None;
SMCError err = parser.ParseFile(g_Filename);
if (err != SMCError_Okay)
{
char buffer[64];
if (parser.GetErrorString(err, buffer, sizeof(buffer)))
{
ParseError("%s", buffer);
} else {
ParseError("Fatal parse error");
}
}
}
void ReadOverrides()
{
InitializeOverrideParsers();
InternalReadOverrides(g_hOldOverrideParser, "configs/admin_levels.cfg");
InternalReadOverrides(g_hNewOverrideParser, "configs/admin_overrides.cfg");
}

View File

@@ -0,0 +1,224 @@
/**
* vim: set ts=4 :
* =============================================================================
* SourceMod Admin File Reader Plugin
* Reads the admins.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$
*/
public void ReadSimpleUsers()
{
BuildPath(Path_SM, g_Filename, sizeof(g_Filename), "configs/admins_simple.ini");
File file = OpenFile(g_Filename, "rt");
if (!file)
{
ParseError("Could not open file!");
return;
}
while (!file.EndOfFile())
{
char line[255];
if (!file.ReadLine(line, sizeof(line)))
break;
/* Trim comments */
int len = strlen(line);
bool ignoring = false;
for (int i=0; i<len; i++)
{
if (ignoring)
{
if (line[i] == '"')
ignoring = false;
} else {
if (line[i] == '"')
{
ignoring = true;
} else if (line[i] == ';') {
line[i] = '\0';
break;
} else if (line[i] == '/'
&& i != len - 1
&& line[i+1] == '/')
{
line[i] = '\0';
break;
}
}
}
TrimString(line);
if ((line[0] == '/' && line[1] == '/')
|| (line[0] == ';' || line[0] == '\0'))
{
continue;
}
ReadAdminLine(line);
}
file.Close();
}
void DecodeAuthMethod(const char[] auth, char method[32], int &offset)
{
if ((StrContains(auth, "STEAM_") == 0) || (strncmp("0:", auth, 2) == 0) || (strncmp("1:", auth, 2) == 0))
{
// Steam2 Id
strcopy(method, sizeof(method), AUTHMETHOD_STEAM);
offset = 0;
}
else if (!strncmp(auth, "[U:", 3) && auth[strlen(auth) - 1] == ']')
{
// Steam3 Id
strcopy(method, sizeof(method), AUTHMETHOD_STEAM);
offset = 0;
}
else
{
if (auth[0] == '!')
{
strcopy(method, sizeof(method), AUTHMETHOD_IP);
offset = 1;
}
else
{
strcopy(method, sizeof(method), AUTHMETHOD_NAME);
offset = 0;
}
}
}
void ReadAdminLine(const char[] line)
{
bool is_bound;
AdminId admin;
char auth[64];
char auth_method[32];
int idx, cur_idx, auth_offset;
if ((cur_idx = BreakString(line, auth, sizeof(auth))) == -1)
{
/* This line is bad... we need at least two parameters */
return;
}
idx = cur_idx;
/* Check if we can bind beforehand */
DecodeAuthMethod(auth, auth_method, auth_offset);
if ((admin = FindAdminByIdentity(auth_method, auth[auth_offset])) == INVALID_ADMIN_ID)
{
/* There is no binding, create the admin */
admin = CreateAdmin();
}
else
{
is_bound = true;
}
/* Read flags */
char flags[64];
cur_idx = BreakString(line[idx], flags, sizeof(flags));
idx += cur_idx;
/* Read immunity level, if any */
int level, flag_idx;
if ((flag_idx = StringToIntEx(flags, level)) > 0)
{
admin.ImmunityLevel = level;
if (flags[flag_idx] == ':')
{
flag_idx++;
}
}
if (flags[flag_idx] == '@')
{
GroupId gid = FindAdmGroup(flags[flag_idx + 1]);
if (gid == INVALID_GROUP_ID)
{
ParseError("Invalid group detected: %s", flags[flag_idx + 1]);
return;
}
admin.InheritGroup(gid);
}
else
{
int len = strlen(flags[flag_idx]);
bool is_default = false;
for (int i=0; i<len; i++)
{
if (!level && flags[flag_idx + i] == '$')
{
admin.ImmunityLevel = 1;
} else {
AdminFlag flag;
if (!FindFlagByChar(flags[flag_idx + i], flag))
{
ParseError("Invalid flag detected: %c", flags[flag_idx + i]);
continue;
}
admin.SetFlag(flag, true);
}
}
if (is_default)
{
GroupId gid = FindAdmGroup("Default");
if (gid != INVALID_GROUP_ID)
{
admin.InheritGroup(gid);
}
}
}
/* Lastly, is there a password? */
if (cur_idx != -1)
{
char password[64];
BreakString(line[idx], password, sizeof(password));
admin.SetPassword(password);
}
/* Now, bind the identity to something */
if (!is_bound)
{
if (!admin.BindIdentity(auth_method, auth[auth_offset]))
{
/* We should never reach here */
RemoveAdmin(admin);
ParseError("Failed to bind identity %s (method %s)", auth[auth_offset], auth_method);
}
}
}

View File

@@ -0,0 +1,252 @@
/**
* vim: set ts=4 sw=4 tw=99 noet :
* =============================================================================
* SourceMod Admin File Reader Plugin
* Reads the admins.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$
*/
enum UserState
{
UserState_None,
UserState_Admins,
UserState_InAdmin,
}
static SMCParser g_hUserParser;
static UserState g_UserState = UserState_None;
static char g_CurAuth[64];
static char g_CurIdent[64];
static char g_CurName[64];
static char g_CurPass[64];
static ArrayList g_GroupArray;
static int g_CurFlags;
static int g_CurImmunity;
public SMCResult ReadUsers_NewSection(SMCParser smc, const char[] name, bool opt_quotes)
{
if (g_IgnoreLevel)
{
g_IgnoreLevel++;
return SMCParse_Continue;
}
if (g_UserState == UserState_None)
{
if (StrEqual(name, "Admins"))
{
g_UserState = UserState_Admins;
}
else
{
g_IgnoreLevel++;
}
}
else if (g_UserState == UserState_Admins)
{
g_UserState = UserState_InAdmin;
strcopy(g_CurName, sizeof(g_CurName), name);
g_CurAuth[0] = '\0';
g_CurIdent[0] = '\0';
g_CurPass[0] = '\0';
g_GroupArray.Clear();
g_CurFlags = 0;
g_CurImmunity = 0;
}
else
{
g_IgnoreLevel++;
}
return SMCParse_Continue;
}
public SMCResult ReadUsers_KeyValue(SMCParser smc,
const char[] key,
const char[] value,
bool key_quotes,
bool value_quotes)
{
if (g_UserState != UserState_InAdmin || g_IgnoreLevel)
{
return SMCParse_Continue;
}
if (StrEqual(key, "auth"))
{
strcopy(g_CurAuth, sizeof(g_CurAuth), value);
}
else if (StrEqual(key, "identity"))
{
strcopy(g_CurIdent, sizeof(g_CurIdent), value);
}
else if (StrEqual(key, "password"))
{
strcopy(g_CurPass, sizeof(g_CurPass), value);
}
else if (StrEqual(key, "group"))
{
GroupId id = FindAdmGroup(value);
if (id == INVALID_GROUP_ID)
{
ParseError("Unknown group \"%s\"", value);
}
g_GroupArray.Push(id);
}
else if (StrEqual(key, "flags"))
{
int len = strlen(value);
AdminFlag flag;
for (int i = 0; i < len; i++)
{
if (!FindFlagByChar(value[i], flag))
{
ParseError("Invalid flag detected: %c", value[i]);
}
else
{
g_CurFlags |= FlagToBit(flag);
}
}
}
else if (StrEqual(key, "immunity"))
{
g_CurImmunity = StringToInt(value);
}
return SMCParse_Continue;
}
public SMCResult ReadUsers_EndSection(SMCParser smc)
{
if (g_IgnoreLevel)
{
g_IgnoreLevel--;
return SMCParse_Continue;
}
if (g_UserState == UserState_InAdmin)
{
/* Dump this user to memory */
if (g_CurIdent[0] != '\0' && g_CurAuth[0] != '\0')
{
AdminFlag flags[26];
AdminId id;
int i, num_groups, num_flags;
if ((id = FindAdminByIdentity(g_CurAuth, g_CurIdent)) == INVALID_ADMIN_ID)
{
id = CreateAdmin(g_CurName);
if (!id.BindIdentity(g_CurAuth, g_CurIdent))
{
RemoveAdmin(id);
ParseError("Failed to bind auth \"%s\" to identity \"%s\"", g_CurAuth, g_CurIdent);
return SMCParse_Continue;
}
}
num_groups = g_GroupArray.Length;
for (i = 0; i < num_groups; i++)
{
id.InheritGroup(g_GroupArray.Get(i));
}
id.SetPassword(g_CurPass);
if (id.ImmunityLevel < g_CurImmunity)
{
id.ImmunityLevel = g_CurImmunity;
}
num_flags = FlagBitsToArray(g_CurFlags, flags, sizeof(flags));
for (i = 0; i < num_flags; i++)
{
id.SetFlag(flags[i], true);
}
}
else
{
ParseError("Failed to create admin: did you forget either the auth or identity properties?");
}
g_UserState = UserState_Admins;
}
else if (g_UserState == UserState_Admins)
{
g_UserState = UserState_None;
}
return SMCParse_Continue;
}
public SMCResult ReadUsers_CurrentLine(SMCParser smc, const char[] line, int lineno)
{
g_CurrentLine = lineno;
return SMCParse_Continue;
}
static void InitializeUserParser()
{
if (!g_hUserParser)
{
g_hUserParser = new SMCParser();
g_hUserParser.OnEnterSection = ReadUsers_NewSection;
g_hUserParser.OnKeyValue = ReadUsers_KeyValue;
g_hUserParser.OnLeaveSection = ReadUsers_EndSection;
g_hUserParser.OnRawLine = ReadUsers_CurrentLine;
g_GroupArray = new ArrayList();
}
}
void ReadUsers()
{
InitializeUserParser();
BuildPath(Path_SM, g_Filename, sizeof(g_Filename), "configs/admins.cfg");
/* Set states */
InitGlobalStates();
g_UserState = UserState_None;
SMCError err = g_hUserParser.ParseFile(g_Filename);
if (err != SMCError_Okay)
{
char buffer[64];
if (g_hUserParser.GetErrorString(err, buffer, sizeof(buffer)))
{
ParseError("%s", buffer);
}
else
{
ParseError("Fatal parse error");
}
}
}