Skip to content

Commit

Permalink
1.6.8a
Browse files Browse the repository at this point in the history
- Updated css version
- Updated mysqlconnector version
- Added information for the player until when he has a chat blocked
- Closing menu after ban
  • Loading branch information
daffyyyy committed Nov 10, 2024
1 parent 7154843 commit 95818e2
Show file tree
Hide file tree
Showing 23 changed files with 86 additions and 38 deletions.
4 changes: 2 additions & 2 deletions CS2-SimpleAdmin/CS2-SimpleAdmin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@

namespace CS2_SimpleAdmin;

[MinimumApiVersion(279)]
[MinimumApiVersion(284)]
public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdminConfig>
{
internal static CS2_SimpleAdmin Instance { get; private set; } = new();

public override string ModuleName => "CS2-SimpleAdmin" + (Helper.IsDebugBuild ? " (DEBUG)" : " (RELEASE)");
public override string ModuleDescription => "Simple admin plugin for Counter-Strike 2 :)";
public override string ModuleAuthor => "daffyy & Dliix66";
public override string ModuleVersion => "1.6.7a";
public override string ModuleVersion => "1.6.8a";

public override void Load(bool hotReload)
{
Expand Down
4 changes: 2 additions & 2 deletions CS2-SimpleAdmin/CS2-SimpleAdmin.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="CounterStrikeSharp.API" Version="1.0.284" />
<PackageReference Include="CounterStrikeSharp.API" Version="1.0.286" />
<PackageReference Include="Dapper" Version="2.1.35" />
<PackageReference Include="MySqlConnector" Version="2.3.7" />
<PackageReference Include="MySqlConnector" Version="2.4.0-beta.2" />
<PackageReference Include="Newtonsoft.Json" Version="*" />
</ItemGroup>

Expand Down
1 change: 0 additions & 1 deletion CS2-SimpleAdmin/Commands/basecommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
using Newtonsoft.Json;
using System.Globalization;
using System.Reflection;
using CounterStrikeSharp.API.Core.Attributes.Registration;
using MenuManager;

namespace CS2_SimpleAdmin;
Expand Down
3 changes: 3 additions & 0 deletions CS2-SimpleAdmin/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,9 @@ public class OtherSettings

[JsonPropertyName("UserMessageGagChatType")]
public bool UserMessageGagChatType { get; set; } = false;

[JsonPropertyName("AdditionalCommandsToLog")]
public List<string> AdditionalCommandsToLog = new();
}

public class CS2_SimpleAdminConfig : BasePluginConfig
Expand Down
50 changes: 35 additions & 15 deletions CS2-SimpleAdmin/Events.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using CS2_SimpleAdminApi;
using Microsoft.Extensions.Logging;
using System.Text;
using CounterStrikeSharp.API.Core.Translations;
using CounterStrikeSharp.API.Modules.Admin;
using CounterStrikeSharp.API.Modules.UserMessages;

Expand Down Expand Up @@ -167,13 +168,16 @@ private HookResult HookUmChat(UserMessage um)
var author = Utilities.GetPlayerFromIndex(um.ReadInt("entityindex"));
if (author == null || !author.IsValid || author.IsBot)
return HookResult.Continue;

if (PlayerPenaltyManager.IsPenalized(author.Slot, PenaltyType.Gag) || PlayerPenaltyManager.IsPenalized(author.Slot, PenaltyType.Silence))
return HookResult.Stop;

if (!PlayerPenaltyManager.IsPenalized(author.Slot, PenaltyType.Gag, out DateTime? endDateTime) &&
!PlayerPenaltyManager.IsPenalized(author.Slot, PenaltyType.Silence, out endDateTime))
return HookResult.Continue;
if (_localizer != null && endDateTime is not null)
author.SendLocalizedMessage(_localizer, "sa_player_penalty_chat_active", endDateTime.Value.ToString("g", author.GetLanguage()));
return HookResult.Stop;

// um.Recipients.Clear();

return HookResult.Continue;

}

