mirror of
https://github.com/daffyyyy/CS2-SimpleAdmin.git
synced 2026-02-18 02:41:55 +00:00
1.2.2a UPDATE
- Fixed css_addban, css_addmute - New command `css_hp` - New command `css_god` - New command `css_speed`
This commit is contained in:
404
Events.cs
404
Events.cs
@@ -6,255 +6,283 @@ using CounterStrikeSharp.API.Modules.Entities;
|
||||
using System.Text;
|
||||
using static CounterStrikeSharp.API.Core.Listeners;
|
||||
|
||||
namespace CS2_SimpleAdmin
|
||||
namespace CS2_SimpleAdmin;
|
||||
public partial class CS2_SimpleAdmin
|
||||
{
|
||||
public partial class CS2_SimpleAdmin
|
||||
private void registerEvents()
|
||||
{
|
||||
private void registerEvents()
|
||||
{
|
||||
RegisterListener<OnClientAuthorized>(OnClientAuthorized);
|
||||
RegisterListener<OnClientDisconnect>(OnClientDisconnect);
|
||||
RegisterListener<OnMapStart>(OnMapStart);
|
||||
AddCommandListener("say", OnCommandSay);
|
||||
AddCommandListener("say_team", OnCommandTeamSay);
|
||||
AddCommandListener("callvote", OnCommandCallVote);
|
||||
}
|
||||
private HookResult OnCommandSay(CCSPlayerController? player, CommandInfo info)
|
||||
{
|
||||
if (player == null || !player.IsValid || info.GetArg(1).Length == 0) return HookResult.Continue;
|
||||
RegisterListener<OnClientAuthorized>(OnClientAuthorized);
|
||||
RegisterListener<OnClientDisconnect>(OnClientDisconnect);
|
||||
RegisterListener<OnMapStart>(OnMapStart);
|
||||
RegisterEventHandler<EventPlayerHurt>(OnPlayerHurt);
|
||||
RegisterEventHandler<EventRoundStart>(OnRoundStart);
|
||||
AddCommandListener("say", OnCommandSay);
|
||||
AddCommandListener("say_team", OnCommandTeamSay);
|
||||
AddCommandListener("callvote", OnCommandCallVote);
|
||||
}
|
||||
|
||||
if (gaggedPlayers.Contains((int)player.Index))
|
||||
{
|
||||
return HookResult.Handled;
|
||||
}
|
||||
private HookResult OnRoundStart(EventRoundStart @event, GameEventInfo info)
|
||||
{
|
||||
GodPlayers.Clear();
|
||||
return HookResult.Continue;
|
||||
}
|
||||
|
||||
return HookResult.Continue;
|
||||
private HookResult OnCommandSay(CCSPlayerController? player, CommandInfo info)
|
||||
{
|
||||
if (player == null || !player.IsValid || info.GetArg(1).Length == 0) return HookResult.Continue;
|
||||
|
||||
if (gaggedPlayers.Contains((int)player.Index))
|
||||
{
|
||||
return HookResult.Handled;
|
||||
}
|
||||
|
||||
private HookResult OnCommandTeamSay(CCSPlayerController? player, CommandInfo info)
|
||||
return HookResult.Continue;
|
||||
}
|
||||
|
||||
private HookResult OnCommandTeamSay(CCSPlayerController? player, CommandInfo info)
|
||||
{
|
||||
if (player == null || !player.IsValid || info.GetArg(1).Length == 0) return HookResult.Continue;
|
||||
|
||||
if (gaggedPlayers.Contains((int)player.Index))
|
||||
{
|
||||
if (player == null || !player.IsValid || info.GetArg(1).Length == 0) return HookResult.Continue;
|
||||
return HookResult.Handled;
|
||||
}
|
||||
|
||||
if (gaggedPlayers.Contains((int)player.Index))
|
||||
if (info.GetArg(1).StartsWith("@"))
|
||||
{
|
||||
StringBuilder sb = new();
|
||||
|
||||
if (AdminManager.PlayerHasPermissions(player, "@css/chat"))
|
||||
{
|
||||
return HookResult.Handled;
|
||||
}
|
||||
|
||||
if (info.GetArg(1).StartsWith("@"))
|
||||
{
|
||||
StringBuilder sb = new();
|
||||
|
||||
if (AdminManager.PlayerHasPermissions(player, "@css/chat"))
|
||||
sb.Append(_localizer!["sa_adminchat_template_admin", player.PlayerName, info.GetArg(1).Remove(0, 1)]);
|
||||
foreach (var p in Utilities.GetPlayers().Where(p => p.IsValid && !p.IsBot && !p.IsHLTV && AdminManager.PlayerHasPermissions(p, "@css/chat")))
|
||||
{
|
||||
sb.Append(_localizer!["sa_adminchat_template_admin", player.PlayerName, info.GetArg(1).Remove(0, 1)]);
|
||||
foreach (var p in Utilities.GetPlayers().Where(p => p.IsValid && !p.IsBot && !p.IsHLTV && AdminManager.PlayerHasPermissions(p, "@css/chat")))
|
||||
{
|
||||
p.PrintToChat(sb.ToString());
|
||||
}
|
||||
p.PrintToChat(sb.ToString());
|
||||
}
|
||||
else
|
||||
{
|
||||
sb.Append(_localizer!["sa_adminchat_template_player", player.PlayerName, info.GetArg(1).Remove(0, 1)]);
|
||||
player.PrintToChat(sb.ToString());
|
||||
foreach (var p in Utilities.GetPlayers().Where(p => p.IsValid && !p.IsBot && !p.IsHLTV && AdminManager.PlayerHasPermissions(p, "@css/chat")))
|
||||
{
|
||||
p.PrintToChat(sb.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
return HookResult.Handled;
|
||||
}
|
||||
|
||||
return HookResult.Continue;
|
||||
}
|
||||
|
||||
private HookResult OnCommandCallVote(CCSPlayerController? player, CommandInfo info)
|
||||
{
|
||||
string reason = info.GetArg(1);
|
||||
|
||||
if (reason == "kick" || reason == "ban")
|
||||
else
|
||||
{
|
||||
int.TryParse(info.GetArg(2), out int target);
|
||||
if (target > 0)
|
||||
sb.Append(_localizer!["sa_adminchat_template_player", player.PlayerName, info.GetArg(1).Remove(0, 1)]);
|
||||
player.PrintToChat(sb.ToString());
|
||||
foreach (var p in Utilities.GetPlayers().Where(p => p.IsValid && !p.IsBot && !p.IsHLTV && AdminManager.PlayerHasPermissions(p, "@css/chat")))
|
||||
{
|
||||
if (!player!.CanTarget(Utilities.GetPlayerFromUserid(target)))
|
||||
return HookResult.Handled;
|
||||
p.PrintToChat(sb.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
return HookResult.Continue;
|
||||
return HookResult.Handled;
|
||||
}
|
||||
|
||||
private void OnClientAuthorized(int playerSlot, SteamID steamID)
|
||||
return HookResult.Continue;
|
||||
}
|
||||
|
||||
private HookResult OnCommandCallVote(CCSPlayerController? player, CommandInfo info)
|
||||
{
|
||||
string reason = info.GetArg(1);
|
||||
|
||||
if (reason == "kick" || reason == "ban")
|
||||
{
|
||||
CCSPlayerController? player = Utilities.GetPlayerFromSlot(playerSlot);
|
||||
|
||||
if (player == null || !player.IsValid || player.IsBot || player.IsHLTV)
|
||||
return;
|
||||
|
||||
if (player.AuthorizedSteamID == null)
|
||||
int.TryParse(info.GetArg(2), out int target);
|
||||
if (target > 0)
|
||||
{
|
||||
AddTimer(3.0f, () =>
|
||||
{
|
||||
OnClientAuthorized(playerSlot, steamID);
|
||||
});
|
||||
return;
|
||||
if (!player!.CanTarget(Utilities.GetPlayerFromUserid(target)))
|
||||
return HookResult.Handled;
|
||||
}
|
||||
}
|
||||
|
||||
PlayerInfo playerInfo = new PlayerInfo
|
||||
return HookResult.Continue;
|
||||
}
|
||||
|
||||
private void OnClientAuthorized(int playerSlot, SteamID steamID)
|
||||
{
|
||||
CCSPlayerController? player = Utilities.GetPlayerFromSlot(playerSlot);
|
||||
|
||||
if (player == null || !player.IsValid || player.IsBot || player.IsHLTV)
|
||||
return;
|
||||
|
||||
if (player.AuthorizedSteamID == null)
|
||||
{
|
||||
AddTimer(3.0f, () =>
|
||||
{
|
||||
UserId = player.UserId,
|
||||
Index = (int)player.Index,
|
||||
SteamId = player?.AuthorizedSteamID?.SteamId64.ToString(),
|
||||
Name = player?.PlayerName,
|
||||
IpAddress = player?.IpAddress?.Split(":")[0]
|
||||
};
|
||||
OnClientAuthorized(playerSlot, steamID);
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
Task.Run(async () =>
|
||||
PlayerInfo playerInfo = new PlayerInfo
|
||||
{
|
||||
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 || !player.IsValid) 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 || !player.IsValid) 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 (isBanned)
|
||||
{
|
||||
if (player == null || !player.IsValid) return;
|
||||
if (isBanned)
|
||||
{
|
||||
Helper.KickPlayer((ushort)player.UserId!, "Banned");
|
||||
return;
|
||||
}
|
||||
Helper.KickPlayer((ushort)player.UserId!, "Banned");
|
||||
return;
|
||||
}
|
||||
|
||||
if (activeMutes.Count > 0)
|
||||
if (activeMutes.Count > 0)
|
||||
{
|
||||
foreach (var mute in activeMutes)
|
||||
{
|
||||
foreach (var mute in activeMutes)
|
||||
string muteType = mute.type;
|
||||
TimeSpan duration = mute.ends - mute.created;
|
||||
int durationInSeconds = (int)duration.TotalSeconds;
|
||||
|
||||
if (muteType == "GAG")
|
||||
{
|
||||
string muteType = mute.type;
|
||||
TimeSpan duration = mute.ends - mute.created;
|
||||
int durationInSeconds = (int)duration.TotalSeconds;
|
||||
// Chat mute
|
||||
if (!gaggedPlayers.Any(index => index == player.Index))
|
||||
gaggedPlayers.Add((int)player.Index);
|
||||
|
||||
if (muteType == "GAG")
|
||||
if (TagsDetected)
|
||||
NativeAPI.IssueServerCommand($"css_tag_mute {player.Index}");
|
||||
|
||||
if (duration.Minutes >= 0 && duration.Minutes <= 30)
|
||||
{
|
||||
// Chat mute
|
||||
if (!gaggedPlayers.Any(index => index == player.Index))
|
||||
gaggedPlayers.Add((int)player.Index);
|
||||
|
||||
if (TagsDetected)
|
||||
NativeAPI.IssueServerCommand($"css_tag_mute {player.Index}");
|
||||
|
||||
if (duration.Minutes >= 0 && duration.Minutes <= 30)
|
||||
AddTimer(durationInSeconds, () =>
|
||||
{
|
||||
AddTimer(durationInSeconds, () =>
|
||||
if (player == null || !player.IsValid || player.AuthorizedSteamID == null) return;
|
||||
|
||||
if (gaggedPlayers.Contains((int)player.Index))
|
||||
{
|
||||
if (player == null || !player.IsValid || player.AuthorizedSteamID == null) return;
|
||||
|
||||
if (gaggedPlayers.Contains((int)player.Index))
|
||||
if (gaggedPlayers.TryTake(out int removedItem) && removedItem != (int)player.Index)
|
||||
{
|
||||
if (gaggedPlayers.TryTake(out int removedItem) && removedItem != (int)player.Index)
|
||||
{
|
||||
gaggedPlayers.Add(removedItem);
|
||||
}
|
||||
gaggedPlayers.Add(removedItem);
|
||||
}
|
||||
}
|
||||
|
||||
if (TagsDetected)
|
||||
NativeAPI.IssueServerCommand($"css_tag_unmute {player.Index}");
|
||||
if (TagsDetected)
|
||||
NativeAPI.IssueServerCommand($"css_tag_unmute {player.Index}");
|
||||
|
||||
MuteManager _muteManager = new(dbConnectionString);
|
||||
_ = _muteManager.UnmutePlayer(player.AuthorizedSteamID.SteamId64.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);
|
||||
}
|
||||
*/
|
||||
MuteManager _muteManager = new(dbConnectionString);
|
||||
_ = _muteManager.UnmutePlayer(player.AuthorizedSteamID.SteamId64.ToString(), 0);
|
||||
}, CounterStrikeSharp.API.Modules.Timers.TimerFlags.STOP_ON_MAPCHANGE);
|
||||
}
|
||||
else
|
||||
|
||||
|
||||
/*
|
||||
CCSPlayerController currentPlayer = player;
|
||||
|
||||
if (mute.duration == 0 || durationInSeconds >= 1800) continue;
|
||||
|
||||
await Task.Delay(TimeSpan.FromSeconds(durationInSeconds));
|
||||
|
||||
if (currentPlayer != null && currentPlayer.IsValid)
|
||||
{
|
||||
// Voice mute
|
||||
player.VoiceFlags = VoiceFlags.Muted;
|
||||
NativeAPI.IssueServerCommand($"css_tag_unmute {currentPlayer.Index.ToString()}");
|
||||
await UnmutePlayer(currentPlayer.AuthorizedSteamID.SteamId64.ToString(), 0);
|
||||
}
|
||||
*/
|
||||
}
|
||||
else
|
||||
{
|
||||
// Voice mute
|
||||
player.VoiceFlags = VoiceFlags.Muted;
|
||||
|
||||
if (duration.Minutes >= 0 && duration.Minutes <= 30)
|
||||
if (duration.Minutes >= 0 && duration.Minutes <= 30)
|
||||
{
|
||||
AddTimer(durationInSeconds, () =>
|
||||
{
|
||||
AddTimer(durationInSeconds, () =>
|
||||
if (player == null || !player.IsValid || player.AuthorizedSteamID == null) return;
|
||||
|
||||
if (mutedPlayers.Contains((int)player.Index))
|
||||
{
|
||||
if (player == null || !player.IsValid || player.AuthorizedSteamID == null) return;
|
||||
|
||||
if (mutedPlayers.Contains((int)player.Index))
|
||||
if (mutedPlayers.TryTake(out int removedItem) && removedItem != (int)player.Index)
|
||||
{
|
||||
if (mutedPlayers.TryTake(out int removedItem) && removedItem != (int)player.Index)
|
||||
{
|
||||
mutedPlayers.Add(removedItem);
|
||||
}
|
||||
mutedPlayers.Add(removedItem);
|
||||
}
|
||||
}
|
||||
|
||||
player.VoiceFlags = VoiceFlags.Normal;
|
||||
player.VoiceFlags = VoiceFlags.Normal;
|
||||
|
||||
//MuteManager _muteManager = new(dbConnectionString);
|
||||
//_ = _muteManager.UnmutePlayer(player.AuthorizedSteamID.SteamId64.ToString(), 1);
|
||||
}, CounterStrikeSharp.API.Modules.Timers.TimerFlags.STOP_ON_MAPCHANGE);
|
||||
}
|
||||
//MuteManager _muteManager = new(dbConnectionString);
|
||||
//_ = _muteManager.UnmutePlayer(player.AuthorizedSteamID.SteamId64.ToString(), 1);
|
||||
}, CounterStrikeSharp.API.Modules.Timers.TimerFlags.STOP_ON_MAPCHANGE);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
private void OnClientDisconnect(int playerSlot)
|
||||
{
|
||||
CCSPlayerController? player = Utilities.GetPlayerFromSlot(playerSlot);
|
||||
|
||||
if (player == null || !player.IsValid || player.IsBot || player.IsHLTV) return;
|
||||
|
||||
if (gaggedPlayers.Contains((int)player.Index))
|
||||
{
|
||||
if (gaggedPlayers.TryTake(out int removedItem) && removedItem != (int)player.Index)
|
||||
{
|
||||
gaggedPlayers.Add(removedItem);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnClientDisconnect(int playerSlot)
|
||||
if (mutedPlayers.Contains((int)player.Index))
|
||||
{
|
||||
CCSPlayerController? player = Utilities.GetPlayerFromSlot(playerSlot);
|
||||
|
||||
if (player == null || !player.IsValid || player.IsBot || player.IsHLTV) return;
|
||||
|
||||
if (gaggedPlayers.Contains((int)player.Index))
|
||||
if (mutedPlayers.TryTake(out int removedItem) && removedItem != (int)player.Index)
|
||||
{
|
||||
if (gaggedPlayers.TryTake(out int removedItem) && removedItem != (int)player.Index)
|
||||
{
|
||||
gaggedPlayers.Add(removedItem);
|
||||
}
|
||||
mutedPlayers.Add(removedItem);
|
||||
}
|
||||
|
||||
if (mutedPlayers.Contains((int)player.Index))
|
||||
{
|
||||
if (mutedPlayers.TryTake(out int removedItem) && removedItem != (int)player.Index)
|
||||
{
|
||||
mutedPlayers.Add(removedItem);
|
||||
}
|
||||
}
|
||||
|
||||
if (TagsDetected)
|
||||
NativeAPI.IssueServerCommand($"css_tag_unmute {player!.Index.ToString()}");
|
||||
}
|
||||
|
||||
private void OnMapStart(string mapName)
|
||||
if (GodPlayers.Contains((int)player.Index))
|
||||
{
|
||||
AddTimer(120.0f, () =>
|
||||
{
|
||||
BanManager _banManager = new(dbConnectionString);
|
||||
_ = _banManager.ExpireOldBans();
|
||||
MuteManager _muteManager = new(dbConnectionString);
|
||||
_ = _muteManager.ExpireOldMutes();
|
||||
}, CounterStrikeSharp.API.Modules.Timers.TimerFlags.REPEAT | CounterStrikeSharp.API.Modules.Timers.TimerFlags.STOP_ON_MAPCHANGE);
|
||||
GodPlayers.Remove((int)player.Index);
|
||||
}
|
||||
|
||||
string? path = Path.GetDirectoryName(ModuleDirectory);
|
||||
if (Directory.Exists(path + "/CS2-Tags"))
|
||||
{
|
||||
TagsDetected = true;
|
||||
}
|
||||
if (TagsDetected)
|
||||
NativeAPI.IssueServerCommand($"css_tag_unmute {player!.Index.ToString()}");
|
||||
}
|
||||
|
||||
private void OnMapStart(string mapName)
|
||||
{
|
||||
AddTimer(120.0f, () =>
|
||||
{
|
||||
BanManager _banManager = new(dbConnectionString);
|
||||
_ = _banManager.ExpireOldBans();
|
||||
MuteManager _muteManager = new(dbConnectionString);
|
||||
_ = _muteManager.ExpireOldMutes();
|
||||
}, CounterStrikeSharp.API.Modules.Timers.TimerFlags.REPEAT | CounterStrikeSharp.API.Modules.Timers.TimerFlags.STOP_ON_MAPCHANGE);
|
||||
|
||||
string? path = Path.GetDirectoryName(ModuleDirectory);
|
||||
if (Directory.Exists(path + "/CS2-Tags"))
|
||||
{
|
||||
TagsDetected = true;
|
||||
}
|
||||
}
|
||||
|
||||
private HookResult OnPlayerHurt(EventPlayerHurt @event, GameEventInfo info)
|
||||
{
|
||||
CCSPlayerController? player = @event.Userid;
|
||||
|
||||
if (player == null || !player.IsValid)
|
||||
return HookResult.Continue;
|
||||
|
||||
if (GodPlayers.Contains((int)player.Index) && player.PawnIsAlive)
|
||||
{
|
||||
player.Health = 100;
|
||||
player.PlayerPawn.Value!.Health = 100;
|
||||
}
|
||||
|
||||
return HookResult.Continue;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user