mirror of
https://github.com/daffyyyy/CS2-SimpleAdmin.git
synced 2026-02-17 18:39:07 +00:00
Added info about crashes with bots
This commit is contained in:
@@ -51,7 +51,7 @@ namespace CS2_SimpleAdmin
|
||||
{
|
||||
DateTime now = DateTime.Now;
|
||||
|
||||
using var connection = await _database.GetConnection();
|
||||
await using var connection = await _database.GetConnectionAsync();
|
||||
|
||||
string sql = "SELECT flags, immunity, ends FROM sa_admins WHERE player_steamid = @PlayerSteamID AND (ends IS NULL OR ends > @CurrentTime) AND (server_id IS NULL OR server_id = @serverid)";
|
||||
List<dynamic>? activeFlags = (await connection.QueryAsync(sql, new { PlayerSteamID = steamId, CurrentTime = now, serverid = CS2_SimpleAdmin.ServerId }))?.ToList();
|
||||
@@ -151,7 +151,7 @@ namespace CS2_SimpleAdmin
|
||||
|
||||
try
|
||||
{
|
||||
using var connection = await _database.GetConnection();
|
||||
await using var 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)";
|
||||
List<dynamic>? activeFlags = (await connection.QueryAsync(sql, new { CurrentTime = now, serverid = CS2_SimpleAdmin.ServerId }))?.ToList();
|
||||
@@ -244,7 +244,7 @@ namespace CS2_SimpleAdmin
|
||||
|
||||
//_adminCache.TryRemove(playerSteamId, out _);
|
||||
|
||||
using var connection = await _database.GetConnection();
|
||||
await using var connection = await _database.GetConnectionAsync();
|
||||
|
||||
string sql = "";
|
||||
|
||||
@@ -273,7 +273,7 @@ namespace CS2_SimpleAdmin
|
||||
else
|
||||
futureTime = null;
|
||||
|
||||
using var connection = await _database.GetConnection();
|
||||
await using var connection = await _database.GetConnectionAsync();
|
||||
|
||||
var sql = "INSERT INTO `sa_admins` (`player_steamid`, `player_name`, `flags`, `immunity`, `ends`, `created`, `server_id`) " +
|
||||
"VALUES (@playerSteamid, @playerName, @flags, @immunity, @ends, @created, @serverid)";
|
||||
@@ -296,7 +296,7 @@ namespace CS2_SimpleAdmin
|
||||
{
|
||||
try
|
||||
{
|
||||
using var connection = await _database.GetConnection();
|
||||
await using var connection = await _database.GetConnectionAsync();
|
||||
|
||||
string sql = "DELETE FROM sa_admins WHERE ends IS NOT NULL AND ends <= @CurrentTime";
|
||||
await connection.ExecuteAsync(sql, new { CurrentTime = DateTime.Now });
|
||||
|
||||
@@ -19,7 +19,7 @@ namespace CS2_SimpleAdmin
|
||||
DateTime now = DateTime.Now;
|
||||
DateTime futureTime = now.AddMinutes(time);
|
||||
|
||||
using var connection = await _database.GetConnection();
|
||||
await using var connection = await _database.GetConnectionAsync();
|
||||
|
||||
var sql = "INSERT INTO `sa_bans` (`player_steamid`, `player_name`, `player_ip`, `admin_steamid`, `admin_name`, `reason`, `duration`, `ends`, `created`, `server_id`) " +
|
||||
"VALUES (@playerSteamid, @playerName, @playerIp, @adminSteamid, @adminName, @banReason, @duration, @ends, @created, @serverid)";
|
||||
@@ -46,7 +46,7 @@ namespace CS2_SimpleAdmin
|
||||
DateTime now = DateTime.Now;
|
||||
DateTime futureTime = now.AddMinutes(time);
|
||||
|
||||
using var connection = await _database.GetConnection();
|
||||
await using var connection = await _database.GetConnectionAsync();
|
||||
|
||||
var sql = "INSERT INTO `sa_bans` (`player_steamid`, `admin_steamid`, `admin_name`, `reason`, `duration`, `ends`, `created`, `server_id`) " +
|
||||
"VALUES (@playerSteamid, @adminSteamid, @adminName, @banReason, @duration, @ends, @created, @serverid)";
|
||||
@@ -71,7 +71,7 @@ namespace CS2_SimpleAdmin
|
||||
DateTime now = DateTime.Now;
|
||||
DateTime futureTime = now.AddMinutes(time);
|
||||
|
||||
using var connection = await _database.GetConnection();
|
||||
await using var connection = await _database.GetConnectionAsync();
|
||||
|
||||
var sql = "INSERT INTO `sa_bans` (`player_ip`, `admin_steamid`, `admin_name`, `reason`, `duration`, `ends`, `created`, `server_id`) " +
|
||||
"VALUES (@playerIp, @adminSteamid, @adminName, @banReason, @duration, @ends, @created, @serverid)";
|
||||
@@ -91,18 +91,23 @@ namespace CS2_SimpleAdmin
|
||||
|
||||
public async Task<bool> IsPlayerBanned(PlayerInfo player)
|
||||
{
|
||||
if (player == null)
|
||||
if (player.SteamId == null && player.IpAddress == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
#if DEBUG
|
||||
if (CS2_SimpleAdmin._logger != null)
|
||||
CS2_SimpleAdmin._logger.LogCritical($"IsPlayerBanned for {player.Name}");
|
||||
#endif
|
||||
|
||||
DateTime currentTimeUtc = DateTime.UtcNow;
|
||||
string sql = "SELECT COUNT(*) FROM sa_bans WHERE (player_steamid = @PlayerSteamID OR player_ip = @PlayerIP) AND status = 'ACTIVE' AND (duration = 0 OR ends > @CurrentTime)";
|
||||
int banCount = 0;
|
||||
|
||||
try
|
||||
{
|
||||
using var connection = await _database.GetConnection();
|
||||
await using var connection = await _database.GetConnectionAsync();
|
||||
|
||||
var parameters = new
|
||||
{
|
||||
@@ -120,12 +125,13 @@ namespace CS2_SimpleAdmin
|
||||
|
||||
return banCount > 0;
|
||||
}
|
||||
|
||||
public async Task<int> GetPlayerBans(PlayerInfo player)
|
||||
{
|
||||
string sql = "SELECT COUNT(*) FROM sa_bans WHERE (player_steamid = @PlayerSteamID OR player_ip = @PlayerIP)";
|
||||
int banCount;
|
||||
|
||||
using var connection = await _database.GetConnection();
|
||||
await using var connection = await _database.GetConnectionAsync();
|
||||
|
||||
if (!string.IsNullOrEmpty(player.IpAddress))
|
||||
{
|
||||
@@ -146,7 +152,7 @@ namespace CS2_SimpleAdmin
|
||||
return;
|
||||
}
|
||||
|
||||
using var connection = await _database.GetConnection();
|
||||
await using var connection = await _database.GetConnectionAsync();
|
||||
|
||||
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 });
|
||||
@@ -156,7 +162,7 @@ namespace CS2_SimpleAdmin
|
||||
{
|
||||
try
|
||||
{
|
||||
using var connection = await _database.GetConnection();
|
||||
await using var connection = await _database.GetConnectionAsync();
|
||||
|
||||
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 });
|
||||
|
||||
@@ -89,7 +89,7 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdmin
|
||||
{
|
||||
try
|
||||
{
|
||||
using (var connection = await _database.GetConnection())
|
||||
using (var connection = await _database.GetConnectionAsync())
|
||||
{
|
||||
using var transaction = await connection.BeginTransactionAsync();
|
||||
|
||||
@@ -244,10 +244,10 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdmin
|
||||
|
||||
if (silentPlayers.Contains(caller.Slot))
|
||||
{
|
||||
silentPlayers = new ConcurrentBag<int>(silentPlayers.Where(item => item != caller.Slot));
|
||||
RemoveFromConcurrentBag(silentPlayers, caller.Slot);
|
||||
caller.PrintToChat($"You aren't hidden now!");
|
||||
caller.ChangeTeam(CsTeam.Spectator);
|
||||
if (Config.DiscordWebhook.Length > 0 && _localizer != null)
|
||||
if (Config.DiscordWebhook.Length > 0)
|
||||
_ = SendWebhookMessage($"{caller.PlayerName} isn't hidden now.");
|
||||
}
|
||||
else
|
||||
@@ -260,14 +260,11 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdmin
|
||||
caller.PlayerPawn.Value.CommitSuicide(true, false);
|
||||
|
||||
AddTimer(1.0f, () => { caller.ChangeTeam(CsTeam.Spectator); }, CounterStrikeSharp.API.Modules.Timers.TimerFlags.STOP_ON_MAPCHANGE);
|
||||
AddTimer(1.1f, () => { caller.ChangeTeam(CsTeam.None); }, CounterStrikeSharp.API.Modules.Timers.TimerFlags.STOP_ON_MAPCHANGE);
|
||||
AddTimer(1.15f, () => { caller.ChangeTeam(CsTeam.None); }, CounterStrikeSharp.API.Modules.Timers.TimerFlags.STOP_ON_MAPCHANGE);
|
||||
caller.PrintToChat($"You are hidden now!");
|
||||
if (Config.DiscordWebhook.Length > 0 && _localizer != null)
|
||||
if (Config.DiscordWebhook.Length > 0)
|
||||
_ = SendWebhookMessage($"{caller.PlayerName} is hidden now.");
|
||||
});
|
||||
Server.NextFrame(() =>
|
||||
{
|
||||
AddTimer(1.2f, () => { Server.ExecuteCommand("sv_disable_teamselect_menu 0"); });
|
||||
AddTimer(1.22f, () => { Server.ExecuteCommand("sv_disable_teamselect_menu 0"); });
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ namespace CS2_SimpleAdmin
|
||||
_dbConnectionString = dbConnectionString;
|
||||
}
|
||||
|
||||
public async Task<MySqlConnection> GetConnection()
|
||||
public async Task<MySqlConnection> GetConnectionAsync()
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
79
Events.cs
79
Events.cs
@@ -8,7 +8,6 @@ using Dapper;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System.Data;
|
||||
using System.Text;
|
||||
using static CounterStrikeSharp.API.Core.Listeners;
|
||||
|
||||
namespace CS2_SimpleAdmin;
|
||||
|
||||
@@ -18,10 +17,10 @@ public partial class CS2_SimpleAdmin
|
||||
{
|
||||
//RegisterListener<OnClientAuthorized>(OnClientAuthorized);
|
||||
//RegisterListener<OnClientConnect>(OnClientConnect);
|
||||
//RegisterListener<OnClientPutInServer>(OnClientPutInServer);
|
||||
RegisterListener<Listeners.OnClientPutInServer>(OnClientPutInServer);
|
||||
//RegisterListener<OnClientDisconnect>(OnClientDisconnect);
|
||||
//RegisterEventHandler<EventPlayerConnectFull>(OnPlayerFullConnect);
|
||||
RegisterListener<OnMapStart>(OnMapStart);
|
||||
RegisterListener<Listeners.OnMapStart>(OnMapStart);
|
||||
//RegisterEventHandler<EventPlayerHurt>(OnPlayerHurt);
|
||||
//RegisterEventHandler<EventRoundStart>(OnRoundStart);
|
||||
AddCommandListener("say", OnCommandSay);
|
||||
@@ -113,20 +112,17 @@ public partial class CS2_SimpleAdmin
|
||||
return HookResult.Continue;
|
||||
}
|
||||
|
||||
[GameEventHandler]
|
||||
public HookResult OnPlayerConnect(EventPlayerConnectFull @event, GameEventInfo info)
|
||||
public void OnClientPutInServer(int playerSlot)
|
||||
{
|
||||
CCSPlayerController? player = @event.Userid;
|
||||
CCSPlayerController? player = Utilities.GetPlayerFromSlot(playerSlot);
|
||||
#if DEBUG
|
||||
Logger.LogCritical("[OnPlayerConnect] Before check");
|
||||
#endif
|
||||
if (_database == null || player is null || !player.IsValid || player.UserId == null || player.SteamID.ToString().Length != 17 || !@event.Userid.PlayerPawn.IsValid || player.IsBot || player.IsHLTV)
|
||||
return HookResult.Continue;
|
||||
|
||||
#endif
|
||||
if (player is null || !player.IsValid || player.IsBot || player.IsHLTV) return;
|
||||
#if DEBUG
|
||||
Logger.LogCritical("[OnPlayerConnect] After Check");
|
||||
#endif
|
||||
|
||||
string? ipAddress = !string.IsNullOrEmpty(player.IpAddress) ? player.IpAddress.Split(":")[0] : null;
|
||||
|
||||
if (
|
||||
@@ -134,13 +130,13 @@ public partial class CS2_SimpleAdmin
|
||||
bannedPlayers.Contains(player.SteamID.ToString())
|
||||
)
|
||||
{
|
||||
Server.NextFrame(() =>
|
||||
{
|
||||
Helper.KickPlayer((ushort)player.UserId!, "Banned");
|
||||
});
|
||||
return HookResult.Continue;
|
||||
Helper.KickPlayer((ushort)player.UserId!, "Banned");
|
||||
return;
|
||||
}
|
||||
|
||||
if (_database == null)
|
||||
return;
|
||||
|
||||
PlayerInfo playerInfo = new PlayerInfo
|
||||
{
|
||||
UserId = player.UserId,
|
||||
@@ -151,13 +147,11 @@ public partial class CS2_SimpleAdmin
|
||||
IpAddress = ipAddress
|
||||
};
|
||||
|
||||
BanManager _banManager = new(_database, Config);
|
||||
MuteManager _muteManager = new(_database);
|
||||
|
||||
Task.Run(async () =>
|
||||
{
|
||||
BanManager _banManager = new(_database, Config);
|
||||
|
||||
MuteManager _muteManager = new(_database);
|
||||
List<dynamic> activeMutes = await _muteManager.IsPlayerMuted(playerInfo.SteamId);
|
||||
|
||||
if (await _banManager.IsPlayerBanned(playerInfo))
|
||||
{
|
||||
if (playerInfo.IpAddress != null && !bannedPlayers.Contains(playerInfo.IpAddress))
|
||||
@@ -175,6 +169,8 @@ public partial class CS2_SimpleAdmin
|
||||
return;
|
||||
}
|
||||
|
||||
List<dynamic> activeMutes = await _muteManager.IsPlayerMuted(playerInfo.SteamId);
|
||||
|
||||
if (activeMutes.Count > 0)
|
||||
{
|
||||
foreach (var mute in activeMutes)
|
||||
@@ -198,20 +194,39 @@ public partial class CS2_SimpleAdmin
|
||||
{
|
||||
Server.NextFrame(() =>
|
||||
{
|
||||
player.VoiceFlags = VoiceFlags.Muted;
|
||||
if (player.IsValid)
|
||||
player.VoiceFlags = VoiceFlags.Muted;
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
if (playerInfo.Slot.HasValue && !gaggedPlayers.Contains(playerInfo.Slot.Value))
|
||||
gaggedPlayers.Add(playerInfo.Slot.Value);
|
||||
|
||||
Server.NextFrame(() =>
|
||||
{
|
||||
if (player.IsValid)
|
||||
{
|
||||
if (TagsDetected)
|
||||
{
|
||||
Server.ExecuteCommand($"css_tag_mute {playerInfo.SteamId}");
|
||||
}
|
||||
player.VoiceFlags = VoiceFlags.Muted;
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return HookResult.Continue;
|
||||
return;
|
||||
}
|
||||
|
||||
[GameEventHandler]
|
||||
public HookResult OnPlayerDisconnect(EventPlayerDisconnect @event, GameEventInfo info)
|
||||
{
|
||||
if (@event.Userid is null || !@event.Userid.IsValid || @event.Userid.IsBot)
|
||||
if (@event.Userid is null || !@event.Userid.IsValid)
|
||||
return HookResult.Continue;
|
||||
|
||||
CCSPlayerController? player = @event.Userid;
|
||||
@@ -220,8 +235,7 @@ public partial class CS2_SimpleAdmin
|
||||
Logger.LogCritical("[OnClientDisconnect] Before");
|
||||
#endif
|
||||
|
||||
if (player == null || player.IsBot || player.IsHLTV || player.Connected == PlayerConnectedState.PlayerConnecting)
|
||||
return HookResult.Continue;
|
||||
if (player.IsBot || player.IsHLTV) return HookResult.Continue;
|
||||
|
||||
#if DEBUG
|
||||
Logger.LogCritical("[OnClientDisconnect] After Check");
|
||||
@@ -250,8 +264,9 @@ public partial class CS2_SimpleAdmin
|
||||
godPlayers.Clear();
|
||||
silentPlayers.Clear();
|
||||
|
||||
if (_database == null) return;
|
||||
_database = new(dbConnectionString);
|
||||
|
||||
if (_database == null) return;
|
||||
|
||||
AddTimer(60.0f, bannedPlayers.Clear, CounterStrikeSharp.API.Modules.Timers.TimerFlags.REPEAT | CounterStrikeSharp.API.Modules.Timers.TimerFlags.STOP_ON_MAPCHANGE);
|
||||
AddTimer(130.0f, async () =>
|
||||
@@ -284,7 +299,7 @@ public partial class CS2_SimpleAdmin
|
||||
AdminSQLManager _adminManager = new(_database);
|
||||
try
|
||||
{
|
||||
using (var connection = await _database.GetConnection())
|
||||
await using (var connection = await _database.GetConnectionAsync())
|
||||
{
|
||||
bool addressExists = await connection.ExecuteScalarAsync<bool>(
|
||||
"SELECT COUNT(*) FROM sa_servers WHERE address = @address",
|
||||
@@ -318,6 +333,16 @@ public partial class CS2_SimpleAdmin
|
||||
await _adminManager.GiveAllFlags();
|
||||
});
|
||||
}, CounterStrikeSharp.API.Modules.Timers.TimerFlags.STOP_ON_MAPCHANGE);
|
||||
|
||||
ConVar? botQuota = ConVar.Find("bot_quota");
|
||||
|
||||
if (botQuota != null && botQuota.GetPrimitiveValue<int>() > 0)
|
||||
{
|
||||
Logger.LogInformation("Due to bugs with bots (game bug), consider disabling bots by setting `bot_quota 0` in the gamemode config if your server crashes after a map change.");
|
||||
Logger.LogWarning("Due to bugs with bots (game bug), consider disabling bots by setting `bot_quota 0` in the gamemode config if your server crashes after a map change.");
|
||||
Logger.LogCritical("Due to bugs with bots (game bug), consider disabling bots by setting `bot_quota 0` in the gamemode config if your server crashes after a map change.");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
[GameEventHandler]
|
||||
|
||||
@@ -17,7 +17,7 @@ namespace CS2_SimpleAdmin
|
||||
{
|
||||
if (player == null || player.SteamId == null) return;
|
||||
|
||||
using var connection = await _database.GetConnection();
|
||||
await using var connection = await _database.GetConnectionAsync();
|
||||
|
||||
DateTime now = DateTime.Now;
|
||||
DateTime futureTime = now.AddMinutes(time);
|
||||
@@ -48,7 +48,7 @@ namespace CS2_SimpleAdmin
|
||||
{
|
||||
if (string.IsNullOrEmpty(playerSteamId)) return;
|
||||
|
||||
using var connection = await _database.GetConnection();
|
||||
await using var connection = await _database.GetConnectionAsync();
|
||||
|
||||
DateTime now = DateTime.Now;
|
||||
DateTime futureTime = now.AddMinutes(time);
|
||||
@@ -81,9 +81,14 @@ namespace CS2_SimpleAdmin
|
||||
return new List<dynamic>();
|
||||
}
|
||||
|
||||
#if DEBUG
|
||||
if (CS2_SimpleAdmin._logger != null)
|
||||
CS2_SimpleAdmin._logger.LogCritical($"IsPlayerMuted for {steamId}");
|
||||
#endif
|
||||
|
||||
try
|
||||
{
|
||||
using var connection = await _database.GetConnection();
|
||||
await using var connection = await _database.GetConnectionAsync();
|
||||
DateTime currentTimeUtc = DateTime.UtcNow;
|
||||
string sql = "SELECT * FROM sa_mutes WHERE player_steamid = @PlayerSteamID AND status = 'ACTIVE' AND (duration = 0 OR ends > @CurrentTime)";
|
||||
|
||||
@@ -99,7 +104,7 @@ namespace CS2_SimpleAdmin
|
||||
|
||||
public async Task<int> GetPlayerMutes(string steamId)
|
||||
{
|
||||
using var connection = await _database.GetConnection();
|
||||
await using var connection = await _database.GetConnectionAsync();
|
||||
|
||||
int muteCount;
|
||||
string sql = "SELECT COUNT(*) FROM sa_mutes WHERE player_steamid = @PlayerSteamID";
|
||||
@@ -116,7 +121,7 @@ namespace CS2_SimpleAdmin
|
||||
return;
|
||||
}
|
||||
|
||||
using var connection = await _database.GetConnection();
|
||||
await using var connection = await _database.GetConnectionAsync();
|
||||
|
||||
if (type == 2)
|
||||
{
|
||||
@@ -140,7 +145,7 @@ namespace CS2_SimpleAdmin
|
||||
{
|
||||
try
|
||||
{
|
||||
using var connection = await _database.GetConnection();
|
||||
await using var connection = await _database.GetConnectionAsync();
|
||||
|
||||
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 });
|
||||
|
||||
Reference in New Issue
Block a user