chore: upgrade to net9.0 & upgrade packages

This commit is contained in:
Somebody
2025-11-23 11:45:31 +08:00
parent a8de6beff6
commit d8980c87ad
11 changed files with 300 additions and 43 deletions

View File

@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<TargetFramework>net8.0</TargetFramework> <TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings> <ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
<RootNamespace>EggLink.DanhengServer.Command</RootNamespace> <RootNamespace>EggLink.DanhengServer.Command</RootNamespace>
@@ -9,8 +9,8 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Google.Protobuf" Version="3.29.1" /> <PackageReference Include="Google.Protobuf" Version="3.33.1" />
<PackageReference Include="Google.Protobuf.Tools" Version="3.29.1" /> <PackageReference Include="Google.Protobuf.Tools" Version="3.33.1" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>

View File

@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<TargetFramework>net8.0</TargetFramework> <TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings> <ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
<RootNamespace>EggLink.DanhengServer</RootNamespace> <RootNamespace>EggLink.DanhengServer</RootNamespace>
@@ -9,17 +9,18 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Google.Protobuf" Version="3.29.1" /> <PackageReference Include="EastAsianWidth" Version="1.2.0" />
<PackageReference Include="Google.Protobuf.Tools" Version="3.29.1" /> <PackageReference Include="Google.Protobuf" Version="3.33.1" />
<PackageReference Include="Google.Protobuf.Tools" Version="3.33.1" />
<PackageReference Include="Microsoft.Data.Sqlite.Core" Version="9.0.0" /> <PackageReference Include="Microsoft.Data.Sqlite.Core" Version="9.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="9.0.0" /> <PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="9.0.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" /> <PackageReference Include="Newtonsoft.Json" Version="13.0.4" />
<PackageReference Include="Spectre.Console" Version="0.49.1" /> <PackageReference Include="Spectre.Console" Version="0.54.0" />
<PackageReference Include="SQLitePCLRaw.core" Version="2.1.10" /> <PackageReference Include="SQLitePCLRaw.core" Version="3.0.2" />
<PackageReference Include="SQLitePCLRaw.provider.e_sqlite3" Version="2.1.10" /> <PackageReference Include="SQLitePCLRaw.provider.e_sqlite3" Version="3.0.2" />
<PackageReference Include="SqlSugarCore" Version="5.1.4.170" /> <PackageReference Include="SqlSugarCore" Version="5.1.4.210" />
<PackageReference Include="System.IO.Pipelines" Version="9.0.0" /> <PackageReference Include="System.IO.Pipelines" Version="10.0.0" />
<PackageReference Include="System.Management" Version="9.0.0" /> <PackageReference Include="System.Management" Version="10.0.0" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>

243
Common/Util/ICommand.cs Normal file
View File

