From 39714170a179f538f9fd696b23278f05b9bdbc18 Mon Sep 17 00:00:00 2001 From: Matthew Faltys Date: Wed, 15 Jan 2020 15:00:41 +0000 Subject: [PATCH 01/15] Add Shadow of the Wyrm to launcher --- Makefile | 7 ++++++- config.gcfg | 2 ++ deps/Dockerfile | 17 +++++++++++++++-- deps/chowner.sh | 5 +++++ nethack-launcher/nethack-launcher.go | 2 ++ nethack-launcher/print_user_screen.go | 10 ++++++++++ nethack-launcher/run_game.go | 22 ++++++++++++++++++++++ 7 files changed, 62 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 0b8600b..a6666bb 100644 --- a/Makefile +++ b/Makefile @@ -35,7 +35,7 @@ stat: dependencies: go get github.com/gorilla/mux -build_docker: +build_docker: fetch_sotw mkdir -p stage.tmp/ cp deps/Dockerfile stage.tmp/ cp config.gcfg stage.tmp/config.gcfg @@ -49,6 +49,11 @@ build_docker: cd stage.tmp/ && \ $(OS_PERMS) docker build -t $(IMAGE_NAME) . +fetch_sotw: + mkdir -p stage.tmp/ + wget https://cryo.unixvoid.com/bin/misc/sotw/shadow-of-the-wyrm-release-1.1.2.tar.gz + mv shadow-of-the-wyrm-release-1.1.2.tar.gz stage.tmp/sotw.tar.gz + run_docker: $(OS_PERMS) docker run \ -d \ diff --git a/config.gcfg b/config.gcfg index 7ff46cc..031e5b5 100644 --- a/config.gcfg +++ b/config.gcfg @@ -6,6 +6,8 @@ nhdatlocation = "/NetHack/dat/nhdat" recoverbinary = "/NetHack/util/recover" sysconflocation = "/NetHack/sys/unix/sysconf" + sotwversion = "1.1.2" + sotwroot = "/sotw" bootstrapdelay = 1 [redis] diff --git a/deps/Dockerfile b/deps/Dockerfile index 597351e..e7b9754 100644 --- a/deps/Dockerfile +++ b/deps/Dockerfile @@ -1,4 +1,4 @@ -FROM debian +FROM debian:stretch # install needed packages RUN apt-get update && \ @@ -8,6 +8,7 @@ RUN apt-get update && \ autoconf \ bison \ bsdmainutils \ + bzip2 \ flex \ gcc \ gdb \ @@ -15,14 +16,24 @@ RUN apt-get update && \ groff \ libncursesw5-dev \ libsqlite3-dev \ + libboost1.62-dev \ + libboost-all-dev \ + libncurses5-dev \ + libncursesw5-dev \ + lua5.1 \ + liblua5.1-0-dev \ + libsdl2-dev \ + libxerces-c-dev \ make \ ncurses-dev \ + premake4 \ sqlite3 \ tar \ telnetd \ xinetd \ locales \ - git \ + wget \ + zlibc \ vim RUN apt-get clean @@ -96,5 +107,7 @@ COPY run.sh / COPY chowner.sh /bin/ COPY nethackrc /.nethackrc COPY run_nethack.sh / +ADD sotw.tar.gz / +RUN mv /shadow-of-the-wyrm* /sotw/ CMD ["/run.sh"] diff --git a/deps/chowner.sh b/deps/chowner.sh index 01db8ae..859025a 100755 --- a/deps/chowner.sh +++ b/deps/chowner.sh @@ -2,7 +2,12 @@ while : do + # chown nethack directory chown -R nethack:nethack /hack 2> /dev/null chmod -R 744 /hack 2> /dev/null + + # chown + chown -R nethack:nethack /sotw 2> /dev/null + chmod -R 744 /sotw 2> /dev/null sleep 2 done diff --git a/nethack-launcher/nethack-launcher.go b/nethack-launcher/nethack-launcher.go index a3c8aa1..891817f 100644 --- a/nethack-launcher/nethack-launcher.go +++ b/nethack-launcher/nethack-launcher.go @@ -20,6 +20,8 @@ type Config struct { NhdatLocation string RecoverBinary string SysconfLocation string + SotwVersion string + SotwRoot string BootstrapDelay time.Duration } diff --git a/nethack-launcher/print_user_screen.go b/nethack-launcher/print_user_screen.go index e4be8d8..33f97f1 100644 --- a/nethack-launcher/print_user_screen.go +++ b/nethack-launcher/print_user_screen.go @@ -23,6 +23,7 @@ func printUserScreen(redisClient *redis.Client, username string) string { println(" e) Edit config") println(" r) Recover from crash") fmt.Printf(" p) Play NetHack %s\n", config.NethackLauncher.NethackVersion) + fmt.Printf(" o) Play Shadow of the Wyrm %s\n", config.NethackLauncher.SotwVersion) println(" q) Quit") println("") fmt.Printf(">> ") @@ -73,6 +74,15 @@ func printUserScreen(redisClient *redis.Client, username string) string { wg.Wait() close(watcher) printUserScreen(redisClient, username) + case "o": + wg.Add(1) + currentTime := time.Now().UTC() + fulltime := currentTime.Format("2006-01-02.03:04:05") + go runSotwGame(username, fulltime) + watcher := startWatcher(username, fulltime, redisClient) + wg.Wait() + close(watcher) + printUserScreen(redisClient, username) case "r": clearScreen() recoverSave(redisClient, username) diff --git a/nethack-launcher/run_game.go b/nethack-launcher/run_game.go index 779c339..ddf38ca 100644 --- a/nethack-launcher/run_game.go +++ b/nethack-launcher/run_game.go @@ -40,6 +40,28 @@ func runGame(username, timestamp string) { wg.Done() } +func runSotwGame(username, timestamp string) { + exec.Command("stty", "-F", "/dev/tty", "echo", "-cbreak").Run() + clearScreen() + + // put together users home dir + //homeDir := fmt.Sprintf("%s/user/%s/", config.NethackLauncher.HackDir, username) + 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.Stdout = os.Stdout + nh.Stdin = os.Stdin + nh.Stderr = os.Stderr + err := nh.Run() + if err != nil { + fmt.Print(err) + } + exec.Command("exit").Run() + wg.Done() +} + func runtimeRecover(username string) { fmt.Printf(" %s\n", config.NethackLauncher.ServerDisplay) println("") -- 2.30.3 From a6a0e72a00bf3b691ed2bd594cab4d0b41d5ba54 Mon Sep 17 00:00:00 2001 From: Matthew Faltys Date: Thu, 16 Jan 2020 15:21:49 +0000 Subject: [PATCH 02/15] Add stable redis version to docker --- Makefile | 2 ++ deps/Dockerfile | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index a6666bb..2a336bc 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/ + 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/ && \ $(OS_PERMS) docker build -t $(IMAGE_NAME) . diff --git a/deps/Dockerfile b/deps/Dockerfile index e7b9754..6ac4d9a 100644 --- a/deps/Dockerfile +++ b/deps/Dockerfile @@ -3,7 +3,6 @@ FROM debian:stretch # install needed packages RUN apt-get update && \ DEBIAN_FRONTEND=noninteractive apt-get install -y \ - redis-server \ openssh-server \ autoconf \ bison \ @@ -100,6 +99,7 @@ RUN gcc reclist.c -o /bin/reclist RUN rm reclist.c # copy in files +COPY redis-server /usr/bin/ COPY config.gcfg / COPY nethack-launcher / COPY redis.conf / -- 2.30.3 From d5f4aa988ddd1059842d86c154accadab7d3f84c Mon Sep 17 00:00:00 2001 From: Matthew Faltys Date: Tue, 28 Jan 2020 18:46:03 +0000 Subject: [PATCH 03/15] Add sotw 1.1.6 --- Makefile | 4 ++-- deps/Dockerfile | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 2a336bc..8bf6569 100644 --- a/Makefile +++ b/Makefile @@ -53,8 +53,8 @@ build_docker: fetch_sotw fetch_sotw: mkdir -p stage.tmp/ - wget https://cryo.unixvoid.com/bin/misc/sotw/shadow-of-the-wyrm-release-1.1.2.tar.gz - mv shadow-of-the-wyrm-release-1.1.2.tar.gz stage.tmp/sotw.tar.gz + wget https://cryo.unixvoid.com/bin/misc/sotw/shadow-of-the-wyrm-release-1.1.6.tar.gz + mv shadow-of-the-wyrm-release-1.1.6.tar.gz stage.tmp/sotw.tar.gz run_docker: $(OS_PERMS) docker run \ diff --git a/deps/Dockerfile b/deps/Dockerfile index 6ac4d9a..7955e38 100644 --- a/deps/Dockerfile +++ b/deps/Dockerfile @@ -22,6 +22,8 @@ RUN apt-get update && \ lua5.1 \ liblua5.1-0-dev \ libsdl2-dev \ + libsdl2-image-2.0-0 \ + libsdl2-image-dev \ libxerces-c-dev \ make \ ncurses-dev \ -- 2.30.3 From 2dac08c09812e7bccc08502b490272b216b15e82 Mon Sep 17 00:00:00 2001 From: Matthew Faltys Date: Tue, 28 Jan 2020 12:48:33 -0600 Subject: [PATCH 04/15] Bump sotw version --- config.gcfg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 -- 2.30.3 From f6cd22a3b979b1836e4ba8e07fbdbe3ce3b83ad3 Mon Sep 17 00:00:00 2001 From: Matthew Faltys Date: Thu, 30 Jan 2020 21:44:03 +0000 Subject: [PATCH 05/15] 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 -- 2.30.3 From 47f4886b489c9adf48805c924c011ba0ab94cd3a Mon Sep 17 00:00:00 2001 From: Matthew Faltys Date: Thu, 30 Jan 2020 21:53:50 +0000 Subject: [PATCH 06/15] Update seed score file --- deps/scores.dat | Bin 98 -> 98 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/deps/scores.dat b/deps/scores.dat index e292bfd88756975d756b53a5bec34da78598de64..716c90daa93b52f0674b36bdf91fc8b06eaf5f6d 100755 GIT binary patch delta 10 RcmYdFnxMes$}myM0RRw80 Date: Fri, 31 Jan 2020 14:10:26 +0000 Subject: [PATCH 07/15] Check user files on login (migration) --- nethack-launcher/print_login_screen.go | 1 + 1 file changed, 1 insertion(+) diff --git a/nethack-launcher/print_login_screen.go b/nethack-launcher/print_login_screen.go index f82e33f..9fd5841 100644 --- a/nethack-launcher/print_login_screen.go +++ b/nethack-launcher/print_login_screen.go @@ -52,6 +52,7 @@ func printLoginScreen(redisClient *redis.Client) { typedHash := sha3.Sum512([]byte(typedAuth)) if fmt.Sprintf("%x", typedHash) == storedHash { // user authed + createUserFiles(username) printUserScreen(redisClient, username) noPass = false } else { -- 2.30.3 From 4fb58d628a71eda467916ef96c4b759915ced4a2 Mon Sep 17 00:00:00 2001 From: Matthew Faltys Date: Wed, 11 Mar 2020 12:50:25 +0000 Subject: [PATCH 08/15] Update stock ini to match seasons --- deps/Dockerfile | 3 +++ 1 file changed, 3 insertions(+) diff --git a/deps/Dockerfile b/deps/Dockerfile index aff8600..2821cb6 100644 --- a/deps/Dockerfile +++ b/deps/Dockerfile @@ -113,5 +113,8 @@ COPY link_sotw.sh /bin/ ADD sotw.tar.gz / RUN mv /shadow-of-the-wyrm* /sotw/ COPY scores.dat /sotw/ +# update ini to match current season by default +RUN cd /sotw && \ + sed -i 's/current_month_is_start_month=0/current_month_is_start_month=1/g' swyrm.ini CMD ["/run.sh"] -- 2.30.3 From 55bc6241288da2f337f2b5de60d3f3154c2a5c4f Mon Sep 17 00:00:00 2001 From: Matthew Faltys Date: Wed, 11 Mar 2020 14:01:32 +0000 Subject: [PATCH 09/15] Add ability to edit sotw config --- nethack-launcher/print_user_screen.go | 36 +++++++++++++++++++++++---- 1 file changed, 31 insertions(+), 5 deletions(-) diff --git a/nethack-launcher/print_user_screen.go b/nethack-launcher/print_user_screen.go index 33f97f1..b0a5bab 100644 --- a/nethack-launcher/print_user_screen.go +++ b/nethack-launcher/print_user_screen.go @@ -18,10 +18,11 @@ func printUserScreen(redisClient *redis.Client, username string) string { println(" l) Logout") println(" c) Change password") println(" w) Watch games in progress") - println(" h) View highscores") - println(" a) View all scores") - println(" e) Edit config") - println(" r) Recover from crash") + println(" h) View NetHack highscores") + println(" a) View all NetHack scores") + println(" e) Edit NetHack config") + println(" f) Edit SOTW config") + println(" r) Recover NetHack from crash") fmt.Printf(" p) Play NetHack %s\n", config.NethackLauncher.NethackVersion) fmt.Printf(" o) Play Shadow of the Wyrm %s\n", config.NethackLauncher.SotwVersion) println(" q) Quit") @@ -46,7 +47,30 @@ func printUserScreen(redisClient *redis.Client, username string) string { hackRCLoc := fmt.Sprintf("%s/user/%s/.nethackrc", config.NethackLauncher.HackDir, username) exec.Command("stty", "-F", "/dev/tty", "echo", "-cbreak").Run() clearScreen() - nh := exec.Command("vim", "-Z", hackRCLoc) + nh := exec.Command("vim", "-i", "NONE", "-Z", hackRCLoc) + nh.Stdout = os.Stdout + nh.Stdin = os.Stdin + nh.Stderr = os.Stderr + nh.Run() + clearScreen() + printUserScreen(redisClient, username) + case "f": + // check if the file has been uplifted + SOTWLoc := fmt.Sprintf("%s/user/%s/sotw/swyrm.ini", config.NethackLauncher.HackDir, username) + il, _ := os.Lstat(SOTWLoc) + if il.Mode()&os.ModeSymlink == os.ModeSymlink { + // the file is still a legacy symlink, remove and recopy + err := os.Remove(SOTWLoc) + if err != nil { + fmt.Println(err) + } + SOTWOrigin := fmt.Sprintf("%s/swyrm.ini", config.NethackLauncher.SotwRoot) + exec.Command("cp", SOTWOrigin, SOTWLoc).Run() + } + + exec.Command("stty", "-F", "/dev/tty", "echo", "-cbreak").Run() + clearScreen() + nh := exec.Command("vim", "-i", "NONE", "-Z", SOTWLoc) nh.Stdout = os.Stdout nh.Stdin = os.Stdin nh.Stderr = os.Stderr @@ -70,6 +94,7 @@ func printUserScreen(redisClient *redis.Client, username string) string { currentTime := time.Now().UTC() fulltime := currentTime.Format("2006-01-02.03:04:05") go runGame(username, fulltime) + //go runCleanup(username) watcher := startWatcher(username, fulltime, redisClient) wg.Wait() close(watcher) @@ -79,6 +104,7 @@ func printUserScreen(redisClient *redis.Client, username string) string { currentTime := time.Now().UTC() fulltime := currentTime.Format("2006-01-02.03:04:05") go runSotwGame(username, fulltime) + //go runCleanup(username) watcher := startWatcher(username, fulltime, redisClient) wg.Wait() close(watcher) -- 2.30.3 From 66b958d952c50764f9e63b38045189199451ccbe Mon Sep 17 00:00:00 2001 From: Matthew Faltys Date: Wed, 11 Mar 2020 14:42:44 +0000 Subject: [PATCH 10/15] Add janitor job to clean up old files Leave 10 most recent ttyrecs Leave 5 most recent SOTW dump files --- Makefile | 2 ++ deps/Dockerfile | 1 + deps/clean.sh | 28 +++++++++++++++++++++++++++ deps/link_sotw.sh | 6 +++++- nethack-launcher/cleanup.go | 19 ++++++++++++++++++ nethack-launcher/print_user_screen.go | 4 ++-- 6 files changed, 57 insertions(+), 3 deletions(-) create mode 100755 deps/clean.sh create mode 100644 nethack-launcher/cleanup.go diff --git a/Makefile b/Makefile index 3d90dbe..7bd7af9 100644 --- a/Makefile +++ b/Makefile @@ -11,6 +11,7 @@ all: stat run: go run \ nethack-launcher/check_dir.go \ + nethack-launcher/cleanup.go \ nethack-launcher/create_initial_files.go \ nethack-launcher/create_user_files.go \ nethack-launcher/janitor.go \ @@ -47,6 +48,7 @@ build_docker: fetch_sotw cp deps/run_nethack.sh stage.tmp/ cp deps/reclist.c stage.tmp/ cp deps/link_sotw.sh stage.tmp/ + cp deps/clean.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 diff --git a/deps/Dockerfile b/deps/Dockerfile index 2821cb6..1f3fb5e 100644 --- a/deps/Dockerfile +++ b/deps/Dockerfile @@ -110,6 +110,7 @@ COPY chowner.sh /bin/ COPY nethackrc /.nethackrc COPY run_nethack.sh / COPY link_sotw.sh /bin/ +COPY clean.sh /bin/ ADD sotw.tar.gz / RUN mv /shadow-of-the-wyrm* /sotw/ COPY scores.dat /sotw/ diff --git a/deps/clean.sh b/deps/clean.sh new file mode 100755 index 0000000..f00ddd9 --- /dev/null +++ b/deps/clean.sh @@ -0,0 +1,28 @@ +#!/bin/bash +HACKDIR=$1 +USERDIR=$2 + +### +# clean old ttyrecs +### +cd /$HACKDIR/user/$USERDIR/ttyrec/ +ls -1tr | head -n -10 | xargs -d '\n' rm -f -- + + +### +# clean sotw files +### +cd /$HACKDIR/user/$USERDIR/sotw/ + +# there are always 4 symlinked files +# leave 5 of the latest dumps + +FILES=$(ls -1tr *.txt | head -n -9) + +for f in $FILES; do + #test -h $f || echo "removing old file $f" + if [ ! -h $f ]; then + echo "removing old file $f" + rm -rf $f + fi +done diff --git a/deps/link_sotw.sh b/deps/link_sotw.sh index 2f69b0a..aeacdcc 100755 --- a/deps/link_sotw.sh +++ b/deps/link_sotw.sh @@ -16,6 +16,10 @@ 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/ + +# remove initial config file +rm -rf $USERDIR/sotw/swyrm.ini +# copy in sotw config file +cp $HACKDIR/swyrm.ini $USERDIR/sotw/ diff --git a/nethack-launcher/cleanup.go b/nethack-launcher/cleanup.go new file mode 100644 index 0000000..12736f3 --- /dev/null +++ b/nethack-launcher/cleanup.go @@ -0,0 +1,19 @@ +package main + +import ( + "fmt" + "os/exec" +) + +func runCleanup(username string) { + // clean up ttyrecs in //user//ttyrec/ + // clean up sotw dumps, aka: + // non-symlinked .txt files in //user//sotw/ + + // run cleanup file + out, err := exec.Command("/bin/clean.sh", config.NethackLauncher.HackDir, username).Output() + if err != nil { + fmt.Println(err) + } + fmt.Printf("%s\n", out) +} diff --git a/nethack-launcher/print_user_screen.go b/nethack-launcher/print_user_screen.go index b0a5bab..0601cc6 100644 --- a/nethack-launcher/print_user_screen.go +++ b/nethack-launcher/print_user_screen.go @@ -94,7 +94,7 @@ func printUserScreen(redisClient *redis.Client, username string) string { currentTime := time.Now().UTC() fulltime := currentTime.Format("2006-01-02.03:04:05") go runGame(username, fulltime) - //go runCleanup(username) + go runCleanup(username) watcher := startWatcher(username, fulltime, redisClient) wg.Wait() close(watcher) @@ -104,7 +104,7 @@ func printUserScreen(redisClient *redis.Client, username string) string { currentTime := time.Now().UTC() fulltime := currentTime.Format("2006-01-02.03:04:05") go runSotwGame(username, fulltime) - //go runCleanup(username) + go runCleanup(username) watcher := startWatcher(username, fulltime, redisClient) wg.Wait() close(watcher) -- 2.30.3 From 2439ca27711a8b280939eb6d571c811fff9d0a09 Mon Sep 17 00:00:00 2001 From: Matthew Faltys Date: Wed, 11 Mar 2020 14:43:14 +0000 Subject: [PATCH 11/15] Bump SOTW version --- Makefile | 4 ++-- config.gcfg | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 7bd7af9..da99eda 100644 --- a/Makefile +++ b/Makefile @@ -57,8 +57,8 @@ build_docker: fetch_sotw fetch_sotw: mkdir -p stage.tmp/ - wget https://cryo.unixvoid.com/bin/misc/sotw/shadow-of-the-wyrm-release-1.1.6.tar.gz - mv shadow-of-the-wyrm-release-1.1.6.tar.gz stage.tmp/sotw.tar.gz + wget https://cryo.unixvoid.com/bin/misc/sotw/shadow-of-the-wyrm-release-1.1.7.tar.gz + mv shadow-of-the-wyrm-release-1.1.7.tar.gz stage.tmp/sotw.tar.gz run_docker: $(OS_PERMS) docker run \ diff --git a/config.gcfg b/config.gcfg index 05e9c6e..93382cb 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.6" + sotwversion = "1.1.7" sotwroot = "/sotw" bootstrapdelay = 1 -- 2.30.3 From f79108ca3142c110a4b2da75d6162fccb8eddfb5 Mon Sep 17 00:00:00 2001 From: Matthew Faltys Date: Wed, 11 Mar 2020 16:01:35 +0000 Subject: [PATCH 12/15] Remove debug statement --- deps/clean.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/deps/clean.sh b/deps/clean.sh index f00ddd9..7c3ed6f 100755 --- a/deps/clean.sh +++ b/deps/clean.sh @@ -22,7 +22,6 @@ FILES=$(ls -1tr *.txt | head -n -9) for f in $FILES; do #test -h $f || echo "removing old file $f" if [ ! -h $f ]; then - echo "removing old file $f" rm -rf $f fi done -- 2.30.3 From ee891cd6153f352e71c46f64fc484623151c2880 Mon Sep 17 00:00:00 2001 From: Matthew Faltys Date: Thu, 12 Mar 2020 12:52:49 +0000 Subject: [PATCH 13/15] Add parameters for save file caching --- config.gcfg | 2 ++ deps/clean.sh | 7 +++++-- nethack-launcher/cleanup.go | 2 +- nethack-launcher/nethack-launcher.go | 2 ++ 4 files changed, 10 insertions(+), 3 deletions(-) diff --git a/config.gcfg b/config.gcfg index 93382cb..a1bf16e 100644 --- a/config.gcfg +++ b/config.gcfg @@ -6,8 +6,10 @@ nhdatlocation = "/NetHack/dat/nhdat" recoverbinary = "/NetHack/util/recover" sysconflocation = "/NetHack/sys/unix/sysconf" + ttyreccache = "10" sotwversion = "1.1.7" sotwroot = "/sotw" + sotwdumpcache = "5" bootstrapdelay = 1 [redis] diff --git a/deps/clean.sh b/deps/clean.sh index 7c3ed6f..819a389 100755 --- a/deps/clean.sh +++ b/deps/clean.sh @@ -1,12 +1,14 @@ #!/bin/bash HACKDIR=$1 USERDIR=$2 +TTYRECCACHE=$3 +SOTWDUMPCACHE=$4 ### # clean old ttyrecs ### cd /$HACKDIR/user/$USERDIR/ttyrec/ -ls -1tr | head -n -10 | xargs -d '\n' rm -f -- +ls -1tr | head -n -$TTYRECCACHE | xargs -d '\n' rm -f -- ### @@ -16,8 +18,9 @@ cd /$HACKDIR/user/$USERDIR/sotw/ # there are always 4 symlinked files # leave 5 of the latest dumps +DUMPFILES=$(expr $SOTWDUMPCACHE + 4) -FILES=$(ls -1tr *.txt | head -n -9) +FILES=$(ls -1tr *.txt | head -n -$DUMPFILES) for f in $FILES; do #test -h $f || echo "removing old file $f" diff --git a/nethack-launcher/cleanup.go b/nethack-launcher/cleanup.go index 12736f3..e1f81ac 100644 --- a/nethack-launcher/cleanup.go +++ b/nethack-launcher/cleanup.go @@ -11,7 +11,7 @@ func runCleanup(username string) { // non-symlinked .txt files in //user//sotw/ // run cleanup file - out, err := exec.Command("/bin/clean.sh", config.NethackLauncher.HackDir, username).Output() + out, err := exec.Command("/bin/clean.sh", config.NethackLauncher.HackDir, username, config.NethackLauncher.TTYRecCache, config.NethackLauncher.SotwDumpCache).Output() if err != nil { fmt.Println(err) } diff --git a/nethack-launcher/nethack-launcher.go b/nethack-launcher/nethack-launcher.go index 891817f..ac2547e 100644 --- a/nethack-launcher/nethack-launcher.go +++ b/nethack-launcher/nethack-launcher.go @@ -20,8 +20,10 @@ type Config struct { NhdatLocation string RecoverBinary string SysconfLocation string + TTYRecCache string SotwVersion string SotwRoot string + SotwDumpCache string BootstrapDelay time.Duration } -- 2.30.3 From 7e2bf9949e1504f9609a8f7ab36194573cb1cd67 Mon Sep 17 00:00:00 2001 From: Matthew Faltys Date: Fri, 13 Mar 2020 13:32:58 +0000 Subject: [PATCH 14/15] Add ttyrec library function Remove welcome screen data Cleanup user screen menu --- Makefile | 3 +- nethack-launcher/library.go | 144 +++++++++++++++++++++++ nethack-launcher/print_user_screen.go | 15 ++- nethack-launcher/print_welcome_screen.go | 9 -- 4 files changed, 158 insertions(+), 13 deletions(-) create mode 100644 nethack-launcher/library.go diff --git a/Makefile b/Makefile index da99eda..9d43abd 100644 --- a/Makefile +++ b/Makefile @@ -11,10 +11,11 @@ all: stat run: go run \ nethack-launcher/check_dir.go \ - nethack-launcher/cleanup.go \ + nethack-launcher/cleanup.go \ nethack-launcher/create_initial_files.go \ nethack-launcher/create_user_files.go \ nethack-launcher/janitor.go \ + nethack-launcher/library.go \ nethack-launcher/nethack-launcher.go \ nethack-launcher/print_change_password_screen.go \ nethack-launcher/print_high_scores.go \ diff --git a/nethack-launcher/library.go b/nethack-launcher/library.go new file mode 100644 index 0000000..652ec0f --- /dev/null +++ b/nethack-launcher/library.go @@ -0,0 +1,144 @@ +package main + +import ( + "bufio" + "fmt" + "io/ioutil" + "os" + "os/exec" + "strconv" + "strings" + + "gopkg.in/redis.v5" +) + +func printLibraryScreen(redisClient *redis.Client, username string) { + // print header + fmt.Printf(" %s\n", config.NethackLauncher.ServerDisplay) + println("") + + println(" Choose a users library to view ('enter' without selection returns)") + println("") + + us, err := ioutil.ReadDir(fmt.Sprintf("/%s/user", config.NethackLauncher.HackDir)) + if err != nil { + println(" No users exist ('enter' without selection returns)") + panic(err) + } + + users := make(map[int]string) + usersTimer := 1 + for _, u := range us { + fmt.Printf(" %d) %s\n", usersTimer, u.Name()) + + // add user to line map + users[usersTimer] = fmt.Sprintf("%s", u.Name()) + usersTimer++ + } + + fmt.Println("") + fmt.Printf(">> ") + // start user input + + // disable input buffering + exec.Command("stty", "-F", "/dev/tty", "cbreak", "min", "1").Run() + // do not display entered characters on the screen + exec.Command("stty", "-F", "/dev/tty", "-echo").Run() + + var b []byte = make([]byte, 1) + for { + os.Stdin.Read(b) + s, _ := strconv.Atoi(string(b)) + + // check if user is trying to navigate + if string(b) == "\n" { + exec.Command("stty", "-F", "/dev/tty", "echo", "-cbreak").Run() + clearScreen() + if username == "" { + clearScreen() + printWelcomeScreen(redisClient) + } else { + clearScreen() + printUserScreen(redisClient, username) + } + } + // check if selection is in out map + if users[s] != "" { + user := strings.Split(users[s], ":") + fmt.Printf("going to spectate '%s'\n", user[0]) + clearScreen() + printUserLibraryScreen(redisClient, username, user[0]) + } + } +} + +func printUserLibraryScreen(redisClient *redis.Client, username, currentUser string) { + // print header + fmt.Printf(" %s\n", config.NethackLauncher.ServerDisplay) + println("") + + println(" Choose a ttyrec to view ('enter' without selection returns)") + println(" The following keybinds are available during playback:") + println(" • + or f: double the speed of playback") + println(" • - or s: halve the speed of playback") + println(" • 0: set playback speed to 0, pausing playback") + println(" • 1: set playback speed to 1 again") + println("") + + t, err := ioutil.ReadDir(fmt.Sprintf("/%s/user/%s/ttyrec", config.NethackLauncher.HackDir, currentUser)) + if err != nil { + println(" No ttyrecs exist ('enter' without selection returns)") + panic(err) + } + + ttyrecs := make(map[int]string) + ttyrecsTimer := 1 + for _, ty := range t { + fmt.Printf(" %d) %s\n", ttyrecsTimer, ty.Name()) + + // add user to line map + ttyrecs[ttyrecsTimer] = fmt.Sprintf("%s", ty.Name()) + ttyrecsTimer++ + } + + fmt.Println("") + fmt.Printf(">> ") + // start user input + + // disable input buffering + exec.Command("stty", "-F", "/dev/tty", "cbreak", "min", "1").Run() + // enable showing input on screen + exec.Command("stty", "-F", "/dev/tty", "echo", "-cbreak").Run() + + scanner := bufio.NewScanner(os.Stdin) + for scanner.Scan() { + if scanner.Text() == "" { + clearScreen() + printLibraryScreen(redisClient, username) + } + // save input + s := scanner.Text() + sel, err := strconv.Atoi(s) + if err != nil { + fmt.Printf(" There was a problem with your last entry.\n>> ") + } + // check if selection is in our map + if ttyrecs[sel] != "" { + fmt.Printf("going to watch '%s'\n", ttyrecs[sel]) + clearScreen() + + // set ttyrec path + ttyrecPath := fmt.Sprintf("%s/user/%s/ttyrec/%s", config.NethackLauncher.HackDir, username, ttyrecs[sel]) + tp := exec.Command("ttyplay", ttyrecPath) + tp.Stdout = os.Stdout + tp.Stdin = os.Stdin + tp.Stderr = os.Stderr + err := tp.Run() + if err != nil { + fmt.Print(err) + } + } + clearScreen() + printUserLibraryScreen(redisClient, username, currentUser) + } +} diff --git a/nethack-launcher/print_user_screen.go b/nethack-launcher/print_user_screen.go index 0601cc6..70b601a 100644 --- a/nethack-launcher/print_user_screen.go +++ b/nethack-launcher/print_user_screen.go @@ -12,19 +12,25 @@ import ( func printUserScreen(redisClient *redis.Client, username string) string { clearScreen() fmt.Printf(" %s\n", config.NethackLauncher.ServerDisplay) - println("") fmt.Printf(" Logged in as: %s\n", username) println("") + println("Global") println(" l) Logout") println(" c) Change password") println(" w) Watch games in progress") + println(" x) Browse library of ttyrecs") + println("") + println("Shadow of the Wyrm") + println(" f) Edit SOTW config") + fmt.Printf(" o) Play Shadow of the Wyrm %s\n", config.NethackLauncher.SotwVersion) + println("") + println("Nethack") println(" h) View NetHack highscores") println(" a) View all NetHack scores") println(" e) Edit NetHack config") - println(" f) Edit SOTW config") println(" r) Recover NetHack from crash") fmt.Printf(" p) Play NetHack %s\n", config.NethackLauncher.NethackVersion) - fmt.Printf(" o) Play Shadow of the Wyrm %s\n", config.NethackLauncher.SotwVersion) + println("") println(" q) Quit") println("") fmt.Printf(">> ") @@ -83,6 +89,9 @@ func printUserScreen(redisClient *redis.Client, username string) string { case "w": clearScreen() printProgressScreen(redisClient, username) + case "x": + clearScreen() + printLibraryScreen(redisClient, username) case "h": clearScreen() printHighScores(redisClient, username) diff --git a/nethack-launcher/print_welcome_screen.go b/nethack-launcher/print_welcome_screen.go index 61e568b..9d2c81c 100644 --- a/nethack-launcher/print_welcome_screen.go +++ b/nethack-launcher/print_welcome_screen.go @@ -11,14 +11,11 @@ import ( func printWelcomeScreen(redisClient *redis.Client) string { clearScreen() fmt.Printf(" %s\n", config.NethackLauncher.ServerDisplay) - println("") println(" Not logged in.") println("") println(" l) Login") println(" r) Register new user") println(" w) Watch games in progress") - println(" h) View highscores") - println(" a) View all scores") println(" q) Quit") println("") fmt.Printf(">> ") @@ -45,12 +42,6 @@ func printWelcomeScreen(redisClient *redis.Client) string { case "w": clearScreen() printProgressScreen(redisClient, "") - case "h": - clearScreen() - printHighScores(redisClient, "") - case "a": - clearScreen() - printAllScores(redisClient, "") case "q": exec.Command("stty", "-F", "/dev/tty", "echo", "-cbreak").Run() clearScreen() -- 2.30.3 From b6f076897182288918906ba0b768c4fd18d17c37 Mon Sep 17 00:00:00 2001 From: Matthew Faltys Date: Thu, 29 Oct 2020 16:07:46 +0000 Subject: [PATCH 15/15] Update to SOTW 1.2.2 --- Makefile | 4 ++-- config.gcfg | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 9d43abd..724a8d3 100644 --- a/Makefile +++ b/Makefile @@ -58,8 +58,8 @@ build_docker: fetch_sotw fetch_sotw: mkdir -p stage.tmp/ - wget https://cryo.unixvoid.com/bin/misc/sotw/shadow-of-the-wyrm-release-1.1.7.tar.gz - mv shadow-of-the-wyrm-release-1.1.7.tar.gz stage.tmp/sotw.tar.gz + wget https://cryo.unixvoid.com/bin/misc/sotw/shadow-of-the-wyrm-release-1.2.2.tar.gz + mv shadow-of-the-wyrm-release-1.2.2.tar.gz stage.tmp/sotw.tar.gz run_docker: $(OS_PERMS) docker run \ diff --git a/config.gcfg b/config.gcfg index a1bf16e..219b199 100644 --- a/config.gcfg +++ b/config.gcfg @@ -7,7 +7,7 @@ recoverbinary = "/NetHack/util/recover" sysconflocation = "/NetHack/sys/unix/sysconf" ttyreccache = "10" - sotwversion = "1.1.7" + sotwversion = "1.2.2" sotwroot = "/sotw" sotwdumpcache = "5" bootstrapdelay = 1 -- 2.30.3