                 cb(GlobalLobby.addPlayer(player))
             ))
     ))
-    socket.on('getUserProfile', (profile_url, cb) ->
+    socket.on('getUserProfile', handleErrors((profile_url, cb) ->
         UserProfiles.get(profile_url, cb)
-    )
-    socket.on('createLobby', (req, cb) ->
-        UserProfiles.get(req.profile_url, handleErrors((err, profile) ->
+    ))
+    socket.on('createLobby', handleErrors((req, cb) ->
+        UserProfiles.get(req.profile_url, (err, profile) ->
             return if err
             req.league = profile.league
             player = new Player(socket, req)
             players = LobbyManager.addPlayer(player)
             GlobalLobby.removeByID(player.id)
             cb(players)
-        ))
-    )
-    socket.on('listLobbies', (req, cb) ->
-        UserProfiles.get(req.profile_url, handleErrors((err, profile) ->
-            return if err
-            req.league = profile.league
-            player = new Player(socket, req)
-            lobbies = LobbyManager.getMatchingLobbies(player)
-            cb(lobbies)
-        ))
-    )
-    socket.on('joinLobby', (req, cb) ->
-        UserProfiles.get(req.profile_url, handleErrors((err, profile) ->
-            return if err
-            req.league = profile.league
-            player = new Player(socket, req)
-            LobbyManager.joinLobby(player, cb)
-        ))
-    )
+        )
+    ))
     socket.on('sendChat', handleErrors((text) ->
         if GlobalLobby.isPresent(socket.id)
             GlobalLobby.sendChat(socket.id, text)

util = require('util')
_ = require('underscore')

raceMatches = (p1, p2) ->
    return p2.race in p1.params.opp_races

leagueMatches = (p1, p2) ->
    return p2.league in p1.params.opp_leagues

seriesMatches = (p1, p2) ->
    return _.intersection(p1.params.series, p2.params.series)

mapMatches = (p1, p2) ->
    return _.intersection(p1.params.maps, p2.params.maps)

blocklistOk = (p1, p2) ->
    user = p2.name + '.' + p2.char_code
    return not p1.params.blocked_users[user]

class Player
    constructor: (socket, request) ->
        _.extend(this, request)
        @socket = socket
        @id = socket.id

    matches: (p2) =>
        p1 = this
        if p1.region isnt p2.region
            return false
        if not raceMatches(p1, p2) or not raceMatches(p2, p1)
            return false
        if not leagueMatches(p1, p2) or not leagueMatches(p2, p1)
            return false
        if not blocklistOk(p1, p2) or not blocklistOk(p2, p1)
            return false
        series = seriesMatches(p1, p2)
        return false if series.length is 0
        maps = mapMatches(p1, p2)
        return false if maps.length is 0
        return {series: series, maps: maps}

    toJSON: =>
        id: @id

            a.emit('playerLeft', id) for a in _.values(@anons)
GlobalLobby = new GlobalLobbyGlobal()

class UserProfilesGlobal
    LEAGUES:
        'none': 'n'
