Пример #1
0
        private async void QueueButton_Click(object sender, RoutedEventArgs e)
        {
            //to queue
            if (InQueue == false)
            {
                LastSender = (Button)sender;
                GameQueueConfig config = (GameQueueConfig)LastSender.Tag;
                //Make TeamBuilder Work for solo
                if (config.Id != 61)
                {
                    if (Queues.Contains(config.Id))
                    {
                        return;
                    }
                    Queues.Add(config.Id);
                    MatchMakerParams parameters = new MatchMakerParams();
                    parameters.QueueIds = new Int32[] { Convert.ToInt32(config.Id) };
                    Client.QueueId      = config.Id;
                    Client.PVPNet.AttachToQueue(parameters, new SearchingForMatchNotification.Callback(EnteredQueue));
                }
                else if (config.Id == 61)
                {
                    LobbyStatus Lobby = await Client.PVPNet.createArrangedTeamLobby(Convert.ToInt32(config.Id));

                    Client.ClearPage(typeof(TeamBuilderPage));
                    Client.SwitchPage(new TeamBuilderPage(false, Lobby));
                }
                return;
            }
            else if (InQueue == true)
            {
                InQueue = false;
                await LeaveAllQueues();
            }
        }
Пример #2
0
        public DefaultLobbyPage(QueueLobby lobby)
        {
            InitializeComponent();

            this.lobby = lobby;

            lobby.MemberJoined += Lobby_MemberJoined;
            lobby.MemberLeft   += Lobby_MemberLeft;

            lobby.QueueEntered += Lobby_QueueEntered;
            lobby.QueueLeft    += Lobby_QueueLeft;

            lobby.LeftLobby += Lobby_LeftLobby;
            lobby.Loaded    += Lobby_Loaded;

            lobby.CatchUp();

            config = Session.Current.AvailableQueues[lobby.QueueID];
            var map = GameMap.Maps.FirstOrDefault(m => config.SupportedMapIds.Contains(m.MapId));

            MapImage.Source       = new BitmapImage(GameMap.Images[map]);
            MapLabel.Content      = map.DisplayName;
            QueueLabel.Content    = GameConfig.Values[config.GameTypeConfigId].Value;
            ModeLabel.Content     = config.Ranked ? "Ranked" : ModeLabel.Content = GameMode.Values[config.GameMode].Value;
            TeamSizeLabel.Content = $"{config.NumPlayersPerTeam}v{config.NumPlayersPerTeam}";
        }
Пример #3
0
        private async void TeamQueueButton_Click(object sender, RoutedEventArgs e)
        {
            //To leave all other queues
            await LeaveAllQueues();

            InQueue    = false;
            LastSender = (Button)sender;
            GameQueueConfig config = (GameQueueConfig)LastSender.Tag;

            //Make Teambuilder work for duo
            if (config.Id != 61 && config.TypeString != "BOT")
            {
                if (Queues.Contains(config.Id))
                {
                    return;
                }
                Queues.Add(config.Id);
                MatchMakerParams parameters = new MatchMakerParams();
                parameters.QueueIds = new Int32[] { Convert.ToInt32(config.Id) };
                Client.GameQueue    = Convert.ToInt32(config.Id);
                LobbyStatus Lobby = await Client.PVPNet.createArrangedTeamLobby(Convert.ToInt32(config.Id));

                Client.ClearPage(typeof(TeamQueuePage));
                Client.SwitchPage(new TeamQueuePage(Lobby.InvitationID, Lobby));
            }
            else if (config.TypeString == "BOT")
            {
            }
            else
            {
                LobbyStatus Lobby = await Client.PVPNet.createArrangedTeamLobby(Convert.ToInt32(config.Id));

                Client.SwitchPage(new TeamBuilderPage(true, Lobby));
            }
        }
Пример #4
0
        /// 2.)
        public async Task <GameQueueConfig[]> GetAvailableQueues()
        {
            int Id = Invoke("matchmakerService", "getAvailableQueues", new object[] { });

            while (!results.ContainsKey(Id))
            {
                await Task.Delay(10);
            }
            GameQueueConfig[] result = new GameQueueConfig[results[Id].GetTO("data").GetArray("body").Length];
            for (int i = 0; i < results[Id].GetTO("data").GetArray("body").Length; i++)
            {
                result[i] = new GameQueueConfig((TypedObject)results[Id].GetTO("data").GetArray("body")[i]);
            }
            results.Remove(Id);
            return(result);
        }
