Compare commits

..

2 Commits

Author SHA1 Message Date
Yuriy Petleshkov
4b0fd14838 Merge 84646e4451 into b2ebe136c3 2024-11-23 06:33:45 +09:00
Dawid Bepierszcz
b2ebe136c3 1.6.9a
- Added `IsAdminSilent` to api
- Fixed disabling noclip via admin menu
- Fixed (?) hibernation problem
- Added discord webhook fire when adding ban or mute for offline player
- Updated css and mysqlconnector
2024-11-22 22:31:06 +01:00
17 changed files with 175 additions and 41 deletions

View File

@@ -82,4 +82,9 @@ public class CS2_SimpleAdminApi : ICS2_SimpleAdminApi
{
Helper.LogCommand(caller, command);
}
public bool IsAdminSilent(CCSPlayerController player)
{
return CS2_SimpleAdmin.SilentPlayers.Contains(player.Slot);
}
}

View File

@@ -11,7 +11,7 @@ using MySqlConnector;
namespace CS2_SimpleAdmin;
[MinimumApiVersion(284)]
[MinimumApiVersion(286)]
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.8a";
public override string ModuleVersion => "1.6.9a";
public override void Load(bool hotReload)
{
@@ -36,10 +36,11 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdmin
AddTimer(2.0f, () =>
{
if (Database == null) return;
var playerManager = new PlayerManager();
Helper.GetValidPlayers().ForEach(player =>
{
var playerManager = new PlayerManager();
playerManager.LoadPlayerData(player);
});
});
@@ -56,9 +57,14 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdmin
{
AddTimer(3.0f, () => ReloadAdmins(null));
MenuApi = MenuCapability.Get();
if (MenuApi == null)
Logger.LogError("MenuManager Core not found...");
try
{
MenuApi = MenuCapability.Get();
}
catch (Exception ex)
{
Logger.LogError("Unable to load required plugins ... \n{exception}", ex.Message);
}
RegisterCommands.InitializeCommands();
}
@@ -88,9 +94,11 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdmin
DbConnectionString = builder.ConnectionString;
Database = new Database.Database(DbConnectionString);
if (!Database.CheckDatabaseConnection())
if (!Database.CheckDatabaseConnection(out var exception))
{
Logger.LogError("Unable connect to database!");
if (exception != null)
Logger.LogError("Problem with database connection! \n{exception}", exception);
Unload(false);
return;
}

View File

@@ -10,9 +10,9 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="CounterStrikeSharp.API" Version="1.0.286" />
<PackageReference Include="CounterStrikeSharp.API" Version="1.0.287" />
<PackageReference Include="Dapper" Version="2.1.35" />
<PackageReference Include="MySqlConnector" Version="2.4.0-beta.2" />
<PackageReference Include="MySqlConnector" Version="2.4.0" />
<PackageReference Include="Newtonsoft.Json" Version="*" />
</ItemGroup>

View File

@@ -171,6 +171,8 @@ public partial class CS2_SimpleAdmin
{
await BanManager.AddBanBySteamid(steamid, adminInfo, reason, time);
});
Helper.SendDiscordPenaltyMessage(caller, steamid, reason, time, PenaltyType.Ban, _localizer);
command.ReplyToCommand($"Player with steamid {steamid} is not online. Ban has been added offline.");
}

View File

@@ -375,14 +375,14 @@ public partial class CS2_SimpleAdmin
var adminsFile = await File.ReadAllTextAsync(Instance.ModuleDirectory + "/data/admins.json");
var groupsFile = await File.ReadAllTextAsync(Instance.ModuleDirectory + "/data/groups.json");
await Server.NextFrameAsync(() =>
await Server.NextWorldUpdateAsync(() =>
{
if (!string.IsNullOrEmpty(adminsFile))
AddTimer(0.5f, () => AdminManager.LoadAdminData(ModuleDirectory + "/data/admins.json"));
AddTimer(1.0f, () => AdminManager.LoadAdminData(ModuleDirectory + "/data/admins.json"));
if (!string.IsNullOrEmpty(groupsFile))
AddTimer(1.0f, () => AdminManager.LoadAdminGroups(ModuleDirectory + "/data/groups.json"));
AddTimer(1.5f, () => AdminManager.LoadAdminGroups(ModuleDirectory + "/data/groups.json"));
if (!string.IsNullOrEmpty(adminsFile))
AddTimer(1.5f, () => AdminManager.LoadAdminData(ModuleDirectory + "/data/admins.json"));
AddTimer(2.0f, () => AdminManager.LoadAdminData(ModuleDirectory + "/data/admins.json"));
});
});

