diff --git a/loader.js b/loader.js
index 83b37cbc2e..3c39371a1a 100644
--- a/loader.js
+++ b/loader.js
@@ -125,11 +125,21 @@ Loader.init = function() {
console.log('[cluster] Restarting...');
});
break;
+ case 'user:connect':
+ case 'user:disconnect':
+ notifyWorkers(worker, message);
+ break;
}
}
});
});
+ function notifyWorkers(currentWorker, msg) {
+ Object.keys(cluster.workers).forEach(function(id) {
+ cluster.workers[id].send(msg);
+ });
+ }
+
cluster.on('exit', function(worker, code, signal) {
if (code !== 0) {
if (Loader.timesStarted < numCPUs*3) {
@@ -159,7 +169,7 @@ Loader.restart = function(callback) {
cluster.workers[id].kill();
next();
}, callback);
-}
+};
Loader.init();
diff --git a/public/src/forum/admin/index.js b/public/src/forum/admin/index.js
index e45c661628..5516c62d55 100644
--- a/public/src/forum/admin/index.js
+++ b/public/src/forum/admin/index.js
@@ -94,10 +94,12 @@ define('forum/admin/index', function() {
Admin.updateRoomUsage = function(err, data) {
+ var roomData = data.rooms;
+
function getUserCountIn(room) {
var count = 0;
- for(var user in data[room]) {
- if (data[room].hasOwnProperty(user)) {
+ for(var user in roomData[room]) {
+ if (roomData[room].hasOwnProperty(user)) {
++count;
}
}
@@ -114,10 +116,10 @@ define('forum/admin/index', function() {
var sortedData = [];
- for (var room in data) {
+ for (var room in roomData) {
if (room !== '') {
- sortedData.push({room: room, count: data[room].length});
- total += data[room].length;
+ sortedData.push({room: room, count: roomData[room].length});
+ total += roomData[room].length;
}
}
@@ -131,6 +133,12 @@ define('forum/admin/index', function() {
sortedData[i].count + " active user" + (sortedData[i].count > 1 ? "s" : "") + "";
}
+ var parent = active_users.parent();
+ parent.prepend('
');
+ parent.prepend('Online Total [ ' + (data.onlineRegisteredCount + data.onlineGuestCount) + ' ]');
+ parent.prepend('Online Guests [ ' + data.onlineGuestCount + ' ]
');
+ parent.prepend('Online Users [ ' + data.onlineRegisteredCount + ' ]
');
+
active_users.html(usersHtml);
$('#connections').html(total);
};
diff --git a/src/socket.io/admin/user.js b/src/socket.io/admin/user.js
index dd8cf8de04..50cc6280a3 100644
--- a/src/socket.io/admin/user.js
+++ b/src/socket.io/admin/user.js
@@ -76,11 +76,7 @@ User.banUser = function(uid, callback) {
return callback(err);
}
- var sockets = websockets.getUserSockets(uid);
-
- for(var i=0; i 0, logger.io_one will hook into this socket */
logger.io_one(socket, uid);
@@ -122,7 +156,7 @@ Sockets.init = function(server) {
socket.on('disconnect', function() {
- if (uid && Sockets.getUserSockets(uid).length <= 1) {
+ if (uid && (!onlineUsersMap[uid] || onlineUsersMap[uid] <= 1)) {
db.sortedSetRemove('users:online', uid, function(err) {
socketUser.isOnline(socket, uid, function(err, data) {
socket.broadcast.emit('user.isOnline', err, data);
@@ -130,6 +164,10 @@ Sockets.init = function(server) {
});
}
+ if (process.send) {
+ process.send({action: 'user:disconnect', uid: uid});
+ }
+
emitOnlineUserCount();
for(var roomName in io.sockets.manager.roomClients[socket.id]) {
@@ -214,22 +252,12 @@ Sockets.uidInRoom = function(uid, room) {
};
Sockets.getConnectedClients = function() {
- var uids = [];
- if (!io) {
- return uids;
- }
- var clients = io.sockets.clients();
-
- clients.forEach(function(client) {
- if(client.uid && uids.indexOf(client.uid) === -1) {
- uids.push(client.uid);
- }
- });
- return uids;
+ return onlineUsers;
};
Sockets.getOnlineAnonCount = function () {
- return Sockets.getUserSockets(0).length;
+ var count = parseInt(onlineUsersMap[0], 10);
+ return count ? count : 0;
};
Sockets.getUserSockets = function(uid) {
@@ -281,22 +309,12 @@ Sockets.reqFromSocket = function(socket) {
Sockets.isUserOnline = isUserOnline;
function isUserOnline(uid) {
- return Sockets.getUserSockets(uid).length > 0;
+ return !!onlineUsersMap[uid];
}
Sockets.isUsersOnline = function(uids, callback) {
- var sockets = io.sockets.clients();
-
- if(!Array.isArray(sockets) || !sockets.length) {
- return callback(null, []);
- }
-
- sockets = sockets.map(function(s) {
- return s.uid;
- });
-
var data = uids.map(function(uid) {
- return sockets.indexOf(parseInt(uid, 10)) !== -1;
+ return !!onlineUsersMap[uid];
});
callback(null, data);
@@ -373,7 +391,7 @@ function emitTopicPostStats(callback) {
Sockets.emitOnlineUserCount = emitOnlineUserCount;
function emitOnlineUserCount(callback) {
- var anon = Sockets.getOnlineAnonCount(0);
+ var anon = Sockets.getOnlineAnonCount();
var registered = Sockets.getConnectedClients().length;
var returnObj = {
diff --git a/src/socket.io/meta.js b/src/socket.io/meta.js
index 107e645569..42814005ab 100644
--- a/src/socket.io/meta.js
+++ b/src/socket.io/meta.js
@@ -78,13 +78,19 @@ SocketMeta.rooms.enter = function(socket, data, callback) {
module.parent.exports.updateRoomBrowsingText(data.enter);
- if (data.enter !== 'admin') {
- websockets.in('admin').emit('event:meta.rooms.update', null, websockets.server.sockets.manager.rooms);
- }
+ //if (data.enter !== 'admin') {
+ // websockets.in('admin').emit('event:meta.rooms.update', null, websockets.server.sockets.manager.rooms);
+ //}
};
SocketMeta.rooms.getAll = function(socket, data, callback) {
- callback(null, websockets.server.sockets.manager.rooms);
+ var userData = {
+ onlineGuestCount: websockets.getOnlineAnonCount(),
+ onlineRegisteredCount: websockets.getConnectedClients().length,
+ rooms: websockets.server.sockets.manager.rooms
+ }
+
+ callback(null, userData);
};
/* Exports */
diff --git a/src/socket.io/modules.js b/src/socket.io/modules.js
index 12878f7d17..1ad5c45e12 100644
--- a/src/socket.io/modules.js
+++ b/src/socket.io/modules.js
@@ -181,11 +181,8 @@ SocketModules.chats.send = function(socket, data, callback) {
Messaging.verifySpammer(socket.uid, function(err, isSpammer) {
if (!err && isSpammer) {
- var sockets = server.getUserSockets(socket.uid);
- for(var i = 0; i < sockets.length; ++i) {
- sockets[i].emit('event:banned');
- }
+ server.in('uid_' + socket.uid).emit('event:banned');
// We're just logging them out, so a "temporary ban" to prevent abuse. Revisit once we implement a way to temporarily ban users
server.logoutUser(socket.uid);