protected void SendTeamUpdate(TeamInfo team) { if (team == null) { return; } MsgTeamUpdate tUpd = new MsgTeamUpdate(); MsgTeamUpdate.TeamUpdate u = new MsgTeamUpdate.TeamUpdate(); u.TeamID = team.Team; u.Size = team.Size(); u.Wins = team.Wins; u.Losses = team.Losses; tUpd.TeamUpdates.Add(u); SendToAll(tUpd, false); }
public virtual bool AddPlayer(ServerPlayer player) { player.Exited += Player_Exited; player.Disconnected += Player_Exited; ServerHost.PreAddPlayer(player); if (player.ActualTeam == TeamColors.NoTeam) { return(false); } player.Info = new PlayerInfo(); lock (PlayerList) PlayerList.Add(player); Logger.Log2("Player " + player.Callsign + " assigned to team " + player.ActualTeam.ToString()); lock (Teams) { if (!Teams.ContainsKey(player.ActualTeam)) { TeamInfo team = new TeamInfo(); team.Team = player.ActualTeam; team.PlayerAdded += Team_PlayerAdded; team.PlayerRemoved += Team_PlayerRemoved; Teams.Add(player.ActualTeam, team); } Teams[player.ActualTeam].Add(player); if (Teams[player.ActualTeam].Members.Count == 1) { TeamInited?.Invoke(this, Teams[player.ActualTeam]); } } Flags.SendInitialFlagUpdate(player); // tell them about everyone except them ServerPlayer[] locals = null; lock (PlayerList) locals = PlayerList.ToArray(); MsgPlayerInfo info = new MsgPlayerInfo(); foreach (ServerPlayer peer in locals) { if (peer == player) { continue; } player.SendMessage(true, BuildPlayerAdd(peer)); info.PlayerUpdates.Add(GetPlayerInfo(peer)); } player.SendMessage(true, info); TeamInfo[] teams = null; lock (Teams) teams = Teams.Values.ToArray(); MsgTeamUpdate tUpd = new MsgTeamUpdate(); foreach (var team in teams) { if (team.Team == player.ActualTeam) // the event already sent this { continue; } MsgTeamUpdate.TeamUpdate u = new MsgTeamUpdate.TeamUpdate(); u.TeamID = team.Team; u.Size = team.Size(); u.Wins = team.Wins; u.Losses = team.Losses; tUpd.TeamUpdates.Add(u); } player.SendMessage(tUpd); // tell everyone they joined SendToAll(BuildPlayerAdd(player), false); // send info bits to everyone info = new MsgPlayerInfo(); info.PlayerUpdates.Add(GetPlayerInfo(player)); SendToAll(info, false); ServerHost.PostAddPlayer(player); if (player.ActualTeam == TeamColors.ObserverTeam) { Chat.SendChatToUser(null, player, Resources.ObserverModeNotificatioMessage, false); } return(true); }