 class UserState
   constructor : (@username) ->
     @roomslist = new FastSet
-    @sockets = {}
-
-  socketAdd : (socket, cb) ->
-    @sockets[socket.id] = socket
+    @sockets = new FastSet
+
+  socketAdd : (id, cb) ->
+    @sockets.add id
     process.nextTick -> cb null
 
   socketRemove : (id, cb) ->
-    @sockets[id]?.disconnect()
-    delete @sockets[id]
+    @sockets.remove id
     process.nextTick -> cb null
 
-  socketGet : (id, cb) ->
-    s = @sockets[id]
-    process.nextTick -> cb null, s
-
   socketsCount : (cb) ->
-    nsockets = Object.keys(@sockets).length
+    nsockets = @sockets.length
     process.nextTick -> cb null, nsockets
 
   socketsGetAll : (cb) ->
-    sockets = @sockets
+    sockets = @sockets.toArray()
     process.nextTick -> cb null, sockets
 
   roomAdd : (roomName, cb) ->

        user.userState.socketsGetAll (error, sockets) =>
          if error
            return fn makeServerError @errorBuilder, error
          for own id, toSocket of sockets
            toSocket.emit 'roomAccessRemoved', roomName
          fn()
    , cb

  broadcast : (socket, roomName, args...) ->
    socket.broadcast.to(roomName).emit args...

  ###
  # commands

  ###

  registerSocket : (socket, cb) ->
    @userState.socketAdd socket.id, (error) =>
      if error
        return cb makeServerError @errorBuilder, error
      for own cmd of userCommands
