diff --git a/lib/test/test-game.js b/lib/test/test-game.js index d0cb9ed8..b213dcec 100644 --- a/lib/test/test-game.js +++ b/lib/test/test-game.js @@ -123,6 +123,10 @@ var TestGame = function(options) { return id; } + this.getIdFromGameServer = function() { + return server.id + }; + this.close = function() { wsclient.close(); }; diff --git a/public/hft/0.x.x/scripts/gameserver.js b/public/hft/0.x.x/scripts/gameserver.js index ab6a53ec..ad3e3687 100644 --- a/public/hft/0.x.x/scripts/gameserver.js +++ b/public/hft/0.x.x/scripts/gameserver.js @@ -71,6 +71,12 @@ define([ var _players = {}; // by id var _totalPlayerCount = 0; var _eventListeners = {}; + var _id; + var _getters = { + id: function() { + throw "you can't read the id before you've connected"; + }, + }; if (!options.gameId) { var m = /games\/([^\/]+)\//.exec(window.location.href); @@ -81,6 +87,13 @@ define([ } } + Object.defineProperty(this, 'id', { + get: function() { return _getters.id(); }, + set: function() {}, + enumerable: true, + configurable: true, + }); + /** * Event that we've connected to happyFunTimes * @@ -189,6 +202,10 @@ define([ }; var handleGameStart_ = function(msg) { + _id = msg.data.id; + _getters.id = function() { + return _id; + }; sendEvent_('connect', [msg.data]); }; @@ -234,6 +251,17 @@ define([ _socket.send(_sendQueue[ii]); } _sendQueue = []; + + // This `preconnect` message is a kind of hack. + // This used to be a `connect` message but + // I needed to be able to pass an `id` back to the + // connect message. On top of that, GameSupport + // was using the `connect` message. In order to allow + // games using `GameSupport` to use the `connect` message + // I changed this to `_hft_preconnect`. Games can therefore + // receive teh `connect` message. I changed `GameSupport` + // to a watch for `_hft_preconnect` + sendEvent_('_hft_preconnect'); }.bind(this); var disconnected_ = function() { diff --git a/test/server/server-version-test.js b/test/server/server-version-test.js index 491c6b09..2c3a3ea1 100644 --- a/test/server/server-version-test.js +++ b/test/server/server-version-test.js @@ -212,6 +212,11 @@ describe('server versions', function() { testGame1.isConnected().should.be.ok; testGame2.isConnected().should.be.ok; + testGame1.getId().should.be.eql("aaa"); + testGame2.getId().should.be.eql("bbb"); + testGame1.getId().should.be.eql(testGame1.getIdFromGameServer()); + testGame2.getId().should.be.eql(testGame2.getIdFromGameServer()); + var testCtrl = new TestController({ gameId: gameId, hftServer: hftServer, @@ -266,6 +271,9 @@ describe('server versions', function() { var testGame1Id = testGame1.getId(); var testGame2Id = testGame2.getId(); + testGame1Id.should.be.eql(testGame1.getIdFromGameServer()); + testGame2Id.should.be.eql(testGame2.getIdFromGameServer()); + var testCtrl = new TestController({ gameId: gameId, hftServer: hftServer,