diff options
author | Kyle K <kylek389@gmail.com> | 2012-09-18 19:48:54 -0500 |
---|---|---|
committer | Kyle Kaminski <kyle@kkaminsk.com> | 2012-09-18 19:48:54 -0500 |
commit | 2adb9818847fe22d6cd4d634c829e04b61b055c1 (patch) | |
tree | b99d1d5220499a16b55410e1afeb9c9ac9d6631a /protoype | |
parent | 60909c1b129238b276d8cf53650f5fac64052013 (diff) | |
download | fubar-2adb9818847fe22d6cd4d634c829e04b61b055c1.tar.gz fubar-2adb9818847fe22d6cd4d634c829e04b61b055c1.tar.bz2 fubar-2adb9818847fe22d6cd4d634c829e04b61b055c1.zip |
aww it has been over a month, god damn work
Diffstat (limited to 'protoype')
-rw-r--r-- | protoype/app-sio.js | 8 | ||||
-rw-r--r-- | protoype/router/user.js | 11 |
2 files changed, 16 insertions, 3 deletions
diff --git a/protoype/app-sio.js b/protoype/app-sio.js index 61c9958..9bd4b71 100644 --- a/protoype/app-sio.js +++ b/protoype/app-sio.js @@ -113,6 +113,14 @@ sio.sockets.on('connection', function(socket) { socket.myip = endpoint.address; socket.myport = endpoint.port; util.log('[server] new socket.io connection from ' + endpoint.address + ':' + endpoint.port); + /* after client logs in, expect him to emit 'login' event, emit should contain tag name and 'logged in' check should be done */ + socket.on('login', function(tag) { + var client = null; + if ((client = get_connected_client(tag)) != undefined) { + util.log('[socket.io] ' + tag + ' is active'); + client.tag.iosocket = socket; + } + }); socket.on('disconnect', function() { /* delete connected_clients */ util.log('[server] client ' + this.myip + ':' + this.myport + ' disconnected from socket.io connection\n'); diff --git a/protoype/router/user.js b/protoype/router/user.js index 5df1469..2f5d370 100644 --- a/protoype/router/user.js +++ b/protoype/router/user.js @@ -92,10 +92,10 @@ function login_post(req, res, next) { return next(new Error('failed to set status to online')); } /* real deal? */ - connected_clients[user.tag] = {ip: res.connection.myip, port: res.connection.myport}; + connected_clients[user.tag] = {ip: res.connection.myip, port: res.connection.myport, res: res}; /* req.session.regenerate(function() { */ req.session.user = user.tag; /* keep track of auth'ed user */ - res.send(200, 'successfully logged in\n'); + res.send(200, 'successfully logged in, expect socket.io connection\n'); }); break; } @@ -111,10 +111,15 @@ function login_post(req, res, next) { }); } +function get_connected_client(tag) { + return connected_clients.tag; +} + module.exports = { create_get: create_get, create_post: create_post, login_get: login_get, - login_post: login_post + login_post: login_post, + get_connected_client: get_connected_client }; |