1.1 --- a/plugins/admin-flatfile/admin-simple.sp Fri Jul 11 06:51:21 2008 +0000
1.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
1.3 @@ -1,223 +0,0 @@
1.4 -/**
1.5 - * vim: set ts=4 :
1.6 - * =============================================================================
1.7 - * SourceMod Admin File Reader Plugin
1.8 - * Reads the admins.cfg file. Do not compile this directly.
1.9 - *
1.10 - * SourceMod (C)2004-2008 AlliedModders LLC. All rights reserved.
1.11 - * =============================================================================
1.12 - *
1.13 - * This program is free software; you can redistribute it and/or modify it under
1.14 - * the terms of the GNU General Public License, version 3.0, as published by the
1.15 - * Free Software Foundation.
1.16 - *
1.17 - * This program is distributed in the hope that it will be useful, but WITHOUT
1.18 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
1.19 - * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
1.20 - * details.
1.21 - *
1.22 - * You should have received a copy of the GNU General Public License along with
1.23 - * this program. If not, see <http://www.gnu.org/licenses/>.
1.24 - *
1.25 - * As a special exception, AlliedModders LLC gives you permission to link the
1.26 - * code of this program (as well as its derivative works) to "Half-Life 2," the
1.27 - * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
1.28 - * by the Valve Corporation. You must obey the GNU General Public License in
1.29 - * all respects for all other code used. Additionally, AlliedModders LLC grants
1.30 - * this exception to all derivative works. AlliedModders LLC defines further
1.31 - * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
1.32 - * or <http://www.sourcemod.net/license.php>.
1.33 - *
1.34 - * Version: $Id$
1.35 - */
1.36 -
1.37 -public ReadSimpleUsers()
1.38 -{
1.39 - BuildPath(Path_SM, g_Filename, sizeof(g_Filename), "configs/admins_simple.ini");
1.40 -
1.41 - new Handle:file = OpenFile(g_Filename, "rt");
1.42 - if (file == INVALID_HANDLE)
1.43 - {
1.44 - ParseError("Could not open file!");
1.45 - return;
1.46 - }
1.47 -
1.48 - while (!IsEndOfFile(file))
1.49 - {
1.50 - decl String:line[255];
1.51 - if (!ReadFileLine(file, line, sizeof(line)))
1.52 - {
1.53 - break;
1.54 - }
1.55 -
1.56 - /* Trim comments */
1.57 - new len = strlen(line);
1.58 - new bool:ignoring = false;
1.59 - for (new i=0; i<len; i++)
1.60 - {
1.61 - if (ignoring)
1.62 - {
1.63 - if (line[i] == '"')
1.64 - {
1.65 - ignoring = false;
1.66 - }
1.67 - } else {
1.68 - if (line[i] == '"')
1.69 - {
1.70 - ignoring = true;
1.71 - } else if (line[i] == ';') {
1.72 - line[i] = '\0';
1.73 - break;
1.74 - } else if (line[i] == '/'
1.75 - && i != len - 1
1.76 - && line[i+1] == '/')
1.77 - {
1.78 - line[i] = '\0';
1.79 - break;
1.80 - }
1.81 - }
1.82 - }
1.83 -
1.84 - TrimString(line);
1.85 -
1.86 - if ((line[0] == '/' && line[1] == '/')
1.87 - || (line[0] == ';' || line[0] == '\0'))
1.88 - {
1.89 - continue;
1.90 - }
1.91 -
1.92 - ReadAdminLine(line);
1.93 - }
1.94 -
1.95 - CloseHandle(file);
1.96 -}
1.97 -
1.98 -
1.99 -
1.100 -DecodeAuthMethod(const String:auth[], String:method[32], &offset)
1.101 -{
1.102 - if (StrContains(auth, "STEAM_") == 0)
1.103 - {
1.104 - strcopy(method, sizeof(method), AUTHMETHOD_STEAM);
1.105 - offset = 0;
1.106 - }
1.107 - else
1.108 - {
1.109 - if (auth[0] == '!')
1.110 - {
1.111 - strcopy(method, sizeof(method), AUTHMETHOD_IP);
1.112 - offset = 1;
1.113 - }
1.114 - else
1.115 - {
1.116 - strcopy(method, sizeof(method), AUTHMETHOD_NAME);
1.117 - offset = 0;
1.118 - }
1.119 - }
1.120 -}
1.121 -
1.122 -ReadAdminLine(const String:line[])
1.123 -{
1.124 - new bool:is_bound;
1.125 - new AdminId:admin;
1.126 - new String:auth[64];
1.127 - decl String:auth_method[32];
1.128 - new idx, cur_idx, auth_offset;
1.129 -
1.130 - if ((cur_idx = BreakString(line, auth, sizeof(auth))) == -1)
1.131 - {
1.132 - /* This line is bad... we need at least two parameters */
1.133 - return;
1.134 - }
1.135 -
1.136 - idx = cur_idx;
1.137 -
1.138 - /* Check if we can bind beforehand */
1.139 - DecodeAuthMethod(auth, auth_method, auth_offset);
1.140 - if ((admin = FindAdminByIdentity(auth_method, auth[auth_offset])) == INVALID_ADMIN_ID)
1.141 - {
1.142 - /* There is no binding, create the admin */
1.143 - admin = CreateAdmin();
1.144 - }
1.145 - else
1.146 - {
1.147 - is_bound = true;
1.148 - }
1.149 -
1.150 - /* Read flags */
1.151 - new String:flags[64];
1.152 - cur_idx = BreakString(line[idx], flags, sizeof(flags));
1.153 - idx += cur_idx;
1.154 -
1.155 - /* Read immunity level, if any */
1.156 - new level, flag_idx;
1.157 -
1.158 - if ((flag_idx = StringToIntEx(flags, level)) > 0)
1.159 - {
1.160 - SetAdminImmunityLevel(admin, level);
1.161 - if (flags[flag_idx] == ':')
1.162 - {
1.163 - flag_idx++;
1.164 - }
1.165 - }
1.166 -
1.167 - if (flags[flag_idx] == '@')
1.168 - {
1.169 - new GroupId:gid = FindAdmGroup(flags[flag_idx + 1]);
1.170 - if (gid == INVALID_GROUP_ID)
1.171 - {
1.172 - ParseError("Invalid group detected: %s", flags[flag_idx + 1]);
1.173 - return;
1.174 - }
1.175 - AdminInheritGroup(admin, gid);
1.176 - }
1.177 - else
1.178 - {
1.179 - new len = strlen(flags[flag_idx]);
1.180 - new bool:is_default = false;
1.181 - for (new i=0; i<len; i++)
1.182 - {
1.183 - if (!level && flags[flag_idx + i] == '$')
1.184 - {
1.185 - SetAdminImmunityLevel(admin, 1);
1.186 - } else {
1.187 - new AdminFlag:flag;
1.188 -
1.189 - if (!FindFlagByChar(flags[flag_idx + i], flag))
1.190 - {
1.191 - ParseError("Invalid flag detected: %c", flags[flag_idx + i]);
1.192 - continue;
1.193 - }
1.194 - SetAdminFlag(admin, flag, true);
1.195 - }
1.196 - }
1.197 -
1.198 - if (is_default)
1.199 - {
1.200 - new GroupId:gid = FindAdmGroup("Default");
1.201 - if (gid != INVALID_GROUP_ID)
1.202 - {
1.203 - AdminInheritGroup(admin, gid);
1.204 - }
1.205 - }
1.206 - }
1.207 -
1.208 - /* Lastly, is there a password? */
1.209 - if (cur_idx != -1)
1.210 - {
1.211 - decl String:password[64];
1.212 - BreakString(line[idx], password, sizeof(password));
1.213 - SetAdminPassword(admin, password);
1.214 - }
1.215 -
1.216 - /* Now, bind the identity to something */
1.217 - if (!is_bound)
1.218 - {
1.219 - if (!BindAdminIdentity(admin, auth_method, auth[auth_offset]))
1.220 - {
1.221 - /* We should never reach here */
1.222 - ParseError("Failed to bind identity %s (method %s)", auth[auth_offset], auth_method);
1.223 - }
1.224 - }
1.225 -}
1.226 -