mirror of
https://github.com/logsol/chuck.js.git
synced 2026-05-11 10:37:34 +00:00
fixed #58
This commit is contained in:
parent
d83376d5c7
commit
810a74a28b
13 changed files with 445 additions and 281 deletions
|
|
@ -9,7 +9,7 @@
|
|||
|
||||
function (GameController, Nc, User, ProtocolHelper, Options, Settings) {
|
||||
|
||||
function Channel (pipeToServer, name, options) {
|
||||
function Channel (pipeToServer, options) {
|
||||
|
||||
var self = this;
|
||||
|
||||
|
|
@ -17,7 +17,7 @@
|
|||
levelUids: Settings.DEFAULT_LEVELS
|
||||
});
|
||||
|
||||
this.name = name;
|
||||
this.name = options.channelName;
|
||||
this.users = {};
|
||||
|
||||
this.pipeToServer = pipeToServer;
|
||||
|
|
@ -34,11 +34,13 @@
|
|||
Nc.on('broadcastGameCommand', this.broadcastGameCommand, this);
|
||||
Nc.on('broadcastGameCommandExcept', this.broadcastGameCommandExcept, this);
|
||||
|
||||
console.checkpoint('channel ' + name + ' created');
|
||||
}
|
||||
console.checkpoint('channel ' + this.name + ' created');
|
||||
|
||||
Channel.validateName = function (name) {
|
||||
return true;
|
||||
setTimeout(function() {
|
||||
if(Object.keys(self.users).length < 1) {
|
||||
self.destroy();
|
||||
}
|
||||
}, Settings.CHANNEL_DESTRUCTION_TIME * 1000);
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -81,11 +83,22 @@
|
|||
|
||||
Channel.prototype.onReleaseUser = function (userId) {
|
||||
var user = this.users[userId];
|
||||
this.broadcastControlCommandExcept("userLeft", user.id, user);
|
||||
Nc.trigger('user/left', user);
|
||||
delete this.users[user.id];
|
||||
Nc.trigger('user/left', userId);
|
||||
delete this.users[userId];
|
||||
|
||||
this.broadcastControlCommand("userLeft", userId);
|
||||
|
||||
// FIXME: if this was the last user terminate forked process
|
||||
if(Object.keys(this.users).length < 1) {
|
||||
this.destroy();
|
||||
}
|
||||
}
|
||||
|
||||
Channel.prototype.destroy = function() {
|
||||
console.checkpoint("channel (" + this.name + ") destroyed");
|
||||
this.pipeToServer.destroy();
|
||||
};
|
||||
|
||||
|
||||
// Sending commands
|
||||
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ function (Parent, PhysicsEngine, Settings, PlayerController, requestAnimFrame, N
|
|||
Parent.call(this);
|
||||
|
||||
Nc.on('user/joined', this.onUserJoined, this);
|
||||
Nc.on('user/left', this.onUserLeft, this); // FIXME: refactor this.userLeft -> this.onUserLeft, even in core and client
|
||||
Nc.on('user/left', this.onUserLeft, this);
|
||||
Nc.on('user/resetLevel', this.onResetLevel, this);
|
||||
Nc.on('user/clientReady', this.onClientReady, this);
|
||||
Nc.on('player/killed', this.onPlayerKilled, this);
|
||||
|
|
|
|||
|
|
@ -17,10 +17,9 @@ function (Nc, Channel) {
|
|||
process.on('message', function (message, handle) {
|
||||
|
||||
if(message.data.hasOwnProperty('CREATE')) {
|
||||
self.channel = new Channel(this, message.data['CREATE']);
|
||||
self.channel = new Channel(self, message.data.options);
|
||||
} else if (message.data.hasOwnProperty('KILL')) {
|
||||
self.channel.destroy();
|
||||
process.exit(0);
|
||||
} else {
|
||||
self.onMessage(message);
|
||||
}
|
||||
|
|
@ -41,6 +40,11 @@ function (Nc, Channel) {
|
|||
Nc.trigger(message.recipient + '/controlCommand', message);
|
||||
}
|
||||
|
||||
PipeToServer.prototype.destroy = function() {
|
||||
this.send('coordinator', {destroy:this.channel.name});
|
||||
this.process.exit(0);
|
||||
};
|
||||
|
||||
return PipeToServer;
|
||||
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue