예제 #1
0
        private static void Queue2TimerCallback(object state) // enter game queue
        {
            //Logger.Log("q2timer");
            try
            {
                /*var process = GetProcessByName("League of Legends");
                 * if (process == null)*/
                int port = GameSession.GetPort();
                if (port == 0)
                {
                    //Logger.Log("port");
                    if (LCU == null || LCU.SummonerID == 0)
                    {
                        LCU = new LCU();
                    }
                    //Logger.Log("sumo");
                    Try++;
                    int lb = LCU.LeaverBuster();
                    switch (Try)
                    {
                    case 1: LogAndInfo("Starting queue..."); LCU.StartQueue(); break;

                    case 2:
                        if (lb > 0)
                        {
                            GameSession.TimerTick = DateTime.Now.Ticks;
                            LogAndInfo("Leaverbuster detected. Trying again in " + lb.ToString() + " seconds...");
                            Try = 1;
                            if (lb > 4)
                            {
                                Thread.Sleep(4000);
                            }
                            LCU = new LCU();
                        }
                        else
                        {
                            LCU.StartQueue();
                            Logger.Log("No Leaverbuster.");
                            Try = 6;
                        }
                        break;

                    default:
                        if (Try > 90 && !LCU.InChampSelect() && port == 0)
                        {
                            for (int i = 0; i < 5; i++)
                            {
                                TryToContinue();
                            }
                            LogAndInfo("Can't find match: Reached to max. number of tries. Restarting queue...");
                            Try = 0;
                            sel = 0;
                        }
                        else if (port != 0)
                        {
                            LogAndInfo("Starting game (3) session... " + sel + " - p: " + port);
                            State = ClientStates.InGame;
                            Communication.SendMessageWithoutReply(Server.ClientID, "state", "ingame");
                            StartGameSession(sel);
                            KillTimers();
                        }
                        else if (Try > 5 && !LCU.InChampSelect())
                        {
                            if (Try > 30 && Try % 5 == 0)
                            {
                                try
                                {
                                    var bmp = PixelCache.GetScreenshot();
                                    bmp.Bitmap.Save("gs5.bmp");
                                    if (bmp.GetPixel(425, 362) == Color.FromArgb(205, 190, 145))
                                    {
                                        ListProcesses();
                                        GameSession.TimerTick = DateTime.Now.Ticks;
                                        Logger.Log("gamesession (5) restart...");
                                        Logger.Log("Game crashed. Trying to continue...");
                                        Server.SetInfoText("Game crashed. Trying to continue...");
                                        Thread.Sleep(5000);
                                        TryToContinue();
                                    }
                                }
                                catch (Exception x)
                                {
                                    Logger.Log("gs5 error: " + x.Message);
                                    Logger.Log("Screenshot error. Trying to continue...");
                                    Server.SetInfoText("Screenshot error. Trying to continue...");
                                    TryToContinue();
                                }
                            }
                            LogAndInfo("Accepting match.");
                            LCU.AcceptQueue();
                            //Logger.Log("acc macc: " + LCU?.auth?.ToString() + " kacc: " + port);
                        }
                        break;
                    }

                    if (LoginTimer != null)
                    {
                        GameSession.TimerTick = DateTime.Now.Ticks;
                        if (LCU != null && !LCU.InChampSelect())
                        {
                            TimerChange(LoginTimer, QueueTimerInterval);
                        }
                        else
                        {
                            sel = LCU.SelectedChamp();
                            int champ = Champions.RandomChamp();
                            try
                            {
                                LCU = new LCU();
                                if (sel == 0 && LCU.InChampSelect())
                                {
                                    LogAndInfo("Picking champion...");
                                    LCU.PickChampion(champ);
                                    Thread.Sleep(500);
                                    while (LCU.SelectedChamp() == 0)
                                    {
                                        LCU.AcceptQueue();
                                        LogAndInfo("Couldn't pick " + Champions.GetChampById(champ) + ". Trying again...");
                                        LCU = new LCU();
                                        Thread.Sleep(3000);
                                        champ = Champions.RandomChamp();
                                        Logger.Log(LCU.PickChampion(champ));
                                    }
                                    if (port == 0)
                                    {
                                        LogAndInfo("picked champion");
                                        TimerChange(LoginTimer, QueueTimerInterval);
                                    }
                                }
                                else
                                {
                                    sel = LCU.SelectedChamp();
                                    if (sel != 0)
                                    {
                                        //LogAndInfo("p: " + port);
                                        Try   = 6;
                                        champ = sel;
                                        LogAndInfo("Picked champion: " + Champions.GetChampById(champ));
                                        Thread.Sleep(1000);
                                        if (port == 0)
                                        {
                                            TimerChange(LoginTimer, QueueTimerInterval);
                                        }
                                        else
                                        {
                                            LogAndInfo("Starting game (1) session...");
                                            State = ClientStates.InGame;
                                            Communication.SendMessageWithoutReply(Server.ClientID, "state", "ingame");
                                            StartGameSession(champ);
                                            KillTimers();
                                        }
                                    }
                                }
                            }
                            catch (Exception x)
                            {
                                Logger.Log("pick chmap exc: " + x.Message);
                            }
                        }
                    }
                }
                else
                {
                    LogAndInfo("Starting game (2) session...");
                    State = ClientStates.InGame;
                    Communication.SendMessageWithoutReply(Server.ClientID, "state", "ingame");
                    StartGameSession((sel != 0) ? sel : 22);
                    KillTimers();
                }

                /*
                 * else if(Try > 20)
                 * {
                 *  LogAndInfo("game is f****d - restarting");
                 *  var process = ClientApi.GetProcessByName("League of Legends");
                 *  if (process != null)
                 *  {
                 *      var x = NativeMethods.GetAllTcpConnections();
                 *      foreach (var a in x)
                 *      {
                 *          if (process.Id == a.owningPid)
                 *          {
                 *              process.Kill();
                 *          }
                 *      }
                 *  }
                 *  TryToContinue();
                 *  State = ClientStates.InGame;
                 *  Communication.SendMessageWithoutReply(Server.ClientID, "state", "ingame");
                 *  StartGameSession(Champions.RandomChamp());
                 *  KillTimers();
                 * }*/
            }
            catch (Exception x)
            {
                Logger.Log("exc");
                try
                {
                    var bmp = PixelCache.GetScreenshot();
                    bmp.Bitmap.Save("q2.bmp");
                    bmp.Dispose();
                }
                catch (Exception a)
                {
                    Logger.Log("q2 login timer (1) image error..." + a.Message);
                }
                if (Try > 0)
                {
                    Try--;
                }
                Server.SetInfoText("q2 Login timer error");
                if (LoginTimer != null)
                {
                    TimerChange(LoginTimer, QueueTimerInterval);
                }
                Logger.Log("restarting...");
                Logger.Log("error: " + x.Message);
                Logger.Log(x.StackTrace);
            }
        }