From f6cd22a3b979b1836e4ba8e07fbdbe3ce3b83ad3 Mon Sep 17 00:00:00 2001 From: Matthew Faltys Date: Thu, 30 Jan 2020 21:44:03 +0000 Subject: [PATCH] Add score persistence Add sotw jail --- Makefile | 2 ++ config.gcfg | 2 +- deps/Dockerfile | 2 ++ deps/link_sotw.sh | 21 +++++++++++++++++++++ deps/scores.dat | Bin 0 -> 98 bytes nethack-launcher/create_initial_files.go | 5 +++++ nethack-launcher/create_user_files.go | 5 +++++ nethack-launcher/run_game.go | 3 +-- 8 files changed, 37 insertions(+), 3 deletions(-) create mode 100755 deps/link_sotw.sh create mode 100755 deps/scores.dat diff --git a/Makefile b/Makefile index 8bf6569..3d90dbe 100644 --- a/Makefile +++ b/Makefile @@ -46,6 +46,8 @@ build_docker: fetch_sotw cp deps/chowner.sh stage.tmp/ cp deps/run_nethack.sh stage.tmp/ cp deps/reclist.c stage.tmp/ + cp deps/link_sotw.sh stage.tmp/ + cp deps/scores.dat stage.tmp/ wget -O stage.tmp/redis-server https://cryo.unixvoid.com/bin/redis/5.0.7/redis-server chmod +x stage.tmp/redis-server cd stage.tmp/ && \ diff --git a/config.gcfg b/config.gcfg index 031e5b5..05e9c6e 100644 --- a/config.gcfg +++ b/config.gcfg @@ -6,7 +6,7 @@ nhdatlocation = "/NetHack/dat/nhdat" recoverbinary = "/NetHack/util/recover" sysconflocation = "/NetHack/sys/unix/sysconf" - sotwversion = "1.1.2" + sotwversion = "1.1.6" sotwroot = "/sotw" bootstrapdelay = 1 diff --git a/deps/Dockerfile b/deps/Dockerfile index 7955e38..aff8600 100644 --- a/deps/Dockerfile +++ b/deps/Dockerfile @@ -109,7 +109,9 @@ COPY run.sh / COPY chowner.sh /bin/ COPY nethackrc /.nethackrc COPY run_nethack.sh / +COPY link_sotw.sh /bin/ ADD sotw.tar.gz / RUN mv /shadow-of-the-wyrm* /sotw/ +COPY scores.dat /sotw/ CMD ["/run.sh"] diff --git a/deps/link_sotw.sh b/deps/link_sotw.sh new file mode 100755 index 0000000..2f69b0a --- /dev/null +++ b/deps/link_sotw.sh @@ -0,0 +1,21 @@ +#!/bin/bash + +FILES=/sotw/* +USERDIR=$1 +HACKDIR=$2 + +# create initial dir if it does not exist +mkdir -p $USERDIR/sotw/ + +# link all game files to user dir +for f in $FILES +do + echo "linking $f" + ln -s $f $USERDIR/sotw/ +done + +# remove inital score file +rm -rf $USERDIR/sotw/scores.dat + +# link in shared score file from hackdir +ln -s $HACKDIR/scores.dat $USERDIR/sotw/ diff --git a/deps/scores.dat b/deps/scores.dat new file mode 100755 index 0000000000000000000000000000000000000000..e292bfd88756975d756b53a5bec34da78598de64 GIT binary patch literal 98 zcmWe&fB>J&ywVCC1$Sp>1v5QkJp)Fl_zXh`gB8jzE-cMVVTW?^QcE%tle3vXT$lzB M8>ZN$JUCYY0B%m4rY literal 0 HcmV?d00001 diff --git a/nethack-launcher/create_initial_files.go b/nethack-launcher/create_initial_files.go index e289db1..fbd0563 100644 --- a/nethack-launcher/create_initial_files.go +++ b/nethack-launcher/create_initial_files.go @@ -51,4 +51,9 @@ func createInitialFiles() { } } + + // make sure initial sotw scores file exists + if _, err := os.Stat(fmt.Sprintf("%s/scores.dat", config.NethackLauncher.HackDir)); os.IsNotExist(err) { + exec.Command("cp", fmt.Sprintf("%s/scores.dat", config.NethackLauncher.SotwRoot), config.NethackLauncher.HackDir).Run() + } } diff --git a/nethack-launcher/create_user_files.go b/nethack-launcher/create_user_files.go index 6f6a22d..2248851 100644 --- a/nethack-launcher/create_user_files.go +++ b/nethack-launcher/create_user_files.go @@ -39,4 +39,9 @@ func createUserFiles(username string) { // move in nhdat file if it does not exist exec.Command("cp", fmt.Sprintf("%s/nhdat", config.NethackLauncher.HackDir), userpath).Run() + + // run sotw prep script + if _, err := os.Stat(fmt.Sprintf("%s/sotw/", userpath)); os.IsNotExist(err) { + exec.Command("/bin/link_sotw.sh", userpath, config.NethackLauncher.HackDir).Run() + } } diff --git a/nethack-launcher/run_game.go b/nethack-launcher/run_game.go index ddf38ca..f2c9eeb 100644 --- a/nethack-launcher/run_game.go +++ b/nethack-launcher/run_game.go @@ -49,8 +49,7 @@ func runSotwGame(username, timestamp string) { ttyrecPath := fmt.Sprintf("%s/user/%s/ttyrec/%s.ttyrec", config.NethackLauncher.HackDir, username, timestamp) nh := exec.Command("ttyrec", "-f", ttyrecPath, "--", "./ShadowOfTheWyrm") - //nh := exec.Command("./ShadowOfTheWyrm") - nh.Dir = (config.NethackLauncher.SotwRoot) + nh.Dir = (fmt.Sprintf("%s/user/%s/sotw/", config.NethackLauncher.HackDir, username)) nh.Stdout = os.Stdout nh.Stdin = os.Stdin nh.Stderr = os.Stderr