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;
|
2020-04-13 21:26:13 -04:00
|
|
|
|
using static SharedLibraryCore.Server;
|
2018-02-21 20:29:23 -05:00
|
|
|
|
|
|
|
|
|
namespace WebfrontCore.ViewComponents
|
|
|
|
|
{
|
|
|
|
|
public class ServerListViewComponent : ViewComponent
|
|
|
|
|
{
|
2020-04-13 21:26:13 -04:00
|
|
|
|
public IViewComponentResult Invoke(Game? game)
|
2018-02-21 20:29:23 -05:00
|
|
|
|
{
|
2020-04-13 21:26:13 -04:00
|
|
|
|
var servers = Program.Manager.GetServers().Where(_server => !game.HasValue ? true : _server.GameName == game);
|
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,
|
2019-05-31 11:17:01 -04:00
|
|
|
|
Port = s.Port,
|
2018-02-21 20:29:23 -05:00
|
|
|
|
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(),
|
2021-01-24 12:47:19 -05:00
|
|
|
|
LevelInt = (int)p.Level,
|
|
|
|
|
Tag = p.Tag
|
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-05-31 11:17:01 -04:00
|
|
|
|
IPAddress = $"{(IPAddress.Parse(s.IP).IsInternal() ? Program.Manager.ExternalIPAddress : s.IP)}:{s.Port}",
|
|
|
|
|
ConnectProtocolUrl = s.EventParser.URLProtocolFormat.FormatExt(IPAddress.Parse(s.IP).IsInternal() ? Program.Manager.ExternalIPAddress : s.IP, s.Port)
|
2018-02-21 20:29:23 -05:00
|
|
|
|
}).ToList();
|
|
|
|
|
return View("_List", serverInfo);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|