RestartManager: re-add restart during night if empty

This commit is contained in:
hubdom 2020-07-09 23:44:52 +02:00
parent 26a23ae643
commit 1a2374cb20

View File

@ -43,7 +43,6 @@ public void OnPluginStart()
RegServerCmd("changelevel", BlockMapSwitch);
IsItTimeToRestart();
CreateTimer(60.0, CheckForRestart, _, TIMER_REPEAT);
}
@ -91,7 +90,7 @@ public Action Command_Uptime(int client, int args)
ReplyToCommand(client, "[SM] Cumulative Server Uptime: %s", sUptime);
IsItTimeToRestart();
IsItTimeToRestartForced();
if (g_bRestart)
ReplyToCommand(client, "[SM] Server is going to restart on next mapswitch");
else
@ -105,16 +104,51 @@ public Action Command_Uptime(int client, int args)
//----------------------------------------------------------------------------------------------------
public Action CheckForRestart(Handle timer)
{
if(!IsItTimeToRestart())
return Plugin_Continue;
int iPlayers = GetClientCount(false);
for(int i = 1; i <= MaxClients; i++)
{
if(IsClientConnected(i) && IsFakeClient(i))
iPlayers--;
}
return Plugin_Stop;
if((iPlayers <= 1) && IsItTimeToRestartNight())
{
PrepareRestartNight();
return Plugin_Stop;
}
if(IsItTimeToRestartForced())
return Plugin_Stop;
return Plugin_Continue;
}
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
public bool IsItTimeToRestart()
stock bool IsItTimeToRestartNight()
{
if (GetEngineTime() < (3600 * 12))
return false;
int iTime = GetTime();
int iHour;
char sTime[32];
FormatTime(sTime, sizeof(sTime), "%H", iTime);
iHour = StringToInt(sTime[0]);
if (iHour >= 3 && iHour < 8)
return true;
return false;
}
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
public bool IsItTimeToRestartForced()
{
if(g_bRestart)
return true;
@ -127,20 +161,6 @@ public bool IsItTimeToRestart()
return true;
}
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
public Action BlockMapSwitch(int args)
{
if (!g_bRestart)
return Plugin_Continue;
char sMap[64];
GetCmdArg(1, sMap, sizeof(sMap));
PrepareRestart(sMap);
return Plugin_Handled;
}
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
@ -176,6 +196,40 @@ public void PrepareRestart(char[] sMap)
RequestFrame(Restart);
}
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
public void PrepareRestartNight()
{
NotifyAdmins();
g_fCumulativeUptime += GetEngineTime();
char sUptime[64];
FloatToString(g_fCumulativeUptime, sUptime, sizeof(sUptime));
File UptimeFile = OpenFile("uptime.txt", "w");
UptimeFile.WriteLine(sUptime);
delete UptimeFile;
char sMap[64];
GetCurrentMap(sMap, sizeof(sMap));
char sMapFile[68];
Format(sMapFile, sizeof(sMapFile), "map %s", sMap);
DeleteFile("cfg/defaultmap.cfg");
File NextmapFile = OpenFile("cfg/defaultmap.cfg", "w");
NextmapFile.WriteLine(sMapFile);
delete NextmapFile;
SimulateMapEnd();
for(int i = 1; i <= MaxClients; i++)
{
if(IsClientConnected(i) && !IsFakeClient(i))
ClientCommand(i, "retry");
}
LogToFile("addons/sourcemod/logs/restarts.log", "Successfully night-restarted the Server.");
RequestFrame(Restart);
}
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
@ -184,6 +238,20 @@ public void Restart()
ServerCommand("_restart");
}
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
public Action BlockMapSwitch(int args)
{
if (!g_bRestart)
return Plugin_Continue;
char sMap[64];
GetCmdArg(1, sMap, sizeof(sMap));
PrepareRestart(sMap);
return Plugin_Handled;
}
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------