forked from UNLOZE/sm-plugins
RestartManager: last polish + safe restart command
+ remove UptimeRestarts
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
#include <sourcemod>
|
||||
#include <files>
|
||||
#include <mapchooser_extended>
|
||||
#include <multicolors>
|
||||
|
||||
#pragma semicolon 1
|
||||
#pragma newdecls required
|
||||
@@ -20,10 +21,10 @@ public Plugin myinfo =
|
||||
name = "RestartManager",
|
||||
author = "Dogan + Neon",
|
||||
description = "Display Server Uptime and do controlled Restarts",
|
||||
version = "1.0.0",
|
||||
version = "2.0.0",
|
||||
url = ""
|
||||
};
|
||||
// TODO: SAFE command for admins to restart!!!
|
||||
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
@@ -31,6 +32,7 @@ public void OnPluginStart()
|
||||
{
|
||||
RegAdminCmd("uptime", Command_Uptime, ADMFLAG_GENERIC, "Displays server Uptime");
|
||||
RegAdminCmd("sm_uptime", Command_Uptime, ADMFLAG_GENERIC, "Displays server Uptime");
|
||||
RegAdminCmd("sm_forcerestart", Command_ForceRestart, ADMFLAG_RCON, "Force-restarts the server");
|
||||
|
||||
g_cvarDefaultMap = CreateConVar("sm_defaultmap", "ze_atix_panic_b3t", "default map of the server");
|
||||
g_cvarMaxUptime = CreateConVar("sm_maxuptime", "68", "Uptime in hours after which the server should be restarted", FCVAR_NONE);
|
||||
@@ -44,6 +46,18 @@ public void OnPluginStart()
|
||||
RegServerCmd("changelevel", BlockMapSwitch);
|
||||
|
||||
CreateTimer(60.0, CheckForRestart, _, TIMER_REPEAT);
|
||||
CreateTimer(20.0, ForceRestartMessage, _, TIMER_REPEAT);
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
public Action Command_ForceRestart(int client, int args)
|
||||
{
|
||||
ReplyToCommand(client, "[SM] Confirm the force-restart please!");
|
||||
OpenAdminPanel(client);
|
||||
|
||||
return Plugin_Handled;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
@@ -94,11 +108,56 @@ public Action Command_Uptime(int client, int args)
|
||||
if (g_bRestart)
|
||||
ReplyToCommand(client, "[SM] Server is going to restart on next mapswitch");
|
||||
else
|
||||
ReplyToCommand(client, "[SM] Time until next restart: %.2fh", ((g_cvarMaxUptime.FloatValue * 3600.0) - GetEngineTime()) / 3600.0);
|
||||
ReplyToCommand(client, "[SM] Time until next force-restart: %.2fh", ((g_cvarMaxUptime.FloatValue * 3600.0) - GetEngineTime()) / 3600.0);
|
||||
|
||||
return Plugin_Handled;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
public void OpenAdminPanel(int client)
|
||||
{
|
||||
Menu menu = new Menu(MenuHandler_MainMenu);
|
||||
|
||||
menu.SetTitle("Are you sure you want to force-restart the server?", client);
|
||||
|
||||
char sBuffer[32];
|
||||
|
||||
Format(sBuffer, sizeof(sBuffer), "Yes.");
|
||||
menu.AddItem("0", sBuffer);
|
||||
|
||||
Format(sBuffer, sizeof(sBuffer), "No.");
|
||||
menu.AddItem("1", sBuffer);
|
||||
|
||||
menu.Display(client, MENU_TIME_FOREVER);
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
public int MenuHandler_MainMenu(Menu menu, MenuAction action, int client, int selection)
|
||||
{
|
||||
char sMap[64];
|
||||
GetCurrentMap(sMap, sizeof(sMap));
|
||||
|
||||
switch(action)
|
||||
{
|
||||
case(MenuAction_Select):
|
||||
{
|
||||
switch(selection)
|
||||
{
|
||||
case(0): PrepareRestart(sMap, client, true);
|
||||
case(1): PrintToChat(client, "[SM] You declined the force-restart.");
|
||||
}
|
||||
}
|
||||
case(MenuAction_Cancel):
|
||||
{
|
||||
PrintToChat(client, "[SM] You declined the force-restart.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
@@ -157,17 +216,14 @@ public bool IsItTimeToRestartForced()
|
||||
return false;
|
||||
|
||||
g_bRestart = true;
|
||||
NotifyAdmins();
|
||||
return true;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
public void PrepareRestart(char[] sMap)
|
||||
public void PrepareRestart(char[] sMap, int client, bool bAdmin)
|
||||
{
|
||||
NotifyAdmins();
|
||||
|
||||
g_fCumulativeUptime += GetEngineTime();
|
||||
|
||||
char sUptime[64];
|
||||
@@ -186,14 +242,52 @@ public void PrepareRestart(char[] sMap)
|
||||
delete NextmapFile;
|
||||
}
|
||||
|
||||
SimulateMapEnd();
|
||||
for(int i = 1; i <= MaxClients; i++)
|
||||
if(bAdmin)
|
||||
{
|
||||
if(IsClientConnected(i) && !IsFakeClient(i))
|
||||
ClientCommand(i, "retry");
|
||||
LogToFile("addons/sourcemod/logs/restarts.log", "%N successfully force-restarted the Server.", client);
|
||||
PrintToChat(client, "[SM] You confirmed the force-restart.");
|
||||
|
||||
CPrintToChatAll("{red}WARNING:{white} Restarting Server in 8 Seconds!");
|
||||
CPrintToChatAll("{red}WARNING:{white} Restarting Server in 8 Seconds");
|
||||
CPrintToChatAll("{red}WARNING:{white} You may disconnect, reconnect if necessary!");
|
||||
PrintCenterTextAll("WARNING: Restarting Server in 8 Seconds.");
|
||||
|
||||
Panel hNotifyPanel = new Panel(GetMenuStyleHandle(MenuStyle_Radio));
|
||||
hNotifyPanel.DrawItem("WARNING: Restarting Server in 8 Seconds.", ITEMDRAW_RAWLINE);
|
||||
hNotifyPanel.DrawItem("", ITEMDRAW_SPACER);
|
||||
hNotifyPanel.DrawItem("IMPORTANT: You may disconnect, reconnect if necessary!", ITEMDRAW_RAWLINE);
|
||||
for(int i = 1; i <= MaxClients; i++)
|
||||
{
|
||||
hNotifyPanel.Send(client, MenuHandler_NotifyPanel, 8);
|
||||
}
|
||||
delete hNotifyPanel;
|
||||
|
||||
CreateTimer(8.0, AdminForceRestart);
|
||||
}
|
||||
else
|
||||
{
|
||||
SimulateMapEnd();
|
||||
for(int i = 1; i <= MaxClients; i++)
|
||||
{
|
||||
if(IsClientConnected(i) && !IsFakeClient(i))
|
||||
ClientCommand(i, "retry");
|
||||
}
|
||||
|
||||
LogToFile("addons/sourcemod/logs/restarts.log", "Successfully force-restarted the Server.");
|
||||
RequestFrame(Restart);
|
||||
}
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
int MenuHandler_NotifyPanel(Menu hMenu, MenuAction iAction, int iParam1, int iParam2)
|
||||
{
|
||||
switch (iAction)
|
||||
{
|
||||
case MenuAction_Select, MenuAction_Cancel:
|
||||
delete hMenu;
|
||||
}
|
||||
LogToFile("addons/sourcemod/logs/restarts.log", "Successfully force-restarted the Server.");
|
||||
RequestFrame(Restart);
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
@@ -201,8 +295,6 @@ public void PrepareRestart(char[] sMap)
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
public void PrepareRestartNight()
|
||||
{
|
||||
NotifyAdmins();
|
||||
|
||||
g_fCumulativeUptime += GetEngineTime();
|
||||
|
||||
char sUptime[64];
|
||||
@@ -248,7 +340,7 @@ public Action BlockMapSwitch(int args)
|
||||
|
||||
char sMap[64];
|
||||
GetCmdArg(1, sMap, sizeof(sMap));
|
||||
PrepareRestart(sMap);
|
||||
PrepareRestart(sMap, 0, false);
|
||||
return Plugin_Handled;
|
||||
}
|
||||
|
||||
@@ -287,16 +379,33 @@ public void SetStartMap(char[] sMap)
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
public void NotifyAdmins()
|
||||
public Action ForceRestartMessage(Handle timer)
|
||||
{
|
||||
if(!g_bRestart)
|
||||
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} You may disconnect, reconnect if necessary!");
|
||||
|
||||
return Plugin_Continue;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
public Action AdminForceRestart(Handle timer)
|
||||
{
|
||||
SimulateMapEnd();
|
||||
for(int i = 1; i <= MaxClients; i++)
|
||||
{
|
||||
if(IsValidClient(i) && CheckCommandAccess(i, "", ADMFLAG_KICK))
|
||||
{
|
||||
PrintToChat(i, "[SM] WARNING: Server will be restarted on mapswitch!");
|
||||
PrintToChat(i, "[SM] WARNING: Server will be restarted on mapswitch!");
|
||||
}
|
||||
if(IsClientConnected(i) && !IsFakeClient(i))
|
||||
ClientCommand(i, "retry");
|
||||
}
|
||||
|
||||
RequestFrame(Restart);
|
||||
|
||||
return Plugin_Handled;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
@@ -308,4 +417,4 @@ stock int IsValidClient(int client, bool nobots = true)
|
||||
return false;
|
||||
|
||||
return IsClientInGame(client);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user