From c4547ff4bd80ef18f0953ba4a2733d23e809a4ea Mon Sep 17 00:00:00 2001 From: Matthew Faltys Date: Mon, 11 Nov 2019 16:49:02 +0000 Subject: [PATCH] Add in progress menu --- config.gcfg | 1 + nethack-launcher.go | 55 +++++++++++++++++++++++++++++++++++++++------ 2 files changed, 49 insertions(+), 7 deletions(-) diff --git a/config.gcfg b/config.gcfg index da4f875..19ebb47 100644 --- a/config.gcfg +++ b/config.gcfg @@ -3,6 +3,7 @@ serverdisplay = "unixvoid.com underground nethack server" nethackversion = "3.6.0" inprogressdir = "savedata/dgldir/inprogress-nh343" + userdir = "savedata/dgldir/userdata" recordlocation = "record" reclistlocation = "reclist" bootstrapdelay = 1 diff --git a/nethack-launcher.go b/nethack-launcher.go index c2d3ef7..44471a7 100644 --- a/nethack-launcher.go +++ b/nethack-launcher.go @@ -8,6 +8,7 @@ import ( "net/http" "os" "os/exec" + "strconv" "strings" "time" @@ -23,6 +24,7 @@ type Config struct { ServerDisplay string NethackVersion string InProgressDir string + UserDir string RecordLocation string ReclistLocation string BootstrapDelay time.Duration @@ -149,8 +151,7 @@ func printWelcomeScreen(redisClient *redis.Client) string { printRegisterScreen(redisClient) case "w": clearScreen() - printProgressScreen() - return ("w") + printProgressScreen(redisClient) case "q": clearScreen() os.Exit(0) @@ -187,6 +188,9 @@ func printUserScreen(redisClient *redis.Client, username string) string { exec.Command("stty", "-F", "/dev/tty", "echo", "-cbreak").Run() clearScreen() printWelcomeScreen(redisClient) + case "w": + clearScreen() + printProgressScreen(redisClient) case "p": // restart display exec.Command("stty", "-F", "/dev/tty", "echo", "-cbreak").Run() @@ -323,7 +327,8 @@ func printRegisterScreen(redisClient *redis.Client) { } } -func printProgressScreen() { +func printProgressScreen(redisClient *redis.Client) { + // TODO check if user is logged in and take them back to login screen after blank entry // print header fmt.Printf(" %s\n", config.NethackLauncher.ServerDisplay) println("") @@ -336,7 +341,7 @@ func printProgressScreen() { if isEmpty { println(" No live players currently (blank entry returns)") } else { - println(" Choose a player to spectate (blank entry aborts)") + println(" Choose a player to spectate ('enter' without selection returns)") } println("") @@ -382,10 +387,46 @@ func printProgressScreen() { inProgTimer++ } println("") - println(">>") - // print out map + fmt.Printf(">> ") + // start user input + + // disable input buffering + exec.Command("stty", "-F", "/dev/tty", "cbreak", "min", "1").Run() + // do not display entered characters on the screen + exec.Command("stty", "-F", "/dev/tty", "-echo").Run() + + var b []byte = make([]byte, 1) + for { + os.Stdin.Read(b) + s, _ := strconv.Atoi(string(b)) + + // check if user is trying to navigate + if string(b) == "\n" { + exec.Command("stty", "-F", "/dev/tty", "echo", "-cbreak").Run() + clearScreen() + printWelcomeScreen(redisClient) + } + + // check if selection is in out map + if inProg[s] != "" { + user := strings.Split(inProg[s], ":") + fmt.Printf("going to spectate '%s'\n", user[0]) - os.Exit(0) + // set ttyrec path + ttyrecPath := fmt.Sprintf("%s/%s/%s/ttyrec/%s:%s:%s.ttyrec", config.NethackLauncher.UserDir, user[0][0:1], user[0], user[1], user[2], user[3]) + + // restart display + exec.Command("stty", "-F", "/dev/tty", "echo", "-cbreak").Run() + clearScreen() + nh := exec.Command("ttyplay", "-p", ttyrecPath) + nh.Stdout = os.Stdout + nh.Stdin = os.Stdin + nh.Stderr = os.Stderr + nh.Run() + // TODO add username to this + //printUserScreen(redisClient, username) + } + } } func gethighscore(w http.ResponseWriter, r *http.Request) {