Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .github/workflows/dotnet-core.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-20.04, windows-latest]
framework: ['8.0']
os: [ubuntu-22.04, windows-latest]
framework: ['9.0']
include:
- os: ubuntu-20.04
- os: ubuntu-22.04
target: linux-x64
- os: windows-latest
target: win-x64
Expand All @@ -20,7 +20,7 @@ jobs:
steps:
- uses: actions/checkout@v4

- if: matrix.os == 'ubuntu-20.04'
- if: matrix.os == 'ubuntu-22.04'
name: Install Linux packages
run: |
sudo apt-get update
Expand Down
8 changes: 3 additions & 5 deletions Commands/ExitCommand.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
using System.Threading.Tasks;
using LocalAdmin.V2.Commands.Meta;
using LocalAdmin.V2.Core;

namespace LocalAdmin.V2.Commands;

internal sealed class ExitCommand : CommandBase
internal sealed class ExitCommand() : CommandBase("Exit", "Stops the server.", true)
{
public ExitCommand() : base("Exit", "Stops the server.", true) { }

internal override void Execute(string[] arguments) { }
internal override ValueTask Execute(string[] arguments) => ValueTask.CompletedTask;
}
10 changes: 5 additions & 5 deletions Commands/ForceRestartCommand.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
using System.Threading.Tasks;
using LocalAdmin.V2.Commands.Meta;

namespace LocalAdmin.V2.Commands;

internal sealed class ForceRestartCommand : CommandBase
internal sealed class ForceRestartCommand() : CommandBase("Forcerestart", "Kills and restarts the server.")
{
public ForceRestartCommand() : base("Forcerestart", "Kills and restarts the server.") { }

internal override void Execute(string[] arguments)
internal override ValueTask Execute(string[] arguments)
{
Core.LocalAdmin.Singleton!.ExitAction = Core.LocalAdmin.ShutdownAction.Restart;
Core.LocalAdmin.Singleton.ExitAction = Core.LocalAdmin.ShutdownAction.Restart;
Core.LocalAdmin.Singleton.Exit(0, restart: true);
return ValueTask.CompletedTask;
}
}
14 changes: 7 additions & 7 deletions Commands/HeartbeatCancelCommand.cs
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
using System;
using System.Threading.Tasks;
using LocalAdmin.V2.Commands.Meta;
using LocalAdmin.V2.IO;

namespace LocalAdmin.V2.Commands;

internal sealed class HeartbeatCancelCommand : CommandBase
internal sealed class HeartbeatCancelCommand() : CommandBase("hbc", "Cancels heartbeat restart countdown.")
{
public HeartbeatCancelCommand() : base("hbc", "Cancels heartbeat restart countdown.") { }

internal override void Execute(string[] arguments)
internal override ValueTask Execute(string[] arguments)
{
if (Core.LocalAdmin.Singleton!.CurrentHeartbeatStatus != Core.LocalAdmin.HeartbeatStatus.Active)
if (Core.LocalAdmin.Singleton.CurrentHeartbeatStatus != Core.LocalAdmin.HeartbeatStatus.Active)
{
ConsoleUtil.WriteLine("Heartbeat is not active!", ConsoleColor.Yellow);
return;
return ValueTask.CompletedTask;
}

if (Core.LocalAdmin.Singleton.HeartbeatWarningStage == 0)
{
ConsoleUtil.WriteLine("Heartbeat restart countdown has not started!", ConsoleColor.Yellow);
return;
return ValueTask.CompletedTask;
}

Core.LocalAdmin.Singleton.CurrentHeartbeatStatus = Core.LocalAdmin.HeartbeatStatus.AwaitingFirstHeartbeat;

ConsoleUtil.WriteLine("Heartbeat restart countdown has been cancelled.", ConsoleColor.DarkGreen);
ConsoleUtil.WriteLine("Crash detection will be resumed after receiving any heartbeat. If you want to disable heartbeat completely for this LocalAdmin session (until server is restarted) run \"hbctrl 0\" command.", ConsoleColor.DarkGreen);
return ValueTask.CompletedTask;
}
}
33 changes: 13 additions & 20 deletions Commands/HeartbeatControlCommand.cs
Original file line number Diff line number Diff line change
@@ -1,25 +1,24 @@
using System;
using System.Threading.Tasks;
using LocalAdmin.V2.Commands.Meta;
using LocalAdmin.V2.IO;