private HookResult ComamndListenerHandler(CCSPlayerController? player, CommandInfo info)
Expand All @@ -183,6 +187,9 @@ private HookResult ComamndListenerHandler(CCSPlayerController? player, CommandIn

var command = info.GetArg(0).ToLower();

if (Config.OtherSettings.AdditionalCommandsToLog.Contains(command))
Helper.LogCommand(player, info);

switch (command)
{
case "css_admins_reload":
Expand All @@ -201,7 +208,7 @@ private HookResult ComamndListenerHandler(CCSPlayerController? player, CommandIn

if (target == null || !target.IsValid || target.Connected != PlayerConnectedState.PlayerConnected)
return HookResult.Continue;

return !AdminManager.CanPlayerTarget(player, target) ? HookResult.Stop : HookResult.Continue;
}
}
Expand All @@ -210,8 +217,15 @@ private HookResult ComamndListenerHandler(CCSPlayerController? player, CommandIn
return HookResult.Continue;

if (!Config.OtherSettings.UserMessageGagChatType)
if (PlayerPenaltyManager.IsPenalized(player.Slot, PenaltyType.Gag) || PlayerPenaltyManager.IsPenalized(player.Slot, PenaltyType.Silence))
{
if (PlayerPenaltyManager.IsPenalized(player.Slot, PenaltyType.Gag, out DateTime? endDateTime) ||
PlayerPenaltyManager.IsPenalized(player.Slot, PenaltyType.Silence, out endDateTime))
{
if (_localizer != null && endDateTime is not null)
player.SendLocalizedMessage(_localizer, "sa_player_penalty_chat_active", endDateTime.Value.ToString("g", player.GetLanguage()));
return HookResult.Stop;
}
}

if (info.GetArg(1).StartsWith($"/")
|| info.GetArg(1).StartsWith($"!"))
Expand Down Expand Up @@ -281,8 +295,8 @@ public HookResult OnCommandTeamSay(CCSPlayerController? player, CommandInfo info
if (info.GetArg(1).Length == 0)
return HookResult.Handled;

if (PlayerPenaltyManager.IsPenalized(player.Slot, PenaltyType.Gag) || PlayerPenaltyManager.IsPenalized(player.Slot, PenaltyType.Silence))
return HookResult.Handled;
if (PlayerPenaltyManager.IsPenalized(player.Slot, PenaltyType.Gag, out _) || PlayerPenaltyManager.IsPenalized(player.Slot, PenaltyType.Silence, out _))
return HookResult.Stop;

if (!info.GetArg(1).StartsWith($"@")) return HookResult.Continue;

Expand Down Expand Up @@ -358,12 +372,18 @@ public HookResult OnPlayerDeath(EventPlayerDeath @event, GameEventInfo info)
SpeedPlayers.Remove(player.Slot);
GravityPlayers.Remove(player);

PlayersInfo[player.UserId.Value].DiePosition =
new DiePosition(
new Vector(player.PlayerPawn.Value?.AbsOrigin?.X, player.PlayerPawn.Value?.AbsOrigin?.Y,
player.PlayerPawn.Value?.AbsOrigin?.Z),
new QAngle(player.PlayerPawn.Value?.AbsRotation?.X, player.PlayerPawn.Value?.AbsRotation?.Y,
player.PlayerPawn.Value?.AbsRotation?.Z));
PlayersInfo[player.UserId.Value].DiePosition = new DiePosition(
new Vector(
player.PlayerPawn.Value?.AbsOrigin?.X ?? 0,
player.PlayerPawn.Value?.AbsOrigin?.Y ?? 0,
player.PlayerPawn.Value?.AbsOrigin?.Z ?? 0
),
new QAngle(
player.PlayerPawn.Value?.AbsRotation?.X ?? 0,
player.PlayerPawn.Value?.AbsRotation?.Y ?? 0,
player.PlayerPawn.Value?.AbsRotation?.Z ?? 0
)
);

return HookResult.Continue;
}
Expand Down
6 changes: 3 additions & 3 deletions CS2-SimpleAdmin/Managers/PlayerManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -306,9 +306,9 @@ public void CheckPlayersTimer()
.Select(player => new
{
Player = player,
IsMuted = PlayerPenaltyManager.IsPenalized(player.Slot, PenaltyType.Mute),
IsSilenced = PlayerPenaltyManager.IsPenalized(player.Slot, PenaltyType.Silence),
IsGagged = PlayerPenaltyManager.IsPenalized(player.Slot, PenaltyType.Gag)
IsMuted = PlayerPenaltyManager.IsPenalized(player.Slot, PenaltyType.Mute, out _),
IsSilenced = PlayerPenaltyManager.IsPenalized(player.Slot, PenaltyType.Silence, out _),
IsGagged = PlayerPenaltyManager.IsPenalized(player.Slot, PenaltyType.Gag, out _)
});

foreach (var entry in penalizedSlots)
Expand Down
22 changes: 10 additions & 12 deletions CS2-SimpleAdmin/Managers/PlayerPenaltyManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,20 @@ public static void AddPenalty(int slot, PenaltyType penaltyType, DateTime endDat
});
}

