X-Git-Url: https://git.cworth.org/git?a=blobdiff_plain;f=empires.js;h=20dfa78d2102e6e1fe0d3b77bc23eb6cba729b30;hb=74fbb20db7ae89671f020a60e77f8d55ec17ee1f;hp=b744f0faa2e0cc68a8d90963055e1a64a8b7b3ab;hpb=74ae0ff19c7a25caf39944ebbf25202f31e48bf8;p=lmno-server diff --git a/empires.js b/empires.js index b744f0f..20dfa78 100644 --- a/empires.js +++ b/empires.js @@ -207,12 +207,11 @@ class Game { } } -const game = new 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. */ const headers = { "Content-type": "text/event-stream", @@ -251,59 +250,69 @@ function handle_events(request, response) { } app.post('/register', (request, response) => { + const game = request.game; game.add_player(request.body.name, request.body.character); response.send(); }); app.post('/deregister/:id', (request, response) => { + const game = request.game; game.remove_player(parseInt(request.params.id)); response.send(); }); app.post('/reveal', (request, response) => { + const game = request.game; game.reveal(); response.send(); }); app.post('/start', (request, response) => { + const game = request.game; game.start(); response.send(); }); app.post('/reset', (request, response) => { + const game = request.game; game.reset(); response.send(); }); app.post('/capture/:captor/:captee', (request, response) => { + const game = request.game; game.capture(parseInt(request.params.captor), parseInt(request.params.captee)); response.send(); }); app.post('/liberate/:id', (request, response) => { + const game = request.game; game.liberate(parseInt(request.params.id)); response.send(); }); app.post('/restart', (request, response) => { + const game = request.game; game.restart(parseInt(request.params.id)); response.send(); }); app.get('/characters', (request, response) => { + const game = request.game; response.send(game.characters); }); app.get('/empires', (request, response) => { + const game = request.game; response.send(game.empires); }); app.get('/players', (request, response) => { + const game = request.game; response.send(game.players); }); app.get('/events', handle_events); -app.listen(3000, function () { - console.log('Empires server listening on localhost:3000'); -}); +exports.app = app; +exports.Game = Game;