]> git.cworth.org Git - lmno-server/blobdiff - lmno.js
Rename "next_player" property to "team_to_play"
[lmno-server] / lmno.js
diff --git a/lmno.js b/lmno.js
index b6c5b78e04e6b83a6700c19d623a6e55d625f1c8..18e60efd947349be35218a643ac6ba7a9756971d 100644 (file)
--- a/lmno.js
+++ b/lmno.js
@@ -69,6 +69,8 @@ nunjucks.configure("templates", {
  *
  *                 /        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.
@@ -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;
 
@@ -301,8 +309,15 @@ for (let key in engines) {
     router.post('/move', (request, response) => {
       const game = request.game;
       const move = request.body.move;
+      const player = game.players[request.session.id];
+
+      /* Reject move if there is no player for this session. */
+      if (! player) {
+        response.json({legal: false, message: "No valid player from session"});
+        return;
+      }
 
-      const result = game.add_move(move);
+      const result = game.add_move(player, move);
 
       /* Feed move response back to the client. */
       response.json(result);