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
60
app/Server/User.js
Executable file
60
app/Server/User.js
Executable file
|
|
@ -0,0 +1,60 @@
|
|||
define([
|
||||
"Game/Core/User",
|
||||
"Lib/Utilities/Protocol/Helper",
|
||||
"Lib/Utilities/NotificationCenter"
|
||||
],
|
||||
|
||||
function (Parent, ProtocolHelper, Nc) {
|
||||
|
||||
function User (socketLink, coordinator) {
|
||||
Parent.call(this, socketLink.id);
|
||||
|
||||
this.coordinator = coordinator;
|
||||
this.channelProcess = null;
|
||||
this.socketLink = socketLink;
|
||||
|
||||
socketLink.on('message', this.onMessage.bind(this));
|
||||
socketLink.on('disconnect', this.onDisconnect.bind(this));
|
||||
|
||||
Nc.on("user/" + this.socketLink.id + "/message", this.socketLink.send, this.socketLink);
|
||||
}
|
||||
|
||||
User.prototype = Object.create(Parent.prototype);
|
||||
|
||||
|
||||
// Socket callbacks
|
||||
|
||||
User.prototype.onMessage = function (message) {
|
||||
ProtocolHelper.applyCommand(message, this);
|
||||
}
|
||||
|
||||
User.prototype.onDisconnect = function () {
|
||||
this.coordinator.removeUser(this);
|
||||
}
|
||||
|
||||
|
||||
// User command callbacks
|
||||
// Remember: control commands are coordinator relevant commands
|
||||
|
||||
User.prototype.onJoin = function(options) {
|
||||
this.coordinator.assignUserToChannel(this, options);
|
||||
};
|
||||
|
||||
User.prototype.onLeave = function(options) {
|
||||
this.coordinator.assignUserToLobby(this);
|
||||
};
|
||||
|
||||
User.prototype.onGameCommand = function(options) {
|
||||
// repacking for transport via pipe
|
||||
var message = ProtocolHelper.encodeCommand("gameCommand", options);
|
||||
Nc.trigger("user/controlCommand", this.id, message);
|
||||
};
|
||||
|
||||
User.prototype.onPing = function(timestamp) {
|
||||
var message = ProtocolHelper.encodeCommand("pong", timestamp);
|
||||
Nc.trigger("user/" + this.socketLink.id + "/message", message);
|
||||
};
|
||||
|
||||
return User;
|
||||
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue