diff --git a/Services/EclipseService.cs b/Services/EclipseService.cs index 23c5998..6701526 100644 --- a/Services/EclipseService.cs +++ b/Services/EclipseService.cs @@ -272,13 +272,11 @@ static IEnumerator ClientUpdateLoop() continue; } - Dictionary players = new(PlayerCache); // Shallow copy of the player cache to make sure updates to that don't interfere with loop + Dictionary players = new(OnlinePlayerCache); // Shallow copy of the player cache to make sure updates to that don't interfere with loop HashSet users = new(RegisteredUsers); foreach (PlayerInfo playerInfo in players.Values) { - if (!playerInfo.User.IsConnected) continue; - if (users.Contains(playerInfo.User.PlatformId)) { try diff --git a/Services/PlayerService.cs b/Services/PlayerService.cs index 1a2d6f4..3ebcc0a 100644 --- a/Services/PlayerService.cs +++ b/Services/PlayerService.cs @@ -26,6 +26,8 @@ public struct PlayerInfo(Entity userEntity = default, Entity charEntity = defaul static EntityQuery UserQuery; public static readonly Dictionary PlayerCache = []; + + public static readonly Dictionary OnlinePlayerCache = []; public PlayerService() { UserQuery = EntityManager.CreateEntityQuery(UserComponent); @@ -36,6 +38,7 @@ static IEnumerator PlayerUpdateLoop() while (true) { PlayerCache.Clear(); + OnlinePlayerCache.Clear(); var players = GetEntitiesEnumerable(UserQuery); players @@ -57,7 +60,15 @@ static IEnumerator PlayerUpdateLoop() .SelectMany(entry => new[] { entry.PlayerNameEntry, entry.SteamIdEntry }) .GroupBy(entry => entry.Key) .ToDictionary(group => group.Key, group => group.First().Value) - .ForEach(kvp => PlayerCache[kvp.Key] = kvp.Value); + .ForEach(kvp => + { + PlayerCache[kvp.Key] = kvp.Value; // Add to PlayerCache + + if (kvp.Value.User.IsConnected) // Add to OnlinePlayerCache if connected + { + OnlinePlayerCache[kvp.Key] = kvp.Value; + } + }); yield return Delay; }