Skip to content

Commit

Permalink
closes #56
Browse files Browse the repository at this point in the history
  • Loading branch information
incompl committed Nov 27, 2013
1 parent 0666117 commit 765bd25
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 4 deletions.
8 changes: 6 additions & 2 deletions src/server/cloak/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -242,15 +242,15 @@ 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;
},

_deleteRoom: function(room) {
delete rooms[room.id];
if (config.notifyRoomChanges) {
lobby._serverMessageMembers('roomDeleted', cloak.getRooms());
lobby._serverMessageMembers('roomDeleted', cloak.roomCount());
}
},

Expand Down Expand Up @@ -282,6 +282,10 @@ module.exports = (function() {
return _(users).size();
},

roomCount: function() {
return _(rooms).size();
},

getUser: function(id) {
return users[id] || false;
},
Expand Down
4 changes: 2 additions & 2 deletions src/server/cloak/room.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
},
Expand All @@ -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'));
},

Expand Down
27 changes: 27 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit 765bd25

Please sign in to comment.