]> git.cworth.org Git - empires-server/commitdiff
/register: Optionally use the session profile nickname for the player's name
authorCarl Worth <cworth@cworth.org>
Sat, 23 May 2020 17:40:54 +0000 (10:40 -0700)
committerCarl Worth <cworth@cworth.org>
Sun, 24 May 2020 20:48:51 +0000 (13:48 -0700)
This allows a UI to set a nickname once in the profile and then send
only the character name in the /register action.

It's still supported to set the name in the /register action as well.

empires.js

index a8c177109a08f409969be419951e97da59d2a96f..d8cff6f70314623f01c06135d426e32e6749de72 100644 (file)
@@ -264,7 +264,13 @@ app.get('/', (request, response) => {
 
 app.post('/register', (request, response) => {
   const game = request.game;
-  game.add_player(request.body.name, request.body.character);
+  var name = request.session.nickname;;
+
+  /* If the request includes a name, that overrides the session nickname. */
+  if (request.body.name)
+    name = request.body.name;
+
+  game.add_player(name, request.body.character);
   response.send();
 });