initial import of group reader (unfinished)
authorDavid Anderson <dvander@alliedmods.net>
Tue Jan 30 05:42:57 2007 +0000 (2007-01-30)
changeset 420bffaab713028
parent 419 e8e44b76d1c3
child 421 81aa2cce0002
initial import of group reader (unfinished)
configs/admin_groups.cfg
plugins/admin-base/admin-groups.sp
plugins/admin-base/admin-overrides.sp
plugins/include/admin.inc
     1.1 --- a/configs/admin_groups.cfg	Tue Jan 30 02:38:12 2007 +0000
     1.2 +++ b/configs/admin_groups.cfg	Tue Jan 30 05:42:57 2007 +0000
     1.3 @@ -4,9 +4,9 @@
     1.4  	 * Allowed properties for a group:
     1.5  	 *
     1.6  	 *   "flags"           - Flag string.
     1.7 -	 *   "inherit"         - Inherits permissions from another group.
     1.8 +	 *   "inherit"         - Inherits permissions from another group.  Use one group per instance of this key.
     1.9  	 *   "immunity"        - Specifies a group to be immune to.  Use "*" for all or "$" for users with no group.
    1.10 -	 *				     NOTE: No one, even a root user, is immune from other root users.
    1.11 +	 *				    	 This key may be used multiple times.
    1.12  	 */
    1.13  	"Full Admins"
    1.14  	{
    1.15 @@ -14,7 +14,7 @@
    1.16  		 * You can override commands and command groups here.
    1.17  		 * Specify a command name or group and either "allow" or "deny"
    1.18  		 * Examples:
    1.19 -		 * 		":CSDM"		"allow"
    1.20 +		 * 		":CSDM"			"allow"
    1.21  		 *		"csdm_enable"	"deny"
    1.22  		 */
    1.23  		 Commands
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/plugins/admin-base/admin-groups.sp	Tue Jan 30 05:42:57 2007 +0000
     2.3 @@ -0,0 +1,147 @@
     2.4 +#define GROUP_STATE_NONE		0
     2.5 +#define GROUP_STATE_GROUPS		1
     2.6 +#define GROUP_STATE_INGROUP		2
     2.7 +#define GROUP_STATE_OVERRIDES	3
     2.8 +#define GROUP_PASS_FIRST		1
     2.9 +#define GROUP_PASS_SECOND		2
    2.10 +
    2.11 +static Handle:g_hGroupParser = INVALID_HANDLE;
    2.12 +static GroupId:g_CurGrp = INVALID_GROUP_ID;
    2.13 +static g_GroupState = GROUP_STATE_NONE;
    2.14 +static g_GroupPass = 0
    2.15 +
    2.16 +static LevelGroupError(const String:buffer[], {Handle,String,Float,_}:...)
    2.17 +{
    2.18 +	decl String:buffer[512];
    2.19 +	
    2.20 +	if (!g_LoggedFileName)
    2.21 +	{
    2.22 +		LogError("Error(s) detected parsing admin_groups.cfg:");
    2.23 +		g_LoggedFileName = true;
    2.24 +	}
    2.25 +	
    2.26 +	VFormat(buffer, sizeof(buffer), format, 2);
    2.27 +	
    2.28 +	LogError(" (%d) %s", ++g_ErrorCount, buffer);
    2.29 +}
    2.30 +
    2.31 +public SMCResult:ReadGroups_NewSection(Handle:smc, const String:name[], bool:opt_quotes)
    2.32 +{
    2.33 +	if (g_GroupState == GROUP_STATE_NONE)
    2.34 +	{
    2.35 +		if (StrEqual(name, "Groups"))
    2.36 +		{
    2.37 +			g_GroupState = GROUP_STATE_GROUPS;
    2.38 +		}
    2.39 +	} else if (g_GroupState == GROUP_STATE_GROUPS) {
    2.40 +		if ((g_CurGrp = CreateAdmGroup(name)) == INVALID_GROUP_ID)
    2.41 +		{
    2.42 +			g_CurGrp = FindAdmGroup(name);
    2.43 +		}
    2.44 +		g_GroupState = GROUP_STATE_INGROUP;
    2.45 +	} else if (g_GroupState == GROUP_STATE_INGROUP) {
    2.46 +		if (StrEqual(name, "Overrides"))
    2.47 +		{
    2.48 +			g_GroupState = GROUP_STATE_OVERRIDES;
    2.49 +		}
    2.50 +	}
    2.51 +	
    2.52 +	return SMCParse_Continue;
    2.53 +}
    2.54 +
    2.55 +public SMCResult:ReadGroups_KeyValue(Handle:smc, 
    2.56 +										const String:key[], 
    2.57 +										const String:value[], 
    2.58 +										bool:key_quotes, 
    2.59 +										bool:value_quotes)
    2.60 +{
    2.61 +	if (g_CurGrp == INVALID_GROUP_ID)
    2.62 +	{
    2.63 +		return SMCParse_Continue;
    2.64 +	}
    2.65 +	
    2.66 +	new AdminFlag:flag;
    2.67 +	
    2.68 +	if (StrEqual(key, "flags"))
    2.69 +	{
    2.70 +		new len = strlen(value);
    2.71 +		for (new i=0; i<len; i++)
    2.72 +		{
    2.73 +			if (value[i] < 'a' || value[i] > 'z')
    2.74 +			{
    2.75 +				continue;
    2.76 +			}
    2.77 +			flag = g_FlagLetters[value[i] - 'a'];
    2.78 +			if (flag == Admin_None)
    2.79 +			{
    2.80 +				continue;
    2.81 +			}
    2.82 +			SetAdmGroupAddFlag(g_CurGrp, flag, true);
    2.83 +		}
    2.84 +	} else if (StrEqual(key, "immunity")) {
    2.85 +		if (StrEqual(value, "*"))
    2.86 +		{
    2.87 +			SetAdmGroupImmunity(g_CurGrp, Immunity_Global, true);
    2.88 +		} else if (StrEqual(value, "$")) {
    2.89 +			SetAdmGroupImmunity(g_CurGrp, Immunity_Default, true);
    2.90 +		}
    2.91 +	}
    2.92 +	
    2.93 +	return SMCParse_Continue;
    2.94 +}
    2.95 +
    2.96 +public SMCResult:ReadGroups_EndSection(Handle:smc)
    2.97 +{
    2.98 +	if (g_GroupState == GROUP_STATE_OVERRIDES)
    2.99 +	{
   2.100 +		g_GroupState = GROUP_STATE_INGROUP;
   2.101 +	} else if (g_GroupState == GROUP_STATE_INGROUP) {
   2.102 +		g_GroupState = GROUP_STATE_GROUPS;
   2.103 +		g_CurGrp = INVALID_GROUP_ID;
   2.104 +	} else if (g_GroupState == GROUP_STATE_GROUPS) {
   2.105 +		g_GroupState = GROUP_STATE_NONE;
   2.106 +	}
   2.107 +	
   2.108 +	return SMCParse_Continue;
   2.109 +}
   2.110 +
   2.111 +static InitializeGroupParser()
   2.112 +{
   2.113 +	if (g_hGroupParser == INVALID_HANDLE)
   2.114 +	{
   2.115 +		g_hGroupParser = SMC_CreateParser();
   2.116 +		SMC_SetReaders(g_hGroupParser,
   2.117 +					   ReadGroup_NewSection,
   2.118 +					   ReadGroup_KeyValue,
   2.119 +					   ReadGroup_EndSection);
   2.120 +	}
   2.121 +}
   2.122 +
   2.123 +ReadGroups()
   2.124 +{
   2.125 +	new String:path[PLATFORM_MAX_PATH];
   2.126 +	
   2.127 +	InitializeGroupParser();
   2.128 +	
   2.129 +	BuildPath(Path_SM, path, sizeof(path), "configs/admin_groups.cfg");
   2.130 +	
   2.131 +	/* Set states */
   2.132 +	g_GroupState = GROUP_STATE_NONE;
   2.133 +	g_LoggedFileName = false;
   2.134 +	g_ErrorCount = 0;
   2.135 +	g_CurGrp = INVALID_GROUP_ID;
   2.136 +	g_GroupPass = GROUP_PASS_FIRST;
   2.137 +		
   2.138 +	new SMCError:err = SMC_ParseFile(g_hGroupParser, path);
   2.139 +	if (err != SMCError_Okay)
   2.140 +	{
   2.141 +		decl String:buffer[64];
   2.142 +		if (SMC_GetErrorString(err, buffer, sizeof(buffer)))
   2.143 +		{
   2.144 +			LogGroupError("%s", buffer);
   2.145 +		} else {
   2.146 +			LogGroupError("Fatal parse error");
   2.147 +		}
   2.148 +	}
   2.149 +}
   2.150 +
     3.1 --- a/plugins/admin-base/admin-overrides.sp	Tue Jan 30 02:38:12 2007 +0000
     3.2 +++ b/plugins/admin-base/admin-overrides.sp	Tue Jan 30 05:42:57 2007 +0000
     3.3 @@ -5,7 +5,7 @@
     3.4  static Handle:g_hOverrideParser = INVALID_HANDLE;
     3.5  static g_OverrideState = OVERRIDE_STATE_NONE;
     3.6  
     3.7 -LogOverrideError(const String:format[], {Handle,String,Float,_}:...)
     3.8 +static LogOverrideError(const String:format[], {Handle,String,Float,_}:...)
     3.9  {
    3.10  	decl String:buffer[512];
    3.11  	
     4.1 --- a/plugins/include/admin.inc	Tue Jan 30 02:38:12 2007 +0000
     4.2 +++ b/plugins/include/admin.inc	Tue Jan 30 05:42:57 2007 +0000
     4.3 @@ -62,6 +62,12 @@
     4.4  	INVALID_GROUP_ID = -1,
     4.5  };
     4.6  
     4.7 +/** Note: These are not Handles */
     4.8 +enum AdminId
     4.9 +{
    4.10 +	INVALID_ADMIN_ID = -1,
    4.11 +};
    4.12 +
    4.13  #define ADMIN_CACHE_OVERRIDES	(1<<0)
    4.14  #define ADMIN_CACHE_ADMINS		(1<<1)
    4.15  #define ADMIN_CACHE_GROUPS		((1<<2)|ADMIN_CACHE_ADMINS)