2018-03-09 03:01:12 -05:00
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
2018-08-07 14:43:09 -04:00
|
|
|
|
using SharedLibraryCore;
|
2019-12-02 16:52:36 -05:00
|
|
|
|
using SharedLibraryCore.Interfaces;
|
2018-03-09 03:01:12 -05:00
|
|
|
|
using System.Linq;
|
|
|
|
|
|
2023-04-04 23:21:18 -04:00
|
|
|
|
namespace WebfrontCore.Controllers.API;
|
|
|
|
|
|
|
|
|
|
public class ApiController : BaseController
|
2018-03-09 03:01:12 -05:00
|
|
|
|
{
|
2023-04-04 23:21:18 -04:00
|
|
|
|
public ApiController(IManager manager) : base(manager)
|
2018-03-09 03:01:12 -05:00
|
|
|
|
{
|
2019-12-27 13:10:20 -05:00
|
|
|
|
|
2023-04-04 23:21:18 -04:00
|
|
|
|
}
|
2018-08-02 21:52:35 -04:00
|
|
|
|
|
2023-04-04 23:21:18 -04:00
|
|
|
|
public IActionResult Index()
|
|
|
|
|
{
|
|
|
|
|
return Ok("IW4MAdmin API");
|
|
|
|
|
}
|
2018-08-02 21:52:35 -04:00
|
|
|
|
|
2023-04-04 23:21:18 -04:00
|
|
|
|
[HttpGet]
|
|
|
|
|
public IActionResult Event()
|
|
|
|
|
{
|
|
|
|
|
return NotFound("This API endpoint is no longer supported");
|
|
|
|
|
}
|
2018-08-02 21:52:35 -04:00
|
|
|
|
|
2023-04-04 23:21:18 -04:00
|
|
|
|
[HttpGet]
|
|
|
|
|
public IActionResult Status(long? id)
|
|
|
|
|
{
|
|
|
|
|
var serverInfo = Manager.GetServers()
|
|
|
|
|
.Select(server => new
|
2018-08-02 21:52:35 -04:00
|
|
|
|
{
|
2023-04-04 23:21:18 -04: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 22:01:29 -05:00
|
|
|
|
{
|
2023-04-04 23:21:18 -04:00
|
|
|
|
serverInfo = serverInfo.Where(server => server.Id == id);
|
2018-11-05 22:01:29 -05:00
|
|
|
|
}
|
2023-04-04 23:21:18 -04:00
|
|
|
|
|
|
|
|
|
return Json(serverInfo);
|
2018-03-09 03:01:12 -05:00
|
|
|
|
}
|
|
|
|
|
}
|