Rewrite: Partially fix bed spawning for SSC #3031
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR rewrites the player spawnpoint saving system for SSC.
When SSC is enabled, player spawnpoints are only saved server side but not client side. However, due to the game's netcode logic, it is most likely impossible for the server (TShock) to change the client's spawnpoint value
Terraria.Player.Spawn{X,Y}
since the server provided value gets overwritten by its own client sided spawnpoint value insp{X,Y}
inTerraria.Player.FindSpawn()
after packet 12 has been received.In order to workaround this, TShock would keep track of the client's initial spawnpoint value on the first player spawn, it uses this value to compare if the player has changed his spawnpoint. This way, we can teleport the player with the correct server saved spawnpoint after the player tries to spawn with its incorrect client sided spawnpoint, at least before the player changes his spawnpoint mid-game.
What this means is that we purposely desync the client and server
Terraria.Player.Spawn{X,Y}
value before we know that the player had changed his spawnpoint. Once we know its changed, both client and server spawnpoint values would be synced, and we won't need to force teleport the player anymore.Note that there is one limitation with this approach - this only works if the player spawns at his changed spawnpoint before logging off, otherwise the server would have no idea that the player's spawnpoint has changed.
I'm not sure if I covered all test cases, but please let me know if there is any bugs :)