Пример #5
0
        private void EnteredQueue(SearchingForMatchNotification result)
        {
            if (result.PlayerJoinFailures != null)
            {
                Dispatcher.BeginInvoke(DispatcherPriority.Input, new ThreadStart(() =>
                {
                    Button item            = LastSender;
                    GameQueueConfig config = (GameQueueConfig)item.Tag;
                    Queues.Remove(config.Id);
                    MessageOverlay message       = new MessageOverlay();
                    message.MessageTitle.Content = "Failed to join queue";
                    message.MessageTextBox.Text  = result.PlayerJoinFailures[0].ReasonFailed;
                    if (result.PlayerJoinFailures[0].ReasonFailed == "QUEUE_DODGER")
                    {
                        message.MessageTextBox.Text = "Unable to join the queue due to you recently dodging a game." + Environment.NewLine;
                        TimeSpan time = TimeSpan.FromMilliseconds(result.PlayerJoinFailures[0].PenaltyRemainingTime);
                        message.MessageTextBox.Text = "You have " + string.Format("{0:D2}m:{1:D2}s", time.Minutes, time.Seconds) + " remaining until you may queue again";
                    }
                    else if (result.PlayerJoinFailures[0].ReasonFailed == "RANKED_MIN_LEVEL")
                    {
                        message.MessageTextBox.Text = "You do not meet the requirements for this queue." + Environment.NewLine;
                    }
                    else if (result.PlayerJoinFailures[0].ReasonFailed == "QUEUE_PARTICIPANTS")
                    {
                        message.MessageTextBox.Text = "This queue is in dev. Please use this queue on the real league of legends client." + Environment.NewLine;
                    }
                    Client.OverlayContainer.Content    = message.Content;
                    Client.OverlayContainer.Visibility = Visibility.Visible;
                }));
                return;
            }

            Dispatcher.BeginInvoke(DispatcherPriority.Input, new ThreadStart(() =>
            {
                Button item       = LastSender;
                Button fakeButton = new Button(); //We require a unique button to add to the dictionary
                fakeButton.Tag    = item;
                item.Content      = "00:00";
                ButtonTimers.Add(fakeButton, 0);
            }));
            InQueue               = true;
            Client.GameStatus     = "inQueue";
            Client.timeStampSince = (DateTime.Now - new DateTime(1970, 1, 1, 0, 0, 0, 0).ToLocalTime()).TotalMilliseconds;
            Client.SetChatHover();
            Client.PVPNet.OnMessageReceived += GotQueuePop;
        }
Пример #6
0
 public AvailableQueue(GameQueueConfig config)
 {
     this.config = config;
     Map         = config.SupportedMapIds.Single(m => DataDragon.MapData.Value.data.ContainsKey(m.ToString()));
 }
