- Updated minimum CounterStrikeSharp version to **154**
- Fixed? issue with checking ban status for player with authorization problem
- Added additional checks for immunity
- Added new config variable `BanType` if `1` = `SteamID + IP`, if `0` = `SteamID`
This commit is contained in:
Dawid Bepierszcz
2024-01-24 23:50:49 +01:00
parent b5600d7e73
commit 855f087a7b
5 changed files with 524 additions and 307 deletions

View File

@@ -23,11 +23,12 @@ namespace CS2_SimpleAdmin
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)";
CS2_SimpleAdminConfig config = new CS2_SimpleAdminConfig();
await connection.ExecuteAsync(sql, new
{
playerSteamid = player.SteamId,
playerName = player.Name,
playerIp = player.IpAddress,
playerIp = config.BanType == 1 ? player.IpAddress : null,
adminSteamid = issuer.SteamId == null ? "Console" : issuer.SteamId,
adminName = issuer.Name == null ? "Console" : issuer.Name,
banReason = reason,

View File

@@ -18,7 +18,7 @@ using System.Text;
namespace CS2_SimpleAdmin;
[MinimumApiVersion(142)]
[MinimumApiVersion(154)]
public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdminConfig>
{
public static IStringLocalizer? _localizer;
@@ -37,7 +37,7 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdmin
public override string ModuleName => "CS2-SimpleAdmin";
public override string ModuleDescription => "Simple admin plugin for Counter-Strike 2 :)";
public override string ModuleAuthor => "daffyy";
public override string ModuleVersion => "1.2.7e";
public override string ModuleVersion => "1.2.8a";
public CS2_SimpleAdminConfig Config { get; set; } = new();
@@ -308,75 +308,78 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdmin
playersToTarget.ForEach(player =>
{
PlayerInfo playerInfo = new PlayerInfo
if (caller!.CanTarget(player))
{
UserId = player.UserId,
Index = (int)player.Index,
SteamId = player?.AuthorizedSteamID?.SteamId64.ToString(),
Name = player?.PlayerName,
IpAddress = player?.IpAddress?.Split(":")[0]
};
Task.Run(async () =>
{
int totalBans = 0;
int totalMutes = 0;
totalBans = await _banManager.GetPlayerBans(playerInfo);
totalMutes = await _muteManager.GetPlayerMutes(playerInfo.SteamId!);
Server.NextFrame(() =>
PlayerInfo playerInfo = new PlayerInfo
{
if (caller != null)
UserId = player.UserId,
Index = (int)player.Index,
SteamId = player?.AuthorizedSteamID?.SteamId64.ToString(),
Name = player?.PlayerName,
IpAddress = player?.IpAddress?.Split(":")[0]
};
Task.Run(async () =>
{
int totalBans = 0;
int totalMutes = 0;
totalBans = await _banManager.GetPlayerBans(playerInfo);
totalMutes = await _muteManager.GetPlayerMutes(playerInfo.SteamId!);
Server.NextFrame(() =>
{
caller!.PrintToConsole($"--------- INFO ABOUT \"{playerInfo.Name}\" ---------");
caller!.PrintToConsole($"• Clan: \"{player!.Clan}\" Name: \"{playerInfo.Name}\"");
caller!.PrintToConsole($"• UserID: \"{playerInfo.UserId}\"");
if (playerInfo.SteamId != null)
caller!.PrintToConsole($"• SteamID64: \"{playerInfo.SteamId}\"");
if (player.AuthorizedSteamID != null)
if (caller != null)
{
caller!.PrintToConsole($"• SteamID2: \"{player.AuthorizedSteamID.SteamId2}\"");
caller!.PrintToConsole($"• Community link: \"{player.AuthorizedSteamID.ToCommunityUrl()}\"");
}
if (playerInfo.IpAddress != null)
caller!.PrintToConsole($"• IP Address: \"{playerInfo.IpAddress}\"");
caller!.PrintToConsole($"• Ping: \"{player.Ping}\"");
if (player.AuthorizedSteamID != null)
{
caller!.PrintToConsole($"• Total Bans: \"{totalBans}\"");
caller!.PrintToConsole($"• Total Mutes: \"{totalMutes}\"");
}
caller!.PrintToConsole($"--------- INFO ABOUT \"{playerInfo.Name}\" ---------");
caller!.PrintToConsole($"--------- END INFO ABOUT \"{player.PlayerName}\" ---------");
}
else
{
Server.PrintToConsole($"--------- INFO ABOUT \"{playerInfo.Name}\" ---------");
caller!.PrintToConsole($"• Clan: \"{player!.Clan}\" Name: \"{playerInfo.Name}\"");
caller!.PrintToConsole($"• UserID: \"{playerInfo.UserId}\"");
if (playerInfo.SteamId != null)
caller!.PrintToConsole($"• SteamID64: \"{playerInfo.SteamId}\"");
if (player.AuthorizedSteamID != null)
{
caller!.PrintToConsole($"• SteamID2: \"{player.AuthorizedSteamID.SteamId2}\"");
caller!.PrintToConsole($"• Community link: \"{player.AuthorizedSteamID.ToCommunityUrl()}\"");
}
if (playerInfo.IpAddress != null)
caller!.PrintToConsole($"• IP Address: \"{playerInfo.IpAddress}\"");
caller!.PrintToConsole($"• Ping: \"{player.Ping}\"");
if (player.AuthorizedSteamID != null)
{
caller!.PrintToConsole($"• Total Bans: \"{totalBans}\"");
caller!.PrintToConsole($"• Total Mutes: \"{totalMutes}\"");
}
Server.PrintToConsole($"• Clan: \"{player!.Clan}\" Name: \"{playerInfo.Name}\"");
Server.PrintToConsole($"• UserID: \"{playerInfo.UserId}\"");
if (playerInfo.SteamId != null)
Server.PrintToConsole($"• SteamID64: \"{playerInfo.SteamId}\"");
if (player.AuthorizedSteamID != null)
{
Server.PrintToConsole($"• SteamID2: \"{player.AuthorizedSteamID.SteamId2}\"");
Server.PrintToConsole($"• Community link: \"{player.AuthorizedSteamID.ToCommunityUrl()}\"");
caller!.PrintToConsole($"--------- END INFO ABOUT \"{player.PlayerName}\" ---------");
}
if (playerInfo.IpAddress != null)
Server.PrintToConsole($"• IP Address: \"{playerInfo.IpAddress}\"");
Server.PrintToConsole($"• Ping: \"{player.Ping}\"");
if (player.AuthorizedSteamID != null)
else
{
Server.PrintToConsole($"• Total Bans: \"{totalBans}\"");
Server.PrintToConsole($"• Total Mutes: \"{totalMutes}\"");
}
Server.PrintToConsole($"--------- INFO ABOUT \"{playerInfo.Name}\" ---------");
Server.PrintToConsole($"--------- END INFO ABOUT \"{player.PlayerName}\" ---------");
}
Server.PrintToConsole($"• Clan: \"{player!.Clan}\" Name: \"{playerInfo.Name}\"");
Server.PrintToConsole($"• UserID: \"{playerInfo.UserId}\"");
if (playerInfo.SteamId != null)
Server.PrintToConsole($"• SteamID64: \"{playerInfo.SteamId}\"");
if (player.AuthorizedSteamID != null)
{
Server.PrintToConsole($"• SteamID2: \"{player.AuthorizedSteamID.SteamId2}\"");
Server.PrintToConsole($"• Community link: \"{player.AuthorizedSteamID.ToCommunityUrl()}\"");
}
if (playerInfo.IpAddress != null)
Server.PrintToConsole($"• IP Address: \"{playerInfo.IpAddress}\"");
Server.PrintToConsole($"• Ping: \"{player.Ping}\"");
if (player.AuthorizedSteamID != null)
{
Server.PrintToConsole($"• Total Bans: \"{totalBans}\"");
Server.PrintToConsole($"• Total Mutes: \"{totalMutes}\"");
}
Server.PrintToConsole($"--------- END INFO ABOUT \"{player.PlayerName}\" ---------");
}
});
});
});
}
});
}
@@ -430,23 +433,26 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdmin
targets.Players.ForEach(player =>
{
player.Pawn.Value!.Freeze();
if (caller!.CanTarget(player))
{
player.Pawn.Value!.Freeze();
if (command.ArgCount >= 2)
{
player.PrintToCenter(_localizer!["sa_player_kick_message", reason, caller == null ? "Console" : caller.PlayerName]);
AddTimer(Config.KickTime, () => Helper.KickPlayer((ushort)player.UserId!, reason));
}
else
{
AddTimer(Config.KickTime, () => Helper.KickPlayer((ushort)player.UserId!));
}
if (command.ArgCount >= 2)
{
player.PrintToCenter(_localizer!["sa_player_kick_message", reason, caller == null ? "Console" : caller.PlayerName]);
AddTimer(Config.KickTime, () => Helper.KickPlayer((ushort)player.UserId!, reason));
}
else
{
AddTimer(Config.KickTime, () => Helper.KickPlayer((ushort)player.UserId!));
}
if (caller == null || caller != null && caller.UserId != null && !silentPlayers.Contains((ushort)caller.UserId))
{
StringBuilder sb = new(_localizer!["sa_prefix"]);
sb.Append(_localizer["sa_admin_kick_message", caller == null ? "Console" : caller.PlayerName, player.PlayerName, reason]);
Server.PrintToChatAll(sb.ToString());
if (caller == null || caller != null && caller.UserId != null && !silentPlayers.Contains((ushort)caller.UserId))
{
StringBuilder sb = new(_localizer!["sa_prefix"]);
sb.Append(_localizer["sa_admin_kick_message", caller == null ? "Console" : caller.PlayerName, player.PlayerName, reason]);
Server.PrintToChatAll(sb.ToString());
}
}
});
}
@@ -477,73 +483,76 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdmin
playersToTarget.ForEach(player =>
{
PlayerInfo playerInfo = new PlayerInfo
if (caller!.CanTarget(player))
{
SteamId = player?.AuthorizedSteamID?.SteamId64.ToString(),
Name = player?.PlayerName,
IpAddress = player?.IpAddress?.Split(":")[0]
};
PlayerInfo adminInfo = new PlayerInfo
{
SteamId = caller?.AuthorizedSteamID?.SteamId64.ToString(),
Name = caller?.PlayerName,
IpAddress = caller?.IpAddress?.Split(":")[0]
};
Task.Run(async () =>
{
await _muteManager.MutePlayer(playerInfo, adminInfo, reason, time);
});
if (TagsDetected)
NativeAPI.IssueServerCommand($"css_tag_mute {player!.UserId}");
if (player != null && player.UserId != null && gaggedPlayers.Contains((ushort)player.UserId))
gaggedPlayers.Add((ushort)player.UserId);
if (time > 0 && time <= 30)
{
AddTimer(time * 60, () =>
PlayerInfo playerInfo = new PlayerInfo
{
if (player == null || !player.IsValid || player.AuthorizedSteamID == null) return;
SteamId = player?.AuthorizedSteamID?.SteamId64.ToString(),
Name = player?.PlayerName,
IpAddress = player?.IpAddress?.Split(":")[0]
};
if (TagsDetected)
NativeAPI.IssueServerCommand($"css_tag_unmute {player.UserId}");
PlayerInfo adminInfo = new PlayerInfo
{
SteamId = caller?.AuthorizedSteamID?.SteamId64.ToString(),
Name = caller?.PlayerName,
IpAddress = caller?.IpAddress?.Split(":")[0]
};
if (player != null && player.UserId != null && gaggedPlayers.Contains((ushort)player.UserId))
Task.Run(async () =>
{
await _muteManager.MutePlayer(playerInfo, adminInfo, reason, time);
});
if (TagsDetected)
NativeAPI.IssueServerCommand($"css_tag_mute {player!.UserId}");
if (player != null && player.UserId != null && gaggedPlayers.Contains((ushort)player.UserId))
gaggedPlayers.Add((ushort)player.UserId);
if (time > 0 && time <= 30)
{
AddTimer(time * 60, () =>
{
if (gaggedPlayers.TryTake(out ushort removedItem) && removedItem != (ushort)player.UserId)
if (player == null || !player.IsValid || player.AuthorizedSteamID == null) return;
if (TagsDetected)
NativeAPI.IssueServerCommand($"css_tag_unmute {player.UserId}");
if (player != null && player.UserId != null && gaggedPlayers.Contains((ushort)player.UserId))
{
gaggedPlayers.Add(removedItem);
if (gaggedPlayers.TryTake(out ushort removedItem) && removedItem != (ushort)player.UserId)
{
gaggedPlayers.Add(removedItem);
}
}
}
//MuteManager _muteManager = new(dbConnectionString);
//_ = _muteManager.UnmutePlayer(player.AuthorizedSteamID.SteamId64.ToString(), 0);
}, CounterStrikeSharp.API.Modules.Timers.TimerFlags.STOP_ON_MAPCHANGE);
}
if (time == 0)
{
player!.PrintToCenter(_localizer!["sa_player_gag_message_perm", reason, caller == null ? "Console" : caller.PlayerName]);
if (caller == null || caller != null && caller.UserId != null && !silentPlayers.Contains((ushort)caller.UserId))
{
StringBuilder sb = new(_localizer!["sa_prefix"]);
sb.Append(_localizer["sa_admin_gag_message_perm", caller == null ? "Console" : caller.PlayerName, player.PlayerName, reason]);
Server.PrintToChatAll(sb.ToString());
//MuteManager _muteManager = new(dbConnectionString);
//_ = _muteManager.UnmutePlayer(player.AuthorizedSteamID.SteamId64.ToString(), 0);
}, CounterStrikeSharp.API.Modules.Timers.TimerFlags.STOP_ON_MAPCHANGE);
}
}
else
{
player!.PrintToCenter(_localizer!["sa_player_gag_message_time", reason, time, caller == null ? "Console" : caller.PlayerName]);
if (caller == null || caller != null && caller != null && caller.UserId != null && !silentPlayers.Contains((ushort)caller.UserId))
if (time == 0)
{
StringBuilder sb = new(_localizer!["sa_prefix"]);
sb.Append(_localizer["sa_admin_gag_message_time", caller == null ? "Console" : caller.PlayerName, player.PlayerName, reason, time]);
Server.PrintToChatAll(sb.ToString());
player!.PrintToCenter(_localizer!["sa_player_gag_message_perm", reason, caller == null ? "Console" : caller.PlayerName]);
if (caller == null || caller != null && caller.UserId != null && !silentPlayers.Contains((ushort)caller.UserId))
{
StringBuilder sb = new(_localizer!["sa_prefix"]);
sb.Append(_localizer["sa_admin_gag_message_perm", caller == null ? "Console" : caller.PlayerName, player.PlayerName, reason]);
Server.PrintToChatAll(sb.ToString());
}
}
else
{
player!.PrintToCenter(_localizer!["sa_player_gag_message_time", reason, time, caller == null ? "Console" : caller.PlayerName]);
if (caller == null || caller != null && caller != null && caller.UserId != null && !silentPlayers.Contains((ushort)caller.UserId))
{
StringBuilder sb = new(_localizer!["sa_prefix"]);
sb.Append(_localizer["sa_admin_gag_message_time", caller == null ? "Console" : caller.PlayerName, player.PlayerName, reason, time]);
Server.PrintToChatAll(sb.ToString());
}
}
}
});
@@ -708,7 +717,7 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdmin
if (TagsDetected)
NativeAPI.IssueServerCommand($"css_tag_unmute {player!.UserId}");
pattern = player.AuthorizedSteamID!.SteamId64.ToString();
pattern = player!.AuthorizedSteamID!.SteamId64.ToString();
found = true;
}
@@ -742,7 +751,7 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdmin
}
}
if (player.AuthorizedSteamID != null)
if (player!.AuthorizedSteamID != null)
_ = _muteManager.UnmutePlayer(player.AuthorizedSteamID.SteamId64.ToString(), 0); // Unmute by type 0 (gag)
if (TagsDetected)
@@ -780,76 +789,79 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdmin
playersToTarget.ForEach(player =>
{
PlayerInfo playerInfo = new PlayerInfo
if (caller!.CanTarget(player))
{
SteamId = player?.AuthorizedSteamID?.SteamId64.ToString(),
Name = player?.PlayerName,
IpAddress = player?.IpAddress?.Split(":")[0]
};
PlayerInfo adminInfo = new PlayerInfo
{
SteamId = caller?.AuthorizedSteamID?.SteamId64.ToString(),
Name = caller?.PlayerName,
IpAddress = caller?.IpAddress?.Split(":")[0]
};
/*
if (!mutedPlayers.Contains((ushort)player.UserId))
mutedPlayers.Add((ushort)player.UserId);
*/
player!.VoiceFlags = VoiceFlags.Muted;
Task.Run(async () =>
{
await _muteManager.MutePlayer(playerInfo, adminInfo, reason, time, 1);
});
if (time > 0 && time <= 30)
{
AddTimer(time * 60, () =>
PlayerInfo playerInfo = new PlayerInfo
{
if (player == null || !player.IsValid || player.AuthorizedSteamID == null) return;
SteamId = player?.AuthorizedSteamID?.SteamId64.ToString(),
Name = player?.PlayerName,
IpAddress = player?.IpAddress?.Split(":")[0]
};
//MuteManager _muteManager = new(dbConnectionString);
//_ = _muteManager.UnmutePlayer(player.AuthorizedSteamID.SteamId64.ToString(), 1);
PlayerInfo adminInfo = new PlayerInfo
{
SteamId = caller?.AuthorizedSteamID?.SteamId64.ToString(),
Name = caller?.PlayerName,
IpAddress = caller?.IpAddress?.Split(":")[0]
};
/*
if (mutedPlayers.Contains((int)player.Index))
/*
if (!mutedPlayers.Contains((ushort)player.UserId))
mutedPlayers.Add((ushort)player.UserId);
*/
player!.VoiceFlags = VoiceFlags.Muted;
Task.Run(async () =>
{
await _muteManager.MutePlayer(playerInfo, adminInfo, reason, time, 1);
});
if (time > 0 && time <= 30)
{
AddTimer(time * 60, () =>
{
if (mutedPlayers.TryTake(out int removedItem) && removedItem != (int)player.Index)
if (player == null || !player.IsValid || player.AuthorizedSteamID == null) return;
//MuteManager _muteManager = new(dbConnectionString);
//_ = _muteManager.UnmutePlayer(player.AuthorizedSteamID.SteamId64.ToString(), 1);
/*
if (mutedPlayers.Contains((int)player.Index))
{
mutedPlayers.Add(removedItem);
if (mutedPlayers.TryTake(out int removedItem) && removedItem != (int)player.Index)
{
mutedPlayers.Add(removedItem);
}
}
}
*/
*/
player.VoiceFlags = VoiceFlags.Normal;
}, CounterStrikeSharp.API.Modules.Timers.TimerFlags.STOP_ON_MAPCHANGE);
}
if (time == 0)
{
player!.PrintToCenter(_localizer!["sa_player_mute_message_perm", reason, caller == null ? "Console" : caller.PlayerName]);
if (caller == null || caller != null && caller.UserId != null && !silentPlayers.Contains((ushort)caller.UserId))
{
StringBuilder sb = new(_localizer!["sa_prefix"]);
sb.Append(_localizer["sa_admin_mute_message_perm", caller == null ? "Console" : caller.PlayerName, player.PlayerName, reason]);
Server.PrintToChatAll(sb.ToString());
player.VoiceFlags = VoiceFlags.Normal;
}, CounterStrikeSharp.API.Modules.Timers.TimerFlags.STOP_ON_MAPCHANGE);
}
}
else
{
player!.PrintToCenter(_localizer!["sa_player_mute_message_time", reason, time, caller == null ? "Console" : caller.PlayerName]);
if (caller == null || caller != null && caller.UserId != null && !silentPlayers.Contains((ushort)caller.UserId))
if (time == 0)
{
StringBuilder sb = new(_localizer!["sa_prefix"]);
sb.Append(_localizer["sa_admin_mute_message_time", caller == null ? "Console" : caller.PlayerName, player.PlayerName, reason, time]);
Server.PrintToChatAll(sb.ToString());
player!.PrintToCenter(_localizer!["sa_player_mute_message_perm", reason, caller == null ? "Console" : caller.PlayerName]);
if (caller == null || caller != null && caller.UserId != null && !silentPlayers.Contains((ushort)caller.UserId))
{
StringBuilder sb = new(_localizer!["sa_prefix"]);
sb.Append(_localizer["sa_admin_mute_message_perm", caller == null ? "Console" : caller.PlayerName, player.PlayerName, reason]);
Server.PrintToChatAll(sb.ToString());
}
}
else
{
player!.PrintToCenter(_localizer!["sa_player_mute_message_time", reason, time, caller == null ? "Console" : caller.PlayerName]);
if (caller == null || caller != null && caller.UserId != null && !silentPlayers.Contains((ushort)caller.UserId))
{
StringBuilder sb = new(_localizer!["sa_prefix"]);
sb.Append(_localizer["sa_admin_mute_message_time", caller == null ? "Console" : caller.PlayerName, player.PlayerName, reason, time]);
Server.PrintToChatAll(sb.ToString());
}
}
}
});
@@ -1088,49 +1100,52 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdmin
playersToTarget.ForEach(player =>
{
player.Pawn.Value!.Freeze();
PlayerInfo playerInfo = new PlayerInfo
if (caller!.CanTarget(player))
{
SteamId = player?.AuthorizedSteamID?.SteamId64.ToString(),
Name = player?.PlayerName,
IpAddress = player?.IpAddress?.Split(":")[0]
};
player.Pawn.Value!.Freeze();
PlayerInfo adminInfo = new PlayerInfo
{
SteamId = caller?.AuthorizedSteamID?.SteamId64.ToString(),
Name = caller?.PlayerName,
IpAddress = caller?.IpAddress?.Split(":")[0]
};
Task.Run(async () =>
{
await _banManager.BanPlayer(playerInfo, adminInfo, reason, time);
});
AddTimer(Config.KickTime, () => Helper.KickPlayer((ushort)player!.UserId!));
if (time == 0)
{
player!.PrintToCenter(_localizer!["sa_player_ban_message_perm", reason, caller == null ? "Console" : caller.PlayerName]);
if (caller == null || caller != null && caller.UserId != null && !silentPlayers.Contains((ushort)caller.UserId))
PlayerInfo playerInfo = new PlayerInfo
{
StringBuilder sb = new(_localizer!["sa_prefix"]);
sb.Append(_localizer["sa_admin_ban_message_perm", caller == null ? "Console" : caller.PlayerName, player.PlayerName, reason]);
Server.PrintToChatAll(sb.ToString());
SteamId = player?.AuthorizedSteamID?.SteamId64.ToString(),
Name = player?.PlayerName,
IpAddress = player?.IpAddress?.Split(":")[0]
};
PlayerInfo adminInfo = new PlayerInfo
{
SteamId = caller?.AuthorizedSteamID?.SteamId64.ToString(),
Name = caller?.PlayerName,
IpAddress = caller?.IpAddress?.Split(":")[0]
};
Task.Run(async () =>
{
await _banManager.BanPlayer(playerInfo, adminInfo, reason, time);
});
AddTimer(Config.KickTime, () => Helper.KickPlayer((ushort)player!.UserId!));
if (time == 0)
{
player!.PrintToCenter(_localizer!["sa_player_ban_message_perm", reason, caller == null ? "Console" : caller.PlayerName]);
if (caller == null || caller != null && caller.UserId != null && !silentPlayers.Contains((ushort)caller.UserId))
{
StringBuilder sb = new(_localizer!["sa_prefix"]);
sb.Append(_localizer["sa_admin_ban_message_perm", caller == null ? "Console" : caller.PlayerName, player.PlayerName, reason]);
Server.PrintToChatAll(sb.ToString());
}
}
}
else
{
player!.PrintToCenter(_localizer!["sa_player_ban_message_time", reason, time, caller == null ? "Console" : caller.PlayerName]);
if (caller == null || caller != null && caller.UserId != null && !silentPlayers.Contains((ushort)caller.UserId))
else
{
StringBuilder sb = new(_localizer!["sa_prefix"]);
sb.Append(_localizer["sa_admin_ban_message_time", caller == null ? "Console" : caller.PlayerName, player.PlayerName, reason, time]);
Server.PrintToChatAll(sb.ToString());
player!.PrintToCenter(_localizer!["sa_player_ban_message_time", reason, time, caller == null ? "Console" : caller.PlayerName]);
if (caller == null || caller != null && caller.UserId != null && !silentPlayers.Contains((ushort)caller.UserId))
{
StringBuilder sb = new(_localizer!["sa_prefix"]);
sb.Append(_localizer["sa_admin_ban_message_time", caller == null ? "Console" : caller.PlayerName, player.PlayerName, reason, time]);
Server.PrintToChatAll(sb.ToString());
}
}
}
});
@@ -1401,14 +1416,17 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdmin
playersToTarget.ForEach(player =>
{
player.RemoveWeapons();
StringBuilder sb = new(_localizer!["sa_prefix"]);
if (caller == null || caller != null && caller.UserId != null && !silentPlayers.Contains((ushort)caller.UserId))
if (caller!.CanTarget(player))
{
sb.Append(_localizer["sa_admin_strip_message", caller == null ? "Console" : caller.PlayerName, player.PlayerName]);
Server.PrintToChatAll(sb.ToString());
player.RemoveWeapons();
StringBuilder sb = new(_localizer!["sa_prefix"]);
if (caller == null || caller != null && caller.UserId != null && !silentPlayers.Contains((ushort)caller.UserId))
{
sb.Append(_localizer["sa_admin_strip_message", caller == null ? "Console" : caller.PlayerName, player.PlayerName]);
Server.PrintToChatAll(sb.ToString());
}
}
});
}
@@ -1427,14 +1445,17 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdmin
playersToTarget.ForEach(player =>
{
player.SetHp(health);
StringBuilder sb = new(_localizer!["sa_prefix"]);
if (caller == null || caller != null && caller.UserId != null && !silentPlayers.Contains((ushort)caller.UserId))
if (caller!.CanTarget(player))
{
sb.Append(_localizer["sa_admin_hp_message", caller == null ? "Console" : caller.PlayerName, player.PlayerName]);
Server.PrintToChatAll(sb.ToString());
player.SetHp(health);
StringBuilder sb = new(_localizer!["sa_prefix"]);
if (caller == null || caller != null && caller.UserId != null && !silentPlayers.Contains((ushort)caller.UserId))
{
sb.Append(_localizer["sa_admin_hp_message", caller == null ? "Console" : caller.PlayerName, player.PlayerName]);
Server.PrintToChatAll(sb.ToString());
}
}
});
}
@@ -1453,18 +1474,21 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdmin
playersToTarget.ForEach(player =>
{
/*
player.Speed = (float)speed;
player.PlayerPawn.Value!.Speed = (float)speed;
*/
player.SetSpeed((float)speed);
StringBuilder sb = new(_localizer!["sa_prefix"]);
if (caller == null || caller != null && caller.UserId != null && !silentPlayers.Contains((ushort)caller.UserId))
if (caller!.CanTarget(player))
{
sb.Append(_localizer["sa_admin_speed_message", caller == null ? "Console" : caller.PlayerName, player.PlayerName]);
Server.PrintToChatAll(sb.ToString());
/*
player.Speed = (float)speed;
player.PlayerPawn.Value!.Speed = (float)speed;
*/
player.SetSpeed((float)speed);
StringBuilder sb = new(_localizer!["sa_prefix"]);
if (caller == null || caller != null && caller.UserId != null && !silentPlayers.Contains((ushort)caller.UserId))
{
sb.Append(_localizer["sa_admin_speed_message", caller == null ? "Console" : caller.PlayerName, player.PlayerName]);
Server.PrintToChatAll(sb.ToString());
}
}
});
}
@@ -1480,19 +1504,22 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdmin
playersToTarget.ForEach(player =>
{
if (player != null && player.UserId != null)
if (caller!.CanTarget(player))
{
if (!godPlayers.Contains((ushort)player.UserId))
godPlayers.Add((ushort)player.UserId);
else
godPlayers.Remove((ushort)player.UserId);
StringBuilder sb = new(_localizer!["sa_prefix"]);
if (caller == null || caller != null && caller.UserId != null && !silentPlayers.Contains((ushort)caller!.UserId))
if (player != null && player.UserId != null)
{
sb.Append(_localizer["sa_admin_god_message", caller == null ? "Console" : caller.PlayerName, player.PlayerName]);
Server.PrintToChatAll(sb.ToString());
if (!godPlayers.Contains((ushort)player.UserId))
godPlayers.Add((ushort)player.UserId);
else
godPlayers.Remove((ushort)player.UserId);
StringBuilder sb = new(_localizer!["sa_prefix"]);
if (caller == null || caller != null && caller.UserId != null && !silentPlayers.Contains((ushort)caller!.UserId))
{
sb.Append(_localizer["sa_admin_god_message", caller == null ? "Console" : caller.PlayerName, player.PlayerName]);
Server.PrintToChatAll(sb.ToString());
}
}
}
});
@@ -1516,13 +1543,16 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdmin
playersToTarget.ForEach(player =>
{
player!.Pawn.Value!.Slap(damage);
StringBuilder sb = new(_localizer!["sa_prefix"]);
if (caller == null || caller != null && caller.UserId != null && !silentPlayers.Contains((ushort)caller.UserId))
if (caller!.CanTarget(player))
{
sb.Append(_localizer["sa_admin_slap_message", caller == null ? "Console" : caller.PlayerName, player.PlayerName]);
Server.PrintToChatAll(sb.ToString());
player!.Pawn.Value!.Slap(damage);
StringBuilder sb = new(_localizer!["sa_prefix"]);
if (caller == null || caller != null && caller.UserId != null && !silentPlayers.Contains((ushort)caller.UserId))
{
sb.Append(_localizer["sa_admin_slap_message", caller == null ? "Console" : caller.PlayerName, player.PlayerName]);
Server.PrintToChatAll(sb.ToString());
}
}
});
}
@@ -1634,7 +1664,7 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdmin
foreach (var p in Utilities.GetPlayers().Where(p => p.IsValid && !p.IsBot && !p.IsHLTV))
{
if (p == null) continue;
ChatMenus.OpenMenu(p, voteMenu);
MenuManager.OpenChatMenu(p, voteMenu);
}
AddTimer(40, () =>
@@ -1797,13 +1827,16 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdmin
playersToTarget.ForEach(player =>
{
player!.Pawn.Value!.ToggleNoclip();
if (caller == null || caller != null && caller.UserId != null && !silentPlayers.Contains((ushort)caller.UserId))
if (caller!.CanTarget(player))
{
StringBuilder sb = new(_localizer!["sa_prefix"]);
sb.Append(_localizer["sa_admin_noclip_message", caller == null ? "Console" : caller.PlayerName, player.PlayerName]);
Server.PrintToChatAll(sb.ToString());
player!.Pawn.Value!.ToggleNoclip();
if (caller == null || caller != null && caller.UserId != null && !silentPlayers.Contains((ushort)caller.UserId))
{
StringBuilder sb = new(_localizer!["sa_prefix"]);
sb.Append(_localizer["sa_admin_noclip_message", caller == null ? "Console" : caller.PlayerName, player.PlayerName]);
Server.PrintToChatAll(sb.ToString());
}
}
});
}
@@ -1821,16 +1854,19 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdmin
playersToTarget.ForEach(player =>
{
player!.Pawn.Value!.Freeze();
if (time > 0)
AddTimer(time, () => player.Pawn.Value!.Unfreeze());
if (caller == null || caller != null && caller.UserId != null && !silentPlayers.Contains((ushort)caller.UserId))
if (caller!.CanTarget(player))
{
StringBuilder sb = new(_localizer!["sa_prefix"]);
sb.Append(_localizer["sa_admin_freeze_message", caller == null ? "Console" : caller.PlayerName, player.PlayerName]);
Server.PrintToChatAll(sb.ToString());
player!.Pawn.Value!.Freeze();
if (time > 0)
AddTimer(time, () => player.Pawn.Value!.Unfreeze());
if (caller == null || caller != null && caller.UserId != null && !silentPlayers.Contains((ushort)caller.UserId))
{
StringBuilder sb = new(_localizer!["sa_prefix"]);
sb.Append(_localizer["sa_admin_freeze_message", caller == null ? "Console" : caller.PlayerName, player.PlayerName]);
Server.PrintToChatAll(sb.ToString());
}
}
});
}
@@ -1866,13 +1902,16 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdmin
playersToTarget.ForEach(player =>
{
player!.Respawn();
if (caller == null || caller != null && caller.UserId != null && !silentPlayers.Contains((ushort)caller.UserId))
if (caller!.CanTarget(player))
{
StringBuilder sb = new(_localizer!["sa_prefix"]);
sb.Append(_localizer["sa_admin_respawn_message", caller == null ? "Console" : caller.PlayerName, player.PlayerName]);
Server.PrintToChatAll(sb.ToString());
player!.Respawn();
if (caller == null || caller != null && caller.UserId != null && !silentPlayers.Contains((ushort)caller.UserId))
{
StringBuilder sb = new(_localizer!["sa_prefix"]);
sb.Append(_localizer["sa_admin_respawn_message", caller == null ? "Console" : caller.PlayerName, player.PlayerName]);
Server.PrintToChatAll(sb.ToString());
}
}
});
}

