diff --git a/LoadBalancerProject-DONT-IMPORT-INTO-UNITY/LRM_LoadBalancer/Endpoint/Endpoint.cs b/LoadBalancerProject-DONT-IMPORT-INTO-UNITY/LRM_LoadBalancer/Endpoint/Endpoint.cs index 53cac99..4337a52 100644 --- a/LoadBalancerProject-DONT-IMPORT-INTO-UNITY/LRM_LoadBalancer/Endpoint/Endpoint.cs +++ b/LoadBalancerProject-DONT-IMPORT-INTO-UNITY/LRM_LoadBalancer/Endpoint/Endpoint.cs @@ -77,11 +77,17 @@ namespace LightReflectiveMirror.LoadBalancing ClearAllServersLists(); List requestedRooms; + Program.cachedRooms.Clear(); + for (int i = 0; i < relays.Count; i++) { requestedRooms = await Program.instance.RequestServerListFromNode(relays[i].Key.address, relays[i].Key.endpointPort); _regionRooms[LRMRegions.Any].AddRange(requestedRooms); _regionRooms[relays[i].Key.serverRegion].AddRange(requestedRooms); + + for (int x = 0; x < requestedRooms.Count; x++) + if (!Program.cachedRooms.TryAdd(requestedRooms[x].serverId, requestedRooms[x])) + Logger.ForceLogMessage("Conflicting Rooms! (That's ok)", ConsoleColor.Yellow); } CacheAllServers(); diff --git a/LoadBalancerProject-DONT-IMPORT-INTO-UNITY/LRM_LoadBalancer/Program/Program.cs b/LoadBalancerProject-DONT-IMPORT-INTO-UNITY/LRM_LoadBalancer/Program/Program.cs index a960313..1b60c3b 100644 --- a/LoadBalancerProject-DONT-IMPORT-INTO-UNITY/LRM_LoadBalancer/Program/Program.cs +++ b/LoadBalancerProject-DONT-IMPORT-INTO-UNITY/LRM_LoadBalancer/Program/Program.cs @@ -15,6 +15,7 @@ namespace LightReflectiveMirror.LoadBalancing /// Keeps track of all the LRM nodes registered to the Load Balancer. /// public Dictionary availableRelayServers = new(); + public static Dictionary cachedRooms = new(); private int _pingDelay = 10000; public static bool showDebugLogs = false; diff --git a/LoadBalancerProject-DONT-IMPORT-INTO-UNITY/LRM_LoadBalancer/Program/ProgramExtra.cs b/LoadBalancerProject-DONT-IMPORT-INTO-UNITY/LRM_LoadBalancer/Program/ProgramExtra.cs index fad6815..84c17f7 100644 --- a/LoadBalancerProject-DONT-IMPORT-INTO-UNITY/LRM_LoadBalancer/Program/ProgramExtra.cs +++ b/LoadBalancerProject-DONT-IMPORT-INTO-UNITY/LRM_LoadBalancer/Program/ProgramExtra.cs @@ -38,30 +38,9 @@ namespace LightReflectiveMirror.LoadBalancing randomID = new string(Enumerable.Repeat(chars, LENGTH) .Select(s => s[random.Next(s.Length)]).ToArray()); } - while (DoesServerIdExist(randomID)); + while (cachedRooms.ContainsKey(randomID)); return randomID; } - - /// - /// Checks if a server id already is in use. - /// - /// The ID to check for - /// - bool DoesServerIdExist(string id) - { - var infos = availableRelayServers.Values; - - foreach (var info in infos) - { - foreach (var server in info.serversConnectedToRelay) - { - if (server.serverId == id) - return true; - } - } - - return false; - } } }