X-Git-Url: https://git.cworth.org/git?a=blobdiff_plain;f=lmno.js;h=5d4ca3e7b554025a2b367cf8aca6dae71945ec1b;hb=16564f558ee42c3fbc0ca5ee56c91407253747b5;hp=60c0f44000dfa702ec04c4b9cddbbb6d9600a40f;hpb=0cc61b68f175ae13fe2390d8e5c6bf374153aecc;p=lmno-server diff --git a/lmno.js b/lmno.js index 60c0f44..5d4ca3e 100644 --- a/lmno.js +++ b/lmno.js @@ -69,6 +69,8 @@ nunjucks.configure("templates", { * * / Serves -game.html template * + * /player Allows client to set name or team + * * /events Serves a stream of events. Game can override * the handle_events method, call super() first, * and then have code to add custom events. @@ -289,6 +291,12 @@ for (let key in engines) { response.render(`${game.meta.identifier}-game.html`); }); + router.put('/player', (request, response) => { + const game = request.game; + + game.handle_player(request, response); + }); + router.get('/events', (request, response) => { const game = request.game; @@ -302,13 +310,13 @@ for (let key in engines) { const game = request.game; const move = request.body.move; - const legal = game.add_move(move); + const result = game.add_move(move); - /* Inform this client whether the move was legal. */ - response.send(JSON.stringify(legal)); + /* Feed move response back to the client. */ + response.json(result); /* And only if legal, inform all clients. */ - if (! legal) + if (! result.legal) return; game.broadcast_move(move);