Skip to content

Commit

Permalink
some fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Iksix committed Dec 26, 2023
1 parent 9383047 commit dadda00
Showing 1 changed file with 36 additions and 12 deletions.
48 changes: 36 additions & 12 deletions NameChecker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using CounterStrikeSharp.API.Core.Attributes.Registration;
using CounterStrikeSharp.API.Core.Translations;
using CounterStrikeSharp.API.Modules.Commands;
using CounterStrikeSharp.API.Modules.Config;
using CounterStrikeSharp.API.Modules.Timers;
using Timer = CounterStrikeSharp.API.Modules.Timers.Timer;

Expand Down Expand Up @@ -49,30 +50,31 @@ public class NameChecker : BasePlugin, IPluginConfig<NameCheckerConfig>
// ================================

// ================================ SETTINGS
public int PluginMode = 2; // 0 - Default(Kick Players); 1 - Remove Nickname and set random; 2 - Replace name xxx.com from other server to aaa.com
public int PluginMode = 0; // 0 - Default(Kick Players); 1 - Remove Nickname and set random; 2 - Replace name xxx.com from other server to aaa.com
public int kickTime = 10; // Seconds
public string siteReplace = "aaa.com"; // Site replace if mode 2;
// ================================

// ================================ LISTES
private List<string> names = new List<string>();
private List<string> namesToReplace = new List<string>();
private List<Timer> _timers = new List<Timer>();
private List<Timer> _timers = new ();
private List<CCSPlayerController> playersProccesed = new List<CCSPlayerController>();
// ================================


public void OnConfigParsed(NameCheckerConfig config)
{
if (config.C_PluginMode > 2 || config.C_PluginMode < 0)
{
Console.WriteLine("[NameChecker] PluginMode must be value between [0-2] || 0 as default");
PluginMode = 0;
}
else PluginMode = config.C_PluginMode;
config = ConfigManager.Load<NameCheckerConfig>("NameChecker");
PluginMode = config.C_PluginMode;
kickTime = config.C_KickTime;
siteReplace = config.C_SiteReplace;
Console.WriteLine($"[NameChecker] config.C_PluginMode {config.C_PluginMode}");
Console.WriteLine($"[NameChecker] config.C_KickTime {config.C_KickTime}");
Console.WriteLine($"[NameChecker] config.C_SiteReplace {config.C_SiteReplace}");

Config = config;
Console.WriteLine("[NameChecker] Config Parsed");
}

public override void Load(bool hotReload)
Expand All @@ -82,7 +84,6 @@ public override void Load(bool hotReload)

public void NamesReload()
{
OnConfigParsed(Config);
names = new List<string>();
StreamReader reader = new StreamReader($"{ModuleDirectory}/names.txt");
string line;
Expand Down Expand Up @@ -118,7 +119,14 @@ public void NamesReload()
[ConsoleCommand("css_nc_reload")]
public void onReloadCommand(CCSPlayerController? controller, CommandInfo eventInfo)
{
OnConfigParsed(Config);
Console.WriteLine(Config.C_PluginMode);
NamesReload();
foreach (var timer in _timers)
{
timer.Kill();
}
_timers.Clear();
if (controller != null)
{
controller.PrintToChat("[NameChecker] Names reloaded");
Expand Down Expand Up @@ -146,11 +154,18 @@ public HookResult onRoundStart(EventRoundStart @event, GameEventInfo gameEventIn
public void checkName(CCSPlayerController controller)
{
string playerName = controller.PlayerName;

foreach (var player in playersProccesed)
{
if (controller == player)
{
return;
}
}
if (PluginMode == 0) // Kick player
{
if (names.Any(playerName.Contains))
{
playersProccesed.Add(controller);
controller.PrintToConsole("Your nickname is banned! Change it!");
controller.PrintToConsole("Banned nickname list:");
foreach (var name in names)
Expand All @@ -162,8 +177,8 @@ public void checkName(CCSPlayerController controller)
controller.PrintToChat($"{Green}[NameChecker]{Red} Your nickname is banned! Change it!");
controller.PrintToChat($"{Green}[NameChecker]{Olive} Check console to see banned nickname list!");
int timerIndex = _timers.Count;
Console.WriteLine(timerIndex);


_timers.Add(AddTimer(1, () =>
{
controller.PrintToChat($"{Green}[NameChecker]{Red} You will be kicked trough {kickTime - timeCounter} seconds!");
Expand All @@ -172,8 +187,17 @@ public void checkName(CCSPlayerController controller)
{
NativeAPI.IssueServerCommand($"kickid {controller.UserId} Your nickname is banned! Change it!");
Console.WriteLine($"[NameChecker] Player with name < {controller.PlayerName} > was kicked");
for (int i = 0; i < playersProccesed.Count; i++)
{
if (playersProccesed[i] == controller)
{
playersProccesed.RemoveAt(i);
}
}
_timers[timerIndex].Kill();
_timers.RemoveAt(timerIndex);
Console.WriteLine($"Timer count = {_timers.Count}");
}
}, TimerFlags.REPEAT));
}
Expand Down Expand Up @@ -212,4 +236,4 @@ public void checkName(CCSPlayerController controller)
_playerName.Set(newPlayerName);
}
}
}
}

0 comments on commit dadda00

Please sign in to comment.