1
0
mirror of https://github.com/RaidMax/IW4M-Admin.git synced 2025-06-10 15:20:48 -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

@ -20,6 +20,9 @@
</ItemGroup>
<ItemGroup>
<None Update="Files\GameEvents.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Files\T6Game.log">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>

View File

@ -0,0 +1,58 @@
using ApplicationTests.Fixtures;
using IW4MAdmin.Application.EventParsers;
using IW4MAdmin.Application.Factories;
using Microsoft.Extensions.DependencyInjection;
using Newtonsoft.Json;
using NUnit.Framework;
using SharedLibraryCore;
using SharedLibraryCore.Interfaces;
using System;
namespace ApplicationTests
{
[TestFixture]
public class BaseEventParserTests
{
private EventLogTest eventLogData;
private IServiceProvider serviceProvider;
[SetUp]
public void Setup()
{
eventLogData = JsonConvert.DeserializeObject<EventLogTest>(System.IO.File.ReadAllText("Files/GameEvents.json"));
serviceProvider = new ServiceCollection()
.AddSingleton<BaseEventParser>()
.AddTransient<IParserPatternMatcher, ParserPatternMatcher>()
.AddSingleton<IParserRegexFactory, ParserRegexFactory>()
.BuildServiceProvider();
}
[Test]
public void TestParsesAllEventData()
{
var eventParser = serviceProvider.GetService<BaseEventParser>();
void AssertMatch(GameEvent src, LogEvent expected)
{
Assert.AreEqual(expected.ExpectedEventType, src.Type);
Assert.AreEqual(expected.ExpectedData, src.Data);
Assert.AreEqual(expected.ExpectedMessage, src.Message);
Assert.AreEqual(expected.ExpectedTime, src.GameTime);
//Assert.AreEqual(expected.ExpectedOriginClientName, src.Origin?.Name);
Assert.AreEqual(expected.ExpectedOriginClientNumber, src.Origin?.ClientNumber);
Assert.AreEqual(expected.ExpectedOriginNetworkId, src.Origin?.NetworkId.ToString("X"));
//Assert.AreEqual(expected.ExpectedTargetClientName, src.Target?.Name);
Assert.AreEqual(expected.ExpectedTargetClientNumber, src.Target?.ClientNumber);
Assert.AreEqual(expected.ExpectedTargetNetworkId, src.Target?.NetworkId.ToString("X"));
}
foreach (var e in eventLogData.Events)
{
var parsedEvent = eventParser.GenerateGameEvent(e.EventLine);
AssertMatch(parsedEvent, e);
}
}
}
}

View File

@ -0,0 +1,47 @@
using FakeItEasy;
using IW4MAdmin.Application.RconParsers;
using NUnit.Framework;
using SharedLibraryCore.Interfaces;
namespace ApplicationTests
{
[TestFixture]
public class BaseRConParserTests
{
[Test]
public void SetDvarAsync_FormatStringType()
{
var parser = new BaseRConParser(A.Fake<IParserRegexFactory>());
var connection = A.Fake<IRConConnection>();
parser.SetDvarAsync(connection, "test", "test").Wait();
A.CallTo(() => connection.SendQueryAsync(SharedLibraryCore.RCon.StaticHelpers.QueryType.SET_DVAR, "test \"test\""))
.MustHaveHappened();
}
[Test]
public void SetDvarAsync_FormatEmptyStringTypeIncludesQuotes()
{
var parser = new BaseRConParser(A.Fake<IParserRegexFactory>());
var connection = A.Fake<IRConConnection>();
parser.SetDvarAsync(connection, "test", "").Wait();
A.CallTo(() => connection.SendQueryAsync(SharedLibraryCore.RCon.StaticHelpers.QueryType.SET_DVAR, "test \"\""))
.MustHaveHappened();
}
[Test]
public void SetDvarAsync_FormatsNonString()
{
var parser = new BaseRConParser(A.Fake<IParserRegexFactory>());
var connection = A.Fake<IRConConnection>();
parser.SetDvarAsync(connection, "test", 123).Wait();
A.CallTo(() => connection.SendQueryAsync(SharedLibraryCore.RCon.StaticHelpers.QueryType.SET_DVAR, "test 123"))
.MustHaveHappened();
}
}
}

