From e37d1eeb2eaac01d194f10d0d6a4fa136d536b93 Mon Sep 17 00:00:00 2001 From: Jeena Paradies Date: Fri, 13 Jul 2012 19:53:07 +0200 Subject: [PATCH] added debug information when users join --- lib/Client/Networker.js | 10 ++++++++++ lib/Server/Channel.js | 17 +++++++++++++++-- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/lib/Client/Networker.js b/lib/Client/Networker.js index c3fbfd8..a6be2d4 100644 --- a/lib/Client/Networker.js +++ b/lib/Client/Networker.js @@ -52,8 +52,14 @@ define(["Protocol/Helper", "Chuck/ClientGame"], function(ProtocolHelper, ClientG Networker.prototype.onJoinSuccess = function(channelName) { this.clientGame = new ClientGame(this); this.clientGame.loadLevel("default.json") + console.log("Joined " + channelName); } + Networker.prototype.onUserJoined = function(userId) { + //this.clientGame.userJoined(userId); + console.log("User " + userId + " joined"); + }; + Networker.prototype.processControlCommand = function(command, options){ switch(command) { case 'joinSuccess': @@ -64,6 +70,10 @@ define(["Protocol/Helper", "Chuck/ClientGame"], function(ProtocolHelper, ClientG this.clientGame.processGameCommand(options); break; + case 'userJoined': + this.onUserJoined(options); + break; + default: break; } diff --git a/lib/Server/Channel.js b/lib/Server/Channel.js index 07671b5..10db7d1 100644 --- a/lib/Server/Channel.js +++ b/lib/Server/Channel.js @@ -12,14 +12,27 @@ define(["Chuck/ServerGame"], function(ServerGame) { Channel.prototype.addUser = function(user){ this.users[user.id] = user; + + user.sendCommand('joinSuccess', this.name); + this.sendCommandToAllUsersBut('userJoined', user.id, user); } Channel.prototype.releaseUser = function(user){ delete this.users[user.id]; } - Channel.prototype.sendToAllUsers = function(package) { - console.log("not implemented sendToAllUsers: " + JSON.stringify(package)) + Channel.prototype.sendCommandToAllUsers = function(command, options) { + for(var id in this.users) { + this.users[id].sendCommand(command, options); + } + } + + Channel.prototype.sendCommandToAllUsersBut = function(command, options, user) { + for(var id in this.users) { + if (id != user.id) { + this.users[id].sendCommand(command, options); + } + } } return Channel;