Add RCON support to UI for adding consoles

This commit is contained in:
Pat Hartl 2023-08-18 00:50:12 -05:00
parent 1281ebff15
commit 463322b709
7 changed files with 1548 additions and 24 deletions

View file

@ -12,7 +12,7 @@ namespace LANCommander.Data.Models
public string Path { get; set; } = "";
public string Host { get; set; } = "";
public int Port { get; set; }
public int? Port { get; set; }
// Change to a secure string at some point
public string Password { get; set; } = "";

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,36 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace LANCommander.Migrations
{
/// <inheritdoc />
public partial class NullRconPort : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AlterColumn<int>(
name: "Port",
table: "ServerConsoles",
type: "INTEGER",
nullable: true,
oldClrType: typeof(int),
oldType: "INTEGER");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.AlterColumn<int>(
name: "Port",
table: "ServerConsoles",
type: "INTEGER",
nullable: false,
defaultValue: 0,
oldClrType: typeof(int),
oldType: "INTEGER",
oldNullable: true);
}
}
}

View file

@ -683,7 +683,7 @@ namespace LANCommander.Migrations
b.ToTable("Servers");
});
modelBuilder.Entity("LANCommander.Data.Models.ServerLog", b =>
modelBuilder.Entity("LANCommander.Data.Models.ServerConsole", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
@ -711,7 +711,7 @@ namespace LANCommander.Migrations
.IsRequired()
.HasColumnType("TEXT");
b.Property<int>("Port")
b.Property<int?>("Port")
.HasColumnType("INTEGER");
b.Property<Guid?>("ServerId")
@ -1296,7 +1296,7 @@ namespace LANCommander.Migrations
b.Navigation("UpdatedBy");
});
modelBuilder.Entity("LANCommander.Data.Models.ServerLog", b =>
modelBuilder.Entity("LANCommander.Data.Models.ServerConsole", b =>
{
b.HasOne("LANCommander.Data.Models.User", "CreatedBy")
.WithMany()
@ -1309,7 +1309,7 @@ namespace LANCommander.Migrations
.IsRequired();
b.HasOne("LANCommander.Data.Models.Server", null)
.WithMany("ServerLogs")
.WithMany("ServerConsoles")
.HasForeignKey("ServerId1");
b.HasOne("LANCommander.Data.Models.User", "UpdatedBy")
@ -1415,7 +1415,7 @@ namespace LANCommander.Migrations
modelBuilder.Entity("LANCommander.Data.Models.Server", b =>
{
b.Navigation("ServerLogs");
b.Navigation("ServerConsoles");
});
modelBuilder.Entity("LANCommander.Data.Models.User", b =>

View file

@ -3,23 +3,72 @@
@using LANCommander.Extensions;
<Space Direction="DirectionVHType.Vertical" Size="@("large")" Style="width: 100%">
<SpaceItem>
<Table TItem="ServerConsole" DataSource="@Value" HidePagination="true">
<PropertyColumn Property="m => m.Name">
<Input Type="text" @bind-Value="context.Name" />
</PropertyColumn>
<PropertyColumn Property="m => m.Path">
<Input Type="text" @bind-Value="context.Path" />
</PropertyColumn>
<ActionColumn>
<Space Style="display: flex; justify-content: end">
<SpaceItem>
<Button OnClick="() => RemoveConsole(context)" Type="@ButtonType.Text" Danger Icon="@IconType.Outline.Close" />
</SpaceItem>
</Space>
</ActionColumn>
</Table>
</SpaceItem>
@foreach (var console in Value)
{
<SpaceItem>
@if (console.Type == ServerConsoleType.RCON)
{
<Card Size="small">
<Body>
<Form Layout="@FormLayout.Vertical" Model="@console">
<GridRow Gutter="16">
<GridCol Span="8">
<FormItem Label="Type">
<Select @bind-Value="context.Type" TItem="ServerConsoleType" TItemValue="ServerConsoleType" DataSource="Enum.GetValues<ServerConsoleType>()">
<LabelTemplate Context="Value">@Value.GetDisplayName()</LabelTemplate>
<ItemTemplate Context="Value">@Value.GetDisplayName()</ItemTemplate>
</Select>
</FormItem>
<FormItem Label="Name">
<Input @bind-Value="context.Name" />
</FormItem>
</GridCol>
<GridCol Span="16">
<FormItem Label="Server">
<InputGroup Compact>
<Input @bind-Value="context.Host" Placeholder="Host" />
<Input @bind-Value="context.Port" Placeholder="Port" Style="width: 25%" />
</InputGroup>
</FormItem>
<FormItem Label="Password">
<InputPassword @bind-Value="context.Password" Placeholder="Password" />
</FormItem>
</GridCol>
</GridRow>
</Form>
</Body>
</Card>
}
else if (console.Type == ServerConsoleType.LogFile)
{
<Card Size="small">
<Body>
<Form Layout="@FormLayout.Vertical" Model="@console">
<GridRow Gutter="16">
<GridCol Span="8">
<FormItem Label="Type">
<Select @bind-Value="context.Type" TItem="ServerConsoleType" TItemValue="ServerConsoleType" DataSource="Enum.GetValues<ServerConsoleType>()">
<LabelTemplate Context="Value">@Value.GetDisplayName()</LabelTemplate>
<ItemTemplate Context="Value">@Value.GetDisplayName()</ItemTemplate>
</Select>
</FormItem>
<FormItem Label="Name">
<Input Type="text" @bind-Value="context.Name" />
</FormItem>
</GridCol>
<GridCol Span="16">
<FormItem Label="Path">
<Input Type="text" @bind-Value="context.Path" Placeholder="Host" />
</FormItem>
</GridCol>
</GridRow>
</Form>
</Body>
</Card>
}
</SpaceItem>
}
<SpaceItem>
<GridRow Justify="end">

View file

@ -202,7 +202,7 @@ namespace LANCommander.Services
{
if (!RconConnections.ContainsKey(console.Id))
{
var rcon = new RCON(new IPEndPoint(IPAddress.Parse(console.Host), console.Port), console.Password);
var rcon = new RCON(new IPEndPoint(IPAddress.Parse(console.Host), console.Port.GetValueOrDefault()), console.Password);
RconConnections[console.Id] = rcon;

View file

@ -1,3 +1,11 @@
.ant-select-selector {
line-height: 30px;
}
.ant-card .ant-form > .ant-form-item {
margin-bottom: 12px;
}
.ant-card .ant-form > .ant-form-item:last-child {
margin-bottom: 0;
}