Beispiel #1
0
        /// <summary>
        /// Disconnect client from the virtual connection
        /// </summary>
        /// <returns>The disconnect.</returns>
        public bool Disconnect(UdpDisconnectReason reason, bool initiate = true, string reasonString = "")
        {
            if (Interlocked.CompareExchange(ref disconnected, 1, 0) == 1)
            {
                return(false);                                                          // return if this method was already called
            }
            var currentState = SetConnectionState(ConnectionState.Disconnected);

            switch (currentState)
            {
            case ConnectionState.Connected:
                if (initiate)
                {
                    SendUdp(new UdpDisconnect(salt, reason, reasonString));     // only send if already connected and initiating the disconnect
                }
                HandleDisconnect();
                OnDisconnect?.Invoke(this);
                socket.Close();
                break;

            case ConnectionState.ReadyToConnect:
                disconnected = 0;
                SetConnectionState(ConnectionState.ReadyToConnect);
                return(true);

            case ConnectionState.AwaitingChallenge:
            case ConnectionState.AwaitingConnected:
                ConnectFailed(ConnectionState.Disconnected, ConnectStatus.Disconnect);
                return(true);
            }

            timer.Stop();
            return(true);
        }
Beispiel #2
0
 protected override void Read(BitReader r)
 {
     salt   = r.ReadUInt64();
     reason = (UdpDisconnectReason)r.Read(4);
     if (reason == UdpDisconnectReason.Custom)
     {
         message = r.ReadUTF(256);
     }
 }
Beispiel #3
0
 public UdpDisconnect(ulong salt, string message)
 {
     this.salt    = salt;
     reason       = UdpDisconnectReason.Custom;
     this.message = message;
 }
Beispiel #4
0
 public UdpDisconnect(ulong salt, UdpDisconnectReason reason)
 {
     this.salt   = salt;
     this.reason = reason;
 }
Beispiel #5
0
 public UdpDisconnect(ulong salt, UdpDisconnectReason reason, string message)
 {
     this.salt    = salt;
     this.reason  = reason;
     this.message = message;
 }