fixed race condition that would overwrite admin access when using the unloze clan tag

This commit is contained in:
jenz 2023-08-12 22:12:33 +02:00
parent f8a4043e5d
commit d2bb72bb88

View File

@ -13,6 +13,8 @@ public Plugin myinfo =
url = "" url = ""
}; };
bool post_filter_admin[MAXPLAYERS + 1];
public void OnPluginStart() public void OnPluginStart()
{ {
/* Handle late load */ /* Handle late load */
@ -25,9 +27,15 @@ public void OnPluginStart()
} }
} }
public void OnClientDisconnect(int client)
{
post_filter_admin[client] = false;
}
public void OnClientPostAdminFilter(int client) public void OnClientPostAdminFilter(int client)
{ {
CheckClantag(client); post_filter_admin[client] = true;
CheckClantag(client);
} }
public void OnClientSettingsChanged(int client) public void OnClientSettingsChanged(int client)
@ -37,33 +45,37 @@ public void OnClientSettingsChanged(int client)
void CheckClantag(int client) void CheckClantag(int client)
{ {
if(!IsClientAuthorized(client)) if(!IsClientAuthorized(client))
return; return;
if (!post_filter_admin[client])
{
return;
}
char sClanID[32]; char sClanID[32];
GetClientInfo(client, "cl_clanid", sClanID, sizeof(sClanID)); GetClientInfo(client, "cl_clanid", sClanID, sizeof(sClanID));
if(!StrEqual(sClanID, CLANID)) if(!StrEqual(sClanID, CLANID))
return; return;
AdminId AdmID; AdminId AdmID;
GroupId GrpID; GroupId GrpID;
if ((AdmID = GetUserAdmin(client)) == INVALID_ADMIN_ID) if ((AdmID = GetUserAdmin(client)) == INVALID_ADMIN_ID)
{ {
LogMessage("Creating new admin for %L", client); LogMessage("Creating new admin for %L", client);
AdmID = CreateAdmin(""); AdmID = CreateAdmin("");
SetUserAdmin(client, AdmID, true); SetUserAdmin(client, AdmID, true);
} }
if ((GrpID = FindAdmGroup(GROUP)) != INVALID_GROUP_ID) if ((GrpID = FindAdmGroup(GROUP)) != INVALID_GROUP_ID)
{ {
if (AdminInheritGroup(AdmID, GrpID)) if (AdminInheritGroup(AdmID, GrpID))
LogMessage("%L added to group %s", client, GROUP); LogMessage("%L added to group %s", client, GROUP);
} }
else else
{ {
LogMessage("%L group not found %s", client, GROUP); LogMessage("%L group not found %s", client, GROUP);
} }
} }