- Updated css version
- Updated mysqlconnector version
- Added information for the player until when he has a chat blocked
- Closing menu after ban
This commit is contained in:
Dawid Bepierszcz
2024-11-10 17:30:48 +01:00
parent 7154843d1d
commit 95818e2742
23 changed files with 86 additions and 38 deletions

View File

@@ -11,7 +11,7 @@ using MySqlConnector;
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();
@@ -19,7 +19,7 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdmin
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)
{

View File

@@ -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>

View File

@@ -15,7 +15,6 @@ using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using System.Globalization;
using System.Reflection;
using CounterStrikeSharp.API.Core.Attributes.Registration;
using MenuManager;
namespace CS2_SimpleAdmin;

View File

@@ -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

View File

@@ -9,6 +9,7 @@ using CS2_SimpleAdmin.Models;
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;
@@ -167,13 +168,16 @@ public partial class CS2_SimpleAdmin
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)
@@ -183,6 +187,9 @@ public partial class CS2_SimpleAdmin
var command = info.GetArg(0).ToLower();
if (Config.OtherSettings.AdditionalCommandsToLog.Contains(command))
Helper.LogCommand(player, info);
switch (command)
{
case "css_admins_reload":
@@ -201,7 +208,7 @@ public partial class CS2_SimpleAdmin
if (target == null || !target.IsValid || target.Connected != PlayerConnectedState.PlayerConnected)
return HookResult.Continue;
return !AdminManager.CanPlayerTarget(player, target) ? HookResult.Stop : HookResult.Continue;
}
}
@@ -210,8 +217,15 @@ public partial class CS2_SimpleAdmin
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($"!"))
@@ -281,8 +295,8 @@ public partial class CS2_SimpleAdmin
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;
@@ -358,12 +372,18 @@ public partial class CS2_SimpleAdmin
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;
}

View File

@@ -306,9 +306,9 @@ public class PlayerManager
.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)

View File

@@ -33,16 +33,20 @@ public static class PlayerPenaltyManager
});
}
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();
@@ -52,28 +56,22 @@ public static class PlayerPenaltyManager
// 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

View File

@@ -158,6 +158,8 @@ public static class ManagePlayersMenu
{
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}");
@@ -178,7 +180,7 @@ public static class ManagePlayersMenu
{
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)

View File

@@ -1 +1 @@
1.6.7a
1.6.8a

View File

@@ -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}]",

View File

@@ -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}]",

View File

@@ -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}]",

View File

@@ -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}]",

View File

@@ -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}]",

View File

@@ -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}]",

View File

@@ -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}]",

View File

@@ -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}]",

View File

@@ -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}]",

View File

@@ -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}]",

View File

@@ -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}]",

View File

@@ -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}]",

View File

@@ -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}]",

View File

@@ -8,7 +8,7 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="CounterStrikeSharp.API" Version="1.0.284" />
<PackageReference Include="CounterStrikeSharp.API" Version="1.0.286" />
</ItemGroup>
</Project>