NoAdminTools: improve sm_checkadmins

This commit is contained in:
Dogan 2019-07-08 15:33:53 +02:00
parent eeba405984
commit 5f01907035

View File

@ -15,6 +15,7 @@ float g_fSelfExtendsDelay;
bool g_bSelfExtends[MAXPLAYERS + 1] = { false, ...};
bool g_bSelfExtendsAllowed;
bool g_bActiveAdmin[MAXPLAYERS + 1] = { false, ...};
int g_iSelfExtends;
ConVar g_cvarTimeLimit;
@ -24,7 +25,7 @@ public Plugin myinfo =
name = "No Admin Tools",
author = "Dogan",
description = "Make it possible for the server to do several things when there is no active admin online",
version = "1.0.0",
version = "1.1.0",
url = ""
};
@ -76,24 +77,29 @@ public void Cvar_SelfExtendsDelay(ConVar convar, const char[] oldValue, const ch
g_fSelfExtendsDelay = convar.FloatValue;
}
public bool ActiveAdminPresent()
public bool ActiveAdmin(int client)
{
for(int i = 1; i <= MaxClients; i++)
{
if(IsValidClient(i) && CheckCommandAccess(i, "", ADMFLAG_GENERIC) && (GetClientIdleTime(i) < g_iAdminAFKTime))
return true;
}
return false;
if(GetClientIdleTime(client) < g_iAdminAFKTime)
return true;
return false;
}
public void OnClientDisconnect(int client)
{
g_bSelfExtends[client] = false;
g_bActiveAdmin[client] = false;
CheckRatio();
}
public void OnClientPutInServer(int client)
public void OnClientPostAdminCheck(int client)
{
if(CheckCommandAccess(client, "", ADMFLAG_GENERIC) && IsValidClient(client))
{
g_bActiveAdmin[client] = true;
}
CheckRatio();
}
@ -120,22 +126,67 @@ public Action Timer_DelaySelfExtend(Handle timer)
public Action Command_DisplayActiveAdmins(int client, int args)
{
if(ActiveAdminPresent())
ReplyToCommand(client, "[SM] There are active Admins online.");
for(int i = 1; i <= MaxClients; i++)
if(CheckCommandAccess(i, "", ADMFLAG_GENERIC) && IsValidClient(i) && ActiveAdmin(i))
g_bActiveAdmin[i] = true;
char aBuf[1024];
char aBuf2[MAX_NAME_LENGTH];
char bBuf[1024];
char bBuf2[MAX_NAME_LENGTH];
for(int i = 1; i <= MaxClients; i++)
{
if(IsClientInGame(i) && !IsFakeClient(i))
{
if(g_bActiveAdmin[i])
{
GetClientName(i, aBuf2, sizeof(aBuf2));
StrCat(aBuf, sizeof(aBuf), aBuf2);
StrCat(aBuf, sizeof(aBuf), ", ");
}
if(!g_bActiveAdmin[i] && CheckCommandAccess(i, "", ADMFLAG_GENERIC) && IsValidClient(i))
{
GetClientName(i, bBuf2, sizeof(bBuf2));
StrCat(bBuf, sizeof(bBuf), bBuf2);
StrCat(bBuf, sizeof(bBuf), ", ");
}
}
}
if(strlen(aBuf))
{
aBuf[strlen(aBuf) - 2] = 0;
ReplyToCommand(client, "[SM] Active Admins online: %s", aBuf);
}
else
ReplyToCommand(client, "[SM] There are no active Admins online.");
ReplyToCommand(client, "[SM] Active Admins online: none");
if(strlen(bBuf))
{
bBuf[strlen(bBuf) - 2] = 0;
ReplyToCommand(client, "[SM] Inactive Admins online: %s", bBuf);
}
else
ReplyToCommand(client, "[SM] Inactive Admins online: none");
return Plugin_Handled;
}
public Action Command_SelfExtend(int client, int args)
{
int iAdminActivity = 0;
for(int i = 1; i <= MaxClients; i++)
if(g_bActiveAdmin[i])
iAdminActivity++;
if(GetExtendsLeft() > 0)
{
ReplyToCommand(client, "[SM] Not available because not all regular extends have been depleted.");
return Plugin_Handled;
}
if(ActiveAdminPresent())
if(iAdminActivity > 0)
{
ReplyToCommand(client, "[SM] Not available because there is atleast one active Admin who can extend. Please ask the Admins.");
return Plugin_Handled;