flag letter assignment is now handled by core
--HG-- extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%401304
This commit is contained in:
@@ -35,14 +35,11 @@ public Plugin:myinfo =
|
||||
};
|
||||
|
||||
/** Various parsing globals */
|
||||
new bool:g_FlagsSet[26]; /* Maps whether flags are set */
|
||||
new AdminFlag:g_FlagLetters[26]; /* Maps the flag letters */
|
||||
new bool:g_LoggedFileName = false; /* Whether or not the file name has been logged */
|
||||
new g_ErrorCount = 0; /* Current error count */
|
||||
new g_IgnoreLevel = 0; /* Nested ignored section count, so users can screw up files safely */
|
||||
new String:g_Filename[PLATFORM_MAX_PATH]; /* Used for error messages */
|
||||
|
||||
#include "admin-levels.sp"
|
||||
#include "admin-overrides.sp"
|
||||
#include "admin-groups.sp"
|
||||
#include "admin-users.sp"
|
||||
@@ -50,7 +47,6 @@ new String:g_Filename[PLATFORM_MAX_PATH]; /* Used for error messages */
|
||||
|
||||
public OnRebuildAdminCache(AdminCachePart:part)
|
||||
{
|
||||
RefreshLevels();
|
||||
if (part == AdminCache_Overrides)
|
||||
{
|
||||
ReadOverrides();
|
||||
|
||||
@@ -92,15 +92,10 @@ public SMCResult:ReadGroups_KeyValue(Handle:smc,
|
||||
new len = strlen(value);
|
||||
for (new i=0; i<len; i++)
|
||||
{
|
||||
if (value[i] < 'a' || value[i] > 'z')
|
||||
if (!FindFlagByChar(value[i], flag))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (!g_FlagsSet[value[i] - 'a'])
|
||||
{
|
||||
continue;
|
||||
}
|
||||
flag = g_FlagLetters[value[i] - 'a'];
|
||||
SetAdmGroupAddFlag(g_CurGrp, flag, true);
|
||||
}
|
||||
} else if (StrEqual(key, "immunity")) {
|
||||
|
||||
@@ -1,217 +0,0 @@
|
||||
/*
|
||||
* admin-levels.sp
|
||||
* Reads access flags from the admin_levels.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.
|
||||
*
|
||||
* Version: $Id$
|
||||
*/
|
||||
|
||||
#define LEVEL_STATE_NONE 0
|
||||
#define LEVEL_STATE_LEVELS 1
|
||||
#define LEVEL_STATE_FLAGS 2
|
||||
|
||||
static Handle:g_hLevelParser = INVALID_HANDLE;
|
||||
static g_LevelState = LEVEL_STATE_NONE;
|
||||
|
||||
/* :TODO: log line numbers? */
|
||||
|
||||
LoadDefaultLetters()
|
||||
{
|
||||
for (new i='t'; i<'z'; i++)
|
||||
{
|
||||
g_FlagsSet[i-'a'] = false;
|
||||
}
|
||||
|
||||
g_FlagLetters['a'-'a'] = Admin_Reservation;
|
||||
g_FlagLetters['b'-'a'] = Admin_Generic;
|
||||
g_FlagLetters['c'-'a'] = Admin_Kick;
|
||||
g_FlagLetters['d'-'a'] = Admin_Ban;
|
||||
g_FlagLetters['e'-'a'] = Admin_Unban;
|
||||
g_FlagLetters['f'-'a'] = Admin_Slay;
|
||||
g_FlagLetters['g'-'a'] = Admin_Changemap;
|
||||
g_FlagLetters['h'-'a'] = Admin_Convars;
|
||||
g_FlagLetters['i'-'a'] = Admin_Config;
|
||||
g_FlagLetters['j'-'a'] = Admin_Chat;
|
||||
g_FlagLetters['k'-'a'] = Admin_Vote;
|
||||
g_FlagLetters['l'-'a'] = Admin_Password;
|
||||
g_FlagLetters['m'-'a'] = Admin_RCON;
|
||||
g_FlagLetters['n'-'a'] = Admin_Cheats;
|
||||
g_FlagLetters['o'-'a'] = Admin_Custom1;
|
||||
g_FlagLetters['p'-'a'] = Admin_Custom2;
|
||||
g_FlagLetters['q'-'a'] = Admin_Custom3;
|
||||
g_FlagLetters['r'-'a'] = Admin_Custom4;
|
||||
g_FlagLetters['s'-'a'] = Admin_Custom5;
|
||||
g_FlagLetters['t'-'a'] = Admin_Custom6;
|
||||
g_FlagLetters['z'-'a'] = Admin_Root;
|
||||
}
|
||||
|
||||
public SMCResult:ReadLevels_NewSection(Handle:smc, const String:name[], bool:opt_quotes)
|
||||
{
|
||||
if (g_IgnoreLevel)
|
||||
{
|
||||
g_IgnoreLevel++;
|
||||
return SMCParse_Continue;
|
||||
}
|
||||
|
||||
if (g_LevelState == LEVEL_STATE_NONE)
|
||||
{
|
||||
if (StrEqual(name, "Levels"))
|
||||
{
|
||||
g_LevelState = LEVEL_STATE_LEVELS;
|
||||
} else {
|
||||
g_IgnoreLevel++;
|
||||
}
|
||||
} else if (g_LevelState == LEVEL_STATE_LEVELS) {
|
||||
if (StrEqual(name, "Flags"))
|
||||
{
|
||||
g_LevelState = LEVEL_STATE_FLAGS;
|
||||
} else {
|
||||
g_IgnoreLevel++;
|
||||
}
|
||||
} else {
|
||||
g_IgnoreLevel++;
|
||||
}
|
||||
|
||||
return SMCParse_Continue;
|
||||
}
|
||||
|
||||
public SMCResult:ReadLevels_KeyValue(Handle:smc, const String:key[], const String:value[], bool:key_quotes, bool:value_quotes)
|
||||
{
|
||||
if (g_LevelState == LEVEL_STATE_FLAGS && !g_IgnoreLevel)
|
||||
{
|
||||
new chr = value[0];
|
||||
|
||||
if (chr < 'a' || chr > 'z')
|
||||
{
|
||||
ParseError("Unrecognized character: \"%s\"", value);
|
||||
return SMCParse_Continue;
|
||||
}
|
||||
|
||||
chr -= 'a';
|
||||
|
||||
new AdminFlag:flag;
|
||||
|
||||
if (StrEqual(key, "reservation"))
|
||||
{
|
||||
flag = Admin_Reservation;
|
||||
} else if (StrEqual(key, "kick")) {
|
||||
flag = Admin_Kick;
|
||||
} else if (StrEqual(key, "generic")) {
|
||||
flag = Admin_Generic;
|
||||
} else if (StrEqual(key, "ban")) {
|
||||
flag = Admin_Ban;
|
||||
} else if (StrEqual(key, "unban")) {
|
||||
flag = Admin_Unban;
|
||||
} else if (StrEqual(key, "slay")) {
|
||||
flag = Admin_Slay;
|
||||
} else if (StrEqual(key, "changemap")) {
|
||||
flag = Admin_Changemap;
|
||||
} else if (StrEqual(key, "cvars")) {
|
||||
flag = Admin_Convars;
|
||||
} else if (StrEqual(key, "config")) {
|
||||
flag = Admin_Config;
|
||||
} else if (StrEqual(key, "chat")) {
|
||||
flag = Admin_Chat;
|
||||
} else if (StrEqual(key, "vote")) {
|
||||
flag = Admin_Vote;
|
||||
} else if (StrEqual(key, "password")) {
|
||||
flag = Admin_Password;
|
||||
} else if (StrEqual(key, "rcon")) {
|
||||
flag = Admin_RCON;
|
||||
} else if (StrEqual(key, "cheats")) {
|
||||
flag = Admin_Cheats;
|
||||
} else if (StrEqual(key, "root")) {
|
||||
flag = Admin_Root;
|
||||
} else if (StrEqual(key, "custom1")) {
|
||||
flag = Admin_Custom1;
|
||||
} else if (StrEqual(key, "custom2")) {
|
||||
flag = Admin_Custom2;
|
||||
} else if (StrEqual(key, "custom3")) {
|
||||
flag = Admin_Custom3;
|
||||
} else if (StrEqual(key, "custom4")) {
|
||||
flag = Admin_Custom4;
|
||||
} else if (StrEqual(key, "custom5")) {
|
||||
flag = Admin_Custom5;
|
||||
} else if (StrEqual(key, "custom6")) {
|
||||
flag = Admin_Custom6;
|
||||
} else {
|
||||
ParseError("Unrecognized flag type: %s", key);
|
||||
}
|
||||
|
||||
g_FlagLetters[chr] = flag;
|
||||
g_FlagsSet[chr] = true;
|
||||
}
|
||||
|
||||
return SMCParse_Continue;
|
||||
}
|
||||
|
||||
public SMCResult:ReadLevels_EndSection(Handle:smc)
|
||||
{
|
||||
/* If we're ignoring, skip out */
|
||||
if (g_IgnoreLevel)
|
||||
{
|
||||
g_IgnoreLevel--;
|
||||
return SMCParse_Continue;
|
||||
}
|
||||
|
||||
if (g_LevelState == LEVEL_STATE_FLAGS)
|
||||
{
|
||||
/* We're totally done parsing */
|
||||
g_LevelState = LEVEL_STATE_LEVELS;
|
||||
return SMCParse_Halt;
|
||||
} else if (g_LevelState == LEVEL_STATE_LEVELS) {
|
||||
g_LevelState = LEVEL_STATE_NONE;
|
||||
}
|
||||
|
||||
return SMCParse_Continue;
|
||||
}
|
||||
|
||||
static InitializeLevelParser()
|
||||
{
|
||||
if (g_hLevelParser == INVALID_HANDLE)
|
||||
{
|
||||
g_hLevelParser = SMC_CreateParser();
|
||||
SMC_SetReaders(g_hLevelParser,
|
||||
ReadLevels_NewSection,
|
||||
ReadLevels_KeyValue,
|
||||
ReadLevels_EndSection);
|
||||
}
|
||||
}
|
||||
|
||||
RefreshLevels()
|
||||
{
|
||||
LoadDefaultLetters();
|
||||
InitializeLevelParser();
|
||||
|
||||
BuildPath(Path_SM, g_Filename, sizeof(g_Filename), "configs/admin_levels.cfg");
|
||||
|
||||
/* Set states */
|
||||
InitGlobalStates();
|
||||
g_LevelState = LEVEL_STATE_NONE;
|
||||
|
||||
new SMCError:err = SMC_ParseFile(g_hLevelParser, g_Filename);
|
||||
if (err != SMCError_Okay)
|
||||
{
|
||||
decl String:buffer[64];
|
||||
if (SMC_GetErrorString(err, buffer, sizeof(buffer)))
|
||||
{
|
||||
ParseError("%s", buffer);
|
||||
} else {
|
||||
ParseError("Fatal parse error");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -69,27 +69,7 @@ public SMCResult:ReadOverrides_KeyValue(Handle:smc,
|
||||
return SMCParse_Continue;
|
||||
}
|
||||
|
||||
new AdminFlag:array[AdminFlags_TOTAL];
|
||||
new flags_total;
|
||||
|
||||
new len = strlen(value);
|
||||
for (new i=0; i<len; i++)
|
||||
{
|
||||
if (value[i] < 'a' || value[i] > 'z')
|
||||
{
|
||||
ParseError("Invalid flag detected: %c", value[i]);
|
||||
continue;
|
||||
}
|
||||
new val = value[i] - 'a';
|
||||
if (!g_FlagsSet[val])
|
||||
{
|
||||
ParseError("Invalid flag detected: %c", value[i]);
|
||||
continue;
|
||||
}
|
||||
array[flags_total++] = g_FlagLetters[val];
|
||||
}
|
||||
|
||||
new flags = FlagArrayToBits(array, flags_total);
|
||||
new flags = ReadFlagString(value);
|
||||
|
||||
if (key[0] == '@')
|
||||
{
|
||||
|
||||
@@ -115,23 +115,19 @@ ReadAdminLine(const String:line[])
|
||||
new bool:is_default = false;
|
||||
for (new i=0; i<len; i++)
|
||||
{
|
||||
if (flags[i] < 'a' || flags[i] > 'z')
|
||||
if (flags[i] == '$')
|
||||
{
|
||||
if (flags[i] == '$')
|
||||
is_default = true;
|
||||
} else {
|
||||
new AdminFlag:flag;
|
||||
|
||||
if (!FindFlagByChar(flags[i], flag))
|
||||
{
|
||||
is_default = true;
|
||||
} else {
|
||||
ParseError("Invalid flag detected: %c", flags[i]);
|
||||
continue;
|
||||
}
|
||||
continue;
|
||||
SetAdminFlag(admin, flag, true);
|
||||
}
|
||||
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)
|
||||
|
||||
@@ -93,21 +93,15 @@ public SMCResult:ReadUsers_KeyValue(Handle:smc,
|
||||
}
|
||||
} else if (StrEqual(key, "flags")) {
|
||||
new len = strlen(value);
|
||||
new AdminFlag:flag;
|
||||
|
||||
for (new i=0; i<len; i++)
|
||||
{
|
||||
if (value[i] < 'a' || value[i] > 'z')
|
||||
if (!FindFlagByChar(value[i], flag))
|
||||
{
|
||||
ParseError("Invalid flag detected: %c", value[i]);
|
||||
continue;
|
||||
}
|
||||
new val = value[i] - 'a';
|
||||
if (!g_FlagsSet[val])
|
||||
{
|
||||
ParseError("Invalid flag detected: %c", value[i]);
|
||||
continue;
|
||||
}
|
||||
SetAdminFlag(g_CurUser, g_FlagLetters[val], true);
|
||||
SetAdminFlag(g_CurUser, flag, true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -488,6 +488,33 @@ native FlagArrayToBits(const AdminFlag:array[], numFlags);
|
||||
*/
|
||||
native FlagBitsToArray(bits, AdminFlag:array[], maxSize);
|
||||
|
||||
/**
|
||||
* Finds a flag by its string name.
|
||||
*
|
||||
* @param name Flag name (like "kick"), case sensitive.
|
||||
* @param flag Variable to store flag in.
|
||||
* @return True on success, false if not found.
|
||||
*/
|
||||
native bool:FindFlagByName(const String:name[], &AdminFlag:flag);
|
||||
|
||||
/**
|
||||
* Finds a flag by a given character.
|
||||
*
|
||||
* @param c Flag ASCII character/token.
|
||||
* @param flag Variable to store flag in.
|
||||
* @return True on success, false if not found.
|
||||
*/
|
||||
native bool:FindFlagByChar(c, &AdminFlag:flag);
|
||||
|
||||
/**
|
||||
* Converts a string of flag characters to a bit string.
|
||||
*
|
||||
* @param flags Flag ASCII string.
|
||||
* @param numchars Optional variable to store the number of bytes read.
|
||||
* @return Bit string of ADMFLAG values.
|
||||
*/
|
||||
native ReadFlagString(const String:flags[], &numchars=0);
|
||||
|
||||
/**
|
||||
* Tests whether one admin can target another.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user