Пример #1
0
        public ChatRoomList RemoveUserByConnectionId(String ConnectionId)
        {
            ChatRoomList roomList = new ChatRoomList();

            lock (syncLock)
            {
                ChatUser thisUser = null;
                foreach (ChatUser user in ChatUsers)
                {
                    if (user.Connections.IndexOf(ConnectionId) != -1)
                    {
                        thisUser = user;
                    }
                }
                if (thisUser == null)
                {
                    return(roomList);
                }
                // Remove the connectionid from the user
                thisUser.Connections.Remove(ConnectionId);

                foreach (ChatRoom room in ChatRooms)
                {
                    if (room.UserList.IndexOf(thisUser.UserId) != -1)
                    {
                        // Remove the user from the room
                        roomList.Add(room.Clone());
                        room.UserList.Remove(thisUser.UserId);
                    }
                }

                // TODO
                // Remove users with no connectionIds
                // Remove rooms with no users (except for Id 0)
            }
            return(roomList);
        }