Compare commits

..

2 Commits

Author SHA1 Message Date
Dawid Bepierszcz
a588267165 Use IpHistory record and make player timer repeat 2026-06-17 03:19:34 +02:00
Dawid Bepierszcz
b0c7fd12c3 Bump version to 1.8.2a and add rename timer 2026-06-17 02:59:23 +02:00
6 changed files with 32 additions and 19 deletions

View File

@@ -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.8.1a"; public override string ModuleVersion => "1.8.2a";
public override void Load(bool hotReload) public override void Load(bool hotReload)
{ {

View File

@@ -253,7 +253,7 @@ public partial class CS2_SimpleAdmin
player.DiePosition = null; player.DiePosition = null;
} }
AddTimer(0.41f, () => AddTimer(0.5f, () =>
{ {
foreach (var list in RenamedPlayers) foreach (var list in RenamedPlayers)
{ {

View File

@@ -73,7 +73,7 @@ internal class CacheManager: IDisposable
if (CS2_SimpleAdmin.Instance.Config.OtherSettings.CheckMultiAccountsByIp) if (CS2_SimpleAdmin.Instance.Config.OtherSettings.CheckMultiAccountsByIp)
{ {
// Optimization: Load IP history and build cache in single pass // Optimization: Load IP history and build cache in single pass
var ipHistory = await connection.QueryAsync<(ulong steamid, string? name, uint address, DateTime used_at)>( var ipHistory = await connection.QueryAsync<IpHistoryRow>(
"SELECT steamid, name, address, used_at FROM sa_players_ips ORDER BY steamid, address, used_at DESC"); "SELECT steamid, name, address, used_at FROM sa_players_ips ORDER BY steamid, address, used_at DESC");
var unknownName = CS2_SimpleAdmin._localizer?["sa_unknown"] ?? "Unknown"; var unknownName = CS2_SimpleAdmin._localizer?["sa_unknown"] ?? "Unknown";
@@ -84,24 +84,24 @@ internal class CacheManager: IDisposable
foreach (var record in ipHistory) foreach (var record in ipHistory)
{ {
// When we encounter a new steamid, save the previous one // When we encounter a new steamid, save the previous one
if (record.steamid != currentSteamId && currentSteamId != 0) if (record.Steamid != currentSteamId && currentSteamId != 0)
{ {
_playerIpsCache[currentSteamId] = currentIpSet; _playerIpsCache[currentSteamId] = currentIpSet;
currentIpSet = new HashSet<IpRecord>(new IpRecordComparer()); currentIpSet = new HashSet<IpRecord>(new IpRecordComparer());
latestIpTimestamps.Clear(); latestIpTimestamps.Clear();
} }
currentSteamId = record.steamid; currentSteamId = record.Steamid;
// Only keep the latest timestamp for each IP // Only keep the latest timestamp for each IP
if (!latestIpTimestamps.TryGetValue(record.address, out var existingTimestamp) || if (!latestIpTimestamps.TryGetValue(record.Address, out var existingTimestamp) ||
record.used_at > existingTimestamp) record.Used_at > existingTimestamp)
{ {
latestIpTimestamps[record.address] = record.used_at; latestIpTimestamps[record.Address] = record.Used_at;
currentIpSet.Add(new IpRecord( currentIpSet.Add(new IpRecord(
record.address, record.Address,
record.used_at, record.Used_at,
string.IsNullOrEmpty(record.name) ? unknownName : record.name string.IsNullOrEmpty(record.Name) ? unknownName : record.Name
)); ));
} }
} }
@@ -283,23 +283,23 @@ internal class CacheManager: IDisposable
if (CS2_SimpleAdmin.Instance.Config.OtherSettings.CheckMultiAccountsByIp) if (CS2_SimpleAdmin.Instance.Config.OtherSettings.CheckMultiAccountsByIp)
{ {
var ipHistory = (await connection.QueryAsync<(ulong steamid, string? name, uint address, DateTime used_at)>( var ipHistory = (await connection.QueryAsync<IpHistoryRow>(
"SELECT steamid, name, address, used_at FROM sa_players_ips WHERE used_at >= @lastUpdate ORDER BY used_at DESC LIMIT 300", "SELECT steamid, name, address, used_at FROM sa_players_ips WHERE used_at >= @lastUpdate ORDER BY used_at DESC LIMIT 300",
new { lastUpdate = _lastUpdateTime })); new { lastUpdate = _lastUpdateTime }));
foreach (var group in ipHistory.AsValueEnumerable().GroupBy(x => x.steamid)) foreach (var group in ipHistory.AsValueEnumerable().GroupBy(x => x.Steamid))
{ {
var ipSet = new HashSet<IpRecord>( var ipSet = new HashSet<IpRecord>(
group group
.GroupBy(x => x.address) .GroupBy(x => x.Address)
.Select(g => .Select(g =>
{ {
var latest = g.MaxBy(x => x.used_at); var latest = g.MaxBy(x => x.Used_at);
return new IpRecord( return new IpRecord(
g.Key, g.Key,
latest.used_at, latest.Used_at,
!string.IsNullOrEmpty(latest.name) !string.IsNullOrEmpty(latest.Name)
? latest.name ? latest.Name
: CS2_SimpleAdmin._localizer?["sa_unknown"] ?? "Unknown" : CS2_SimpleAdmin._localizer?["sa_unknown"] ?? "Unknown"
); );
}), }),

View File

@@ -275,6 +275,16 @@ internal class PlayerManager
/// </remarks> /// </remarks>
public void CheckPlayersTimer() public void CheckPlayersTimer()
{ {
CS2_SimpleAdmin.Instance.AddTimer(5f, () =>
{
foreach (var (steamid, name) in CS2_SimpleAdmin.RenamedPlayers)
{
var player = Helper.GetPlayerFromSteamid64(steamid);
if (player == null || !player.IsValid || player.PlayerName == name) continue;
player.Rename(name);
}
}, TimerFlags.REPEAT);
CS2_SimpleAdmin.Instance.PlayersTimer = CS2_SimpleAdmin.Instance.AddTimer(61.0f, () => CS2_SimpleAdmin.Instance.PlayersTimer = CS2_SimpleAdmin.Instance.AddTimer(61.0f, () =>
{ {
#if DEBUG #if DEBUG

View File

@@ -0,0 +1,3 @@
namespace CS2_SimpleAdmin.Models;
public record IpHistoryRow(ulong Steamid, string? Name, uint Address, DateTime Used_at);

View File

@@ -1 +1 @@
1.8.1a 1.8.2a