1
0
mirror of https://github.com/RaidMax/IW4M-Admin.git synced 2025-07-01 09:30:16 -05:00

fix for runaway regular expression on linux

explicitly set string dvars in quotes to allow setting empty dvars
allow piping in input from command line (#114)
update the distribution for top stats elo
prevent game log file rotation from stopping event parsing
This commit is contained in:
RaidMax
2020-04-01 14:11:56 -05:00
parent 87987f885d
commit d45d99454b
35 changed files with 504 additions and 124 deletions

View File

@ -6,12 +6,11 @@ using System.Threading.Tasks;
namespace IW4MAdmin.Application.IO
{
class GameLogEventDetection
public class GameLogEventDetection
{
private long previousFileSize;
private readonly Server _server;
private readonly IGameLogReader _reader;
private readonly string _gameLogFile;
private readonly bool _ignoreBots;
class EventState
@ -20,12 +19,13 @@ namespace IW4MAdmin.Application.IO
public string ServerId { get; set; }
}
public GameLogEventDetection(Server server, string gameLogPath, Uri gameLogServerUri)
public GameLogEventDetection(Server server, string gameLogPath, Uri gameLogServerUri, IGameLogReader reader = null)
{
_gameLogFile = gameLogPath;
_reader = gameLogServerUri != null ? new GameLogReaderHttp(gameLogServerUri, gameLogPath, server.EventParser) : _reader = new GameLogReader(gameLogPath, server.EventParser);
_reader = gameLogServerUri != null
? reader ?? new GameLogReaderHttp(gameLogServerUri, gameLogPath, server.EventParser)
: reader ?? new GameLogReader(gameLogPath, server.EventParser);
_server = server;
_ignoreBots = server.Manager.GetApplicationSettings().Configuration().IgnoreBots;
_ignoreBots = server?.Manager.GetApplicationSettings().Configuration().IgnoreBots ?? false;
}
public async Task PollForChanges()
@ -52,7 +52,7 @@ namespace IW4MAdmin.Application.IO
_server.Logger.WriteDebug("Stopped polling for changes");
}
private async Task UpdateLogEvents()
public async Task UpdateLogEvents()
{
long fileSize = _reader.Length;
@ -65,7 +65,10 @@ namespace IW4MAdmin.Application.IO
// this makes the http log get pulled
if (fileDiff < 1 && fileSize != -1)
{
previousFileSize = fileSize;
return;
}
var events = await _reader.ReadEventsFromLog(_server, fileDiff, previousFileSize);

View File

@ -24,7 +24,7 @@ namespace IW4MAdmin.Application.IO
_parser = parser;
}
public async Task<ICollection<GameEvent>> ReadEventsFromLog(Server server, long fileSizeDiff, long startPosition)
public async Task<IEnumerable<GameEvent>> ReadEventsFromLog(Server server, long fileSizeDiff, long startPosition)
{
// allocate the bytes for the new log lines
List<string> logLines = new List<string>();

View File

@ -16,27 +16,27 @@ namespace IW4MAdmin.Application.IO
/// </summary>
class GameLogReaderHttp : IGameLogReader
{
readonly IEventParser Parser;
readonly IGameLogServer Api;
private readonly IEventParser _eventParser;
private readonly IGameLogServer _logServerApi;
readonly string logPath;
private string lastKey = "next";
public GameLogReaderHttp(Uri gameLogServerUri, string logPath, IEventParser parser)
{
this.logPath = logPath.ToBase64UrlSafeString(); ;
Parser = parser;
Api = RestClient.For<IGameLogServer>(gameLogServerUri);
this.logPath = logPath.ToBase64UrlSafeString();
_eventParser = parser;
_logServerApi = RestClient.For<IGameLogServer>(gameLogServerUri);
}
public long Length => -1;
public int UpdateInterval => 500;
public async Task<ICollection<GameEvent>> ReadEventsFromLog(Server server, long fileSizeDiff, long startPosition)
public async Task<IEnumerable<GameEvent>> ReadEventsFromLog(Server server, long fileSizeDiff, long startPosition)
{
var events = new List<GameEvent>();
string b64Path = logPath;
var response = await Api.Log(b64Path, lastKey);
var response = await _logServerApi.Log(b64Path, lastKey);
lastKey = response.NextKey;
if (!response.Success && string.IsNullOrEmpty(lastKey))
@ -48,17 +48,17 @@ namespace IW4MAdmin.Application.IO
else if (!string.IsNullOrWhiteSpace(response.Data))
{
// parse each line
foreach (string eventLine in response.Data
.Split(Environment.NewLine)
.Where(_line => _line.Length > 0))
var lines = response.Data
.Split(Environment.NewLine)
.Where(_line => _line.Length > 0);
foreach (string eventLine in lines)
{
try
{
var gameEvent = Parser.GenerateGameEvent(eventLine);
// this trim end should hopefully fix the nasty runaway regex
var gameEvent = _eventParser.GenerateGameEvent(eventLine.TrimEnd('\r'));
events.Add(gameEvent);
#if DEBUG == true
server.Logger.WriteDebug($"Parsed event with id {gameEvent.Id} from http");
#endif
}
catch (Exception e)