diff options
author | Tor Andersson <tor@ccxvii.net> | 2022-11-24 21:23:56 +0100 |
---|---|---|
committer | Tor Andersson <tor@ccxvii.net> | 2022-11-25 17:37:12 +0100 |
commit | 83835ea22d7e169f80d8740ce8a542103257d173 (patch) | |
tree | 24744e958aca45e583563ed6db9c58194dcd0b5c /tools | |
parent | 1fd20db73895cf1ca8fab9cf2c7d288d3bcc1c92 (diff) | |
download | server-83835ea22d7e169f80d8740ce8a542103257d173.tar.gz |
Remove obsolete tools and update other tools.
Diffstat (limited to 'tools')
-rw-r--r-- | tools/editgame.sh | 8 | ||||
-rwxr-xr-x | tools/fonts/woff2css2 | 42 | ||||
-rw-r--r-- | tools/makecert.sh | 6 | ||||
-rw-r--r-- | tools/packreplay.sql | 8 | ||||
-rw-r--r-- | tools/patchgame.js | 26 | ||||
-rw-r--r-- | tools/purge.sh | 25 | ||||
-rw-r--r-- | tools/readgame.sh | 10 | ||||
-rwxr-xr-x | tools/replay.js | 37 | ||||
-rw-r--r-- | tools/showgame.sh | 7 | ||||
-rw-r--r-- | tools/start.sh | 2 | ||||
-rw-r--r-- | tools/stop.sh | 2 | ||||
-rw-r--r-- | tools/thumbnail.sh | 7 | ||||
-rw-r--r-- | tools/writegame.sh | 7 |
13 files changed, 71 insertions, 116 deletions
diff --git a/tools/editgame.sh b/tools/editgame.sh deleted file mode 100644 index 2638f45..0000000 --- a/tools/editgame.sh +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/bash -if [ -n "$1" -a -n "$VISUAL" ] -then - sqlite3 db "update game_state set state=edit(state) where game_id = $1" -else - echo "usage: bash tools/editgame.sh GAME" - echo "note: \$VISUAL must be set to your preferred editor" -fi diff --git a/tools/fonts/woff2css2 b/tools/fonts/woff2css2 new file mode 100755 index 0000000..8105524 --- /dev/null +++ b/tools/fonts/woff2css2 @@ -0,0 +1,42 @@ +#!/usr/bin/python3 + +# Embed a woff2 font in a static CSS file. +# Usage: woff2css in.woff2 out.css +# +# Limitations: takes weight and style information from the file name of the font. +# This script will throw an unhelpful exception if weight and style cannot +# be determined. + +# @font-face { +# font-family: "Dinish"; +# font-weight: 700; +# font-style: bold; +# src: url(data:font/woff2;base64,d09GMgABAAAAACzcAA0AAAAAc/wAACyGAAIAxQAAAAAAAAAAAAAAAAAAAAAAAAAAGnYbnkIcg0IGYACDHAqBpT +# } + +import os +import re +import sys + +if not re.search(r"\.woff2$", sys.argv[1]): + print("Usage: woff2css *.woff2") + sys.exit(1) + +for src in sys.argv[1:]: + m = re.match(r"([\w-]+)-(\w+)\.", os.path.basename(src)) + if m: + family = m.group(1) + style = m.group(2) + else: + print("Font should be named Family-Style.woff2; could not determine font weight.") + sys.exit(1) + + s = ("@font-face{") + s += (f"font-family:'{family}';") + if style == "Bold" or style == "BoldItalic": + s += (f"font-weight:bold;") + if style == "Italic" or style == "BoldItalic": + s += (f"font-style:italic;") + s += (f"src:url('{src}')format('woff2')") + s += ("}") + print(s) diff --git a/tools/makecert.sh b/tools/makecert.sh deleted file mode 100644 index 94d8bb7..0000000 --- a/tools/makecert.sh +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/bash -# -# Create a simple self-signed SSL certificate. -# - -openssl req -nodes -new -x509 -keyout key.pem -out cert.pem diff --git a/tools/packreplay.sql b/tools/packreplay.sql new file mode 100644 index 0000000..28cd11f --- /dev/null +++ b/tools/packreplay.sql @@ -0,0 +1,8 @@ +begin transaction; +create temporary table replay_repack as + select game_id,role,action,arguments + from game_replay + order by game_id,replay_id; +delete from game_replay; +insert into game_replay (game_id,role,action,arguments) select * from replay_repack; +commit; diff --git a/tools/patchgame.js b/tools/patchgame.js index 9b63f4f..167aca9 100644 --- a/tools/patchgame.js +++ b/tools/patchgame.js @@ -1,5 +1,7 @@ #!/usr/bin/env node +const VERIFY = true + const fs = require('fs') const sqlite3 = require('better-sqlite3') @@ -20,8 +22,8 @@ fs.writeFileSync("backup-" + game_id + ".txt", save) function is_valid_action(rules, game, role, action, a) { if (action !== 'undo') - if (game.active !== role && game.active !== "Both" && game.active !== "All") - return false + if (game.active !== role && game.active !== "Both" && game.active !== "All") + return false let view = rules.view(game, role) let va = view.actions[action] if (va === undefined) @@ -47,27 +49,27 @@ try { game = rules.resign(game, item.role) else { console.log("ACTION", i, game.seed, game.state, game.active, ">", item.role, item.action, item.arguments) - if (1) - if (!is_valid_action(rules, game, item.role, item.action, args)) { - console.log(`invalid action: ${item.role} ${item.action} ${item.arguments}`) - console.log("\t", game.state, game.active, JSON.stringify(rules.view(game, item.role).actions)) - throw "invalid action" + if (VERIFY) { + if (!is_valid_action(rules, game, item.role, item.action, args)) { + console.log(`invalid action: ${item.role} ${item.action} ${item.arguments}`) + console.log("\t", game.state, game.active, JSON.stringify(rules.view(game, item.role).actions)) + throw "invalid action" + } } game = rules.action(game, item.role, item.action, args) } ++i }) + console.log("SUCCESS %d", log.length) + db.prepare("update game_state set active=?, state=? where game_id=?").run(game.active, JSON.stringify(game), game_id) } catch (err) { console.log("FAILED %d/%d", i+1, log.length) console.log(err) - game.log=undefined - game.undo=undefined - //console.log(JSON.stringify(game,0,4)) + delete game.log + delete game.undo console.log(game) } -db.prepare("update game_state set active=?, state=? where game_id=?").run(game.active, JSON.stringify(game), game_id) - if (i < log.length) { console.log("BROKEN ENTRIES: %d", log.length-i) console.log(`sqlite3 db "delete from game_replay where game_id=${game_id} and replay_id>=${log[i].replay_id}"`) diff --git a/tools/purge.sh b/tools/purge.sh deleted file mode 100644 index 10cee16..0000000 --- a/tools/purge.sh +++ /dev/null @@ -1,25 +0,0 @@ -#!/bin/bash - -# Clean out stale games from the database. - -WHERE_TIMEOUT_OPEN="WHERE status = 0 AND ctime < datetime('now', '-7 days')" -WHERE_TIMEOUT_ACTIVE="WHERE status = 1 AND mtime < datetime('now', '-14 days')" -WHERE_TIMEOUT_SOLO="WHERE status = 2 AND mtime < datetime('now', '-3 months') AND is_solo=1" - -echo "--- TIMED OUT OPEN GAMES ---" -sqlite3 db -box -cmd "pragma foreign_keys=1" "SELECT * FROM game_view $WHERE_TIMEOUT_OPEN" -sqlite3 db -box -cmd "pragma foreign_keys=1" "DELETE FROM games WHERE game_id IN ( SELECT game_id FROM game_view $WHERE_TIMEOUT_OPEN )" - -echo "--- TIMED OUT ACTIVE GAMES ---" -sqlite3 db -box -cmd "pragma foreign_keys=1" "SELECT * FROM game_view $WHERE_TIMEOUT_ACTIVE" -sqlite3 db -box -cmd "pragma foreign_keys=1" "UPDATE games SET status = 3 WHERE game_id IN ( SELECT game_id FROM game_view $WHERE_TIMEOUT_ACTIVE )" - -echo "--- ANCIENT SOLO GAMES ---" -sqlite3 db -box -cmd "pragma foreign_keys=1" "SELECT * FROM game_full_view $WHERE_TIMEOUT_SOLO" -sqlite3 db -box -cmd "pragma foreign_keys=1" "UPDATE games SET status = 3 WHERE game_id IN ( SELECT game_id FROM game_full_view $WHERE_TIMEOUT_SOLO )" - -echo "--- DELETED MESSAGES ---" -sqlite3 db -box -cmd "pragma foreign_keys=1" "SELECT message_id, from_name, to_name, subject FROM message_view WHERE is_deleted_from_inbox=1 AND is_deleted_from_outbox=1" -sqlite3 db -box -cmd "pragma foreign_keys=1" "DELETE FROM messages WHERE is_deleted_from_inbox=1 AND is_deleted_from_outbox=1" - -sqlite3 db -box -cmd "pragma foreign_keys=1" "DELETE FROM game_replay WHERE game_id < 1346" diff --git a/tools/readgame.sh b/tools/readgame.sh deleted file mode 100644 index 4a8fdbd..0000000 --- a/tools/readgame.sh +++ /dev/null @@ -1,10 +0,0 @@ -#!/bin/bash -if [ -n "$1" -a -n "$2" ] -then - sqlite3 db "select writefile('$2',state) from game_state where game_id = $1" -elif [ -n "$1" ] -then - sqlite3 db "select state from game_state where game_id = $1" -else - echo "usage: bash tools/readgame.sh GAME [ state.json ]" -fi diff --git a/tools/replay.js b/tools/replay.js deleted file mode 100755 index af2cde0..0000000 --- a/tools/replay.js +++ /dev/null @@ -1,37 +0,0 @@ -#!/usr/bin/env node - -const sqlite3 = require('better-sqlite3'); - -if (process.argv.length !== 3) { - process.stderr.write("usage: ./tools/replay.js <game_id>\n"); - process.exit(1); -} - -let game_id = process.argv[2] | 0; - -let db = new sqlite3("./db"); -let title_id = db.prepare("SELECT title_id FROM games WHERE game_id = ?").pluck().get(game_id); -let rules = require("../public/" + title_id + "/rules"); -let log = db.prepare("SELECT * FROM replay WHERE game_id = ?").all(game_id); - -let replay = new sqlite3("./replay.db"); -replay.pragma("synchronous = off"); -replay.prepare("create table if not exists replay ( game_id int, time, role, action, arguments, state )").run(); -replay.prepare("delete from replay where game_id = ?").run(game_id); -let replay_insert = replay.prepare("insert into replay (game_id,time,role,action,arguments,state) VALUES (?,?,?,?,?,?)"); - -process.stdout.write(`// REPLAY ${title_id} ${game_id}\n`) -let game = { state: "null", active: "None" } -log.forEach(item => { - process.stdout.write(`${game.state} ${game.active}\n`); - process.stdout.write(`\t${item.time} ${item.role} ${item.action} ${item.arguments}\n`); - let args = JSON.parse(item.arguments); - if (item.action === 'setup') - game = rules.setup(args[0], args[1], args[2]); - else if (item.action === 'resign') - game = rules.resign(game, item.role); - else - game = rules.action(game, item.role, item.action, args); - replay_insert.run(game_id, item.time, item.role, item.action, item.arguments, JSON.stringify(game)); -}); -process.stdout.write(`${game.state} ${game.active}\n`); diff --git a/tools/showgame.sh b/tools/showgame.sh new file mode 100644 index 0000000..f45be78 --- /dev/null +++ b/tools/showgame.sh @@ -0,0 +1,7 @@ +#!/bin/bash +if [ -n "$1" ] +then + sqlite3 db "select json_remove(json_remove(state, '$.undo'), '$.log') from game_state where game_id = $1" +else + echo "usage: bash tools/showgame.sh GAME" +fi diff --git a/tools/start.sh b/tools/start.sh deleted file mode 100644 index eb5240a..0000000 --- a/tools/start.sh +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/bash -forever start -a --uid rally --killSignal=SIGTERM -c 'nodemon --exitcrash' server.js diff --git a/tools/stop.sh b/tools/stop.sh deleted file mode 100644 index 39f920a..0000000 --- a/tools/stop.sh +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/bash -forever stop rally diff --git a/tools/thumbnail.sh b/tools/thumbnail.sh deleted file mode 100644 index e4a10ee..0000000 --- a/tools/thumbnail.sh +++ /dev/null @@ -1,7 +0,0 @@ -mogrify -resize 300x300 -format ppm */cover.jpg -for F in tools/*/cover.jpg -do - OUT=public/*$(dirname $F | sed 's,tools/,,;s/-.*//')* - echo Thumbnail $OUT/cover.jpg $F - djpeg $F | pnmscale -xysize 400 400 | mozjpeg -q 90 > $OUT/cover.jpg -done diff --git a/tools/writegame.sh b/tools/writegame.sh deleted file mode 100644 index a6e673d..0000000 --- a/tools/writegame.sh +++ /dev/null @@ -1,7 +0,0 @@ -#!/bin/bash -if [ -n "$1" -a -f "$2" ] -then - sqlite3 db "update game_state set state=readfile('$2') where game_id = $1" -else - echo "usage: bash tools/writegame.sh GAME state.json" -fi |