namespace LocalAdmin.V2.Commands;

internal sealed class HeartbeatControlCommand : CommandBase
internal sealed class HeartbeatControlCommand() : CommandBase("hbctrl", "Controls Heartbeat")
{
public HeartbeatControlCommand() : base("hbctrl", "Controls Heartbeat") { }

internal override void Execute(string[] arguments)
internal override ValueTask Execute(string[] arguments)
{
if (!Core.LocalAdmin.Singleton!.EnableGameHeartbeat)
if (!Core.LocalAdmin.Singleton.EnableGameHeartbeat)
{
ConsoleUtil.WriteLine("Heartbeat is not enabled in the LA config!", ConsoleColor.Yellow);
return;
return ValueTask.CompletedTask;
}

if (arguments.Length != 1)
{
ConsoleUtil.WriteLine("Usage: hbctrl <enable|disable|status>", ConsoleColor.Yellow);
return;
return ValueTask.CompletedTask;
}

switch (arguments[0].ToLowerInvariant())
Expand Down Expand Up @@ -68,26 +67,20 @@ internal override void Execute(string[] arguments)
ConsoleUtil.WriteLine("Unknown subcommand. Run \"hbctrl\" for get command usage.", ConsoleColor.Red);
break;
}
return ValueTask.CompletedTask;
}

private static string HeartbeatStatusString
{
get
{
switch (Core.LocalAdmin.Singleton!.CurrentHeartbeatStatus)
return Core.LocalAdmin.Singleton.CurrentHeartbeatStatus switch
{
case Core.LocalAdmin.HeartbeatStatus.Disabled:
return "DISABLED";

case Core.LocalAdmin.HeartbeatStatus.AwaitingFirstHeartbeat:
return "ACTIVE - AWAITING FIRST HEARTBEAT";

case Core.LocalAdmin.HeartbeatStatus.Active:
return "ACTIVE - MONITORING";

default:
return "(unknown)";
}
Core.LocalAdmin.HeartbeatStatus.Disabled => "DISABLED",
Core.LocalAdmin.HeartbeatStatus.AwaitingFirstHeartbeat => "ACTIVE - AWAITING FIRST HEARTBEAT",
Core.LocalAdmin.HeartbeatStatus.Active => "ACTIVE - MONITORING",
_ => "(unknown)"
};
}
}
}
18 changes: 9 additions & 9 deletions Commands/HelpCommand.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
using LocalAdmin.V2.Commands.Meta;
using LocalAdmin.V2.IO;
using System;
using System.Linq;
using System.Threading.Tasks;
using LocalAdmin.V2.Commands.Meta;
using LocalAdmin.V2.IO;

namespace LocalAdmin.V2.Commands;

internal sealed class HelpCommand : CommandBase
internal sealed class HelpCommand() : CommandBase("Help", "Prints all available commands.", true)
{
public HelpCommand() : base("Help", "Prints all available commands.", true) { }

internal override void Execute(string[] arguments)
internal override ValueTask Execute(string[] arguments)
{
var commands = Core.LocalAdmin.Singleton?.CommandService.GetAllCommands().OrderBy(p => p.Name);

Expand All @@ -18,9 +17,10 @@ internal override void Execute(string[] arguments)

if (commands is not null)
foreach (var item in commands)
ConsoleUtil.WriteLine($"{item.Name} - {item.Description}");
ConsoleUtil.WriteLine("------------" + Environment.NewLine, ConsoleColor.DarkGray);
ConsoleUtil.WriteLine($"{item.Name.ToUpperInvariant()} - {item.Description}");

ConsoleUtil.WriteLine($"------------{Environment.NewLine}", ConsoleColor.DarkGray);
ConsoleUtil.WriteLine("---- Game Commands ----", ConsoleColor.DarkGray);
return ValueTask.CompletedTask;
}
}
11 changes: 6 additions & 5 deletions Commands/LaCfgCommand.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
using System;
using System.Threading.Tasks;
using LocalAdmin.V2.Commands.Meta;
using LocalAdmin.V2.IO;

namespace LocalAdmin.V2.Commands;

