mirror of
https://github.com/D1GQ/BetterAmongUs.git
synced 2026-10-20 01:46:19 +00:00
ban player name list
This commit is contained in:
1 parent
abaa3b3a6f
commit
1f525bf797
2 files changed
+40
-11
No files matched your search
@@ -7,8 +7,9 @@ namespace BetterAmongUs;
|
||||
class BetterDataManager
|
||||
{
|
||||
private static string filePath = GetFilePath("BetterData");
|
||||
private static string filePathFolder = Path.Combine(Main.GetGamePathToAmongUs(), $"BetterSaveFolder");
|
||||
public static string banListFile = Path.Combine(filePathFolder, "BanList.txt");
|
||||
private static string filePathFolder = Path.Combine(Main.GetGamePathToAmongUs(), $"Better_Data");
|
||||
public static string banPlayerListFile = Path.Combine(filePathFolder, "BanPlayerList.txt");
|
||||
public static string banNameListFile = Path.Combine(filePathFolder, "BanNameList.txt");
|
||||
|
||||
public static string GetFilePath(string name)
|
||||
{
|
||||
@@ -22,9 +23,14 @@ class BetterDataManager
|
||||
Directory.CreateDirectory(filePathFolder);
|
||||
}
|
||||
|
||||
if (!File.Exists(banListFile))
|
||||
if (!File.Exists(banPlayerListFile))
|
||||
{
|
||||
File.WriteAllText(banListFile, "// Example\nFriendCode#0000\nHashPUID\n// Or\nFriendCode#0000, HashPUID");
|
||||
File.WriteAllText(banPlayerListFile, "// Example\nFriendCode#0000\nHashPUID\n// Or\nFriendCode#0000, HashPUID");
|
||||
}
|
||||
|
||||
if (!File.Exists(banNameListFile))
|
||||
{
|
||||
File.WriteAllText(banNameListFile, "// Example\nBanName1\nBanName2");
|
||||
}
|
||||
|
||||
if (!File.Exists(filePath))
|
||||
@@ -133,10 +139,10 @@ class BetterDataManager
|
||||
}
|
||||
|
||||
// Check if the file already contains the new entry
|
||||
if (!File.Exists(banListFile) || !File.ReadLines(banListFile).Any(line => line.Equals(newText)))
|
||||
if (!File.Exists(banPlayerListFile) || !File.ReadLines(banPlayerListFile).Any(line => line.Equals(newText)))
|
||||
{
|
||||
// Append the new string to the file if it's not already present
|
||||
File.AppendAllText(banListFile, Environment.NewLine + newText);
|
||||
File.AppendAllText(banPlayerListFile, Environment.NewLine + newText);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ using BetterAmongUs.Patches;
|
||||
using HarmonyLib;
|
||||
using Hazel;
|
||||
using InnerNet;
|
||||
using System.Text.RegularExpressions;
|
||||
using UnityEngine.ProBuilder;
|
||||
|
||||
namespace BetterAmongUs;
|
||||
@@ -62,21 +63,43 @@ public static class OnPlayerJoinedPatch
|
||||
var player = Utils.PlayerFromClientId(client.Id);
|
||||
if (player != null)
|
||||
{
|
||||
string banListContent = File.ReadAllText(BetterDataManager.banListFile);
|
||||
string banPlayerListContent = File.ReadAllText(BetterDataManager.banPlayerListFile);
|
||||
|
||||
string[] listArray = banListContent.Split(new[] { Environment.NewLine }, StringSplitOptions.None);
|
||||
string[] listPlayerArray = banPlayerListContent.Split(new[] { Environment.NewLine }, StringSplitOptions.None);
|
||||
|
||||
foreach (string text in listArray)
|
||||
foreach (string text in listPlayerArray)
|
||||
{
|
||||
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 list!");
|
||||
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!");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}, 2.5f, "OnPlayerJoinedPatch", false);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user