From 9b4e352797901aa077fcbb788f064da44e4f8445 Mon Sep 17 00:00:00 2001 From: CWX Date: Thu, 10 Apr 2025 12:47:13 +0100 Subject: [PATCH] change to ConcurrentDict to lock object --- .../SPTarkov.Server.Core/Helpers/BotHelper.cs | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/Libraries/SPTarkov.Server.Core/Helpers/BotHelper.cs b/Libraries/SPTarkov.Server.Core/Helpers/BotHelper.cs index b93f8eb9..bd6acb33 100644 --- a/Libraries/SPTarkov.Server.Core/Helpers/BotHelper.cs +++ b/Libraries/SPTarkov.Server.Core/Helpers/BotHelper.cs @@ -1,3 +1,4 @@ +using System.Collections.Concurrent; using SPTarkov.Server.Core.Models.Eft.Common.Tables; using SPTarkov.Server.Core.Models.Spt.Config; using SPTarkov.Server.Core.Models.Utils; @@ -20,7 +21,7 @@ public class BotHelper( protected BotConfig _botConfig = _configServer.GetConfig(); protected PmcConfig _pmcConfig = _configServer.GetConfig(); protected static readonly FrozenSet _pmcTypeIds = ["usec", "bear", "pmc", "pmcbear", "pmcusec"]; - protected Dictionary> _pmcNameCache = new(); + protected ConcurrentDictionary> _pmcNameCache = new(); /// /// Get a template object for the specified botRole from bots.types db @@ -213,16 +214,8 @@ public class BotHelper( return _randomUtil.GetCollectionValue(chosenFactionDetails.FirstNames); } - // TODO: this keeps randomly null refing with nothing being null, plz fix smart person - try - { - _pmcNameCache.TryAdd(cacheKey, matchingNames); - } - catch (Exception e) - { - _logger.Debug($"this keeps randomly null refing with nothing being null, plz fix smart person"); - _logger.Debug(e.ToString()); - } + _pmcNameCache.TryAdd(cacheKey, matchingNames); + eligibleNames = matchingNames; }