diff --git a/src/server/cloak/index.js b/src/server/cloak/index.js index c29c280..1171d6d 100644 --- a/src/server/cloak/index.js +++ b/src/server/cloak/index.js @@ -242,7 +242,7 @@ module.exports = (function() { rooms[room.id] = room; if (config.notifyRoomChanges) { // Message everyone in lobby - lobby._serverMessageMembers('roomCreated', cloak.getRooms()); + lobby._serverMessageMembers('roomCreated', cloak.roomCount()); } return room; }, @@ -250,7 +250,7 @@ module.exports = (function() { _deleteRoom: function(room) { delete rooms[room.id]; if (config.notifyRoomChanges) { - lobby._serverMessageMembers('roomDeleted', cloak.getRooms()); + lobby._serverMessageMembers('roomDeleted', cloak.roomCount()); } }, @@ -282,6 +282,10 @@ module.exports = (function() { return _(users).size(); }, + roomCount: function() { + return _(rooms).size(); + }, + getUser: function(id) { return users[id] || false; }, diff --git a/src/server/cloak/room.js b/src/server/cloak/room.js index 9980270..b82becd 100644 --- a/src/server/cloak/room.js +++ b/src/server/cloak/room.js @@ -39,7 +39,7 @@ module.exports = (function() { this._hasReachedMin = true; } this._emitEvent('newMember', this, user); - this._serverMessageMembers(this.isLobby ? 'lobbyMemberJoined' : 'roomMemberJoined', _.pick(user, 'id', 'username')); + this._serverMessageMembers(this.isLobby ? 'lobbyMemberJoined' : 'roomMemberJoined', _.pick(user, 'id', 'name')); user._serverMessage('joinedRoom', _.pick(this, 'name')); return true; }, @@ -57,7 +57,7 @@ module.exports = (function() { this._lobby.addMember(user); } this._emitEvent('memberLeaves', this, user); - this._serverMessageMembers(this.isLobby ? 'lobbyMemberLeft' : 'roomMemberLeft', _.pick(user, 'id', 'username')); + this._serverMessageMembers(this.isLobby ? 'lobbyMemberLeft' : 'roomMemberLeft', _.pick(user, 'id', 'name')); user._serverMessage('leftRoom', _.pick(this, 'name')); }, diff --git a/test/test.js b/test/test.js index a02d980..ddcc9b3 100644 --- a/test/test.js +++ b/test/test.js @@ -382,6 +382,33 @@ module.exports = _.extend(suite, { client.run(this.host); }, + roomCount: function(test) { + test.expect(3); + + var server = this.server; + var client = suite.createClient(); + + server.configure({ + port: this.port + }); + + client.configure({ + serverEvents: { + begin: function() { + test.equals(server.roomCount(), 0); + server.createRoom('My Cool Game'); + test.equals(server.roomCount(), 1); + server.createRoom('My Lame Game'); + test.equals(server.roomCount(), 2); + test.done(); + } + } + }); + server.run(); + client.run(this.host); + }, + + getRooms: function(test) { test.expect(9);