Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rewrite: Partially fix bed spawning for SSC #3031

Open
wants to merge 1 commit into
base: general-devel
Choose a base branch
from

Conversation

PotatoCider
Copy link
Contributor

@PotatoCider PotatoCider commented Jun 2, 2024

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 in sp{X,Y} in Terraria.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 respawns (via death or magic mirror) 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 :)

@hakusaro
Copy link
Member

hakusaro commented Jun 2, 2024

What problem are you trying to solve here?

@PotatoCider
Copy link
Contributor Author

What problem are you trying to solve here?

I'm mainly trying to solve #1966 (and #2844, #3011) which were known issues for quite some time. This PR doesn't fully solve the bed spawning problem with the limitations above. There are also other related issues like #1849.

@PotatoCider PotatoCider force-pushed the general-devel branch 2 times, most recently from 1a957d8 to 3ef485b Compare January 27, 2025 02:00
@PotatoCider
Copy link
Contributor Author

PotatoCider commented Jan 27, 2025

Need testers for this PR! You can help test out with this Docker image with:
docker run -p 7777:7777 -v $(pwd)/tshock:/tshock -v $(pwd)/worlds:/worlds --rm -it ghcr.io/potatocider/tshock:general-devel
(This will create two folders tshock/ and worlds/ in your current working directory. You can then enable SSC via tshock/sscconfig.json)

Please do let me know if there's any bugs or potential issues with this workaround.

@xNarnia
Copy link

xNarnia commented Feb 6, 2025

Upon dying and respawning, any action I take seems to not register.
Can anyone reproduce this?

Steps to Reproduce

  • Run & initialize the server
    • docker run -p 7777:7777 --rm -it ghcr.io/potatocider/tshock:general-devel
  • Enter the world
  • Die
  • Attempt to place a block or hurt enemies
    • The enemies will not register your hits server-side
  • Leave and re-enter the server
    • The blocks placed before will be gone as if never placed

@xNarnia
Copy link

xNarnia commented Feb 6, 2025

Also, there seems to be some debugging output in the console. Is this intended?
image

@PotatoCider
Copy link
Contributor Author

PotatoCider commented Feb 9, 2025

@xNarnia

Also, there seems to be some debugging output in the console. Is this intended?

Oops. That's not intended.

I've fixed the death issue you mentioned, could you help test it again?

@xNarnia
Copy link

xNarnia commented Feb 9, 2025

Tested scenarios in #1966, #2844, #3011, and #1849. All passing with no errors.

Also tested some scenarios with bombs destroying beds during death.
It works similarly to previous versions of TShock, where the client sees destroyed blocks but it doesn't register on the server.
In this scenario with the new change, the user is teleported back to the spawnpoint after the blocks are destroyed during death. However when relogging, the destroyed blocks and destroyed bed return. The player's spawnpoint is set back to the bed, and that is where they spawn in.

Tested with both SSC on & off.

Looks good to me! ✅

Copy link

@xNarnia xNarnia left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As per our conversation in Discord, Potato will implement the use case for the bed being broken

@PotatoCider
Copy link
Contributor Author

Okay, the case where beds are broken/invalid is now handled. This PR should be ready for merging ^^

@xNarnia
Copy link

xNarnia commented Feb 10, 2025

Tested bed breaking with both the magic mirror and death.
Also tested Player A setting spawn point, Player A exiting server, Player B destroying Player A's bed spawnpoint, Player A logging back in. Player A returns to the world spawnpoint as intended.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants