mirror of
https://github.com/logsol/chuck.js.git
synced 2026-05-11 10:37:34 +00:00
refactored Server and Lobby
This commit is contained in:
parent
42475c9b38
commit
d83376d5c7
26 changed files with 29 additions and 29 deletions
107
app/Server/Coordinator.js
Executable file
107
app/Server/Coordinator.js
Executable file
|
|
@ -0,0 +1,107 @@
|
|||
define([
|
||||
"Server/User",
|
||||
"Game/Channel/Channel",
|
||||
"Server/PipeToChannel",
|
||||
"Lib/Utilities/NotificationCenter"
|
||||
],
|
||||
|
||||
function (User, Channel, PipeToChannel, Nc) {
|
||||
|
||||
function Coordinator () {
|
||||
this.channelPipes = {};
|
||||
this.lobbyUsers = {};
|
||||
|
||||
console.checkpoint('create Coordinator');
|
||||
}
|
||||
|
||||
Coordinator.prototype.createUser = function (socketLink) {
|
||||
var user = new User(socketLink, this);
|
||||
console.checkpoint('creating user');
|
||||
this.assignUserToLobby(user);
|
||||
}
|
||||
|
||||
Coordinator.prototype.assignUserToLobby = function (user) {
|
||||
if(user.channelPipe) {
|
||||
//user.channel.releaseUser(user); -> generate message
|
||||
}
|
||||
this.lobbyUsers[user.id] = user;
|
||||
console.checkpoint('assign user to lobby');
|
||||
}
|
||||
|
||||
Coordinator.prototype.assignUserToChannel = function (user, channelName) {
|
||||
|
||||
if(user.channelPipe) {
|
||||
//user.channel.releaseUser(user); -> generate message
|
||||
}
|
||||
|
||||
if(!Channel.validateName(channelName)) {
|
||||
//TODO send validation error
|
||||
return false;
|
||||
}
|
||||
|
||||
var channelPipe = this.channelPipes[channelName];
|
||||
if(!channelPipe) {
|
||||
this.createPipe(channelName);
|
||||
}
|
||||
|
||||
//channel.addUser(user);
|
||||
//user.setChannel(channel);
|
||||
Nc.trigger('user/joined', user);
|
||||
|
||||
delete this.lobbyUsers[user.id];
|
||||
}
|
||||
|
||||
Coordinator.prototype.removeUser = function (user) {
|
||||
|
||||
Nc.trigger('user/left', user);
|
||||
//NotificationCenter.off('channel/' + user.channel.channelName + '/user/' + user.id);
|
||||
|
||||
delete this.lobbyUsers[user.id];
|
||||
}
|
||||
|
||||
Coordinator.prototype.createPipe = function(channelName) {
|
||||
|
||||
var channelPipe = new PipeToChannel(channelName);
|
||||
this.channelPipes[channelName] = channelPipe;
|
||||
|
||||
|
||||
Nc.on('channel/' + channelName + '/message', function (data) {
|
||||
channelPipe.send('channel', data);
|
||||
}, this);
|
||||
|
||||
// sending info to user
|
||||
Nc.on('user/joined', function (user) {
|
||||
/*
|
||||
Nc.on('channel/' + channelName + '/user/' + user.id, function (recipient, data) {
|
||||
channelPipe.send(recipient, data);
|
||||
}, this);
|
||||
*/
|
||||
|
||||
channelPipe.send('channel', { addUser: user.id });
|
||||
|
||||
}, this);
|
||||
|
||||
Nc.on('user/left', function (user) {
|
||||
channelPipe.send('channel', { releaseUser: user.id });
|
||||
}, this);
|
||||
|
||||
Nc.on('user/controlCommand', function (userId, data) {
|
||||
channelPipe.sendToUser(userId, data);
|
||||
}, this);
|
||||
|
||||
return channelPipe;
|
||||
};
|
||||
|
||||
Coordinator.prototype.getChannels = function(options) {
|
||||
var list = [];
|
||||
for (var channelName in this.channelPipes) {
|
||||
list.push({
|
||||
name: channelName
|
||||
});
|
||||
}
|
||||
return list;
|
||||
};
|
||||
|
||||
return Coordinator;
|
||||
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue