Browse Source

Remove depricated config options

master
Matthew Faltys 5 years ago
parent
commit
94dc2ced23
  1. 1
      config.gcfg
  2. 1
      deps/server_config.gcfg
  3. 74
      nethack-launcher.go

1
config.gcfg

@ -4,7 +4,6 @@
nethackversion = "3.6.0" nethackversion = "3.6.0"
hackdir = "savedata/hack" hackdir = "savedata/hack"
nhdatlocation = "/usr/lib/games/nethack/nhdat" nhdatlocation = "/usr/lib/games/nethack/nhdat"
reclistlocation = "reclist"
bootstrapdelay = 1 bootstrapdelay = 1
[redis] [redis]

1
deps/server_config.gcfg vendored

@ -4,7 +4,6 @@
nethackversion = "3.6.0" nethackversion = "3.6.0"
hackdir = "/hack" hackdir = "/hack"
nhdatlocation = "/usr/lib/games/nethack/nhdat" nhdatlocation = "/usr/lib/games/nethack/nhdat"
reclistlocation = "/bin/reclist"
bootstrapdelay = 1 bootstrapdelay = 1
[redis] [redis]

74
nethack-launcher.go

@ -5,7 +5,6 @@ import (
"fmt" "fmt"
"io" "io"
"io/ioutil" "io/ioutil"
"net/http"
"os" "os"
"os/exec" "os/exec"
"strconv" "strconv"
@ -21,13 +20,12 @@ import (
type Config struct { type Config struct {
NethackLauncher struct { NethackLauncher struct {
Loglevel string Loglevel string
ServerDisplay string ServerDisplay string
NethackVersion string NethackVersion string
HackDir string HackDir string
NhdatLocation string NhdatLocation string
ReclistLocation string BootstrapDelay time.Duration
BootstrapDelay time.Duration
} }
Redis struct { Redis struct {
@ -111,13 +109,6 @@ func checkFiles() {
fmt.Printf("%s\n", err) fmt.Printf("%s\n", err)
os.Exit(1) os.Exit(1)
} }
// make sure reclist bin exists
if _, err := os.Stat(config.NethackLauncher.ReclistLocation); os.IsNotExist(err) {
glogger.Info.Printf("reclist binary not found in %s\n", config.NethackLauncher.ReclistLocation)
fmt.Printf("%s\n", err)
os.Exit(1)
}
// TODO check other needed files
} }
func clearScreen() { func clearScreen() {
@ -135,6 +126,7 @@ func printWelcomeScreen(redisClient *redis.Client) string {
println(" l) Login") println(" l) Login")
println(" r) Register new user") println(" r) Register new user")
println(" w) Watch games in progress") println(" w) Watch games in progress")
println(" h) View highscores")
println(" q) Quit") println(" q) Quit")
println("") println("")
fmt.Printf(">> ") fmt.Printf(">> ")
@ -161,6 +153,9 @@ func printWelcomeScreen(redisClient *redis.Client) string {
case "w": case "w":
clearScreen() clearScreen()
printProgressScreen(redisClient, "") printProgressScreen(redisClient, "")
case "h":
clearScreen()
printHighScores(redisClient, "")
case "q": case "q":
exec.Command("stty", "-F", "/dev/tty", "echo", "-cbreak").Run() exec.Command("stty", "-F", "/dev/tty", "echo", "-cbreak").Run()
clearScreen() clearScreen()
@ -178,6 +173,7 @@ func printUserScreen(redisClient *redis.Client, username string) string {
println("") println("")
println(" l) Logout") println(" l) Logout")
println(" w) Watch games in progress") println(" w) Watch games in progress")
println(" h) View highscores")
println(" e) Edit config") println(" e) Edit config")
fmt.Printf(" p) Play NetHack %s\n", config.NethackLauncher.NethackVersion) fmt.Printf(" p) Play NetHack %s\n", config.NethackLauncher.NethackVersion)
println(" q) Quit") println(" q) Quit")
@ -212,6 +208,9 @@ func printUserScreen(redisClient *redis.Client, username string) string {
case "w": case "w":
clearScreen() clearScreen()
printProgressScreen(redisClient, username) printProgressScreen(redisClient, username)
case "h":
clearScreen()
printHighScores(redisClient, username)
case "p": case "p":
wg.Add(1) wg.Add(1)
currentTime := time.Now().UTC() currentTime := time.Now().UTC()
@ -481,7 +480,6 @@ func startWatcher(username, timestamp string, redisClient *redis.Client) chan st
case <-ch: case <-ch:
return return
default: default:
// SADD
redisClient.Expire(fmt.Sprintf("inprogress:%s", username), 10*time.Second) redisClient.Expire(fmt.Sprintf("inprogress:%s", username), 10*time.Second)
time.Sleep(8 * time.Second) time.Sleep(8 * time.Second)
} }
@ -536,16 +534,42 @@ func janitor(redisClient *redis.Client) {
} }
} }
func gethighscore(w http.ResponseWriter, r *http.Request) { func printHighScores(redisClient *redis.Client, username string) {
// run script exec.Command("stty", "-F", "/dev/tty", "echo", "-cbreak").Run()
output, err := exec.Command(config.NethackLauncher.ReclistLocation, clearScreen()
"-f",
fmt.Sprintf("%s/record", config.NethackLauncher.HackDir)).CombinedOutput()
if err != nil {
fmt.Printf("%s\n", err)
}
fmt.Fprintf(w, "%s\n", output) nh := exec.Command("nethack", "-d", config.NethackLauncher.HackDir, "-s")
nh.Stdout = os.Stdout
nh.Stdin = os.Stdin
nh.Stderr = os.Stderr
nh.Run()
println("")
println(" Press enter to return to menu")
println("")
fmt.Printf(">> ")
// allow user back to home screen
// 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)
// check if user is trying to navigate
if string(b) == "\n" {
exec.Command("stty", "-F", "/dev/tty", "echo", "-cbreak").Run()
clearScreen()
if username == "" {
printWelcomeScreen(redisClient)
} else {
printUserScreen(redisClient, username)
}
}
}
} }
func checkDir(dirName string) (bool, error) { func checkDir(dirName string) (bool, error) {

Loading…
Cancel
Save