/// <summary> /// Completely shuts down a targeted Socket /// </summary> /// <param name="Socket"></param> public void DeactivateSocket(IWebSocketConnection Socket) { if (this._webSockets.ContainsKey(Socket)) { WebSocketUser user = null; this._webSockets[Socket].Closing = true; this._webSockets[Socket].Dispose(); this._webSockets.TryRemove(Socket, out user); } Socket.Close(); }
/// <summary> /// OnSocketAdd. /// </summary> /// <param name="NewUser"></param> public void OnSocketAdd(IWebSocketConnection ConnectingSocket) { if (ConnectingSocket == null) { return; } if (!ConnectingSocket.IsAvailable) { return; } if (ConnectingSocket.ConnectionInfo == null) { return; } if (string.IsNullOrEmpty(ConnectingSocket.ConnectionInfo.Path)) { return; } if (!ConnectingSocket.ConnectionInfo.Path.Trim().Contains("/")) { return; } if ((string.IsNullOrEmpty(ConnectingSocket.ConnectionInfo.Path.Trim().Split('/')[1]))) { return; } try { WebSocketUser outUser; int ConnectingUsersID = this.GetSocketsUserID(ConnectingSocket); List <GameClient> PotentialConnectedClients = this.GetSocketsClient(ConnectingSocket); if (PotentialConnectedClients.Count > 0) { this.DeactivateSocket(ConnectingSocket); return; } WebSocketUser User = null; if (this._webSockets.ContainsKey(ConnectingSocket)) { this._webSockets.TryRemove(ConnectingSocket, out User); } this._webSockets.TryAdd(ConnectingSocket, new WebSocketUser(ConnectingUsersID, "", ConnectingSocket)); } catch (Exception ex) { if (ex is System.IO.IOException) { return; } this.OnSocketError(ex.Message); } }