IW4M-Admin/SharedLibraryCore/Helpers/ParserRegex.cs

82 lines
2.5 KiB
C#
Raw Normal View History

2019-01-27 17:40:08 -05:00
using System;
using System.Collections.Generic;
using System.Text;
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>
2019-01-27 17:40:08 -05:00
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,
2019-02-01 20:49:25 -05:00
RConDvarName = 106,
RConDvarValue = 107,
RConDvarDefaultValue = 108,
RConDvarLatchedValue = 109,
RConDvarDomain = 110,
2019-01-27 17:40:08 -05:00
AdditionalGroup = 200
}
/// <summary>
/// stores the regular expression groups that will be mapped to group types
/// </summary>
2019-01-27 17:40:08 -05:00
public string Pattern { get; set; }
/// <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; }
/// <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-01-27 17:40:08 -05:00
public ParserRegex()
{
GroupMapping = new Dictionary<GroupType, int>();
}
}
}