MCPcopy Create free account
hub / github.com/GoMudEngine/GoMud / DeleteUser

Function DeleteUser

internal/users/users.go:701–733  ·  view source on GitHub ↗

DeleteUser permanently removes a user record, their YAML file, and all index entries. It refuses to delete a user that is currently online.

(userId int)

Source from the content-addressed store, hash-verified

699// DeleteUser permanently removes a user record, their YAML file, and all index
700// entries. It refuses to delete a user that is currently online.
701func DeleteUser(userId int) error {
702 u, err := LoadUserById(userId)
703 if err != nil {
704 return fmt.Errorf("user %d not found: %w", userId, err)
705 }
706
707 userManagerMu.Lock()
708 defer userManagerMu.Unlock()
709
710 if _, online := userManager.Users[userId]; online {
711 return fmt.Errorf("user %d is currently online and cannot be deleted", userId)
712 }
713
714 filePath := util.FilePath(string(configs.GetFilePathsConfig().DataFiles), `/`, `users`, `/`, strconv.Itoa(userId)+`.yaml`)
715 if err := os.Remove(filePath); err != nil && !os.IsNotExist(err) {
716 return fmt.Errorf("failed to remove user file: %w", err)
717 }
718
719 idx := GetUserIndex()
720 _ = idx.RemoveByUsername(u.Username)
721
722 GetCharacterIndex().Remove(u.Character.Name)
723
724 delete(userManager.Users, userId)
725 delete(userManager.Usernames, u.Username)
726 if connId, ok := userManager.UserConnections[userId]; ok {
727 delete(userManager.Connections, connId)
728 delete(userManager.LinkDeadConnections, connId)
729 }
730 delete(userManager.UserConnections, userId)
731
732 return nil
733}
734
735func Exists(name string) bool {
736

Callers

nothing calls this directly

Calls 10

FilePathFunction · 0.92
GetFilePathsConfigFunction · 0.92
LoadUserByIdFunction · 0.85
GetUserIndexFunction · 0.85
GetCharacterIndexFunction · 0.85
deleteFunction · 0.85
LockMethod · 0.80
UnlockMethod · 0.80
RemoveByUsernameMethod · 0.80
RemoveMethod · 0.45

Tested by

no test coverage detected