Пример #7
0
        public async void OnMessageReceived(object sender, object message)
        {
            Debug.WriteLine("Calling message: " + message.GetType());

            #region Before Start
            if (message is ClientBeforeStart)
            {
                if (Packets.ReconnectInfo != null && Packets.ReconnectInfo.Game != null)
                {
                    OnMessageReceived(sender, (object)Packets.ReconnectInfo.PlayerCredentials);
                    return;
                }

                Client.Status("Successfully connected!", AccountName);
                Client.Accounts.Add(Packets);

                var playerCount         = Client.Accounts.Count();
                var lastConnectedPlayer = Client.Accounts.LastOrDefault();
                if (Account.Autoboost)
                {
                    BuyBoost();
                }

                if (lastConnectedPlayer == null)
                {
                    Console.WriteLine("Critical error!");
                    Controller.Restart();
                    return;
                }

                if (playerCount == _setting.MaxBots && lastConnectedPlayer.AllSummonerData.Summoner.SumId.Equals(SummonerId))
                {
                    Client.Status("Players connected! Creating lobby...", AccountName);
                    Timer createPremade = new Timer {
                        Interval = 3000, AutoReset = false
                    };
                    createPremade.Elapsed += (ek, eo) =>
                    {
                        createPremade.Stop();
                        OnMessageReceived(sender, (object)new CreateLobby());
                    };
                    createPremade.Start();
                    return;
                }
            }
            #endregion

            #region Creating lobby...
            if (message is CreateLobby)
            {
                if (!Controller.IsAvailable(SummonerQueue))
                {
                    Client.Status("QueueType is invalid or it is not supported!", AccountName);
                    return;
                }

                GameQueueConfig Game = new GameQueueConfig();
                Game.Id = SummonerQueue;

                if (_setting.Difficulty == "EASY" || _setting.Difficulty == "MEDIUM")
                {
                    Client.Lobby = await Connections.createArrangedBotTeamLobby(Game.Id, _setting.Difficulty);
                }
                else
                {
                    Client.Lobby = await Connections.createArrangedTeamLobby(Game.Id);
                }

                PlayerAcceptedInvite = true;
                Client.Status("Lobby created. Inviting players...", AccountName);

                if (Client.Accounts.Count == 1)
                {
                    OnMessageReceived(sender, Client.Lobby);
                    return;
                }

                foreach (var bot in Client.Accounts)
                {
                    if ((int)bot.AllSummonerData.Summoner.SumId != (int)SummonerId)
                    {
                        await Connections.Invite(bot.AllSummonerData.Summoner.SumId);
                    }
                }
            }
            #endregion

            #region Invite requested
            if (message is InvitationRequest)
            {
                var invitation = message as InvitationRequest;

                if (invitation.InvitationId == Client.Lobby.InvitationID && PlayerAcceptedInvite == false)
                {
                    Client.Lobby = await Connections.AcceptLobby(invitation.InvitationId);

                    PlayerAcceptedInvite = true;
                    Client.Status("Invitation accepted.", AccountName);
                    return;
                }
            }
            #endregion

            #region Lobby status
            if (message is LobbyStatus)
            {
                #region Ignore pls
                List <string> errors = new List <string>();
                if (Client.Lobby == null)
                {
                    errors.Add("NO!");
                }
                if (SummonerName != Client.Lobby.Owner.SummonerName)
                {
                    errors.Add("Trying to access LobbyStatus not as owner.");
                }
                if (Client.LobbyStatusWaiting)
                {
                    errors.Add("Currently waiting for all players.");
                }

                if (errors.Count > 0)
                {
                    Debug.WriteLine("-----------------------------");
                    Debug.WriteLine("LobbyStatus was terminated due following errors:");
                    foreach (var msg in errors)
                    {
                        Debug.WriteLine("        " + msg);
                    }
                    Debug.WriteLine("-----------------------------");
                    return;
                }
                #endregion

                if (Client.Lobby.Members.Count < _setting.MaxBots && !Client.LobbyStatusWaiting)
                {
                    Client.LobbyStatusWaiting = true;
                    while (Client.Lobby.Members.Count < _setting.MaxBots)
                    {
                        Thread.Sleep(100);
                    }
                }

                var lobbyInfo = Client.Lobby;
                Client.Status("Players are ready to start the game!", AccountName);

                #region Queue
                Client.LobbyGame.QueueIds = new Int32[1] {
                    (int)SummonerQueue
                };
                Client.LobbyGame.InvitationId  = lobbyInfo.InvitationID;
                Client.LobbyGame.Team          = lobbyInfo.Members.Select(stats => Convert.ToInt32(stats.SummonerId)).ToList();
                Client.LobbyGame.BotDifficulty = _setting.Difficulty;
                #endregion

                OnMessageReceived(sender, await Connections.AttachTeamToQueue(Client.LobbyGame));
                Client.Status("Game search initialized!", AccountName);
                return;
            }
            #endregion

            #region Game state
            if (message is GameDTO)
            {
                GameDTO game = message as GameDTO;
                switch (game.GameState)
                {
                case "CHAMP_SELECT":
                    if (FirstSelection)
                    {
                        break;
                    }

                    FirstSelection = true;
                    Client.Status("Champion select in.", AccountName);
                    await Connections.SetClientReceivedGameMessage(game.Id, "CHAMP_SELECT_CLIENT");

                    if (SummonerQueue != 65)
                    {
                        var hArray = HeroesArray.Shuffle();
                        await Connections.SelectChampion(hArray.First(hr => hr.FreeToPlay || hr.Owned || !hr.OwnedByYourTeam).ChampionId);

                        await Connections.ChampionSelectCompleted();
                    }

                    break;

                case "POST_CHAMP_SELECT":
                    FirstQueue = true;
                    //Client.Status("Post champion select.", AccountName);
                    break;

                case "PRE_CHAMP_SELECT":
                    break;

                case "GAME_START_CLIENT":
                    Client.Status("Lauching League of Legends.", AccountName);
                    break;

                case "GameClientConnectedToServer":
                    break;

                case "IN_QUEUE":
                    Client.Status("Waiting for game.", AccountName);
                    break;

                case "TERMINATED":
                    FirstQueue           = true;
                    PlayerAcceptedInvite = false;
                    Client.Status("Re-entering queue.", AccountName);
                    break;

                case "JOINING_CHAMP_SELECT":
                    if (FirstQueue)
                    {
                        Client.Status("Game accepted!", AccountName);
                        FirstQueue     = false;
                        FirstSelection = false;
                        try
                        {
                            await Connections.AcceptPoppedGame(true);
                        }
                        catch
                        {
                            RestartQueue(sender);
                        }
                        break;
                    }
                    break;

                case "LEAVER_BUSTED":
                    Client.Status("Leave Busted!", AccountName);
                    break;
                }
            }
            #endregion

            #region Starting game...
            if (message is PlayerCredentialsDto)
            {
                string gameLocation = Controller.GameClientLocation(_setting.GamePath);
                PlayerCredentialsDto credentials = message as PlayerCredentialsDto;
                ProcessStartInfo     startInfo   = new ProcessStartInfo();

                startInfo.CreateNoWindow   = false;
                startInfo.WorkingDirectory = gameLocation;
                startInfo.FileName         = "League of Legends.exe";
                startInfo.Arguments        = "\"8394\" \"LoLLauncher.exe\" \"\" \"" + credentials.ServerIp + " " +
                                             credentials.ServerPort + " " + credentials.EncryptionKey + " " + credentials.SummonerId + "\"";
                Client.Status("Launching League of Legends", AccountName);



                new Thread((ThreadStart)(() =>
                {
                    while (Client.ClientDelay)
                    {
                        Thread.Sleep(100);
                    }

                    Client.ClientDelay = true;
                    LeagueProcess = Process.Start(startInfo);
                    LeagueProcess.Exited += LeagueProcess_Exited;
                    while (LeagueProcess.MainWindowHandle == IntPtr.Zero)
                    {
                        ;
                    }
                    LeagueProcess.PriorityClass = ProcessPriorityClass.Idle;
                    LeagueProcess.EnableRaisingEvents = true;
                    Timer clientDelay = new Timer {
                        AutoReset = false, Interval = Client.Delay
                    };
                    clientDelay.Elapsed += (o, args) =>
                    {
                        Client.ClientDelay = false;
                    };
                    clientDelay.Start();
                })).Start();
            }

            if (message is EndOfGameStats)
            {
                Client.Accounts.Clear();
                Client.LobbyStatusWaiting = false;

                // Process kill
                LeagueProcess.Exited -= LeagueProcess_Exited;

                while (LeagueProcess.Responding)
                {
                    LeagueProcess.Kill();
                    Thread.Sleep(500);
                }


                var msg = message as EndOfGameStats;
                Packets = await Connections.GetLoginDataPacketForUser();

                WebService.SetLevel(Account.Id, (int)Packets.AllSummonerData.SummonerLevel.Level);
                WebService.SetMoney(Account.Id, (int)Packets.IpBalance);


                if (SummonerLevel < Packets.AllSummonerData.SummonerLevel.Level)
                {
                    Client.Status("Level up! " + Packets.AllSummonerData.SummonerLevel.Level, AccountName);
                }

                // Player level limit
                if (MaxLevelReached((int)Packets.AllSummonerData.SummonerLevel.Level))
                {
                    // This player will not be added to lobby!
                    Client.Status("Maximum level reached!", AccountName);
                    return;
                }
                else if (Account.Autoboost)
                {
                    BuyBoost();
                }

                OnMessageReceived(sender, new ClientBeforeStart());
                return;
            }
            #endregion

            #region Searching for match
            if (message is SearchingForMatchNotification)
            {
                var result = message as SearchingForMatchNotification;

                if (result.PlayerJoinFailures != null)
                {
                    List <Tuple <string, int> > summoners = new List <Tuple <string, int> >();
                    string accessToken = null;
                    bool   penalty     = false;


                    foreach (var item in result.PlayerJoinFailures)
                    {
                        var x = new QueueDodger(item as TypedObject);
                        if (x.ReasonFailed == "LEAVER_BUSTED")
                        {
                            accessToken = x.AccessToken;
                            summoners.Add(new Tuple <string, int>(x.Summoner.Name, x.LeaverPenaltyMillisRemaining));
                            penalty = true;
                        }
                        else
                        {
                            Client.Status("Reason: " + x.ReasonFailed, AccountName);

                            return;
                        }
                    }

                    if (penalty)
                    {
                        Debug.WriteLine("Penalty timer.");
                        var timeWait = summoners.OrderByDescending(s => s.Item2).FirstOrDefault().Item2;
                        var time     = TimeSpan.FromMilliseconds(timeWait);
                        var players  = string.Join(",", summoners.Select(s => s.Item1).ToArray());
                        Debug.WriteLine("Time wait" + timeWait + "ms." + "Counted summoners: " + summoners.Count + "; Summoners: " + players);
                        Client.Status("Waiting " + time.Minutes + " mins to be able to join queue", AccountName);
                        Thread.Sleep(timeWait + 2999);

                        if (SummonerName == Client.Lobby.Owner.SummonerName)
                        {
                            OnMessageReceived(sender, await Connections.AttachToQueue(Client.LobbyGame, accessToken));
                        }
                    }
                }
            }
            #endregion
        }