Skip to content

Commit

Permalink
1.3.6b
Browse files Browse the repository at this point in the history
- Fixed ban checking
- Small changes
- Updated css
  • Loading branch information
daffyyyy committed Mar 9, 2024
1 parent 2ab2f9c commit 5259051
Show file tree
Hide file tree
Showing 10 changed files with 62 additions and 45 deletions.
4 changes: 2 additions & 2 deletions CS2-SimpleAdmin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

namespace CS2_SimpleAdmin;

[MinimumApiVersion(178)]
[MinimumApiVersion(191)]
public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdminConfig>
{
public static CS2_SimpleAdmin Instance { get; private set; } = new();
Expand All @@ -38,7 +38,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 & Dliix66";
public override string ModuleVersion => "1.3.6a";
public override string ModuleVersion => "1.3.6b";

public CS2_SimpleAdminConfig Config { get; set; } = new();

Expand Down
2 changes: 1 addition & 1 deletion CS2-SimpleAdmin.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="CounterStrikeSharp.API" Version="1.0.189" />
<PackageReference Include="CounterStrikeSharp.API" Version="1.0.193" />
<PackageReference Include="Dapper" Version="2.1.35" />
<PackageReference Include="Discord.Net.Webhook" Version="3.13.1" />
<PackageReference Include="MySqlConnector" Version="2.3.5" />
Expand Down
2 changes: 0 additions & 2 deletions Commands/basecomms.cs
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,6 @@ public void OnUngagCommand(CCSPlayerController? caller, CommandInfo command)
await _muteManager.UnmutePlayer(player.SteamID.ToString(), 0); // Unmute by type 0 (gag)
});
if (TagsDetected)
Server.ExecuteCommand($"css_tag_unmute {player!.SteamID}");
});
Expand Down Expand Up @@ -695,7 +694,6 @@ public void OnUnmuteCommand(CCSPlayerController? caller, CommandInfo command)
player.VoiceFlags = VoiceFlags.Normal;
});
*/

}

[ConsoleCommand("css_silence")]
Expand Down
2 changes: 2 additions & 0 deletions Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ public class CustomServerCommandData
{
[JsonPropertyName("Flag")]
public string Flag { get; set; } = "@css/generic";

[JsonPropertyName("DisplayName")]
public string DisplayName { get; set; } = "";

[JsonPropertyName("Command")]
public string Command { get; set; } = "";
}
Expand Down
58 changes: 37 additions & 21 deletions Events.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using CounterStrikeSharp.API.Modules.Admin;
using CounterStrikeSharp.API.Modules.Commands;
using CounterStrikeSharp.API.Modules.Cvars;
using CounterStrikeSharp.API.Modules.Entities;
using Dapper;
using Microsoft.Extensions.Logging;
using System.Data;
Expand All @@ -17,21 +18,21 @@ public partial class CS2_SimpleAdmin
private void RegisterEvents()
{
RegisterListener<Listeners.OnMapStart>(OnMapStart);
RegisterListener<Listeners.OnClientConnected>(OnClientConnected);
RegisterListener<Listeners.OnClientDisconnectPost>(OnClientDisconnectPost);
//RegisterListener<Listeners.OnClientConnected>(OnClientConnected);
RegisterListener<Listeners.OnClientDisconnect>(OnClientDisconnect);
AddCommandListener("say", OnCommandSay);
AddCommandListener("say_team", OnCommandTeamSay);
}

private void OnClientDisconnectPost(int playerSlot)
private void OnClientDisconnect(int playerSlot)
{
CCSPlayerController? player = Utilities.GetPlayerFromSlot(playerSlot);

#if DEBUG
Logger.LogCritical("[OnClientDisconnect] Before");
#endif

if (player is null || player.IsBot || player.IsHLTV || player.SteamID.ToString().Length != 17) return;
if (player is null || !player.IsValid || string.IsNullOrEmpty(player.CrosshairCodes) || player.IsBot || player.IsHLTV || !player.UserId.HasValue) return;

#if DEBUG
Logger.LogCritical("[OnClientDisconnect] After Check");
Expand All @@ -47,37 +48,54 @@ private void OnClientDisconnectPost(int playerSlot)
if (godPlayers.Contains(player.Slot))
RemoveFromConcurrentBag(godPlayers, player.Slot);

if (player.AuthorizedSteamID == null) return;
SteamID? authorizedSteamID = player.AuthorizedSteamID;

if (AdminSQLManager._adminCache.TryGetValue(player.AuthorizedSteamID, out DateTime? expirationTime)
&& expirationTime <= DateTime.Now)
if (authorizedSteamID == null) return;

Task.Run(() =>
{
AdminManager.ClearPlayerPermissions(player.AuthorizedSteamID);
AdminManager.RemovePlayerAdminData(player.AuthorizedSteamID);
}
}
if (AdminSQLManager._adminCache.TryGetValue(authorizedSteamID, out DateTime? expirationTime)
&& expirationTime <= DateTime.Now)
{
AdminManager.ClearPlayerPermissions(authorizedSteamID);
AdminManager.RemovePlayerAdminData(authorizedSteamID);
}
});

private void OnClientConnected(int playerSlot)
//if (player.AuthorizedSteamID == null) return;

