servuo/Scripts/Misc/AutoRestart.cs
Dexter e5e21c514f Bug Fixes * REQUIRES CORE RECOMPILE *
- Allured/Command Undead creatures will no longer produce any loot. A convenience extention was added to Utility.cs and will require a core recompile.
- Vice Vs Virtue notortiey/beneficial acts bug has been fixed and works as follows; Any non-VVV player performing a beneficial act on a VVV player that is in active combat with another active VVV player will become orange to any other active VVV member not guilded/allied with the beneficial acts recipient.

Vice Vs Virtue Enhanced Rules, disabled by default (since its a custom addition)
- Vice Vs Virtue combat will be active in ALL facets, not just Felucca
- Entering the region of an active VvV battle will flag any VvV player as combat restricted, ie will not be able to recall/gate
- Silver gained during a VvV battle during an uncontested period (ie, no opposing VvV players in the region) will reduce silver by 50%
2018-11-10 21:34:54 -07:00

145 lines
4.5 KiB
C#

using System;
using Server.Commands;
namespace Server.Misc
{
public class AutoRestart : Timer
{
private static readonly TimeSpan RestartDelay = TimeSpan.FromSeconds(10); // how long the server should remain active before restart (period of 'server wars')
private static readonly TimeSpan WarningDelay = TimeSpan.FromMinutes(1.0); // at what interval should the shutdown message be displayed?
public static DateTime RestartTime { get; private set; }
public static bool Restarting { get; private set; }
public static Timer Timer { get; private set; }
public static bool DoneWarning { get; private set; }
public static bool Enabled = Config.Get("AutoRestart.Enabled", false);
public static int Hour = Config.Get("AutoRestart.Hour", 12);
public static int Minutes = Config.Get("AutoRestart.Minute", 0);
public static int Frequency = Config.Get("AutoRestart.Frequency", 24);
public AutoRestart()
: base(TimeSpan.FromSeconds(1.0), TimeSpan.FromSeconds(1.0))
{
}
public static void Initialize()
{
CommandSystem.Register("Restart", AccessLevel.Administrator, new CommandEventHandler(Restart_OnCommand));
CommandSystem.Register("Shutdown", AccessLevel.Administrator, new CommandEventHandler(Shutdown_OnCommand));
if (Enabled)
{
var now = DateTime.Now;
var force = new DateTime(now.Year, now.Month, now.Day, Hour, Minutes, 0);
if (now > force)
{
force += TimeSpan.FromHours(Frequency);
}
RestartTime = force;
BeginTimer();
Utility.WriteConsoleColor(ConsoleColor.Magenta, "[Auto Restart] Configured for {0}:{1}:00, every {2} hours!", RestartTime.Hour, RestartTime.Minute, Frequency);
Utility.WriteConsoleColor(ConsoleColor.Magenta, "[Auto Restart] Next Shard Restart: {0}", RestartTime.ToString());
}
}
public static void Restart_OnCommand(CommandEventArgs e)
{
if (Restarting)
{
e.Mobile.SendMessage("The server is already restarting.");
}
else
{
e.Mobile.SendMessage("You have initiated server restart.");
StopTimer();
Timer.DelayCall(TimeSpan.FromSeconds(1), () =>
{
AutoSave.Save();
Restarting = true;
TimedShutdown(true);
});
}
}
public static void Shutdown_OnCommand(CommandEventArgs e)
{
if (Restarting)
{
e.Mobile.SendMessage("The server is already shutting down.");
}
else
{
e.Mobile.SendMessage("You have initiated server shutdown.");
StopTimer();
Timer.DelayCall(TimeSpan.FromSeconds(1), () =>
{
AutoSave.Save();
Restarting = true;
TimedShutdown(false);
});
}
}
private static void BeginTimer()
{
StopTimer();
Timer = new AutoRestart();
Timer.Start();
}
private static void StopTimer()
{
if (Timer != null)
{
Timer.Stop();
Timer = null;
}
}
protected override void OnTick()
{
if (Restarting || !Enabled)
return;
if (WarningDelay > TimeSpan.Zero && !DoneWarning && RestartTime - WarningDelay < DateTime.Now)
{
World.Broadcast(0x22, true, "The server will be going down in about {0} minute{1}.", WarningDelay.TotalMinutes.ToString(), WarningDelay.TotalMinutes == 1 ? "" : "s");
DoneWarning = true;
return;
}
if (DateTime.Now < RestartTime)
{
return;
}
AutoSave.Save();
Restarting = true;
TimedShutdown(true);
}
private static void TimedShutdown(bool restart)
{
World.Broadcast(0x22, true, String.Format("The server will be going down in about {0} seconds!", RestartDelay.TotalSeconds.ToString()));
Timer.DelayCall(RestartDelay, rest =>
{
Core.Kill(rest);
},
restart);
}
}
}