IW4M-Admin/WebfrontCore/Controllers/ServerController.cs

42 lines
1.3 KiB
C#
Raw Normal View History

2018-02-21 20:29:23 -05:00
using Microsoft.AspNetCore.Mvc;
using SharedLibrary.Dtos;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace WebfrontCore.Controllers
{
2018-03-06 02:22:19 -05:00
public class ServerController : BaseController
2018-02-21 20:29:23 -05:00
{
[HttpGet]
[ResponseCache(NoStore = true, Duration = 0)]
2018-02-21 20:29:23 -05:00
public IActionResult ClientActivity(int id)
{
2018-03-06 02:22:19 -05:00
var s = Manager.GetServers().FirstOrDefault(s2 => s2.GetHashCode() == id);
2018-02-21 20:29:23 -05:00
if (s == null)
return View("Error", "Invalid server!");
var serverInfo = new ServerInfo()
{
Name = s.Hostname,
ID = s.GetHashCode(),
Port = s.GetPort(),
Map = s.CurrentMap.Alias,
ClientCount = s.ClientNum,
MaxClients = s.MaxClients,
GameType = s.Gametype,
Players = s.Players.Where(p => p != null).Select(p => new PlayerInfo
{
Name = p.Name,
ClientId = p.ClientId
}).ToList(),
ChatHistory = s.ChatHistory.OrderBy(c => c.Time).Take((int)Math.Ceiling(s.ClientNum / 2.0)).ToArray(),
2018-02-21 20:29:23 -05:00
PlayerHistory = s.PlayerHistory.ToArray()
};
return PartialView("_ClientActivity", serverInfo);
}
}
}