2019-01-27 17:40:08 -05:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
|
|
|
|
namespace SharedLibraryCore.Interfaces
|
|
|
|
|
{
|
|
|
|
|
public sealed class ParserRegex
|
|
|
|
|
{
|
2019-02-02 20:40:37 -05:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// represents the logical mapping of information provided by
|
|
|
|
|
/// game logs, get status, and get dvar information
|
|
|
|
|
/// </summary>
|
2019-01-27 17:40:08 -05:00
|
|
|
|
public enum GroupType
|
|
|
|
|
{
|
2021-06-03 11:51:03 -04:00
|
|
|
|
EventType = 0,
|
|
|
|
|
OriginNetworkId = 1,
|
|
|
|
|
TargetNetworkId = 2,
|
|
|
|
|
OriginClientNumber = 3,
|
|
|
|
|
TargetClientNumber = 4,
|
|
|
|
|
OriginName = 5,
|
|
|
|
|
TargetName = 6,
|
|
|
|
|
OriginTeam = 7,
|
|
|
|
|
TargetTeam = 8,
|
|
|
|
|
Weapon = 9,
|
|
|
|
|
Damage = 10,
|
|
|
|
|
MeansOfDeath = 11,
|
|
|
|
|
HitLocation = 12,
|
|
|
|
|
Message = 13,
|
2019-01-27 17:40:08 -05:00
|
|
|
|
RConClientNumber = 100,
|
|
|
|
|
RConScore = 101,
|
|
|
|
|
RConPing = 102,
|
|
|
|
|
RConNetworkId = 103,
|
|
|
|
|
RConName = 104,
|
|
|
|
|
RConIpAddress = 105,
|
2019-02-01 20:49:25 -05:00
|
|
|
|
RConDvarName = 106,
|
|
|
|
|
RConDvarValue = 107,
|
|
|
|
|
RConDvarDefaultValue = 108,
|
|
|
|
|
RConDvarLatchedValue = 109,
|
|
|
|
|
RConDvarDomain = 110,
|
2019-11-18 15:02:35 -05:00
|
|
|
|
RConStatusMap = 111,
|
2020-08-05 10:30:02 -04:00
|
|
|
|
RConStatusGametype = 112,
|
2021-06-03 11:51:03 -04:00
|
|
|
|
RConStatusHostname = 113,
|
|
|
|
|
RConStatusMaxPlayers = 114,
|
2019-01-27 17:40:08 -05:00
|
|
|
|
AdditionalGroup = 200
|
|
|
|
|
}
|
2019-02-02 20:40:37 -05:00
|
|
|
|
|
2020-04-01 15:11:56 -04:00
|
|
|
|
public IParserPatternMatcher PatternMatcher { get; private set; }
|
|
|
|
|
|
|
|
|
|
private string pattern;
|
2019-02-02 20:40:37 -05:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// stores the regular expression groups that will be mapped to group types
|
|
|
|
|
/// </summary>
|
2020-04-01 15:11:56 -04:00
|
|
|
|
public string Pattern
|
|
|
|
|
{
|
|
|
|
|
get => pattern;
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
pattern = value;
|
|
|
|
|
PatternMatcher.Compile(value);
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-02-02 20:40:37 -05:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// stores the mapping from group type to group index in the regular expression
|
|
|
|
|
/// </summary>
|
2019-01-27 17:40:08 -05:00
|
|
|
|
public Dictionary<GroupType, int> GroupMapping { get; private set; }
|
|
|
|
|
|
2019-02-02 20:40:37 -05:00
|
|
|
|
/// <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>
|
2019-02-02 19:54:30 -05:00
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-02-02 21:19:24 -05:00
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-02-02 19:54:30 -05:00
|
|
|
|
}
|
|
|
|
|
|
2020-04-01 15:11:56 -04:00
|
|
|
|
public ParserRegex(IParserPatternMatcher pattern)
|
2019-01-27 17:40:08 -05:00
|
|
|
|
{
|
|
|
|
|
GroupMapping = new Dictionary<GroupType, int>();
|
2020-04-01 15:11:56 -04:00
|
|
|
|
PatternMatcher = pattern;
|
2019-01-27 17:40:08 -05:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|