diff --git a/server.js b/server.js index 4858095..5b5556e 100644 --- a/server.js +++ b/server.js @@ -297,7 +297,7 @@ io.sockets.on('connection', function (socket) { if(!('avatars' in player)) { player = undefined; - return callback('fail', { code: 3, message: 'Currputed accound - no avatar list.'}); + return callback('fail', { code: 3, message: 'Corrupted account - no avatar list.'}); } for(var k in player.avatars) { socket.join(k); @@ -312,7 +312,9 @@ io.sockets.on('connection', function (socket) { var check_feature = function(object, feature) { if(!object.features[feature]) { throw { code: 8, message: 'Specified component doesn\'t have ' + feature + ' capabilities' }; + return false; } + return true; }; var battery_check = function(battery, energy) { @@ -481,25 +483,15 @@ io.sockets.on('connection', function (socket) { return; if(typeof target.manipulator_slot === 'undefined') return fail(999, 'Manipulator empty - nothing to be attached.'); - var hub = find_co_component(target, data.hub, 'hub'); - if(typeof data.hub_slot !== 'number') - return fail(999, 'hub slot should be a number.'); - var idx = Math.round(data.skeleton_slot); - if(idx < 0) - return fail(999, 'Specified skeleton doesn\'t have negative slots.'); - if(idx >= skeleton.skeleton_slots.length) - return fail(999, 'Specified skeleton doesn\'t have that many slots.'); - if(skeleton.skeleton_slots[idx]) - return fail(999, 'Skeleton '+data.skeleton+' slot '+idx+' occupied by '+skeleton.skeleton_slots[idx].id+'.'); + if(typeof data.hub === 'undefined') + return fail(999, 'You must define hub to attach to.'); + var hub = common.get(data.hub); var o = target.manipulator_slot; - skeleton.skeleton_slots[idx] = o; - o.parent = skeleton; - delete target.manipulator_slot.position; - delete target.manipulator_slot.velocity; + connect(hub, o); delete target.manipulator_slot.grabbed_by; delete target.manipulator_slot; - socket.emit('manipulator attached', { manipulator: { id: target.id }, skeleton: { id: skeleton.id }, slot: idx, object: { id: o.id } }); + socket.emit('manipulator attached', { manipulator: { id: target.id }, hub: { id: hub.id }, object: { id: o.id } }); }); on('manipulator detach', function(target, data) { diff --git a/static/common.js b/static/common.js index b04916a..2b45c1a 100644 --- a/static/common.js +++ b/static/common.js @@ -97,6 +97,10 @@ String.prototype.capitalize = function() { return this.charAt(0).toUpperCase() + this.slice(1); } + + var get_position = e.get_position = function(object) { + return vectors.create(object.position); + }; })(typeof exports === 'undefined' ? this['common'] = {} : exports); diff --git a/static/manipulator.js b/static/manipulator.js index d0ae018..a05a187 100644 --- a/static/manipulator.js +++ b/static/manipulator.js @@ -18,19 +18,15 @@ socket.on('manipulator released', function(data) { delete objects[data.id].manipulator_slot; }); -var attach = function(hub, slot) { +var attach = function(hub) { hub = common.get(hub); - socket.emit('manipulator attach', {target: manipulator.id, hub: hub.id, hub_slot: slot}); + socket.emit('manipulator attach', {target: manipulator.id, hub: hub.id}); }; socket.on('manipulator attached', function(data) { var s = common.get(data.hub.id); var o = common.get(data.object.id); var m = common.get(data.manipulator.id); - s.hub_slots[data.slot] = o; - o.parent = s; - delete o.position; - delete o.velocity; delete o.grabbed_by; delete m.manipulator_slot; socket.emit('report', { target: o.id });