2018-03-09 03:01:12 -05:00
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
2018-08-07 14:43:09 -04:00
|
|
|
|
using SharedLibraryCore;
|
2018-08-30 21:53:00 -04:00
|
|
|
|
using SharedLibraryCore.Events;
|
2018-03-09 03:01:12 -05:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace WebfrontCore.Controllers.API
|
|
|
|
|
{
|
2018-08-02 21:52:35 -04:00
|
|
|
|
public class ApiController : BaseController
|
2018-03-09 03:01:12 -05:00
|
|
|
|
{
|
2018-08-02 21:52:35 -04:00
|
|
|
|
public IActionResult Index() => Ok($"IW4MAdmin API");
|
|
|
|
|
|
|
|
|
|
[HttpGet]
|
|
|
|
|
public IActionResult Event(bool shouldConsume = true)
|
|
|
|
|
{
|
2018-08-30 21:53:00 -04:00
|
|
|
|
var events = EventApi.GetEvents(shouldConsume);
|
2018-08-02 21:52:35 -04:00
|
|
|
|
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,
|
2018-08-03 22:11:58 -04:00
|
|
|
|
State = player.State.ToString(),
|
2018-08-02 21:52:35 -04:00
|
|
|
|
player.ClientNumber,
|
2018-08-07 14:43:09 -04:00
|
|
|
|
ConnectionTime = Math.Round((DateTime.UtcNow - player.ConnectionTime).TotalSeconds, 0),
|
|
|
|
|
Level = player.Level.ToLocalizedLevelName(),
|
2018-08-02 21:52:35 -04:00
|
|
|
|
})
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (id != 0)
|
|
|
|
|
{
|
|
|
|
|
serverInfo = serverInfo.Where(server => server.Id == id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return Json(serverInfo);
|
|
|
|
|
}
|
2018-03-09 03:01:12 -05:00
|
|
|
|
}
|
|
|
|
|
}
|