Exemplo n.º 1
0
        public static async Task Login(object sender, Dispatcher disp, string user, string pass, string region, RiotAuthOpenIdConfiguration openId, bool save, Action callback)
        {
            var regionData         = RiotClientData.ReadSystemRegionData(Path.Combine(StaticVars.IcyWindLocation, "IcyWindAssets", "system", "system.yaml"), region);
            var loginDataAuthToken = GetLoginToken(user, pass, regionData, openId);

            if (loginDataAuthToken.Result != RiotAuthResult.Success)
            {
                await disp.BeginInvoke(DispatcherPriority.Render, (Action)(() =>
                {
                    UserInterfaceCore.HolderPage.ShowNotification(UserInterfaceCore.ShortNameToString("InvalidRiotCred").Replace("{User}", user));
                    if (sender.GetType() == typeof(LoginPage))
                    {
                        ((LoginPage)sender).LoginProgressBar.Visibility = Visibility.Hidden;
                    }
                }));

                return;
            }
            var userInfo = GetLoginUserInfo(loginDataAuthToken, openId);
            //I have no idea why this is called, it doesn't seem to be used for much but it simulates the
            //Connections that riot has. Don't question riot, they do funny things.
            var loginEnt   = GetLoginEntitlements(regionData, loginDataAuthToken);
            var rsoAuth    = GetLoginLcdsRsoLoginQueue(regionData, loginDataAuthToken, userInfo);
            var userClient = await LoginRtmps(regionData, JsonConvert.SerializeObject(rsoAuth.Lqt),
                                              loginDataAuthToken.AccessTokenJson.AccessToken, user);



            if (userClient.Success)
            {
                userClient.Client.RiotMessagingService = new WebSocket(regionData.Servers.Rms.RmsUrl.Replace(":443", "") +
                                                                       $"/rms/v1/session?token={loginDataAuthToken.AccessTokenJson.AccessToken}&id={Guid.NewGuid():D}&token_type=access");
                userClient.Client.Token  = loginDataAuthToken;
                userClient.Client.Region = regionData;
                userClient.Client.OpenId = openId;
                var ping = new Thread(() =>
                {
                    Thread.Sleep(TimeSpan.FromSeconds(60));
                    userClient.Client.RiotMessagingService.Ping();
                });
                userClient.Client.RiotMessagingService.OnMessage +=
                    userClient.Client.OnRiotMessagingServiceReceived;
                userClient.Client.RiotMessagingService.OnOpen += (o, args) => ping.Start();
                //userClient.Client.RiotMessagingService.Connect();

                userClient.Client.SaveToServer = save;

                var           str1      = $"gn-{userClient.Client.RiotSession.AccountSummary.AccountId}";
                var           str2      = $"cn-{userClient.Client.RiotSession.AccountSummary.AccountId}";
                var           str3      = $"bc-{userClient.Client.RiotSession.AccountSummary.AccountId}";
                Task <bool>[] taskArray = { userClient.Client.RiotConnection.SubscribeAsync("my-rtmps", "messagingDestination", str1, str1),
                                            userClient.Client.RiotConnection.SubscribeAsync("my-rtmps", "messagingDestination", str2, str2),
                                            userClient.Client.RiotConnection.SubscribeAsync("my-rtmps", "messagingDestination", "bc", str3) };

                await Task.WhenAll(taskArray);

                var plainTextbytes = Encoding.UTF8.GetBytes(userClient.Client.RiotSession.AccountSummary.Username + ":" + userClient.Client.RiotSession.Token);
                var reconnectToken = Convert.ToBase64String(plainTextbytes);

                userClient.Client.RiotConnection.MessageReceived += userClient.Client.OnRtmpMessage;

                await userClient.Client.RiotConnection.LoginAsync(user,
                                                                  userClient.Client.RiotSession.Token);

                userClient.Client.RiotProxyCalls = new LcdsRiotCalls((RiotCalls)userClient.Client);

                userClient.Client.RegionData.RegionName = region;

                userClient.Client.LoginDataPacket =
                    await((RiotCalls)userClient.Client).GetLoginDataPacketForUser();

                var pref = GetPlayerPref(loginDataAuthToken,
                                         userClient.Client.Configs["PlayerPreferences"]["ServiceEndpoint"].ToString(),
                                         regionData.PlatformId.ToString(),
                                         userClient.Client.LoginDataPacket.AllSummonerData.Summoner.AcctId.ToString());

                var jsonPref = JsonConvert.DeserializeObject <Dictionary <string, string> >(pref);

                var        deserializer = new Deserializer();
                var        tempData     = Encoding.UTF8.GetString(Deflate.Uncompress(Convert.FromBase64String(jsonPref["data"])));
                TextReader sr           = new StringReader(tempData);
                var        yamlObject   = deserializer.Deserialize(sr);

                var serializer = new JsonSerializer();
                var w          = new StringWriter();
                serializer.Serialize(w, yamlObject);

                var jsonAsRunesReforaged = JsonConvert.DeserializeObject <RunesReforaged>(w.ToString());

                userClient.Client.RunesReforaged = jsonAsRunesReforaged;

                //Connect to chat now
                await ChatAuth.ConnectToChat(regionData, userClient.Client, Convert.ToBase64String(Encoding.UTF8.GetBytes(loginDataAuthToken.AccessTokenJson.AccessToken)));

                userClient.Client.DoHeartbeatShit();

                userClient.Client.ActiveBoots =
                    await((RiotCalls)userClient.Client).GetSummonerActiveBoosts();

                userClient.Client.ChampionList =
                    await((RiotCalls)userClient.Client).GetAvailableChampions();

                var da = await userClient.Client.RiotProxyCalls.WithMoreThanOneResponce("teambuilder-draft",
                                                                                        "retrieveGameloopPlayerInfoV1", 2, "");

                userClient.Client.RiotQueues =
                    await((RiotCalls)userClient.Client).GetAllQueues();


                //Create a game

                var inventoryToken = GetInventoryFromType(regionData,
                                                          loginDataAuthToken,
                                                          userClient.Client.Configs["Inventory"]["BaseServiceUrl"].ToString(),
                                                          userClient.Client.LoginDataPacket.AllSummonerData.Summoner.Puuid.ToString("D"),
                                                          userClient.Client.LoginDataPacket.AllSummonerData.Summoner.AcctId.ToString(),
                                                          "QUEUE_ENTRY");

                var leaguesTierRankToken =
                    await userClient.Client.RiotProxyCalls.DoLcdsProxyCallWithResponse("leagues",
                                                                                       "getMySignedQueueTierRank", "");

                var simpleInventoryToken = GetInventorySimpleFromType(regionData,
                                                                      loginDataAuthToken,
                                                                      userClient.Client.Configs["Inventory"]["BaseServiceUrl"].ToString(),
                                                                      userClient.Client.LoginDataPacket.AllSummonerData.Summoner.Puuid.ToString("D"),
                                                                      userClient.Client.LoginDataPacket.AllSummonerData.Summoner.AcctId.ToString(),
                                                                      "CHAMPION&inventoryTypes=CHAMPION_SKIN");

                userClient.Client.InvToken = simpleInventoryToken;

                var summonerToken =
                    await userClient.Client.RiotProxyCalls.DoLcdsProxyCallWithResponse("summoner",
                                                                                       "getMySummoner", "");

                //userInfo :D

                var party = new CreatePartyService
                {
                    AccountId       = userClient.Client.LoginDataPacket.AllSummonerData.Summoner.AcctId,
                    CreatedAt       = 0,
                    CurrentParty    = null,
                    EligibilityHash = 0,
                    Parties         = null,
                    PlatformId      = regionData.PlatformId.ToString(),
                    Puuid           = userClient.Client.LoginDataPacket.AllSummonerData.Summoner.Puuid.ToString("D"),
                    Registration    = new Registration
                    {
                        InventoryToken  = null,
                        InventoryTokens = new[]
                        {
                            JsonConvert.DeserializeObject <InventoryService>(inventoryToken).Data.ItemsJwt,
                        },
                        LeaguesTierRankToken =
                            Encoding.UTF8.GetString(
                                Gzip.Decompress(Convert.FromBase64String(leaguesTierRankToken.Payload))),
                        SimpleInventoryToken = JsonConvert.DeserializeObject <InventoryService>(simpleInventoryToken)
                                               .Data
                                               .ItemsJwt,
                        SummonerToken = summonerToken.Payload,
                        UserInfoToken = userInfo
                    },
                    ServerUtcMillis = 0,
                    SummonerId      = userClient.Client.LoginDataPacket.AllSummonerData.Summoner.SumId,
                    Version         = 0
                };

                var sendPartyHelper = new BodyHelper
                {
                    body = JsonConvert.SerializeObject(party),
                    url  = $"v1/players/{userClient.Client.LoginDataPacket.AllSummonerData.Summoner.Puuid:D}"
                };

                var partyRtmp = await userClient.Client.RiotProxyCalls.DoLcdsProxyCallWithResponse("parties.service",
                                                                                                   "proxy", JsonConvert.SerializeObject(sendPartyHelper));

                userClient.Client.CurrentParty = JsonConvert.DeserializeObject <PartyPayload>(partyRtmp.Payload);

                //New restricted queue method

                sendPartyHelper = new BodyHelper
                {
                    body   = "",
                    method = "GET",
                    url    = $"v1/parties/{userClient.Client.CurrentParty.Payload.CurrentParty.PartyId}/eligibility"
                };

                var partyElg = await userClient.Client.RiotProxyCalls.DoLcdsProxyCallWithResponse("parties.service",
                                                                                                  "proxy", JsonConvert.SerializeObject(sendPartyHelper));


                //F*****g removed by riot

                /*
                 * //Get restricted Queues
                 * var activeQueues = userClient.Client.RiotQueues.Where(x => x.QueueState == "ON");
                 *
                 * var str = string.Empty;
                 * var queueArr = activeQueues.Select(queue => (int)queue.Id).OrderBy(i => i);
                 * str = queueArr.Aggregate(str, (current, queue) => current + (queue + ","));
                 *
                 * str = str.Remove(str.Length - 1);
                 *
                 * var resp = await userClient.Client.RiotProxyCalls.DoLcdsProxyCallWithResponse("gatekeeper",
                 *  "getQueueRestrictionsForQueuesV2", $"{{\"queueIds\":[{str}],\"queueRestrictionsToExclude\":" +
                 *                                     "[\"QUEUE_DODGER\",\"LEAVER_BUSTED\",\"LEAVER_BUSTER" +
                 *                                     $"_TAINTED_WARNING\"],\"summonerIds\":[{userClient.Client.LoginDataPacket.AllSummonerData.Summoner.SumId}]}}");
                 * //*/

                if (StaticVars.UserClientList == null)
                {
                    StaticVars.UserClientList = new List <UserClient>();
                }
                StaticVars.UserClientList.Add(userClient.Client);

                if (sender.GetType() == typeof(AccountSelectorPage) && save)
                {
                    var acc = new IcyWindRiotAccountInfo
                    {
                        Password = pass,
                        Region   = region,
                        Username = user,
                        SumIcon  = userClient.Client.LoginDataPacket.AllSummonerData.Summoner.ProfileIconId,
                        SumLevel = userClient.Client.LoginDataPacket.AllSummonerData.SummonerLevelAndPoints.SummonerLevel,
                        SumName  = userClient.Client.LoginDataPacket.AllSummonerData.Summoner.InternalName,
                    };
                    if (StaticVars.AccountInfo == null)
                    {
                        return;
                    }

                    if (StaticVars.AccountInfo.Accounts == null)
                    {
                        StaticVars.AccountInfo.Accounts = string.Empty;
                    }

                    var crypto = AES.EncryptBase64(StaticVars.Password, JsonConvert.SerializeObject(acc));

                    /*
                     * if (StaticVars.LoginCred.AccountData.All(x => x.CryptString != crypto))
                     * {
                     *  StaticVars.LoginCred.AccountData.Add(new IcyWindRiotAccountCrypted
                     *  {
                     *      CryptString = crypto,
                     *      Region = region,
                     *      SumUuid = userClient.Client.LoginDataPacket.AllSummonerData.Summoner.Puuid.ToString(),
                     *      SumId = userClient.Client.LoginDataPacket.AllSummonerData.Summoner.SumId
                     *  });
                     *  if (callback != null)
                     *  {
                     *      await disp.BeginInvoke(DispatcherPriority.Render, callback);
                     *  }
                     * }
                     * else
                     * {
                     *  return;
                     * }
                     *
                     * if (StaticVars.UserClientList.Count(x => x.SaveToServer) > 4 && !(StaticVars.AccountInfo.IsDev ||
                     *                                                                StaticVars.AccountInfo.IsPaid ||
                     *                                                                StaticVars.AccountInfo.IsPro))
                     * {
                     *  return;
                     * }
                     * var output = await AccountManager.UpdateAccountInfo(StaticVars.LoginCred);
                     *
                     * //*/
                }
            }
        }