diff options
Diffstat (limited to 'internal/game/core_login_char.go')
| -rw-r--r-- | internal/game/core_login_char.go | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/internal/game/core_login_char.go b/internal/game/core_login_char.go index 38499e2..9d7c211 100644 --- a/internal/game/core_login_char.go +++ b/internal/game/core_login_char.go @@ -144,6 +144,16 @@ func (g *Game) handleRenameChar(sess *net.Session, input string) { sess.Write("New name: ") } +// characterOnline reports whether the named character is currently connected +// through a live session. Menu operations that rename or delete character +// files must refuse while the character is online, otherwise the in-memory +// player later overwrites or resurrects the moved/removed file. +func (g *Game) characterOnline(name string) bool { + g.charsMu.Lock() + defer g.charsMu.Unlock() + return g.loggedInChars[name] != nil +} + func (g *Game) handleRenameCharName(sess *net.Session, input string) { newName := strings.TrimSpace(input) oldName := sess.PendingChar @@ -166,6 +176,12 @@ func (g *Game) handleRenameCharName(sess *net.Session, input string) { sess.Write("New name: ") return } + if g.characterOnline(oldName) { + sess.WriteLine("That character is logged in elsewhere. Log them out first.") + sess.PendingChar = "" + g.showMenu(sess) + return + } oldPath := g.AccountStore.CharPath(oldName) newPath := g.AccountStore.CharPath(newName) @@ -240,6 +256,13 @@ func (g *Game) handleDeleteChar(sess *net.Session, input string) { return } + if g.characterOnline(sess.PendingChar) { + sess.WriteLine("That character is logged in elsewhere. Log them out first.") + sess.PendingChar = "" + g.showMenu(sess) + return + } + charPath := g.AccountStore.CharPath(sess.PendingChar) if err := os.Remove(charPath); err != nil { sess.WriteLine(fmt.Sprintf("Error deleting: %v", err)) |