//if (AdminSQLManager._adminCache.TryGetValue(player.AuthorizedSteamID, out DateTime? expirationTime)
// && expirationTime <= DateTime.Now)
//{
// AdminManager.ClearPlayerPermissions(player.AuthorizedSteamID);
// AdminManager.RemovePlayerAdminData(player.AuthorizedSteamID);
//}
}
[GameEventHandler]
public HookResult OnPlayerFullConnect(EventPlayerConnectFull @event, GameEventInfo info)
{
CCSPlayerController? player = Utilities.GetPlayerFromSlot(playerSlot);
CCSPlayerController? player = @event.Userid;
#if DEBUG
Logger.LogCritical($"[OnPlayerConnect] Before check {player.PlayerName} : {player.IpAddress}");
#endif
if (player is null || player.IsBot || player.IsHLTV || player.SteamID.ToString().Length != 17 || string.IsNullOrEmpty(player.IpAddress)) return;
if (player is null || string.IsNullOrEmpty(player.CrosshairCodes)
|| string.IsNullOrEmpty(player.IpAddress)
|| player.IsBot || player.IsHLTV || !player.UserId.HasValue) return HookResult.Continue;

#if DEBUG
Logger.LogCritical("[OnPlayerConnect] After Check");
#endif
string ipAddress = player.IpAddress.Split(":")[0];

if (bannedPlayers.Contains(ipAddress) || bannedPlayers.Contains(player.SteamID.ToString()))
{
if (!player.UserId.HasValue) return;
if (!player.UserId.HasValue) return HookResult.Continue;
Helper.KickPlayer(player.UserId.Value, "Banned");
return;
return HookResult.Continue;
}

if (_database == null || !player.UserId.HasValue || player.UserId == null)
return;
return HookResult.Continue;

PlayerInfo playerInfo = new PlayerInfo
{
Expand Down Expand Up @@ -159,6 +177,8 @@ private void OnClientConnected(int playerSlot)
}
}
});

return HookResult.Continue;
}

[GameEventHandler]
Expand Down Expand Up @@ -224,15 +244,12 @@ private HookResult OnCommandTeamSay(CCSPlayerController? player, CommandInfo inf
[GameEventHandler]
public HookResult OnPlayerFullConnect(EventPlayerConnectFull @event, GameEventInfo info)
{
return HookResult.Continue;
}
[GameEventHandler]
public HookResult OnPlayerDisconnect(EventPlayerDisconnect @event, GameEventInfo info)
{
return HookResult.Continue;
}
*/
Expand Down Expand Up @@ -273,7 +290,6 @@ private void OnMapStart(string mapName)
{
try
{

foreach (CCSPlayerController player in Helper.GetValidPlayers())
{
if (playerPenaltyManager.IsSlotInPenalties(player.Slot))
Expand Down
3 changes: 2 additions & 1 deletion Managers/AdminSQLManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Collections.Concurrent;

namespace CS2_SimpleAdmin;

public class AdminSQLManager
{
private readonly Database _database;
Expand Down Expand Up @@ -222,4 +223,4 @@ public async Task DeleteOldAdmins()
CS2_SimpleAdmin._logger.LogCritical("Unable to remove expired admins");
}
}
}
}
28 changes: 14 additions & 14 deletions Managers/BanManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Microsoft.Extensions.Logging;

namespace CS2_SimpleAdmin;

internal class BanManager
{
private readonly Database _database;
Expand Down Expand Up @@ -188,14 +189,14 @@ public async Task ExpireOldBans()
*/

string sql = @"
UPDATE sa_bans
SET
UPDATE sa_bans
SET
status = 'EXPIRED'
WHERE
status = 'ACTIVE'
AND
`duration` > 0
AND
WHERE
status = 'ACTIVE'
AND
`duration` > 0
AND
ends <= @currentTime";

await connection.ExecuteAsync(sql, new { currentTime });
Expand All @@ -205,21 +206,20 @@ UPDATE sa_bans
DateTime ipBansTime = currentTime.AddDays(-_config.ExpireOldIpBans).ToLocalTime();

sql = @"
UPDATE sa_bans
SET
UPDATE sa_bans
SET
player_ip = NULL
WHERE
status = 'ACTIVE'
AND
WHERE
status = 'ACTIVE'
AND
ends <= @ipBansTime";

await connection.ExecuteAsync(sql, new { ipBansTime });
}

}
catch (Exception)
{
CS2_SimpleAdmin._logger?.LogCritical("Unable to remove expired bans");
}
}
}
}
4 changes: 2 additions & 2 deletions Managers/MuteManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Microsoft.Extensions.Logging;

namespace CS2_SimpleAdmin;

internal class MuteManager
{
private readonly Database _database;
Expand Down Expand Up @@ -160,5 +161,4 @@ public async Task ExpireOldMutes()
CS2_SimpleAdmin._logger.LogCritical("Unable to remove expired mutes");
}
}

}
}
3 changes: 2 additions & 1 deletion Managers/PlayerPenaltyManager.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Collections.Concurrent;

namespace CS2_SimpleAdmin;

public enum PenaltyType
{
Mute,
Expand Down Expand Up @@ -134,4 +135,4 @@ public void RemoveExpiredPenalties()
}
}
}
}
}
1 change: 0 additions & 1 deletion lang/pl.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,4 @@
"sa_adminchat_template_player": "{SILVER}(GRACZ) {lightred}{0}{default}: {lightred}{1}{default}",

"sa_discord_log_command": "**{0}** użył komendy `{1}` na serwerze `HOSTNAME`"

}

0 comments on commit 5259051

Please sign in to comment.