Пример #1
0
        internal void RtmpConnect()
        {
            Console.WriteLine("Connecting to RTMPS with Token: " + loginToken);
            var authLoginPacket = new AuthenticationCredentials();

            authLoginPacket.Username      = credentials.Username;
            authLoginPacket.Password      = credentials.Password;
            authLoginPacket.Domain        = "lolclient.lol.riotgames.com";
            authLoginPacket.Locale        = "en_US";
            authLoginPacket.ClientVersion = ClientVersion.Get(credentials.Region);
            authLoginPacket.IpAddress     = GetIPAddress();
            authLoginPacket.AuthToken     = loginToken;
            rtmpClient.ConnectAsync().Wait();
            var loginTask = InvokeAsync <Session>("loginService", "login", authLoginPacket);

            loginTask.Wait();
            clientSession = loginTask.Result;
            rtmpClient.SubscribeAsync("my-rtmps", "messagingDestination", "bc", "bc-" + clientSession.AccountSummary.AccountId.ToString()).Wait();
            rtmpClient.SubscribeAsync("my-rtmps", "messagingDestination", "gn-" + clientSession.AccountSummary.AccountId.ToString(), "gn-" + clientSession.AccountSummary.AccountId.ToString()).Wait();
            rtmpClient.SubscribeAsync("my-rtmps", "messagingDestination", "cn-" + clientSession.AccountSummary.AccountId.ToString(), "cn-" + clientSession.AccountSummary.AccountId.ToString()).Wait();
            RtmpLogin();
            var loginPacketTask = InvokeAsync <LoginDataPacket>("clientFacadeService", "getLoginDataPacketForUser");

            loginPacketTask.Wait();
            this.loginPacket = loginPacketTask.Result;
            if (loginPacket.AllSummonerData == null)
            {
                SetSummonerNameForNewAccount();
            }
            notifications = loginPacket.BroadcastNotification.broadcastMessages;
            var stateTask = InvokeAsync <String>("accountService", "getAccountStateForCurrentSession");

            stateTask.Wait();
            String state = stateTask.Result;

            if (state != "ENABLED")
            {
                if (loggedIn)
                {
                    RtmpLogout();
                }
                return; //Keep the client but mark it as logged out
            }
            beginHeartbeat();
        }
Пример #2
0
        /// <summary>
        /// Connects to the
        /// </summary>
        /// <param name="User"></param>
        /// <param name="Shard"></param>
        /// <returns></returns>
        public async Task <bool> Connect()
        {
            //Connects to the RTMPS client
            await _client.ConnectAsync();

            //Decrypts the users password when logging in
            string password = DPAPI.Decrypt(_user.Password);

            AuthenticationCredentials auth = new AuthenticationCredentials
            {
                Username      = _user.Username,
                Password      = password,
                ClientVersion = PoroServer.ClientVersion,
                IpAddress     = "209.133.52.232",
                Locale        = _shard.Locale,
                Domain        = "lolclient.lol.riotgames.com",
                AuthToken     = GetAuthKey(_user.Username, password, _shard.LoginQueue)
            };

            //Gets the current login session
            Session login = await Login(_client, auth);

            _accountId = login.Summary.AccountId;

            //Subscribes to server messages
            await _client.SubscribeAsync("my-rtmps", "messagingDestination", "bc", "bc-" + login.Summary.AccountId.ToString());

            await _client.SubscribeAsync("my-rtmps", "messagingDestination", "gn-" + login.Summary.AccountId.ToString(), "gn-" + login.Summary.AccountId.ToString());

            await _client.SubscribeAsync("my-rtmps", "messagingDestination", "cn-" + login.Summary.AccountId.ToString(), "cn-" + login.Summary.AccountId.ToString());

            bool LoggedIn = await _client.LoginAsync(_user.Username.ToLower(), login.Token);

            //TODO: Find easier way of getting summoner name and id without having to download a huge packet
            LoginDataPacket dataPacket = await GetLoginPacket(_client);

            _packet       = dataPacket;
            _summonerId   = dataPacket.AllSummonerData.Summoner.SumId;
            _summonerName = dataPacket.AllSummonerData.Summoner.Name;

            return(LoggedIn);
        }
