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,
MaxClientNum = s.MaxClients,
Id = s.EndPoint,
Port = (short)s.GetPort(),
Port = (short)s.Port,
IPAddress = s.IP
}).ToList()
};

View File

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

View File

@ -9,15 +9,15 @@ namespace IW4MAdmin.Application
{
class GameEventHandler : IEventHandler
{
readonly IManager Manager;
readonly ApplicationManager Manager;
public GameEventHandler(IManager mgr)
{
Manager = mgr;
Manager = (ApplicationManager)mgr;
}
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 GameLogEventDetection LogEvent;
private DateTime SessionStart;
public int Id { get; private set; }
@ -211,7 +210,7 @@ namespace IW4MAdmin
return false;
}
CONNECT:
//CONNECT:
if (Clients[E.Origin.ClientNumber] == null)
{
#if DEBUG == true
@ -250,8 +249,8 @@ namespace IW4MAdmin
else
{
Logger.WriteWarning($"{E.Origin} is connecting but {Clients[E.Origin.ClientNumber]} is currently in that client slot");
await OnClientDisconnected(Clients[E.Origin.ClientNumber]);
goto CONNECT;
//await OnClientDisconnected(Clients[E.Origin.ClientNumber]);
//goto CONNECT;
}
}
@ -457,7 +456,6 @@ namespace IW4MAdmin
if (E.Type == GameEvent.EventType.MapEnd)
{
Logger.WriteInfo("Game ending...");
SessionStart = DateTime.UtcNow;
}
if (E.Type == GameEvent.EventType.Tell)

View File

@ -202,28 +202,33 @@ namespace IW4MAdmin.Application
string lastCommand;
var Origin = Utilities.IW4MAdminClient(ServerManager.Servers[0]);
while (!ServerManager.CancellationToken.IsCancellationRequested)
try
{
lastCommand = Console.ReadLine();
if (lastCommand?.Length > 0)
while (!ServerManager.CancellationToken.IsCancellationRequested)
{
lastCommand = Console.ReadLine();
if (lastCommand?.Length > 0)
{
GameEvent E = new GameEvent()
if (lastCommand?.Length > 0)
{
Type = GameEvent.EventType.Command,
Data = lastCommand,
Origin = Origin,
Owner = ServerManager.Servers[0]
};
GameEvent E = new GameEvent()
{
Type = GameEvent.EventType.Command,
Data = lastCommand,
Origin = Origin,
Owner = ServerManager.Servers[0]
};
ServerManager.GetEventHandler().AddEvent(E);
await E.WaitAsync(Utilities.DefaultCommandTimeout, ServerManager.CancellationToken);
Console.Write('>');
ServerManager.GetEventHandler().AddEvent(E);
await E.WaitAsync(Utilities.DefaultCommandTimeout, ServerManager.CancellationToken);
Console.Write('>');
}
}
}
}
catch (OperationCanceledException)
{ }
}
}
}

View File

@ -6,7 +6,7 @@ class LogReader(object):
def __init__(self):
self.log_file_sizes = {}
# (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):
# this removes old entries that are no longer valid

View File

@ -216,7 +216,7 @@ namespace IW4MAdmin.Plugins.Stats.Helpers
{
server = new EFServer()
{
Port = sv.GetPort(),
Port = sv.Port,
EndPoint = sv.ToString(),
ServerId = serverId,
GameName = sv.GameName
@ -1230,12 +1230,12 @@ namespace IW4MAdmin.Plugins.Stats.Helpers
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;
}
long id = HashCode.Combine(server.IP, server.GetPort());
long id = HashCode.Combine(server.IP, server.Port);
id = id < 0 ? Math.Abs(id) : id;
long? serverId;

View File

@ -1180,7 +1180,7 @@ namespace SharedLibraryCore.Commands
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;
}

View File

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

View File

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

View File

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

View File

@ -16,7 +16,7 @@ namespace WebfrontCore.ViewComponents
{
Name = s.Hostname,
ID = s.EndPoint,
Port = s.GetPort(),
Port = s.Port,
Map = s.CurrentMap.Alias,
ClientCount = s.ClientNum,
MaxClients = s.MaxClients,
@ -32,8 +32,8 @@ namespace WebfrontCore.ViewComponents
}).ToList(),
ChatHistory = s.ChatHistory.ToList(),
Online = !s.Throttled,
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())
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)
}).ToList();
return View("_List", serverInfo);
}