Пример #1
0
		static void ws_SessionClosed(WebSocketSession session, SuperSocket.SocketBase.CloseReason reason)
		{
			User userObj = Server.FindClientBySessionId(session.SessionID);

			foreach (IUserConnection userConnection in userObj.Connections) {
				if (userConnection.Type == UserConnectionTypes.WebSocket) {
					WebSocketUserCommunication connection = (WebSocketUserCommunication)userConnection;

					if (connection.SessionId() == session.SessionID) {
						userConnection.Close();

						List<IUserConnection> userConnectionList = new List<IUserConnection>();

						userConnectionList.AddRange(userObj.Connections);
						userConnectionList.Remove(userConnection);
						userObj.Connections = new ReadOnlyCollection<IUserConnection>(userConnectionList);
						//userObj.Connections.Remove(userConnection);
						break;
					}
				}
			}

			if (userObj.Connections.Count <= 0) {
				Server.ClientList.Remove(userObj);
				//TODO: just do quit command instead.
				userObj.Save();
			}

				//TODO: deal with multi user login?
		}
Пример #2
0
        public static User FindClientBySessionId(string SessionId)
        {
            foreach (User CurrentUser in ClientList)
            {
                foreach (IUserConnection UserConnection in CurrentUser.Connections)
                {
                    if (UserConnection.Type == UserConnectionTypes.WebSocket)
                    {
                        WebSocketUserCommunication UserCommunication = (WebSocketUserCommunication)UserConnection;

                        if (UserCommunication.SessionId() == SessionId)
                        {
                            return(CurrentUser);
                        }
                    }
                }
            }

            return(null);
        }