mirror of
https://github.com/daffyyyy/CS2-SimpleAdmin.git
synced 2026-02-24 04:17:47 +00:00
Hotfix for cssharp 101
Hotfix for non-main thread
This commit is contained in:
@@ -1,9 +1,5 @@
|
|||||||
using CounterStrikeSharp.API.Core;
|
using Dapper;
|
||||||
using CounterStrikeSharp.API.Modules.Entities;
|
|
||||||
using Dapper;
|
|
||||||
using MySqlConnector;
|
using MySqlConnector;
|
||||||
using System.Data;
|
|
||||||
using System.Xml.Linq;
|
|
||||||
|
|
||||||
namespace CS2_SimpleAdmin
|
namespace CS2_SimpleAdmin
|
||||||
{
|
{
|
||||||
@@ -15,10 +11,8 @@ namespace CS2_SimpleAdmin
|
|||||||
{
|
{
|
||||||
_dbConnection = new MySqlConnection(connectionString);
|
_dbConnection = new MySqlConnection(connectionString);
|
||||||
}
|
}
|
||||||
public async Task BanPlayer(CCSPlayerController? player, CCSPlayerController? issuer, string reason, int time = 0)
|
public async Task BanPlayer(PlayerInfo player, PlayerInfo issuer, string reason, int time = 0)
|
||||||
{
|
{
|
||||||
if (player == null || !player.IsValid || player.AuthorizedSteamID == null) return;
|
|
||||||
|
|
||||||
DateTime now = DateTime.Now;
|
DateTime now = DateTime.Now;
|
||||||
DateTime futureTime = now.AddMinutes(time);
|
DateTime futureTime = now.AddMinutes(time);
|
||||||
|
|
||||||
@@ -30,11 +24,11 @@ namespace CS2_SimpleAdmin
|
|||||||
|
|
||||||
await connection.ExecuteAsync(sql, new
|
await connection.ExecuteAsync(sql, new
|
||||||
{
|
{
|
||||||
playerSteamid = player.AuthorizedSteamID.SteamId64.ToString(),
|
playerSteamid = player.SteamId,
|
||||||
playerName = player.PlayerName,
|
playerName = player.Name,
|
||||||
playerIp = player.IpAddress!.Split(":")[0],
|
playerIp = player.IpAddress,
|
||||||
adminSteamid = issuer == null ? "Console" : issuer.AuthorizedSteamID?.SteamId64.ToString(),
|
adminSteamid = issuer.SteamId == null ? "Console" : issuer.SteamId,
|
||||||
adminName = issuer == null ? "Console" : issuer.PlayerName,
|
adminName = issuer.Name == null ? "Console" : issuer.Name,
|
||||||
banReason = reason,
|
banReason = reason,
|
||||||
duration = time,
|
duration = time,
|
||||||
ends = futureTime,
|
ends = futureTime,
|
||||||
@@ -42,7 +36,7 @@ namespace CS2_SimpleAdmin
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task AddBanBySteamid(string playerSteamId, CCSPlayerController? issuer, string reason, int time = 0)
|
public async Task AddBanBySteamid(string playerSteamId, PlayerInfo issuer, string reason, int time = 0)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(playerSteamId)) return;
|
if (string.IsNullOrEmpty(playerSteamId)) return;
|
||||||
|
|
||||||
@@ -58,8 +52,8 @@ namespace CS2_SimpleAdmin
|
|||||||
await connection.ExecuteAsync(sql, new
|
await connection.ExecuteAsync(sql, new
|
||||||
{
|
{
|
||||||
playerSteamid = playerSteamId,
|
playerSteamid = playerSteamId,
|
||||||
adminSteamid = issuer == null ? "Console" : issuer.AuthorizedSteamID?.SteamId64.ToString(),
|
adminSteamid = issuer.SteamId == null ? "Console" : issuer.SteamId,
|
||||||
adminName = issuer == null ? "Console" : issuer.PlayerName,
|
adminName = issuer.Name == null ? "Console" : issuer.Name,
|
||||||
banReason = reason,
|
banReason = reason,
|
||||||
duration = time,
|
duration = time,
|
||||||
ends = futureTime,
|
ends = futureTime,
|
||||||
@@ -67,7 +61,7 @@ namespace CS2_SimpleAdmin
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task AddBanByIp(string playerIp, CCSPlayerController? issuer, string reason, int time = 0)
|
public async Task AddBanByIp(string playerIp, PlayerInfo issuer, string reason, int time = 0)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(playerIp)) return;
|
if (string.IsNullOrEmpty(playerIp)) return;
|
||||||
|
|
||||||
@@ -83,8 +77,8 @@ namespace CS2_SimpleAdmin
|
|||||||
await connection.ExecuteAsync(sql, new
|
await connection.ExecuteAsync(sql, new
|
||||||
{
|
{
|
||||||
playerIp,
|
playerIp,
|
||||||
adminSteamid = issuer == null ? "Console" : issuer?.AuthorizedSteamID?.SteamId64.ToString(),
|
adminSteamid = issuer.SteamId == null ? "Console" : issuer.SteamId,
|
||||||
adminName = issuer == null ? "Console" : issuer.PlayerName,
|
adminName = issuer.Name == null ? "Console" : issuer.Name,
|
||||||
banReason = reason,
|
banReason = reason,
|
||||||
duration = time,
|
duration = time,
|
||||||
ends = futureTime,
|
ends = futureTime,
|
||||||
@@ -92,7 +86,7 @@ namespace CS2_SimpleAdmin
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<bool> IsPlayerBanned(string steamId, string? ipAddress = null)
|
public async Task<bool> IsPlayerBanned(PlayerInfo player)
|
||||||
{
|
{
|
||||||
DateTime now = DateTime.Now;
|
DateTime now = DateTime.Now;
|
||||||
|
|
||||||
@@ -103,13 +97,13 @@ namespace CS2_SimpleAdmin
|
|||||||
await using var connection = _dbConnection;
|
await using var connection = _dbConnection;
|
||||||
await connection.OpenAsync();
|
await connection.OpenAsync();
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(ipAddress))
|
if (!string.IsNullOrEmpty(player.IpAddress))
|
||||||
{
|
{
|
||||||
banCount = await connection.ExecuteScalarAsync<int>(sql, new { PlayerSteamID = steamId, PlayerIP = ipAddress, CurrentTime = now });
|
banCount = await connection.ExecuteScalarAsync<int>(sql, new { PlayerSteamID = player.SteamId, PlayerIP = player.IpAddress, CurrentTime = now });
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
banCount = await connection.ExecuteScalarAsync<int>(sql, new { PlayerSteamID = steamId, PlayerIP = DBNull.Value, CurrentTime = now });
|
banCount = await connection.ExecuteScalarAsync<int>(sql, new { PlayerSteamID = player.SteamId, PlayerIP = DBNull.Value, CurrentTime = now });
|
||||||
}
|
}
|
||||||
|
|
||||||
return banCount > 0;
|
return banCount > 0;
|
||||||
@@ -137,30 +131,5 @@ namespace CS2_SimpleAdmin
|
|||||||
string sql = "UPDATE sa_bans SET status = 'EXPIRED' WHERE status = 'ACTIVE' AND `duration` > 0 AND ends <= @CurrentTime";
|
string sql = "UPDATE sa_bans SET status = 'EXPIRED' WHERE status = 'ACTIVE' AND `duration` > 0 AND ends <= @CurrentTime";
|
||||||
await connection.ExecuteAsync(sql, new { CurrentTime = DateTime.Now });
|
await connection.ExecuteAsync(sql, new { CurrentTime = DateTime.Now });
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task CheckBan(CCSPlayerController? player)
|
|
||||||
{
|
|
||||||
if (player == null || !player.IsValid || player.AuthorizedSteamID == null) return;
|
|
||||||
|
|
||||||
string steamId = player.AuthorizedSteamID.SteamId64.ToString();
|
|
||||||
string? ipAddress = player.IpAddress?.Split(":")[0];
|
|
||||||
|
|
||||||
bool isBanned = false;
|
|
||||||
|
|
||||||
if (ipAddress != null)
|
|
||||||
{
|
|
||||||
isBanned = await IsPlayerBanned(steamId, ipAddress);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
isBanned = await IsPlayerBanned(steamId);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isBanned)
|
|
||||||
{
|
|
||||||
Helper.KickPlayer(player.UserId, "Banned");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ using MySqlConnector;
|
|||||||
using System.Collections.Concurrent;
|
using System.Collections.Concurrent;
|
||||||
|
|
||||||
namespace CS2_SimpleAdmin;
|
namespace CS2_SimpleAdmin;
|
||||||
[MinimumApiVersion(98)]
|
[MinimumApiVersion(101)]
|
||||||
public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdminConfig>
|
public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdminConfig>
|
||||||
{
|
{
|
||||||
public static ConcurrentBag<int> gaggedPlayers = new ConcurrentBag<int>();
|
public static ConcurrentBag<int> gaggedPlayers = new ConcurrentBag<int>();
|
||||||
@@ -22,7 +22,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 => "";
|
public override string ModuleDescription => "";
|
||||||
public override string ModuleAuthor => "daffyy";
|
public override string ModuleAuthor => "daffyy";
|
||||||
public override string ModuleVersion => "1.0.4b";
|
public override string ModuleVersion => "1.0.4c";
|
||||||
|
|
||||||
public CS2_SimpleAdminConfig Config { get; set; } = new();
|
public CS2_SimpleAdminConfig Config { get; set; } = new();
|
||||||
|
|
||||||
@@ -138,12 +138,11 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdmin
|
|||||||
if (command.ArgCount >= 2)
|
if (command.ArgCount >= 2)
|
||||||
{
|
{
|
||||||
player!.PrintToCenter($"{Config.Messages.PlayerKickMessage}".Replace("{REASON}", reason).Replace("{ADMIN}", caller?.PlayerName == null ? "Console" : caller.PlayerName));
|
player!.PrintToCenter($"{Config.Messages.PlayerKickMessage}".Replace("{REASON}", reason).Replace("{ADMIN}", caller?.PlayerName == null ? "Console" : caller.PlayerName));
|
||||||
AddTimer(Config.KickTime, () => Helper.KickPlayer(player!.UserId, reason));
|
AddTimer(Config.KickTime, () => Helper.KickPlayer((ushort)player.UserId!, reason));
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
AddTimer(Config.KickTime, () => Helper.KickPlayer(player!.UserId));
|
AddTimer(Config.KickTime, () => Helper.KickPlayer((ushort)player.UserId!));
|
||||||
}
|
}
|
||||||
|
|
||||||
Server.PrintToChatAll(Helper.ReplaceTags($" {Config.Prefix} {Config.Messages.AdminKickMessage}".Replace("{REASON}", reason).Replace("{ADMIN}", caller?.PlayerName == null ? "Console" : caller.PlayerName).Replace("{PLAYER}", player.PlayerName)));
|
Server.PrintToChatAll(Helper.ReplaceTags($" {Config.Prefix} {Config.Messages.AdminKickMessage}".Replace("{REASON}", reason).Replace("{ADMIN}", caller?.PlayerName == null ? "Console" : caller.PlayerName).Replace("{PLAYER}", player.PlayerName)));
|
||||||
@@ -162,14 +161,30 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdmin
|
|||||||
int time = 0;
|
int time = 0;
|
||||||
string reason = "Unknown";
|
string reason = "Unknown";
|
||||||
|
|
||||||
MuteManager _muteManager = new(dbConnectionString);
|
|
||||||
|
|
||||||
int.TryParse(command.GetArg(2), out time);
|
int.TryParse(command.GetArg(2), out time);
|
||||||
|
|
||||||
if (command.ArgCount >= 3)
|
if (command.ArgCount >= 3)
|
||||||
reason = command.GetArg(3);
|
reason = command.GetArg(3);
|
||||||
|
|
||||||
_ = _muteManager.MutePlayer(player, caller, reason, time, 0);
|
PlayerInfo playerInfo = new PlayerInfo
|
||||||
|
{
|
||||||
|
SteamId = player?.AuthorizedSteamID?.SteamId64.ToString(),
|
||||||
|
Name = player?.PlayerName,
|
||||||
|
IpAddress = player?.IpAddress?.Split(":")[0]
|
||||||
|
};
|
||||||
|
|
||||||
|
PlayerInfo adminInfo = new PlayerInfo
|
||||||
|
{
|
||||||
|
SteamId = caller?.AuthorizedSteamID?.SteamId64.ToString(),
|
||||||
|
Name = caller?.PlayerName,
|
||||||
|
IpAddress = caller?.IpAddress?.Split(":")[0]
|
||||||
|
};
|
||||||
|
|
||||||
|
Task.Run(async () =>
|
||||||
|
{
|
||||||
|
MuteManager _muteManager = new(dbConnectionString);
|
||||||
|
await _muteManager.MutePlayer(playerInfo, adminInfo, reason, time);
|
||||||
|
});
|
||||||
|
|
||||||
if (TagsDetected)
|
if (TagsDetected)
|
||||||
NativeAPI.IssueServerCommand($"css_tag_mute {player!.Index.ToString()}");
|
NativeAPI.IssueServerCommand($"css_tag_mute {player!.Index.ToString()}");
|
||||||
@@ -184,8 +199,9 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdmin
|
|||||||
if (player == null || !player.IsValid || player.AuthorizedSteamID == null) return;
|
if (player == null || !player.IsValid || player.AuthorizedSteamID == null) return;
|
||||||
|
|
||||||
if (TagsDetected)
|
if (TagsDetected)
|
||||||
NativeAPI.IssueServerCommand($"css_tag_unmute {player.Index.ToString()}");
|
NativeAPI.IssueServerCommand($"css_tag_unmute {player.Index}");
|
||||||
|
|
||||||
|
MuteManager _muteManager = new(dbConnectionString);
|
||||||
_ = _muteManager.UnmutePlayer(player.AuthorizedSteamID.SteamId64.ToString(), 0);
|
_ = _muteManager.UnmutePlayer(player.AuthorizedSteamID.SteamId64.ToString(), 0);
|
||||||
}, CounterStrikeSharp.API.Modules.Timers.TimerFlags.STOP_ON_MAPCHANGE);
|
}, CounterStrikeSharp.API.Modules.Timers.TimerFlags.STOP_ON_MAPCHANGE);
|
||||||
}
|
}
|
||||||
@@ -229,7 +245,14 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdmin
|
|||||||
if (command.ArgCount >= 3)
|
if (command.ArgCount >= 3)
|
||||||
reason = command.GetArg(3);
|
reason = command.GetArg(3);
|
||||||
|
|
||||||
_ = _muteManager.AddMuteBySteamid(steamid, caller, reason, time, 0);
|
PlayerInfo adminInfo = new PlayerInfo
|
||||||
|
{
|
||||||
|
SteamId = caller?.AuthorizedSteamID?.SteamId64.ToString(),
|
||||||
|
Name = caller?.PlayerName,
|
||||||
|
IpAddress = caller?.IpAddress?.Split(":")[0]
|
||||||
|
};
|
||||||
|
|
||||||
|
_ = _muteManager.AddMuteBySteamid(steamid, adminInfo, reason, time, 0);
|
||||||
|
|
||||||
List<CCSPlayerController> matches = Helper.GetPlayerFromSteamid64(steamid);
|
List<CCSPlayerController> matches = Helper.GetPlayerFromSteamid64(steamid);
|
||||||
if (matches.Count == 1)
|
if (matches.Count == 1)
|
||||||
@@ -360,6 +383,7 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdmin
|
|||||||
{
|
{
|
||||||
if (!GetTarget(command, out var player))
|
if (!GetTarget(command, out var player))
|
||||||
return;
|
return;
|
||||||
|
if (player == null || !player.IsValid || player.AuthorizedSteamID == null) return;
|
||||||
if (command.ArgCount < 2)
|
if (command.ArgCount < 2)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -368,14 +392,30 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdmin
|
|||||||
|
|
||||||
player!.Pawn.Value!.Freeze();
|
player!.Pawn.Value!.Freeze();
|
||||||
|
|
||||||
BanManager _banManager = new(dbConnectionString);
|
|
||||||
|
|
||||||
int.TryParse(command.GetArg(2), out time);
|
int.TryParse(command.GetArg(2), out time);
|
||||||
|
|
||||||
if (command.ArgCount >= 3)
|
if (command.ArgCount >= 3)
|
||||||
reason = command.GetArg(3);
|
reason = command.GetArg(3);
|
||||||
|
|
||||||
_ = _banManager.BanPlayer(player, caller, reason, time);
|
PlayerInfo playerInfo = new PlayerInfo
|
||||||
|
{
|
||||||
|
SteamId = player?.AuthorizedSteamID?.SteamId64.ToString(),
|
||||||
|
Name = player?.PlayerName,
|
||||||
|
IpAddress = player?.IpAddress?.Split(":")[0]
|
||||||
|
};
|
||||||
|
|
||||||
|
PlayerInfo adminInfo = new PlayerInfo
|
||||||
|
{
|
||||||
|
SteamId = caller?.AuthorizedSteamID?.SteamId64.ToString(),
|
||||||
|
Name = caller?.PlayerName,
|
||||||
|
IpAddress = caller?.IpAddress?.Split(":")[0]
|
||||||
|
};
|
||||||
|
|
||||||
|
Task.Run(async () =>
|
||||||
|
{
|
||||||
|
BanManager _banManager = new(dbConnectionString);
|
||||||
|
await _banManager.BanPlayer(playerInfo, adminInfo, reason, time);
|
||||||
|
});
|
||||||
|
|
||||||
if (time == 0)
|
if (time == 0)
|
||||||
{
|
{
|
||||||
@@ -388,7 +428,7 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdmin
|
|||||||
Server.PrintToChatAll(Helper.ReplaceTags($" {Config.Prefix} {Config.Messages.AdminBanMessageTime}".Replace("{REASON}", reason).Replace("{TIME}", time.ToString()).Replace("{ADMIN}", caller?.PlayerName == null ? "Console" : caller.PlayerName).Replace("{PLAYER}", player.PlayerName)));
|
Server.PrintToChatAll(Helper.ReplaceTags($" {Config.Prefix} {Config.Messages.AdminBanMessageTime}".Replace("{REASON}", reason).Replace("{TIME}", time.ToString()).Replace("{ADMIN}", caller?.PlayerName == null ? "Console" : caller.PlayerName).Replace("{PLAYER}", player.PlayerName)));
|
||||||
}
|
}
|
||||||
|
|
||||||
AddTimer(Config.KickTime, () => Helper.KickPlayer(player!.UserId));
|
AddTimer(Config.KickTime, () => Helper.KickPlayer((ushort)player.UserId!));
|
||||||
}
|
}
|
||||||
|
|
||||||
[ConsoleCommand("css_addban")]
|
[ConsoleCommand("css_addban")]
|
||||||
@@ -418,7 +458,18 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdmin
|
|||||||
if (command.ArgCount >= 3)
|
if (command.ArgCount >= 3)
|
||||||
reason = command.GetArg(3);
|
reason = command.GetArg(3);
|
||||||
|
|
||||||
_ = _banManager.AddBanBySteamid(steamid, caller, reason, time);
|
PlayerInfo adminInfo = new PlayerInfo
|
||||||
|
{
|
||||||
|
SteamId = caller?.AuthorizedSteamID?.SteamId64.ToString(),
|
||||||
|
Name = caller?.PlayerName,
|
||||||
|
IpAddress = caller?.IpAddress?.Split(":")[0]
|
||||||
|
};
|
||||||
|
|
||||||
|
Task.Run(async () =>
|
||||||
|
{
|
||||||
|
BanManager _banManager = new(dbConnectionString);
|
||||||
|
await _banManager.AddBanBySteamid(steamid, adminInfo, reason, time);
|
||||||
|
});
|
||||||
|
|
||||||
List<CCSPlayerController> matches = Helper.GetPlayerFromSteamid64(steamid);
|
List<CCSPlayerController> matches = Helper.GetPlayerFromSteamid64(steamid);
|
||||||
if (matches.Count == 1)
|
if (matches.Count == 1)
|
||||||
@@ -439,7 +490,7 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdmin
|
|||||||
Server.PrintToChatAll(Helper.ReplaceTags($" {Config.Prefix} {Config.Messages.AdminBanMessageTime}".Replace("{REASON}", reason).Replace("{TIME}", time.ToString()).Replace("{ADMIN}", caller?.PlayerName == null ? "Console" : caller.PlayerName).Replace("{PLAYER}", player.PlayerName)));
|
Server.PrintToChatAll(Helper.ReplaceTags($" {Config.Prefix} {Config.Messages.AdminBanMessageTime}".Replace("{REASON}", reason).Replace("{TIME}", time.ToString()).Replace("{ADMIN}", caller?.PlayerName == null ? "Console" : caller.PlayerName).Replace("{PLAYER}", player.PlayerName)));
|
||||||
}
|
}
|
||||||
|
|
||||||
AddTimer(Config.KickTime, () => Helper.KickPlayer(player.UserId));
|
AddTimer(Config.KickTime, () => Helper.KickPlayer((ushort)player.UserId!));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
command.ReplyToCommand($"Banned player with steamid {steamid}.");
|
command.ReplyToCommand($"Banned player with steamid {steamid}.");
|
||||||
@@ -465,15 +516,24 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdmin
|
|||||||
int time = 0;
|
int time = 0;
|
||||||
string reason = "Unknown";
|
string reason = "Unknown";
|
||||||
|
|
||||||
BanManager _banManager = new(dbConnectionString);
|
PlayerInfo adminInfo = new PlayerInfo
|
||||||
|
{
|
||||||
|
SteamId = caller?.AuthorizedSteamID?.SteamId64.ToString(),
|
||||||
|
Name = caller?.PlayerName,
|
||||||
|
IpAddress = caller?.IpAddress?.Split(":")[0]
|
||||||
|
};
|
||||||
|
|
||||||
|
Task.Run(async () =>
|
||||||
|
{
|
||||||
|
BanManager _banManager = new(dbConnectionString);
|
||||||
|
await _banManager.AddBanByIp(ipAddress, adminInfo, reason, time);
|
||||||
|
});
|
||||||
|
|
||||||
int.TryParse(command.GetArg(2), out time);
|
int.TryParse(command.GetArg(2), out time);
|
||||||
|
|
||||||
if (command.ArgCount >= 3)
|
if (command.ArgCount >= 3)
|
||||||
reason = command.GetArg(3);
|
reason = command.GetArg(3);
|
||||||
|
|
||||||
_ = _banManager.AddBanByIp(ipAddress, caller, reason, time);
|
|
||||||
|
|
||||||
List<CCSPlayerController> matches = Helper.GetPlayerFromIp(ipAddress);
|
List<CCSPlayerController> matches = Helper.GetPlayerFromIp(ipAddress);
|
||||||
if (matches.Count == 1)
|
if (matches.Count == 1)
|
||||||
{
|
{
|
||||||
@@ -493,9 +553,10 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdmin
|
|||||||
Server.PrintToChatAll(Helper.ReplaceTags($" {Config.Prefix} {Config.Messages.AdminBanMessageTime}".Replace("{REASON}", reason).Replace("{TIME}", time.ToString()).Replace("{ADMIN}", caller?.PlayerName == null ? "Console" : caller.PlayerName).Replace("{PLAYER}", player.PlayerName)));
|
Server.PrintToChatAll(Helper.ReplaceTags($" {Config.Prefix} {Config.Messages.AdminBanMessageTime}".Replace("{REASON}", reason).Replace("{TIME}", time.ToString()).Replace("{ADMIN}", caller?.PlayerName == null ? "Console" : caller.PlayerName).Replace("{PLAYER}", player.PlayerName)));
|
||||||
}
|
}
|
||||||
|
|
||||||
AddTimer(Config.KickTime, () => Helper.KickPlayer(player.UserId));
|
AddTimer(Config.KickTime, () => Helper.KickPlayer((ushort)player.UserId!, "Banned"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
command.ReplyToCommand($"Banned player with IP address {ipAddress}.");
|
command.ReplyToCommand($"Banned player with IP address {ipAddress}.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
71
Events.cs
71
Events.cs
@@ -35,7 +35,7 @@ namespace CS2_SimpleAdmin
|
|||||||
|
|
||||||
CCSPlayerController? player = Utilities.GetPlayerFromIndex(playerIndex);
|
CCSPlayerController? player = Utilities.GetPlayerFromIndex(playerIndex);
|
||||||
|
|
||||||
if (player.AuthorizedSteamID == null)
|
if (player == null || !player.IsValid || player.AuthorizedSteamID == null)
|
||||||
{
|
{
|
||||||
AddTimer(3.0f, () =>
|
AddTimer(3.0f, () =>
|
||||||
{
|
{
|
||||||
@@ -44,11 +44,72 @@ namespace CS2_SimpleAdmin
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
BanManager _banManager = new(dbConnectionString);
|
PlayerInfo playerInfo = new PlayerInfo
|
||||||
MuteManager _muteManager = new(dbConnectionString);
|
{
|
||||||
|
UserId = player.UserId,
|
||||||
|
Index = (int)player.Index,
|
||||||
|
SteamId = player?.AuthorizedSteamID?.SteamId64.ToString(),
|
||||||
|
Name = player?.PlayerName,
|
||||||
|
IpAddress = player?.IpAddress?.Split(":")[0]
|
||||||
|
};
|
||||||
|
|
||||||
|
Task.Run(async () =>
|
||||||
|
{
|
||||||
|
if (player == null) return;
|
||||||
|
BanManager _banManager = new(dbConnectionString);
|
||||||
|
bool isBanned = await _banManager.IsPlayerBanned(playerInfo);
|
||||||
|
|
||||||
|
MuteManager _muteManager = new(dbConnectionString);
|
||||||
|
List<dynamic> activeMutes = await _muteManager.IsPlayerMuted(playerInfo.SteamId);
|
||||||
|
|
||||||
|
Server.NextFrame(() =>
|
||||||
|
{
|
||||||
|
if (player == null) return;
|
||||||
|
if (isBanned)
|
||||||
|
{
|
||||||
|
Helper.KickPlayer((ushort)player.UserId!, "Banned");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (activeMutes.Count > 0)
|
||||||
|
{
|
||||||
|
foreach (var mute in activeMutes)
|
||||||
|
{
|
||||||
|
string muteType = mute.type;
|
||||||
|
TimeSpan duration = mute.ends - mute.created;
|
||||||
|
int durationInSeconds = (int)duration.TotalSeconds;
|
||||||
|
|
||||||
|
if (muteType == "GAG")
|
||||||
|
{
|
||||||
|
if (!gaggedPlayers.Any(index => index == player.Index))
|
||||||
|
gaggedPlayers.Add((int)player.Index);
|
||||||
|
|
||||||
|
if (TagsDetected)
|
||||||
|
NativeAPI.IssueServerCommand($"css_tag_mute {player.Index}");
|
||||||
|
|
||||||
|
/*
|
||||||
|
CCSPlayerController currentPlayer = player;
|
||||||
|
|
||||||
|
if (mute.duration == 0 || durationInSeconds >= 1800) continue;
|
||||||
|
|
||||||
|
await Task.Delay(TimeSpan.FromSeconds(durationInSeconds));
|
||||||
|
|
||||||
|
if (currentPlayer != null && currentPlayer.IsValid)
|
||||||
|
{
|
||||||
|
NativeAPI.IssueServerCommand($"css_tag_unmute {currentPlayer.Index.ToString()}");
|
||||||
|
await UnmutePlayer(currentPlayer.AuthorizedSteamID.SteamId64.ToString(), 0);
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Mic mute
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
_ = _banManager.CheckBan(player);
|
|
||||||
_ = _muteManager.CheckMute(player);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnClientDisconnect(int playerSlot)
|
private void OnClientDisconnect(int playerSlot)
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
using CounterStrikeSharp.API.Core;
|
using CounterStrikeSharp.API.Core;
|
||||||
using CounterStrikeSharp.API;
|
using CounterStrikeSharp.API;
|
||||||
using MySqlConnector;
|
|
||||||
using CounterStrikeSharp.API.Modules.Utils;
|
using CounterStrikeSharp.API.Modules.Utils;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
@@ -66,7 +65,7 @@ namespace CS2_SimpleAdmin
|
|||||||
return player?.IsValid == true ? TargetResult.Single : TargetResult.None;
|
return player?.IsValid == true ? TargetResult.Single : TargetResult.None;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void KickPlayer(int? userId, string? reason = null)
|
public static void KickPlayer(ushort userId, string? reason = null)
|
||||||
{
|
{
|
||||||
NativeAPI.IssueServerCommand($"kickid {userId} {reason}");
|
NativeAPI.IssueServerCommand($"kickid {userId} {reason}");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,9 +14,9 @@ namespace CS2_SimpleAdmin
|
|||||||
_dbConnection = new MySqlConnection(connectionString);
|
_dbConnection = new MySqlConnection(connectionString);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task MutePlayer(CCSPlayerController? player, CCSPlayerController? 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.IsValid || player.AuthorizedSteamID == null) return;
|
if (player == null || player.SteamId == null) return;
|
||||||
|
|
||||||
await using var connection = _dbConnection;
|
await using var connection = _dbConnection;
|
||||||
await connection.OpenAsync();
|
await connection.OpenAsync();
|
||||||
@@ -33,24 +33,19 @@ namespace CS2_SimpleAdmin
|
|||||||
|
|
||||||
await connection.ExecuteAsync(sql, new
|
await connection.ExecuteAsync(sql, new
|
||||||
{
|
{
|
||||||
playerSteamid = player.AuthorizedSteamID.SteamId64.ToString(),
|
playerSteamid = player.SteamId,
|
||||||
playerName = player.PlayerName,
|
playerName = player.Name,
|
||||||
adminSteamid = issuer == null ? "Console" : issuer?.AuthorizedSteamID?.SteamId64.ToString(),
|
adminSteamid = issuer.SteamId == null ? "Console" : issuer.SteamId,
|
||||||
adminName = issuer == null ? "Console" : issuer.PlayerName,
|
adminName = issuer.SteamId == null ? "Console" : issuer.Name,
|
||||||
banReason = reason,
|
banReason = reason,
|
||||||
duration = time,
|
duration = time,
|
||||||
ends = futureTime,
|
ends = futureTime,
|
||||||
created = now,
|
created = now,
|
||||||
type = muteType,
|
type = muteType,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (connection.State != ConnectionState.Closed)
|
|
||||||
{
|
|
||||||
connection.Close();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task AddMuteBySteamid(string playerSteamId, CCSPlayerController? 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;
|
||||||
|
|
||||||
@@ -70,19 +65,14 @@ namespace CS2_SimpleAdmin
|
|||||||
await connection.ExecuteAsync(sql, new
|
await connection.ExecuteAsync(sql, new
|
||||||
{
|
{
|
||||||
playerSteamid = playerSteamId,
|
playerSteamid = playerSteamId,
|
||||||
adminSteamid = issuer == null ? "Console" : issuer?.AuthorizedSteamID?.SteamId64.ToString(),
|
adminSteamid = issuer.SteamId == null ? "Console" : issuer.SteamId,
|
||||||
adminName = issuer == null ? "Console" : issuer.PlayerName,
|
adminName = issuer.Name == null ? "Console" : issuer.Name,
|
||||||
banReason = reason,
|
banReason = reason,
|
||||||
duration = time,
|
duration = time,
|
||||||
ends = futureTime,
|
ends = futureTime,
|
||||||
created = now,
|
created = now,
|
||||||
type = muteType
|
type = muteType
|
||||||
});
|
});
|
||||||
|
|
||||||
if (connection.State != ConnectionState.Closed)
|
|
||||||
{
|
|
||||||
connection.Close();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<List<dynamic>> IsPlayerMuted(string steamId)
|
public async Task<List<dynamic>> IsPlayerMuted(string steamId)
|
||||||
@@ -95,11 +85,6 @@ namespace CS2_SimpleAdmin
|
|||||||
string sql = "SELECT * FROM sa_mutes WHERE player_steamid = @PlayerSteamID AND status = 'ACTIVE' AND (duration = 0 OR ends > @CurrentTime)";
|
string sql = "SELECT * FROM sa_mutes WHERE player_steamid = @PlayerSteamID AND status = 'ACTIVE' AND (duration = 0 OR ends > @CurrentTime)";
|
||||||
var activeMutes = (await connection.QueryAsync(sql, new { PlayerSteamID = steamId, CurrentTime = now })).ToList();
|
var activeMutes = (await connection.QueryAsync(sql, new { PlayerSteamID = steamId, CurrentTime = now })).ToList();
|
||||||
|
|
||||||
if (connection.State != ConnectionState.Closed)
|
|
||||||
{
|
|
||||||
connection.Close();
|
|
||||||
}
|
|
||||||
|
|
||||||
return activeMutes;
|
return activeMutes;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -134,11 +119,6 @@ namespace CS2_SimpleAdmin
|
|||||||
|
|
||||||
string sqlUnban = "UPDATE sa_mutes SET status = 'UNMUTED' WHERE (player_steamid = @pattern OR player_name = @pattern) AND type = @muteType AND status = 'ACTIVE'";
|
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 });
|
await connection.ExecuteAsync(sqlUnban, new { pattern = playerPattern, muteType });
|
||||||
|
|
||||||
if (connection.State != ConnectionState.Closed)
|
|
||||||
{
|
|
||||||
connection.Close();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task ExpireOldMutes()
|
public async Task ExpireOldMutes()
|
||||||
@@ -148,18 +128,13 @@ namespace CS2_SimpleAdmin
|
|||||||
|
|
||||||
string sql = "UPDATE sa_mutes SET status = 'EXPIRED' WHERE status = 'ACTIVE' AND `duration` > 0 AND ends <= @CurrentTime";
|
string sql = "UPDATE sa_mutes SET status = 'EXPIRED' WHERE status = 'ACTIVE' AND `duration` > 0 AND ends <= @CurrentTime";
|
||||||
await connection.ExecuteAsync(sql, new { CurrentTime = DateTime.Now });
|
await connection.ExecuteAsync(sql, new { CurrentTime = DateTime.Now });
|
||||||
|
|
||||||
if (connection.State != ConnectionState.Closed)
|
|
||||||
{
|
|
||||||
connection.Close();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task CheckMute(CCSPlayerController? player)
|
public async Task CheckMute(PlayerInfo player)
|
||||||
{
|
{
|
||||||
if (player == null || !player.IsValid || player.AuthorizedSteamID == null) return;
|
if (player.Index == null) return;
|
||||||
|
|
||||||
string steamId = player.AuthorizedSteamID.SteamId64.ToString();
|
string steamId = player.SteamId!;
|
||||||
List<dynamic> activeMutes = await IsPlayerMuted(steamId);
|
List<dynamic> activeMutes = await IsPlayerMuted(steamId);
|
||||||
|
|
||||||
if (activeMutes.Count > 0)
|
if (activeMutes.Count > 0)
|
||||||
@@ -172,12 +147,13 @@ namespace CS2_SimpleAdmin
|
|||||||
|
|
||||||
if (muteType == "GAG")
|
if (muteType == "GAG")
|
||||||
{
|
{
|
||||||
if (!CS2_SimpleAdmin.gaggedPlayers.Contains((int)player.Index))
|
if (!CS2_SimpleAdmin.gaggedPlayers.Any(index => index == player.Index))
|
||||||
CS2_SimpleAdmin.gaggedPlayers.Add((int)player.Index);
|
CS2_SimpleAdmin.gaggedPlayers.Add((int)player.Index);
|
||||||
|
|
||||||
if (CS2_SimpleAdmin.TagsDetected)
|
if (CS2_SimpleAdmin.TagsDetected)
|
||||||
NativeAPI.IssueServerCommand($"css_tag_mute {player!.Index.ToString()}");
|
NativeAPI.IssueServerCommand($"css_tag_mute {player!.Index.ToString()}");
|
||||||
|
|
||||||
|
/*
|
||||||
CCSPlayerController currentPlayer = player;
|
CCSPlayerController currentPlayer = player;
|
||||||
|
|
||||||
if (mute.duration == 0 || durationInSeconds >= 1800) continue;
|
if (mute.duration == 0 || durationInSeconds >= 1800) continue;
|
||||||
@@ -189,6 +165,7 @@ namespace CS2_SimpleAdmin
|
|||||||
NativeAPI.IssueServerCommand($"css_tag_unmute {currentPlayer.Index.ToString()}");
|
NativeAPI.IssueServerCommand($"css_tag_unmute {currentPlayer.Index.ToString()}");
|
||||||
await UnmutePlayer(currentPlayer.AuthorizedSteamID.SteamId64.ToString(), 0);
|
await UnmutePlayer(currentPlayer.AuthorizedSteamID.SteamId64.ToString(), 0);
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
17
PlayerInfo.cs
Normal file
17
PlayerInfo.cs
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace CS2_SimpleAdmin
|
||||||
|
{
|
||||||
|
public class PlayerInfo
|
||||||
|
{
|
||||||
|
public int? Index { get; set; }
|
||||||
|
public int? UserId { get; set; }
|
||||||
|
public string? SteamId { get; set; }
|
||||||
|
public string? Name { get; set; }
|
||||||
|
public string? IpAddress { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user