@@ -0,0 +1,243 @@
using Kodnix.Character;
namespace EggLink.DanhengServer.Util
{
public static class IConsole
{
public const string PrefixContent = "> ";
private const string PinkColor = "\e[38;2;255;192;203m";
private const string RedColor = "\e[38;2;255;0;0m";
private const string ResetColor = "\e[0m";
// coloured prefix
public static string Prefix => $"{(IsCommandValid ? ResetColor : RedColor)}{PrefixContent}{ResetColor}";
public static bool IsCommandValid { get; private set; } = true;
private const int HistoryMaxCount = 10;
public static List<char> Input { get; set; } = [];
private static int CursorIndex { get; set; }
private static readonly List<string> InputHistory = [];
private static int HistoryIndex = -1;
public static event Action<string>? OnConsoleExcuteCommand;
public static void InitConsole()
{
Console.Title = "Danheng Server";
}
public static int GetWidth(string str)
=> str.ToCharArray().Sum(EastAsianWidth.GetLength);
public static void RedrawInput(List<char> input, bool hasPrefix = true)
=> RedrawInput(new string([.. input]), hasPrefix);
public static void RedrawInput(string input, bool hasPrefix = true)
{
// check validity
UpdateCommandValidity(input);
var length = GetWidth(input);
if (hasPrefix)
{
input = Prefix + input;
length += GetWidth(PrefixContent);
}
if (Console.GetCursorPosition().Left > 0)
Console.SetCursorPosition(0, Console.CursorTop);
Console.Write(input + new string(' ', Console.BufferWidth - length));
Console.SetCursorPosition(length, Console.CursorTop);
CursorIndex = length - GetWidth(PrefixContent);
}
// check validity and update
private static void UpdateCommandValidity(string input)
{
IsCommandValid = CheckCommandValid(input);
}
#region Handlers
public static void HandleEnter()
{
var input = new string([.. Input]);
if (string.IsNullOrWhiteSpace(input)) return;
// New line
Console.WriteLine();
Input = [];
CursorIndex = 0;
if (InputHistory.Count >= HistoryMaxCount)
InputHistory.RemoveAt(0);
InputHistory.Add(input);
HistoryIndex = InputHistory.Count;
// Handle command
if (input.StartsWith('/')) input = input[1..].Trim();
OnConsoleExcuteCommand?.Invoke(input);
// reset
IsCommandValid = true;
}
public static void HandleBackspace()
{
if (CursorIndex <= 0) return;
CursorIndex--;
var targetWidth = GetWidth(Input[CursorIndex].ToString());
Input.RemoveAt(CursorIndex);
var (left, _) = Console.GetCursorPosition();
Console.SetCursorPosition(left - targetWidth, Console.CursorTop);
var remain = new string([.. Input.Skip(CursorIndex)]);
Console.Write(remain + new string(' ', targetWidth));
Console.SetCursorPosition(left - targetWidth, Console.CursorTop);
// update
var prev = IsCommandValid;
UpdateCommandValidity(new string([.. Input]));
if (IsCommandValid != prev)
{
RedrawInput(Input);
}
}
public static void HandleUpArrow()
{
if (InputHistory.Count == 0) return;
if (HistoryIndex <= 0) return;
HistoryIndex--;
var history = InputHistory[HistoryIndex];
Input = [.. history];
CursorIndex = Input.Count;
// update
UpdateCommandValidity(history);
RedrawInput(Input);
}
public static void HandleDownArrow()
{
if (HistoryIndex >= InputHistory.Count) return;
HistoryIndex++;
if (HistoryIndex >= InputHistory.Count)
{
HistoryIndex = InputHistory.Count;
Input = [];
CursorIndex = 0;
IsCommandValid = true;
}
else
{
var history = InputHistory[HistoryIndex];
Input = [.. history];
CursorIndex = Input.Count;
// update
UpdateCommandValidity(history);
}
RedrawInput(Input);
}
public static void HandleLeftArrow()
{
if (CursorIndex <= 0) return;
var (left, _) = Console.GetCursorPosition();
CursorIndex--;
Console.SetCursorPosition(left - GetWidth(Input[CursorIndex].ToString()), Console.CursorTop);
}
public static void HandleRightArrow()
{
if (CursorIndex >= Input.Count) return;
var (left, _) = Console.GetCursorPosition();
CursorIndex++;
Console.SetCursorPosition(left + GetWidth(Input[CursorIndex - 1].ToString()), Console.CursorTop);
}
public static void HandleInput(ConsoleKeyInfo keyInfo)
{
if (char.IsControl(keyInfo.KeyChar)) return;
var newWidth = GetWidth(new string([.. Input])) + GetWidth(keyInfo.KeyChar.ToString());
if (newWidth >= (Console.BufferWidth - GetWidth(PrefixContent))) return;
HandleInput(keyInfo.KeyChar);
}
public static void HandleInput(char keyChar)
{
Input.Insert(CursorIndex, keyChar);
CursorIndex++;
var (left, _) = Console.GetCursorPosition();
var newCursor = left + GetWidth(keyChar.ToString());
if (newCursor > Console.BufferWidth - 1) newCursor = Console.BufferWidth - 1;
Console.Write(new string([.. Input.Skip(CursorIndex - 1)]));
Console.SetCursorPosition(newCursor, Console.CursorTop);
// update
var prev = IsCommandValid;
UpdateCommandValidity(new string([.. Input]));
if (IsCommandValid != prev)
{
RedrawInput(Input);
}
}
#endregion
public static string ListenConsole()
{
while (true)
{
ConsoleKeyInfo keyInfo;
try { keyInfo = Console.ReadKey(true); }
catch (InvalidOperationException) { continue; }
switch (keyInfo.Key)
{
case ConsoleKey.Enter:
HandleEnter();
break;
case ConsoleKey.Backspace:
HandleBackspace();
break;
case ConsoleKey.LeftArrow:
HandleLeftArrow();
break;
case ConsoleKey.RightArrow:
HandleRightArrow();
break;
case ConsoleKey.UpArrow:
HandleUpArrow();
break;
case ConsoleKey.DownArrow:
HandleDownArrow();
break;
default:
HandleInput(keyInfo);
break;
}
}
}
private static bool CheckCommandValid(string input)
{
if (string.IsNullOrEmpty(input))
return true;
var invalidChars = new[] { '@', '#', '$', '%', '&', '*' };
return !invalidChars.Any(c => input.Contains(c));
}
}
}

View File

