X-Git-Url: https://git.cworth.org/git?a=blobdiff_plain;f=tictactoe.js;h=12bf6801ac0f20e4f36e444bbb9fab1909fce116;hb=40abb70f85a1f833c6dfcc8541db3bf876096616;hp=79d7350f7c84e70473e25d6310057afbcfdbfe39;hpb=ea14cbbefb26afd558aff8329d92f1a7b9442bac;p=empires-server diff --git a/tictactoe.js b/tictactoe.js index 79d7350..12bf680 100644 --- a/tictactoe.js +++ b/tictactoe.js @@ -27,16 +27,16 @@ class TicTacToe extends Game { broadcast_move(square) { this.broadcast_event("move", square); } -} -router.get('/', (request, response) => { - const game = request.game; + handle_events(request, response) { + super.handle_events(request, response); - if (! request.session.nickname) - response.render('choose-nickname.html', { game_name: "Tic Tac Toe" }); - else - response.render('tictactoe-game.html'); -}); + /* When a new client joins, replay all previous moves to it. */ + for (let move of this.moves) { + response.write(`event: move\ndata: ${move}\n\n`); + } + } +} router.post('/move', (request, response) => { const game = request.game; @@ -61,5 +61,11 @@ router.get('/events', (request, response) => { }); exports.router = router; -exports.name = engine_name; exports.Game = TicTacToe; + +TicTacToe.meta = { + name: "Tic Tac Toe", + identifier: "tictactoe" +}; + +exports.meta = TicTacToe.meta;