From 67ddcfdfc632fc081ae267d6482082ddfe1635aa Mon Sep 17 00:00:00 2001 From: Carl Worth Date: Sun, 17 May 2020 12:19:53 -0700 Subject: [PATCH] Add a new server: lmno.js This is the new top-level server for all dynamic content and games that we plan to host at https://lmno.games. The previous server implementation (in server.js) will likely be subsumed as a sub-application within this new server soon. --- lmno.js | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 lmno.js diff --git a/lmno.js b/lmno.js new file mode 100644 index 0000000..dc23fc2 --- /dev/null +++ b/lmno.js @@ -0,0 +1,53 @@ +const express = require("express"); +const cors = require("cors"); +const body_parser = require("body-parser"); + +const app = express(); +app.use(cors()); + +class LMNO { + constructor() { + this.ids = {}; + } + + generate_id() { + return [null,null,null,null].map(() => LMNO.letters.charAt(Math.floor(Math.random() * LMNO.letters.length))).join(''); + } + + create_game(engine) { + do { + var id = this.generate_id(); + } while (id in this.ids); + + const game = { + id: id, + engine: engine, + }; + + this.ids[id] = game; + + return game; + } +} + +/* Some letters we don't use in our IDs: + * + * 1. Vowels (AEIOU) to avoid accidentally spelling an unfortunate word + * 2. Lowercase letters (replace with corresponding capital on input) + * 3. N (replace with M on input) + * 4. P (replace with B on input) + * 5. S (replace with F on input) + */ +LMNO.letters = "BCDFGHJKLMQRTVWXYZ"; + +const lmno = new LMNO(); + +app.post('/new/:game_engine', (request, response) => { + const game_engine = request.params.game_engine; + const game = lmno.create_game(game_engine); + response.send(JSON.stringify(game.id)); +}); + +app.listen(4000, function () { + console.log('LMNO server listening on localhost:4000'); +}); -- 2.43.0