1
0
mirror of synced 2024-11-30 17:04:28 +01:00

Update to support custom shop name and id

Bump dependency
This commit is contained in:
asesidaa 2023-09-30 16:33:21 +08:00
parent 5997452412
commit 64da380363
11 changed files with 86 additions and 16 deletions

View File

@ -12,10 +12,9 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="ChoETL" Version="1.2.1.52" /> <PackageReference Include="ChoETL" Version="1.2.1.64" />
<PackageReference Include="FlexLabs.EntityFrameworkCore.Upsert" Version="7.0.0" /> <PackageReference Include="FlexLabs.EntityFrameworkCore.Upsert" Version="7.0.0" />
<PackageReference Include="MediatR" Version="11.1.0" /> <PackageReference Include="MediatR" Version="12.1.1" />
<PackageReference Include="MediatR.Extensions.Microsoft.DependencyInjection" Version="11.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Core" Version="2.2.5" /> <PackageReference Include="Microsoft.AspNetCore.Mvc.Core" Version="2.2.5" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.2" /> <PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.2" />
<PackageReference Include="Microsoft.Extensions.Options" Version="7.0.0" /> <PackageReference Include="Microsoft.Extensions.Options" Version="7.0.0" />

View File

@ -9,6 +9,7 @@ public static class XmlSerializationExtensions
public static T DeserializeCardData<T>(this string source) where T : class public static T DeserializeCardData<T>(this string source) where T : class
{ {
using var reader = new ChoXmlReader<T>(new StringReader(source)).WithXPath("/root/data"); using var reader = new ChoXmlReader<T>(new StringReader(source)).WithXPath("/root/data");
reader.Configuration.IgnoreFieldValueMode = ChoIgnoreFieldValueMode.Any;
var result = reader.Read(); var result = reader.Read();
result.ThrowIfNull(); result.ThrowIfNull();

View File

@ -12,7 +12,7 @@ public static class DependencyInjection
{ {
public static IServiceCollection AddApplication(this IServiceCollection services) public static IServiceCollection AddApplication(this IServiceCollection services)
{ {
services.AddMediatR(Assembly.GetExecutingAssembly()); services.AddMediatR(configuration => configuration.RegisterServicesFromAssembly(Assembly.GetExecutingAssembly()));
services.AddScoped<ICardDependencyAggregate, CardDependencyAggregate>(); services.AddScoped<ICardDependencyAggregate, CardDependencyAggregate>();
services.AddTransient(typeof(IPipelineBehavior<,>), typeof(UnhandledExceptionBehaviour<,>)); services.AddTransient(typeof(IPipelineBehavior<,>), typeof(UnhandledExceptionBehaviour<,>));

View File

@ -13,10 +13,12 @@ public partial class CertifyCommandHandler : IRequestHandler<CertifyCommand, str
{ {
private readonly RelayConfig relayConfig; private readonly RelayConfig relayConfig;
private readonly AuthConfig authConfig;
public CertifyCommandHandler(IOptions<RelayConfig> relayOptions) public CertifyCommandHandler(IOptions<RelayConfig> relayOptions, IOptions<AuthConfig> authOptions)
{ {
relayConfig = relayOptions.Value; relayConfig = relayOptions.Value;
authConfig = authOptions.Value;
} }
public Task<string> Handle(CertifyCommand request, CancellationToken cancellationToken) public Task<string> Handle(CertifyCommand request, CancellationToken cancellationToken)
@ -41,7 +43,7 @@ public partial class CertifyCommandHandler : IRequestHandler<CertifyCommand, str
return Task.FromResult(QuitWithError(ErrorCode.ErrorNoHash)); return Task.FromResult(QuitWithError(ErrorCode.ErrorNoHash));
} }
if (!MacValid(request.Mac)) if (!MacValid(request.Mac) )
{ {
return Task.FromResult(QuitWithError(ErrorCode.ErrorInvalidMac)); return Task.FromResult(QuitWithError(ErrorCode.ErrorInvalidMac));
} }
@ -50,15 +52,31 @@ public partial class CertifyCommandHandler : IRequestHandler<CertifyCommand, str
{ {
return Task.FromResult(QuitWithError(ErrorCode.ErrorInvalidHash)); return Task.FromResult(QuitWithError(ErrorCode.ErrorInvalidHash));
} }
var machine = new Machine
{
TenpoId = "1337",
TenpoName = "GCLocalServer",
Pref = "nesys",
Location = "Local",
Mac = request.Mac
};
if (authConfig.Enabled)
{
machine = authConfig.Machines.FirstOrDefault(m => m.Mac == request.Mac);
if (machine is null)
{
return Task.FromResult(QuitWithError(ErrorCode.ErrorInvalidMac));
}
}
var ticket = string.Join(string.Empty, var ticket = string.Join(string.Empty,
MD5.HashData(Encoding.UTF8.GetBytes(request.Gid)).Select(b => b.ToString("x2"))); 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" + var response = $"host=card_id=7020392000147361,relay_addr={relayConfig.RelayServer},relay_port={relayConfig.RelayPort}\n" +
"no=1337\n" + $"no={machine.TenpoId}\n" +
"name=GCLocalServer\n" + $"name={machine.TenpoName}\n" +
"pref=nesys\n" + $"pref={machine.Pref}\n" +
"addr=Local\n" + $"addr={machine.Location}\n" +
"x-next-time=15\n" + "x-next-time=15\n" +
$"x-img=http://{request.Host}/news.png\n" + $"x-img=http://{request.Host}/news.png\n" +
$"x-ranking=http://{request.Host}/ranking/ranking.php\n" + $"x-ranking=http://{request.Host}/ranking/ranking.php\n" +

View File

@ -0,0 +1,19 @@
namespace Domain.Config;
public class AuthConfig
{
public const string AUTH_SECTION = "Auth";
public bool Enabled { get; set; }
public List<Machine> 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;
}

View File

@ -7,7 +7,9 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="NetEscapades.EnumGenerators" Version="1.0.0-beta06" PrivateAssets="all" ExcludeAssets="runtime" /> <PackageReference Include="NetEscapades.EnumGenerators" Version="1.0.0-beta08" PrivateAssets="all" ExcludeAssets="runtime">
<IncludeAssets>compile; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup> </ItemGroup>
</Project> </Project>

View File

@ -1,5 +1,6 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation"> <wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:Boolean x:Key="/Default/UserDictionary/Words/=ADDR/@EntryIndexedValue">True</s:Boolean> <s:Boolean x:Key="/Default/UserDictionary/Words/=ADDR/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=BDATA/@EntryIndexedValue">True</s:Boolean> <s:Boolean x:Key="/Default/UserDictionary/Words/=BDATA/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Fcol/@EntryIndexedValue">True</s:Boolean> <s:Boolean x:Key="/Default/UserDictionary/Words/=Fcol/@EntryIndexedValue">True</s:Boolean>

View File

@ -0,0 +1,14 @@
{
"Auth": {
"Enabled": false,
"Machines": [
{
"TenpoId": "1",
"TenpoName": "店舗1",
"Pref": "東京都",
"Location": "渋谷区",
"Mac": "000000000000"
}
]
}
}

View File

@ -1,4 +1,5 @@
using Application.Game.Server; using System.Text;
using Application.Game.Server;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
namespace MainServer.Controllers.Game; namespace MainServer.Controllers.Game;
@ -24,12 +25,19 @@ public class ServerController : BaseController<ServerController>
} }
[HttpGet("certify.php")] [HttpGet("certify.php")]
public async Task<ActionResult<string>> Certify(string? gid, string? mac, public async Task<ContentResult> Certify(string? gid, string? mac,
[FromQuery(Name = "r")]string? random, [FromQuery(Name = "md")]string? md5) [FromQuery(Name = "r")]string? random, [FromQuery(Name = "md")]string? md5)
{ {
var host = Request.Host.Value; var host = Request.Host.Value;
var command = new CertifyCommand(gid, mac, random, md5, host); 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")] [HttpGet("data.php")]

View File

@ -123,6 +123,7 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Folder Include="Formatters\" />
<Folder Include="Logs" /> <Folder Include="Logs" />
</ItemGroup> </ItemGroup>

View File

@ -1,7 +1,9 @@
using System.Reflection; using System.Reflection;
using System.Security.Authentication; using System.Security.Authentication;
using System.Text;
using Application; using Application;
using Application.Interfaces; using Application.Interfaces;
using ChoETL;
using Domain.Config; using Domain.Config;
using Infrastructure; using Infrastructure;
using Infrastructure.Common; using Infrastructure.Common;
@ -25,6 +27,8 @@ Log.Information("Server starting up...");
try try
{ {
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
ChoETLFrxBootstrap.IsSandboxEnvironment = true;
var builder = WebApplication.CreateBuilder(args); var builder = WebApplication.CreateBuilder(args);
// Add services to the container. // Add services to the container.
@ -35,6 +39,7 @@ try
.AddJsonFile($"{configurationsDirectory}/logging.json", optional: false, reloadOnChange: false) .AddJsonFile($"{configurationsDirectory}/logging.json", optional: false, reloadOnChange: false)
.AddJsonFile($"{configurationsDirectory}/events.json", optional: true, reloadOnChange: false) .AddJsonFile($"{configurationsDirectory}/events.json", optional: true, reloadOnChange: false)
.AddJsonFile($"{configurationsDirectory}/matching.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); .AddJsonFile($"{configurationsDirectory}/server.json", optional: true, reloadOnChange: false);
builder.Services.Configure<EventConfig>( builder.Services.Configure<EventConfig>(
@ -43,6 +48,8 @@ try
builder.Configuration.GetSection(RelayConfig.RELAY_SECTION)); builder.Configuration.GetSection(RelayConfig.RELAY_SECTION));
builder.Services.Configure<GameConfig>( builder.Services.Configure<GameConfig>(
builder.Configuration.GetSection(GameConfig.GAME_SECTION)); builder.Configuration.GetSection(GameConfig.GAME_SECTION));
builder.Services.Configure<AuthConfig>(
builder.Configuration.GetSection(AuthConfig.AUTH_SECTION));
var serverIp = builder.Configuration["ServerIp"] ?? "127.0.0.1"; var serverIp = builder.Configuration["ServerIp"] ?? "127.0.0.1";
var certificateManager = new CertificateService(serverIp, new SerilogLoggerFactory(Log.Logger).CreateLogger("")); var certificateManager = new CertificateService(serverIp, new SerilogLoggerFactory(Log.Logger).CreateLogger(""));