From 7c0eb693a50dbd2890a5ad1b27516a0a829bbf7c Mon Sep 17 00:00:00 2001 From: Tor Andersson Date: Fri, 31 Mar 2023 23:53:20 +0200 Subject: Rename game "description" to "notice". --- public/style.css | 2 +- schema.sql | 2 +- server.js | 31 ++++++++++++++++++------------- views/create.pug | 15 +++++---------- views/head.pug | 4 ++-- views/join.pug | 18 ++++++++++++++---- 6 files changed, 41 insertions(+), 31 deletions(-) diff --git a/public/style.css b/public/style.css index aeb9584..bcac7fe 100644 --- a/public/style.css +++ b/public/style.css @@ -44,7 +44,7 @@ div.logo img { box-shadow: 1px 2px 4px 0px rgba(0,0,0,0.3); } -input[type="checkbox"] { +input[type="checkbox"], input[type="radio"] { margin-right: 7px; } input[type="text"], input[type="password"], input[type="email"], textarea { diff --git a/schema.sql b/schema.sql index 49d195a..e685e3b 100644 --- a/schema.sql +++ b/schema.sql @@ -277,7 +277,7 @@ create table if not exists games ( ctime datetime default current_timestamp, is_private boolean default 0, is_random boolean default 0, - description text, + notice text, status integer default 0, result text ); diff --git a/server.js b/server.js index 5b76883..163c0f6 100644 --- a/server.js +++ b/server.js @@ -1075,7 +1075,7 @@ function is_game_ready(title_id, scenario, options, players) { load_rules() -const SQL_INSERT_GAME = SQL("INSERT INTO games (owner_id,title_id,scenario,options,is_private,is_random,description) VALUES (?,?,?,?,?,?,?)") +const SQL_INSERT_GAME = SQL("INSERT INTO games (owner_id,title_id,scenario,options,is_private,is_random,notice) VALUES (?,?,?,?,?,?,?)") const SQL_DELETE_GAME = SQL("DELETE FROM games WHERE game_id=? AND owner_id=?") const SQL_SELECT_UNREAD_CHAT_GAMES = SQL("select game_id from unread_chats where user_id = ?").pluck() @@ -1147,15 +1147,15 @@ const SQL_DELETE_PLAYER_ROLE = SQL("DELETE FROM players WHERE game_id=? AND role const SQL_SELECT_OPEN_GAMES = SQL("SELECT * FROM games WHERE status=0") const SQL_COUNT_OPEN_GAMES = SQL("SELECT COUNT(*) FROM games WHERE owner_id=? AND status=0").pluck() -const SQL_SELECT_REMATCH = SQL("SELECT game_id FROM games WHERE status < 3 AND description=?").pluck() +const SQL_SELECT_REMATCH = SQL("SELECT game_id FROM games WHERE status < 3 AND notice=?").pluck() const SQL_INSERT_REMATCH = SQL(` INSERT INTO games - (owner_id, title_id, scenario, options, is_private, is_random, description) + (owner_id, title_id, scenario, options, is_private, is_random, notice) SELECT $user_id, title_id, scenario, options, is_private, 0, $magic FROM games WHERE game_id = $game_id AND NOT EXISTS ( - SELECT * FROM games WHERE description=$magic + SELECT * FROM games WHERE notice=$magic ) `) @@ -1402,7 +1402,7 @@ app.get('/create/:title_id', must_be_logged_in, function (req, res) { function options_json_replacer(key, value) { if (key === 'scenario') return undefined - if (key === 'description') return undefined + if (key === 'notice') return undefined if (key === 'is_random') return undefined if (key === 'is_private') return undefined if (value === 'true') return true @@ -1411,14 +1411,15 @@ function options_json_replacer(key, value) { return value } -app.post('/create/:title_id', must_be_logged_in, function (req, res) { +app.post("/create/:title_id", must_be_logged_in, function (req, res) { let title_id = req.params.title_id - let descr = req.body.description - let priv = req.body.is_private === 'true' - let rand = req.body.is_random === 'true' + let priv = req.body.is_private === "true" + let rand = req.body.is_random === "true" let user_id = req.user.user_id let scenario = req.body.scenario let options = JSON.stringify(req.body, options_json_replacer) + let notice = req.body.notice + let count = SQL_COUNT_OPEN_GAMES.get(user_id) if (count >= 5) return res.send("You have too many open games!") @@ -1426,8 +1427,9 @@ app.post('/create/:title_id', must_be_logged_in, function (req, res) { return res.send("Invalid title.") if (!RULES[title_id].scenarios.includes(scenario)) return res.send("Invalid scenario.") - let info = SQL_INSERT_GAME.run(user_id, title_id, scenario, options, priv ? 1 : 0, rand ? 1 : 0, descr) - res.redirect('/join/'+info.lastInsertRowid) + + let info = SQL_INSERT_GAME.run(user_id, title_id, scenario, options, priv ? 1 : 0, rand ? 1 : 0, notice) + res.redirect("/join/" + info.lastInsertRowid) }) app.get('/delete/:game_id', must_be_logged_in, function (req, res) { @@ -1516,6 +1518,8 @@ app.get('/join/:game_id', must_be_logged_in, function (req, res) { if (game.owner_id === req.user.user_id) friends = SQL_SELECT_CONTACT_FRIEND_NAMES.all(req.user.user_id) let ready = (game.status === 0) && is_game_ready(game.title_id, game.scenario, game.options, players) + game.ctime = human_date(game.ctime) + game.mtime = human_date(game.mtime) res.render('join.pug', { user: req.user, game, roles, players, ready, whitelist, blacklist, friends }) @@ -1807,8 +1811,9 @@ function mail_game_info(game) { let desc = `Game: ${game.title_name}\n` desc += `Scenario: ${game.scenario}\n` desc += `Players: ${game.player_names}\n` - if (game.description.length > 0) - desc += `Description: ${game.description}\n` + desc += "\n" + if (game.notice && game.notice.length > 0) + desc += game.notice + "\n" return desc + "\n" } diff --git a/views/create.pug b/views/create.pug index 42d3a46..d742cfc 100644 --- a/views/create.pug +++ b/views/create.pug @@ -24,21 +24,16 @@ html else input(type="hidden" name="scenario" value=scenarios[0]) | !{ create_html } - p Description: + + p Notice: br - input(type="text" list="speed" autocomplete="off" name="description" size=50) - datalist(id="speed") - option Async - 1 move per day - option Async - x moves per day - option Live - America - option Live - Europe - option Live - Asia - option Live - Oceania - option Learning game + input(type="text" autocomplete="off" name="notice" size=50 placeholder="What are you looking for?") + p label input(type="checkbox" name="is_random" value="true") | Random player roles + p label input(type="checkbox" name="is_private" value="true") diff --git a/views/head.pug b/views/head.pug index e90ce6b..cf0b268 100644 --- a/views/head.pug +++ b/views/head.pug @@ -85,8 +85,8 @@ mixin gamelist(list,hide_title=0) div.game_main div.game_info - if item.description - i= item.description + if item.notice + i= item.notice if item.scenario !== "Standard" && item.scenario !== "Historical" && item.scenario.length > 2 div Scenario: #{item.scenario} unless item.human_options === "None" diff --git a/views/join.pug b/views/join.pug index abbaf2c..0f9daef 100644 --- a/views/join.pug +++ b/views/join.pug @@ -39,17 +39,27 @@ html div.logo +gamecover(game.title_id) + div Scenario: #{game.scenario} + + unless game.human_options === "None" + div Options: #{game.human_options} div if game.is_private | Owner: #{game.owner_name} (private) else | Owner: #{game.owner_name} - div Scenario: #{game.scenario} - div Options: #{game.human_options} + + div Created: #{game.ctime} + unless game.mtime === "never" + div Changed: #{game.mtime} + if game.status === 2 - div Result: !{game.result} + div Result: #{game.result} - p= game.description || "No description." + if game.notice + br + div + i= game.notice br(clear="left") -- cgit v1.2.3