UptimeRestarts: first major update
more to follow
This commit is contained in:
parent
62d14ea7b7
commit
e27a18d42b
@ -2,16 +2,22 @@
|
||||
|
||||
#include <sourcemod>
|
||||
#include <files>
|
||||
#include <multicolors>
|
||||
|
||||
float g_fUptime;
|
||||
int g_iRestartCountdown;
|
||||
bool g_bForcedRestart;
|
||||
|
||||
ConVar g_cvarMaxPlayersForControlledRestart;
|
||||
ConVar g_cvarMinPlayersForForcedRestart;
|
||||
ConVar g_cvarMinHoursUptimeForForcedRestart;
|
||||
|
||||
public Plugin myinfo =
|
||||
{
|
||||
name = "UptimeRestart",
|
||||
author = "Dogan",
|
||||
description = "Display Server Uptime and do controlled Restarts",
|
||||
version = "1.1.0",
|
||||
version = "2.0.0",
|
||||
url = ""
|
||||
};
|
||||
|
||||
@ -20,10 +26,56 @@ public void OnPluginStart()
|
||||
RegAdminCmd("uptime", Command_Uptime, ADMFLAG_GENERIC, "Displays server Uptime");
|
||||
RegAdminCmd("sm_uptime", Command_Uptime, ADMFLAG_GENERIC, "Displays server Uptime");
|
||||
|
||||
g_cvarMaxPlayersForControlledRestart = CreateConVar("sm_maxplayers_controlled_restart", "1", "Max Amount of Players Connected to Server to do a controlled restart in the night", FCVAR_NONE, true, 1.0, true, 64.0);
|
||||
g_cvarMinPlayersForForcedRestart = CreateConVar("sm_minplayers_forced_restart", "55", "Min Amount of Players Connected to Server to do a forced restart in the afternoon", FCVAR_NONE, true, 1.0, true, 64.0);
|
||||
g_cvarMinHoursUptimeForForcedRestart = CreateConVar("sm_minhours_forced_restart", "60", "Min Hours of Uptime to force a forced restart in the afternoon", FCVAR_NONE, true, 1.0, true, 96.0);
|
||||
|
||||
g_iRestartCountdown = 5;
|
||||
g_bForcedRestart = false;
|
||||
GetUptimeIfControlledRestart();
|
||||
GetNextmapIfForcedRestart();
|
||||
|
||||
AutoExecConfig(true, "plugin.UptimeRestarts");
|
||||
|
||||
CreateTimer(60.0, CheckRestart, _, TIMER_REPEAT);
|
||||
CreateTimer(20.0, ForceRestartMessage, _, TIMER_REPEAT);
|
||||
}
|
||||
|
||||
public void OnMapEnd()
|
||||
{
|
||||
if(!g_bForcedRestart)
|
||||
return;
|
||||
|
||||
CPrintToChatAll("{red}WARNING:{white} Restarting Server now!");
|
||||
CPrintToChatAll("{red}WARNING:{white} Restarting Server now!");
|
||||
CPrintToChatAll("{red}WARNING:{white} Restarting Server now!");
|
||||
PrintCenterTextAll("WARNING: Restarting Server now!");
|
||||
|
||||
char sNextmap[64];
|
||||
GetNextMap(sNextmap, sizeof(sNextmap));
|
||||
|
||||
if(!StrEqual(sNextmap, ""))
|
||||
{
|
||||
File NextmapFile = OpenFile("nextmap.txt", "w");
|
||||
NextmapFile.WriteLine(sNextmap);
|
||||
delete NextmapFile;
|
||||
}
|
||||
|
||||
RequestFrame(ForceRestart);
|
||||
}
|
||||
|
||||
public void GetNextmapIfForcedRestart()
|
||||
{
|
||||
File NextmapFile = OpenFile("nextmap.txt", "r");
|
||||
|
||||
if(NextmapFile != null)//There was a nextmap set
|
||||
{
|
||||
char sNextmap[64];
|
||||
NextmapFile.ReadLine(sNextmap, sizeof(sNextmap));
|
||||
delete NextmapFile;
|
||||
DeleteFile("nextmap.txt");
|
||||
ForceChangeLevel(sNextmap, "Set to Map that was next before Force Restart happened");
|
||||
}
|
||||
}
|
||||
|
||||
public void GetUptimeIfControlledRestart()
|
||||
@ -87,11 +139,10 @@ public Action Command_Uptime(int client, int args)
|
||||
|
||||
public Action CheckRestart(Handle timer)
|
||||
{
|
||||
if(!IsItRestartTime())
|
||||
if(g_bForcedRestart)
|
||||
return Plugin_Continue;
|
||||
|
||||
if(GetEngineTime() < 57500) //16 hours
|
||||
return Plugin_Continue;
|
||||
float fMinHoursUptime = g_cvarMinHoursUptimeForForcedRestart.FloatValue * 60.0 * 60.0;
|
||||
|
||||
int iPlayers = GetClientCount(false);
|
||||
for(int i = 1; i <= MaxClients; i++)
|
||||
@ -99,7 +150,17 @@ public Action CheckRestart(Handle timer)
|
||||
if(IsClientConnected(i) && IsFakeClient(i))
|
||||
iPlayers--;
|
||||
}
|
||||
if(iPlayers > 1) //jenz's autism bot
|
||||
|
||||
if((GetEngineTime() > fMinHoursUptime) && (iPlayers > g_cvarMinPlayersForForcedRestart.IntValue))
|
||||
{
|
||||
g_bForcedRestart = true;
|
||||
return Plugin_Continue;
|
||||
}
|
||||
|
||||
if(!IsItRestartTime())
|
||||
return Plugin_Continue;
|
||||
|
||||
if(iPlayers > g_cvarMaxPlayersForControlledRestart.IntValue) //jenz's autism bot
|
||||
return Plugin_Continue;
|
||||
|
||||
float fUptime = GetEngineTime();
|
||||
@ -135,7 +196,7 @@ stock bool IsItRestartTime()
|
||||
public Action RestartCountdown(Handle timer)
|
||||
{
|
||||
PrintCenterTextAll("WARNING: Restarting Server in %d.", g_iRestartCountdown);
|
||||
PrintToChatAll("WARNING: Restarting Server in %d.", g_iRestartCountdown);
|
||||
CPrintToChatAll("{red}WARNING:{white} Restarting Server in %d.", g_iRestartCountdown);
|
||||
g_iRestartCountdown--;
|
||||
|
||||
if(g_iRestartCountdown < 0)
|
||||
@ -147,3 +208,20 @@ public Action RestartCountdown(Handle timer)
|
||||
|
||||
return Plugin_Handled; //Server is dead by here anyway xD
|
||||
}
|
||||
|
||||
public void ForceRestart()
|
||||
{
|
||||
LogToFile("addons/sourcemod/logs/restarts.txt", "Successfully force-restarted the Server.");
|
||||
ServerCommand("_restart");
|
||||
}
|
||||
|
||||
public Action ForceRestartMessage(Handle timer)
|
||||
{
|
||||
if(!g_bForcedRestart)
|
||||
return Plugin_Continue;
|
||||
|
||||
CPrintToChatAll("{red}WARNING:{white} Restarting Server when this Map ends!");
|
||||
CPrintToChatAll("{red}WARNING:{white} Remember to join after couple seconds!");
|
||||
|
||||
return Plugin_Continue;
|
||||
}
|
Loading…
Reference in New Issue
Block a user