UptimeRestarts: first major update
more to follow
This commit is contained in:
parent
62d14ea7b7
commit
e27a18d42b
@ -2,16 +2,22 @@
|
|||||||
|
|
||||||
#include <sourcemod>
|
#include <sourcemod>
|
||||||
#include <files>
|
#include <files>
|
||||||
|
#include <multicolors>
|
||||||
|
|
||||||
float g_fUptime;
|
float g_fUptime;
|
||||||
int g_iRestartCountdown;
|
int g_iRestartCountdown;
|
||||||
|
bool g_bForcedRestart;
|
||||||
|
|
||||||
|
ConVar g_cvarMaxPlayersForControlledRestart;
|
||||||
|
ConVar g_cvarMinPlayersForForcedRestart;
|
||||||
|
ConVar g_cvarMinHoursUptimeForForcedRestart;
|
||||||
|
|
||||||
public Plugin myinfo =
|
public Plugin myinfo =
|
||||||
{
|
{
|
||||||
name = "UptimeRestart",
|
name = "UptimeRestart",
|
||||||
author = "Dogan",
|
author = "Dogan",
|
||||||
description = "Display Server Uptime and do controlled Restarts",
|
description = "Display Server Uptime and do controlled Restarts",
|
||||||
version = "1.1.0",
|
version = "2.0.0",
|
||||||
url = ""
|
url = ""
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -20,10 +26,56 @@ public void OnPluginStart()
|
|||||||
RegAdminCmd("uptime", Command_Uptime, ADMFLAG_GENERIC, "Displays server Uptime");
|
RegAdminCmd("uptime", Command_Uptime, ADMFLAG_GENERIC, "Displays server Uptime");
|
||||||
RegAdminCmd("sm_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_iRestartCountdown = 5;
|
||||||
|
g_bForcedRestart = false;
|
||||||
GetUptimeIfControlledRestart();
|
GetUptimeIfControlledRestart();
|
||||||
|
GetNextmapIfForcedRestart();
|
||||||
|
|
||||||
|
AutoExecConfig(true, "plugin.UptimeRestarts");
|
||||||
|
|
||||||
CreateTimer(60.0, CheckRestart, _, TIMER_REPEAT);
|
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()
|
public void GetUptimeIfControlledRestart()
|
||||||
@ -87,11 +139,10 @@ public Action Command_Uptime(int client, int args)
|
|||||||
|
|
||||||
public Action CheckRestart(Handle timer)
|
public Action CheckRestart(Handle timer)
|
||||||
{
|
{
|
||||||
if(!IsItRestartTime())
|
if(g_bForcedRestart)
|
||||||
return Plugin_Continue;
|
return Plugin_Continue;
|
||||||
|
|
||||||
if(GetEngineTime() < 57500) //16 hours
|
float fMinHoursUptime = g_cvarMinHoursUptimeForForcedRestart.FloatValue * 60.0 * 60.0;
|
||||||
return Plugin_Continue;
|
|
||||||
|
|
||||||
int iPlayers = GetClientCount(false);
|
int iPlayers = GetClientCount(false);
|
||||||
for(int i = 1; i <= MaxClients; i++)
|
for(int i = 1; i <= MaxClients; i++)
|
||||||
@ -99,7 +150,17 @@ public Action CheckRestart(Handle timer)
|
|||||||
if(IsClientConnected(i) && IsFakeClient(i))
|
if(IsClientConnected(i) && IsFakeClient(i))
|
||||||
iPlayers--;
|
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;
|
return Plugin_Continue;
|
||||||
|
|
||||||
float fUptime = GetEngineTime();
|
float fUptime = GetEngineTime();
|
||||||
@ -135,7 +196,7 @@ stock bool IsItRestartTime()
|
|||||||
public Action RestartCountdown(Handle timer)
|
public Action RestartCountdown(Handle timer)
|
||||||
{
|
{
|
||||||
PrintCenterTextAll("WARNING: Restarting Server in %d.", g_iRestartCountdown);
|
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--;
|
g_iRestartCountdown--;
|
||||||
|
|
||||||
if(g_iRestartCountdown < 0)
|
if(g_iRestartCountdown < 0)
|
||||||
@ -147,3 +208,20 @@ public Action RestartCountdown(Handle timer)
|
|||||||
|
|
||||||
return Plugin_Handled; //Server is dead by here anyway xD
|
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