/// <summary>
        ///     When invited to a team
        /// </summary>
        public TeamQueuePage(string Invid, LobbyStatus NewLobby = null, bool IsReturningToLobby = false, TeamId SelectedTeam = null, string BotDifficulty = null)
        {
            InitializeComponent();

            Client.InviteListView = InviteListView;
            Client.RiotConnection.MessageReceived += Update_OnMessageReceived;

            //MainWindow Window = new MainWindow();
            //Window.Hide();
            //Opps
            Invite = Invid;
            CurrentLobby = NewLobby;
            selectedTeamId = SelectedTeam;
            botDifficulty = BotDifficulty;
            if (!IsReturningToLobby)
            {
                LoadStats();
            }

            Client.CurrentPage = this;
            Client.ReturnButton.Visibility = Visibility.Visible;
            Client.ReturnButton.Content = "Return to Lobby";
        }
        //TeamBuilder is just a little insane. This code is very messy too. :P
        /* 
         Note by horato: This code is not messy, its ugly as f**k. If you don't want to suffer from serious brain damage and moral panic
         do not attempt to study it. But hey, it works (kind of). 
         I also suck at GUI and xaml, if you want to fix my shit then be my guest ;)
        */

        public TeamBuilderPage(bool iscreater, LobbyStatus myLobby)
        {
            InitializeComponent();

            if (iscreater == false)
                Invite.IsEnabled = false;

            CurrentLobby = myLobby;

            MyMasteries = Client.LoginPacket.AllSummonerData.MasteryBook;
            MyRunes = Client.LoginPacket.AllSummonerData.SpellBook;
            LoadStats();

            Client.InviteListView = InvitedPlayers;
            Client.RiotConnection.MessageReceived += PVPNet_OnMessageReceived;
            Client.LastPageContent = Content;
            Client.CurrentPage = this;
            Client.ReturnButton.Visibility = Visibility.Visible;
            Client.ReturnButton.Content = "Return to team builder";
            Client.GameStatus = "inTeamBuilder";
            Client.SetChatHover();
            AddPlayer();

            CallWithArgs(Guid.NewGuid().ToString(), "cap", "retrieveFeatureToggles", "{}");
            CallWithArgs(Guid.NewGuid().ToString(), "cap", "retrieveInfoV1", "{\"queueId\":61}");
        }
        public async void LoadStats()
        {
            i = 10;
            PingTimer = new Timer(1000);
            PingTimer.Elapsed += PingElapsed;
            PingTimer.Enabled = true;
            PingElapsed(1, null);
            InviteButton.IsEnabled = false;
            StartGameButton.IsEnabled = false;

            if (CurrentLobby == null)
            {
                CurrentLobby = await RiotCalls.AcceptInvite(Invite);
            }
            if (CurrentLobby.InvitationID != null)
            {
                string ObfuscatedName =
                    Client.GetObfuscatedChatroomName(CurrentLobby.InvitationID.ToLower(),
                        ChatPrefixes.Arranging_Game);
                string Jid = Client.GetChatroomJid(ObfuscatedName, CurrentLobby.ChatKey, false);
                newRoom = new MucManager(Client.XmppConnection);
                jid = new Jid(Jid);
                Client.XmppConnection.OnMessage += XmppConnection_OnMessage;
                Client.XmppConnection.OnPresence += XmppConnection_OnPresence;
                newRoom.AcceptDefaultConfiguration(jid);
                newRoom.JoinRoom(jid, Client.LoginPacket.AllSummonerData.Summoner.Name, CurrentLobby.ChatKey);
                RenderLobbyData();
            }
            else
            {
                Client.GameStatus = "outOfGame";
                Client.SetChatHover();
                Client.SwitchPage(Client.MainPage);
                Client.ClearPage(typeof(TeamQueuePage));
                Client.Log("Failed to join room.");
            }
        }
 private void Update_OnMessageReceived(object sender, MessageReceivedEventArgs message)
 {
     if (message.Body.GetType() == typeof(LobbyStatus))
     {
         var Lobby = message.Body as LobbyStatus;
         CurrentLobby = Lobby;
         RenderLobbyData();
     }
     else if (message.Body is GameDTO)
     {
         var QueueDTO = message.Body as GameDTO;
         Dispatcher.BeginInvoke(DispatcherPriority.Input, new ThreadStart(() =>
         {
             if (QueueDTO.GameState == "TERMINATED")
             {
                 Client.HasPopped = false;
                 Client.RiotConnection.MessageReceived += GotQueuePop;
             }
         }));
     }
     else if (message.Body is GameNotification)
     {
         Dispatcher.BeginInvoke(DispatcherPriority.Input, new ThreadStart(() =>
         {
             setStartButtonText("Start Game");
             inQueue = false;
             Client.inQueueTimer.Visibility = Visibility.Hidden;
         }));
     }
     else if (message.Body is SearchingForMatchNotification)
     {
         Dispatcher.BeginInvoke(DispatcherPriority.Input,
             new ThreadStart(() => { EnteredQueue(message.Body as SearchingForMatchNotification); }));
     }
     else if (message.Body is InvitePrivileges)
     {
         Dispatcher.BeginInvoke(DispatcherPriority.Input, new ThreadStart(() =>
         {
             var priv = message.Body as InvitePrivileges;
             if (priv.canInvite)
             {
                 var tr = new TextRange(ChatText.Document.ContentEnd, ChatText.Document.ContentEnd);
                 tr.Text = "You may invite players to this game." + Environment.NewLine;
                 tr.ApplyPropertyValue(TextElement.ForegroundProperty, Brushes.Yellow);
                 InviteButton.IsEnabled = true;
             }
             else
             {
                 var tr = new TextRange(ChatText.Document.ContentEnd, ChatText.Document.ContentEnd);
                 tr.Text = "You may no longer invite players to this game." + Environment.NewLine;
                 tr.ApplyPropertyValue(TextElement.ForegroundProperty, Brushes.Yellow);
                 InviteButton.IsEnabled = false;
             }
         }));
     }
     else if (message.Body is LcdsServiceProxyResponse)
     {
         parseLcdsMessage(message.Body as LcdsServiceProxyResponse); //Don't look there, its ugly!!! :)))
     }
 }