|
|
@ -8,6 +8,7 @@ import ( |
|
|
|
"net/http" |
|
|
|
"net/http" |
|
|
|
"os" |
|
|
|
"os" |
|
|
|
"os/exec" |
|
|
|
"os/exec" |
|
|
|
|
|
|
|
"strconv" |
|
|
|
"strings" |
|
|
|
"strings" |
|
|
|
"time" |
|
|
|
"time" |
|
|
|
|
|
|
|
|
|
|
@ -23,6 +24,7 @@ type Config struct { |
|
|
|
ServerDisplay string |
|
|
|
ServerDisplay string |
|
|
|
NethackVersion string |
|
|
|
NethackVersion string |
|
|
|
InProgressDir string |
|
|
|
InProgressDir string |
|
|
|
|
|
|
|
UserDir string |
|
|
|
RecordLocation string |
|
|
|
RecordLocation string |
|
|
|
ReclistLocation string |
|
|
|
ReclistLocation string |
|
|
|
BootstrapDelay time.Duration |
|
|
|
BootstrapDelay time.Duration |
|
|
@ -149,8 +151,7 @@ func printWelcomeScreen(redisClient *redis.Client) string { |
|
|
|
printRegisterScreen(redisClient) |
|
|
|
printRegisterScreen(redisClient) |
|
|
|
case "w": |
|
|
|
case "w": |
|
|
|
clearScreen() |
|
|
|
clearScreen() |
|
|
|
printProgressScreen() |
|
|
|
printProgressScreen(redisClient) |
|
|
|
return ("w") |
|
|
|
|
|
|
|
case "q": |
|
|
|
case "q": |
|
|
|
clearScreen() |
|
|
|
clearScreen() |
|
|
|
os.Exit(0) |
|
|
|
os.Exit(0) |
|
|
@ -187,6 +188,9 @@ func printUserScreen(redisClient *redis.Client, username string) string { |
|
|
|
exec.Command("stty", "-F", "/dev/tty", "echo", "-cbreak").Run() |
|
|
|
exec.Command("stty", "-F", "/dev/tty", "echo", "-cbreak").Run() |
|
|
|
clearScreen() |
|
|
|
clearScreen() |
|
|
|
printWelcomeScreen(redisClient) |
|
|
|
printWelcomeScreen(redisClient) |
|
|
|
|
|
|
|
case "w": |
|
|
|
|
|
|
|
clearScreen() |
|
|
|
|
|
|
|
printProgressScreen(redisClient) |
|
|
|
case "p": |
|
|
|
case "p": |
|
|
|
// restart display
|
|
|
|
// restart display
|
|
|
|
exec.Command("stty", "-F", "/dev/tty", "echo", "-cbreak").Run() |
|
|
|
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
|
|
|
|
// print header
|
|
|
|
fmt.Printf(" %s\n", config.NethackLauncher.ServerDisplay) |
|
|
|
fmt.Printf(" %s\n", config.NethackLauncher.ServerDisplay) |
|
|
|
println("") |
|
|
|
println("") |
|
|
@ -336,7 +341,7 @@ func printProgressScreen() { |
|
|
|
if isEmpty { |
|
|
|
if isEmpty { |
|
|
|
println(" No live players currently (blank entry returns)") |
|
|
|
println(" No live players currently (blank entry returns)") |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
println(" Choose a player to spectate (blank entry aborts)") |
|
|
|
println(" Choose a player to spectate ('enter' without selection returns)") |
|
|
|
} |
|
|
|
} |
|
|
|
println("") |
|
|
|
println("") |
|
|
|
|
|
|
|
|
|
|
@ -382,10 +387,46 @@ func printProgressScreen() { |
|
|
|
inProgTimer++ |
|
|
|
inProgTimer++ |
|
|
|
} |
|
|
|
} |
|
|
|
println("") |
|
|
|
println("") |
|
|
|
println(">>") |
|
|
|
fmt.Printf(">> ") |
|
|
|
// print out map
|
|
|
|
// 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) { |
|
|
|
func gethighscore(w http.ResponseWriter, r *http.Request) { |
|
|
|