Make controllers async, handle /Index/version better, more version logging

This commit is contained in:
Kyle873 2024-05-25 04:52:39 -04:00
parent 42c07d68d3
commit 431fdb6f9e
4 changed files with 40 additions and 12 deletions

View File

@ -9,7 +9,7 @@ namespace Elisa.Controllers;
public class CommandController : ControllerBase public class CommandController : ControllerBase
{ {
[HttpGet("command")] [HttpGet("command")]
public IResult Command([FromQuery] string command) public async Task<IResult> Command([FromQuery] string command)
{ {
CommandHandlerFactory.HandleCommand(command); CommandHandlerFactory.HandleCommand(command);

View File

@ -1,4 +1,5 @@
using Microsoft.AspNetCore.Http; using Elisa.Utils;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
namespace Elisa.Controllers; namespace Elisa.Controllers;
@ -8,18 +9,18 @@ namespace Elisa.Controllers;
public class IndexController : ControllerBase public class IndexController : ControllerBase
{ {
[HttpGet("version")] [HttpGet("version")]
public IResult Version([FromQuery] string req_id) public async Task<IResult> Version([FromQuery] string req_idreturn)
{ {
return Results.Json(new return Results.Json(new
{ {
now = "1716182820", now = DateTime.Now.ToUnixSeconds(),
tomorrow_zero = "1716192000", tomorrow_zero = Time.GetTomorrowZero(),
month_zero = 1714550400, month_zero = Time.GetCurrentMonthZero(),
next_month_zero = 1717228800, next_month_zero = Time.GetNextMonthZero(),
timezone = "PST8PDT", timezone = "PST8PDT",
data_version = "d630eea53a1b869fa4d7d1479a3d09e7", data_version = Program.DataVersion,
client_version = "30400", client_version = Program.ClientVersion,
ab_version = "2024051417", ab_version = Program.ABVersion,
is_kick = "0", is_kick = "0",
weekday = 1, weekday = 1,
authentication_url = $"http://realauth.ucenter.ppgame.com/authoriz.html?appid={0}&openid={1}&accounttype=1&language=zh" authentication_url = $"http://realauth.ucenter.ppgame.com/authoriz.html?appid={0}&openid={1}&accounttype=1&language=zh"

View File

@ -3,6 +3,7 @@ using Elisa.Data;
using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration;
using Serilog; using Serilog;
using Serilog.Events; using Serilog.Events;
using Serilog.Sinks.SystemConsole.Themes;
using System.Diagnostics; using System.Diagnostics;
using System.Reflection; using System.Reflection;
@ -10,6 +11,10 @@ namespace Elisa;
internal static class Program 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!; static IConfiguration config = null!;
public static void Main(string[] args) public static void Main(string[] args)
@ -18,6 +23,9 @@ internal static class Program
SetupSerilog(); SetupSerilog();
Log.Information($"Version {Assembly.GetEntryAssembly()?.GetCustomAttribute<AssemblyInformationalVersionAttribute>()?.InformationalVersion}"); Log.Information($"Version {Assembly.GetEntryAssembly()?.GetCustomAttribute<AssemblyInformationalVersionAttribute>()?.InformationalVersion}");
Log.Information($"Client Version: {ClientVersion}");
Log.Information($"Data Version: {DataVersion}");
Log.Information($"AB Version: {ABVersion}");
Log.Information($"Starting {Assembly.GetEntryAssembly()?.GetName().Name}..."); Log.Information($"Starting {Assembly.GetEntryAssembly()?.GetName().Name}...");
Stopwatch stopwatch = Stopwatch.StartNew(); Stopwatch stopwatch = Stopwatch.StartNew();
@ -26,7 +34,7 @@ internal static class Program
Table.Load(); Table.Load();
} }
stopwatch.Stop(); stopwatch.Stop();
Log.Information($"Done! loaded in {stopwatch.ElapsedMilliseconds}ms"); Log.Information($"Done! Loaded in {stopwatch.ElapsedMilliseconds}ms");
Task.Run(GameServer.Start).Wait(); Task.Run(GameServer.Start).Wait();
} }
@ -54,7 +62,7 @@ internal static class Program
} }
Log.Logger = new LoggerConfiguration() Log.Logger = new LoggerConfiguration()
.WriteTo.Console() .WriteTo.Console(theme: AnsiConsoleTheme.Literate)
.WriteTo.File(logFilePath, restrictedToMinimumLevel: LogEventLevel.Verbose, shared: true) .WriteTo.File(logFilePath, restrictedToMinimumLevel: LogEventLevel.Verbose, shared: true)
.ReadFrom.Configuration(config) .ReadFrom.Configuration(config)
.CreateBootstrapLogger(); .CreateBootstrapLogger();

19
Elisa/Utils/Time.cs Normal file
View File

@ -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();
}