Loads all user recvords and runs against a function. Stops searching if false is returned.
(searchFunc func(u *UserRecord) bool)
| 478 | // Loads all user recvords and runs against a function. |
| 479 | // Stops searching if false is returned. |
| 480 | func 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 | |
| 530 | func ValidateName(name string) error { |
| 531 |
no test coverage detected