Update start.sh
Browse files48 unmodified lines4950515253545510 unmodified lines6667686970717273747576777818 unmodified lines9798991001011021031041051061071081091101111121131141151161171 unmodified line1191201211221231241251261271281291301311321331341351361378 unmodified lines14614714814915015115215315448 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 & MULTIPLEXERcat << '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 UIif (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 logelse 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 tmuxelse 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`);res.writeHead(200); res.end();});} else {1 unmodified line}});// Proxy WebSocket connections to Eaglercraft!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\`;for (let i = 0; i < req.rawHeaders.length; i += 2) {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)tmux 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 Logstail -f logs/latest.log48 unmodified lines49505152535410 unmodified lines6566676869707172737475767718 unmodified lines969798991001011021031041051061071081091101111121 unmodified line1141151161171181191201211221231241251261271281291301311321331341358 unmodified lines14414514614714814915015148 unmodified linesfetch_via "ViaVersion" "ViaVersion.jar"fetch_via "ViaBackwards" "ViaBackwards.jar"fetch_via "ViaRewind" "ViaRewind.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) => {if (req.method === 'GET' && req.url === '/') {res.writeHead(200, { 'Content-Type': 'text/html' });res.end(`18 unmodified lines</script></body></html>`);} 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.');});} 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');res.writeHead(200); res.end();});} else {1 unmodified line}});// 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';for (let i = 0; i < req.rawHeaders.length; i += 2) {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' sessiontmux new-session -d -s mc "java -Xms2G -Xmx2G -jar server.jar nogui"# 10. Tail the log file to keep the Docker container alivetail -f logs/latest.log
start.sh+12-15