diff --git a/TaikoLocalServer/Controllers/Game/Headclerk2Controller.cs b/TaikoLocalServer/Controllers/Game/Headclerk2Controller.cs index d71bf69..026778d 100644 --- a/TaikoLocalServer/Controllers/Game/Headclerk2Controller.cs +++ b/TaikoLocalServer/Controllers/Game/Headclerk2Controller.cs @@ -4,16 +4,36 @@ [Route("/v12r00_cn/chassis/headclerk2.php")] public class Headclerk2Controller : BaseController { - [HttpPost] - [Produces("application/protobuf")] - public IActionResult Headclerk2([FromBody] HeadClerk2Request request) - { - Logger.LogInformation("Headclerk2 request: {Request}", request.Stringify()); - var response = new HeadClerk2Response - { - Result = 1 - }; + [HttpPost] + [Produces("application/protobuf")] + public IActionResult Headclerk2([FromBody] HeadClerk2Request request) + { + Logger.LogInformation("Headclerk2 request: {Request}", request.Stringify()); - return Ok(response); - } + var chassisId = request.ChassisId; + var shopId = request.ShopId; + foreach (var playInfo in request.AryPlayInfoes) + { + var baid = playInfo.Baid; + var playedAt = playInfo.PlayedAt; + var isRight = playInfo.IsRight; + var type = playInfo.Type; + var amount = playInfo.Amount; + Logger.LogInformation("CSV WRITE: \n" + + "ChassisId:{ChassisId},\n" + + "ShopId:{ShopId},\n" + + "Baid:{Baid},\n" + + "PlayedAt{PlayedAt},\n" + + "IsRight:{IsRight},\n" + + "Type:{Type},\n" + + "Amount{Amount}", chassisId, shopId, baid, playedAt, isRight, type, amount); + } + + var response = new HeadClerk2Response + { + Result = 1 + }; + + return Ok(response); + } } \ No newline at end of file diff --git a/TaikoLocalServer/Controllers/Game/SetAnyStringController.cs b/TaikoLocalServer/Controllers/Game/SetAnyStringController.cs new file mode 100644 index 0000000..c81bd0d --- /dev/null +++ b/TaikoLocalServer/Controllers/Game/SetAnyStringController.cs @@ -0,0 +1,20 @@ +namespace TaikoLocalServer.Controllers.Game; + +[Route("/v12r00_cn/chassis/setanystring.php")] +[ApiController] +public class SetAnyStringController : BaseController +{ + [HttpPost] + [Produces("application/protobuf")] + public IActionResult SetAnyString([FromBody] SetAnyStringRequest request) + { + Logger.LogInformation("SetAnyString request : {Request}", request.Stringify()); + + var response = new SetAnyStringResponse + { + Result = 1, + }; + + return Ok(response); + } +} \ No newline at end of file diff --git a/TaikoLocalServer/Logging/CsvFormatter.cs b/TaikoLocalServer/Logging/CsvFormatter.cs new file mode 100644 index 0000000..dfadfb7 --- /dev/null +++ b/TaikoLocalServer/Logging/CsvFormatter.cs @@ -0,0 +1,35 @@ +using Serilog.Events; +using Serilog.Formatting; + +namespace TaikoLocalServer.Logging; + +public class CsvFormatter: ITextFormatter +{ + public void Format(LogEvent logEvent, TextWriter output) + { + logEvent.Properties.TryGetValue("ChassisId", out var chassisId); + logEvent.Properties.TryGetValue("ShopId", out var shopId); + logEvent.Properties.TryGetValue("Baid", out var baid); + logEvent.Properties.TryGetValue("PlayedAt", out var playedAt); + logEvent.Properties.TryGetValue("IsRight", out var isRight); + logEvent.Properties.TryGetValue("Type", out var type); + logEvent.Properties.TryGetValue("Amount", out var amount); + + output.Write(logEvent.Timestamp.ToString("yyyy-MM-dd")); + output.Write(","); + output.Write(chassisId); + output.Write(","); + output.Write(shopId); + output.Write(","); + output.Write(baid); + output.Write(","); + output.Write(playedAt); + output.Write(","); + output.Write(isRight); + output.Write(","); + output.Write(type); + output.Write(","); + output.Write(amount); + output.WriteLine(); + } +} \ No newline at end of file diff --git a/TaikoLocalServer/Program.cs b/TaikoLocalServer/Program.cs index 312ac0c..9978850 100644 --- a/TaikoLocalServer/Program.cs +++ b/TaikoLocalServer/Program.cs @@ -1,5 +1,7 @@ using System.Reflection; using System.Security.Authentication; +using Serilog.Sinks.File.Header; +using TaikoLocalServer.Logging; using GameDatabase.Context; using Microsoft.AspNetCore.HttpLogging; using Microsoft.AspNetCore.HttpOverrides; @@ -40,7 +42,16 @@ try builder.Host.UseSerilog((context, configuration) => { - configuration.WriteTo.Console().ReadFrom.Configuration(context.Configuration); + configuration + .WriteTo.Console().ReadFrom.Configuration(context.Configuration) + .WriteTo.Logger(x => + { + x.WriteTo.File(new CsvFormatter(), + path: "./Logs/HeadClerkLog-.csv", + hooks: new HeaderWriter("Date,ChassisId,ShopId,Baid,PlayedAt,IsRight,Type,Amount"), + rollingInterval: RollingInterval.Day); + x.Filter.ByIncludingOnly("StartsWith(@m, 'CSV WRITE:')"); + }); }); if (builder.Configuration.GetValue("ServerSettings:EnableMoreSongs")) diff --git a/TaikoLocalServer/TaikoLocalServer.csproj b/TaikoLocalServer/TaikoLocalServer.csproj index 3103980..f7fe243 100644 --- a/TaikoLocalServer/TaikoLocalServer.csproj +++ b/TaikoLocalServer/TaikoLocalServer.csproj @@ -25,6 +25,7 @@ +