StatGroups: Convert to AdminGroups plugin.
This commit is contained in:
parent
a7207969ec
commit
5e5dfffb94
@ -1,16 +1,9 @@
|
||||
#pragma newdecls required
|
||||
|
||||
#include <sourcemod>
|
||||
#include <admingroups>
|
||||
|
||||
#define GAMEID "csgo-ze"
|
||||
|
||||
/* BOOLS */
|
||||
bool G_bPreAdminChecked[MAXPLAYERS+1];
|
||||
bool G_bResponseFailed[MAXPLAYERS+1];
|
||||
bool G_bResponsePassed[MAXPLAYERS+1];
|
||||
|
||||
/* INTERGERS */
|
||||
int iRank[MAXPLAYERS+1] = {-1, ...};
|
||||
#define GameID "csgo-ze"
|
||||
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
@ -26,59 +19,11 @@ public Plugin myinfo =
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
public void OnRebuildAdminCache(AdminCachePart part)
|
||||
public void OnAllPluginsLoaded()
|
||||
{
|
||||
if (part == AdminCache_Overrides)
|
||||
return;
|
||||
|
||||
if (part == AdminCache_Groups)
|
||||
{
|
||||
CreateAdminGroup("Ranking-Top10");
|
||||
CreateAdminGroup("Ranking-Top20");
|
||||
CreateAdminGroup("Ranking-Top40");
|
||||
}
|
||||
|
||||
CreateTimer(1.0, OnRebuildAdminCachePost, INVALID_HANDLE, TIMER_FLAG_NO_MAPCHANGE);
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
public Action OnRebuildAdminCachePost(Handle hTimer)
|
||||
{
|
||||
for (int client = 1; client <= MaxClients; client++)
|
||||
{
|
||||
if (!G_bResponsePassed[client] || !G_bPreAdminChecked[client])
|
||||
continue;
|
||||
|
||||
if (iRank[client] <= 10) ApplyAdminGroup(client, "Ranking-Top10");
|
||||
if (iRank[client] <= 20) ApplyAdminGroup(client, "Ranking-Top20");
|
||||
if (iRank[client] <= 40) ApplyAdminGroup(client, "Ranking-Top40");
|
||||
}
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
public void OnClientConnected(int client)
|
||||
{
|
||||
G_bPreAdminChecked[client] = false;
|
||||
G_bResponseFailed[client] = false;
|
||||
G_bResponsePassed[client] = false;
|
||||
|
||||
iRank[client] = -1;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
public void OnClientDisconnect(int client)
|
||||
{
|
||||
G_bPreAdminChecked[client] = false;
|
||||
G_bResponseFailed[client] = false;
|
||||
G_bResponsePassed[client] = false;
|
||||
|
||||
iRank[client] = -1;
|
||||
AdminGroups_CreateAdminGroup("Ranking-Top10");
|
||||
AdminGroups_CreateAdminGroup("Ranking-Top20");
|
||||
AdminGroups_CreateAdminGroup("Ranking-Top40");
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
@ -86,82 +31,11 @@ public void OnClientDisconnect(int client)
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
public void OnClientAuthorized(int client, const char[] sAuthID)
|
||||
{
|
||||
if ((iRank[client] = RetrieveStatRank(client)) != -1)
|
||||
G_bResponsePassed[client] = true;
|
||||
else
|
||||
G_bResponseFailed[client] = true;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
public Action OnClientPreAdminCheck(int client)
|
||||
{
|
||||
G_bPreAdminChecked[client] = true;
|
||||
|
||||
if (G_bResponsePassed[client] || G_bResponseFailed[client])
|
||||
return Plugin_Continue;
|
||||
|
||||
RunAdminCacheChecks(client);
|
||||
return Plugin_Handled;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
public void OnClientPostAdminFilter(int client)
|
||||
{
|
||||
if (!G_bResponsePassed[client])
|
||||
return;
|
||||
|
||||
if (iRank[client] <= 10) ApplyAdminGroup(client, "Ranking-Top10");
|
||||
if (iRank[client] <= 20) ApplyAdminGroup(client, "Ranking-Top20");
|
||||
if (iRank[client] <= 40) ApplyAdminGroup(client, "Ranking-Top40");
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
stock void CreateAdminGroup(const char[] group)
|
||||
{
|
||||
GroupId GrpID;
|
||||
|
||||
if ((GrpID = FindAdmGroup(group)) == INVALID_GROUP_ID)
|
||||
{
|
||||
LogMessage("Creating new admin group %s", group);
|
||||
|
||||
GrpID = CreateAdmGroup(group);
|
||||
GrpID.ImmunityLevel = 0;
|
||||
}
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
stock void ApplyAdminGroup(int client, const char[] group)
|
||||
{
|
||||
AdminId AdmID;
|
||||
GroupId GrpID;
|
||||
|
||||
if ((AdmID = GetUserAdmin(client)) == INVALID_ADMIN_ID)
|
||||
{
|
||||
LogMessage("Creating new admin for %L", client);
|
||||
|
||||
AdmID = CreateAdmin();
|
||||
SetUserAdmin(client, AdmID, true);
|
||||
}
|
||||
|
||||
if ((GrpID = FindAdmGroup(group)) != INVALID_GROUP_ID)
|
||||
{
|
||||
if (AdminInheritGroup(AdmID, GrpID))
|
||||
{
|
||||
LogMessage("%L added to group %s", client, group);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
LogMessage("%L group not found %s", client, group);
|
||||
}
|
||||
int rank = RetrieveStatRank(client);
|
||||
|
||||
if (rank <= 10) AdminGroups_GrantAdminGroup(client, "Ranking-Top10");
|
||||
if (rank <= 20) AdminGroups_GrantAdminGroup(client, "Ranking-Top20");
|
||||
if (rank <= 40) AdminGroups_GrantAdminGroup(client, "Ranking-Top40");
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
@ -190,7 +64,7 @@ stock int RetrieveStatRank(int client)
|
||||
if (GetClientAuthId(client, AuthId_Steam2, sSteamID, sizeof(sSteamID)))
|
||||
strcopy(sSteamID, sizeof(sSteamID), sSteamID[8]);
|
||||
|
||||
SQL_FormatQuery(database, sQuery, sizeof(sQuery), "SELECT COUNT(*) AS rank FROM hlstats_Players WHERE hlstats_Players.game = '%s' AND hideranking = 0 AND skill > (SELECT skill FROM hlstats_Players JOIN hlstats_PlayerUniqueIds ON hlstats_Players.playerId = hlstats_PlayerUniqueIds.playerId WHERE hlstats_PlayerUniqueIds.game = '%s' AND uniqueId = '%s')", GAMEID, GAMEID, sSteamID);
|
||||
SQL_FormatQuery(database, sQuery, sizeof(sQuery), "SELECT COUNT(*) AS rank FROM hlstats_Players WHERE hlstats_Players.game = '%s' AND hideranking = 0 AND skill > (SELECT skill FROM hlstats_Players JOIN hlstats_PlayerUniqueIds ON hlstats_Players.playerId = hlstats_PlayerUniqueIds.playerId WHERE hlstats_PlayerUniqueIds.game = '%s' AND uniqueId = '%s')", GameID, GameID, sSteamID);
|
||||
|
||||
DBResultSet results;
|
||||
if ((results = SQL_Query(database, sQuery)) == null)
|
||||
|
Loading…
Reference in New Issue
Block a user