|
|
@ -7,9 +7,11 @@ import ( |
|
|
|
"net/http" |
|
|
|
"net/http" |
|
|
|
"os" |
|
|
|
"os" |
|
|
|
"os/exec" |
|
|
|
"os/exec" |
|
|
|
|
|
|
|
"strings" |
|
|
|
"time" |
|
|
|
"time" |
|
|
|
|
|
|
|
|
|
|
|
"github.com/unixvoid/glogger" |
|
|
|
"github.com/unixvoid/glogger" |
|
|
|
|
|
|
|
"golang.org/x/crypto/sha3" |
|
|
|
"gopkg.in/gcfg.v1" |
|
|
|
"gopkg.in/gcfg.v1" |
|
|
|
"gopkg.in/redis.v5" |
|
|
|
"gopkg.in/redis.v5" |
|
|
|
) |
|
|
|
) |
|
|
@ -17,6 +19,7 @@ import ( |
|
|
|
type Config struct { |
|
|
|
type Config struct { |
|
|
|
NethackLauncher struct { |
|
|
|
NethackLauncher struct { |
|
|
|
Loglevel string |
|
|
|
Loglevel string |
|
|
|
|
|
|
|
ServerDisplay string |
|
|
|
RecordLocation string |
|
|
|
RecordLocation string |
|
|
|
ReclistLocation string |
|
|
|
ReclistLocation string |
|
|
|
BootstrapDelay time.Duration |
|
|
|
BootstrapDelay time.Duration |
|
|
@ -111,7 +114,7 @@ func clearScreen() { |
|
|
|
|
|
|
|
|
|
|
|
func printWelcomeScreen(redisClient *redis.Client) string { |
|
|
|
func printWelcomeScreen(redisClient *redis.Client) string { |
|
|
|
clearScreen() |
|
|
|
clearScreen() |
|
|
|
println("unixvoid.com underground nethack server") |
|
|
|
fmt.Printf(" %s\n", config.NethackLauncher.ServerDisplay) |
|
|
|
println("") |
|
|
|
println("") |
|
|
|
println(" Not logged in.") |
|
|
|
println(" Not logged in.") |
|
|
|
println("") |
|
|
|
println("") |
|
|
@ -133,12 +136,14 @@ func printWelcomeScreen(redisClient *redis.Client) string { |
|
|
|
switch string(b) { |
|
|
|
switch string(b) { |
|
|
|
case "l": |
|
|
|
case "l": |
|
|
|
// restart display
|
|
|
|
// restart display
|
|
|
|
exec.Command("stty", "-F", "/dev/tty", "echo").Run() |
|
|
|
exec.Command("stty", "-F", "/dev/tty", "echo", "-cbreak").Run() |
|
|
|
clearScreen() |
|
|
|
clearScreen() |
|
|
|
printLoginScreen(redisClient) |
|
|
|
printLoginScreen(redisClient) |
|
|
|
case "r": |
|
|
|
case "r": |
|
|
|
|
|
|
|
// restart display
|
|
|
|
|
|
|
|
exec.Command("stty", "-F", "/dev/tty", "echo", "-cbreak").Run() |
|
|
|
clearScreen() |
|
|
|
clearScreen() |
|
|
|
return ("r") |
|
|
|
printRegisterScreen(redisClient) |
|
|
|
case "w": |
|
|
|
case "w": |
|
|
|
clearScreen() |
|
|
|
clearScreen() |
|
|
|
return ("w") |
|
|
|
return ("w") |
|
|
@ -151,7 +156,7 @@ func printWelcomeScreen(redisClient *redis.Client) string { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func printLoginScreen(redisClient *redis.Client) { |
|
|
|
func printLoginScreen(redisClient *redis.Client) { |
|
|
|
println("unixvoid.com underground nethack server") |
|
|
|
fmt.Printf(" %s\n", config.NethackLauncher.ServerDisplay) |
|
|
|
println("") |
|
|
|
println("") |
|
|
|
println(" Please enter your username. (blank entry aborts)") |
|
|
|
println(" Please enter your username. (blank entry aborts)") |
|
|
|
println("") |
|
|
|
println("") |
|
|
@ -165,6 +170,79 @@ func printLoginScreen(redisClient *redis.Client) { |
|
|
|
|
|
|
|
|
|
|
|
fmt.Printf("you entered '%s'\n", scanner.Text()) |
|
|
|
fmt.Printf("you entered '%s'\n", scanner.Text()) |
|
|
|
// check redis for user
|
|
|
|
// 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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
// set up user
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if err := scanner.Err(); err != nil { |
|
|
|
|
|
|
|
fmt.Printf("%s\n", err) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func printRegisterScreen(redisClient *redis.Client) { |
|
|
|
|
|
|
|
// TODO : configure password restriction checking
|
|
|
|
|
|
|
|
fmt.Printf(" %s\n", config.NethackLauncher.ServerDisplay) |
|
|
|
|
|
|
|
println("") |
|
|
|
|
|
|
|
println(" Welcome new user. Please enter a username") |
|
|
|
|
|
|
|
println(" Only characters and numbers are allowed, with no spaces.") |
|
|
|
|
|
|
|
println(" 20 characters max.") |
|
|
|
|
|
|
|
println("") |
|
|
|
|
|
|
|
fmt.Printf(">> ") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
scanner := bufio.NewScanner(os.Stdin) |
|
|
|
|
|
|
|
for scanner.Scan() { |
|
|
|
|
|
|
|
if scanner.Text() == "" { |
|
|
|
|
|
|
|
printWelcomeScreen(redisClient) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 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
|
|
|
|
|
|
|
|
fmt.Printf("There was a problem with your last entry.\n>> ") |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
// set up user
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// turn off echo display
|
|
|
|
|
|
|
|
exec.Command("stty", "-F", "/dev/tty", "-echo").Run() |
|
|
|
|
|
|
|
reader := bufio.NewReader(os.Stdin) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
noPass := true |
|
|
|
|
|
|
|
sec := "" |
|
|
|
|
|
|
|
for noPass { |
|
|
|
|
|
|
|
// pull pass the first time
|
|
|
|
|
|
|
|
fmt.Printf(" Please enter your password (blank entry aborts).\n>> ") |
|
|
|
|
|
|
|
sec0, _ := reader.ReadString('\n') |
|
|
|
|
|
|
|
sec0 = strings.Replace(sec0, "\n", "", -1) |
|
|
|
|
|
|
|
if sec0 == "" { |
|
|
|
|
|
|
|
printWelcomeScreen(redisClient) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// pull pass the second time
|
|
|
|
|
|
|
|
fmt.Printf("\n Please enter your password again.\n>> ") |
|
|
|
|
|
|
|
sec1, _ := reader.ReadString('\n') |
|
|
|
|
|
|
|
sec1 = strings.Replace(sec1, "\n", "", -1) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// make sure passwords match
|
|
|
|
|
|
|
|
if sec0 == sec1 { |
|
|
|
|
|
|
|
sec = sec0 |
|
|
|
|
|
|
|
noPass = false |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
fmt.Println("Lets try that again.") |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
// 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) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
if err := scanner.Err(); err != nil { |
|
|
|
if err := scanner.Err(); err != nil { |
|
|
|
fmt.Printf("%s\n", err) |
|
|
|
fmt.Printf("%s\n", err) |
|
|
|