RaidMax 9fdf4bad9c 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 ()
update the distribution for top stats elo
prevent game log file rotation from stopping event parsing
2020-04-01 14:11:56 -05:00

110 lines
3.3 KiB
C#

using System;
using System.Collections.Generic;
namespace SharedLibraryCore.Interfaces
{
public sealed class ParserRegex
{
/// <summary>
/// represents the logical mapping of information provided by
/// game logs, get status, and get dvar information
/// </summary>
public enum GroupType
{
EventType,
OriginNetworkId,
TargetNetworkId,
OriginClientNumber,
TargetClientNumber,
OriginName,
TargetName,
OriginTeam,
TargetTeam,
Weapon,
Damage,
MeansOfDeath,
HitLocation,
Message,
RConClientNumber = 100,
RConScore = 101,
RConPing = 102,
RConNetworkId = 103,
RConName = 104,
RConIpAddress = 105,
RConDvarName = 106,
RConDvarValue = 107,
RConDvarDefaultValue = 108,
RConDvarLatchedValue = 109,
RConDvarDomain = 110,
RConStatusMap = 111,
AdditionalGroup = 200
}
public IParserPatternMatcher PatternMatcher { get; private set; }
private string pattern;
/// <summary>
/// stores the regular expression groups that will be mapped to group types
/// </summary>
public string Pattern
{
get => pattern;
set
{
pattern = value;
PatternMatcher.Compile(value);
}
}
/// <summary>
/// stores the mapping from group type to group index in the regular expression
/// </summary>
public Dictionary<GroupType, int> GroupMapping { get; private set; }
/// <summary>
/// helper method to enable script parsers to app regex mapping
/// the first parameter specifies the group type contained in the regex pattern
/// the second parameter specifies the group index to retrieve in the matched regex pattern
/// </summary>
/// <param name="mapKey">group type</param>
/// <param name="mapValue">group index</param>
public void AddMapping(object mapKey, object mapValue)
{
if (int.TryParse(mapKey.ToString(), out int key) && int.TryParse(mapValue.ToString(), out int value))
{
if (GroupMapping.ContainsKey((GroupType)key))
{
GroupMapping[(GroupType)key] = value;
}
else
{
GroupMapping.Add((GroupType)key, value);
}
}
if (mapKey.GetType() == typeof(GroupType) && mapValue.GetType().ToString() == "System.Int32")
{
GroupType k = (GroupType)Enum.Parse(typeof(GroupType), mapKey.ToString());
int v = int.Parse(mapValue.ToString());
if (GroupMapping.ContainsKey(k))
{
GroupMapping[k] = v;
}
else
{
GroupMapping.Add(k, v);
}
}
}
public ParserRegex(IParserPatternMatcher pattern)
{
GroupMapping = new Dictionary<GroupType, int>();
PatternMatcher = pattern;
}
}
}