Skip to content

Commit

Permalink
Better modded lobby name regex by xilo
Browse files Browse the repository at this point in the history
  • Loading branch information
legoandmars committed Feb 20, 2024
1 parent d8eb6ac commit a2be322
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
13 changes: 13 additions & 0 deletions LobbyCompatibility/Features/LobbyHelper.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using HarmonyLib;
using LobbyCompatibility.Enums;
using LobbyCompatibility.Models;
Expand All @@ -13,6 +14,8 @@ namespace LobbyCompatibility.Features;
/// </summary>
internal static class LobbyHelper
{
public static readonly Regex ModdedLobbyIdentifierRegex = new Regex(@"(\bmod(s|ded)?\b)", RegexOptions.IgnoreCase);

public static Dictionary<string, string> LatestLobbyRequestStringFilters = new();
public static LobbyDistanceFilter? LatestLobbyRequestDistanceFilter;
private static List<PluginInfoRecord>? _clientPlugins;
Expand Down Expand Up @@ -287,4 +290,14 @@ public static string GetEmptyLobbyListString(ModdedLobbyFilter moddedLobbyFilter
_ => "No available servers to join."
};
}

/// <summary>
/// Returns true if a lobby name already contains a mod identifier, such as [MOD] or modded
/// </summary>
/// <param name="lobby"> The <see cref="Lobby" /> to check. </param>
/// <returns> True if the lobby name contains a mod idenitfier. </returns>
public static bool LobbyNameContainsModIdentifier(Lobby lobby)
{
return ModdedLobbyIdentifierRegex.IsMatch(lobby.GetData(LobbyMetadata.Name));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ private static void Postfix(Result result, ref Lobby lobby)
// Add a prefix to the lobby name to indicate that it's modded, if it doesn't already have some kind of modded mention
if (pluginInfo.Any(plugin => plugin.CompatibilityLevel is CompatibilityLevel.ServerOnly
or CompatibilityLevel.Everyone or CompatibilityLevel.ClientOptional) &&
!lobby.GetData(LobbyMetadata.Name).ToLower().Contains("modded"))
!LobbyHelper.LobbyNameContainsModIdentifier(lobby))
lobby.SetData(LobbyMetadata.Name, LobbyMetadata.ModdedLobbyPrefix + lobby.GetData(LobbyMetadata.Name));

// Check if there are any required plugins in the lobby
Expand Down

0 comments on commit a2be322

Please sign in to comment.