View File

@@ -9,9 +9,9 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="CounterStrikeSharp.API" Version="1.0.148" />
<PackageReference Include="CounterStrikeSharp.API" Version="1.0.154" />
<PackageReference Include="Dapper" Version="*" />
<PackageReference Include="MySqlConnector" Version="*" />
<PackageReference Include="MySqlConnector" Version="2.3.5" />
</ItemGroup>
<ItemGroup>

View File

@@ -5,7 +5,7 @@ namespace CS2_SimpleAdmin
{
public class CS2_SimpleAdminConfig : BasePluginConfig
{
public override int Version { get; set; } = 2;
public override int Version { get; set; } = 3;
[JsonPropertyName("DatabaseHost")]
public string DatabaseHost { get; set; } = "";
@@ -23,9 +23,13 @@ namespace CS2_SimpleAdmin
public string DatabaseName { get; set; } = "";
[JsonPropertyName("KickTime")]
public int KickTime { get; set; } = 10;
public int KickTime { get; set; } = 5;
[JsonPropertyName("DisableDangerousCommands")]
public bool DisableDangerousCommands { get; set; } = true;
[JsonPropertyName("BanType")]
public int BanType { get; set; } = 1;
}
}

187
Events.cs
View File

@@ -15,8 +15,8 @@ public partial class CS2_SimpleAdmin
{
private void registerEvents()
{
RegisterListener<OnClientAuthorized>(OnClientAuthorized);
RegisterListener<OnClientConnected>(OnClientConnected);
//RegisterListener<OnClientAuthorized>(OnClientAuthorized);
RegisterListener<OnClientConnect>(OnClientConnect);
//RegisterEventHandler<EventPlayerConnectFull>(OnPlayerFullConnect);
RegisterListener<OnClientDisconnect>(OnClientDisconnect);
RegisterListener<OnMapStart>(OnMapStart);
@@ -86,7 +86,7 @@ public partial class CS2_SimpleAdmin
if (AdminManager.PlayerHasPermissions(player, "@css/chat"))
{
sb.Append(_localizer!["sa_adminchat_template_admin", player.PlayerName, info.GetArg(1).Remove(0, 1)]);
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());
@@ -94,7 +94,7 @@ public partial class CS2_SimpleAdmin
}
else
{
sb.Append(_localizer!["sa_adminchat_template_player", player.PlayerName, info.GetArg(1).Remove(0, 1)]);
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")))
{
@@ -125,10 +125,179 @@ public partial class CS2_SimpleAdmin
return HookResult.Continue;
}
private void OnClientConnected(int playerSlot)
private void OnClientConnect(int playerSlot, string name, string ipAddress)
{
CCSPlayerController? player = Utilities.GetPlayerFromSlot(playerSlot);
if (player == null || !player.IsValid || player.IsBot || player.IsHLTV)
return;
ipAddress = ipAddress.Split(":")[0];
if (
ipAddress != null && bannedPlayers.Contains(ipAddress) ||
player.SteamID.ToString() != "" && bannedPlayers.Contains(player.SteamID.ToString())
)
Helper.KickPlayer((ushort)player.UserId!, "Banned");
PlayerInfo playerInfo = new PlayerInfo
{
UserId = player.UserId,
Index = (ushort)player.Index,
SteamId = player?.SteamID.ToString(),
Name = player?.PlayerName,
IpAddress = ipAddress
};
Task.Run(async () =>
{
BanManager _banManager = new(dbConnectionString);
bool isBanned = await _banManager.IsPlayerBanned(playerInfo);
MuteManager _muteManager = new(dbConnectionString);
List<dynamic> activeMutes = await _muteManager.IsPlayerMuted(playerInfo.SteamId!);
AdminSQLManager _adminManager = new(dbConnectionString);
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.UserId != null && !gaggedPlayers.Any(index => index == (ushort)player.UserId))
gaggedPlayers.Add((ushort)player.UserId);
if (TagsDetected)
NativeAPI.IssueServerCommand($"css_tag_mute {player.UserId}");
if (durationInSeconds != 0 && duration.Minutes >= 0 && duration.Minutes <= 30)
{
AddTimer(durationInSeconds, () =>
{
if (player == null || !player.IsValid || player.SteamID.ToString() == "") return;
if (player != null && player.UserId != null && gaggedPlayers.Contains((ushort)player.UserId))
{
if (gaggedPlayers.TryTake(out ushort removedItem) && removedItem != (int)player.UserId)
{
gaggedPlayers.Add(removedItem);
}
}
if (TagsDetected)
NativeAPI.IssueServerCommand($"css_tag_unmute {player!.UserId}");
MuteManager _muteManager = new(dbConnectionString);
_ = _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
{
// 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(dbConnectionString);
//_ = _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;
@@ -161,11 +330,15 @@ public partial class CS2_SimpleAdmin
}
});
});
*/
}
private void OnClientAuthorized(int playerSlot, SteamID steamID)
{
return;
#pragma warning disable CS0162
CCSPlayerController? player = Utilities.GetPlayerFromSlot(playerSlot);
#pragma warning restore CS0162
if (player == null || !player.IsValid || player.IsBot || player.IsHLTV)
return;
@@ -247,7 +420,7 @@ public partial class CS2_SimpleAdmin
NativeAPI.IssueServerCommand($"css_tag_unmute {player!.UserId}");
MuteManager _muteManager = new(dbConnectionString);
_ = _muteManager.UnmutePlayer(player.AuthorizedSteamID.SteamId64.ToString(), 0);
_ = _muteManager.UnmutePlayer(player!.AuthorizedSteamID.SteamId64.ToString(), 0);
}, CounterStrikeSharp.API.Modules.Timers.TimerFlags.STOP_ON_MAPCHANGE);
}
@@ -359,7 +532,7 @@ public partial class CS2_SimpleAdmin
}
*/
if (player.UserId != null && silentPlayers.Contains((ushort)player.UserId))
if (player!.UserId != null && silentPlayers.Contains((ushort)player.UserId))
{
silentPlayers.Remove((ushort)player.UserId);
}