func getNpcName(s *Session) string { name := "" for { name = s.getCleanUserInput("Desired NPC name: ") char := model.GetNpcByName(name) if name == "" { return "" } else if char != nil { s.printError("That name is unavailable") } else if err := utils.ValidateName(name); err != nil { s.printError(err.Error()) } else { break } } return name }
func newUser(conn *wrappedConnection) types.User { for { name := utils.GetUserInput(conn, "Desired username: "******"" { return nil } user := model.GetUserByName(name) password := "" if user != nil { utils.WriteLine(conn, "That name is unavailable", types.ColorModeNone) } else if err := utils.ValidateName(name); err != nil { utils.WriteLine(conn, err.Error(), types.ColorModeNone) } else { conn.WillEcho() for { pass1 := utils.GetRawUserInputSuffix(conn, "Desired password: "******"\r\n", types.ColorModeNone) if len(pass1) < 7 { utils.WriteLine(conn, "Passwords must be at least 7 letters in length", types.ColorModeNone) continue } pass2 := utils.GetRawUserInputSuffix(conn, "Confirm password: "******"\r\n", types.ColorModeNone) if pass1 != pass2 { utils.WriteLine(conn, "Passwords do not match", types.ColorModeNone) continue } password = pass1 break } conn.WontEcho() admin := model.UserCount() == 0 user = model.CreateUser(name, password, admin) return user } } }
func (self *connectionHandler) newPlayer() types.PC { // TODO: character slot limit const SizeLimit = 12 for { name := self.user.GetInput("Desired character name: ") if name == "" { return nil } char := model.GetCharacterByName(name) if char != nil { self.user.WriteLine("That name is unavailable") } else if err := utils.ValidateName(name); err != nil { self.user.WriteLine(err.Error()) } else { room := model.GetRooms()[0] // TODO: Better way to pick an initial character location return model.CreatePlayerCharacter(name, self.user.GetId(), room) } } }