async function sendChunk() { const ticksToSend = currentTick - lastSentTick; if (ticksToSend <= 0) return; const snapshotobstacles = JSON.parse(JSON.stringify(obstacles)); const payload = { sessionId: sessionID, inputs: [...inputLog], totalTicks: ticksToSend }; inputLog = []; lastSentTick = currentTick; try { const res = await fetch('/api/validate', { method: 'POST', headers: {'Content-Type': 'application/json'}, body: JSON.stringify(payload) }); const data = await res.json(); // Update für visuelles Debugging if (data.serverObs) { serverObstacles = data.serverObs; if (typeof DEBUG_SYNC !== 'undefined' && DEBUG_SYNC) { compareState(snapshotobstacles, data.serverObs); } if (data.powerups) { const sTick = data.serverTick; if (lastPowerupTick > sTick) { } else { godModeLives = data.powerups.godLives; hasBat = data.powerups.hasBat; bootTicks = data.powerups.bootTicks; } } // Sync Spawning Timer if (data.NextSpawnTick) { if (Math.abs(nextSpawnTick - data.nextSpawnTick) > 5) { console.log("Sync Spawn Timer:", nextSpawnTick, "->", data.NextSpawnTick); nextSpawnTick = data.nextSpawnTick; } } } if (data.status === "dead") { console.error("💀 SERVER KILL", data); gameOver("Vom Server gestoppt"); } else { const sScore = data.verifiedScore; // Score Korrektur if (Math.abs(score - sScore) > 200) { console.warn(`⚠️ SCORE DRIFT: Client=${score} Server=${sScore}`); score = sScore; } } } catch (e) { console.error("Netzwerkfehler:", e); } } window.submitScore = async function() { const nameInput = document.getElementById('playerNameInput'); const name = nameInput.value; const btn = document.getElementById('submitBtn'); if (!name) return alert("Namen eingeben!"); btn.disabled = true; try { const res = await fetch('/api/submit-name', { method: 'POST', headers: {'Content-Type': 'application/json'}, body: JSON.stringify({ sessionId: sessionID, name: name }) }); const data = await res.json(); let myClaims = JSON.parse(localStorage.getItem('escape_claims') || '[]'); myClaims.push({ name: name, score: Math.floor(score / 10), code: data.claimCode, date: new Date().toLocaleString('de-DE'), sessionId: sessionID }); localStorage.setItem('escape_claims', JSON.stringify(myClaims)); document.getElementById('inputSection').style.display = 'none'; loadLeaderboard(); } catch (e) {} }; async function loadLeaderboard() { const res = await fetch(`/api/leaderboard?sessionId=${sessionID}`); const entries = await res.json(); let html = "