internal sealed class LaCfgCommand : CommandBase
internal sealed class LaCfgCommand() : CommandBase("lacfg",
"Prints the current LocalAdmin configuration and the configuration file path.")
{
public LaCfgCommand() : base("lacfg", "Prints the current LocalAdmin configuration and the configuration file path.") { }

internal override void Execute(string[] arguments)
internal override ValueTask Execute(string[] arguments)
{
ConsoleUtil.WriteLine($"Current LocalAdmin config file path is: {Core.LocalAdmin.CurrentConfigPath ?? "(null)"}", ConsoleColor.DarkGreen);
ConsoleUtil.WriteLine($"Current LocalAdmin Configuration:{Environment.NewLine}{LocalAdmin.V2.Core.LocalAdmin.Configuration!.ToString()}");
ConsoleUtil.WriteLine($"Current LocalAdmin Configuration:{Environment.NewLine}{Core.LocalAdmin.Configuration!}");
return ValueTask.CompletedTask;
}
}
13 changes: 6 additions & 7 deletions Commands/LicenseCommand.cs
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
using System;
using System.Threading.Tasks;
using LocalAdmin.V2.Commands.Meta;
using LocalAdmin.V2.IO;
using System;

namespace LocalAdmin.V2.Commands;

internal sealed class LicenseCommand : CommandBase
internal sealed class LicenseCommand() : CommandBase("License", "Prints LocalAdmin license details.")
{
public LicenseCommand() : base("License", "Prints LocalAdmin license details.") { }

internal override void Execute(string[] arguments)
internal override ValueTask Execute(string[] arguments)
{
ConsoleUtil.WriteLine("MIT License", ConsoleColor.Cyan);
ConsoleUtil.WriteLine("Copyright by Łukasz \"zabszk\" Jurczyk and KernelError, 2019 - 2024", ConsoleColor.Gray);
ConsoleUtil.WriteLine("Copyright by Łukasz \"zabszk\" Jurczyk and KernelError, 2019 - 2025", ConsoleColor.Gray);
ConsoleUtil.WriteLine("Permission is hereby granted, free of charge, to any person obtaining a copy\r\nof this software and associated documentation files (the \"Software\"), to deal\r\nin the Software without restriction, including without limitation the rights\r\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\r\ncopies of the Software, and to permit persons to whom the Software is\r\nfurnished to do so, subject to the following conditions:", ConsoleColor.Gray);
ConsoleUtil.WriteLine("\r\nThe above copyright notice and this permission notice shall be included in all\r\ncopies or substantial portions of the Software.", ConsoleColor.Gray);
ConsoleUtil.WriteLine("\r\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\r\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\r\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\r\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\r\nSOFTWARE.", ConsoleColor.Gray);

ConsoleUtil.WriteLine("", ConsoleColor.Gray);
ConsoleUtil.WriteLine("LocalAdmin includes Utf8Json developed by Yoshifumi Kawai licensed under The MIT License.", ConsoleColor.Gray);
return ValueTask.CompletedTask;
}
}
24 changes: 8 additions & 16 deletions Commands/Meta/CommandBase.cs
Original file line number Diff line number Diff line change
@@ -1,24 +1,16 @@
using System.Threading.Tasks;

namespace LocalAdmin.V2.Commands.Meta;

internal abstract class CommandBase
internal abstract class CommandBase(string name, string description, bool sendToGame = false)
{
public readonly string Name;
public readonly string Description;
public readonly bool SendToGame;

protected CommandBase(string name, bool sendToGame = false)
{
Name = name.ToUpperInvariant();
Description = "No Description Provided";
SendToGame = sendToGame;
}
public readonly string Name = name;
public readonly string Description = description;
public readonly bool SendToGame = sendToGame;

protected CommandBase(string name, string description, bool sendToGame = false)
protected CommandBase(string name, bool sendToGame = false) : this(name, "No Description Provided", sendToGame)
{
Name = name.ToUpperInvariant();
Description = description;
SendToGame = sendToGame;
}

internal abstract void Execute(string[] arguments);
internal abstract ValueTask Execute(string[] arguments);
}
5 changes: 2 additions & 3 deletions Commands/Meta/CommandService.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
using System.Linq;

namespace LocalAdmin.V2.Commands.Meta;

Expand All @@ -21,11 +20,11 @@ internal void UnregisterCommand(CommandBase command)

internal CommandBase? GetCommandByName(string name)
{
return _commands.TryGetValue(name, out CommandBase? command) ? command : null;
return _commands.GetValueOrDefault(name);
}

internal CommandBase[] GetAllCommands()
{
return _commands.Values.ToArray();
return [.. _commands.Values];
}
}
Loading