-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
81 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
AmiyaBotPlayerRatingServer/Controllers/Game/GameServerController.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<IActionResult> 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<IActionResult> 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<IActionResult> RefreshArknightsData() | ||
Check warning on line 63 in AmiyaBotPlayerRatingServer/Controllers/Game/GameServerController.cs GitHub Actions / build
|
||
{ | ||
|
||
try | ||
{ | ||
memoryCache.UpdateAssets(); | ||
} | ||
catch(Exception e) | ||
{ | ||
return BadRequest(e.Message); | ||
} | ||
|
||
return Ok(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters