#pragma semicolon 1
#pragma newdecls required
Handle hTimer;
bool bEnabled;
int iTime;
public Plugin myinfo =
{
name = "[CSGO] Server Restarter",
author = "Grey83",
description = "Restarts a server at a specified time",
version = "1.0.0",
url = "http://steamcommunity.com/groups/grey83ds"
}
public void OnPluginStart()
{
if(GetEngineVersion() != Engine_CSGO) SetFailState("Plugin only for CS:GO!");
ConVar CVar;
(CVar = CreateConVar("sm_restart_time", "500", "Time when server will restarted (-1 - disable)", FCVAR_NOTIFY, true, -1.0, true, 2359.0)).AddChangeHook(CVarChanged_Time);
iTime = CVar.IntValue;
if((bEnabled = iTime > -1)) hTimer = CreateTimer(60.0, CheckTime, _, TIMER_REPEAT);
AutoExecConfig(true, "csgo_restart");
}
public void CVarChanged_Time(ConVar CVar, const char[] oldValue, const char[] newValue)
{
if(StrEqual(oldValue, newValue)) return;
iTime = CVar.IntValue;
static bool old_status;
if(old_status == (bEnabled = iTime > -1)) return;
old_status = bEnabled;
ToggleTimer(bEnabled);
}
stock void ToggleTimer(const bool enable)
{
if(enable) hTimer = CreateTimer(60.0, CheckTime, _, TIMER_REPEAT);
else if(hTimer != null)
{
KillTimer(hTimer);
hTimer = null;
}
}
public Action CheckTime(Handle timer)
{
static char buffer[8];
FormatTime(buffer, 8, "%H%M", GetTime());
static int current_time;
current_time = StringToInt(buffer);
if(current_time == iTime) ForceRestartCount();
}
stock void ForceRestartCount()
{
PrintHintTextToAll("Сервер будет перезагружен<br/>через <b>15</b> сек.");
CreateTimer(1.0, Countdown, _, TIMER_REPEAT);
}
public Action Countdown(Handle timer)
{
static int time = 15;
if(--time < 1)
{
PrintHintTextToAll("Сервер перезагружается!");
LogMessage("Server restart using [CSGO] Server Restarter...");
if(time == -1) ServerCommand("_restart");
}
else PrintHintTextToAll("Сервер будет перезагружен<br/>через <b>%d</b> сек.", time);
return Plugin_Continue;
}