Added new console streaming

This commit is contained in:
Marcel Baumgartner
2023-05-28 04:27:00 +02:00
parent a180cfa31d
commit feec9426b9
21 changed files with 540 additions and 65 deletions

View File

@@ -1,6 +1,4 @@
@using PteroConsole.NET
@using Moonlight.App.Services
@using Task = System.Threading.Tasks.Task
@using Moonlight.App.Services
@using Moonlight.App.Helpers
@using Logging.Net
@using BlazorContextMenu
@@ -101,9 +99,6 @@
@code
{
[CascadingParameter]
public PteroConsole Console { get; set; }
[CascadingParameter]
public Server CurrentServer { get; set; }

View File

@@ -1,11 +1,9 @@
@using PteroConsole.NET
@using PteroConsole.NET.Enums
@using Task = System.Threading.Tasks.Task
@using Moonlight.App.Helpers
@using Moonlight.App.Helpers
@using Moonlight.App.Repositories
@using Moonlight.App.Services
@using Logging.Net
@using Moonlight.App.Database.Entities
@using Moonlight.App.Helpers.Wings
@using Moonlight.App.Helpers.Wings.Data
@using Moonlight.App.Services.Interop
@using Moonlight.Shared.Components.Xterm
@@ -37,7 +35,7 @@
@code
{
[CascadingParameter]
public PteroConsole Console { get; set; }
public WingsConsole Console { get; set; }
[CascadingParameter]
public Server CurrentServer { get; set; }
@@ -51,21 +49,35 @@
Console.OnMessage += OnMessage;
}
private async void OnMessage(object? sender, string e)
private async void OnMessage(object? sender, ConsoleMessage message)
{
if (Terminal != null)
{
var s = e;
if (message.IsInternal)
{
await Terminal.WriteLine("\x1b[38;5;16;48;5;135m\x1b[39m\x1b[1m Moonlight \x1b[0m " + message.Content + "\x1b[0m");
}
else
{
var s = message.Content;
s = s.Replace("Pterodactyl Daemon", "Moonlight Daemon");
s = s.Replace("Checking server disk space usage, this could take a few seconds...", TranslationService.Translate("Checking disk space"));
s = s.Replace("Updating process configuration files...", TranslationService.Translate("Updating config files"));
s = s.Replace("Ensuring file permissions are set correctly, this could take a few seconds...", TranslationService.Translate("Checking file permissions"));
s = s.Replace("Pulling Docker container image, this could take a few minutes to complete...", TranslationService.Translate("Downloading server image"));
s = s.Replace("Finished pulling Docker container image", TranslationService.Translate("Downloaded server image"));
s = s.Replace("container@pterodactyl~", "server@moonlight >");
if (s.Contains("Moonlight Daemon") || s.Contains("Pterodactyl Daemon"))
{
s = s.Replace("[39m", "\x1b[0m");
s = s.Replace("[33m", "[38;5;16;48;5;135m\x1b[39m");
}
await Terminal.WriteLine(s);
s = s.Replace("[Pterodactyl Daemon]:", " Moonlight ");
s = s.Replace("[Moonlight Daemon]:", " Moonlight ");
s = s.Replace("Checking server disk space usage, this could take a few seconds...", TranslationService.Translate("Checking disk space"));
s = s.Replace("Updating process configuration files...", TranslationService.Translate("Updating config files"));
s = s.Replace("Ensuring file permissions are set correctly, this could take a few seconds...", TranslationService.Translate("Checking file permissions"));
s = s.Replace("Pulling Docker container image, this could take a few minutes to complete...", TranslationService.Translate("Downloading server image"));
s = s.Replace("Finished pulling Docker container image", TranslationService.Translate("Downloaded server image"));
s = s.Replace("container@pterodactyl~", "server@moonlight >");
await Terminal.WriteLine(s);
}
}
}
@@ -85,9 +97,9 @@
private void RunOnFirstRender()
{
lock (Console.MessageCache)
lock (Console.Messages)
{
foreach (var message in Console.MessageCache.TakeLast(30))
foreach (var message in Console.Messages)
{
OnMessage(null, message);
}

View File

@@ -4,6 +4,7 @@
@using Moonlight.App.Helpers.Files
@using Moonlight.App.Services
@using Moonlight.App.ApiClients.Wings
@using Moonlight.App.Helpers.Wings
@inject WingsApiHelper WingsApiHelper
@inject WingsJwtHelper WingsJwtHelper

View File

@@ -1,9 +1,8 @@
@using PteroConsole.NET
@using PteroConsole.NET.Enums
@using Task = System.Threading.Tasks.Task
@using Moonlight.App.Services
@using Moonlight.App.Services
@using Moonlight.App.Database.Entities
@using Moonlight.App.Helpers
@using Moonlight.App.Helpers.Wings
@using Moonlight.App.Helpers.Wings.Enums
@inject SmartTranslateService TranslationService
@@ -77,32 +76,32 @@
case ServerState.Starting:
<span class="text-warning"><TL>Starting</TL></span>
<span class="text-gray-700 pt-1 fw-semibold">(@(Formatter.FormatUptime(Console.ServerResource.Uptime)))</span>
<span class="text-gray-700 pt-1 fw-semibold">(@(Formatter.FormatUptime(Console.Resource.Uptime)))</span>
break;
case ServerState.Stopping:
<span class="text-warning"><TL>Stopping</TL></span>
<span class="text-gray-700 pt-1 fw-semibold">(@(Formatter.FormatUptime(Console.ServerResource.Uptime)))</span>
<span class="text-gray-700 pt-1 fw-semibold">(@(Formatter.FormatUptime(Console.Resource.Uptime)))</span>
break;
case ServerState.Running:
<span class="text-success"><TL>Online</TL></span>
<span class="text-gray-700 pt-1 fw-semibold">(@(Formatter.FormatUptime(Console.ServerResource.Uptime)))</span>
<span class="text-gray-700 pt-1 fw-semibold">(@(Formatter.FormatUptime(Console.Resource.Uptime)))</span>
break;
}
</span>
</div>
<div class="col fs-5">
<span class="fw-bold"><TL>Cpu</TL>:</span>
<span class="ms-1 text-muted">@(Math.Round(Console.ServerResource.CpuAbsolute, 2))%</span>
<span class="ms-1 text-muted">@(Math.Round(Console.Resource.CpuAbsolute, 2))%</span>
</div>
<div class="col fs-5">
<span class="fw-bold"><TL>Memory</TL>:</span>
<span class="ms-1 text-muted">@(Formatter.FormatSize(Console.ServerResource.MemoryBytes)) / @(Formatter.FormatSize(Console.ServerResource.MemoryLimitBytes))</span>
<span class="ms-1 text-muted">@(Formatter.FormatSize(Console.Resource.MemoryBytes)) / @(Formatter.FormatSize(Console.Resource.MemoryLimitBytes))</span>
</div>
<div class="col fs-5">
<span class="fw-bold"><TL>Disk</TL>:</span>
<span class="ms-1 text-muted">@(Formatter.FormatSize(Console.ServerResource.DiskBytes)) / @(Math.Round(CurrentServer.Disk / 1024f, 2)) GB</span>
<span class="ms-1 text-muted">@(Formatter.FormatSize(Console.Resource.DiskBytes)) / @(Math.Round(CurrentServer.Disk / 1024f, 2)) GB</span>
</div>
</div>
</div>
@@ -178,7 +177,7 @@
public User User { get; set; }
[CascadingParameter]
public PteroConsole Console { get; set; }
public WingsConsole Console { get; set; }
[Parameter]
public RenderFragment ChildContent { get; set; }
@@ -190,8 +189,8 @@
protected override void OnInitialized()
{
Console.OnServerStateUpdated += async (sender, state) => { await InvokeAsync(StateHasChanged); };
Console.OnServerResourceUpdated += async (sender, x) => { await InvokeAsync(StateHasChanged); };
Console.OnServerStateUpdated += async (_, _) => { await InvokeAsync(StateHasChanged); };
Console.OnResourceUpdated += async (_, _) => { await InvokeAsync(StateHasChanged); };
}
#region Power Actions