fixed a bug where the JIT initiated the optimized stack top boundary check with a doubly relocated address, causing a rare bug with stack operations
3 * Reads the admin_groups.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.
21 #define GROUP_STATE_NONE 0
22 #define GROUP_STATE_GROUPS 1
23 #define GROUP_STATE_INGROUP 2
24 #define GROUP_STATE_OVERRIDES 3
25 #define GROUP_PASS_FIRST 1
26 #define GROUP_PASS_SECOND 2
28 static Handle:g_hGroupParser = INVALID_HANDLE;
29 static GroupId:g_CurGrp = INVALID_GROUP_ID;
30 static g_GroupState = GROUP_STATE_NONE;
31 static g_GroupPass = 0;
32 static bool:g_NeedReparse = false;
34 public SMCResult:ReadGroups_NewSection(Handle:smc, const String:name[], bool:opt_quotes)
39 return SMCParse_Continue;
42 if (g_GroupState == GROUP_STATE_NONE)
44 if (StrEqual(name, "Groups"))
46 g_GroupState = GROUP_STATE_GROUPS;
50 } else if (g_GroupState == GROUP_STATE_GROUPS) {
51 if ((g_CurGrp = CreateAdmGroup(name)) == INVALID_GROUP_ID)
53 g_CurGrp = FindAdmGroup(name);
55 g_GroupState = GROUP_STATE_INGROUP;
56 } else if (g_GroupState == GROUP_STATE_INGROUP) {
57 if (StrEqual(name, "Overrides"))
59 g_GroupState = GROUP_STATE_OVERRIDES;
67 return SMCParse_Continue;
70 public SMCResult:ReadGroups_KeyValue(Handle:smc,
76 if (g_CurGrp == INVALID_GROUP_ID
79 return SMCParse_Continue;
84 if (g_GroupPass == GROUP_PASS_FIRST)
86 if (g_GroupState == GROUP_STATE_INGROUP)
88 if (StrEqual(key, "flags"))
90 new len = strlen(value);
91 for (new i=0; i<len; i++)
93 if (value[i] < 'a' || value[i] > 'z')
97 if (!g_FlagsSet[value[i] - 'a'])
101 flag = g_FlagLetters[value[i] - 'a'];
102 SetAdmGroupAddFlag(g_CurGrp, flag, true);
104 } else if (StrEqual(key, "immunity")) {
105 /* If it's a value we know about, use it */
106 if (StrEqual(value, "*"))
108 SetAdmGroupImmunity(g_CurGrp, Immunity_Global, true);
109 } else if (StrEqual(value, "$")) {
110 SetAdmGroupImmunity(g_CurGrp, Immunity_Default, true);
112 /* If we can't find the group, we'll need to schedule a reparse */
113 new GroupId:id = FindAdmGroup(value);
114 if (id != INVALID_GROUP_ID)
116 SetAdmGroupImmuneFrom(g_CurGrp, id);
118 g_NeedReparse = true;
122 } else if (g_GroupState == GROUP_STATE_OVERRIDES) {
123 new OverrideRule:rule = Command_Deny;
125 if (StrEqual(value, "allow", false))
127 rule = Command_Allow;
132 AddAdmGroupCmdOverride(g_CurGrp, key[1], Override_CommandGroup, rule);
134 AddAdmGroupCmdOverride(g_CurGrp, key, Override_Command, rule);
137 } else if (g_GroupPass == GROUP_PASS_SECOND
138 && g_GroupState == GROUP_STATE_INGROUP) {
139 /* Check for immunity again, core should handle double inserts */
140 if (StrEqual(key, "immunity"))
142 new GroupId:id = FindAdmGroup(value);
143 if (id != INVALID_GROUP_ID)
145 SetAdmGroupImmuneFrom(g_CurGrp, id);
147 ParseError("Unable to find group: \"%s\"", value);
152 return SMCParse_Continue;
155 public SMCResult:ReadGroups_EndSection(Handle:smc)
157 /* If we're ignoring, skip out */
161 return SMCParse_Continue;
164 if (g_GroupState == GROUP_STATE_OVERRIDES)
166 g_GroupState = GROUP_STATE_INGROUP;
167 } else if (g_GroupState == GROUP_STATE_INGROUP) {
168 g_GroupState = GROUP_STATE_GROUPS;
169 g_CurGrp = INVALID_GROUP_ID;
170 } else if (g_GroupState == GROUP_STATE_GROUPS) {
171 g_GroupState = GROUP_STATE_NONE;
174 return SMCParse_Continue;
177 static InitializeGroupParser()
179 if (g_hGroupParser == INVALID_HANDLE)
181 g_hGroupParser = SMC_CreateParser();
182 SMC_SetReaders(g_hGroupParser,
183 ReadGroups_NewSection,
185 ReadGroups_EndSection);
189 static InternalReadGroups(const String:path[], pass)
193 g_GroupState = GROUP_STATE_NONE;
194 g_CurGrp = INVALID_GROUP_ID;
196 g_NeedReparse = false;
198 new SMCError:err = SMC_ParseFile(g_hGroupParser, path);
199 if (err != SMCError_Okay)
201 decl String:buffer[64];
202 if (SMC_GetErrorString(err, buffer, sizeof(buffer)))
204 ParseError("%s", buffer);
206 ParseError("Fatal parse error");
213 InitializeGroupParser();
215 BuildPath(Path_SM, g_Filename, sizeof(g_Filename), "configs/admin_groups.cfg");
217 InternalReadGroups(g_Filename, GROUP_PASS_FIRST);
220 InternalReadGroups(g_Filename, GROUP_PASS_SECOND);