Skip to content

Conversation

@cp89gamedev
Copy link
Contributor

@cp89gamedev cp89gamedev commented Aug 19, 2025

Manually tested:
Alt-F4 with config set to false - items remain in player inventory
Alt-F4 with config set to true - items removed in player inventory
Finish raid with success - items remain in player inventory
Finish raid with death - items removed from player inventory

@cp89gamedev cp89gamedev changed the title alt-f4 is for timmys and rats, not chads like Chomp Fix: Killing the client will no longer save your items Aug 19, 2025
@qodo-merge-for-open-source
Copy link

qodo-merge-for-open-source bot commented Aug 19, 2025

PR Code Suggestions ✨

Explore these optional code suggestions:

CategorySuggestion                                                                                                                                    Impact
Possible issue
Restrict wipe to PMC raids
Suggestion Impact:The commit removed the unconditional wipe and introduced a method that wipes inventory only when the player side is PMC, along with a log message, matching the suggestion’s intent.

code diff:

-        // If config enabled, remove players equipped items to prevent alt-F4 from persisting items
-        if (_lostOnDeathConfig.WipeOnRaidStart)
-            inRaidHelper.DeleteInventory(playerProfile.CharacterData.PmcData, sessionId);
-
         // Raid is starting, adjust run times to reduce server load while player is in raid
         _ragfairConfig.RunIntervalSeconds = _ragfairConfig.RunIntervalValues.InRaid;
         _hideoutConfig.RunIntervalSeconds = _hideoutConfig.RunIntervalValues.InRaid;
@@ -133,7 +129,23 @@
 
         GC.Collect(GC.MaxGeneration, GCCollectionMode.Aggressive, true, true);
 
+        // Handle Player Inventory Wiping checks for alt-f4 prevention
+        HandlePreRaidInventoryChecks(request.PlayerSide, playerProfile.CharacterData.PmcData, sessionId);
+
         return result;
+    }
+
+    /// <summary>
+    /// Handle Pre Raid checks Alt-F4 Prevention and player inventory wiping
+    /// </summary>
+    protected void HandlePreRaidInventoryChecks(string playerSide, PmcData pmcData, string sessionId)
+    {
+        // If config enabled, remove players equipped items to prevent alt-F4 from persisting items
+        if (string.Equals(playerSide, "pmc", StringComparison.OrdinalIgnoreCase) && _lostOnDeathConfig.WipeOnRaidStart)
+        {
+            logger.Debug("Wiping player inventory on raid start to prevent alt-f4");
+            inRaidHelper.DeleteInventory(pmcData, sessionId);
+        }
     }

This unconditionally wipes PMC inventory on raid start and ignores the side
chosen for the raid. If the player starts as Scav, this will still wipe PMC
gear. Gate the wipe to PMC raids only, and consider logging the action for
traceability.

Libraries/SPTarkov.Server.Core/Services/LocationLifecycleService.cs [76-78]

-// If config enabled, remove players equipped items to prevent alt-F4 from persisting items
-if (_lostOnDeathConfig.WipeOnRaidStart)
+// If config enabled, remove equipped items to prevent alt-F4 from persisting items (PMC raids only)
+if (_lostOnDeathConfig.WipeOnRaidStart && string.Equals(request.PlayerSide, "pmc", StringComparison.OrdinalIgnoreCase))
+{
+    logger.Info("WipeOnRaidStart enabled - clearing PMC inventory before raid start");
     inRaidHelper.DeleteInventory(playerProfile.CharacterData.PmcData, sessionId);
+}
Suggestion importance[1-10]: 9

__

Why: The suggestion correctly identifies a critical bug where a player's PMC inventory would be wiped even when starting a Scav raid, and provides a correct fix.

High
General
Use safe default configuration
Suggestion Impact:The commit changed "wipeOnRaidStart" from true to false as suggested.

code diff:

-  "wipeOnRaidStart": true
+  "wipeOnRaidStart": false

Enabling this by default can surprise users by wiping gear at raid start.
Default the flag to false and let server operators opt in via configuration.

