From ba0ef68713b284f9c1c88f572e5a85b318ba0a63 Mon Sep 17 00:00:00 2001 From: Max <89798523+MaxWasUnavailable@users.noreply.github.com> Date: Sun, 18 Feb 2024 02:43:14 +0100 Subject: [PATCH 1/7] Add PresumedCompatible to LobbyDiffResult --- LobbyCompatibility/Enums/LobbyDiffResult.cs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/LobbyCompatibility/Enums/LobbyDiffResult.cs b/LobbyCompatibility/Enums/LobbyDiffResult.cs index 1e6266c..342988e 100644 --- a/LobbyCompatibility/Enums/LobbyDiffResult.cs +++ b/LobbyCompatibility/Enums/LobbyDiffResult.cs @@ -17,7 +17,12 @@ public enum LobbyDiffResult Incompatible, /// - /// Mod list does not exist, and lobby might be compatible. + /// Mod list is compatible, except for unknown mods. + /// + PresumedCompatible, + + /// + /// Mod list information is not available, server does not have LobbyCompatibility installed, or other unknown cause. /// Also applies to vanilla lobbies. /// Unknown From 90a8392739306b2ef64f5edba75b98ed91faab30 Mon Sep 17 00:00:00 2001 From: Max <89798523+MaxWasUnavailable@users.noreply.github.com> Date: Sun, 18 Feb 2024 02:43:50 +0100 Subject: [PATCH 2/7] Use PresumedCompatible in LobbyDiffResults & rework unknown --- LobbyCompatibility/Models/LobbyDiff.cs | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/LobbyCompatibility/Models/LobbyDiff.cs b/LobbyCompatibility/Models/LobbyDiff.cs index 1639a19..310d14f 100644 --- a/LobbyCompatibility/Models/LobbyDiff.cs +++ b/LobbyCompatibility/Models/LobbyDiff.cs @@ -8,7 +8,8 @@ namespace LobbyCompatibility.Models; /// Container for diffs between lobby and client plugins. /// /// The diffs between the lobby and client plugins. -public record LobbyDiff(List PluginDiffs) +/// Whether or not the lobby has this mod installed. +public record LobbyDiff(List PluginDiffs, bool LobbyCompatibilityPresent = true) { private LobbyDiffResult? _cachedResult; @@ -30,20 +31,18 @@ internal LobbyDiffResult GetModdedLobbyType() if (_cachedResult != null) return (LobbyDiffResult)_cachedResult; - if (PluginDiffs.Count == 0) - { - _cachedResult = LobbyDiffResult.Unknown; - return LobbyDiffResult.Unknown; - } + if (!LobbyCompatibilityPresent) + return (LobbyDiffResult)(_cachedResult = LobbyDiffResult.Unknown); + + var unknownFound = PluginDiffs.Any(pluginDiff => pluginDiff.PluginDiffResult == PluginDiffResult.Unknown); if (PluginDiffs.Any(pluginDiff => pluginDiff.PluginDiffResult != PluginDiffResult.Compatible && pluginDiff.PluginDiffResult != PluginDiffResult.Unknown)) - { - _cachedResult = LobbyDiffResult.Incompatible; - return LobbyDiffResult.Incompatible; - } + return (LobbyDiffResult)(_cachedResult = LobbyDiffResult.Incompatible); + + if (unknownFound) + return (LobbyDiffResult)(_cachedResult = LobbyDiffResult.PresumedCompatible); - _cachedResult = LobbyDiffResult.Compatible; - return LobbyDiffResult.Compatible; + return (LobbyDiffResult)(_cachedResult = LobbyDiffResult.Compatible); } } \ No newline at end of file From 28f159c590cc7c7cce5471f1f659a3cf718b421d Mon Sep 17 00:00:00 2001 From: Max <89798523+MaxWasUnavailable@users.noreply.github.com> Date: Sun, 18 Feb 2024 02:45:54 +0100 Subject: [PATCH 3/7] Apply name refactor Wasn't adhering to proper name rules --- LobbyCompatibility/Features/LobbyHelper.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/LobbyCompatibility/Features/LobbyHelper.cs b/LobbyCompatibility/Features/LobbyHelper.cs index 7cdd4b6..b263680 100644 --- a/LobbyCompatibility/Features/LobbyHelper.cs +++ b/LobbyCompatibility/Features/LobbyHelper.cs @@ -16,7 +16,7 @@ internal static class LobbyHelper public static Dictionary LatestLobbyRequestStringFilters = new(); public static LobbyDistanceFilter? LatestLobbyRequestDistanceFilter; - private static Dictionary _lobbyDiffCache { get; set; } = new(); + private static Dictionary LobbyDiffCache { get; set; } = new(); private static List? _clientPlugins; /// @@ -26,7 +26,7 @@ internal static class LobbyHelper /// The from the . public static LobbyDiff GetLobbyDiff(Lobby lobby) { - if (_lobbyDiffCache.TryGetValue(lobby.Id, out LobbyDiff cachedLobbyDiff)) + if (LobbyDiffCache.TryGetValue(lobby.Id, out LobbyDiff cachedLobbyDiff)) return cachedLobbyDiff; var lobbyPlugins = PluginHelper @@ -100,7 +100,7 @@ public static LobbyDiff GetLobbyDiff(Lobby lobby) LatestLobbyDiff = new LobbyDiff(pluginDiffs); // Add to cache to avoid making multiple unnecessary GetData() calls - _lobbyDiffCache.Add(lobby.Id, LatestLobbyDiff); + LobbyDiffCache.Add(lobby.Id, LatestLobbyDiff); return LatestLobbyDiff; } From 79bce99143a700c79486e7cc8e829302e80b50a0 Mon Sep 17 00:00:00 2001 From: Max <89798523+MaxWasUnavailable@users.noreply.github.com> Date: Sun, 18 Feb 2024 02:46:47 +0100 Subject: [PATCH 4/7] Check lobby compatibility present when creating lobbydiff --- LobbyCompatibility/Features/LobbyHelper.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/LobbyCompatibility/Features/LobbyHelper.cs b/LobbyCompatibility/Features/LobbyHelper.cs index b263680..394982f 100644 --- a/LobbyCompatibility/Features/LobbyHelper.cs +++ b/LobbyCompatibility/Features/LobbyHelper.cs @@ -96,8 +96,10 @@ public static LobbyDiff GetLobbyDiff(Lobby lobby) pluginDiffs.Add(new PluginDiff(PluginDiffResult.Compatible, clientPlugin.GUID, clientPlugin.Version, null)); } + + var lobbyCompatibilityPresent = lobbyPlugins.Any(); - LatestLobbyDiff = new LobbyDiff(pluginDiffs); + LatestLobbyDiff = new LobbyDiff(pluginDiffs, lobbyCompatibilityPresent); // Add to cache to avoid making multiple unnecessary GetData() calls LobbyDiffCache.Add(lobby.Id, LatestLobbyDiff); From d775e612d20faea6aafc62a501ab87210ffc54e7 Mon Sep 17 00:00:00 2001 From: Max <89798523+MaxWasUnavailable@users.noreply.github.com> Date: Sun, 18 Feb 2024 02:48:29 +0100 Subject: [PATCH 5/7] Minor refactor for cleanliness --- LobbyCompatibility/Features/LobbyHelper.cs | 46 +++++++++++++--------- 1 file changed, 27 insertions(+), 19 deletions(-) diff --git a/LobbyCompatibility/Features/LobbyHelper.cs b/LobbyCompatibility/Features/LobbyHelper.cs index 394982f..fa1bacb 100644 --- a/LobbyCompatibility/Features/LobbyHelper.cs +++ b/LobbyCompatibility/Features/LobbyHelper.cs @@ -12,12 +12,11 @@ namespace LobbyCompatibility.Features; /// internal static class LobbyHelper { - public static LobbyDiff LatestLobbyDiff { get; private set; } = new(new List()); public static Dictionary LatestLobbyRequestStringFilters = new(); public static LobbyDistanceFilter? LatestLobbyRequestDistanceFilter; - - private static Dictionary LobbyDiffCache { get; set; } = new(); private static List? _clientPlugins; + public static LobbyDiff LatestLobbyDiff { get; private set; } = new(new List()); + private static Dictionary LobbyDiffCache { get; } = new(); /// /// Get a from a . @@ -26,7 +25,7 @@ internal static class LobbyHelper /// The from the . public static LobbyDiff GetLobbyDiff(Lobby lobby) { - if (LobbyDiffCache.TryGetValue(lobby.Id, out LobbyDiff cachedLobbyDiff)) + if (LobbyDiffCache.TryGetValue(lobby.Id, out var cachedLobbyDiff)) return cachedLobbyDiff; var lobbyPlugins = PluginHelper @@ -96,7 +95,7 @@ public static LobbyDiff GetLobbyDiff(Lobby lobby) pluginDiffs.Add(new PluginDiff(PluginDiffResult.Compatible, clientPlugin.GUID, clientPlugin.Version, null)); } - + var lobbyCompatibilityPresent = lobbyPlugins.Any(); LatestLobbyDiff = new LobbyDiff(pluginDiffs, lobbyCompatibilityPresent); @@ -126,17 +125,16 @@ public static string GetCompatibilityHeader(PluginDiffResult pluginDiffResult) /// A custom list of lobbies, with special search filters applied. /// The to filter the lobbies against. /// A array with the applied. - public static Lobby[] FilterLobbies(Lobby[] normalLobbies, Lobby[]? filteredLobbies, ModdedLobbyFilter currentFilter) + public static Lobby[] FilterLobbies(Lobby[] normalLobbies, Lobby[]? filteredLobbies, + ModdedLobbyFilter currentFilter) { List allLobbies = new(); if (filteredLobbies != null) - { // Remove duplicate "normal" lobbies if they were also caught by the hashfilter normalLobbies = normalLobbies .Where(lobby => !filteredLobbies.Any(check => lobby.Equals(check))) .ToArray(); - } if (currentFilter == ModdedLobbyFilter.VanillaAndUnknownOnly) { @@ -148,11 +146,13 @@ public static Lobby[] FilterLobbies(Lobby[] normalLobbies, Lobby[]? filteredLobb // Add only lobbies that are vanilla/unknown allLobbies.AddRange(FilterLobbiesByDiffResult(normalLobbies, LobbyDiffResult.Unknown)); } - else if (filteredLobbies != null && (currentFilter == ModdedLobbyFilter.CompatibleFirst || currentFilter == ModdedLobbyFilter.CompatibleOnly)) + else if (filteredLobbies != null && currentFilter is ModdedLobbyFilter.CompatibleFirst or ModdedLobbyFilter.CompatibleOnly) { // Lobbies returned by the hashfilter are not 100% going to always be compatible, so we'll still need to filter them - var (compatibleFilteredLobbies, otherFilteredLobbies) = SplitLobbiesByDiffResult(filteredLobbies, LobbyDiffResult.Compatible); - var (compatibleNormalLobbies, otherNormalLobbies) = SplitLobbiesByDiffResult(normalLobbies, LobbyDiffResult.Compatible); + var (compatibleFilteredLobbies, otherFilteredLobbies) = + SplitLobbiesByDiffResult(filteredLobbies, LobbyDiffResult.Compatible); + var (compatibleNormalLobbies, otherNormalLobbies) = + SplitLobbiesByDiffResult(normalLobbies, LobbyDiffResult.Compatible); // Add filtered lobbies that are 100% compatible first, then any extra compatible lobbies not caught by the hashfilter allLobbies.AddRange(compatibleFilteredLobbies); @@ -168,7 +168,7 @@ public static Lobby[] FilterLobbies(Lobby[] normalLobbies, Lobby[]? filteredLobb else if (filteredLobbies == null && currentFilter == ModdedLobbyFilter.CompatibleOnly) { // Handle the special case where we're sorting for compatible only and nothing comes up, so we need to force return nothing - allLobbies = new(); + allLobbies = new List(); } else { @@ -180,12 +180,17 @@ public static Lobby[] FilterLobbies(Lobby[] normalLobbies, Lobby[]? filteredLobb } /// - /// Splits a IEnumerable into two arrays based on of it matches or not. + /// Splits a IEnumerable into two arrays based on of it matches or + /// not. /// /// The lobbies. /// The to match against. - /// A tuple containing two IEnumerables. matchedLobbies contains the lobbies that match the LobbyDiffResult, and unmatchedLobbies contains everything else. - private static (IEnumerable matchedLobbies, IEnumerable unmatchedLobbies) SplitLobbiesByDiffResult(IEnumerable lobbies, LobbyDiffResult filteredLobbyDiffResult) + /// + /// A tuple containing two IEnumerables. matchedLobbies contains the lobbies that match the + /// LobbyDiffResult, and unmatchedLobbies contains everything else. + /// + private static (IEnumerable matchedLobbies, IEnumerable unmatchedLobbies) SplitLobbiesByDiffResult( + IEnumerable lobbies, LobbyDiffResult filteredLobbyDiffResult) { List matchedLobbies = new(); List unmatchedLobbies = new(); @@ -208,11 +213,14 @@ private static (IEnumerable matchedLobbies, IEnumerable unmatchedL /// The lobbies. /// The to match against. /// A filtered IEnumerable. - private static IEnumerable FilterLobbiesByDiffResult(IEnumerable lobbies, LobbyDiffResult filteredLobbyDiffResult) - => SplitLobbiesByDiffResult(lobbies, filteredLobbyDiffResult).matchedLobbies; + private static IEnumerable FilterLobbiesByDiffResult(IEnumerable lobbies, + LobbyDiffResult filteredLobbyDiffResult) + { + return SplitLobbiesByDiffResult(lobbies, filteredLobbyDiffResult).matchedLobbies; + } /// - /// Gets the error message for when no lobbies are found using a . + /// Gets the error message for when no lobbies are found using a . /// /// The to get the error message for. public static string GetEmptyLobbyListString(ModdedLobbyFilter moddedLobbyFilter) @@ -224,4 +232,4 @@ public static string GetEmptyLobbyListString(ModdedLobbyFilter moddedLobbyFilter _ => "No available servers to join." }; } -} +} \ No newline at end of file From fe6f19a3544a309d374c2cf33b716b3992f82e51 Mon Sep 17 00:00:00 2001 From: Max <89798523+MaxWasUnavailable@users.noreply.github.com> Date: Sun, 18 Feb 2024 02:55:41 +0100 Subject: [PATCH 6/7] Allow LobbyCompat to join unknown/vanilla lobbies with unknown mods --- LobbyCompatibility/Features/PluginHelper.cs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/LobbyCompatibility/Features/PluginHelper.cs b/LobbyCompatibility/Features/PluginHelper.cs index 7e016c2..4bd2784 100644 --- a/LobbyCompatibility/Features/PluginHelper.cs +++ b/LobbyCompatibility/Features/PluginHelper.cs @@ -186,12 +186,15 @@ internal static bool MatchesTargetRequirements(IEnumerable tar } /// - /// Checks if client is allowed to join vanilla lobbies. + /// Checks if client is allowed to join vanilla or unknown lobbies. /// - /// True if client is allowed to join vanilla lobbies, false otherwise. + /// True if client is allowed to join vanilla or unknown lobbies, false otherwise. + /// This means the client is allowed to have unknown or clientside mods. internal static bool CanJoinVanillaLobbies() { - return GetAllPluginInfo().All(plugin => plugin.CompatibilityLevel is CompatibilityLevel.ClientOnly or null); + return GetAllPluginInfo().All(plugin => + plugin.CompatibilityLevel != CompatibilityLevel.ServerOnly && + plugin.CompatibilityLevel != CompatibilityLevel.ClientOptional); } /// From 382169c87b42ba9958a2b1f27915aa4833b9ea29 Mon Sep 17 00:00:00 2001 From: Max <89798523+MaxWasUnavailable@users.noreply.github.com> Date: Sun, 18 Feb 2024 02:59:46 +0100 Subject: [PATCH 7/7] Fix incorrect enum --- LobbyCompatibility/Features/PluginHelper.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/LobbyCompatibility/Features/PluginHelper.cs b/LobbyCompatibility/Features/PluginHelper.cs index 4bd2784..779ae97 100644 --- a/LobbyCompatibility/Features/PluginHelper.cs +++ b/LobbyCompatibility/Features/PluginHelper.cs @@ -193,7 +193,7 @@ internal static bool MatchesTargetRequirements(IEnumerable tar internal static bool CanJoinVanillaLobbies() { return GetAllPluginInfo().All(plugin => - plugin.CompatibilityLevel != CompatibilityLevel.ServerOnly && + plugin.CompatibilityLevel != CompatibilityLevel.Everyone && plugin.CompatibilityLevel != CompatibilityLevel.ClientOptional); } @@ -275,4 +275,4 @@ private static string GetRequiredPluginsChecksum() return _cachedChecksum = stringBuilder.ToString(); } -} \ No newline at end of file +}