From a4f8036d09d0e11121980b15275d470ff8950063 Mon Sep 17 00:00:00 2001 From: CWX Date: Wed, 5 Feb 2025 07:36:13 +0000 Subject: [PATCH] formatting, fix build error --- ExampleMods/Mods/EditConfigs.cs | 10 +- Libraries/Core/Callbacks/DialogueCallbacks.cs | 22 ++--- Libraries/Core/Callbacks/HideoutCallbacks.cs | 32 +++---- .../Core/Callbacks/InsuranceCallbacks.cs | 30 +++--- Libraries/Core/Callbacks/SaveCallbacks.cs | 10 +- Libraries/Core/Callbacks/TraderCallbacks.cs | 10 +- Libraries/Core/Controllers/GameController.cs | 6 +- .../Core/Controllers/HideoutController.cs | 3 +- .../Core/Controllers/InRaidController.cs | 2 +- .../Core/Controllers/PrestigeController.cs | 14 ++- .../Core/Controllers/RagfairController.cs | 56 +++++------ Libraries/Core/DI/Router.cs | 2 +- .../Core/Generators/BotWeaponGenerator.cs | 4 +- Libraries/Core/Generators/LootGenerator.cs | 12 +-- Libraries/Core/Generators/PMCLootGenerator.cs | 10 +- .../Core/Generators/RagfairOfferGenerator.cs | 7 +- .../Generators/RepeatableQuestGenerator.cs | 2 +- .../Generators/ScavCaseRewardGenerator.cs | 4 +- .../Generators/WeaponGen/InventoryMagGen.cs | 6 +- .../Dialogue/Commando/SptCommandoCommands.cs | 26 ++--- .../SptCommands/GiveCommand/GiveSptCommand.cs | 5 +- .../SPTFriend/Commands/HelloMessageHandler.cs | 72 +++++++------- .../Helpers/Dialogue/SptDialogueChatBot.cs | 16 ++-- Libraries/Core/Helpers/HandbookHelper.cs | 14 +-- Libraries/Core/Helpers/HideoutHelper.cs | 3 +- Libraries/Core/Helpers/InRaidHelper.cs | 2 +- Libraries/Core/Helpers/PaymentHelper.cs | 2 +- Libraries/Core/Helpers/PresetHelper.cs | 6 +- Libraries/Core/Helpers/ProfileHelper.cs | 3 +- Libraries/Core/Helpers/QuestHelper.cs | 2 +- Libraries/Core/Helpers/RagfairOfferHelper.cs | 4 +- Libraries/Core/Helpers/RagfairServerHelper.cs | 4 +- Libraries/Core/Helpers/TradeHelper.cs | 2 +- Libraries/Core/Helpers/TraderAssortHelper.cs | 2 +- Libraries/Core/Helpers/TraderHelper.cs | 4 +- .../Models/Spt/Logging/LogBackgroundColor.cs | 1 - .../Core/Models/Spt/Logging/LogTextColor.cs | 1 - .../Core/Models/Spt/Mod/NewItemDetails.cs | 12 +-- Libraries/Core/Models/Spt/Server/Locations.cs | 94 +++++++++---------- Libraries/Core/Routers/EventOutputHolder.cs | 8 +- Libraries/Core/Routers/HttpRouter.cs | 2 +- Libraries/Core/Routers/ImageRouter.cs | 2 +- Libraries/Core/Routers/ItemEventRouter.cs | 12 +-- .../CustomizationItemEventRouter.cs | 2 +- .../ItemEvents/InventoryItemEventRouter.cs | 2 +- Libraries/Core/Servers/ConfigServer.cs | 6 +- .../Core/Servers/Http/SptHttpListener.cs | 14 +-- Libraries/Core/Servers/SaveServer.cs | 7 +- .../Ws/SptWebSocketConnectionHandler.cs | 51 +++++----- Libraries/Core/Services/BackupService.cs | 12 +-- .../Services/BotEquipmentFilterService.cs | 7 +- .../Services/BotEquipmentModPoolService.cs | 19 ++-- .../Services/BotGenerationCacheService.cs | 2 +- .../Core/Services/BotLootCacheService.cs | 2 +- Libraries/Core/Services/BotNameService.cs | 2 +- .../Services/Cache/BundleHashCacheService.cs | 2 +- .../Services/Cache/ModHashCacheService.cs | 2 +- .../Core/Services/CircleOfCultistService.cs | 2 +- Libraries/Core/Services/FenceService.cs | 17 ++-- Libraries/Core/Services/I18nService.cs | 8 +- Libraries/Core/Services/ItemFilterService.cs | 2 +- .../Core/Services/LocalisationService.cs | 8 +- .../Core/Services/LocationLifecycleService.cs | 48 +++++----- .../Core/Services/PmcChatResponseService.cs | 2 +- Libraries/Core/Services/PostDbLoadService.cs | 6 +- .../Core/Services/ProfileFixerService.cs | 3 +- .../Core/Services/RagfairOfferService.cs | 4 +- .../Core/Services/RagfairPriceService.cs | 2 +- .../Core/Services/SeasonalEventService.cs | 17 ++-- Libraries/Core/Utils/App.cs | 22 ++--- .../Utils/Collections/ExhaustableArray.cs | 4 +- .../Collections/ProbabilityObjectArray.cs | 2 +- Libraries/Core/Utils/DatabaseImporter.cs | 56 +++++------ Libraries/Core/Utils/HashUtil.cs | 3 +- Libraries/Core/Utils/HttpResponseUtil.cs | 20 ++-- Libraries/Core/Utils/ImporterUtil.cs | 2 +- Libraries/Core/Utils/Json/LazyLoad.cs | 4 +- Libraries/Core/Utils/ProgressWriter.cs | 6 +- Libraries/Core/Utils/RagfairOfferHolder.cs | 2 +- Libraries/Core/Utils/RandomUtil.cs | 5 +- Libraries/Core/Utils/Watermark.cs | 12 +-- .../DependencyInjectionRegistrator.cs | 6 +- Server/Logger/AbstractFormatter.cs | 14 +-- Server/Logger/ConsoleFormatter.cs | 4 +- Server/Logger/FileFormatter.cs | 4 +- Server/Logger/WebApplicationLogger.cs | 36 +++---- Tools/ItemTplGenerator/ItemTplGenerator.cs | 4 +- UnitTests/Mock/MockLogger.cs | 20 ++-- 88 files changed, 514 insertions(+), 502 deletions(-) diff --git a/ExampleMods/Mods/EditConfigs.cs b/ExampleMods/Mods/EditConfigs.cs index ab19297e..0dea17d9 100644 --- a/ExampleMods/Mods/EditConfigs.cs +++ b/ExampleMods/Mods/EditConfigs.cs @@ -8,14 +8,14 @@ namespace ExampleMods.Mods; [Injectable] public class EditConfigs { - private readonly AirdropConfig _airdropConfig; - private readonly BotConfig _botConfig; private readonly ConfigServer _configServer; + private readonly BotConfig _botConfig; private readonly HideoutConfig _hideoutConfig; - private readonly PmcChatResponse _pmcChatResponseConfig; - private readonly PmcConfig _pmcConfig; - private readonly QuestConfig _questConfig; private readonly WeatherConfig _weatherConfig; + private readonly AirdropConfig _airdropConfig; + private readonly PmcChatResponse _pmcChatResponseConfig; + private readonly QuestConfig _questConfig; + private readonly PmcConfig _pmcConfig; // We access configs via ConfigServer public EditConfigs( diff --git a/Libraries/Core/Callbacks/DialogueCallbacks.cs b/Libraries/Core/Callbacks/DialogueCallbacks.cs index 25c92d3f..95476264 100644 --- a/Libraries/Core/Callbacks/DialogueCallbacks.cs +++ b/Libraries/Core/Callbacks/DialogueCallbacks.cs @@ -18,17 +18,6 @@ public class DialogueCallbacks( ) : OnUpdate { - public bool OnUpdate(long timeSinceLastRun) - { - _dialogueController.Update(); - return true; - } - - public string GetRoute() - { - return "spt-dialogue"; - } - /// /// Handle client/friend/list /// @@ -326,4 +315,15 @@ public class DialogueCallbacks( { return "Not Implemented!"; // Not implemented in Node } + + public bool OnUpdate(long timeSinceLastRun) + { + _dialogueController.Update(); + return true; + } + + public string GetRoute() + { + return "spt-dialogue"; + } } diff --git a/Libraries/Core/Callbacks/HideoutCallbacks.cs b/Libraries/Core/Callbacks/HideoutCallbacks.cs index e95038c5..11e19ac3 100644 --- a/Libraries/Core/Callbacks/HideoutCallbacks.cs +++ b/Libraries/Core/Callbacks/HideoutCallbacks.cs @@ -18,22 +18,6 @@ public class HideoutCallbacks( { private readonly HideoutConfig _hideoutConfig = _configServer.GetConfig(); - public bool OnUpdate(long timeSinceLastRun) - { - if (timeSinceLastRun > _hideoutConfig.RunIntervalSeconds) - { - _hideoutController.Update(); - return true; - } - - return false; - } - - public string GetRoute() - { - return "spt-hideout"; - } - /// /// Handle HideoutUpgrade event /// @@ -178,4 +162,20 @@ public class HideoutCallbacks( { return _hideoutController.HideoutCustomizationSetMannequinPose(sessionId, pmcData, request); } + + public bool OnUpdate(long timeSinceLastRun) + { + if (timeSinceLastRun > _hideoutConfig.RunIntervalSeconds) + { + _hideoutController.Update(); + return true; + } + + return false; + } + + public string GetRoute() + { + return "spt-hideout"; + } } diff --git a/Libraries/Core/Callbacks/InsuranceCallbacks.cs b/Libraries/Core/Callbacks/InsuranceCallbacks.cs index 43643dca..300d5267 100644 --- a/Libraries/Core/Callbacks/InsuranceCallbacks.cs +++ b/Libraries/Core/Callbacks/InsuranceCallbacks.cs @@ -23,21 +23,6 @@ public class InsuranceCallbacks( { private InsuranceConfig _insuranceConfig = _configServer.GetConfig(); - public bool OnUpdate(long timeSinceLastRun) - { - if (timeSinceLastRun > Math.Max(_insuranceConfig.RunIntervalSeconds, 1)) - // _insuranceController.ProcessReturn(); - // TODO: InsuranceController is not implemented rn - return true; - - return false; - } - - public string GetRoute() - { - return "spt-insurance"; - } - /// /// Handle client/insurance/items/list/cost /// @@ -61,4 +46,19 @@ public class InsuranceCallbacks( { return _insuranceController.Insure(pmcData, info, sessionID); } + + public bool OnUpdate(long timeSinceLastRun) + { + if (timeSinceLastRun > Math.Max(_insuranceConfig.RunIntervalSeconds, 1)) + // _insuranceController.ProcessReturn(); + // TODO: InsuranceController is not implemented rn + return true; + + return false; + } + + public string GetRoute() + { + return "spt-insurance"; + } } diff --git a/Libraries/Core/Callbacks/SaveCallbacks.cs b/Libraries/Core/Callbacks/SaveCallbacks.cs index a9abd4cb..43fab8e1 100644 --- a/Libraries/Core/Callbacks/SaveCallbacks.cs +++ b/Libraries/Core/Callbacks/SaveCallbacks.cs @@ -23,11 +23,6 @@ public class SaveCallbacks( _saveServer.Load(); } - public string GetRoute() - { - return "spt-save"; - } - public bool OnUpdate(long secondsSinceLastRun) { if (secondsSinceLastRun > _coreConfig.ProfileSaveIntervalInSeconds) @@ -38,4 +33,9 @@ public class SaveCallbacks( return false; } + + public string GetRoute() + { + return "spt-save"; + } } diff --git a/Libraries/Core/Callbacks/TraderCallbacks.cs b/Libraries/Core/Callbacks/TraderCallbacks.cs index bf13014c..8379df49 100644 --- a/Libraries/Core/Callbacks/TraderCallbacks.cs +++ b/Libraries/Core/Callbacks/TraderCallbacks.cs @@ -25,16 +25,16 @@ public class TraderCallbacks( return Task.CompletedTask; } - public string GetRoute() - { - return "spt-traders"; - } - public bool OnUpdate(long _) { return _traderController.Update(); } + public string GetRoute() + { + return "spt-traders"; + } + /// /// Handle client/trading/api/traderSettings /// diff --git a/Libraries/Core/Controllers/GameController.cs b/Libraries/Core/Controllers/GameController.cs index 60eece65..b9784d78 100644 --- a/Libraries/Core/Controllers/GameController.cs +++ b/Libraries/Core/Controllers/GameController.cs @@ -44,12 +44,12 @@ public class GameController( ICloner _cloner ) { - protected BotConfig _botConfig = _configServer.GetConfig(); protected CoreConfig _coreConfig = _configServer.GetConfig(); - protected double _deviation = 0.0001; - protected HideoutConfig _hideoutConfig = _configServer.GetConfig(); protected HttpConfig _httpConfig = _configServer.GetConfig(); protected RagfairConfig _ragfairConfig = _configServer.GetConfig(); + protected HideoutConfig _hideoutConfig = _configServer.GetConfig(); + protected BotConfig _botConfig = _configServer.GetConfig(); + protected double _deviation = 0.0001; /// /// Handle client/game/start diff --git a/Libraries/Core/Controllers/HideoutController.cs b/Libraries/Core/Controllers/HideoutController.cs index a9b08277..9819d6a6 100644 --- a/Libraries/Core/Controllers/HideoutController.cs +++ b/Libraries/Core/Controllers/HideoutController.cs @@ -46,6 +46,7 @@ public class HideoutController( ConfigServer _configServer ) { + protected HideoutConfig _hideoutConfig = _configServer.GetConfig(); public const string NameTaskConditionCountersCraftingId = "673f5d6fdd6ed700c703afdc"; protected List _hideoutAreas = @@ -56,8 +57,6 @@ public class HideoutController( HideoutAreas.BITCOIN_FARM ]; - protected HideoutConfig _hideoutConfig = _configServer.GetConfig(); - public void StartUpgrade(PmcData pmcData, HideoutUpgradeRequestData request, string sessionID, ItemEventRouterResponse output) { var items = request.Items.Select( diff --git a/Libraries/Core/Controllers/InRaidController.cs b/Libraries/Core/Controllers/InRaidController.cs index 4260352d..6642dd54 100644 --- a/Libraries/Core/Controllers/InRaidController.cs +++ b/Libraries/Core/Controllers/InRaidController.cs @@ -16,8 +16,8 @@ public class InRaidController( ConfigServer _configServer ) { - protected BotConfig _botConfig = _configServer.GetConfig(); protected InRaidConfig _inRaidConfig = _configServer.GetConfig(); + protected BotConfig _botConfig = _configServer.GetConfig(); /// /// Save locationId to active profiles in-raid object AND app context diff --git a/Libraries/Core/Controllers/PrestigeController.cs b/Libraries/Core/Controllers/PrestigeController.cs index 0ade8e3a..d2b094a7 100644 --- a/Libraries/Core/Controllers/PrestigeController.cs +++ b/Libraries/Core/Controllers/PrestigeController.cs @@ -71,9 +71,19 @@ public class PrestigeController( // hideout progress // going to prestige 2 - // most likely the same, but wait for dump of new beginnings quest - + // 10% of skills should be transfered over + // 10% of mastering should be transfered over + // earned achievements should be transfered over + // profile stats should be transfered over + // prestige progress should be transfered over + // reset + // trader standing + // task progress + // character level + // stash + // hideout progress + // Clone existing profile, create a new one var prePrestigeProfileClone = _cloner.Clone(_profileHelper.GetFullProfile(sessionId)); var prePrestigePmc = prePrestigeProfileClone.CharacterData.PmcData; diff --git a/Libraries/Core/Controllers/RagfairController.cs b/Libraries/Core/Controllers/RagfairController.cs index 66e323e4..84898738 100644 --- a/Libraries/Core/Controllers/RagfairController.cs +++ b/Libraries/Core/Controllers/RagfairController.cs @@ -25,32 +25,32 @@ namespace Core.Controllers; [Injectable] public class RagfairController { - private readonly ConfigServer _configServer; - private readonly DatabaseService _databaseService; - private readonly EventOutputHolder _eventOutputHolder; - private readonly HandbookHelper _handbookHelper; - private readonly HttpResponseUtil _httpResponseUtil; - private readonly InventoryHelper _inventoryHelper; - private readonly ItemHelper _itemHelper; - private readonly JsonUtil _jsonUtil; - private readonly LocalisationService _localisationService; private readonly ISptLogger _logger; - private readonly PaymentHelper _paymentHelper; - private readonly PaymentService _paymentService; + private readonly TimeUtil _timeUtil; + private readonly JsonUtil _jsonUtil; + private readonly HttpResponseUtil _httpResponseUtil; + private readonly EventOutputHolder _eventOutputHolder; + private readonly RagfairServer _ragfairServer; + private readonly ItemHelper _itemHelper; + private readonly InventoryHelper _inventoryHelper; + private readonly RagfairSellHelper _ragfairSellHelper; + private readonly HandbookHelper _handbookHelper; private readonly ProfileHelper _profileHelper; + private readonly PaymentHelper _paymentHelper; + private readonly RagfairHelper _ragfairHelper; + private readonly RagfairSortHelper _ragfairSortHelper; + private readonly RagfairOfferHelper _ragfairOfferHelper; + private readonly TraderHelper _traderHelper; + private readonly DatabaseService _databaseService; + private readonly LocalisationService _localisationService; + private readonly RagfairTaxService _ragfairTaxService; + private readonly RagfairOfferService _ragfairOfferService; + private readonly PaymentService _paymentService; + private readonly RagfairPriceService _ragfairPriceService; + private readonly RagfairOfferGenerator _ragfairOfferGenerator; + private readonly ConfigServer _configServer; private readonly RagfairConfig _ragfairConfig; - private readonly RagfairHelper _ragfairHelper; - private readonly RagfairOfferGenerator _ragfairOfferGenerator; - private readonly RagfairOfferHelper _ragfairOfferHelper; - private readonly RagfairOfferService _ragfairOfferService; - private readonly RagfairPriceService _ragfairPriceService; - private readonly RagfairSellHelper _ragfairSellHelper; - private readonly RagfairServer _ragfairServer; - private readonly RagfairSortHelper _ragfairSortHelper; - private readonly RagfairTaxService _ragfairTaxService; - private readonly TimeUtil _timeUtil; - private readonly TraderHelper _traderHelper; public RagfairController( ISptLogger logger, @@ -879,6 +879,12 @@ public class RagfairController return new GetItemsToListOnFleaFromInventoryResult { Items = itemsToReturn, ErrorMessage = errorMessage }; } + public record GetItemsToListOnFleaFromInventoryResult + { + public List>? Items { get; set; } + public string? ErrorMessage { get; set; } + } + public ItemEventRouterResponse RemoveOffer(RemoveOfferRequestData removeRequest, string sessionId) { var output = _eventOutputHolder.GetOutput(sessionId); @@ -1022,10 +1028,4 @@ public class RagfairController return offerToReturn; } - - public record GetItemsToListOnFleaFromInventoryResult - { - public List>? Items { get; set; } - public string? ErrorMessage { get; set; } - } } diff --git a/Libraries/Core/DI/Router.cs b/Libraries/Core/DI/Router.cs index 83598e9b..8f0eecf3 100644 --- a/Libraries/Core/DI/Router.cs +++ b/Libraries/Core/DI/Router.cs @@ -66,8 +66,8 @@ public abstract class StaticRouter : Router public abstract class DynamicRouter : Router { - private readonly JsonUtil _jsonUtil; private readonly List actions; + private readonly JsonUtil _jsonUtil; public DynamicRouter(JsonUtil jsonUtil, List routes) : base() { diff --git a/Libraries/Core/Generators/BotWeaponGenerator.cs b/Libraries/Core/Generators/BotWeaponGenerator.cs index 6e3a5fbf..df3fb936 100644 --- a/Libraries/Core/Generators/BotWeaponGenerator.cs +++ b/Libraries/Core/Generators/BotWeaponGenerator.cs @@ -34,11 +34,11 @@ public class BotWeaponGenerator( IEnumerable inventoryMagGenComponents ) { - protected const string _modMagazineSlotId = "mod_magazine"; - protected BotConfig _botConfig = _configServer.GetConfig(); protected IEnumerable _inventoryMagGenComponents = MagGenSetUp(inventoryMagGenComponents); + protected BotConfig _botConfig = _configServer.GetConfig(); protected PmcConfig _pmcConfig = _configServer.GetConfig(); protected RepairConfig _repairConfig = _configServer.GetConfig(); + protected const string _modMagazineSlotId = "mod_magazine"; private static List MagGenSetUp(IEnumerable components) { diff --git a/Libraries/Core/Generators/LootGenerator.cs b/Libraries/Core/Generators/LootGenerator.cs index c41771a4..1bd38fe9 100644 --- a/Libraries/Core/Generators/LootGenerator.cs +++ b/Libraries/Core/Generators/LootGenerator.cs @@ -241,6 +241,12 @@ public class LootGenerator( return new ItemRewardPoolResults { ItemPool = items, Blacklist = itemBlacklist }; } + public record ItemRewardPoolResults + { + public List ItemPool { get; set; } + public HashSet Blacklist { get; set; } + } + /// /// Filter armor items by their front plates protection level - top if it's a helmet /// @@ -648,12 +654,6 @@ public class LootGenerator( ) ); } - - public record ItemRewardPoolResults - { - public List ItemPool { get; set; } - public HashSet Blacklist { get; set; } - } } public class ItemLimit diff --git a/Libraries/Core/Generators/PMCLootGenerator.cs b/Libraries/Core/Generators/PMCLootGenerator.cs index f3cd3457..61c1aa2a 100644 --- a/Libraries/Core/Generators/PMCLootGenerator.cs +++ b/Libraries/Core/Generators/PMCLootGenerator.cs @@ -12,19 +12,19 @@ namespace Core.Generators; [Injectable] public class PMCLootGenerator { - private readonly ConfigServer _configServer; - private readonly DatabaseService _databaseService; - private readonly ItemFilterService _itemFilterService; - private readonly ItemHelper _itemHelper; private readonly ISptLogger _logger; - private readonly PmcConfig _pmcConfig; + private readonly DatabaseService _databaseService; + private readonly ItemHelper _itemHelper; + private readonly ItemFilterService _itemFilterService; private readonly RagfairPriceService _ragfairPriceService; private readonly SeasonalEventService _seasonalEventService; private readonly WeightedRandomHelper _weightedRandomHelper; + private readonly ConfigServer _configServer; private Dictionary? _backpackLootPool; private Dictionary? _pocketLootPool; private Dictionary? _vestLootPool; + private readonly PmcConfig _pmcConfig; public PMCLootGenerator( ISptLogger logger, diff --git a/Libraries/Core/Generators/RagfairOfferGenerator.cs b/Libraries/Core/Generators/RagfairOfferGenerator.cs index a40b37c5..94619ed0 100644 --- a/Libraries/Core/Generators/RagfairOfferGenerator.cs +++ b/Libraries/Core/Generators/RagfairOfferGenerator.cs @@ -43,15 +43,14 @@ public class RagfairOfferGenerator( ICloner cloner ) { - protected List? allowedFleaPriceItemsForBarter; + protected RagfairConfig ragfairConfig = configServer.GetConfig(); + protected TraderConfig traderConfig = configServer.GetConfig(); protected BotConfig botConfig = configServer.GetConfig(); + protected List? allowedFleaPriceItemsForBarter; /** Internal counter to ensure each offer created has a unique value for its intId property */ protected int offerCounter = 0; - protected RagfairConfig ragfairConfig = configServer.GetConfig(); - protected TraderConfig traderConfig = configServer.GetConfig(); - /** * Create a flea offer and store it in the Ragfair server offers array * @param userID Owner of the offer diff --git a/Libraries/Core/Generators/RepeatableQuestGenerator.cs b/Libraries/Core/Generators/RepeatableQuestGenerator.cs index 11c60e24..d55591f9 100644 --- a/Libraries/Core/Generators/RepeatableQuestGenerator.cs +++ b/Libraries/Core/Generators/RepeatableQuestGenerator.cs @@ -31,8 +31,8 @@ public class RepeatableQuestGenerator( ICloner _cloner ) { - protected int _maxRandomNumberAttempts = 6; protected QuestConfig _questConfig = _configServer.GetConfig(); + protected int _maxRandomNumberAttempts = 6; /// /// This method is called by /GetClientRepeatableQuests/ and creates one element of quest type format (see diff --git a/Libraries/Core/Generators/ScavCaseRewardGenerator.cs b/Libraries/Core/Generators/ScavCaseRewardGenerator.cs index 9f956eb8..368072a5 100644 --- a/Libraries/Core/Generators/ScavCaseRewardGenerator.cs +++ b/Libraries/Core/Generators/ScavCaseRewardGenerator.cs @@ -31,9 +31,9 @@ public class ScavCaseRewardGenerator( ICloner _cloner ) { - protected List _dbAmmoItemsCache = []; - protected List _dbItemsCache = []; protected ScavCaseConfig _scavCaseConfig = _configServer.GetConfig(); + protected List _dbItemsCache = []; + protected List _dbAmmoItemsCache = []; /// /// Create an array of rewards that will be given to the player upon completing their scav case build diff --git a/Libraries/Core/Generators/WeaponGen/InventoryMagGen.cs b/Libraries/Core/Generators/WeaponGen/InventoryMagGen.cs index 7b4ea227..00c3a1b6 100644 --- a/Libraries/Core/Generators/WeaponGen/InventoryMagGen.cs +++ b/Libraries/Core/Generators/WeaponGen/InventoryMagGen.cs @@ -6,11 +6,11 @@ namespace Core.Generators.WeaponGen; [Injectable] public class InventoryMagGen() { - private TemplateItem _ammoTemplate; - private TemplateItem _magazineTemplate; private GenerationData _magCounts; - private BotBaseInventory _pmcInventory; + private TemplateItem _magazineTemplate; private TemplateItem _weaponTemplate; + private TemplateItem _ammoTemplate; + private BotBaseInventory _pmcInventory; public InventoryMagGen ( diff --git a/Libraries/Core/Helpers/Dialogue/Commando/SptCommandoCommands.cs b/Libraries/Core/Helpers/Dialogue/Commando/SptCommandoCommands.cs index 828b22a8..79ae38a5 100644 --- a/Libraries/Core/Helpers/Dialogue/Commando/SptCommandoCommands.cs +++ b/Libraries/Core/Helpers/Dialogue/Commando/SptCommandoCommands.cs @@ -11,8 +11,8 @@ namespace Core.Helpers.Dialog.Commando; [Injectable] public class SptCommandoCommands : IChatCommand { - protected LocalisationService _localisationService; protected List _sptCommands; + protected LocalisationService _localisationService; public SptCommandoCommands( ConfigServer configServer, @@ -32,6 +32,18 @@ public class SptCommandoCommands : IChatCommand } } + public void RegisterSptCommandoCommand(ISptCommand command) + { + if (_sptCommands.Any((c) => c.GetCommand() == command.GetCommand())) + throw new Exception( + _localisationService.GetText( + "chat-unable_to_register_command_already_registered", + command.GetCommand() + ) + ); + _sptCommands.Add(command); + } + public string GetCommandPrefix() { return "spt"; @@ -53,16 +65,4 @@ public class SptCommandoCommands : IChatCommand .First((c) => c.GetCommand() == command) .PerformAction(commandHandler, sessionId, request); } - - public void RegisterSptCommandoCommand(ISptCommand command) - { - if (_sptCommands.Any((c) => c.GetCommand() == command.GetCommand())) - throw new Exception( - _localisationService.GetText( - "chat-unable_to_register_command_already_registered", - command.GetCommand() - ) - ); - _sptCommands.Add(command); - } } diff --git a/Libraries/Core/Helpers/Dialogue/Commando/SptCommands/GiveCommand/GiveSptCommand.cs b/Libraries/Core/Helpers/Dialogue/Commando/SptCommands/GiveCommand/GiveSptCommand.cs index 2df4e53e..f96b0b0f 100644 --- a/Libraries/Core/Helpers/Dialogue/Commando/SptCommands/GiveCommand/GiveSptCommand.cs +++ b/Libraries/Core/Helpers/Dialogue/Commando/SptCommands/GiveCommand/GiveSptCommand.cs @@ -25,8 +25,9 @@ public class GiveSptCommand( ICloner _cloner ) : ISptCommand { - private const double _acceptableConfidence = 0.9d; + protected Dictionary _savedCommand = new(); private static readonly Regex _commandRegex = new(@"^spt give (((([a-z]{2,5}) )?""(.+)""|\w+) )?([0-9]+)$"); + private const double _acceptableConfidence = 0.9d; // Exception for flares protected readonly HashSet _excludedPresetItems = @@ -36,8 +37,6 @@ public class GiveSptCommand( ItemTpl.FLARE_RSP30_REACTIVE_SIGNAL_CARTRIDGE_YELLOW ]; - protected Dictionary _savedCommand = new(); - public string GetCommand() { return "give"; diff --git a/Libraries/Core/Helpers/Dialogue/SPTFriend/Commands/HelloMessageHandler.cs b/Libraries/Core/Helpers/Dialogue/SPTFriend/Commands/HelloMessageHandler.cs index c36865ff..b764414c 100644 --- a/Libraries/Core/Helpers/Dialogue/SPTFriend/Commands/HelloMessageHandler.cs +++ b/Libraries/Core/Helpers/Dialogue/SPTFriend/Commands/HelloMessageHandler.cs @@ -16,42 +16,6 @@ public class HelloMessageHandler( protected List _listOfMessages = ["hello", "hi", "sup", "yo", "hey", "bonjour"]; - public int GetPriority() - { - return 100; - } - - public bool CanHandle(string message) - { - return _listOfMessages.Contains(message, StringComparer.OrdinalIgnoreCase); - } - - public void Process(string sessionId, UserDialogInfo sptFriendUser, PmcData sender) - { - _mailSendService.SendUserMessageToPlayer( - sessionId, - sptFriendUser, - _randomUtil.GetArrayValue( - [ - "Howdy", - "Hi", - "Greetings", - "Hello", - "Bonjor", - "Yo", - "Sup", - "Heyyyyy", - "Hey there", - "OH its you", - $"Hello {sender?.Info?.Nickname}" - ] - ), - [], - null - ); - } - - public string GetCommand() { return "hello"; @@ -92,4 +56,40 @@ public class HelloMessageHandler( return request.DialogId; } + + + public int GetPriority() + { + return 100; + } + + public bool CanHandle(string message) + { + return _listOfMessages.Contains(message, StringComparer.OrdinalIgnoreCase); + } + + public void Process(string sessionId, UserDialogInfo sptFriendUser, PmcData sender) + { + _mailSendService.SendUserMessageToPlayer( + sessionId, + sptFriendUser, + _randomUtil.GetArrayValue( + [ + "Howdy", + "Hi", + "Greetings", + "Hello", + "Bonjor", + "Yo", + "Sup", + "Heyyyyy", + "Hey there", + "OH its you", + $"Hello {sender?.Info?.Nickname}" + ] + ), + [], + null + ); + } } diff --git a/Libraries/Core/Helpers/Dialogue/SptDialogueChatBot.cs b/Libraries/Core/Helpers/Dialogue/SptDialogueChatBot.cs index 5f83b3d9..b679ef5c 100644 --- a/Libraries/Core/Helpers/Dialogue/SptDialogueChatBot.cs +++ b/Libraries/Core/Helpers/Dialogue/SptDialogueChatBot.cs @@ -24,6 +24,14 @@ public class SptDialogueChatBot( { protected IEnumerable _chatMessageHandlers = ChatMessageHandlerSetup(chatMessageHandlers); + private static List ChatMessageHandlerSetup(IEnumerable components) + { + var chatMessageHandlers = components.ToList(); + chatMessageHandlers.Sort((a, b) => a.GetPriority() - b.GetPriority()); + + return chatMessageHandlers; + } + protected CoreConfig _coreConfig = _configServer.GetConfig(); @@ -72,14 +80,6 @@ public class SptDialogueChatBot( return request.DialogId; } - private static List ChatMessageHandlerSetup(IEnumerable components) - { - var chatMessageHandlers = components.ToList(); - chatMessageHandlers.Sort((a, b) => a.GetPriority() - b.GetPriority()); - - return chatMessageHandlers; - } - private string GetUnrecognizedCommandMessage() { return "Unknown command."; diff --git a/Libraries/Core/Helpers/HandbookHelper.cs b/Libraries/Core/Helpers/HandbookHelper.cs index 3648da4c..2e05754e 100644 --- a/Libraries/Core/Helpers/HandbookHelper.cs +++ b/Libraries/Core/Helpers/HandbookHelper.cs @@ -15,9 +15,9 @@ public class HandbookHelper( ICloner _cloner ) { - protected LookupCollection _handbookPriceCache = new(); protected ItemConfig _itemConfig = _configServer.GetConfig(); protected bool _lookupCacheGenerated = false; + protected LookupCollection _handbookPriceCache = new(); /// /// Create an in-memory cache of all items with associated handbook price in handbookPriceCache class @@ -180,24 +180,24 @@ public class HandbookHelper( public class LookupItem { + public Dictionary ById { get; set; } + public Dictionary> ByParent { get; set; } + public LookupItem() { ById = new Dictionary(); ByParent = new Dictionary>(); } - - public Dictionary ById { get; set; } - public Dictionary> ByParent { get; set; } } public class LookupCollection { + public LookupItem Items { get; set; } + public LookupItem Categories { get; set; } + public LookupCollection() { Items = new LookupItem(); Categories = new LookupItem(); } - - public LookupItem Items { get; set; } - public LookupItem Categories { get; set; } } diff --git a/Libraries/Core/Helpers/HideoutHelper.cs b/Libraries/Core/Helpers/HideoutHelper.cs index d83a308d..5062cf48 100644 --- a/Libraries/Core/Helpers/HideoutHelper.cs +++ b/Libraries/Core/Helpers/HideoutHelper.cs @@ -33,13 +33,14 @@ public class HideoutHelper( ICloner _cloner ) { + protected HideoutConfig hideoutConfig = _configServer.GetConfig(); + public const string BitcoinFarm = "5d5c205bd582a50d042a3c0e"; public const string CultistCircleCraftId = "66827062405f392b203a44cf"; public const string BitcoinProductionId = "5d5c205bd582a50d042a3c0e"; public const string WaterCollector = "5d5589c1f934db045e6c5492"; public const int MaxSkillPoint = 5000; protected List _idCheck = [BitcoinFarm, CultistCircleCraftId]; - protected HideoutConfig hideoutConfig = _configServer.GetConfig(); /// /// Add production to profiles' Hideout.Production array diff --git a/Libraries/Core/Helpers/InRaidHelper.cs b/Libraries/Core/Helpers/InRaidHelper.cs index a3aee68a..dec4e3bb 100644 --- a/Libraries/Core/Helpers/InRaidHelper.cs +++ b/Libraries/Core/Helpers/InRaidHelper.cs @@ -18,8 +18,8 @@ public class InRaidHelper( DatabaseService _databaseService ) { - protected InRaidConfig _inRaidConfig = _configServer.GetConfig(); protected LostOnDeathConfig _lostOnDeathConfig = _configServer.GetConfig(); + protected InRaidConfig _inRaidConfig = _configServer.GetConfig(); protected List _pocketSlots = ["pocket1", "pocket2", "pocket3", "pocket4"]; /// diff --git a/Libraries/Core/Helpers/PaymentHelper.cs b/Libraries/Core/Helpers/PaymentHelper.cs index 176b5dc7..c785a065 100644 --- a/Libraries/Core/Helpers/PaymentHelper.cs +++ b/Libraries/Core/Helpers/PaymentHelper.cs @@ -8,9 +8,9 @@ namespace Core.Helpers; [Injectable] public class PaymentHelper(ConfigServer _configServer) { - protected bool _addedCustomMoney; protected InventoryConfig _inventoryConfig = _configServer.GetConfig(); protected List _moneyTpls = [Money.DOLLARS, Money.EUROS, Money.ROUBLES, Money.GP]; + protected bool _addedCustomMoney; /// /// Is the passed in tpl money (also checks custom currencies in inventoryConfig.customMoneyTpls) diff --git a/Libraries/Core/Helpers/PresetHelper.cs b/Libraries/Core/Helpers/PresetHelper.cs index 5ddbb508..dda8e4f4 100644 --- a/Libraries/Core/Helpers/PresetHelper.cs +++ b/Libraries/Core/Helpers/PresetHelper.cs @@ -13,14 +13,14 @@ public class PresetHelper( ICloner _cloner ) { - protected Dictionary _defaultEquipmentPresets; - protected Dictionary? _defaultWeaponPresets; - /// /// Preset cache - key = item tpl, value = preset ids /// protected Dictionary> _lookup = new(); + protected Dictionary _defaultEquipmentPresets; + protected Dictionary? _defaultWeaponPresets; + public void HydratePresetStore(Dictionary> input) { _lookup = input; diff --git a/Libraries/Core/Helpers/ProfileHelper.cs b/Libraries/Core/Helpers/ProfileHelper.cs index 302b7f2a..662929ae 100644 --- a/Libraries/Core/Helpers/ProfileHelper.cs +++ b/Libraries/Core/Helpers/ProfileHelper.cs @@ -27,7 +27,6 @@ public class ProfileHelper( ConfigServer _configServer ) { - protected readonly List gameEditions = ["edge_of_darkness", "unheard_edition"]; protected InventoryConfig _inventoryConfig = _configServer.GetConfig(); /// @@ -558,6 +557,8 @@ public class ProfileHelper( return pmcProfile?.Info?.Bans?.Any(b => b.BanType == BanType.RAGFAIR && currentTimestamp < b.DateTime) ?? false; } + protected readonly List gameEditions = ["edge_of_darkness", "unheard_edition"]; + public bool HasAccessToRepeatableFreeRefreshSystem(PmcData pmcProfile) { return gameEditions.Contains(pmcProfile.Info.GameVersion); diff --git a/Libraries/Core/Helpers/QuestHelper.cs b/Libraries/Core/Helpers/QuestHelper.cs index 63a9754e..76398f37 100644 --- a/Libraries/Core/Helpers/QuestHelper.cs +++ b/Libraries/Core/Helpers/QuestHelper.cs @@ -38,8 +38,8 @@ public class QuestHelper( ICloner _cloner ) { - protected List _newlyQuestCheck = [QuestStatusEnum.Started, QuestStatusEnum.AvailableForFinish]; protected QuestConfig _questConfig = _configServer.GetConfig(); + protected List _newlyQuestCheck = [QuestStatusEnum.Started, QuestStatusEnum.AvailableForFinish]; /// /// Get status of a quest in player profile by its id diff --git a/Libraries/Core/Helpers/RagfairOfferHelper.cs b/Libraries/Core/Helpers/RagfairOfferHelper.cs index a2a05efa..9292f94d 100644 --- a/Libraries/Core/Helpers/RagfairOfferHelper.cs +++ b/Libraries/Core/Helpers/RagfairOfferHelper.cs @@ -42,9 +42,9 @@ public class RagfairOfferHelper( EventOutputHolder _eventOutputHolder, ConfigServer _configServer) { - protected static string _goodSoldTemplate = "5bdabfb886f7743e152e867e 0"; // Your {soldItem} {itemCount} items were bought by {buyerNickname}. - protected BotConfig _botConfig = _configServer.GetConfig(); protected RagfairConfig _ragfairConfig = _configServer.GetConfig(); + protected BotConfig _botConfig = _configServer.GetConfig(); + protected static string _goodSoldTemplate = "5bdabfb886f7743e152e867e 0"; // Your {soldItem} {itemCount} items were bought by {buyerNickname}. /// /// Passthrough to ragfairOfferService.getOffers(), get flea offers a player should see diff --git a/Libraries/Core/Helpers/RagfairServerHelper.cs b/Libraries/Core/Helpers/RagfairServerHelper.cs index 155e6daa..181bfa0c 100644 --- a/Libraries/Core/Helpers/RagfairServerHelper.cs +++ b/Libraries/Core/Helpers/RagfairServerHelper.cs @@ -28,9 +28,9 @@ public class RagfairServerHelper( ICloner cloner ) { - protected static string goodsReturnedTemplate = "5bdabfe486f7743e1665df6e 0"; // Your item was not sold - protected QuestConfig questConfig = configServer.GetConfig(); protected RagfairConfig ragfairConfig = configServer.GetConfig(); + protected QuestConfig questConfig = configServer.GetConfig(); + protected static string goodsReturnedTemplate = "5bdabfe486f7743e1665df6e 0"; // Your item was not sold /** * Is item valid / on blacklist / quest item diff --git a/Libraries/Core/Helpers/TradeHelper.cs b/Libraries/Core/Helpers/TradeHelper.cs index 1838222a..2f6ce415 100644 --- a/Libraries/Core/Helpers/TradeHelper.cs +++ b/Libraries/Core/Helpers/TradeHelper.cs @@ -36,8 +36,8 @@ public class TradeHelper( ICloner _cloner ) { - protected InventoryConfig _inventoryConfig = _configServer.GetConfig(); protected TraderConfig _traderConfig = _configServer.GetConfig(); + protected InventoryConfig _inventoryConfig = _configServer.GetConfig(); /// /// Buy item from flea or trader diff --git a/Libraries/Core/Helpers/TraderAssortHelper.cs b/Libraries/Core/Helpers/TraderAssortHelper.cs index ead2c1b0..62a8f2c4 100644 --- a/Libraries/Core/Helpers/TraderAssortHelper.cs +++ b/Libraries/Core/Helpers/TraderAssortHelper.cs @@ -32,8 +32,8 @@ public class TraderAssortHelper( ICloner _cloner ) { - protected Dictionary> _mergedQuestAssorts = new(); protected TraderConfig _traderConfig = _configServer.GetConfig(); + protected Dictionary> _mergedQuestAssorts = new(); protected bool createdMergedQuestAssorts = false; /// diff --git a/Libraries/Core/Helpers/TraderHelper.cs b/Libraries/Core/Helpers/TraderHelper.cs index 87ab5a98..95c40908 100644 --- a/Libraries/Core/Helpers/TraderHelper.cs +++ b/Libraries/Core/Helpers/TraderHelper.cs @@ -30,9 +30,9 @@ public class TraderHelper( ConfigServer _configServer ) { - protected List _gameVersions = [GameEditions.EDGE_OF_DARKNESS, GameEditions.UNHEARD]; - protected Dictionary _highestTraderPriceItems = new(); protected TraderConfig _traderConfig = _configServer.GetConfig(); + protected Dictionary _highestTraderPriceItems = new(); + protected List _gameVersions = [GameEditions.EDGE_OF_DARKNESS, GameEditions.UNHEARD]; /// diff --git a/Libraries/Core/Models/Spt/Logging/LogBackgroundColor.cs b/Libraries/Core/Models/Spt/Logging/LogBackgroundColor.cs index f45f58a4..3dbf4cbd 100644 --- a/Libraries/Core/Models/Spt/Logging/LogBackgroundColor.cs +++ b/Libraries/Core/Models/Spt/Logging/LogBackgroundColor.cs @@ -16,4 +16,3 @@ // TODO: this likely wont be used anymore, so commenting out insteaad of reimplementing - diff --git a/Libraries/Core/Models/Spt/Logging/LogTextColor.cs b/Libraries/Core/Models/Spt/Logging/LogTextColor.cs index 8b2b7d8c..b2db1494 100644 --- a/Libraries/Core/Models/Spt/Logging/LogTextColor.cs +++ b/Libraries/Core/Models/Spt/Logging/LogTextColor.cs @@ -16,4 +16,3 @@ // TODO: this likely wont be used anymore, so commenting out insteaad of reimplementing - diff --git a/Libraries/Core/Models/Spt/Mod/NewItemDetails.cs b/Libraries/Core/Models/Spt/Mod/NewItemDetails.cs index 86513ab4..d3c19b04 100644 --- a/Libraries/Core/Models/Spt/Mod/NewItemDetails.cs +++ b/Libraries/Core/Models/Spt/Mod/NewItemDetails.cs @@ -54,12 +54,6 @@ public record LocaleDetails public record CreateItemResult { - public CreateItemResult() - { - Success = false; - Errors = new List(); - } - [JsonPropertyName("success")] public bool? Success { get; set; } @@ -68,6 +62,12 @@ public record CreateItemResult [JsonPropertyName("errors")] public List? Errors { get; set; } + + public CreateItemResult() + { + Success = false; + Errors = new List(); + } } // TODO: This needs to be reworked with however we do it for this project diff --git a/Libraries/Core/Models/Spt/Server/Locations.cs b/Libraries/Core/Models/Spt/Server/Locations.cs index bf43bf24..c552a1ff 100644 --- a/Libraries/Core/Models/Spt/Server/Locations.cs +++ b/Libraries/Core/Models/Spt/Server/Locations.cs @@ -5,53 +5,6 @@ namespace Core.Models.Spt.Server; public record Locations { - private Dictionary? _locationDictionaryCache; - - // sometimes we get the key or value given so save changing logic in each place - // have it key both - private Dictionary _locationMappings = new() - { - // EFT - { "factory4_day", "Factory4Day" }, - { "bigmap", "Bigmap" }, - { "develop", "Develop" }, - { "factory4_night", "Factory4Night" }, - { "hideout", "Hideout" }, - { "interchange", "Interchange" }, - { "laboratory", "Laboratory" }, - { "lighthouse", "Lighthouse" }, - { "privatearea", "PrivateArea" }, - { "rezervbase", "RezervBase" }, - { "shoreline", "Shoreline" }, - { "suburbs", "Suburbs" }, - { "tarkovstreets", "TarkovStreets" }, - { "terminal", "Terminal" }, - { "town", "Town" }, - { "woods", "Woods" }, - { "sandbox", "Sandbox" }, - { "sandbox_high", "SandboxHigh" }, - - // SPT - { "Factory4Day", "Factory4Day" }, - { "Bigmap", "Bigmap" }, - { "Develop", "Develop" }, - { "Factory4Night", "Factory4Night" }, - { "Hideout", "Hideout" }, - { "Interchange", "Interchange" }, - { "Laboratory", "Laboratory" }, - { "Lighthouse", "Lighthouse" }, - { "PrivateArea", "PrivateArea" }, - { "RezervBase", "RezervBase" }, - { "Shoreline", "Shoreline" }, - { "Suburbs", "Suburbs" }, - { "TarkovStreets", "TarkovStreets" }, - { "Terminal", "Terminal" }, - { "Town", "Town" }, - { "Woods", "Woods" }, - { "Sandbox", "Sandbox" }, - { "SandboxHigh", "SandboxHigh" } - }; - [JsonPropertyName("bigmap")] public Eft.Common.Location? Bigmap { get; set; } @@ -110,6 +63,8 @@ public record Locations [JsonPropertyName("base")] public LocationsBase? Base { get; set; } + private Dictionary? _locationDictionaryCache; + /// /// Get map locations as a dictionary, keyed by its name e.g. Factory4Day /// @@ -138,4 +93,49 @@ public record Locations _locationDictionaryCache = classProps .ToDictionary(propertyInfo => propertyInfo.Name, propertyInfo => propertyInfo.GetValue(this, null) as Eft.Common.Location); } + + // sometimes we get the key or value given so save changing logic in each place + // have it key both + private Dictionary _locationMappings = new() + { + // EFT + { "factory4_day", "Factory4Day" }, + { "bigmap", "Bigmap" }, + { "develop", "Develop" }, + { "factory4_night", "Factory4Night" }, + { "hideout", "Hideout" }, + { "interchange", "Interchange" }, + { "laboratory", "Laboratory" }, + { "lighthouse", "Lighthouse" }, + { "privatearea", "PrivateArea" }, + { "rezervbase", "RezervBase" }, + { "shoreline", "Shoreline" }, + { "suburbs", "Suburbs" }, + { "tarkovstreets", "TarkovStreets" }, + { "terminal", "Terminal" }, + { "town", "Town" }, + { "woods", "Woods" }, + { "sandbox", "Sandbox" }, + { "sandbox_high", "SandboxHigh" }, + + // SPT + { "Factory4Day", "Factory4Day" }, + { "Bigmap", "Bigmap" }, + { "Develop", "Develop" }, + { "Factory4Night", "Factory4Night" }, + { "Hideout", "Hideout" }, + { "Interchange", "Interchange" }, + { "Laboratory", "Laboratory" }, + { "Lighthouse", "Lighthouse" }, + { "PrivateArea", "PrivateArea" }, + { "RezervBase", "RezervBase" }, + { "Shoreline", "Shoreline" }, + { "Suburbs", "Suburbs" }, + { "TarkovStreets", "TarkovStreets" }, + { "Terminal", "Terminal" }, + { "Town", "Town" }, + { "Woods", "Woods" }, + { "Sandbox", "Sandbox" }, + { "SandboxHigh", "SandboxHigh" } + }; } diff --git a/Libraries/Core/Routers/EventOutputHolder.cs b/Libraries/Core/Routers/EventOutputHolder.cs index 338ce63f..90023dfb 100644 --- a/Libraries/Core/Routers/EventOutputHolder.cs +++ b/Libraries/Core/Routers/EventOutputHolder.cs @@ -12,13 +12,13 @@ namespace Core.Routers; [Injectable] public class EventOutputHolder { - protected Dictionary> _clientActiveSessionStorage = new(); - protected ICloner _cloner; protected ISptLogger _logger; - - protected Dictionary _outputStore = new(); protected ProfileHelper _profileHelper; protected TimeUtil _timeUtil; + protected ICloner _cloner; + + protected Dictionary _outputStore = new(); + protected Dictionary> _clientActiveSessionStorage = new(); public EventOutputHolder( ISptLogger logger, diff --git a/Libraries/Core/Routers/HttpRouter.cs b/Libraries/Core/Routers/HttpRouter.cs index e8ab8944..8a9f58af 100644 --- a/Libraries/Core/Routers/HttpRouter.cs +++ b/Libraries/Core/Routers/HttpRouter.cs @@ -6,8 +6,8 @@ namespace Core.Routers; [Injectable] public class HttpRouter { - protected IEnumerable _dynamicRoutes; protected IEnumerable _staticRouters; + protected IEnumerable _dynamicRoutes; public HttpRouter( IEnumerable staticRouters, diff --git a/Libraries/Core/Routers/ImageRouter.cs b/Libraries/Core/Routers/ImageRouter.cs index 74fd0d84..49618ab4 100644 --- a/Libraries/Core/Routers/ImageRouter.cs +++ b/Libraries/Core/Routers/ImageRouter.cs @@ -8,8 +8,8 @@ namespace Core.Routers; public class ImageRouter { protected FileUtil _fileUtil; - protected HttpFileUtil _httpFileUtil; protected ImageRouterService _imageRouterService; + protected HttpFileUtil _httpFileUtil; public ImageRouter( FileUtil fileUtil, diff --git a/Libraries/Core/Routers/ItemEventRouter.cs b/Libraries/Core/Routers/ItemEventRouter.cs index 5f11f963..823ebe52 100644 --- a/Libraries/Core/Routers/ItemEventRouter.cs +++ b/Libraries/Core/Routers/ItemEventRouter.cs @@ -13,14 +13,14 @@ namespace Core.Routers; [Injectable] public class ItemEventRouter { - protected ICloner _cloner; - protected EventOutputHolder _eventOutputHolder; - protected HttpResponseUtil _httpResponseUtil; - protected List _itemEventRouters; - protected JsonUtil _jsonUtil; - protected LocalisationService _localisationService; protected ISptLogger _logger; + protected HttpResponseUtil _httpResponseUtil; + protected JsonUtil _jsonUtil; protected ProfileHelper _profileHelper; + protected LocalisationService _localisationService; + protected EventOutputHolder _eventOutputHolder; + protected List _itemEventRouters; + protected ICloner _cloner; public ItemEventRouter( ISptLogger logger, diff --git a/Libraries/Core/Routers/ItemEvents/CustomizationItemEventRouter.cs b/Libraries/Core/Routers/ItemEvents/CustomizationItemEventRouter.cs index 1b660530..d8435e20 100644 --- a/Libraries/Core/Routers/ItemEvents/CustomizationItemEventRouter.cs +++ b/Libraries/Core/Routers/ItemEvents/CustomizationItemEventRouter.cs @@ -12,8 +12,8 @@ namespace Core.Routers.ItemEvents; [Injectable(InjectableTypeOverride = typeof(ItemEventRouterDefinition))] public class CustomizationItemEventRouter : ItemEventRouterDefinition { - protected CustomizationCallbacks _customizationCallbacks; protected ISptLogger _logger; + protected CustomizationCallbacks _customizationCallbacks; public CustomizationItemEventRouter ( diff --git a/Libraries/Core/Routers/ItemEvents/InventoryItemEventRouter.cs b/Libraries/Core/Routers/ItemEvents/InventoryItemEventRouter.cs index 9177495d..5bc348e3 100644 --- a/Libraries/Core/Routers/ItemEvents/InventoryItemEventRouter.cs +++ b/Libraries/Core/Routers/ItemEvents/InventoryItemEventRouter.cs @@ -14,8 +14,8 @@ namespace Core.Routers.ItemEvents; [Injectable(InjectableTypeOverride = typeof(ItemEventRouterDefinition))] public class InventoryItemEventRouter : ItemEventRouterDefinition { - protected HideoutCallbacks _hideoutCallbacks; protected InventoryCallbacks _inventoryCallbacks; + protected HideoutCallbacks _hideoutCallbacks; public InventoryItemEventRouter ( diff --git a/Libraries/Core/Servers/ConfigServer.cs b/Libraries/Core/Servers/ConfigServer.cs index 5befbf21..a0010449 100644 --- a/Libraries/Core/Servers/ConfigServer.cs +++ b/Libraries/Core/Servers/ConfigServer.cs @@ -10,11 +10,11 @@ namespace Core.Servers; [Injectable(InjectionType.Singleton)] public class ConfigServer { - protected readonly string[] acceptableFileExtensions = ["json", "jsonc"]; - protected FileUtil _fileUtil; - protected JsonUtil _jsonUtil; protected ISptLogger _logger; + protected JsonUtil _jsonUtil; + protected FileUtil _fileUtil; protected Dictionary configs = new(); + protected readonly string[] acceptableFileExtensions = ["json", "jsonc"]; public ConfigServer( ISptLogger logger, diff --git a/Libraries/Core/Servers/Http/SptHttpListener.cs b/Libraries/Core/Servers/Http/SptHttpListener.cs index 64783a3e..408eceee 100644 --- a/Libraries/Core/Servers/Http/SptHttpListener.cs +++ b/Libraries/Core/Servers/Http/SptHttpListener.cs @@ -21,16 +21,14 @@ public class SptHttpListener : IHttpListener // We want to read 1KB at a time, for most request this is already big enough private const int BodyReadBufferSize = 1024 * 1; - private static readonly ImmutableHashSet SupportedMethods = ["GET", "PUT", "POST"]; - protected readonly HttpResponseUtil _httpResponseUtil; - protected readonly JsonUtil _jsonUtil; - protected readonly LocalisationService _localisationService; - protected readonly ISptLogger _logger; - protected readonly ISptLogger _requestLogger; - protected readonly HttpRouter _router; protected readonly IEnumerable _serializers; + protected readonly ISptLogger _logger; + protected readonly ISptLogger _requestLogger; + protected readonly HttpResponseUtil _httpResponseUtil; + protected readonly LocalisationService _localisationService; + protected readonly JsonUtil _jsonUtil; public SptHttpListener( HttpRouter httpRouter, @@ -51,6 +49,8 @@ public class SptHttpListener : IHttpListener _jsonUtil = jsonUtil; } + private static readonly ImmutableHashSet SupportedMethods = ["GET", "PUT", "POST"]; + public bool CanHandle(string _, HttpRequest req) { return SupportedMethods.Contains(req.Method); diff --git a/Libraries/Core/Servers/SaveServer.cs b/Libraries/Core/Servers/SaveServer.cs index 198a9379..c860f5ea 100644 --- a/Libraries/Core/Servers/SaveServer.cs +++ b/Libraries/Core/Servers/SaveServer.cs @@ -22,12 +22,13 @@ public class SaveServer( ConfigServer _configServer ) { - // onLoad = require("../bindings/SaveLoad"); - protected readonly Dictionary> onBeforeSaveCallbacks = new(); - private Lock _lock = new(); protected string profileFilepath = "user/profiles/"; protected Dictionary profiles = new(); + private Lock _lock = new(); + + // onLoad = require("../bindings/SaveLoad"); + protected readonly Dictionary> onBeforeSaveCallbacks = new(); protected Dictionary saveMd5 = new(); /** diff --git a/Libraries/Core/Servers/Ws/SptWebSocketConnectionHandler.cs b/Libraries/Core/Servers/Ws/SptWebSocketConnectionHandler.cs index 6d64b0dc..d59ca21d 100644 --- a/Libraries/Core/Servers/Ws/SptWebSocketConnectionHandler.cs +++ b/Libraries/Core/Servers/Ws/SptWebSocketConnectionHandler.cs @@ -22,13 +22,14 @@ public class SptWebSocketConnectionHandler( IEnumerable _messageHandlers ) : IWebSocketConnectionHandler { - protected WsPing _defaultNotification = new(); protected HttpConfig _httpConfig = _configServer.GetConfig(); - protected Lock _lockObject = new(); - protected Dictionary _receiveTasks = new(); - protected Dictionary _socketAliveTimers = new(); protected Dictionary _sockets = new(); + protected Dictionary _socketAliveTimers = new(); + protected Dictionary _receiveTasks = new(); + protected Lock _lockObject = new(); + + protected WsPing _defaultNotification = new(); public string GetHookUrl() { @@ -83,6 +84,22 @@ public class SptWebSocketConnectionHandler( ); } + private void TimedTask(WebSocket ws, string sessionID) + { + if (_logger.IsLogEnabled(LogLevel.Debug)) _logger.Debug(_localisationService.GetText("websocket-pinging_player", sessionID)); + + if (ws.State == WebSocketState.Open) + { + var sendTask = ws.SendAsync( + Encoding.UTF8.GetBytes(_jsonUtil.Serialize(_defaultNotification)), + WebSocketMessageType.Text, + true, + CancellationToken.None + ); + sendTask.Wait(); + } + } + public void SendMessage(string sessionID, WsNotificationEvent output) { try @@ -111,27 +128,6 @@ public class SptWebSocketConnectionHandler( } } - public bool IsWebSocketConnected(string sessionID) - { - return _sockets.TryGetValue(sessionID, out var socket) && socket.State == WebSocketState.Open; - } - - private void TimedTask(WebSocket ws, string sessionID) - { - if (_logger.IsLogEnabled(LogLevel.Debug)) _logger.Debug(_localisationService.GetText("websocket-pinging_player", sessionID)); - - if (ws.State == WebSocketState.Open) - { - var sendTask = ws.SendAsync( - Encoding.UTF8.GetBytes(_jsonUtil.Serialize(_defaultNotification)), - WebSocketMessageType.Text, - true, - CancellationToken.None - ); - sendTask.Wait(); - } - } - private void ReceiveTask(string sessionID, WebSocket ws, CancellationToken cancelToken) { List readBytes = new(); @@ -176,6 +172,11 @@ public class SptWebSocketConnectionHandler( } } + public bool IsWebSocketConnected(string sessionID) + { + return _sockets.TryGetValue(sessionID, out var socket) && socket.State == WebSocketState.Open; + } + public WebSocket GetSessionWebSocket(string sessionID) { return _sockets[sessionID]; diff --git a/Libraries/Core/Services/BackupService.cs b/Libraries/Core/Services/BackupService.cs index 7270879e..3444bbb0 100644 --- a/Libraries/Core/Services/BackupService.cs +++ b/Libraries/Core/Services/BackupService.cs @@ -10,17 +10,17 @@ namespace Core.Services; [Injectable(InjectionType.Singleton)] public class BackupService { - protected const string _profileDir = "./user/profiles"; + protected ISptLogger _logger; + protected JsonUtil _jsonUtil; + protected TimeUtil _timeUtil; + protected FileUtil _fileUtil; + protected BackupConfig _backupConfig; protected readonly List _activeServerMods; - protected BackupConfig _backupConfig; + protected const string _profileDir = "./user/profiles"; // Runs Init() every x minutes protected Timer _backupIntervalTimer; - protected FileUtil _fileUtil; - protected JsonUtil _jsonUtil; - protected ISptLogger _logger; - protected TimeUtil _timeUtil; public BackupService( ISptLogger _logger, diff --git a/Libraries/Core/Services/BotEquipmentFilterService.cs b/Libraries/Core/Services/BotEquipmentFilterService.cs index 7a386af8..2dbe0231 100644 --- a/Libraries/Core/Services/BotEquipmentFilterService.cs +++ b/Libraries/Core/Services/BotEquipmentFilterService.cs @@ -14,11 +14,12 @@ namespace Core.Services; [Injectable(InjectionType.Singleton)] public class BotEquipmentFilterService { - protected BotConfig _botConfig; - protected Dictionary _botEquipmentConfig; - protected BotHelper _botHelper; protected ISptLogger _logger; protected ProfileHelper _profileHelper; + protected BotHelper _botHelper; + + protected BotConfig _botConfig; + protected Dictionary _botEquipmentConfig; public BotEquipmentFilterService( ISptLogger logger, diff --git a/Libraries/Core/Services/BotEquipmentModPoolService.cs b/Libraries/Core/Services/BotEquipmentModPoolService.cs index b2a25fbf..4600d11c 100644 --- a/Libraries/Core/Services/BotEquipmentModPoolService.cs +++ b/Libraries/Core/Services/BotEquipmentModPoolService.cs @@ -12,18 +12,19 @@ namespace Core.Services; [Injectable(InjectionType.Singleton)] public class BotEquipmentModPoolService { - private readonly Lock _lock = new(); - protected bool _armorPoolGenerated; - protected BotConfig _botConfig; - protected ConfigServer _configServer; - protected DatabaseService _databaseService; - protected ConcurrentDictionary>> _gearModPool; - protected ItemHelper _itemHelper; - protected LocalisationService _localisationService; protected ISptLogger _logger; - protected ConcurrentDictionary>> _weaponModPool; + protected ItemHelper _itemHelper; + protected DatabaseService _databaseService; + protected LocalisationService _localisationService; + protected ConfigServer _configServer; protected bool _weaponPoolGenerated; + protected bool _armorPoolGenerated; + protected ConcurrentDictionary>> _weaponModPool; + protected ConcurrentDictionary>> _gearModPool; + protected BotConfig _botConfig; + + private readonly Lock _lock = new(); public BotEquipmentModPoolService( ISptLogger logger, diff --git a/Libraries/Core/Services/BotGenerationCacheService.cs b/Libraries/Core/Services/BotGenerationCacheService.cs index 90af6e8d..0b60a1e3 100644 --- a/Libraries/Core/Services/BotGenerationCacheService.cs +++ b/Libraries/Core/Services/BotGenerationCacheService.cs @@ -11,9 +11,9 @@ public class BotGenerationCacheService( LocalisationService _localisationService ) { + protected Dictionary> _storedBots = new(); protected Queue _activeBotsInRaid = []; protected object _lock = new(); - protected Dictionary> _storedBots = new(); /** diff --git a/Libraries/Core/Services/BotLootCacheService.cs b/Libraries/Core/Services/BotLootCacheService.cs index 503955d7..62749664 100644 --- a/Libraries/Core/Services/BotLootCacheService.cs +++ b/Libraries/Core/Services/BotLootCacheService.cs @@ -21,8 +21,8 @@ public class BotLootCacheService( ICloner _cloner ) { - protected object _lock = new(); protected Dictionary _lootCache = new(); + protected object _lock = new(); /// /// Remove cached bot loot data diff --git a/Libraries/Core/Services/BotNameService.cs b/Libraries/Core/Services/BotNameService.cs index 23574712..92cd6fea 100644 --- a/Libraries/Core/Services/BotNameService.cs +++ b/Libraries/Core/Services/BotNameService.cs @@ -21,8 +21,8 @@ public class BotNameService( ) { protected BotConfig _botConfig = _configServer.GetConfig(); - protected object _lock = new(); protected HashSet _usedNameCache = new(); + protected object _lock = new(); /// /// Clear out any entries in Name Set diff --git a/Libraries/Core/Services/Cache/BundleHashCacheService.cs b/Libraries/Core/Services/Cache/BundleHashCacheService.cs index 27b5bae1..dafe2aed 100644 --- a/Libraries/Core/Services/Cache/BundleHashCacheService.cs +++ b/Libraries/Core/Services/Cache/BundleHashCacheService.cs @@ -13,8 +13,8 @@ public class BundleHashCacheService( FileUtil _fileUtil ) { - protected readonly string _bundleHashCachePath = "./user/cache/bundleHashCache.json"; protected Dictionary _bundleHashes = new(); + protected readonly string _bundleHashCachePath = "./user/cache/bundleHashCache.json"; public string GetStoredValue(string key) { diff --git a/Libraries/Core/Services/Cache/ModHashCacheService.cs b/Libraries/Core/Services/Cache/ModHashCacheService.cs index d4e4c6b0..8a60dad4 100644 --- a/Libraries/Core/Services/Cache/ModHashCacheService.cs +++ b/Libraries/Core/Services/Cache/ModHashCacheService.cs @@ -13,8 +13,8 @@ public class ModHashCacheService( FileUtil _fileUtil ) { - protected readonly string _modCachePath = "./user/cache/modCache.json"; protected readonly Dictionary _modHashes = new(); + protected readonly string _modCachePath = "./user/cache/modCache.json"; public string? GetStoredValue(string key) { diff --git a/Libraries/Core/Services/CircleOfCultistService.cs b/Libraries/Core/Services/CircleOfCultistService.cs index 1548872a..a232d9c4 100644 --- a/Libraries/Core/Services/CircleOfCultistService.cs +++ b/Libraries/Core/Services/CircleOfCultistService.cs @@ -39,8 +39,8 @@ public class CircleOfCultistService( ConfigServer _configServer ) { - protected const string CircleOfCultistSlotId = "CircleOfCultistsGrid1"; protected HideoutConfig _hideoutConfig = _configServer.GetConfig(); + protected const string CircleOfCultistSlotId = "CircleOfCultistsGrid1"; /// /// Start a sacrifice event diff --git a/Libraries/Core/Services/FenceService.cs b/Libraries/Core/Services/FenceService.cs index 032e7829..7f5c3f48 100644 --- a/Libraries/Core/Services/FenceService.cs +++ b/Libraries/Core/Services/FenceService.cs @@ -28,8 +28,10 @@ public class FenceService( ICloner _cloner ) { - /** Desired baseline counts - Hydrated on initial assort generation as part of generateFenceAssorts() */ - protected FenceAssortGenerationValues desiredAssortCounts; + protected TraderConfig traderConfig = configServer.GetConfig(); + + /** Time when some items in assort will be replaced */ + protected long nextPartialRefreshTimestamp; /** Main assorts you see at all rep levels */ protected TraderAssort? fenceAssort = null; @@ -37,6 +39,9 @@ public class FenceService( /** Assorts shown on a separate tab when you max out fence rep */ protected TraderAssort? fenceDiscountAssort = null; + /** Desired baseline counts - Hydrated on initial assort generation as part of generateFenceAssorts() */ + protected FenceAssortGenerationValues desiredAssortCounts; + protected HashSet fenceItemUpdCompareProperties = [ "Buff", @@ -50,11 +55,6 @@ public class FenceService( "RepairKit" ]; - /** Time when some items in assort will be replaced */ - protected long nextPartialRefreshTimestamp; - - protected TraderConfig traderConfig = configServer.GetConfig(); - /** * Replace main fence assort with new assort @@ -1367,7 +1367,8 @@ public class FenceService( { var itemTypeCounts = new Dictionary(); - foreach (var x in limits.Keys) itemTypeCounts[x] = new ValueTuple { current = 0, max = limits[x] }; + foreach (var x in limits.Keys) + itemTypeCounts[x] = new(0, limits[x]); return itemTypeCounts; } diff --git a/Libraries/Core/Services/I18nService.cs b/Libraries/Core/Services/I18nService.cs index 044c07bc..9efd3158 100644 --- a/Libraries/Core/Services/I18nService.cs +++ b/Libraries/Core/Services/I18nService.cs @@ -6,15 +6,15 @@ namespace Core.Services; public class I18nService { + private List _locales; + private Dictionary _fallbacks; private string _defaultLocale; private string _directory; - private Dictionary _fallbacks; - private FileUtil _fileUtil; private JsonUtil _jsonUtil; + private FileUtil _fileUtil; + private string _setLocale; private Dictionary>> _loadedLocales = new(); - private List _locales; - private string _setLocale; // TODO: try convert to primary ctor public I18nService( diff --git a/Libraries/Core/Services/ItemFilterService.cs b/Libraries/Core/Services/ItemFilterService.cs index 6ee0aed5..c4e8d7b1 100644 --- a/Libraries/Core/Services/ItemFilterService.cs +++ b/Libraries/Core/Services/ItemFilterService.cs @@ -13,10 +13,10 @@ public class ItemFilterService( ConfigServer _configServer ) { - protected HashSet? _itemBlacklistCache = []; protected ItemConfig _itemConfig = _configServer.GetConfig(); protected HashSet? _lootableItemBlacklistCache = []; + protected HashSet? _itemBlacklistCache = []; /** * Check if the provided template id is blacklisted in config/item.json/blacklist diff --git a/Libraries/Core/Services/LocalisationService.cs b/Libraries/Core/Services/LocalisationService.cs index a193236a..b25ec2dc 100644 --- a/Libraries/Core/Services/LocalisationService.cs +++ b/Libraries/Core/Services/LocalisationService.cs @@ -8,12 +8,12 @@ namespace Core.Services; [Injectable(InjectionType.Singleton)] public class LocalisationService { - protected DatabaseServer _databaseServer; - - protected I18nService _i18nService; - protected LocaleService _localeService; protected ISptLogger _logger; protected RandomUtil _randomUtil; + protected DatabaseServer _databaseServer; + protected LocaleService _localeService; + + protected I18nService _i18nService; // TODO: turn into primary ctor public LocalisationService( diff --git a/Libraries/Core/Services/LocationLifecycleService.cs b/Libraries/Core/Services/LocationLifecycleService.cs index 97e04cb1..6e2342c0 100644 --- a/Libraries/Core/Services/LocationLifecycleService.cs +++ b/Libraries/Core/Services/LocationLifecycleService.cs @@ -20,39 +20,39 @@ namespace Core.Services; [Injectable(InjectionType.Singleton)] public class LocationLifecycleService { + private readonly ISptLogger _logger; + private readonly RewardHelper _rewardHelper; + private readonly ConfigServer _configServer; + private readonly TimeUtil _timeUtil; + private readonly DatabaseService _databaseService; + private readonly ProfileHelper _profileHelper; + private readonly HashUtil _hashUtil; private readonly ApplicationContext _applicationContext; private readonly BotGenerationCacheService _botGenerationCacheService; - private readonly BotLootCacheService _botLootCacheService; private readonly BotNameService _botNameService; + private readonly PmcConfig _pmcConfig; private readonly ICloner _cloner; - private readonly ConfigServer _configServer; - private readonly DatabaseService _databaseService; - private readonly HashUtil _hashUtil; - private readonly HealthHelper _healthHelper; - private readonly HideoutConfig _hideoutConfig; - private readonly InRaidConfig _inRaidConfig; - private readonly InRaidHelper _inRaidHelper; - private readonly InsuranceService _insuranceService; - private readonly LocalisationService _localisationService; private readonly LocationConfig _locationConfig; + private readonly RaidTimeAdjustmentService _raidTimeAdjustmentService; private readonly LocationLootGenerator _locationLootGenerator; - private readonly ISptLogger _logger; + private readonly LocalisationService _localisationService; + private readonly BotLootCacheService _botLootCacheService; + private readonly RagfairConfig _ragfairConfig; + private readonly HideoutConfig _hideoutConfig; + private readonly TraderConfig _traderConfig; private readonly LootGenerator _lootGenerator; private readonly MailSendService _mailSendService; - private readonly MatchBotDetailsCacheService _matchBotDetailsCacheService; - private readonly PlayerScavGenerator _playerScavGenerator; - private readonly PmcChatResponseService _pmcChatResponseService; - private readonly PmcConfig _pmcConfig; - private readonly ProfileHelper _profileHelper; - private readonly QuestHelper _questHelper; - private readonly RagfairConfig _ragfairConfig; - private readonly RaidTimeAdjustmentService _raidTimeAdjustmentService; - private readonly RandomUtil _randomUtil; - private readonly RewardHelper _rewardHelper; - private readonly SaveServer _saveServer; - private readonly TimeUtil _timeUtil; - private readonly TraderConfig _traderConfig; private readonly TraderHelper _traderHelper; + private readonly RandomUtil _randomUtil; + private readonly InRaidConfig _inRaidConfig; + private readonly InRaidHelper _inRaidHelper; + private readonly PlayerScavGenerator _playerScavGenerator; + private readonly SaveServer _saveServer; + private readonly HealthHelper _healthHelper; + private readonly PmcChatResponseService _pmcChatResponseService; + private readonly QuestHelper _questHelper; + private readonly InsuranceService _insuranceService; + private readonly MatchBotDetailsCacheService _matchBotDetailsCacheService; public LocationLifecycleService( ISptLogger logger, diff --git a/Libraries/Core/Services/PmcChatResponseService.cs b/Libraries/Core/Services/PmcChatResponseService.cs index 159059a4..2006eef4 100644 --- a/Libraries/Core/Services/PmcChatResponseService.cs +++ b/Libraries/Core/Services/PmcChatResponseService.cs @@ -26,8 +26,8 @@ public class PmcChatResponseService( MatchBotDetailsCacheService _matchBotDetailsCacheService, ConfigServer _configServer) { - protected GiftsConfig _giftConfig = _configServer.GetConfig(); protected PmcChatResponse _pmcResponsesConfig = _configServer.GetConfig(); + protected GiftsConfig _giftConfig = _configServer.GetConfig(); /** * For each PMC victim of the player, have a chance to send a message to the player, can be positive or negative diff --git a/Libraries/Core/Services/PostDbLoadService.cs b/Libraries/Core/Services/PostDbLoadService.cs index c1d26bff..ecc461da 100644 --- a/Libraries/Core/Services/PostDbLoadService.cs +++ b/Libraries/Core/Services/PostDbLoadService.cs @@ -23,13 +23,13 @@ public class PostDbLoadService( ConfigServer _configServer, ICloner _cloner) { - protected BotConfig _botConfig = _configServer.GetConfig(); - protected CoreConfig _coreConfig = _configServer.GetConfig(); protected HideoutConfig _hideoutConfig = _configServer.GetConfig(); - protected ItemConfig _itemConfig = _configServer.GetConfig(); protected LocationConfig _locationConfig = _configServer.GetConfig(); protected LootConfig _lootConfig = _configServer.GetConfig(); + protected BotConfig _botConfig = _configServer.GetConfig(); + protected ItemConfig _itemConfig = _configServer.GetConfig(); protected RagfairConfig _ragfairConfig = _configServer.GetConfig(); + protected CoreConfig _coreConfig = _configServer.GetConfig(); public void PerformPostDbLoadActions() { diff --git a/Libraries/Core/Services/ProfileFixerService.cs b/Libraries/Core/Services/ProfileFixerService.cs index 20936bc9..adafa1bf 100644 --- a/Libraries/Core/Services/ProfileFixerService.cs +++ b/Libraries/Core/Services/ProfileFixerService.cs @@ -28,7 +28,6 @@ public class ProfileFixerService( InventoryHelper _inventoryHelper ) { - protected List _areas = ["hideout", "main"]; protected CoreConfig _coreConfig = _configServer.GetConfig(); /// @@ -437,6 +436,8 @@ public class ProfileFixerService( foreach (var skill in skills.Where(skill => skill.Progress > 5100)) skill.Progress = 5100; } + protected List _areas = ["hideout", "main"]; + /** * Checks profile inventory for items that do not exist inside the items db * @param sessionId Session id diff --git a/Libraries/Core/Services/RagfairOfferService.cs b/Libraries/Core/Services/RagfairOfferService.cs index 3672b77e..1aec18a5 100644 --- a/Libraries/Core/Services/RagfairOfferService.cs +++ b/Libraries/Core/Services/RagfairOfferService.cs @@ -27,11 +27,11 @@ public class RagfairOfferService( RagfairOfferHolder ragfairOfferHolder ) { + protected bool playerOffersLoaded; + /** Offer id + offer object */ protected Dictionary expiredOffers = new(); - protected bool playerOffersLoaded; - protected RagfairConfig ragfairConfig = configServer.GetConfig(); /** diff --git a/Libraries/Core/Services/RagfairPriceService.cs b/Libraries/Core/Services/RagfairPriceService.cs index df72095c..8b26708a 100644 --- a/Libraries/Core/Services/RagfairPriceService.cs +++ b/Libraries/Core/Services/RagfairPriceService.cs @@ -25,8 +25,8 @@ public class RagfairPriceService( ConfigServer _configServer ) { - private RagfairConfig _ragfairConfig = _configServer.GetConfig(); protected Dictionary? _staticPrices; + private RagfairConfig _ragfairConfig = _configServer.GetConfig(); /// /// Generate static (handbook) and dynamic (prices.json) flea prices, store inside class as dictionaries diff --git a/Libraries/Core/Services/SeasonalEventService.cs b/Libraries/Core/Services/SeasonalEventService.cs index 769467cb..dbb21ede 100644 --- a/Libraries/Core/Services/SeasonalEventService.cs +++ b/Libraries/Core/Services/SeasonalEventService.cs @@ -24,7 +24,15 @@ public class SeasonalEventService( ConfigServer _configServer ) { + protected SeasonalEventConfig _seasonalEventConfig = _configServer.GetConfig(); + protected QuestConfig _questConfig = _configServer.GetConfig(); + protected HttpConfig _httpConfig = _configServer.GetConfig(); + protected WeatherConfig _weatherConfig = _configServer.GetConfig(); + protected LocationConfig _locationConfig = _configServer.GetConfig(); + + private List _currentlyActiveEvents = []; private bool _christmasEventActive = false; + private bool _halloweenEventActive = false; protected IReadOnlyList _christmasEventItems = [ @@ -53,9 +61,6 @@ public class SeasonalEventService( ItemTpl.FACECOVER_AYBOLIT_MASK ]; - private List _currentlyActiveEvents = []; - private bool _halloweenEventActive = false; - protected IReadOnlyList _halloweenEventItems = [ ItemTpl.FACECOVER_SPOOKY_SKULL_MASK, @@ -71,12 +76,6 @@ public class SeasonalEventService( ItemTpl.FACECOVER_HOCKEY_PLAYER_MASK_QUIET ]; - protected HttpConfig _httpConfig = _configServer.GetConfig(); - protected LocationConfig _locationConfig = _configServer.GetConfig(); - protected QuestConfig _questConfig = _configServer.GetConfig(); - protected SeasonalEventConfig _seasonalEventConfig = _configServer.GetConfig(); - protected WeatherConfig _weatherConfig = _configServer.GetConfig(); - /// /// Get an array of christmas items found in bots inventories as loot /// diff --git a/Libraries/Core/Utils/App.cs b/Libraries/Core/Utils/App.cs index 88af96bb..8fb69327 100644 --- a/Libraries/Core/Utils/App.cs +++ b/Libraries/Core/Utils/App.cs @@ -12,20 +12,20 @@ namespace Core.Utils; [Injectable(InjectionType.Singleton)] public class App { - protected readonly RandomUtil _randomUtil; - protected ConfigServer _configServer; - protected CoreConfig _coreConfig; - protected DatabaseService _databaseService; - protected EncodingUtil _encodingUtil; - protected HttpServer _httpServer; - protected LocalisationService _localisationService; - - protected ISptLogger _logger; - protected IEnumerable _onLoad; - protected IEnumerable _onUpdate; protected Dictionary _onUpdateLastRun = new(); protected Timer _timer; + protected CoreConfig _coreConfig; + + protected ISptLogger _logger; protected TimeUtil _timeUtil; + protected readonly RandomUtil _randomUtil; + protected LocalisationService _localisationService; + protected ConfigServer _configServer; + protected EncodingUtil _encodingUtil; + protected HttpServer _httpServer; + protected DatabaseService _databaseService; + protected IEnumerable _onLoad; + protected IEnumerable _onUpdate; public App( ISptLogger logger, diff --git a/Libraries/Core/Utils/Collections/ExhaustableArray.cs b/Libraries/Core/Utils/Collections/ExhaustableArray.cs index 7def7b34..14db6fc7 100644 --- a/Libraries/Core/Utils/Collections/ExhaustableArray.cs +++ b/Libraries/Core/Utils/Collections/ExhaustableArray.cs @@ -4,9 +4,9 @@ namespace Core.Utils.Collections; public record ExhaustableArray : IExhaustableArray { - private ICloner _cloner; - private RandomUtil _randomUtil; private LinkedList? pool; + private RandomUtil _randomUtil; + private ICloner _cloner; public ExhaustableArray( T[]? itemPool, diff --git a/Libraries/Core/Utils/Collections/ProbabilityObjectArray.cs b/Libraries/Core/Utils/Collections/ProbabilityObjectArray.cs index ee07ee3c..f5ea79ea 100644 --- a/Libraries/Core/Utils/Collections/ProbabilityObjectArray.cs +++ b/Libraries/Core/Utils/Collections/ProbabilityObjectArray.cs @@ -23,8 +23,8 @@ namespace Core.Utils.Collections; /// public class ProbabilityObjectArray : List> { - private readonly ICloner _cloner; private readonly MathUtil _mathUtil; + private readonly ICloner _cloner; public ProbabilityObjectArray( MathUtil mathUtil, diff --git a/Libraries/Core/Utils/DatabaseImporter.cs b/Libraries/Core/Utils/DatabaseImporter.cs index dd3906ff..4244079f 100644 --- a/Libraries/Core/Utils/DatabaseImporter.cs +++ b/Libraries/Core/Utils/DatabaseImporter.cs @@ -14,22 +14,22 @@ namespace Core.Utils; [Injectable(InjectionType.Singleton, InjectableTypeOverride = typeof(OnLoad), TypePriority = OnLoadOrder.Database)] public class DatabaseImporter : OnLoad { - protected ConfigServer _configServer; - - protected DatabaseServer _databaseServer; - protected EncodingUtil _encodingUtil; - protected FileUtil _fileUtil; - protected HashUtil _hashUtil; - - protected ImageRouter _imageRouter; - protected ImporterUtil _importerUtil; - protected LocalisationService _localisationService; + private object hashedFile; + private ValidationResult valid = ValidationResult.UNDEFINED; + private string filepath; + private HttpConfig httpConfig; protected ISptLogger _logger; - private string filepath; - private object hashedFile; - private HttpConfig httpConfig; - private ValidationResult valid = ValidationResult.UNDEFINED; + protected LocalisationService _localisationService; + + protected DatabaseServer _databaseServer; + + protected ImageRouter _imageRouter; + protected EncodingUtil _encodingUtil; + protected HashUtil _hashUtil; + protected ImporterUtil _importerUtil; + protected ConfigServer _configServer; + protected FileUtil _fileUtil; public DatabaseImporter( ISptLogger logger, @@ -56,6 +56,15 @@ public class DatabaseImporter : OnLoad httpConfig = _configServer.GetConfig(); } + /** + * Get path to spt data + * @returns path to data + */ + public string GetSptDataPath() + { + return "./Assets/"; + } + public async Task OnLoad() { filepath = GetSptDataPath(); @@ -88,20 +97,6 @@ public class DatabaseImporter : OnLoad CreateRouteMapping(imageFilePath, "files"); } - public string GetRoute() - { - return "spt-database"; - } - - /** - * Get path to spt data - * @returns path to data - */ - public string GetSptDataPath() - { - return "./Assets/"; - } - private void CreateRouteMapping(string directory, string newBasePath) { var directoryContent = GetAllFilesInDirectory(directory); @@ -168,6 +163,11 @@ public class DatabaseImporter : OnLoad //} } + public string GetRoute() + { + return "spt-database"; + } + protected bool ValidateFile(string filePathAndName, object fileData) { /* diff --git a/Libraries/Core/Utils/HashUtil.cs b/Libraries/Core/Utils/HashUtil.cs index 35a02413..bf377c45 100644 --- a/Libraries/Core/Utils/HashUtil.cs +++ b/Libraries/Core/Utils/HashUtil.cs @@ -8,9 +8,10 @@ namespace Core.Utils; [Injectable(InjectionType.Singleton)] public class HashUtil { - protected RandomUtil _randomUtil; protected Regex MongoIdRegex = new("^[a-fA-F0-9]{24}$"); + protected RandomUtil _randomUtil; + public HashUtil(RandomUtil randomUtil) { _randomUtil = randomUtil; diff --git a/Libraries/Core/Utils/HttpResponseUtil.cs b/Libraries/Core/Utils/HttpResponseUtil.cs index 22e02d86..f6f57d5c 100644 --- a/Libraries/Core/Utils/HttpResponseUtil.cs +++ b/Libraries/Core/Utils/HttpResponseUtil.cs @@ -11,17 +11,8 @@ namespace Core.Utils; [Injectable] public class HttpResponseUtil { - protected readonly JsonUtil _jsonUtil; protected readonly LocalisationService _localisationService; - - protected ImmutableList _cleanupRegexList = - [ - new("[\\b]"), - new("[\\f]"), - new("[\\n]"), - new("[\\r]"), - new("[\\t]") - ]; + protected readonly JsonUtil _jsonUtil; public HttpResponseUtil( JsonUtil jsonUtil, @@ -32,6 +23,15 @@ public class HttpResponseUtil _jsonUtil = jsonUtil; } + protected ImmutableList _cleanupRegexList = + [ + new("[\\b]"), + new("[\\f]"), + new("[\\n]"), + new("[\\r]"), + new("[\\t]") + ]; + protected string ClearString(string? s) { var value = s ?? ""; diff --git a/Libraries/Core/Utils/ImporterUtil.cs b/Libraries/Core/Utils/ImporterUtil.cs index 4ca0fa76..d851a9e1 100644 --- a/Libraries/Core/Utils/ImporterUtil.cs +++ b/Libraries/Core/Utils/ImporterUtil.cs @@ -12,9 +12,9 @@ public class ImporterUtil protected FileUtil _fileUtil; protected JsonUtil _jsonUtil; protected ISptLogger _logger; - protected HashSet directoriesToIgnore = ["./Assets/database/locales/server"]; protected HashSet filesToIgnore = ["bearsuits.json", "usecsuits.json", "archivedquests.json"]; + protected HashSet directoriesToIgnore = ["./Assets/database/locales/server"]; public ImporterUtil(ISptLogger logger, FileUtil fileUtil, JsonUtil jsonUtil) { diff --git a/Libraries/Core/Utils/Json/LazyLoad.cs b/Libraries/Core/Utils/Json/LazyLoad.cs index 09a2050e..e3683cee 100644 --- a/Libraries/Core/Utils/Json/LazyLoad.cs +++ b/Libraries/Core/Utils/Json/LazyLoad.cs @@ -2,11 +2,11 @@ public class LazyLoad(Func deserialize) { - private static readonly TimeSpan _autoCleanerTimeout = TimeSpan.FromSeconds(30); - private bool _isLoaded; private T? _result; + private bool _isLoaded; private Timer? autoCleanerTimeout; + private static readonly TimeSpan _autoCleanerTimeout = TimeSpan.FromSeconds(30); public T? Value { diff --git a/Libraries/Core/Utils/ProgressWriter.cs b/Libraries/Core/Utils/ProgressWriter.cs index 9142b127..a709111e 100644 --- a/Libraries/Core/Utils/ProgressWriter.cs +++ b/Libraries/Core/Utils/ProgressWriter.cs @@ -2,10 +2,10 @@ namespace Core.Utils; public class ProgressWriter { - protected string? _barEmptyChar; - protected string? _barFillChar; - protected int? _maxBarLength; protected int _total; + protected int? _maxBarLength; + protected string? _barFillChar; + protected string? _barEmptyChar; public ProgressWriter(int total, int maxBarLength, string barFillChar, string barEmptyChar) { diff --git a/Libraries/Core/Utils/RagfairOfferHolder.cs b/Libraries/Core/Utils/RagfairOfferHolder.cs index 69fc6247..31f139be 100644 --- a/Libraries/Core/Utils/RagfairOfferHolder.cs +++ b/Libraries/Core/Utils/RagfairOfferHolder.cs @@ -13,13 +13,13 @@ public class RagfairOfferHolder( HashUtil hashUtil, ConfigServer configServer) { - protected int _maxOffersPerTemplate = (int)configServer.GetConfig().Dynamic.OfferItemCount.Max; protected Dictionary _offersById = new(); protected object _offersByIdLock = new(); protected Dictionary> _offersByTemplate = new(); protected object _offersByTemplateLock = new(); protected Dictionary> _offersByTrader = new(); protected object _offersByTraderLock = new(); + protected int _maxOffersPerTemplate = (int)configServer.GetConfig().Dynamic.OfferItemCount.Max; public RagfairOffer? GetOfferById(string id) { diff --git a/Libraries/Core/Utils/RandomUtil.cs b/Libraries/Core/Utils/RandomUtil.cs index 43c14182..d943a5d7 100644 --- a/Libraries/Core/Utils/RandomUtil.cs +++ b/Libraries/Core/Utils/RandomUtil.cs @@ -10,7 +10,9 @@ namespace Core.Utils; [Injectable(InjectionType.Singleton)] public class RandomUtil(ISptLogger _logger, ICloner _cloner) { + public readonly Random Random = new(); private const int DecimalPointRandomPrecision = 6; + private static readonly int DecimalPointRandomPrecisionMultiplier = (int)Math.Pow(10, DecimalPointRandomPrecision); /// /// The IEEE-754 standard for double-precision floating-point numbers limits the number of digits (including both @@ -18,9 +20,6 @@ public class RandomUtil(ISptLogger _logger, ICloner _cloner) /// public const int MaxSignificantDigits = 15; - private static readonly int DecimalPointRandomPrecisionMultiplier = (int)Math.Pow(10, DecimalPointRandomPrecision); - public readonly Random Random = new(); - /// /// Generates a random integer between the specified minimum and maximum values, inclusive. /// diff --git a/Libraries/Core/Utils/Watermark.cs b/Libraries/Core/Utils/Watermark.cs index 84f07862..708bbe39 100644 --- a/Libraries/Core/Utils/Watermark.cs +++ b/Libraries/Core/Utils/Watermark.cs @@ -12,8 +12,8 @@ namespace Core.Utils; public class WatermarkLocale { protected List description; - protected List modding; protected List warning; + protected List modding; public WatermarkLocale(LocalisationService localisationService) { @@ -65,15 +65,15 @@ public class WatermarkLocale [Injectable] public class Watermark { - protected ConfigServer _configServer; - protected LocalisationService _localisationService; - - protected ISptLogger _logger; - protected WatermarkLocale _watermarkLocale; protected CoreConfig sptConfig; protected List text = []; protected string versionLabel = ""; + protected ISptLogger _logger; + protected ConfigServer _configServer; + protected LocalisationService _localisationService; + protected WatermarkLocale _watermarkLocale; + public Watermark( ISptLogger logger, ConfigServer configServer, diff --git a/Libraries/SptDependencyInjection/DependencyInjectionRegistrator.cs b/Libraries/SptDependencyInjection/DependencyInjectionRegistrator.cs index a16f1385..6594aba0 100644 --- a/Libraries/SptDependencyInjection/DependencyInjectionRegistrator.cs +++ b/Libraries/SptDependencyInjection/DependencyInjectionRegistrator.cs @@ -6,9 +6,6 @@ namespace SptDependencyInjection; public static class DependencyInjectionRegistrator { - private static List? _allLoadedTypes; - private static List? _allConstructors; - public static void RegisterModOverrideComponents(IServiceCollection builderServices, List assemblies) { // We get all the services from this assembly first, since mods will override them later @@ -56,6 +53,9 @@ public static class DependencyInjectionRegistrator ); } + private static List? _allLoadedTypes; + private static List? _allConstructors; + private static void RegisterGenericComponents(IServiceCollection builderServices, RegisterableType valueTuple) { _allLoadedTypes ??= AppDomain.CurrentDomain.GetAssemblies().SelectMany(t => t.GetTypes()).ToList(); diff --git a/Server/Logger/AbstractFormatter.cs b/Server/Logger/AbstractFormatter.cs index e8a26864..548e9e58 100644 --- a/Server/Logger/AbstractFormatter.cs +++ b/Server/Logger/AbstractFormatter.cs @@ -5,6 +5,13 @@ namespace Server.Logger; public abstract class AbstractFormatter : ITextFormatter { + protected abstract string ProcessText(string text); + + protected virtual string GetFormattedText(string timestamp, string logLevel, string sourceContext, string message) + { + return $"[{timestamp} {logLevel}][{sourceContext}] {message}"; + } + public void Format(LogEvent logEvent, TextWriter output) { var newLine = Environment.NewLine; @@ -16,11 +23,4 @@ public abstract class AbstractFormatter : ITextFormatter var logMessage = ProcessText(GetFormattedText(timestamp, logLevel, sourceContext, $"{message}{exception}")); output.WriteLine(logMessage); } - - protected abstract string ProcessText(string text); - - protected virtual string GetFormattedText(string timestamp, string logLevel, string sourceContext, string message) - { - return $"[{timestamp} {logLevel}][{sourceContext}] {message}"; - } } diff --git a/Server/Logger/ConsoleFormatter.cs b/Server/Logger/ConsoleFormatter.cs index 10ea329f..ceb9ecbe 100644 --- a/Server/Logger/ConsoleFormatter.cs +++ b/Server/Logger/ConsoleFormatter.cs @@ -2,8 +2,6 @@ namespace Server.Logger; public class ConsoleFormatter : AbstractFormatter { - public static ConsoleFormatter Default { get; } = new(); - protected override string ProcessText(string text) { return text; @@ -13,4 +11,6 @@ public class ConsoleFormatter : AbstractFormatter { return message; } + + public static ConsoleFormatter Default { get; } = new(); } diff --git a/Server/Logger/FileFormatter.cs b/Server/Logger/FileFormatter.cs index bafe62bb..25427abb 100644 --- a/Server/Logger/FileFormatter.cs +++ b/Server/Logger/FileFormatter.cs @@ -4,11 +4,11 @@ namespace Server.Logger; public class FileFormatter : AbstractFormatter { - public static FileFormatter Default { get; } = new(); - protected override string ProcessText(string message) { foreach (Match match in Regex.Matches(message, @"\x1b\[[0-9]{1,2}(;[0-1]{1,2}){0,1}m")) message = message.Replace(match.Value, ""); return message.Replace("\"", ""); } + + public static FileFormatter Default { get; } = new(); } diff --git a/Server/Logger/WebApplicationLogger.cs b/Server/Logger/WebApplicationLogger.cs index 800c303d..434823d1 100644 --- a/Server/Logger/WebApplicationLogger.cs +++ b/Server/Logger/WebApplicationLogger.cs @@ -29,6 +29,24 @@ public class SptWebApplicationLogger : ISptLogger _logger.LogInformation(ex, data); } + private string GetColorizedText( + string data, + LogTextColor? textColor = null, + LogBackgroundColor? backgroundColor = null + ) + { + var colorString = string.Empty; + if (textColor != null) + colorString += ((int)textColor.Value).ToString(); + + if (backgroundColor != null) + colorString += string.IsNullOrEmpty(colorString) + ? ((int)backgroundColor.Value).ToString() + : $";{((int)backgroundColor.Value).ToString()}"; + + return $"\x1b[{colorString}m{data}\x1b[0m"; + } + public void Success(string data, Exception? ex = null) { _logger.LogInformation(ex, GetColorizedText(data, LogTextColor.Green)); @@ -70,24 +88,6 @@ public class SptWebApplicationLogger : ISptLogger return _logger.IsEnabled(ConvertLogLevel(level)); } - private string GetColorizedText( - string data, - LogTextColor? textColor = null, - LogBackgroundColor? backgroundColor = null - ) - { - var colorString = string.Empty; - if (textColor != null) - colorString += ((int)textColor.Value).ToString(); - - if (backgroundColor != null) - colorString += string.IsNullOrEmpty(colorString) - ? ((int)backgroundColor.Value).ToString() - : $";{((int)backgroundColor.Value).ToString()}"; - - return $"\x1b[{colorString}m{data}\x1b[0m"; - } - protected Microsoft.Extensions.Logging.LogLevel ConvertLogLevel(LogLevel level) { return level switch diff --git a/Tools/ItemTplGenerator/ItemTplGenerator.cs b/Tools/ItemTplGenerator/ItemTplGenerator.cs index c9c4d877..11b749e6 100644 --- a/Tools/ItemTplGenerator/ItemTplGenerator.cs +++ b/Tools/ItemTplGenerator/ItemTplGenerator.cs @@ -22,10 +22,10 @@ public class ItemTplGenerator( IEnumerable _onLoadComponents ) { - private HashSet collidedEnumKeys = []; private string enumDir; - private IDictionary itemOverrides; private Dictionary items; + private IDictionary itemOverrides; + private HashSet collidedEnumKeys = []; public async Task Run() { diff --git a/UnitTests/Mock/MockLogger.cs b/UnitTests/Mock/MockLogger.cs index a15e9fba..57449f47 100644 --- a/UnitTests/Mock/MockLogger.cs +++ b/UnitTests/Mock/MockLogger.cs @@ -6,6 +6,16 @@ namespace UnitTests.Mock; public class MockLogger : ISptLogger { + public void LogWithColor( + string data, + Exception? ex = null, + LogTextColor? textColor = null, + LogBackgroundColor? backgroundColor = null + ) + { + Console.WriteLine(data); + } + public void LogWithColor(string data, LogTextColor? textColor = null, LogBackgroundColor? backgroundColor = null, Exception? ex = null) { throw new NotImplementedException(); @@ -51,16 +61,6 @@ public class MockLogger : ISptLogger return true; } - public void LogWithColor( - string data, - Exception? ex = null, - LogTextColor? textColor = null, - LogBackgroundColor? backgroundColor = null - ) - { - Console.WriteLine(data); - } - public void WriteToLogFile(object body) { Console.WriteLine(body);