Fixed SDKTools dota build.
3 * =============================================================================
4 * SourceMod Admin File Reader Plugin
5 * Reads the admins.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 USER_STATE_NONE 0
35 #define USER_STATE_ADMINS 1
36 #define USER_STATE_INADMIN 2
38 static Handle:g_hUserParser = INVALID_HANDLE;
39 static g_UserState = USER_STATE_NONE;
40 static String:g_CurAuth[64];
41 static String:g_CurIdent[64];
42 static String:g_CurName[64];
43 static String:g_CurPass[64];
44 static Handle:g_GroupArray;
48 public SMCResult:ReadUsers_NewSection(Handle:smc, const String:name[], bool:opt_quotes)
53 return SMCParse_Continue;
56 if (g_UserState == USER_STATE_NONE)
58 if (StrEqual(name, "Admins"))
60 g_UserState = USER_STATE_ADMINS;
67 else if (g_UserState == USER_STATE_ADMINS)
69 g_UserState = USER_STATE_INADMIN;
70 strcopy(g_CurName, sizeof(g_CurName), name);
74 ClearArray(g_GroupArray);
83 return SMCParse_Continue;
86 public SMCResult:ReadUsers_KeyValue(Handle:smc,
92 if (g_UserState != USER_STATE_INADMIN || g_IgnoreLevel)
94 return SMCParse_Continue;
97 if (StrEqual(key, "auth"))
99 strcopy(g_CurAuth, sizeof(g_CurAuth), value);
101 else if (StrEqual(key, "identity"))
103 strcopy(g_CurIdent, sizeof(g_CurIdent), value);
105 else if (StrEqual(key, "password"))
107 strcopy(g_CurPass, sizeof(g_CurPass), value);
109 else if (StrEqual(key, "group"))
111 new GroupId:id = FindAdmGroup(value);
112 if (id == INVALID_GROUP_ID)
114 ParseError("Unknown group \"%s\"", value);
117 PushArrayCell(g_GroupArray, id);
119 else if (StrEqual(key, "flags"))
121 new len = strlen(value);
124 for (new i = 0; i < len; i++)
126 if (!FindFlagByChar(value[i], flag))
128 ParseError("Invalid flag detected: %c", value[i]);
132 g_CurFlags |= FlagToBit(flag);
136 else if (StrEqual(key, "immunity"))
138 g_CurImmunity = StringToInt(value);
141 return SMCParse_Continue;
144 public SMCResult:ReadUsers_EndSection(Handle:smc)
149 return SMCParse_Continue;
152 if (g_UserState == USER_STATE_INADMIN)
154 /* Dump this user to memory */
155 if (g_CurIdent[0] != '\0' && g_CurAuth[0] != '\0')
157 decl AdminFlag:flags[26];
158 new AdminId:id, i, num_groups, num_flags;
160 if ((id = FindAdminByIdentity(g_CurAuth, g_CurIdent)) == INVALID_ADMIN_ID)
162 id = CreateAdmin(g_CurName);
163 if (!BindAdminIdentity(id, g_CurAuth, g_CurIdent))
166 ParseError("Failed to bind auth \"%s\" to identity \"%s\"", g_CurAuth, g_CurIdent);
167 return SMCParse_Continue;
171 num_groups = GetArraySize(g_GroupArray);
172 for (i = 0; i < num_groups; i++)
174 AdminInheritGroup(id, GetArrayCell(g_GroupArray, i));
177 SetAdminPassword(id, g_CurPass);
178 if (GetAdminImmunityLevel(id) < g_CurImmunity)
180 SetAdminImmunityLevel(id, g_CurImmunity);
183 num_flags = FlagBitsToArray(g_CurFlags, flags, sizeof(flags));
184 for (i = 0; i < num_flags; i++)
186 SetAdminFlag(id, flags[i], true);
191 ParseError("Failed to create admin: did you forget either the auth or identity properties?");
194 g_UserState = USER_STATE_ADMINS;
196 else if (g_UserState == USER_STATE_ADMINS)
198 g_UserState = USER_STATE_NONE;
201 return SMCParse_Continue;
204 public SMCResult:ReadUsers_CurrentLine(Handle:smc, const String:line[], lineno)
206 g_CurrentLine = lineno;
208 return SMCParse_Continue;
211 static InitializeUserParser()
213 if (g_hUserParser == INVALID_HANDLE)
215 g_hUserParser = SMC_CreateParser();
216 SMC_SetReaders(g_hUserParser,
217 ReadUsers_NewSection,
219 ReadUsers_EndSection);
220 SMC_SetRawLine(g_hUserParser, ReadUsers_CurrentLine);
222 g_GroupArray = CreateArray();
228 InitializeUserParser();
230 BuildPath(Path_SM, g_Filename, sizeof(g_Filename), "configs/admins.cfg");
234 g_UserState = USER_STATE_NONE;
236 new SMCError:err = SMC_ParseFile(g_hUserParser, g_Filename);
237 if (err != SMCError_Okay)
239 decl String:buffer[64];
240 if (SMC_GetErrorString(err, buffer, sizeof(buffer)))
242 ParseError("%s", buffer);
246 ParseError("Fatal parse error");