mirror of
https://github.com/daffyyyy/CS2-SimpleAdmin.git
synced 2026-03-04 14:44:55 +00:00
1.4.3c
- Fixed rare problems with expiring bans - More checks for `BanType` - Minor changes about validating players - Added `css_players -duplicate` to list players with same ip address
This commit is contained in:
@@ -37,7 +37,7 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdmin
|
|||||||
public override string ModuleName => "CS2-SimpleAdmin" + (Helper.IsDebugBuild ? " (DEBUG)" : " (RELEASE)");
|
public override string ModuleName => "CS2-SimpleAdmin" + (Helper.IsDebugBuild ? " (DEBUG)" : " (RELEASE)");
|
||||||
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.4.3b";
|
public override string ModuleVersion => "1.4.3c";
|
||||||
|
|
||||||
public CS2_SimpleAdminConfig Config { get; set; } = new();
|
public CS2_SimpleAdminConfig Config { get; set; } = new();
|
||||||
|
|
||||||
@@ -55,6 +55,15 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdmin
|
|||||||
_cBasePlayerControllerSetPawnFunc = new MemoryFunctionVoid<CBasePlayerController, CCSPlayerPawn, bool, bool>(GameData.GetSignature("CBasePlayerController_SetPawn"));
|
_cBasePlayerControllerSetPawnFunc = new MemoryFunctionVoid<CBasePlayerController, CCSPlayerPawn, bool, bool>(GameData.GetSignature("CBasePlayerController_SetPawn"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override void Unload(bool hotReload)
|
||||||
|
{
|
||||||
|
if (hotReload) return;
|
||||||
|
|
||||||
|
RemoveListener(OnMapStart);
|
||||||
|
RemoveCommandListener("say", OnCommandSay, HookMode.Post);
|
||||||
|
RemoveCommandListener("say_team", OnCommandTeamSay, HookMode.Post);
|
||||||
|
}
|
||||||
|
|
||||||
public void OnConfigParsed(CS2_SimpleAdminConfig config)
|
public void OnConfigParsed(CS2_SimpleAdminConfig config)
|
||||||
{
|
{
|
||||||
if (config.DatabaseHost.Length < 1 || config.DatabaseName.Length < 1 || config.DatabaseUser.Length < 1)
|
if (config.DatabaseHost.Length < 1 || config.DatabaseName.Length < 1 || config.DatabaseUser.Length < 1)
|
||||||
|
|||||||
@@ -9,8 +9,8 @@ using CounterStrikeSharp.API.Modules.Entities;
|
|||||||
using CounterStrikeSharp.API.Modules.Utils;
|
using CounterStrikeSharp.API.Modules.Utils;
|
||||||
using CS2_SimpleAdmin.Menus;
|
using CS2_SimpleAdmin.Menus;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using System.Text;
|
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
namespace CS2_SimpleAdmin
|
namespace CS2_SimpleAdmin
|
||||||
{
|
{
|
||||||
@@ -429,8 +429,15 @@ namespace CS2_SimpleAdmin
|
|||||||
[RequiresPermissions("@css/generic")]
|
[RequiresPermissions("@css/generic")]
|
||||||
public void OnPlayersCommand(CCSPlayerController? caller, CommandInfo command)
|
public void OnPlayersCommand(CCSPlayerController? caller, CommandInfo command)
|
||||||
{
|
{
|
||||||
var playersToTarget = Helper.GetValidPlayers();
|
|
||||||
var isJson = command.GetArg(1).ToLower().Equals("-json");
|
var isJson = command.GetArg(1).ToLower().Equals("-json");
|
||||||
|
var isDuplicate = command.GetArg(1).ToLower().Equals("-duplicate");
|
||||||
|
|
||||||
|
var playersToTarget = isDuplicate
|
||||||
|
? Helper.GetValidPlayers().GroupBy(player => player.IpAddress?.Split(":")[0] ?? "Unknown")
|
||||||
|
.Where(group => group.Count() > 1)
|
||||||
|
.SelectMany(group => group)
|
||||||
|
.ToList()
|
||||||
|
: Helper.GetValidPlayers();
|
||||||
|
|
||||||
if (!isJson)
|
if (!isJson)
|
||||||
{
|
{
|
||||||
@@ -467,13 +474,12 @@ namespace CS2_SimpleAdmin
|
|||||||
SteamId = player.SteamID.ToString(),
|
SteamId = player.SteamID.ToString(),
|
||||||
IpAddress = player.IpAddress?.Split(":")[0] ?? "Unknown",
|
IpAddress = player.IpAddress?.Split(":")[0] ?? "Unknown",
|
||||||
Ping = player.Ping,
|
Ping = player.Ping,
|
||||||
AdminData = AdminManager.GetPlayerAdminData(player),
|
IsAdmin = AdminManager.PlayerHasPermissions(player, "@css/ban") || AdminManager.PlayerHasPermissions(player, "@css/generic"),
|
||||||
Stats = new
|
Stats = new
|
||||||
{
|
{
|
||||||
Score = player.Score,
|
Score = player.Score,
|
||||||
Kills = matchStats?.Kills ?? 0,
|
Kills = matchStats?.Kills ?? 0,
|
||||||
Deaths = matchStats?.Deaths ?? 0,
|
Deaths = matchStats?.Deaths ?? 0,
|
||||||
Assists = matchStats?.Assists,
|
|
||||||
MVPs = player.MVPs
|
MVPs = player.MVPs
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
151
Events.cs
151
Events.cs
@@ -4,7 +4,6 @@ using CounterStrikeSharp.API.Core.Attributes.Registration;
|
|||||||
using CounterStrikeSharp.API.Modules.Admin;
|
using CounterStrikeSharp.API.Modules.Admin;
|
||||||
using CounterStrikeSharp.API.Modules.Commands;
|
using CounterStrikeSharp.API.Modules.Commands;
|
||||||
using CounterStrikeSharp.API.Modules.Cvars;
|
using CounterStrikeSharp.API.Modules.Cvars;
|
||||||
using CounterStrikeSharp.API.Modules.Entities;
|
|
||||||
using Dapper;
|
using Dapper;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
@@ -31,7 +30,7 @@ public partial class CS2_SimpleAdmin
|
|||||||
Logger.LogCritical("[OnClientDisconnect] Before");
|
Logger.LogCritical("[OnClientDisconnect] Before");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (player == null || !player.IsValid || string.IsNullOrEmpty(player.IpAddress) || player.IsBot || player.IsHLTV)
|
if (player == null || !player.IsValid || string.IsNullOrEmpty(player.IpAddress) || player.IsBot)
|
||||||
{
|
{
|
||||||
return HookResult.Continue;
|
return HookResult.Continue;
|
||||||
}
|
}
|
||||||
@@ -61,7 +60,7 @@ public partial class CS2_SimpleAdmin
|
|||||||
var authorizedSteamId = player.AuthorizedSteamID;
|
var authorizedSteamId = player.AuthorizedSteamID;
|
||||||
if (authorizedSteamId == null || !PermissionManager.AdminCache.TryGetValue(authorizedSteamId,
|
if (authorizedSteamId == null || !PermissionManager.AdminCache.TryGetValue(authorizedSteamId,
|
||||||
out var expirationTime)
|
out var expirationTime)
|
||||||
|| !(expirationTime <= DateTime.Now)) return HookResult.Continue;
|
|| !(expirationTime <= DateTime.UtcNow.ToLocalTime())) return HookResult.Continue;
|
||||||
|
|
||||||
AdminManager.ClearPlayerPermissions(authorizedSteamId);
|
AdminManager.ClearPlayerPermissions(authorizedSteamId);
|
||||||
AdminManager.RemovePlayerAdminData(authorizedSteamId);
|
AdminManager.RemovePlayerAdminData(authorizedSteamId);
|
||||||
@@ -81,13 +80,13 @@ public partial class CS2_SimpleAdmin
|
|||||||
CCSPlayerController? player = @event.Userid;
|
CCSPlayerController? player = @event.Userid;
|
||||||
|
|
||||||
if (player == null || string.IsNullOrEmpty(player.IpAddress) || player.IpAddress.Contains("127.0.0.1")
|
if (player == null || string.IsNullOrEmpty(player.IpAddress) || player.IpAddress.Contains("127.0.0.1")
|
||||||
|| player.IsBot || player.IsHLTV || !player.UserId.HasValue)
|
|| player.IsBot || !player.UserId.HasValue)
|
||||||
return HookResult.Continue;
|
return HookResult.Continue;
|
||||||
|
|
||||||
var ipAddress = player.IpAddress.Split(":")[0];
|
var ipAddress = player.IpAddress.Split(":")[0];
|
||||||
|
|
||||||
// Check if the player's IP or SteamID is in the bannedPlayers list
|
// Check if the player's IP or SteamID is in the bannedPlayers list
|
||||||
if (BannedPlayers.Contains(ipAddress) || BannedPlayers.Contains(player.SteamID.ToString()))
|
if (Config.BanType > 0 && BannedPlayers.Contains(ipAddress) || BannedPlayers.Contains(player.SteamID.ToString()))
|
||||||
{
|
{
|
||||||
// Kick the player if banned
|
// Kick the player if banned
|
||||||
if (player.UserId.HasValue)
|
if (player.UserId.HasValue)
|
||||||
@@ -121,7 +120,7 @@ public partial class CS2_SimpleAdmin
|
|||||||
if (isBanned)
|
if (isBanned)
|
||||||
{
|
{
|
||||||
// Add player's IP and SteamID to bannedPlayers list if not already present
|
// Add player's IP and SteamID to bannedPlayers list if not already present
|
||||||
if (playerInfo.IpAddress != null && !BannedPlayers.Contains(playerInfo.IpAddress))
|
if (Config.BanType > 0 && playerInfo.IpAddress != null && !BannedPlayers.Contains(playerInfo.IpAddress))
|
||||||
BannedPlayers.Add(playerInfo.IpAddress);
|
BannedPlayers.Add(playerInfo.IpAddress);
|
||||||
|
|
||||||
if (playerInfo.SteamId != null && !BannedPlayers.Contains(playerInfo.SteamId))
|
if (playerInfo.SteamId != null && !BannedPlayers.Contains(playerInfo.SteamId))
|
||||||
@@ -257,7 +256,7 @@ public partial class CS2_SimpleAdmin
|
|||||||
return HookResult.Handled;
|
return HookResult.Handled;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnMapStart(string mapName)
|
public void OnMapStart(string mapName)
|
||||||
{
|
{
|
||||||
var path = Path.GetDirectoryName(ModuleDirectory);
|
var path = Path.GetDirectoryName(ModuleDirectory);
|
||||||
if (Directory.Exists(path + "/CS2-Tags"))
|
if (Directory.Exists(path + "/CS2-Tags"))
|
||||||
@@ -272,75 +271,22 @@ public partial class CS2_SimpleAdmin
|
|||||||
|
|
||||||
_database = new Database.Database(_dbConnectionString);
|
_database = new Database.Database(_dbConnectionString);
|
||||||
|
|
||||||
AddTimer(61.0f, () =>
|
|
||||||
{
|
|
||||||
#if DEBUG
|
|
||||||
Logger.LogCritical("[OnMapStart] Expired check");
|
|
||||||
#endif
|
|
||||||
|
|
||||||
var players = Helper.GetValidPlayers();
|
|
||||||
var onlinePlayers = players
|
|
||||||
.Where(player => player.IpAddress != null && player.SteamID.ToString().Length == 17)
|
|
||||||
.Select(player => (player.IpAddress, player.SteamID, player.UserId))
|
|
||||||
.ToList();
|
|
||||||
|
|
||||||
Task.Run(async () =>
|
|
||||||
{
|
|
||||||
PermissionManager adminManager = new(_database);
|
|
||||||
BanManager banManager = new(_database, Config);
|
|
||||||
MuteManager muteManager = new(_database);
|
|
||||||
|
|
||||||
await banManager.ExpireOldBans();
|
|
||||||
await muteManager.ExpireOldMutes();
|
|
||||||
await adminManager.DeleteOldAdmins();
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
await banManager.CheckOnlinePlayers(onlinePlayers);
|
|
||||||
}
|
|
||||||
catch { }
|
|
||||||
|
|
||||||
BannedPlayers.Clear();
|
|
||||||
|
|
||||||
await Server.NextFrameAsync(() =>
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
foreach (var player in players.Where(player => PlayerPenaltyManager.IsSlotInPenalties(player.Slot)))
|
|
||||||
{
|
|
||||||
if (!PlayerPenaltyManager.IsPenalized(player.Slot, PenaltyType.Mute) && !PlayerPenaltyManager.IsPenalized(player.Slot, PenaltyType.Silence))
|
|
||||||
player.VoiceFlags = VoiceFlags.Normal;
|
|
||||||
|
|
||||||
if (!PlayerPenaltyManager.IsPenalized(player.Slot, PenaltyType.Gag) && !PlayerPenaltyManager.IsPenalized(player.Slot, PenaltyType.Silence))
|
|
||||||
{
|
|
||||||
if (_tagsDetected)
|
|
||||||
Server.ExecuteCommand($"css_tag_unmute {player.SteamID}");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (PlayerPenaltyManager.IsPenalized(player.Slot, PenaltyType.Silence) ||
|
|
||||||
PlayerPenaltyManager.IsPenalized(player.Slot, PenaltyType.Mute) ||
|
|
||||||
PlayerPenaltyManager.IsPenalized(player.Slot, PenaltyType.Gag)) continue;
|
|
||||||
player.VoiceFlags = VoiceFlags.Normal;
|
|
||||||
|
|
||||||
if (_tagsDetected)
|
|
||||||
Server.ExecuteCommand($"css_tag_unmute {player.SteamID}");
|
|
||||||
}
|
|
||||||
|
|
||||||
PlayerPenaltyManager.RemoveExpiredPenalties();
|
|
||||||
}
|
|
||||||
catch { }
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}, CounterStrikeSharp.API.Modules.Timers.TimerFlags.REPEAT | CounterStrikeSharp.API.Modules.Timers.TimerFlags.STOP_ON_MAPCHANGE);
|
|
||||||
|
|
||||||
AddTimer(2.0f, () =>
|
AddTimer(2.0f, () =>
|
||||||
{
|
{
|
||||||
var address = $"{ConVar.Find("ip")!.StringValue}:{ConVar.Find("hostport")!.GetPrimitiveValue<int>()}";
|
var ipAddress = ConVar.Find("ip")?.StringValue;
|
||||||
|
|
||||||
|
if (string.IsNullOrEmpty(ipAddress))
|
||||||
|
{
|
||||||
|
Logger.LogError("Unable to get server ip, Check that you have added the correct start parameter \"-ip <ip>\"");
|
||||||
|
}
|
||||||
|
|
||||||
|
var address = $"{ipAddress}:{ConVar.Find("hostport")?.GetPrimitiveValue<int>()}";
|
||||||
var hostname = ConVar.Find("hostname")!.StringValue;
|
var hostname = ConVar.Find("hostname")!.StringValue;
|
||||||
|
|
||||||
Task.Run(async () =>
|
Task.Run(async () =>
|
||||||
{
|
{
|
||||||
PermissionManager adminManager = new(_database);
|
PermissionManager adminManager = new(_database);
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
await using var connection = await _database.GetConnectionAsync();
|
await using var connection = await _database.GetConnectionAsync();
|
||||||
@@ -390,12 +336,75 @@ public partial class CS2_SimpleAdmin
|
|||||||
//await _adminManager.GiveAllGroupsFlags();
|
//await _adminManager.GiveAllGroupsFlags();
|
||||||
//await _adminManager.GiveAllFlags();
|
//await _adminManager.GiveAllFlags();
|
||||||
|
|
||||||
|
await Server.NextFrameAsync(() =>
|
||||||
await Server.NextFrameAsync(() => {
|
{
|
||||||
ReloadAdmins(null);
|
ReloadAdmins(null);
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
}, CounterStrikeSharp.API.Modules.Timers.TimerFlags.STOP_ON_MAPCHANGE);
|
}, CounterStrikeSharp.API.Modules.Timers.TimerFlags.STOP_ON_MAPCHANGE);
|
||||||
|
|
||||||
|
AddTimer(61.0f, () =>
|
||||||
|
{
|
||||||
|
#if DEBUG
|
||||||
|
Logger.LogCritical("[OnMapStart] Expired check");
|
||||||
|
#endif
|
||||||
|
|
||||||
|
var players = Helper.GetValidPlayers();
|
||||||
|
var onlinePlayers = players
|
||||||
|
.Where(player => player.IpAddress != null && player.SteamID.ToString().Length == 17)
|
||||||
|
.Select(player => (player.IpAddress, player.SteamID, player.UserId))
|
||||||
|
.ToList();
|
||||||
|
|
||||||
|
Task.Run(async () =>
|
||||||
|
{
|
||||||
|
PermissionManager adminManager = new(_database);
|
||||||
|
BanManager banManager = new(_database, Config);
|
||||||
|
MuteManager muteManager = new(_database);
|
||||||
|
|
||||||
|
await banManager.ExpireOldBans();
|
||||||
|
await muteManager.ExpireOldMutes();
|
||||||
|
await adminManager.DeleteOldAdmins();
|
||||||
|
BannedPlayers.Clear();
|
||||||
|
if (onlinePlayers.Count > 0)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
await banManager.CheckOnlinePlayers(onlinePlayers);
|
||||||
|
}
|
||||||
|
catch { }
|
||||||
|
}
|
||||||
|
|
||||||
|
await Server.NextFrameAsync(() =>
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
foreach (var player in players.Where(player => PlayerPenaltyManager.IsSlotInPenalties(player.Slot)))
|
||||||
|
{
|
||||||
|
if (!PlayerPenaltyManager.IsPenalized(player.Slot, PenaltyType.Mute) && !PlayerPenaltyManager.IsPenalized(player.Slot, PenaltyType.Silence))
|
||||||
|
player.VoiceFlags = VoiceFlags.Normal;
|
||||||
|
|
||||||
|
if (!PlayerPenaltyManager.IsPenalized(player.Slot, PenaltyType.Gag) && !PlayerPenaltyManager.IsPenalized(player.Slot, PenaltyType.Silence))
|
||||||
|
{
|
||||||
|
if (_tagsDetected)
|
||||||
|
Server.ExecuteCommand($"css_tag_unmute {player.SteamID}");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (PlayerPenaltyManager.IsPenalized(player.Slot, PenaltyType.Silence) ||
|
||||||
|
PlayerPenaltyManager.IsPenalized(player.Slot, PenaltyType.Mute) ||
|
||||||
|
PlayerPenaltyManager.IsPenalized(player.Slot, PenaltyType.Gag)) continue;
|
||||||
|
player.VoiceFlags = VoiceFlags.Normal;
|
||||||
|
|
||||||
|
if (_tagsDetected)
|
||||||
|
Server.ExecuteCommand($"css_tag_unmute {player.SteamID}");
|
||||||
|
}
|
||||||
|
|
||||||
|
PlayerPenaltyManager.RemoveExpiredPenalties();
|
||||||
|
}
|
||||||
|
catch { }
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}, CounterStrikeSharp.API.Modules.Timers.TimerFlags.REPEAT | CounterStrikeSharp.API.Modules.Timers.TimerFlags.STOP_ON_MAPCHANGE);
|
||||||
}
|
}
|
||||||
|
|
||||||
[GameEventHandler]
|
[GameEventHandler]
|
||||||
|
|||||||
@@ -59,16 +59,14 @@ namespace CS2_SimpleAdmin
|
|||||||
|
|
||||||
public static List<CCSPlayerController> GetValidPlayers()
|
public static List<CCSPlayerController> GetValidPlayers()
|
||||||
{
|
{
|
||||||
return Utilities.GetPlayers().FindAll(p =>
|
return Utilities.GetPlayers().FindAll(p => p is
|
||||||
p.IsValid && p.SteamID.ToString().Length == 17 && !string.IsNullOrEmpty(p.IpAddress) && p is
|
{ IsBot: false, IsHLTV: false });
|
||||||
{ Connected: PlayerConnectedState.PlayerConnected, IsBot: false, IsHLTV: false });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static IEnumerable<CCSPlayerController?> GetValidPlayersWithBots()
|
public static IEnumerable<CCSPlayerController?> GetValidPlayersWithBots()
|
||||||
{
|
{
|
||||||
return Utilities.GetPlayers().FindAll(p =>
|
return Utilities.GetPlayers().FindAll(p =>
|
||||||
p.IsValid && p.SteamID.ToString().Length == 17 && !string.IsNullOrEmpty(p.IpAddress) && p is { Connected: PlayerConnectedState.PlayerConnected, IsBot: false, IsHLTV: false } ||
|
p is { IsBot: false, IsHLTV: false } or { IsBot: true, IsHLTV: false }
|
||||||
p is { IsValid: true, Connected: PlayerConnectedState.PlayerConnected, IsBot: true, IsHLTV: false }
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ internal class BanManager(Database.Database database, CS2_SimpleAdminConfig conf
|
|||||||
public async Task BanPlayer(PlayerInfo player, PlayerInfo issuer, string reason, int time = 0)
|
public async Task BanPlayer(PlayerInfo player, PlayerInfo issuer, string reason, int time = 0)
|
||||||
{
|
{
|
||||||
DateTime now = DateTime.UtcNow.ToLocalTime();
|
DateTime now = DateTime.UtcNow.ToLocalTime();
|
||||||
DateTime futureTime = now.AddMinutes(time).ToLocalTime();
|
DateTime futureTime = now.AddMinutes(time);
|
||||||
|
|
||||||
await using MySqlConnection connection = await database.GetConnectionAsync();
|
await using MySqlConnection connection = await database.GetConnectionAsync();
|
||||||
try
|
try
|
||||||
@@ -41,7 +41,7 @@ internal class BanManager(Database.Database database, CS2_SimpleAdminConfig conf
|
|||||||
if (string.IsNullOrEmpty(playerSteamId)) return;
|
if (string.IsNullOrEmpty(playerSteamId)) return;
|
||||||
|
|
||||||
DateTime now = DateTime.UtcNow.ToLocalTime();
|
DateTime now = DateTime.UtcNow.ToLocalTime();
|
||||||
DateTime futureTime = now.AddMinutes(time).ToLocalTime();
|
DateTime futureTime = now.AddMinutes(time);
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -70,7 +70,7 @@ internal class BanManager(Database.Database database, CS2_SimpleAdminConfig conf
|
|||||||
if (string.IsNullOrEmpty(playerIp)) return;
|
if (string.IsNullOrEmpty(playerIp)) return;
|
||||||
|
|
||||||
DateTime now = DateTime.UtcNow.ToLocalTime();
|
DateTime now = DateTime.UtcNow.ToLocalTime();
|
||||||
DateTime futureTime = now.AddMinutes(time).ToLocalTime();
|
DateTime futureTime = now.AddMinutes(time);
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -108,7 +108,7 @@ internal class BanManager(Database.Database database, CS2_SimpleAdminConfig conf
|
|||||||
|
|
||||||
int banCount;
|
int banCount;
|
||||||
|
|
||||||
DateTime currentTime = DateTime.Now.ToLocalTime();
|
DateTime currentTime = DateTime.UtcNow.ToLocalTime();
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -172,12 +172,14 @@ internal class BanManager(Database.Database database, CS2_SimpleAdminConfig conf
|
|||||||
|
|
||||||
await using var connection = await database.GetConnectionAsync();
|
await using var connection = await database.GetConnectionAsync();
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(player.IpAddress))
|
if (config.BanType > 0 && !string.IsNullOrEmpty(player.IpAddress))
|
||||||
{
|
{
|
||||||
banCount = await connection.ExecuteScalarAsync<int>(sql,
|
banCount = await connection.ExecuteScalarAsync<int>(sql,
|
||||||
new
|
new
|
||||||
{
|
{
|
||||||
PlayerSteamID = player.SteamId, PlayerIP = player.IpAddress, serverid = CS2_SimpleAdmin.ServerId
|
PlayerSteamID = player.SteamId,
|
||||||
|
PlayerIP = player.IpAddress,
|
||||||
|
serverid = CS2_SimpleAdmin.ServerId
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -185,7 +187,9 @@ internal class BanManager(Database.Database database, CS2_SimpleAdminConfig conf
|
|||||||
banCount = await connection.ExecuteScalarAsync<int>(sql,
|
banCount = await connection.ExecuteScalarAsync<int>(sql,
|
||||||
new
|
new
|
||||||
{
|
{
|
||||||
PlayerSteamID = player.SteamId, PlayerIP = DBNull.Value, serverid = CS2_SimpleAdmin.ServerId
|
PlayerSteamID = player.SteamId,
|
||||||
|
PlayerIP = DBNull.Value,
|
||||||
|
serverid = CS2_SimpleAdmin.ServerId
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -264,6 +268,7 @@ internal class BanManager(Database.Database database, CS2_SimpleAdminConfig conf
|
|||||||
{
|
{
|
||||||
await using var connection = await database.GetConnectionAsync();
|
await using var connection = await database.GetConnectionAsync();
|
||||||
string sql;
|
string sql;
|
||||||
|
bool checkIpBans = config.BanType > 0;
|
||||||
|
|
||||||
if (config.MultiServerMode)
|
if (config.MultiServerMode)
|
||||||
{
|
{
|
||||||
@@ -280,7 +285,7 @@ internal class BanManager(Database.Database database, CS2_SimpleAdminConfig conf
|
|||||||
if (!UserId.HasValue) continue;
|
if (!UserId.HasValue) continue;
|
||||||
|
|
||||||
var banCount = 0;
|
var banCount = 0;
|
||||||
if (!string.IsNullOrEmpty(IpAddress))
|
if (checkIpBans && !string.IsNullOrEmpty(IpAddress))
|
||||||
{
|
{
|
||||||
banCount = await connection.ExecuteScalarAsync<int>(sql,
|
banCount = await connection.ExecuteScalarAsync<int>(sql,
|
||||||
new { PlayerSteamID = SteamID, PlayerIP = IpAddress, serverid = CS2_SimpleAdmin.ServerId });
|
new { PlayerSteamID = SteamID, PlayerIP = IpAddress, serverid = CS2_SimpleAdmin.ServerId });
|
||||||
@@ -349,7 +354,7 @@ internal class BanManager(Database.Database database, CS2_SimpleAdminConfig conf
|
|||||||
|
|
||||||
if (config.ExpireOldIpBans > 0)
|
if (config.ExpireOldIpBans > 0)
|
||||||
{
|
{
|
||||||
var ipBansTime = currentTime.AddDays(-config.ExpireOldIpBans).ToLocalTime();
|
var ipBansTime = currentTime.AddDays(-config.ExpireOldIpBans);
|
||||||
sql = config.MultiServerMode ? """
|
sql = config.MultiServerMode ? """
|
||||||
|
|
||||||
UPDATE sa_bans
|
UPDATE sa_bans
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ internal class MuteManager(Database.Database database)
|
|||||||
if (player.SteamId == null) return;
|
if (player.SteamId == null) return;
|
||||||
|
|
||||||
var now = DateTime.UtcNow.ToLocalTime();
|
var now = DateTime.UtcNow.ToLocalTime();
|
||||||
var futureTime = now.AddMinutes(time).ToLocalTime();
|
var futureTime = now.AddMinutes(time);
|
||||||
|
|
||||||
var muteType = type switch
|
var muteType = type switch
|
||||||
{
|
{
|
||||||
@@ -49,7 +49,7 @@ internal class MuteManager(Database.Database database)
|
|||||||
|
|
||||||
|
|
||||||
var now = DateTime.UtcNow.ToLocalTime();
|
var now = DateTime.UtcNow.ToLocalTime();
|
||||||
var futureTime = now.AddMinutes(time).ToLocalTime();
|
var futureTime = now.AddMinutes(time);
|
||||||
|
|
||||||
var muteType = type switch
|
var muteType = type switch
|
||||||
{
|
{
|
||||||
@@ -95,7 +95,7 @@ internal class MuteManager(Database.Database database)
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
await using var connection = await database.GetConnectionAsync();
|
await using var connection = await database.GetConnectionAsync();
|
||||||
var currentTime = DateTime.Now.ToLocalTime();
|
var currentTime = DateTime.UtcNow.ToLocalTime();
|
||||||
string sql;
|
string sql;
|
||||||
|
|
||||||
if (CS2_SimpleAdmin.Instance.Config.MultiServerMode)
|
if (CS2_SimpleAdmin.Instance.Config.MultiServerMode)
|
||||||
@@ -217,7 +217,7 @@ internal class MuteManager(Database.Database database)
|
|||||||
? "UPDATE sa_mutes SET status = 'EXPIRED' WHERE status = 'ACTIVE' AND `duration` > 0 AND ends <= @CurrentTime AND server_id = @serverid"
|
? "UPDATE sa_mutes SET status = 'EXPIRED' WHERE status = 'ACTIVE' AND `duration` > 0 AND ends <= @CurrentTime AND server_id = @serverid"
|
||||||
: "UPDATE sa_mutes SET status = 'EXPIRED' WHERE status = 'ACTIVE' AND `duration` > 0 AND ends <= @CurrentTime";
|
: "UPDATE sa_mutes SET status = 'EXPIRED' WHERE status = 'ACTIVE' AND `duration` > 0 AND ends <= @CurrentTime";
|
||||||
|
|
||||||
await connection.ExecuteAsync(sql, new { CurrentTime = DateTime.Now.ToLocalTime(), serverid = CS2_SimpleAdmin.ServerId });
|
await connection.ExecuteAsync(sql, new { CurrentTime = DateTime.UtcNow.ToLocalTime(), serverid = CS2_SimpleAdmin.ServerId });
|
||||||
}
|
}
|
||||||
catch (Exception)
|
catch (Exception)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,11 +1,10 @@
|
|||||||
using CounterStrikeSharp.API.Modules.Entities;
|
using CounterStrikeSharp.API;
|
||||||
|
using CounterStrikeSharp.API.Modules.Entities;
|
||||||
using Dapper;
|
using Dapper;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using MySqlConnector;
|
using MySqlConnector;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using System.Collections.Concurrent;
|
using System.Collections.Concurrent;
|
||||||
using CounterStrikeSharp.API;
|
|
||||||
using CounterStrikeSharp.API.Modules.Admin;
|
|
||||||
|
|
||||||
namespace CS2_SimpleAdmin;
|
namespace CS2_SimpleAdmin;
|
||||||
|
|
||||||
@@ -400,7 +399,7 @@ public class PermissionManager(Database.Database database)
|
|||||||
DateTime? futureTime;
|
DateTime? futureTime;
|
||||||
|
|
||||||
if (time != 0)
|
if (time != 0)
|
||||||
futureTime = now.ToLocalTime().AddMinutes(time);
|
futureTime = now.AddMinutes(time);
|
||||||
else
|
else
|
||||||
futureTime = null;
|
futureTime = null;
|
||||||
|
|
||||||
@@ -531,7 +530,7 @@ public class PermissionManager(Database.Database database)
|
|||||||
await using var connection = await database.GetConnectionAsync();
|
await using var connection = await database.GetConnectionAsync();
|
||||||
|
|
||||||
const string sql = "DELETE FROM sa_admins WHERE ends IS NOT NULL AND ends <= @CurrentTime";
|
const string sql = "DELETE FROM sa_admins WHERE ends IS NOT NULL AND ends <= @CurrentTime";
|
||||||
await connection.ExecuteAsync(sql, new { CurrentTime = DateTime.Now.ToLocalTime() });
|
await connection.ExecuteAsync(sql, new { CurrentTime = DateTime.UtcNow.ToLocalTime() });
|
||||||
}
|
}
|
||||||
catch (Exception)
|
catch (Exception)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user