1
0
mirror of synced 2024-11-28 00:20:53 +01:00

Start working on card

This commit is contained in:
asesidaa 2022-08-15 17:50:40 +08:00
parent 304eedf44b
commit b5b1bf8dfb
14 changed files with 420 additions and 29 deletions

View File

@ -0,0 +1,32 @@
using Microsoft.AspNetCore.Mvc;
using Swan.Formatters;
using taiko.game;
namespace TaikoLocalServer.Controllers;
[ApiController]
[Route("/v12r03/chassis/baidcheck.php")]
public class BaidController:ControllerBase
{
private readonly ILogger<BaidController> logger;
public BaidController(ILogger<BaidController> logger)
{
this.logger = logger;
}
[HttpPost]
[Produces("application/protobuf")]
public IActionResult InitialDataCheck([FromBody] BAIDRequest request)
{
logger.LogInformation("Heartbeat request: {Request}", request.Stringify());
var response = new BAIDResponse()
{
Result = 0
};
return Ok(response);
}
}

View File

@ -1,10 +1,6 @@
using System.Net; using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc;
using ProtoBuf;
using Swan.Formatters; using Swan.Formatters;
using Swan.Logging;
using taiko.game; using taiko.game;
using taiko.vsinterface;
namespace TaikoLocalServer.Controllers; namespace TaikoLocalServer.Controllers;

View File

@ -0,0 +1,34 @@
using Microsoft.AspNetCore.Mvc;
using Swan.Formatters;
using taiko.game;
using taiko.vsinterface;
namespace TaikoLocalServer.Controllers;
[ApiController]
[Route("/v12r03/chassis/initialdatacheck.php")]
public class InitialDataCheckController:ControllerBase
{
private readonly ILogger<InitialDataCheckController> logger;
public InitialDataCheckController(ILogger<InitialDataCheckController> logger)
{
this.logger = logger;
}
[HttpPost]
[Produces("application/protobuf")]
public IActionResult InitialDataCheck([FromBody] InitialdatacheckRequest request)
{
logger.LogInformation("Heartbeat request: {Request}", request.Stringify());
var response = new InitialdatacheckResponse()
{
Result = 1,
IsDanplay = true
};
return Ok(response);
}
}

View File

