UptimeRestart: fix map switch

+ atttempt force retry (doesnt work yet)
This commit is contained in:
dogan 2020-07-08 16:59:54 +02:00
parent 035b678e7f
commit 8c1117039b

View File

@ -11,13 +11,14 @@ bool g_bForcedRestart;
ConVar g_cvarMaxPlayersForControlledRestart; ConVar g_cvarMaxPlayersForControlledRestart;
ConVar g_cvarMinPlayersForForcedRestart; ConVar g_cvarMinPlayersForForcedRestart;
ConVar g_cvarMinHoursUptimeForForcedRestart; ConVar g_cvarMinHoursUptimeForForcedRestart;
ConVar g_cvarDefaultMap;
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 = "2.0.0", version = "3.0.0",
url = "" url = ""
}; };
@ -29,11 +30,12 @@ public void OnPluginStart()
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_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_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_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_cvarDefaultMap = CreateConVar("sm_defaultmap", "ze_atix_panic_b3t", "default map of the server");
g_iRestartCountdown = 5; g_iRestartCountdown = 5;
g_bForcedRestart = false; g_bForcedRestart = false;
GetUptimeIfControlledRestart(); GetUptimeIfControlledRestart();
GetNextmapIfForcedRestart(); SetCorrectDefaultMapAgain();
AutoExecConfig(true, "plugin.UptimeRestarts"); AutoExecConfig(true, "plugin.UptimeRestarts");
@ -51,31 +53,54 @@ public void OnMapEnd()
CPrintToChatAll("{red}WARNING:{white} Restarting Server now!"); CPrintToChatAll("{red}WARNING:{white} Restarting Server now!");
PrintCenterTextAll("WARNING: Restarting Server now!"); PrintCenterTextAll("WARNING: Restarting Server now!");
char sNextmap[64]; float fUptime = GetEngineTime();
GetNextMap(sNextmap, sizeof(sNextmap)); g_fUptime = g_fUptime + fUptime;
if(!StrEqual(sNextmap, "")) char sUptime[64];
FloatToString(g_fUptime, sUptime, sizeof(sUptime));
File UptimeFile = OpenFile("uptime.txt", "w");
UptimeFile.WriteLine(sUptime);
delete UptimeFile;
char sNextmap[64];
GetCurrentMap(sNextmap, sizeof(sNextmap));
char sMapFile[64];
Format(sMapFile, sizeof(sMapFile), "map %s", sNextmap);
if(!StrEqual(sMapFile, ""))
{ {
File NextmapFile = OpenFile("nextmap.txt", "w"); DeleteFile("cfg/defaultmap.cfg");
NextmapFile.WriteLine(sNextmap); File NextmapFile = OpenFile("cfg/defaultmap.cfg", "w");
NextmapFile.WriteLine(sMapFile);
delete NextmapFile; delete NextmapFile;
} }
RequestFrame(ForceRestart); for(int i = 1; i <= MaxClients; i++)
{
if(IsClientConnected(i))
ClientCommand(i, "retry");
} }
public void GetNextmapIfForcedRestart() LogToFile("addons/sourcemod/logs/restarts.txt", "Successfully force-restarted the Server.");
{ CreateTimer(0.01, ForceRestart);
File NextmapFile = OpenFile("nextmap.txt", "r"); }
if(NextmapFile != null)//There was a nextmap set public Action ForceRestart(Handle timer)
{ {
char sNextmap[64]; ServerCommand("_restart");
NextmapFile.ReadLine(sNextmap, sizeof(sNextmap)); return Plugin_Handled;
}
public void SetCorrectDefaultMapAgain()
{
DeleteFile("cfg/defaultmap.cfg");
char sDefaultMap[64];
GetConVarString(g_cvarDefaultMap, sDefaultMap, sizeof(sDefaultMap));
char sMapFile[64];
Format(sMapFile, sizeof(sMapFile), "map %s", sDefaultMap);
File NextmapFile = OpenFile("cfg/defaultmap.cfg", "w");
NextmapFile.WriteLine(sMapFile);
delete NextmapFile; delete NextmapFile;
DeleteFile("nextmap.txt");
ForceChangeLevel(sNextmap, "Set to Map that was next before Force Restart happened");
}
} }
public void GetUptimeIfControlledRestart() public void GetUptimeIfControlledRestart()
@ -209,28 +234,14 @@ 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()
{
float fUptime = GetEngineTime();
g_fUptime = g_fUptime + fUptime;
char sUptime[64];
FloatToString(g_fUptime, sUptime, sizeof(sUptime));
File UptimeFile = OpenFile("uptime.txt", "w");
UptimeFile.WriteLine(sUptime);
delete UptimeFile;
LogToFile("addons/sourcemod/logs/restarts.txt", "Successfully force-restarted the Server.");
ServerCommand("_restart");
}
public Action ForceRestartMessage(Handle timer) public Action ForceRestartMessage(Handle timer)
{ {
if(!g_bForcedRestart) if(!g_bForcedRestart)
return Plugin_Continue; return Plugin_Continue;
CPrintToChatAll("{red}WARNING:{white} Restarting Server when this Map ends!"); CPrintToChatAll("{red}WARNING:{white} Restarting Server when this Map ends!");
CPrintToChatAll("{red}WARNING:{white} Remember to join after couple seconds!"); CPrintToChatAll("{red}WARNING:{white} Restarting Server when this Map ends!");
CPrintToChatAll("{red}WARNING:{white} Remember to rejoin after couple seconds!");
return Plugin_Continue; return Plugin_Continue;
} }