/// <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); }
protected override void Read(BitReader r) { salt = r.ReadUInt64(); reason = (UdpDisconnectReason)r.Read(4); if (reason == UdpDisconnectReason.Custom) { message = r.ReadUTF(256); } }
public UdpDisconnect(ulong salt, string message) { this.salt = salt; reason = UdpDisconnectReason.Custom; this.message = message; }
public UdpDisconnect(ulong salt, UdpDisconnectReason reason) { this.salt = salt; this.reason = reason; }
public UdpDisconnect(ulong salt, UdpDisconnectReason reason, string message) { this.salt = salt; this.reason = reason; this.message = message; }