Added a load-block for incorrect mods to TF2 and cstrike extensions.
3 * =============================================================================
4 * SourceMod Admin File Reader Plugin
5 * Reads the admin_groups.cfg file. Do not compile this directly.
7 * SourceMod (C)2004-2008 AlliedModders LLC. All rights reserved.
8 * =============================================================================
10 * This program is free software; you can redistribute it and/or modify it under
11 * the terms of the GNU General Public License, version 3.0, as published by the
12 * Free Software Foundation.
14 * This program is distributed in the hope that it will be useful, but WITHOUT
15 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
19 * You should have received a copy of the GNU General Public License along with
20 * this program. If not, see <http://www.gnu.org/licenses/>.
22 * As a special exception, AlliedModders LLC gives you permission to link the
23 * code of this program (as well as its derivative works) to "Half-Life 2," the
24 * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
25 * by the Valve Corporation. You must obey the GNU General Public License in
26 * all respects for all other code used. Additionally, AlliedModders LLC grants
27 * this exception to all derivative works. AlliedModders LLC defines further
28 * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
29 * or <http://www.sourcemod.net/license.php>.
34 #define GROUP_STATE_NONE 0
35 #define GROUP_STATE_GROUPS 1
36 #define GROUP_STATE_INGROUP 2
37 #define GROUP_STATE_OVERRIDES 3
38 #define GROUP_PASS_FIRST 1
39 #define GROUP_PASS_SECOND 2
41 static Handle:g_hGroupParser = INVALID_HANDLE;
42 static GroupId:g_CurGrp = INVALID_GROUP_ID;
43 static g_GroupState = GROUP_STATE_NONE;
44 static g_GroupPass = 0;
45 static bool:g_NeedReparse = false;
47 public SMCResult:ReadGroups_NewSection(Handle:smc, const String:name[], bool:opt_quotes)
52 return SMCParse_Continue;
55 if (g_GroupState == GROUP_STATE_NONE)
57 if (StrEqual(name, "Groups"))
59 g_GroupState = GROUP_STATE_GROUPS;
63 } else if (g_GroupState == GROUP_STATE_GROUPS) {
64 if ((g_CurGrp = CreateAdmGroup(name)) == INVALID_GROUP_ID)
66 g_CurGrp = FindAdmGroup(name);
68 g_GroupState = GROUP_STATE_INGROUP;
69 } else if (g_GroupState == GROUP_STATE_INGROUP) {
70 if (StrEqual(name, "Overrides"))
72 g_GroupState = GROUP_STATE_OVERRIDES;
80 return SMCParse_Continue;
83 public SMCResult:ReadGroups_KeyValue(Handle:smc,
89 if (g_CurGrp == INVALID_GROUP_ID
92 return SMCParse_Continue;
97 if (g_GroupPass == GROUP_PASS_FIRST)
99 if (g_GroupState == GROUP_STATE_INGROUP)
101 if (StrEqual(key, "flags"))
103 new len = strlen(value);
104 for (new i=0; i<len; i++)
106 if (!FindFlagByChar(value[i], flag))
110 SetAdmGroupAddFlag(g_CurGrp, flag, true);
112 } else if (StrEqual(key, "immunity")) {
113 g_NeedReparse = true;
115 } else if (g_GroupState == GROUP_STATE_OVERRIDES) {
116 new OverrideRule:rule = Command_Deny;
118 if (StrEqual(value, "allow", false))
120 rule = Command_Allow;
125 AddAdmGroupCmdOverride(g_CurGrp, key[1], Override_CommandGroup, rule);
127 AddAdmGroupCmdOverride(g_CurGrp, key, Override_Command, rule);
130 } else if (g_GroupPass == GROUP_PASS_SECOND
131 && g_GroupState == GROUP_STATE_INGROUP) {
132 /* Check for immunity again, core should handle double inserts */
133 if (StrEqual(key, "immunity"))
135 /* If it's a value we know about, use it */
136 if (StrEqual(value, "*"))
138 SetAdmGroupImmunityLevel(g_CurGrp, 2);
139 } else if (StrEqual(value, "$")) {
140 SetAdmGroupImmunityLevel(g_CurGrp, 1);
143 if (StringToIntEx(value, level))
145 SetAdmGroupImmunityLevel(g_CurGrp, level);
150 id = FindAdmGroup(value[1]);
152 id = FindAdmGroup(value);
154 if (id != INVALID_GROUP_ID)
156 SetAdmGroupImmuneFrom(g_CurGrp, id);
158 ParseError("Unable to find group: \"%s\"", value);
165 return SMCParse_Continue;
168 public SMCResult:ReadGroups_EndSection(Handle:smc)
170 /* If we're ignoring, skip out */
174 return SMCParse_Continue;
177 if (g_GroupState == GROUP_STATE_OVERRIDES)
179 g_GroupState = GROUP_STATE_INGROUP;
180 } else if (g_GroupState == GROUP_STATE_INGROUP) {
181 g_GroupState = GROUP_STATE_GROUPS;
182 g_CurGrp = INVALID_GROUP_ID;
183 } else if (g_GroupState == GROUP_STATE_GROUPS) {
184 g_GroupState = GROUP_STATE_NONE;
187 return SMCParse_Continue;
190 public SMCResult:ReadGroups_CurrentLine(Handle:smc, const String:line[], lineno)
192 g_CurrentLine = lineno;
194 return SMCParse_Continue;
197 static InitializeGroupParser()
199 if (g_hGroupParser == INVALID_HANDLE)
201 g_hGroupParser = SMC_CreateParser();
202 SMC_SetReaders(g_hGroupParser,
203 ReadGroups_NewSection,
205 ReadGroups_EndSection);
206 SMC_SetRawLine(g_hGroupParser, ReadGroups_CurrentLine);
210 static InternalReadGroups(const String:path[], pass)
214 g_GroupState = GROUP_STATE_NONE;
215 g_CurGrp = INVALID_GROUP_ID;
217 g_NeedReparse = false;
219 new SMCError:err = SMC_ParseFile(g_hGroupParser, path);
220 if (err != SMCError_Okay)
222 decl String:buffer[64];
223 if (SMC_GetErrorString(err, buffer, sizeof(buffer)))
225 ParseError("%s", buffer);
227 ParseError("Fatal parse error");
234 InitializeGroupParser();
236 BuildPath(Path_SM, g_Filename, sizeof(g_Filename), "configs/admin_groups.cfg");
238 InternalReadGroups(g_Filename, GROUP_PASS_FIRST);
241 InternalReadGroups(g_Filename, GROUP_PASS_SECOND);