bugfix: fixed crash b/c state.json had empty UUID as key for a newly created user
This commit is contained in:
parent
8caf619c12
commit
8f87f331cc
@ -44,11 +44,13 @@ func (app *Application) SavePlayer(usr *user.User, w http.ResponseWriter, r *htt
|
||||
return
|
||||
}
|
||||
} else {
|
||||
if err := app.createUser(gm, name, authcode); err != nil {
|
||||
if newPlayerId, err := app.createUser(gm, name, authcode); err != nil {
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
fmt.Printf("%v\n", err)
|
||||
fmt.Fprintf(w, "server error")
|
||||
return
|
||||
} else {
|
||||
id = newPlayerId
|
||||
}
|
||||
}
|
||||
|
||||
@ -97,9 +99,11 @@ func (app *Application) modifyUser(id string, gm *game.Game, name, authcode stri
|
||||
return nil
|
||||
}
|
||||
|
||||
func (app *Application) createUser(gm *game.Game, name, authcode string) error {
|
||||
func (app *Application) createUser(gm *game.Game, name, authcode string) (string, error) {
|
||||
if authcode != "" {
|
||||
if _, err := app.GetUserByAuthcode(authcode); err == nil {
|
||||
return fmt.Errorf("%s authcode already in use", gm.GetId())
|
||||
return "", fmt.Errorf("%s authcode already in use", gm.GetId())
|
||||
}
|
||||
}
|
||||
|
||||
dirName := path.Join(app.config.DataDir, "users")
|
||||
@ -110,9 +114,9 @@ func (app *Application) createUser(gm *game.Game, name, authcode string) error {
|
||||
newUser.SetName(name)
|
||||
newUser.SetAuthcode(authcode)
|
||||
if err := newUser.SaveUser(); err != nil {
|
||||
return err
|
||||
return "", err
|
||||
}
|
||||
app.users[newUser.GetId()] = newUser
|
||||
gm.AddPlayer(newUser)
|
||||
return nil
|
||||
return newUser.GetId(), nil
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user