|
|
|
@ -155,6 +155,46 @@ func printWelcomeScreen(redisClient *redis.Client) string {
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func printUserScreen(redisClient *redis.Client, username string) string { |
|
|
|
|
clearScreen() |
|
|
|
|
fmt.Printf(" %s\n", config.NethackLauncher.ServerDisplay) |
|
|
|
|
println("") |
|
|
|
|
fmt.Printf(" Logged in as: %s\n", username) |
|
|
|
|
println("") |
|
|
|
|
println(" l) Logout") |
|
|
|
|
println(" w) Watch games in progress") |
|
|
|
|
println(" p) Play NetHack 3.4.3") |
|
|
|
|
println(" q) Quit") |
|
|
|
|
println("") |
|
|
|
|
fmt.Printf(">> ") |
|
|
|
|
|
|
|
|
|
// 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) |
|
|
|
|
switch string(b) { |
|
|
|
|
case "l": |
|
|
|
|
// restart display
|
|
|
|
|
exec.Command("stty", "-F", "/dev/tty", "echo", "-cbreak").Run() |
|
|
|
|
clearScreen() |
|
|
|
|
printWelcomeScreen(redisClient) |
|
|
|
|
case "p": |
|
|
|
|
// restart display
|
|
|
|
|
exec.Command("stty", "-F", "/dev/tty", "echo", "-cbreak").Run() |
|
|
|
|
clearScreen() |
|
|
|
|
os.Exit(0) |
|
|
|
|
case "q": |
|
|
|
|
clearScreen() |
|
|
|
|
os.Exit(0) |
|
|
|
|
default: |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func printLoginScreen(redisClient *redis.Client) { |
|
|
|
|
fmt.Printf(" %s\n", config.NethackLauncher.ServerDisplay) |
|
|
|
|
println("") |
|
|
|
@ -168,15 +208,40 @@ func printLoginScreen(redisClient *redis.Client) {
|
|
|
|
|
printWelcomeScreen(redisClient) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fmt.Printf("you entered '%s'\n", scanner.Text()) |
|
|
|
|
// check redis for user
|
|
|
|
|
usernameHash := sha3.Sum512([]byte(scanner.Text())) |
|
|
|
|
_, err := redisClient.Get(fmt.Sprintf("user:%x", usernameHash)).Result() |
|
|
|
|
if err != redis.Nil { |
|
|
|
|
// user already exists
|
|
|
|
|
username := scanner.Text() |
|
|
|
|
storedHash, err := redisClient.Get(fmt.Sprintf("user:%s", username)).Result() |
|
|
|
|
if err != nil { |
|
|
|
|
// user does not exist
|
|
|
|
|
fmt.Printf(" There was a problem with your last entry.\n>> ") |
|
|
|
|
} else { |
|
|
|
|
// get password from user and compare
|
|
|
|
|
// turn off echo display
|
|
|
|
|
exec.Command("stty", "-F", "/dev/tty", "-echo").Run() |
|
|
|
|
|
|
|
|
|
noPass := true |
|
|
|
|
for noPass { |
|
|
|
|
fmt.Printf("\n Please enter your password (blank entry aborts).\n>> ") |
|
|
|
|
reader := bufio.NewReader(os.Stdin) |
|
|
|
|
|
|
|
|
|
typedAuth, _ := reader.ReadString('\n') |
|
|
|
|
typedAuth = strings.Replace(typedAuth, "\n", "", -1) |
|
|
|
|
|
|
|
|
|
if typedAuth == "" { |
|
|
|
|
// exit to main menu
|
|
|
|
|
printWelcomeScreen(redisClient) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// get hash of typedAuth
|
|
|
|
|
typedHash := sha3.Sum512([]byte(typedAuth)) |
|
|
|
|
if fmt.Sprintf("%x", typedHash) == storedHash { |
|
|
|
|
// user authed
|
|
|
|
|
printUserScreen(redisClient, username) |
|
|
|
|
noPass = false |
|
|
|
|
} else { |
|
|
|
|
// set up user
|
|
|
|
|
fmt.Printf("\n There was a problem with your last entry.") |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
if err := scanner.Err(); err != nil { |
|
|
|
@ -190,7 +255,7 @@ func printRegisterScreen(redisClient *redis.Client) {
|
|
|
|
|
println("") |
|
|
|
|
println(" Welcome new user. Please enter a username") |
|
|
|
|
println(" Only characters and numbers are allowed, with no spaces.") |
|
|
|
|
println(" 20 characters max.") |
|
|
|
|
println(" 20 characters max. (blank entry aborts)") |
|
|
|
|
println("") |
|
|
|
|
fmt.Printf(">> ") |
|
|
|
|
|
|
|
|
@ -201,8 +266,8 @@ func printRegisterScreen(redisClient *redis.Client) {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// check redis for user
|
|
|
|
|
usernameHash := sha3.Sum512([]byte(scanner.Text())) |
|
|
|
|
_, err := redisClient.Get(fmt.Sprintf("user:%x", usernameHash)).Result() |
|
|
|
|
username := scanner.Text() |
|
|
|
|
_, err := redisClient.Get(fmt.Sprintf("user:%s", username)).Result() |
|
|
|
|
if err != redis.Nil { |
|
|
|
|
// user already exists
|
|
|
|
|
fmt.Printf("There was a problem with your last entry.\n>> ") |
|
|
|
@ -239,9 +304,8 @@ func printRegisterScreen(redisClient *redis.Client) {
|
|
|
|
|
} |
|
|
|
|
// set user in redis
|
|
|
|
|
secHash := sha3.Sum512([]byte(sec)) |
|
|
|
|
redisClient.Set(fmt.Sprintf("user:%x", usernameHash), fmt.Sprintf("%x", secHash), 0).Err() |
|
|
|
|
fmt.Println("Success") |
|
|
|
|
os.Exit(0) |
|
|
|
|
redisClient.Set(fmt.Sprintf("user:%s", username), fmt.Sprintf("%x", secHash), 0).Err() |
|
|
|
|
printUserScreen(redisClient, username) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
if err := scanner.Err(); err != nil { |
|
|
|
|