Пример #1
0
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
// Marshal should encode the current receiver into the passed recordjar.Encoder.
func (t *Thing) Marshal(e recordjar.Encoder) {
	e.String("name", t.name)
	e.String(":data:", t.description)
}