2023-05-30 19:12:57 -04:00
|
|
|
|
using System.Collections.Generic;
|
2021-08-29 14:10:10 -04: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;
|
2022-06-04 10:58:30 -04:00
|
|
|
|
using Data.Models;
|
2021-06-30 10:57:07 -04:00
|
|
|
|
using Data.Models.Client.Stats;
|
2023-04-04 23:10:37 -04:00
|
|
|
|
using IW4MAdmin.Plugins.Stats.Helpers;
|
2021-08-29 14:10:10 -04:00
|
|
|
|
using SharedLibraryCore.Configuration;
|
2018-02-21 20:29:23 -05:00
|
|
|
|
|
|
|
|
|
namespace WebfrontCore.ViewComponents
|
|
|
|
|
{
|
|
|
|
|
public class ServerListViewComponent : ViewComponent
|
|
|
|
|
{
|
2022-03-29 17:42:53 -04:00
|
|
|
|
private readonly DefaultSettings _defaultSettings;
|
2021-08-29 14:10:10 -04:00
|
|
|
|
|
2023-05-30 19:12:57 -04:00
|
|
|
|
public ServerListViewComponent(DefaultSettings defaultSettings)
|
2021-08-29 14:10:10 -04:00
|
|
|
|
{
|
2022-03-29 17:42:53 -04:00
|
|
|
|
_defaultSettings = defaultSettings;
|
2021-08-29 14:10:10 -04:00
|
|
|
|
}
|
|
|
|
|
|
2023-04-19 20:55:33 -04:00
|
|
|
|
public IViewComponentResult Invoke(Reference.Game? game)
|
2018-02-21 20:29:23 -05:00
|
|
|
|
{
|
2022-03-29 17:42:53 -04:00
|
|
|
|
if (game.HasValue)
|
|
|
|
|
{
|
2023-04-19 20:55:33 -04:00
|
|
|
|
ViewBag.Maps = _defaultSettings.Maps?.FirstOrDefault(map => map.Game == (Server.Game)game)?.Maps
|
|
|
|
|
?.ToList() ?? new List<Map>();
|
2022-03-29 17:42:53 -04:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2023-04-19 20:55:33 -04:00
|
|
|
|
ViewBag.Maps = _defaultSettings.Maps?.SelectMany(maps => maps.Maps).ToList();
|
2022-03-29 17:42:53 -04:00
|
|
|
|
}
|
|
|
|
|
|
2023-04-19 20:55:33 -04:00
|
|
|
|
var servers = Program.Manager.GetServers()
|
|
|
|
|
.Where(server => game is null || server.GameName == (Server.Game)game);
|
2021-08-29 14:10:10 -04:00
|
|
|
|
|
|
|
|
|
var serverInfo = new List<ServerInfo>();
|
2019-04-08 13:29:48 -04:00
|
|
|
|
|
2021-08-29 14:10:10 -04:00
|
|
|
|
foreach (var server in servers)
|
2018-02-21 20:29:23 -05:00
|
|
|
|
{
|
2022-03-29 17:42:53 -04:00
|
|
|
|
serverInfo.Add(new ServerInfo
|
2021-08-29 14:10:10 -04:00
|
|
|
|
{
|
|
|
|
|
Name = server.Hostname,
|
|
|
|
|
ID = server.EndPoint,
|
2023-04-04 23:10:37 -04:00
|
|
|
|
Port = server.ListenPort,
|
|
|
|
|
Map = server.CurrentMap?.Alias,
|
2022-06-04 10:58:30 -04:00
|
|
|
|
Game = (Reference.Game)server.GameName,
|
2023-04-04 23:10:37 -04:00
|
|
|
|
ClientCount = server.ClientNum,
|
2021-08-29 14:10:10 -04:00
|
|
|
|
MaxClients = server.MaxClients,
|
2023-04-06 00:10:40 -04:00
|
|
|
|
PrivateClientSlots = server.PrivateClientSlots,
|
2021-11-28 11:17:56 -05:00
|
|
|
|
GameType = server.GametypeName,
|
2023-05-30 19:12:57 -04:00
|
|
|
|
ClientHistory = new ClientHistoryInfo(),
|
2021-08-29 14:10:10 -04:00
|
|
|
|
Players = server.GetClientsAsList()
|
2023-04-04 23:10:37 -04:00
|
|
|
|
.Select(client => new PlayerInfo
|
2021-08-29 14:10:10 -04:00
|
|
|
|
{
|
2023-04-04 23:10:37 -04:00
|
|
|
|
Name = client.Name,
|
|
|
|
|
ClientId = client.ClientId,
|
|
|
|
|
Level = client.Level.ToLocalizedLevelName(),
|
|
|
|
|
LevelInt = (int)client.Level,
|
|
|
|
|
Tag = client.Tag,
|
|
|
|
|
ZScore = client.GetAdditionalProperty<EFClientStatistics>(StatManager
|
2021-08-29 14:10:10 -04:00
|
|
|
|
.CLIENT_STATS_KEY)?.ZScore
|
|
|
|
|
}).ToList(),
|
|
|
|
|
ChatHistory = server.ChatHistory.ToList(),
|
|
|
|
|
Online = !server.Throttled,
|
2023-04-04 23:21:18 -04:00
|
|
|
|
IPAddress = server.ListenAddress,
|
|
|
|
|
ExternalIPAddress = server.ResolvedIpEndPoint.Address.IsInternal() ? Program.Manager.ExternalIPAddress : server.ListenAddress,
|
2021-08-29 14:10:10 -04:00
|
|
|
|
ConnectProtocolUrl = server.EventParser.URLProtocolFormat.FormatExt(
|
2023-04-04 23:21:18 -04:00
|
|
|
|
server.ResolvedIpEndPoint.Address.IsInternal() ? Program.Manager.ExternalIPAddress : server.ListenAddress,
|
2023-04-04 23:10:37 -04:00
|
|
|
|
server.ListenPort)
|
2021-08-29 14:10:10 -04:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2018-02-21 20:29:23 -05:00
|
|
|
|
return View("_List", serverInfo);
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-11-28 11:17:56 -05:00
|
|
|
|
}
|