View File

@@ -151,6 +151,8 @@ public partial class CS2_SimpleAdmin
await MuteManager.AddMuteBySteamid(steamid, adminInfo, reason, time);
});
Helper.SendDiscordPenaltyMessage(caller, steamid, reason, time, PenaltyType.Gag, _localizer);
command.ReplyToCommand($"Player with steamid {steamid} is not online. Gag has been added offline.");
}
@@ -370,6 +372,8 @@ public partial class CS2_SimpleAdmin
await MuteManager.AddMuteBySteamid(steamid, adminInfo, reason, time, 1);
});
Helper.SendDiscordPenaltyMessage(caller, steamid, reason, time, PenaltyType.Mute, _localizer);
command.ReplyToCommand($"Player with steamid {steamid} is not online. Mute has been added offline.");
}
@@ -589,6 +593,8 @@ public partial class CS2_SimpleAdmin
await MuteManager.AddMuteBySteamid(steamid, adminInfo, reason, time, 2);
});
Helper.SendDiscordPenaltyMessage(caller, steamid, reason, time, PenaltyType.Silence, _localizer);
command.ReplyToCommand($"Player with steamid {steamid} is not online. Silence has been added offline.");
}

View File

@@ -41,16 +41,18 @@ public class Database(string dbConnectionString)
migrator.ExecuteMigrations();
}
public bool CheckDatabaseConnection()
public bool CheckDatabaseConnection(out string? exception)
{
using var connection = GetConnection();
exception = null;
try
{
return connection.Ping();
}
catch
catch (Exception ex)
{
exception = ex.Message;
return false;
}
}

View File

@@ -96,7 +96,7 @@ public partial class CS2_SimpleAdmin
GravityPlayers.Remove(player);
if (player.UserId.HasValue)
PlayersInfo.Remove(player.UserId.Value);
PlayersInfo.TryRemove(player.UserId.Value, out _);
var authorizedSteamId = player.AuthorizedSteamID;
if (authorizedSteamId == null || !PermissionManager.AdminCache.TryGetValue(authorizedSteamId,
@@ -132,7 +132,7 @@ public partial class CS2_SimpleAdmin
public HookResult OnRoundStart(EventRoundStart @event, GameEventInfo info)
{
#if DEBUG
Logger.LogCritical("[OnRoundEnd]");
Logger.LogCritical("[OnRoundStart]");
#endif
GodPlayers.Clear();
@@ -209,7 +209,9 @@ 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;
Logger.LogInformation($"{player.PlayerName} {AdminManager.GetPlayerImmunity(player).ToString()} probuje wywalic {target.PlayerName} {AdminManager.GetPlayerImmunity(target).ToString()}");
return !player.CanTarget(target) ? HookResult.Stop : HookResult.Continue;
}
}
@@ -370,12 +372,15 @@ public partial class CS2_SimpleAdmin
{
var player = @event.Userid;
if (player?.UserId == null || player.IsBot || player.Connected != PlayerConnectedState.PlayerConnected)
if (player?.UserId == null || !player.IsValid || player.IsHLTV || player.Connected != PlayerConnectedState.PlayerConnected)
return HookResult.Continue;
SpeedPlayers.Remove(player.Slot);
GravityPlayers.Remove(player);
if (!PlayersInfo.ContainsKey(player.UserId.Value))
return HookResult.Continue;
PlayersInfo[player.UserId.Value].DiePosition = new DiePosition(
new Vector(
player.PlayerPawn.Value?.