mirror of
https://github.com/logsol/chuck.js.git
synced 2026-05-11 10:37:34 +00:00
removed node-fork, using native child_process now, the API is the same
This commit is contained in:
parent
25653b4d58
commit
b5b10ba0b9
3 changed files with 29 additions and 7 deletions
|
|
@ -6,9 +6,10 @@ define([
|
||||||
function(GameController, NotificationCenter) {
|
function(GameController, NotificationCenter) {
|
||||||
|
|
||||||
function Channel(coordinatorLink) {
|
function Channel(coordinatorLink) {
|
||||||
|
var self = this;
|
||||||
|
|
||||||
this.coordinatorLink = coordinatorLink;
|
this.coordinatorLink = coordinatorLink;
|
||||||
this.coordinatorLink.receive = this.onMessage;
|
this.coordinatorLink.receive = function(message) { self.onMessage(message) };
|
||||||
|
|
||||||
this.users = {};
|
this.users = {};
|
||||||
|
|
||||||
|
|
@ -26,15 +27,22 @@ function(GameController, NotificationCenter) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Messages look like:
|
||||||
|
// {chanel: {setName: 'foo'}}
|
||||||
|
// {user: {jupm: null}, id: 12}
|
||||||
Channel.prototype.onMessage = function(message) {
|
Channel.prototype.onMessage = function(message) {
|
||||||
|
|
||||||
for(var recipient in message) {
|
for(var recipient in message) {
|
||||||
|
|
||||||
switch(recipient) {
|
switch(recipient) {
|
||||||
|
|
||||||
case 'user':
|
case 'user':
|
||||||
this.users[message.id].onMessage(message.user);
|
this.users[message.id].onMessage(message.user);
|
||||||
break;
|
break;
|
||||||
|
case 'id': // Do nothing, it is needed by the user
|
||||||
|
break;
|
||||||
case 'channel':
|
case 'channel':
|
||||||
this.onMessage(message.channel);
|
this.onCommand(message.channel);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
throw 'unknown recipient';
|
throw 'unknown recipient';
|
||||||
|
|
@ -42,6 +50,21 @@ function(GameController, NotificationCenter) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Channel.prototype.onCommand = function(message) {
|
||||||
|
for(var command in message) {
|
||||||
|
switch(command) {
|
||||||
|
|
||||||
|
case 'setName':
|
||||||
|
this.name = message[command];
|
||||||
|
console.log("Chanel name set to '" + this.name + "'");
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw 'unknown command';
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
/*
|
/*
|
||||||
Channel.prototype.addUser = function(user){
|
Channel.prototype.addUser = function(user){
|
||||||
var userIds = Object.keys(this.users);
|
var userIds = Object.keys(this.users);
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,12 @@
|
||||||
define([
|
define([
|
||||||
"Lobby/User",
|
"Lobby/User",
|
||||||
"Game/Server/Channel",
|
"Game/Server/Channel",
|
||||||
"node-fork"
|
"child_process"
|
||||||
],
|
],
|
||||||
|
|
||||||
function(User, Channel, nodeFork) {
|
function(User, Channel, childProcess) {
|
||||||
|
|
||||||
var fork = nodeFork.fork;
|
var fork = childProcess.fork;
|
||||||
|
|
||||||
function Coordinator() {
|
function Coordinator() {
|
||||||
this.channels = {};
|
this.channels = {};
|
||||||
|
|
|
||||||
|
|
@ -17,8 +17,7 @@
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"socket.io": ">= 0.9.6",
|
"socket.io": ">= 0.9.6",
|
||||||
"node-static": ">= 0.6.0",
|
"node-static": ">= 0.6.0",
|
||||||
"requirejs": ">= 2.0.2",
|
"requirejs": ">= 2.0.2"
|
||||||
"node-fork": ">= 0.4.2"
|
|
||||||
},
|
},
|
||||||
"devDependencies": {},
|
"devDependencies": {},
|
||||||
"optionalDependencies": {},
|
"optionalDependencies": {},
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue