1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/plugins/admin-flatfile/admin-simple.sp Fri Mar 16 22:15:03 2007 +0000
1.3 @@ -0,0 +1,132 @@
1.4 +/**
1.5 + * admin-simple.sp
1.6 + * Reads the admins.cfg file. Do not compile this directly.
1.7 + * This file is part of SourceMod, Copyright (C) 2004-2007 AlliedModders LLC
1.8 + *
1.9 + * This program is free software; you can redistribute it and/or
1.10 + * modify it under the terms of the GNU General Public License
1.11 + * as published by the Free Software Foundation; either version 2
1.12 + * of the License, or (at your option) any later version.
1.13 + *
1.14 + * This program is distributed in the hope that it will be useful,
1.15 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
1.16 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1.17 + * GNU General Public License for more details.
1.18 + *
1.19 + * You should have received a copy of the GNU General Public License
1.20 + * along with this program; if not, write to the Free Software
1.21 + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
1.22 + */
1.23 +
1.24 +ReadSimpleUsers()
1.25 +{
1.26 + BuildPath(Path_SM, g_Filename, sizeof(g_Filename), "configs/admins_simple.ini");
1.27 +
1.28 + new Handle:file = OpenFile(g_Filename, "rt");
1.29 + if (file == INVALID_HANDLE)
1.30 + {
1.31 + ParseError("Could not open file!");
1.32 + return;
1.33 + }
1.34 +
1.35 + while (!IsEndOfFile(file))
1.36 + {
1.37 + decl String:line[255];
1.38 + ReadFileLine(file, line, sizeof(line));
1.39 +
1.40 + if ((line[0] == '/' && line[1] == '/')
1.41 + || (line[0] == ';' || line[0] == '\0'))
1.42 + {
1.43 + continue;
1.44 + }
1.45 +
1.46 + ReadAdminLine(line);
1.47 + }
1.48 +
1.49 + CloseHandle(file);
1.50 +}
1.51 +
1.52 +ReadAdminLine(const String:line[])
1.53 +{
1.54 + new String:auth[64];
1.55 + new cur_idx = StrBreak(line, auth, sizeof(auth));
1.56 + new idx = cur_idx;
1.57 +
1.58 + if (cur_idx == -1)
1.59 + {
1.60 + /* This line is bad... we need at least two parameters */
1.61 + return;
1.62 + }
1.63 +
1.64 + /* Create the admin */
1.65 + new AdminId:admin = CreateAdmin(auth);
1.66 +
1.67 + /* Read flags */
1.68 + new String:flags[64];
1.69 + cur_idx = StrBreak(line[idx], flags, sizeof(flags));
1.70 + idx += cur_idx;
1.71 +
1.72 + if (flags[0] == '@')
1.73 + {
1.74 + new GroupId:gid = FindAdmGroup(flags[1]);
1.75 + if (gid == INVALID_GROUP_ID)
1.76 + {
1.77 + ParseError("Invalid group detected: %s", flags[1]);
1.78 + return;
1.79 + }
1.80 + AdminInheritGroup(admin, gid);
1.81 + } else {
1.82 + new len = strlen(flags);
1.83 + new bool:is_default = false;
1.84 + for (new i=0; i<len; i++)
1.85 + {
1.86 + if (flags[i] < 'a' || flags[i] > 'z')
1.87 + {
1.88 + if (flags[i] == '$')
1.89 + {
1.90 + is_default = true;
1.91 + } else {
1.92 + ParseError("Invalid flag detected: %c", flags[i]);
1.93 + }
1.94 + continue;
1.95 + }
1.96 + new val = flags[i] - 'a';
1.97 + if (!g_FlagsSet[val])
1.98 + {
1.99 + ParseError("Invalid flag detected: %c", flags[i]);
1.100 + continue;
1.101 + }
1.102 + SetAdminFlag(admin, g_FlagLetters[val], true);
1.103 + }
1.104 +
1.105 + if (is_default)
1.106 + {
1.107 + new GroupId:gid = FindAdmGroup("Default");
1.108 + if (gid != INVALID_GROUP_ID)
1.109 + {
1.110 + AdminInheritGroup(admin, gid);
1.111 + }
1.112 + }
1.113 + }
1.114 +
1.115 + /* Lastly, is there a password? */
1.116 + if (cur_idx != -1)
1.117 + {
1.118 + decl String:password[64];
1.119 + StrBreak(line[idx], password, sizeof(password));
1.120 + SetAdminPassword(admin, password);
1.121 + }
1.122 +
1.123 + /* Now, bind the identity to something */
1.124 + if (StrContains(auth, "STEAM_") == 0)
1.125 + {
1.126 + BindAdminIdentity(admin, AUTHMETHOD_STEAM, auth);
1.127 + } else {
1.128 + if (auth[0] == '!')
1.129 + {
1.130 + BindAdminIdentity(admin, AUTHMETHOD_IP, auth[1]);
1.131 + } else {
1.132 + BindAdminIdentity(admin, AUTHMETHOD_NAME, auth);
1.133 + }
1.134 + }
1.135 +}