fix issue with PT6 guid parsing in log file

This commit is contained in:
RaidMax 2020-01-15 18:43:52 -06:00
parent fa8dbe7988
commit 7e3f632399
10 changed files with 51 additions and 23 deletions

View File

@ -95,7 +95,7 @@ namespace IW4MAdmin.Application.EventParsers
if (message.Length > 0)
{
long originId = matchResult.Groups[Configuration.Say.GroupMapping[ParserRegex.GroupType.OriginNetworkId]].ToString().ConvertGuidToLong();
long originId = matchResult.Groups[Configuration.Say.GroupMapping[ParserRegex.GroupType.OriginNetworkId]].ToString().ConvertGuidToLong(Configuration.GuidNumberStyle);
if (message[0] == '!' || message[0] == '@')
{
@ -129,8 +129,8 @@ namespace IW4MAdmin.Application.EventParsers
if (match.Success)
{
long originId = match.Groups[Configuration.Kill.GroupMapping[ParserRegex.GroupType.OriginNetworkId]].Value.ToString().ConvertGuidToLong(1);
long targetId = match.Groups[Configuration.Kill.GroupMapping[ParserRegex.GroupType.TargetNetworkId]].Value.ToString().ConvertGuidToLong(1);
long originId = match.Groups[Configuration.Kill.GroupMapping[ParserRegex.GroupType.OriginNetworkId]].Value.ToString().ConvertGuidToLong(Configuration.GuidNumberStyle, 1);
long targetId = match.Groups[Configuration.Kill.GroupMapping[ParserRegex.GroupType.TargetNetworkId]].Value.ToString().ConvertGuidToLong(Configuration.GuidNumberStyle, 1);
return new GameEvent()
{
@ -149,8 +149,8 @@ namespace IW4MAdmin.Application.EventParsers
if (regexMatch.Success)
{
long originId = regexMatch.Groups[Configuration.Damage.GroupMapping[ParserRegex.GroupType.OriginNetworkId]].ToString().ConvertGuidToLong(1);
long targetId = regexMatch.Groups[Configuration.Damage.GroupMapping[ParserRegex.GroupType.TargetNetworkId]].ToString().ConvertGuidToLong(1);
long originId = regexMatch.Groups[Configuration.Damage.GroupMapping[ParserRegex.GroupType.OriginNetworkId]].ToString().ConvertGuidToLong(Configuration.GuidNumberStyle, 1);
long targetId = regexMatch.Groups[Configuration.Damage.GroupMapping[ParserRegex.GroupType.TargetNetworkId]].ToString().ConvertGuidToLong(Configuration.GuidNumberStyle, 1);
return new GameEvent()
{
@ -179,7 +179,7 @@ namespace IW4MAdmin.Application.EventParsers
{
Name = regexMatch.Groups[Configuration.Join.GroupMapping[ParserRegex.GroupType.OriginName]].ToString(),
},
NetworkId = regexMatch.Groups[Configuration.Join.GroupMapping[ParserRegex.GroupType.OriginNetworkId]].ToString().ConvertGuidToLong(),
NetworkId = regexMatch.Groups[Configuration.Join.GroupMapping[ParserRegex.GroupType.OriginNetworkId]].ToString().ConvertGuidToLong(Configuration.GuidNumberStyle),
ClientNumber = Convert.ToInt32(regexMatch.Groups[Configuration.Join.GroupMapping[ParserRegex.GroupType.OriginClientNumber]].ToString()),
State = EFClient.ClientState.Connecting,
},
@ -204,7 +204,7 @@ namespace IW4MAdmin.Application.EventParsers
{
Name = regexMatch.Groups[Configuration.Quit.GroupMapping[ParserRegex.GroupType.OriginName]].ToString()
},
NetworkId = regexMatch.Groups[Configuration.Quit.GroupMapping[ParserRegex.GroupType.OriginNetworkId]].ToString().ConvertGuidToLong(),
NetworkId = regexMatch.Groups[Configuration.Quit.GroupMapping[ParserRegex.GroupType.OriginNetworkId]].ToString().ConvertGuidToLong(Configuration.GuidNumberStyle),
ClientNumber = Convert.ToInt32(regexMatch.Groups[Configuration.Quit.GroupMapping[ParserRegex.GroupType.OriginClientNumber]].ToString()),
State = EFClient.ClientState.Disconnecting
},
@ -248,7 +248,7 @@ namespace IW4MAdmin.Application.EventParsers
{
Type = GameEvent.EventType.JoinTeam,
Data = logLine,
Origin = new EFClient() { NetworkId = lineSplit[1].ConvertGuidToLong() },
Origin = new EFClient() { NetworkId = lineSplit[1].ConvertGuidToLong(Configuration.GuidNumberStyle) },
RequiredEntity = GameEvent.EventRequiredEntity.Target
};
}
@ -257,8 +257,8 @@ namespace IW4MAdmin.Application.EventParsers
if (eventType == "ScriptKill")
{
long originId = lineSplit[1].ConvertGuidToLong(1);
long targetId = lineSplit[2].ConvertGuidToLong(1);
long originId = lineSplit[1].ConvertGuidToLong(Configuration.GuidNumberStyle, 1);
long targetId = lineSplit[2].ConvertGuidToLong(Configuration.GuidNumberStyle, 1);
return new GameEvent()
{
@ -273,8 +273,8 @@ namespace IW4MAdmin.Application.EventParsers
// this is a custom event printed out by _customcallbacks.gsc (used for anticheat)
if (eventType == "ScriptDamage")
{
long originId = lineSplit[1].ConvertGuidToLong(1);
long targetId = lineSplit[2].ConvertGuidToLong(1);
long originId = lineSplit[1].ConvertGuidToLong(Configuration.GuidNumberStyle, 1);
long targetId = lineSplit[2].ConvertGuidToLong(Configuration.GuidNumberStyle, 1);
return new GameEvent()
{

View File

@ -1,4 +1,5 @@
using SharedLibraryCore.Interfaces;
using System.Globalization;
namespace IW4MAdmin.Application.EventParsers
{
@ -15,5 +16,6 @@ namespace IW4MAdmin.Application.EventParsers
public ParserRegex Kill { get; set; } = new ParserRegex();
public ParserRegex Damage { get; set; } = new ParserRegex();
public ParserRegex Action { get; set; } = new ParserRegex();
public NumberStyles GuidNumberStyle { get; set; } = NumberStyles.HexNumber;
}
}

View File

@ -169,7 +169,7 @@ namespace IW4MAdmin.Application.RconParsers
long networkId;
try
{
networkId = regex.Groups[Configuration.Status.GroupMapping[ParserRegex.GroupType.RConNetworkId]].Value.ConvertGuidToLong();
networkId = regex.Groups[Configuration.Status.GroupMapping[ParserRegex.GroupType.RConNetworkId]].Value.ConvertGuidToLong(Configuration.GuidNumberStyle);
}
catch (FormatException)

View File

@ -1,5 +1,6 @@
using SharedLibraryCore.Interfaces;
using SharedLibraryCore.RCon;
using System.Globalization;
namespace IW4MAdmin.Application.RconParsers
{
@ -15,5 +16,6 @@ namespace IW4MAdmin.Application.RconParsers
public ParserRegex Dvar { get; set; } = new ParserRegex();
public string ServerNotRunningResponse { get; set; }
public bool WaitForResponse { get; set; } = true;
public NumberStyles GuidNumberStyle { get; set; } = NumberStyles.HexNumber;
}
}

View File

@ -3,7 +3,7 @@ var eventParser;
var plugin = {
author: 'RaidMax, Xerxes',
version: 0.4,
version: 0.5,
name: 'Plutonium T6 Parser',
isParser: true,
@ -33,8 +33,9 @@ var plugin = {
rconParser.Configuration.Status.AddMapping(103, 4);
rconParser.Configuration.Status.AddMapping(104, 5);
rconParser.Configuration.Status.AddMapping(105, 6);
eventParser.Configuration.GameDirectory = 't6r\\data';
eventParser.Configuration.GuidNumberStyle = 7; // Integer
rconParser.Version = 'Call of Duty Multiplayer - Ship COD_T6_S MP build 1.0.44 CL(1759941) CODPCAB2 CEG Fri May 9 19:19:19 2014 win-x86 813e66d5';
rconParser.GameName = 7; // T6

View File

@ -88,7 +88,7 @@ namespace SharedLibraryCore
if (clientId > 0)
{
Client.ClientId = clientId;
Client.NetworkId = clientId == 1 ? 0 : User.Claims.First(_claim => _claim.Type == ClaimTypes.PrimarySid).Value.ConvertGuidToLong();
Client.NetworkId = clientId == 1 ? 0 : User.Claims.First(_claim => _claim.Type == ClaimTypes.PrimarySid).Value.ConvertGuidToLong(System.Globalization.NumberStyles.HexNumber);
Client.Level = (EFClient.Permission)Enum.Parse(typeof(EFClient.Permission), User.Claims.First(c => c.Type == ClaimTypes.Role).Value);
Client.CurrentAlias = new EFAlias() { Name = User.Claims.First(c => c.Type == ClaimTypes.NameIdentifier).Value };
Authorized = Client.ClientId >= 0;

View File

@ -1,4 +1,6 @@
namespace SharedLibraryCore.Interfaces
using System.Globalization;
namespace SharedLibraryCore.Interfaces
{
public interface IEventParserConfiguration
{
@ -6,29 +8,40 @@
/// stores the fs_game directory (this folder may vary between different clients)
/// </summary>
string GameDirectory { get; set; }
/// <summary>
/// stores the regex information for a say event printed in the game log
/// </summary>
ParserRegex Say { get; set; }
/// <summary>
/// stores the regex information for a join event printed in the game log
/// </summary>
ParserRegex Join { get; set; }
/// <summary>
/// stores the regex information for a quit event printed in the game log
/// </summary>
ParserRegex Quit { get; set; }
/// <summary>
/// stores the regex information for a kill event printed in the game log
/// </summary>
ParserRegex Kill { get; set; }
/// <summary>
/// stores the regex information for a damage event printed in the game log
/// </summary>
ParserRegex Damage { get; set; }
/// <summary>
/// stores the regex information for an action event printed in the game log
/// </summary>
ParserRegex Action { get; set; }
/// <summary>
/// indicates the format expected for parsed guids
/// </summary>
NumberStyles GuidNumberStyle { get; set; }
}
}

View File

@ -1,4 +1,5 @@
using SharedLibraryCore.RCon;
using System.Globalization;
namespace SharedLibraryCore.Interfaces
{
@ -34,5 +35,10 @@ namespace SharedLibraryCore.Interfaces
/// when executing a command
/// </summary>
bool WaitForResponse { get; set; }
/// <summary>
/// indicates the format expected for parsed guids
/// </summary>
NumberStyles GuidNumberStyle { get; set; }
}
}

View File

@ -537,7 +537,7 @@ namespace SharedLibraryCore.Services
long? networkId = null;
try
{
networkId = identifier.ConvertGuidToLong();
networkId = identifier.ConvertGuidToLong(System.Globalization.NumberStyles.HexNumber);
}
catch { }

View File

@ -281,7 +281,7 @@ namespace SharedLibraryCore
}
}
public static long ConvertGuidToLong(this string str, long? fallback = null)
public static long ConvertGuidToLong(this string str, NumberStyles numberStyle, long? fallback = null)
{
str = str.Substring(0, Math.Min(str.Length, 19));
var bot = Regex.Match(str, @"bot[0-9]+").Value;
@ -291,20 +291,24 @@ namespace SharedLibraryCore
return fallback.Value;
}
// this is a special case for Plutonium T6 and CoD4x
if (long.TryParse(str, NumberStyles.Integer, CultureInfo.InvariantCulture, out long id))
long id = 0;
if (numberStyle == NumberStyles.Integer)
{
long.TryParse(str, numberStyle, CultureInfo.InvariantCulture, out id);
if (id < 0)
{
id = (uint)id;
}
}
else if (long.TryParse(str.Length > 16 ? str.Substring(0, 16) : str, NumberStyles.HexNumber, CultureInfo.InvariantCulture, out id))
else
{
long.TryParse(str.Length > 16 ? str.Substring(0, 16) : str, numberStyle, CultureInfo.InvariantCulture, out id);
}
else if (!string.IsNullOrEmpty(bot))
if (!string.IsNullOrEmpty(bot))
{
id = -1;
#if DEBUG