plugins/admin-flatfile/admin-simple.sp
author David Anderson <dvander@alliedmods.net>
Fri Jun 08 01:01:44 2007 +0000 (2007-06-08)
changeset 921 e07dad9724f5
parent 908 cd411e8827c4
child 1107 3789127b580e
permissions -rw-r--r--
added sm_execcfg
     1 /**
     2  * admin-simple.sp
     3  * Reads the admins.cfg file.  Do not compile this directly.
     4  * This file is part of SourceMod, Copyright (C) 2004-2007 AlliedModders LLC
     5  *
     6  * This program is free software; you can redistribute it and/or
     7  * modify it under the terms of the GNU General Public License
     8  * as published by the Free Software Foundation; either version 2
     9  * of the License, or (at your option) any later version.
    10  *
    11  * This program is distributed in the hope that it will be useful,
    12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
    13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    14  * GNU General Public License for more details.
    15  * 
    16  * You should have received a copy of the GNU General Public License
    17  * along with this program; if not, write to the Free Software
    18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
    19  *
    20  * Version: $Id$
    21  */
    22  
    23 public ReadSimpleUsers()
    24 {
    25 	BuildPath(Path_SM, g_Filename, sizeof(g_Filename), "configs/admins_simple.ini");
    26 	
    27 	new Handle:file = OpenFile(g_Filename, "rt");
    28 	if (file == INVALID_HANDLE)
    29 	{
    30 		ParseError("Could not open file!");
    31 		return;
    32 	}
    33 	
    34 	while (!IsEndOfFile(file))
    35 	{
    36 		decl String:line[255];
    37 		if (!ReadFileLine(file, line, sizeof(line)))
    38 		{
    39 			break;
    40 		}
    41 		
    42 		if ((line[0] == '/' && line[1] == '/')
    43 			|| (line[0] == ';' || line[0] == '\0'))
    44 		{
    45 			continue;
    46 		}
    47 	
    48 		ReadAdminLine(line);
    49 	}
    50 	
    51 	CloseHandle(file);
    52 }
    53 
    54 ReadAdminLine(const String:line[])
    55 {
    56 	new String:auth[64];
    57 	new cur_idx = StrBreak(line, auth, sizeof(auth));
    58 	new idx = cur_idx;
    59 	
    60 	if (cur_idx == -1)
    61 	{
    62 		/* This line is bad... we need at least two parameters */
    63 		return;
    64 	}
    65 	
    66 	/* Create the admin */
    67 	new AdminId:admin = CreateAdmin(auth);
    68 	
    69 	/* Read flags */
    70 	new String:flags[64];	
    71 	cur_idx = StrBreak(line[idx], flags, sizeof(flags));
    72 	idx += cur_idx;
    73 	
    74 	if (flags[0] == '@')
    75 	{
    76 		new GroupId:gid = FindAdmGroup(flags[1]);
    77 		if (gid == INVALID_GROUP_ID)
    78 		{
    79 			ParseError("Invalid group detected: %s", flags[1]);
    80 			return;
    81 		}
    82 		AdminInheritGroup(admin, gid);
    83 	} else {
    84 		new len = strlen(flags);
    85 		new bool:is_default = false;
    86 		for (new i=0; i<len; i++)
    87 		{
    88 			if (flags[i] < 'a' || flags[i] > 'z')
    89 			{
    90 				if (flags[i] == '$')
    91 				{
    92 					is_default = true;
    93 				} else {
    94 					ParseError("Invalid flag detected: %c", flags[i]);
    95 				}
    96 				continue;
    97 			}
    98 			new val = flags[i] - 'a';
    99 			if (!g_FlagsSet[val])
   100 			{
   101 				ParseError("Invalid flag detected: %c", flags[i]);
   102 				continue;
   103 			}
   104 			SetAdminFlag(admin, g_FlagLetters[val], true);
   105 		}
   106 		
   107 		if (is_default)
   108 		{
   109 			new GroupId:gid = FindAdmGroup("Default");
   110 			if (gid != INVALID_GROUP_ID)
   111 			{
   112 				AdminInheritGroup(admin, gid);
   113 			}
   114 		}
   115 	}
   116 	
   117 	/* Lastly, is there a password? */
   118 	if (cur_idx != -1)
   119 	{
   120 		decl String:password[64];
   121 		StrBreak(line[idx], password, sizeof(password));
   122 		SetAdminPassword(admin, password);
   123 	}
   124 	
   125 	/* Now, bind the identity to something */
   126 	if (StrContains(auth, "STEAM_") == 0)
   127 	{
   128 		BindAdminIdentity(admin, AUTHMETHOD_STEAM, auth);
   129 	} else {
   130 		if (auth[0] == '!')
   131 		{
   132 			BindAdminIdentity(admin, AUTHMETHOD_IP, auth[1]);
   133 		} else {
   134 			BindAdminIdentity(admin, AUTHMETHOD_NAME, auth);
   135 		}
   136 	}
   137 }