added support for average hours count on server

This commit is contained in:
jenz
2023-04-09 13:57:09 +02:00
parent d21303488b
commit 1c4f1d532c
3 changed files with 173 additions and 109 deletions
@@ -360,100 +360,107 @@ public void OnNominationRemoved(const char[] map)
public Action Command_Addmap(int client, int args)
{
if(args == 0)
{
AttemptAdminNominate(client);
return Plugin_Handled;
}
if(args == 0)
{
AttemptAdminNominate(client);
return Plugin_Handled;
}
if(args != 1)
{
CReplyToCommand(client, "[NE] Usage: sm_nominate_addmap <mapname>");
return Plugin_Handled;
}
if(args != 1)
{
CReplyToCommand(client, "[NE] Usage: sm_nominate_addmap <mapname>");
return Plugin_Handled;
}
static char mapname[PLATFORM_MAX_PATH];
GetCmdArg(1, mapname, sizeof(mapname));
static char mapname[PLATFORM_MAX_PATH];
GetCmdArg(1, mapname, sizeof(mapname));
if(!IsMapValid(mapname))
{
CReplyToCommand(client, "%t", "Map was not found", mapname);
AttemptAdminNominate(client, mapname);
return Plugin_Handled;
}
if(!IsMapValid(mapname))
{
CReplyToCommand(client, "%t", "Map was not found", mapname);
AttemptAdminNominate(client, mapname);
return Plugin_Handled;
}
if(!CheckCommandAccess(client, "sm_nominate_ignore", ADMFLAG_CHEATS, true))
{
bool RestrictionsActive = AreRestrictionsActive();
if(!CheckCommandAccess(client, "sm_nominate_ignore", ADMFLAG_CHEATS, true))
{
bool RestrictionsActive = AreRestrictionsActive();
int status;
if(GetTrieValue(g_mapTrie, mapname, status))
{
if((status & MAPSTATUS_DISABLED) == MAPSTATUS_DISABLED)
{
if((status & MAPSTATUS_EXCLUDE_CURRENT) == MAPSTATUS_EXCLUDE_CURRENT)
CPrintToChat(client, "[NE] %t", "Cant Nominate Current Map");
int status;
if(GetTrieValue(g_mapTrie, mapname, status))
{
if((status & MAPSTATUS_DISABLED) == MAPSTATUS_DISABLED)
{
if((status & MAPSTATUS_EXCLUDE_CURRENT) == MAPSTATUS_EXCLUDE_CURRENT)
CPrintToChat(client, "[NE] %t", "Cant Nominate Current Map");
if(RestrictionsActive && (status & MAPSTATUS_EXCLUDE_PREVIOUS) == MAPSTATUS_EXCLUDE_PREVIOUS)
{
int Cooldown = GetMapCooldown(mapname);
CPrintToChat(client, "[NE] %t (%d)", "Map in Exclude List", Cooldown);
}
if(RestrictionsActive && (status & MAPSTATUS_EXCLUDE_PREVIOUS) == MAPSTATUS_EXCLUDE_PREVIOUS)
{
int Cooldown = GetMapCooldown(mapname);
CPrintToChat(client, "[NE] %t (%d)", "Map in Exclude List", Cooldown);
}
if((status & MAPSTATUS_EXCLUDE_NOMINATED) == MAPSTATUS_EXCLUDE_NOMINATED)
CPrintToChat(client, "[NE] %t", "Map Already Nominated");
if((status & MAPSTATUS_EXCLUDE_NOMINATED) == MAPSTATUS_EXCLUDE_NOMINATED)
CPrintToChat(client, "[NE] %t", "Map Already Nominated");
return Plugin_Handled;
}
}
return Plugin_Handled;
}
}
int Cooldown = GetMapCooldownTime(mapname);
if(RestrictionsActive && Cooldown > GetTime())
{
int Seconds = Cooldown - GetTime();
CPrintToChat(client, "[NE] %t", "Map Cooldown Time Error", Seconds / 3600, (Seconds % 3600) / 60);
int Cooldown = GetMapCooldownTime(mapname);
if(RestrictionsActive && Cooldown > GetTime())
{
int Seconds = Cooldown - GetTime();
CPrintToChat(client, "[NE] %t", "Map Cooldown Time Error", Seconds / 3600, (Seconds % 3600) / 60);
return Plugin_Handled;
}
return Plugin_Handled;
}
int TimeRestriction = GetMapTimeRestriction(mapname);
if(RestrictionsActive && TimeRestriction)
{
CPrintToChat(client, "[NE] %t", "Map Nominate Time Error", TimeRestriction / 60, TimeRestriction % 60);
int TimeRestriction = GetMapTimeRestriction(mapname);
if(RestrictionsActive && TimeRestriction)
{
CPrintToChat(client, "[NE] %t", "Map Nominate Time Error", TimeRestriction / 60, TimeRestriction % 60);
return Plugin_Handled;
}
return Plugin_Handled;
}
int PlayerRestriction = GetMapPlayerRestriction(mapname);
if(RestrictionsActive && PlayerRestriction)
{
if(PlayerRestriction < 0)
CPrintToChat(client, "[NE] %t", "Map Nominate MinPlayers Error", PlayerRestriction * -1);
else
CPrintToChat(client, "[NE] %t", "Map Nominate MaxPlayers Error", PlayerRestriction);
int AverageHourRestricted = GetAveragePlayerTimeOnServerMapRestriction(mapname);
if (AverageHourRestricted > 0)
{
PrintToChat(client, "%s requires +%i hours average. Use sm_houravg to check average.", mapname, AverageHourRestricted);
return Plugin_Handled;
}
return Plugin_Handled;
}
}
int PlayerRestriction = GetMapPlayerRestriction(mapname);
if(RestrictionsActive && PlayerRestriction)
{
if(PlayerRestriction < 0)
CPrintToChat(client, "[NE] %t", "Map Nominate MinPlayers Error", PlayerRestriction * -1);
else
CPrintToChat(client, "[NE] %t", "Map Nominate MaxPlayers Error", PlayerRestriction);
NominateResult result = NominateMap(mapname, true, 0);
return Plugin_Handled;
}
}
if(result > Nominate_Replaced)
{
/* We assume already in vote is the casue because the maplist does a Map Validity check and we forced, so it cant be full */
CReplyToCommand(client, "%t", "Map Already In Vote", mapname);
NominateResult result = NominateMap(mapname, true, 0);
return Plugin_Handled;
}
if(result > Nominate_Replaced)
{
/* We assume already in vote is the casue because the maplist does a Map Validity check and we forced, so it cant be full */
CReplyToCommand(client, "%t", "Map Already In Vote", mapname);
SetTrieValue(g_mapTrie, mapname, MAPSTATUS_DISABLED|MAPSTATUS_EXCLUDE_NOMINATED);
return Plugin_Handled;
}
CReplyToCommand(client, "%t", "Map Inserted", mapname);
LogAction(client, -1, "\"%L\" inserted map \"%s\".", client, mapname);
SetTrieValue(g_mapTrie, mapname, MAPSTATUS_DISABLED|MAPSTATUS_EXCLUDE_NOMINATED);
PrintToChatAll("[NE] %N has inserted %s into nominations", client, mapname);
CReplyToCommand(client, "%t", "Map Inserted", mapname);
LogAction(client, -1, "\"%L\" inserted map \"%s\".", client, mapname);
return Plugin_Handled;
PrintToChatAll("[NE] %N has inserted %s into nominations", client, mapname);
return Plugin_Handled;
}
public Action Command_Removemap(int client, int args)
@@ -695,6 +702,13 @@ public Action Command_Nominate(int client, int args)
return Plugin_Handled;
}
int AverageHourRestricted = GetAveragePlayerTimeOnServerMapRestriction(mapname);
if (AverageHourRestricted > 0)
{
PrintToChat(client, "%s requires +%i hours average. Use sm_houravg to check average.", mapname, AverageHourRestricted);
return Plugin_Handled;
}
int PlayerRestriction = GetMapPlayerRestriction(mapname);
if(RestrictionsActive && PlayerRestriction)
{
@@ -1003,6 +1017,7 @@ Menu BuildMapMenu(const char[] filter, int client)
GetMapCooldownTime(map) > GetTime() ||
GetMapTimeRestriction(map) ||
GetMapPlayerRestriction(map) ||
GetAveragePlayerTimeOnServerMapRestriction(map) > 0 ||
GetMapVIPRestriction(map, client)))
{
continue;
@@ -1098,6 +1113,7 @@ public int Handler_MapSelectMenu(Menu menu, MenuAction action, int param1, int p
GetMapCooldownTime(map) > GetTime() ||
GetMapTimeRestriction(map) ||
GetMapPlayerRestriction(map) ||
GetAveragePlayerTimeOnServerMapRestriction(map) > 0 ||
GetMapVIPRestriction(map, param1)))
{
PrintToChat(param1, "[NE] You cant nominate this map right now.");
@@ -1167,6 +1183,7 @@ public int Handler_MapSelectMenu(Menu menu, MenuAction action, int param1, int p
GetMapCooldownTime(map) > GetTime() ||
GetMapTimeRestriction(map) ||
GetMapPlayerRestriction(map) ||
GetAveragePlayerTimeOnServerMapRestriction(map) > 0 ||
GetMapVIPRestriction(map, param1)))
{
return ITEMDRAW_DISABLED;
@@ -1258,6 +1275,13 @@ public int Handler_MapSelectMenu(Menu menu, MenuAction action, int param1, int p
return RedrawMenuItem(display);
}
int AverageHourRestricted = GetAveragePlayerTimeOnServerMapRestriction(map);
if (AverageHourRestricted > 0)
{
Format(display, sizeof(display), "%s requires +%i hours average.", map, AverageHourRestricted);
return RedrawMenuItem(display);
}
int PlayerRestriction = GetMapPlayerRestriction(map);
if(RestrictionsActive && PlayerRestriction)
{
@@ -1352,6 +1376,7 @@ public int Handler_AdminMapSelectMenu(Menu menu, MenuAction action, int param1,
GetMapCooldownTime(map) > GetTime() ||
GetMapTimeRestriction(map) ||
GetMapPlayerRestriction(map) ||
GetAveragePlayerTimeOnServerMapRestriction(map) > 0 ||
GetMapVIPRestriction(map, param1)))
{
PrintToChat(param1, "[NE] You cant nominate this map right now.");