mirror of
https://github.com/daffyyyy/CS2-SimpleAdmin.git
synced 2026-02-18 18:49:23 +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:
350
Events.cs
350
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())
|
||||
)
|
||||
Helper.KickPlayer((ushort)player.UserId!, "Banned");
|
||||
{
|
||||
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 () =>
|
||||
{
|
||||
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!);
|
||||
|
||||
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 (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");
|
||||
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 (TagsDetected)
|
||||
NativeAPI.IssueServerCommand($"css_tag_mute {player!.SteamID.ToString()}");
|
||||
|
||||
if (durationInSeconds != 0 && duration.Minutes >= 0 && duration.Minutes <= 30)
|
||||
{
|
||||
AddTimer(durationInSeconds, () =>
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
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(() =>
|
||||
BanManager _banManager = new(_database, Config);
|
||||
|
||||
MuteManager _muteManager = new(_database);
|
||||
List<dynamic> activeMutes = await _muteManager.IsPlayerMuted(playerInfo.SteamId);
|
||||
|
||||
if (await _banManager.IsPlayerBanned(playerInfo))
|
||||
{
|
||||
if (player == null || !player.IsValid) return;
|
||||
if (isBanned)
|
||||
if (playerInfo.IpAddress != null && !bannedPlayers.Contains(playerInfo.IpAddress))
|
||||
bannedPlayers.Add(playerInfo.IpAddress);
|
||||
|
||||
if (!bannedPlayers.Contains(playerInfo.SteamId))
|
||||
bannedPlayers.Add(playerInfo.SteamId);
|
||||
|
||||
Server.NextFrame(() =>
|
||||
{
|
||||
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");
|
||||
if (playerInfo.UserId != null)
|
||||
Helper.KickPlayer((ushort)playerInfo.UserId, "Banned");
|
||||
});
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (activeMutes.Count > 0)
|
||||
{
|
||||
foreach (var mute in activeMutes)
|
||||
{
|
||||
string muteType = mute.type;
|
||||
|
||||
if (muteType == "GAG")
|
||||
{
|
||||
// Chat mute
|
||||
if (playerInfo.Slot.HasValue && !gaggedPlayers.Contains(playerInfo.Slot.Value))
|
||||
gaggedPlayers.Add(playerInfo.Slot.Value);
|
||||
|
||||
if (TagsDetected)
|
||||
{
|
||||
Server.NextFrame(() =>
|
||||
{
|
||||
Server.ExecuteCommand($"css_tag_mute {playerInfo.SteamId}");
|
||||
});
|
||||
}
|
||||
}
|
||||
else if (muteType == "MUTE")
|
||||
{
|
||||
// Voice mute
|
||||
Server.NextFrame(() =>
|
||||
{
|
||||
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;
|
||||
|
||||
Reference in New Issue
Block a user