Nethack Launcher
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

67 lines
1.6 KiB

package main
import (
"bufio"
"fmt"
"os"
"os/exec"
"strings"
"golang.org/x/crypto/sha3"
"gopkg.in/redis.v5"
)
func printLoginScreen(redisClient *redis.Client) {
fmt.Printf(" %s\n", config.NethackLauncher.ServerDisplay)
println("")
println(" Please enter your username. (blank entry aborts)")
println("")
fmt.Printf(">> ")
scanner := bufio.NewScanner(os.Stdin)
for scanner.Scan() {
if scanner.Text() == "" {
printWelcomeScreen(redisClient)
}
// check redis for user
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
createUserFiles(username)
printUserScreen(redisClient, username)
noPass = false
} else {
fmt.Printf("\n There was a problem with your last entry.")
}
}
}
}
if err := scanner.Err(); err != nil {
fmt.Printf("%s\n", err)
}
}