public bool TryAddKill(Game parent, Killing kill, IEnumerable <KillAssist> killAssists) { var dateTime = new DateTime(kill.TimeStamp); if (Start > dateTime || dateTime > End) { return(false); } double killTime = (dateTime - Start).TotalSeconds; var assists = new List <Assist>(); foreach (var ka in killAssists) { //obtain weapon var weaponName = Strings.TrimName(ka.Weapon).ToString(); var weapon = parent.Weapons.Find(x => Strings.NameEquals(weaponName, x.Name)); if (weapon == null) //create new weapon { var criticalDamage = ka.IsCriticalDamage ? ka.TotalDamage : 0.0; var armorDamage = ka.IsCriticalDamage ? ka.TotalDamage : 0.0; weapon = new Weapon(weaponName, criticalDamage, armorDamage); } assists.Add(new Assist(ka.Assistant, weapon, ka.Elapsed, ka.TotalDamage, ka.DamageFlags)); } Kills.Add(new Kill(killTime, kill.Killer, kill.Victim, assists)); return(true); }
public override async Task ExitAsync(ChromiumProcess p, TimeSpan timeout) { var waitForExitTask = WaitForExitAsync(p); await waitForExitTask.WithTimeout(async() => { await Killing.EnterFromAsync(p, this).ConfigureAwait(false); await waitForExitTask.ConfigureAwait(false); }, timeout).ConfigureAwait(false); }
public override async Task ExitAsync(LauncherBase p, TimeSpan timeout) { var waitForExitTask = WaitForExitAsync(p); await waitForExitTask.WithTimeout( async() => { await Killing.EnterFromAsync(p, this).ConfigureAwait(false); await waitForExitTask.ConfigureAwait(false); }, timeout, CancellationToken.None).ConfigureAwait(false); }
public override async Task ExitAsync(ChromiumProcess p, TimeSpan timeout) { var timeoutTask = Task.Delay(timeout); var waitForExitTask = WaitForExitAsync(p); var completedTask = await Task.WhenAny(waitForExitTask, timeoutTask).ConfigureAwait(false); if (completedTask == timeoutTask) { await Killing.EnterFromAsync(p, this).ConfigureAwait(false); await waitForExitTask.ConfigureAwait(false); } }
public void Kill() { Killing?.Invoke(this, EventArgs.Empty); LockProcesses(() => { _killProcesses = true; foreach (var p in Processes) { Kill(p); } }); }
public override Task KillAsync(ChromiumProcess p) => Killing.EnterFromAsync(p, this);
private async Task StartCoreAsync(ChromiumProcess p) { var output = new StringBuilder(); void OnProcessDataReceivedWhileStarting(object sender, DataReceivedEventArgs e) { if (e.Data != null) { output.AppendLine(e.Data); var match = Regex.Match(e.Data, "^DevTools listening on (ws:\\/\\/.*)"); if (match.Success) { p._startCompletionSource.TrySetResult(match.Groups[1].Value); } } } void OnProcessExitedWhileStarting(object sender, EventArgs e) => p._startCompletionSource.TrySetException(new ChromiumProcessException($"Failed to launch Chromium! {output}")); void OnProcessExited(object sender, EventArgs e) => Exited.EnterFrom(p, p._currentState); p.Process.ErrorDataReceived += OnProcessDataReceivedWhileStarting; p.Process.Exited += OnProcessExitedWhileStarting; p.Process.Exited += OnProcessExited; CancellationTokenSource cts = null; try { p.Process.Start(); await Started.EnterFromAsync(p, this).ConfigureAwait(false); p.Process.BeginErrorReadLine(); var timeout = p._options.Timeout; if (timeout > 0) { cts = new CancellationTokenSource(timeout); cts.Token.Register(() => p._startCompletionSource.TrySetException( new ChromiumProcessException($"Timed out after {timeout} ms while trying to connect to Chromium!"))); } try { await p._startCompletionSource.Task.ConfigureAwait(false); await Started.EnterFromAsync(p, this).ConfigureAwait(false); } catch { await Killing.EnterFromAsync(p, this).ConfigureAwait(false); throw; } } finally { cts?.Dispose(); p.Process.Exited -= OnProcessExitedWhileStarting; p.Process.ErrorDataReceived -= OnProcessDataReceivedWhileStarting; } }
public override Task KillAsync(LauncherBase p) => Killing.EnterFromAsync(p, this);
public static List <Player> ParsePlayers(IEnumerable <ILogEntry> gameLog) { var players = new List <Player>(); Killing currentKill = null; foreach (var pll in gameLog.Where(x => x is PlayerLoad).Cast <PlayerLoad>()) { players.Add(new Player(pll)); } if (players.Count == 0) { throw new PlayerNotFoundException("Log contains no players", nameof(gameLog)); } foreach (var logEntry in gameLog) { if (logEntry is Damage dmg) { var attacker = players.Find(x => NameEquals(dmg.Attacker, x.Name)); var victim = players.Find(x => NameEquals(dmg.Victim, x.Name)); if (attacker is null || victim is null) { continue; } double criticalDamage, armorDamage; if (dmg.IsCriticalDamage()) { criticalDamage = dmg.DamageAmmount; armorDamage = 0.0; } else { criticalDamage = 0.0; armorDamage = dmg.DamageAmmount; } attacker.ArmorDamageDealt += armorDamage; attacker.CriticalDamageDealt += criticalDamage; var weaponName = TrimName(dmg.Weapon).ToString(); var weapon = attacker.Weapons.Find(x => NameEquals(weaponName, x.Name)); if (weapon == null) { attacker.Weapons.Add(new Weapon(weaponName, criticalDamage, armorDamage)); } else { weapon.ArmorDamage += armorDamage; weapon.CriticalDamage += criticalDamage; } victim.ArmorDamageTaken += armorDamage; victim.CriticalDamageTaken += criticalDamage; } else if (logEntry is Score score) { var player = players.Find(x => x.PlayerIndex == score.PlayerNumber); if (player != null) { player.Score += score.ScoreAmmount; } } else if (logEntry is Killing kill) { var attacker = players.Find(x => NameEquals(kill.Killer, x.Name)); var victim = players.Find(x => NameEquals(kill.Victim, x.Name)); if (Kill.IsValidKill(attacker, victim)) { attacker.Kills++; victim.Deaths++; currentKill = kill; } } else if (currentKill != null && logEntry is KillAssist assist) { var assistant = players.Find(x => NameEquals(x.Name, assist.Assistant)); if (assistant != null && !NameEquals(assistant.Name, currentKill.Killer)) { assistant.Assists++; } } else if (logEntry is Decal decal) { var player = players.Find(x => x.PlayerIndex == decal.PlayerNumber); if (player is null) { continue; } var stripe = player.Stripes.Find(x => NameEquals(decal.StripeName, x.Name)); if (stripe != null) { stripe.Ammount++; } else if (player != null) { player.Stripes.Add(new Stripe(decal.StripeName, decal.AwardAmmount)); } } } //merge players from different rounds var playersDistinct = new List <Player>(); foreach (IGrouping <int, Player> group in players.GroupBy(x => x.UserID)) { Player distinct = null; foreach (var player in group) { if (distinct == null) { distinct = player; } else { PlayerBase.Merge(distinct, player); } } playersDistinct.Add(distinct); } return(playersDistinct); }
public override Task KillAsync(FirefoxProcessManager p) => Killing.EnterFromAsync(p, this);
public bool TryAdd(ReadOnlySpan <char> logLine) { if (LevelLoad.TryParse(logLine, LogDate, out var ll)) { Current = ll; LoadLevelList.Add(ll); } else if (TestDriveStart.TryParse(logLine, LogDate, out var std)) { Current = std; StartTestDriveList.Add(std); } else if (TestDriveFinish.TryParse(logLine, LogDate, out var ftd)) { Current = ftd; FinishTestDriveList.Add(ftd); } else if (GameStart.TryParse(logLine, LogDate, out var sg)) { Current = sg; StartGameList.Add(sg); } else if (GameFinish.TryParse(logLine, LogDate, out var fg)) { Current = fg; FinishGameList.Add(fg); } else if (GameRound.TryParse(logLine, LogDate, out var rg)) { Current = rg; RoundGameList.Add(rg); } else if (ActiveBattleStart.TryParse(logLine, LogDate, out var sab)) { Current = sab; StartActiveBattleList.Add(sab); } else if (PlayerLoad.TryParse(logLine, LogDate, out var pl)) { Current = pl; PlayerLoadList.Add(pl); } else if (Damage.TryParse(logLine, LogDate, out var dmg)) { Current = dmg; DamageList.Add(dmg); } else if (Killing.TryParse(logLine, LogDate, out var kill)) { Current = kill; KillList.Add(kill); } else if (KillAssist.TryParse(logLine, LogDate, out var ka)) { Current = ka; KillAssistList.Add(ka); } else if (Score.TryParse(logLine, LogDate, out var sc)) { Current = sc; ScoreList.Add(sc); } else if (Decal.TryParse(logLine, LogDate, out var dec)) { Current = dec; DecalList.Add(dec); } else { Current = null; return(false); } //update datetimes var currentDateTime = new DateTime(Current.TimeStamp); if (currentDateTime > Last) { Last = currentDateTime; } if (currentDateTime < First) { First = currentDateTime; } return(true); }