diff --git a/AmiyaBotPlayerRatingServer/Controllers/Game/GameHubController.cs b/AmiyaBotPlayerRatingServer/Controllers/Game/GameHubController.cs index def5e7d..b28388f 100644 --- a/AmiyaBotPlayerRatingServer/Controllers/Game/GameHubController.cs +++ b/AmiyaBotPlayerRatingServer/Controllers/Game/GameHubController.cs @@ -18,32 +18,6 @@ public class GameHubController( GameManager gameManager) : ControllerBase { -#pragma warning disable CS8618 - // ReSharper disable UnusedAutoPropertyAccessor.Global - public class SendNotificationModel - { - public string Message { get; set; } - public DateTime ExpiredAt { get; set; } - } - // ReSharper restore UnusedAutoPropertyAccessor.Global -#pragma warning restore CS8618 - - [Authorize(Roles = "管理员账户")] - [HttpPost("sendNotificationToAll")] - public async Task SendNotificationToAll([FromBody] SendNotificationModel model) - { - var not = new SystemNotification - { - Id = Guid.NewGuid(), - Message = model.Message, - ExpiredAt = model.ExpiredAt - }; - - dbContext.SystemNotifications.Add(not); - await dbContext.SaveChangesAsync(); - - return Ok(); - } private object GetGameReturnObj(GameLogic.Game game) { diff --git a/AmiyaBotPlayerRatingServer/Controllers/Game/GameServerController.cs b/AmiyaBotPlayerRatingServer/Controllers/Game/GameServerController.cs new file mode 100644 index 0000000..ff881d3 --- /dev/null +++ b/AmiyaBotPlayerRatingServer/Controllers/Game/GameServerController.cs @@ -0,0 +1,78 @@ +using AmiyaBotPlayerRatingServer.Data; +using AmiyaBotPlayerRatingServer.GameLogic; +using AmiyaBotPlayerRatingServer.Model; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Mvc; +using Microsoft.EntityFrameworkCore; + +namespace AmiyaBotPlayerRatingServer.Controllers.Game +{ + [ApiController] + [Route("api/gameHub")] + public class GameServerController( + PlayerRatingDatabaseContext dbContext, + IConfiguration configuration, + ArknightsMemoryCache memoryCache) + : ControllerBase + { +#pragma warning disable CS8618 + // ReSharper disable UnusedAutoPropertyAccessor.Global + public class SendNotificationModel + { + public string Message { get; set; } + public DateTime ExpiredAt { get; set; } + } + // ReSharper restore UnusedAutoPropertyAccessor.Global +#pragma warning restore CS8618 + + [AllowAnonymous] + [HttpGet("serverStatistics")] + public async Task GetServerStatistics() + { + var totalPlaying = await dbContext.GameInfos.Where(c => c.IsClosed != true).CountAsync(); + var totalGames = await dbContext.GameInfos.CountAsync(); + var validPlayers = await dbContext.ApplicationUserMinigameStatistics.CountAsync(); + + return Ok(new + { + GamesPlaying = totalPlaying, + GamesTotal = totalGames, + PlayersTotal = validPlayers + }); + } + + [Authorize(Roles = "管理员账户")] + [HttpPost("sendNotificationToAll")] + public async Task SendNotificationToAll([FromBody] SendNotificationModel model) + { + var not = new SystemNotification + { + Id = Guid.NewGuid(), + Message = model.Message, + ExpiredAt = model.ExpiredAt + }; + + dbContext.SystemNotifications.Add(not); + await dbContext.SaveChangesAsync(); + + return Ok(); + } + + [Authorize(Roles = "管理员账户")] + [HttpPost("refreshArknightsData")] + public async Task RefreshArknightsData() + { + + try + { + memoryCache.UpdateAssets(); + } + catch(Exception e) + { + return BadRequest(e.Message); + } + + return Ok(); + } + } +} diff --git a/AmiyaBotPlayerRatingServer/Data/ArknightsMemoryCache.cs b/AmiyaBotPlayerRatingServer/Data/ArknightsMemoryCache.cs index 8aee3dc..ef68fba 100644 --- a/AmiyaBotPlayerRatingServer/Data/ArknightsMemoryCache.cs +++ b/AmiyaBotPlayerRatingServer/Data/ArknightsMemoryCache.cs @@ -12,10 +12,10 @@ namespace AmiyaBotPlayerRatingServer.Data public class ArknightsMemoryCache { // abs path is /app/Resources - private readonly string _directoryPath = "Resources/amiya-bot-assets"; + private readonly string _directoryPath = "Resources/amiya-bot-assets/repo"; private readonly string _gitRepoUrl = "https://gitee.com/amiya-bot/amiya-bot-assets.git"; - private readonly string _zipFilePath = "Resources/amiya-bot-assets/gamedata.zip"; - private readonly string _extractPath = "Resources/amiya-bot-assets/gamedata"; + private readonly string _zipFilePath = "Resources/amiya-bot-assets/repo/gamedata.zip"; + private readonly string _extractPath = "Resources/amiya-bot-assets/repo/gamedata"; public class ArknightsOperator @@ -112,7 +112,6 @@ private void InitializeAssets() if (!Directory.Exists(_directoryPath)) { - //因为目标文件夹是NFSMount,因此不会有需要创建的情况,但是还是留着. Directory.CreateDirectory(_directoryPath); CloneRepo(); ExtractGameData();