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

Function SearchOfflineUsers

internal/users/users.go:480–528  ·  view source on GitHub ↗

Loads all user recvords and runs against a function. Stops searching if false is returned.

(searchFunc func(u *UserRecord) bool)

Source from the content-addressed store, hash-verified

478// Loads all user recvords and runs against a function.
479// Stops searching if false is returned.
480func SearchOfflineUsers(searchFunc func(u *UserRecord) bool) {
481
482 basePath := util.FilePath(string(configs.GetFilePathsConfig().DataFiles), `/`, `users`)
483
484 filepath.Walk(basePath, func(path string, info os.FileInfo, err error) error {
485
486 if err != nil {
487 return err
488 }
489
490 if info.IsDir() {
491 return nil
492 }
493
494 if len(path) > 10 && path[len(path)-10:] == `.alts.yaml` {
495 return nil
496 }
497
498 var uRecord UserRecord
499
500 fpathLower := path[len(path)-5:] // Only need to compare the last 5 characters
501 if fpathLower == `.yaml` {
502
503 bytes, err := os.ReadFile(path)
504 if err != nil {
505 return err
506 }
507
508 err = yaml.Unmarshal(bytes, &uRecord)
509 if err != nil {
510 return err
511 }
512
513 // If this is an online user, skip it
514 userManagerMu.RLock()
515 _, isOnline := userManager.Usernames[uRecord.Username]
516 userManagerMu.RUnlock()
517 if isOnline {
518 return nil
519 }
520
521 if res := searchFunc(&uRecord); !res {
522 return errors.New(`done searching`)
523 }
524 }
525 return nil
526 })
527
528}
529
530func ValidateName(name string) error {
531

Callers 10

initFunction · 0.92
mudmailCommandMethod · 0.92
apiAdminSendMudmailMethod · 0.92
coldPopulateCacheMethod · 0.92
ModifyFunction · 0.92
findAdminUserFunction · 0.92
RebuildMethod · 0.85
GetUniqueUserIdFunction · 0.85
DoFilenameMigrationV1Function · 0.85
RebuildMethod · 0.85

Calls 4

FilePathFunction · 0.92
GetFilePathsConfigFunction · 0.92
NewMethod · 0.80
ReadFileMethod · 0.45

Tested by

no test coverage detected