feat: Adds AdminGump Shutdown with 15m Delay & Save (#2058)

This commit is contained in:
Bohica 2025-01-10 18:28:17 -08:00 committed by GitHub
parent 1da5a49baf
commit 5c1573193b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -12,6 +12,7 @@ using Server.Misc;
using Server.Multis; using Server.Multis;
using Server.Network; using Server.Network;
using Server.Prompts; using Server.Prompts;
using Server.Saves;
using Server.Text; using Server.Text;
namespace Server.Gumps namespace Server.Gumps
@ -295,6 +296,9 @@ namespace Server.Gumps
AddButtonLabeled(20, 230, GetButtonID(3, 203), "Shutdown & Restart (With Save)"); AddButtonLabeled(20, 230, GetButtonID(3, 203), "Shutdown & Restart (With Save)");
AddButtonLabeled(20, 250, GetButtonID(3, 204), "Shutdown & Restart (Without Save)"); AddButtonLabeled(20, 250, GetButtonID(3, 204), "Shutdown & Restart (Without Save)");
AddButtonLabeled(20, 270, GetButtonID(3, 205), "Shutdown (With 15m Delay & Save)");
/*} /*}
else else
{ {
@ -2147,6 +2151,12 @@ namespace Server.Gumps
Shutdown(true, false); Shutdown(true, false);
break; break;
} }
case 205: // shutdown with delay and save
{
var t = new ShutdownTimer(this);
t.Start();
break;
}
case 210: case 210:
case 211: case 211:
{ {
@ -4251,5 +4261,30 @@ namespace Server.Gumps
public AdminNoticeGump(string content, Action callback) : base(callback) => Content = content; public AdminNoticeGump(string content, Action callback) : base(callback) => Content = content;
} }
public class ShutdownTimer : Timer
{
private readonly AdminGump _adminGump;
public ShutdownTimer(AdminGump gump) : base(TimeSpan.Zero, TimeSpan.Zero, 8) =>
_adminGump = gump;
protected override void OnTick()
{
if (Index >= 7)
{
AutoSave.SavesEnabled = false;
_adminGump.Shutdown(false, true);
return;
}
ReadOnlySpan<int> times = [15, 10, 5, 4, 3, 2, 1, 0];
var time = times[Index];
_adminGump.m_From.SendMessage(
$"The shard will shutdown in {time} minute{(time == 1 ? "s" : "")} for maintenance."
);
Interval = TimeSpan.FromMinutes(time - times[Index + 1]);
}
}
} }
} }