Handle ToLower neutrally across all locales (#412)

This commit is contained in:
Archangel
2025-07-03 18:27:41 +02:00
parent 939198026f
commit 79489eadce
38 changed files with 106 additions and 104 deletions
@@ -30,7 +30,7 @@ public class BotCallbacks(BotController _botController, HttpResponseUtil _httpRe
public ValueTask<string> GetBotDifficulty(string url, EmptyRequestData _, string sessionID) public ValueTask<string> GetBotDifficulty(string url, EmptyRequestData _, string sessionID)
{ {
var splitUrl = url.Split('/'); var splitUrl = url.Split('/');
var type = splitUrl[^2].ToLower(); var type = splitUrl[^2].ToLowerInvariant();
var difficulty = splitUrl[^1]; var difficulty = splitUrl[^1];
if (difficulty == "core") if (difficulty == "core")
{ {
@@ -88,7 +88,7 @@ public class BotController(
bool ignoreRaidSettings = false bool ignoreRaidSettings = false
) )
{ {
var difficulty = diffLevel.ToLower(); var difficulty = diffLevel.ToLowerInvariant();
var raidConfig = _profileActivityService var raidConfig = _profileActivityService
.GetProfileActivityRaidData(sessionId) .GetProfileActivityRaidData(sessionId)
@@ -107,7 +107,7 @@ public class BotController(
// Check value chosen in pre-raid difficulty dropdown // Check value chosen in pre-raid difficulty dropdown
// If value is not 'asonline', change requested difficulty to be what was chosen in dropdown // If value is not 'asonline', change requested difficulty to be what was chosen in dropdown
var botDifficultyDropDownValue = var botDifficultyDropDownValue =
raidConfig?.WavesSettings?.BotDifficulty?.ToString().ToLower() ?? "asonline"; raidConfig?.WavesSettings?.BotDifficulty?.ToString().ToLowerInvariant() ?? "asonline";
if (botDifficultyDropDownValue != "asonline") if (botDifficultyDropDownValue != "asonline")
{ {
difficulty = _botDifficultyHelper.ConvertBotDifficultyDropdownToBotDifficulty( difficulty = _botDifficultyHelper.ConvertBotDifficultyDropdownToBotDifficulty(
@@ -138,8 +138,8 @@ public class BotController(
{ {
// If bot is usec/bear, swap to different name // If bot is usec/bear, swap to different name
var botTypeLower = botType.IsPmc() var botTypeLower = botType.IsPmc()
? (botType.GetPmcSideByRole() ?? "usec").ToLower() ? (botType.GetPmcSideByRole() ?? "usec").ToLowerInvariant()
: botType.ToString().ToLower(); : botType.ToString().ToLowerInvariant();
// Get details from db // Get details from db
if (!botTypesDb.TryGetValue(botTypeLower, out var botDetails)) if (!botTypesDb.TryGetValue(botTypeLower, out var botDetails))
@@ -165,7 +165,7 @@ public class BotController(
continue; continue;
} }
var botNameKey = botType.ToString().ToLower(); var botNameKey = botType.ToString().ToLowerInvariant();
foreach (var (difficultyName, _) in botDetails.BotDifficulty) foreach (var (difficultyName, _) in botDetails.BotDifficulty)
{ {
// Bot doesn't exist in result, add // Bot doesn't exist in result, add
@@ -378,7 +378,7 @@ public class BotController(
protected MinMax<int> GetPmcLevelRangeForMap(string? location) protected MinMax<int> GetPmcLevelRangeForMap(string? location)
{ {
return _pmcConfig.LocationSpecificPmcLevelOverride!.GetValueOrDefault( return _pmcConfig.LocationSpecificPmcLevelOverride!.GetValueOrDefault(
location?.ToLower() ?? "", location?.ToLowerInvariant() ?? "",
null null
); );
} }
@@ -430,7 +430,7 @@ public class BotController(
/// <returns>bot cap for map</returns> /// <returns>bot cap for map</returns>
public int GetBotCap(string location) public int GetBotCap(string location)
{ {
if (!_botConfig.MaxBotCap.TryGetValue(location.ToLower(), out var maxCap)) if (!_botConfig.MaxBotCap.TryGetValue(location.ToLowerInvariant(), out var maxCap))
{ {
return _botConfig.MaxBotCap["default"]; return _botConfig.MaxBotCap["default"];
} }
@@ -440,7 +440,7 @@ public class BotController(
_logger.Warning( _logger.Warning(
_serverLocalisationService.GetText( _serverLocalisationService.GetText(
"bot-no_bot_cap_found_for_location", "bot-no_bot_cap_found_for_location",
location.ToLower() location.ToLowerInvariant()
) )
); );
} }
@@ -872,7 +872,7 @@ public class InsuranceController(
{ {
var softInsertSlots = pmcData.Inventory.Items.Where(item => var softInsertSlots = pmcData.Inventory.Items.Where(item =>
item.ParentId == itemWithSoftInserts.Id item.ParentId == itemWithSoftInserts.Id
&& _itemHelper.IsSoftInsertId(item.SlotId.ToLower()) && _itemHelper.IsSoftInsertId(item.SlotId.ToLowerInvariant())
); );
foreach (var softInsertSlot in softInsertSlots) foreach (var softInsertSlot in softInsertSlots)
@@ -168,7 +168,7 @@ public class LauncherController(
var timeStampStr = Convert.ToString(timeStamp, 16).PadLeft(8, '0'); var timeStampStr = Convert.ToString(timeStamp, 16).PadLeft(8, '0');
var counterStr = Convert.ToString(counter, 16).PadLeft(16, '0'); var counterStr = Convert.ToString(counter, 16).PadLeft(16, '0');
return timeStampStr.ToLower() + counterStr.ToLower(); return timeStampStr.ToLowerInvariant() + counterStr.ToLowerInvariant();
} }
/// <summary> /// <summary>
@@ -196,7 +196,7 @@ public class LauncherV2Controller(
var timeStampStr = Convert.ToString(timeStamp, 16).PadLeft(8, '0'); var timeStampStr = Convert.ToString(timeStamp, 16).PadLeft(8, '0');
var counterStr = Convert.ToString(counter, 16).PadLeft(16, '0'); var counterStr = Convert.ToString(counter, 16).PadLeft(16, '0');
return timeStampStr.ToLower() + counterStr.ToLower(); return timeStampStr.ToLowerInvariant() + counterStr.ToLowerInvariant();
} }
protected string? GetSessionId(LoginRequestData info) protected string? GetSessionId(LoginRequestData info)
@@ -171,7 +171,7 @@ public class ProfileController(
var pmcData = _profileHelper.GetPmcProfile(sessionId); var pmcData = _profileHelper.GetPmcProfile(sessionId);
pmcData.Info.Nickname = request.Nickname; pmcData.Info.Nickname = request.Nickname;
pmcData.Info.LowerNickname = request.Nickname.ToLower(); pmcData.Info.LowerNickname = request.Nickname.ToLowerInvariant();
} }
return output; return output;
@@ -207,7 +207,7 @@ public class ProfileController(
foreach (var profile in allProfiles) foreach (var profile in allProfiles)
{ {
var pmcProfile = profile?.CharacterData?.PmcData; var pmcProfile = profile?.CharacterData?.PmcData;
if (!pmcProfile?.Info?.LowerNickname?.Contains(request.Nickname.ToLower()) ?? false) if (!pmcProfile?.Info?.LowerNickname?.Contains(request.Nickname.ToLowerInvariant()) ?? false)
{ {
continue; continue;
} }
@@ -137,7 +137,7 @@ public class RepeatableQuestController(
} }
// Subtype name of quest - daily/weekly/scav // Subtype name of quest - daily/weekly/scav
var repeatableTypeLower = repeatablesOfTypeInProfile.Name.ToLower(); var repeatableTypeLower = repeatablesOfTypeInProfile.Name.ToLowerInvariant();
// Save for later standing loss calculation // Save for later standing loss calculation
var replacedQuestTraderId = questToReplace.TraderId; var replacedQuestTraderId = questToReplace.TraderId;
@@ -575,7 +575,7 @@ public class RepeatableQuestController(
repeatableConfig, repeatableConfig,
pmcData pmcData
); );
var repeatableTypeLower = repeatableConfig.Name.ToLower(); var repeatableTypeLower = repeatableConfig.Name.ToLowerInvariant();
var canAccessRepeatables = CanProfileAccessRepeatableQuests(repeatableConfig, pmcData); var canAccessRepeatables = CanProfileAccessRepeatableQuests(repeatableConfig, pmcData);
if (!canAccessRepeatables) if (!canAccessRepeatables)
@@ -158,7 +158,7 @@ namespace SPTarkov.Server.Core.Extensions
} }
// Dev profile additions // Dev profile additions
if (fullProfile.ProfileInfo.Edition.ToLower().Contains("developer")) if (fullProfile.ProfileInfo.Edition.ToLowerInvariant().Contains("developer"))
// CyberTark background // CyberTark background
{ {
fullProfile.CustomisationUnlocks.Add( fullProfile.CustomisationUnlocks.Add(
@@ -185,7 +185,7 @@ namespace SPTarkov.Server.Core.Extensions
// Edge case - profile not created yet, fall back to what launcher has set // Edge case - profile not created yet, fall back to what launcher has set
var launcherEdition = fullProfile.ProfileInfo.Edition; var launcherEdition = fullProfile.ProfileInfo.Edition;
switch (launcherEdition.ToLower()) switch (launcherEdition.ToLowerInvariant())
{ {
case "edge of darkness": case "edge of darkness":
return GameEditions.EDGE_OF_DARKNESS; return GameEditions.EDGE_OF_DARKNESS;
@@ -174,12 +174,12 @@ public class BotEquipmentModGenerator(
// Slot can hold armor plates + we are filtering possible items by bot level, handle // Slot can hold armor plates + we are filtering possible items by bot level, handle
if ( if (
settings.BotEquipmentConfig.FilterPlatesByLevel.GetValueOrDefault(false) settings.BotEquipmentConfig.FilterPlatesByLevel.GetValueOrDefault(false)
&& _itemHelper.IsRemovablePlateSlot(modSlotName.ToLower()) && _itemHelper.IsRemovablePlateSlot(modSlotName.ToLowerInvariant())
) )
{ {
var plateSlotFilteringOutcome = FilterPlateModsForSlotByLevel( var plateSlotFilteringOutcome = FilterPlateModsForSlotByLevel(
settings, settings,
modSlotName.ToLower(), modSlotName.ToLowerInvariant(),
compatibleModsPool.GetValueOrDefault(modSlotName), compatibleModsPool.GetValueOrDefault(modSlotName),
parentTemplate parentTemplate
); );
@@ -889,7 +889,7 @@ public class BotEquipmentModGenerator(
/// <returns>true if it can hold a scope</returns> /// <returns>true if it can hold a scope</returns>
public bool ModSlotCanHoldScope(string modSlot, string modsParentId) public bool ModSlotCanHoldScope(string modSlot, string modsParentId)
{ {
return _scopeIds.Contains(modSlot.ToLower()) && modsParentId == BaseClasses.MOUNT; return _scopeIds.Contains(modSlot.ToLowerInvariant()) && modsParentId == BaseClasses.MOUNT;
} }
/// <summary> /// <summary>
@@ -932,7 +932,7 @@ public class BotEquipmentModGenerator(
/// <returns>True if modSlot can have muzzle-related items</returns> /// <returns>True if modSlot can have muzzle-related items</returns>
public bool ModSlotCanHoldMuzzleDevices(string modSlot, string? modsParentId) public bool ModSlotCanHoldMuzzleDevices(string modSlot, string? modsParentId)
{ {
return _muzzleIds.Contains(modSlot.ToLower()); return _muzzleIds.Contains(modSlot.ToLowerInvariant());
} }
/// <summary> /// <summary>
@@ -1057,7 +1057,7 @@ public class BotEquipmentModGenerator(
/// <returns>Slot item</returns> /// <returns>Slot item</returns>
public Slot? GetModItemSlotFromDb(string modSlot, TemplateItem parentTemplate) public Slot? GetModItemSlotFromDb(string modSlot, TemplateItem parentTemplate)
{ {
var modSlotLower = modSlot.ToLower(); var modSlotLower = modSlot.ToLowerInvariant();
switch (modSlotLower) switch (modSlotLower)
{ {
case "patron_in_weapon": case "patron_in_weapon":
@@ -1100,7 +1100,7 @@ public class BotEquipmentModGenerator(
} }
var spawnMod = _randomUtil.RollChance( var spawnMod = _randomUtil.RollChance(
modSpawnChances.GetValueOrDefault(modSlotName.ToLower()) modSpawnChances.GetValueOrDefault(modSlotName.ToLowerInvariant())
); );
if ( if (
!spawnMod !spawnMod
@@ -1556,8 +1556,8 @@ public class BotEquipmentModGenerator(
var parentSlotCompatibleItems = request var parentSlotCompatibleItems = request
.ParentTemplate.Properties.Slots?.FirstOrDefault(slot => .ParentTemplate.Properties.Slots?.FirstOrDefault(slot =>
string.Equals( string.Equals(
slot.Name.ToLower(), slot.Name.ToLowerInvariant(),
request.ModSlot.ToLower(), request.ModSlot.ToLowerInvariant(),
StringComparison.Ordinal StringComparison.Ordinal
) )
) )
@@ -188,7 +188,7 @@ public class BotGenerator(
BotGenerationDetails botGenerationDetails BotGenerationDetails botGenerationDetails
) )
{ {
var botRoleLowercase = botGenerationDetails.Role.ToLower(); var botRoleLowercase = botGenerationDetails.Role.ToLowerInvariant();
var botLevel = _botLevelGenerator.GenerateBotLevel( var botLevel = _botLevelGenerator.GenerateBotLevel(
botJsonTemplate.BotExperience.Level, botJsonTemplate.BotExperience.Level,
botGenerationDetails, botGenerationDetails,
@@ -215,7 +215,7 @@ public class BotGenerator(
// Only Pmcs should have a lower nickname // Only Pmcs should have a lower nickname
bot.Info.LowerNickname = botGenerationDetails.IsPmc.GetValueOrDefault(false) bot.Info.LowerNickname = botGenerationDetails.IsPmc.GetValueOrDefault(false)
? bot.Info.Nickname.ToLower() ? bot.Info.Nickname.ToLowerInvariant()
: string.Empty; : string.Empty;
// Only run when generating a 'fake' playerscav, not actual player scav // Only run when generating a 'fake' playerscav, not actual player scav
@@ -351,7 +351,7 @@ public class BotGenerator(
string role string role
) )
{ {
if (!experiences.TryGetValue(botDifficulty.ToLower(), out var result)) if (!experiences.TryGetValue(botDifficulty.ToLowerInvariant(), out var result))
{ {
if (_logger.IsLogEnabled(LogLevel.Debug)) if (_logger.IsLogEnabled(LogLevel.Debug))
{ {
@@ -386,7 +386,7 @@ public class BotGenerator(
string role string role
) )
{ {
if (!standingsForKill.TryGetValue(botDifficulty.ToLower(), out var result)) if (!standingsForKill.TryGetValue(botDifficulty.ToLowerInvariant(), out var result))
{ {
_logger.Warning( _logger.Warning(
$"Unable to find standing for kill value for: {role} {botDifficulty}, falling back to `normal`" $"Unable to find standing for kill value for: {role} {botDifficulty}, falling back to `normal`"
@@ -411,7 +411,7 @@ public class BotGenerator(
string role string role
) )
{ {
if (!aggressorBonuses.TryGetValue(botDifficulty.ToLower(), out var result)) if (!aggressorBonuses.TryGetValue(botDifficulty.ToLowerInvariant(), out var result))
{ {
_logger.Warning( _logger.Warning(
$"Unable to find aggressor bonus for kill value for: {role} {botDifficulty}, falling back to `normal`" $"Unable to find aggressor bonus for kill value for: {role} {botDifficulty}, falling back to `normal`"
@@ -115,7 +115,7 @@ public class BotLootGenerator(
var grenadeCount = _weightedRandomHelper.GetWeightedValue(itemCounts.Grenades.Weights); var grenadeCount = _weightedRandomHelper.GetWeightedValue(itemCounts.Grenades.Weights);
// If bot has been flagged as not having loot, set below counts to 0 // If bot has been flagged as not having loot, set below counts to 0
if (_botConfig.DisableLootOnBotTypes.Contains(botRole.ToLower())) if (_botConfig.DisableLootOnBotTypes.Contains(botRole.ToLowerInvariant()))
{ {
backpackLootCount = 0; backpackLootCount = 0;
pocketLootCount = 0; pocketLootCount = 0;
@@ -945,9 +945,9 @@ public class BotLootGenerator(
return _botConfig.ItemSpawnLimits["pmc"]; return _botConfig.ItemSpawnLimits["pmc"];
} }
if (_botConfig.ItemSpawnLimits.ContainsKey(botRole.ToLower())) if (_botConfig.ItemSpawnLimits.ContainsKey(botRole.ToLowerInvariant()))
{ {
return _botConfig.ItemSpawnLimits[botRole.ToLower()]; return _botConfig.ItemSpawnLimits[botRole.ToLowerInvariant()];
} }
_logger.Warning( _logger.Warning(
@@ -58,7 +58,7 @@ public class LocationLootGenerator(
// Pull location-specific spawn limits from db // Pull location-specific spawn limits from db
var itemsWithSpawnCountLimitsClone = _cloner.Clone( var itemsWithSpawnCountLimitsClone = _cloner.Clone(
_locationConfig.LootMaxSpawnLimits.GetValueOrDefault(locationId.ToLower()) _locationConfig.LootMaxSpawnLimits.GetValueOrDefault(locationId.ToLowerInvariant())
); );
// Store items with spawn count limits inside so they can be accessed later inside static/dynamic loot spawn methods // Store items with spawn count limits inside so they can be accessed later inside static/dynamic loot spawn methods
@@ -68,13 +68,13 @@ public class LocationLootGenerator(
} }
// Create containers with loot // Create containers with loot
result.AddRange(GenerateStaticContainers(locationId.ToLower(), staticAmmoDist)); result.AddRange(GenerateStaticContainers(locationId.ToLowerInvariant(), staticAmmoDist));
// Add dynamic loot to output loot // Add dynamic loot to output loot
var dynamicSpawnPoints = GenerateDynamicLoot( var dynamicSpawnPoints = GenerateDynamicLoot(
_cloner.Clone(locationDetails.LooseLoot.Value), _cloner.Clone(locationDetails.LooseLoot.Value),
staticAmmoDist, staticAmmoDist,
locationId.ToLower() locationId.ToLowerInvariant()
); );
// Merge dynamic spawns into result // Merge dynamic spawns into result
@@ -80,7 +80,7 @@ public class PlayerScavGenerator(
var scavData = _botGenerator.GeneratePlayerScav( var scavData = _botGenerator.GeneratePlayerScav(
sessionID, sessionID,
playerScavKarmaSettings.BotTypeForLoot.ToLower(), playerScavKarmaSettings.BotTypeForLoot.ToLowerInvariant(),
"easy", "easy",
baseBotNode, baseBotNode,
pmcDataClone pmcDataClone
@@ -58,7 +58,7 @@ public class PmcWaveGenerator(
/// <param name="location"> Location Object </param> /// <param name="location"> Location Object </param>
public void ApplyWaveChangesToMap(LocationBase location) public void ApplyWaveChangesToMap(LocationBase location)
{ {
if (!_pmcConfig.CustomPmcWaves.TryGetValue(location.Id.ToLower(), out var pmcWavesToAdd)) if (!_pmcConfig.CustomPmcWaves.TryGetValue(location.Id.ToLowerInvariant(), out var pmcWavesToAdd))
{ {
return; return;
} }
@@ -495,7 +495,7 @@ public class RagfairOfferGenerator(
} }
var plateSlots = presetWithChildren var plateSlots = presetWithChildren
.Where(item => itemHelper.GetRemovablePlateSlotIds().Contains(item.SlotId?.ToLower())) .Where(item => itemHelper.GetRemovablePlateSlotIds().Contains(item.SlotId?.ToLowerInvariant()))
.ToList(); .ToList();
if (plateSlots.Count == 0) if (plateSlots.Count == 0)
// Has no plate slots e.g. "front_plate", exit // Has no plate slots e.g. "front_plate", exit
@@ -507,7 +507,7 @@ public class RagfairOfferGenerator(
foreach (var plateSlot in plateSlots) foreach (var plateSlot in plateSlots)
{ {
var plateDetails = itemHelper.GetItem(plateSlot.Template).Value; var plateDetails = itemHelper.GetItem(plateSlot.Template).Value;
if (plateSettings.IgnoreSlots.Contains(plateSlot.SlotId.ToLower())) if (plateSettings.IgnoreSlots.Contains(plateSlot.SlotId.ToLowerInvariant()))
{ {
continue; continue;
} }
@@ -631,7 +631,7 @@ public class RagfairOfferGenerator(
} }
var offerItemPlatesToRemove = itemWithChildren.Where(item => var offerItemPlatesToRemove = itemWithChildren.Where(item =>
armorConfig.PlateSlotIdToRemovePool.Contains(item.SlotId?.ToLower()) armorConfig.PlateSlotIdToRemovePool.Contains(item.SlotId?.ToLowerInvariant())
); );
// Latest first, to ensure we don't move later items off by 1 each time we remove an item below it // Latest first, to ensure we don't move later items off by 1 each time we remove an item below it
@@ -211,7 +211,7 @@ public class ExplorationQuestGenerator(
/// <returns>List of Exit objects</returns> /// <returns>List of Exit objects</returns>
protected List<Exit>? GetLocationExitsForSide(string locationKey, PlayerGroup playerGroup) protected List<Exit>? GetLocationExitsForSide(string locationKey, PlayerGroup playerGroup)
{ {
var mapExtracts = databaseService.GetLocation(locationKey.ToLower())?.AllExtracts; var mapExtracts = databaseService.GetLocation(locationKey.ToLowerInvariant())?.AllExtracts;
return mapExtracts?.Where(exit => exit.Side == Enum.GetName(playerGroup)).ToList(); return mapExtracts?.Where(exit => exit.Side == Enum.GetName(playerGroup)).ToList();
} }
@@ -37,8 +37,8 @@ public class BotDifficultyHelper(
) )
{ {
var desiredType = _botHelper.IsBotPmc(type) var desiredType = _botHelper.IsBotPmc(type)
? _botHelper.GetPmcSideByRole(type).ToLower() ? _botHelper.GetPmcSideByRole(type).ToLowerInvariant()
: type.ToLower(); : type.ToLowerInvariant();
if (!botDb.Types.ContainsKey(desiredType)) if (!botDb.Types.ContainsKey(desiredType))
{ {
// No bot found, get fallback difficulty values // No bot found, get fallback difficulty values
@@ -85,7 +85,7 @@ public class BotDifficultyHelper(
StringComparison.OrdinalIgnoreCase StringComparison.OrdinalIgnoreCase
) )
? difficulty ? difficulty
: _pmcConfig.Difficulty.ToLower(); : _pmcConfig.Difficulty.ToLowerInvariant();
difficultySetting = ConvertBotDifficultyDropdownToBotDifficulty(difficultySetting); difficultySetting = ConvertBotDifficultyDropdownToBotDifficulty(difficultySetting);
@@ -101,14 +101,14 @@ public class BotDifficultyHelper(
/// <returns>bot difficulty</returns> /// <returns>bot difficulty</returns>
public string ConvertBotDifficultyDropdownToBotDifficulty(string dropDownDifficulty) public string ConvertBotDifficultyDropdownToBotDifficulty(string dropDownDifficulty)
{ {
switch (dropDownDifficulty.ToLower()) switch (dropDownDifficulty.ToLowerInvariant())
{ {
case "medium": case "medium":
return "normal"; return "normal";
case "random": case "random":
return ChooseRandomDifficulty(); return ChooseRandomDifficulty();
default: default:
return dropDownDifficulty.ToLower(); return dropDownDifficulty.ToLowerInvariant();
} }
} }
@@ -37,7 +37,7 @@ public class BotGeneratorHelper(
EquipmentSlots.ArmBand.ToString(), EquipmentSlots.ArmBand.ToString(),
]; ];
private static readonly string[] _pmcTypes = [Sides.PmcBear.ToLower(), Sides.PmcUsec.ToLower()]; private static readonly string[] _pmcTypes = [Sides.PmcBear.ToLowerInvariant(), Sides.PmcUsec.ToLowerInvariant()];
private readonly BotConfig _botConfig = _configServer.GetConfig<BotConfig>(); private readonly BotConfig _botConfig = _configServer.GetConfig<BotConfig>();
@@ -22,10 +22,10 @@ public class BotHelper(
{ {
private static readonly FrozenSet<string> _pmcTypeIds = private static readonly FrozenSet<string> _pmcTypeIds =
[ [
Sides.Usec.ToLower(), Sides.Usec.ToLowerInvariant(),
Sides.Bear.ToLower(), Sides.Bear.ToLowerInvariant(),
Sides.PmcBear.ToLower(), Sides.PmcBear.ToLowerInvariant(),
Sides.PmcUsec.ToLower(), Sides.PmcUsec.ToLowerInvariant(),
]; ];
private readonly BotConfig _botConfig = _configServer.GetConfig<BotConfig>(); private readonly BotConfig _botConfig = _configServer.GetConfig<BotConfig>();
@@ -39,7 +39,7 @@ public class BotHelper(
/// <returns>BotType object</returns> /// <returns>BotType object</returns>
public BotType? GetBotTemplate(string role) public BotType? GetBotTemplate(string role)
{ {
if (!_databaseService.GetBots().Types.TryGetValue(role?.ToLower(), out var bot)) if (!_databaseService.GetBots().Types.TryGetValue(role?.ToLowerInvariant(), out var bot))
{ {
_logger.Error($"Unable to get bot of type: {role} from DB"); _logger.Error($"Unable to get bot of type: {role} from DB");
@@ -56,7 +56,7 @@ public class BotHelper(
/// <returns>true if is pmc</returns> /// <returns>true if is pmc</returns>
public bool IsBotPmc(string? botRole) public bool IsBotPmc(string? botRole)
{ {
return _pmcTypeIds.Contains(botRole?.ToLower()); return _pmcTypeIds.Contains(botRole?.ToLowerInvariant());
} }
public bool IsBotBoss(string botRole) public bool IsBotBoss(string botRole)
@@ -135,10 +135,10 @@ public class BotHelper(
{ {
HashSet<string> listToCheck = HashSet<string> listToCheck =
[ [
_pmcConfig.UsecType.ToLower(), _pmcConfig.UsecType.ToLowerInvariant(),
_pmcConfig.BearType.ToLower(), _pmcConfig.BearType.ToLowerInvariant(),
]; ];
return listToCheck.Contains(botRole.ToLower()); return listToCheck.Contains(botRole.ToLowerInvariant());
} }
/// <summary> /// <summary>
@@ -227,7 +227,7 @@ public class BotHelper(
) )
{ {
_logger.Error($"Unknown faction: {chosenFaction} Defaulting to: {Sides.Usec}"); _logger.Error($"Unknown faction: {chosenFaction} Defaulting to: {Sides.Usec}");
chosenFaction = Sides.Usec.ToLower(); chosenFaction = Sides.Usec.ToLowerInvariant();
chosenFactionDetails = _databaseService.GetBots().Types[chosenFaction]; chosenFactionDetails = _databaseService.GetBots().Types[chosenFaction];
} }
@@ -157,7 +157,7 @@ public class GiveSptCommand(
.Select(i => .Select(i =>
localizedGlobal localizedGlobal
.GetValueOrDefault($"{i.Id} Name", i.Properties.Name) .GetValueOrDefault($"{i.Id} Name", i.Properties.Name)
?.ToLower() ?.ToLowerInvariant()
) )
.Where(i => !string.IsNullOrEmpty(i)); .Where(i => !string.IsNullOrEmpty(i));
@@ -210,7 +210,7 @@ public class GiveSptCommand(
.GetItems() .GetItems()
.Where(IsItemAllowed) .Where(IsItemAllowed)
.FirstOrDefault(i => .FirstOrDefault(i =>
(localizedGlobal[$"{i?.Id} Name"]?.ToLower() ?? i.Properties.Name) == item (localizedGlobal[$"{i?.Id} Name"]?.ToLowerInvariant() ?? i.Properties.Name) == item
) )
.Id .Id
: item; : item;
@@ -14,8 +14,8 @@ public static class StringSimilarity
{ {
if (!caseSensitive) if (!caseSensitive)
{ {
str1 = str1.ToLower(); str1 = str1.ToLowerInvariant();
str2 = str2.ToLower(); str2 = str2.ToLowerInvariant();
} }
if (str1.Length < substringLength || str2.Length < substringLength) if (str1.Length < substringLength || str2.Length < substringLength)
@@ -1303,7 +1303,7 @@ public class InventoryHelper(
// Reset fast panel value if item was moved to a container other than pocket/rig (cant be used from fastpanel) // Reset fast panel value if item was moved to a container other than pocket/rig (cant be used from fastpanel)
HashSet<string> slots = ["pockets", "tacticalvest"]; HashSet<string> slots = ["pockets", "tacticalvest"];
var wasMovedToFastPanelAccessibleContainer = slots.Contains( var wasMovedToFastPanelAccessibleContainer = slots.Contains(
itemParent?.SlotId?.ToLower() ?? "" itemParent?.SlotId?.ToLowerInvariant() ?? ""
); );
if (!wasMovedToFastPanelAccessibleContainer) if (!wasMovedToFastPanelAccessibleContainer)
{ {
@@ -359,7 +359,7 @@ public class ItemHelper(
var itemTemplate = GetItem(itemTpl); var itemTemplate = GetItem(itemTpl);
return itemTemplate.Value.Properties.Slots.Any(slot => return itemTemplate.Value.Properties.Slots.Any(slot =>
_removablePlateSlotIds.Contains(slot.Name.ToLower()) _removablePlateSlotIds.Contains(slot.Name.ToLowerInvariant())
); );
} }
@@ -390,7 +390,7 @@ public class ItemHelper(
} }
// Check if item has slots that match soft insert name ids // Check if item has slots that match soft insert name ids
if (itemDbDetails.Value.Properties.Slots.Any(slot => IsSoftInsertId(slot.Name.ToLower()))) if (itemDbDetails.Value.Properties.Slots.Any(slot => IsSoftInsertId(slot.Name.ToLowerInvariant())))
{ {
return true; return true;
} }
@@ -1782,9 +1782,9 @@ public class ItemHelper(
if (modSpawnChanceDict is not null && !(slot.Required ?? false)) if (modSpawnChanceDict is not null && !(slot.Required ?? false))
{ {
// only roll chance to not include mod if dict exists and has value for this mod type (e.g. front_plate) // only roll chance to not include mod if dict exists and has value for this mod type (e.g. front_plate)
if (modSpawnChanceDict.ContainsKey(slot.Name.ToLower())) if (modSpawnChanceDict.ContainsKey(slot.Name.ToLowerInvariant()))
{ {
if (!_randomUtil.GetChance100(modSpawnChanceDict[slot.Name.ToLower()])) if (!_randomUtil.GetChance100(modSpawnChanceDict[slot.Name.ToLowerInvariant()]))
{ {
continue; continue;
} }
@@ -1885,7 +1885,7 @@ public class ItemHelper(
/// <returns>True if it is a slot that holds a removable plate</returns> /// <returns>True if it is a slot that holds a removable plate</returns>
public bool IsRemovablePlateSlot(string slotName) public bool IsRemovablePlateSlot(string slotName)
{ {
return GetRemovablePlateSlotIds().Contains(slotName.ToLower()); return GetRemovablePlateSlotIds().Contains(slotName.ToLowerInvariant());
} }
// Get a list of slot names that hold removable plates // Get a list of slot names that hold removable plates
@@ -123,8 +123,8 @@ public class ProfileHelper(
&& !StringsMatch(p.ProfileInfo.ProfileId, sessionID) && !StringsMatch(p.ProfileInfo.ProfileId, sessionID)
&& // SessionIds dont match && // SessionIds dont match
StringsMatch( StringsMatch(
p.CharacterData.PmcData.Info.LowerNickname.ToLower(), p.CharacterData.PmcData.Info.LowerNickname.ToLowerInvariant(),
nicknameRequest.Nickname.ToLower() nicknameRequest.Nickname.ToLowerInvariant()
) )
); // Nicknames do ); // Nicknames do
} }
@@ -564,7 +564,7 @@ public class ProfileHelper(
public bool IsDeveloperAccount(string sessionID) public bool IsDeveloperAccount(string sessionID)
{ {
return GetFullProfile(sessionID) return GetFullProfile(sessionID)
?.ProfileInfo?.Edition?.ToLower() ?.ProfileInfo?.Edition?.ToLowerInvariant()
.StartsWith("spt developer") ?? false; .StartsWith("spt developer") ?? false;
} }
@@ -28,7 +28,7 @@ public class ImageRouter
public void AddRoute(string key, string valueToAdd) public void AddRoute(string key, string valueToAdd)
{ {
_imageRouterService.AddRoute(key.ToLower(), valueToAdd); _imageRouterService.AddRoute(key.ToLowerInvariant(), valueToAdd);
} }
public async Task SendImage(string sessionId, HttpRequest req, HttpResponse resp, object body) public async Task SendImage(string sessionId, HttpRequest req, HttpResponse resp, object body)
@@ -37,7 +37,7 @@ public class ImageRouter
var url = _fileUtil.StripExtension(req.Path, true); var url = _fileUtil.StripExtension(req.Path, true);
// Send image // Send image
var urlKeyLower = url.ToLower(); var urlKeyLower = url.ToLowerInvariant();
if (_imageRouterService.ExistsByKey(urlKeyLower)) if (_imageRouterService.ExistsByKey(urlKeyLower))
{ {
await _httpFileUtil.SendFile(resp, _imageRouterService.GetByKey(urlKeyLower)); await _httpFileUtil.SendFile(resp, _imageRouterService.GetByKey(urlKeyLower));
@@ -51,7 +51,7 @@ public class BotEquipmentFilterService(
); );
RandomisationDetails? randomisationDetails = null; RandomisationDetails? randomisationDetails = null;
if (_botEquipmentConfig.TryGetValue(botRole.ToLower(), out var botEquipmentConfig)) if (_botEquipmentConfig.TryGetValue(botRole.ToLowerInvariant(), out var botEquipmentConfig))
{ {
randomisationDetails = botHelper.GetBotRandomizationDetails( randomisationDetails = botHelper.GetBotRandomizationDetails(
botLevel, botLevel,
@@ -115,6 +115,6 @@ public class BotGenerationCacheService(
public string CreateCacheKey(string? role, string? difficulty) public string CreateCacheKey(string? role, string? difficulty)
{ {
return $"{role?.ToLower()}{difficulty?.ToLower()}"; return $"{role?.ToLowerInvariant()}{difficulty?.ToLowerInvariant()}";
} }
} }
@@ -53,7 +53,7 @@ public class BotNameService(
var showTypeInNickname = var showTypeInNickname =
!botGenerationDetails.IsPlayerScav.GetValueOrDefault(false) !botGenerationDetails.IsPlayerScav.GetValueOrDefault(false)
&& _botConfig.ShowTypeInNickname; && _botConfig.ShowTypeInNickname;
var roleShouldBeUnique = uniqueRoles?.Contains(botRole.ToLower()); var roleShouldBeUnique = uniqueRoles?.Contains(botRole.ToLowerInvariant());
var attempts = 0; var attempts = 0;
while (attempts <= 5) while (attempts <= 5)
@@ -55,7 +55,7 @@ public class CreateProfileService(
pmcData.Savage = account.ProfileInfo.ScavengerId; pmcData.Savage = account.ProfileInfo.ScavengerId;
pmcData.SessionId = sessionId; pmcData.SessionId = sessionId;
pmcData.Info.Nickname = request.Nickname; pmcData.Info.Nickname = request.Nickname;
pmcData.Info.LowerNickname = request.Nickname.ToLower(); pmcData.Info.LowerNickname = request.Nickname.ToLowerInvariant();
pmcData.Info.RegistrationDate = (int)_timeUtil.GetTimeStamp(); pmcData.Info.RegistrationDate = (int)_timeUtil.GetTimeStamp();
pmcData.Info.Voice = _databaseService.GetCustomization()[request.VoiceId].Name; pmcData.Info.Voice = _databaseService.GetCustomization()[request.VoiceId].Name;
pmcData.Stats = _profileHelper.GetDefaultCounters(); pmcData.Stats = _profileHelper.GetDefaultCounters();
@@ -123,7 +123,7 @@ public class DatabaseService(
/// <returns> assets/database/locations/ </returns> /// <returns> assets/database/locations/ </returns>
public Location? GetLocation(string locationId) public Location? GetLocation(string locationId)
{ {
var desiredLocation = GetLocations()?.GetByJsonProp<Location>(locationId.ToLower()); var desiredLocation = GetLocations()?.GetByJsonProp<Location>(locationId.ToLowerInvariant());
if (desiredLocation == null) if (desiredLocation == null)
{ {
_logger.Error( _logger.Error(
@@ -1301,7 +1301,7 @@ public class FenceService(
var modItemToAdjust = armorItemAndMods.FirstOrDefault(mod => var modItemToAdjust = armorItemAndMods.FirstOrDefault(mod =>
string.Equals( string.Equals(
mod.SlotId, mod.SlotId,
requiredSlot.Name.ToLower(), requiredSlot.Name.ToLowerInvariant(),
StringComparison.OrdinalIgnoreCase StringComparison.OrdinalIgnoreCase
) )
); );
@@ -78,7 +78,7 @@ public class LocaleService(
StringComparison.OrdinalIgnoreCase StringComparison.OrdinalIgnoreCase
) )
? GetPlatformForClientLocale() ? GetPlatformForClientLocale()
: _localeConfig.GameLocale.ToLower(); // Use custom locale value : _localeConfig.GameLocale.ToLowerInvariant(); // Use custom locale value
} }
return _chosenClientLocale; return _chosenClientLocale;
@@ -99,7 +99,7 @@ public class LocaleService(
StringComparison.OrdinalIgnoreCase StringComparison.OrdinalIgnoreCase
) )
? GetPlatformForServerLocale() ? GetPlatformForServerLocale()
: _localeConfig.ServerLocale.ToLower(); // Use custom locale value : _localeConfig.ServerLocale.ToLowerInvariant(); // Use custom locale value
} }
return _chosenServerLocale; return _chosenServerLocale;
@@ -136,7 +136,7 @@ public class LocaleService(
return "en"; return "en";
} }
var baseNameCode = platformLocale.TwoLetterISOLanguageName.ToLower(); var baseNameCode = platformLocale.TwoLetterISOLanguageName.ToLowerInvariant();
if (_localeConfig.ServerSupportedLocales.Contains(baseNameCode)) if (_localeConfig.ServerSupportedLocales.Contains(baseNameCode))
{ {
// Found a matching locale // Found a matching locale
@@ -144,7 +144,7 @@ public class LocaleService(
} }
// Check if base language (e.g. CN / EN / DE) exists // Check if base language (e.g. CN / EN / DE) exists
var languageCode = platformLocale.Name.ToLower(); var languageCode = platformLocale.Name.ToLowerInvariant();
if (_localeConfig.ServerSupportedLocales.Contains(languageCode)) if (_localeConfig.ServerSupportedLocales.Contains(languageCode))
{ {
if (baseNameCode == "zh") if (baseNameCode == "zh")
@@ -183,13 +183,13 @@ public class LocaleService(
} }
var locales = _databaseServer.GetTables().Locales; var locales = _databaseServer.GetTables().Locales;
var baseNameCode = platformLocale.TwoLetterISOLanguageName.ToLower(); var baseNameCode = platformLocale.TwoLetterISOLanguageName.ToLowerInvariant();
if (locales.Global.ContainsKey(baseNameCode)) if (locales.Global.ContainsKey(baseNameCode))
{ {
return baseNameCode; return baseNameCode;
} }
var languageCode = platformLocale.Name.ToLower(); var languageCode = platformLocale.Name.ToLowerInvariant();
if (locales.Global.ContainsKey(languageCode)) if (locales.Global.ContainsKey(languageCode))
{ {
return languageCode; return languageCode;
@@ -446,8 +446,8 @@ public class LocationLifecycleService
// ServerId has various info stored in it, delimited by a period // ServerId has various info stored in it, delimited by a period
var serverDetails = request.ServerId.Split("."); var serverDetails = request.ServerId.Split(".");
var locationName = serverDetails[0].ToLower(); var locationName = serverDetails[0].ToLowerInvariant();
var isPmc = serverDetails[1].ToLower().Contains("pmc"); var isPmc = serverDetails[1].ToLowerInvariant().Contains("pmc");
var isDead = IsPlayerDead(request.Results); var isDead = IsPlayerDead(request.Results);
var isTransfer = IsMapToMapTransfer(request.Results); var isTransfer = IsMapToMapTransfer(request.Results);
var isSurvived = IsPlayerSurvived(request.Results); var isSurvived = IsPlayerSurvived(request.Results);
@@ -554,7 +554,7 @@ public class LocationLifecycleService
return false; return false;
} }
if (extractName.ToLower().Contains("v-ex")) if (extractName.ToLowerInvariant().Contains("v-ex"))
{ {
return true; return true;
} }
@@ -1018,7 +1018,7 @@ public class LocationLifecycleService
var roles = new List<string> { "pmcbear", "pmcusec" }; var roles = new List<string> { "pmcbear", "pmcusec" };
var victims = postRaidProfile var victims = postRaidProfile
.Stats.Eft.Victims.Where(victim => roles.Contains(victim.Role.ToLower())) .Stats.Eft.Victims.Where(victim => roles.Contains(victim.Role.ToLowerInvariant()))
.ToList(); .ToList();
if (victims?.Count > 0) if (victims?.Count > 0)
// Player killed PMCs, send some mail responses to them // Player killed PMCs, send some mail responses to them
@@ -181,7 +181,7 @@ public class PmcChatResponseService(
if (StripCapitalisation(isVictim)) if (StripCapitalisation(isVictim))
{ {
responseText = responseText.ToLower(); responseText = responseText.ToLowerInvariant();
} }
if (AllCaps(isVictim)) if (AllCaps(isVictim))
@@ -148,7 +148,7 @@ public class RaidTimeAdjustmentService(
public RaidChanges GetRaidAdjustments(string sessionId, GetRaidTimeRequest request) public RaidChanges GetRaidAdjustments(string sessionId, GetRaidTimeRequest request)
{ {
var globals = _databaseService.GetGlobals(); var globals = _databaseService.GetGlobals();
var mapBase = _databaseService.GetLocation(request.Location.ToLower()).Base; var mapBase = _databaseService.GetLocation(request.Location.ToLowerInvariant()).Base;
var baseEscapeTimeMinutes = mapBase.EscapeTimeLimit; var baseEscapeTimeMinutes = mapBase.EscapeTimeLimit;
// Prep result object to return // Prep result object to return
@@ -248,7 +248,7 @@ public class RaidTimeAdjustmentService(
/// <returns>ScavRaidTimeLocationSettings</returns> /// <returns>ScavRaidTimeLocationSettings</returns>
protected ScavRaidTimeLocationSettings GetMapSettings(string location) protected ScavRaidTimeLocationSettings GetMapSettings(string location)
{ {
var mapSettings = _locationConfig.ScavRaidTimeSettings.Maps?[location.ToLower()]; var mapSettings = _locationConfig.ScavRaidTimeSettings.Maps?[location.ToLowerInvariant()];
if (mapSettings is null) if (mapSettings is null)
{ {
_logger.Warning( _logger.Warning(
@@ -387,8 +387,8 @@ public class SeasonalEventService(
{ {
var propInfo = props.FirstOrDefault(p => var propInfo = props.FirstOrDefault(p =>
string.Equals( string.Equals(
p.Name.ToLower(), p.Name.ToLowerInvariant(),
lootContainerKey.ToLower(), lootContainerKey.ToLowerInvariant(),
StringComparison.OrdinalIgnoreCase StringComparison.OrdinalIgnoreCase
) )
); );
@@ -871,7 +871,7 @@ public class SeasonalEventService(
protected void AddEventWavesToMaps(string eventType) protected void AddEventWavesToMaps(string eventType)
{ {
var wavesToAddByMap = _seasonalEventConfig.EventWaves[eventType.ToLower()]; var wavesToAddByMap = _seasonalEventConfig.EventWaves[eventType.ToLowerInvariant()];
if (wavesToAddByMap is null) if (wavesToAddByMap is null)
{ {
@@ -903,7 +903,7 @@ public class SeasonalEventService(
{ {
if ( if (
!_seasonalEventConfig.EventBossSpawns.TryGetValue( !_seasonalEventConfig.EventBossSpawns.TryGetValue(
eventType.ToLower(), eventType.ToLowerInvariant(),
out var botsToAddPerMap out var botsToAddPerMap
) )
) )
@@ -1018,7 +1018,7 @@ public class SeasonalEventService(
// Iterate over bots with changes to apply // Iterate over bots with changes to apply
foreach (var botKvP in botGearChanges) foreach (var botKvP in botGearChanges)
{ {
var botToUpdate = _databaseService.GetBots().Types[botKvP.Key.ToLower()]; var botToUpdate = _databaseService.GetBots().Types[botKvP.Key.ToLowerInvariant()];
if (botToUpdate is null) if (botToUpdate is null)
{ {
_logger.Warning( _logger.Warning(
@@ -1068,7 +1068,7 @@ public class SeasonalEventService(
// Iterate over bots with changes to apply // Iterate over bots with changes to apply
foreach (var botKvpP in botLootChanges) foreach (var botKvpP in botLootChanges)
{ {
var botToUpdate = _databaseService.GetBots().Types[botKvpP.Key.ToLower()]; var botToUpdate = _databaseService.GetBots().Types[botKvpP.Key.ToLowerInvariant()];
if (botToUpdate is null) if (botToUpdate is null)
{ {
_logger.Warning( _logger.Warning(
@@ -65,7 +65,9 @@ public class ImporterUtil(ISptLogger<ImporterUtil> _logger, FileUtil _fileUtil,
{ {
if ( if (
_fileUtil.GetFileExtension(file) != "json" _fileUtil.GetFileExtension(file) != "json"
|| _filesToIgnore.Contains(_fileUtil.GetFileNameAndExtension(file).ToLower()) || _filesToIgnore.Contains(
_fileUtil.GetFileNameAndExtension(file).ToLowerInvariant()
)
) )
{ {
continue; continue;
@@ -127,7 +129,7 @@ public class ImporterUtil(ISptLogger<ImporterUtil> _logger, FileUtil _fileUtil,
// Get the set method to update the object // Get the set method to update the object
var setMethod = GetSetMethod( var setMethod = GetSetMethod(
_fileUtil.StripExtension(file).ToLower(), _fileUtil.StripExtension(file).ToLowerInvariant(),
loadedType, loadedType,
out var propertyType, out var propertyType,
out var isDictionary out var isDictionary
@@ -253,8 +255,8 @@ public class ImporterUtil(ISptLogger<ImporterUtil> _logger, FileUtil _fileUtil,
var matchedProperty = type.GetProperties() var matchedProperty = type.GetProperties()
.FirstOrDefault(prop => .FirstOrDefault(prop =>
string.Equals( string.Equals(
prop.Name.ToLower(), prop.Name.ToLowerInvariant(),
_fileUtil.StripExtension(propertyName).ToLower(), _fileUtil.StripExtension(propertyName).ToLowerInvariant(),
StringComparison.Ordinal StringComparison.Ordinal
) )
); );
+1 -1
View File
@@ -384,7 +384,7 @@ public class ItemTplGenerator(
} }
// Add "DAMAGED" for damaged items // Add "DAMAGED" for damaged items
if (item.Name.ToLower().Contains("damaged")) if (item.Name.ToLowerInvariant().Contains("damaged"))
{ {
suffix += "_DAMAGED"; suffix += "_DAMAGED";
} }