plugins/admin-flatfile/admin-simple.sp
author Scott Ehlert <ds@alliedmods.net>
Thu Jun 07 02:04:05 2007 +0000 (2007-06-07)
changeset 898 f8ff0a7cd037
parent 639 3a0eda369c82
child 908 cd411e8827c4
permissions -rw-r--r--
Yikes, fixed PrintToChatAll() and PrintCenterTextAll()
     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  
    21 public ReadSimpleUsers()
    22 {
    23 	BuildPath(Path_SM, g_Filename, sizeof(g_Filename), "configs/admins_simple.ini");
    24 	
    25 	new Handle:file = OpenFile(g_Filename, "rt");
    26 	if (file == INVALID_HANDLE)
    27 	{
    28 		ParseError("Could not open file!");
    29 		return;
    30 	}
    31 	
    32 	while (!IsEndOfFile(file))
    33 	{
    34 		decl String:line[255];
    35 		if (!ReadFileLine(file, line, sizeof(line)))
    36 		{
    37 			break;
    38 		}
    39 		
    40 		if ((line[0] == '/' && line[1] == '/')
    41 			|| (line[0] == ';' || line[0] == '\0'))
    42 		{
    43 			continue;
    44 		}
    45 	
    46 		ReadAdminLine(line);
    47 	}
    48 	
    49 	CloseHandle(file);
    50 }
    51 
    52 ReadAdminLine(const String:line[])
    53 {
    54 	new String:auth[64];
    55 	new cur_idx = StrBreak(line, auth, sizeof(auth));
    56 	new idx = cur_idx;
    57 	
    58 	if (cur_idx == -1)
    59 	{
    60 		/* This line is bad... we need at least two parameters */
    61 		return;
    62 	}
    63 	
    64 	/* Create the admin */
    65 	new AdminId:admin = CreateAdmin(auth);
    66 	
    67 	/* Read flags */
    68 	new String:flags[64];	
    69 	cur_idx = StrBreak(line[idx], flags, sizeof(flags));
    70 	idx += cur_idx;
    71 	
    72 	if (flags[0] == '@')
    73 	{
    74 		new GroupId:gid = FindAdmGroup(flags[1]);
    75 		if (gid == INVALID_GROUP_ID)
    76 		{
    77 			ParseError("Invalid group detected: %s", flags[1]);
    78 			return;
    79 		}
    80 		AdminInheritGroup(admin, gid);
    81 	} else {
    82 		new len = strlen(flags);
    83 		new bool:is_default = false;
    84 		for (new i=0; i<len; i++)
    85 		{
    86 			if (flags[i] < 'a' || flags[i] > 'z')
    87 			{
    88 				if (flags[i] == '$')
    89 				{
    90 					is_default = true;
    91 				} else {
    92 					ParseError("Invalid flag detected: %c", flags[i]);
    93 				}
    94 				continue;
    95 			}
    96 			new val = flags[i] - 'a';
    97 			if (!g_FlagsSet[val])
    98 			{
    99 				ParseError("Invalid flag detected: %c", flags[i]);
   100 				continue;
   101 			}
   102 			SetAdminFlag(admin, g_FlagLetters[val], true);
   103 		}
   104 		
   105 		if (is_default)
   106 		{
   107 			new GroupId:gid = FindAdmGroup("Default");
   108 			if (gid != INVALID_GROUP_ID)
   109 			{
   110 				AdminInheritGroup(admin, gid);
   111 			}
   112 		}
   113 	}
   114 	
   115 	/* Lastly, is there a password? */
   116 	if (cur_idx != -1)
   117 	{
   118 		decl String:password[64];
   119 		StrBreak(line[idx], password, sizeof(password));
   120 		SetAdminPassword(admin, password);
   121 	}
   122 	
   123 	/* Now, bind the identity to something */
   124 	if (StrContains(auth, "STEAM_") == 0)
   125 	{
   126 		BindAdminIdentity(admin, AUTHMETHOD_STEAM, auth);
   127 	} else {
   128 		if (auth[0] == '!')
   129 		{
   130 			BindAdminIdentity(admin, AUTHMETHOD_IP, auth[1]);
   131 		} else {
   132 			BindAdminIdentity(admin, AUTHMETHOD_NAME, auth);
   133 		}
   134 	}
   135 }