*
* / Serves <identifier>-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.
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;
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);