diff options
Diffstat (limited to 'internal/game/core_login_account.go')
| -rw-r--r-- | internal/game/core_login_account.go | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/internal/game/core_login_account.go b/internal/game/core_login_account.go index 186a5c3..77b72d3 100644 --- a/internal/game/core_login_account.go +++ b/internal/game/core_login_account.go @@ -340,6 +340,25 @@ func (g *Game) handleRenameAccount(sess *net.Session, input string) { return } + // Persist the new name inside the account file itself; otherwise the next + // login adopts the old name again and account lookup drifts apart from + // the filename. Roll the rename back if the file cannot be updated so the + // account never ends up in a half-renamed state. + acc, err := g.AccountStore.LoadAccount(newName) + if err != nil { + sess.WriteLine(fmt.Sprintf("Error renaming account: %v", err)) + os.Rename(newPath, oldPath) + g.showMenu(sess) + return + } + acc.Name = newName + if err := g.AccountStore.SaveAccount(acc); err != nil { + sess.WriteLine(fmt.Sprintf("Error renaming account: %v", err)) + os.Rename(newPath, oldPath) + g.showMenu(sess) + return + } + sess.Account.Name = newName sess.WriteLine(fmt.Sprintf("Account renamed to %s.", newName)) g.showMenu(sess) @@ -354,6 +373,16 @@ func (g *Game) handlePurgeAccount(sess *net.Session, input string) { return } + // Refuse to purge while any character is connected: a live session would + // keep playing (and saving) a character whose file is about to vanish. + for _, name := range sess.Account.Characters { + if g.characterOnline(name) { + sess.WriteLine(fmt.Sprintf("%s is logged in. Log all characters out before purging.", name)) + g.showMenu(sess) + return + } + } + for _, name := range sess.Account.Characters { os.Remove(g.AccountStore.CharPath(name)) } |
