mirror of
https://github.com/daffyyyy/CS2-SimpleAdmin.git
synced 2026-02-18 10:43:23 +00:00
Compare commits
13 Commits
build-1.7.
...
build-1.7.
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3d23b8981b | ||
|
|
39cbfdab1e | ||
|
|
4599f08fd7 | ||
|
|
4c43f14c82 | ||
|
|
f16f8cf1a5 | ||
|
|
193685826c | ||
|
|
fe73fa9917 | ||
|
|
bdada2df1e | ||
|
|
310a43fcd9 | ||
|
|
58243e813a | ||
|
|
d53446e0fe | ||
|
|
2404c1bc03 | ||
|
|
665962565e |
@@ -22,7 +22,7 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdmin
|
|||||||
public override string ModuleName => "CS2-SimpleAdmin" + (Helper.IsDebugBuild ? " (DEBUG)" : " (RELEASE)");
|
public override string ModuleName => "CS2-SimpleAdmin" + (Helper.IsDebugBuild ? " (DEBUG)" : " (RELEASE)");
|
||||||
public override string ModuleDescription => "Simple admin plugin for Counter-Strike 2 :)";
|
public override string ModuleDescription => "Simple admin plugin for Counter-Strike 2 :)";
|
||||||
public override string ModuleAuthor => "daffyy";
|
public override string ModuleAuthor => "daffyy";
|
||||||
public override string ModuleVersion => "1.7.8-beta-7";
|
public override string ModuleVersion => "1.7.8-beta-10b";
|
||||||
|
|
||||||
public override void Load(bool hotReload)
|
public override void Load(bool hotReload)
|
||||||
{
|
{
|
||||||
@@ -83,9 +83,9 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig<CS2_SimpleAdmin
|
|||||||
Unload(false);
|
Unload(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
AddTimer(6.0f, () => ReloadAdmins(null));
|
|
||||||
RegisterEvents();
|
RegisterEvents();
|
||||||
AddTimer(0.5f, RegisterCommands.InitializeCommands);
|
AddTimer(0.5f, RegisterCommands.InitializeCommands);
|
||||||
|
AddTimer(1.0f, () => ReloadAdmins(null));
|
||||||
|
|
||||||
if (!CoreConfig.UnlockConCommands)
|
if (!CoreConfig.UnlockConCommands)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -19,16 +19,16 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="CounterStrikeSharp.API" Version="1.0.346">
|
<PackageReference Include="CounterStrikeSharp.API" Version="1.0.361">
|
||||||
<PrivateAssets>none</PrivateAssets>
|
<PrivateAssets>none</PrivateAssets>
|
||||||
<ExcludeAssets>runtime</ExcludeAssets>
|
<ExcludeAssets>runtime</ExcludeAssets>
|
||||||
<IncludeAssets>compile; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
<IncludeAssets>compile; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
</PackageReference>
|
</PackageReference>
|
||||||
<PackageReference Include="Dapper" Version="2.1.66" />
|
<PackageReference Include="Dapper" Version="2.1.66" />
|
||||||
<PackageReference Include="MySqlConnector" Version="2.5.0-beta.1" />
|
<PackageReference Include="MySqlConnector" Version="2.5.0" />
|
||||||
<PackageReference Include="System.Data.SQLite.Core" Version="1.0.119" />
|
<PackageReference Include="System.Data.SQLite.Core" Version="1.0.119" />
|
||||||
<PackageReference Include="System.Linq.Async" Version="7.0.0-preview.1.g24680b5469" />
|
<PackageReference Include="System.Linq.Async" Version="7.0.0" />
|
||||||
<PackageReference Include="ZLinq" Version="1.5.3" />
|
<PackageReference Include="ZLinq" Version="1.5.4" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
@@ -507,7 +507,7 @@ public partial class CS2_SimpleAdmin
|
|||||||
var adminsFile = await File.ReadAllTextAsync(Instance.ModuleDirectory + "/data/admins.json");
|
var adminsFile = await File.ReadAllTextAsync(Instance.ModuleDirectory + "/data/admins.json");
|
||||||
var groupsFile = await File.ReadAllTextAsync(Instance.ModuleDirectory + "/data/groups.json");
|
var groupsFile = await File.ReadAllTextAsync(Instance.ModuleDirectory + "/data/groups.json");
|
||||||
|
|
||||||
await Server.NextWorldUpdateAsync(() =>
|
await Server.NextWorldUpdateAsync(() =>
|
||||||
{
|
{
|
||||||
AddTimer(1, () =>
|
AddTimer(1, () =>
|
||||||
{
|
{
|
||||||
@@ -521,7 +521,7 @@ public partial class CS2_SimpleAdmin
|
|||||||
_logger?.LogInformation("Loaded admins!");
|
_logger?.LogInformation("Loaded admins!");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
//_ = _adminManager.GiveAllGroupsFlags();
|
//_ = _adminManager.GiveAllGroupsFlags();
|
||||||
//_ = _adminManager.GiveAllFlags();
|
//_ = _adminManager.GiveAllFlags();
|
||||||
|
|||||||
@@ -448,13 +448,13 @@ public partial class CS2_SimpleAdmin
|
|||||||
|
|
||||||
private void OnMapStart(string mapName)
|
private void OnMapStart(string mapName)
|
||||||
{
|
{
|
||||||
if (!ServerLoaded || ServerId == null)
|
|
||||||
AddTimer(2.0f, OnGameServerSteamAPIActivated);
|
|
||||||
|
|
||||||
if (Config.OtherSettings.ReloadAdminsEveryMapChange && ServerLoaded && ServerId != null)
|
if (Config.OtherSettings.ReloadAdminsEveryMapChange && ServerLoaded && ServerId != null)
|
||||||
AddTimer(5.0f, () => ReloadAdmins(null));
|
ReloadAdmins(null);
|
||||||
|
|
||||||
AddTimer(1.0f, ServerManager.CheckHibernationStatus);
|
AddTimer(1.0f, ServerManager.CheckHibernationStatus);
|
||||||
|
|
||||||
|
if (!ServerLoaded || ServerId == null)
|
||||||
|
AddTimer(1.5f, OnGameServerSteamAPIActivated);
|
||||||
|
|
||||||
// AddTimer(34, () =>
|
// AddTimer(34, () =>
|
||||||
// {
|
// {
|
||||||
|
|||||||
@@ -620,47 +620,40 @@ internal class CacheManager: IDisposable
|
|||||||
if (CS2_SimpleAdmin.Instance.Config.OtherSettings.BanType == 0 || string.IsNullOrEmpty(ipAddress))
|
if (CS2_SimpleAdmin.Instance.Config.OtherSettings.BanType == 0 || string.IsNullOrEmpty(ipAddress))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (!_playerIpsCache.TryGetValue(steamId, out var ipData))
|
if (!IpHelper.TryConvertIpToUint(ipAddress, out var ipUInt))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
var cutoff = Time.ActualDateTime().AddDays(-CS2_SimpleAdmin.Instance.Config.OtherSettings.ExpireOldIpBans);
|
if (_cachedIgnoredIps.Contains(ipUInt))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (!_ipIndex.TryGetValue(ipUInt, out var ipBanRecords))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
var ipBan = ipBanRecords.FirstOrDefault(r => r.StatusEnum == BanStatus.ACTIVE);
|
||||||
|
if (ipBan == null)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (!_banCache.TryGetValue(ipBan.Id, out var cachedIpBan) || cachedIpBan.StatusEnum != BanStatus.ACTIVE)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
var expireOldIpBans = CS2_SimpleAdmin.Instance.Config.OtherSettings.ExpireOldIpBans;
|
||||||
|
if (expireOldIpBans > 0)
|
||||||
|
{
|
||||||
|
var cutoff = Time.ActualDateTime().AddDays(-expireOldIpBans);
|
||||||
|
if (ipBan.Created < cutoff)
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
var unknownName = CS2_SimpleAdmin._localizer?["sa_unknown"] ?? "Unknown";
|
var unknownName = CS2_SimpleAdmin._localizer?["sa_unknown"] ?? "Unknown";
|
||||||
|
|
||||||
if (ipAddress != null && IpHelper.TryConvertIpToUint(ipAddress, out var ipAsUint))
|
if (string.IsNullOrEmpty(ipBan.PlayerName))
|
||||||
{
|
ipBan.PlayerName = playerName;
|
||||||
if (!_cachedIgnoredIps.Contains(ipAsUint))
|
|
||||||
{
|
|
||||||
ipData.Add(new IpRecord(ipAsUint, Time.ActualDateTime().AddSeconds(-2), unknownName));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach (var ipRecord in ipData)
|
ipBan.PlayerSteamId ??= steamId;
|
||||||
{
|
|
||||||
if (ipRecord.UsedAt < cutoff || _cachedIgnoredIps.Contains(ipRecord.Ip))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if (!_ipIndex.TryGetValue(ipRecord.Ip, out var banRecords))
|
_ = Task.Run(() => UpdatePlayerData(playerName, steamId, ipAddress));
|
||||||
continue;
|
|
||||||
|
|
||||||
var activeBan = banRecords.FirstOrDefault(r => r.StatusEnum == BanStatus.ACTIVE);
|
return true;
|
||||||
if (activeBan == null)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
// Double-check the ban is still active in cache (handle race conditions)
|
|
||||||
if (!_banCache.TryGetValue(activeBan.Id, out var cachedBan) || cachedBan.StatusEnum != BanStatus.ACTIVE)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if (string.IsNullOrEmpty(activeBan.PlayerName))
|
|
||||||
activeBan.PlayerName = unknownName;
|
|
||||||
|
|
||||||
activeBan.PlayerSteamId ??= steamId;
|
|
||||||
|
|
||||||
_ = Task.Run(() => UpdatePlayerData(playerName, steamId, ipAddress));
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ public class ServerManager
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public void LoadServerData()
|
public void LoadServerData()
|
||||||
{
|
{
|
||||||
CS2_SimpleAdmin.Instance.AddTimer(2.0f, () =>
|
CS2_SimpleAdmin.Instance.AddTimer(1.0f, () =>
|
||||||
{
|
{
|
||||||
if (CS2_SimpleAdmin.ServerLoaded || CS2_SimpleAdmin.DatabaseProvider == null) return;
|
if (CS2_SimpleAdmin.ServerLoaded || CS2_SimpleAdmin.DatabaseProvider == null) return;
|
||||||
|
|
||||||
@@ -103,14 +103,12 @@ public class ServerManager
|
|||||||
CS2_SimpleAdmin.ServerId = serverId;
|
CS2_SimpleAdmin.ServerId = serverId;
|
||||||
CS2_SimpleAdmin._logger?.LogInformation("Loaded server with ip {ip}", ipAddress);
|
CS2_SimpleAdmin._logger?.LogInformation("Loaded server with ip {ip}", ipAddress);
|
||||||
|
|
||||||
if (CS2_SimpleAdmin.ServerId != null)
|
CS2_SimpleAdmin.ServerLoaded = true;
|
||||||
{
|
|
||||||
await Server.NextWorldUpdateAsync(() => CS2_SimpleAdmin.Instance.ReloadAdmins(null));
|
|
||||||
}
|
|
||||||
|
|
||||||
CS2_SimpleAdmin.ServerLoaded = true;
|
|
||||||
if (CS2_SimpleAdmin.Instance.CacheManager != null)
|
if (CS2_SimpleAdmin.Instance.CacheManager != null)
|
||||||
|
{
|
||||||
await CS2_SimpleAdmin.Instance.CacheManager.InitializeCacheAsync();
|
await CS2_SimpleAdmin.Instance.CacheManager.InitializeCacheAsync();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -24,7 +24,10 @@ public record BanRecord
|
|||||||
|
|
||||||
[Column("player_ip")]
|
[Column("player_ip")]
|
||||||
public string? PlayerIp { get; set; }
|
public string? PlayerIp { get; set; }
|
||||||
|
|
||||||
|
[Column("created")]
|
||||||
|
public DateTime Created { get; init; }
|
||||||
|
|
||||||
[Column("status")]
|
[Column("status")]
|
||||||
public required string Status { get; init; }
|
public required string Status { get; init; }
|
||||||
|
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
1.7.8-beta-7
|
1.7.8-beta-10b
|
||||||
@@ -9,7 +9,7 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="CounterStrikeSharp.API" Version="1.0.346" />
|
<PackageReference Include="CounterStrikeSharp.API" Version="1.0.361" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user