Lidgren.Network.NetConnection.ExecuteDisconnect C# (CSharp) Method

ExecuteDisconnect() private method

private ExecuteDisconnect ( string reason, bool sendByeMessage ) : void
reason string
sendByeMessage bool
return void
        internal void ExecuteDisconnect(string reason, bool sendByeMessage)
        {
            m_peer.VerifyNetworkThread();

            // clear send queues
            for (int i = 0; i < m_sendChannels.Length; i++)
            {
                NetSenderChannelBase channel = m_sendChannels[i];
                if (channel != null)
                    channel.Reset();
            }

            if (sendByeMessage)
                SendDisconnect(reason, true);

            if (m_status == NetConnectionStatus.ReceivedInitiation)
            {
                // nothing much has happened yet; no need to send disconnected status message
                m_status = NetConnectionStatus.Disconnected;
            }
            else
            {
                SetStatus(NetConnectionStatus.Disconnected, reason);
            }

            // in case we're still in handshake
            lock (m_peer.m_handshakes)
                m_peer.m_handshakes.Remove(m_remoteEndPoint);

            m_disconnectRequested = false;
            m_connectRequested = false;
            m_handshakeAttempts = 0;
        }