public static bool IsPenalized(int slot, PenaltyType penaltyType)
public static bool IsPenalized(int slot, PenaltyType penaltyType, out DateTime? endDateTime)
{
//Console.WriteLine($"Checking penalties for player with slot {slot} and penalty type {penaltyType}");
endDateTime = null;

if (!Penalties.TryGetValue(slot, out var penaltyDict) ||
!penaltyDict.TryGetValue(penaltyType, out var penaltiesList)) return false;
//Console.WriteLine($"Found penalties for player with slot {slot} and penalty type {penaltyType}");

if (CS2_SimpleAdmin.Instance.Config.OtherSettings.TimeMode == 0)
return penaltiesList.Count != 0;
{
if (penaltiesList.Count == 0) return false;

endDateTime = penaltiesList.First().EndDateTime;
return true;
}

var now = Time.ActualDateTime();

Expand All @@ -52,28 +56,22 @@ public static bool IsPenalized(int slot, PenaltyType penaltyType)
// Check if the penalty is still active
if (penalty.Duration > 0 && now >= penalty.EndDateTime)
{
//Console.WriteLine($"Removing expired penalty for player with slot {slot} and penalty type {penaltyType}");
penaltiesList.Remove(penalty); // Remove expired penalty
if (penaltiesList.Count == 0)
{
//Console.WriteLine($"No more penalties of type {penaltyType} for player with slot {slot}. Removing penalty type.");
penaltyDict.Remove(penaltyType); // Remove penalty type if no more penalties exist
}
}
else if (penalty.Duration == 0 || now < penalty.EndDateTime)
{
//Console.WriteLine($"Player with slot {slot} is penalized for type {penaltyType}");
// Return true if there's an active penalty
// Set endDateTime to the end time of this active penalty
endDateTime = penalty.EndDateTime;
return true;
}
}

// Return false if no active penalties are found
//Console.WriteLine($"Player with slot {slot} is not penalized for type {penaltyType}");
return false;

// Return false if no penalties of the specified type were found for the player
//Console.WriteLine($"No penalties found for player with slot {slot} and penalty type {penaltyType}");
}

// Get the end datetime and duration of penalties for a player and penalty type
Expand Down
4 changes: 3 additions & 1 deletion CS2-SimpleAdmin/Menus/ManagePlayersMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,8 @@ internal static void BanMenu(CCSPlayerController admin, CCSPlayerController play
{
if (player is { IsValid: true })
Ban(admin, player, duration, reason);

CS2_SimpleAdmin.MenuApi?.CloseMenu(admin);
});

