mirror of
https://github.com/D1GQ/BetterAmongUs.git
synced 2026-10-20 01:46:19 +00:00
UseBannedPlayerAndName option
This commit is contained in:
1 parent
a81c258254
commit
133d4907b8
3 files changed
+47
-36
No files matched your search
@@ -12,6 +12,7 @@ public static class OptionsMenuBehaviourPatch
|
||||
private static ClientOptionItem BetterHost;
|
||||
private static ClientOptionItem BetterRoleAlgorithma;
|
||||
private static ClientOptionItem BetterNotifications;
|
||||
private static ClientOptionItem UseBannedPlayerAndName;
|
||||
private static ClientOptionItem LobbyPlayerInfo;
|
||||
private static ClientOptionItem DisableLobbyTheme;
|
||||
private static ClientOptionItem UnlockFPS;
|
||||
@@ -73,6 +74,11 @@ public static class OptionsMenuBehaviourPatch
|
||||
BetterNotificationManager.Notifying = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (UseBannedPlayerAndName == null || UseBannedPlayerAndName.ToggleButton == null)
|
||||
{
|
||||
UseBannedPlayerAndName = ClientOptionItem.Create("<color=#4f92ff>Use Banned Player & Name List</color>", Main.UseBannedPlayerAndName, __instance);
|
||||
}
|
||||
|
||||
if (LobbyPlayerInfo == null || LobbyPlayerInfo.ToggleButton == null)
|
||||
{
|
||||
|
||||
@@ -50,45 +50,48 @@ public static class OnPlayerJoinedPatch
|
||||
client.Character.RpcSendHostChat(HudManagerPatch.WelcomeMessage, sendToBetterUser: false);
|
||||
|
||||
// Auto ban player on ban list
|
||||
var player = Utils.PlayerFromClientId(client.Id);
|
||||
if (player != null)
|
||||
if (Main.UseBannedPlayerAndName.Value)
|
||||
{
|
||||
string banPlayerListContent = File.ReadAllText(BetterDataManager.banPlayerListFile);
|
||||
|
||||
string[] listPlayerArray = banPlayerListContent.Split(new[] { Environment.NewLine }, StringSplitOptions.None);
|
||||
|
||||
foreach (string text in listPlayerArray)
|
||||
var player = Utils.PlayerFromClientId(client.Id);
|
||||
if (player != null)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(player.Data.FriendCode) && text.Contains(player.Data.FriendCode)
|
||||
|| !string.IsNullOrEmpty(Utils.GetHashPuid(player)) && text.Contains(Utils.GetHashPuid(player)))
|
||||
string banPlayerListContent = File.ReadAllText(BetterDataManager.banPlayerListFile);
|
||||
|
||||
string[] listPlayerArray = banPlayerListContent.Split(new[] { Environment.NewLine }, StringSplitOptions.None);
|
||||
|
||||
foreach (string text in listPlayerArray)
|
||||
{
|
||||
player.Kick(true, $"{player.Data.PlayerName} has been banned due to being on the ban player list!");
|
||||
break;
|
||||
if (!string.IsNullOrEmpty(player.Data.FriendCode) && text.Contains(player.Data.FriendCode)
|
||||
|| !string.IsNullOrEmpty(Utils.GetHashPuid(player)) && text.Contains(Utils.GetHashPuid(player)))
|
||||
{
|
||||
player.Kick(true, $"{player.Data.PlayerName} has been banned due to being on the ban player list!");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Normalize and remove spaces and special characters from names
|
||||
Func<string, string> normalizeName = name => new string(name.Where(c => char.IsLetterOrDigit(c)).ToArray()).ToLower();
|
||||
|
||||
// Read all banned names into a HashSet with normalized names
|
||||
HashSet<string> bannedNames = new HashSet<string>(
|
||||
File.ReadLines(BetterDataManager.banNameListFile)
|
||||
.Select(normalizeName)
|
||||
.Where(name => !string.IsNullOrWhiteSpace(name))
|
||||
);
|
||||
|
||||
string normalizedPlayerName = normalizeName(player.Data.PlayerName);
|
||||
|
||||
// Check if any banned name is a prefix of the player's normalized name
|
||||
bool isNameBanned = bannedNames.Any(bannedName =>
|
||||
normalizedPlayerName.StartsWith(bannedName)
|
||||
);
|
||||
|
||||
if (!string.IsNullOrEmpty(normalizedPlayerName) && isNameBanned)
|
||||
{
|
||||
player.Kick(false, $"{player.Data.PlayerName} has been kicked due to their name being on the ban name list!");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Normalize and remove spaces and special characters from names
|
||||
Func<string, string> normalizeName = name => new string(name.Where(c => char.IsLetterOrDigit(c)).ToArray()).ToLower();
|
||||
|
||||
// Read all banned names into a HashSet with normalized names
|
||||
HashSet<string> bannedNames = new HashSet<string>(
|
||||
File.ReadLines(BetterDataManager.banNameListFile)
|
||||
.Select(normalizeName)
|
||||
.Where(name => !string.IsNullOrWhiteSpace(name))
|
||||
);
|
||||
|
||||
string normalizedPlayerName = normalizeName(player.Data.PlayerName);
|
||||
|
||||
// Check if any banned name is a prefix of the player's normalized name
|
||||
bool isNameBanned = bannedNames.Any(bannedName =>
|
||||
normalizedPlayerName.StartsWith(bannedName)
|
||||
);
|
||||
|
||||
if (!string.IsNullOrEmpty(normalizedPlayerName) && isNameBanned)
|
||||
{
|
||||
player.Kick(false, $"{player.Data.PlayerName} has been kicked due to their name being on the ban name list!");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}, 2.5f, "OnPlayerJoinedPatch", false);
|
||||
|
||||
@@ -27,8 +27,8 @@ public class Main : BasePlugin
|
||||
public const string HotfixNum = "0";
|
||||
public const bool IsHotFix = false;
|
||||
public const string PluginGuid = "com.d1gq.betteramongus";
|
||||
public const string PluginVersion = "1.0.2";
|
||||
public const string ReleaseDate = "08.16.2024"; // mm/dd/yyyy
|
||||
public const string PluginVersion = "1.0.3";
|
||||
public const string ReleaseDate = "08.17.2024"; // mm/dd/yyyy
|
||||
public const string Github = "https://github.com/D1GQ/BetterAmongUs-Public";
|
||||
public const string Discord = "https://discord.gg/vjYrXpzNAn";
|
||||
|
||||
@@ -161,6 +161,7 @@ public class Main : BasePlugin
|
||||
public static ConfigEntry<bool> BetterHost { get; private set; }
|
||||
public static ConfigEntry<bool> BetterRoleAlgorithma { get; private set; }
|
||||
public static ConfigEntry<bool> BetterNotifications { get; private set; }
|
||||
public static ConfigEntry<bool> UseBannedPlayerAndName { get; private set; }
|
||||
public static ConfigEntry<bool> LobbyPlayerInfo { get; private set; }
|
||||
public static ConfigEntry<bool> DisableLobbyTheme { get; private set; }
|
||||
public static ConfigEntry<bool> UnlockFPS { get; private set; }
|
||||
@@ -172,6 +173,7 @@ public class Main : BasePlugin
|
||||
BetterHost = Config.Bind("Better Options", "BetterHost", false);
|
||||
BetterRoleAlgorithma = Config.Bind("Better Options", "BetterRoleAlgorithma", true);
|
||||
BetterNotifications = Config.Bind("Better Options", "BetterNotifications", true);
|
||||
UseBannedPlayerAndName = Config.Bind("Better Options", "UseBannedPlayerAndName", true);
|
||||
LobbyPlayerInfo = Config.Bind("Better Options", "LobbyPlayerInfo", true);
|
||||
DisableLobbyTheme = Config.Bind("Better Options", "DisableLobbyTheme", true);
|
||||
UnlockFPS = Config.Bind("Better Options", "UnlockFPS", false);
|
||||
|
||||
Reference in new issue
Block a user