SuperMartijn642 / PackedUp

3 stars 6 forks source link

[Bug] Backpack Gaining Other Players' Items, or Deleting Inventory When Offline #36

Closed steventopper closed 1 year ago

steventopper commented 2 years ago

Version Info

Description of the Bug I've been playing on the official server for the Moonlit Myths modpack, which includes PackedUp. On the first day of the server, a few days ago, we were having decent lag issues, but I made myself a gold backpack and tried to get some mining done. After an hour, the lag was so bad that I had to get off, so I went to stash things in my backpack, but I noticed that several items were in the backpack that I had not added, such as a spellbook from Ars Nouveau and cutting boards from Farmer's Delight and Pam's Harvestcraft. I put the cutting boards into my inventory and logged out.

Today, I logged in and found my backpack empty, though the cutting boards were still in my inventory. Oh well, I went back to mining for several hours. Near the end, the server started lagging heavily again, and once again I noticed several items in my backpack that were not put in there by me. I removed all of my valuables and logged off; I logged in 6 hours later to find my backpack empty once again. See screenshot for details.

I suspect that the items found in the backpack belong to other players, though I am unsure if these items are being removed or copied from other players' backpacks. I also doubt that they are from a player's inventory, a loot table, or a random list, as there have been no tools or items you would not typically find as loot, and they are mostly items that players would typically put into backpacks, such as waystones and crafting tools.

Steps to Reproduce I'm honestly not sure, as this is one of the weirdest bugs I've seen, but here's the best I have:

  1. Play on a multiplayer server.
  2. Lag the server heavily, i.e. 6 TPS or less.
  3. Open your backpack to find various items that were not inserted by you.
  4. Log off and log back in later.
  5. Open your backpack to find it empty.

Screenshots image

steventopper commented 2 years ago

Update: I've confirmed that it is linked to another player's active backpack due to seeing another player move items around inside the backpack. It also appears to only be affecting my specific backpack, as others on the server are able to use backpacks without the issue occurring. I suspect it may be due to a corruption of the NBT tag, which is carried over when the backpack is upgraded, explaining why upgrading my backpack did not fix the issue.

SuperMartijn642 commented 2 years ago

The backpack inventories are stored in a separate system and not directly on the items. Packed Up's backpacks are simply an item with an id in their nbt that points to the inventory. Normally, whenever a backpack without an id in its nbt is right-clicked, the inventory system just increases a global counter by one and gives the backpack that id.

From your description it seems like your backpack may have the same id as someone else's backpack. In that case both of you would simply be interacting with the same inventory.

I think of a couple ways this could have happened:

  1. You create your backpack and it got its inventory id, then you logged off and your player data, including the backpack with its id, were saved. After that the server may have crashed or been shut down incorrectly, thus not saving the corresponding inventory and the increased global counter. Then someone else created a backpack and got the same id.
  2. You and someone else requested an inventory id at the exact same time, thus the counter was read by both before one updated it, resulting in the same id. This is possible, but very unlikely.
  3. There's some other bug in Packed Up which I have not spotted.

Do you know if the server crashed in between you creating your backpack and logging off, and when you logged back in?

I am currently working on some other stuff and quite busy with school, so it might be a bit before I have time to properly look into the code to see whether I can find issues in Packed Up.

steventopper commented 2 years ago

Thanks for the explanation, that definitely gives some insight into what might be causing this.

It very well may be due to a server crash; after looking at the chat logs, the server crashed around 4 minutes after after I crafted a golden backpack. There were also three separate times afterwards (while I was online) that all players were timed out from the server due to TPS lag.

This could also explain the empty backpack by that the other player removed everything from the backpack while I was offline. I wish that I had thought to ask the server owner for my inventory file to check the NBT tag for the ID; I will make to do so if the issue arises again.

I found a potential issue with this theory based on the chat timestamps, here are the relevant events:

Based on this, items appeared in the backpack without any other players owning a backpack at the time. This seems wildly incorrect, but all I have to go off of here are the chat logs and my terrible memory, both of which support this series of events.

Feel free to take your time dealing with this, I fully understand that this is lower priority, especially since this seems to be a very rare issue. I'll keep an eye out for it happening again and try to get more information to help get to the bottom of this.

Anaerin commented 2 years ago

(Server admin for this server here): Okay, this is somewhat confusing. A player here has an Obsidian Backpack, with the packedup:invIndex value of 30. But in the packedup\backpacks folder there are only 26 inventory#.nbt files. Could this be related?

SuperMartijn642 commented 2 years ago

Yes, this likely part of the issue. This means a player created a backpack which then got id 30. Once they log of their inventory, including the backpack, got saved to their player file. If after that the server crashes, the inventory associated with id 30 doesn't get saved, thus once the server starts up again someone else may then also get id 30 on their backpack.

SuperMartijn642 commented 1 year ago

Packed Up's data now gets saved far more frequently, so I believe this issue is no longer relevant.