summaryrefslogtreecommitdiff
path: root/server.js
diff options
context:
space:
mode:
authorTor Andersson <tor@ccxvii.net>2021-06-17 16:35:18 +0200
committerTor Andersson <tor@ccxvii.net>2021-06-19 11:48:10 +0200
commit95cfd9241629f50ff36fb0c4700530cf5b697158 (patch)
tree6b6bbe5c721fad871de9a1131a27341cbe1b79b4 /server.js
parentfb9fa1b6365c1c13e00c35257e53eebf610f0c6c (diff)
downloadserver-95cfd9241629f50ff36fb0c4700530cf5b697158.tar.gz
Add list of public games page at /games.
Diffstat (limited to 'server.js')
-rw-r--r--server.js38
1 files changed, 38 insertions, 0 deletions
diff --git a/server.js b/server.js
index e9e21f9..327fa59 100644
--- a/server.js
+++ b/server.js
@@ -447,6 +447,26 @@ const QUERY_LIST_PUBLIC_GAMES = db.prepare(`
ORDER BY status ASC, mtime DESC
`);
+const QUERY_LIST_OPEN_GAMES = db.prepare(`
+ SELECT
+ games.game_id,
+ games.title_id AS title_id,
+ games.scenario AS scenario,
+ games.owner AS owner_id,
+ users.name AS owner_name,
+ games.ctime,
+ games.mtime,
+ games.description,
+ games.status,
+ games.result,
+ games.active,
+ titles.title_name
+ FROM games
+ LEFT JOIN users ON games.owner = users.user_id
+ LEFT JOIN titles ON games.title_id = titles.title_id
+ WHERE private = 0 AND status < 2
+`);
+
const QUERY_LIST_USER_GAMES = db.prepare(`
SELECT DISTINCT
games.game_id,
@@ -592,6 +612,24 @@ app.get('/profile', must_be_logged_in, function (req, res) {
});
});
+app.get('/games', must_be_logged_in, function (req, res) {
+ LOG(req, "GET /join");
+ let games = QUERY_LIST_OPEN_GAMES.all();
+ humanize(games);
+ for (let game of games) {
+ game.players = QUERY_PLAYER_NAMES.all(game.game_id);
+ game.your_turn = is_your_turn(game, req.user);
+ }
+ let open_games = games.filter(game => game.status == 0);
+ let active_games = games.filter(game => game.status == 1);
+ res.set("Cache-Control", "no-store");
+ res.render('games.ejs', { user: req.user,
+ open_games: open_games,
+ active_games: active_games,
+ message: req.flash('message')
+ });
+});
+
app.get('/info/:title_id', function (req, res) {
LOG(req, "GET /info/" + req.params.title_id);
let title_id = req.params.title_id;