View File

@ -0,0 +1,26 @@
using static SharedLibraryCore.GameEvent;
using static SharedLibraryCore.Server;
namespace ApplicationTests.Fixtures
{
class LogEvent
{
public Game Game { get; set; }
public string EventLine { get; set; }
public EventType ExpectedEventType { get; set; }
public string ExpectedData { get; set; }
public string ExpectedMessage { get; set; }
public string ExpectedOriginNetworkId { get; set; }
public int? ExpectedOriginClientNumber { get; set; }
public string ExpectedOriginClientName { get; set; }
public string ExpectedTargetNetworkId { get; set; }
public int? ExpectedTargetClientNumber { get; set; }
public string ExpectedTargetClientName { get; set; }
public int? ExpectedTime { get; set; }
}
class EventLogTest
{
public LogEvent[] Events { get; set; }
}
}

View File

@ -0,0 +1,42 @@
using FakeItEasy;
using IW4MAdmin.Application.IO;
using NUnit.Framework;
using SharedLibraryCore;
using SharedLibraryCore.Interfaces;
using System;
using System.Threading.Tasks;
namespace ApplicationTests
{
[TestFixture]
public class IOTests
{
[Test]
public async Task GameLogEventDetection_WorksAfterFileSizeReset()
{
var reader = A.Fake<IGameLogReader>();
var detect = new GameLogEventDetection(null, "", A.Fake<Uri>(), reader);
A.CallTo(() => reader.Length)
.Returns(100)
.Once()
.Then
.Returns(200)
.Once()
.Then
.Returns(10)
.Once()
.Then
.Returns(100);
for (int i = 0; i < 4; i++)
{
await detect.UpdateLogEvents();
}
A.CallTo(() => reader.ReadEventsFromLog(A<Server>.Ignored, A<long>.Ignored, A<long>.Ignored))
.MustHaveHappenedTwiceExactly();
}
}
}

View File

@ -35,7 +35,7 @@ namespace ApplicationTests
new SharedLibraryCore.Configuration.ServerConfiguration() { IPAddress = "127.0.0.1", Port = 28960 },
A.Fake<ITranslationLookup>(), A.Fake<IRConConnectionFactory>());
var parser = new BaseEventParser();
var parser = new BaseEventParser(A.Fake<IParserRegexFactory>());
parser.Configuration.GuidNumberStyle = System.Globalization.NumberStyles.Integer;
var log = System.IO.File.ReadAllLines("Files\\T6MapRotation.log");
@ -61,7 +61,7 @@ namespace ApplicationTests
new SharedLibraryCore.Configuration.ServerConfiguration() { IPAddress = "127.0.0.1", Port = 28960 },
A.Fake<ITranslationLookup>(), A.Fake<IRConConnectionFactory>());
var parser = new BaseEventParser();
var parser = new BaseEventParser(A.Fake<IParserRegexFactory>());
parser.Configuration.GuidNumberStyle = System.Globalization.NumberStyles.Integer;
var log = System.IO.File.ReadAllLines("Files\\T6Game.log");

View File

@ -56,7 +56,7 @@ namespace ApplicationTests
A.Fake<ITranslationLookup>(),
A.Fake<IRConConnectionFactory>());
var parser = new BaseEventParser();
var parser = new BaseEventParser(A.Fake<IParserRegexFactory>());
parser.Configuration.GuidNumberStyle = System.Globalization.NumberStyles.Integer;
var log = System.IO.File.ReadAllLines("Files\\T6GameStats.log");