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;
|
2019-12-02 16:52:36 -05:00
|
|
|
|
using SharedLibraryCore.Interfaces;
|
2018-03-09 03:01:12 -05:00
|
|
|
|
using System.Linq;
|
|
|
|
|
|
|
|
|
|
namespace WebfrontCore.Controllers.API
|
|
|
|
|
{
|
2018-08-02 21:52:35 -04:00
|
|
|
|
public class ApiController : BaseController
|
2018-03-09 03:01:12 -05:00
|
|
|
|
{
|
2019-12-02 16:52:36 -05:00
|
|
|
|
public ApiController(IManager manager) : base(manager)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
2019-12-27 13:10:20 -05:00
|
|
|
|
|
2018-11-05 22:01:29 -05:00
|
|
|
|
public IActionResult Index()
|
|
|
|
|
{
|
|
|
|
|
return Ok($"IW4MAdmin API");
|
|
|
|
|
}
|
2018-08-02 21:52:35 -04:00
|
|
|
|
|
|
|
|
|
[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]
|
2019-08-28 14:45:53 -04:00
|
|
|
|
public IActionResult Status(long? id)
|
2018-08-02 21:52:35 -04:00
|
|
|
|
{
|
|
|
|
|
var serverInfo = Manager.GetServers()
|
|
|
|
|
.Select(server => new
|
|
|
|
|
{
|
2018-11-27 19:31:48 -05:00
|
|
|
|
Id = server.EndPoint,
|
2019-08-28 14:45:53 -04:00
|
|
|
|
IsOnline = !server.Throttled,
|
2018-08-02 21:52:35 -04:00
|
|
|
|
Name = server.Hostname,
|
|
|
|
|
MaxPlayers = server.MaxClients,
|
2018-11-05 22:01:29 -05:00
|
|
|
|
CurrentPlayers = server.GetClientsAsList().Count,
|
2018-08-02 21:52:35 -04:00
|
|
|
|
Map = server.CurrentMap,
|
|
|
|
|
GameMode = server.Gametype,
|
2019-08-28 14:45:53 -04:00
|
|
|
|
server.Port,
|
2018-08-02 21:52:35 -04:00
|
|
|
|
Game = server.GameName.ToString(),
|
2018-11-05 22:01:29 -05:00
|
|
|
|
Players = server.GetClientsAsList()
|
2018-08-02 21:52:35 -04:00
|
|
|
|
.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-09-07 23:29:42 -04:00
|
|
|
|
ConnectionTime = player.ConnectionLength,
|
2018-08-07 14:43:09 -04:00
|
|
|
|
Level = player.Level.ToLocalizedLevelName(),
|
2018-08-02 21:52:35 -04:00
|
|
|
|
})
|
|
|
|
|
});
|
|
|
|
|
|
2019-08-28 14:45:53 -04:00
|
|
|
|
if (id != null)
|
2018-08-02 21:52:35 -04:00
|
|
|
|
{
|
|
|
|
|
serverInfo = serverInfo.Where(server => server.Id == id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return Json(serverInfo);
|
|
|
|
|
}
|
2018-11-05 22:01:29 -05:00
|
|
|
|
|
|
|
|
|
[HttpGet]
|
|
|
|
|
public IActionResult RestartApproved()
|
|
|
|
|
{
|
|
|
|
|
var serverToRestart = Manager.GetServers().FirstOrDefault(_server => _server.RestartRequested);
|
|
|
|
|
|
|
|
|
|
if (serverToRestart != null)
|
|
|
|
|
{
|
|
|
|
|
serverToRestart.RestartRequested = false;
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-28 14:45:53 -04:00
|
|
|
|
return serverToRestart != null ?
|
2018-11-05 22:01:29 -05:00
|
|
|
|
(IActionResult)Json(new
|
|
|
|
|
{
|
2019-05-31 11:17:01 -04:00
|
|
|
|
port = serverToRestart.Port
|
2019-08-28 14:45:53 -04:00
|
|
|
|
}) :
|
2018-11-05 22:01:29 -05:00
|
|
|
|
Unauthorized();
|
|
|
|
|
}
|
2018-03-09 03:01:12 -05:00
|
|
|
|
}
|
|
|
|
|
}
|