Merge branch 'main' of https://github.com/sp-tarkov/server-csharp
This commit is contained in:
@@ -15,6 +15,7 @@ using Core.Services;
|
||||
using Core.Utils;
|
||||
using Core.Utils.Cloners;
|
||||
using SptCommon.Extensions;
|
||||
using LogLevel = Core.Models.Spt.Logging.LogLevel;
|
||||
|
||||
namespace Core.Controllers;
|
||||
|
||||
@@ -102,7 +103,8 @@ public class BotController(
|
||||
{
|
||||
// No bot of this type found, copy details from assault
|
||||
result[botTypeLower] = result["assault"];
|
||||
_logger.Debug($"Unable to find bot: {botTypeLower} in db, copying 'assault'");
|
||||
if(_logger.IsLogEnabled(LogLevel.Debug))
|
||||
_logger.Debug($"Unable to find bot: {botTypeLower} in db, copying 'assault'");
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -149,21 +151,31 @@ public class BotController(
|
||||
_pmcConfig.AllPMCsHavePlayerNameWithRandomPrefixChance
|
||||
);
|
||||
|
||||
var tasks = new List<Task>();
|
||||
// Map conditions to promises for bot generation
|
||||
foreach (var condition in request.Conditions ?? [])
|
||||
{
|
||||
var botGenerationDetails = GetBotGenerationDetailsForWave(
|
||||
condition,
|
||||
pmcProfile,
|
||||
allPmcsHaveSameNameAsPlayer,
|
||||
raidSettings,
|
||||
_botConfig.PresetBatch!.GetValueOrDefault(condition.Role, 15),
|
||||
_botHelper.IsBotPmc(condition.Role)
|
||||
);
|
||||
tasks.Add(
|
||||
Task.Factory.StartNew(
|
||||
() =>
|
||||
{
|
||||
var botGenerationDetails = GetBotGenerationDetailsForWave(
|
||||
condition,
|
||||
pmcProfile,
|
||||
allPmcsHaveSameNameAsPlayer,
|
||||
raidSettings,
|
||||
_botConfig.PresetBatch!.GetValueOrDefault(condition.Role, 15),
|
||||
_botHelper.IsBotPmc(condition.Role)
|
||||
);
|
||||
|
||||
// Generate bots for the current condition
|
||||
GenerateWithBotDetails(condition, botGenerationDetails, sessionId);
|
||||
// Generate bots for the current condition
|
||||
GenerateWithBotDetails(condition, botGenerationDetails, sessionId);
|
||||
}
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
Task.WaitAll(tasks.ToArray());
|
||||
|
||||
return [];
|
||||
}
|
||||
@@ -191,15 +203,17 @@ public class BotController(
|
||||
|
||||
if (botCacheCount >= botGenerationDetails.BotCountToGenerate)
|
||||
{
|
||||
_logger.Debug($"Cache already has sufficient {cacheKey} bots: {botCacheCount}");
|
||||
if(_logger.IsLogEnabled(LogLevel.Debug))
|
||||
_logger.Debug($"Cache already has sufficient {cacheKey} bots: {botCacheCount}");
|
||||
return;
|
||||
}
|
||||
|
||||
// We're below desired count, add bots to cache
|
||||
var botsToGenerate = botGenerationDetails.BotCountToGenerate - botCacheCount;
|
||||
var progressWriter = new ProgressWriter(botGenerationDetails.BotCountToGenerate.GetValueOrDefault(30));
|
||||
|
||||
_logger.Debug($"Generating {botsToGenerate} bots for cacheKey: {cacheKey}");
|
||||
|
||||
if(_logger.IsLogEnabled(LogLevel.Debug))
|
||||
_logger.Debug($"Generating {botsToGenerate} bots for cacheKey: {cacheKey}");
|
||||
|
||||
for (var i = 0; i < botsToGenerate; i++)
|
||||
{
|
||||
@@ -215,10 +229,11 @@ public class BotController(
|
||||
// }
|
||||
}
|
||||
|
||||
_logger.Debug(
|
||||
$"Generated {botGenerationDetails.BotCountToGenerate} {botGenerationDetails.Role}" +
|
||||
$"({botGenerationDetails.EventRole ?? botGenerationDetails.Role ?? ""}) {botGenerationDetails.BotDifficulty}bots"
|
||||
);
|
||||
if(_logger.IsLogEnabled(LogLevel.Debug))
|
||||
_logger.Debug(
|
||||
$"Generated {botGenerationDetails.BotCountToGenerate} {botGenerationDetails.Role}" +
|
||||
$"({botGenerationDetails.EventRole ?? botGenerationDetails.Role ?? ""}) {botGenerationDetails.BotDifficulty}bots"
|
||||
);
|
||||
}
|
||||
|
||||
private List<BotBase> ReturnSingleBotFromCache(string sessionId, GenerateBotsRequestData request)
|
||||
@@ -303,11 +318,12 @@ public class BotController(
|
||||
{
|
||||
// No bot in cache, generate new and store in cache
|
||||
GenerateSingleBotAndStoreInCache(botGenerationDetails, sessionId, cacheKey);
|
||||
|
||||
_logger.Debug(
|
||||
$"Generated {botGenerationDetails.BotCountToGenerate} " +
|
||||
$"{botGenerationDetails.Role} ({botGenerationDetails.EventRole ?? ""}) {botGenerationDetails.BotDifficulty} bots"
|
||||
);
|
||||
|
||||
if(_logger.IsLogEnabled(LogLevel.Debug))
|
||||
_logger.Debug(
|
||||
$"Generated {botGenerationDetails.BotCountToGenerate} " +
|
||||
$"{botGenerationDetails.Role} ({botGenerationDetails.EventRole ?? ""}) {botGenerationDetails.BotDifficulty} bots"
|
||||
);
|
||||
}
|
||||
|
||||
var desiredBot = _botGenerationCacheService.GetBot(cacheKey);
|
||||
|
||||
@@ -12,6 +12,7 @@ using Core.Services;
|
||||
using Core.Utils;
|
||||
using Core.Utils.Cloners;
|
||||
using BodyPart = Core.Models.Eft.Common.Tables.BodyPart;
|
||||
using LogLevel = Core.Models.Spt.Logging.LogLevel;
|
||||
|
||||
|
||||
namespace Core.Generators;
|
||||
@@ -322,7 +323,8 @@ public class BotGenerator(
|
||||
|
||||
if (!experiences.TryGetValue(botDifficulty.ToLower(), out var result))
|
||||
{
|
||||
_logger.Debug($"Unable to find experience: {botDifficulty} for {role} bot, falling back to `normal`");
|
||||
if(_logger.IsLogEnabled(LogLevel.Debug))
|
||||
_logger.Debug($"Unable to find experience: {botDifficulty} for {role} bot, falling back to `normal`");
|
||||
|
||||
return _randomUtil.GetDouble(experiences["normal"].Min.Value, experiences["normal"].Max.Value);
|
||||
}
|
||||
@@ -479,7 +481,8 @@ public class BotGenerator(
|
||||
public void LogPmcGeneratedCount(List<BotBase> output)
|
||||
{
|
||||
var pmcCount = output.Aggregate(0, (acc, cur) => { return cur.Info.Side is "Bear" or "Usec" ? acc + 1 : acc; });
|
||||
_logger.Debug($"Generated {output.Count} total bots. Replaced {pmcCount} with PMCs");
|
||||
if(_logger.IsLogEnabled(LogLevel.Debug))
|
||||
_logger.Debug($"Generated {output.Count} total bots. Replaced {pmcCount} with PMCs");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -10,6 +10,7 @@ using Core.Models.Utils;
|
||||
using Core.Servers;
|
||||
using Core.Services;
|
||||
using Core.Utils;
|
||||
using LogLevel = Core.Models.Spt.Logging.LogLevel;
|
||||
|
||||
|
||||
namespace Core.Generators;
|
||||
@@ -342,7 +343,8 @@ public class BotInventoryGenerator(
|
||||
|
||||
if (!tacVestsWithArmor.Any())
|
||||
{
|
||||
_logger.Debug($"Unable to filter to only armored rigs as bot: {botRole} has none in pool");
|
||||
if(_logger.IsLogEnabled(LogLevel.Debug))
|
||||
_logger.Debug($"Unable to filter to only armored rigs as bot: {botRole} has none in pool");
|
||||
|
||||
return;
|
||||
}
|
||||
@@ -365,7 +367,8 @@ public class BotInventoryGenerator(
|
||||
|
||||
if (!allowEmptyResult && !tacVestsWithoutArmor.Any())
|
||||
{
|
||||
_logger.Debug($"Unable to filter to only unarmored rigs as bot: {botRole} has none in pool");
|
||||
if(_logger.IsLogEnabled(LogLevel.Debug))
|
||||
_logger.Debug($"Unable to filter to only unarmored rigs as bot: {botRole} has none in pool");
|
||||
|
||||
return;
|
||||
}
|
||||
@@ -420,7 +423,8 @@ public class BotInventoryGenerator(
|
||||
if (!dbResult.Key)
|
||||
{
|
||||
_logger.Error(_localisationService.GetText("bot-missing_item_template", chosenItemTpl));
|
||||
_logger.Debug($"EquipmentSlot-> {settings.RootEquipmentSlot}");
|
||||
if(_logger.IsLogEnabled(LogLevel.Debug))
|
||||
_logger.Debug($"EquipmentSlot-> {settings.RootEquipmentSlot}");
|
||||
|
||||
// Remove picked item
|
||||
settings.RootEquipmentPool.Remove(chosenItemTpl);
|
||||
|
||||
@@ -9,6 +9,7 @@ using Core.Models.Utils;
|
||||
using Core.Services;
|
||||
using Core.Servers;
|
||||
using Core.Utils.Cloners;
|
||||
using LogLevel = Core.Models.Spt.Logging.LogLevel;
|
||||
|
||||
namespace Core.Generators;
|
||||
|
||||
@@ -530,18 +531,20 @@ public class BotLootGenerator(
|
||||
if (itemAddedResult == ItemAddedResult.NO_CONTAINERS)
|
||||
{
|
||||
// Bot has no container to put item in, exit
|
||||
_logger.Debug($"Unable to add: {totalItemCount} items to bot as it lacks a container to include them");
|
||||
if(_logger.IsLogEnabled(LogLevel.Debug))
|
||||
_logger.Debug($"Unable to add: {totalItemCount} items to bot as it lacks a container to include them");
|
||||
break;
|
||||
}
|
||||
|
||||
fitItemIntoContainerAttempts++;
|
||||
if (fitItemIntoContainerAttempts >= 4)
|
||||
{
|
||||
_logger.Debug(
|
||||
$"Failed placing item: {itemToAddTemplate.Name}: {i} of: {totalItemCount} items into: {botRole} " +
|
||||
$"containers: {string.Join(",", equipmentSlots)}. Tried: {fitItemIntoContainerAttempts} " +
|
||||
$"times, reason: {itemAddedResult}, skipping"
|
||||
);
|
||||
if(_logger.IsLogEnabled(LogLevel.Debug))
|
||||
_logger.Debug(
|
||||
$"Failed placing item: {itemToAddTemplate.Name}: {i} of: {totalItemCount} items into: {botRole} " +
|
||||
$"containers: {string.Join(",", equipmentSlots)}. Tried: {fitItemIntoContainerAttempts} " +
|
||||
$"times, reason: {itemAddedResult}, skipping"
|
||||
);
|
||||
|
||||
break;
|
||||
}
|
||||
@@ -697,7 +700,8 @@ public class BotLootGenerator(
|
||||
|
||||
if (result != ItemAddedResult.SUCCESS)
|
||||
{
|
||||
_logger.Debug($"Failed to add additional weapon {generatedWeapon.Weapon[0].Id} to bot backpack, reason: {result.ToString()}");
|
||||
if(_logger.IsLogEnabled(LogLevel.Debug))
|
||||
_logger.Debug($"Failed to add additional weapon {generatedWeapon.Weapon[0].Id} to bot backpack, reason: {result.ToString()}");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -763,17 +767,18 @@ public class BotLootGenerator(
|
||||
// Prevent edge-case of small loot pools + code trying to add limited item over and over infinitely
|
||||
if (itemSpawnLimits.CurrentLimits[idToCheckFor] > itemSpawnLimits.CurrentLimits[idToCheckFor] * 10)
|
||||
{
|
||||
_logger.Debug(
|
||||
_localisationService.GetText(
|
||||
"bot-item_spawn_limit_reached_skipping_item",
|
||||
new
|
||||
{
|
||||
botRole = botRole,
|
||||
itemName = itemTemplate.Name,
|
||||
attempts = itemSpawnLimits.CurrentLimits[idToCheckFor]
|
||||
}
|
||||
)
|
||||
);
|
||||
if(_logger.IsLogEnabled(LogLevel.Debug))
|
||||
_logger.Debug(
|
||||
_localisationService.GetText(
|
||||
"bot-item_spawn_limit_reached_skipping_item",
|
||||
new
|
||||
{
|
||||
botRole = botRole,
|
||||
itemName = itemTemplate.Name,
|
||||
attempts = itemSpawnLimits.CurrentLimits[idToCheckFor]
|
||||
}
|
||||
)
|
||||
);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
using System.Diagnostics;
|
||||
using System.Runtime.InteropServices.JavaScript;
|
||||
using Core.Helpers;
|
||||
using SptCommon.Annotations;
|
||||
@@ -327,15 +328,26 @@ public class RagfairOfferGenerator(
|
||||
{
|
||||
var replacingExpiredOffers = (expiredOffers?.Count ?? 0) > 0;
|
||||
|
||||
var stopwatch = Stopwatch.StartNew();
|
||||
// get assort items from param if they exist, otherwise grab freshly generated assorts
|
||||
var assortItemsToProcess = replacingExpiredOffers
|
||||
? expiredOffers ?? []
|
||||
: ragfairAssortGenerator.GetAssortItems();
|
||||
|
||||
stopwatch.Stop();
|
||||
logger.Info($"Took {stopwatch.ElapsedMilliseconds}ms to GetRagfairAssorts");
|
||||
stopwatch.Restart();
|
||||
var tasks = new List<Task>();
|
||||
foreach (var assortItem in assortItemsToProcess)
|
||||
{
|
||||
CreateOffersFromAssort(assortItem, replacingExpiredOffers, ragfairConfig.Dynamic);
|
||||
tasks.Add(
|
||||
Task.Factory.StartNew(
|
||||
() => { CreateOffersFromAssort(assortItem, replacingExpiredOffers, ragfairConfig.Dynamic); }
|
||||
)
|
||||
);
|
||||
}
|
||||
Task.WaitAll(tasks.ToArray());
|
||||
stopwatch.Stop();
|
||||
logger.Info($"Took {stopwatch.ElapsedMilliseconds}ms to CreateOffersFromAssort");
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -2,12 +2,14 @@
|
||||
|
||||
public enum LogLevel
|
||||
{
|
||||
Fatal,
|
||||
Error,
|
||||
Warn,
|
||||
Success,
|
||||
Info,
|
||||
Custom,
|
||||
Debug
|
||||
Debug,
|
||||
Trace
|
||||
}
|
||||
|
||||
// TODO: needs to be moved to enums namespace
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using Core.Models.Logging;
|
||||
using LogLevel = Core.Models.Spt.Logging.LogLevel;
|
||||
|
||||
namespace Core.Models.Utils;
|
||||
|
||||
@@ -14,4 +15,5 @@ public interface ISptLogger<T>
|
||||
void Debug(string data, Exception? ex = null);
|
||||
void Critical(string data, Exception? ex = null);
|
||||
void WriteToLogFile(string body);
|
||||
bool IsLogEnabled(LogLevel level);
|
||||
}
|
||||
|
||||
@@ -11,9 +11,9 @@ public class BotGenerationCacheService(
|
||||
LocalisationService _localisationService
|
||||
)
|
||||
{
|
||||
protected Dictionary<string, List<BotBase>> _storedBots = new Dictionary<string, List<BotBase>>();
|
||||
protected Dictionary<string, List<BotBase>> _storedBots = new();
|
||||
protected Queue<BotBase> _activeBotsInRaid = [];
|
||||
protected Lock _lock = new Lock();
|
||||
protected object _lock = new();
|
||||
|
||||
|
||||
/**
|
||||
@@ -108,16 +108,25 @@ public class BotGenerationCacheService(
|
||||
*/
|
||||
public bool CacheHasBotWithKey(string key, int size = 0)
|
||||
{
|
||||
return _storedBots.ContainsKey(key) && _storedBots[key].Count > size;
|
||||
lock (_lock)
|
||||
{
|
||||
return _storedBots.ContainsKey(key) && _storedBots[key].Count > size;
|
||||
}
|
||||
}
|
||||
|
||||
public int GetCachedBotCount(string key)
|
||||
{
|
||||
return _storedBots.TryGetValue(key, out var bot) ? bot.Count : 0;
|
||||
lock (_lock)
|
||||
{
|
||||
return _storedBots.TryGetValue(key, out var bot) ? bot.Count : 0;
|
||||
}
|
||||
}
|
||||
|
||||
public string CreateCacheKey(string? role, string? difficulty)
|
||||
{
|
||||
return $"{role?.ToLower()}{difficulty?.ToLower()}";
|
||||
lock (_lock)
|
||||
{
|
||||
return $"{role?.ToLower()}{difficulty?.ToLower()}";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,29 +10,42 @@ namespace Core.Utils;
|
||||
public class RagfairOfferHolder(
|
||||
RagfairServerHelper ragfairServerHelper,
|
||||
ProfileHelper profileHelper,
|
||||
HashUtil hashUtil,
|
||||
ConfigServer configServer)
|
||||
{
|
||||
|
||||
protected Dictionary<string, RagfairOffer> _offersById = new();
|
||||
protected object _offersByIdLock = new();
|
||||
protected Dictionary<string, Dictionary<string, RagfairOffer>> _offersByTemplate = new();
|
||||
protected object _offersByTemplateLock = new();
|
||||
protected Dictionary<string, Dictionary<string, RagfairOffer>> _offersByTrader = new();
|
||||
protected object _offersByTraderLock = new();
|
||||
protected int _maxOffersPerTemplate = (int) configServer.GetConfig<RagfairConfig>().Dynamic.OfferItemCount.Max;
|
||||
|
||||
public RagfairOffer? GetOfferById(string id)
|
||||
{
|
||||
return _offersById.GetValueOrDefault(id);
|
||||
lock (_offersByIdLock)
|
||||
{
|
||||
return _offersById.GetValueOrDefault(id);
|
||||
}
|
||||
}
|
||||
|
||||
public List<RagfairOffer>? GetOffersByTemplate(string templateId)
|
||||
{
|
||||
return _offersByTemplate.TryGetValue(templateId, out var value) ? value.Values.ToList() : null;
|
||||
lock (_offersByTemplateLock)
|
||||
{
|
||||
return _offersByTemplate.TryGetValue(templateId, out var value) ? value.Values.ToList() : null;
|
||||
}
|
||||
}
|
||||
|
||||
public List<RagfairOffer> GetOffersByTrader(string traderId)
|
||||
{
|
||||
if (_offersByTrader.ContainsKey(traderId))
|
||||
lock (_offersByTraderLock)
|
||||
{
|
||||
return _offersByTrader[traderId].Values.ToList();
|
||||
if (_offersByTrader.ContainsKey(traderId))
|
||||
{
|
||||
return _offersByTrader[traderId].Values.ToList();
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
@@ -40,9 +53,12 @@ public class RagfairOfferHolder(
|
||||
|
||||
public List<RagfairOffer> GetOffers()
|
||||
{
|
||||
if (_offersById.Count > 0)
|
||||
lock (_offersByIdLock)
|
||||
{
|
||||
return _offersById.Values.ToList();
|
||||
if (_offersById.Count > 0)
|
||||
{
|
||||
return _offersById.Values.ToList();
|
||||
}
|
||||
}
|
||||
|
||||
return [];
|
||||
@@ -55,22 +71,28 @@ public class RagfairOfferHolder(
|
||||
|
||||
public void AddOffer(RagfairOffer offer)
|
||||
{
|
||||
var trader = offer.User.Id;
|
||||
var offerId = offer.Id;
|
||||
var itemTpl = offer.Items.FirstOrDefault().Template;
|
||||
// If its an NPC PMC offer AND we have already reached the maximum amount of possible offers
|
||||
// for this template, just dont add in more
|
||||
if (
|
||||
!(ragfairServerHelper.IsTrader(trader) || profileHelper.IsPlayer(trader)) &&
|
||||
(GetOffersByTemplate(itemTpl)?.Count ?? 0) >= _maxOffersPerTemplate
|
||||
)
|
||||
lock (_offersByIdLock)
|
||||
{
|
||||
return;
|
||||
var trader = offer.User.Id;
|
||||
// keep generating IDs until we get a new one
|
||||
while (_offersById.ContainsKey(offer.Id))
|
||||
offer.Id = hashUtil.Generate();
|
||||
|
||||
var offerId = offer.Id;
|
||||
var itemTpl = offer.Items.FirstOrDefault().Template;
|
||||
// If its an NPC PMC offer AND we have already reached the maximum amount of possible offers
|
||||
// for this template, just dont add in more
|
||||
if (!(ragfairServerHelper.IsTrader(trader) || profileHelper.IsPlayer(trader)) &&
|
||||
(GetOffersByTemplate(itemTpl)?.Count ?? 0) >= _maxOffersPerTemplate
|
||||
)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_offersById.Add(offerId, offer);
|
||||
AddOfferByTrader(trader, offer);
|
||||
AddOfferByTemplates(itemTpl, offer);
|
||||
}
|
||||
|
||||
_offersById.Add(offerId, offer);
|
||||
AddOfferByTrader(trader, offer);
|
||||
AddOfferByTemplates(itemTpl, offer);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -79,25 +101,34 @@ public class RagfairOfferHolder(
|
||||
*/
|
||||
public void RemoveOffer(RagfairOffer offer)
|
||||
{
|
||||
if (_offersById.ContainsKey(offer.Id))
|
||||
lock (_offersByIdLock)
|
||||
{
|
||||
_offersById.Remove(offer.Id);
|
||||
if (_offersByTrader.ContainsKey(offer.User.Id))
|
||||
if (_offersById.ContainsKey(offer.Id))
|
||||
{
|
||||
_offersByTrader[offer.User.Id].Remove(offer.Id);
|
||||
// This was causing a memory leak, we need to make sure that we remove
|
||||
// the user ID from the cached offers after they dont have anything else
|
||||
// on the flea placed. We regenerate the ID for the NPC users, making it
|
||||
// continuously grow otherwise
|
||||
if (_offersByTrader[offer.User.Id].Count == 0)
|
||||
_offersById.Remove(offer.Id);
|
||||
lock (_offersByTraderLock)
|
||||
{
|
||||
_offersByTrader.Remove(offer.User.Id);
|
||||
if (_offersByTrader.ContainsKey(offer.User.Id))
|
||||
{
|
||||
_offersByTrader[offer.User.Id].Remove(offer.Id);
|
||||
// This was causing a memory leak, we need to make sure that we remove
|
||||
// the user ID from the cached offers after they dont have anything else
|
||||
// on the flea placed. We regenerate the ID for the NPC users, making it
|
||||
// continuously grow otherwise
|
||||
if (_offersByTrader[offer.User.Id].Count == 0)
|
||||
{
|
||||
_offersByTrader.Remove(offer.User.Id);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (_offersByTemplate.ContainsKey(offer.Items.FirstOrDefault().Template))
|
||||
{
|
||||
_offersByTemplate[offer.Items[0].Template].Remove(offer.Id);
|
||||
lock (_offersByTemplateLock)
|
||||
{
|
||||
if (_offersByTemplate.ContainsKey(offer.Items.FirstOrDefault().Template))
|
||||
{
|
||||
_offersByTemplate[offer.Items[0].Template].Remove(offer.Id);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -109,9 +140,12 @@ public class RagfairOfferHolder(
|
||||
|
||||
public void RemoveAllOffersByTrader(string traderId)
|
||||
{
|
||||
if (_offersByTrader.ContainsKey(traderId))
|
||||
lock (_offersByTraderLock)
|
||||
{
|
||||
RemoveOffers(_offersByTrader[traderId].Values.ToList());
|
||||
if (_offersByTrader.ContainsKey(traderId))
|
||||
{
|
||||
RemoveOffers(_offersByTrader[traderId].Values.ToList());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -126,28 +160,34 @@ public class RagfairOfferHolder(
|
||||
|
||||
protected void AddOfferByTemplates(string template, RagfairOffer offer)
|
||||
{
|
||||
if (_offersByTemplate.ContainsKey(template))
|
||||
lock (_offersByTemplateLock)
|
||||
{
|
||||
_offersByTemplate[template].Add(offer.Id, offer);
|
||||
}
|
||||
else
|
||||
{
|
||||
var valueMapped = new Dictionary<string, RagfairOffer>();
|
||||
valueMapped.Add(offer.Id, offer);
|
||||
_offersByTemplate.Add(template, valueMapped);
|
||||
if (_offersByTemplate.ContainsKey(template))
|
||||
{
|
||||
_offersByTemplate[template].Add(offer.Id, offer);
|
||||
}
|
||||
else
|
||||
{
|
||||
var valueMapped = new Dictionary<string, RagfairOffer>();
|
||||
valueMapped.Add(offer.Id, offer);
|
||||
_offersByTemplate.Add(template, valueMapped);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void AddOfferByTrader(string trader, RagfairOffer offer)
|
||||
{
|
||||
if (_offersByTrader.ContainsKey(trader))
|
||||
lock (_offersByTraderLock)
|
||||
{
|
||||
_offersByTrader[trader].Add(offer.Id, offer);
|
||||
}
|
||||
else
|
||||
{
|
||||
var valueMapped = new Dictionary<string, RagfairOffer> { { offer.Id, offer } };
|
||||
_offersByTrader.Add(trader, valueMapped);
|
||||
if (_offersByTrader.ContainsKey(trader))
|
||||
{
|
||||
_offersByTrader[trader].Add(offer.Id, offer);
|
||||
}
|
||||
else
|
||||
{
|
||||
var valueMapped = new Dictionary<string, RagfairOffer> { { offer.Id, offer } };
|
||||
_offersByTrader.Add(trader, valueMapped);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ using SptCommon.Annotations;
|
||||
using Core.Models.Eft.ItemEvent;
|
||||
using Core.Models.Logging;
|
||||
using Core.Models.Utils;
|
||||
using LogLevel = Core.Models.Spt.Logging.LogLevel;
|
||||
|
||||
namespace Server.Logger;
|
||||
|
||||
@@ -88,4 +89,25 @@ public class SptWebApplicationLogger<T> : ISptLogger<T>
|
||||
//TODO - implement + turn object into json
|
||||
_logger.LogError("NOT IMPLEMENTED - WriteToLogFile");
|
||||
}
|
||||
|
||||
public bool IsLogEnabled(LogLevel level)
|
||||
{
|
||||
return _logger.IsEnabled(ConvertLogLevel(level));
|
||||
}
|
||||
|
||||
protected Microsoft.Extensions.Logging.LogLevel ConvertLogLevel(LogLevel level)
|
||||
{
|
||||
return level switch
|
||||
{
|
||||
LogLevel.Trace => Microsoft.Extensions.Logging.LogLevel.Trace,
|
||||
LogLevel.Debug => Microsoft.Extensions.Logging.LogLevel.Debug,
|
||||
LogLevel.Success
|
||||
or LogLevel.Info
|
||||
or LogLevel.Custom => Microsoft.Extensions.Logging.LogLevel.Information,
|
||||
LogLevel.Warn => Microsoft.Extensions.Logging.LogLevel.Warning,
|
||||
LogLevel.Error => Microsoft.Extensions.Logging.LogLevel.Error,
|
||||
LogLevel.Fatal => Microsoft.Extensions.Logging.LogLevel.Critical,
|
||||
_ => throw new ArgumentOutOfRangeException(nameof(level), level, null)
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using Core.Models.Logging;
|
||||
using Core.Models.Spt.Logging;
|
||||
using Core.Models.Utils;
|
||||
using SptCommon.Annotations;
|
||||
|
||||
@@ -53,4 +54,9 @@ public class SptBasicLogger<T> : ISptLogger<T>
|
||||
{
|
||||
Console.WriteLine($"{categoryName}: {body}");
|
||||
}
|
||||
|
||||
public bool IsLogEnabled(LogLevel level)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using Core.Models.Logging;
|
||||
using Core.Models.Spt.Logging;
|
||||
using Core.Models.Utils;
|
||||
|
||||
namespace UnitTests.Mock;
|
||||
@@ -55,6 +56,11 @@ public class MockLogger<T> : ISptLogger<T>
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public bool IsLogEnabled(LogLevel level)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public void WriteToLogFile(object body)
|
||||
{
|
||||
Console.WriteLine(body);
|
||||
|
||||
Reference in New Issue
Block a user