46bdc2ac33
finally fixed threading issue (which actually had to do with IW4x log outputs being out of sync (not an issue with my code). What a lot of headache over something that wasn't my fault.
58 lines
1.9 KiB
C#
58 lines
1.9 KiB
C#
using Microsoft.AspNetCore.Mvc;
|
|
using SharedLibraryCore;
|
|
using SharedLibraryCore.Events;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace WebfrontCore.Controllers.API
|
|
{
|
|
public class ApiController : BaseController
|
|
{
|
|
public IActionResult Index() => Ok($"IW4MAdmin API");
|
|
|
|
[HttpGet]
|
|
public IActionResult Event(bool shouldConsume = true)
|
|
{
|
|
var events = EventApi.GetEvents(shouldConsume);
|
|
return Json(events);
|
|
}
|
|
|
|
[HttpGet]
|
|
public IActionResult Status(int id)
|
|
{
|
|
var serverInfo = Manager.GetServers()
|
|
.Select(server => new
|
|
{
|
|
Id = server.GetHashCode(),
|
|
Name = server.Hostname,
|
|
MaxPlayers = server.MaxClients,
|
|
CurrentPlayers = server.GetPlayersAsList().Count,
|
|
Map = server.CurrentMap,
|
|
GameMode = server.Gametype,
|
|
Port = server.GetPort(),
|
|
Game = server.GameName.ToString(),
|
|
Players = server.GetPlayersAsList()
|
|
.Select(player => new
|
|
{
|
|
player.Name,
|
|
player.Score,
|
|
player.Ping,
|
|
State = player.State.ToString(),
|
|
player.ClientNumber,
|
|
ConnectionTime = Math.Round((DateTime.UtcNow - player.ConnectionTime).TotalSeconds, 0),
|
|
Level = player.Level.ToLocalizedLevelName(),
|
|
})
|
|
});
|
|
|
|
if (id != 0)
|
|
{
|
|
serverInfo = serverInfo.Where(server => server.Id == id);
|
|
}
|
|
|
|
return Json(serverInfo);
|
|
}
|
|
}
|
|
}
|