From d3cd8274a613e3f33576b121e7d53c1cc50198bd Mon Sep 17 00:00:00 2001 From: Matthew Faltys Date: Fri, 15 Nov 2019 20:56:10 +0000 Subject: [PATCH] Termrec research --- .gitignore | 2 +- Makefile | 7 +++---- deps/Dockerfile | 1 + deps/chowner.sh | 1 + deps/nethackrc | 9 +-------- deps/redis.conf | 2 +- deps/run_nethack.sh | 2 +- nethack-launcher.go | 23 ++++++++++++++++++----- 8 files changed, 27 insertions(+), 20 deletions(-) diff --git a/.gitignore b/.gitignore index 9f2af87..f715a0c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ *.swp -savedata/ +hack/ stage.tmp/ bin/ diff --git a/Makefile b/Makefile index 09951b4..5cbc143 100644 --- a/Makefile +++ b/Makefile @@ -2,7 +2,7 @@ GOC=go build GOFLAGS=-a -ldflags '-s' CGOR=CGO_ENABLED=0 OS_PERMS=sudo -NETHACK_DIR=$(shell pwd)/savedata +NETHACK_DIR=$(shell pwd)/hack IMAGE_NAME=nethack_launch @@ -35,13 +35,12 @@ build_docker: run_docker: $(OS_PERMS) docker run \ -d \ + -p 2222:22 \ --name=nethack \ + -v $(NETHACK_DIR):/hack:rw \ --restart always \ $(IMAGE_NAME) - #-v $(NETHACK_DIR)/var:/opt/nethack/nethack.alt.org/nh343/var:rw \ - #-v $(NETHACK_DIR)/dgldir:/opt/nethack/nethack.alt.org/dgldir:rw \ - clean: rm -rf bin/ rm -rf stage.tmp/ diff --git a/deps/Dockerfile b/deps/Dockerfile index e1432d3..874fe63 100644 --- a/deps/Dockerfile +++ b/deps/Dockerfile @@ -4,6 +4,7 @@ FROM debian RUN apt-get update && \ DEBIAN_FRONTEND=noninteractive apt-get install -y \ ttyrec \ + termrec \ nethack-console \ redis-server \ openssh-server \ diff --git a/deps/chowner.sh b/deps/chowner.sh index fdc3aec..602fca1 100755 --- a/deps/chowner.sh +++ b/deps/chowner.sh @@ -3,5 +3,6 @@ while : do chown -R hack:hack /hack 2> /dev/null + chmod -R 744 /hack 2> /dev/null sleep 2 done diff --git a/deps/nethackrc b/deps/nethackrc index 7035ddc..0250414 100644 --- a/deps/nethackrc +++ b/deps/nethackrc @@ -8,7 +8,7 @@ OPTIONS=menucolors OPTIONS=autodig OPTIONS=autoopen -OPTIONS=autopickup,pickup_types:$!/="+? +#OPTIONS=autopickup,pickup_types:$!/="+? OPTIONS=autoquiver OPTIONS=bones OPTIONS=boulder:0 @@ -16,20 +16,14 @@ OPTIONS=checkpoint OPTIONS=color OPTIONS=confirm OPTIONS=dark_room -OPTIONS=disclose:+iagcv -OPTIONS=fruit:berries OPTIONS=hilite_pet OPTIONS=hilite_pile -OPTIONS=lootabc OPTIONS=msg_window:reverse,msghistory:1000 -OPTIONS=pickup_burden:B -OPTIONS=!prayconfirm OPTIONS=lit_corridor OPTIONS=showrace OPTIONS=showexp,time OPTIONS=sortloot:full -OPTIONS=runmode:teleport,!rest_on_space ## Change symbols SYMBOLS=S_ghost:X @@ -168,6 +162,5 @@ MENUCOLOR=" uncursed| UC?($| )"=white MENUCOLOR=" \([-0-9]+:[-0-9]+\)"=white #nethack doesn't display "uncursed" if charges are known MENUCOLOR=" [+-][0-9]"=white - MENUCOLOR=" blessed| B($| )"=cyan MENUCOLOR=" cursed| C($| )"=red diff --git a/deps/redis.conf b/deps/redis.conf index 6554e91..6da04ac 100644 --- a/deps/redis.conf +++ b/deps/redis.conf @@ -1,4 +1,4 @@ daemonize yes dbfilename dump.rdb -dir /redisbackup/ +dir /hack/ save 30 1 diff --git a/deps/run_nethack.sh b/deps/run_nethack.sh index 3bb2058..81d6982 100755 --- a/deps/run_nethack.sh +++ b/deps/run_nethack.sh @@ -5,5 +5,5 @@ HOMEDIR=$2 HACKDIR=$3 USER=$4 -HOME=$HOMEDIR nethack -d $HACKDIR -u $USER +#HOME=$HOMEDIR nethack -d $HACKDIR -u $USER ttyrec $TTYRECPATH -e "HOME=$HOMEDIR nethack -d $HACKDIR -u $USER" diff --git a/nethack-launcher.go b/nethack-launcher.go index fbfd122..dd0523d 100644 --- a/nethack-launcher.go +++ b/nethack-launcher.go @@ -1,5 +1,8 @@ package main +// TODO make poll time faster +// TODO password redo field + import ( "bufio" "fmt" @@ -47,15 +50,15 @@ func main() { // init redis connection redisClient, redisErr := initRedisConnection() if redisErr != nil { - glogger.Debug.Printf("redis connection cannot be made, trying again in %s second(s)\n", config.NethackLauncher.BootstrapDelay*time.Second) + //glogger.Debug.Printf("redis connection cannot be made, trying again in %s second(s)\n", config.NethackLauncher.BootstrapDelay*time.Second) time.Sleep(config.NethackLauncher.BootstrapDelay * time.Second) redisClient, redisErr = initRedisConnection() if redisErr != nil { - glogger.Error.Println("redis connection cannot be made, exiting.") + //glogger.Error.Println("redis connection cannot be made, exiting.") panic(redisErr) } } else { - glogger.Debug.Println("connection to redis succeeded.") + //glogger.Debug.Println("connection to redis succeeded.") } // create initial files needed by nethack @@ -438,7 +441,8 @@ func printProgressScreen(redisClient *redis.Client, username string) { // restart display exec.Command("stty", "-F", "/dev/tty", "echo", "-cbreak").Run() clearScreen() - nh := exec.Command("ttyplay", "-p", ttyrecPath) + //nh := exec.Command("ttyplay", "-p", ttyrecPath) + nh := exec.Command("termplay", "-f", "live", ttyrecPath) nh.Stdout = os.Stdout nh.Stdin = os.Stdin nh.Stderr = os.Stderr @@ -459,7 +463,13 @@ func runGame(username, timestamp string) { ttyrecPath := fmt.Sprintf("%s/user/%s/ttyrec/%s.ttyrec", config.NethackLauncher.HackDir, username, timestamp) exec.Command("stty", "-F", "/dev/tty", "echo", "-cbreak").Run() clearScreen() - nh := exec.Command("/run_nethack.sh", ttyrecPath, homeDir, config.NethackLauncher.HackDir, username) + //nh := exec.Command("ttyrec", ttyrecPath, "-e", "nethack") + nh := exec.Command("termrec", ttyrecPath, "-e", "nethack") + //nh := exec.Command("termrec", ttyrecPath, "-e", "nethack") + nh.Env = os.Environ() + nh.Env = append(nh.Env, fmt.Sprintf("HOME=%s", homeDir)) + nh.Env = append(nh.Env, fmt.Sprintf("USER=%s", username)) + nh.Env = append(nh.Env, fmt.Sprintf("NETHACKDIR=%s", config.NethackLauncher.HackDir)) nh.Stdout = os.Stdout nh.Stdin = os.Stdin nh.Stderr = os.Stderr @@ -467,6 +477,9 @@ func runGame(username, timestamp string) { if err != nil { fmt.Print(err) } + fmt.Printf("%v\n", nh.Stdout) + fmt.Printf("%v\n", nh.Stdin) + fmt.Printf("%v\n", nh.Stderr) exec.Command("exit").Run() wg.Done() }