2018-04-13 02:32:30 -04:00
|
|
|
|
using System;
|
2018-04-23 01:43:48 -04:00
|
|
|
|
using System.Collections.Generic;
|
2018-04-13 02:32:30 -04:00
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text.RegularExpressions;
|
|
|
|
|
using SharedLibraryCore;
|
|
|
|
|
using SharedLibraryCore.Interfaces;
|
|
|
|
|
using SharedLibraryCore.Objects;
|
|
|
|
|
|
2018-04-25 02:38:59 -04:00
|
|
|
|
namespace IW4MAdmin.Application.EventParsers
|
2018-04-13 02:32:30 -04:00
|
|
|
|
{
|
|
|
|
|
class IW4EventParser : IEventParser
|
|
|
|
|
{
|
2018-08-07 14:43:09 -04:00
|
|
|
|
private const string SayRegex = @"(say|sayteam);(.{1,32});([0-9]+)(.*);(.*)";
|
2018-07-04 22:09:42 -04:00
|
|
|
|
|
2018-04-23 01:43:48 -04:00
|
|
|
|
public virtual GameEvent GetEvent(Server server, string logLine)
|
2018-04-13 02:32:30 -04:00
|
|
|
|
{
|
2018-06-30 21:55:16 -04:00
|
|
|
|
logLine = Regex.Replace(logLine, @"([0-9]+:[0-9]+ |^[0-9]+ )", "").Trim();
|
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-07 22:19:12 -04:00
|
|
|
|
// kill
|
2018-06-30 21:55:16 -04:00
|
|
|
|
if (eventType == "K")
|
2018-04-13 02:32:30 -04:00
|
|
|
|
{
|
|
|
|
|
if (!server.CustomCallback)
|
|
|
|
|
{
|
|
|
|
|
return new GameEvent()
|
|
|
|
|
{
|
2018-05-10 01:34:29 -04:00
|
|
|
|
Type = GameEvent.EventType.Kill,
|
2018-04-13 02:32:30 -04:00
|
|
|
|
Data = logLine,
|
|
|
|
|
Origin = server.GetPlayersAsList().First(c => c.ClientNumber == Utilities.ClientIdFromString(lineSplit, 6)),
|
|
|
|
|
Target = server.GetPlayersAsList().First(c => c.ClientNumber == Utilities.ClientIdFromString(lineSplit, 2)),
|
|
|
|
|
Owner = server
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-06-30 21:55:16 -04:00
|
|
|
|
if (eventType == "JoinTeam")
|
2018-06-05 17:31:36 -04:00
|
|
|
|
{
|
|
|
|
|
return new GameEvent()
|
|
|
|
|
{
|
|
|
|
|
Type = GameEvent.EventType.JoinTeam,
|
2018-06-30 21:55:16 -04:00
|
|
|
|
Data = eventType,
|
2018-06-16 22:11:25 -04:00
|
|
|
|
Origin = server.GetPlayersAsList().FirstOrDefault(c => c.NetworkId == lineSplit[1].ConvertLong()),
|
2018-06-05 17:31:36 -04:00
|
|
|
|
Owner = server
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2018-06-30 21:55:16 -04:00
|
|
|
|
if (eventType == "say" || eventType == "sayteam")
|
2018-04-13 02:32:30 -04:00
|
|
|
|
{
|
2018-07-04 22:09:42 -04:00
|
|
|
|
var matchResult = Regex.Match(logLine, SayRegex);
|
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
|
|
|
|
{
|
2018-07-04 22:09:42 -04:00
|
|
|
|
string message = matchResult.Groups[5].ToString()
|
|
|
|
|
.Replace("\x15", "")
|
|
|
|
|
.Trim();
|
|
|
|
|
|
|
|
|
|
if (message[0] == '!' || message[0] == '@')
|
|
|
|
|
{
|
|
|
|
|
return new GameEvent()
|
|
|
|
|
{
|
|
|
|
|
Type = GameEvent.EventType.Command,
|
|
|
|
|
Data = message,
|
|
|
|
|
Origin = server.GetPlayersAsList().First(c => c.ClientNumber == Utilities.ClientIdFromString(lineSplit, 2)),
|
|
|
|
|
Owner = server,
|
|
|
|
|
Message = message
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2018-05-10 01:34:29 -04:00
|
|
|
|
return new GameEvent()
|
|
|
|
|
{
|
2018-07-04 22:09:42 -04:00
|
|
|
|
Type = GameEvent.EventType.Say,
|
2018-05-10 01:34:29 -04:00
|
|
|
|
Data = message,
|
|
|
|
|
Origin = server.GetPlayersAsList().First(c => c.ClientNumber == Utilities.ClientIdFromString(lineSplit, 2)),
|
|
|
|
|
Owner = server,
|
|
|
|
|
Message = message
|
|
|
|
|
};
|
|
|
|
|
}
|
2018-04-13 02:32:30 -04:00
|
|
|
|
}
|
|
|
|
|
|
2018-06-30 21:55:16 -04:00
|
|
|
|
if (eventType == "ScriptKill")
|
2018-04-13 02:32:30 -04:00
|
|
|
|
{
|
|
|
|
|
return new GameEvent()
|
|
|
|
|
{
|
2018-05-10 01:34:29 -04:00
|
|
|
|
Type = GameEvent.EventType.ScriptKill,
|
2018-04-13 02:32:30 -04:00
|
|
|
|
Data = logLine,
|
|
|
|
|
Origin = server.GetPlayersAsList().First(c => c.NetworkId == lineSplit[1].ConvertLong()),
|
|
|
|
|
Target = server.GetPlayersAsList().First(c => c.NetworkId == lineSplit[2].ConvertLong()),
|
|
|
|
|
Owner = server
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2018-06-30 21:55:16 -04:00
|
|
|
|
if (eventType == "ScriptDamage")
|
2018-05-08 00:58:46 -04:00
|
|
|
|
{
|
|
|
|
|
return new GameEvent()
|
|
|
|
|
{
|
|
|
|
|
Type = GameEvent.EventType.ScriptDamage,
|
|
|
|
|
Data = logLine,
|
|
|
|
|
Origin = server.GetPlayersAsList().First(c => c.NetworkId == lineSplit[1].ConvertLong()),
|
|
|
|
|
Target = server.GetPlayersAsList().First(c => c.NetworkId == lineSplit[2].ConvertLong()),
|
|
|
|
|
Owner = server
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2018-06-07 22:19:12 -04:00
|
|
|
|
// damage
|
2018-06-30 21:55:16 -04:00
|
|
|
|
if (eventType == "D")
|
2018-05-03 01:25:49 -04:00
|
|
|
|
{
|
2018-06-30 21:55:16 -04:00
|
|
|
|
if (Regex.Match(eventType, @"^(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]|_)+)$").Success)
|
2018-05-03 01:25:49 -04:00
|
|
|
|
{
|
2018-05-14 13:55:10 -04:00
|
|
|
|
return new GameEvent()
|
|
|
|
|
{
|
|
|
|
|
Type = GameEvent.EventType.Damage,
|
2018-06-30 21:55:16 -04:00
|
|
|
|
Data = eventType,
|
2018-05-14 13:55:10 -04:00
|
|
|
|
Origin = server.GetPlayersAsList().First(c => c.NetworkId == lineSplit[5].ConvertLong()),
|
|
|
|
|
Target = server.GetPlayersAsList().First(c => c.NetworkId == lineSplit[1].ConvertLong()),
|
|
|
|
|
Owner = server
|
|
|
|
|
};
|
|
|
|
|
}
|
2018-05-03 01:25:49 -04:00
|
|
|
|
}
|
|
|
|
|
|
2018-06-07 22:19:12 -04:00
|
|
|
|
// join
|
2018-06-30 21:55:16 -04:00
|
|
|
|
if (eventType == "J")
|
2018-06-07 22:19:12 -04:00
|
|
|
|
{
|
2018-08-07 14:43:09 -04:00
|
|
|
|
var regexMatch = Regex.Match(logLine, @"^(J;)(.{1,32});([0-9]+);(.*)$");
|
2018-06-07 22:19:12 -04:00
|
|
|
|
if (regexMatch.Success)
|
|
|
|
|
{
|
|
|
|
|
return new GameEvent()
|
|
|
|
|
{
|
|
|
|
|
Type = GameEvent.EventType.Join,
|
2018-06-30 21:55:16 -04:00
|
|
|
|
Data = logLine,
|
2018-06-07 22:19:12 -04:00
|
|
|
|
Owner = server,
|
|
|
|
|
Origin = new Player()
|
|
|
|
|
{
|
2018-06-30 21:55:16 -04:00
|
|
|
|
Name = regexMatch.Groups[4].ToString().StripColors(),
|
2018-06-07 22:19:12 -04:00
|
|
|
|
NetworkId = regexMatch.Groups[2].ToString().ConvertLong(),
|
|
|
|
|
ClientNumber = Convert.ToInt32(regexMatch.Groups[3].ToString())
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-06-30 21:55:16 -04:00
|
|
|
|
if (eventType == "Q")
|
|
|
|
|
{
|
2018-08-07 14:43:09 -04:00
|
|
|
|
var regexMatch = Regex.Match(logLine, @"^(Q;)(.{1,32});([0-9]+);(.*)$");
|
2018-06-30 21:55:16 -04:00
|
|
|
|
if (regexMatch.Success)
|
|
|
|
|
{
|
|
|
|
|
return new GameEvent()
|
|
|
|
|
{
|
|
|
|
|
Type = GameEvent.EventType.Quit,
|
|
|
|
|
Data = logLine,
|
|
|
|
|
Owner = server,
|
|
|
|
|
Origin = new Player()
|
|
|
|
|
{
|
|
|
|
|
Name = regexMatch.Groups[4].ToString().StripColors(),
|
|
|
|
|
NetworkId = regexMatch.Groups[2].ToString().ConvertLong(),
|
|
|
|
|
ClientNumber = Convert.ToInt32(regexMatch.Groups[3].ToString()),
|
|
|
|
|
State = Player.ClientState.Connecting
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (eventType.Contains("ExitLevel"))
|
2018-04-13 02:32:30 -04:00
|
|
|
|
{
|
|
|
|
|
return new GameEvent()
|
|
|
|
|
{
|
|
|
|
|
Type = GameEvent.EventType.MapEnd,
|
|
|
|
|
Data = lineSplit[0],
|
|
|
|
|
Origin = new Player()
|
|
|
|
|
{
|
|
|
|
|
ClientId = 1
|
|
|
|
|
},
|
|
|
|
|
Target = new Player()
|
|
|
|
|
{
|
|
|
|
|
ClientId = 1
|
|
|
|
|
},
|
|
|
|
|
Owner = server
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
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,
|
|
|
|
|
Data = lineSplit[0],
|
|
|
|
|
Origin = new Player()
|
|
|
|
|
{
|
|
|
|
|
ClientId = 1
|
|
|
|
|
},
|
|
|
|
|
Target = new Player()
|
|
|
|
|
{
|
|
|
|
|
ClientId = 1
|
|
|
|
|
},
|
2018-04-24 18:01:27 -04:00
|
|
|
|
Owner = server,
|
|
|
|
|
Extra = dump.DictionaryFromKeyValue()
|
2018-04-13 02:32:30 -04:00
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return new GameEvent()
|
|
|
|
|
{
|
|
|
|
|
Type = GameEvent.EventType.Unknown,
|
|
|
|
|
Origin = new Player()
|
|
|
|
|
{
|
|
|
|
|
ClientId = 1
|
|
|
|
|
},
|
|
|
|
|
Target = new Player()
|
|
|
|
|
{
|
|
|
|
|
ClientId = 1
|
|
|
|
|
},
|
|
|
|
|
Owner = server
|
|
|
|
|
};
|
|
|
|
|
}
|
2018-04-15 00:26:27 -04:00
|
|
|
|
|
|
|
|
|
// other parsers can derive from this parser so we make it virtual
|
|
|
|
|
public virtual string GetGameDir() => "userraw";
|
2018-04-13 02:32:30 -04:00
|
|
|
|
}
|
|
|
|
|
}
|