From 64da38036341a943343f727ae1d21b1ecf287a74 Mon Sep 17 00:00:00 2001 From: asesidaa <1061472754@qq.com> Date: Sat, 30 Sep 2023 16:33:21 +0800 Subject: [PATCH] Update to support custom shop name and id Bump dependency --- Application/Application.csproj | 5 ++- .../Extensions/XmlSerializationExtensions.cs | 1 + Application/DependencyInjection.cs | 2 +- Application/Game/Server/CertifyCommand.cs | 32 +++++++++++++++---- Domain/Config/AuthConfig.cs | 19 +++++++++++ Domain/Domain.csproj | 4 ++- GC-local-server-rewrite.sln.DotSettings.user | 1 + MainServer/Configurations/auth.json | 14 ++++++++ .../Controllers/Game/ServerController.cs | 14 ++++++-- MainServer/MainServer.csproj | 1 + MainServer/Program.cs | 9 +++++- 11 files changed, 86 insertions(+), 16 deletions(-) create mode 100644 Domain/Config/AuthConfig.cs create mode 100644 MainServer/Configurations/auth.json diff --git a/Application/Application.csproj b/Application/Application.csproj index d86fa22..9ea0e9d 100644 --- a/Application/Application.csproj +++ b/Application/Application.csproj @@ -12,10 +12,9 @@ - + - - + diff --git a/Application/Common/Extensions/XmlSerializationExtensions.cs b/Application/Common/Extensions/XmlSerializationExtensions.cs index 640b7d2..ef64d7e 100644 --- a/Application/Common/Extensions/XmlSerializationExtensions.cs +++ b/Application/Common/Extensions/XmlSerializationExtensions.cs @@ -9,6 +9,7 @@ public static class XmlSerializationExtensions public static T DeserializeCardData(this string source) where T : class { using var reader = new ChoXmlReader(new StringReader(source)).WithXPath("/root/data"); + reader.Configuration.IgnoreFieldValueMode = ChoIgnoreFieldValueMode.Any; var result = reader.Read(); result.ThrowIfNull(); diff --git a/Application/DependencyInjection.cs b/Application/DependencyInjection.cs index 915b0b3..3c5cfd6 100644 --- a/Application/DependencyInjection.cs +++ b/Application/DependencyInjection.cs @@ -12,7 +12,7 @@ public static class DependencyInjection { public static IServiceCollection AddApplication(this IServiceCollection services) { - services.AddMediatR(Assembly.GetExecutingAssembly()); + services.AddMediatR(configuration => configuration.RegisterServicesFromAssembly(Assembly.GetExecutingAssembly())); services.AddScoped(); services.AddTransient(typeof(IPipelineBehavior<,>), typeof(UnhandledExceptionBehaviour<,>)); diff --git a/Application/Game/Server/CertifyCommand.cs b/Application/Game/Server/CertifyCommand.cs index f0a500b..8fdc8bb 100644 --- a/Application/Game/Server/CertifyCommand.cs +++ b/Application/Game/Server/CertifyCommand.cs @@ -12,11 +12,13 @@ public record CertifyCommand(string? Gid, string? Mac, string? Random, string? M public partial class CertifyCommandHandler : IRequestHandler { private readonly RelayConfig relayConfig; - - public CertifyCommandHandler(IOptions relayOptions) + private readonly AuthConfig authConfig; + + public CertifyCommandHandler(IOptions relayOptions, IOptions authOptions) { relayConfig = relayOptions.Value; + authConfig = authOptions.Value; } public Task Handle(CertifyCommand request, CancellationToken cancellationToken) @@ -41,7 +43,7 @@ public partial class CertifyCommandHandler : IRequestHandler m.Mac == request.Mac); + if (machine is null) + { + return Task.FromResult(QuitWithError(ErrorCode.ErrorInvalidMac)); + } + } var ticket = string.Join(string.Empty, MD5.HashData(Encoding.UTF8.GetBytes(request.Gid)).Select(b => b.ToString("x2"))); var response = $"host=card_id=7020392000147361,relay_addr={relayConfig.RelayServer},relay_port={relayConfig.RelayPort}\n" + - "no=1337\n" + - "name=GCLocalServer\n" + - "pref=nesys\n" + - "addr=Local\n" + + $"no={machine.TenpoId}\n" + + $"name={machine.TenpoName}\n" + + $"pref={machine.Pref}\n" + + $"addr={machine.Location}\n" + "x-next-time=15\n" + $"x-img=http://{request.Host}/news.png\n" + $"x-ranking=http://{request.Host}/ranking/ranking.php\n" + diff --git a/Domain/Config/AuthConfig.cs b/Domain/Config/AuthConfig.cs new file mode 100644 index 0000000..e477c95 --- /dev/null +++ b/Domain/Config/AuthConfig.cs @@ -0,0 +1,19 @@ +namespace Domain.Config; + +public class AuthConfig +{ + public const string AUTH_SECTION = "Auth"; + + public bool Enabled { get; set; } + + public List Machines { get; set; } = new(); +} + +public class Machine +{ + public string TenpoId { get; set; } = string.Empty; + public string TenpoName { get; set; } = string.Empty; + public string Pref { get; set; } = string.Empty; + public string Location { get; set; } = string.Empty; + public string Mac { get; set; } = string.Empty; +} \ No newline at end of file diff --git a/Domain/Domain.csproj b/Domain/Domain.csproj index 2c82047..0dff19f 100644 --- a/Domain/Domain.csproj +++ b/Domain/Domain.csproj @@ -7,7 +7,9 @@ - + + compile; build; native; contentfiles; analyzers; buildtransitive + diff --git a/GC-local-server-rewrite.sln.DotSettings.user b/GC-local-server-rewrite.sln.DotSettings.user index 06d7a7b..1ad11c4 100644 --- a/GC-local-server-rewrite.sln.DotSettings.user +++ b/GC-local-server-rewrite.sln.DotSettings.user @@ -1,5 +1,6 @@  + True True True diff --git a/MainServer/Configurations/auth.json b/MainServer/Configurations/auth.json new file mode 100644 index 0000000..98008be --- /dev/null +++ b/MainServer/Configurations/auth.json @@ -0,0 +1,14 @@ +{ + "Auth": { + "Enabled": false, + "Machines": [ + { + "TenpoId": "1", + "TenpoName": "店舗1", + "Pref": "東京都", + "Location": "渋谷区", + "Mac": "000000000000" + } + ] + } +} \ No newline at end of file diff --git a/MainServer/Controllers/Game/ServerController.cs b/MainServer/Controllers/Game/ServerController.cs index 8757b9f..dac354b 100644 --- a/MainServer/Controllers/Game/ServerController.cs +++ b/MainServer/Controllers/Game/ServerController.cs @@ -1,4 +1,5 @@ -using Application.Game.Server; +using System.Text; +using Application.Game.Server; using Microsoft.AspNetCore.Mvc; namespace MainServer.Controllers.Game; @@ -24,12 +25,19 @@ public class ServerController : BaseController } [HttpGet("certify.php")] - public async Task> Certify(string? gid, string? mac, + public async Task Certify(string? gid, string? mac, [FromQuery(Name = "r")]string? random, [FromQuery(Name = "md")]string? md5) { var host = Request.Host.Value; var command = new CertifyCommand(gid, mac, random, md5, host); - return Ok(await Mediator.Send(command)); + var result = await Mediator.Send(command); + var shiftJis = Encoding.GetEncoding(932); + var originalBytes = Encoding.UTF8.GetBytes(result); + var converted = Encoding.Convert(Encoding.Default, shiftJis, originalBytes); + result = shiftJis.GetString(converted); + //Response.ContentType = "text/plain; charset=shift_jis"; + + return Content(result, "text/plain", shiftJis); } [HttpGet("data.php")] diff --git a/MainServer/MainServer.csproj b/MainServer/MainServer.csproj index 01c2bfc..8b3cfba 100644 --- a/MainServer/MainServer.csproj +++ b/MainServer/MainServer.csproj @@ -123,6 +123,7 @@ + diff --git a/MainServer/Program.cs b/MainServer/Program.cs index a78c8cc..091ddac 100644 --- a/MainServer/Program.cs +++ b/MainServer/Program.cs @@ -1,7 +1,9 @@ using System.Reflection; using System.Security.Authentication; +using System.Text; using Application; using Application.Interfaces; +using ChoETL; using Domain.Config; using Infrastructure; using Infrastructure.Common; @@ -25,6 +27,8 @@ Log.Information("Server starting up..."); try { + Encoding.RegisterProvider(CodePagesEncodingProvider.Instance); + ChoETLFrxBootstrap.IsSandboxEnvironment = true; var builder = WebApplication.CreateBuilder(args); // Add services to the container. @@ -35,6 +39,7 @@ try .AddJsonFile($"{configurationsDirectory}/logging.json", optional: false, reloadOnChange: false) .AddJsonFile($"{configurationsDirectory}/events.json", optional: true, reloadOnChange: false) .AddJsonFile($"{configurationsDirectory}/matching.json", optional: true, reloadOnChange: false) + .AddJsonFile($"{configurationsDirectory}/auth.json", optional: true, reloadOnChange: false) .AddJsonFile($"{configurationsDirectory}/server.json", optional: true, reloadOnChange: false); builder.Services.Configure( @@ -42,7 +47,9 @@ try builder.Services.Configure( builder.Configuration.GetSection(RelayConfig.RELAY_SECTION)); builder.Services.Configure( - builder.Configuration.GetSection(GameConfig.GAME_SECTION)); + builder.Configuration.GetSection(GameConfig.GAME_SECTION)); + builder.Services.Configure( + builder.Configuration.GetSection(AuthConfig.AUTH_SECTION)); var serverIp = builder.Configuration["ServerIp"] ?? "127.0.0.1"; var certificateManager = new CertificateService(serverIp, new SerilogLoggerFactory(Log.Logger).CreateLogger(""));