Libraries/SPTarkov.Server.Assets/SPT_Data/configs/lostondeath.json [20-21]

 "specialSlotItems": false,
-"wipeOnRaidStart": true
+"wipeOnRaidStart": false
Suggestion importance[1-10]: 8

__

Why: The suggestion correctly points out that enabling the destructive wipeOnRaidStart feature by default is risky and could lead to unexpected gear loss for users.

Medium
Add error handling around wipe
Suggestion Impact:The commit moved the wipe logic into a dedicated method with additional checks (only for PMC side) and logging. While it did not add a try/catch, it implemented part of the suggestion’s intent by refining conditions and adding logging around the wipe operation.

code diff:

+        // Handle Player Inventory Wiping checks for alt-f4 prevention
+        HandlePreRaidInventoryChecks(request.PlayerSide, playerProfile.CharacterData.PmcData, sessionId);
+
         return result;
+    }
+
+    /// <summary>
+    /// Handle Pre Raid checks Alt-F4 Prevention and player inventory wiping
+    /// </summary>
+    protected void HandlePreRaidInventoryChecks(string playerSide, PmcData pmcData, string sessionId)
+    {
+        // If config enabled, remove players equipped items to prevent alt-F4 from persisting items
+        if (string.Equals(playerSide, "pmc", StringComparison.OrdinalIgnoreCase) && _lostOnDeathConfig.WipeOnRaidStart)
+        {
+            logger.Debug("Wiping player inventory on raid start to prevent alt-f4");
+            inRaidHelper.DeleteInventory(pmcData, sessionId);
+        }
     }

Deleting the entire inventory at raid start is high risk; a transient error or
misconfiguration can cause irreversible loss. Wrap the wipe in a try/catch and
add a warning log to capture failures without crashing the raid start flow.

Libraries/SPTarkov.Server.Core/Services/LocationLifecycleService.cs [76-78]

-// If config enabled, remove players equipped items to prevent alt-F4 from persisting items
-if (_lostOnDeathConfig.WipeOnRaidStart)
-    inRaidHelper.DeleteInventory(playerProfile.CharacterData.PmcData, sessionId);
+// If config enabled, remove equipped items to prevent alt-F4 from persisting items
+if (_lostOnDeathConfig.WipeOnRaidStart && string.Equals(request.PlayerSide, "pmc", StringComparison.OrdinalIgnoreCase))
+{
+    try
+    {
+        logger.Info("WipeOnRaidStart enabled - clearing PMC inventory before raid start");
+        inRaidHelper.DeleteInventory(playerProfile.CharacterData.PmcData, sessionId);
+    }
+    catch (Exception ex)
+    {
+        logger.Error(ex, "Failed to clear PMC inventory on raid start; proceeding without wipe");
+    }
+}
Suggestion importance[1-10]: 7

__

Why: The suggestion improves code robustness by adding a try-catch block to a critical operation, preventing potential raid start failures.

Medium
Possible issue
Honour configured inventory exemptions

Respect the lost-on-death configuration for exemptions (e.g., secured container,
special slots) when wiping, otherwise you may delete protected items
unintentionally. Pass the appropriate options/flags or filter items before
deletion to avoid removing exempt gear.

Libraries/SPTarkov.Server.Core/Services/LocationLifecycleService.cs [76-78]

 // If config enabled, remove players equipped items to prevent alt-F4 from persisting items
 if (_lostOnDeathConfig.WipeOnRaidStart)
-    inRaidHelper.DeleteInventory(playerProfile.CharacterData.PmcData, sessionId);
+{
+    // Ensure exempt containers/slots are preserved according to config
+    inRaidHelper.DeleteInventory(
+        playerProfile.CharacterData.PmcData,
+        sessionId,
+        preserveSecuredContainer: !_lostOnDeathConfig.Equipment.SecuredContainer,
+        preserveSpecialSlots: !_lostOnDeathConfig.SpecialSlotItems,
+        preserveQuestItems: !_lostOnDeathConfig.QuestItems
+    );
+}
Suggestion importance[1-10]: 10

