Example #1
0
        private async Task Cleanup()
        {
            var oldState = State;

            State = ConnectionState.Disconnecting;

            if (oldState == ConnectionState.Connected)
            {
                try { await ClientAPI.Send(new LogoutRequest()).ConfigureAwait(false); }
                catch (OperationCanceledException) { }
            }

            MessageQueue.Clear();

            await GatewaySocket.Disconnect().ConfigureAwait(false);

            ClientAPI.Token = null;

            _servers.Clear();
            _channels.Clear();
            _privateChannels.Clear();

            PrivateUser = null;
            CurrentUser = null;

            State = (int)ConnectionState.Disconnected;
            _connectedEvent.Reset();
            _disconnectedEvent.Set();
        }
Example #2
0
        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;
        }