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