}
}
+ handle_player(request, response) {
+ const player = this.find_player(request.session);
+ if (! player) {
+ response.sendStatus(404);
+ return;
+ }
+
+ if (request.body.name && (player.name !== request.body.name)) {
+ player.name = request.body.name;
+
+ /* In addition to setting the name within this game's player
+ * object, also set the name in the session. */
+ request.session.nickname = player.name;
+ request.session.save();
+
+ this.broadcast_event("player-update", player.info_json());
+ }
+
+ response.send("");
+ }
+
broadcast_move(move) {
this.broadcast_event("move", move);
}
*
* / Serves <identifier>-game.html template
*
+ * /player Allows client to set name
+ *
* /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;
| grep ^data
}
+tictactoe_player()
+{
+ curl_put $tictactoe_game_path/player "{ \"name\": \"$1\" }" "-b .test-cookie"
+}
+
TEST_SUBSECTION "Tic Tac Toe player-info"
TEST "Hit LMNO /profile to set name to 'curl'"
test "$result" = 'data: {"id":1,"name":"curl"}'
TEST_END
+TEST_SUBSECTION "Tic Tac Toe /player"
+
+TEST "Change name to 'newname'"
+tictactoe_player newname
+TEST_END
+
+TEST "Verify player-info event reports 'newname'"
+result=$(tictactoe_player_info)
+test "$result" = 'data: {"id":1,"name":"newname"}'
+TEST_END
+
TEST_SUBSECTION "Tic Tac Toe /move"
TEST "Move to the center square"