Browse Source

Add in progress menu

master
Matthew Faltys 5 years ago
parent
commit
c4547ff4bd
  1. 1
      config.gcfg
  2. 55
      nethack-launcher.go

1
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

55
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
os.Exit(0)
// 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])
// 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) {

Loading…
Cancel
Save