/// <summary> /// Intercepts the login attempt in order to provide some internal handling. /// </summary> /// <param name="result">Result of the login attempt.</param> /// <param name="session">Session proxy, if one exists.</param> /// <param name="e">Exception thrown from the callback.</param> private void LoginCallback(Result <MainSessionPrx> result) { System.Exception e = result.Exception; if (result.Success) { if (KeepAlive) { keepAliveTimer = new Timer(new TimerCallback(OnKeepAlive), null, KeepAliveInterval, KeepAliveInterval); } session = result.ReturnedResult; session.GetTankList(); //session = MainSessionPrxHelper.uncheckedCast(session.ice_router(router)); pinger = new Pinger(session); } else { logger.Error("LoginCallback() Login attempt failed: {0}", e); if (e is PermissionDeniedException) { PermissionDeniedException ex = (PermissionDeniedException)e; e = new LoginFailedException(ex.reason); } else { e = new LoginFailedException("Unable to login."); } result.Exception = e; } remoteCallback(new Result(result.Success, session, result.Exception)); remoteCallback = null; }
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 RtmpLoginResult(bool success, UserClient client, LoginFailedException ex) { Success = success; Client = client; LoginException = ex; }