plugins/admin-sql-threaded.sp
changeset 1403 ecb9c66fd4bb
parent 1332 917ded8333d5
child 1874 6bd98dba0f2a
     1.1 --- a/plugins/admin-sql-threaded.sp	Mon Sep 10 22:28:22 2007 +0000
     1.2 +++ b/plugins/admin-sql-threaded.sp	Mon Sep 10 23:38:58 2007 +0000
     1.3 @@ -352,6 +352,7 @@
     1.4  	decl String:flags[32];
     1.5  	decl String:name[80];
     1.6  	new AdminId:adm, id;
     1.7 +	new immunity;
     1.8  	
     1.9  	/**
    1.10  	 * Cache user info -- [0] = db id, [1] = cache id, [2] = groups
    1.11 @@ -367,6 +368,7 @@
    1.12  		SQL_FetchString(hndl, 3, password, sizeof(password));
    1.13  		SQL_FetchString(hndl, 4, flags, sizeof(flags));
    1.14  		SQL_FetchString(hndl, 5, name, sizeof(name));
    1.15 +		immunity = SQL_FetchInt(hndl, 7);
    1.16  		
    1.17  		/* For dynamic admins we clear anything already in the cache. */
    1.18  		if ((adm = FindAdminByIdentity(authtype, identity)) != INVALID_ADMIN_ID)
    1.19 @@ -387,7 +389,7 @@
    1.20  		total_users++;
    1.21  		
    1.22  #if defined _DEBUG
    1.23 -		PrintToServer("Found SQL admin (%d,%s,%s,%s,%s,%s):%d:%d", id, authtype, identity, password, flags, name, adm, user_lookup[total_users-1][2]);
    1.24 +		PrintToServer("Found SQL admin (%d,%s,%s,%s,%s,%s,%d):%d:%d", id, authtype, identity, password, flags, name, immunity, adm, user_lookup[total_users-1][2]);
    1.25  #endif
    1.26  		
    1.27  		/* See if this admin wants a password */
    1.28 @@ -395,6 +397,8 @@
    1.29  		{
    1.30  			SetAdminPassword(adm, password);
    1.31  		}
    1.32 +
    1.33 +		SetAdminImmunityLevel(adm, immunity);
    1.34  		
    1.35  		/* Apply each flag */
    1.36  		new len = strlen(flags);
    1.37 @@ -488,7 +492,7 @@
    1.38  	decl String:query[512];
    1.39  	new len = 0;
    1.40  	
    1.41 -	len += Format(query[len], sizeof(query)-len, "SELECT a.id, a.authtype, a.identity, a.password, a.flags, a.name, COUNT(ag.group_id)");
    1.42 +	len += Format(query[len], sizeof(query)-len, "SELECT a.id, a.authtype, a.identity, a.password, a.flags, a.name, COUNT(ag.group_id), immunity");
    1.43  	len += Format(query[len], sizeof(query)-len, " FROM sm_admins a LEFT JOIN sm_admins_groups ag ON a.id = ag.admin_id WHERE ");
    1.44  	len += Format(query[len], sizeof(query)-len, " (a.authtype = 'ip' AND a.identity = '%s')", ipaddr);
    1.45  	len += Format(query[len], sizeof(query)-len, " OR (a.authtype = 'name' AND a.identity = '%s')", safe_name);
    1.46 @@ -710,17 +714,17 @@
    1.47  	/**
    1.48  	 * Now start fetching groups.
    1.49  	 */
    1.50 -	decl String:immunity[16];
    1.51  	decl String:flags[32];
    1.52  	decl String:name[128];
    1.53 +	new immunity;
    1.54  	while (SQL_FetchRow(hndl))
    1.55  	{
    1.56 -		SQL_FetchString(hndl, 0, immunity, sizeof(immunity));
    1.57 -		SQL_FetchString(hndl, 1, flags, sizeof(flags));
    1.58 -		SQL_FetchString(hndl, 2, name, sizeof(name));
    1.59 +		SQL_FetchString(hndl, 0, flags, sizeof(flags));
    1.60 +		SQL_FetchString(hndl, 1, name, sizeof(name));
    1.61 +		immunity = SQL_FetchInt(hndl, 2);
    1.62  		
    1.63  #if defined _DEBUG
    1.64 -		PrintToServer("Adding group (%s, %s, %s)", immunity, flags, name);
    1.65 +		PrintToServer("Adding group (%d, %s, %s)", immunity, flags, name);
    1.66  #endif
    1.67  		
    1.68  		/* Find or create the group */
    1.69 @@ -729,7 +733,7 @@
    1.70  		{
    1.71  			gid = CreateAdmGroup(name);
    1.72  		}
    1.73 -		
    1.74 +
    1.75  		/* Add flags from the database to the group */
    1.76  		new num_flag_chars = strlen(flags);
    1.77  		for (new i=0; i<num_flag_chars; i++)
    1.78 @@ -742,16 +746,7 @@
    1.79  			SetAdmGroupAddFlag(gid, flag, true);
    1.80  		}
    1.81  		
    1.82 -		/* Set the immunity level this group has */
    1.83 -		if (StrEqual(immunity, "all"))
    1.84 -		{
    1.85 -			SetAdmGroupImmunity(gid, Immunity_Default, true);
    1.86 -			SetAdmGroupImmunity(gid, Immunity_Global, true);
    1.87 -		} else if (StrEqual(immunity, "default")) {
    1.88 -			SetAdmGroupImmunity(gid, Immunity_Default, true);
    1.89 -		} else if (StrEqual(immunity, "global")) {
    1.90 -			SetAdmGroupImmunity(gid, Immunity_Global, true);
    1.91 -		}
    1.92 +		SetAdmGroupImmunityLevel(gid, immunity);
    1.93  	}
    1.94  	
    1.95  	/**
    1.96 @@ -774,7 +769,7 @@
    1.97  	decl String:query[255];
    1.98  	new Handle:pk;
    1.99  	
   1.100 -	Format(query, sizeof(query), "SELECT immunity, flags, name FROM sm_groups");
   1.101 +	Format(query, sizeof(query), "SELECT flags, name, immunity_level FROM sm_groups");
   1.102  
   1.103  	pk = CreateDataPack();
   1.104  	WritePackCell(pk, sequence);
   1.105 @@ -858,68 +853,3 @@
   1.106  	SQL_TQuery(db, OnReceiveOverrides, query, pk, DBPrio_High);
   1.107  }
   1.108  
   1.109 -/**
   1.110 - * Finds an entry in a temporary group list (used by immunity resolver).
   1.111 - * 
   1.112 - * @param group_list		Array(3,n) (0=db id, 1=gid, 2=immunity list)
   1.113 - * @param id				group database id
   1.114 - * @return					GroupId of the database id or INVALID_GROUP_ID.
   1.115 - */
   1.116 -stock GroupId:UTIL_FindGroupInCache(Handle:group_list, id)
   1.117 -{
   1.118 -	new size = GetArraySize(group_list);
   1.119 -	
   1.120 -	for (new i=0; i<size; i++)
   1.121 -	{
   1.122 -		decl data[3];
   1.123 -		GetArrayArray(group_list, i, data);
   1.124 -		
   1.125 -		if (data[0] == id)
   1.126 -		{
   1.127 -			return GroupId:data[1];
   1.128 -		}
   1.129 -	}
   1.130 -	
   1.131 -	return INVALID_GROUP_ID;
   1.132 -}
   1.133 -
   1.134 -/**
   1.135 - * Breaks a comma-delimited string into a list of numbers, returning a new 
   1.136 - * dynamic array.
   1.137 - *
   1.138 - * @param text				The string to split.
   1.139 - * @return					A new array Handle which must be closed, or 
   1.140 - *							INVALID_HANDLE on no strings found.
   1.141 - */
   1.142 -stock Handle:UTIL_ExplodeNumberString(const String:text[])
   1.143 -{
   1.144 -	new Handle:array = INVALID_HANDLE;
   1.145 -	decl String:buffer[32];
   1.146 -	new reloc_idx, idx;
   1.147 -	
   1.148 -	while ((idx = SplitString(text[reloc_idx], ",", buffer, sizeof(buffer))) != -1)
   1.149 -	{
   1.150 -		reloc_idx += idx;
   1.151 -		if (text[reloc_idx] == '\0')
   1.152 -		{
   1.153 -			break;
   1.154 -		}
   1.155 -		if (array == INVALID_HANDLE)
   1.156 -		{
   1.157 -			array = CreateArray();
   1.158 -		}
   1.159 -		PushArrayCell(array, StringToInt(buffer));
   1.160 -	}
   1.161 -	
   1.162 -	if (text[reloc_idx] != '\0')
   1.163 -	{
   1.164 -		if (array == INVALID_HANDLE)
   1.165 -		{
   1.166 -			array = CreateArray();
   1.167 -		}
   1.168 -		PushArrayCell(array, StringToInt(text[reloc_idx]));
   1.169 -	}
   1.170 -	
   1.171 -	return array;
   1.172 -}
   1.173 -