@ -0,0 +1,88 @@
using Microsoft.AspNetCore.Mvc;
using Swan.Formatters;
using TaikoLocalServer.Models;
using TaikoLocalServer.Utils;
namespace TaikoLocalServer.Controllers;
public class MuchaController : ControllerBase
{
private const string UrlBase = "https://v402-front.mucha-prd.nbgi-amnet.jp:10122";
private readonly ILogger<MuchaController> logger;
public MuchaController(ILogger<MuchaController> logger) {
this.logger = logger;
}
[HttpPost("/mucha_front/boardauth.do")]
public ContentResult BoardAuth([FromForm] MuchaUpdateCheckRequest request)
{
logger.LogInformation("Request is {Request}", request.Stringify());
var serverTime = DateTime.Now.ToString("yyyyMMddHHmm");
var utcServerTime = DateTime.UtcNow.ToString("yyyyMMddHHmm");
var response = new Dictionary<string, string>
{
{ "RESULTS", "001" },
{ "AREA_0", "008" },
{ "AREA_0_EN", "" },
{ "AREA_1", "009" },
{ "AREA_1_EN", "" },
{ "AREA_2", "010" },
{ "AREA_2_EN", "" },
{ "AREA_3", "011" },
{ "AREA_3_EN", "" },
{ "AREA_FULL_0", "" },
{ "AREA_FULL_0_EN", "" },
{ "AREA_FULL_1", "" },
{ "AREA_FULL_1_EN", "" },
{ "AREA_FULL_2", "" },
{ "AREA_FULL_2_EN", "" },
{ "AREA_FULL_3", "" },
{ "AREA_FULL_3_EN", "" },
{ "AUTH_INTERVAL", "86400" },
{ "CHARGE_URL", $"{UrlBase}/charge/" },
{ "CONSUME_TOKEN", "0" },
{ "COUNTRY_CD", "JPN" },
{ "DONGLE_FLG", "1" },
{ "EXPIRATION_DATE", "null" },
{ "FILE_URL", $"{UrlBase}/file/" },
{ "FORCE_BOOT", "0" },
{ "PLACE_ID", request.PlaceId ?? "" },
{ "PREFECTURE_ID", "14" },
{ "SERVER_TIME", serverTime },
{ "UTC_SERVER_TIME", utcServerTime },
{ "SHOP_NAME", "NAMCO" },
{ "SHOP_NAME_EN", "NAMCO" },
{ "SHOP_NICKNAME", "W" },
{ "SHOP_NICKNAME_EN", "W" },
{ "URL_1", $"{UrlBase}/url1/" },
{ "URL_2", $"{UrlBase}/url2/" },
{ "URL_3", $"{UrlBase}/url3/" },
{ "USE_TOKEN", "0" }
};
var formOutput = FormOutputUtil.ToFormOutput(response);
return Content(formOutput);
}
[HttpPost("/mucha_front/updatacheck.do")]
public ContentResult UpdateCheck(MuchaBoardAuthRequest request)
{
logger.LogInformation("Request is {Request}", request.Stringify());
var response = new Dictionary<string, string>
{
{ "RESULTS", "001" },
{ "UPDATE_VER_1", request.GameVersion ?? "S1210JPN08.18" },
{ "UPDATE_URL_1", $"{UrlBase}/updUrl1/" },
{ "UPDATE_SIZE_1", "0" },
{ "UPDATE_CRC_1", "0000000000000000" },
{ "CHECK_URL_1", $"{UrlBase}/checkUrl/" },
{ "EXE_VER_1", request.GameVersion ?? "S1210JPN08.18" },
{ "INFO_SIZE_1", "0" },
{ "COM_SIZE_1", "0" },
{ "COM_TIME_1", "0" },
{ "LAN_INFO_SIZE_1", "0" }
};
var formOutput = FormOutputUtil.ToFormOutput(response);
return Content(formOutput);
}
}

View File

@ -0,0 +1,53 @@
using Microsoft.AspNetCore.Mvc;
using Swan.Formatters;
using TaikoLocalServer.Models;
using TaikoLocalServer.Utils;
namespace TaikoLocalServer.Controllers;
[ApiController]
[Route("/sys/servlet/PowerOn")]
public class PowerOnController : ControllerBase
{
private const string HostStartup = "vsapi.taiko-p.jp";
private readonly ILogger<PowerOnController> logger;
public PowerOnController(ILogger<PowerOnController> logger) {
this.logger = logger;
}
[HttpPost]
public ContentResult PowerOn([FromForm] PowerOnRequest request)
{
logger.LogInformation("{Request}",request.Stringify());
var now = DateTime.Now;
var response = new Dictionary<string, string>
{
{"stat", "1"},
{"uri", HostStartup},
{"host", HostStartup},
{"place_id", "JPN0123"},
{"name", "NAMCO"},
{"nickname", "NAMCO"},
{"region0", "1"},
{"region_name0", "NAMCO"},
{"region_name1", "X"},
{"region_name2", "Y"},
{"region_name3", "Z"},
{"country", "JPN"},
{"allnet_id", "456"},
{"timezone", "002,00"},
{"setting", ""},
{"year", now.Year.ToString()},
{"month", now.Month.ToString()},
{"day", now.Day.ToString()},
{"hour", now.Hour.ToString()},
{"minute", now.Minute.ToString()},
{"second", now.Second.ToString()},
{"res_class", "PowerOnResponseVer2"},
{"token", "123"}
};
return Content(FormOutputUtil.ToFormOutput(response) + '\n');
}
}

View File

@ -1,6 +1,4 @@
using System.Net; using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc;
using ProtoBuf;
using Swan.Formatters; using Swan.Formatters;
using taiko.vsinterface; using taiko.vsinterface;

View File

