2018-11-25 21:00:36 -05:00
|
|
|
|
using SharedLibraryCore;
|
2020-07-31 21:40:03 -04:00
|
|
|
|
using SharedLibraryCore.Configuration;
|
2018-11-05 22:01:29 -05:00
|
|
|
|
using SharedLibraryCore.Database.Models;
|
2018-04-13 02:32:30 -04:00
|
|
|
|
using SharedLibraryCore.Interfaces;
|
2018-11-25 21:00:36 -05:00
|
|
|
|
using System;
|
2020-04-04 13:40:23 -04:00
|
|
|
|
using System.Collections.Generic;
|
2020-02-06 19:35:30 -05:00
|
|
|
|
using System.Linq;
|
2019-02-05 19:02:45 -05:00
|
|
|
|
using static SharedLibraryCore.Server;
|
2018-04-13 02:32:30 -04:00
|
|
|
|
|
2018-04-25 02:38:59 -04:00
|
|
|
|
namespace IW4MAdmin.Application.EventParsers
|
2018-04-13 02:32:30 -04:00
|
|
|
|
{
|
2020-02-11 17:44:06 -05:00
|
|
|
|
public class BaseEventParser : IEventParser
|
2018-04-13 02:32:30 -04:00
|
|
|
|
{
|
2020-04-04 13:40:23 -04:00
|
|
|
|
private readonly Dictionary<string, (string, Func<string, IEventParserConfiguration, GameEvent, GameEvent>)> _customEventRegistrations;
|
|
|
|
|
private readonly ILogger _logger;
|
2020-07-31 21:40:03 -04:00
|
|
|
|
private readonly ApplicationConfiguration _appConfig;
|
2020-04-04 13:40:23 -04:00
|
|
|
|
|
2020-07-31 21:40:03 -04:00
|
|
|
|
public BaseEventParser(IParserRegexFactory parserRegexFactory, ILogger logger, ApplicationConfiguration appConfig)
|
2019-01-26 21:33:37 -05:00
|
|
|
|
{
|
2020-04-04 13:40:23 -04:00
|
|
|
|
_customEventRegistrations = new Dictionary<string, (string, Func<string, IEventParserConfiguration, GameEvent, GameEvent>)>();
|
|
|
|
|
_logger = logger;
|
2020-07-31 21:40:03 -04:00
|
|
|
|
_appConfig = appConfig;
|
2020-04-04 13:40:23 -04:00
|
|
|
|
|
2020-04-01 15:11:56 -04:00
|
|
|
|
Configuration = new DynamicEventParserConfiguration(parserRegexFactory)
|
2019-01-26 21:33:37 -05:00
|
|
|
|
{
|
2019-02-05 12:14:43 -05:00
|
|
|
|
GameDirectory = "main",
|
2019-01-26 21:33:37 -05:00
|
|
|
|
};
|
2019-01-27 17:40:08 -05:00
|
|
|
|
|
2020-05-16 21:55:18 -04:00
|
|
|
|
Configuration.Say.Pattern = @"^(say|sayteam);(-?[A-Fa-f0-9_]{1,32}|bot[0-9]+|0);([0-9]+);([^;]*);(.*)$";
|
2019-02-02 20:40:37 -05:00
|
|
|
|
Configuration.Say.AddMapping(ParserRegex.GroupType.EventType, 1);
|
|
|
|
|
Configuration.Say.AddMapping(ParserRegex.GroupType.OriginNetworkId, 2);
|
|
|
|
|
Configuration.Say.AddMapping(ParserRegex.GroupType.OriginClientNumber, 3);
|
|
|
|
|
Configuration.Say.AddMapping(ParserRegex.GroupType.OriginName, 4);
|
|
|
|
|
Configuration.Say.AddMapping(ParserRegex.GroupType.Message, 5);
|
2019-01-27 17:40:08 -05:00
|
|
|
|
|
2020-05-04 17:50:02 -04:00
|
|
|
|
Configuration.Quit.Pattern = @"^(Q);(-?[A-Fa-f0-9_]{1,32}|bot[0-9]+|0);([0-9]+);(.*)$";
|
2019-02-02 20:40:37 -05:00
|
|
|
|
Configuration.Quit.AddMapping(ParserRegex.GroupType.EventType, 1);
|
|
|
|
|
Configuration.Quit.AddMapping(ParserRegex.GroupType.OriginNetworkId, 2);
|
|
|
|
|
Configuration.Quit.AddMapping(ParserRegex.GroupType.OriginClientNumber, 3);
|
|
|
|
|
Configuration.Quit.AddMapping(ParserRegex.GroupType.OriginName, 4);
|
2019-01-27 17:40:08 -05:00
|
|
|
|
|
2020-05-04 17:50:02 -04:00
|
|
|
|
Configuration.Join.Pattern = @"^(J);(-?[A-Fa-f0-9_]{1,32}|bot[0-9]+|0);([0-9]+);(.*)$";
|
2019-02-02 20:40:37 -05:00
|
|
|
|
Configuration.Join.AddMapping(ParserRegex.GroupType.EventType, 1);
|
|
|
|
|
Configuration.Join.AddMapping(ParserRegex.GroupType.OriginNetworkId, 2);
|
|
|
|
|
Configuration.Join.AddMapping(ParserRegex.GroupType.OriginClientNumber, 3);
|
|
|
|
|
Configuration.Join.AddMapping(ParserRegex.GroupType.OriginName, 4);
|
2019-01-27 17:40:08 -05:00
|
|
|
|
|
2020-06-16 18:16:12 -04:00
|
|
|
|
Configuration.Damage.Pattern = @"^(D);(-?[A-Fa-f0-9_]{1,32}|bot[0-9]+|0);(-?[0-9]+);(axis|allies|world|none)?;([^;]{1,24});(-?[A-Fa-f0-9_]{1,32}|bot[0-9]+|0)?;(-?[0-9]+);(axis|allies|world|none)?;([^;]{1,24})?;((?:[0-9]+|[a-z]+|_|\+)+);([0-9]+);((?:[A-Z]|_)+);((?:[a-z]|_)+)$";
|
2019-02-02 20:40:37 -05:00
|
|
|
|
Configuration.Damage.AddMapping(ParserRegex.GroupType.EventType, 1);
|
|
|
|
|
Configuration.Damage.AddMapping(ParserRegex.GroupType.TargetNetworkId, 2);
|
|
|
|
|
Configuration.Damage.AddMapping(ParserRegex.GroupType.TargetClientNumber, 3);
|
|
|
|
|
Configuration.Damage.AddMapping(ParserRegex.GroupType.TargetTeam, 4);
|
|
|
|
|
Configuration.Damage.AddMapping(ParserRegex.GroupType.TargetName, 5);
|
|
|
|
|
Configuration.Damage.AddMapping(ParserRegex.GroupType.OriginNetworkId, 6);
|
|
|
|
|
Configuration.Damage.AddMapping(ParserRegex.GroupType.OriginClientNumber, 7);
|
|
|
|
|
Configuration.Damage.AddMapping(ParserRegex.GroupType.OriginTeam, 8);
|
|
|
|
|
Configuration.Damage.AddMapping(ParserRegex.GroupType.OriginName, 9);
|
|
|
|
|
Configuration.Damage.AddMapping(ParserRegex.GroupType.Weapon, 10);
|
|
|
|
|
Configuration.Damage.AddMapping(ParserRegex.GroupType.Damage, 11);
|
|
|
|
|
Configuration.Damage.AddMapping(ParserRegex.GroupType.MeansOfDeath, 12);
|
|
|
|
|
Configuration.Damage.AddMapping(ParserRegex.GroupType.HitLocation, 13);
|
2019-01-27 17:40:08 -05:00
|
|
|
|
|
2020-06-16 18:16:12 -04:00
|
|
|
|
Configuration.Kill.Pattern = @"^(K);(-?[A-Fa-f0-9_]{1,32}|bot[0-9]+|0);(-?[0-9]+);(axis|allies|world|none)?;([^;]{1,24});(-?[A-Fa-f0-9_]{1,32}|bot[0-9]+|0)?;(-?[0-9]+);(axis|allies|world|none)?;([^;]{1,24})?;((?:[0-9]+|[a-z]+|_|\+)+);([0-9]+);((?:[A-Z]|_)+);((?:[a-z]|_)+)$";
|
2019-02-02 20:40:37 -05:00
|
|
|
|
Configuration.Kill.AddMapping(ParserRegex.GroupType.EventType, 1);
|
|
|
|
|
Configuration.Kill.AddMapping(ParserRegex.GroupType.TargetNetworkId, 2);
|
|
|
|
|
Configuration.Kill.AddMapping(ParserRegex.GroupType.TargetClientNumber, 3);
|
|
|
|
|
Configuration.Kill.AddMapping(ParserRegex.GroupType.TargetTeam, 4);
|
|
|
|
|
Configuration.Kill.AddMapping(ParserRegex.GroupType.TargetName, 5);
|
|
|
|
|
Configuration.Kill.AddMapping(ParserRegex.GroupType.OriginNetworkId, 6);
|
|
|
|
|
Configuration.Kill.AddMapping(ParserRegex.GroupType.OriginClientNumber, 7);
|
|
|
|
|
Configuration.Kill.AddMapping(ParserRegex.GroupType.OriginTeam, 8);
|
|
|
|
|
Configuration.Kill.AddMapping(ParserRegex.GroupType.OriginName, 9);
|
|
|
|
|
Configuration.Kill.AddMapping(ParserRegex.GroupType.Weapon, 10);
|
|
|
|
|
Configuration.Kill.AddMapping(ParserRegex.GroupType.Damage, 11);
|
|
|
|
|
Configuration.Kill.AddMapping(ParserRegex.GroupType.MeansOfDeath, 12);
|
|
|
|
|
Configuration.Kill.AddMapping(ParserRegex.GroupType.HitLocation, 13);
|
2020-04-01 15:11:56 -04:00
|
|
|
|
|
|
|
|
|
Configuration.Time.Pattern = @"^ *(([0-9]+):([0-9]+) |^[0-9]+ )";
|
2019-01-26 21:33:37 -05:00
|
|
|
|
}
|
|
|
|
|
|
2019-01-27 19:41:54 -05:00
|
|
|
|
public IEventParserConfiguration Configuration { get; set; }
|
2018-07-04 22:09:42 -04:00
|
|
|
|
|
2019-02-05 12:14:43 -05:00
|
|
|
|
public string Version { get; set; } = "CoD";
|
2019-02-02 19:54:30 -05:00
|
|
|
|
|
2019-02-05 19:02:45 -05:00
|
|
|
|
public Game GameName { get; set; } = Game.COD;
|
|
|
|
|
|
2019-04-06 22:48:49 -04:00
|
|
|
|
public string URLProtocolFormat { get; set; } = "CoD://{{ip}}:{{port}}";
|
|
|
|
|
|
2020-01-21 19:08:18 -05:00
|
|
|
|
public string Name { get; set; } = "Call of Duty";
|
|
|
|
|
|
2019-05-13 11:36:11 -04:00
|
|
|
|
public virtual GameEvent GenerateGameEvent(string logLine)
|
2018-04-13 02:32:30 -04:00
|
|
|
|
{
|
2020-04-01 15:11:56 -04:00
|
|
|
|
var timeMatch = Configuration.Time.PatternMatcher.Match(logLine);
|
2020-02-06 19:35:30 -05:00
|
|
|
|
int gameTime = 0;
|
2020-04-01 15:11:56 -04:00
|
|
|
|
|
2020-02-06 19:35:30 -05:00
|
|
|
|
if (timeMatch.Success)
|
|
|
|
|
{
|
2020-04-01 15:11:56 -04:00
|
|
|
|
gameTime = timeMatch
|
|
|
|
|
.Values
|
2020-02-06 19:35:30 -05:00
|
|
|
|
.Skip(2)
|
2020-04-01 15:11:56 -04:00
|
|
|
|
// this converts the timestamp into seconds passed
|
|
|
|
|
.Select((_value, index) => int.Parse(_value.ToString()) * (index == 0 ? 60 : 1))
|
2020-02-06 19:35:30 -05:00
|
|
|
|
.Sum();
|
2020-04-01 15:11:56 -04:00
|
|
|
|
// we want to strip the time from the log line
|
|
|
|
|
logLine = logLine.Substring(timeMatch.Values.First().Length);
|
|
|
|
|
}
|
2020-02-06 19:35:30 -05:00
|
|
|
|
|
2018-04-13 02:32:30 -04:00
|
|
|
|
string[] lineSplit = logLine.Split(';');
|
2018-06-30 21:55:16 -04:00
|
|
|
|
string eventType = lineSplit[0];
|
2018-04-13 02:32:30 -04:00
|
|
|
|
|
2018-06-30 21:55:16 -04:00
|
|
|
|
if (eventType == "say" || eventType == "sayteam")
|
2018-04-13 02:32:30 -04:00
|
|
|
|
{
|
2020-04-01 15:11:56 -04:00
|
|
|
|
var matchResult = Configuration.Say.PatternMatcher.Match(logLine);
|
2018-05-10 01:34:29 -04:00
|
|
|
|
|
2018-07-04 22:09:42 -04:00
|
|
|
|
if (matchResult.Success)
|
2018-05-10 01:34:29 -04:00
|
|
|
|
{
|
2020-04-01 15:11:56 -04:00
|
|
|
|
string message = matchResult.Values[Configuration.Say.GroupMapping[ParserRegex.GroupType.Message]]
|
2019-01-27 17:40:08 -05:00
|
|
|
|
.ToString()
|
2018-07-04 22:09:42 -04:00
|
|
|
|
.Replace("\x15", "")
|
|
|
|
|
.Trim();
|
|
|
|
|
|
2019-05-02 23:33:38 -04:00
|
|
|
|
if (message.Length > 0)
|
2018-07-04 22:09:42 -04:00
|
|
|
|
{
|
2020-05-04 17:50:02 -04:00
|
|
|
|
string originIdString = matchResult.Values[Configuration.Say.GroupMapping[ParserRegex.GroupType.OriginNetworkId]].ToString();
|
|
|
|
|
string originName = matchResult.Values[Configuration.Say.GroupMapping[ParserRegex.GroupType.OriginName]].ToString();
|
|
|
|
|
|
|
|
|
|
long originId = originIdString.IsBotGuid() ?
|
|
|
|
|
originName.GenerateGuidFromString() :
|
|
|
|
|
originIdString.ConvertGuidToLong(Configuration.GuidNumberStyle);
|
|
|
|
|
|
2020-04-01 15:11:56 -04:00
|
|
|
|
int clientNumber = int.Parse(matchResult.Values[Configuration.Say.GroupMapping[ParserRegex.GroupType.OriginClientNumber]]);
|
2019-05-02 23:33:38 -04:00
|
|
|
|
|
2020-07-31 21:40:03 -04:00
|
|
|
|
if (message.StartsWith(_appConfig.CommandPrefix) || message.StartsWith(_appConfig.BroadcastCommandPrefix))
|
2019-05-02 23:33:38 -04:00
|
|
|
|
{
|
|
|
|
|
return new GameEvent()
|
|
|
|
|
{
|
|
|
|
|
Type = GameEvent.EventType.Command,
|
|
|
|
|
Data = message,
|
2020-04-01 15:11:56 -04:00
|
|
|
|
Origin = new EFClient() { NetworkId = originId, ClientNumber = clientNumber },
|
2019-05-29 17:55:35 -04:00
|
|
|
|
Message = message,
|
2019-10-18 14:39:21 -04:00
|
|
|
|
Extra = logLine,
|
2020-02-06 19:35:30 -05:00
|
|
|
|
RequiredEntity = GameEvent.EventRequiredEntity.Origin,
|
2020-05-04 17:50:02 -04:00
|
|
|
|
GameTime = gameTime,
|
|
|
|
|
Source = GameEvent.EventSource.Log
|
2019-05-02 23:33:38 -04:00
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2018-07-04 22:09:42 -04:00
|
|
|
|
return new GameEvent()
|
|
|
|
|
{
|
2019-05-02 23:33:38 -04:00
|
|
|
|
Type = GameEvent.EventType.Say,
|
2018-07-04 22:09:42 -04:00
|
|
|
|
Data = message,
|
2020-04-01 15:11:56 -04:00
|
|
|
|
Origin = new EFClient() { NetworkId = originId, ClientNumber = clientNumber },
|
2019-05-29 17:55:35 -04:00
|
|
|
|
Message = message,
|
2019-10-18 14:39:21 -04:00
|
|
|
|
Extra = logLine,
|
2020-02-06 19:35:30 -05:00
|
|
|
|
RequiredEntity = GameEvent.EventRequiredEntity.Origin,
|
2020-05-04 17:50:02 -04:00
|
|
|
|
GameTime = gameTime,
|
|
|
|
|
Source = GameEvent.EventSource.Log
|
2018-07-04 22:09:42 -04:00
|
|
|
|
};
|
|
|
|
|
}
|
2018-05-10 01:34:29 -04:00
|
|
|
|
}
|
2018-04-13 02:32:30 -04:00
|
|
|
|
}
|
|
|
|
|
|
2018-08-31 23:35:51 -04:00
|
|
|
|
if (eventType == "K")
|
|
|
|
|
{
|
2020-04-01 15:11:56 -04:00
|
|
|
|
var match = Configuration.Kill.PatternMatcher.Match(logLine);
|
2018-08-31 23:35:51 -04:00
|
|
|
|
|
2019-05-13 11:36:11 -04:00
|
|
|
|
if (match.Success)
|
2018-04-13 02:32:30 -04:00
|
|
|
|
{
|
2020-05-04 17:50:02 -04:00
|
|
|
|
string originIdString = match.Values[Configuration.Kill.GroupMapping[ParserRegex.GroupType.OriginNetworkId]].ToString();
|
|
|
|
|
string targetIdString = match.Values[Configuration.Kill.GroupMapping[ParserRegex.GroupType.TargetNetworkId]].ToString();
|
|
|
|
|
string originName = match.Values[Configuration.Kill.GroupMapping[ParserRegex.GroupType.OriginName]].ToString();
|
|
|
|
|
string targetName = match.Values[Configuration.Kill.GroupMapping[ParserRegex.GroupType.TargetName]].ToString();
|
|
|
|
|
|
|
|
|
|
long originId = originIdString.IsBotGuid() ?
|
|
|
|
|
originName.GenerateGuidFromString() :
|
|
|
|
|
originIdString.ConvertGuidToLong(Configuration.GuidNumberStyle, Utilities.WORLD_ID);
|
|
|
|
|
long targetId = targetIdString.IsBotGuid() ?
|
|
|
|
|
targetName.GenerateGuidFromString() :
|
|
|
|
|
targetIdString.ConvertGuidToLong(Configuration.GuidNumberStyle, Utilities.WORLD_ID);
|
|
|
|
|
|
2020-04-01 15:11:56 -04:00
|
|
|
|
int originClientNumber = int.Parse(match.Values[Configuration.Kill.GroupMapping[ParserRegex.GroupType.OriginClientNumber]]);
|
|
|
|
|
int targetClientNumber = int.Parse(match.Values[Configuration.Kill.GroupMapping[ParserRegex.GroupType.TargetClientNumber]]);
|
2018-04-13 02:32:30 -04:00
|
|
|
|
|
2019-05-13 11:36:11 -04:00
|
|
|
|
return new GameEvent()
|
|
|
|
|
{
|
|
|
|
|
Type = GameEvent.EventType.Kill,
|
|
|
|
|
Data = logLine,
|
2020-04-01 15:11:56 -04:00
|
|
|
|
Origin = new EFClient() { NetworkId = originId, ClientNumber = originClientNumber },
|
|
|
|
|
Target = new EFClient() { NetworkId = targetId, ClientNumber = targetClientNumber },
|
2020-02-06 19:35:30 -05:00
|
|
|
|
RequiredEntity = GameEvent.EventRequiredEntity.Origin | GameEvent.EventRequiredEntity.Target,
|
2020-05-04 17:50:02 -04:00
|
|
|
|
GameTime = gameTime,
|
|
|
|
|
Source = GameEvent.EventSource.Log
|
2019-05-13 11:36:11 -04:00
|
|
|
|
};
|
|
|
|
|
}
|
2018-05-08 00:58:46 -04:00
|
|
|
|
}
|
|
|
|
|
|
2018-06-30 21:55:16 -04:00
|
|
|
|
if (eventType == "D")
|
2018-05-03 01:25:49 -04:00
|
|
|
|
{
|
2020-04-01 15:11:56 -04:00
|
|
|
|
var match = Configuration.Damage.PatternMatcher.Match(logLine);
|
2019-01-27 17:40:08 -05:00
|
|
|
|
|
2020-04-01 15:11:56 -04:00
|
|
|
|
if (match.Success)
|
2019-05-29 17:55:35 -04:00
|
|
|
|
{
|
2020-05-04 17:50:02 -04:00
|
|
|
|
string originIdString = match.Values[Configuration.Damage.GroupMapping[ParserRegex.GroupType.OriginNetworkId]].ToString();
|
|
|
|
|
string targetIdString = match.Values[Configuration.Damage.GroupMapping[ParserRegex.GroupType.TargetNetworkId]].ToString();
|
|
|
|
|
string originName = match.Values[Configuration.Damage.GroupMapping[ParserRegex.GroupType.OriginName]].ToString();
|
|
|
|
|
string targetName = match.Values[Configuration.Damage.GroupMapping[ParserRegex.GroupType.TargetName]].ToString();
|
|
|
|
|
|
|
|
|
|
long originId = originIdString.IsBotGuid() ?
|
|
|
|
|
originName.GenerateGuidFromString() :
|
|
|
|
|
originIdString.ConvertGuidToLong(Configuration.GuidNumberStyle, Utilities.WORLD_ID);
|
|
|
|
|
long targetId = targetIdString.IsBotGuid() ?
|
|
|
|
|
targetName.GenerateGuidFromString() :
|
|
|
|
|
targetIdString.ConvertGuidToLong(Configuration.GuidNumberStyle, Utilities.WORLD_ID);
|
|
|
|
|
|
2020-04-01 15:11:56 -04:00
|
|
|
|
int originClientNumber = int.Parse(match.Values[Configuration.Damage.GroupMapping[ParserRegex.GroupType.OriginClientNumber]]);
|
|
|
|
|
int targetClientNumber = int.Parse(match.Values[Configuration.Damage.GroupMapping[ParserRegex.GroupType.TargetClientNumber]]);
|
2018-09-02 17:59:27 -04:00
|
|
|
|
|
2019-05-29 17:55:35 -04:00
|
|
|
|
return new GameEvent()
|
|
|
|
|
{
|
|
|
|
|
Type = GameEvent.EventType.Damage,
|
|
|
|
|
Data = logLine,
|
2020-04-01 15:11:56 -04:00
|
|
|
|
Origin = new EFClient() { NetworkId = originId, ClientNumber = originClientNumber },
|
|
|
|
|
Target = new EFClient() { NetworkId = targetId, ClientNumber = targetClientNumber },
|
2020-02-06 19:35:30 -05:00
|
|
|
|
RequiredEntity = GameEvent.EventRequiredEntity.Origin | GameEvent.EventRequiredEntity.Target,
|
2020-05-04 17:50:02 -04:00
|
|
|
|
GameTime = gameTime,
|
|
|
|
|
Source = GameEvent.EventSource.Log
|
2019-05-29 17:55:35 -04:00
|
|
|
|
};
|
|
|
|
|
}
|
2018-05-03 01:25:49 -04:00
|
|
|
|
}
|
|
|
|
|
|
2018-06-30 21:55:16 -04:00
|
|
|
|
if (eventType == "J")
|
2018-06-07 22:19:12 -04:00
|
|
|
|
{
|
2020-04-01 15:11:56 -04:00
|
|
|
|
var match = Configuration.Join.PatternMatcher.Match(logLine);
|
2019-05-13 11:36:11 -04:00
|
|
|
|
|
2020-04-01 15:11:56 -04:00
|
|
|
|
if (match.Success)
|
2018-06-07 22:19:12 -04:00
|
|
|
|
{
|
2020-05-04 17:50:02 -04:00
|
|
|
|
string originIdString = match.Values[Configuration.Join.GroupMapping[ParserRegex.GroupType.OriginNetworkId]].ToString();
|
|
|
|
|
string originName = match.Values[Configuration.Join.GroupMapping[ParserRegex.GroupType.OriginName]].ToString();
|
|
|
|
|
|
|
|
|
|
long networkId = originIdString.IsBotGuid() ?
|
|
|
|
|
originName.GenerateGuidFromString() :
|
|
|
|
|
originIdString.ConvertGuidToLong(Configuration.GuidNumberStyle);
|
|
|
|
|
|
2018-06-07 22:19:12 -04:00
|
|
|
|
return new GameEvent()
|
|
|
|
|
{
|
2018-11-07 21:30:11 -05:00
|
|
|
|
Type = GameEvent.EventType.PreConnect,
|
2018-06-30 21:55:16 -04:00
|
|
|
|
Data = logLine,
|
2018-11-05 22:01:29 -05:00
|
|
|
|
Origin = new EFClient()
|
2018-06-07 22:19:12 -04:00
|
|
|
|
{
|
2018-11-25 21:00:36 -05:00
|
|
|
|
CurrentAlias = new EFAlias()
|
|
|
|
|
{
|
2020-04-01 15:11:56 -04:00
|
|
|
|
Name = match.Values[Configuration.Join.GroupMapping[ParserRegex.GroupType.OriginName]].ToString().TrimNewLine(),
|
2018-11-25 21:00:36 -05:00
|
|
|
|
},
|
2020-05-04 17:50:02 -04:00
|
|
|
|
NetworkId = networkId,
|
2020-04-01 15:11:56 -04:00
|
|
|
|
ClientNumber = Convert.ToInt32(match.Values[Configuration.Join.GroupMapping[ParserRegex.GroupType.OriginClientNumber]].ToString()),
|
2018-11-05 22:01:29 -05:00
|
|
|
|
State = EFClient.ClientState.Connecting,
|
2019-05-29 17:55:35 -04:00
|
|
|
|
},
|
2019-10-18 14:39:21 -04:00
|
|
|
|
RequiredEntity = GameEvent.EventRequiredEntity.None,
|
2020-02-06 19:35:30 -05:00
|
|
|
|
IsBlocking = true,
|
2020-05-04 17:50:02 -04:00
|
|
|
|
GameTime = gameTime,
|
|
|
|
|
Source = GameEvent.EventSource.Log
|
2018-06-07 22:19:12 -04:00
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-07 21:30:11 -05:00
|
|
|
|
if (eventType == "Q")
|
|
|
|
|
{
|
2020-04-01 15:11:56 -04:00
|
|
|
|
var match = Configuration.Quit.PatternMatcher.Match(logLine);
|
|
|
|
|
|
|
|
|
|
if (match.Success)
|
2018-11-07 21:30:11 -05:00
|
|
|
|
{
|
2020-05-04 17:50:02 -04:00
|
|
|
|
string originIdString = match.Values[Configuration.Quit.GroupMapping[ParserRegex.GroupType.OriginNetworkId]].ToString();
|
|
|
|
|
string originName = match.Values[Configuration.Quit.GroupMapping[ParserRegex.GroupType.OriginName]].ToString();
|
|
|
|
|
|
|
|
|
|
long networkId = originIdString.IsBotGuid() ?
|
|
|
|
|
originName.GenerateGuidFromString() :
|
|
|
|
|
originIdString.ConvertGuidToLong(Configuration.GuidNumberStyle);
|
|
|
|
|
|
2018-11-07 21:30:11 -05:00
|
|
|
|
return new GameEvent()
|
|
|
|
|
{
|
|
|
|
|
Type = GameEvent.EventType.PreDisconnect,
|
|
|
|
|
Data = logLine,
|
|
|
|
|
Origin = new EFClient()
|
|
|
|
|
{
|
2018-11-25 21:00:36 -05:00
|
|
|
|
CurrentAlias = new EFAlias()
|
|
|
|
|
{
|
2020-04-01 15:11:56 -04:00
|
|
|
|
Name = match.Values[Configuration.Quit.GroupMapping[ParserRegex.GroupType.OriginName]].ToString().TrimNewLine()
|
2018-11-25 21:00:36 -05:00
|
|
|
|
},
|
2020-05-04 17:50:02 -04:00
|
|
|
|
NetworkId = networkId,
|
2020-04-01 15:11:56 -04:00
|
|
|
|
ClientNumber = Convert.ToInt32(match.Values[Configuration.Quit.GroupMapping[ParserRegex.GroupType.OriginClientNumber]].ToString()),
|
2018-11-07 21:30:11 -05:00
|
|
|
|
State = EFClient.ClientState.Disconnecting
|
2019-05-29 17:55:35 -04:00
|
|
|
|
},
|
2019-10-18 14:39:21 -04:00
|
|
|
|
RequiredEntity = GameEvent.EventRequiredEntity.None,
|
2020-02-06 19:35:30 -05:00
|
|
|
|
IsBlocking = true,
|
2020-05-04 17:50:02 -04:00
|
|
|
|
GameTime = gameTime,
|
|
|
|
|
Source = GameEvent.EventSource.Log
|
2018-11-07 21:30:11 -05:00
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-06-30 21:55:16 -04:00
|
|
|
|
|
|
|
|
|
if (eventType.Contains("ExitLevel"))
|
2018-04-13 02:32:30 -04:00
|
|
|
|
{
|
|
|
|
|
return new GameEvent()
|
|
|
|
|
{
|
|
|
|
|
Type = GameEvent.EventType.MapEnd,
|
2019-10-18 14:39:21 -04:00
|
|
|
|
Data = logLine,
|
2019-05-13 11:36:11 -04:00
|
|
|
|
Origin = Utilities.IW4MAdminClient(),
|
|
|
|
|
Target = Utilities.IW4MAdminClient(),
|
2020-02-06 19:35:30 -05:00
|
|
|
|
RequiredEntity = GameEvent.EventRequiredEntity.None,
|
2020-05-04 17:50:02 -04:00
|
|
|
|
GameTime = gameTime,
|
|
|
|
|
Source = GameEvent.EventSource.Log
|
2018-04-13 02:32:30 -04:00
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2018-06-30 21:55:16 -04:00
|
|
|
|
if (eventType.Contains("InitGame"))
|
2018-04-13 02:32:30 -04:00
|
|
|
|
{
|
2018-06-30 21:55:16 -04:00
|
|
|
|
string dump = eventType.Replace("InitGame: ", "");
|
2018-04-23 01:43:48 -04:00
|
|
|
|
|
2018-04-13 02:32:30 -04:00
|
|
|
|
return new GameEvent()
|
|
|
|
|
{
|
|
|
|
|
Type = GameEvent.EventType.MapChange,
|
2019-10-18 14:39:21 -04:00
|
|
|
|
Data = logLine,
|
2019-05-13 11:36:11 -04:00
|
|
|
|
Origin = Utilities.IW4MAdminClient(),
|
|
|
|
|
Target = Utilities.IW4MAdminClient(),
|
2019-05-29 17:55:35 -04:00
|
|
|
|
Extra = dump.DictionaryFromKeyValue(),
|
2020-02-06 19:35:30 -05:00
|
|
|
|
RequiredEntity = GameEvent.EventRequiredEntity.None,
|
2020-05-04 17:50:02 -04:00
|
|
|
|
GameTime = gameTime,
|
|
|
|
|
Source = GameEvent.EventSource.Log
|
2018-04-13 02:32:30 -04:00
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-04 13:40:23 -04:00
|
|
|
|
if (_customEventRegistrations.ContainsKey(eventType))
|
2019-05-13 11:36:11 -04:00
|
|
|
|
{
|
2020-04-04 13:40:23 -04:00
|
|
|
|
var eventModifier = _customEventRegistrations[eventType];
|
2019-05-13 11:36:11 -04:00
|
|
|
|
|
2020-04-04 13:40:23 -04:00
|
|
|
|
try
|
2019-05-13 11:36:11 -04:00
|
|
|
|
{
|
2020-04-04 13:40:23 -04:00
|
|
|
|
return eventModifier.Item2(logLine, Configuration, new GameEvent()
|
|
|
|
|
{
|
|
|
|
|
Type = GameEvent.EventType.Other,
|
|
|
|
|
Data = logLine,
|
|
|
|
|
Subtype = eventModifier.Item1,
|
2020-05-04 17:50:02 -04:00
|
|
|
|
GameTime = gameTime,
|
|
|
|
|
Source = GameEvent.EventSource.Log
|
2020-04-04 13:40:23 -04:00
|
|
|
|
});
|
|
|
|
|
}
|
2019-05-13 11:36:11 -04:00
|
|
|
|
|
2020-04-04 13:40:23 -04:00
|
|
|
|
catch (Exception e)
|
2019-05-13 11:36:11 -04:00
|
|
|
|
{
|
2020-04-04 13:40:23 -04:00
|
|
|
|
_logger.WriteWarning($"Could not handle custom event generation - {e.GetExceptionInfo()}");
|
|
|
|
|
}
|
2019-05-13 11:36:11 -04:00
|
|
|
|
}
|
|
|
|
|
|
2018-04-13 02:32:30 -04:00
|
|
|
|
return new GameEvent()
|
|
|
|
|
{
|
|
|
|
|
Type = GameEvent.EventType.Unknown,
|
2019-06-30 14:37:59 -04:00
|
|
|
|
Data = logLine,
|
2019-05-13 11:36:11 -04:00
|
|
|
|
Origin = Utilities.IW4MAdminClient(),
|
2019-05-29 17:55:35 -04:00
|
|
|
|
Target = Utilities.IW4MAdminClient(),
|
2020-02-06 19:35:30 -05:00
|
|
|
|
RequiredEntity = GameEvent.EventRequiredEntity.None,
|
2020-05-04 17:50:02 -04:00
|
|
|
|
GameTime = gameTime,
|
|
|
|
|
Source = GameEvent.EventSource.Log
|
2018-04-13 02:32:30 -04:00
|
|
|
|
};
|
|
|
|
|
}
|
2020-04-04 13:40:23 -04:00
|
|
|
|
|
|
|
|
|
/// <inheritdoc/>
|
|
|
|
|
public void RegisterCustomEvent(string eventSubtype, string eventTriggerValue, Func<string, IEventParserConfiguration, GameEvent, GameEvent> eventModifier)
|
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrWhiteSpace(eventSubtype))
|
|
|
|
|
{
|
|
|
|
|
throw new ArgumentException("Event subtype cannot be empty");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (string.IsNullOrWhiteSpace(eventTriggerValue))
|
|
|
|
|
{
|
|
|
|
|
throw new ArgumentException("Event trigger value cannot be empty");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (eventModifier == null)
|
|
|
|
|
{
|
|
|
|
|
throw new ArgumentException("Event modifier must be specified");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (_customEventRegistrations.ContainsKey(eventTriggerValue))
|
|
|
|
|
{
|
|
|
|
|
throw new ArgumentException($"Event trigger value '{eventTriggerValue}' is already registered");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_customEventRegistrations.Add(eventTriggerValue, (eventSubtype, eventModifier));
|
|
|
|
|
}
|
2018-04-13 02:32:30 -04:00
|
|
|
|
}
|
|
|
|
|
}
|