From b5b72e9f6c4a6d439ddc158fb6d01fb8391a0257 Mon Sep 17 00:00:00 2001 From: James Puleo Date: Fri, 9 Jun 2023 03:00:45 -0400 Subject: [PATCH 1/2] Ensure `TSPlayer.PlayerData` is non-null whilst syncing loadouts During connection, we receive a `SyncLoadout` packet before the `ContinueConnecting2` packet, meaning we have not yet created a `PlayerData` for this player. --- TShockAPI/GetDataHandlers.cs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/TShockAPI/GetDataHandlers.cs b/TShockAPI/GetDataHandlers.cs index 1ef2f4f8b..b736a5123 100644 --- a/TShockAPI/GetDataHandlers.cs +++ b/TShockAPI/GetDataHandlers.cs @@ -4445,6 +4445,11 @@ private static bool HandleSyncLoadout(GetDataHandlerArgs args) return true; } + // Don't modify the player data if it isn't there. + // This is the case whilst the player is connecting, as we receive the SyncLoadout packet before the ContinueConnecting2 packet. + if (args.Player.PlayerData == null) + return false; + // The client does not sync slot changes when changing loadouts, it only tells the server the loadout index changed, // and the server will replicate the changes the client did. This means that PlayerData.StoreSlot is never called, so we need to // swap around the PlayerData items ourself. From fbc1d9dc8d792f3b9511736276ca40e8d7b35184 Mon Sep 17 00:00:00 2001 From: James Puleo Date: Fri, 9 Jun 2023 03:05:43 -0400 Subject: [PATCH 2/2] Update `docs/changelog.md` --- docs/changelog.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/changelog.md b/docs/changelog.md index f02867f8c..d329a6dfb 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -88,6 +88,7 @@ Use past tense when adding new entries; sign your name off when you add or chang * Added a method `TSPlayer.UpdateSection` with arguments `rectangle` and `isLoaded`, which will load some area from the server to the player. (@AgaSpace) * Added a method `TSPlayer.GiveItem`, which has `TShockAPI.NetItem` structure in its arguments. (@AgaSpace) * Added a property `TSPlayer.Hostile`, which gets pvp player mode. +* Ensured `TSPlayer.PlayerData` is non-null whilst syncing loadouts. (@drunderscore) ## TShock 5.2 * An additional option `pvpwithnoteam` is added at `PvPMode` to enable PVP with no team. (@CelestialAnarchy, #2617, @ATFGK)