fixes #12 and added health

This commit is contained in:
Jeena 2014-02-10 14:21:26 +01:00
parent 6c78c750f0
commit d84fb20f90
7 changed files with 83 additions and 18 deletions

View file

@ -28,8 +28,11 @@
ProtocolHelper.applyCommand(message.data, self);
});
NotificationCenter.on('sendControlCommandToAllUsers', this.sendControlCommandToAllUsers, this);
NotificationCenter.on('sendControlCommandToAllUsersExcept', this.sendControlCommandToAllUsersExcept, this);
NotificationCenter.on('broadcastControlCommand', this.broadcastControlCommand, this);
NotificationCenter.on('broadcastControlCommandExcept', this.broadcastControlCommandExcept, this);
NotificationCenter.on('broadcastGameCommand', this.broadcastGameCommand, this);
NotificationCenter.on('broadcastGameCommandExcept', this.broadcastGameCommandExcept, this);
console.checkpoint('channel ' + name + ' created');
}
@ -69,7 +72,7 @@
Channel.prototype.onReleaseUser = function (userId) {
var user = this.users[userId];
this.sendControlCommandToAllUsersExcept("userLeft", user.id, user);
this.broadcastControlCommandExcept("userLeft", user.id, user);
NotificationCenter.trigger('user/left', user);
delete this.users[user.id];
}
@ -77,13 +80,13 @@
// Sending commands
Channel.prototype.sendControlCommandToAllUsers = function (command, options) {
Channel.prototype.broadcastControlCommand = function (command, options) {
for(var id in this.users) {
this.users[id].sendControlCommand(command, options);
}
}
Channel.prototype.sendControlCommandToAllUsersExcept = function (command, options, exceptUser) {
Channel.prototype.broadcastControlCommandExcept = function (command, options, exceptUser) {
for(var id in this.users) {
if (id != exceptUser.id) {
this.users[id].sendControlCommand(command, options);
@ -91,6 +94,14 @@
}
}
Channel.prototype.broadcastGameCommand = function (command, options) {
this.broadcastControlCommand("gameCommand", ProtocolHelper.encodeCommand(command, options));
}
Channel.prototype.broadcastGameCommandExcept = function (command, options, exceptUser) {
this.broadcastControlCommandExcept("gameCommand", ProtocolHelper.encodeCommand(command, options), exceptUser);
}
return Channel;
});