UptimeRestart: fix map switch
+ atttempt force retry (doesnt work yet)
This commit is contained in:
		
							parent
							
								
									035b678e7f
								
							
						
					
					
						commit
						8c1117039b
					
				@ -11,13 +11,14 @@ bool g_bForcedRestart;
 | 
			
		||||
ConVar g_cvarMaxPlayersForControlledRestart;
 | 
			
		||||
ConVar g_cvarMinPlayersForForcedRestart;
 | 
			
		||||
ConVar g_cvarMinHoursUptimeForForcedRestart;
 | 
			
		||||
ConVar g_cvarDefaultMap;
 | 
			
		||||
 | 
			
		||||
public Plugin myinfo =
 | 
			
		||||
{
 | 
			
		||||
	name        = "UptimeRestart",
 | 
			
		||||
	author      = "Dogan",
 | 
			
		||||
	description = "Display Server Uptime and do controlled Restarts",
 | 
			
		||||
	version     = "2.0.0",
 | 
			
		||||
	version     = "3.0.0",
 | 
			
		||||
	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_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_cvarDefaultMap = CreateConVar("sm_defaultmap", "ze_atix_panic_b3t", "default map of the server");
 | 
			
		||||
 | 
			
		||||
	g_iRestartCountdown = 5;
 | 
			
		||||
	g_bForcedRestart = false;
 | 
			
		||||
	GetUptimeIfControlledRestart();
 | 
			
		||||
	GetNextmapIfForcedRestart();
 | 
			
		||||
	SetCorrectDefaultMapAgain();
 | 
			
		||||
 | 
			
		||||
	AutoExecConfig(true, "plugin.UptimeRestarts");
 | 
			
		||||
 | 
			
		||||
@ -51,31 +53,54 @@ public void OnMapEnd()
 | 
			
		||||
	CPrintToChatAll("{red}WARNING:{white} Restarting Server now!");
 | 
			
		||||
	PrintCenterTextAll("WARNING: Restarting Server now!");
 | 
			
		||||
 | 
			
		||||
	char sNextmap[64];
 | 
			
		||||
	GetNextMap(sNextmap, sizeof(sNextmap));
 | 
			
		||||
	float fUptime = GetEngineTime();
 | 
			
		||||
	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");
 | 
			
		||||
		NextmapFile.WriteLine(sNextmap);
 | 
			
		||||
		DeleteFile("cfg/defaultmap.cfg");
 | 
			
		||||
		File NextmapFile = OpenFile("cfg/defaultmap.cfg", "w");
 | 
			
		||||
		NextmapFile.WriteLine(sMapFile);
 | 
			
		||||
		delete NextmapFile;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	RequestFrame(ForceRestart);
 | 
			
		||||
	for(int i = 1; i <= MaxClients; i++)
 | 
			
		||||
	{
 | 
			
		||||
		if(IsClientConnected(i))
 | 
			
		||||
			ClientCommand(i, "retry");
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	LogToFile("addons/sourcemod/logs/restarts.txt", "Successfully force-restarted the Server.");
 | 
			
		||||
	CreateTimer(0.01, ForceRestart);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
public void GetNextmapIfForcedRestart()
 | 
			
		||||
public Action ForceRestart(Handle timer)
 | 
			
		||||
{
 | 
			
		||||
	File NextmapFile = OpenFile("nextmap.txt", "r");
 | 
			
		||||
	ServerCommand("_restart");
 | 
			
		||||
	return Plugin_Handled;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
	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 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;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
public void GetUptimeIfControlledRestart()
 | 
			
		||||
@ -209,28 +234,14 @@ public Action RestartCountdown(Handle timer)
 | 
			
		||||
	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)
 | 
			
		||||
{
 | 
			
		||||
	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!");
 | 
			
		||||
	CPrintToChatAll("{red}WARNING:{white} Restarting Server when this Map ends!");
 | 
			
		||||
	CPrintToChatAll("{red}WARNING:{white} Remember to rejoin after couple seconds!");
 | 
			
		||||
 | 
			
		||||
	return Plugin_Continue;
 | 
			
		||||
}
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user