mirror of
https://github.com/logsol/chuck.js.git
synced 2026-05-11 10:37:34 +00:00
implemented channel forking
This commit is contained in:
parent
815c63009f
commit
25653b4d58
4 changed files with 33 additions and 16 deletions
|
|
@ -1,8 +1,9 @@
|
||||||
define([
|
define([
|
||||||
"Game/Server/Channel"
|
"Game/Server/Channel",
|
||||||
|
"Game/Server/CoordinatorLink"
|
||||||
],
|
],
|
||||||
|
|
||||||
function(Channel) {
|
function(Channel, CoordinatorLink) {
|
||||||
|
|
||||||
function ChannelBootstrap(process) {
|
function ChannelBootstrap(process) {
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -8,14 +8,13 @@ function(GameController, NotificationCenter) {
|
||||||
function Channel(coordinatorLink) {
|
function Channel(coordinatorLink) {
|
||||||
|
|
||||||
this.coordinatorLink = coordinatorLink;
|
this.coordinatorLink = coordinatorLink;
|
||||||
|
this.coordinatorLink.receive = this.onMessage;
|
||||||
console.log('A CHANNEL WAS CREATED');
|
|
||||||
/*
|
|
||||||
this.users = {};
|
this.users = {};
|
||||||
|
|
||||||
this.gameController = new GameController();
|
this.gameController = new GameController();
|
||||||
this.gameController.loadLevel("default.json");
|
this.gameController.loadLevel("default.json");
|
||||||
*/
|
/*
|
||||||
/*
|
|
||||||
var self = this;
|
var self = this;
|
||||||
NotificationCenter.on("processGameCommandFromUser", function(topic, args) {
|
NotificationCenter.on("processGameCommandFromUser", function(topic, args) {
|
||||||
self.processGameCommandFromUser.apply(self, args);
|
self.processGameCommandFromUser.apply(self, args);
|
||||||
|
|
@ -26,6 +25,23 @@ function(GameController, NotificationCenter) {
|
||||||
Channel.validateName = function(name){
|
Channel.validateName = function(name){
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Channel.prototype.onMessage = function(message) {
|
||||||
|
for(var recipient in message) {
|
||||||
|
switch(recipient) {
|
||||||
|
|
||||||
|
case 'user':
|
||||||
|
this.users[message.id].onMessage(message.user);
|
||||||
|
break;
|
||||||
|
case 'channel':
|
||||||
|
this.onMessage(message.channel);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw 'unknown recipient';
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
/*
|
/*
|
||||||
Channel.prototype.addUser = function(user){
|
Channel.prototype.addUser = function(user){
|
||||||
var userIds = Object.keys(this.users);
|
var userIds = Object.keys(this.users);
|
||||||
|
|
|
||||||
|
|
@ -40,10 +40,15 @@ function(User, Channel, nodeFork) {
|
||||||
if(!channel) {
|
if(!channel) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
console.log('try');
|
channel = fork('channel.js');
|
||||||
channel = fork('app/Bootstrap/Channel.js');
|
|
||||||
channel.send('CREATE');
|
channel.send('CREATE');
|
||||||
channel.send('{setName:"' + channelName + '"}');
|
|
||||||
|
channel.send({
|
||||||
|
channel: {
|
||||||
|
setName: channelName
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
throw 'Failed to fork channel ' + channelName + '! (' + err + ')';
|
throw 'Failed to fork channel ' + channelName + '! (' + err + ')';
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,4 @@
|
||||||
console.log(requirejs);
|
var requirejs = require('requirejs');
|
||||||
|
|
||||||
|
|
||||||
var ree = require('requirejs');
|
|
||||||
|
|
||||||
console.log(ree);
|
|
||||||
|
|
||||||
requirejs.config({
|
requirejs.config({
|
||||||
baseUrl: 'app'
|
baseUrl: 'app'
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue