/// <summary> /// Handler for incoming <see cref="AuthResponsePacket"/>s. /// </summary> /// <param name="connectionId">Original connection ID</param> /// <param name="packet">Incoming <see cref="AuthResponsePacket"/></param> private void authResponsePacketHandler(string connectionId, AuthResponsePacket packet) { // Was authentication successful? if (packet.Success) { // Set authenticated state, session ID, and expiry Authenticated = true; SessionId = packet.SessionId; sessionExpiry = packet.Expiry.ToDateTime(); // Reset the session extension timer for halfway between now and the expiry sessionExtendTimer.Stop(); sessionExtendTimer.Interval = (sessionExpiry - DateTime.UtcNow).TotalMilliseconds / 2; sessionExtendTimer.Start(); // Raise successful auth event OnAuthenticationSuccess?.Invoke(this, new AuthenticationEventArgs()); } else { // Set authenticated state Authenticated = false; // Raise failed auth event OnAuthenticationFailure?.Invoke(this, new AuthenticationEventArgs(packet.FailureReason, packet.FailureMessage)); } }
/// <summary> /// Handler for incoming <see cref="AuthResponsePacket"/>s. /// </summary> /// <param name="connectionId">Original connection ID</param> /// <param name="packet">Incoming <see cref="AuthResponsePacket"/></param> private void authResponsePacketHandler(string connectionId, AuthResponsePacket packet) { // Was authentication successful? if (packet.Success) { // Set authenticated state and session ID Authenticated = true; SessionId = packet.SessionId; double timerInterval; if (packet.Expiry != null) { // COMPAT: Maintains backward-compatibility for 0.6.0 servers // This requires that the clock be properly synchronised or the interval may be calculated as negative timerInterval = (packet.Expiry.ToDateTime() - DateTime.UtcNow).TotalMilliseconds / 2; if (timerInterval < 0) { RaiseLogEntry(new LogEventArgs("Got a negative interval until session expiry. Check your system's clock is set correctly and try connecting again.", LogLevel.ERROR)); } } else { timerInterval = packet.ExpiresIn / 2; } // Reset the session extension timer for halfway between now and the expiry sessionExtendTimer.Stop(); sessionExtendTimer.Interval = timerInterval; sessionExtendTimer.Start(); // Raise successful auth event OnAuthenticationSuccess?.Invoke(this, new AuthenticationEventArgs()); } else { // Set authenticated state Authenticated = false; // Raise failed auth event OnAuthenticationFailure?.Invoke(this, new AuthenticationEventArgs(packet.FailureReason, packet.FailureMessage)); } }
/// <summary> /// Method to raise authentication success event. /// </summary> protected void RaiseAuthenticationSuccess <T>(Client server, T response = null) where T : class { OnAuthenticationSuccess?.Invoke(this, new ClientHttpEventArgs <T>(server, response)); }