IW4M-Admin/WebfrontCore/Controllers/API/APIController.cs
RaidMax bbade07646 add localized level names
intellisense suggestion junk
2018-08-03 21:11:58 -05:00

56 lines
1.8 KiB
C#

using Microsoft.AspNetCore.Mvc;
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 = Manager.GetEventApi().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 = (DateTime.UtcNow - player.ConnectionTime).TotalSeconds,
player.Level,
})
});
if (id != 0)
{
serverInfo = serverInfo.Where(server => server.Id == id);
}
return Json(serverInfo);
}
}
}