private void talker_SpringEvent(object sender, Talker.SpringEventArgs e) { try { switch (e.EventType) { case Talker.SpringEventType.PLAYER_JOINED: var entry = Context?.GetOrAddPlayer(e.PlayerName); if (entry != null) { entry.IsIngame = true; } PlayerJoined?.Invoke(this, new SpringLogEventArgs(e.PlayerName)); break; case Talker.SpringEventType.PLAYER_LEFT: entry = Context?.GetOrAddPlayer(e.PlayerName); if (entry != null) { entry.IsIngame = false; entry.QuitTime = (int)DateTime.UtcNow.Subtract(Context.IngameStartTime ?? Context.StartTime).TotalSeconds; } if (e.Param == 0) { PlayerDisconnected?.Invoke(this, new SpringLogEventArgs(e.PlayerName)); } PlayerLeft?.Invoke(this, new SpringLogEventArgs(e.PlayerName)); break; case Talker.SpringEventType.GAME_LUAMSG: HandleSpecialMessages(e); break; case Talker.SpringEventType.PLAYER_CHAT: if (e.Param == 255) { HandleSpecialMessages(e); } else { AddToLogs(e); } if ((PlayerSaid != null) && !string.IsNullOrEmpty(e.PlayerName)) { SpringChatLocation location = SpringChatLocation.Private; if (((e.Param == Talker.TO_EVERYONE) || (e.Param == Talker.TO_EVERYONE_LEGACY))) { location = SpringChatLocation.Public; } if (e.Param == Talker.TO_ALLIES) { location = SpringChatLocation.Allies; } if (e.Param == Talker.TO_SPECTATORS) { location = SpringChatLocation.Spectators; } PlayerSaid(this, new SpringChatEventArgs(e.PlayerName, e.Text, location)); } break; case Talker.SpringEventType.PLAYER_DEFEATED: MarkPlayerDead(e.PlayerName, true); if (PlayerLost != null) { PlayerLost(this, new SpringLogEventArgs(e.PlayerName)); } break; case Talker.SpringEventType.SERVER_GAMEOVER: if (!Context.GameEndedOk) // server gameover runs multiple times { foreach (var p in Context.ActualPlayers) { if (!p.IsIngame && !p.IsSpectator) { MarkPlayerDead(p.Name, true); } p.IsIngame = false; } // set victory team for all allied with currently alive if (e.winningAllyTeams.Length > 0) { foreach (var ally in e.winningAllyTeams) { foreach (var p in Context.ActualPlayers.Where(x => !x.IsSpectator && (x.AllyNumber == ally))) { p.IsVictoryTeam = true; } } } else // Fallback, shouldn't happen { foreach (var p in Context.ActualPlayers.Where(x => !x.IsSpectator && (x.LoseTime == null))) { foreach (var q in Context.ActualPlayers.Where(x => !x.IsSpectator && (x.AllyNumber == p.AllyNumber))) { q.IsVictoryTeam = true; } } } if (Context.IngameStartTime != null) { Context.GameEndedOk = true; Context.Duration = (int)DateTime.UtcNow.Subtract(Context.IngameStartTime ?? Context.StartTime).TotalSeconds; GameOver?.Invoke(this, new SpringLogEventArgs(e.PlayerName)); } else { Trace.TraceWarning("recieved GAMEOVER before STARTPLAYING!"); } Task.Delay(10000).ContinueWith(x => ExitGame()); } break; case Talker.SpringEventType.PLAYER_READY: if (e.Param == 1) { entry = Context.GetOrAddPlayer(e.PlayerName); if (entry != null) { entry.IsIngameReady = true; } } break; case Talker.SpringEventType.SERVER_STARTPLAYING: Context.ReplayName = e.ReplayFileName; Context.EngineBattleID = e.GameID; Context.IngameStartTime = DateTime.UtcNow; Context.PlayersUnreadyOnStart = Context.ActualPlayers.Where(x => !x.IsSpectator && !(x.IsIngameReady && x.IsIngame)).Select(x => x.Name).ToList(); foreach (var p in Context.ActualPlayers.Where(x => !x.IsSpectator)) { p.IsIngameReady = true; } process.PriorityClass = ProcessPriorityClass.High; BattleStarted(this, Context); break; case Talker.SpringEventType.SERVER_QUIT: if (LobbyStartContext != null) { foreach (var p in Context.ActualPlayers) { p.IsIngame = false; } } //if (GameOver != null) GameOver(this, new SpringLogEventArgs(e.PlayerName)); break; } } catch (Exception ex) { Trace.TraceError("Error processing spring message:{0}", ex); } }
public SpringChatEventArgs(string username, string line, SpringChatLocation location) : base(username, line) { this.Location = location; }