Implement more dynamic parser stuff
This commit is contained in:
parent
7a6dccc26a
commit
e6154822f6
@ -5,10 +5,20 @@ namespace IW4MAdmin.Application.EventParsers
|
||||
class DynamicEventParserConfiguration : IEventParserConfiguration
|
||||
{
|
||||
public string GameDirectory { get; set; }
|
||||
public string SayRegex { get; set; }
|
||||
public string JoinRegex { get; set; }
|
||||
public string QuitRegex { get; set; }
|
||||
public string KillRegex { get; set; }
|
||||
public string DamageRegex { get; set; }
|
||||
|
||||
public ParserRegex Say { get; set; }
|
||||
public ParserRegex Join { get; set; }
|
||||
public ParserRegex Quit { get; set; }
|
||||
public ParserRegex Kill { get; set; }
|
||||
public ParserRegex Damage { get; set; }
|
||||
|
||||
public DynamicEventParserConfiguration()
|
||||
{
|
||||
Say = new ParserRegex();
|
||||
Join = new ParserRegex();
|
||||
Quit = new ParserRegex();
|
||||
Kill = new ParserRegex();
|
||||
Damage = new ParserRegex();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -16,11 +16,56 @@ namespace IW4MAdmin.Application.EventParsers
|
||||
_configuration = new DynamicEventParserConfiguration()
|
||||
{
|
||||
GameDirectory = "userraw",
|
||||
SayRegex = "(say|sayteam);(.{1,32});([0-9]+)(.*);(.*)",
|
||||
QuitRegex = @"^(Q;)(.{1,32});([0-9]+);(.*)$",
|
||||
JoinRegex = @"^(J;)(.{1,32});([0-9]+);(.*)$",
|
||||
DamageRegex = @"^(D);((?:bot[0-9]+)|(?:[A-Z]|[0-9])+);([0-9]+);(axis|allies);(.+);((?:[A-Z]|[0-9])+);([0-9]+);(axis|allies);(.+);((?:[0-9]+|[a-z]+|_)+);([0-9]+);((?:[A-Z]|_)+);((?:[a-z]|_)+)$"
|
||||
};
|
||||
|
||||
_configuration.Say.Pattern = @"^(say|sayteam);(.{1,32});([0-9]+)(.*);(.*)$";
|
||||
_configuration.Say.GroupMapping.Add(ParserRegex.GroupType.EventType, 1);
|
||||
_configuration.Say.GroupMapping.Add(ParserRegex.GroupType.OriginNetworkId, 2);
|
||||
_configuration.Say.GroupMapping.Add(ParserRegex.GroupType.OriginClientNumber, 3);
|
||||
_configuration.Say.GroupMapping.Add(ParserRegex.GroupType.OriginName, 4);
|
||||
_configuration.Say.GroupMapping.Add(ParserRegex.GroupType.Message, 5);
|
||||
|
||||
_configuration.Quit.Pattern = @"^(Q);(.{16,32}|bot[0-9]+);([0-9]+);(.*)$";
|
||||
_configuration.Quit.GroupMapping.Add(ParserRegex.GroupType.EventType, 1);
|
||||
_configuration.Quit.GroupMapping.Add(ParserRegex.GroupType.OriginNetworkId, 2);
|
||||
_configuration.Quit.GroupMapping.Add(ParserRegex.GroupType.OriginClientNumber, 3);
|
||||
_configuration.Quit.GroupMapping.Add(ParserRegex.GroupType.OriginName, 4);
|
||||
|
||||
_configuration.Join.Pattern = @"^(J);(.{16,32}|bot[0-9]+);([0-9]+);(.*)$";
|
||||
_configuration.Join.GroupMapping.Add(ParserRegex.GroupType.EventType, 1);
|
||||
_configuration.Join.GroupMapping.Add(ParserRegex.GroupType.OriginNetworkId, 2);
|
||||
_configuration.Join.GroupMapping.Add(ParserRegex.GroupType.OriginClientNumber, 3);
|
||||
_configuration.Join.GroupMapping.Add(ParserRegex.GroupType.OriginName, 4);
|
||||
|
||||
_configuration.Damage.Pattern = @"^(D);([A-Fa-f0-9_]{16,32}|bot[0-9]+);(-?[0-9]+);(axis|allies|world);(.{1,24});([A-Fa-f0-9_]{16,32}|bot[0-9]+)?;-?([0-9]+);(axis|allies|world);(.{1,24})?;((?:[0-9]+|[a-z]+|_)+);([0-9]+);((?:[A-Z]|_)+);((?:[a-z]|_)+)$";
|
||||
_configuration.Damage.GroupMapping.Add(ParserRegex.GroupType.EventType, 1);
|
||||
_configuration.Damage.GroupMapping.Add(ParserRegex.GroupType.TargetNetworkId, 2);
|
||||
_configuration.Damage.GroupMapping.Add(ParserRegex.GroupType.TargetClientNumber, 3);
|
||||
_configuration.Damage.GroupMapping.Add(ParserRegex.GroupType.TargetTeam, 4);
|
||||
_configuration.Damage.GroupMapping.Add(ParserRegex.GroupType.TargetName, 5);
|
||||
_configuration.Damage.GroupMapping.Add(ParserRegex.GroupType.OriginNetworkId, 6);
|
||||
_configuration.Damage.GroupMapping.Add(ParserRegex.GroupType.OriginClientNumber, 7);
|
||||
_configuration.Damage.GroupMapping.Add(ParserRegex.GroupType.OriginTeam, 8);
|
||||
_configuration.Damage.GroupMapping.Add(ParserRegex.GroupType.OriginName, 9);
|
||||
_configuration.Damage.GroupMapping.Add(ParserRegex.GroupType.Weapon, 10);
|
||||
_configuration.Damage.GroupMapping.Add(ParserRegex.GroupType.Damage, 11);
|
||||
_configuration.Damage.GroupMapping.Add(ParserRegex.GroupType.MeansOfDeath, 12);
|
||||
_configuration.Damage.GroupMapping.Add(ParserRegex.GroupType.HitLocation, 13);
|
||||
|
||||
_configuration.Kill.Pattern = @"^(K);([A-Fa-f0-9_]{16,32}|bot[0-9]+);(-?[0-9]+);(axis|allies|world);(.{1,24});([A-Fa-f0-9_]{16,32}|bot[0-9]+)?;-?([0-9]+);(axis|allies|world);(.{1,24})?;((?:[0-9]+|[a-z]+|_)+);([0-9]+);((?:[A-Z]|_)+);((?:[a-z]|_)+)$";
|
||||
_configuration.Kill.GroupMapping.Add(ParserRegex.GroupType.EventType, 1);
|
||||
_configuration.Kill.GroupMapping.Add(ParserRegex.GroupType.TargetNetworkId, 2);
|
||||
_configuration.Kill.GroupMapping.Add(ParserRegex.GroupType.TargetClientNumber, 3);
|
||||
_configuration.Kill.GroupMapping.Add(ParserRegex.GroupType.TargetTeam, 4);
|
||||
_configuration.Kill.GroupMapping.Add(ParserRegex.GroupType.TargetName, 5);
|
||||
_configuration.Kill.GroupMapping.Add(ParserRegex.GroupType.OriginNetworkId, 6);
|
||||
_configuration.Kill.GroupMapping.Add(ParserRegex.GroupType.OriginClientNumber, 7);
|
||||
_configuration.Kill.GroupMapping.Add(ParserRegex.GroupType.OriginTeam, 8);
|
||||
_configuration.Kill.GroupMapping.Add(ParserRegex.GroupType.OriginName, 9);
|
||||
_configuration.Kill.GroupMapping.Add(ParserRegex.GroupType.Weapon, 10);
|
||||
_configuration.Kill.GroupMapping.Add(ParserRegex.GroupType.Damage, 11);
|
||||
_configuration.Kill.GroupMapping.Add(ParserRegex.GroupType.MeansOfDeath, 12);
|
||||
_configuration.Kill.GroupMapping.Add(ParserRegex.GroupType.HitLocation, 13);
|
||||
}
|
||||
|
||||
public IEventParserConfiguration Configuration { get => _configuration; set => _configuration = value; }
|
||||
@ -33,7 +78,8 @@ namespace IW4MAdmin.Application.EventParsers
|
||||
|
||||
if (eventType == "JoinTeam")
|
||||
{
|
||||
var origin = server.GetClientsAsList().FirstOrDefault(c => c.NetworkId == lineSplit[1].ConvertLong());
|
||||
var origin = server.GetClientsAsList()
|
||||
.FirstOrDefault(c => c.NetworkId == lineSplit[1].ConvertLong());
|
||||
|
||||
return new GameEvent()
|
||||
{
|
||||
@ -46,15 +92,18 @@ namespace IW4MAdmin.Application.EventParsers
|
||||
|
||||
if (eventType == "say" || eventType == "sayteam")
|
||||
{
|
||||
var matchResult = Regex.Match(logLine, _configuration.SayRegex);
|
||||
var matchResult = Regex.Match(logLine, _configuration.Say.Pattern);
|
||||
|
||||
if (matchResult.Success)
|
||||
{
|
||||
string message = matchResult.Groups[5].ToString()
|
||||
string message = matchResult
|
||||
.Groups[_configuration.Say.GroupMapping[ParserRegex.GroupType.Message]]
|
||||
.ToString()
|
||||
.Replace("\x15", "")
|
||||
.Trim();
|
||||
|
||||
var origin = server.GetClientsAsList().First(c => c.ClientNumber == Utilities.ClientIdFromString(lineSplit, 2));
|
||||
var origin = server.GetClientsAsList()
|
||||
.First(c => c.NetworkId == matchResult.Groups[_configuration.Say.GroupMapping[ParserRegex.GroupType.OriginNetworkId]].ToString().ConvertLong());
|
||||
|
||||
if (message[0] == '!' || message[0] == '@')
|
||||
{
|
||||
@ -83,8 +132,15 @@ namespace IW4MAdmin.Application.EventParsers
|
||||
{
|
||||
if (!server.CustomCallback)
|
||||
{
|
||||
var origin = server.GetClientsAsList().First(c => c.ClientNumber == Utilities.ClientIdFromString(lineSplit, 6));
|
||||
var target = server.GetClientsAsList().First(c => c.ClientNumber == Utilities.ClientIdFromString(lineSplit, 2));
|
||||
var match = Regex.Match(logLine, _configuration.Kill.Pattern);
|
||||
|
||||
if (match.Success)
|
||||
{
|
||||
var origin = server.GetClientsAsList()
|
||||
.First(c => c.NetworkId == match.Groups[_configuration.Kill.GroupMapping[ParserRegex.GroupType.OriginNetworkId]].ToString().ConvertLong());
|
||||
var target = server.GetClientsAsList()
|
||||
.First(c => c.NetworkId == match.Groups[_configuration.Kill.GroupMapping[ParserRegex.GroupType.TargetNetworkId]].ToString().ConvertLong());
|
||||
|
||||
|
||||
return new GameEvent()
|
||||
{
|
||||
@ -96,6 +152,7 @@ namespace IW4MAdmin.Application.EventParsers
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (eventType == "ScriptKill")
|
||||
{
|
||||
@ -129,12 +186,16 @@ namespace IW4MAdmin.Application.EventParsers
|
||||
// damage
|
||||
if (eventType == "D")
|
||||
{
|
||||
if (!server.CustomCallback)
|
||||
// if (!server.CustomCallback)
|
||||
{
|
||||
if (Regex.Match(eventType, _configuration.DamageRegex).Success)
|
||||
var regexMatch = Regex.Match(logLine, _configuration.Damage.Pattern);
|
||||
|
||||
if (regexMatch.Success)
|
||||
{
|
||||
var origin = server.GetClientsAsList().First(c => c.NetworkId == lineSplit[5].ConvertLong());
|
||||
var target = server.GetClientsAsList().First(c => c.NetworkId == lineSplit[1].ConvertLong());
|
||||
var origin = server.GetClientsAsList()
|
||||
.First(c => c.NetworkId == regexMatch.Groups[_configuration.Damage.GroupMapping[ParserRegex.GroupType.OriginNetworkId]].ToString().ConvertLong());
|
||||
var target = server.GetClientsAsList()
|
||||
.First(c => c.NetworkId == regexMatch.Groups[_configuration.Damage.GroupMapping[ParserRegex.GroupType.TargetNetworkId]].ToString().ConvertLong());
|
||||
|
||||
return new GameEvent()
|
||||
{
|
||||
@ -151,7 +212,7 @@ namespace IW4MAdmin.Application.EventParsers
|
||||
// join
|
||||
if (eventType == "J")
|
||||
{
|
||||
var regexMatch = Regex.Match(logLine, _configuration.JoinRegex);
|
||||
var regexMatch = Regex.Match(logLine, _configuration.Join.Pattern);
|
||||
if (regexMatch.Success)
|
||||
{
|
||||
return new GameEvent()
|
||||
@ -164,10 +225,10 @@ namespace IW4MAdmin.Application.EventParsers
|
||||
CurrentAlias = new EFAlias()
|
||||
{
|
||||
Active = false,
|
||||
Name = regexMatch.Groups[4].ToString().StripColors(),
|
||||
Name = regexMatch.Groups[_configuration.Join.GroupMapping[ParserRegex.GroupType.OriginName]].ToString().StripColors(),
|
||||
},
|
||||
NetworkId = regexMatch.Groups[2].ToString().ConvertLong(),
|
||||
ClientNumber = Convert.ToInt32(regexMatch.Groups[3].ToString()),
|
||||
NetworkId = regexMatch.Groups[_configuration.Join.GroupMapping[ParserRegex.GroupType.OriginNetworkId]].ToString().ConvertLong(),
|
||||
ClientNumber = Convert.ToInt32(regexMatch.Groups[_configuration.Join.GroupMapping[ParserRegex.GroupType.OriginClientNumber]].ToString()),
|
||||
State = EFClient.ClientState.Connecting,
|
||||
CurrentServer = server
|
||||
}
|
||||
@ -177,7 +238,7 @@ namespace IW4MAdmin.Application.EventParsers
|
||||
|
||||
if (eventType == "Q")
|
||||
{
|
||||
var regexMatch = Regex.Match(logLine, _configuration.QuitRegex);
|
||||
var regexMatch = Regex.Match(logLine, _configuration.Quit.Pattern);
|
||||
if (regexMatch.Success)
|
||||
{
|
||||
return new GameEvent()
|
||||
@ -190,10 +251,10 @@ namespace IW4MAdmin.Application.EventParsers
|
||||
CurrentAlias = new EFAlias()
|
||||
{
|
||||
Active = false,
|
||||
Name = regexMatch.Groups[4].ToString().StripColors()
|
||||
Name = regexMatch.Groups[_configuration.Quit.GroupMapping[ParserRegex.GroupType.OriginName]].ToString().StripColors()
|
||||
},
|
||||
NetworkId = regexMatch.Groups[2].ToString().ConvertLong(),
|
||||
ClientNumber = Convert.ToInt32(regexMatch.Groups[3].ToString()),
|
||||
NetworkId = regexMatch.Groups[_configuration.Quit.GroupMapping[ParserRegex.GroupType.OriginNetworkId]].ToString().ConvertLong(),
|
||||
ClientNumber = Convert.ToInt32(regexMatch.Groups[_configuration.Quit.GroupMapping[ParserRegex.GroupType.OriginClientNumber]].ToString()),
|
||||
State = EFClient.ClientState.Disconnecting
|
||||
}
|
||||
};
|
||||
|
@ -671,7 +671,7 @@ namespace IW4MAdmin
|
||||
|
||||
var version = await this.GetDvarAsync<string>("version");
|
||||
Version = version.Value;
|
||||
//GameName = Utilities.GetGame(version.Value);
|
||||
GameName = Utilities.GetGame(version.Value);
|
||||
|
||||
if (GameName == Game.IW4)
|
||||
{
|
||||
|
41
SharedLibraryCore/Helpers/ParserRegex.cs
Normal file
41
SharedLibraryCore/Helpers/ParserRegex.cs
Normal file
@ -0,0 +1,41 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace SharedLibraryCore.Interfaces
|
||||
{
|
||||
public sealed class ParserRegex
|
||||
{
|
||||
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,
|
||||
AdditionalGroup = 200
|
||||
}
|
||||
public string Pattern { get; set; }
|
||||
public Dictionary<GroupType, int> GroupMapping { get; private set; }
|
||||
|
||||
public ParserRegex()
|
||||
{
|
||||
GroupMapping = new Dictionary<GroupType, int>();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,16 +1,12 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace SharedLibraryCore.Interfaces
|
||||
namespace SharedLibraryCore.Interfaces
|
||||
{
|
||||
public interface IEventParserConfiguration
|
||||
{
|
||||
string GameDirectory { get; set; }
|
||||
string SayRegex { get; set; }
|
||||
string JoinRegex { get; set; }
|
||||
string QuitRegex { get; set; }
|
||||
string KillRegex { get; set; }
|
||||
string DamageRegex { get; set; }
|
||||
ParserRegex Say { get; set; }
|
||||
ParserRegex Join { get; set; }
|
||||
ParserRegex Quit { get; set; }
|
||||
ParserRegex Kill { get; set; }
|
||||
ParserRegex Damage { get; set; }
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user