Пример #1
0
        public void Connect(string user, string password, Region region, string clientVersion)
        {
            if (!isConnected)
            {
                Thread t = new Thread(() =>
                {
                    this.user          = user;
                    this.password      = password;
                    this.clientVersion = clientVersion;
                    //this.server = "127.0.0.1";
                    this.server     = RegionInfo.GetServerValue(region);
                    this.loginQueue = RegionInfo.GetLoginQueueValue(region);
                    this.locale     = RegionInfo.GetLocaleValue(region);
                    this.useGarena  = RegionInfo.GetUseGarenaValue(region);

                    //Sets up our sslStream to riots servers
                    try
                    {
                        client = new TcpClient(server, 2099);
                    }
                    catch
                    {
                        Error("Riots servers are currently unavailable.", ErrorType.AuthKey);
                        Disconnect();
                        return;
                    }

                    //Check for riot webserver status
                    //along with gettin out Auth Key that we need for the login process.
                    if (useGarena)
                    {
                        if (!GetGarenaToken())
                        {
                            return;
                        }
                    }

                    if (!GetAuthKey())
                    {
                        return;
                    }

                    if (!GetIpAddress())
                    {
                        return;
                    }

                    var ar = (IAsyncResult)null;
                    try
                    {
                        sslStream = new SslStream(client.GetStream(), false, AcceptAllCertificates);
                        ar        = sslStream.BeginAuthenticateAsClient(server, null, null);
                    }
                    catch (Exception ex)
                    {
                        Disconnect();
                    }
                    if (ar == null)
                    {
                        Disconnect();
                        HandsFreeLeveler.App.smurfList.First(smurf => (smurf.username == user)).start();
                    }
                    else
                    {
                        using (ar.AsyncWaitHandle) //Burda manyama var
                        {
                            if (ar.AsyncWaitHandle.WaitOne(-1))
                            {
                                sslStream.EndAuthenticateAsClient(ar);
                            }
                        }

                        if (!Handshake())
                        {
                            return;
                        }

                        BeginReceive();

                        if (!SendConnect())
                        {
                            return;
                        }

                        if (!Login())
                        {
                            return;
                        }
                        StartHeartbeat();
                    }
                });

                t.Start();
            }
        }
Пример #2
0
        private bool Login()
        {
            TypedObject result, body;

            // Login 1
            RiotObjects.Platform.Login.AuthenticationCredentials cred = new RiotObjects.Platform.Login.AuthenticationCredentials();
            cred.Password       = password;
            cred.ClientVersion  = clientVersion;
            cred.IpAddress      = ipAddress;
            cred.SecurityAnswer = null;
            cred.Locale         = locale;
            cred.Domain         = "lolclient.lol.riotgames.com";
            cred.OldPassword    = null;
            cred.AuthToken      = authToken;

            if (useGarena)
            {
                cred.PartnerCredentials = "8393 " + garenaToken;
                cred.Username           = userID;
            }
            else
            {
                cred.PartnerCredentials = null;
                cred.Username           = user;
            }
            int id = Invoke("loginService", "login", new object[] { cred.GetBaseTypedObject() });

            result = GetResult(id);
            if (result["result"].Equals("_error"))
            {
                string newVersion = (string)result.GetTO("data").GetTO("rootCause").GetArray("substitutionArguments")[1];
                RegionInfo.updateRegionVersion(regionName, newVersion);
                isConnected = false;
                Thread.Sleep(300);
                Connect(user, password, reg);
                return(false);
            }

            body         = result.GetTO("data").GetTO("body");
            sessionToken = body.GetString("token");
            accountID    = (int)body.GetTO("accountSummary").GetInt("accountId");

            // Login 2

            if (useGarena)
            {
                body = WrapBody(Convert.ToBase64String(Encoding.UTF8.GetBytes(userID + ":" + sessionToken)), "auth", 8);
            }
            else
            {
                body = WrapBody(Convert.ToBase64String(Encoding.UTF8.GetBytes(user.ToLower() + ":" + sessionToken)), "auth", 8);
            }

            body.type = "flex.messaging.messages.CommandMessage";

            id     = Invoke(body);
            result = GetResult(id); // Read result and discard

            isLoggedIn = true;
            if (OnLogin != null)
            {
                OnLogin(this, user, ipAddress);
            }
            return(true);
        }