private void Finish(DateTime dt, GameLogEvent evData) { evData.IsFinished = true; evData.Duration = dt - evData.Timestamp; if (evData.GameLogEventID != 0) { _context.Update(evData); } }
protected override void AppendEvent(GameLogEvent gameLogEvent, GameSnapshot gameSnapshot) { base.AppendEvent(gameLogEvent, gameSnapshot); using var context = new DosDbContext(); context.ReplayMove.Add(new ReplayMove { TargetPlayer = gameLogEvent.TargetPlayer, SourcePlayer = gameLogEvent.SourcePlayer, Cards = gameLogEvent.Cards, EventType = gameLogEvent.EventType, ReplayId = replayId }); context.ReplaySnapshot.Add(new ReplaySnapshot { CenterRow = gameSnapshot.CenterRow, PlayerHands = gameSnapshot.PlayerHands, ReplayId = replayId, CurrentPlayerId = gameSnapshot.CurrentPlayerId, }); context.SaveChanges(); }
private void PlayerEvent(Dictionary <string, GameLogEvent> dict, GameLogEvent evData) { GameLogEvent st; if (dict.TryGetValue(evData.SteamId, out st)) { if (evData.Type == GameLogEventType.Disconnect) { _context.GameLogEvents.Add(evData); Finish(evData.Timestamp, st); dict.Remove(evData.SteamId); } } else { if (evData.Type == GameLogEventType.Connect) { _context.GameLogEvents.Add(evData); dict[evData.SteamId] = evData; } } }
private async Task ProcessArmaLogFile(GameServer server, SftpClient client, SftpFile actualFile, GameLogFile logFileInfos) { var data = await ReadData(client, actualFile, logFileInfos); logFileInfos.LastSyncUTC = DateTime.UtcNow; if (logFileInfos.GameLogFileID == 0) { _context.Add(logFileInfos); } else { _context.Update(logFileInfos); } var playerConnectEvents = await _context.GameLogEvents .Where(e => e.Type == GameLogEventType.Connect && !e.IsFinished && e.GameServerID == server.GameServerID) .ToDictionaryAsync(e => e.SteamId, e => e); var lineMatch = 0; foreach (var line in data.Split("\r\n")) { var match = ArmaLineRegex.Match(line); if (match.Success) { lineMatch++; var lineData = match.Groups[7].Value; if (lineData == "Starting mission:") { var dt = ParseDateTime(match); foreach (var evData in playerConnectEvents.Values) { Finish(dt, evData); } playerConnectEvents = new Dictionary <string, GameLogEvent>(); } else if (lineData.StartsWith("OPC DATA") || lineData.StartsWith("OPD DATA")) { var ev = AramaSteamIdQuotedRegex.Match(lineData); if (ev.Success) { var evData = new GameLogEvent() { Timestamp = ParseDateTime(match), SteamId = ev.Groups[1].Value, Server = server, Type = lineData.StartsWith("OPD DATA") ? GameLogEventType.Disconnect : GameLogEventType.Connect }; PlayerEvent(playerConnectEvents, evData); } } else if (lineData.StartsWith("[GTD] (persistence)")) { var ev = ArmaConnectRegex.Match(lineData); if (ev.Success) { var evData = new GameLogEvent() { Timestamp = ParseDateTime(match), SteamId = ev.Groups[2].Value, Server = server, Type = ev.Groups[1].Value == "Saved" ? GameLogEventType.Disconnect : GameLogEventType.Connect }; PlayerEvent(playerConnectEvents, evData); } } } } _logger.LogInformation("{0} matching lines", lineMatch); await _context.SaveChangesAsync(); }