mirror of
https://github.com/JogmansonReal/Radicade.git
synced 2026-10-25 23:18:56 -07:00
Radicade Public Code
This commit is contained in:
@@ -0,0 +1,76 @@
|
||||
using Microsoft.AspNetCore.Cors;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using RadicadeServer.DB;
|
||||
using RadicadeServer.Utils;
|
||||
|
||||
namespace RadicadeServer.Admin
|
||||
{
|
||||
[Route("admin/status")]
|
||||
[EnableCors("AdminPanel")]
|
||||
public class AdminStatusAPI(RecDBContext db) : Controller
|
||||
{
|
||||
private Task<IActionResult?> RejectInvalidKey(string key)
|
||||
{
|
||||
return Task.FromResult<IActionResult?>(key.IsAdminKey() ? null : Unauthorized("Invalid secret"));
|
||||
}
|
||||
|
||||
[HttpGet("players/active")]
|
||||
public async Task<IActionResult> GetActivePlayerCount([FromQuery] string key)
|
||||
{
|
||||
var rejection = await RejectInvalidKey(key);
|
||||
if (rejection != null) return rejection;
|
||||
|
||||
var activePlayerCount = await db.Presences.CountAsync(x => x.isOnline);
|
||||
|
||||
return Ok(new
|
||||
{
|
||||
activePlayerCount
|
||||
});
|
||||
}
|
||||
|
||||
[HttpGet("")]
|
||||
public async Task<IActionResult> GetServerStatus([FromQuery] string key)
|
||||
{
|
||||
var rejection = await RejectInvalidKey(key);
|
||||
if (rejection != null) return rejection;
|
||||
|
||||
var activePlayerCount = await db.Presences.CountAsync(x => x.isOnline);
|
||||
var playersInRoomsCount = await db.Presences.CountAsync(x => x.isOnline && x.roomInstance != null);
|
||||
var activeRoomInstanceCount = await db.RoomInstances.CountAsync();
|
||||
var gameVersion = await db.ServerConfig
|
||||
.Where(x => x.Key == "GameVersion")
|
||||
.Select(x => x.Value)
|
||||
.FirstOrDefaultAsync() ?? DBConfig.GameVersion;
|
||||
var barrelVersion = await db.ServerConfig
|
||||
.Where(x => x.Key == "BarrelVersion")
|
||||
.Select(x => x.Value)
|
||||
.FirstOrDefaultAsync();
|
||||
var barrelKey = await db.ServerConfig
|
||||
.Where(x => x.Key == "BarrelKey")
|
||||
.Select(x => x.Value)
|
||||
.FirstOrDefaultAsync();
|
||||
var barrelCheck = await db.ServerConfig
|
||||
.Where(x => x.Key == "BarrelCheck")
|
||||
.Select(x => x.Value)
|
||||
.FirstOrDefaultAsync();
|
||||
var config = await db.Config.FirstOrDefaultAsync();
|
||||
|
||||
return Ok(new
|
||||
{
|
||||
status = "online",
|
||||
serverUrl = DBConfig.ServerUrl,
|
||||
activePlayerCount,
|
||||
playersInRoomsCount,
|
||||
activeRoomInstanceCount,
|
||||
gameVersion,
|
||||
barrelVersion,
|
||||
barrelKey,
|
||||
barrelCheck,
|
||||
maintenance = config?.ServerMaintenance,
|
||||
startedAtUtc = AdminRuntime.ServerStartedAtUtc,
|
||||
uptimeSeconds = (long)(DateTime.UtcNow - AdminRuntime.ServerStartedAtUtc).TotalSeconds
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user