Make spawn and movement acceptance server-authoritative

This commit is contained in:
Jage9
2026-02-24 19:52:38 -05:00
parent a588148039
commit 7488ac9f67
12 changed files with 78 additions and 29 deletions

View File

@@ -196,6 +196,7 @@ const renderer = new CanvasRenderer(dom.canvas);
const audio = new AudioEngine();
const settings = new SettingsStore();
let worldGridSize = GRID_SIZE;
let movementTickMs = MOVE_COOLDOWN_MS;
let lastWallCollisionDirection: string | null = null;
let statusTimeout: number | null = null;
let lastFocusedElement: Element | null = null;
@@ -1122,7 +1123,7 @@ function handleMovement(): void {
if (state.mode !== 'normal') return;
if (activeTeleport) return;
const now = Date.now();
if (now - state.player.lastMoveTime < MOVE_COOLDOWN_MS) return;
if (now - state.player.lastMoveTime < movementTickMs) return;
let dx = 0;
let dy = 0;
@@ -1154,7 +1155,7 @@ function handleMovement(): void {
persistPlayerPosition();
state.player.lastMoveTime = now;
void refreshAudioSubscriptions(true);
void audio.playSample(randomFootstepUrl(), FOOTSTEP_GAIN, MOVE_COOLDOWN_MS);
void audio.playSample(randomFootstepUrl(), FOOTSTEP_GAIN, movementTickMs);
signaling.send({ type: 'update_position', x: nextX, y: nextY });
const namesOnTile = getPeerNamesAtPosition(nextX, nextY);
@@ -1307,7 +1308,6 @@ function getConnectionFlowDeps(): ConnectFlowDeps {
signalingConnect: (handler) => signaling.connect(handler as (message: IncomingMessage) => Promise<void>),
signalingDisconnect: () => signaling.disconnect(),
onMessage: (message) => onSignalingMessage(message as IncomingMessage),
worldGridSize,
persistPlayerPosition,
peerManagerCleanupAll: () => peerManager.cleanupAll(),
radioCleanupAll: () => radioRuntime.cleanupAll(),
@@ -1346,6 +1346,9 @@ const onAppMessage = createOnMessageHandler({
setWorldGridSize: (size) => {
worldGridSize = size;
},
setMovementTickMs: (value) => {
movementTickMs = Math.max(1, value);
},
setConnecting: (value) => {
mediaSession.setConnecting(value);
updateConnectAvailability();