convert GetPort to auto property

don't force disconnect player if someone is "in" their spot
increase gamelogserver max time before purge
This commit is contained in:
RaidMax 2019-05-31 10:17:01 -05:00
parent 95d64df321
commit 163523d586
12 changed files with 48 additions and 53 deletions

View File

@ -47,7 +47,7 @@ namespace IW4MAdmin.Application.API.Master
Map = s.CurrentMap.Name, Map = s.CurrentMap.Name,
MaxClientNum = s.MaxClients, MaxClientNum = s.MaxClients,
Id = s.EndPoint, Id = s.EndPoint,
Port = (short)s.GetPort(), Port = (short)s.Port,
IPAddress = s.IP IPAddress = s.IP
}).ToList() }).ToList()
}; };

View File

@ -45,7 +45,7 @@ namespace IW4MAdmin.Application
public string ExternalIPAddress { get; private set; } public string ExternalIPAddress { get; private set; }
public bool IsRestartRequested { get; private set; } public bool IsRestartRequested { get; private set; }
static ApplicationManager Instance; static ApplicationManager Instance;
readonly List<AsyncStatus> TaskStatuses; private readonly List<AsyncStatus> _taskStatuses;
List<Command> Commands; List<Command> Commands;
readonly List<MessageToken> MessageTokens; readonly List<MessageToken> MessageTokens;
ClientService ClientSvc; ClientService ClientSvc;
@ -64,7 +64,7 @@ namespace IW4MAdmin.Application
{ {
_servers = new ConcurrentBag<Server>(); _servers = new ConcurrentBag<Server>();
Commands = new List<Command>(); Commands = new List<Command>();
TaskStatuses = new List<AsyncStatus>(); _taskStatuses = new List<AsyncStatus>();
MessageTokens = new List<MessageToken>(); MessageTokens = new List<MessageToken>();
ClientSvc = new ClientService(); ClientSvc = new ClientService();
AliasSvc = new AliasService(); AliasSvc = new AliasService();

View File

@ -9,15 +9,15 @@ namespace IW4MAdmin.Application
{ {
class GameEventHandler : IEventHandler class GameEventHandler : IEventHandler
{ {
readonly IManager Manager; readonly ApplicationManager Manager;
public GameEventHandler(IManager mgr) public GameEventHandler(IManager mgr)
{ {
Manager = mgr; Manager = (ApplicationManager)mgr;
} }
public void AddEvent(GameEvent gameEvent) public void AddEvent(GameEvent gameEvent)
{ {
((Manager as ApplicationManager).OnServerEvent)(this, new GameEventArgs(null, false, gameEvent)); Manager.OnServerEvent?.Invoke(gameEvent.Owner, new GameEventArgs(null, false, gameEvent));
} }
} }
} }

View File

@ -26,7 +26,6 @@ namespace IW4MAdmin
{ {
private static readonly Index loc = Utilities.CurrentLocalization.LocalizationIndex; private static readonly Index loc = Utilities.CurrentLocalization.LocalizationIndex;
private GameLogEventDetection LogEvent; private GameLogEventDetection LogEvent;
private DateTime SessionStart;
public int Id { get; private set; } public int Id { get; private set; }
@ -211,7 +210,7 @@ namespace IW4MAdmin
return false; return false;
} }
CONNECT: //CONNECT:
if (Clients[E.Origin.ClientNumber] == null) if (Clients[E.Origin.ClientNumber] == null)
{ {
#if DEBUG == true #if DEBUG == true
@ -250,8 +249,8 @@ namespace IW4MAdmin
else else
{ {
Logger.WriteWarning($"{E.Origin} is connecting but {Clients[E.Origin.ClientNumber]} is currently in that client slot"); Logger.WriteWarning($"{E.Origin} is connecting but {Clients[E.Origin.ClientNumber]} is currently in that client slot");
await OnClientDisconnected(Clients[E.Origin.ClientNumber]); //await OnClientDisconnected(Clients[E.Origin.ClientNumber]);
goto CONNECT; //goto CONNECT;
} }
} }
@ -457,7 +456,6 @@ namespace IW4MAdmin
if (E.Type == GameEvent.EventType.MapEnd) if (E.Type == GameEvent.EventType.MapEnd)
{ {
Logger.WriteInfo("Game ending..."); Logger.WriteInfo("Game ending...");
SessionStart = DateTime.UtcNow;
} }
if (E.Type == GameEvent.EventType.Tell) if (E.Type == GameEvent.EventType.Tell)

View File

@ -202,6 +202,8 @@ namespace IW4MAdmin.Application
string lastCommand; string lastCommand;
var Origin = Utilities.IW4MAdminClient(ServerManager.Servers[0]); var Origin = Utilities.IW4MAdminClient(ServerManager.Servers[0]);
try
{
while (!ServerManager.CancellationToken.IsCancellationRequested) while (!ServerManager.CancellationToken.IsCancellationRequested)
{ {
lastCommand = Console.ReadLine(); lastCommand = Console.ReadLine();
@ -225,5 +227,8 @@ namespace IW4MAdmin.Application
} }
} }
} }
catch (OperationCanceledException)
{ }
}
} }
} }

