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); }
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)); }