fixed a bug where HandleSecurity was not initialized properly for the datapack natives
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.
23 #define GROUP_STATE_NONE 0
24 #define GROUP_STATE_GROUPS 1
25 #define GROUP_STATE_INGROUP 2
26 #define GROUP_STATE_OVERRIDES 3
27 #define GROUP_PASS_FIRST 1
28 #define GROUP_PASS_SECOND 2
30 static Handle:g_hGroupParser = INVALID_HANDLE;
31 static GroupId:g_CurGrp = INVALID_GROUP_ID;
32 static g_GroupState = GROUP_STATE_NONE;
33 static g_GroupPass = 0;
34 static bool:g_NeedReparse = false;
36 public SMCResult:ReadGroups_NewSection(Handle:smc, const String:name[], bool:opt_quotes)
41 return SMCParse_Continue;
44 if (g_GroupState == GROUP_STATE_NONE)
46 if (StrEqual(name, "Groups"))
48 g_GroupState = GROUP_STATE_GROUPS;
52 } else if (g_GroupState == GROUP_STATE_GROUPS) {
53 if ((g_CurGrp = CreateAdmGroup(name)) == INVALID_GROUP_ID)
55 g_CurGrp = FindAdmGroup(name);
57 g_GroupState = GROUP_STATE_INGROUP;
58 } else if (g_GroupState == GROUP_STATE_INGROUP) {
59 if (StrEqual(name, "Overrides"))
61 g_GroupState = GROUP_STATE_OVERRIDES;
69 return SMCParse_Continue;
72 public SMCResult:ReadGroups_KeyValue(Handle:smc,
78 if (g_CurGrp == INVALID_GROUP_ID
81 return SMCParse_Continue;
86 if (g_GroupPass == GROUP_PASS_FIRST)
88 if (g_GroupState == GROUP_STATE_INGROUP)
90 if (StrEqual(key, "flags"))
92 new len = strlen(value);
93 for (new i=0; i<len; i++)
95 if (value[i] < 'a' || value[i] > 'z')
99 if (!g_FlagsSet[value[i] - 'a'])
103 flag = g_FlagLetters[value[i] - 'a'];
104 SetAdmGroupAddFlag(g_CurGrp, flag, true);
106 } else if (StrEqual(key, "immunity")) {
107 /* If it's a value we know about, use it */
108 if (StrEqual(value, "*"))
110 SetAdmGroupImmunity(g_CurGrp, Immunity_Global, true);
111 } else if (StrEqual(value, "$")) {
112 SetAdmGroupImmunity(g_CurGrp, Immunity_Default, true);
114 /* If we can't find the group, we'll need to schedule a reparse */
115 new GroupId:id = FindAdmGroup(value);
116 if (id != INVALID_GROUP_ID)
118 SetAdmGroupImmuneFrom(g_CurGrp, id);
120 g_NeedReparse = true;
124 } else if (g_GroupState == GROUP_STATE_OVERRIDES) {
125 new OverrideRule:rule = Command_Deny;
127 if (StrEqual(value, "allow", false))
129 rule = Command_Allow;
134 AddAdmGroupCmdOverride(g_CurGrp, key[1], Override_CommandGroup, rule);
136 AddAdmGroupCmdOverride(g_CurGrp, key, Override_Command, rule);
139 } else if (g_GroupPass == GROUP_PASS_SECOND
140 && g_GroupState == GROUP_STATE_INGROUP) {
141 /* Check for immunity again, core should handle double inserts */
142 if (StrEqual(key, "immunity"))
144 new GroupId:id = FindAdmGroup(value);
145 if (id != INVALID_GROUP_ID)
147 SetAdmGroupImmuneFrom(g_CurGrp, id);
149 ParseError("Unable to find group: \"%s\"", value);
154 return SMCParse_Continue;
157 public SMCResult:ReadGroups_EndSection(Handle:smc)
159 /* If we're ignoring, skip out */
163 return SMCParse_Continue;
166 if (g_GroupState == GROUP_STATE_OVERRIDES)
168 g_GroupState = GROUP_STATE_INGROUP;
169 } else if (g_GroupState == GROUP_STATE_INGROUP) {
170 g_GroupState = GROUP_STATE_GROUPS;
171 g_CurGrp = INVALID_GROUP_ID;
172 } else if (g_GroupState == GROUP_STATE_GROUPS) {
173 g_GroupState = GROUP_STATE_NONE;
176 return SMCParse_Continue;
179 static InitializeGroupParser()
181 if (g_hGroupParser == INVALID_HANDLE)
183 g_hGroupParser = SMC_CreateParser();
184 SMC_SetReaders(g_hGroupParser,
185 ReadGroups_NewSection,
187 ReadGroups_EndSection);
191 static InternalReadGroups(const String:path[], pass)
195 g_GroupState = GROUP_STATE_NONE;
196 g_CurGrp = INVALID_GROUP_ID;
198 g_NeedReparse = false;
200 new SMCError:err = SMC_ParseFile(g_hGroupParser, path);
201 if (err != SMCError_Okay)
203 decl String:buffer[64];
204 if (SMC_GetErrorString(err, buffer, sizeof(buffer)))
206 ParseError("%s", buffer);
208 ParseError("Fatal parse error");
215 InitializeGroupParser();
217 BuildPath(Path_SM, g_Filename, sizeof(g_Filename), "configs/admin_groups.cfg");
219 InternalReadGroups(g_Filename, GROUP_PASS_FIRST);
222 InternalReadGroups(g_Filename, GROUP_PASS_SECOND);