mirror of
https://github.com/daffyyyy/CS2-SimpleAdmin.git
synced 2026-03-09 16:18:49 +00:00
Compare commits
2 Commits
c31addb9e6
...
4b0fd14838
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4b0fd14838 | ||
|
|
b2ebe136c3 |
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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>
|
||||
|
||||
|
||||
@@ -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.");
|
||||
}
|
||||
|
||||
@@ -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"));
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -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.");
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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?. | ||||