mirror of
https://github.com/logsol/chuck.js.git
synced 2026-05-11 18:47:35 +00:00
replaced all tabs with 4 spaces
This commit is contained in:
parent
5d11540c55
commit
26f3d22db7
30 changed files with 1017 additions and 1011 deletions
|
|
@ -1,74 +1,74 @@
|
|||
define([
|
||||
"Lobby/User",
|
||||
"Game/Server/Channel",
|
||||
"child_process"
|
||||
"Lobby/User",
|
||||
"Game/Server/Channel",
|
||||
"child_process"
|
||||
],
|
||||
|
||||
function(User, Channel, childProcess) {
|
||||
|
||||
var fork = childProcess.fork;
|
||||
var fork = childProcess.fork;
|
||||
|
||||
function Coordinator() {
|
||||
this.channels = {};
|
||||
this.lobbyUsers = {};
|
||||
}
|
||||
function Coordinator() {
|
||||
this.channels = {};
|
||||
this.lobbyUsers = {};
|
||||
}
|
||||
|
||||
Coordinator.prototype.createUser = function(socketLink){
|
||||
var user = new User(socketLink, this);
|
||||
this.assignUserToLobby(user);
|
||||
}
|
||||
Coordinator.prototype.createUser = function(socketLink){
|
||||
var user = new User(socketLink, this);
|
||||
this.assignUserToLobby(user);
|
||||
}
|
||||
|
||||
Coordinator.prototype.assignUserToLobby = function(user){
|
||||
if(user.channelProcess) {
|
||||
//user.channel.releaseUser(user); -> generate message
|
||||
}
|
||||
this.lobbyUsers[user.id] = user;
|
||||
}
|
||||
Coordinator.prototype.assignUserToLobby = function(user){
|
||||
if(user.channelProcess) {
|
||||
//user.channel.releaseUser(user); -> generate message
|
||||
}
|
||||
this.lobbyUsers[user.id] = user;
|
||||
}
|
||||
|
||||
Coordinator.prototype.assignUserToChannel = function(user, channelName){
|
||||
Coordinator.prototype.assignUserToChannel = function(user, channelName){
|
||||
|
||||
if(user.channelProcess) {
|
||||
//user.channel.releaseUser(user); -> generate message
|
||||
}
|
||||
if(user.channelProcess) {
|
||||
//user.channel.releaseUser(user); -> generate message
|
||||
}
|
||||
|
||||
if(!Channel.validateName(channelName)){
|
||||
//TODO send validation error
|
||||
return false;
|
||||
}
|
||||
if(!Channel.validateName(channelName)){
|
||||
//TODO send validation error
|
||||
return false;
|
||||
}
|
||||
|
||||
var channel = this.channels[channelName];
|
||||
if(!channel) {
|
||||
var channel = this.channels[channelName];
|
||||
if(!channel) {
|
||||
|
||||
try {
|
||||
channel = fork('channel.js');
|
||||
channel.send('CREATE');
|
||||
try {
|
||||
channel = fork('channel.js');
|
||||
channel.send('CREATE');
|
||||
|
||||
channel.send({
|
||||
channel: {
|
||||
setName: channelName
|
||||
}
|
||||
});
|
||||
|
||||
} catch (err) {
|
||||
throw 'Failed to fork channel ' + channelName + '! (' + err + ')';
|
||||
}
|
||||
channel.send({
|
||||
channel: {
|
||||
setName: channelName
|
||||
}
|
||||
});
|
||||
|
||||
} catch (err) {
|
||||
throw 'Failed to fork channel ' + channelName + '! (' + err + ')';
|
||||
}
|
||||
|
||||
this.channels[channelName] = channel;
|
||||
}
|
||||
this.channels[channelName] = channel;
|
||||
}
|
||||
|
||||
//channel.addUser(user);
|
||||
//user.setChannel(channel);
|
||||
//channel.addUser(user);
|
||||
//user.setChannel(channel);
|
||||
|
||||
delete this.lobbyUsers[user.id];
|
||||
}
|
||||
delete this.lobbyUsers[user.id];
|
||||
}
|
||||
|
||||
Coordinator.prototype.removeUser = function(user){
|
||||
delete this.lobbyUsers[user.id];
|
||||
if(user.channelProcess) {
|
||||
//user.channel.releaseUser(user); -> generate message
|
||||
}
|
||||
}
|
||||
Coordinator.prototype.removeUser = function(user){
|
||||
delete this.lobbyUsers[user.id];
|
||||
if(user.channelProcess) {
|
||||
//user.channel.releaseUser(user); -> generate message
|
||||
}
|
||||
}
|
||||
|
||||
return Coordinator;
|
||||
return Coordinator;
|
||||
|
||||
});
|
||||
|
|
@ -1,66 +1,66 @@
|
|||
define([
|
||||
"Game/Core/User",
|
||||
"Game/Core/Protocol/Helper"
|
||||
"Game/Core/User",
|
||||
"Game/Core/Protocol/Helper"
|
||||
],
|
||||
|
||||
function(Parent, ProtocolHelper) {
|
||||
|
||||
function User(socketLink, coordinator) {
|
||||
Parent.call(this, socketLink.id);
|
||||
function User(socketLink, coordinator) {
|
||||
Parent.call(this, socketLink.id);
|
||||
|
||||
this.coordinator = coordinator;
|
||||
this.channelProcess = null;
|
||||
this.coordinator = coordinator;
|
||||
this.channelProcess = null;
|
||||
|
||||
var self = this;
|
||||
var self = this;
|
||||
|
||||
socketLink.on('message', function(message){
|
||||
self.onMessage(message);
|
||||
});
|
||||
socketLink.on('disconnect', function(){
|
||||
self.onDisconnect();
|
||||
});
|
||||
}
|
||||
socketLink.on('message', function(message){
|
||||
self.onMessage(message);
|
||||
});
|
||||
socketLink.on('disconnect', function(){
|
||||
self.onDisconnect();
|
||||
});
|
||||
}
|
||||
|
||||
User.prototype = Object.create(Parent.prototype);
|
||||
User.prototype = Object.create(Parent.prototype);
|
||||
|
||||
User.prototype.setChannelProcess = function(channelProcess) {
|
||||
this.channelProcess = channelProcess;
|
||||
}
|
||||
User.prototype.setChannelProcess = function(channelProcess) {
|
||||
this.channelProcess = channelProcess;
|
||||
}
|
||||
|
||||
User.prototype.onMessage = function(message){
|
||||
var self = this;
|
||||
ProtocolHelper.runCommands(message, function(command, options){
|
||||
self.processControlCommand(command, options);
|
||||
});
|
||||
}
|
||||
User.prototype.onMessage = function(message){
|
||||
var self = this;
|
||||
ProtocolHelper.runCommands(message, function(command, options){
|
||||
self.processControlCommand(command, options);
|
||||
});
|
||||
}
|
||||
|
||||
User.prototype.onDisconnect = function(){
|
||||
this.coordinator.removeUser(this);
|
||||
}
|
||||
User.prototype.onDisconnect = function(){
|
||||
this.coordinator.removeUser(this);
|
||||
}
|
||||
|
||||
User.prototype.processControlCommand = function(command, options){
|
||||
switch(command) {
|
||||
User.prototype.processControlCommand = function(command, options){
|
||||
switch(command) {
|
||||
|
||||
case 'join':
|
||||
this.coordinator.assignUserToChannel(this, options);
|
||||
break;
|
||||
case 'join':
|
||||
this.coordinator.assignUserToChannel(this, options);
|
||||
break;
|
||||
|
||||
case 'leave':
|
||||
this.coordinator.assignUserToLobby(this);
|
||||
break;
|
||||
case 'leave':
|
||||
this.coordinator.assignUserToLobby(this);
|
||||
break;
|
||||
|
||||
case 'gameCommand':
|
||||
for(var gameCommand in options) {
|
||||
//NotificationCenter.trigger("processGameCommandFromUser", [gameCommand, options[gameCommand], this]);
|
||||
//this.channel.processGameCommandFromUser(gameCommand, options[gameCommand], this);
|
||||
}
|
||||
break;
|
||||
case 'gameCommand':
|
||||
for(var gameCommand in options) {
|
||||
//NotificationCenter.trigger("processGameCommandFromUser", [gameCommand, options[gameCommand], this]);
|
||||
//this.channel.processGameCommandFromUser(gameCommand, options[gameCommand], this);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return User;
|
||||
return User;
|
||||
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue