From d156d69bc4378d733665454e6435171f225e256f Mon Sep 17 00:00:00 2001 From: Matthew Faltys Date: Wed, 13 Nov 2019 03:55:11 +0000 Subject: [PATCH] Add initial user hackfile --- Makefile | 1 + deps/Dockerfile | 2 ++ deps/nethackrc | 6 ++++++ nethack-launcher.go | 26 +++++++++++++++++++------- 4 files changed, 28 insertions(+), 7 deletions(-) create mode 100644 deps/nethackrc diff --git a/Makefile b/Makefile index 446b07a..7441335 100644 --- a/Makefile +++ b/Makefile @@ -31,6 +31,7 @@ build_docker: cp bin/nethack-launcher stage.tmp/ cp deps/redis.conf stage.tmp/ cp deps/run.sh stage.tmp/ + cp deps/nethackrc stage.tmp/ cd stage.tmp/ && \ $(OS_PERMS) docker build -t $(IMAGE_NAME) . diff --git a/deps/Dockerfile b/deps/Dockerfile index f0fa378..58a46d3 100644 --- a/deps/Dockerfile +++ b/deps/Dockerfile @@ -13,6 +13,7 @@ RUN mkdir -p /redisbackup/ # update nethack bin location RUN mv /usr/games/nethack /bin/nethack +RUN mkdir /hack/ # copy in files COPY config.gcfg / @@ -20,5 +21,6 @@ COPY nethack-launcher / COPY reclist /bin/ COPY redis.conf / COPY run.sh / +COPY nethackrc /hack/.nethackrc CMD ["/run.sh"] diff --git a/deps/nethackrc b/deps/nethackrc new file mode 100644 index 0000000..da7e942 --- /dev/null +++ b/deps/nethackrc @@ -0,0 +1,6 @@ +# welcome to the real unixvoid dungeon +# good luck escaping +# jk, its vim + +OPTIONS=showexp,showscore,time,color,!autopickup +OPTIONS=autodig,fruit:slime mold,boulder:0 diff --git a/nethack-launcher.go b/nethack-launcher.go index dc014cc..3813b7d 100644 --- a/nethack-launcher.go +++ b/nethack-launcher.go @@ -160,7 +160,7 @@ func printWelcomeScreen(redisClient *redis.Client) string { printRegisterScreen(redisClient) case "w": clearScreen() - printProgressScreen(redisClient) + printProgressScreen(redisClient, "") case "q": exec.Command("stty", "-F", "/dev/tty", "echo", "-cbreak").Run() clearScreen() @@ -200,7 +200,7 @@ func printUserScreen(redisClient *redis.Client, username string) string { printWelcomeScreen(redisClient) case "w": clearScreen() - printProgressScreen(redisClient) + printProgressScreen(redisClient, username) case "p": wg.Add(1) currentTime := time.Now().UTC() @@ -342,6 +342,12 @@ func printRegisterScreen(redisClient *redis.Client) { userPath := fmt.Sprintf("%s/user/%s/ttyrec/", config.NethackLauncher.HackDir, username) exec.Command("mkdir", "-p", userPath).Run() + // copy in rc file + // TODO make sure rc file exists before copying + hackRCLoc := fmt.Sprintf("%s/.nethackrc", config.NethackLauncher.HackDir) + hackRCDest := fmt.Sprintf("%s/user/%s/.nethackrc", config.NethackLauncher.HackDir, username) + exec.Command("cp", hackRCLoc, hackRCDest).Run() + // back to main screen printUserScreen(redisClient, username) } @@ -351,7 +357,7 @@ func printRegisterScreen(redisClient *redis.Client) { } } -func printProgressScreen(redisClient *redis.Client) { +func printProgressScreen(redisClient *redis.Client, username string) { // print header fmt.Printf(" %s\n", config.NethackLauncher.ServerDisplay) println("") @@ -401,7 +407,11 @@ func printProgressScreen(redisClient *redis.Client) { if string(b) == "\n" { exec.Command("stty", "-F", "/dev/tty", "echo", "-cbreak").Run() clearScreen() - printWelcomeScreen(redisClient) + if username == "" { + printWelcomeScreen(redisClient) + } else { + printUserScreen(redisClient, username) + } } // check if selection is in out map @@ -421,10 +431,12 @@ func printProgressScreen(redisClient *redis.Client) { nh.Stdin = os.Stdin nh.Stderr = os.Stderr nh.Run() - // TODO add username to this + if username == "" { + printWelcomeScreen(redisClient) + } else { + printUserScreen(redisClient, username) + } // TODO fix bug where user has to when game exists - //printUserScreen(redisClient, username) - printWelcomeScreen(redisClient) } } }