From b4b388d91d70712ed447841c72ad874100671173 Mon Sep 17 00:00:00 2001 From: Matthew Faltys Date: Tue, 12 Nov 2019 14:42:22 +0000 Subject: [PATCH] Add initial ttyrec code --- Makefile | 17 +++++++++++++++++ nethack-launcher.go | 25 +++++++++++++------------ 2 files changed, 30 insertions(+), 12 deletions(-) diff --git a/Makefile b/Makefile index f26cf05..070d4d4 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,8 @@ GOC=go build GOFLAGS=-a -ldflags '-s' CGOR=CGO_ENABLED=0 +NETHACK_DIR=$(shell pwd)/savedata +IMAGE_NAME=nethack_launch all: stat reclist @@ -20,5 +22,20 @@ reclist: dependencies: go get github.com/gorilla/mux +#build_docker: +# mkdir -p stage.tmp/ +# cp -R deps/Dockerfile stage.tmp/ +# +#run: savedata +# $(OS_PERMS) docker run \ +# -d \ +# -p 23:23 \ +# -v $(NETHACK_DIR)/var:/opt/nethack/nethack.alt.org/nh343/var:rw \ +# -v $(NETHACK_DIR)/dgldir:/opt/nethack/nethack.alt.org/dgldir:rw \ +# --name=nethack \ +# --restart always \ +# $(IMAGE_NAME) + clean: rm -rf bin/ + rm -rf stage.tmp/ diff --git a/nethack-launcher.go b/nethack-launcher.go index 44471a7..bee8037 100644 --- a/nethack-launcher.go +++ b/nethack-launcher.go @@ -20,14 +20,14 @@ import ( type Config struct { NethackLauncher struct { - Loglevel string - ServerDisplay string - NethackVersion string - InProgressDir string - UserDir string - RecordLocation string - ReclistLocation string - BootstrapDelay time.Duration + Loglevel string + ServerDisplay string + NethackVersion string + InProgressDir string + UserDir string + RecordFileLocation string + ReclistLocation string + BootstrapDelay time.Duration } Redis struct { @@ -98,8 +98,8 @@ func initRedisConnection() (*redis.Client, error) { func checkFiles() { // make sure record file exists - if _, err := os.Stat(config.NethackLauncher.RecordLocation); os.IsNotExist(err) { - glogger.Info.Printf("record file not found in %s\n", config.NethackLauncher.RecordLocation) + if _, err := os.Stat(config.NethackLauncher.RecordFileLocation); os.IsNotExist(err) { + glogger.Info.Printf("record file not found in %s\n", config.NethackLauncher.RecordFileLocation) fmt.Printf("%s\n", err) os.Exit(1) } @@ -195,11 +195,12 @@ func printUserScreen(redisClient *redis.Client, username string) string { // restart display exec.Command("stty", "-F", "/dev/tty", "echo", "-cbreak").Run() clearScreen() - nh := exec.Command("nethack", "-u", username) + nh := exec.Command("ttyrec", "yeto.ttyrec", "-e", "nethack", "-u", username) nh.Stdout = os.Stdout nh.Stdin = os.Stdin nh.Stderr = os.Stderr nh.Run() + exec.Command("exit").Run() printUserScreen(redisClient, username) case "q": clearScreen() @@ -433,7 +434,7 @@ func gethighscore(w http.ResponseWriter, r *http.Request) { // run script output, err := exec.Command(config.NethackLauncher.ReclistLocation, "-f", - config.NethackLauncher.RecordLocation).CombinedOutput() + config.NethackLauncher.RecordFileLocation).CombinedOutput() if err != nil { fmt.Printf("%s\n", err) }