added admin "simple file" parsing
--HG-- extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%40643
This commit is contained in:
@@ -22,6 +22,9 @@
|
||||
#include <sourcemod>
|
||||
#include <textparse>
|
||||
|
||||
/* We like semicolons */
|
||||
#pragma semicolon 1
|
||||
|
||||
public Plugin:myinfo =
|
||||
{
|
||||
name = "Admin File Reader",
|
||||
@@ -43,6 +46,7 @@ new String: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 OnRebuildAdminCache(AdminCachePart:part)
|
||||
{
|
||||
@@ -54,6 +58,7 @@ public OnRebuildAdminCache(AdminCachePart:part)
|
||||
ReadGroups();
|
||||
} else if (part == AdminCache_Admins) {
|
||||
ReadUsers();
|
||||
ReadSimpleUsers();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
static Handle:g_hGroupParser = INVALID_HANDLE;
|
||||
static GroupId:g_CurGrp = INVALID_GROUP_ID;
|
||||
static g_GroupState = GROUP_STATE_NONE;
|
||||
static g_GroupPass = 0
|
||||
static g_GroupPass = 0;
|
||||
static bool:g_NeedReparse = false;
|
||||
|
||||
public SMCResult:ReadGroups_NewSection(Handle:smc, const String:name[], bool:opt_quotes)
|
||||
|
||||
@@ -0,0 +1,132 @@
|
||||
/**
|
||||
* admin-simple.sp
|
||||
* Reads the admins.cfg file. Do not compile this directly.
|
||||
* This file is part of SourceMod, Copyright (C) 2004-2007 AlliedModders LLC
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* 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, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
ReadSimpleUsers()
|
||||
{
|
||||
BuildPath(Path_SM, g_Filename, sizeof(g_Filename), "configs/admins_simple.ini");
|
||||
|
||||
new Handle:file = OpenFile(g_Filename, "rt");
|
||||
if (file == INVALID_HANDLE)
|
||||
{
|
||||
ParseError("Could not open file!");
|
||||
return;
|
||||
}
|
||||
|
||||
while (!IsEndOfFile(file))
|
||||
{
|
||||
decl String:line[255];
|
||||
ReadFileLine(file, line, sizeof(line));
|
||||
|
||||
if ((line[0] == '/' && line[1] == '/')
|
||||
|| (line[0] == ';' || line[0] == '\0'))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
ReadAdminLine(line);
|
||||
}
|
||||
|
||||
CloseHandle(file);
|
||||
}
|
||||
|
||||
ReadAdminLine(const String:line[])
|
||||
{
|
||||
new String:auth[64];
|
||||
new cur_idx = StrBreak(line, auth, sizeof(auth));
|
||||
new idx = cur_idx;
|
||||
|
||||
if (cur_idx == -1)
|
||||
{
|
||||
/* This line is bad... we need at least two parameters */
|
||||
return;
|
||||
}
|
||||
|
||||
/* Create the admin */
|
||||
new AdminId:admin = CreateAdmin(auth);
|
||||
|
||||
/* Read flags */
|
||||
new String:flags[64];
|
||||
cur_idx = StrBreak(line[idx], flags, sizeof(flags));
|
||||
idx += cur_idx;
|
||||
|
||||
if (flags[0] == '@')
|
||||
{
|
||||
new GroupId:gid = FindAdmGroup(flags[1]);
|
||||
if (gid == INVALID_GROUP_ID)
|
||||
{
|
||||
ParseError("Invalid group detected: %s", flags[1]);
|
||||
return;
|
||||
}
|
||||
AdminInheritGroup(admin, gid);
|
||||
} else {
|
||||
new len = strlen(flags);
|
||||
new bool:is_default = false;
|
||||
for (new i=0; i<len; i++)
|
||||
{
|
||||
if (flags[i] < 'a' || flags[i] > 'z')
|
||||
{
|
||||
if (flags[i] == '$')
|
||||
{
|
||||
is_default = true;
|
||||
} else {
|
||||
ParseError("Invalid flag detected: %c", flags[i]);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
new val = flags[i] - 'a';
|
||||
if (!g_FlagsSet[val])
|
||||
{
|
||||
ParseError("Invalid flag detected: %c", flags[i]);
|
||||
continue;
|
||||
}
|
||||
SetAdminFlag(admin, g_FlagLetters[val], true);
|
||||
}
|
||||
|
||||
if (is_default)
|
||||
{
|
||||
new GroupId:gid = FindAdmGroup("Default");
|
||||
if (gid != INVALID_GROUP_ID)
|
||||
{
|
||||
AdminInheritGroup(admin, gid);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Lastly, is there a password? */
|
||||
if (cur_idx != -1)
|
||||
{
|
||||
decl String:password[64];
|
||||
StrBreak(line[idx], password, sizeof(password));
|
||||
SetAdminPassword(admin, password);
|
||||
}
|
||||
|
||||
/* Now, bind the identity to something */
|
||||
if (StrContains(auth, "STEAM_") == 0)
|
||||
{
|
||||
BindAdminIdentity(admin, AUTHMETHOD_STEAM, auth);
|
||||
} else {
|
||||
if (auth[0] == '!')
|
||||
{
|
||||
BindAdminIdentity(admin, AUTHMETHOD_IP, auth[1]);
|
||||
} else {
|
||||
BindAdminIdentity(admin, AUTHMETHOD_NAME, auth);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user