diff options
-rw-r--r-- | public/sort.js | 82 | ||||
-rw-r--r-- | server.js | 39 | ||||
-rwxr-xr-x | tools/fonts/woff2css2 | 42 | ||||
-rw-r--r-- | tools/packreplay.sql | 8 | ||||
-rw-r--r-- | tools/readgame.sh | 10 | ||||
-rw-r--r-- | tools/showreplay.sh | 2 | ||||
-rw-r--r-- | tools/undo.sh | 6 | ||||
-rw-r--r-- | tools/writegame.sh | 7 |
8 files changed, 23 insertions, 173 deletions
diff --git a/public/sort.js b/public/sort.js deleted file mode 100644 index ed243c2..0000000 --- a/public/sort.js +++ /dev/null @@ -1,82 +0,0 @@ -"use strict" - -function sort_table_column(table, column) { - const minute = 60000 - const hour = 60 * minute - const day = 24 * hour - const week = 7 * day - - function is_date(s) { - if (s.match(/^\d{4}-\d{2}-\d{2}$/)) - return true - if (s.match(/^\d+ (minutes?|hours?|days|weeks) ago$/)) - return true - if (s.match(/^(Yesterday|now)$/)) - return true - return false - } - - function parse_date(s) { - if (s.match(/^\d{4}-\d{2}-\d{2}$/)) - return new Date(s).valueOf() - if (s === "now") - return Date.now() - if (s === "Yesterday") - return Date.now() - day - let [ _, value, unit ] = s.match(/^(\d+) (minutes?|hours?|days|weeks) ago$/) - switch (unit) { - default: - unit = 0 - break - case "minute": - case "minutes": - unit = minute - break - case "hours": - case "hours": - unit = hour - break - case "days": - unit = day - break - case "weeks": - unit = week - break - } - return Date.now() - Number(value) * unit - } - - let tbody = table.querySelector("tbody") - let rows = Array.from(tbody.querySelectorAll("tr")) - rows.sort((row_a, row_b) => { - let cell_a = row_a.querySelectorAll("td")[column].textContent - let cell_b = row_b.querySelectorAll("td")[column].textContent - if (is_date(cell_a) && is_date(cell_b)) { - let age_a = parse_date(cell_a) - let age_b = parse_date(cell_b) - if (age_a > age_b) return -1 - if (age_a < age_b) return 1 - return 0 - } else if (cell_a.match(/^\d+$/) && cell_b.match(/^\d+$/)) { - cell_a = Number(cell_a) - cell_b = Number(cell_b) - if (cell_a > cell_b) return -1 - if (cell_a < cell_b) return 1 - return 0 - } else { - if (cell_a > cell_b) return 1 - if (cell_a < cell_b) return -1 - return 0 - } - }) - rows.forEach((row) => tbody.appendChild(row)) -} - -document.querySelectorAll("table.sort").forEach((table) => { - table.querySelectorAll("th").forEach((th, column) => { - if (th.textContent !== "") { - th.addEventListener("click", (evt) => sort_table_column(table, column)) - th.style.cursor = "pointer" - } - }) -}) @@ -302,43 +302,7 @@ function is_blacklisted(mail) { return false } -function parse_user_agent(req) { - let user_agent = req.headers["user-agent"] - if (!user_agent) - return "Browser" - let agent = user_agent - if (user_agent.indexOf("Firefox/") >= 0) - agent = "Firefox" - else if (user_agent.indexOf("Chrome/") >= 0) - agent = "Chrome" - else if (user_agent.indexOf("Safari/") >= 0) - agent = "Safari" - else if (user_agent.indexOf("Edg/") >= 0) - agent = "Edge" - else if (user_agent.indexOf("OPR/") >= 0) - agent = "Opera" - else if (user_agent.indexOf("Opera") >= 0) - agent = "Opera" - else if (user_agent.indexOf("Googlebot") >= 0) - agent = "Googlebot" - else if (user_agent.indexOf("bingbot") >= 0) - agent = "Bingbot" - else if (user_agent.indexOf("; MSIE") >= 0) - agent = "MSIE" - else if (user_agent.indexOf("Trident/") >= 0) - agent = "MSIE" - else if (user_agent.indexOf("AppleWebKit/") >= 0) - agent = "AppleWebKit" - if (user_agent.indexOf("Mobile") >= 0) - return agent + "/M" - return agent -} - app.use(function (req, res, next) { - req.user_agent = parse_user_agent(req) - if (req.user_agent === "MSIE") - return res.redirect("/msie.html") - let ip = req.headers["x-real-ip"] || req.ip || req.connection.remoteAddress || "0.0.0.0" res.setHeader('Cache-Control', 'no-store') @@ -357,9 +321,8 @@ app.use(function (req, res, next) { // Log non-static accesses. let time = new Date().toISOString().substring(11,19) let name = (req.user ? req.user.name : "guest").padEnd(20) - let ua = req.user_agent.padEnd(10) ip = String(ip).padEnd(15) - console.log(time, ip, ua, name, req.method, req.url) + console.log(time, ip, name, req.method, req.url) return next() }) diff --git a/tools/fonts/woff2css2 b/tools/fonts/woff2css2 deleted file mode 100755 index 8105524..0000000 --- a/tools/fonts/woff2css2 +++ /dev/null @@ -1,42 +0,0 @@ -#!/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/packreplay.sql b/tools/packreplay.sql deleted file mode 100644 index 28cd11f..0000000 --- a/tools/packreplay.sql +++ /dev/null @@ -1,8 +0,0 @@ -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/readgame.sh b/tools/readgame.sh new file mode 100644 index 0000000..4a8fdbd --- /dev/null +++ b/tools/readgame.sh @@ -0,0 +1,10 @@ +#!/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/showreplay.sh b/tools/showreplay.sh new file mode 100644 index 0000000..413e12f --- /dev/null +++ b/tools/showreplay.sh @@ -0,0 +1,2 @@ +#!/bin/bash +sqlite3 db "select * from game_replay where game_id=$1" diff --git a/tools/undo.sh b/tools/undo.sh index 3cd5b4a..716e88b 100644 --- a/tools/undo.sh +++ b/tools/undo.sh @@ -1,9 +1,9 @@ #!/bin/bash if [ -n "$1" ] then - RID=$(sqlite3 db "select replay_id from game_replay where game_id=$1 order by replay_id desc limit 1") - echo $RID - sqlite3 db "delete from game_replay where game_id=$1 and replay_id=$RID" + COUNT=$(sqlite3 db "select count(1) from game_replay where game_id=$1") + echo Game has $COUNT actions. + sqlite3 db "delete from game_replay where game_id=$1 and replay_id=$COUNT" node tools/patchgame.js $1 else echo "usage: bash tools/undo.sh GAME" diff --git a/tools/writegame.sh b/tools/writegame.sh new file mode 100644 index 0000000..ea0f599 --- /dev/null +++ b/tools/writegame.sh @@ -0,0 +1,7 @@ +#!/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 |