View File

@ -6,7 +6,7 @@ class LogReader(object):
def __init__(self): def __init__(self):
self.log_file_sizes = {} self.log_file_sizes = {}
# (if the time between checks is greater, ignore ) - in seconds # (if the time between checks is greater, ignore ) - in seconds
self.max_file_time_change = 30 self.max_file_time_change = 60
def read_file(self, path): def read_file(self, path):
# this removes old entries that are no longer valid # this removes old entries that are no longer valid

View File

@ -216,7 +216,7 @@ namespace IW4MAdmin.Plugins.Stats.Helpers
{ {
server = new EFServer() server = new EFServer()
{ {
Port = sv.GetPort(), Port = sv.Port,
EndPoint = sv.ToString(), EndPoint = sv.ToString(),
ServerId = serverId, ServerId = serverId,
GameName = sv.GameName GameName = sv.GameName
@ -1230,12 +1230,12 @@ namespace IW4MAdmin.Plugins.Stats.Helpers
public static async Task<long> GetIdForServer(Server server) public static async Task<long> GetIdForServer(Server server)
{ {
if ($"{server.IP}:{server.GetPort().ToString()}" == "66.150.121.184:28965") if ($"{server.IP}:{server.Port.ToString()}" == "66.150.121.184:28965")
{ {
return 886229536; return 886229536;
} }
long id = HashCode.Combine(server.IP, server.GetPort()); long id = HashCode.Combine(server.IP, server.Port);
id = id < 0 ? Math.Abs(id) : id; id = id < 0 ? Math.Abs(id) : id;
long? serverId; long? serverId;

View File

@ -1180,7 +1180,7 @@ namespace SharedLibraryCore.Commands
var regex = Regex.Match(cmdLine, @".*((?:\+set|\+) net_port) +([0-9]+).*"); var regex = Regex.Match(cmdLine, @".*((?:\+set|\+) net_port) +([0-9]+).*");
if (regex.Success && Int32.Parse(regex.Groups[2].Value) == E.Owner.GetPort()) if (regex.Success && Int32.Parse(regex.Groups[2].Value) == E.Owner.Port)
{ {
currentProcess = p; currentProcess = p;
} }

View File

@ -52,13 +52,10 @@ namespace SharedLibraryCore
public long EndPoint => Convert.ToInt64($"{IP.Replace(".", "")}{Port}"); public long EndPoint => Convert.ToInt64($"{IP.Replace(".", "")}{Port}");
//Returns current server port set by `net_port` -- *INT* /// <summary>
public int GetPort() /// Returns list of all current players
{ /// </summary>
return Port; /// <returns></returns>
}
//Returns list of all current players
public List<EFClient> GetClientsAsList() public List<EFClient> GetClientsAsList()
{ {
return Clients.FindAll(x => x != null && x.NetworkId != 0); return Clients.FindAll(x => x != null && x.NetworkId != 0);
@ -69,18 +66,18 @@ namespace SharedLibraryCore
/// </summary> /// </summary>
/// <param name="P">EFClient pulled from memory reading</param> /// <param name="P">EFClient pulled from memory reading</param>
/// <returns>True if player added sucessfully, false otherwise</returns> /// <returns>True if player added sucessfully, false otherwise</returns>
abstract public Task OnClientConnected(EFClient P); public abstract Task OnClientConnected(EFClient P);
/// <summary> /// <summary>
/// Remove player by client number /// Remove player by client number
/// </summary> /// </summary>
/// <param name="cNum">Client ID of player to be removed</param> /// <param name="cNum">Client ID of player to be removed</param>
/// <returns>true if removal succeded, false otherwise</returns> /// <returns>true if removal succeded, false otherwise</returns>
abstract public Task OnClientDisconnected(EFClient client); public abstract Task OnClientDisconnected(EFClient client);
/// <summary> /// <summary>
/// Get a player by name /// Get a player by name
/// todo: make this an extension
/// </summary> /// </summary>
/// <param name="pName">EFClient name to search for</param> /// <param name="pName">EFClient name to search for</param>
/// <returns>Matching player if found</returns> /// <returns>Matching player if found</returns>
@ -113,8 +110,8 @@ namespace SharedLibraryCore
/// </summary> /// </summary>
/// <param name="E">Event</param> /// <param name="E">Event</param>
/// <returns>True on sucess</returns> /// <returns>True on sucess</returns>
abstract protected Task<bool> ProcessEvent(GameEvent E); protected abstract Task<bool> ProcessEvent(GameEvent E);
abstract public Task ExecuteEvent(GameEvent E); public abstract Task ExecuteEvent(GameEvent E);
/// <summary> /// <summary>
/// Send a message to all players /// Send a message to all players
@ -233,11 +230,6 @@ namespace SharedLibraryCore
await this.ExecuteCommandAsync($"map {mapName}"); await this.ExecuteCommandAsync($"map {mapName}");
} }
public async Task LoadMap(Map newMap)
{
await this.ExecuteCommandAsync($"map {newMap.Name}");
}
/// <summary> /// <summary>
/// Initalize the macro variables /// Initalize the macro variables
/// </summary> /// </summary>
@ -323,7 +315,7 @@ namespace SharedLibraryCore
public string Version { get; protected set; } public string Version { get; protected set; }
public bool IsInitialized { get; set; } public bool IsInitialized { get; set; }
protected int Port; public int Port { get; private set; }
protected string FSGame; protected string FSGame;
protected int NextMessage; protected int NextMessage;
protected int ConnectionErrors; protected int ConnectionErrors;

View File

@ -31,7 +31,7 @@ namespace WebfrontCore.Controllers.API
CurrentPlayers = server.GetClientsAsList().Count, CurrentPlayers = server.GetClientsAsList().Count,
Map = server.CurrentMap, Map = server.CurrentMap,
GameMode = server.Gametype, GameMode = server.Gametype,
Port = server.GetPort(), Port = server.Port,
Game = server.GameName.ToString(), Game = server.GameName.ToString(),
Players = server.GetClientsAsList() Players = server.GetClientsAsList()
.Select(player => new .Select(player => new
@ -67,7 +67,7 @@ namespace WebfrontCore.Controllers.API
return serverToRestart != null ? return serverToRestart != null ?
(IActionResult)Json(new (IActionResult)Json(new
{ {
port = serverToRestart.GetPort() port = serverToRestart.Port
}) : }) :
Unauthorized(); Unauthorized();
} }

View File

@ -22,7 +22,7 @@ namespace WebfrontCore.Controllers
{ {
Name = s.Hostname, Name = s.Hostname,
ID = s.EndPoint, ID = s.EndPoint,
Port = s.GetPort(), Port = s.Port,
Map = s.CurrentMap.Alias, Map = s.CurrentMap.Alias,
ClientCount = s.ClientNum, ClientCount = s.ClientNum,
MaxClients = s.MaxClients, MaxClients = s.MaxClients,

View File

@ -16,7 +16,7 @@ namespace WebfrontCore.ViewComponents
{ {
Name = s.Hostname, Name = s.Hostname,
ID = s.EndPoint, ID = s.EndPoint,
Port = s.GetPort(), Port = s.Port,
Map = s.CurrentMap.Alias, Map = s.CurrentMap.Alias,
ClientCount = s.ClientNum, ClientCount = s.ClientNum,
MaxClients = s.MaxClients, MaxClients = s.MaxClients,
@ -32,8 +32,8 @@ namespace WebfrontCore.ViewComponents
}).ToList(), }).ToList(),
ChatHistory = s.ChatHistory.ToList(), ChatHistory = s.ChatHistory.ToList(),
Online = !s.Throttled, Online = !s.Throttled,
IPAddress = $"{(IPAddress.Parse(s.IP).IsInternal() ? Program.Manager.ExternalIPAddress : s.IP)}:{s.GetPort()}", 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.GetPort()) ConnectProtocolUrl = s.EventParser.URLProtocolFormat.FormatExt(IPAddress.Parse(s.IP).IsInternal() ? Program.Manager.ExternalIPAddress : s.IP, s.Port)
}).ToList(); }).ToList();
return View("_List", serverInfo); return View("_List", serverInfo);
} }