Skip to content

Commit 9723a4f

Browse files
committed
:(
:(
1 parent 4865b76 commit 9723a4f

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

CS2-SimpleAdmin/Managers/PlayerManager.cs

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,15 @@ public void CheckPlayersTimer()
283283
#endif
284284
if (CS2_SimpleAdmin.DatabaseProvider == null)
285285
return;
286+
287+
// Optimization: Get players once and avoid allocating anonymous types
288+
var validPlayers = Helper.GetValidPlayers();
289+
// Use ValueTuple instead of anonymous type - better performance and less allocations
290+
var tempPlayers = new List<(string PlayerName, ulong SteamID, string? IpAddress, int? UserId, int Slot)>(validPlayers.Count);
291+
foreach (var p in validPlayers)
292+
{
293+
tempPlayers.Add((p.PlayerName, p.SteamID, p.IpAddress, p.UserId, p.Slot));
294+
}
286295

287296
var pluginInstance = CS2_SimpleAdmin.Instance;
288297
var config = _config.OtherSettings; // Cache config access
@@ -291,8 +300,7 @@ public void CheckPlayersTimer()
291300
{
292301
try
293302
{
294-
// Always run cache and permission refresh, regardless of player count
295-
// This ensures bans/mutes status changes are detected even when server is empty
303+
// Run all expire tasks in parallel
296304
var expireTasks = new[]
297305
{
298306
pluginInstance.BanManager.ExpireOldBans(),
@@ -320,19 +328,14 @@ public void CheckPlayersTimer()
320328
if (pluginInstance.CacheManager == null)
321329
return;
322330

323-
// Only check players if there are any online
324-
var validPlayers = Helper.GetValidPlayers();
325-
if (validPlayers.Count == 0)
326-
return;
327-
328331
// Optimization: Cache ban type and multi-account check to avoid repeated config access
329332
var banType = config.BanType;
330333
var checkMultiAccounts = config.CheckMultiAccountsByIp;
331334

332335
var bannedPlayers = new List<(string PlayerName, ulong SteamID, string? IpAddress, int? UserId, int Slot)>();
333336

334337
// Manual loop instead of LINQ - better performance
335-
foreach (var player in validPlayers)
338+
foreach (var player in tempPlayers)
336339
{
337340
var playerName = player.PlayerName;
338341
var steamId = player.SteamID;
@@ -348,7 +351,7 @@ public void CheckPlayersTimer()
348351

349352
if (isBanned)
350353
{
351-
bannedPlayers.Add((playerName, steamId, ip, player.UserId, player.Slot));
354+
bannedPlayers.Add(player);
352355
}
353356
}
354357

@@ -369,8 +372,8 @@ await Server.NextWorldUpdateAsync(() =>
369372
if (config.TimeMode == 0)
370373
{
371374
// Optimization: Manual projection instead of LINQ
372-
var onlinePlayers = new List<(ulong, int?, int)>(validPlayers.Count);
373-
foreach (var player in validPlayers)
375+
var onlinePlayers = new List<(ulong, int?, int)>(tempPlayers.Count);
376+
foreach (var player in tempPlayers)
374377
{
375378
onlinePlayers.Add((player.SteamID, player.UserId, player.Slot));
376379
}

0 commit comments

Comments
 (0)