IW4M-Admin/WebfrontCore/Controllers/ServerController.cs
RaidMax 06cdaef8a4 allow Kekno to run with sv_running not returning anything :upside_down:
make sure script plugins output correct errors instead of being swallowed
prevent webfront error when webfront tab is left open on a server no longer being modified
2020-02-01 12:27:14 -06:00

51 lines
1.5 KiB
C#

using Microsoft.AspNetCore.Mvc;
using SharedLibraryCore;
using SharedLibraryCore.Dtos;
using SharedLibraryCore.Interfaces;
using System.Linq;
namespace WebfrontCore.Controllers
{
public class ServerController : BaseController
{
public ServerController(IManager manager) : base(manager)
{
}
[HttpGet]
[ResponseCache(NoStore = true, Duration = 0)]
public IActionResult ClientActivity(long id)
{
var s = Manager.GetServers().FirstOrDefault(_server => _server.EndPoint == id);
if (s == null)
{
return NotFound();
}
var serverInfo = new ServerInfo()
{
Name = s.Hostname,
ID = s.EndPoint,
Port = s.Port,
Map = s.CurrentMap.Alias,
ClientCount = s.ClientNum,
MaxClients = s.MaxClients,
GameType = s.Gametype,
Players = s.GetClientsAsList()
.Select(p => new PlayerInfo
{
Name = p.Name,
ClientId = p.ClientId,
Level = p.Level.ToLocalizedLevelName(),
LevelInt = (int)p.Level
}).ToList(),
ChatHistory = s.ChatHistory.ToList(),
PlayerHistory = s.ClientHistory.ToArray()
};
return PartialView("_ClientActivity", serverInfo);
}
}
}