summaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
Diffstat (limited to 'bin')
-rwxr-xr-xbin/rtt-fuzz13
-rwxr-xr-xbin/rtt-fuzz-rand32
-rwxr-xr-xbin/rtt-fuzz-rand-n12
-rwxr-xr-xbin/rtt-help1
-rwxr-xr-xbin/rtt-import3
-rwxr-xr-xbin/rtt-patch10
-rwxr-xr-xbin/rtt-run2
-rwxr-xr-xbin/rtt-show-game2
-rwxr-xr-xbin/rtt-tm-unban-tick4
-rwxr-xr-xbin/rtt-update-elo1
10 files changed, 66 insertions, 14 deletions
diff --git a/bin/rtt-fuzz b/bin/rtt-fuzz
index d7f2aef..464ff34 100755
--- a/bin/rtt-fuzz
+++ b/bin/rtt-fuzz
@@ -1,6 +1,6 @@
#!/bin/bash
-TITLE=$1
+export TITLE=$1
shift
if [ ! -f ./public/$TITLE/rules.js ]
@@ -9,8 +9,11 @@ then
exit 1
fi
-mkdir -p fuzzer/corpus-$TITLE
+if [ -z $(npm ls -p jsfuzz) ]
+then
+ echo Installing "jsfuzz" package.
+ npm install -s --no-save jsfuzz
+fi
-RULES=../public/$TITLE/rules.js \
- npx jazzer tools/fuzz.js --sync fuzzer/corpus-$TITLE "$@" -- -exact_artifact_path=/dev/null | \
- tee fuzzer/log-$TITLE.txt
+mkdir -p fuzzer/corpus-$TITLE
+npx jsfuzz tools/fuzz.js fuzzer/corpus-$TITLE --exact-artifact-path=/dev/null | tee fuzzer/log-$TITLE.txt
diff --git a/bin/rtt-fuzz-rand b/bin/rtt-fuzz-rand
new file mode 100755
index 0000000..38878c3
--- /dev/null
+++ b/bin/rtt-fuzz-rand
@@ -0,0 +1,32 @@
+#!/usr/bin/env -S node
+
+"use strict"
+
+const fs = require("fs")
+const crypto = require("crypto")
+
+if (process.argv.length < 3) {
+ console.error("rtt-fuzz-rand TITLE")
+ process.exit(1)
+}
+
+process.env.TITLE = process.argv[2]
+
+const { fuzz } = require("../tools/fuzz.js")
+
+fs.mkdir("fuzzer", ()=>{})
+
+if (process.argv.length > 3) {
+ fuzz(parseInt(process.argv[3]))
+} else {
+ // run for an hour-ish
+ var i, n, a, b
+ for (i = 0; i < 3600; ++i) {
+ a = b = Date.now()
+ for (n = 0; b < a + 5_000; ++n) {
+ fuzz(crypto.randomInt(1, 2**48))
+ b = Date.now()
+ }
+ console.log("# " + Math.round( (1000 * n) / (b-a) ) + " runs/second")
+ }
+}
diff --git a/bin/rtt-fuzz-rand-n b/bin/rtt-fuzz-rand-n
new file mode 100755
index 0000000..7d3c969
--- /dev/null
+++ b/bin/rtt-fuzz-rand-n
@@ -0,0 +1,12 @@
+#!/bin/bash
+
+# count number of actual cores
+CORES=$(lscpu --all --parse=SOCKET,CORE | grep -v '^#' | sort -u | wc -l)
+# CORES=$(nproc)
+
+for P in $(seq $CORES)
+do
+ ./bin/rtt-fuzz-rand $1 &
+done
+
+wait $(jobs -p)
diff --git a/bin/rtt-help b/bin/rtt-help
index 5f6815c..57e42d1 100755
--- a/bin/rtt-help
+++ b/bin/rtt-help
@@ -16,6 +16,7 @@ game management
module development
foreach -- run a command for each module
fuzz -- fuzz test a module
+ fuzz-rand -- fuzz test a module (random)
game debugging
show-chat -- show game chat (for moderation)
diff --git a/bin/rtt-import b/bin/rtt-import
index 2e4295b..53be292 100755
--- a/bin/rtt-import
+++ b/bin/rtt-import
@@ -1,4 +1,5 @@
#!/usr/bin/env -S node
+"use strict"
const fs = require("fs")
const sqlite3 = require("better-sqlite3")
@@ -30,7 +31,7 @@ for (let file of input) {
game.setup.notice = options.notice
if (game.setup.notice === undefined)
- game.setup.notice = ""
+ game.setup.notice = file
if (game.setup.options === undefined)
game.setup.options = "{}"
diff --git a/bin/rtt-patch b/bin/rtt-patch
index ec0b795..2abb431 100755
--- a/bin/rtt-patch
+++ b/bin/rtt-patch
@@ -1,5 +1,7 @@
#!/usr/bin/env -S node
+"use strict"
+
const sqlite3 = require("better-sqlite3")
let db = new sqlite3("db")
@@ -7,7 +9,7 @@ let db = new sqlite3("db")
let select_game = db.prepare("select * from games where game_id=?")
let select_replay = db.prepare("select * from game_replay where game_id=?")
-let delete_replay = db.prepare("delete from game_replay where game_id=? and replay_id>?")
+let delete_replay = db.prepare("delete from game_replay where game_id=?")
let insert_replay = db.prepare("insert into game_replay (game_id,replay_id,role,action,arguments) values (?,?,?,?,?)")
let select_last_snap = db.prepare("select max(snap_id) from game_snap where game_id=?").pluck()
@@ -260,8 +262,8 @@ function patch_game(game_id, {validate_actions=true, save_snaps=true, delete_und
db.exec("begin")
if (need_to_rewrite) {
- delete_replay.run(game_id, skip_replay_id)
- for (item of replay)
+ delete_replay.run(game_id)
+ for (let item of replay)
if (!item.remove)
insert_replay.run(game_id, item.replay_id, item.role, item.action, item.arguments)
}
@@ -269,7 +271,7 @@ function patch_game(game_id, {validate_actions=true, save_snaps=true, delete_und
if (save_snaps) {
delete_snap.run(game_id, start_snap_id)
let snap_id = start_snap_id
- for (item of replay)
+ for (let item of replay)
if (item.save)
insert_snap.run(game_id, ++snap_id, item.replay_id, item.state)
}
diff --git a/bin/rtt-run b/bin/rtt-run
index 6873e2f..b0f9b3e 100755
--- a/bin/rtt-run
+++ b/bin/rtt-run
@@ -1,7 +1,7 @@
#!/bin/bash
while true
do
- nodemon --exitcrash server.js
+ npx nodemon --exitcrash server.js
echo
echo "Restarting soon!"
echo "Hit Ctl-C to exit."
diff --git a/bin/rtt-show-game b/bin/rtt-show-game
index ece9e49..f055449 100755
--- a/bin/rtt-show-game
+++ b/bin/rtt-show-game
@@ -3,5 +3,5 @@ if [ -n "$1" ]
then
sqlite3 db "select json_remove(json_remove(state, '$.undo'), '$.log') from game_state where game_id = $1"
else
- echo "usage: rtt-show-state GAME"
+ echo "usage: rtt-show-game GAME"
fi
diff --git a/bin/rtt-tm-unban-tick b/bin/rtt-tm-unban-tick
index 7294e81..d98a8d8 100755
--- a/bin/rtt-tm-unban-tick
+++ b/bin/rtt-tm-unban-tick
@@ -12,7 +12,7 @@ create temporary view tm_lift_ban_view as
select
user_id,
name,
- date(timeout_last),
+ date(timeout_last) as timeout_date,
timeout_total,
games_since_timeout,
(games_since_timeout > timeout_total) and (julianday() > julianday(timeout_last)+14) as lift_ban
@@ -23,7 +23,7 @@ create temporary view tm_lift_ban_view as
order by lift_ban desc, timeout_last asc
;
-select * from tm_lift_ban_view;
+select name, timeout_date, timeout_total, games_since_timeout from tm_lift_ban_view where lift_ban;
delete from tm_banned where user_id in (select user_id from tm_lift_ban_view where lift_ban) returning user_id;
diff --git a/bin/rtt-update-elo b/bin/rtt-update-elo
index 538964a..9e04224 100755
--- a/bin/rtt-update-elo
+++ b/bin/rtt-update-elo
@@ -1,4 +1,5 @@
#!/usr/bin/env -S node
+"use strict"
// Recompute Elo ratings from scratch!