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

Function LoadUser

internal/users/users.go:441–476  ·  view source on GitHub ↗
(username string, skipValidation ...bool)

Source from the content-addressed store, hash-verified

439}
440
441func LoadUser(username string, skipValidation ...bool) (*UserRecord, error) {
442
443 idx := GetUserIndex()
444 userId, found := idx.FindByUsername(username)
445
446 if !found {
447 return nil, errors.New("user doesn't exist")
448 }
449
450 userFilePath := util.FilePath(string(configs.GetFilePathsConfig().DataFiles), `/`, `users`, `/`, strconv.Itoa(userId)+`.yaml`)
451
452 userFileTxt, err := util.ReadFile(userFilePath)
453 if err != nil {
454 return nil, err
455 }
456
457 loadedUser := &UserRecord{}
458 if err := yaml.Unmarshal([]byte(userFileTxt), loadedUser); err != nil {
459 mudlog.Error("LoadUser", "error", err.Error())
460 }
461
462 if len(skipValidation) == 0 || !skipValidation[0] {
463 if err := loadedUser.Character.Validate(true); err == nil {
464 SaveUser(*loadedUser)
465 }
466 }
467
468 if loadedUser.Joined.IsZero() {
469 loadedUser.Joined = time.Now()
470 }
471
472 // Set their connection time to now
473 loadedUser.connectionTime = time.Now()
474
475 return loadedUser, nil
476}
477
478// Loads all user recvords and runs against a function.
479// Stops searching if false is returned.

Callers 7

FinalizeLoginOrCreateFunction · 0.92
doBasicAuthFunction · 0.92
LoadUserByIdFunction · 0.85
searchByUserIdFunction · 0.85
SearchUsersByRoleFunction · 0.85
searchByUsernameFunction · 0.85

Calls 9

FilePathFunction · 0.92
GetFilePathsConfigFunction · 0.92
ReadFileFunction · 0.92
ErrorFunction · 0.92
GetUserIndexFunction · 0.85
SaveUserFunction · 0.85
FindByUsernameMethod · 0.80
NewMethod · 0.80
ValidateMethod · 0.65

Tested by 1