|
|
@ -20,16 +20,15 @@ import ( |
|
|
|
|
|
|
|
|
|
|
|
type Config struct { |
|
|
|
type Config struct { |
|
|
|
NethackLauncher struct { |
|
|
|
NethackLauncher struct { |
|
|
|
Loglevel string |
|
|
|
Loglevel string |
|
|
|
ServerDisplay string |
|
|
|
ServerDisplay string |
|
|
|
NethackVersion string |
|
|
|
NethackVersion string |
|
|
|
InProgressDir string // TODO: depricate this
|
|
|
|
InProgressDir string // TODO: depricate this
|
|
|
|
UserDir string // TODO: depricate this
|
|
|
|
UserDir string // TODO: depricate this
|
|
|
|
HackDir string |
|
|
|
HackDir string |
|
|
|
NhdatLocation string |
|
|
|
NhdatLocation string |
|
|
|
RecordFileLocation string |
|
|
|
ReclistLocation string |
|
|
|
ReclistLocation string |
|
|
|
BootstrapDelay time.Duration |
|
|
|
BootstrapDelay time.Duration |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
Redis struct { |
|
|
|
Redis struct { |
|
|
@ -104,8 +103,8 @@ func initRedisConnection() (*redis.Client, error) { |
|
|
|
|
|
|
|
|
|
|
|
func checkFiles() { |
|
|
|
func checkFiles() { |
|
|
|
// make sure record file exists
|
|
|
|
// make sure record file exists
|
|
|
|
if _, err := os.Stat(config.NethackLauncher.RecordFileLocation); os.IsNotExist(err) { |
|
|
|
if _, err := os.Stat(fmt.Sprintf("%s/record", config.NethackLauncher.HackDir)); os.IsNotExist(err) { |
|
|
|
glogger.Info.Printf("record file not found in %s\n", config.NethackLauncher.RecordFileLocation) |
|
|
|
glogger.Info.Printf("record file not found in %s/record\n", config.NethackLauncher.HackDir) |
|
|
|
fmt.Printf("%s\n", err) |
|
|
|
fmt.Printf("%s\n", err) |
|
|
|
os.Exit(1) |
|
|
|
os.Exit(1) |
|
|
|
} |
|
|
|
} |
|
|
@ -200,6 +199,13 @@ func printUserScreen(redisClient *redis.Client, username string) string { |
|
|
|
printProgressScreen(redisClient) |
|
|
|
printProgressScreen(redisClient) |
|
|
|
case "p": |
|
|
|
case "p": |
|
|
|
// TODO save to inprogress
|
|
|
|
// 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
|
|
|
|
// restart display
|
|
|
|
nhCommand := fmt.Sprintf("nethack -d %s -u %s\n", config.NethackLauncher.HackDir, username) |
|
|
|
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) |
|
|
|
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
|
|
|
|
// run script
|
|
|
|
output, err := exec.Command(config.NethackLauncher.ReclistLocation, |
|
|
|
output, err := exec.Command(config.NethackLauncher.ReclistLocation, |
|
|
|
"-f", |
|
|
|
"-f", |
|
|
|
config.NethackLauncher.RecordFileLocation).CombinedOutput() |
|
|
|
fmt.Sprintf("%s/record", config.NethackLauncher.HackDir)).CombinedOutput() |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
fmt.Printf("%s\n", err) |
|
|
|
fmt.Printf("%s\n", err) |
|
|
|
} |
|
|
|
} |
|
|
|