|
10 | 10 | using Intersect.Logging; |
11 | 11 | using Intersect.Reflection; |
12 | 12 | using Intersect.Security; |
| 13 | +using Intersect.Server.Collections.Indexing; |
| 14 | +using Intersect.Server.Collections.Sorting; |
13 | 15 | using Intersect.Server.Core; |
14 | 16 | using Intersect.Server.Database.Logging.Entities; |
15 | 17 | using Intersect.Server.Database.PlayerData.Api; |
|
19 | 21 | using Intersect.Server.General; |
20 | 22 | using Intersect.Server.Localization; |
21 | 23 | using Intersect.Server.Networking; |
22 | | -using Intersect.Server.Web.RestApi.Payloads; |
23 | 24 | using Intersect.Utilities; |
24 | 25 | using Microsoft.EntityFrameworkCore; |
25 | 26 | using Newtonsoft.Json; |
@@ -529,18 +530,33 @@ public UserSaveResult Save(PlayerContext? playerContext, bool force = false, boo |
529 | 530 | return user; |
530 | 531 | } |
531 | 532 |
|
532 | | - public static Tuple<Client, User> Fetch(Guid userId) |
| 533 | + public static bool TryFind(LookupKey lookupKey, [NotNullWhen(true)] out User? user) |
533 | 534 | { |
534 | | - var client = Globals.Clients.Find(queryClient => userId == queryClient?.User?.Id); |
535 | | - |
536 | | - return new Tuple<Client, User>(client, client?.User ?? FindById(userId)); |
| 535 | + using var playerContext = DbInterface.CreatePlayerContext(); |
| 536 | + return TryFind(lookupKey, playerContext, out user); |
537 | 537 | } |
538 | 538 |
|
539 | | - public static Tuple<Client, User> Fetch(string userName) |
| 539 | + public static bool TryFetch(LookupKey lookupKey, [NotNullWhen(true)] out User? user) => TryFetch(lookupKey, out user, out _); |
| 540 | + |
| 541 | + public static bool TryFetch(LookupKey lookupKey, [NotNullWhen(true)] out User? user, out Client? client) |
540 | 542 | { |
541 | | - var client = Globals.Clients.Find(queryClient => Entity.CompareName(userName, queryClient?.User?.Name)); |
| 543 | + if (lookupKey.IsInvalid) |
| 544 | + { |
| 545 | + user = default; |
| 546 | + client = default; |
| 547 | + return false; |
| 548 | + } |
542 | 549 |
|
543 | | - return new Tuple<Client, User>(client, client?.User ?? Find(userName)); |
| 550 | + if (lookupKey.HasId) |
| 551 | + { |
| 552 | + client = Globals.Clients.Find(queryClient => lookupKey.Id == queryClient?.User?.Id); |
| 553 | + user = client?.User ?? FindById(lookupKey.Id); |
| 554 | + return user != default; |
| 555 | + } |
| 556 | + |
| 557 | + client = Globals.Clients.Find(queryClient => Entity.CompareName(lookupKey.Name, queryClient?.User?.Name)); |
| 558 | + user = client?.User ?? Find(lookupKey.Name); |
| 559 | + return user != default; |
544 | 560 | } |
545 | 561 |
|
546 | 562 | public static bool TryLogin( |
@@ -620,28 +636,6 @@ out LoginFailureReason failureReason |
620 | 636 | } |
621 | 637 | } |
622 | 638 |
|
623 | | - public static bool TryFetch(LookupKey lookupKey, [NotNullWhen(true)] out User? user) => |
624 | | - TryFetch(lookupKey, out user, out _); |
625 | | - |
626 | | - public static bool TryFetch(LookupKey lookupKey, [NotNullWhen(true)] out User? user, out Client? client) |
627 | | - { |
628 | | - if (lookupKey is { HasName: false, HasId: false }) |
629 | | - { |
630 | | - user = default; |
631 | | - client = default; |
632 | | - return false; |
633 | | - } |
634 | | - |
635 | | - (client, user) = lookupKey.HasId ? Fetch(lookupKey.Id) : Fetch(lookupKey.Name); |
636 | | - return user != default; |
637 | | - } |
638 | | - |
639 | | - public static bool TryFind(LookupKey lookupKey, [NotNullWhen(true)] out User? user) |
640 | | - { |
641 | | - using var playerContext = DbInterface.CreatePlayerContext(); |
642 | | - return TryFind(lookupKey, playerContext, out user); |
643 | | - } |
644 | | - |
645 | 639 | public static bool TryFind(LookupKey lookupKey, PlayerContext playerContext, [NotNullWhen(true)] out User? user) |
646 | 640 | { |
647 | 641 | if (lookupKey.HasId) |
|
0 commit comments