mirror of
https://github.com/logsol/chuck.js.git
synced 2026-05-11 10:37:34 +00:00
58 lines
No EOL
1.5 KiB
JavaScript
Executable file
58 lines
No EOL
1.5 KiB
JavaScript
Executable file
define(["Game/Server/GameController"], function(GameController) {
|
|
|
|
function Channel(name) {
|
|
this.name = name;
|
|
this.users = {};
|
|
this.serverGame = new GameController();
|
|
console.log("server game " + this.serverGame);
|
|
this.serverGame.loadLevel("default.json");
|
|
|
|
var self = this;
|
|
this.notificationCenter.on("processGameCommandFromUser", function(topic, args) {
|
|
self.processGameCommandFromUser.apply(self, args);
|
|
});
|
|
}
|
|
|
|
Channel.validateName = function(name){
|
|
return true;
|
|
}
|
|
|
|
Channel.prototype.addUser = function(user){
|
|
var userIds = Object.keys(this.users);
|
|
|
|
this.users[user.id] = user;
|
|
|
|
user.sendCommand('joinSuccess', {channelName: this.name, id: user.id, userIds: userIds});
|
|
this.sendCommandToAllUsersExcept('userJoined', user.id, user);
|
|
|
|
this.serverGame.createPlayerForUser(user)
|
|
}
|
|
|
|
Channel.prototype.releaseUser = function(user) {
|
|
this.serverGame.userIdLeft(user.id);
|
|
|
|
this.sendCommandToAllUsersExcept("userLeft", user.id, user);
|
|
delete this.users[user.id];
|
|
}
|
|
|
|
Channel.prototype.sendCommandToAllUsers = function(command, options) {
|
|
for(var id in this.users) {
|
|
this.users[id].sendCommand(command, options);
|
|
}
|
|
}
|
|
|
|
Channel.prototype.sendCommandToAllUsersExcept = function(command, options, except_user) {
|
|
for(var id in this.users) {
|
|
if (id != except_user.id) {
|
|
this.users[id].sendCommand(command, options);
|
|
}
|
|
}
|
|
}
|
|
|
|
Channel.prototype.processGameCommandFromUser = function(command, options, user) {
|
|
this.serverGame.progressGameCommandFromUser(command, options, user);
|
|
}
|
|
|
|
return Channel;
|
|
|
|
}); |