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. 24
      nethack-launcher.go

1
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) .

2
deps/Dockerfile vendored

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

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

24
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()
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
// TODO fix bug where user has to <ctrl-c> when game exists
//printUserScreen(redisClient, username)
if username == "" {
printWelcomeScreen(redisClient)
} else {
printUserScreen(redisClient, username)
}
// TODO fix bug where user has to <ctrl-c> when game exists
}
}
}

Loading…
Cancel
Save