Skip to content

Fix stale position packets and remember minigame arenas - #64

Merged
perronosaurio merged 3 commits into
masterfrom
fix-stale-positions
Oct 5, 2026
Merged

perronosaurio merged 3 commits into
masterfrom
fix-stale-positions

Conversation

@perronosaurio

@perronosaurio perronosaurio commented Oct 5, 2026 •

Copy link
Copy Markdown
Owner

What does this change?

This PR fixes two issues and adds one feature:

  1. Stale position packets after teleport/level change: When a server teleports a player or changes their level, the client continues sending position packets from its old location until it receives the teleport/level change packet. These late-arriving packets were being processed as if the player had moved to that old position, which could trigger portals, message blocks, or parkour checkpoints in the wrong place. The fix tracks the old position and ignores packets that are closer to it than the new position (within a 2-second window).

  2. Minigame arena persistence: Levels enabled as minigame arenas (via /tntwars enable, /ctf enable, /zombie enable) are now remembered and loaded at startup. This allows /<game> join to work from any level, and /<game> join <level> can load the arena if needed.

  3. Supervised restart fix: When /restart is used under a supervisor (systemd, pm2, or a start script loop), the server now exits cleanly instead of spawning a second copy. This is controlled by the MCSCRIPT_SUPERVISED=1 environment variable.

How did you test it?

  • Added comprehensive test 'position packets sent before a teleport or level change arrived are ignored' covering teleport, level change, and combined scenarios
  • Added test 'minigame arenas are remembered and loaded at startup' verifying arena persistence across restarts
  • Updated existing 'minigames: capture the flag' test to properly simulate client behavior by confirming spawn position before moving
  • All tests pass with npm test

The client keeps reporting its old position until it receives the
teleport (or the new level), and those packets were taken as the new
position. After walking into a portal the player could be moved back or
trigger portals and checkpoints at the old coordinates in the new level.

For two seconds after the server moves a player, packets that are still
next to the old spot and far from the new one are dropped; the first
packet near the new position ends that early.
/restart started a new copy of the server and exited. Under systemd, pm2
or a start script loop the supervisor then started another one, and the
two fought over the port. With MCSCRIPT_SUPERVISED set, /restart only
exits.
Arenas enabled with /<game> enable are stored and loaded at startup, so
/<game> join works from the lobby instead of only from a loaded arena.

/warp changes level and then teleports; the second move replaced the
spot the client was really coming from, so a normal step near the new
spawn looked like a late packet. Keep the first spot while it's fresh and
only drop packets closer to it than to the new position.
@perronosaurio
perronosaurio merged commit 5b7b171 into master Oct 5, 2026
6 checks passed
@perronosaurio
perronosaurio deleted the fix-stale-positions branch October 5, 2026 19:05
@perronosaurio perronosaurio mentioned this pull request Oct 5, 2026
2 of 3 tasks
perronosaurio added a commit that referenced this pull request Oct 5, 2026
Version 2.1.0 with the Discord bot, BetaCraft support, remembered minigame arenas and the fixes from #63 and #64.
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.

1 participant