// var menu = AdminMenu.CreateMenu($"{CS2_SimpleAdmin._localizer?["sa_ban"] ?? "Ban"}: {player?.PlayerName}");
Expand All @@ -178,7 +180,7 @@ private static void Ban(CCSPlayerController admin, CCSPlayerController player, i
{
if (player is not { IsValid: true }) return;

CS2_SimpleAdmin.Instance.Ban(admin, player, duration, reason);
// CS2_SimpleAdmin.Instance.Ban(admin, player, duration, reason);
}

private static void WarnMenu(CCSPlayerController admin, CCSPlayerController player, int duration)
Expand Down
2 changes: 1 addition & 1 deletion CS2-SimpleAdmin/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.6.7a
1.6.8a
2 changes: 2 additions & 0 deletions CS2-SimpleAdmin/lang/ar.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@
"sa_discord_penalty_warn": "التحذير مسجل",
"sa_discord_penalty_unknown": "غير معروف مسجل",

"sa_player_penalty_chat_active": "{lightred}تم حظر الدردشة الخاصة بك إلى: {grey}{0}",

"sa_player_penalty_info_active_mute": "➔ كتم [{lightred}❌{default}] - ينتهي [{lightred}{0}{default}]",
"sa_player_penalty_info_active_gag": "➔ صمت [{lightred}❌{default}] - ينتهي [{lightred}{0}{default}]",
"sa_player_penalty_info_active_silence": "➔ سكوت [{lightred}❌{default}] - ينتهي [{lightred}{0}{default}]",
Expand Down
2 changes: 2 additions & 0 deletions CS2-SimpleAdmin/lang/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@
"sa_discord_penalty_warn": "Warnung registriert",
"sa_discord_penalty_unknown": "Unbekanntes registriert",

"sa_player_penalty_chat_active": "{lightred}Dein Chat ist blockiert für: {grey}{0}",

"sa_player_penalty_info_active_mute": "➔ Stummschaltung [{lightred}❌{default}] - Ablauf [{lightred}{0}{default}]",
"sa_player_penalty_info_active_gag": "➔ Mundtot [{lightred}❌{default}] - Ablauf [{lightred}{0}{default}]",
"sa_player_penalty_info_active_silence": "➔ Stille [{lightred}❌{default}] - Ablauf [{lightred}{0}{default}]",
Expand Down
2 changes: 2 additions & 0 deletions CS2-SimpleAdmin/lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@
"sa_discord_penalty_silence": "Silence registered",
"sa_discord_penalty_warn": "Warn registered",
"sa_discord_penalty_unknown": "Unknown registered",

"sa_player_penalty_chat_active": "{lightred}Your chat is blocked to: {grey}{0}",

"sa_player_penalty_info_active_mute": "➔ Mute [{lightred}❌{default}] - Expire [{lightred}{0}{default}]",
"sa_player_penalty_info_active_gag": "➔ Gag [{lightred}❌{default}] - Expire [{lightred}{0}{default}]",
Expand Down
2 changes: 2 additions & 0 deletions CS2-SimpleAdmin/lang/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@
"sa_discord_penalty_warn": "Advertencia registrada",
"sa_discord_penalty_unknown": "Registro desconocido",

"sa_player_penalty_chat_active": "{lightred}Tu chat está bloqueado para: {grey}{0}",

"sa_player_penalty_info_active_mute": "➔ Silenciado [{lightred}❌{default}] - Expira [{lightred}{0}{default}]",
"sa_player_penalty_info_active_gag": "➔ Boqueado [{lightred}❌{default}] - Expira [{lightred}{0}{default}]",
"sa_player_penalty_info_active_silence": "➔ Silencio [{lightred}❌{default}] - Expira [{lightred}{0}{default}]",
Expand Down
2 changes: 2 additions & 0 deletions CS2-SimpleAdmin/lang/fa.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@
"sa_discord_penalty_warn": "هشدار ثبت شد",
"sa_discord_penalty_unknown": "ناشناخته انجام شده",

"sa_player_penalty_chat_active": "{lightred}چت شما برای: {grey}{0} مسدود شده است",

"sa_player_penalty_info_active_mute": "➔ بی‌صدا [{lightred}❌{default}] - منقضی شدن [{lightred}{0}{default}]",
"sa_player_penalty_info_active_gag": "➔ مسدود کردن صدا [{lightred}❌{default}] - منقضی شدن [{lightred}{0}{default}]",
"sa_player_penalty_info_active_silence": "➔ سکوت [{lightred}❌{default}] - منقضی شدن [{lightred}{0}{default}]",
Expand Down
2 changes: 2 additions & 0 deletions CS2-SimpleAdmin/lang/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@
"sa_discord_penalty_warn": "Avertissement enregistré",
"sa_discord_penalty_unknown": "Inconnu enregistré",

"sa_player_penalty_chat_active": "{lightred}Votre chat est bloqué pour : {grey}{0}",

"sa_player_penalty_info_active_mute": "➔ Muet [{lightred}❌{default}] - Expire [{lightred}{0}{default}]",
"sa_player_penalty_info_active_gag": "➔ Gag [{lightred}❌{default}] - Expire [{lightred}{0}{default}]",
"sa_player_penalty_info_active_silence": "➔ Silence [{lightred}❌{default}] - Expire [{lightred}{0}{default}]",
Expand Down
2 changes: 2 additions & 0 deletions CS2-SimpleAdmin/lang/lv.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@
"sa_discord_penalty_warn": "Brīdinājums reģistrēts",
"sa_discord_penalty_unknown": "Nezināms reģistrēts",

"sa_player_penalty_chat_active": "{lightred}Jūsu čats ir bloķēts uz: {grey}{0}",

"sa_player_penalty_info_active_mute": "➔ Izslēgts [{lightred}❌{default}] - Beidzas [{lightred}{0}{default}]",
"sa_player_penalty_info_active_gag": "➔ Klusums [{lightred}❌{default}] - Beidzas [{lightred}{0}{default}]",
"sa_player_penalty_info_active_silence": "➔ Klusēšana [{lightred}❌{default}] - Beidzas [{lightred}{0}{default}]",
Expand Down
2 changes: 2 additions & 0 deletions CS2-SimpleAdmin/lang/pl.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@
"sa_discord_penalty_warn": "Nowe ostrzeżenie",
"sa_discord_penalty_unknown": "Nowa nieznana blokada",

"sa_player_penalty_chat_active": "{lightred}Twój czat jest zablokowany do: {grey}{0}",

"sa_player_penalty_info_active_mute": "➔ Zakneblowanie [{lightred}❌{default}] - Wygasa [{lightred}{0}{default}]",
"sa_player_penalty_info_active_gag": "➔ Wyciszenie [{lightred}❌{default}] - Wygasa [{lightred}{0}{default}]",
"sa_player_penalty_info_active_silence": "➔ Uciszenie [{lightred}❌{default}] - Wygasa [{lightred}{0}{default}]",
Expand Down
2 changes: 2 additions & 0 deletions CS2-SimpleAdmin/lang/pt-BR.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@
"sa_discord_penalty_warn": "Aviso registrado",
"sa_discord_penalty_unknown": "Desconhecido registrado",

"sa_player_penalty_chat_active": "{lightred}Seu chat está bloqueado para: {grey}{0}",

"sa_player_penalty_info_active_mute": "➔ Mudo [{lightred}❌{default}] - Expira [{lightred}{0}{default}]",
"sa_player_penalty_info_active_gag": "➔ Gag [{lightred}❌{default}] - Expira [{lightred}{0}{default}]",
"sa_player_penalty_info_active_silence": "➔ Silêncio [{lightred}❌{default}] - Expira [{lightred}{0}{default}]",
Expand Down
2 changes: 2 additions & 0 deletions CS2-SimpleAdmin/lang/pt-PT.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@
"sa_discord_penalty_warn": "Aviso registrado",
"sa_discord_penalty_unknown": "Desconhecido registrado",

"sa_player_penalty_chat_active": "{lightred}O seu chat está bloqueado para: {grey}{0}",

"sa_player_penalty_info_active_mute": "➔ Mudo [{lightred}❌{default}] - Expira [{lightred}{0}{default}]",
"sa_player_penalty_info_active_gag": "➔ Gag [{lightred}❌{default}] - Expira [{lightred}{0}{default}]",
"sa_player_penalty_info_active_silence": "➔ Silêncio [{lightred}❌{default}] - Expira [{lightred}{0}{default}]",
Expand Down
2 changes: 2 additions & 0 deletions CS2-SimpleAdmin/lang/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@
"sa_discord_penalty_warn": "Предупреждение зарегистрировано",
"sa_discord_penalty_unknown": "Неизвестно зарегистрировано",

"sa_player_penalty_chat_active": "{lightred}Ваш чат заблокирован для: {grey}{0}",

"sa_player_penalty_info_active_mute": "➔ Мут [{lightred}❌{default}] - Истекает [{lightred}{0}{default}]",
"sa_player_penalty_info_active_gag": "➔ Гэг [{lightred}❌{default}] - Истекает [{lightred}{0}{default}]",
"sa_player_penalty_info_active_silence": "➔ Тишина [{lightred}❌{default}] - Истекает [{lightred}{0}{default}]",
Expand Down
2 changes: 2 additions & 0 deletions CS2-SimpleAdmin/lang/tr.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@
"sa_discord_penalty_warn": "Uyarı kaydedildi",
"sa_discord_penalty_unknown": "Bilinmeyen kaydedildi",

"sa_player_penalty_chat_active": "{lightred}Sohbetiniz şu kişiye engellendi: {grey}{0}",

"sa_player_penalty_info_active_mute": "➔ Mute [{lightred}❌{default}] - Süre Dolacak [{lightred}{0}{default}]",
"sa_player_penalty_info_active_gag": "➔ Gag [{lightred}❌{default}] - Süre Dolacak [{lightred}{0}{default}]",
"sa_player_penalty_info_active_silence": "➔ Sessizlik [{lightred}❌{default}] - Süre Dolacak [{lightred}{0}{default}]",
Expand Down
2 changes: 2 additions & 0 deletions CS2-SimpleAdmin/lang/zh-Hans.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@
"sa_discord_penalty_warn": "警告已注册",
"sa_discord_penalty_unknown": "未知已记录",

"sa_player_penalty_chat_active": "{lightred}您的聊天已被封锁到: {grey}{0}",

"sa_player_penalty_info_active_mute": "➔ 静音 [{lightred}❌{default}] - 到期 [{lightred}{0}{default}]",
"sa_player_penalty_info_active_gag": "➔ 禁言 [{lightred}❌{default}] - 到期 [{lightred}{0}{default}]",
"sa_player_penalty_info_active_silence": "➔ 沉默 [{lightred}❌{default}] - 到期 [{lightred}{0}{default}]",
Expand Down
2 changes: 1 addition & 1 deletion CS2-SimpleAdminApi/CS2-SimpleAdminApi.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="CounterStrikeSharp.API" Version="1.0.284" />
<PackageReference Include="CounterStrikeSharp.API" Version="1.0.286" />
</ItemGroup>

</Project>

0 comments on commit 95818e2

Please sign in to comment.