2018-03-09 02:01:12 -06:00
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
2018-08-07 13:43:09 -05:00
|
|
|
|
using SharedLibraryCore;
|
2019-12-02 15:52:36 -06:00
|
|
|
|
using SharedLibraryCore.Interfaces;
|
2018-03-09 02:01:12 -06:00
|
|
|
|
using System.Linq;
|
|
|
|
|
|
2023-04-04 22:21:18 -05:00
|
|
|
|
namespace WebfrontCore.Controllers.API;
|
|
|
|
|
|
|
|
|
|
public class ApiController : BaseController
|
2018-03-09 02:01:12 -06:00
|
|
|
|
{
|
2023-04-04 22:21:18 -05:00
|
|
|
|
public ApiController(IManager manager) : base(manager)
|
2018-03-09 02:01:12 -06:00
|
|
|
|
{
|
2019-12-27 12:10:20 -06:00
|
|
|
|
|
2023-04-04 22:21:18 -05:00
|
|
|
|
}
|
2018-08-02 20:52:35 -05:00
|
|
|
|
|
2023-04-04 22:21:18 -05:00
|
|
|
|
public IActionResult Index()
|
|
|
|
|
{
|
|
|
|
|
return Ok("IW4MAdmin API");
|
|
|
|
|
}
|
2018-08-02 20:52:35 -05:00
|
|
|
|
|
2023-04-04 22:21:18 -05:00
|
|
|
|
[HttpGet]
|
|
|
|
|
public IActionResult Event()
|
|
|
|
|
{
|
|
|
|
|
return NotFound("This API endpoint is no longer supported");
|
|
|
|
|
}
|
2018-08-02 20:52:35 -05:00
|
|
|
|
|
2023-04-04 22:21:18 -05:00
|
|
|
|
[HttpGet]
|
|
|
|
|
public IActionResult Status(long? id)
|
|
|
|
|
{
|
|
|
|
|
var serverInfo = Manager.GetServers()
|
|
|
|
|
.Select(server => new
|
2018-08-02 20:52:35 -05:00
|
|
|
|
{
|
2023-04-04 22:21:18 -05:00
|
|
|
|
Id = server.EndPoint,
|
|
|
|
|
IsOnline = !server.Throttled,
|
|
|
|
|
Name = server.ServerName,
|
|
|
|
|
MaxPlayers = server.MaxClients,
|
|
|
|
|
CurrentPlayers = server.GetClientsAsList().Count,
|
|
|
|
|
Map = server.CurrentMap,
|
|
|
|
|
GameMode = server.Gametype,
|
|
|
|
|
server.ListenAddress,
|
|
|
|
|
server.ListenPort,
|
|
|
|
|
Game = server.GameName.ToString(),
|
|
|
|
|
Players = server.GetClientsAsList()
|
|
|
|
|
.Select(player => new
|
|
|
|
|
{
|
|
|
|
|
player.Name,
|
|
|
|
|
player.Score,
|
|
|
|
|
player.Ping,
|
|
|
|
|
State = player.State.ToString(),
|
|
|
|
|
player.ClientNumber,
|
|
|
|
|
ConnectionTime = player.ConnectionLength,
|
|
|
|
|
Level = player.Level.ToLocalizedLevelName(),
|
|
|
|
|
})
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (id != null)
|
2018-11-05 21:01:29 -06:00
|
|
|
|
{
|
2023-04-04 22:21:18 -05:00
|
|
|
|
serverInfo = serverInfo.Where(server => server.Id == id);
|
2018-11-05 21:01:29 -06:00
|
|
|
|
}
|
2023-04-04 22:21:18 -05:00
|
|
|
|
|
|
|
|
|
return Json(serverInfo);
|
2018-03-09 02:01:12 -06:00
|
|
|
|
}
|
|
|
|
|
}
|