From 6aaadb51bfb8720722b4e80f3439372fbb9bdbb4 Mon Sep 17 00:00:00 2001 From: Johnsmith0508 Date: Mon, 7 Mar 2016 12:53:50 -0500 Subject: [PATCH] fixed issue with authenticated users position not saving callbacks within callbacks --- app.js | 35 +++++++++++++------------- index.html | 3 ++- js/GUI.js | 66 ++++++++++++++++++++++++++++++++++++++++++++++++- js/chatlogic.js | 1 - js/client.js | 5 +--- 5 files changed, 86 insertions(+), 24 deletions(-) diff --git a/app.js b/app.js index 4cabf82..0447b8e 100644 --- a/app.js +++ b/app.js @@ -133,6 +133,7 @@ exports.start = function(port) { socket /*.broadcast.to(socket.id)*/ .emit('user created'); console.info(user.name + " joined "); userName = user.name; + User[userName] = new THREE.Object3D(); if (config.enableMysql) { connection.query('SELECT * FROM ' + config.mysql.table, function(err, rows, fields) { for (var i = 0; i < rows.length; i++) { @@ -142,9 +143,24 @@ exports.start = function(port) { break; } } + if (config.enableRedis && User[userName].posSaved) { + redisClient.hset("cubeuser:" + userName, 'keyConfig', user.keyConfig); + redisClient.hgetall("cubeuser:" + userName, function(err, obj) { + if (obj !== null) { + User[userName].phisObj.position.set(parseInt(obj.x), parseInt(obj.y), parseInt(obj.z)); + User[userName].health = obj.health || 100; + try { + User[userName].items = JSON.parse(obj.items); + } catch (e) { + console.info("Can't read empty array"); + console.warn(e); + console.warn(e.stack); + } + } + }); + } }); } - User[userName] = new THREE.Object3D(); User[userName].sid = socket.id; User[userName].model = user.model; User[userName].items = {}; @@ -180,22 +196,7 @@ exports.start = function(port) { rotation: User[user.name].rotation.toArray() }); - if (config.enableRedis && User[userName].posSaved) { - redisClient.hset("cubeuser:" + userName, 'keyConfig', user.keyConfig); - redisClient.hgetall("cubeuser:" + userName, function(err, obj) { - if (obj !== null) { - User[userName].phisObj.position.set(parseInt(obj.x), parseInt(obj.y), parseInt(obj.z)); - User[userName].health = obj.health || 100; - try { - User[userName].items = JSON.parse(obj.items); - } catch (e) { - console.info("Can't read empty array"); - console.warn(e); - console.warn(e.stack); - } - } - }); - } + socket.broadcast.emit('chat message', user.name + " Joined!"); }); socket.on('keys pressed', function(keys) { diff --git a/index.html b/index.html index 0d3f9a3..bf6fb1d 100644 --- a/index.html +++ b/index.html @@ -128,7 +128,8 @@ - + +