3 * Reads access flags from the admin_levels.cfg file. Do not compile this directly.
4 * This file is part of SourceMod, Copyright (C) 2004-2007 AlliedModders LLC
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23 #define LEVEL_STATE_NONE 0
24 #define LEVEL_STATE_LEVELS 1
25 #define LEVEL_STATE_FLAGS 2
27 static Handle:g_hLevelParser = INVALID_HANDLE;
28 static g_LevelState = LEVEL_STATE_NONE;
30 /* :TODO: log line numbers? */
34 for (new i='t'; i<'z'; i++)
36 g_FlagsSet[i-'a'] = false;
39 g_FlagLetters['a'-'a'] = Admin_Reservation;
40 g_FlagLetters['b'-'a'] = Admin_Generic;
41 g_FlagLetters['c'-'a'] = Admin_Kick;
42 g_FlagLetters['d'-'a'] = Admin_Ban;
43 g_FlagLetters['e'-'a'] = Admin_Unban;
44 g_FlagLetters['f'-'a'] = Admin_Slay;
45 g_FlagLetters['g'-'a'] = Admin_Changemap;
46 g_FlagLetters['h'-'a'] = Admin_Convars;
47 g_FlagLetters['i'-'a'] = Admin_Config;
48 g_FlagLetters['j'-'a'] = Admin_Chat;
49 g_FlagLetters['k'-'a'] = Admin_Vote;
50 g_FlagLetters['l'-'a'] = Admin_Password;
51 g_FlagLetters['m'-'a'] = Admin_RCON;
52 g_FlagLetters['n'-'a'] = Admin_Cheats;
53 g_FlagLetters['o'-'a'] = Admin_Custom1;
54 g_FlagLetters['p'-'a'] = Admin_Custom2;
55 g_FlagLetters['q'-'a'] = Admin_Custom3;
56 g_FlagLetters['r'-'a'] = Admin_Custom4;
57 g_FlagLetters['s'-'a'] = Admin_Custom5;
58 g_FlagLetters['t'-'a'] = Admin_Custom6;
59 g_FlagLetters['z'-'a'] = Admin_Root;
62 public SMCResult:ReadLevels_NewSection(Handle:smc, const String:name[], bool:opt_quotes)
67 return SMCParse_Continue;
70 if (g_LevelState == LEVEL_STATE_NONE)
72 if (StrEqual(name, "Levels"))
74 g_LevelState = LEVEL_STATE_LEVELS;
78 } else if (g_LevelState == LEVEL_STATE_LEVELS) {
79 if (StrEqual(name, "Flags"))
81 g_LevelState = LEVEL_STATE_FLAGS;
89 return SMCParse_Continue;
92 public SMCResult:ReadLevels_KeyValue(Handle:smc, const String:key[], const String:value[], bool:key_quotes, bool:value_quotes)
94 if (g_LevelState == LEVEL_STATE_FLAGS && !g_IgnoreLevel)
98 if (chr < 'a' || chr > 'z')
100 ParseError("Unrecognized character: \"%s\"", value);
101 return SMCParse_Continue;
108 if (StrEqual(key, "reservation"))
110 flag = Admin_Reservation;
111 } else if (StrEqual(key, "kick")) {
113 } else if (StrEqual(key, "generic")) {
114 flag = Admin_Generic;
115 } else if (StrEqual(key, "ban")) {
117 } else if (StrEqual(key, "unban")) {
119 } else if (StrEqual(key, "slay")) {
121 } else if (StrEqual(key, "changemap")) {
122 flag = Admin_Changemap;
123 } else if (StrEqual(key, "cvars")) {
124 flag = Admin_Convars;
125 } else if (StrEqual(key, "config")) {
127 } else if (StrEqual(key, "chat")) {
129 } else if (StrEqual(key, "vote")) {
131 } else if (StrEqual(key, "password")) {
132 flag = Admin_Password;
133 } else if (StrEqual(key, "rcon")) {
135 } else if (StrEqual(key, "cheats")) {
137 } else if (StrEqual(key, "root")) {
139 } else if (StrEqual(key, "custom1")) {
140 flag = Admin_Custom1;
141 } else if (StrEqual(key, "custom2")) {
142 flag = Admin_Custom2;
143 } else if (StrEqual(key, "custom3")) {
144 flag = Admin_Custom3;
145 } else if (StrEqual(key, "custom4")) {
146 flag = Admin_Custom4;
147 } else if (StrEqual(key, "custom5")) {
148 flag = Admin_Custom5;
149 } else if (StrEqual(key, "custom6")) {
150 flag = Admin_Custom6;
152 ParseError("Unrecognized flag type: %s", key);
155 g_FlagLetters[chr] = flag;
156 g_FlagsSet[chr] = true;
159 return SMCParse_Continue;
162 public SMCResult:ReadLevels_EndSection(Handle:smc)
164 /* If we're ignoring, skip out */
168 return SMCParse_Continue;
171 if (g_LevelState == LEVEL_STATE_FLAGS)
173 /* We're totally done parsing */
174 g_LevelState = LEVEL_STATE_LEVELS;
175 return SMCParse_Halt;
176 } else if (g_LevelState == LEVEL_STATE_LEVELS) {
177 g_LevelState = LEVEL_STATE_NONE;
180 return SMCParse_Continue;
183 static InitializeLevelParser()
185 if (g_hLevelParser == INVALID_HANDLE)
187 g_hLevelParser = SMC_CreateParser();
188 SMC_SetReaders(g_hLevelParser,
189 ReadLevels_NewSection,
191 ReadLevels_EndSection);
197 LoadDefaultLetters();
198 InitializeLevelParser();
200 BuildPath(Path_SM, g_Filename, sizeof(g_Filename), "configs/admin_levels.cfg");
204 g_LevelState = LEVEL_STATE_NONE;
206 new SMCError:err = SMC_ParseFile(g_hLevelParser, g_Filename);
207 if (err != SMCError_Okay)
209 decl String:buffer[64];
210 if (SMC_GetErrorString(err, buffer, sizeof(buffer)))
212 ParseError("%s", buffer);
214 ParseError("Fatal parse error");