Truncate log in UI, add ability to cancel restart
This commit is contained in:
@@ -18,6 +18,7 @@ namespace Torch.Server
|
||||
{
|
||||
private FlowDocument _document = new FlowDocument { Background = new SolidColorBrush(Colors.Black) };
|
||||
private readonly Paragraph _paragraph = new Paragraph();
|
||||
private readonly int _maxLines = 500;
|
||||
|
||||
public FlowDocument Document => _document;
|
||||
|
||||
@@ -33,6 +34,10 @@ namespace Torch.Server
|
||||
{
|
||||
var message = $"{Layout.Render(logEvent)}\n";
|
||||
_paragraph.Inlines.Add(new Run(message) {Foreground = LogLevelColors[logEvent.Level]});
|
||||
|
||||
// A massive paragraph slows the UI down
|
||||
if (_paragraph.Inlines.Count > _maxLines)
|
||||
_paragraph.Inlines.Remove(_paragraph.Inlines.FirstInline);
|
||||
});
|
||||
}
|
||||
|
||||
|
@@ -133,10 +133,6 @@ namespace Torch.Server.Managers
|
||||
return;
|
||||
}
|
||||
|
||||
var sb = new StringBuilder();
|
||||
foreach (var mod in checkpoint.Mods)
|
||||
sb.AppendLine(mod.PublishedFileId.ToString());
|
||||
|
||||
DedicatedConfig.Mods = checkpoint.Mods.Select(x => x.PublishedFileId).ToList();
|
||||
|
||||
Log.Debug("Loaded mod list from world");
|
||||
|
@@ -8,6 +8,7 @@ using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Timers;
|
||||
using Sandbox.Game.Multiplayer;
|
||||
using Sandbox.ModAPI;
|
||||
using SteamSDK;
|
||||
using Torch;
|
||||
@@ -22,6 +23,9 @@ namespace Torch.Commands
|
||||
{
|
||||
public class TorchCommands : CommandModule
|
||||
{
|
||||
private static bool _restartPending = false;
|
||||
private static bool _cancelRestart = false;
|
||||
|
||||
[Command("whatsmyip")]
|
||||
[Permission(MyPromoteLevel.None)]
|
||||
public void GetIP(ulong steamId = 0)
|
||||
@@ -148,6 +152,7 @@ namespace Torch.Commands
|
||||
[Command("restart", "Restarts the server.")]
|
||||
public void Restart(int countdownSeconds = 10, bool save = true)
|
||||
{
|
||||
_restartPending = true;
|
||||
Task.Run(() =>
|
||||
{
|
||||
var countdown = RestartCountdown(countdownSeconds, save).GetEnumerator();
|
||||
@@ -158,10 +163,29 @@ namespace Torch.Commands
|
||||
});
|
||||
}
|
||||
|
||||
[Command("restart cancel", "Cancel a pending restart.")]
|
||||
public void CancelRestart()
|
||||
{
|
||||
if (_restartPending)
|
||||
_cancelRestart = true;
|
||||
else
|
||||
Context.Respond("A restart is not pending.");
|
||||
}
|
||||
|
||||
private IEnumerable RestartCountdown(int countdown, bool save)
|
||||
{
|
||||
for (var i = countdown; i >= 0; i--)
|
||||
{
|
||||
if (_cancelRestart)
|
||||
{
|
||||
Context.Torch.CurrentSession.Managers.GetManager<IChatManagerClient>()
|
||||
.SendMessageAsSelf($"Restart cancelled.");
|
||||
|
||||
_restartPending = false;
|
||||
_cancelRestart = false;
|
||||
yield break;
|
||||
}
|
||||
|
||||
if (i >= 60 && i % 60 == 0)
|
||||
{
|
||||
Context.Torch.CurrentSession.Managers.GetManager<IChatManagerClient>()
|
||||
|
Reference in New Issue
Block a user