X-Git-Url: https://git.cworth.org/git?a=blobdiff_plain;f=empires.js;h=e6b7e77979736a6269a27250899e3420c89fe178;hb=5bcba2b19093613581ba5ac4030d2e46f6f78dcd;hp=593598ad6153c5c524fd2dfeaf7274f07cc36b63;hpb=615d8cf656c88fa3ebd6deceecf468338928815e;p=empires-server diff --git a/empires.js b/empires.js index 593598a..e6b7e77 100644 --- a/empires.js +++ b/empires.js @@ -2,9 +2,17 @@ const express = require("express"); const cors = require("cors"); const body_parser = require("body-parser"); const path = require("path"); +const nunjucks = require("nunjucks"); const app = express(); app.use(cors()); +app.use(body_parser.urlencoded({ extended: false })); +app.use(body_parser.json()); + +nunjucks.configure("templates", { + autoescape: true, + express: app +}); const GameState = { JOIN: 1, @@ -208,9 +216,6 @@ class Game { } } -app.use(body_parser.urlencoded({ extended: false })); -app.use(body_parser.json()); - function handle_events(request, response) { const game = request.game; /* These headers will keep the connection open so we can stream events. */ @@ -251,12 +256,21 @@ function handle_events(request, response) { } app.get('/', (request, response) => { - response.sendFile(path.join(__dirname, './game.html')); + if (! request.session.nickname) + response.render('choose-nickname.html'); + else + response.render('empires-game.html'); }); 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(); });