@@ -13,9 +13,13 @@ public class Logger(string moduleName)
{ {
lock (Lock) lock (Lock)
{ {
var savedInput = IConsole.Input.ToList(); // Copy
IConsole.RedrawInput("", false);
AnsiConsole.Write(new Markup($"[[[bold deepskyblue3_1]{DateTime.Now:HH:mm:ss}[/]]] " + AnsiConsole.Write(new Markup($"[[[bold deepskyblue3_1]{DateTime.Now:HH:mm:ss}[/]]] " +
$"[[[gray]{moduleName}[/]]] [[[{(ConsoleColor)level}]{level}[/]]] {message.Replace("[", "[[").Replace("]", "]]")}\n")); $"[[[gray]{moduleName}[/]]] [[[{(ConsoleColor)level}]{level}[/]]] {message.Replace("[", "[[").Replace("]", "]]")}\n"));
IConsole.RedrawInput(savedInput);
var logMessage = $"[{DateTime.Now:HH:mm:ss}] [{moduleName}] [{level}] {message}"; var logMessage = $"[{DateTime.Now:HH:mm:ss}] [{moduleName}] [{level}] {message}";
PluginEventCommon.InvokeOnConsoleLog(logMessage); PluginEventCommon.InvokeOnConsoleLog(logMessage);

View File

@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<TargetFramework>net8.0</TargetFramework> <TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings> <ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
<AssemblyName>DanhengKcpSharp</AssemblyName> <AssemblyName>DanhengKcpSharp</AssemblyName>
@@ -9,9 +9,9 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Google.Protobuf" Version="3.29.1" /> <PackageReference Include="Google.Protobuf" Version="3.33.1" />
<PackageReference Include="Google.Protobuf.Tools" Version="3.29.1" /> <PackageReference Include="Google.Protobuf.Tools" Version="3.33.1" />
<PackageReference Include="System.IO.Pipelines" Version="9.0.0" /> <PackageReference Include="System.IO.Pipelines" Version="10.0.0" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>

View File

@@ -2,7 +2,7 @@
<PropertyGroup> <PropertyGroup>
<OutputType>Library</OutputType> <OutputType>Library</OutputType>
<TargetFramework>net8.0</TargetFramework> <TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings> <ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
<RootNamespace>EggLink.DanhengServer.GameServer</RootNamespace> <RootNamespace>EggLink.DanhengServer.GameServer</RootNamespace>
@@ -21,11 +21,11 @@
<ProjectReference Include="..\DanhengKcpSharp\DanhengKcpSharp.csproj" /> <ProjectReference Include="..\DanhengKcpSharp\DanhengKcpSharp.csproj" />
<ProjectReference Include="..\Proto\Proto.csproj" /> <ProjectReference Include="..\Proto\Proto.csproj" />
<ProjectReference Include="..\ServerSideProto\ServerSideProto.csproj" /> <ProjectReference Include="..\ServerSideProto\ServerSideProto.csproj" />
<PackageReference Include="Google.Protobuf" Version="3.29.1" /> <PackageReference Include="Google.Protobuf" Version="3.33.1" />
<PackageReference Include="Google.Protobuf.Tools" Version="3.29.1" /> <PackageReference Include="Google.Protobuf.Tools" Version="3.33.1" />
<PackageReference Include="McMaster.NETCore.Plugins" Version="1.4.0" /> <PackageReference Include="McMaster.NETCore.Plugins" Version="2.0.0" />
<PackageReference Include="McMaster.NETCore.Plugins.Mvc" Version="1.4.0" /> <PackageReference Include="McMaster.NETCore.Plugins.Mvc" Version="2.0.0" />
<PackageReference Include="System.IO.Pipelines" Version="9.0.0" /> <PackageReference Include="System.IO.Pipelines" Version="10.0.0" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>

View File

@@ -2,7 +2,7 @@
<PropertyGroup> <PropertyGroup>
<OutputType>Exe</OutputType> <OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework> <TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings> <ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
<RootNamespace>EggLink.DanhengServer.Program</RootNamespace> <RootNamespace>EggLink.DanhengServer.Program</RootNamespace>
@@ -15,8 +15,8 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Google.Protobuf" Version="3.29.1" /> <PackageReference Include="Google.Protobuf" Version="3.33.1" />
<PackageReference Include="Google.Protobuf.Tools" Version="3.29.1" /> <PackageReference Include="Google.Protobuf.Tools" Version="3.33.1" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>

View File

@@ -1,5 +1,4 @@
using System.Globalization; using EggLink.DanhengServer.Command;
using System.IO.Compression;
using EggLink.DanhengServer.Command.Command; using EggLink.DanhengServer.Command.Command;
using EggLink.DanhengServer.Configuration; using EggLink.DanhengServer.Configuration;
using EggLink.DanhengServer.Data; using EggLink.DanhengServer.Data;
@@ -19,6 +18,8 @@ using EggLink.DanhengServer.Program.Handbook;
using EggLink.DanhengServer.Util; using EggLink.DanhengServer.Util;
using EggLink.DanhengServer.WebServer; using EggLink.DanhengServer.WebServer;
using EggLink.DanhengServer.WebServer.Server; using EggLink.DanhengServer.WebServer.Server;
using System.Globalization;
using System.IO.Compression;
namespace EggLink.DanhengServer.Program.Program; namespace EggLink.DanhengServer.Program.Program;
@@ -31,6 +32,8 @@ public class EntryPoint
public static async Task Main(string[] args) public static async Task Main(string[] args)
{ {
IConsole.InitConsole();
IConsole.RedrawInput(IConsole.Input);
AppDomain.CurrentDomain.ProcessExit += (_, _) => AppDomain.CurrentDomain.ProcessExit += (_, _) =>
{ {
Logger.Info(I18NManager.Translate("Server.ServerInfo.Shutdown")); Logger.Info(I18NManager.Translate("Server.ServerInfo.Shutdown"));
@@ -417,7 +420,13 @@ public class EntryPoint
ResourceManager.IsLoaded = true; ResourceManager.IsLoaded = true;
CommandManager.Start(); IConsole.OnConsoleExcuteCommand += command =>
{
CommandManager.HandleCommand(command, new ConsoleCommandSender(Logger));
IConsole.RedrawInput(IConsole.Input);
};
IConsole.ListenConsole();
} }
public static ConfigContainer GetConfig() public static ConfigContainer GetConfig()

View File

@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<TargetFramework>net8.0</TargetFramework> <TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings> <ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
<AssemblyName>DanhengProto</AssemblyName> <AssemblyName>DanhengProto</AssemblyName>
@@ -9,7 +9,7 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Google.Protobuf" Version="3.29.1" /> <PackageReference Include="Google.Protobuf" Version="3.33.1" />
</ItemGroup> </ItemGroup>
</Project> </Project>

View File

@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<TargetFramework>net8.0</TargetFramework> <TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings> <ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
<RootNamespace>EggLink.DanhengServer.Proto.ServerSide</RootNamespace> <RootNamespace>EggLink.DanhengServer.Proto.ServerSide</RootNamespace>
@@ -9,7 +9,7 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Google.Protobuf" Version="3.29.1" /> <PackageReference Include="Google.Protobuf" Version="3.33.1" />
</ItemGroup> </ItemGroup>
</Project> </Project>

View File

@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Web"> <Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup> <PropertyGroup>
<TargetFramework>net8.0</TargetFramework> <TargetFramework>net9.0</TargetFramework>
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings> <ImplicitUsings>enable</ImplicitUsings>
<RootNamespace>EggLink.DanhengServer.WebServer</RootNamespace> <RootNamespace>EggLink.DanhengServer.WebServer</RootNamespace>
@@ -10,16 +10,16 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Google.Protobuf" Version="3.29.1" /> <PackageReference Include="Google.Protobuf" Version="3.33.1" />
<PackageReference Include="Google.Protobuf.Tools" Version="3.29.1" /> <PackageReference Include="Google.Protobuf.Tools" Version="3.33.1" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" /> <PackageReference Include="Newtonsoft.Json" Version="13.0.4" />
<PackageReference Include="Portable.BouncyCastle" Version="1.9.0" /> <PackageReference Include="Portable.BouncyCastle" Version="1.9.0" />
<PackageReference Include="Spectre.Console" Version="0.49.1" /> <PackageReference Include="Spectre.Console" Version="0.54.0" />
<PackageReference Include="SQLitePCLRaw.core" Version="2.1.10" /> <PackageReference Include="SQLitePCLRaw.core" Version="3.0.2" />
<PackageReference Include="SQLitePCLRaw.provider.e_sqlite3" Version="2.1.10" /> <PackageReference Include="SQLitePCLRaw.provider.e_sqlite3" Version="3.0.2" />
<PackageReference Include="SqlSugarCore" Version="5.1.4.170" /> <PackageReference Include="SqlSugarCore" Version="5.1.4.210" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="7.1.0" /> <PackageReference Include="Swashbuckle.AspNetCore" Version="10.0.1" />
<PackageReference Include="System.Management" Version="9.0.0" /> <PackageReference Include="System.Management" Version="10.0.0" />
<ProjectReference Include="..\Common\Common.csproj" /> <ProjectReference Include="..\Common\Common.csproj" />
<ProjectReference Include="..\Proto\Proto.csproj" /> <ProjectReference Include="..\Proto\Proto.csproj" />
</ItemGroup> </ItemGroup>