Update start.sh
Browse files48 unmodified lines4950515252535410 unmodified lines656667686970717273747575767718 unmodified lines969798100101102991001011021031071081091041051061071081141091101111121 unmodified line1141151161221171181191251201211271221231241251261271281291301311321331341358 unmodified lines14414514614915014714814915315015148 unmodified linesfetch_via "ViaVersion" "ViaVersion.jar"fetch_via "ViaBackwards" "ViaBackwards.jar"fetch_via "ViaRewind" "ViaRewind.jar"fetch_via "ViaRewind-Legacy-Support" "ViaRewind-Legacy-Support.jar"
# 5. Accept EULA and Set Base Propertiesecho "eula=true" > eula.txt10 unmodified linesEOF
# 7. GENERATE THE NODE.JS WEB CONSOLE & MULTIPLEXER# (Fixed: Using standard string concatenation to prevent Bash template errors)cat << 'EOF' > /app/webconsole.jsconst http = require('http');const net = require('net');const { exec } = require('child_process');
const server = http.createServer((req, res) => { // Serve the Web Console HTML UI if (req.method === 'GET' && req.url === '/') { res.writeHead(200, { 'Content-Type': 'text/html' }); res.end(`18 unmodified lines </script> </body> </html>`); } // API: Fetch the last 150 lines of the server log else if (req.method === 'GET' && req.url === '/logs') { } else if (req.method === 'GET' && req.url === '/logs') { exec('tail -n 150 /data/logs/latest.log', (err, stdout) => { res.writeHead(200, { 'Content-Type': 'text/plain' }); res.end(stdout || 'Starting server... please wait.'); }); } // API: Send a command to the Minecraft server via tmux else if (req.method === 'POST' && req.url === '/command') { } else if (req.method === 'POST' && req.url === '/command') { let body = ''; req.on('data', c => body += c); req.on('end', () => { const cmd = new URLSearchParams(body).get('cmd'); if (cmd) exec(`tmux send-keys -t mc "${cmd}" ENTER`); if (cmd) exec('tmux send-keys -t mc "' + cmd + '" ENTER'); res.writeHead(200); res.end(); }); } else {1 unmodified line }});
// Proxy WebSocket connections to Eaglercraft!// Proxy WebSocket connections to Eaglercraft (Port 25566)server.on('upgrade', (req, clientSocket, head) => { const serverSocket = net.connect(25566, '127.0.0.1', () => { let headers = \`\${req.method} \${req.url} HTTP/\${req.httpVersion}\r\n\`; let headers = req.method + ' ' + req.url + ' HTTP/' + req.httpVersion + '\r\n'; for (let i = 0; i < req.rawHeaders.length; i += 2) { headers += \`\${req.rawHeaders[i]}: \${req.rawHeaders[i+1]}\r\n\`; headers += req.rawHeaders[i] + ': ' + req.rawHeaders[i+1] + '\r\n'; } headers += '\r\n'; serverSocket.write(headers); serverSocket.write(head); clientSocket.pipe(serverSocket); serverSocket.pipe(clientSocket); }); serverSocket.on('error', () => clientSocket.end()); clientSocket.on('error', () => serverSocket.end());});8 unmodified lines# 8. Start the Web Console Multiplexer in the backgroundnode /app/webconsole.js &
# 9. Start the Minecraft Server inside a detached 'tmux' session # (This allows the Web Console to securely type commands into it)# 9. Start the Minecraft Server inside a detached 'tmux' sessiontmux new-session -d -s mc "java -Xms2G -Xmx2G -jar server.jar nogui"
# 10. Tail the log file to keep the Docker container alive and print to HF Logs# 10. Tail the log file to keep the Docker container alivetail -f logs/latest.logstart.sh+12-15