|
|
@ -23,8 +23,10 @@ type Config struct { |
|
|
|
Loglevel string |
|
|
|
Loglevel string |
|
|
|
ServerDisplay string |
|
|
|
ServerDisplay string |
|
|
|
NethackVersion string |
|
|
|
NethackVersion string |
|
|
|
InProgressDir string |
|
|
|
InProgressDir string // TODO: depricate this
|
|
|
|
UserDir string |
|
|
|
UserDir string // TODO: depricate this
|
|
|
|
|
|
|
|
HackDir string |
|
|
|
|
|
|
|
NhdatLocation string |
|
|
|
RecordFileLocation string |
|
|
|
RecordFileLocation string |
|
|
|
ReclistLocation string |
|
|
|
ReclistLocation string |
|
|
|
BootstrapDelay time.Duration |
|
|
|
BootstrapDelay time.Duration |
|
|
@ -59,6 +61,10 @@ func main() { |
|
|
|
glogger.Debug.Println("connection to redis succeeded.") |
|
|
|
glogger.Debug.Println("connection to redis succeeded.") |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// create initial files needed by nethack
|
|
|
|
|
|
|
|
createInitialFiles() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// start homescreen
|
|
|
|
screenFunction := printWelcomeScreen(redisClient) |
|
|
|
screenFunction := printWelcomeScreen(redisClient) |
|
|
|
fmt.Printf("screen %s recieved\n", screenFunction) |
|
|
|
fmt.Printf("screen %s recieved\n", screenFunction) |
|
|
|
} |
|
|
|
} |
|
|
@ -153,6 +159,7 @@ func printWelcomeScreen(redisClient *redis.Client) string { |
|
|
|
clearScreen() |
|
|
|
clearScreen() |
|
|
|
printProgressScreen(redisClient) |
|
|
|
printProgressScreen(redisClient) |
|
|
|
case "q": |
|
|
|
case "q": |
|
|
|
|
|
|
|
exec.Command("stty", "-F", "/dev/tty", "echo", "-cbreak").Run() |
|
|
|
clearScreen() |
|
|
|
clearScreen() |
|
|
|
os.Exit(0) |
|
|
|
os.Exit(0) |
|
|
|
default: |
|
|
|
default: |
|
|
@ -192,10 +199,13 @@ func printUserScreen(redisClient *redis.Client, username string) string { |
|
|
|
clearScreen() |
|
|
|
clearScreen() |
|
|
|
printProgressScreen(redisClient) |
|
|
|
printProgressScreen(redisClient) |
|
|
|
case "p": |
|
|
|
case "p": |
|
|
|
|
|
|
|
// TODO save to inprogress
|
|
|
|
// restart display
|
|
|
|
// 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) |
|
|
|
exec.Command("stty", "-F", "/dev/tty", "echo", "-cbreak").Run() |
|
|
|
exec.Command("stty", "-F", "/dev/tty", "echo", "-cbreak").Run() |
|
|
|
clearScreen() |
|
|
|
clearScreen() |
|
|
|
nh := exec.Command("ttyrec", "yeto.ttyrec", "-e", "nethack", "-u", username) |
|
|
|
nh := exec.Command("ttyrec", ttyrecPath, "-e", nhCommand) |
|
|
|
nh.Stdout = os.Stdout |
|
|
|
nh.Stdout = os.Stdout |
|
|
|
nh.Stdin = os.Stdin |
|
|
|
nh.Stdin = os.Stdin |
|
|
|
nh.Stderr = os.Stderr |
|
|
|
nh.Stderr = os.Stderr |
|
|
@ -317,9 +327,23 @@ func printRegisterScreen(redisClient *redis.Client) { |
|
|
|
fmt.Println("Lets try that again.") |
|
|
|
fmt.Println("Lets try that again.") |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// reset display
|
|
|
|
|
|
|
|
exec.Command("stty", "-F", "/dev/tty", "echo", "-cbreak").Run() |
|
|
|
|
|
|
|
|
|
|
|
// set user in redis
|
|
|
|
// set user in redis
|
|
|
|
secHash := sha3.Sum512([]byte(sec)) |
|
|
|
secHash := sha3.Sum512([]byte(sec)) |
|
|
|
redisClient.Set(fmt.Sprintf("user:%s", username), fmt.Sprintf("%x", secHash), 0).Err() |
|
|
|
redisClient.Set(fmt.Sprintf("user:%s", username), fmt.Sprintf("%x", secHash), 0).Err() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// TODO create config file
|
|
|
|
|
|
|
|
// HackDir/user/username/<config>
|
|
|
|
|
|
|
|
// HackDir/user/username/ttyrec/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// create user directories
|
|
|
|
|
|
|
|
userPath := fmt.Sprintf("%s/user/%s/ttyrec/", config.NethackLauncher.HackDir, username) |
|
|
|
|
|
|
|
exec.Command("mkdir", "-p", userPath).Run() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// back to main screen
|
|
|
|
printUserScreen(redisClient, username) |
|
|
|
printUserScreen(redisClient, username) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -430,6 +454,30 @@ func printProgressScreen(redisClient *redis.Client) { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func createInitialFiles() { |
|
|
|
|
|
|
|
// create necessary directories if they dont exist
|
|
|
|
|
|
|
|
if _, err := os.Stat(config.NethackLauncher.HackDir); os.IsNotExist(err) { |
|
|
|
|
|
|
|
os.Mkdir(config.NethackLauncher.HackDir, os.ModeDir) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if _, err := os.Stat(fmt.Sprintf("%s/dumps/", config.NethackLauncher.HackDir)); os.IsNotExist(err) { |
|
|
|
|
|
|
|
os.Mkdir(fmt.Sprintf("%s/dumps/", config.NethackLauncher.HackDir), os.ModeDir) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if _, err := os.Stat(fmt.Sprintf("%s/save/", config.NethackLauncher.HackDir)); os.IsNotExist(err) { |
|
|
|
|
|
|
|
os.Mkdir(fmt.Sprintf("%s/save/", config.NethackLauncher.HackDir), os.ModeDir) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// create necessary files if they dont exist
|
|
|
|
|
|
|
|
os.OpenFile(fmt.Sprintf("%s/logfile", config.NethackLauncher.HackDir), os.O_RDONLY|os.O_CREATE, 0666) |
|
|
|
|
|
|
|
os.OpenFile(fmt.Sprintf("%s/perm", config.NethackLauncher.HackDir), os.O_RDONLY|os.O_CREATE, 0666) |
|
|
|
|
|
|
|
os.OpenFile(fmt.Sprintf("%s/record", config.NethackLauncher.HackDir), os.O_RDONLY|os.O_CREATE, 0666) |
|
|
|
|
|
|
|
os.OpenFile(fmt.Sprintf("%s/xlogfile", config.NethackLauncher.HackDir), os.O_RDONLY|os.O_CREATE, 0666) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// move in nhdat file if it does not exist
|
|
|
|
|
|
|
|
if _, err := os.Stat(fmt.Sprintf("%s/nhdat", config.NethackLauncher.HackDir)); os.IsNotExist(err) { |
|
|
|
|
|
|
|
exec.Command("cp", config.NethackLauncher.NhdatLocation, config.NethackLauncher.HackDir).Run() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func gethighscore(w http.ResponseWriter, r *http.Request) { |
|
|
|
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, |
|
|
|