From 2adb9818847fe22d6cd4d634c829e04b61b055c1 Mon Sep 17 00:00:00 2001
From: Kyle K <kylek389@gmail.com>
Date: Tue, 18 Sep 2012 19:48:54 -0500
Subject: aww it has been over a month, god damn work

---
 protoype/app-sio.js     |  8 ++++++++
 protoype/router/user.js | 11 ++++++++---
 2 files changed, 16 insertions(+), 3 deletions(-)

(limited to 'protoype')

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
 };
 
-- 
cgit v1.2.3