mirror of
https://github.com/daffyyyy/CS2-SimpleAdmin.git
synced 2026-02-17 18:39:07 +00:00
1.3.0a
- Fixed crashing on servers with a lot of players - Every command chat message respect player language for now css_lang or use https://github.com/aprox2/GeoLocationLanguageManagerPlugin to detect language related on player ip - Fixed css_respawn - Fixed css_vote player can't vote multiple times - Added TeamSwitchType to config, if set to 0 plugin always slay player on css_team command - Minor changes
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
using CounterStrikeSharp.API.Modules.Entities;
|
||||
using Dapper;
|
||||
using System.Collections.Concurrent;
|
||||
|
||||
namespace CS2_SimpleAdmin
|
||||
{
|
||||
@@ -8,8 +9,8 @@ namespace CS2_SimpleAdmin
|
||||
private readonly Database _database;
|
||||
// Unused for now
|
||||
//public static readonly ConcurrentDictionary<string, ConcurrentBag<string>> _adminCache = new ConcurrentDictionary<string, ConcurrentBag<string>>();
|
||||
public static readonly HashSet<SteamID> _adminCacheSet = new HashSet<SteamID>();
|
||||
public static readonly Dictionary<SteamID, DateTime?> _adminCacheTimestamps = new Dictionary<SteamID, DateTime?>();
|
||||
public static readonly ConcurrentDictionary<SteamID, DateTime?> _adminCache = new ConcurrentDictionary<SteamID, DateTime?>();
|
||||
//public static readonly ConcurrentDictionary<SteamID, DateTime?> _adminCacheTimestamps = new ConcurrentDictionary<SteamID, DateTime?>();
|
||||
|
||||
public AdminSQLManager(Database database)
|
||||
{
|
||||
@@ -216,10 +217,10 @@ namespace CS2_SimpleAdmin
|
||||
|
||||
if (!string.IsNullOrEmpty(steamIdStr) && SteamID.TryParse(steamIdStr, out var steamId) && steamId != null)
|
||||
{
|
||||
if (!_adminCacheSet.Contains(steamId))
|
||||
if (!_adminCache.ContainsKey(steamId))
|
||||
{
|
||||
_adminCacheSet.Add(steamId);
|
||||
_adminCacheTimestamps.Add(steamId, ends);
|
||||
_adminCache.TryAdd(steamId, ends);
|
||||
//_adminCacheTimestamps.Add(steamId, ends);
|
||||
}
|
||||
|
||||
Helper.GivePlayerFlags(steamId, flags, (uint)immunity);
|
||||
|
||||
@@ -90,26 +90,35 @@ namespace CS2_SimpleAdmin
|
||||
|
||||
public async Task<bool> IsPlayerBanned(PlayerInfo player)
|
||||
{
|
||||
DateTime now = DateTime.Now;
|
||||
if (player == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
int banCount;
|
||||
|
||||
try
|
||||
{
|
||||
await using var connection = _database.GetConnection();
|
||||
|
||||
if (!string.IsNullOrEmpty(player.IpAddress))
|
||||
var parameters = new
|
||||
{
|
||||
banCount = await connection.ExecuteScalarAsync<int>(sql, new { PlayerSteamID = player.SteamId, PlayerIP = player.IpAddress, CurrentTime = now });
|
||||
PlayerSteamID = player.SteamId,
|
||||
PlayerIP = !string.IsNullOrEmpty(player.IpAddress) ? player.IpAddress : (object)DBNull.Value,
|
||||
CurrentTime = currentTimeUtc
|
||||
};
|
||||
|
||||
banCount = await connection.ExecuteScalarAsync<int>(sql, parameters);
|
||||
}
|
||||
else
|
||||
catch (Exception)
|
||||
{
|
||||
banCount = await connection.ExecuteScalarAsync<int>(sql, new { PlayerSteamID = player.SteamId, PlayerIP = DBNull.Value, CurrentTime = now });
|
||||
return false;
|
||||
}
|
||||
|
||||
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)";
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -5,7 +5,7 @@ namespace CS2_SimpleAdmin
|
||||
{
|
||||
public class CS2_SimpleAdminConfig : BasePluginConfig
|
||||
{
|
||||
public override int Version { get; set; } = 4;
|
||||
public override int Version { get; set; } = 5;
|
||||
|
||||
[JsonPropertyName("DatabaseHost")]
|
||||
public string DatabaseHost { get; set; } = "";
|
||||
@@ -31,8 +31,10 @@ namespace CS2_SimpleAdmin
|
||||
[JsonPropertyName("BanType")]
|
||||
public int BanType { get; set; } = 1;
|
||||
|
||||
[JsonPropertyName("TeamSwitchType")]
|
||||
public int TeamSwitchType { get; set; } = 1;
|
||||
|
||||
[JsonPropertyName("DiscordWebhook")]
|
||||
public string DiscordWebhook { get; set; } = "";
|
||||
|
||||
}
|
||||
}
|
||||
@@ -17,11 +17,3 @@ public class Database
|
||||
return connection;
|
||||
}
|
||||
}
|
||||
|
||||
public static class DatabaseExtension
|
||||
{
|
||||
public static string WithConnectionPooling(this string connectionString)
|
||||
{
|
||||
return $"{connectionString};Pooling=true;MinimumPoolSize=1;MaximumPoolSize=15";
|
||||
}
|
||||
}
|
||||
292
Events.cs
292
Events.cs
@@ -1,10 +1,12 @@
|
||||
using CounterStrikeSharp.API;
|
||||
using CounterStrikeSharp.API.Core;
|
||||
using CounterStrikeSharp.API.Core.Attributes.Registration;
|
||||
using CounterStrikeSharp.API.Modules.Admin;
|
||||
using CounterStrikeSharp.API.Modules.Commands;
|
||||
using CounterStrikeSharp.API.Modules.Cvars;
|
||||
using Dapper;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Data;
|
||||
using System.Text;
|
||||
using static CounterStrikeSharp.API.Core.Listeners;
|
||||
@@ -17,12 +19,12 @@ public partial class CS2_SimpleAdmin
|
||||
{
|
||||
//RegisterListener<OnClientAuthorized>(OnClientAuthorized);
|
||||
//RegisterListener<OnClientConnect>(OnClientConnect);
|
||||
RegisterListener<OnClientPutInServer>(OnClientPutInServer);
|
||||
//RegisterListener<OnClientPutInServer>(OnClientPutInServer);
|
||||
//RegisterListener<OnClientDisconnect>(OnClientDisconnect);
|
||||
//RegisterEventHandler<EventPlayerConnectFull>(OnPlayerFullConnect);
|
||||
RegisterListener<OnClientDisconnect>(OnClientDisconnect);
|
||||
RegisterListener<OnMapStart>(OnMapStart);
|
||||
RegisterEventHandler<EventPlayerHurt>(OnPlayerHurt);
|
||||
RegisterEventHandler<EventRoundStart>(OnRoundStart);
|
||||
//RegisterEventHandler<EventPlayerHurt>(OnPlayerHurt);
|
||||
//RegisterEventHandler<EventRoundStart>(OnRoundStart);
|
||||
AddCommandListener("say", OnCommandSay);
|
||||
AddCommandListener("say_team", OnCommandTeamSay);
|
||||
}
|
||||
@@ -31,7 +33,7 @@ public partial class CS2_SimpleAdmin
|
||||
{
|
||||
CCSPlayerController? player = @event.Userid;
|
||||
|
||||
if (player == null || player.IsBot || player.IsHLTV) return HookResult.Continue;
|
||||
if (player is null || player.IsBot || player.IsHLTV) return HookResult.Continue;
|
||||
|
||||
PlayerInfo playerInfo = new PlayerInfo
|
||||
{
|
||||
@@ -46,27 +48,28 @@ public partial class CS2_SimpleAdmin
|
||||
{
|
||||
Server.NextFrame(() =>
|
||||
{
|
||||
if (player == null) return;
|
||||
if (player is null) return;
|
||||
});
|
||||
});
|
||||
return HookResult.Continue;
|
||||
}
|
||||
*/
|
||||
|
||||
private HookResult OnRoundStart(EventRoundStart @event, GameEventInfo info)
|
||||
[GameEventHandler]
|
||||
private HookResult OnRoundEnd(EventRoundEnd @event, GameEventInfo info)
|
||||
{
|
||||
godPlayers.Clear();
|
||||
#if DEBUG
|
||||
Logger.LogCritical("[OnRoundStart]");
|
||||
Logger.LogCritical("[OnRoundEnd]");
|
||||
#endif
|
||||
godPlayers.Clear();
|
||||
return HookResult.Continue;
|
||||
}
|
||||
|
||||
private HookResult OnCommandSay(CCSPlayerController? player, CommandInfo info)
|
||||
{
|
||||
if (player == 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) return HookResult.Continue;
|
||||
|
||||
if (player != null && player.SteamID.ToString() != "" && gaggedPlayers.Contains(player.SteamID.ToString()))
|
||||
if (player != null && gaggedPlayers.Contains(player.Slot))
|
||||
{
|
||||
return HookResult.Handled;
|
||||
}
|
||||
@@ -76,9 +79,9 @@ public partial class CS2_SimpleAdmin
|
||||
|
||||
private HookResult OnCommandTeamSay(CCSPlayerController? player, CommandInfo info)
|
||||
{
|
||||
if (player == 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) return HookResult.Continue;
|
||||
|
||||
if (player != null && player.SteamID.ToString() != "" && gaggedPlayers.Contains(player.SteamID.ToString()))
|
||||
if (player != null && gaggedPlayers.Contains(player.Slot))
|
||||
{
|
||||
return HookResult.Handled;
|
||||
}
|
||||
@@ -111,265 +114,145 @@ public partial class CS2_SimpleAdmin
|
||||
return HookResult.Continue;
|
||||
}
|
||||
|
||||
private void OnClientPutInServer(int playerSlot)
|
||||
[GameEventHandler]
|
||||
public HookResult OnPlayerConnect(EventPlayerConnectFull @event, GameEventInfo info)
|
||||
{
|
||||
CCSPlayerController? player = Utilities.GetPlayerFromSlot(playerSlot);
|
||||
#if DEBUG
|
||||
Logger.LogCritical("[OnClientPutInServer] Before check");
|
||||
#endif
|
||||
if (!@event.Userid.IsValid || !@event.Userid.PlayerPawn.IsValid)
|
||||
return HookResult.Continue;
|
||||
|
||||
if (player == null || !player.IsValid || player.IsBot || player.IsHLTV || player.Connected == PlayerConnectedState.PlayerDisconnecting)
|
||||
return;
|
||||
CCSPlayerController? player = @event.Userid;
|
||||
#if DEBUG
|
||||
Logger.LogCritical("[OnClientPutInServer] After Check");
|
||||
Logger.LogCritical("[OnPlayerConnect] Before check");
|
||||
#endif
|
||||
if (_database == null || player is null || !player.IsValid || player.IsBot || player.IsHLTV)
|
||||
return HookResult.Continue;
|
||||
|
||||
#if DEBUG
|
||||
Logger.LogCritical("[OnPlayerConnect] After Check");
|
||||
#endif
|
||||
|
||||
string? ipAddress = !string.IsNullOrEmpty(player.IpAddress) ? player.IpAddress.Split(":")[0] : null;
|
||||
|
||||
if (
|
||||
ipAddress != null && bannedPlayers.Contains(ipAddress) ||
|
||||
player.SteamID.ToString() != "" && bannedPlayers.Contains(player.SteamID.ToString())
|
||||
bannedPlayers.Contains(player.SteamID.ToString())
|
||||
)
|
||||
{
|
||||
Server.NextFrame(() =>
|
||||
{
|
||||
Helper.KickPlayer((ushort)player.UserId!, "Banned");
|
||||
});
|
||||
return HookResult.Continue;
|
||||
}
|
||||
|
||||
PlayerInfo playerInfo = new PlayerInfo
|
||||
{
|
||||
UserId = player.UserId,
|
||||
Index = (ushort)player.Index,
|
||||
SteamId = player?.SteamID.ToString(),
|
||||
Name = player?.PlayerName,
|
||||
Slot = player.Slot,
|
||||
SteamId = player.SteamID.ToString(),
|
||||
Name = player.PlayerName,
|
||||
IpAddress = ipAddress
|
||||
};
|
||||
|
||||
_ = Task.Run(async () =>
|
||||
Task.Run(async () =>
|
||||
{
|
||||
if (_database == null) return;
|
||||
|
||||
BanManager _banManager = new(_database, Config);
|
||||
bool isBanned = await _banManager.IsPlayerBanned(playerInfo);
|
||||
|
||||
MuteManager _muteManager = new(_database);
|
||||
List<dynamic> activeMutes = await _muteManager.IsPlayerMuted(playerInfo.SteamId!);
|
||||
List<dynamic> activeMutes = await _muteManager.IsPlayerMuted(playerInfo.SteamId);
|
||||
|
||||
AdminSQLManager _adminManager = new(_database);
|
||||
List<(List<string>, int)> activeFlags = await _adminManager.GetAdminFlags(playerInfo.SteamId!);
|
||||
|
||||
Server.NextFrame(() =>
|
||||
{
|
||||
if (player == null || !player.IsValid) return;
|
||||
if (isBanned)
|
||||
if (await _banManager.IsPlayerBanned(playerInfo))
|
||||
{
|
||||
if (playerInfo.IpAddress != null && !bannedPlayers.Contains(playerInfo.IpAddress))
|
||||
bannedPlayers.Add(playerInfo.IpAddress);
|
||||
if (player.SteamID.ToString() != "" && !bannedPlayers.Contains(player.SteamID.ToString()))
|
||||
bannedPlayers.Add(player.SteamID.ToString());
|
||||
|
||||
Helper.KickPlayer((ushort)player.UserId!, "Banned");
|
||||
if (!bannedPlayers.Contains(playerInfo.SteamId))
|
||||
bannedPlayers.Add(playerInfo.SteamId);
|
||||
|
||||
Server.NextFrame(() =>
|
||||
{
|
||||
if (playerInfo.UserId != null)
|
||||
Helper.KickPlayer((ushort)playerInfo.UserId, "Banned");
|
||||
});
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
//Helper.GivePlayerFlags(player, activeFlags);
|
||||
|
||||
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")
|
||||
{
|
||||
// Chat mute
|
||||
if (player.SteamID.ToString() != "" && !gaggedPlayers.Any(steamid => steamid.Equals(player.SteamID.ToString())))
|
||||
gaggedPlayers.Add(player.SteamID.ToString());
|
||||
if (playerInfo.Slot.HasValue && !gaggedPlayers.Contains(playerInfo.Slot.Value))
|
||||
gaggedPlayers.Add(playerInfo.Slot.Value);
|
||||
|
||||
if (TagsDetected)
|
||||
NativeAPI.IssueServerCommand($"css_tag_mute {player!.SteamID.ToString()}");
|
||||
|
||||
if (durationInSeconds != 0 && duration.Minutes >= 0 && duration.Minutes <= 30)
|
||||
{
|
||||
AddTimer(durationInSeconds, () =>
|
||||
Server.NextFrame(() =>
|
||||
{
|
||||
if (player == null || !player.IsValid || player.SteamID.ToString() == "") return;
|
||||
|
||||
if (player != null && player.SteamID.ToString() != "" && gaggedPlayers.Contains(player.SteamID.ToString()))
|
||||
{
|
||||
if (gaggedPlayers.TryTake(out string? removedItem) && removedItem != player.SteamID.ToString())
|
||||
{
|
||||
gaggedPlayers.Add(removedItem);
|
||||
Server.ExecuteCommand($"css_tag_mute {playerInfo.SteamId}");
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if (TagsDetected)
|
||||
NativeAPI.IssueServerCommand($"css_tag_unmute {player!.SteamID.ToString()}");
|
||||
|
||||
MuteManager _muteManager = new(_database);
|
||||
_ = _muteManager.UnmutePlayer(player!.SteamID.ToString(), 0);
|
||||
}, CounterStrikeSharp.API.Modules.Timers.TimerFlags.STOP_ON_MAPCHANGE);
|
||||
}
|
||||
|
||||
/*
|
||||
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 if (muteType == "MUTE")
|
||||
{
|
||||
// Voice mute
|
||||
player.VoiceFlags = VoiceFlags.Muted;
|
||||
|
||||
if (durationInSeconds != 0 && duration.Minutes >= 0 && duration.Minutes <= 30)
|
||||
{
|
||||
AddTimer(durationInSeconds, () =>
|
||||
{
|
||||
if (player == null || !player.IsValid || player.SteamID.ToString() == "") return;
|
||||
|
||||
/*
|
||||
if (mutedPlayers.Contains((ushort)player.UserId))
|
||||
{
|
||||
if (mutedPlayers.TryTake(out int removedItem) && removedItem != (ushort)player.UserId)
|
||||
{
|
||||
mutedPlayers.Add(removedItem);
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
player.VoiceFlags = VoiceFlags.Normal;
|
||||
|
||||
//MuteManager _muteManager = new(_database);
|
||||
//_ = _muteManager.UnmutePlayer(player.AuthorizedSteamID.SteamId64.ToString(), 1);
|
||||
}, CounterStrikeSharp.API.Modules.Timers.TimerFlags.STOP_ON_MAPCHANGE);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
if (_adminManager._adminCache != null && _adminManager._adminCache.Count > 0)
|
||||
{
|
||||
foreach (var flags in activeFlags)
|
||||
{
|
||||
if (flags == null) continue;
|
||||
string flagsValue = flags.flags.ToString();
|
||||
|
||||
if (!string.IsNullOrEmpty(flagsValue))
|
||||
{
|
||||
string[] _flags = flagsValue.Split(",");
|
||||
|
||||
AddTimer(10, () =>
|
||||
{
|
||||
if (player == null) return;
|
||||
foreach (var _flag in _flags)
|
||||
{
|
||||
if (_flag.StartsWith("@"))
|
||||
{
|
||||
AdminManager.AddPlayerPermissions(player, _flag);
|
||||
}
|
||||
if (_flag.StartsWith("3"))
|
||||
{
|
||||
AdminManager.AddPlayerToGroup(player, _flag);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
});
|
||||
});
|
||||
|
||||
/*
|
||||
CCSPlayerController? player = Utilities.GetPlayerFromSlot(playerSlot);
|
||||
|
||||
if (player == null || !player.IsValid || player.IpAddress == null || player.UserId == null || loadedPlayers.Contains((ushort)player.UserId) || player.IsBot || player.IsHLTV)
|
||||
return;
|
||||
|
||||
if (bannedPlayers.Contains(player.IpAddress) || player.AuthorizedSteamID != null && bannedPlayers.Contains(player.AuthorizedSteamID.SteamId64.ToString()))
|
||||
Helper.KickPlayer((ushort)player.UserId!, "Banned");
|
||||
|
||||
PlayerInfo playerInfo = new PlayerInfo
|
||||
{
|
||||
UserId = player.UserId,
|
||||
Index = (ushort)player.UserId,
|
||||
SteamId = player?.AuthorizedSteamID?.SteamId64.ToString(),
|
||||
Name = player?.PlayerName,
|
||||
IpAddress = player?.IpAddress.Split(":")[0]
|
||||
};
|
||||
|
||||
Task.Run(async () =>
|
||||
{
|
||||
BanManager _banManager = new(dbConnectionString);
|
||||
bool isBanned = await _banManager.IsPlayerBanned(playerInfo);
|
||||
Server.NextFrame(() =>
|
||||
{
|
||||
if (player == null || !player.IsValid) return;
|
||||
if (isBanned)
|
||||
{
|
||||
if (player.IpAddress != null && !bannedPlayers.Contains(player.IpAddress))
|
||||
bannedPlayers.Add(player.IpAddress);
|
||||
if (player.AuthorizedSteamID != null && !bannedPlayers.Contains(player.AuthorizedSteamID.SteamId64.ToString()))
|
||||
bannedPlayers.Add(player.AuthorizedSteamID.SteamId64.ToString());
|
||||
Helper.KickPlayer((ushort)player.UserId!, "Banned");
|
||||
player.VoiceFlags = VoiceFlags.Muted;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
*/
|
||||
|
||||
return HookResult.Continue;
|
||||
}
|
||||
|
||||
private void OnClientDisconnect(int playerSlot)
|
||||
[GameEventHandler]
|
||||
public HookResult OnPlayerDisconnect(EventPlayerDisconnect @event, GameEventInfo info)
|
||||
{
|
||||
CCSPlayerController? player = Utilities.GetPlayerFromSlot(playerSlot);
|
||||
if (!@event.Userid.IsValid || @event.Userid.IsBot)
|
||||
return HookResult.Continue;
|
||||
|
||||
CCSPlayerController? player = @event.Userid;
|
||||
#if DEBUG
|
||||
Logger.LogCritical("[OnClientDisconnect] Before");
|
||||
#endif
|
||||
|
||||
if (player == null || !player.IsValid || player.IsBot || player.IsHLTV) return;
|
||||
if (player is null || !player.IsValid || player.IsBot || player.IsHLTV)
|
||||
return HookResult.Continue;
|
||||
|
||||
if (player.Connected == PlayerConnectedState.PlayerConnecting)
|
||||
return HookResult.Continue;
|
||||
#if DEBUG
|
||||
Logger.LogCritical("[OnClientDisconnect] After Check");
|
||||
#endif
|
||||
|
||||
if (player != null && player.SteamID.ToString() != "" && gaggedPlayers.Contains(player.SteamID.ToString()))
|
||||
if (gaggedPlayers.Contains(player.Slot))
|
||||
{
|
||||
if (gaggedPlayers.TryTake(out string? removedItem) && removedItem != player.SteamID.ToString())
|
||||
{
|
||||
gaggedPlayers.Add(removedItem);
|
||||
}
|
||||
gaggedPlayers = new ConcurrentBag<int>(gaggedPlayers.Where(item => item != player.Slot));
|
||||
}
|
||||
|
||||
/*
|
||||
if (mutedPlayers.Contains((ushort)player.UserId))
|
||||
if (silentPlayers.Contains(player.Slot))
|
||||
{
|
||||
if (mutedPlayers.TryTake(out int removedItem) && removedItem != (ushort)player.UserId)
|
||||
{
|
||||
mutedPlayers.Add(removedItem);
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
if (player!.UserId != null && silentPlayers.Contains((ushort)player.UserId))
|
||||
{
|
||||
silentPlayers.Remove((ushort)player.UserId);
|
||||
silentPlayers = new ConcurrentBag<int>(silentPlayers.Where(item => item != player.Slot));
|
||||
}
|
||||
|
||||
if (player.UserId != null && godPlayers.Contains((ushort)player.UserId))
|
||||
if (godPlayers.Contains(player.Slot))
|
||||
{
|
||||
godPlayers.Remove((ushort)player.UserId);
|
||||
godPlayers = new ConcurrentBag<int>(godPlayers.Where(item => item != player.Slot));
|
||||
}
|
||||
|
||||
if (player.AuthorizedSteamID != null && AdminSQLManager._adminCacheSet.Contains(player.AuthorizedSteamID))
|
||||
if (player.AuthorizedSteamID != null && AdminSQLManager._adminCache.ContainsKey(player.AuthorizedSteamID))
|
||||
{
|
||||
if (AdminSQLManager._adminCacheTimestamps != null && AdminSQLManager._adminCacheTimestamps.TryGetValue(player.AuthorizedSteamID, out DateTime? expirationTime) && expirationTime.HasValue && expirationTime.Value <= DateTime.Now)
|
||||
if (AdminSQLManager._adminCache.TryGetValue(player.AuthorizedSteamID, out DateTime? expirationTime) &&
|
||||
expirationTime <= DateTime.Now)
|
||||
{
|
||||
AdminManager.ClearPlayerPermissions(player.AuthorizedSteamID);
|
||||
AdminManager.RemovePlayerAdminData(player.AuthorizedSteamID);
|
||||
@@ -377,12 +260,16 @@ public partial class CS2_SimpleAdmin
|
||||
}
|
||||
|
||||
if (TagsDetected)
|
||||
NativeAPI.IssueServerCommand($"css_tag_unmute {player!.SteamID.ToString()}");
|
||||
NativeAPI.IssueServerCommand($"css_tag_unmute {player!.SteamID}");
|
||||
|
||||
return HookResult.Continue;
|
||||
}
|
||||
|
||||
private void OnMapStart(string mapName)
|
||||
{
|
||||
gaggedPlayers.Clear();
|
||||
godPlayers.Clear();
|
||||
silentPlayers.Clear();
|
||||
|
||||
if (_database == null) return;
|
||||
|
||||
@@ -434,17 +321,18 @@ public partial class CS2_SimpleAdmin
|
||||
}, CounterStrikeSharp.API.Modules.Timers.TimerFlags.STOP_ON_MAPCHANGE);
|
||||
}
|
||||
|
||||
[GameEventHandler]
|
||||
private HookResult OnPlayerHurt(EventPlayerHurt @event, GameEventInfo info)
|
||||
{
|
||||
CCSPlayerController? player = @event.Userid;
|
||||
|
||||
if (player == null || !player.IsValid || player.IsBot || player.IsHLTV || player.Connected == PlayerConnectedState.PlayerDisconnecting)
|
||||
if (player is null || !player.IsValid || !player.PlayerPawn.IsValid || player.PlayerPawn.Value == null || player.IsBot || player.IsHLTV || player.PlayerPawn.IsValid || player.Connected == PlayerConnectedState.PlayerDisconnecting)
|
||||
return HookResult.Continue;
|
||||
|
||||
if (player.UserId != null && godPlayers.Contains((ushort)player.UserId) && player.PawnIsAlive)
|
||||
if (godPlayers.Contains(player.Slot) && player.PawnIsAlive)
|
||||
{
|
||||
player.Health = 100;
|
||||
player.PlayerPawn.Value!.Health = 100;
|
||||
player.PlayerPawn.Value.Health = 100;
|
||||
}
|
||||
|
||||
return HookResult.Continue;
|
||||
|
||||
@@ -116,7 +116,7 @@ namespace CS2_SimpleAdmin
|
||||
|
||||
public static void KickPlayer(ushort userId, string? reason = null)
|
||||
{
|
||||
NativeAPI.IssueServerCommand($"kickid {userId} {reason}");
|
||||
Server.ExecuteCommand($"kickid {userId} {reason}");
|
||||
}
|
||||
|
||||
public static void PrintToCenterAll(string message)
|
||||
@@ -148,8 +148,12 @@ namespace CS2_SimpleAdmin
|
||||
|
||||
internal static void handleVotes(CCSPlayerController player, ChatMenuOption option)
|
||||
{
|
||||
if (CS2_SimpleAdmin.voteInProgress)
|
||||
if (CS2_SimpleAdmin.voteInProgress && !CS2_SimpleAdmin.votePlayers.Contains(player.Slot))
|
||||
{
|
||||
CS2_SimpleAdmin.votePlayers.Add(player.Slot);
|
||||
CS2_SimpleAdmin.voteAnswers[option.Text]++;
|
||||
option.Disabled = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -75,15 +75,26 @@ namespace CS2_SimpleAdmin
|
||||
|
||||
public async Task<List<dynamic>> IsPlayerMuted(string steamId)
|
||||
{
|
||||
if (string.IsNullOrEmpty(steamId))
|
||||
{
|
||||
return new List<dynamic>();
|
||||
}
|
||||
|
||||
await using var connection = _database.GetConnection();
|
||||
|
||||
DateTime now = DateTime.Now;
|
||||
|
||||
DateTime currentTimeUtc = DateTime.UtcNow;
|
||||
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();
|
||||
|
||||
try
|
||||
{
|
||||
var parameters = new { PlayerSteamID = steamId, CurrentTime = currentTimeUtc };
|
||||
var activeMutes = (await connection.QueryAsync(sql, parameters)).ToList();
|
||||
return activeMutes;
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
return new List<dynamic>();
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<int> GetPlayerMutes(string steamId)
|
||||
{
|
||||
@@ -134,9 +145,9 @@ namespace CS2_SimpleAdmin
|
||||
|
||||
public async Task CheckMute(PlayerInfo player)
|
||||
{
|
||||
if (player.UserId == null) return;
|
||||
if (player.UserId == null || player.SteamId == null) return;
|
||||
|
||||
string steamId = player.SteamId!;
|
||||
string steamId = player.SteamId;
|
||||
List<dynamic> activeMutes = await IsPlayerMuted(steamId);
|
||||
|
||||
if (activeMutes.Count > 0)
|
||||
@@ -149,11 +160,13 @@ namespace CS2_SimpleAdmin
|
||||
|
||||
if (muteType == "GAG")
|
||||
{
|
||||
if (!CS2_SimpleAdmin.gaggedPlayers.Any(steamid => steamid == player.SteamId!.ToString()))
|
||||
CS2_SimpleAdmin.gaggedPlayers.Add(player.SteamId!.ToString());
|
||||
if (player.Slot.HasValue && !CS2_SimpleAdmin.gaggedPlayers.Contains(player.Slot.Value))
|
||||
{
|
||||
CS2_SimpleAdmin.gaggedPlayers.Add(player.Slot.Value);
|
||||
}
|
||||
|
||||
if (CS2_SimpleAdmin.TagsDetected)
|
||||
NativeAPI.IssueServerCommand($"css_tag_mute {player!.SteamId!.ToString()}");
|
||||
NativeAPI.IssueServerCommand($"css_tag_mute {player!.SteamId}");
|
||||
|
||||
/*
|
||||
CCSPlayerController currentPlayer = player;
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
{
|
||||
public int? Index { get; set; }
|
||||
public int? UserId { get; set; }
|
||||
public int? Slot { get; set; }
|
||||
public string? SteamId { get; set; }
|
||||
public string? Name { get; set; }
|
||||
public string? IpAddress { get; set; }
|
||||
|
||||
@@ -15,8 +15,7 @@ Manage your Counter-Strike 2 server by simple commands :)
|
||||
- css_addadmin <steamid> <name> <flags/groups> <immunity> [time in minutes] - Add admin by steamid // @css/root
|
||||
- css_deladmin <steamid> - Delete admin by steamid // @css/root
|
||||
- css_reladmin - Reload sql admins // @css/root
|
||||
- css_silentmode - Enable or disable silentmode for admins // @css/kick
|
||||
- css_hide - Hide admin on scoreboard // @css/kick
|
||||
- css_hide - Hide admin on scoreboard and commands action // @css/kick
|
||||
- css_admin - Display all admin commands // @css/generic
|
||||
- css_who <#userid or name> - Display informations about player // @css/generic
|
||||
- css_players - Display player list // @css/generic
|
||||
@@ -59,7 +58,7 @@ Manage your Counter-Strike 2 server by simple commands :)
|
||||
```
|
||||
|
||||
### Requirments
|
||||
- [CounterStrikeSharp](https://github.com/roflmuffin/CounterStrikeSharp/) **tested on v144**
|
||||
- [CounterStrikeSharp](https://github.com/roflmuffin/CounterStrikeSharp/) **tested on v159**
|
||||
- MySQL **tested on MySQL (MariaDB) Server version: 10.11.4-MariaDB-1~deb12u1 Debian 12**
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user