@ -0,0 +1,61 @@
using System.Buffers.Text;
using System.IO.Compression;
using System.Net;
using ICSharpCode.SharpZipLib.Zip.Compression.Streams;
namespace TaikoLocalServer.Middlewares;
public class AllNetRequestMiddleware
{
private readonly RequestDelegate next;
public AllNetRequestMiddleware(RequestDelegate next)
{
this.next = next;
}
public async Task InvokeAsync(HttpContext context)
{
if (context.Request.Method != WebRequestMethods.Http.Post)
{
context.Response.StatusCode = StatusCodes.Status405MethodNotAllowed;
return;
}
if (!context.Request.HasFormContentType)
{
await next(context);
return;
}
context.Request.EnableBuffering();
var bodyAsText = await new StreamReader(context.Request.Body).ReadToEndAsync();
var compressed = Convert.FromBase64String(bodyAsText);
var decompressed = Decompress(compressed);
context.Request.Body.Position = 0;
context.Request.Body = decompressed;
context.Request.ContentLength = decompressed.Length;
// Call the next delegate/middleware in the pipeline.
await next(context);
}
private static Stream Decompress(byte[] data)
{
var outputStream = new MemoryStream();
using var compressedStream = new MemoryStream(data);
using var inputStream = new InflaterInputStream(compressedStream);
inputStream.CopyTo(outputStream);
outputStream.Position = 0;
return outputStream;
}
}
public static class AllNetMiddlewareExtensions
{
public static IApplicationBuilder UseAllNetRequestMiddleware(
this IApplicationBuilder builder)
{
return builder.UseMiddleware<AllNetRequestMiddleware>();
}
}

View File

@ -0,0 +1,40 @@
using Microsoft.AspNetCore.Mvc;
namespace TaikoLocalServer.Models;
public class MuchaBoardAuthRequest
{
[FromForm(Name = "gameVer")]
public string? GameVersion { get; set; }
[FromForm(Name = "sendDate")]
public string? SendDate { get; set; }
[FromForm(Name = "serialNum")]
public string? SerialNumber { get; set; }
[FromForm(Name = "gameCd")]
public string? GameCode { get; set; }
[FromForm(Name = "boardType")]
public string? BoardType { get; set; }
[FromForm(Name = "boardId")]
public string? BoardId { get; set; }
[FromForm(Name = "placeId")]
public string? PlaceId { get; set; }
[FromForm(Name = "storeRouterIp")]
public string? StoreRouterIp { get; set; }
[FromForm(Name = "countryCd")]
public string? CountryCode { get; set; }
[FromForm(Name = "useToken")]
public string? UseToken { get; set; }
[FromForm(Name = "allToken")]
public string? AllToken { get; set; }
}

View File

@ -0,0 +1,24 @@
using Microsoft.AspNetCore.Mvc;
namespace TaikoLocalServer.Models;
public class MuchaUpdateCheckRequest
{
[FromForm(Name = "gameCd")]
public string? GameCode { get; set; }
[FromForm(Name = "gameVer")]
public string? GameVersion { get; set; }
[FromForm(Name = "serialNum")]
public string? SerialNumber { get; set; }
[FromForm(Name = "countryCd")]
public string? CountryCode { get; set; }
[FromForm(Name = "placeId")]
public string? PlaceId { get; set; }
[FromForm(Name = "storeRouterIp")]
public string? StoreRouterIp { get; set; }
}

View File

@ -0,0 +1,33 @@
using Microsoft.AspNetCore.Mvc;
namespace TaikoLocalServer.Models;
public class PowerOnRequest
{
[FromForm(Name = "game_id")]
public string? GameId { get; set; }
[FromForm(Name = "ver")]
public string? Version { get; set; }
[FromForm(Name = "serial")]
public string? Serial { get; set; }
[FromForm(Name = "ip")]
public string? Ip { get; set; }
[FromForm(Name = "firm_ver")]
public string? FirmwareVersion { get; set; }
[FromForm(Name = "boot_ver")]
public string? BootVersion { get; set; }
[FromForm(Name = "encode")]
public string? Encode { get; set; }
[FromForm(Name = "format_ver")]
public string? FormatVersion { get; set; }
[FromForm(Name = "hops")]
public string? Hops { get; set; }
}

View File