Пример #3
0
        internal async Task Login(AuthResult auth)
        {
            if (!Init.IsCompleted)
            {
                await Init;
            }
            if (auth.Content.Status != "LOGIN")
            {
                throw new ArgumentException("Invalid auth credentials");
            }

            var context = Riot.Services.Service.RegisterObjects();

            rtmp = new RtmpClient(new Uri("rtmps://" + Region.Current.MainServer + ":2099"), context, ObjectEncoding.Amf3);
            rtmp.MessageReceived += Rtmp_MessageReceived;
            rtmp.Disconnected    += Rtmp_Disconnected;
            await rtmp.ConnectAsync();

            chat.Connect(auth);

            LoginSession session = null;

            do
            {
                try {
                    var creds = auth.GetAuthCredentials();
                    creds.ClientVersion = clientVersion;
                    session             = await LoginService.Login(creds);
                } catch (InvocationException x) when(x.RootCause is ClientVersionMismatchException)
                {
                    var inner = (ClientVersionMismatchException)x.RootCause;

                    clientVersion = (string)inner.SubstitutionArguments[1];
                    Log("Patch (DDragon outdated): " + clientVersion);
                }
            } while (session == null);

            string bc = $"bc-{session.AccountSummary.AccountId}";
            string gn = $"gn-{session.AccountSummary.AccountId}";
            string cn = $"cn-{session.AccountSummary.AccountId}";
            await Task.WhenAll(
                rtmp.SubscribeAsync("my-rtmps", "messagingDestination", "bc", bc),
                rtmp.SubscribeAsync("my-rtmps", "messagingDestination", gn, gn),
                rtmp.SubscribeAsync("my-rtmps", "messagingDestination", cn, cn)
                );

            await rtmp.LoginAsync(auth.Username.ToLower(), session.Token);

            string state = await AccountService.GetAccountState();

            if (state != "ENABLED")
            {
                Log(state);
                throw new AuthenticationException("Not Enabled: " + state);
            }

            this.LoginQueue   = auth.Content;
            this.loginSession = session;
            this.Me           = await summoner.Connect(session);

            try {
                Authed?.Invoke(this, EventArgs.Empty);
            } catch (Exception x) {
                Log("Caught exception while dispatching auth: " + x);
            }

            BackEndServer.Async("/kappa/defer/auth", new JSONObject());

            new Thread(HeartBeatLoop)
            {
                IsBackground = true
            }.Start();
        }
Пример #4
0
        public async Task <bool> ConnectAndLogin()
        {
            if (_useGarena)
            {
                //this.RaiseError("Garena servers are not yet supported.", ErrorType.Connect);
                //return false;
            }
            SetDefaultsParams();
            RtmpClient = new RtmpClient(new Uri(_gameServer), SerializationContext, ObjectEncoding.Amf3);
            // ISSUE: reference to a compiler-generated field
            RtmpClient.MessageReceived += OnMessageReceived;
            LoginQueue loginQueue = new LoginQueue(Username, Password, Region);

            loginQueue.OnAuthFailed          += message => RaiseError(message, ErrorType.Login);
            loginQueue.OnUpdateStatusMessage += (sender, s) =>
            {
                if (OnUpdateStatusMessage == null)
                {
                    return;
                }
                object sender1 = sender;
                string e       = s;
                OnUpdateStatusMessage(sender1, e);
            };
            if (!await loginQueue.GetAuthToken().ConfigureAwait(false))
            {
                return(false);
            }
            this.AuthToken = loginQueue.AuthToken;
            this.UserId    = loginQueue.UserId;
            Stopwatch sw = new Stopwatch();

            sw.Start();
            try
            {
                while (sw.ElapsedMilliseconds / 1000L <= ConnectTimeoutSeconds)
                {
                    try
                    {
                        AsObject asObject = await RtmpClient.ConnectAsync().ConfigureAwait(false);

                        sw.Stop();
                        goto label_13;
                    }
                    catch (Exception ex)
                    {
                        Tools.Log(ex.StackTrace);
                    }
                    await Task.Delay(5000).ConfigureAwait(false);

                    continue;
label_13:

                    OnConnect?.Invoke((object)this, EventArgs.Empty);
                    this.RtmpClient.SetChunkSize(int.MaxValue);

                    AuthenticationCredentials cred = new AuthenticationCredentials()
                    {
                        Username        = Username,
                        Password        = Password,
                        ClientVersion   = ClientVersion,
                        Domain          = "lolclient.lol.riotgames.com",
                        Locale          = _locale,
                        OperatingSystem = "Windows 10",
                        AuthToken       = AuthToken
                    };

                    if (_useGarena)
                    {
                        cred.PartnerCredentials = loginQueue.Token;
                        cred.Username           = loginQueue.User;//UserId
                        cred.Password           = null;
                    }

                    this.Session = await this.Login(cred).ConfigureAwait(false);

                    string[] strArray = new string[3]
                    {
                        "gn",
                        "cn",
                        "bc"
                    };

                    for (int index = 0; index < strArray.Length; ++index)
                    {
                        strArray[index] = string.Format("{0}-{1}", strArray[index], Session.AccountSummary.AccountId);
                    }

                    bool[] flagArray = await Task.WhenAll(new Task <bool>[3]
                    {
                        RtmpClient.SubscribeAsync("my-rtmps", "messagingDestination", strArray[0], strArray[0]),
                        RtmpClient.SubscribeAsync("my-rtmps", "messagingDestination", strArray[1], strArray[1]),
                        RtmpClient.SubscribeAsync("my-rtmps", "messagingDestination", "bc", strArray[2])
                    }).ConfigureAwait(false);


                    if (_useGarena)
                    {
                        IsConnected = await RtmpClient.LoginAsync(cred.Username, Session.Token).ConfigureAwait(false);
                    }
                    else
                    {
                        IsConnected = await RtmpClient.LoginAsync(Username.ToLower(), Session.Token).ConfigureAwait(false);
                    }

                    //IsConnected = await RtmpClient.LoginAsync(Username.ToLower(), Session.Token).ConfigureAwait(false);

                    _heartbeatTimer          = new Timer();
                    _heartbeatTimer.Elapsed += new ElapsedEventHandler(DoHeartBeat);
                    _heartbeatTimer.Interval = 120000.0;
                    _heartbeatTimer.Start();

                    _uptime = DateTime.Now;

                    OnLogin?.Invoke(Username);
                    return(true);
                }
                sw.Stop();
                RaiseError("Connection failed.", ErrorType.Connect);
                return(false);
            }
            catch (InvocationException ex)
            {
                if (ex.RootCause != null && ex.RootCause.GetType() == typeof(LoginFailedException))
                {
                    LoginFailedException rootCause = (LoginFailedException)ex.RootCause;
                    string errorCode = rootCause.ErrorCode;
                    if (!(errorCode == "LOGIN-0018"))
                    {
                        if (errorCode == "LOGIN-0019")
                        {
                            RaiseError("User blocked.", ErrorType.Login);
                            return(false);
                        }
                        this.RaiseError(string.Format("{0}: {1}", "LoginFailedException", rootCause.ErrorCode).Trim(), ErrorType.Login);
                        return(false);
                    }
                    RaiseError("Password change required.", ErrorType.Password);
                    return(false);
                }
                if (!string.IsNullOrEmpty(ex.Message))
                {
                    RaiseError(ex.Message, ErrorType.Invoke);
                    return(false);
                }
            }
            catch (Exception ex)
            {
                Tools.Log(ex.StackTrace);
            }
            finally
            {
                sw.Stop();
            }
            this.RaiseError("Login failed with unknown error. Try again later.", ErrorType.Login);
            return(false);
        }
