private async Task Cleanup() { var oldState = _gatewayState; _gatewayState = ConnectionState.Disconnecting; var server = VoiceSocket.Server; VoiceSocket.Server = null; VoiceSocket.Channel = null; await Service.RemoveClient(server, this).ConfigureAwait(false); SendVoiceUpdate(server.Id, null); await VoiceSocket.Disconnect().ConfigureAwait(false); _gatewayState = (int)ConnectionState.Disconnected; }
private async Task Cleanup() { var oldState = _gatewayState; _gatewayState = ConnectionState.Disconnecting; if (Config.EnableMultiserver) { if (oldState == ConnectionState.Connected) { try { await ClientAPI.Send(new LogoutRequest()).ConfigureAwait(false); } catch (OperationCanceledException) { } } await GatewaySocket.Disconnect().ConfigureAwait(false); ClientAPI.Token = null; } var server = VoiceSocket.Server; VoiceSocket.Server = null; VoiceSocket.Channel = null; if (Config.EnableMultiserver) { await Service.RemoveClient(server, this).ConfigureAwait(false); } SendVoiceUpdate(server.Id, null); await VoiceSocket.Disconnect().ConfigureAwait(false); if (Config.EnableMultiserver) { await GatewaySocket.Disconnect().ConfigureAwait(false); } _gatewayState = (int)ConnectionState.Disconnected; }