From 815bf73cde10bfb22861c95d543a749b028386de Mon Sep 17 00:00:00 2001 From: Jeremiah Billmann Date: Sat, 8 Jun 2013 16:19:29 -0400 Subject: [PATCH] Fixed broadcast issue --- lib/server/garageserver.io.js | 6 ++---- lib/server/garageservergame.js | 10 +++++----- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/lib/server/garageserver.io.js b/lib/server/garageserver.io.js index bd59f8c..2627b62 100644 --- a/lib/server/garageserver.io.js +++ b/lib/server/garageserver.io.js @@ -15,16 +15,14 @@ options = { function GarageServer (socketio, options) { this.io = socketio; - this.game = null; + this.game = new garageServerGame.createGame(options); this.registerSocketEvents(options); } GarageServer.prototype.registerSocketEvents = function (options) { var self = this; - + self.io.of('/garageserver.io').on('connection', function (socket) { - self.game = new garageServerGame.createGame(socket, options); - if (options.logging) { console.log('garageserver.io:: socket ' + socket.id + ' connection'); } diff --git a/lib/server/garageservergame.js b/lib/server/garageservergame.js index f444dfd..533e77f 100644 --- a/lib/server/garageservergame.js +++ b/lib/server/garageservergame.js @@ -1,8 +1,7 @@ -function GarageServerGame (socket, options) { +function GarageServerGame (options) { var self = this; this.players = []; - this.socket = socket; this.options = options; this.physicsIntervalId = setInterval(function () { self.updatePhysics(options); }, options.physicsInterval ? options.physicsInterval : 15); @@ -13,7 +12,8 @@ GarageServerGame.prototype.updatePlayers = function () { var currentTime = new Date().getTime(); for (var i = 0; i < this.players.length; i ++) { //TODO: Retink efficiency - this.socket.emit('update', { id: this.players[i].client.id, state: this.players[i].state, seq: this.players[i].sequence, timestamp: currentTime }); + this.players[i].client.emit('update', { id: this.players[i].client.id, state: this.players[i].state, seq: this.players[i].sequence, timestamp: currentTime }); + this.players[i].client.broadcast.emit('update', { id: this.players[i].client.id, state: this.players[i].state, seq: this.players[i].sequence, timestamp: currentTime }); } }; @@ -64,6 +64,6 @@ GarageServerGame.prototype.addPlayerInput = function (client, input) { } }; -exports.createGame = function (socketio, options){ - return new GarageServerGame(socketio, options); +exports.createGame = function (options){ + return new GarageServerGame(options); }; \ No newline at end of file