From 431fdb6f9e25dcb6fa50edae7289e0bdb3c999df Mon Sep 17 00:00:00 2001 From: Kyle873 Date: Sat, 25 May 2024 04:52:39 -0400 Subject: [PATCH] Make controllers async, handle /Index/version better, more version logging --- Elisa/Controllers/CommandController.cs | 2 +- Elisa/Controllers/IndexController.cs | 19 ++++++++++--------- Elisa/Program.cs | 12 ++++++++++-- Elisa/Utils/Time.cs | 19 +++++++++++++++++++ 4 files changed, 40 insertions(+), 12 deletions(-) create mode 100644 Elisa/Utils/Time.cs diff --git a/Elisa/Controllers/CommandController.cs b/Elisa/Controllers/CommandController.cs index 8275ab7..5cd3434 100644 --- a/Elisa/Controllers/CommandController.cs +++ b/Elisa/Controllers/CommandController.cs @@ -9,7 +9,7 @@ namespace Elisa.Controllers; public class CommandController : ControllerBase { [HttpGet("command")] - public IResult Command([FromQuery] string command) + public async Task Command([FromQuery] string command) { CommandHandlerFactory.HandleCommand(command); diff --git a/Elisa/Controllers/IndexController.cs b/Elisa/Controllers/IndexController.cs index 251af73..726f3e6 100644 --- a/Elisa/Controllers/IndexController.cs +++ b/Elisa/Controllers/IndexController.cs @@ -1,4 +1,5 @@ -using Microsoft.AspNetCore.Http; +using Elisa.Utils; +using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; namespace Elisa.Controllers; @@ -8,18 +9,18 @@ namespace Elisa.Controllers; public class IndexController : ControllerBase { [HttpGet("version")] - public IResult Version([FromQuery] string req_id) + public async Task Version([FromQuery] string req_idreturn) { return Results.Json(new { - now = "1716182820", - tomorrow_zero = "1716192000", - month_zero = 1714550400, - next_month_zero = 1717228800, + now = DateTime.Now.ToUnixSeconds(), + tomorrow_zero = Time.GetTomorrowZero(), + month_zero = Time.GetCurrentMonthZero(), + next_month_zero = Time.GetNextMonthZero(), timezone = "PST8PDT", - data_version = "d630eea53a1b869fa4d7d1479a3d09e7", - client_version = "30400", - ab_version = "2024051417", + data_version = Program.DataVersion, + client_version = Program.ClientVersion, + ab_version = Program.ABVersion, is_kick = "0", weekday = 1, authentication_url = $"http://realauth.ucenter.ppgame.com/authoriz.html?appid={0}&openid={1}&accounttype=1&language=zh" diff --git a/Elisa/Program.cs b/Elisa/Program.cs index da3c25e..e35b61d 100644 --- a/Elisa/Program.cs +++ b/Elisa/Program.cs @@ -3,6 +3,7 @@ using Elisa.Data; using Microsoft.Extensions.Configuration; using Serilog; using Serilog.Events; +using Serilog.Sinks.SystemConsole.Themes; using System.Diagnostics; using System.Reflection; @@ -10,6 +11,10 @@ namespace Elisa; internal static class Program { + public static string ClientVersion = 30400.ToString(); + public static string DataVersion = "d630eea53a1b869fa4d7d1479a3d09e7"; + public static string ABVersion = 2024051417.ToString(); + static IConfiguration config = null!; public static void Main(string[] args) @@ -18,6 +23,9 @@ internal static class Program SetupSerilog(); Log.Information($"Version {Assembly.GetEntryAssembly()?.GetCustomAttribute()?.InformationalVersion}"); + Log.Information($"Client Version: {ClientVersion}"); + Log.Information($"Data Version: {DataVersion}"); + Log.Information($"AB Version: {ABVersion}"); Log.Information($"Starting {Assembly.GetEntryAssembly()?.GetName().Name}..."); Stopwatch stopwatch = Stopwatch.StartNew(); @@ -26,7 +34,7 @@ internal static class Program Table.Load(); } stopwatch.Stop(); - Log.Information($"Done! loaded in {stopwatch.ElapsedMilliseconds}ms"); + Log.Information($"Done! Loaded in {stopwatch.ElapsedMilliseconds}ms"); Task.Run(GameServer.Start).Wait(); } @@ -54,7 +62,7 @@ internal static class Program } Log.Logger = new LoggerConfiguration() - .WriteTo.Console() + .WriteTo.Console(theme: AnsiConsoleTheme.Literate) .WriteTo.File(logFilePath, restrictedToMinimumLevel: LogEventLevel.Verbose, shared: true) .ReadFrom.Configuration(config) .CreateBootstrapLogger(); diff --git a/Elisa/Utils/Time.cs b/Elisa/Utils/Time.cs new file mode 100644 index 0000000..88697ec --- /dev/null +++ b/Elisa/Utils/Time.cs @@ -0,0 +1,19 @@ +namespace Elisa.Utils; + +internal static class DateTimeExtensions +{ + public static long ToUnixSeconds(this DateTime dateTime) + => (long)(dateTime - new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)).TotalSeconds; +} + +public static class Time +{ + public static long GetTomorrowZero() + => new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 0, 0, 0, DateTimeKind.Utc).AddDays(1).ToUnixSeconds(); + + public static long GetCurrentMonthZero() + => new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1, 0, 0, 0, DateTimeKind.Utc).ToUnixSeconds(); + + public static long GetNextMonthZero() + => new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1, 0, 0, 0, DateTimeKind.Utc).AddMonths(1).ToUnixSeconds(); +} \ No newline at end of file