exports.setup = function (socket, io, app) {

    socket.on('disconnect', function () {

        var room = app.userManager.getRoom(socket.id);

        if (null !== room) {
            socket.leave(room);
            app.roomManager.leave(room, app.userManager.get(socket.id));
            io.sockets.emit('ROOM_LIST', app.roomManager.getAll());
            io.sockets.in(room).emit('GAME_MENU_INFOS', app.roomManager.get(room));
        }

        app.userManager.remove(socket.id);
        
        io.sockets.emit('USER_LIST', app.userManager.getAll());
    });

};
