const express = require("express");
const cors = require("cors");
const body_parser = require("body-parser");
const express = require("express");
const cors = require("cors");
const body_parser = require("body-parser");
if (this.reveal_index >= this.characters_to_reveal.length) {
clearInterval(this.reveal_interval);
this.broadcast_event("character-reveal", '{"character":""}');
if (this.reveal_index >= this.characters_to_reveal.length) {
clearInterval(this.reveal_interval);
this.broadcast_event("character-reveal", '{"character":""}');
app.use(body_parser.urlencoded({ extended: false }));
app.use(body_parser.json());
function handle_events(request, response) {
app.use(body_parser.urlencoded({ extended: false }));
app.use(body_parser.json());
function handle_events(request, response) {
/* These headers will keep the connection open so we can stream events. */
const headers = {
"Content-type": "text/event-stream",
/* These headers will keep the connection open so we can stream events. */
const headers = {
"Content-type": "text/event-stream",
game.add_player(request.body.name, request.body.character);
response.send();
});
app.post('/deregister/:id', (request, response) => {
game.add_player(request.body.name, request.body.character);
response.send();
});
app.post('/deregister/:id', (request, response) => {
game.remove_player(parseInt(request.params.id));
response.send();
});
app.post('/reveal', (request, response) => {
game.remove_player(parseInt(request.params.id));
response.send();
});
app.post('/reveal', (request, response) => {
game.capture(parseInt(request.params.captor), parseInt(request.params.captee));
response.send();
});
app.post('/liberate/:id', (request, response) => {
game.capture(parseInt(request.params.captor), parseInt(request.params.captee));
response.send();
});
app.post('/liberate/:id', (request, response) => {
game.liberate(parseInt(request.params.id));
response.send();
});
app.post('/restart', (request, response) => {
game.liberate(parseInt(request.params.id));
response.send();
});
app.post('/restart', (request, response) => {
game.restart(parseInt(request.params.id));
response.send();
});
app.get('/characters', (request, response) => {
game.restart(parseInt(request.params.id));
response.send();
});
app.get('/characters', (request, response) => {
response.send(game.characters);
});
app.get('/empires', (request, response) => {
response.send(game.characters);
});
app.get('/empires', (request, response) => {
response.send(game.empires);
});
app.get('/players', (request, response) => {
response.send(game.empires);
});
app.get('/players', (request, response) => {
response.send(game.players);
});
app.get('/events', handle_events);
response.send(game.players);
});
app.get('/events', handle_events);