2018-02-21 20:29:23 -05:00
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
2018-08-03 22:11:58 -04:00
|
|
|
|
using SharedLibraryCore;
|
2018-04-08 02:44:42 -04:00
|
|
|
|
using SharedLibraryCore.Dtos;
|
2018-02-21 20:29:23 -05:00
|
|
|
|
using System.Linq;
|
2019-04-08 13:29:48 -04:00
|
|
|
|
using System.Net;
|
2018-02-21 20:29:23 -05:00
|
|
|
|
|
|
|
|
|
namespace WebfrontCore.ViewComponents
|
|
|
|
|
{
|
|
|
|
|
public class ServerListViewComponent : ViewComponent
|
|
|
|
|
{
|
|
|
|
|
public IViewComponentResult Invoke()
|
|
|
|
|
{
|
2018-04-08 14:48:40 -04:00
|
|
|
|
var servers = Program.Manager.GetServers();
|
2019-04-08 13:29:48 -04:00
|
|
|
|
|
2018-02-21 20:29:23 -05:00
|
|
|
|
var serverInfo = servers.Select(s => new ServerInfo()
|
|
|
|
|
{
|
|
|
|
|
Name = s.Hostname,
|
2018-11-27 19:31:48 -05:00
|
|
|
|
ID = s.EndPoint,
|
2018-02-21 20:29:23 -05:00
|
|
|
|
Port = s.GetPort(),
|
|
|
|
|
Map = s.CurrentMap.Alias,
|
|
|
|
|
ClientCount = s.ClientNum,
|
|
|
|
|
MaxClients = s.MaxClients,
|
|
|
|
|
GameType = s.Gametype,
|
2018-11-05 22:01:29 -05:00
|
|
|
|
PlayerHistory = s.ClientHistory.ToArray(),
|
|
|
|
|
Players = s.GetClientsAsList()
|
2018-02-21 20:29:23 -05:00
|
|
|
|
.Select(p => new PlayerInfo()
|
|
|
|
|
{
|
|
|
|
|
Name = p.Name,
|
2018-03-29 00:40:57 -04:00
|
|
|
|
ClientId = p.ClientId,
|
2018-08-03 22:11:58 -04:00
|
|
|
|
Level = p.Level.ToLocalizedLevelName(),
|
2018-04-02 01:25:06 -04:00
|
|
|
|
LevelInt = (int)p.Level
|
2018-02-21 20:29:23 -05:00
|
|
|
|
}).ToList(),
|
2019-01-28 19:21:56 -05:00
|
|
|
|
ChatHistory = s.ChatHistory.ToList(),
|
2019-04-07 21:14:59 -04:00
|
|
|
|
Online = !s.Throttled,
|
2019-04-08 13:29:48 -04:00
|
|
|
|
IPAddress = $"{(IPAddress.Parse(s.IP).IsInternal() ? Program.Manager.ExternalIPAddress : s.IP)}:{s.GetPort()}",
|
|
|
|
|
ConnectProtocolUrl = s.EventParser.URLProtocolFormat.FormatExt(IPAddress.Parse(s.IP).IsInternal() ? Program.Manager.ExternalIPAddress : s.IP, s.GetPort())
|
2018-02-21 20:29:23 -05:00
|
|
|
|
}).ToList();
|
|
|
|
|
return View("_List", serverInfo);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|