mirror of
https://github.com/logsol/chuck.js.git
synced 2026-05-11 10:37:34 +00:00
some more renaming
This commit is contained in:
parent
9de3147406
commit
bd45f538c7
34 changed files with 0 additions and 0 deletions
53
app/Lobby/Coordinator.js
Normal file
53
app/Lobby/Coordinator.js
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
define(["Server/User", "Server/Channel", "Server/Factory"], function(User, Channel, Factory) {
|
||||
|
||||
function Coordinator() {
|
||||
this.channels = {};
|
||||
this.lobbyUsers = {};
|
||||
}
|
||||
|
||||
Coordinator.prototype.createUser = function(socketLink){
|
||||
var user = new User(socketLink, this);
|
||||
this.assignUserToLobby(user);
|
||||
}
|
||||
|
||||
Coordinator.prototype.assignUserToLobby = function(user){
|
||||
if(user.channel) {
|
||||
user.channel.releaseUser(user);
|
||||
}
|
||||
this.lobbyUsers[user.id] = user;
|
||||
}
|
||||
|
||||
Coordinator.prototype.assignUserToChannel = function(user, channelName){
|
||||
|
||||
if(user.channel) {
|
||||
user.channel.releaseUser(user);
|
||||
}
|
||||
|
||||
if(!Channel.validateName(channelName)){
|
||||
//TODO send validation error
|
||||
return false;
|
||||
}
|
||||
|
||||
var channel = this.channels[channelName];
|
||||
if(!channel) {
|
||||
var factory = new Factory();
|
||||
channel = factory.new(Channel, channelName);
|
||||
this.channels[channelName] = channel;
|
||||
}
|
||||
|
||||
channel.addUser(user);
|
||||
user.setChannel(channel);
|
||||
|
||||
delete this.lobbyUsers[user.id];
|
||||
}
|
||||
|
||||
Coordinator.prototype.removeUser = function(user){
|
||||
delete this.lobbyUsers[user.id];
|
||||
if(user.channel) {
|
||||
user.channel.releaseUser(user);
|
||||
}
|
||||
}
|
||||
|
||||
return Coordinator;
|
||||
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue