mirror of
https://github.com/daffyyyy/CS2-SimpleAdmin.git
synced 2026-02-18 10:43:23 +00:00
1.3.9a
**MAJOR UPDATE** - New database schema - Added `css_admins_flags` table - Added `css_unmutes` table - Added `css_unbans` table
This commit is contained in:
@@ -3,7 +3,6 @@ using CounterStrikeSharp.API.Core.Attributes;
|
|||||||
using CounterStrikeSharp.API.Modules.Commands;
|
using CounterStrikeSharp.API.Modules.Commands;
|
||||||
using CounterStrikeSharp.API.Modules.Commands.Targeting;
|
using CounterStrikeSharp.API.Modules.Commands.Targeting;
|
||||||
using CounterStrikeSharp.API.Modules.Memory.DynamicFunctions;
|
using CounterStrikeSharp.API.Modules.Memory.DynamicFunctions;
|
||||||
using Dapper;
|
|
||||||
using Discord.Webhook;
|
using Discord.Webhook;
|
||||||
using Microsoft.Extensions.Localization;
|
using Microsoft.Extensions.Localization;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
@@ -38,7 +37,7 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdmin
|
|||||||
public override string ModuleName => "CS2-SimpleAdmin";
|
public override string ModuleName => "CS2-SimpleAdmin";
|
||||||
public override string ModuleDescription => "Simple admin plugin for Counter-Strike 2 :)";
|
public override string ModuleDescription => "Simple admin plugin for Counter-Strike 2 :)";
|
||||||
public override string ModuleAuthor => "daffyy & Dliix66";
|
public override string ModuleAuthor => "daffyy & Dliix66";
|
||||||
public override string ModuleVersion => "1.3.8b";
|
public override string ModuleVersion => "1.3.9a";
|
||||||
|
|
||||||
public CS2_SimpleAdminConfig Config { get; set; } = new();
|
public CS2_SimpleAdminConfig Config { get; set; } = new();
|
||||||
|
|
||||||
@@ -54,7 +53,6 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdmin
|
|||||||
}
|
}
|
||||||
|
|
||||||
CBasePlayerController_SetPawnFunc = new(GameData.GetSignature("CBasePlayerController_SetPawn"));
|
CBasePlayerController_SetPawnFunc = new(GameData.GetSignature("CBasePlayerController_SetPawn"));
|
||||||
_logger = Logger;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void OnConfigParsed(CS2_SimpleAdminConfig config)
|
public void OnConfigParsed(CS2_SimpleAdminConfig config)
|
||||||
@@ -64,7 +62,10 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdmin
|
|||||||
throw new Exception("[CS2-SimpleAdmin] You need to setup Database credentials in config!");
|
throw new Exception("[CS2-SimpleAdmin] You need to setup Database credentials in config!");
|
||||||
}
|
}
|
||||||
|
|
||||||
MySqlConnectionStringBuilder builder = new MySqlConnectionStringBuilder
|
Instance = this;
|
||||||
|
_logger = Logger;
|
||||||
|
|
||||||
|
MySqlConnectionStringBuilder builder = new()
|
||||||
{
|
{
|
||||||
Server = config.DatabaseHost,
|
Server = config.DatabaseHost,
|
||||||
Database = config.DatabaseName,
|
Database = config.DatabaseName,
|
||||||
@@ -74,12 +75,21 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdmin
|
|||||||
Pooling = true,
|
Pooling = true,
|
||||||
MinimumPoolSize = 0,
|
MinimumPoolSize = 0,
|
||||||
MaximumPoolSize = 640,
|
MaximumPoolSize = 640,
|
||||||
ConnectionReset = false
|
|
||||||
};
|
};
|
||||||
|
|
||||||
dbConnectionString = builder.ConnectionString;
|
dbConnectionString = builder.ConnectionString;
|
||||||
_database = new(dbConnectionString);
|
_database = new(dbConnectionString);
|
||||||
|
|
||||||
|
if (!_database.CheckDatabaseConnection())
|
||||||
|
{
|
||||||
|
Logger.LogError("Unable connect to database!");
|
||||||
|
Unload(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Task.Run(() => _database.DatabaseMigration());
|
||||||
|
|
||||||
|
/*
|
||||||
Task.Run(async () =>
|
Task.Run(async () =>
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
@@ -109,6 +119,7 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdmin
|
|||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
*/
|
||||||
|
|
||||||
Config = config;
|
Config = config;
|
||||||
Helper.UpdateConfig(config);
|
Helper.UpdateConfig(config);
|
||||||
@@ -143,7 +154,7 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdmin
|
|||||||
|
|
||||||
public static void RemoveFromConcurrentBag(ConcurrentBag<int> bag, int playerSlot)
|
public static void RemoveFromConcurrentBag(ConcurrentBag<int> bag, int playerSlot)
|
||||||
{
|
{
|
||||||
List<int> tempList = new List<int>();
|
List<int> tempList = [];
|
||||||
while (!bag.IsEmpty)
|
while (!bag.IsEmpty)
|
||||||
{
|
{
|
||||||
if (bag.TryTake(out int item) && item != playerSlot)
|
if (bag.TryTake(out int item) && item != playerSlot)
|
||||||
|
|||||||
@@ -10,7 +10,7 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="CounterStrikeSharp.API" Version="1.0.202" />
|
<PackageReference Include="CounterStrikeSharp.API" Version="1.0.213" />
|
||||||
<PackageReference Include="Dapper" Version="2.1.35" />
|
<PackageReference Include="Dapper" Version="2.1.35" />
|
||||||
<PackageReference Include="Discord.Net.Webhook" Version="3.14.1" />
|
<PackageReference Include="Discord.Net.Webhook" Version="3.14.1" />
|
||||||
<PackageReference Include="MySqlConnector" Version="2.3.6" />
|
<PackageReference Include="MySqlConnector" Version="2.3.6" />
|
||||||
@@ -22,7 +22,7 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Update="Database\database_setup.sql" CopyToOutputDirectory="PreserveNewest" />
|
<None Update="Database\Migrations\*.sql" CopyToOutputDirectory="PreserveNewest" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
@@ -371,12 +371,14 @@ namespace CS2_SimpleAdmin
|
|||||||
|
|
||||||
[ConsoleCommand("css_unban")]
|
[ConsoleCommand("css_unban")]
|
||||||
[RequiresPermissions("@css/unban")]
|
[RequiresPermissions("@css/unban")]
|
||||||
[CommandHelper(minArgs: 1, usage: "<steamid or name or ip>", whoCanExecute: CommandUsage.CLIENT_AND_SERVER)]
|
[CommandHelper(minArgs: 1, usage: "<steamid or name or ip> [reason]", whoCanExecute: CommandUsage.CLIENT_AND_SERVER)]
|
||||||
public void OnUnbanCommand(CCSPlayerController? caller, CommandInfo command)
|
public void OnUnbanCommand(CCSPlayerController? caller, CommandInfo command)
|
||||||
{
|
{
|
||||||
if (_database == null) return;
|
if (_database == null) return;
|
||||||
|
|
||||||
string callerName = caller == null ? "Console" : caller.PlayerName;
|
string callerName = caller?.PlayerName ?? "Console";
|
||||||
|
string callerSteamId = caller?.SteamID.ToString() ?? "Console";
|
||||||
|
|
||||||
if (command.GetArg(1).Length <= 1)
|
if (command.GetArg(1).Length <= 1)
|
||||||
{
|
{
|
||||||
command.ReplyToCommand($"Too short pattern to search.");
|
command.ReplyToCommand($"Too short pattern to search.");
|
||||||
@@ -384,9 +386,10 @@ namespace CS2_SimpleAdmin
|
|||||||
}
|
}
|
||||||
|
|
||||||
string pattern = command.GetArg(1);
|
string pattern = command.GetArg(1);
|
||||||
|
string reason = command.GetArg(2);
|
||||||
|
|
||||||
BanManager _banManager = new(_database, Config);
|
BanManager _banManager = new(_database, Config);
|
||||||
Task.Run(async () => await _banManager.UnbanPlayer(pattern));
|
Task.Run(async () => await _banManager.UnbanPlayer(pattern, callerSteamId, reason));
|
||||||
|
|
||||||
Helper.SendDiscordLogMessage(caller, command, _discordWebhookClientLog, _localizer);
|
Helper.SendDiscordLogMessage(caller, command, _discordWebhookClientLog, _localizer);
|
||||||
Helper.LogCommand(caller, command);
|
Helper.LogCommand(caller, command);
|
||||||
|
|||||||
@@ -134,11 +134,13 @@ namespace CS2_SimpleAdmin
|
|||||||
AddAdmin(caller, steamid, name, flags, immunity, time, globalAdmin, command);
|
AddAdmin(caller, steamid, name, flags, immunity, time, globalAdmin, command);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void AddAdmin(CCSPlayerController? caller, string steamid, string name, string flags, int immunity, int time = 0, bool globalAdmin = false, CommandInfo? command = null)
|
public static void AddAdmin(CCSPlayerController? caller, string steamid, string name, string flags, int immunity, int time = 0, bool globalAdmin = false, CommandInfo? command = null)
|
||||||
{
|
{
|
||||||
if (_database == null) return;
|
if (_database == null) return;
|
||||||
AdminSQLManager _adminManager = new(_database);
|
AdminSQLManager _adminManager = new(_database);
|
||||||
_ = _adminManager.AddAdminBySteamId(steamid, name, flags, immunity, time, globalAdmin);
|
|
||||||
|
List<string> flagsList = flags.Split(',').Select(flag => flag.Trim()).ToList();
|
||||||
|
_ = _adminManager.AddAdminBySteamId(steamid, name, flagsList, immunity, time, globalAdmin);
|
||||||
|
|
||||||
if (command != null)
|
if (command != null)
|
||||||
Helper.SendDiscordLogMessage(caller, command, _discordWebhookClientLog, _localizer);
|
Helper.SendDiscordLogMessage(caller, command, _discordWebhookClientLog, _localizer);
|
||||||
|
|||||||
@@ -77,7 +77,7 @@ namespace CS2_SimpleAdmin
|
|||||||
if (TagsDetected)
|
if (TagsDetected)
|
||||||
Server.ExecuteCommand($"css_tag_mute {player!.SteamID}");
|
Server.ExecuteCommand($"css_tag_mute {player!.SteamID}");
|
||||||
|
|
||||||
playerPenaltyManager.AddPenalty(player!.Slot, PenaltyType.Gag, DateTime.Now.AddMinutes(time), time);
|
PlayerPenaltyManager.AddPenalty(player!.Slot, PenaltyType.Gag, DateTime.Now.AddMinutes(time), time);
|
||||||
if (time == 0)
|
if (time == 0)
|
||||||
{
|
{
|
||||||
if (!player!.IsBot && !player.IsHLTV)
|
if (!player!.IsBot && !player.IsHLTV)
|
||||||
@@ -230,7 +230,7 @@ namespace CS2_SimpleAdmin
|
|||||||
if (TagsDetected)
|
if (TagsDetected)
|
||||||
Server.ExecuteCommand($"css_tag_mute {player!.SteamID}");
|
Server.ExecuteCommand($"css_tag_mute {player!.SteamID}");
|
||||||
|
|
||||||
playerPenaltyManager.AddPenalty(player!.Slot, PenaltyType.Gag, DateTime.Now.AddMinutes(time), time);
|
PlayerPenaltyManager.AddPenalty(player!.Slot, PenaltyType.Gag, DateTime.Now.AddMinutes(time), time);
|
||||||
}
|
}
|
||||||
|
|
||||||
Helper.SendDiscordPenaltyMessage(caller, player, reason, time, Helper.PenaltyType.Gag, _discordWebhookClientPenalty, _localizer);
|
Helper.SendDiscordPenaltyMessage(caller, player, reason, time, Helper.PenaltyType.Gag, _discordWebhookClientPenalty, _localizer);
|
||||||
@@ -252,13 +252,16 @@ namespace CS2_SimpleAdmin
|
|||||||
|
|
||||||
[ConsoleCommand("css_ungag")]
|
[ConsoleCommand("css_ungag")]
|
||||||
[RequiresPermissions("@css/chat")]
|
[RequiresPermissions("@css/chat")]
|
||||||
[CommandHelper(minArgs: 1, usage: "<steamid or name>", whoCanExecute: CommandUsage.CLIENT_AND_SERVER)]
|
[CommandHelper(minArgs: 1, usage: "<steamid or name> [reason]", whoCanExecute: CommandUsage.CLIENT_AND_SERVER)]
|
||||||
public void OnUngagCommand(CCSPlayerController? caller, CommandInfo command)
|
public void OnUngagCommand(CCSPlayerController? caller, CommandInfo command)
|
||||||
{
|
{
|
||||||
if (_database == null) return;
|
if (_database == null) return;
|
||||||
string callerName = caller == null ? "Console" : caller.PlayerName;
|
string callerName = caller == null ? "Console" : caller.PlayerName;
|
||||||
|
string callerSteamId = caller?.SteamID.ToString() ?? "Console";
|
||||||
|
|
||||||
string foundPlayerName = string.Empty;
|
string foundPlayerName = string.Empty;
|
||||||
string foundPlayerSteamId64 = string.Empty;
|
string foundPlayerSteamId64 = string.Empty;
|
||||||
|
string reason = command.GetArg(2);
|
||||||
|
|
||||||
if (command.GetArg(1).Length <= 1)
|
if (command.GetArg(1).Length <= 1)
|
||||||
{
|
{
|
||||||
@@ -284,7 +287,7 @@ namespace CS2_SimpleAdmin
|
|||||||
CCSPlayerController? player = matches.FirstOrDefault();
|
CCSPlayerController? player = matches.FirstOrDefault();
|
||||||
if (player != null && player.IsValid)
|
if (player != null && player.IsValid)
|
||||||
{
|
{
|
||||||
playerPenaltyManager.RemovePenaltiesByType(player!.Slot, PenaltyType.Gag);
|
PlayerPenaltyManager.RemovePenaltiesByType(player!.Slot, PenaltyType.Gag);
|
||||||
|
|
||||||
if (TagsDetected)
|
if (TagsDetected)
|
||||||
Server.ExecuteCommand($"css_tag_unmute {player!.SteamID}");
|
Server.ExecuteCommand($"css_tag_unmute {player!.SteamID}");
|
||||||
@@ -303,7 +306,7 @@ namespace CS2_SimpleAdmin
|
|||||||
CCSPlayerController? player = matches.FirstOrDefault();
|
CCSPlayerController? player = matches.FirstOrDefault();
|
||||||
if (player != null && player.IsValid)
|
if (player != null && player.IsValid)
|
||||||
{
|
{
|
||||||
playerPenaltyManager.RemovePenaltiesByType(player!.Slot, PenaltyType.Gag);
|
PlayerPenaltyManager.RemovePenaltiesByType(player!.Slot, PenaltyType.Gag);
|
||||||
|
|
||||||
if (TagsDetected)
|
if (TagsDetected)
|
||||||
Server.ExecuteCommand($"css_tag_unmute {player!.SteamID.ToString()}");
|
Server.ExecuteCommand($"css_tag_unmute {player!.SteamID.ToString()}");
|
||||||
@@ -319,12 +322,12 @@ namespace CS2_SimpleAdmin
|
|||||||
|
|
||||||
if (found)
|
if (found)
|
||||||
{
|
{
|
||||||
Task.Run(async () => { await _muteManager.UnmutePlayer(foundPlayerSteamId64, 0); }); // Unmute by type 0 (gag)
|
Task.Run(async () => { await _muteManager.UnmutePlayer(foundPlayerSteamId64, callerSteamId, reason, 0); }); // Unmute by type 0 (gag)
|
||||||
command.ReplyToCommand($"Ungaged player {foundPlayerName}.");
|
command.ReplyToCommand($"Ungaged player {foundPlayerName}.");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Task.Run(async () => { await _muteManager.UnmutePlayer(pattern, 0); }); // Unmute by type 0 (gag)
|
Task.Run(async () => { await _muteManager.UnmutePlayer(pattern, callerSteamId, reason, 0); }); // Unmute by type 0 (gag)
|
||||||
command.ReplyToCommand($"Ungaged offline player with pattern {pattern}.");
|
command.ReplyToCommand($"Ungaged offline player with pattern {pattern}.");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -424,7 +427,7 @@ namespace CS2_SimpleAdmin
|
|||||||
await muteManager.MutePlayer(playerInfo, adminInfo, reason, time, 1);
|
await muteManager.MutePlayer(playerInfo, adminInfo, reason, time, 1);
|
||||||
});
|
});
|
||||||
|
|
||||||
playerPenaltyManager.AddPenalty(player!.Slot, PenaltyType.Mute, DateTime.Now.AddMinutes(time), time);
|
PlayerPenaltyManager.AddPenalty(player!.Slot, PenaltyType.Mute, DateTime.Now.AddMinutes(time), time);
|
||||||
|
|
||||||
if (time == 0)
|
if (time == 0)
|
||||||
{
|
{
|
||||||
@@ -526,7 +529,7 @@ namespace CS2_SimpleAdmin
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
playerPenaltyManager.AddPenalty(player!.Slot, PenaltyType.Mute, DateTime.Now.AddMinutes(time), time);
|
PlayerPenaltyManager.AddPenalty(player!.Slot, PenaltyType.Mute, DateTime.Now.AddMinutes(time), time);
|
||||||
|
|
||||||
if (time == 0)
|
if (time == 0)
|
||||||
{
|
{
|
||||||
@@ -594,8 +597,11 @@ namespace CS2_SimpleAdmin
|
|||||||
{
|
{
|
||||||
if (_database == null) return;
|
if (_database == null) return;
|
||||||
string callerName = caller == null ? "Console" : caller.PlayerName;
|
string callerName = caller == null ? "Console" : caller.PlayerName;
|
||||||
|
string callerSteamId = caller?.SteamID.ToString() ?? "Console";
|
||||||
|
|
||||||
string foundPlayerName = string.Empty;
|
string foundPlayerName = string.Empty;
|
||||||
string foundPlayerSteamId64 = string.Empty;
|
string foundPlayerSteamId64 = string.Empty;
|
||||||
|
string reason = command.GetArg(2);
|
||||||
|
|
||||||
if (command.GetArg(1).Length <= 1)
|
if (command.GetArg(1).Length <= 1)
|
||||||
{
|
{
|
||||||
@@ -609,7 +615,7 @@ namespace CS2_SimpleAdmin
|
|||||||
string pattern = command.GetArg(1);
|
string pattern = command.GetArg(1);
|
||||||
bool found = false;
|
bool found = false;
|
||||||
MuteManager _muteManager = new(_database);
|
MuteManager _muteManager = new(_database);
|
||||||
PlayerPenaltyManager playerPenaltyManager = new PlayerPenaltyManager();
|
PlayerPenaltyManager playerPenaltyManager = new();
|
||||||
|
|
||||||
if (Helper.IsValidSteamID64(pattern))
|
if (Helper.IsValidSteamID64(pattern))
|
||||||
{
|
{
|
||||||
@@ -619,7 +625,7 @@ namespace CS2_SimpleAdmin
|
|||||||
CCSPlayerController? player = matches.FirstOrDefault();
|
CCSPlayerController? player = matches.FirstOrDefault();
|
||||||
if (player != null && player.IsValid)
|
if (player != null && player.IsValid)
|
||||||
{
|
{
|
||||||
playerPenaltyManager.RemovePenaltiesByType(player!.Slot, PenaltyType.Mute);
|
PlayerPenaltyManager.RemovePenaltiesByType(player!.Slot, PenaltyType.Mute);
|
||||||
player.VoiceFlags = VoiceFlags.Normal;
|
player.VoiceFlags = VoiceFlags.Normal;
|
||||||
found = true;
|
found = true;
|
||||||
foundPlayerName = player.PlayerName;
|
foundPlayerName = player.PlayerName;
|
||||||
@@ -635,7 +641,7 @@ namespace CS2_SimpleAdmin
|
|||||||
CCSPlayerController? player = matches.FirstOrDefault();
|
CCSPlayerController? player = matches.FirstOrDefault();
|
||||||
if (player != null && player.IsValid)
|
if (player != null && player.IsValid)
|
||||||
{
|
{
|
||||||
playerPenaltyManager.RemovePenaltiesByType(player!.Slot, PenaltyType.Mute);
|
PlayerPenaltyManager.RemovePenaltiesByType(player!.Slot, PenaltyType.Mute);
|
||||||
player.VoiceFlags = VoiceFlags.Normal;
|
player.VoiceFlags = VoiceFlags.Normal;
|
||||||
pattern = player.SteamID.ToString();
|
pattern = player.SteamID.ToString();
|
||||||
found = true;
|
found = true;
|
||||||
@@ -647,12 +653,12 @@ namespace CS2_SimpleAdmin
|
|||||||
|
|
||||||
if (found)
|
if (found)
|
||||||
{
|
{
|
||||||
Task.Run(async () => { await _muteManager.UnmutePlayer(foundPlayerSteamId64, 1); }); // Unmute by type 1 (mute)
|
Task.Run(async () => { await _muteManager.UnmutePlayer(foundPlayerSteamId64, callerSteamId, reason, 1); }); // Unmute by type 1 (mute)
|
||||||
command.ReplyToCommand($"Unmuted player {foundPlayerName}.");
|
command.ReplyToCommand($"Unmuted player {foundPlayerName}.");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Task.Run(async () => { await _muteManager.UnmutePlayer(pattern, 1); }); // Unmute by type 1 (mute)
|
Task.Run(async () => { await _muteManager.UnmutePlayer(pattern, callerSteamId, reason, 1); }); // Unmute by type 1 (mute)
|
||||||
command.ReplyToCommand($"Unmuted offline player with pattern {pattern}.");
|
command.ReplyToCommand($"Unmuted offline player with pattern {pattern}.");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -749,7 +755,7 @@ namespace CS2_SimpleAdmin
|
|||||||
Server.ExecuteCommand($"css_tag_mute {player!.SteamID}");
|
Server.ExecuteCommand($"css_tag_mute {player!.SteamID}");
|
||||||
|
|
||||||
player!.VoiceFlags = VoiceFlags.Muted;
|
player!.VoiceFlags = VoiceFlags.Muted;
|
||||||
playerPenaltyManager.AddPenalty(player!.Slot, PenaltyType.Silence, DateTime.Now.AddMinutes(time), time);
|
PlayerPenaltyManager.AddPenalty(player!.Slot, PenaltyType.Silence, DateTime.Now.AddMinutes(time), time);
|
||||||
|
|
||||||
if (time == 0)
|
if (time == 0)
|
||||||
{
|
{
|
||||||
@@ -859,7 +865,7 @@ namespace CS2_SimpleAdmin
|
|||||||
if (TagsDetected)
|
if (TagsDetected)
|
||||||
Server.ExecuteCommand($"css_tag_mute {player!.SteamID}");
|
Server.ExecuteCommand($"css_tag_mute {player!.SteamID}");
|
||||||
|
|
||||||
playerPenaltyManager.AddPenalty(player!.Slot, PenaltyType.Silence, DateTime.Now.AddMinutes(time), time);
|
PlayerPenaltyManager.AddPenalty(player!.Slot, PenaltyType.Silence, DateTime.Now.AddMinutes(time), time);
|
||||||
|
|
||||||
if (time == 0)
|
if (time == 0)
|
||||||
{
|
{
|
||||||
@@ -921,13 +927,16 @@ namespace CS2_SimpleAdmin
|
|||||||
|
|
||||||
[ConsoleCommand("css_unsilence")]
|
[ConsoleCommand("css_unsilence")]
|
||||||
[RequiresPermissions("@css/chat")]
|
[RequiresPermissions("@css/chat")]
|
||||||
[CommandHelper(minArgs: 1, usage: "<steamid or name>", whoCanExecute: CommandUsage.CLIENT_AND_SERVER)]
|
[CommandHelper(minArgs: 1, usage: "<steamid or name> [reason]", whoCanExecute: CommandUsage.CLIENT_AND_SERVER)]
|
||||||
public void OnUnsilenceCommand(CCSPlayerController? caller, CommandInfo command)
|
public void OnUnsilenceCommand(CCSPlayerController? caller, CommandInfo command)
|
||||||
{
|
{
|
||||||
if (_database == null) return;
|
if (_database == null) return;
|
||||||
string callerName = caller == null ? "Console" : caller.PlayerName;
|
string callerName = caller == null ? "Console" : caller.PlayerName;
|
||||||
|
string callerSteamId = caller?.SteamID.ToString() ?? "Console";
|
||||||
|
|
||||||
string foundPlayerName = string.Empty;
|
string foundPlayerName = string.Empty;
|
||||||
string foundPlayerSteamId64 = string.Empty;
|
string foundPlayerSteamId64 = string.Empty;
|
||||||
|
string reason = command.GetArg(2);
|
||||||
|
|
||||||
if (command.GetArg(1).Length <= 1)
|
if (command.GetArg(1).Length <= 1)
|
||||||
{
|
{
|
||||||
@@ -941,7 +950,7 @@ namespace CS2_SimpleAdmin
|
|||||||
string pattern = command.GetArg(1);
|
string pattern = command.GetArg(1);
|
||||||
bool found = false;
|
bool found = false;
|
||||||
MuteManager _muteManager = new(_database);
|
MuteManager _muteManager = new(_database);
|
||||||
PlayerPenaltyManager playerPenaltyManager = new PlayerPenaltyManager();
|
PlayerPenaltyManager playerPenaltyManager = new();
|
||||||
|
|
||||||
if (Helper.IsValidSteamID64(pattern))
|
if (Helper.IsValidSteamID64(pattern))
|
||||||
{
|
{
|
||||||
@@ -954,7 +963,7 @@ namespace CS2_SimpleAdmin
|
|||||||
if (TagsDetected)
|
if (TagsDetected)
|
||||||
Server.ExecuteCommand($"css_tag_unmute {player!.SteamID}");
|
Server.ExecuteCommand($"css_tag_unmute {player!.SteamID}");
|
||||||
|
|
||||||
playerPenaltyManager.RemovePenaltiesByType(player!.Slot, PenaltyType.Silence);
|
PlayerPenaltyManager.RemovePenaltiesByType(player!.Slot, PenaltyType.Silence);
|
||||||
player.VoiceFlags = VoiceFlags.Normal;
|
player.VoiceFlags = VoiceFlags.Normal;
|
||||||
found = true;
|
found = true;
|
||||||
foundPlayerName = player.PlayerName;
|
foundPlayerName = player.PlayerName;
|
||||||
@@ -973,7 +982,7 @@ namespace CS2_SimpleAdmin
|
|||||||
if (TagsDetected)
|
if (TagsDetected)
|
||||||
Server.ExecuteCommand($"css_tag_unmute {player!.SteamID}");
|
Server.ExecuteCommand($"css_tag_unmute {player!.SteamID}");
|
||||||
|
|
||||||
playerPenaltyManager.RemovePenaltiesByType(player!.Slot, PenaltyType.Silence);
|
PlayerPenaltyManager.RemovePenaltiesByType(player!.Slot, PenaltyType.Silence);
|
||||||
player.VoiceFlags = VoiceFlags.Normal;
|
player.VoiceFlags = VoiceFlags.Normal;
|
||||||
pattern = player.SteamID.ToString();
|
pattern = player.SteamID.ToString();
|
||||||
found = true;
|
found = true;
|
||||||
@@ -985,13 +994,13 @@ namespace CS2_SimpleAdmin
|
|||||||
|
|
||||||
if (found)
|
if (found)
|
||||||
{
|
{
|
||||||
Task.Run(async () => { await _muteManager.UnmutePlayer(foundPlayerSteamId64, 2); }); // Unmute by type 2 (silence)
|
Task.Run(async () => { await _muteManager.UnmutePlayer(foundPlayerSteamId64, callerSteamId, reason, 2); }); // Unmute by type 2 (silence)
|
||||||
command.ReplyToCommand($"Unsilenced player {foundPlayerName}.");
|
command.ReplyToCommand($"Unsilenced player {foundPlayerName}.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Task.Run(async () => { await _muteManager.UnmutePlayer(pattern, 2); }); // Unmute by type 2 (silence)
|
Task.Run(async () => { await _muteManager.UnmutePlayer(pattern, callerSteamId, reason, 2); }); // Unmute by type 2 (silence)
|
||||||
command.ReplyToCommand($"Unsilenced offline player with pattern {pattern}.");
|
command.ReplyToCommand($"Unsilenced offline player with pattern {pattern}.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,31 +1,60 @@
|
|||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using MySqlConnector;
|
using MySqlConnector;
|
||||||
|
|
||||||
namespace CS2_SimpleAdmin
|
namespace CS2_SimpleAdmin;
|
||||||
|
|
||||||
|
public class Database(string dbConnectionString)
|
||||||
{
|
{
|
||||||
public class Database
|
private readonly string _dbConnectionString = dbConnectionString;
|
||||||
|
|
||||||
|
public MySqlConnection GetConnection()
|
||||||
{
|
{
|
||||||
private readonly string _dbConnectionString;
|
try
|
||||||
|
|
||||||
public Database(string dbConnectionString)
|
|
||||||
{
|
{
|
||||||
_dbConnectionString = dbConnectionString;
|
var connection = new MySqlConnection(_dbConnectionString);
|
||||||
|
connection.Open();
|
||||||
|
return connection;
|
||||||
}
|
}
|
||||||
|
catch (Exception ex)
|
||||||
public async Task<MySqlConnection> GetConnectionAsync()
|
|
||||||
{
|
{
|
||||||
try
|
if (CS2_SimpleAdmin._logger != null)
|
||||||
{
|
CS2_SimpleAdmin._logger.LogCritical($"Unable to connect to database: {ex.Message}");
|
||||||
var connection = new MySqlConnection(_dbConnectionString);
|
throw;
|
||||||
await connection.OpenAsync();
|
|
||||||
return connection;
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
if (CS2_SimpleAdmin._logger != null)
|
|
||||||
CS2_SimpleAdmin._logger.LogCritical($"Unable to connect to database: {ex.Message}");
|
|
||||||
throw;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
public async Task<MySqlConnection> GetConnectionAsync()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var connection = new MySqlConnection(_dbConnectionString);
|
||||||
|
await connection.OpenAsync();
|
||||||
|
return connection;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
CS2_SimpleAdmin._logger?.LogCritical($"Unable to connect to database: {ex.Message}");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void DatabaseMigration()
|
||||||
|
{
|
||||||
|
Migration migrator = new(this);
|
||||||
|
migrator.ExecuteMigrations();
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool CheckDatabaseConnection()
|
||||||
|
{
|
||||||
|
using MySqlConnection connection = GetConnection();
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return connection.Ping();
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
64
Database/Migration.cs
Normal file
64
Database/Migration.cs
Normal file
@@ -0,0 +1,64 @@
|
|||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using MySqlConnector;
|
||||||
|
|
||||||
|
namespace CS2_SimpleAdmin;
|
||||||
|
|
||||||
|
public class Migration(Database database)
|
||||||
|
{
|
||||||
|
private readonly Database _database = database;
|
||||||
|
|
||||||
|
public void ExecuteMigrations()
|
||||||
|
{
|
||||||
|
string migrationsDirectory = CS2_SimpleAdmin.Instance.ModuleDirectory + "/Database/Migrations";
|
||||||
|
|
||||||
|
var files = Directory.GetFiles(migrationsDirectory, "*.sql")
|
||||||
|
.OrderBy(f => f);
|
||||||
|
|
||||||
|
using MySqlConnection connection = _database.GetConnection();
|
||||||
|
|
||||||
|
// Create sa_migrations table if not exists
|
||||||
|
using var cmd = new MySqlCommand(@"
|
||||||
|
CREATE TABLE IF NOT EXISTS `sa_migrations` (
|
||||||
|
`id` INT PRIMARY KEY AUTO_INCREMENT,
|
||||||
|
`version` VARCHAR(255) NOT NULL
|
||||||
|
);", connection);
|
||||||
|
|
||||||
|
cmd.ExecuteNonQuery();
|
||||||
|
|
||||||
|
// Get the last applied migration version
|
||||||
|
var lastAppliedVersion = GetLastAppliedVersion(connection);
|
||||||
|
|
||||||
|
foreach (var file in files)
|
||||||
|
{
|
||||||
|
var version = Path.GetFileNameWithoutExtension(file);
|
||||||
|
|
||||||
|
// Check if the migration has already been applied
|
||||||
|
if (string.Compare(version, lastAppliedVersion, StringComparison.OrdinalIgnoreCase) > 0)
|
||||||
|
{
|
||||||
|
var sqlScript = File.ReadAllText(file);
|
||||||
|
|
||||||
|
using var cmdMigration = new MySqlCommand(sqlScript, connection);
|
||||||
|
cmdMigration.ExecuteNonQuery();
|
||||||
|
|
||||||
|
// Update the last applied migration version
|
||||||
|
UpdateLastAppliedVersion(connection, version);
|
||||||
|
|
||||||
|
CS2_SimpleAdmin._logger?.LogInformation($"Migration \"{version}\" successfully applied.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static string GetLastAppliedVersion(MySqlConnection connection)
|
||||||
|
{
|
||||||
|
using var cmd = new MySqlCommand("SELECT `version` FROM `sa_migrations` ORDER BY `id` DESC LIMIT 1;", connection);
|
||||||
|
var result = cmd.ExecuteScalar();
|
||||||
|
return result?.ToString() ?? string.Empty;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void UpdateLastAppliedVersion(MySqlConnection connection, string version)
|
||||||
|
{
|
||||||
|
using var cmd = new MySqlCommand("INSERT INTO `sa_migrations` (`version`) VALUES (@Version);", connection);
|
||||||
|
cmd.Parameters.AddWithValue("@Version", version);
|
||||||
|
cmd.ExecuteNonQuery();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
CREATE TABLE IF NOT EXISTS `sa_bans` (
|
CREATE TABLE IF NOT EXISTS `sa_bans` (
|
||||||
`id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
|
`id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
|
||||||
`player_steamid` VARCHAR(64),
|
|
||||||
`player_name` VARCHAR(128),
|
`player_name` VARCHAR(128),
|
||||||
|
`player_steamid` VARCHAR(64),
|
||||||
`player_ip` VARCHAR(128),
|
`player_ip` VARCHAR(128),
|
||||||
`admin_steamid` VARCHAR(64) NOT NULL,
|
`admin_steamid` VARCHAR(64) NOT NULL,
|
||||||
`admin_name` VARCHAR(128) NOT NULL,
|
`admin_name` VARCHAR(128) NOT NULL,
|
||||||
@@ -15,8 +15,8 @@ CREATE TABLE IF NOT EXISTS `sa_bans` (
|
|||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS `sa_mutes` (
|
CREATE TABLE IF NOT EXISTS `sa_mutes` (
|
||||||
`id` int(11) NOT NULL AUTO_INCREMENT,
|
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||||
`player_steamid` varchar(64) NOT NULL,
|
|
||||||
`player_name` varchar(128) NULL,
|
`player_name` varchar(128) NULL,
|
||||||
|
`player_steamid` varchar(64) NOT NULL,
|
||||||
`admin_steamid` varchar(64) NOT NULL,
|
`admin_steamid` varchar(64) NOT NULL,
|
||||||
`admin_name` varchar(128) NOT NULL,
|
`admin_name` varchar(128) NOT NULL,
|
||||||
`reason` varchar(255) NOT NULL,
|
`reason` varchar(255) NOT NULL,
|
||||||
@@ -31,8 +31,8 @@ CREATE TABLE IF NOT EXISTS `sa_mutes` (
|
|||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS `sa_admins` (
|
CREATE TABLE IF NOT EXISTS `sa_admins` (
|
||||||
`id` int(11) NOT NULL AUTO_INCREMENT,
|
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||||
`player_steamid` varchar(64) NOT NULL,
|
|
||||||
`player_name` varchar(128) NOT NULL,
|
`player_name` varchar(128) NOT NULL,
|
||||||
|
`player_steamid` varchar(64) NOT NULL,
|
||||||
`flags` TEXT NOT NULL,
|
`flags` TEXT NOT NULL,
|
||||||
`immunity` varchar(64) NOT NULL DEFAULT '0',
|
`immunity` varchar(64) NOT NULL DEFAULT '0',
|
||||||
`server_id` INT NULL,
|
`server_id` INT NULL,
|
||||||
@@ -43,8 +43,8 @@ CREATE TABLE IF NOT EXISTS `sa_admins` (
|
|||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS `sa_servers` (
|
CREATE TABLE IF NOT EXISTS `sa_servers` (
|
||||||
`id` int(11) NOT NULL AUTO_INCREMENT,
|
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||||
`address` varchar(64) NOT NULL,
|
|
||||||
`hostname` varchar(128) NOT NULL,
|
`hostname` varchar(128) NOT NULL,
|
||||||
|
`address` varchar(64) NOT NULL,
|
||||||
PRIMARY KEY (`id`),
|
PRIMARY KEY (`id`),
|
||||||
UNIQUE KEY `address` (`address`)
|
UNIQUE KEY `address` (`address`)
|
||||||
) ENGINE=InnoDB AUTO_INCREMENT=36 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
|
) ENGINE=InnoDB AUTO_INCREMENT=36 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
|
||||||
9
Database/Migrations/002_CreateFlagsTable.sql
Normal file
9
Database/Migrations/002_CreateFlagsTable.sql
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
CREATE TABLE IF NOT EXISTS `sa_admins_flags` (
|
||||||
|
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||||
|
`admin_id` int(11) NOT NULL,
|
||||||
|
`flag` varchar(64) NOT NULL,
|
||||||
|
PRIMARY KEY (`id`),
|
||||||
|
FOREIGN KEY (`admin_id`) REFERENCES `sa_admins` (`id`) ON DELETE CASCADE
|
||||||
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
|
||||||
|
|
||||||
|
ALTER TABLE `sa_admins` CHANGE `flags` `flags` TEXT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL;
|
||||||
4
Database/Migrations/003_ChangeColumnsPosition.sql
Normal file
4
Database/Migrations/003_ChangeColumnsPosition.sql
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
ALTER TABLE `sa_bans` CHANGE `player_name` `player_name` VARCHAR(128) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL AFTER `id`;
|
||||||
|
ALTER TABLE `sa_mutes` CHANGE `player_name` `player_name` VARCHAR(128) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL AFTER `id`;
|
||||||
|
ALTER TABLE `sa_admins` CHANGE `player_name` `player_name` VARCHAR(128) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL AFTER `id`;
|
||||||
|
ALTER TABLE `sa_servers` CHANGE `hostname` `hostname` VARCHAR(128) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL AFTER `id`;
|
||||||
30
Database/Migrations/004_MoveOldFlagsToFlagsTable.sql
Normal file
30
Database/Migrations/004_MoveOldFlagsToFlagsTable.sql
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
INSERT INTO sa_admins_flags (admin_id, flag)
|
||||||
|
WITH RECURSIVE numbers AS (
|
||||||
|
SELECT 1 AS n
|
||||||
|
UNION ALL
|
||||||
|
SELECT n + 1 FROM numbers
|
||||||
|
WHERE n < (SELECT MAX(CHAR_LENGTH(flags) - CHAR_LENGTH(REPLACE(flags, ',', '')) + 1) FROM sa_admins)
|
||||||
|
)
|
||||||
|
SELECT
|
||||||
|
min_admins.admin_id,
|
||||||
|
TRIM(SUBSTRING_INDEX(SUBSTRING_INDEX(sa_admins.flags, ',', numbers.n), ',', -1)) AS flag
|
||||||
|
FROM numbers
|
||||||
|
JOIN (
|
||||||
|
SELECT MIN(id) AS admin_id, player_steamid, server_id
|
||||||
|
FROM sa_admins
|
||||||
|
WHERE player_steamid != 'Console'
|
||||||
|
GROUP BY player_steamid, server_id
|
||||||
|
) AS min_admins ON 1=1
|
||||||
|
JOIN sa_admins ON CHAR_LENGTH(sa_admins.flags) - CHAR_LENGTH(REPLACE(sa_admins.flags, ',', '')) >= numbers.n - 1
|
||||||
|
AND min_admins.player_steamid = sa_admins.player_steamid
|
||||||
|
AND (min_admins.server_id = sa_admins.server_id OR (min_admins.server_id IS NULL AND sa_admins.server_id IS NULL))
|
||||||
|
|
||||||
|
UNION
|
||||||
|
|
||||||
|
SELECT
|
||||||
|
(SELECT MAX(id) + 1 FROM sa_admins WHERE server_id IS NULL) AS admin_id,
|
||||||
|
TRIM(SUBSTRING_INDEX(SUBSTRING_INDEX(sa_admins.flags, ',', numbers.n), ',', -1)) AS flag
|
||||||
|
FROM numbers
|
||||||
|
JOIN sa_admins ON CHAR_LENGTH(sa_admins.flags) - CHAR_LENGTH(REPLACE(sa_admins.flags, ',', '')) >= numbers.n - 1
|
||||||
|
AND sa_admins.server_id IS NULL
|
||||||
|
WHERE sa_admins.player_steamid != 'Console';
|
||||||
29
Database/Migrations/005_CreateUnbansTable.sql
Normal file
29
Database/Migrations/005_CreateUnbansTable.sql
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
CREATE TABLE IF NOT EXISTS `sa_unbans` (
|
||||||
|
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||||
|
`ban_id` int(11) NOT NULL,
|
||||||
|
`admin_id` int(11) NOT NULL DEFAULT 0,
|
||||||
|
`reason` varchar(255) NOT NULL DEFAULT 'Unknown',
|
||||||
|
`date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
PRIMARY KEY (`id`)
|
||||||
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS `sa_unmutes` (
|
||||||
|
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||||
|
`mute_id` int(11) NOT NULL,
|
||||||
|
`admin_id` int(11) NOT NULL DEFAULT 0,
|
||||||
|
`reason` varchar(255) NOT NULL DEFAULT 'Unknown',
|
||||||
|
`date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
PRIMARY KEY (`id`)
|
||||||
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
|
||||||
|
|
||||||
|
INSERT INTO `sa_admins` (`id`, `player_name`, `player_steamid`, `flags`, `immunity`, `server_id`, `ends`, `created`)
|
||||||
|
VALUES (-1, 'Console', 'Console', '', '0', NULL, NULL, '0000-00-00 00:00:00');
|
||||||
|
|
||||||
|
UPDATE `sa_admins` SET `id` = 0 WHERE `id` = -1;
|
||||||
|
|
||||||
|
ALTER TABLE `sa_bans` ADD `unban_id` INT NULL AFTER `server_id`;
|
||||||
|
ALTER TABLE `sa_mutes` ADD `unmute_id` INT NULL AFTER `server_id`;
|
||||||
|
ALTER TABLE `sa_bans` ADD FOREIGN KEY (`unban_id`) REFERENCES `sa_unbans`(`id`) ON DELETE CASCADE;
|
||||||
|
ALTER TABLE `sa_mutes` ADD FOREIGN KEY (`unmute_id`) REFERENCES `sa_unmutes`(`id`) ON DELETE CASCADE;
|
||||||
|
ALTER TABLE `sa_unbans` ADD FOREIGN KEY (`admin_id`) REFERENCES `sa_admins`(`id`) ON DELETE CASCADE;
|
||||||
|
ALTER TABLE `sa_unmutes` ADD FOREIGN KEY (`admin_id`) REFERENCES `sa_admins`(`id`) ON DELETE CASCADE;
|
||||||
33
Events.cs
33
Events.cs
@@ -51,7 +51,7 @@ public partial class CS2_SimpleAdmin
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
PlayerPenaltyManager playerPenaltyManager = new PlayerPenaltyManager();
|
PlayerPenaltyManager playerPenaltyManager = new PlayerPenaltyManager();
|
||||||
playerPenaltyManager.RemoveAllPenalties(player.Slot);
|
PlayerPenaltyManager.RemoveAllPenalties(player.Slot);
|
||||||
|
|
||||||
if (TagsDetected)
|
if (TagsDetected)
|
||||||
{
|
{
|
||||||
@@ -167,7 +167,7 @@ public partial class CS2_SimpleAdmin
|
|||||||
// Apply mute penalty based on mute type
|
// Apply mute penalty based on mute type
|
||||||
if (muteType == "GAG")
|
if (muteType == "GAG")
|
||||||
{
|
{
|
||||||
playerPenaltyManager.AddPenalty(playerInfo.Slot, PenaltyType.Gag, ends, duration);
|
PlayerPenaltyManager.AddPenalty(playerInfo.Slot, PenaltyType.Gag, ends, duration);
|
||||||
Server.NextFrame(() =>
|
Server.NextFrame(() =>
|
||||||
{
|
{
|
||||||
if (TagsDetected)
|
if (TagsDetected)
|
||||||
@@ -178,7 +178,7 @@ public partial class CS2_SimpleAdmin
|
|||||||
}
|
}
|
||||||
else if (muteType == "MUTE")
|
else if (muteType == "MUTE")
|
||||||
{
|
{
|
||||||
playerPenaltyManager.AddPenalty(playerInfo.Slot, PenaltyType.Mute, ends, duration);
|
PlayerPenaltyManager.AddPenalty(playerInfo.Slot, PenaltyType.Mute, ends, duration);
|
||||||
Server.NextFrame(() =>
|
Server.NextFrame(() =>
|
||||||
{
|
{
|
||||||
player.VoiceFlags = VoiceFlags.Muted;
|
player.VoiceFlags = VoiceFlags.Muted;
|
||||||
@@ -186,7 +186,7 @@ public partial class CS2_SimpleAdmin
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
playerPenaltyManager.AddPenalty(playerInfo.Slot, PenaltyType.Silence, ends, duration);
|
PlayerPenaltyManager.AddPenalty(playerInfo.Slot, PenaltyType.Silence, ends, duration);
|
||||||
Server.NextFrame(() =>
|
Server.NextFrame(() =>
|
||||||
{
|
{
|
||||||
player.VoiceFlags = VoiceFlags.Muted;
|
player.VoiceFlags = VoiceFlags.Muted;
|
||||||
@@ -234,7 +234,7 @@ public partial class CS2_SimpleAdmin
|
|||||||
|
|
||||||
PlayerPenaltyManager playerPenaltyManager = new PlayerPenaltyManager();
|
PlayerPenaltyManager playerPenaltyManager = new PlayerPenaltyManager();
|
||||||
|
|
||||||
if (playerPenaltyManager.IsPenalized(player.Slot, PenaltyType.Gag) || playerPenaltyManager.IsPenalized(player.Slot, PenaltyType.Silence))
|
if (PlayerPenaltyManager.IsPenalized(player.Slot, PenaltyType.Gag) || PlayerPenaltyManager.IsPenalized(player.Slot, PenaltyType.Silence))
|
||||||
return HookResult.Handled;
|
return HookResult.Handled;
|
||||||
|
|
||||||
return HookResult.Continue;
|
return HookResult.Continue;
|
||||||
@@ -251,7 +251,7 @@ public partial class CS2_SimpleAdmin
|
|||||||
|
|
||||||
PlayerPenaltyManager playerPenaltyManager = new PlayerPenaltyManager();
|
PlayerPenaltyManager playerPenaltyManager = new PlayerPenaltyManager();
|
||||||
|
|
||||||
if (playerPenaltyManager.IsPenalized(player.Slot, PenaltyType.Gag) || playerPenaltyManager.IsPenalized(player.Slot, PenaltyType.Silence))
|
if (PlayerPenaltyManager.IsPenalized(player.Slot, PenaltyType.Gag) || PlayerPenaltyManager.IsPenalized(player.Slot, PenaltyType.Silence))
|
||||||
return HookResult.Handled;
|
return HookResult.Handled;
|
||||||
|
|
||||||
if (info.GetArg(1).StartsWith("@"))
|
if (info.GetArg(1).StartsWith("@"))
|
||||||
@@ -294,7 +294,7 @@ public partial class CS2_SimpleAdmin
|
|||||||
silentPlayers.Clear();
|
silentPlayers.Clear();
|
||||||
|
|
||||||
PlayerPenaltyManager playerPenaltyManager = new PlayerPenaltyManager();
|
PlayerPenaltyManager playerPenaltyManager = new PlayerPenaltyManager();
|
||||||
playerPenaltyManager.RemoveAllPenalties();
|
PlayerPenaltyManager.RemoveAllPenalties();
|
||||||
|
|
||||||
_database = new(dbConnectionString);
|
_database = new(dbConnectionString);
|
||||||
|
|
||||||
@@ -317,6 +317,7 @@ public partial class CS2_SimpleAdmin
|
|||||||
AdminSQLManager _adminManager = new(_database);
|
AdminSQLManager _adminManager = new(_database);
|
||||||
BanManager _banManager = new(_database, Config);
|
BanManager _banManager = new(_database, Config);
|
||||||
MuteManager _muteManager = new(_database);
|
MuteManager _muteManager = new(_database);
|
||||||
|
|
||||||
await _banManager.ExpireOldBans();
|
await _banManager.ExpireOldBans();
|
||||||
await _muteManager.ExpireOldMutes();
|
await _muteManager.ExpireOldMutes();
|
||||||
await _adminManager.DeleteOldAdmins();
|
await _adminManager.DeleteOldAdmins();
|
||||||
@@ -335,21 +336,21 @@ public partial class CS2_SimpleAdmin
|
|||||||
{
|
{
|
||||||
foreach (CCSPlayerController player in players)
|
foreach (CCSPlayerController player in players)
|
||||||
{
|
{
|
||||||
if (playerPenaltyManager.IsSlotInPenalties(player.Slot))
|
if (PlayerPenaltyManager.IsSlotInPenalties(player.Slot))
|
||||||
{
|
{
|
||||||
if (!playerPenaltyManager.IsPenalized(player.Slot, PenaltyType.Mute) && !playerPenaltyManager.IsPenalized(player.Slot, PenaltyType.Silence))
|
if (!PlayerPenaltyManager.IsPenalized(player.Slot, PenaltyType.Mute) && !PlayerPenaltyManager.IsPenalized(player.Slot, PenaltyType.Silence))
|
||||||
player.VoiceFlags = VoiceFlags.Normal;
|
player.VoiceFlags = VoiceFlags.Normal;
|
||||||
|
|
||||||
if (!playerPenaltyManager.IsPenalized(player.Slot, PenaltyType.Gag) && !playerPenaltyManager.IsPenalized(player.Slot, PenaltyType.Silence))
|
if (!PlayerPenaltyManager.IsPenalized(player.Slot, PenaltyType.Gag) && !PlayerPenaltyManager.IsPenalized(player.Slot, PenaltyType.Silence))
|
||||||
{
|
{
|
||||||
if (TagsDetected)
|
if (TagsDetected)
|
||||||
Server.ExecuteCommand($"css_tag_unmute {player!.SteamID}");
|
Server.ExecuteCommand($"css_tag_unmute {player!.SteamID}");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (
|
if (
|
||||||
!playerPenaltyManager.IsPenalized(player.Slot, PenaltyType.Silence) &&
|
!PlayerPenaltyManager.IsPenalized(player.Slot, PenaltyType.Silence) &&
|
||||||
!playerPenaltyManager.IsPenalized(player.Slot, PenaltyType.Mute) &&
|
!PlayerPenaltyManager.IsPenalized(player.Slot, PenaltyType.Mute) &&
|
||||||
!playerPenaltyManager.IsPenalized(player.Slot, PenaltyType.Gag)
|
!PlayerPenaltyManager.IsPenalized(player.Slot, PenaltyType.Gag)
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
player.VoiceFlags = VoiceFlags.Normal;
|
player.VoiceFlags = VoiceFlags.Normal;
|
||||||
@@ -360,14 +361,14 @@ public partial class CS2_SimpleAdmin
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
playerPenaltyManager.RemoveExpiredPenalties();
|
PlayerPenaltyManager.RemoveExpiredPenalties();
|
||||||
}
|
}
|
||||||
catch (Exception) { }
|
catch (Exception) { }
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}, CounterStrikeSharp.API.Modules.Timers.TimerFlags.REPEAT | CounterStrikeSharp.API.Modules.Timers.TimerFlags.STOP_ON_MAPCHANGE);
|
}, CounterStrikeSharp.API.Modules.Timers.TimerFlags.REPEAT | CounterStrikeSharp.API.Modules.Timers.TimerFlags.STOP_ON_MAPCHANGE);
|
||||||
|
|
||||||
AddTimer(2.5f, () =>
|
AddTimer(2.0f, () =>
|
||||||
{
|
{
|
||||||
string? address = $"{ConVar.Find("ip")!.StringValue}:{ConVar.Find("hostport")!.GetPrimitiveValue<int>()}";
|
string? address = $"{ConVar.Find("ip")!.StringValue}:{ConVar.Find("hostport")!.GetPrimitiveValue<int>()}";
|
||||||
string? hostname = ConVar.Find("hostname")!.StringValue;
|
string? hostname = ConVar.Find("hostname")!.StringValue;
|
||||||
@@ -391,7 +392,7 @@ public partial class CS2_SimpleAdmin
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
await connection.ExecuteAsync(
|
await connection.ExecuteAsync(
|
||||||
"UPDATE `sa_servers` SET hostname = @hostname WHERE address = @address",
|
"UPDATE `sa_servers` SET `hostname` = @hostname, `id` = `id` WHERE `address` = @address",
|
||||||
new { address, hostname });
|
new { address, hostname });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,21 +6,15 @@ using System.Collections.Concurrent;
|
|||||||
|
|
||||||
namespace CS2_SimpleAdmin;
|
namespace CS2_SimpleAdmin;
|
||||||
|
|
||||||
public class AdminSQLManager
|
public class AdminSQLManager(Database database)
|
||||||
{
|
{
|
||||||
private readonly Database _database;
|
private readonly Database _database = database;
|
||||||
|
|
||||||
// Unused for now
|
// Unused for now
|
||||||
//public static readonly ConcurrentDictionary<string, ConcurrentBag<string>> _adminCache = new ConcurrentDictionary<string, ConcurrentBag<string>>();
|
//public static readonly ConcurrentDictionary<string, ConcurrentBag<string>> _adminCache = new ConcurrentDictionary<string, ConcurrentBag<string>>();
|
||||||
public static readonly ConcurrentDictionary<SteamID, DateTime?> _adminCache = new();
|
public static readonly ConcurrentDictionary<SteamID, DateTime?> _adminCache = new();
|
||||||
|
|
||||||
//public static readonly ConcurrentDictionary<SteamID, DateTime?> _adminCacheTimestamps = new ConcurrentDictionary<SteamID, DateTime?>();
|
/*
|
||||||
|
|
||||||
public AdminSQLManager(Database database)
|
|
||||||
{
|
|
||||||
_database = database;
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task<List<(List<string>, int)>> GetAdminFlags(string steamId)
|
public async Task<List<(List<string>, int)>> GetAdminFlags(string steamId)
|
||||||
{
|
{
|
||||||
DateTime now = DateTime.UtcNow.ToLocalTime();
|
DateTime now = DateTime.UtcNow.ToLocalTime();
|
||||||
@@ -35,7 +29,7 @@ public class AdminSQLManager
|
|||||||
return new List<(List<string>, int)>();
|
return new List<(List<string>, int)>();
|
||||||
}
|
}
|
||||||
|
|
||||||
List<(List<string>, int)> filteredFlagsWithImmunity = new List<(List<string>, int)>();
|
List<(List<string>, int)> filteredFlagsWithImmunity = [];
|
||||||
|
|
||||||
foreach (dynamic flags in activeFlags)
|
foreach (dynamic flags in activeFlags)
|
||||||
{
|
{
|
||||||
@@ -61,6 +55,7 @@ public class AdminSQLManager
|
|||||||
|
|
||||||
return filteredFlagsWithImmunity;
|
return filteredFlagsWithImmunity;
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
public async Task<List<(string, List<string>, int, DateTime?)>> GetAllPlayersFlags()
|
public async Task<List<(string, List<string>, int, DateTime?)>> GetAllPlayersFlags()
|
||||||
{
|
{
|
||||||
@@ -70,61 +65,74 @@ public class AdminSQLManager
|
|||||||
{
|
{
|
||||||
await using MySqlConnection connection = await _database.GetConnectionAsync();
|
await using MySqlConnection connection = await _database.GetConnectionAsync();
|
||||||
|
|
||||||
string sql = "SELECT player_steamid, flags, immunity, ends FROM sa_admins WHERE (ends IS NULL OR ends > @CurrentTime) AND (server_id IS NULL OR server_id = @serverid)";
|
string sql = @"
|
||||||
|
SELECT sa_admins.player_steamid, sa_admins_flags.flag, sa_admins.immunity, sa_admins.ends
|
||||||
|
FROM sa_admins_flags
|
||||||
|
JOIN sa_admins ON sa_admins_flags.admin_id = sa_admins.id
|
||||||
|
WHERE (sa_admins.ends IS NULL OR sa_admins.ends > @CurrentTime)
|
||||||
|
AND (sa_admins.server_id IS NULL OR sa_admins.server_id = @serverid)
|
||||||
|
ORDER BY sa_admins.player_steamid";
|
||||||
|
|
||||||
List<dynamic>? activeFlags = (await connection.QueryAsync(sql, new { CurrentTime = now, serverid = CS2_SimpleAdmin.ServerId }))?.ToList();
|
List<dynamic>? activeFlags = (await connection.QueryAsync(sql, new { CurrentTime = now, serverid = CS2_SimpleAdmin.ServerId }))?.ToList();
|
||||||
|
|
||||||
if (activeFlags == null)
|
if (activeFlags == null)
|
||||||
{
|
{
|
||||||
return new List<(string, List<string>, int, DateTime?)>();
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
List<(string, List<string>, int, DateTime?)> filteredFlagsWithImmunity = new List<(string, List<string>, int, DateTime?)>();
|
List<(string, List<string>, int, DateTime?)> filteredFlagsWithImmunity = [];
|
||||||
|
string currentSteamId = string.Empty;
|
||||||
|
List<string> currentFlags = [];
|
||||||
|
int immunityValue = 0;
|
||||||
|
DateTime? ends = null;
|
||||||
|
|
||||||
foreach (dynamic flags in activeFlags)
|
foreach (dynamic flagInfo in activeFlags)
|
||||||
{
|
{
|
||||||
if (flags is not IDictionary<string, object> flagsDict)
|
if (flagInfo is not IDictionary<string, object> flagInfoDict)
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!flagsDict.TryGetValue("player_steamid", out var steamIdObj) ||
|
if (!flagInfoDict.TryGetValue("player_steamid", out var steamIdObj) ||
|
||||||
!flagsDict.TryGetValue("flags", out var flagsValueObj) ||
|
!flagInfoDict.TryGetValue("flag", out var flagObj) ||
|
||||||
!flagsDict.TryGetValue("immunity", out var immunityValueObj) ||
|
!flagInfoDict.TryGetValue("immunity", out var immunityValueObj) ||
|
||||||
!flagsDict.TryGetValue("ends", out var endsObj))
|
!flagInfoDict.TryGetValue("ends", out var endsObj))
|
||||||
{
|
{
|
||||||
//Console.WriteLine("One or more required keys are missing.");
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
DateTime? ends = null;
|
if (steamIdObj is not string steamId ||
|
||||||
|
flagObj is not string flag ||
|
||||||
if (endsObj != null) // Check if "ends" is not null
|
!int.TryParse(immunityValueObj.ToString(), out immunityValue))
|
||||||
{
|
{
|
||||||
if (!DateTime.TryParse(endsObj.ToString(), out var parsedEnds))
|
continue;
|
||||||
{
|
}
|
||||||
//Console.WriteLine("Failed to parse 'ends' value.");
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
if (endsObj != null && DateTime.TryParse(endsObj.ToString(), out var parsedEnds))
|
||||||
|
{
|
||||||
ends = parsedEnds;
|
ends = parsedEnds;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(steamIdObj is string steamId) ||
|
if (currentSteamId != steamId && !string.IsNullOrEmpty(currentSteamId))
|
||||||
!(flagsValueObj is string flagsValue) ||
|
|
||||||
!int.TryParse(immunityValueObj.ToString(), out var immunityValue))
|
|
||||||
{
|
{
|
||||||
//Console.WriteLine("Failed to parse one or more values.");
|
filteredFlagsWithImmunity.Add((currentSteamId, currentFlags, immunityValue, ends));
|
||||||
continue;
|
currentFlags = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
filteredFlagsWithImmunity.Add((steamId, flagsValue.Split(',').ToList(), immunityValue, ends));
|
currentSteamId = steamId;
|
||||||
|
currentFlags.Add(flag);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!string.IsNullOrEmpty(currentSteamId))
|
||||||
|
{
|
||||||
|
filteredFlagsWithImmunity.Add((currentSteamId, currentFlags, immunityValue, ends));
|
||||||
}
|
}
|
||||||
|
|
||||||
return filteredFlagsWithImmunity;
|
return filteredFlagsWithImmunity;
|
||||||
}
|
}
|
||||||
catch (Exception)
|
catch (Exception)
|
||||||
{
|
{
|
||||||
return new List<(string, List<string>, int, DateTime?)>();
|
return [];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -161,52 +169,73 @@ public class AdminSQLManager
|
|||||||
|
|
||||||
//_adminCache.TryRemove(playerSteamId, out _);
|
//_adminCache.TryRemove(playerSteamId, out _);
|
||||||
|
|
||||||
await using MySqlConnection connection = await _database.GetConnectionAsync();
|
try
|
||||||
|
|
||||||
string sql = "";
|
|
||||||
|
|
||||||
if (globalDelete)
|
|
||||||
{
|
{
|
||||||
sql = "DELETE FROM sa_admins WHERE player_steamid = @PlayerSteamID";
|
await using MySqlConnection connection = await _database.GetConnectionAsync();
|
||||||
}
|
string sql = "";
|
||||||
else
|
|
||||||
{
|
|
||||||
sql = "DELETE FROM sa_admins WHERE player_steamid = @PlayerSteamID AND server_id = @ServerId";
|
|
||||||
}
|
|
||||||
|
|
||||||
await connection.ExecuteAsync(sql, new { PlayerSteamID = playerSteamId, ServerId = CS2_SimpleAdmin.ServerId });
|
if (globalDelete)
|
||||||
|
{
|
||||||
|
sql = "DELETE FROM sa_admins WHERE player_steamid = @PlayerSteamID";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
sql = "DELETE FROM sa_admins WHERE player_steamid = @PlayerSteamID AND server_id = @ServerId";
|
||||||
|
}
|
||||||
|
|
||||||
|
await connection.ExecuteAsync(sql, new { PlayerSteamID = playerSteamId, CS2_SimpleAdmin.ServerId });
|
||||||
|
}
|
||||||
|
catch { };
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task AddAdminBySteamId(string playerSteamId, string playerName, string flags, int immunity = 0, int time = 0, bool globalAdmin = false)
|
public async Task AddAdminBySteamId(string playerSteamId, string playerName, List<string> flagsList, int immunity = 0, int time = 0, bool globalAdmin = false)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(playerSteamId)) return;
|
if (string.IsNullOrEmpty(playerSteamId) || flagsList == null || flagsList.Count == 0) return;
|
||||||
|
|
||||||
flags = flags.Replace(" ", "");
|
|
||||||
|
|
||||||
DateTime now = DateTime.UtcNow.ToLocalTime();
|
DateTime now = DateTime.UtcNow.ToLocalTime();
|
||||||
DateTime? futureTime;
|
DateTime? futureTime;
|
||||||
|
|
||||||
if (time != 0)
|
if (time != 0)
|
||||||
futureTime = now.ToLocalTime().AddMinutes(time);
|
futureTime = now.ToLocalTime().AddMinutes(time);
|
||||||
else
|
else
|
||||||
futureTime = null;
|
futureTime = null;
|
||||||
|
|
||||||
await using MySqlConnection connection = await _database.GetConnectionAsync();
|
try
|
||||||
|
|
||||||
var sql = "INSERT INTO `sa_admins` (`player_steamid`, `player_name`, `flags`, `immunity`, `ends`, `created`, `server_id`) " +
|
|
||||||
"VALUES (@playerSteamid, @playerName, @flags, @immunity, @ends, @created, @serverid)";
|
|
||||||
|
|
||||||
int? serverId = globalAdmin ? null : CS2_SimpleAdmin.ServerId;
|
|
||||||
|
|
||||||
await connection.ExecuteAsync(sql, new
|
|
||||||
{
|
{
|
||||||
playerSteamId,
|
await using MySqlConnection connection = await _database.GetConnectionAsync();
|
||||||
playerName,
|
|
||||||
flags,
|
// Insert admin into sa_admins table
|
||||||
immunity,
|
var insertAdminSql = "INSERT INTO `sa_admins` (`player_steamid`, `player_name`, `immunity`, `ends`, `created`, `server_id`) " +
|
||||||
ends = futureTime,
|
"VALUES (@playerSteamid, @playerName, @immunity, @ends, @created, @serverid); SELECT LAST_INSERT_ID();";
|
||||||
created = now,
|
|
||||||
serverid = serverId
|
int adminId = await connection.ExecuteScalarAsync<int>(insertAdminSql, new
|
||||||
});
|
{
|
||||||
|
playerSteamId,
|
||||||
|
playerName,
|
||||||
|
immunity,
|
||||||
|
ends = futureTime,
|
||||||
|
created = now,
|
||||||
|
serverid = globalAdmin ? null : CS2_SimpleAdmin.ServerId
|
||||||
|
});
|
||||||
|
|
||||||
|
// Insert flags into sa_admins_flags table
|
||||||
|
foreach (var flag in flagsList)
|
||||||
|
{
|
||||||
|
Console.WriteLine(flag);
|
||||||
|
var insertFlagsSql = "INSERT INTO `sa_admins_flags` (`admin_id`, `flag`) " +
|
||||||
|
"VALUES (@adminId, @flag)";
|
||||||
|
|
||||||
|
await connection.ExecuteAsync(insertFlagsSql, new
|
||||||
|
{
|
||||||
|
adminId,
|
||||||
|
flag
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Console.WriteLine(ex.ToString());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task DeleteOldAdmins()
|
public async Task DeleteOldAdmins()
|
||||||
@@ -220,8 +249,7 @@ public class AdminSQLManager
|
|||||||
}
|
}
|
||||||
catch (Exception)
|
catch (Exception)
|
||||||
{
|
{
|
||||||
if (CS2_SimpleAdmin._logger != null)
|
CS2_SimpleAdmin._logger?.LogCritical("Unable to remove expired admins");
|
||||||
CS2_SimpleAdmin._logger.LogCritical("Unable to remove expired admins");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -173,7 +173,7 @@ internal class BanManager(Database database, CS2_SimpleAdminConfig config)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task UnbanPlayer(string playerPattern)
|
public async Task UnbanPlayer(string playerPattern, string adminSteamId, string reason)
|
||||||
{
|
{
|
||||||
if (playerPattern == null || playerPattern.Length <= 1)
|
if (playerPattern == null || playerPattern.Length <= 1)
|
||||||
{
|
{
|
||||||
@@ -183,8 +183,43 @@ internal class BanManager(Database database, CS2_SimpleAdminConfig config)
|
|||||||
{
|
{
|
||||||
await using MySqlConnection connection = await _database.GetConnectionAsync();
|
await using MySqlConnection connection = await _database.GetConnectionAsync();
|
||||||
|
|
||||||
|
string sqlRetrieveBans = "SELECT id FROM sa_bans WHERE (player_steamid = @pattern OR player_name = @pattern OR player_ip = @pattern) AND status = 'ACTIVE'";
|
||||||
|
var bans = await connection.QueryAsync(sqlRetrieveBans, new { pattern = playerPattern });
|
||||||
|
|
||||||
|
if (!bans.Any())
|
||||||
|
return;
|
||||||
|
|
||||||
|
string sqlAdmin = "SELECT id FROM sa_admins WHERE player_steamid = @adminSteamId";
|
||||||
|
string sqlInsertUnban = "INSERT INTO sa_unbans (ban_id, admin_id, reason) VALUES (@banId, @adminId, @reason); SELECT LAST_INSERT_ID();";
|
||||||
|
|
||||||
|
int? sqlAdminId = await connection.ExecuteScalarAsync<int?>(sqlAdmin, new { adminSteamId });
|
||||||
|
int adminId = sqlAdminId ?? 0;
|
||||||
|
|
||||||
|
foreach (var ban in bans)
|
||||||
|
{
|
||||||
|
int banId = ban.id;
|
||||||
|
int? unbanId;
|
||||||
|
|
||||||
|
// Insert into sa_unbans
|
||||||
|
if (reason != null)
|
||||||
|
{
|
||||||
|
unbanId = await connection.ExecuteScalarAsync<int>(sqlInsertUnban, new { banId, adminId, reason });
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
sqlInsertUnban = "INSERT INTO sa_unbans (ban_id, admin_id) VALUES (@banId, @adminId); SELECT LAST_INSERT_ID();";
|
||||||
|
unbanId = await connection.ExecuteScalarAsync<int>(sqlInsertUnban, new { banId, adminId });
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update sa_bans to set unban_id
|
||||||
|
string sqlUpdateBan = "UPDATE sa_bans SET status = 'UNBANNED', unban_id = @unbanId WHERE id = @banId";
|
||||||
|
await connection.ExecuteAsync(sqlUpdateBan, new { unbanId, banId });
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
string sqlUnban = "UPDATE sa_bans SET status = 'UNBANNED' WHERE player_steamid = @pattern OR player_name = @pattern OR player_ip = @pattern AND status = 'ACTIVE'";
|
string sqlUnban = "UPDATE sa_bans SET status = 'UNBANNED' WHERE player_steamid = @pattern OR player_name = @pattern OR player_ip = @pattern AND status = 'ACTIVE'";
|
||||||
await connection.ExecuteAsync(sqlUnban, new { pattern = playerPattern });
|
await connection.ExecuteAsync(sqlUnban, new { pattern = playerPattern });
|
||||||
|
*/
|
||||||
|
|
||||||
}
|
}
|
||||||
catch { }
|
catch { }
|
||||||
|
|||||||
@@ -4,20 +4,14 @@ using MySqlConnector;
|
|||||||
|
|
||||||
namespace CS2_SimpleAdmin;
|
namespace CS2_SimpleAdmin;
|
||||||
|
|
||||||
internal class MuteManager
|
internal class MuteManager(Database database)
|
||||||
{
|
{
|
||||||
private readonly Database _database;
|
private readonly Database _database = database;
|
||||||
|
|
||||||
public MuteManager(Database database)
|
|
||||||
{
|
|
||||||
_database = database;
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task MutePlayer(PlayerInfo player, PlayerInfo issuer, string reason, int time = 0, int type = 0)
|
public async Task MutePlayer(PlayerInfo player, PlayerInfo issuer, string reason, int time = 0, int type = 0)
|
||||||
{
|
{
|
||||||
if (player == null || player.SteamId == null) return;
|
if (player == null || player.SteamId == null) return;
|
||||||
|
|
||||||
await using MySqlConnection connection = await _database.GetConnectionAsync();
|
|
||||||
|
|
||||||
DateTime now = DateTime.UtcNow.ToLocalTime();
|
DateTime now = DateTime.UtcNow.ToLocalTime();
|
||||||
DateTime futureTime = now.AddMinutes(time).ToLocalTime();
|
DateTime futureTime = now.AddMinutes(time).ToLocalTime();
|
||||||
@@ -28,29 +22,33 @@ internal class MuteManager
|
|||||||
else if (type == 2)
|
else if (type == 2)
|
||||||
muteType = "SILENCE";
|
muteType = "SILENCE";
|
||||||
|
|
||||||
var sql = "INSERT INTO `sa_mutes` (`player_steamid`, `player_name`, `admin_steamid`, `admin_name`, `reason`, `duration`, `ends`, `created`, `type`, `server_id`) " +
|
try
|
||||||
"VALUES (@playerSteamid, @playerName, @adminSteamid, @adminName, @banReason, @duration, @ends, @created, @type, @serverid)";
|
|
||||||
|
|
||||||
await connection.ExecuteAsync(sql, new
|
|
||||||
{
|
{
|
||||||
playerSteamid = player.SteamId,
|
await using MySqlConnection connection = await _database.GetConnectionAsync();
|
||||||
playerName = player.Name,
|
var sql = "INSERT INTO `sa_mutes` (`player_steamid`, `player_name`, `admin_steamid`, `admin_name`, `reason`, `duration`, `ends`, `created`, `type`, `server_id`) " +
|
||||||
adminSteamid = issuer.SteamId == null ? "Console" : issuer.SteamId,
|
"VALUES (@playerSteamid, @playerName, @adminSteamid, @adminName, @muteReason, @duration, @ends, @created, @type, @serverid)";
|
||||||
adminName = issuer.SteamId == null ? "Console" : issuer.Name,
|
|
||||||
banReason = reason,
|
await connection.ExecuteAsync(sql, new
|
||||||
duration = time,
|
{
|
||||||
ends = futureTime,
|
playerSteamid = player.SteamId,
|
||||||
created = now,
|
playerName = player.Name,
|
||||||
type = muteType,
|
adminSteamid = issuer.SteamId ?? "Console",
|
||||||
serverid = CS2_SimpleAdmin.ServerId
|
adminName = issuer.SteamId == null ? "Console" : issuer.Name,
|
||||||
});
|
muteReason = reason,
|
||||||
|
duration = time,
|
||||||
|
ends = futureTime,
|
||||||
|
created = now,
|
||||||
|
type = muteType,
|
||||||
|
serverid = CS2_SimpleAdmin.ServerId
|
||||||
|
});
|
||||||
|
}
|
||||||
|
catch { };
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task AddMuteBySteamid(string playerSteamId, PlayerInfo issuer, string reason, int time = 0, int type = 0)
|
public async Task AddMuteBySteamid(string playerSteamId, PlayerInfo issuer, string reason, int time = 0, int type = 0)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(playerSteamId)) return;
|
if (string.IsNullOrEmpty(playerSteamId)) return;
|
||||||
|
|
||||||
await using MySqlConnection connection = await _database.GetConnectionAsync();
|
|
||||||
|
|
||||||
DateTime now = DateTime.UtcNow.ToLocalTime();
|
DateTime now = DateTime.UtcNow.ToLocalTime();
|
||||||
DateTime futureTime = now.AddMinutes(time).ToLocalTime();
|
DateTime futureTime = now.AddMinutes(time).ToLocalTime();
|
||||||
@@ -61,28 +59,33 @@ internal class MuteManager
|
|||||||
else if (type == 2)
|
else if (type == 2)
|
||||||
muteType = "SILENCE";
|
muteType = "SILENCE";
|
||||||
|
|
||||||
var sql = "INSERT INTO `sa_mutes` (`player_steamid`, `admin_steamid`, `admin_name`, `reason`, `duration`, `ends`, `created`, `type`, `server_id`) " +
|
try
|
||||||
"VALUES (@playerSteamid, @adminSteamid, @adminName, @banReason, @duration, @ends, @created, @type, @serverid)";
|
|
||||||
|
|
||||||
await connection.ExecuteAsync(sql, new
|
|
||||||
{
|
{
|
||||||
playerSteamid = playerSteamId,
|
await using MySqlConnection connection = await _database.GetConnectionAsync();
|
||||||
adminSteamid = issuer.SteamId == null ? "Console" : issuer.SteamId,
|
var sql = "INSERT INTO `sa_mutes` (`player_steamid`, `admin_steamid`, `admin_name`, `reason`, `duration`, `ends`, `created`, `type`, `server_id`) " +
|
||||||
adminName = issuer.Name == null ? "Console" : issuer.Name,
|
"VALUES (@playerSteamid, @adminSteamid, @adminName, @muteReason, @duration, @ends, @created, @type, @serverid)";
|
||||||
banReason = reason,
|
|
||||||
duration = time,
|
await connection.ExecuteAsync(sql, new
|
||||||
ends = futureTime,
|
{
|
||||||
created = now,
|
playerSteamid = playerSteamId,
|
||||||
type = muteType,
|
adminSteamid = issuer.SteamId ?? "Console",
|
||||||
serverid = CS2_SimpleAdmin.ServerId
|
adminName = issuer.Name ?? "Console",
|
||||||
});
|
muteReason = reason,
|
||||||
|
duration = time,
|
||||||
|
ends = futureTime,
|
||||||
|
created = now,
|
||||||
|
type = muteType,
|
||||||
|
serverid = CS2_SimpleAdmin.ServerId
|
||||||
|
});
|
||||||
|
}
|
||||||
|
catch { };
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<List<dynamic>> IsPlayerMuted(string steamId)
|
public async Task<List<dynamic>> IsPlayerMuted(string steamId)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(steamId))
|
if (string.IsNullOrEmpty(steamId))
|
||||||
{
|
{
|
||||||
return new List<dynamic>();
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
@@ -102,49 +105,84 @@ internal class MuteManager
|
|||||||
}
|
}
|
||||||
catch (Exception)
|
catch (Exception)
|
||||||
{
|
{
|
||||||
return new List<dynamic>();
|
return [];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<int> GetPlayerMutes(string steamId)
|
public async Task<int> GetPlayerMutes(string steamId)
|
||||||
{
|
{
|
||||||
await using MySqlConnection connection = await _database.GetConnectionAsync();
|
try
|
||||||
|
{
|
||||||
|
await using MySqlConnection connection = await _database.GetConnectionAsync();
|
||||||
|
|
||||||
int muteCount;
|
int muteCount;
|
||||||
string sql = "SELECT COUNT(*) FROM sa_mutes WHERE player_steamid = @PlayerSteamID";
|
string sql = "SELECT COUNT(*) FROM sa_mutes WHERE player_steamid = @PlayerSteamID";
|
||||||
|
|
||||||
muteCount = await connection.ExecuteScalarAsync<int>(sql, new { PlayerSteamID = steamId });
|
muteCount = await connection.ExecuteScalarAsync<int>(sql, new { PlayerSteamID = steamId });
|
||||||
|
return muteCount;
|
||||||
return muteCount;
|
}
|
||||||
|
catch (Exception)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task UnmutePlayer(string playerPattern, int type = 0)
|
public async Task UnmutePlayer(string playerPattern, string adminSteamId, string reason, int type = 0)
|
||||||
{
|
{
|
||||||
if (playerPattern == null || playerPattern.Length <= 1)
|
if (playerPattern == null || playerPattern.Length <= 1)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
await using MySqlConnection connection = await _database.GetConnectionAsync();
|
try
|
||||||
|
|
||||||
if (type == 2)
|
|
||||||
{
|
{
|
||||||
string _unbanSql = "UPDATE sa_mutes SET status = 'UNMUTED' WHERE (player_steamid = @pattern OR player_name = @pattern) AND status = 'ACTIVE'";
|
await using MySqlConnection connection = await _database.GetConnectionAsync();
|
||||||
await connection.ExecuteAsync(_unbanSql, new { pattern = playerPattern });
|
|
||||||
|
|
||||||
return;
|
string muteType = "GAG";
|
||||||
|
if (type == 1)
|
||||||
|
{
|
||||||
|
muteType = "MUTE";
|
||||||
|
}
|
||||||
|
else if (type == 2)
|
||||||
|
muteType = "SILENCE";
|
||||||
|
|
||||||
|
string sqlRetrieveMutes = "SELECT id FROM sa_mutes WHERE (player_steamid = @pattern OR player_name = @pattern) AND type = @muteType AND status = 'ACTIVE'";
|
||||||
|
var mutes = await connection.QueryAsync(sqlRetrieveMutes, new { pattern = playerPattern, muteType });
|
||||||
|
|
||||||
|
if (!mutes.Any())
|
||||||
|
return;
|
||||||
|
|
||||||
|
string sqlAdmin = "SELECT id FROM sa_admins WHERE player_steamid = @adminSteamId";
|
||||||
|
string sqlInsertUnmute = "INSERT INTO sa_unmutes (mute_id, admin_id, reason) VALUES (@muteId, @adminId, @reason); SELECT LAST_INSERT_ID();";
|
||||||
|
|
||||||
|
int? sqlAdminId = await connection.ExecuteScalarAsync<int?>(sqlAdmin, new { adminSteamId });
|
||||||
|
int adminId = sqlAdminId ?? 0;
|
||||||
|
|
||||||
|
foreach (var mute in mutes)
|
||||||
|
{
|
||||||
|
int muteId = mute.id;
|
||||||
|
int? unmuteId;
|
||||||
|
|
||||||
|
// Insert into sa_unmutes
|
||||||
|
if (reason != null)
|
||||||
|
{
|
||||||
|
unmuteId = await connection.ExecuteScalarAsync<int>(sqlInsertUnmute, new { muteId, adminId, reason });
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
sqlInsertUnmute = "INSERT INTO sa_unmutes (muteId, admin_id) VALUES (@muteId, @adminId); SELECT LAST_INSERT_ID();";
|
||||||
|
unmuteId = await connection.ExecuteScalarAsync<int>(sqlInsertUnmute, new { muteId, adminId });
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update sa_mutes to set unmute_id
|
||||||
|
string sqlUpdateMute = "UPDATE sa_mutes SET status = 'UNMUTED', unmute_id = @unmuteId WHERE id = @muteId";
|
||||||
|
await connection.ExecuteAsync(sqlUpdateMute, new { unmuteId, muteId });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
catch (Exception ex)
|
||||||
string muteType = "GAG";
|
|
||||||
if (type == 1)
|
|
||||||
{
|
{
|
||||||
muteType = "MUTE";
|
Console.WriteLine(ex);
|
||||||
}
|
}
|
||||||
else if (type == 2)
|
|
||||||
muteType = "SILENCE";
|
|
||||||
|
|
||||||
string sqlUnban = "UPDATE sa_mutes SET status = 'UNMUTED' WHERE (player_steamid = @pattern OR player_name = @pattern) AND type = @muteType AND status = 'ACTIVE'";
|
|
||||||
await connection.ExecuteAsync(sqlUnban, new { pattern = playerPattern, muteType });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task ExpireOldMutes()
|
public async Task ExpireOldMutes()
|
||||||
@@ -158,8 +196,7 @@ internal class MuteManager
|
|||||||
}
|
}
|
||||||
catch (Exception)
|
catch (Exception)
|
||||||
{
|
{
|
||||||
if (CS2_SimpleAdmin._logger != null)
|
CS2_SimpleAdmin._logger?.LogCritical("Unable to remove expired mutes");
|
||||||
CS2_SimpleAdmin._logger.LogCritical("Unable to remove expired mutes");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -15,13 +15,15 @@ public class PlayerPenaltyManager
|
|||||||
new ConcurrentDictionary<int, Dictionary<PenaltyType, List<(DateTime, int)>>>();
|
new ConcurrentDictionary<int, Dictionary<PenaltyType, List<(DateTime, int)>>>();
|
||||||
|
|
||||||
// Add a penalty for a player
|
// Add a penalty for a player
|
||||||
public void AddPenalty(int slot, PenaltyType penaltyType, DateTime endDateTime, int durationSeconds)
|
public static void AddPenalty(int slot, PenaltyType penaltyType, DateTime endDateTime, int durationSeconds)
|
||||||
{
|
{
|
||||||
penalties.AddOrUpdate(slot,
|
penalties.AddOrUpdate(slot,
|
||||||
(_) =>
|
(_) =>
|
||||||
{
|
{
|
||||||
var dict = new Dictionary<PenaltyType, List<(DateTime, int)>>();
|
var dict = new Dictionary<PenaltyType, List<(DateTime, int)>>
|
||||||
dict[penaltyType] = new List<(DateTime, int)>() { (endDateTime, durationSeconds) };
|
{
|
||||||
|
[penaltyType] = [(endDateTime, durationSeconds)]
|
||||||
|
};
|
||||||
return dict;
|
return dict;
|
||||||
},
|
},
|
||||||
(_, existingDict) =>
|
(_, existingDict) =>
|
||||||
@@ -35,7 +37,7 @@ public class PlayerPenaltyManager
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool IsPenalized(int slot, PenaltyType penaltyType)
|
public static bool IsPenalized(int slot, PenaltyType penaltyType)
|
||||||
{
|
{
|
||||||
//Console.WriteLine($"Checking penalties for player with slot {slot} and penalty type {penaltyType}");
|
//Console.WriteLine($"Checking penalties for player with slot {slot} and penalty type {penaltyType}");
|
||||||
|
|
||||||
@@ -78,23 +80,23 @@ public class PlayerPenaltyManager
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Get the end datetime and duration of penalties for a player and penalty type
|
// Get the end datetime and duration of penalties for a player and penalty type
|
||||||
public List<(DateTime EndDateTime, int Duration)> GetPlayerPenalties(int slot, PenaltyType penaltyType)
|
public static List<(DateTime EndDateTime, int Duration)> GetPlayerPenalties(int slot, PenaltyType penaltyType)
|
||||||
{
|
{
|
||||||
if (penalties.TryGetValue(slot, out Dictionary<PenaltyType, List<(DateTime EndDateTime, int Duration)>>? penaltyDict) &&
|
if (penalties.TryGetValue(slot, out Dictionary<PenaltyType, List<(DateTime EndDateTime, int Duration)>>? penaltyDict) &&
|
||||||
penaltyDict.TryGetValue(penaltyType, out List<(DateTime EndDateTime, int Duration)>? penaltiesList) && penaltiesList != null)
|
penaltyDict.TryGetValue(penaltyType, out List<(DateTime EndDateTime, int Duration)>? penaltiesList) && penaltiesList != null)
|
||||||
{
|
{
|
||||||
return penaltiesList;
|
return penaltiesList;
|
||||||
}
|
}
|
||||||
return new List<(DateTime EndDateTime, int Duration)>();
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool IsSlotInPenalties(int slot)
|
public static bool IsSlotInPenalties(int slot)
|
||||||
{
|
{
|
||||||
return penalties.ContainsKey(slot);
|
return penalties.ContainsKey(slot);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove all penalties for a player slot
|
// Remove all penalties for a player slot
|
||||||
public void RemoveAllPenalties(int slot)
|
public static void RemoveAllPenalties(int slot)
|
||||||
{
|
{
|
||||||
if (penalties.ContainsKey(slot))
|
if (penalties.ContainsKey(slot))
|
||||||
{
|
{
|
||||||
@@ -103,13 +105,13 @@ public class PlayerPenaltyManager
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Remove all penalties
|
// Remove all penalties
|
||||||
public void RemoveAllPenalties()
|
public static void RemoveAllPenalties()
|
||||||
{
|
{
|
||||||
penalties.Clear();
|
penalties.Clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove all penalties of a selected type from a specific player
|
// Remove all penalties of a selected type from a specific player
|
||||||
public void RemovePenaltiesByType(int slot, PenaltyType penaltyType)
|
public static void RemovePenaltiesByType(int slot, PenaltyType penaltyType)
|
||||||
{
|
{
|
||||||
if (penalties.TryGetValue(slot, out Dictionary<PenaltyType, List<(DateTime EndDateTime, int Duration)>>? penaltyDict) &&
|
if (penalties.TryGetValue(slot, out Dictionary<PenaltyType, List<(DateTime EndDateTime, int Duration)>>? penaltyDict) &&
|
||||||
penaltyDict.ContainsKey(penaltyType))
|
penaltyDict.ContainsKey(penaltyType))
|
||||||
@@ -119,7 +121,7 @@ public class PlayerPenaltyManager
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Remove all expired penalties for all players and penalty types
|
// Remove all expired penalties for all players and penalty types
|
||||||
public void RemoveExpiredPenalties()
|
public static void RemoveExpiredPenalties()
|
||||||
{
|
{
|
||||||
DateTime now = DateTime.UtcNow.ToLocalTime();
|
DateTime now = DateTime.UtcNow.ToLocalTime();
|
||||||
foreach (var kvp in penalties.ToList()) // Use ToList to avoid modification while iterating
|
foreach (var kvp in penalties.ToList()) // Use ToList to avoid modification while iterating
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ namespace CS2_SimpleAdmin.Menus
|
|||||||
{
|
{
|
||||||
public static BaseMenu CreateMenu(string title)
|
public static BaseMenu CreateMenu(string title)
|
||||||
{
|
{
|
||||||
return CS2_SimpleAdmin.Instance.Config.UseChatMenu ? new ChatMenu(title) : new CenterHtmlMenu(title);
|
return CS2_SimpleAdmin.Instance.Config.UseChatMenu ? new ChatMenu(title) : new CenterHtmlMenu(title, CS2_SimpleAdmin.Instance);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void OpenMenu(CCSPlayerController player, BaseMenu menu)
|
public static void OpenMenu(CCSPlayerController player, BaseMenu menu)
|
||||||
@@ -44,7 +44,7 @@ namespace CS2_SimpleAdmin.Menus
|
|||||||
new ChatMenuOptionData("Manage Server", () => ManageServerMenu.OpenMenu(admin)),
|
new ChatMenuOptionData("Manage Server", () => ManageServerMenu.OpenMenu(admin)),
|
||||||
new ChatMenuOptionData("Fun actions", () => FunActionsMenu.OpenMenu(admin)),
|
new ChatMenuOptionData("Fun actions", () => FunActionsMenu.OpenMenu(admin)),
|
||||||
};
|
};
|
||||||
|
|
||||||
List<CustomServerCommandData> customCommands = CS2_SimpleAdmin.Instance.Config.CustomServerCommands;
|
List<CustomServerCommandData> customCommands = CS2_SimpleAdmin.Instance.Config.CustomServerCommands;
|
||||||
if (customCommands.Count > 0)
|
if (customCommands.Count > 0)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -69,7 +69,7 @@ namespace CS2_SimpleAdmin.Menus
|
|||||||
private static void AddAdmin(CCSPlayerController admin, CCSPlayerController player, string flag)
|
private static void AddAdmin(CCSPlayerController admin, CCSPlayerController player, string flag)
|
||||||
{
|
{
|
||||||
// TODO: Change default immunity?
|
// TODO: Change default immunity?
|
||||||
CS2_SimpleAdmin.Instance.AddAdmin(admin, player.SteamID.ToString(), player.PlayerName, flag, 10);
|
CS2_SimpleAdmin.AddAdmin(admin, player.SteamID.ToString(), player.PlayerName, flag, 10);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void RemoveAdmin(CCSPlayerController admin, CCSPlayerController player)
|
private static void RemoveAdmin(CCSPlayerController admin, CCSPlayerController player)
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
using System.Web;
|
|
||||||
using CounterStrikeSharp.API.Core;
|
using CounterStrikeSharp.API.Core;
|
||||||
using CounterStrikeSharp.API.Modules.Admin;
|
using CounterStrikeSharp.API.Modules.Admin;
|
||||||
using CounterStrikeSharp.API.Modules.Menu;
|
using CounterStrikeSharp.API.Modules.Menu;
|
||||||
|
using System.Web;
|
||||||
|
|
||||||
namespace CS2_SimpleAdmin.Menus
|
namespace CS2_SimpleAdmin.Menus
|
||||||
{
|
{
|
||||||
@@ -32,9 +32,13 @@ namespace CS2_SimpleAdmin.Menus
|
|||||||
BaseMenu menu = AdminMenu.CreateMenu(menuName);
|
BaseMenu menu = AdminMenu.CreateMenu(menuName);
|
||||||
|
|
||||||
IEnumerable<CCSPlayerController> players = Helper.GetValidPlayersWithBots();
|
IEnumerable<CCSPlayerController> players = Helper.GetValidPlayersWithBots();
|
||||||
|
string playerName = string.Empty;
|
||||||
|
|
||||||
foreach (CCSPlayerController player in players)
|
foreach (CCSPlayerController player in players)
|
||||||
{
|
{
|
||||||
string optionName = HttpUtility.HtmlEncode(player.PlayerName);
|
playerName = player.PlayerName.Length > 26 ? player.PlayerName[..26] : player.PlayerName;
|
||||||
|
|
||||||
|
string optionName = HttpUtility.HtmlEncode(playerName);
|
||||||
if (enableFilter != null && enableFilter(player) == false)
|
if (enableFilter != null && enableFilter(player) == false)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user