@ -1,11 +1,27 @@
using System.Security.Authentication;
using Microsoft.AspNetCore.HttpLogging;
using Microsoft.AspNetCore.HttpOverrides; using Microsoft.AspNetCore.HttpOverrides;
using TaikoLocalServer.Middlewares;
var builder = WebApplication.CreateBuilder(args); var builder = WebApplication.CreateBuilder(args);
// Manually enable tls 1.0
builder.WebHost.UseKestrel(kestrelOptions =>
{
kestrelOptions.ConfigureHttpsDefaults(httpsOptions =>
{
httpsOptions.SslProtocols = SslProtocols.Tls | SslProtocols.Tls11 | SslProtocols.Tls12 | SslProtocols.Tls13;
});
});
// Add services to the container. // Add services to the container.
builder.Services.AddControllers().AddProtoBufNet(); builder.Services.AddControllers().AddProtoBufNet();
// builder.Services.AddHttpLogging(options => op); builder.Services.AddHttpLogging(options =>
{
options.LoggingFields = HttpLoggingFields.RequestPropertiesAndHeaders |
HttpLoggingFields.ResponsePropertiesAndHeaders |
HttpLoggingFields.RequestBody;
options.RequestHeaders.Add("Pragma");
});
var app = builder.Build(); var app = builder.Build();
app.UseForwardedHeaders(new ForwardedHeadersOptions app.UseForwardedHeaders(new ForwardedHeadersOptions
@ -16,6 +32,9 @@ app.UseForwardedHeaders(new ForwardedHeadersOptions
app.UseHttpLogging(); app.UseHttpLogging();
app.MapControllers(); app.MapControllers();
app.UseWhen(context => context.Request.Path.StartsWithSegments("/sys/servlet/PowerOn", StringComparison.InvariantCulture),
applicationBuilder => applicationBuilder.UseAllNetRequestMiddleware());
app.MapGet("/", () => "Hello world"); app.MapGet("/", () => "Hello world");
app.Run(); app.Run();

View File

@ -9,9 +9,11 @@
<ItemGroup> <ItemGroup>
<PackageReference Include="protobuf-net" Version="3.1.17" /> <PackageReference Include="protobuf-net" Version="3.1.17" />
<PackageReference Include="protobuf-net.AspNetCore" Version="3.1.17" /> <PackageReference Include="protobuf-net.AspNetCore" Version="3.1.17" />
<PackageReference Include="SharpZipLib" Version="1.3.3" />
<PackageReference Include="Swan.Core" Version="6.0.2-beta.90" /> <PackageReference Include="Swan.Core" Version="6.0.2-beta.90" />
<PackageReference Include="Swan.Logging" Version="6.0.2-beta.69" /> <PackageReference Include="Swan.Logging" Version="6.0.2-beta.69" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" /> <PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" />
<PackageReference Include="Yoh.Text.Json.NamingPolicies" Version="0.2.1" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>

View File

@ -0,0 +1,20 @@
using System.Text;
namespace TaikoLocalServer.Utils;
public static class FormOutputUtil
{
public static string ToFormOutput(Dictionary<string, string> response)
{
var responseStr = new StringBuilder();
foreach (var pair in response)
{
responseStr.Append(pair.Key)
.Append('=')
.Append(pair.Value)
.Append('&');
}
return responseStr.ToString().TrimEnd('&');
}
}

View File

@ -2,31 +2,22 @@
"Logging": { "Logging": {
"LogLevel": { "LogLevel": {
"Default": "Information", "Default": "Information",
"Microsoft.AspNetCore": "Warning" "Microsoft.AspNetCore": "Information"
} }
}, },
"AllowedHosts": "*", "AllowedHosts": "*",
"Kestrel": { "Kestrel": {
"Endpoints": { "Endpoints": {
"All.Net": { "Server": {
"Url": "http://0.0.0.0:80" "Url": "http://0.0.0.0:5000"
}, }
"Mucha": { },
"Url": "https://0.0.0.0:10122" "Certificates": {
}, "Default": {
"VsInterface": { "Path": "Certificates/cert.pfx",
"Url": "https://0.0.0.0:54430" "Password": "",
}, "AllowInvalid": true
"Game": {
"Url": "https://0.0.0.0:54431"
} }
}
},
"Certificates": {
"Default": {
"Path": "Certificates/cert.pfx",
"Password": "",
"AllowInvalid": true
} }
} }
} }