Esempio n. 1
0
        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() =>
                {
                    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;
                        try
                        {
                            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);
                        }
                        catch { }
                    }
                    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();
                            BotControl botPlayer          = new BotControl();
                            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;
                                AddBotBlueTeam.IsEnabled   = IsOwner;
                                AddBotPurpleTeam.IsEnabled = IsOwner;

                                if (Client.Whitelist.Count > 0)
                                {
                                    if (!Client.Whitelist.Contains(player.SummonerName.ToLower()))
                                    {
                                        await Client.PVPNet.BanUserFromGame(Client.GameID, player.AccountId);
                                    }
                                }
                            }
                            else if (playerTeam is BotParticipant)
                            {
                                BotParticipant botParticipant = playerTeam as BotParticipant;
                                botPlayer = RenderBot(botParticipant);
                            }

                            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(this));
                            Client.GameStatus = "championSelect";
                            Client.SetChatHover();
                            LaunchedTeamSelect = true;
                        }
                    }
                }));
            }
        }
Esempio n. 2
0
        private async void StartChampSelect()
        {
            //Force client to popup once in champion select
            Client.FocusClient();
            Client.IsInGame = true;
            //Get champions and sort alphabetically



            ChampList = new List <ChampionDTO>(Client.PlayerChampions);
            ChampList.Sort((x, y) => champions.GetChampion(x.ChampionId).displayName.CompareTo(champions.GetChampion(y.ChampionId).displayName));



            //Retrieve masteries and runes
            MyMasteries = Client.LoginPacket.AllSummonerData.MasteryBook;
            MyRunes     = Client.LoginPacket.AllSummonerData.SpellBook;

            //Put masteries & runes into combo boxes
            int i = 0;

            foreach (MasteryBookPageDTO MasteryPage in MyMasteries.BookPages)
            {
                string MasteryPageName = MasteryPage.Name;
                //Stop garbage mastery names
                if (MasteryPageName.StartsWith("@@"))
                {
                    MasteryPageName = "Mastery Page " + ++i;
                }
                MasteryComboBox.Items.Add(MasteryPageName);
                if (MasteryPage.Current)
                {
                    MasteryComboBox.SelectedValue = MasteryPageName;
                }
            }
            i = 0;
            foreach (SpellBookPageDTO RunePage in MyRunes.BookPages)
            {
                string RunePageName = RunePage.Name;
                //Stop garbage rune names
                if (RunePageName.StartsWith("@@"))
                {
                    RunePageName = "Rune Page " + ++i;
                }
                RuneComboBox.Items.Add(RunePageName);
                if (RunePage.Current)
                {
                    RuneComboBox.SelectedValue = RunePageName;
                }
            }
            //Allow runes & masteries to be changed
            QuickLoad = true;

            //Signal to the server we are in champion select
            await Client.PVPNet.SetClientReceivedGameMessage(Client.GameID, "CHAMP_SELECT_CLIENT");

            //Retrieve the latest GameDTO
            GameDTO latestDTO = await Client.PVPNet.GetLatestGameTimerState(Client.GameID, Client.ChampSelectDTO.GameState, Client.ChampSelectDTO.PickTurn);

            //Find the game config for timers
            configType = Client.LoginPacket.GameTypeConfigs.Find(x => x.Id == latestDTO.GameTypeConfigId);
            if (configType == null) //Invalid config... abort!
            {
                QuitCurrentGame();

                MessageOverlay overlay = new MessageOverlay();
                overlay.MessageTextBox.Text        = "Invalid Config ID (" + latestDTO.GameTypeConfigId.ToString() + "). Report to Eddy5641 [https://github.com/Eddy5641/LegendaryClient/issues/new]";
                overlay.MessageTitle.Content       = "Invalid Config";
                Client.OverlayContainer.Content    = overlay.Content;
                Client.OverlayContainer.Visibility = Visibility.Visible;
            }
            counter                 = configType.MainPickTimerDuration - 5; //Seems to be a 5 second inconsistancy with riot and what they actually provide
            CountdownTimer          = new System.Windows.Forms.Timer();
            CountdownTimer.Tick    += new EventHandler(CountdownTimer_Tick);
            CountdownTimer.Interval = 1000; // 1 second
            CountdownTimer.Start();

            LatestDto = latestDTO;
            //Get the champions for the other team to ban & sort alpabetically
            ChampionBanInfoDTO[] ChampsForBan = await Client.PVPNet.GetChampionsForBan();

            ChampionsForBan = new List <ChampionBanInfoDTO>(ChampsForBan);
            ChampionsForBan.Sort((x, y) => champions.GetChampion(x.ChampionId).displayName.CompareTo(champions.GetChampion(y.ChampionId).displayName));

            //Join champion select chatroom
            string JID = Client.GetChatroomJID(latestDTO.RoomName.Replace("@sec", ""), latestDTO.RoomPassword, false);

            Chatroom                    = Client.ConfManager.GetRoom(new jabber.JID(JID));
            Chatroom.Nickname           = Client.LoginPacket.AllSummonerData.Summoner.Name;
            Chatroom.OnRoomMessage     += Chatroom_OnRoomMessage;
            Chatroom.OnParticipantJoin += Chatroom_OnParticipantJoin;
            Chatroom.Join(latestDTO.RoomPassword);

            //Render our champions
            RenderChamps(false);

            //Start recieving champ select
            ChampSelect_OnMessageReceived(this, latestDTO);
            Client.OnFixChampSelect         += ChampSelect_OnMessageReceived;
            Client.PVPNet.OnMessageReceived += ChampSelect_OnMessageReceived;
        }
Esempio n. 3
0
        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.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;
                    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;
                }
            }));
        }
Esempio n. 4
0
        private void GameLobby_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;
                    try
                    {
                        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 JID(jid));
                        newRoom.Nickname           = Client.LoginPacket.AllSummonerData.Summoner.Name;
                        newRoom.OnRoomMessage     += newRoom_OnRoomMessage;
                        newRoom.OnParticipantJoin += newRoom_OnParticipantJoin;
                        newRoom.Join(dto.RoomPassword);
                    }
                    catch
                    {
                    }
                }
                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 Client.PVPNet.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 Client.PVPNet.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;
                }
            }));
        }