From 592bbbd67d56aef8ecae7ff89c43b446e43e5d01 Mon Sep 17 00:00:00 2001 From: D1GQ Date: Sun, 9 Nov 2025 13:00:48 -0600 Subject: [PATCH] Fix friend code false flag --- Mono/PlayerInfoDisplay.cs | 42 +++++++++++++++++++++++++++++---------- 1 file changed, 32 insertions(+), 10 deletions(-) diff --git a/Mono/PlayerInfoDisplay.cs b/Mono/PlayerInfoDisplay.cs index a3d3c51..d55614a 100644 --- a/Mono/PlayerInfoDisplay.cs +++ b/Mono/PlayerInfoDisplay.cs @@ -32,7 +32,6 @@ internal class PlayerInfoDisplay : MonoBehaviour // Cached regex patterns private static readonly Regex _friendCodePattern = new(@"^[a-zA-Z0-9#]+$", RegexOptions.Compiled); - private static readonly Regex _hashtagPattern = new(@"^#[0-9]{4}$", RegexOptions.Compiled); private CachedTranslations _cachedTranslations = new(); @@ -206,25 +205,48 @@ internal class PlayerInfoDisplay : MonoBehaviour string friendCode = _player.Data.FriendCode; - bool isValidFriendCode = !string.IsNullOrEmpty(friendCode) && - _friendCodePattern.IsMatch(friendCode) && - _hashtagPattern.IsMatch(friendCode) && - !friendCode.Contains(' ') && - Regex.Replace(friendCode, @"^#[0-9]{4}$", string.Empty).Length is > 10 or < 5; - - color = isValidFriendCode ? "#ff0000" : "#00f7ff"; + // Proper friend code validation + bool isValidFriendCode = true; if (string.IsNullOrEmpty(friendCode)) { friendCode = _cachedTranslations.NoFriendCode; color = "#ff0000"; + isValidFriendCode = false; TryKick(); } - else if (!isValidFriendCode) + else { - TryKick(); + // Check if it matches the basic pattern (alphanumeric and # only) + if (!_friendCodePattern.IsMatch(friendCode) || friendCode.Contains(' ')) + { + isValidFriendCode = false; + TryKick(); + } + else + { + // Check if it ends with # followed by exactly 4 digits + var hashtagMatch = Regex.Match(friendCode, @"#\d{4}$"); + if (!hashtagMatch.Success) + { + isValidFriendCode = false; + TryKick(); + } + else + { + // The part before the # should be reasonable length + string namePart = friendCode[..^5]; + if (namePart.Length < 5 || namePart.Length > 10) + { + isValidFriendCode = false; + TryKick(); + } + } + } } + color = isValidFriendCode ? "#00f7ff" : "#ff0000"; + if (DataManager.Settings.Gameplay.StreamerMode) { friendCode = new string('*', friendCode.Length);