diff --git a/app/Game/Server/Channel.js b/app/Game/Server/Channel.js index 97a2621..f5a59da 100755 --- a/app/Game/Server/Channel.js +++ b/app/Game/Server/Channel.js @@ -6,9 +6,10 @@ define([ function(GameController, NotificationCenter) { function Channel(coordinatorLink) { + var self = this; this.coordinatorLink = coordinatorLink; - this.coordinatorLink.receive = this.onMessage; + this.coordinatorLink.receive = function(message) { self.onMessage(message) }; this.users = {}; @@ -26,15 +27,22 @@ function(GameController, NotificationCenter) { return true; } + // Messages look like: + // {chanel: {setName: 'foo'}} + // {user: {jupm: null}, id: 12} Channel.prototype.onMessage = function(message) { + for(var recipient in message) { + switch(recipient) { case 'user': this.users[message.id].onMessage(message.user); break; + case 'id': // Do nothing, it is needed by the user + break; case 'channel': - this.onMessage(message.channel); + this.onCommand(message.channel); break; default: 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){ var userIds = Object.keys(this.users); diff --git a/app/Lobby/Coordinator.js b/app/Lobby/Coordinator.js index 8322726..b2434d4 100755 --- a/app/Lobby/Coordinator.js +++ b/app/Lobby/Coordinator.js @@ -1,12 +1,12 @@ define([ "Lobby/User", "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() { this.channels = {}; diff --git a/package.json b/package.json index 0503987..15afafd 100755 --- a/package.json +++ b/package.json @@ -17,8 +17,7 @@ "dependencies": { "socket.io": ">= 0.9.6", "node-static": ">= 0.6.0", - "requirejs": ">= 2.0.2", - "node-fork": ">= 0.4.2" + "requirejs": ">= 2.0.2" }, "devDependencies": {}, "optionalDependencies": {},