IW4M-Admin/WebfrontCore/Controllers/API/APIController.cs
RaidMax a0fafe5797 cleaned up some namespace discrepancies
fixed the coloring for custom groups translation
add reserved slots
add webhook project to show notifications in discord
2018-08-07 13:43:09 -05:00

57 lines
1.8 KiB
C#

using Microsoft.AspNetCore.Mvc;
using SharedLibraryCore;
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 = 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);
}
}
}