コード例 #1
0
ファイル: account.go プロジェクト: iaingmackay/simplemud
func (a *account) create() {

	password, salt := player.HashPassword(a.password)

	// Setup player
	e := recordjar.Encoder{}
	e.Keyword("type", "player")
	e.Keyword("ref", "player")
	e.String("account", a.account)
	e.String("password", string(password[:]))
	e.String("salt", salt)
	e.String("name", a.name)
	e.Keyword("gender", a.gender)
	e.Time("created", time.Now())

	var err error

	// Write out player file
	if err = player.Save(e); err != nil {
		a.Respond("[RED]Oops, there was an error creating your account :(")
		log.Printf("Error creating account: %s", err)
		a.needName()
		return
	}

	// Load player from written file
	a.player, err = player.Load(a.account, a.password)
	if err != nil {
		a.Respond("[RED]Oops, there was an error setting up your account :(")
		log.Printf("Error setting up account: %s", err)
		a.needName()
		return
	}

	// Log player in
	//
	// NOTE: We could take our encoder, wrap it in a decoder and unmarshal the
	// player. However by using the normal login method we make sure any
	// additional processing is carried out.
	//
	// TODO: Should this be done earlier to 'reserve' the account name? Then we
	// wouldn't go all the way through the account creation process to possibly
	// have it fail.
	if err = a.login(); err != nil {
		a.Respond("[RED]That account is already logged in!")
		log.Printf("Error setting up account: %s", err)
		a.needName()
		return
	}

	a.newMenu()
}
コード例 #2
0
ファイル: login.go プロジェクト: iaingmackay/simplemud
// checkPassword processes the current input as the player's password. If no
// password is entered we go back to asking for the player's account. Otherwise
// we try loading the player's data file and respond accordingly. If the
// player's data file is loaded and everything is OK we switch to the menu
// driver.
func (l *login) checkPassword() {

	// If no password entered go back to asking for an account.
	if l.input == "" {
		l.needAccount()
		return
	}

	// Ignores processing if quit sent from client on timeout
	if l.input == "QUIT" {
		return
	}

	var err error
	l.player, err = player.Load(l.account, l.input)

	switch err {

	case player.BadCredentials:
		l.Respond("[RED]Account or password is incorrect. Please try again.")

	case player.BadPlayerFile:
		l.Respond("[RED]An embarrassed sounding little voice squeaks 'Sorry... there seems to be a problem restoring you. Please contact the MUD Admin staff.")

	}

	if err != nil {
		l.needAccount()
		return
	}

	if err := l.login(); err != nil {
		l.Respond("[RED]That account is already logged in!")
		l.player = nil
		l.needAccount()
		return
	}

	l.Respond("[GREEN]A loud voice booms 'You have been brought back " + l.player.Name() + "'.")
	l.next = l.newMenu()
}