mirror of
https://github.com/logsol/chuck.js.git
synced 2026-05-11 10:37:34 +00:00
messed everything up .... :( 111
This commit is contained in:
parent
03678eb773
commit
ec1bceb1b6
13 changed files with 145 additions and 117 deletions
|
|
@ -1,34 +0,0 @@
|
|||
define([
|
||||
"Game/Server/Channel",
|
||||
"Game/Server/CoordinatorLink"
|
||||
],
|
||||
|
||||
function (Channel, CoordinatorLink) {
|
||||
|
||||
function ChannelBootstrap (process) {
|
||||
|
||||
var coordinatorLink = new CoordinatorLink(process);
|
||||
var channel = null;
|
||||
|
||||
process.on('message', function (message) {
|
||||
|
||||
switch(message) {
|
||||
case 'CREATE':
|
||||
channel = new Channel(coordinatorLink);
|
||||
break;
|
||||
|
||||
case 'KILL':
|
||||
channel.destroy();
|
||||
process.exit(0);
|
||||
break;
|
||||
|
||||
default:
|
||||
coordinatorLink.receive(message);
|
||||
break;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return ChannelBootstrap;
|
||||
|
||||
});
|
||||
|
|
@ -1,15 +0,0 @@
|
|||
define([
|
||||
"Game/Client/Networker",
|
||||
"Lib/Vendor/SocketIO"
|
||||
],
|
||||
|
||||
function (Networker, SocketIO) {
|
||||
|
||||
function Client (location, options) {
|
||||
this.socket = SocketIO.connect(location, options);
|
||||
this.networker = new Networker(this.socket);
|
||||
}
|
||||
|
||||
return Client;
|
||||
|
||||
});
|
||||
|
|
@ -1,16 +0,0 @@
|
|||
define([
|
||||
"Bootstrap/HttpServer",
|
||||
"Bootstrap/Socket",
|
||||
"Lobby/Coordinator"
|
||||
],
|
||||
|
||||
function (HttpServer, Socket, Coordinator) {
|
||||
|
||||
function Server (options) {
|
||||
coordinator = new Coordinator();
|
||||
httpServer = new HttpServer(options);
|
||||
this.socket = new Socket(httpServer.getServer(), options, coordinator);
|
||||
}
|
||||
|
||||
return Server;
|
||||
});
|
||||
|
|
@ -8,7 +8,7 @@ function () {
|
|||
this.subUid = -1;
|
||||
}
|
||||
|
||||
NotificationCenter.prototype.trigger = function (topic) {
|
||||
NotificationCenter.prototype.trigger = function (topic /*, arguments*/) {
|
||||
|
||||
if (!this.topics[topic]) {
|
||||
throw "No such topic " + topic + ". Could not trigger.";
|
||||
|
|
|
|||
|
|
@ -1,20 +0,0 @@
|
|||
define([
|
||||
],
|
||||
|
||||
function () {
|
||||
|
||||
function CoordinatorLink (process) {
|
||||
this.process = process;
|
||||
}
|
||||
|
||||
CoordinatorLink.prototype.send = function (message) {
|
||||
this.process.send(message);
|
||||
};
|
||||
|
||||
CoordinatorLink.prototype.receive = function (message) {
|
||||
throw 'This method is abstract and must be overwritten by Channel';
|
||||
};
|
||||
|
||||
return CoordinatorLink;
|
||||
|
||||
});
|
||||
48
app/Game/Server/PipeToLobby.js
Executable file
48
app/Game/Server/PipeToLobby.js
Executable file
|
|
@ -0,0 +1,48 @@
|
|||
define([
|
||||
"Game/Core/NotficationCenter"
|
||||
],
|
||||
|
||||
function (NotficationCenter) {
|
||||
|
||||
function PipeToLobby (process) {
|
||||
|
||||
this.channel = null;
|
||||
this.process = process;
|
||||
|
||||
NotficationCenter.on('net/send', this.send, this);
|
||||
|
||||
process.on('message', function (message, handle) {
|
||||
|
||||
switch(message) {
|
||||
case 'CREATE':
|
||||
this.channel = new Channel(this);
|
||||
break;
|
||||
|
||||
case 'KILL':
|
||||
this.channel.destroy();
|
||||
process.exit(0);
|
||||
break;
|
||||
|
||||
default:
|
||||
this.onMessage(message);
|
||||
break;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
PipeToLobby.prototype.send = function (recipient, data) {
|
||||
var message = {
|
||||
recipient: recipient,
|
||||
data: data
|
||||
}
|
||||
|
||||
this.process.send(message);
|
||||
};
|
||||
|
||||
PipeToLobby.prototype.onMessage = function (message) {
|
||||
NotficationCenter.trigger(message.recipient + '/message', message.data);
|
||||
}
|
||||
|
||||
return PipeToLobby;
|
||||
|
||||
});
|
||||
|
|
@ -6,8 +6,8 @@ define([
|
|||
|
||||
function (Parent, ProtocolHelper, NotificationCenter) {
|
||||
|
||||
function User (id, coordinator) {
|
||||
Parent.call(this, id);
|
||||
function User (socketLink, coordinator) {
|
||||
Parent.call(this, socketLink.id);
|
||||
this.id = socketLink.id;
|
||||
this.socketLink = socketLink;
|
||||
this.coordinator = coordinator;
|
||||
|
|
|
|||
|
|
@ -1,10 +1,11 @@
|
|||
define([
|
||||
"Lobby/User",
|
||||
"Game/Server/Channel",
|
||||
"Lobby/PipeToChannel"
|
||||
"child_process"
|
||||
],
|
||||
|
||||
function (User, Channel, childProcess) {
|
||||
function (User, Channel, PipeToChannel, childProcess) {
|
||||
|
||||
var fork = childProcess.fork;
|
||||
|
||||
|
|
@ -38,22 +39,22 @@ function (User, Channel, childProcess) {
|
|||
|
||||
var channel = this.channels[channelName];
|
||||
if(!channel) {
|
||||
|
||||
try {
|
||||
channel = fork('channel.js');
|
||||
channel.send('CREATE');
|
||||
|
||||
channel.send({
|
||||
channel: {
|
||||
setName: channelName
|
||||
}
|
||||
});
|
||||
|
||||
} catch (err) {
|
||||
throw 'Failed to fork channel ' + channelName + '! (' + err + ')';
|
||||
}
|
||||
|
||||
channel = new PipeToChannel(channelName);
|
||||
this.channels[channelName] = channel;
|
||||
|
||||
NotificationCenter.on('channel/' + channelName + '/message', function (data) {
|
||||
channel.send('channel', data);
|
||||
}, this);
|
||||
|
||||
NotificationCenter.on('user/joined', function (user) {
|
||||
NotificationCenter.on('channel/' + channelName + '/user/' + user.id, function (recipient, data) {
|
||||
channel.send(recipient, data);
|
||||
}, this);
|
||||
}, this);
|
||||
|
||||
NotificationCenter.on('user/left', function (user) {
|
||||
|
||||
}, this);
|
||||
}
|
||||
|
||||
//channel.addUser(user);
|
||||
|
|
@ -63,10 +64,11 @@ function (User, Channel, childProcess) {
|
|||
}
|
||||
|
||||
Coordinator.prototype.removeUser = function (user) {
|
||||
|
||||
user.channel.send('user/' + user.id + '/left');
|
||||
NotificationCenter.off('channel/' + user.channel.channelName + '/user/' + user.id);
|
||||
|
||||
delete this.lobbyUsers[user.id];
|
||||
if(user.channelProcess) {
|
||||
//user.channel.releaseUser(user); -> generate message
|
||||
}
|
||||
}
|
||||
|
||||
return Coordinator;
|
||||
|
|
|
|||
38
app/Lobby/PipeToChannel.js
Executable file
38
app/Lobby/PipeToChannel.js
Executable file
|
|
@ -0,0 +1,38 @@
|
|||
define([
|
||||
"Game/Core/NotificationCenter"
|
||||
],
|
||||
|
||||
function (NotificationCenter) {
|
||||
|
||||
function PipeToChannel (channelName) {
|
||||
|
||||
this.channelProcess = null;
|
||||
|
||||
try {
|
||||
this.channelProcess = fork('channel.js');
|
||||
} catch (err) {
|
||||
throw 'Failed to fork channel! (' + err + ')';
|
||||
}
|
||||
|
||||
this.send('channel/' + channelName, 'CREATE');
|
||||
this.channelProcess.on('message', this.onMessage.bind(this));
|
||||
|
||||
var self = this;
|
||||
}
|
||||
|
||||
PipeToChannel.prototype.send = function (recipient, data) {
|
||||
var message = {
|
||||
recipient: recipient,
|
||||
data: data
|
||||
}
|
||||
|
||||
this.channelProcess.send(message);
|
||||
}
|
||||
|
||||
PipeToChannel.prototype.onMessage = function (message) {
|
||||
NotficationCenter.trigger(message.recipient + '/message', message.data);
|
||||
}
|
||||
|
||||
return PipeToChannel;
|
||||
|
||||
});
|
||||
|
|
@ -10,6 +10,7 @@ function (Parent, ProtocolHelper) {
|
|||
|
||||
this.coordinator = coordinator;
|
||||
this.channelProcess = null;
|
||||
this.socketLink = socketLink;
|
||||
|
||||
var self = this;
|
||||
|
||||
|
|
|
|||
10
channel.js
10
channel.js
|
|
@ -6,8 +6,12 @@ requirejs.config({
|
|||
|
||||
var inspector = {};
|
||||
|
||||
requirejs(["Bootstrap/Channel"], function (ChannelBootstrap) {
|
||||
requirejs([
|
||||
"Game/Server/LobbyPipe"
|
||||
],
|
||||
|
||||
var channelBootstrap = new ChannelBootstrap(process);
|
||||
inspector.channelBootstrap = channelBootstrap;
|
||||
function (LobbyPipe) {
|
||||
var lobbyPipe = new LobbyPipe(process);
|
||||
|
||||
inspector.lobbyPipe = lobbyPipe;
|
||||
});
|
||||
13
client.js
13
client.js
|
|
@ -4,7 +4,12 @@ requirejs.config({
|
|||
|
||||
var inspector = {};
|
||||
|
||||
requirejs(["Bootstrap/Client"], function (Client) {
|
||||
requirejs([
|
||||
"Game/Client/Networker",
|
||||
"Lib/Vendor/SocketIO"
|
||||
],
|
||||
|
||||
function (Networker, SocketIO) {
|
||||
|
||||
var options = {
|
||||
"reconnect": false,
|
||||
|
|
@ -17,6 +22,8 @@ requirejs(["Bootstrap/Client"], function (Client) {
|
|||
],
|
||||
};
|
||||
|
||||
var client = new Client(location.href, options);
|
||||
inspector.client = client;
|
||||
var socket = SocketIO.connect(location.href, options);
|
||||
var networker = new Networker(socket);
|
||||
|
||||
inspector.networker = networker;
|
||||
});
|
||||
21
server.js
21
server.js
|
|
@ -1,6 +1,6 @@
|
|||
var requirejs = require('requirejs');
|
||||
|
||||
var inspector = {};
|
||||
var inspector;
|
||||
|
||||
requirejs.config({
|
||||
nodeRequire: require,
|
||||
|
|
@ -18,9 +18,22 @@ var options = {
|
|||
logLevel: process.argv[3] || 0
|
||||
};
|
||||
|
||||
requirejs(["Bootstrap/Server"], function (Server) {
|
||||
var server = new Server(options);
|
||||
inspector.server = server;
|
||||
requirejs([
|
||||
"Bootstrap/HttpServer",
|
||||
"Bootstrap/Socket",
|
||||
"Lobby/Coordinator"
|
||||
],
|
||||
|
||||
function (HttpServer, Socket, Coordinator) {
|
||||
var coordinator = new Coordinator();
|
||||
var httpServer = new HttpServer(options);
|
||||
var socket = new Socket(httpServer.getServer(), options, coordinator);
|
||||
|
||||
inspector = {
|
||||
coordinator: coordinator,
|
||||
httpServer: httpServer,
|
||||
socket: socket
|
||||
}
|
||||
});
|
||||
|
||||
exports = module.exports = inspector;
|
||||
Loading…
Add table
Add a link
Reference in a new issue