mirror of
https://github.com/logsol/chuck.js.git
synced 2026-05-11 10:37:34 +00:00
join success roundtrip added
This commit is contained in:
parent
e93dbf2f2a
commit
2183e70bd8
5 changed files with 48 additions and 53 deletions
|
|
@ -19,11 +19,12 @@ function (ProtocolHelper, GameController) {
|
||||||
this.socketLink.on('connect', function () {
|
this.socketLink.on('connect', function () {
|
||||||
self.onConnect();
|
self.onConnect();
|
||||||
});
|
});
|
||||||
/*
|
|
||||||
this.socketLink.on('message', function (message) {
|
this.socketLink.on('message', function (message) {
|
||||||
self.onMessage(message);
|
//self.onMessage(message);
|
||||||
|
console.log('Message from server: ', message);
|
||||||
});
|
});
|
||||||
*/
|
|
||||||
this.socketLink.on('disconnect', function () {
|
this.socketLink.on('disconnect', function () {
|
||||||
self.onDisconnect();
|
self.onDisconnect();
|
||||||
});
|
});
|
||||||
|
|
@ -48,7 +49,7 @@ function (ProtocolHelper, GameController) {
|
||||||
|
|
||||||
|
|
||||||
Networker.prototype.onJoinSuccess = function (options) {
|
Networker.prototype.onJoinSuccess = function (options) {
|
||||||
this.gameController = new GameController(options.id);
|
this.gameController = new GameController();
|
||||||
this.gameController.loadLevel("default.json");
|
this.gameController.loadLevel("default.json");
|
||||||
/*
|
/*
|
||||||
console.log("Joined " + options.channelName);
|
console.log("Joined " + options.channelName);
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,10 @@
|
||||||
define([
|
define([
|
||||||
"Game/Server/GameController",
|
"Game/Server/GameController",
|
||||||
"Game/Core/NotificationCenter"
|
"Game/Core/NotificationCenter",
|
||||||
|
"Game/Server/User"
|
||||||
],
|
],
|
||||||
|
|
||||||
function (GameController, NotificationCenter) {
|
function (GameController, NotificationCenter, User) {
|
||||||
|
|
||||||
function Channel (pipeToLobby, name) {
|
function Channel (pipeToLobby, name) {
|
||||||
|
|
||||||
|
|
@ -36,12 +37,12 @@
|
||||||
|
|
||||||
switch(message.recipient) {
|
switch(message.recipient) {
|
||||||
case 'user':
|
case 'user':
|
||||||
self.forward(self.users[message.id], message.user);
|
self.forward(self.users[message.id], message.data);
|
||||||
break;
|
break;
|
||||||
case 'id': // Do nothing, it is needed by the user
|
case 'id': // Do nothing, it is needed by the user
|
||||||
break;
|
break;
|
||||||
case 'channel':
|
case 'channel':
|
||||||
self.forward(self, message.channel);
|
self.forward(self, message.data);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
throw 'unknown recipient';
|
throw 'unknown recipient';
|
||||||
|
|
@ -67,16 +68,16 @@
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
Channel.prototype.addUser = function (user) {
|
Channel.prototype.addUser = function (userId) {
|
||||||
//var userIds = Object.keys(this.users);
|
var user = new User(userId, this);
|
||||||
console.log('addUser', user);
|
|
||||||
this.users[user.id] = user;
|
this.users[user.id] = user;
|
||||||
|
NotificationCenter.trigger('user/joined', user);
|
||||||
//user.sendCommand('joinSuccess', {channelName: this.name, id: user.id, userIds: userIds});
|
|
||||||
//this.sendCommandToAllUsersExcept('userJoined', user.id, user);
|
|
||||||
|
|
||||||
//NotificationCenter.trigger('user/joined', user);
|
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
|
Channel.prototype.send = function(recipient, message) {
|
||||||
|
|
||||||
|
this.pipeToLobby.send(recipient, message);
|
||||||
|
}*/
|
||||||
/*
|
/*
|
||||||
Channel.prototype.releaseUser = function (user) {
|
Channel.prototype.releaseUser = function (user) {
|
||||||
this.gameController.userIdLeft(user.id);
|
this.gameController.userIdLeft(user.id);
|
||||||
|
|
|
||||||
46
app/Game/Server/User.js
Executable file → Normal file
46
app/Game/Server/User.js
Executable file → Normal file
|
|
@ -1,45 +1,31 @@
|
||||||
define([
|
define([
|
||||||
"Game/Core/User",
|
"Game/Core/User",
|
||||||
"Game/Core/Protocol/Helper",
|
"Game/Core/NotificationCenter",
|
||||||
"Game/Core/NotificationCenter"
|
"Game/Core/Protocol/Helper"
|
||||||
],
|
],
|
||||||
|
|
||||||
function (Parent, ProtocolHelper, NotificationCenter) {
|
function(Parent, NotificationCenter, ProtocolHelper) {
|
||||||
|
|
||||||
function User (socketLink, coordinator) {
|
function User(id, channel) {
|
||||||
Parent.call(this, socketLink.id);
|
Parent.call(this, id);
|
||||||
this.id = socketLink.id;
|
|
||||||
this.socketLink = socketLink;
|
|
||||||
this.coordinator = coordinator;
|
|
||||||
this.channel = null;
|
|
||||||
|
|
||||||
this.init(socketLink);
|
this.channel = channel;
|
||||||
|
var self = this;
|
||||||
|
|
||||||
|
NotificationCenter.on('user/joined', function(user) {
|
||||||
|
self.sendCommand("joined", true);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
User.prototype = Object.create(Parent.prototype);
|
User.prototype = Object.create(Parent.prototype);
|
||||||
|
|
||||||
User.prototype.init = function (socketLink) {
|
User.prototype.sendCommand = function(command, options) {
|
||||||
|
var recipient = "user/" + this.id;
|
||||||
|
var data = ProtocolHelper.encodeCommand(command, options);
|
||||||
|
|
||||||
var self = this;
|
NotificationCenter.trigger("net/send", recipient, data);
|
||||||
|
|
||||||
}
|
|
||||||
/*
|
|
||||||
User.prototype.setChannel = function (channel) {
|
|
||||||
this.channel = channel;
|
|
||||||
}
|
|
||||||
|
|
||||||
User.prototype.sendCommand = function (command, options) {
|
|
||||||
|
|
||||||
var message = ProtocolHelper.encodeCommand(command, options);
|
|
||||||
this.socketLink.send(message);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
User.prototype.toString = function () {
|
|
||||||
return "[User " + this.id + "]";
|
|
||||||
};
|
};
|
||||||
*/
|
|
||||||
return User;
|
return User;
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
@ -36,7 +36,7 @@ function (NotificationCenter, childProcess) {
|
||||||
}
|
}
|
||||||
|
|
||||||
PipeToChannel.prototype.onMessage = function (message) {
|
PipeToChannel.prototype.onMessage = function (message) {
|
||||||
NotficationCenter.trigger(message.recipient + '/message', message.data);
|
NotificationCenter.trigger(message.recipient + '/message', message.data);
|
||||||
}
|
}
|
||||||
|
|
||||||
return PipeToChannel;
|
return PipeToChannel;
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,10 @@
|
||||||
define([
|
define([
|
||||||
"Game/Core/User",
|
"Game/Core/User",
|
||||||
"Game/Core/Protocol/Helper"
|
"Game/Core/Protocol/Helper",
|
||||||
|
"Game/Core/NotificationCenter"
|
||||||
],
|
],
|
||||||
|
|
||||||
function (Parent, ProtocolHelper) {
|
function (Parent, ProtocolHelper, NotificationCenter) {
|
||||||
|
|
||||||
function User (socketLink, coordinator) {
|
function User (socketLink, coordinator) {
|
||||||
Parent.call(this, socketLink.id);
|
Parent.call(this, socketLink.id);
|
||||||
|
|
@ -20,6 +21,8 @@ function (Parent, ProtocolHelper) {
|
||||||
socketLink.on('disconnect', function () {
|
socketLink.on('disconnect', function () {
|
||||||
self.onDisconnect();
|
self.onDisconnect();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
NotificationCenter.on("user/" + this.socketLink.id + "/message", this.onChannelMessage, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
User.prototype = Object.create(Parent.prototype);
|
User.prototype = Object.create(Parent.prototype);
|
||||||
|
|
@ -62,6 +65,10 @@ function (Parent, ProtocolHelper) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
User.prototype.onChannelMessage = function(message) {
|
||||||
|
this.socketLink.send(message);
|
||||||
|
};
|
||||||
|
|
||||||
return User;
|
return User;
|
||||||
|
|
||||||
});
|
});
|
||||||
Loading…
Add table
Add a link
Reference in a new issue