mirror of
https://github.com/logsol/chuck.js.git
synced 2026-05-11 10:37:34 +00:00
When we require a singleton, its instance name should be named by lowercase, since it is not a class. Relates to #128
75 lines
No EOL
1.9 KiB
JavaScript
75 lines
No EOL
1.9 KiB
JavaScript
define([
|
|
"Server/User",
|
|
"Server/PipeToChannel",
|
|
"Lib/Utilities/NotificationCenter",
|
|
"Game/Config/Settings"
|
|
],
|
|
|
|
function (User, PipeToChannel, nc, Settings) {
|
|
|
|
"use strict";
|
|
|
|
function Coordinator() {
|
|
this.channelPipes = {};
|
|
|
|
nc.on(nc.ns.server.events.controlCommand.coordinator, this.onMessage, this);
|
|
|
|
console.checkpoint('create Coordinator');
|
|
}
|
|
|
|
Coordinator.prototype.createUser = function (socketLink) {
|
|
new User(socketLink, this);
|
|
}
|
|
|
|
// was assignUserToChannel...
|
|
Coordinator.prototype.getChannelPipeByName = function (channelName) {
|
|
return this.channelPipes[channelName];
|
|
}
|
|
|
|
Coordinator.prototype.onDestroyPipe = function(channelName) {
|
|
delete this.channelPipes[channelName];
|
|
}
|
|
|
|
Coordinator.prototype.getChannels = function(options) {
|
|
var list = [];
|
|
for (var channelName in this.channelPipes) {
|
|
|
|
var options = this.channelPipes[channelName].options;
|
|
|
|
var playerNames = [];
|
|
var users = this.channelPipes[channelName].getUsers();
|
|
for (var i = 0; i < users.length; i++) {
|
|
playerNames[i] = users[i].options.nickname;
|
|
};
|
|
options.players = playerNames;
|
|
options.playerCount = options.players.length;
|
|
|
|
list.push(options);
|
|
}
|
|
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;
|
|
|
|
}); |