public void RemoveClient(WebSocketUser user, WebSocketDisconnection reason)
        {
            try {
                if (user == null)
                {
                    return;
                }

                user.Disconnected = true;

                WebSocketUser outer;

                if (Users.ContainsKey(user.UID))
                {
                    Users.TryRemove(user.UID, out outer);
                }

                if (user.ListenToken != null)
                {
                    user.ListenToken.Cancel();
                }

                if (user.Socket != null)
                {
                    user.Socket.Shutdown(SocketShutdown.Both);
                }
            } catch (Exception) { }


            Logger.DebugWrite("INFO", $"Socket got removed. UID: {user.UID}, Reason: {reason}");
            OnDisconnect?.Invoke(this, new DisconnectEventArgs(user, reason));
        }
Beispiel #2
0
        private void Remove(WebSocketDisconnection type)
        {
            Disconnect();

            Logger.DebugWrite("INFO", $"Disconnection Reason: {type}");
            OnDisconnect?.Invoke(this, new DisconnectEventArgs(null, type));
        }
 public DisconnectEventArgs(WebSocketUser user, WebSocketDisconnection reason)
 {
     User   = user;
     Reason = reason;
 }