Пример #5
0
        public async Task <bool> Connect(string user, string pass)
        {
            try
            {
                _user = user;
                await _client.ConnectAsync();

                var cred = new AuthenticationCredentials();
                cred.Username      = user;
                cred.Password      = pass;
                cred.ClientVersion = _version;
                cred.Domain        = "lolclient.lol.riotgames.com";
                cred.IpAddress     = GetIpAddress();
                cred.Locale        = "en_US";
                cred.AuthToken     = GetAuthToken(_region, user, pass);

                if (cred.AuthToken == "RETRY")
                {
                    Log.Error("[{0}] Login queue error!", _user);
                    Disconnect();
                    return(await Connect(user, pass));
                }

                _session = await Login(cred);

                await _client.SubscribeAsync("my-rtmps", "messagingDestination", "bc", "bc-" + _session.AccountSummary.AccountId.ToString());

                await _client.SubscribeAsync("my-rtmps", "messagingDestination", "gn-" + _session.AccountSummary.AccountId.ToString(), "gn-" + _session.AccountSummary.AccountId.ToString());

                await _client.SubscribeAsync("my-rtmps", "messagingDestination", "cn-" + _session.AccountSummary.AccountId.ToString(), "cn-" + _session.AccountSummary.AccountId.ToString());

                var loggedIn = await _client.LoginAsync(user.ToLower(), _session.Token);

                _auth = true;
                //Log.Write("[{0}] Logged in!", _session.AccountSummary.Username);

                _heartbeatTimer          = new Timer();
                _heartbeatTimer.Elapsed += new ElapsedEventHandler(Heartbeat);
                _heartbeatTimer.Interval = 120000;
                _heartbeatTimer.Start();

                _uptime = DateTime.Now;
                return(true);
            }
            catch (InvocationException e)
            {
            }
            catch (ClientDisconnectedException)
            {
            }
            catch (System.Net.WebException ex)
            {
                var res = (System.Net.HttpWebResponse)ex.Response;
                if (res != null && (int)res.StatusCode == 403)
                {
                    using (var reader = new StreamReader(res.GetResponseStream()))
                    {
                        var body           = reader.ReadToEnd();
                        var jsonSerializer = new JavaScriptSerializer();
                        var json           = jsonSerializer.Deserialize <Dictionary <string, object> >(body);

                        Log.Write("[{0}] Error on login: {1}", user, json["reason"]);
                        if (Convert.ToString(json["reason"]) == "attempt_rate_too_fast")
                        {
                            Log.Write("[{0}] Waiting 5 seconds due to throttle from Riot.", user);
                            System.Threading.Thread.Sleep(TimeSpan.FromSeconds(5));

                            //Log.Close();
                            //Process.Start(Environment.CurrentDirectory + "\\Summoning.exe");
                            //Environment.Exit(0);
                        }
                    }

                    return(false);
                }
            }
            catch (Exception e)
            {
                Log.Write("[{0}] Exception while authing: {1}", user, e.Message);
                return(false);
            }
            _client.Close();
            return(await Connect(user, pass));
        }