__

Why: This suggestion correctly identifies a critical flaw where wiping inventory on raid start would ignore exemptions for items in secured containers or special slots, leading to unintended and severe item loss for players.

High
Set safe default value

Provide an explicit default value for the new flag to prevent behavioural
changes when the JSON omits it. Set a safe default (false) in the model to avoid
unintended wipes on deserialisation.

Libraries/SPTarkov.Server.Core/Models/Spt/Config/LostOnDeathConfig.cs [28-29]

 [JsonPropertyName("wipeOnRaidStart")]
-public bool WipeOnRaidStart { get; set; }
+public bool WipeOnRaidStart { get; set; } = false;
Suggestion importance[1-10]: 6

__

Why: The suggestion correctly recommends initializing the new boolean property WipeOnRaidStart to false to ensure safer behavior if the property is missing from the configuration file, preventing accidental activation of a destructive feature.

Low
General
Gate wipe to standard raid modes
Suggestion Impact:The commit changed unconditional wipe-on-start logic into a guarded check that only wipes when the player side is PMC and the config is enabled, moving the logic into a dedicated method. This partially implements the suggestion by gating wipes to PMC raids.

code diff:

-        // If config enabled, remove players equipped items to prevent alt-F4 from persisting items
-        if (_lostOnDeathConfig.WipeOnRaidStart)
-            inRaidHelper.DeleteInventory(playerProfile.CharacterData.PmcData, sessionId);
-
         // Raid is starting, adjust run times to reduce server load while player is in raid
         _ragfairConfig.RunIntervalSeconds = _ragfairConfig.RunIntervalValues.InRaid;
         _hideoutConfig.RunIntervalSeconds = _hideoutConfig.RunIntervalValues.InRaid;
@@ -133,7 +129,23 @@
 
         GC.Collect(GC.MaxGeneration, GCCollectionMode.Aggressive, true, true);
 
+        // Handle Player Inventory Wiping checks for alt-f4 prevention
+        HandlePreRaidInventoryChecks(request.PlayerSide, playerProfile.CharacterData.PmcData, sessionId);
+
         return result;
+    }
+
+    /// <summary>
+    /// Handle Pre Raid checks Alt-F4 Prevention and player inventory wiping
+    /// </summary>
+    protected void HandlePreRaidInventoryChecks(string playerSide, PmcData pmcData, string sessionId)
+    {
+        // If config enabled, remove players equipped items to prevent alt-F4 from persisting items
+        if (string.Equals(playerSide, "pmc", StringComparison.OrdinalIgnoreCase) && _lostOnDeathConfig.WipeOnRaidStart)
+        {
+            logger.Debug("Wiping player inventory on raid start to prevent alt-f4");
+            inRaidHelper.DeleteInventory(pmcData, sessionId);
+        }
     }

Avoid wiping when joining non-standard sessions (e.g., offline testing, co-op,
or after reconnects). Check the raid context (e.g.,
request.IsLocal/request.AiAmount/match mode flags) and only wipe for standard
PMC live raids to prevent unintended loss.

Libraries/SPTarkov.Server.Core/Services/LocationLifecycleService.cs [76-78]

 // If config enabled, remove players equipped items to prevent alt-F4 from persisting items
-if (_lostOnDeathConfig.WipeOnRaidStart)
+if (_lostOnDeathConfig.WipeOnRaidStart
+    && string.Equals(request.PlayerSide, "pmc", StringComparison.OrdinalIgnoreCase)
+    && request.SavageLock == false
+    && request.InsuredEquipment == true)
+{
     inRaidHelper.DeleteInventory(playerProfile.CharacterData.PmcData, sessionId);
+}
Suggestion importance[1-10]: 9

__

Why: The suggestion correctly points out that wiping inventory should only occur in standard online PMC raids, preventing unintended data loss in other modes like offline or Scav runs, which is a significant oversight.

High
  • Update

@chompDev
Copy link
Contributor

Looks good

@chompDev chompDev merged commit b610f59 into sp-tarkov:develop Aug 19, 2025
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants