diff --git a/config.gcfg b/config.gcfg index b554e4c..9a9d61f 100644 --- a/config.gcfg +++ b/config.gcfg @@ -6,7 +6,6 @@ userdir = "savedata/dgldir/userdata" hackdir = "savedata/hack" nhdatlocation = "/usr/lib/games/nethack/nhdat" - recordfilelocation = "record" reclistlocation = "reclist" bootstrapdelay = 1 diff --git a/deps/server_config.gcfg b/deps/server_config.gcfg index 45e50f7..1583c4b 100644 --- a/deps/server_config.gcfg +++ b/deps/server_config.gcfg @@ -6,7 +6,6 @@ userdir = "savedata/dgldir/userdata" hackdir = "/hack" nhdatlocation = "/usr/lib/games/nethack/nhdat" - recordfilelocation = "/hack/record" reclistlocation = "/bin/reclist" bootstrapdelay = 1 diff --git a/nethack-launcher.go b/nethack-launcher.go index 2c5bfeb..ba210d9 100644 --- a/nethack-launcher.go +++ b/nethack-launcher.go @@ -20,16 +20,15 @@ import ( type Config struct { NethackLauncher struct { - Loglevel string - ServerDisplay string - NethackVersion string - InProgressDir string // TODO: depricate this - UserDir string // TODO: depricate this - HackDir string - NhdatLocation string - RecordFileLocation string - ReclistLocation string - BootstrapDelay time.Duration + Loglevel string + ServerDisplay string + NethackVersion string + InProgressDir string // TODO: depricate this + UserDir string // TODO: depricate this + HackDir string + NhdatLocation string + ReclistLocation string + BootstrapDelay time.Duration } Redis struct { @@ -104,8 +103,8 @@ func initRedisConnection() (*redis.Client, error) { func checkFiles() { // make sure record file exists - if _, err := os.Stat(config.NethackLauncher.RecordFileLocation); os.IsNotExist(err) { - glogger.Info.Printf("record file not found in %s\n", config.NethackLauncher.RecordFileLocation) + if _, err := os.Stat(fmt.Sprintf("%s/record", config.NethackLauncher.HackDir)); os.IsNotExist(err) { + glogger.Info.Printf("record file not found in %s/record\n", config.NethackLauncher.HackDir) fmt.Printf("%s\n", err) os.Exit(1) } @@ -200,6 +199,13 @@ func printUserScreen(redisClient *redis.Client, username string) string { printProgressScreen(redisClient) case "p": // TODO save to inprogress + // SADD user to an inprogress redis set + // SET inprogress:user and expire it to 10 seconds + // start goroutine that keeps upping expire time every 8 or so seconds + // when goroutine exists, the key will be allowed to expire + // have a janitor that watches inprogress set + // janitor looks at every user in 'inprogress' and checks if the key remains + // if the key is gone, janitor kills the user from redis set // restart display nhCommand := fmt.Sprintf("nethack -d %s -u %s\n", config.NethackLauncher.HackDir, username) ttyrecPath := fmt.Sprintf("%s/user/%s/ttyrec/yeet.ttyrec", config.NethackLauncher.HackDir, username) @@ -482,7 +488,7 @@ func gethighscore(w http.ResponseWriter, r *http.Request) { // run script output, err := exec.Command(config.NethackLauncher.ReclistLocation, "-f", - config.NethackLauncher.RecordFileLocation).CombinedOutput() + fmt.Sprintf("%s/record", config.NethackLauncher.HackDir)).CombinedOutput() if err != nil { fmt.Printf("%s\n", err) }