Browse Source

Add initial user hackfile

master
Matthew Faltys 5 years ago
parent
commit
d156d69bc4
  1. 1
      Makefile
  2. 2
      deps/Dockerfile
  3. 6
      deps/nethackrc
  4. 26
      nethack-launcher.go

1
Makefile

@ -31,6 +31,7 @@ build_docker:
cp bin/nethack-launcher stage.tmp/ cp bin/nethack-launcher stage.tmp/
cp deps/redis.conf stage.tmp/ cp deps/redis.conf stage.tmp/
cp deps/run.sh stage.tmp/ cp deps/run.sh stage.tmp/
cp deps/nethackrc stage.tmp/
cd stage.tmp/ && \ cd stage.tmp/ && \
$(OS_PERMS) docker build -t $(IMAGE_NAME) . $(OS_PERMS) docker build -t $(IMAGE_NAME) .

2
deps/Dockerfile vendored

@ -13,6 +13,7 @@ RUN mkdir -p /redisbackup/
# update nethack bin location # update nethack bin location
RUN mv /usr/games/nethack /bin/nethack RUN mv /usr/games/nethack /bin/nethack
RUN mkdir /hack/
# copy in files # copy in files
COPY config.gcfg / COPY config.gcfg /
@ -20,5 +21,6 @@ COPY nethack-launcher /
COPY reclist /bin/ COPY reclist /bin/
COPY redis.conf / COPY redis.conf /
COPY run.sh / COPY run.sh /
COPY nethackrc /hack/.nethackrc
CMD ["/run.sh"] CMD ["/run.sh"]

6
deps/nethackrc vendored

@ -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

26
nethack-launcher.go

@ -160,7 +160,7 @@ func printWelcomeScreen(redisClient *redis.Client) string {
printRegisterScreen(redisClient) printRegisterScreen(redisClient)
case "w": case "w":
clearScreen() clearScreen()
printProgressScreen(redisClient) printProgressScreen(redisClient, "")
case "q": case "q":
exec.Command("stty", "-F", "/dev/tty", "echo", "-cbreak").Run() exec.Command("stty", "-F", "/dev/tty", "echo", "-cbreak").Run()
clearScreen() clearScreen()
@ -200,7 +200,7 @@ func printUserScreen(redisClient *redis.Client, username string) string {
printWelcomeScreen(redisClient) printWelcomeScreen(redisClient)
case "w": case "w":
clearScreen() clearScreen()
printProgressScreen(redisClient) printProgressScreen(redisClient, username)
case "p": case "p":
wg.Add(1) wg.Add(1)
currentTime := time.Now().UTC() currentTime := time.Now().UTC()
@ -342,6 +342,12 @@ func printRegisterScreen(redisClient *redis.Client) {
userPath := fmt.Sprintf("%s/user/%s/ttyrec/", config.NethackLauncher.HackDir, username) userPath := fmt.Sprintf("%s/user/%s/ttyrec/", config.NethackLauncher.HackDir, username)
exec.Command("mkdir", "-p", userPath).Run() 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 // back to main screen
printUserScreen(redisClient, username) 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 // print header
fmt.Printf(" %s\n", config.NethackLauncher.ServerDisplay) fmt.Printf(" %s\n", config.NethackLauncher.ServerDisplay)
println("") println("")
@ -401,7 +407,11 @@ func printProgressScreen(redisClient *redis.Client) {
if string(b) == "\n" { if string(b) == "\n" {
exec.Command("stty", "-F", "/dev/tty", "echo", "-cbreak").Run() exec.Command("stty", "-F", "/dev/tty", "echo", "-cbreak").Run()
clearScreen() clearScreen()
printWelcomeScreen(redisClient) if username == "" {
printWelcomeScreen(redisClient)
} else {
printUserScreen(redisClient, username)
}
} }
// check if selection is in out map // check if selection is in out map
@ -421,10 +431,12 @@ func printProgressScreen(redisClient *redis.Client) {
nh.Stdin = os.Stdin nh.Stdin = os.Stdin
nh.Stderr = os.Stderr nh.Stderr = os.Stderr
nh.Run() nh.Run()
// TODO add username to this if username == "" {
printWelcomeScreen(redisClient)
} else {
printUserScreen(redisClient, username)
}
// TODO fix bug where user has to <ctrl-c> when game exists // TODO fix bug where user has to <ctrl-c> when game exists
//printUserScreen(redisClient, username)
printWelcomeScreen(redisClient)
} }
} }
} }

Loading…
Cancel
Save