plugins/admin-flatfile/admin-simple.sp
branchsourcemod-1.1.0
changeset 2283 03a67e41afbc
parent 1951 c7b4237fff50
child 2287 017a725c9d17
     1.1 --- a/plugins/admin-flatfile/admin-simple.sp	Fri Mar 28 06:21:34 2008 +0000
     1.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.3 @@ -1,187 +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-2007 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 -ReadAdminLine(const String:line[])
    1.99 -{
   1.100 -	new String:auth[64];
   1.101 -	new cur_idx = BreakString(line, auth, sizeof(auth));
   1.102 -	new idx = cur_idx;
   1.103 -	
   1.104 -	if (cur_idx == -1)
   1.105 -	{
   1.106 -		/* This line is bad... we need at least two parameters */
   1.107 -		return;
   1.108 -	}
   1.109 -	
   1.110 -	/* Create the admin */
   1.111 -	new AdminId:admin = CreateAdmin();
   1.112 -	
   1.113 -	/* Read flags */
   1.114 -	new String:flags[64];	
   1.115 -	cur_idx = BreakString(line[idx], flags, sizeof(flags));
   1.116 -	idx += cur_idx;
   1.117 -
   1.118 -	/* Read immunity level, if any */
   1.119 -	new level, flag_idx;
   1.120 -
   1.121 -	if ((flag_idx = StringToIntEx(flags, level)) > 0)
   1.122 -	{
   1.123 -		SetAdminImmunityLevel(admin, level);
   1.124 -		if (flags[flag_idx] == ':')
   1.125 -		{
   1.126 -			flag_idx++;
   1.127 -		}
   1.128 -	}
   1.129 -
   1.130 -	if (flags[flag_idx] == '@')
   1.131 -	{
   1.132 -		new GroupId:gid = FindAdmGroup(flags[flag_idx + 1]);
   1.133 -		if (gid == INVALID_GROUP_ID)
   1.134 -		{
   1.135 -			ParseError("Invalid group detected: %s", flags[flag_idx + 1]);
   1.136 -			return;
   1.137 -		}
   1.138 -		AdminInheritGroup(admin, gid);
   1.139 -	} else {
   1.140 -		new len = strlen(flags[flag_idx]);
   1.141 -		new bool:is_default = false;
   1.142 -		for (new i=0; i<len; i++)
   1.143 -		{
   1.144 -			if (!level && flags[flag_idx + i] == '$')
   1.145 -			{
   1.146 -				SetAdminImmunityLevel(admin, 1);
   1.147 -			} else {
   1.148 -				new AdminFlag:flag;
   1.149 -				
   1.150 -				if (!FindFlagByChar(flags[flag_idx + i], flag))
   1.151 -				{
   1.152 -					ParseError("Invalid flag detected: %c", flags[flag_idx + i]);
   1.153 -					continue;
   1.154 -				}
   1.155 -				SetAdminFlag(admin, flag, true);
   1.156 -			}
   1.157 -		}
   1.158 -		
   1.159 -		if (is_default)
   1.160 -		{
   1.161 -			new GroupId:gid = FindAdmGroup("Default");
   1.162 -			if (gid != INVALID_GROUP_ID)
   1.163 -			{
   1.164 -				AdminInheritGroup(admin, gid);
   1.165 -			}
   1.166 -		}
   1.167 -	}
   1.168 -	
   1.169 -	/* Lastly, is there a password? */
   1.170 -	if (cur_idx != -1)
   1.171 -	{
   1.172 -		decl String:password[64];
   1.173 -		BreakString(line[idx], password, sizeof(password));
   1.174 -		SetAdminPassword(admin, password);
   1.175 -	}
   1.176 -	
   1.177 -	/* Now, bind the identity to something */
   1.178 -	if (StrContains(auth, "STEAM_") == 0)
   1.179 -	{
   1.180 -		BindAdminIdentity(admin, AUTHMETHOD_STEAM, auth);
   1.181 -	} else {
   1.182 -		if (auth[0] == '!')
   1.183 -		{
   1.184 -			BindAdminIdentity(admin, AUTHMETHOD_IP, auth[1]);
   1.185 -		} else {
   1.186 -			BindAdminIdentity(admin, AUTHMETHOD_NAME, auth);
   1.187 -		}
   1.188 -	}
   1.189 -}
   1.190 -