private void Lobby_OnMessageReceived(object sender, object message)
        {
            if (message == null)
                return;

            if (message.GetType() != typeof(GameDTO))
                return;

            var dto = message as GameDTO;
            Dispatcher.BeginInvoke(DispatcherPriority.Input, new ThreadStart(async () =>
            {
                if (!HasConnectedToChat)
                {
                    //Run once
                    BaseMap map = BaseMap.GetMap(dto.MapId);
                    MapLabel.Content = map.DisplayName;
                    ModeLabel.Content = Client.TitleCaseString(dto.GameMode);
                    GameTypeConfigDTO configType = Client.LoginPacket.GameTypeConfigs.Find(x => x.Id == dto.GameTypeConfigId);
                    TypeLabel.Content = GetGameMode(configType.Id);
                    SizeLabel.Content = dto.MaxNumPlayers / 2 + "v" + dto.MaxNumPlayers / 2;

                    HasConnectedToChat = true;

                    string obfuscatedName = Client.GetObfuscatedChatroomName(dto.Name.ToLower() + Convert.ToInt64(dto.Id), ChatPrefixes.Arranging_Practice);
                    string Jid = Client.GetChatroomJid(obfuscatedName, dto.RoomPassword, false);
                    newRoom = new MucManager(Client.XmppConnection);
                    Client.XmppConnection.OnMessage +=XmppConnection_OnMessage;
                    Client.XmppConnection.OnPresence += XmppConnection_OnPresence;
                    roomJid = new Jid(Jid);
                    newRoom.AcceptDefaultConfiguration(roomJid);
                    newRoom.JoinRoom(roomJid, Client.LoginPacket.AllSummonerData.Summoner.Name);
                }
                switch (dto.GameState)
                {
                    case "TEAM_SELECT":
                        {
                            bool isSpectator = false;
                            OptomisticLock = dto.OptimisticLock;
                            LaunchedTeamSelect = false;
                            BlueTeamListView.Items.Clear();
                            PurpleTeamListView.Items.Clear();
                            SpectatorListView.Items.Clear();

                            foreach (Participant playerTeam in dto.TeamOne)
                            {
                                if (playerTeam is PlayerParticipant)
                                {
                                    var lobbyPlayer = new CustomLobbyPlayer();
                                    var player = playerTeam as PlayerParticipant;
                                    lobbyPlayer = RenderPlayer(player, dto.OwnerSummary.SummonerId == player.SummonerId);
                                    Client.isOwnerOfGame = dto.OwnerSummary.SummonerId == Client.LoginPacket.AllSummonerData.Summoner.SumId;
                                    StartGameButton.IsEnabled = Client.isOwnerOfGame;
                                    AddBotBlueTeam.IsEnabled = Client.isOwnerOfGame;
                                    AddBotPurpleTeam.IsEnabled = Client.isOwnerOfGame;

                                    BlueTeamListView.Items.Add(lobbyPlayer);

                                    if (Client.Whitelist.Count <= 0)
                                        continue;

                                    if (!Client.Whitelist.Contains(player.SummonerName.ToLower()))
                                        await RiotCalls.BanUserFromGame(Client.GameID, player.AccountId);
                                }
                                else if (playerTeam is BotParticipant)
                                {
                                    var botParticipant = playerTeam as BotParticipant;
                                    var botPlayer = new BotControl();
                                    botPlayer = RenderBot(botParticipant);
                                    BlueTeamListView.Items.Add(botPlayer);
                                }
                            }
                            foreach (Participant playerTeam in dto.TeamTwo)
                            {
                                if (playerTeam is PlayerParticipant)
                                {
                                    var lobbyPlayer = new CustomLobbyPlayer();
                                    var player = playerTeam as PlayerParticipant;
                                    lobbyPlayer = RenderPlayer(player, dto.OwnerSummary.SummonerId == player.SummonerId);
                                    Client.isOwnerOfGame = dto.OwnerSummary.SummonerId == Client.LoginPacket.AllSummonerData.Summoner.SumId;
                                    StartGameButton.IsEnabled = Client.isOwnerOfGame;
                                    AddBotBlueTeam.IsEnabled = Client.isOwnerOfGame;
                                    AddBotPurpleTeam.IsEnabled = Client.isOwnerOfGame;

                                    PurpleTeamListView.Items.Add(lobbyPlayer);

                                    if (Client.Whitelist.Count <= 0)
                                        continue;

                                    if (!Client.Whitelist.Contains(player.SummonerName.ToLower()))
                                        await RiotCalls.BanUserFromGame(Client.GameID, player.AccountId);
                                }
                                else if (playerTeam is BotParticipant)
                                {
                                    var botParticipant = playerTeam as BotParticipant;
                                    var botPlayer = new BotControl();
                                    botPlayer = RenderBot(botParticipant);
                                    PurpleTeamListView.Items.Add(botPlayer);
                                }
                            }
                            foreach (GameObserver observer in dto.Observers)
                            {
                                if (observer.SummonerId == Client.LoginPacket.AllSummonerData.Summoner.SumId)
                                    isSpectator = true;

                                var spectatorItem = new CustomLobbyObserver();

                                spectatorItem = RenderObserver(observer);
                                SpectatorListView.Items.Add(spectatorItem);
                            }
                            if (isSpectator)
                            {
                                AddBotPurpleTeam.Visibility = Visibility.Hidden;
                                AddBotBlueTeam.Visibility = Visibility.Hidden;
                                JoinBlueTeamFromSpectator.Visibility = Visibility.Visible;
                                JoinPurpleTeamFromSpectator.Visibility = Visibility.Visible;
                            }
                            else
                            {
                                AddBotPurpleTeam.Visibility = Visibility.Visible;
                                AddBotBlueTeam.Visibility = Visibility.Visible;
                                JoinBlueTeamFromSpectator.Visibility = Visibility.Hidden;
                                JoinPurpleTeamFromSpectator.Visibility = Visibility.Hidden;
                            }
                        }
                        break;
                    case "PRE_CHAMP_SELECT":
                    case "CHAMP_SELECT":
                        if (!LaunchedTeamSelect)
                        {
                            Client.ChampSelectDTO = dto;
                            Client.LastPageContent = Client.Container.Content;
                            Client.SwitchPage(new ChampSelectPage(dto.RoomName, dto.RoomPassword).Load(this));
                            Client.GameStatus = "championSelect";
                            Client.SetChatHover();
                            LaunchedTeamSelect = true;
                        }
                        break;
                }
            }));
        }
        private CustomLobbyPlayer RenderPlayer(PlayerParticipant player, bool IsOwner)
        {
            var lobbyPlayer = new CustomLobbyPlayer
            {
                PlayerName =
                {
                    Content = player.SummonerName
                }
            };
            var UriSource = new System.Uri(Path.Combine(Client.ExecutingDirectory, "Assets", "profileicon", player.ProfileIconId + ".png"), UriKind.RelativeOrAbsolute);
            lobbyPlayer.ProfileImage.Source = new BitmapImage(UriSource);
            if (IsOwner)
                lobbyPlayer.OwnerLabel.Visibility = Visibility.Visible;

            lobbyPlayer.Width = 400;
            lobbyPlayer.Margin = new Thickness(0, 0, 0, 5);
            if ((player.SummonerId == Client.LoginPacket.AllSummonerData.Summoner.SumId) || (player.SummonerId != Client.LoginPacket.AllSummonerData.Summoner.SumId && !Client.isOwnerOfGame))
                lobbyPlayer.BanButton.Visibility = Visibility.Hidden;

            lobbyPlayer.BanButton.Tag = player;
            lobbyPlayer.BanButton.Click += KickAndBan_Click;

            return lobbyPlayer;
        }
        private void GameLobby_OnMessageReceived(object sender, object message)
        {
            if (message.GetType() == typeof(GameDTO))
            {
                GameDTO dto = message as GameDTO;
                Dispatcher.BeginInvoke(DispatcherPriority.Input, new ThreadStart(async () =>
                {
                    MapId = dto.MapId;
                    GameId = dto.Id;
                    if (!HasConnectedToChat)
                    {
                        //Run once
                        BaseMap map = BaseMap.GetMap(dto.MapId);
                        MapLabel.Content = map.DisplayName;
                        ModeLabel.Content = Client.TitleCaseString(dto.GameMode);
                        GameTypeConfigDTO configType = Client.LoginPacket.GameTypeConfigs.Find(x => x.Id == dto.GameTypeConfigId);
                        TypeLabel.Content = GetGameMode(configType.Id);
                        SizeLabel.Content = dto.MaxNumPlayers / 2 + "v" + dto.MaxNumPlayers / 2;

                        HasConnectedToChat = true;
                        string ObfuscatedName = Client.GetObfuscatedChatroomName(dto.Name.ToLower() + Convert.ToInt32(dto.Id), ChatPrefixes.Arranging_Practice);
                        string JID = Client.GetChatroomJID(ObfuscatedName, dto.RoomPassword, false);
                        newRoom = Client.ConfManager.GetRoom(new jabber.JID(JID));
                        newRoom.Nickname = Client.LoginPacket.AllSummonerData.Summoner.Name;
                        newRoom.OnRoomMessage += newRoom_OnRoomMessage;
                        newRoom.OnParticipantJoin += newRoom_OnParticipantJoin;
                        newRoom.Join(dto.RoomPassword);
                    }
                    if (dto.GameState == "TEAM_SELECT")
                    {
                        OptomisticLock = dto.OptimisticLock;
                        LaunchedTeamSelect = false;
                        BlueTeamListView.Items.Clear();
                        PurpleTeamListView.Items.Clear();

                        List<Participant> AllParticipants = new List<Participant>(dto.TeamOne.ToArray());
                        AllParticipants.AddRange(dto.TeamTwo);

                        int i = 0;
                        bool PurpleSide = false;

                        foreach (Participant playerTeam in AllParticipants)
                        {
                            i++;
                            CustomLobbyPlayer lobbyPlayer = new CustomLobbyPlayer();
                            if (playerTeam is PlayerParticipant)
                            {
                                PlayerParticipant player = playerTeam as PlayerParticipant;
                                lobbyPlayer = RenderPlayer(player, dto.OwnerSummary.SummonerId == player.SummonerId);
                                IsOwner = dto.OwnerSummary.SummonerId == Client.LoginPacket.AllSummonerData.Summoner.SumId;
                                StartGameButton.IsEnabled = IsOwner;
                                WhitelistAddButton.IsEnabled = IsOwner;

                                if (Client.Whitelist.Count > 0)
                                {
                                    if (!Client.Whitelist.Contains(player.SummonerName.ToLower()) && player.SummonerId != Client.LoginPacket.AllSummonerData.Summoner.SumId && IsOwner)
                                    {
                                        await Client.PVPNet.BanUserFromGame(Client.GameID, player.AccountId);
                                    }
                                }
                            }

                            if (i > dto.TeamOne.Count)
                            {
                                i = 0;
                                PurpleSide = true;
                            }

                            if (!PurpleSide)
                            {
                                BlueTeamListView.Items.Add(lobbyPlayer);
                            }
                            else
                            {
                                PurpleTeamListView.Items.Add(lobbyPlayer);
                            }
                        }
                    }
                    else if (dto.GameState == "CHAMP_SELECT" || dto.GameState == "PRE_CHAMP_SELECT")
                    {
                        if (!LaunchedTeamSelect)
                        {
                            Client.ChampSelectDTO = dto;
                            Client.LastPageContent = Client.Container.Content;
                            Client.SwitchPage(new ChampSelectPage());
                            LaunchedTeamSelect = true;
                        }
                    }
                }));
            }
        }
        private CustomLobbyPlayer RenderPlayer(PlayerParticipant player, bool IsOwner)
        {
            CustomLobbyPlayer lobbyPlayer = new CustomLobbyPlayer();
            lobbyPlayer.PlayerName.Content = player.SummonerName;

            string uriSource = Path.Combine(Client.ExecutingDirectory, "Assets", "profileicon", player.ProfileIconId + ".png");
            lobbyPlayer.ProfileImage.Source = Client.GetImage(uriSource);

            if (IsOwner)
                lobbyPlayer.OwnerLabel.Visibility = Visibility.Visible;
            lobbyPlayer.Width = 400;
            lobbyPlayer.Margin = new Thickness(0, 0, 0, 5);
            if ((player.SummonerId == Client.LoginPacket.AllSummonerData.Summoner.SumId) ||
                (player.SummonerId != Client.LoginPacket.AllSummonerData.Summoner.SumId && !this.IsOwner))
            {
                lobbyPlayer.BanButton.Visibility = Visibility.Hidden;
            }
            lobbyPlayer.BanButton.Tag = player;
            lobbyPlayer.BanButton.Click += KickAndBan_Click;
            return lobbyPlayer;
        }
        private void Lobby_OnMessageReceived(object sender, object message)
        {
            if (message.GetType() != typeof(GameDTO))
                return;

            var dto = message as GameDTO;
            Dispatcher.BeginInvoke(DispatcherPriority.Input, new ThreadStart(async () =>
            {
                if (!HasConnectedToChat)
                {
                    //Run once
                    BaseMap map = BaseMap.GetMap(dto.MapId);
                    MapLabel.Content = map.DisplayName;
                    ModeLabel.Content = Client.TitleCaseString(dto.GameMode);
                    GameTypeConfigDTO configType =
                        Client.LoginPacket.GameTypeConfigs.Find(x => x.Id == dto.GameTypeConfigId);
                    TypeLabel.Content = GetGameMode(configType.Id);
                    SizeLabel.Content = dto.MaxNumPlayers / 2 + "v" + dto.MaxNumPlayers / 2;

                    HasConnectedToChat = true;
                    string obfuscatedName =
                        Client.GetObfuscatedChatroomName(dto.Name.ToLower() + Convert.ToInt32(dto.Id),
                            ChatPrefixes.Arranging_Practice);
                    string Jid = Client.GetChatroomJid(obfuscatedName, dto.RoomPassword, false);
                    newRoom = new MucManager(Client.XmppConnection);
                    Client.XmppConnection.OnMessage += XmppConnection_OnMessage;
                    Client.XmppConnection.OnPresence += XmppConnection_OnPresence;
                    jid = new Jid(dto.RoomName);
                    newRoom.AcceptDefaultConfiguration(jid);
                    newRoom.JoinRoom(jid, Client.LoginPacket.AllSummonerData.Summoner.Name, dto.RoomPassword);
                }
                switch (dto.GameState)
                {
                    case "TEAM_SELECT":
                        {
                            OptomisticLock = dto.OptimisticLock;
                            LaunchedTeamSelect = false;
                            BlueTeamListView.Items.Clear();
                            PurpleTeamListView.Items.Clear();

                            var allParticipants = new List<Participant>(dto.TeamOne.ToArray());
                            allParticipants.AddRange(dto.TeamTwo);

                            int i = 0;
                            bool purpleSide = false;

                            foreach (Participant playerTeam in allParticipants)
                            {
                                i++;
                                var lobbyPlayer = new CustomLobbyPlayer();
                                //var botPlayer = new BotControl();
                                if (playerTeam is PlayerParticipant)
                                {
                                    var player = playerTeam as PlayerParticipant;
                                    lobbyPlayer = RenderPlayer(player, dto.OwnerSummary.SummonerId == player.SummonerId);
                                    ///BotParticipant botParticipant = playerTeam as BotParticipant;
                                    //botPlayer = RenderBot(botParticipant);
                                    IsOwner = dto.OwnerSummary.SummonerId ==
                                              Client.LoginPacket.AllSummonerData.Summoner.SumId;
                                    StartGameButton.IsEnabled = IsOwner;

                                    if (Client.Whitelist.Count > 0)
                                        if (!Client.Whitelist.Contains(player.SummonerName.ToLower()))
                                            await RiotCalls.BanUserFromGame(Client.GameID, player.AccountId);
                                }

                                if (i > dto.TeamOne.Count)
                                {
                                    i = 0;
                                    purpleSide = true;
                                }

                                if (!purpleSide)
                                    BlueTeamListView.Items.Add(lobbyPlayer);
                                else
                                    PurpleTeamListView.Items.Add(lobbyPlayer);
                            }
                        }
                        break;
                    case "PRE_CHAMP_SELECT":
                    case "CHAMP_SELECT":
                        if (!LaunchedTeamSelect)
                        {
                            Client.ChampSelectDTO = dto;
                            Client.LastPageContent = Client.Container.Content;
                            Client.SwitchPage(new ChampSelectPage(dto.RoomName, dto.RoomPassword).Load(this));
                            LaunchedTeamSelect = true;
                        }
                        break;
                }
            }));
        }