File size: 12,051 Bytes
e07dcf7 7e4140e e07dcf7 7e4140e e07dcf7 7e4140e e07dcf7 7e4140e c9a50ca 7e4140e db1bb16 c9a50ca db1bb16 b08836d f5e4212 7e4140e ecc66f5 7e4140e c9a50ca 7e4140e e07dcf7 7e4140e e07dcf7 7e4140e 82827d6 7e4140e 82827d6 7e4140e e07dcf7 7e4140e e07dcf7 7e4140e 43b2be0 ecc66f5 43b2be0 7e4140e 43b2be0 7e4140e 43b2be0 7e4140e 0a9724b 7e4140e 43b2be0 7e4140e ecc66f5 7e4140e ecc66f5 7e4140e ecc66f5 7e4140e 0a9724b 7e4140e 0a9724b 7e4140e 0a9724b 7e4140e 0a9724b 7e4140e 0a9724b 7e4140e 43b2be0 7e4140e 0a9724b 7e4140e 0a9724b 7e4140e 0a9724b 7e4140e ecc66f5 7e4140e ecc66f5 0a9724b 7e4140e 0a9724b 7e4140e 0b76416 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 | #!/bin/bash
set -e
# βββββββββββββββββββββββββββββββββββββββββββββ
# 1. Resolve Working Directory
# βββββββββββββββββββββββββββββββββββββββββββββ
if [ -d "/data" ]; then
echo "[System] Persistent /data bucket found. Taking ownership..."
sudo chown -R minecraft:minecraft /data 2>/dev/null || true
sudo chmod -R 775 /data 2>/dev/null || true
cd /data
else
echo "[Warning] No /data bucket found. World will reset on restart!"
mkdir -p /app/server
cd /app/server
fi
WORKDIR=$(pwd)
echo "[System] Working directory: $WORKDIR"
# βββββββββββββββββββββββββββββββββββββββββββββ
# 2. Clean Up Old/Corrupted Files
# βββββββββββββββββββββββββββββββββββββββββββββ
echo "[System] Cleaning up old jars..."
# Only remove specific old plugin jars, NOT the whole plugins dir yet
rm -f plugins/Via*.jar
rm -f plugins/EaglerX*.jar
rm -f server.jar
echo "[System] Clearing Paperclip cache..."
rm -rf cache
mkdir -p logs
mkdir -p plugins/EaglercraftXServer
# βββββββββββββββββββββββββββββββββββββββββββββ
# 3. Install Node.js Dependencies
# βββββββββββββββββββββββββββββββββββββββββββββ
echo "[System] Installing WebSocket proxy dependencies..."
npm install http-proxy --save 2>&1 | tail -1
# βββββββββββββββββββββββββββββββββββββββββββββ
# 4. Download Paper 1.12.2
# βββββββββββββββββββββββββββββββββββββββββββββ
echo "[System] Downloading Paper 1.12.2..."
curl -fsSL \
-A "Mozilla/5.0" \
-o server.jar \
"https://api.papermc.io/v2/projects/paper/versions/1.12.2/builds/1620/downloads/paper-1.12.2-1620.jar"
if [ ! -s server.jar ]; then
echo "[Error] server.jar download failed or is empty. Aborting."
exit 1
fi
echo "[System] server.jar downloaded successfully ($(du -sh server.jar | cut -f1))."
# βββββββββββββββββββββββββββββββββββββββββββββ
# 5. Download Plugins
# βββββββββββββββββββββββββββββββββββββββββββββ
echo "[System] Downloading EaglerXServer & EaglerXRewind..."
curl -fsSL -A "Mozilla/5.0" \
-o plugins/EaglerXServer.jar \
"https://github.com/lax1dude/eaglerxserver/releases/download/v1.0.8/EaglerXServer.jar"
curl -fsSL -A "Mozilla/5.0" \
-o plugins/EaglerXRewind.jar \
"https://github.com/lax1dude/eaglerxserver/releases/download/v1.0.8/EaglerXRewind.jar"
echo "[System] Downloading ViaVersion suite..."
curl -fsSL -A "Mozilla/5.0" \
-o plugins/ViaVersion.jar \
"https://github.com/ViaVersion/ViaVersion/releases/download/5.8.1/ViaVersion-5.8.1.jar"
curl -fsSL -A "Mozilla/5.0" \
-o plugins/ViaBackwards.jar \
"https://cdn.modrinth.com/data/NpvuJQoq/versions/8YdMHUIl/ViaBackwards-5.9.0-SNAPSHOT.jar"
curl -fsSL -A "Mozilla/5.0" \
-o plugins/ViaRewind.jar \
"https://cdn.modrinth.com/data/TbHIxhx5/versions/r3AZ5yTY/ViaRewind-4.1.0-SNAPSHOT.jar"
# Verify all plugins downloaded
echo "[System] Verifying plugin downloads..."
for jar in \
plugins/EaglerXServer.jar \
plugins/EaglerXRewind.jar \
plugins/ViaVersion.jar \
plugins/ViaBackwards.jar \
plugins/ViaRewind.jar
do
if [ ! -s "$jar" ]; then
echo "[Error] $jar is missing or empty! Aborting."
exit 1
fi
echo " [OK] $jar ($(du -sh "$jar" | cut -f1))"
done
# βββββββββββββββββββββββββββββββββββββββββββββ
# 6. Server Configuration
# βββββββββββββββββββββββββββββββββββββββββββββ
echo "[System] Writing eula.txt and server.properties..."
echo "eula=true" > eula.txt
cat > server.properties << 'PROPS'
server-port=25565
online-mode=false
motd=Eaglercraft Server
max-players=60
PROPS
# βββββββββββββββββββββββββββββββββββββββββββββ
# 7. EaglerXServer Listener Config
# βββββββββββββββββββββββββββββββββββββββββββββ
echo "[System] Writing EaglercraftXServer listener config..."
cat > plugins/EaglercraftXServer/listeners.yml << 'LISTENEOF'
listeners:
- address: 127.0.0.1:25566
motd: "&dEaglercraftX\n&ePowered by EaglerXServer"
max_players: 60
online_mode: false
forward_ip: true
LISTENEOF
# βββββββοΏ½οΏ½βββββββββββββββββββββββββββββββββββββ
# 8. Generate Node.js Web Console
# βββββββββββββββββββββββββββββββββββββββββββββ
echo "[System] Writing webconsole.js..."
cat > webconsole.js << 'NODEEOF'
'use strict';
const http = require('http');
const fs = require('fs');
const path = require('path');
const { spawn, exec } = require('child_process');
const httpProxy = require('http-proxy');
const LOG_FILE = path.join(__dirname, 'logs', 'latest.log');
const MC_PORT = 25566; // EaglerXServer internal WS port
const WEB_PORT = 7860; // Exposed port
// ββ Banner ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
console.log('=========================================');
console.log(' Eaglercraft Server + Web Console ');
console.log('=========================================');
// ββ Start Minecraft βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
const mcProcess = spawn('java', [
'-Xms2G', '-Xmx2G',
'-XX:+UseG1GC',
'-jar', 'server.jar', 'nogui'
], { cwd: __dirname });
const logStream = fs.createWriteStream(LOG_FILE, { flags: 'w' });
mcProcess.stdout.pipe(logStream, { end: false });
mcProcess.stderr.pipe(logStream, { end: false });
mcProcess.stdout.pipe(process.stdout);
mcProcess.stderr.pipe(process.stderr);
mcProcess.on('exit', (code) => {
console.log(`[MC] Server process exited with code ${code}`);
logStream.end();
});
// ββ WebSocket Proxy βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
const proxy = httpProxy.createProxyServer({
target: `ws://127.0.0.1:${MC_PORT}`,
ws: true
});
proxy.on('error', (err, req, socket) => {
console.warn('[Proxy] Routing error (server may still be booting):', err.message);
if (socket && socket.writable) socket.destroy();
});
// ββ HTML Page βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
const PAGE_HTML = `<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Eaglercraft Console</title>
<style>
* { box-sizing: border-box; margin: 0; padding: 0; }
body {
background: #1e1e1e; color: #d4d4d4;
font-family: 'Consolas', monospace;
display: flex; flex-direction: column;
height: 100vh; padding: 16px; gap: 12px;
}
h2 { color: #569cd6; font-size: 1.1rem; }
#logs {
flex: 1; overflow-y: auto; white-space: pre-wrap; word-break: break-all;
background: #0d0d0d; padding: 12px;
border: 1px solid #333; border-radius: 4px;
font-size: 0.82rem; line-height: 1.45;
}
form { display: flex; gap: 8px; }
input[type=text] {
flex: 1; padding: 9px 12px;
background: #2d2d2d; color: #fff;
border: 1px solid #444; border-radius: 4px; font-family: inherit;
}
button {
padding: 9px 20px; background: #0e639c; color: #fff;
border: none; border-radius: 4px; cursor: pointer; font-family: inherit;
}
button:hover { background: #1177bb; }
</style>
</head>
<body>
<h2>▶ Eaglercraft Live Console</h2>
<div id="logs">Connecting to server logβ¦</div>
<form action="/command" method="POST" target="_blank"
onsubmit="setTimeout(()=>this.reset(),10)">
<input type="text" name="cmd"
placeholder="e.g. op YourName | say Hello!"
autocomplete="off" autofocus>
<button type="submit">Send</button>
</form>
<script>
const logs = document.getElementById('logs');
let last = '';
async function poll() {
try {
const t = await fetch('/logs').then(r => r.text());
if (t !== last) {
last = t;
const atBottom =
logs.scrollHeight - logs.clientHeight <= logs.scrollTop + 60;
logs.textContent = t;
if (atBottom) logs.scrollTop = logs.scrollHeight;
}
} catch(_) {}
setTimeout(poll, 1000);
}
poll();
</script>
</body>
</html>`;
// ββ HTTP Server βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
const server = http.createServer((req, res) => {
// ββ GET / β console page
if (req.method === 'GET' && req.url === '/') {
res.writeHead(200, { 'Content-Type': 'text/html; charset=utf-8' });
return res.end(PAGE_HTML);
}
// ββ GET /logs β last 200 lines of log
if (req.method === 'GET' && req.url === '/logs') {
exec(`tail -n 200 "${LOG_FILE}"`, (err, stdout) => {
res.writeHead(200, { 'Content-Type': 'text/plain; charset=utf-8' });
res.end(stdout || '(Waiting for server outputβ¦)');
});
return;
}
// ββ POST /command β write to MC stdin
if (req.method === 'POST' && req.url === '/command') {
let body = '';
req.on('data', chunk => { body += chunk; });
req.on('end', () => {
const cmd = new URLSearchParams(body).get('cmd') || '';
const safe = cmd.trim().replace(/[\r\n]+/g, ''); // no newline injection
if (safe && mcProcess.stdin.writable) {
mcProcess.stdin.write(safe + '\n');
console.log(`[Console] Command sent: ${safe}`);
}
res.writeHead(200, { 'Content-Type': 'text/plain' });
res.end('ok');
});
return;
}
res.writeHead(404);
res.end('Not found');
});
// ββ Upgrade β proxy WebSocket to Eaglercraft
server.on('upgrade', (req, socket, head) => {
console.log(`[Proxy] WS upgrade from ${socket.remoteAddress} β MC:${MC_PORT}`);
proxy.ws(req, socket, head);
});
server.listen(WEB_PORT, '0.0.0.0', () => {
console.log(`[WebConsole] Listening on http://0.0.0.0:${WEB_PORT}`);
});
NODEEOF
# βββββββββββββββββββββββββββββββββββββββββββββ
# 9. Launch
# βββββββββββββββββββββββββββββββββββββββββββββ
echo "[System] Handing off to Node.js master controller..."
exec node webconsole.js |