diff --git a/LANCommander/Pages/Servers/Components/Console.razor b/LANCommander/Pages/Servers/Components/Console.razor index 989df76..fff4bfa 100644 --- a/LANCommander/Pages/Servers/Components/Console.razor +++ b/LANCommander/Pages/Servers/Components/Console.razor @@ -11,7 +11,7 @@ -@if (ServerConsole.Type == ServerConsoleType.RCON) +@if (ServerConsole != null && ServerConsole.Type == ServerConsoleType.RCON) { } @@ -42,8 +42,56 @@ protected override async Task OnInitializedAsync() { - ServerConsole = await ServerConsoleService.Get(ServerConsoleId); + if (ServerConsoleId != Guid.Empty) + { + ServerConsole = await ServerConsoleService.Get(ServerConsoleId); + await Connect(ServerConsole); + } + else + { + await Connect(); + } + } + + protected override async Task OnAfterRenderAsync(bool firstRender) + { + if (firstRender) + { + await Task.Delay(100); + + if (Terminal != null) + await Terminal.InvokeAddonFunctionVoidAsync("xterm-addon-fit", "fit"); + + if (ServerConsoleId != Guid.Empty) + { + var log = await ServerConsoleService.ReadLog(ServerConsoleId); + + foreach (var line in log) + { + await Terminal.WriteLine(line); + } + } + } + } + + async Task Connect() + { + HubConnection = new HubConnectionBuilder() + .WithUrl(NavigationManager.ToAbsoluteUri("/hubs/gameserver")) + .Build(); + + HubConnection.On("Log", (serverId, message) => + { + if (serverId == ServerId) + Terminal.WriteLine(message); + }); + + await HubConnection.StartAsync(); + } + + async Task Connect(ServerConsole serverConsole) + { History = new string[50]; HistoryPosition = 0; @@ -63,7 +111,8 @@ } else if (ServerConsole.Type == ServerConsoleType.RCON) { - try { + try + { ServerProcessService.RconConnect(ServerConsole); } catch (Exception ex) @@ -73,24 +122,6 @@ } } - protected override async Task OnAfterRenderAsync(bool firstRender) - { - if (firstRender) - { - await Task.Delay(100); - - if (Terminal != null) - await Terminal.InvokeAddonFunctionVoidAsync("xterm-addon-fit", "fit"); - - var log = await ServerConsoleService.ReadLog(ServerConsoleId); - - foreach (var line in log) - { - await Terminal.WriteLine(line); - } - } - } - public async Task OnPressEnter() { await ServerProcessService.RconSendCommandAsync(Command, ServerConsole); diff --git a/LANCommander/Pages/Servers/Edit.razor b/LANCommander/Pages/Servers/Edit.razor index 21fe2af..18d919f 100644 --- a/LANCommander/Pages/Servers/Edit.razor +++ b/LANCommander/Pages/Servers/Edit.razor @@ -1,6 +1,6 @@ @page "/Servers/{id:guid}" @page "/Servers/{id:guid}/{panel}" -@page "/Servers/{id:guid}/{panel}/{logId:guid}" +@page "/Servers/{id:guid}/{panel}/{logId}" @page "/Servers/Add" @using LANCommander.Pages.Servers.Components @inject GameService GameService @@ -18,9 +18,14 @@ { Consoles + @if (!Server.UseShellExecute) + { + Console + } + @foreach (var log in Server.ServerConsoles) { - @log.Name + @log.Name } Files @@ -107,11 +112,14 @@ } - @if (Panel == "Consoles") + @if (Panel == "Monitor") { - @if (LogId != null && LogId != Guid.Empty) + @if (LogId == "Console") { + + } + else if (LogId != null && LogId != Guid.Empty.ToString()) { - + } else { @@ -146,7 +154,7 @@ @code { [Parameter] public Guid Id { get; set; } [Parameter] public string Panel { get; set; } - [Parameter] public Guid LogId { get; set; } + [Parameter] public string LogId { get; set; } IEnumerable Games = new List(); diff --git a/LANCommander/Services/ServerProcessService.cs b/LANCommander/Services/ServerProcessService.cs index c124392..b35fcc9 100644 --- a/LANCommander/Services/ServerProcessService.cs +++ b/LANCommander/Services/ServerProcessService.cs @@ -146,11 +146,13 @@ namespace LANCommander.Services process.OutputDataReceived += new DataReceivedEventHandler((sender, e) => { + HubContext.Clients.All.SendAsync("Log", e.Data); Logger.Info("Game Server {ServerName} ({ServerId}) Info: {Message}", server.Name, server.Id, e.Data); }); process.ErrorDataReceived += new DataReceivedEventHandler((sender, e) => { + HubContext.Clients.All.SendAsync("Log", e.Data); Logger.Error("Game Server {ServerName} ({ServerId}) Error: {Message}", server.Name, server.Id, e.Data); }); }