mirror of
https://github.com/logsol/chuck.js.git
synced 2026-05-11 10:37:34 +00:00
65 lines
No EOL
1.6 KiB
JavaScript
65 lines
No EOL
1.6 KiB
JavaScript
define([
|
|
"Server/User",
|
|
"Game/Channel/Channel",
|
|
"Server/PipeToChannel",
|
|
"Lib/Utilities/NotificationCenter",
|
|
"Game/Config/Settings"
|
|
],
|
|
|
|
function (User, Channel, PipeToChannel, Nc, Settings) {
|
|
|
|
function Coordinator() {
|
|
this.channelPipes = {};
|
|
|
|
Nc.on('coordinator/message', this.onMessage, this);
|
|
|
|
console.checkpoint('create Coordinator');
|
|
}
|
|
|
|
Coordinator.prototype.createUser = function (socketLink) {
|
|
new User(socketLink, this);
|
|
}
|
|
|
|
Coordinator.prototype.assignUserToChannel = function (user, channelName) {
|
|
var channelPipe = this.channelPipes[channelName];
|
|
user.setChannelPipe(channelPipe);
|
|
}
|
|
|
|
Coordinator.prototype.onDestroyPipe = function(channelName) {
|
|
delete this.channelPipes[channelName];
|
|
}
|
|
|
|
Coordinator.prototype.getChannels = function(options) {
|
|
var list = [];
|
|
for (var channelName in this.channelPipes) {
|
|
list.push({
|
|
name: channelName
|
|
});
|
|
}
|
|
return list;
|
|
}
|
|
|
|
Coordinator.prototype.createChannel = function(options) {
|
|
if(this.channelPipes[options.channelName]) {
|
|
return false;
|
|
}
|
|
|
|
var channelPipe = new PipeToChannel(options);
|
|
this.channelPipes[options.channelName] = channelPipe;
|
|
return {
|
|
channelName: options.channelName,
|
|
link: "#" + options.channelName,
|
|
timeout: Settings.CHANNEL_DESTRUCTION_TIME
|
|
}
|
|
};
|
|
|
|
Coordinator.prototype.onMessage = function(message) {
|
|
if(message.destroy) {
|
|
delete this.channelPipes[message.destroy];
|
|
}
|
|
};
|
|
|
|
|
|
return Coordinator;
|
|
|
|
}); |