added amb1448 - duplicate admins are now combined rather than excluded
--HG-- extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%402145
This commit is contained in:
parent
9023afff0d
commit
a7cc2609e1
@ -92,20 +92,57 @@ public ReadSimpleUsers()
|
|||||||
CloseHandle(file);
|
CloseHandle(file);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
DecodeAuthMethod(const String:auth[], String:method[32], &offset)
|
||||||
|
{
|
||||||
|
if (StrContains(auth, "STEAM_") == 0)
|
||||||
|
{
|
||||||
|
strcopy(method, sizeof(method), AUTHMETHOD_STEAM);
|
||||||
|
offset = 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (auth[0] == '!')
|
||||||
|
{
|
||||||
|
strcopy(method, sizeof(method), AUTHMETHOD_IP);
|
||||||
|
offset = 1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
strcopy(method, sizeof(method), AUTHMETHOD_NAME);
|
||||||
|
offset = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ReadAdminLine(const String:line[])
|
ReadAdminLine(const String:line[])
|
||||||
{
|
{
|
||||||
|
new bool:is_bound;
|
||||||
|
new AdminId:admin;
|
||||||
new String:auth[64];
|
new String:auth[64];
|
||||||
new cur_idx = BreakString(line, auth, sizeof(auth));
|
decl String:auth_method[32];
|
||||||
new idx = cur_idx;
|
new idx, cur_idx, auth_offset;
|
||||||
|
|
||||||
if (cur_idx == -1)
|
if ((cur_idx = BreakString(line, auth, sizeof(auth))) == -1)
|
||||||
{
|
{
|
||||||
/* This line is bad... we need at least two parameters */
|
/* This line is bad... we need at least two parameters */
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Create the admin */
|
idx = cur_idx;
|
||||||
new AdminId:admin = CreateAdmin();
|
|
||||||
|
/* Check if we can bind beforehand */
|
||||||
|
DecodeAuthMethod(auth, auth_method, auth_offset);
|
||||||
|
if ((admin = FindAdminByIdentity(auth_method, auth[auth_offset])) == INVALID_ADMIN_ID)
|
||||||
|
{
|
||||||
|
/* There is no binding, create the admin */
|
||||||
|
admin = CreateAdmin();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
is_bound = true;
|
||||||
|
}
|
||||||
|
|
||||||
/* Read flags */
|
/* Read flags */
|
||||||
new String:flags[64];
|
new String:flags[64];
|
||||||
@ -133,7 +170,9 @@ ReadAdminLine(const String:line[])
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
AdminInheritGroup(admin, gid);
|
AdminInheritGroup(admin, gid);
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
new len = strlen(flags[flag_idx]);
|
new len = strlen(flags[flag_idx]);
|
||||||
new bool:is_default = false;
|
new bool:is_default = false;
|
||||||
for (new i=0; i<len; i++)
|
for (new i=0; i<len; i++)
|
||||||
@ -172,15 +211,12 @@ ReadAdminLine(const String:line[])
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Now, bind the identity to something */
|
/* Now, bind the identity to something */
|
||||||
if (StrContains(auth, "STEAM_") == 0)
|
if (!is_bound)
|
||||||
{
|
{
|
||||||
BindAdminIdentity(admin, AUTHMETHOD_STEAM, auth);
|
if (!BindAdminIdentity(admin, auth_method, auth[auth_offset]))
|
||||||
} else {
|
|
||||||
if (auth[0] == '!')
|
|
||||||
{
|
{
|
||||||
BindAdminIdentity(admin, AUTHMETHOD_IP, auth[1]);
|
/* We should never reach here */
|
||||||
} else {
|
ParseError("Failed to bind identity %s (method %s)", auth[auth_offset], auth_method);
|
||||||
BindAdminIdentity(admin, AUTHMETHOD_NAME, auth);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -36,10 +36,14 @@
|
|||||||
#define USER_STATE_INADMIN 2
|
#define USER_STATE_INADMIN 2
|
||||||
|
|
||||||
static Handle:g_hUserParser = INVALID_HANDLE;
|
static Handle:g_hUserParser = INVALID_HANDLE;
|
||||||
static AdminId:g_CurUser = INVALID_ADMIN_ID;
|
|
||||||
static g_UserState = USER_STATE_NONE;
|
static g_UserState = USER_STATE_NONE;
|
||||||
static String:g_CurAuth[64];
|
static String:g_CurAuth[64];
|
||||||
static String:g_CurIdent[64];
|
static String:g_CurIdent[64];
|
||||||
|
static String:g_CurName[64];
|
||||||
|
static String:g_CurPass[64];
|
||||||
|
static Handle:g_GroupArray;
|
||||||
|
static g_CurFlags;
|
||||||
|
static g_CurImmunity;
|
||||||
|
|
||||||
public SMCResult:ReadUsers_NewSection(Handle:smc, const String:name[], bool:opt_quotes)
|
public SMCResult:ReadUsers_NewSection(Handle:smc, const String:name[], bool:opt_quotes)
|
||||||
{
|
{
|
||||||
@ -54,16 +58,25 @@ public SMCResult:ReadUsers_NewSection(Handle:smc, const String:name[], bool:opt_
|
|||||||
if (StrEqual(name, "Admins"))
|
if (StrEqual(name, "Admins"))
|
||||||
{
|
{
|
||||||
g_UserState = USER_STATE_ADMINS;
|
g_UserState = USER_STATE_ADMINS;
|
||||||
g_CurUser = INVALID_ADMIN_ID;
|
}
|
||||||
} else {
|
else
|
||||||
|
{
|
||||||
g_IgnoreLevel++;
|
g_IgnoreLevel++;
|
||||||
}
|
}
|
||||||
} else if (g_UserState == USER_STATE_ADMINS) {
|
}
|
||||||
|
else if (g_UserState == USER_STATE_ADMINS)
|
||||||
|
{
|
||||||
g_UserState = USER_STATE_INADMIN;
|
g_UserState = USER_STATE_INADMIN;
|
||||||
g_CurUser = CreateAdmin(name);
|
strcopy(g_CurName, sizeof(g_CurName), name);
|
||||||
g_CurAuth[0] = '\0';
|
g_CurAuth[0] = '\0';
|
||||||
g_CurIdent[0] = '\0';
|
g_CurIdent[0] = '\0';
|
||||||
} else {
|
g_CurPass[0] = '\0';
|
||||||
|
ClearArray(g_GroupArray);
|
||||||
|
g_CurFlags = 0;
|
||||||
|
g_CurImmunity = 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
g_IgnoreLevel++;
|
g_IgnoreLevel++;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -76,28 +89,22 @@ public SMCResult:ReadUsers_KeyValue(Handle:smc,
|
|||||||
bool:key_quotes,
|
bool:key_quotes,
|
||||||
bool:value_quotes)
|
bool:value_quotes)
|
||||||
{
|
{
|
||||||
if (g_UserState != USER_STATE_INADMIN
|
if (g_UserState != USER_STATE_INADMIN || g_IgnoreLevel)
|
||||||
|| g_IgnoreLevel
|
|
||||||
|| g_CurUser == INVALID_ADMIN_ID)
|
|
||||||
{
|
{
|
||||||
return SMCParse_Continue;
|
return SMCParse_Continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
new bool:auth = false;
|
|
||||||
|
|
||||||
if (StrEqual(key, "auth"))
|
if (StrEqual(key, "auth"))
|
||||||
{
|
{
|
||||||
auth = true;
|
|
||||||
strcopy(g_CurAuth, sizeof(g_CurAuth), value);
|
strcopy(g_CurAuth, sizeof(g_CurAuth), value);
|
||||||
}
|
}
|
||||||
else if (StrEqual(key, "identity"))
|
else if (StrEqual(key, "identity"))
|
||||||
{
|
{
|
||||||
auth = true;
|
|
||||||
strcopy(g_CurIdent, sizeof(g_CurIdent), value);
|
strcopy(g_CurIdent, sizeof(g_CurIdent), value);
|
||||||
}
|
}
|
||||||
else if (StrEqual(key, "password"))
|
else if (StrEqual(key, "password"))
|
||||||
{
|
{
|
||||||
SetAdminPassword(g_CurUser, value);
|
strcopy(g_CurPass, sizeof(g_CurPass), value);
|
||||||
}
|
}
|
||||||
else if (StrEqual(key, "group"))
|
else if (StrEqual(key, "group"))
|
||||||
{
|
{
|
||||||
@ -105,39 +112,30 @@ public SMCResult:ReadUsers_KeyValue(Handle:smc,
|
|||||||
if (id == INVALID_GROUP_ID)
|
if (id == INVALID_GROUP_ID)
|
||||||
{
|
{
|
||||||
ParseError("Unknown group \"%s\"", value);
|
ParseError("Unknown group \"%s\"", value);
|
||||||
} else if (!AdminInheritGroup(g_CurUser, id)) {
|
|
||||||
ParseError("Unable to inherit group \"%s\"", value);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PushArrayCell(g_GroupArray, id);
|
||||||
}
|
}
|
||||||
else if (StrEqual(key, "flags"))
|
else if (StrEqual(key, "flags"))
|
||||||
{
|
{
|
||||||
new len = strlen(value);
|
new len = strlen(value);
|
||||||
new AdminFlag:flag;
|
new AdminFlag:flag;
|
||||||
|
|
||||||
for (new i=0; i<len; i++)
|
for (new i = 0; i < len; i++)
|
||||||
{
|
{
|
||||||
if (!FindFlagByChar(value[i], flag))
|
if (!FindFlagByChar(value[i], flag))
|
||||||
{
|
{
|
||||||
ParseError("Invalid flag detected: %c", value[i]);
|
ParseError("Invalid flag detected: %c", value[i]);
|
||||||
}
|
}
|
||||||
SetAdminFlag(g_CurUser, flag, true);
|
else
|
||||||
|
{
|
||||||
|
g_CurFlags |= FlagToBit(flag);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (StrEqual(key, "immunity"))
|
else if (StrEqual(key, "immunity"))
|
||||||
{
|
{
|
||||||
new level = StringToInt(value);
|
g_CurImmunity = StringToInt(value);
|
||||||
SetAdminImmunityLevel(g_CurUser, level);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (auth && g_CurIdent[0] && g_CurAuth[0])
|
|
||||||
{
|
|
||||||
if (BindAdminIdentity(g_CurUser, g_CurAuth, g_CurIdent))
|
|
||||||
{
|
|
||||||
g_CurAuth[0] = '\0';
|
|
||||||
g_CurIdent[0] = '\0';
|
|
||||||
} else {
|
|
||||||
ParseError("Failed to bind auth \"%s\" to identity \"%s\"", g_CurAuth, g_CurIdent);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return SMCParse_Continue;
|
return SMCParse_Continue;
|
||||||
@ -153,9 +151,48 @@ public SMCResult:ReadUsers_EndSection(Handle:smc)
|
|||||||
|
|
||||||
if (g_UserState == USER_STATE_INADMIN)
|
if (g_UserState == USER_STATE_INADMIN)
|
||||||
{
|
{
|
||||||
|
/* Dump this user to memory */
|
||||||
|
if (g_CurIdent[0] != '\0' && g_CurAuth[0] != '\0')
|
||||||
|
{
|
||||||
|
decl AdminFlag:flags[26];
|
||||||
|
new AdminId:id, i, num_groups, num_flags;
|
||||||
|
|
||||||
|
if ((id = FindAdminByIdentity(g_CurAuth, g_CurIdent)) == INVALID_ADMIN_ID)
|
||||||
|
{
|
||||||
|
id = CreateAdmin(g_CurName);
|
||||||
|
if (!BindAdminIdentity(id, g_CurAuth, g_CurIdent))
|
||||||
|
{
|
||||||
|
ParseError("Failed to bind auth \"%s\" to identity \"%s\"", g_CurAuth, g_CurIdent);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
num_groups = GetArraySize(g_GroupArray);
|
||||||
|
for (i = 0; i < num_groups; i++)
|
||||||
|
{
|
||||||
|
AdminInheritGroup(id, GetArrayCell(g_GroupArray, i));
|
||||||
|
}
|
||||||
|
|
||||||
|
SetAdminPassword(id, g_CurPass);
|
||||||
|
if (GetAdminImmunityLevel(id) < g_CurImmunity)
|
||||||
|
{
|
||||||
|
SetAdminImmunityLevel(id, g_CurImmunity);
|
||||||
|
}
|
||||||
|
|
||||||
|
num_flags = FlagBitsToArray(g_CurFlags, flags, sizeof(flags));
|
||||||
|
for (i = 0; i < num_flags; i++)
|
||||||
|
{
|
||||||
|
SetAdminFlag(id, flags[i], true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ParseError("Failed to create admin: did you forget either the auth or identity properties?");
|
||||||
|
}
|
||||||
|
|
||||||
g_UserState = USER_STATE_ADMINS;
|
g_UserState = USER_STATE_ADMINS;
|
||||||
g_CurUser = INVALID_ADMIN_ID;
|
}
|
||||||
} else if (g_UserState == USER_STATE_ADMINS) {
|
else if (g_UserState == USER_STATE_ADMINS)
|
||||||
|
{
|
||||||
g_UserState = USER_STATE_NONE;
|
g_UserState = USER_STATE_NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -179,6 +216,8 @@ static InitializeUserParser()
|
|||||||
ReadUsers_KeyValue,
|
ReadUsers_KeyValue,
|
||||||
ReadUsers_EndSection);
|
ReadUsers_EndSection);
|
||||||
SMC_SetRawLine(g_hUserParser, ReadUsers_CurrentLine);
|
SMC_SetRawLine(g_hUserParser, ReadUsers_CurrentLine);
|
||||||
|
|
||||||
|
g_GroupArray = CreateArray();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -199,7 +238,9 @@ ReadUsers()
|
|||||||
if (SMC_GetErrorString(err, buffer, sizeof(buffer)))
|
if (SMC_GetErrorString(err, buffer, sizeof(buffer)))
|
||||||
{
|
{
|
||||||
ParseError("%s", buffer);
|
ParseError("%s", buffer);
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
ParseError("Fatal parse error");
|
ParseError("Fatal parse error");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user