add initial CS:GO support

This commit is contained in:
RaidMax
2021-06-03 10:51:03 -05:00
parent 9488f754d4
commit be08d49f0a
38 changed files with 873 additions and 197 deletions

View File

@ -176,6 +176,12 @@ namespace IW4MAdmin.Plugins.Stats.Client
foreach (var hitInfo in new[] {attackerHitInfo, victimHitInfo})
{
if (hitInfo.MeansOfDeath == null || hitInfo.Location == null || hitInfo.Weapon == null)
{
_logger.LogDebug("Skipping hit because it does not contain the required data");
continue;
}
try
{
await _onTransaction.WaitAsync();

View File

@ -15,13 +15,13 @@ namespace Stats.Client
private readonly IWeaponNameParser _weaponNameParser;
private readonly ILogger _logger;
private const int MaximumDamage = 1000;
public HitInfoBuilder(ILogger<HitInfoBuilder> logger, IWeaponNameParser weaponNameParser)
{
_weaponNameParser = weaponNameParser;
_logger = logger;
}
public HitInfo Build(string[] log, int entityId, bool isSelf, bool isVictim, Server.Game gameName)
{
var eventType = log[(uint) ParserRegex.GroupType.EventType].First();
@ -50,11 +50,19 @@ namespace Stats.Client
EntityId = entityId,
IsVictim = isVictim,
HitType = hitType,
Damage = Math.Min(MaximumDamage, int.Parse(log[(uint) ParserRegex.GroupType.Damage])),
Location = log[(uint) ParserRegex.GroupType.HitLocation],
Weapon = _weaponNameParser.Parse(log[(uint) ParserRegex.GroupType.Weapon], gameName),
MeansOfDeath = log[(uint)ParserRegex.GroupType.MeansOfDeath],
Game = (Reference.Game)gameName
Damage = Math.Min(MaximumDamage,
log.Length > (uint) ParserRegex.GroupType.Damage
? int.Parse(log[(uint) ParserRegex.GroupType.Damage])
: 0),
Location = log.Length > (uint) ParserRegex.GroupType.HitLocation
? log[(uint) ParserRegex.GroupType.HitLocation]
: "Unknown",
Weapon = log.Length == 10 ? _weaponNameParser.Parse(log[8], gameName)
: _weaponNameParser.Parse(log[(uint) ParserRegex.GroupType.Weapon], gameName),
MeansOfDeath = log.Length > (uint) ParserRegex.GroupType.MeansOfDeath
? log[(uint) ParserRegex.GroupType.MeansOfDeath]
: "Unknown",
Game = (Reference.Game) gameName
};
//_logger.LogDebug("Generated new hitInfo {@hitInfo}", hitInfo);

View File

@ -6,6 +6,7 @@ using System.Linq;
using IW4MAdmin.Plugins.Stats.Config;
using SharedLibraryCore;
using SharedLibraryCore.Interfaces;
using Stats.Config;
using ILogger = Microsoft.Extensions.Logging.ILogger;
namespace Stats.Client
@ -24,22 +25,16 @@ namespace Stats.Client
public WeaponInfo Parse(string weaponName, Server.Game gameName)
{
var configForGame = _config.WeaponNameParserConfigurations
?.FirstOrDefault(config => config.Game == gameName);
if (configForGame == null)
?.FirstOrDefault(config => config.Game == gameName) ?? new WeaponNameParserConfiguration()
{
_logger.LogWarning("No weapon parser config available for game {game}", gameName);
return new WeaponInfo()
{
Name = "Unknown"
};
}
Game = gameName
};
var splitWeaponName = weaponName.Split(configForGame.Delimiters);
if (!splitWeaponName.Any())
{
_logger.LogError("Could not parse weapon name {weapon}", weaponName);
_logger.LogError("Could not parse weapon name {Weapon}", weaponName);
return new WeaponInfo()
{