mirror of
https://github.com/daffyyyy/CS2-SimpleAdmin.git
synced 2026-02-17 18:39:07 +00:00
1.3.6d - IMPORTANT
- Fixed pool size - Fixed `css_rename` - Updated CounterStrikeSharp - Minor changes
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using CounterStrikeSharp.API.Core;
|
||||
using CounterStrikeSharp.API;
|
||||
using CounterStrikeSharp.API.Core;
|
||||
using CounterStrikeSharp.API.Core.Attributes;
|
||||
using CounterStrikeSharp.API.Modules.Commands;
|
||||
using CounterStrikeSharp.API.Modules.Commands.Targeting;
|
||||
@@ -12,7 +13,7 @@ using System.Collections.Concurrent;
|
||||
|
||||
namespace CS2_SimpleAdmin;
|
||||
|
||||
[MinimumApiVersion(191)]
|
||||
[MinimumApiVersion(198)]
|
||||
public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdminConfig>
|
||||
{
|
||||
public static CS2_SimpleAdmin Instance { get; private set; } = new();
|
||||
@@ -38,7 +39,7 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdmin
|
||||
public override string ModuleName => "CS2-SimpleAdmin";
|
||||
public override string ModuleDescription => "Simple admin plugin for Counter-Strike 2 :)";
|
||||
public override string ModuleAuthor => "daffyy & Dliix66";
|
||||
public override string ModuleVersion => "1.3.6c";
|
||||
public override string ModuleVersion => "1.3.6d";
|
||||
|
||||
public CS2_SimpleAdminConfig Config { get; set; } = new();
|
||||
|
||||
@@ -71,7 +72,10 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdmin
|
||||
UserID = config.DatabaseUser,
|
||||
Password = config.DatabasePassword,
|
||||
Port = (uint)config.DatabasePort,
|
||||
Pooling = true
|
||||
Pooling = true,
|
||||
MinimumPoolSize = 0,
|
||||
MaximumPoolSize = (uint)(Server.MaxPlayers > 21 ? 640 : 210),
|
||||
ConnectionIdleTimeout = 30
|
||||
};
|
||||
|
||||
dbConnectionString = builder.ConnectionString;
|
||||
|
||||
@@ -10,10 +10,10 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="CounterStrikeSharp.API" Version="1.0.193" />
|
||||
<PackageReference Include="CounterStrikeSharp.API" Version="1.0.198" />
|
||||
<PackageReference Include="Dapper" Version="2.1.35" />
|
||||
<PackageReference Include="Discord.Net.Webhook" Version="3.13.1" />
|
||||
<PackageReference Include="MySqlConnector" Version="2.3.5" />
|
||||
<PackageReference Include="Discord.Net.Webhook" Version="3.14.1" />
|
||||
<PackageReference Include="MySqlConnector" Version="2.3.6" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="*" />
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
@@ -33,7 +33,12 @@ namespace CS2_SimpleAdmin
|
||||
commandSql.CommandText = commandText;
|
||||
await commandSql.ExecuteNonQueryAsync();
|
||||
|
||||
command.ReplyToCommand("Successfully updated the database");
|
||||
commandText = "ALTER TABLE `sa_servers` MODIFY COLUMN `hostname` varchar(128);";
|
||||
using var commandSql1 = connection.CreateCommand();
|
||||
commandSql1.CommandText = commandText;
|
||||
await commandSql1.ExecuteNonQueryAsync();
|
||||
|
||||
command.ReplyToCommand($"Successfully updated the database - {ModuleVersion}");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
@@ -662,7 +662,6 @@ namespace CS2_SimpleAdmin
|
||||
|
||||
if (caller!.CanTarget(player))
|
||||
{
|
||||
player.Rename(newName);
|
||||
|
||||
if (caller == null || caller != null && !silentPlayers.Contains(caller.Slot))
|
||||
{
|
||||
@@ -676,6 +675,8 @@ namespace CS2_SimpleAdmin
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
player.Rename(newName);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -815,6 +816,7 @@ namespace CS2_SimpleAdmin
|
||||
_discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(_localizer["sa_discord_log_command", $"[{callerName}]({communityUrl})", command.GetCommandString]));
|
||||
}
|
||||
|
||||
|
||||
Helper.LogCommand(caller, command);
|
||||
|
||||
playersToTarget.ForEach(player =>
|
||||
|
||||
@@ -44,7 +44,7 @@ CREATE TABLE IF NOT EXISTS `sa_admins` (
|
||||
CREATE TABLE IF NOT EXISTS `sa_servers` (
|
||||
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`address` varchar(64) NOT NULL,
|
||||
`hostname` varchar(64) NOT NULL,
|
||||
`hostname` varchar(128) NOT NULL,
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `address` (`address`)
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=36 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
|
||||
102
Events.cs
102
Events.cs
@@ -35,67 +35,81 @@ public partial class CS2_SimpleAdmin
|
||||
Logger.LogCritical("[OnClientDisconnect] Before");
|
||||
#endif
|
||||
|
||||
if (player is null || !player.IsValid || string.IsNullOrEmpty(player.IpAddress) || player.IsBot || player.IsHLTV) return HookResult.Continue;
|
||||
if (!loadedPlayers.Contains(player.Slot)) return HookResult.Continue;
|
||||
if (player == null || !player.IsValid || string.IsNullOrEmpty(player.IpAddress) || player.IsBot || player.IsHLTV)
|
||||
{
|
||||
return HookResult.Continue;
|
||||
}
|
||||
|
||||
if (!loadedPlayers.Contains(player.Slot))
|
||||
{
|
||||
return HookResult.Continue;
|
||||
}
|
||||
|
||||
#if DEBUG
|
||||
Logger.LogCritical("[OnClientDisconnect] After Check");
|
||||
#endif
|
||||
|
||||
PlayerPenaltyManager playerPenaltyManager = new();
|
||||
try
|
||||
{
|
||||
PlayerPenaltyManager playerPenaltyManager = new PlayerPenaltyManager();
|
||||
playerPenaltyManager.RemoveAllPenalties(player.Slot);
|
||||
|
||||
if (TagsDetected)
|
||||
{
|
||||
Server.ExecuteCommand($"css_tag_unmute {player.SteamID}");
|
||||
}
|
||||
|
||||
if (silentPlayers.Contains(player.Slot))
|
||||
{
|
||||
RemoveFromConcurrentBag(silentPlayers, player.Slot);
|
||||
if (godPlayers.Contains(player.Slot))
|
||||
RemoveFromConcurrentBag(godPlayers, player.Slot);
|
||||
}
|
||||
|
||||
loadedPlayers.Remove(player.Slot);
|
||||
if (godPlayers.Contains(player.Slot))
|
||||
{
|
||||
RemoveFromConcurrentBag(godPlayers, player.Slot);
|
||||
}
|
||||
|
||||
SteamID? authorizedSteamID = player.AuthorizedSteamID;
|
||||
|
||||
if (authorizedSteamID == null) return HookResult.Continue;
|
||||
|
||||
Task.Run(() =>
|
||||
{
|
||||
if (AdminSQLManager._adminCache.TryGetValue(authorizedSteamID, out DateTime? expirationTime)
|
||||
if (authorizedSteamID != null && AdminSQLManager._adminCache.TryGetValue(authorizedSteamID, out DateTime? expirationTime)
|
||||
&& expirationTime <= DateTime.Now)
|
||||
{
|
||||
AdminManager.ClearPlayerPermissions(authorizedSteamID);
|
||||
AdminManager.RemovePlayerAdminData(authorizedSteamID);
|
||||
}
|
||||
});
|
||||
|
||||
loadedPlayers.Remove(player.Slot);
|
||||
|
||||
return HookResult.Continue;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logger.LogError($"An error occurred in OnClientDisconnect: {ex.Message}");
|
||||
return HookResult.Continue;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
[GameEventHandler]
|
||||
public HookResult OnPlayerFullConnect(EventPlayerConnectFull @event, GameEventInfo info)
|
||||
{
|
||||
CCSPlayerController? player = @event.Userid;
|
||||
#if DEBUG
|
||||
Logger.LogCritical($"[OnPlayerConnect] Before check {player.PlayerName} : {player.IpAddress}");
|
||||
#endif
|
||||
if (player is null
|
||||
|| string.IsNullOrEmpty(player.IpAddress) || player.IpAddress.Contains("127.0.0.1")
|
||||
|| player.IsBot || player.IsHLTV || !player.UserId.HasValue) return HookResult.Continue;
|
||||
|
||||
#if DEBUG
|
||||
Logger.LogCritical("[OnPlayerConnect] After Check");
|
||||
#endif
|
||||
if (player == null || string.IsNullOrEmpty(player.IpAddress) || player.IpAddress.Contains("127.0.0.1")
|
||||
|| player.IsBot || player.IsHLTV || !player.UserId.HasValue)
|
||||
return HookResult.Continue;
|
||||
|
||||
string ipAddress = player.IpAddress.Split(":")[0];
|
||||
|
||||
// Check if the player's IP or SteamID is in the bannedPlayers list
|
||||
if (bannedPlayers.Contains(ipAddress) || bannedPlayers.Contains(player.SteamID.ToString()))
|
||||
{
|
||||
if (!player.UserId.HasValue) return HookResult.Continue;
|
||||
// Kick the player if banned
|
||||
if (player.UserId.HasValue)
|
||||
Helper.KickPlayer(player.UserId.Value, "Banned");
|
||||
|
||||
return HookResult.Continue;
|
||||
}
|
||||
|
||||
if (_database == null || !player.UserId.HasValue || player.UserId == null)
|
||||
return HookResult.Continue;
|
||||
if (_database == null) return HookResult.Continue;
|
||||
|
||||
PlayerInfo playerInfo = new PlayerInfo
|
||||
{
|
||||
@@ -107,12 +121,13 @@ public partial class CS2_SimpleAdmin
|
||||
IpAddress = ipAddress
|
||||
};
|
||||
|
||||
Task.Run(async () =>
|
||||
{
|
||||
// Initialize BanManager, MuteManager, and PlayerPenaltyManager within the async delegate
|
||||
BanManager _banManager = new(_database, Config);
|
||||
MuteManager _muteManager = new(_database);
|
||||
PlayerPenaltyManager playerPenaltyManager = new PlayerPenaltyManager();
|
||||
|
||||
Task.Run(async () =>
|
||||
{
|
||||
if (await _banManager.IsPlayerBanned(playerInfo))
|
||||
{
|
||||
if (playerInfo.IpAddress != null && !bannedPlayers.Contains(playerInfo.IpAddress))
|
||||
@@ -178,6 +193,7 @@ public partial class CS2_SimpleAdmin
|
||||
}
|
||||
});
|
||||
|
||||
// Add player to loadedPlayers
|
||||
if (!loadedPlayers.Contains(player.Slot))
|
||||
loadedPlayers.Add(player.Slot);
|
||||
|
||||
@@ -197,7 +213,9 @@ public partial class CS2_SimpleAdmin
|
||||
|
||||
public HookResult OnCommandSay(CCSPlayerController? player, CommandInfo info)
|
||||
{
|
||||
if (player is null || !player.IsValid || player.IsBot || player.IsHLTV || info.GetArg(1).Length == 0) return HookResult.Continue;
|
||||
if (player is null || !player.IsValid || player.IsBot || player.IsHLTV || info.GetArg(1).Length == 0 || info.GetArg(1).StartsWith("/")
|
||||
|| info.GetArg(1).StartsWith("!") && info.GetArg(1).Length >= 12)
|
||||
return HookResult.Continue;
|
||||
|
||||
PlayerPenaltyManager playerPenaltyManager = new PlayerPenaltyManager();
|
||||
|
||||
@@ -209,7 +227,9 @@ public partial class CS2_SimpleAdmin
|
||||
|
||||
public HookResult OnCommandTeamSay(CCSPlayerController? player, CommandInfo info)
|
||||
{
|
||||
if (player is null || !player.IsValid || player.IsBot || player.IsHLTV || info.GetArg(1).Length == 0) return HookResult.Continue;
|
||||
if (player is null || !player.IsValid || player.IsBot || player.IsHLTV || info.GetArg(1).Length == 0 || info.GetArg(1).StartsWith("/")
|
||||
|| info.GetArg(1).StartsWith("!") && info.GetArg(1).Length >= 12)
|
||||
return HookResult.Continue;
|
||||
|
||||
PlayerPenaltyManager playerPenaltyManager = new PlayerPenaltyManager();
|
||||
|
||||
@@ -262,14 +282,18 @@ public partial class CS2_SimpleAdmin
|
||||
|
||||
if (_database == null) return;
|
||||
|
||||
AddTimer(61.0f, async () =>
|
||||
AddTimer(61.0f, () =>
|
||||
{
|
||||
|
||||
#if DEBUG
|
||||
Logger.LogCritical("[OnMapStart] Expired check");
|
||||
#endif
|
||||
AdminSQLManager _adminManager = new(_database);
|
||||
BanManager _banManager = new(_database, Config);
|
||||
MuteManager _muteManager = new(_database);
|
||||
|
||||
Task.Run(async () =>
|
||||
{
|
||||
AdminSQLManager _adminManager = new AdminSQLManager(_database);
|
||||
BanManager _banManager = new BanManager(_database, Config);
|
||||
MuteManager _muteManager = new MuteManager(_database);
|
||||
await _banManager.ExpireOldBans();
|
||||
await _muteManager.ExpireOldMutes();
|
||||
await _adminManager.DeleteOldAdmins();
|
||||
@@ -306,19 +330,20 @@ public partial class CS2_SimpleAdmin
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
playerPenaltyManager.RemoveExpiredPenalties();
|
||||
}
|
||||
catch (Exception) { }
|
||||
});
|
||||
|
||||
playerPenaltyManager.RemoveExpiredPenalties();
|
||||
});
|
||||
}, CounterStrikeSharp.API.Modules.Timers.TimerFlags.REPEAT | CounterStrikeSharp.API.Modules.Timers.TimerFlags.STOP_ON_MAPCHANGE);
|
||||
|
||||
AddTimer(2.0f, async () =>
|
||||
AddTimer(2.5f, () =>
|
||||
{
|
||||
string? address = $"{ConVar.Find("ip")!.StringValue}:{ConVar.Find("hostport")!.GetPrimitiveValue<int>()}";
|
||||
string? hostname = ConVar.Find("hostname")!.StringValue;
|
||||
|
||||
await Task.Run(async () =>
|
||||
Task.Run(async () =>
|
||||
{
|
||||
AdminSQLManager _adminManager = new(_database);
|
||||
try
|
||||
@@ -354,6 +379,7 @@ public partial class CS2_SimpleAdmin
|
||||
|
||||
await _adminManager.GiveAllFlags();
|
||||
});
|
||||
|
||||
}, CounterStrikeSharp.API.Modules.Timers.TimerFlags.STOP_ON_MAPCHANGE);
|
||||
|
||||
AddTimer(3.0f, () =>
|
||||
|
||||
@@ -121,7 +121,7 @@ public static class PlayerExtensions
|
||||
if (CS2_SimpleAdmin.Instance == null)
|
||||
return;
|
||||
|
||||
newName = CS2_SimpleAdmin._localizer?["sa_unknown"] ?? "Unknown";
|
||||
newName = newName ?? CS2_SimpleAdmin._localizer?["sa_unknown"] ?? "Unknown";
|
||||
|
||||
SchemaString<CBasePlayerController> playerName = new SchemaString<CBasePlayerController>(controller, "m_iszPlayerName");
|
||||
playerName.Set(newName + " ");
|
||||
|
||||
@@ -45,13 +45,13 @@ namespace CS2_SimpleAdmin
|
||||
|
||||
public static List<CCSPlayerController> GetValidPlayers()
|
||||
{
|
||||
return Utilities.GetPlayers().FindAll(p => p != null && p.IsValid && p.SteamID.ToString().Length == 17 && p.Connected == PlayerConnectedState.PlayerConnected && !p.IsBot && !p.IsHLTV);
|
||||
return Utilities.GetPlayers().FindAll(p => p != null && p.IsValid && p.SteamID.ToString().Length == 17 && !string.IsNullOrEmpty(p.IpAddress) && p.Connected == PlayerConnectedState.PlayerConnected && !p.IsBot && !p.IsHLTV);
|
||||
}
|
||||
|
||||
public static List<CCSPlayerController> GetValidPlayersWithBots()
|
||||
{
|
||||
return Utilities.GetPlayers().FindAll(p =>
|
||||
p != null && p.IsValid && p.SteamID.ToString().Length == 17 && p.Connected == PlayerConnectedState.PlayerConnected && !p.IsBot && !p.IsHLTV ||
|
||||
p != null && p.IsValid && p.SteamID.ToString().Length == 17 && !string.IsNullOrEmpty(p.IpAddress) && p.Connected == PlayerConnectedState.PlayerConnected && !p.IsBot && !p.IsHLTV ||
|
||||
p != null && p.IsValid && p.Connected == PlayerConnectedState.PlayerConnected && p.IsBot && !p.IsHLTV
|
||||
);
|
||||
}
|
||||
|
||||
@@ -17,17 +17,22 @@ public class PlayerPenaltyManager
|
||||
// Add a penalty for a player
|
||||
public void AddPenalty(int slot, PenaltyType penaltyType, DateTime endDateTime, int durationSeconds)
|
||||
{
|
||||
if (!penalties.ContainsKey(slot))
|
||||
penalties.AddOrUpdate(slot,
|
||||
(_) =>
|
||||
{
|
||||
penalties[slot] = new Dictionary<PenaltyType, List<(DateTime, int)>>();
|
||||
}
|
||||
|
||||
if (!penalties[slot].ContainsKey(penaltyType))
|
||||
var dict = new Dictionary<PenaltyType, List<(DateTime, int)>>();
|
||||
dict[penaltyType] = new List<(DateTime, int)>() { (endDateTime, durationSeconds) };
|
||||
return dict;
|
||||
},
|
||||
(_, existingDict) =>
|
||||
{
|
||||
penalties[slot][penaltyType] = new List<(DateTime, int)>();
|
||||
if (!existingDict.ContainsKey(penaltyType))
|
||||
{
|
||||
existingDict[penaltyType] = new List<(DateTime, int)>();
|
||||
}
|
||||
|
||||
penalties[slot][penaltyType].Add((endDateTime, durationSeconds));
|
||||
existingDict[penaltyType].Add((endDateTime, durationSeconds));
|
||||
return existingDict;
|
||||
});
|
||||
}
|
||||
|
||||
public bool IsPenalized(int slot, PenaltyType penaltyType)
|
||||
|
||||
Reference in New Issue
Block a user