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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import sys
|
| 3 |
+
import subprocess
|
| 4 |
+
import json
|
| 5 |
+
import threading
|
| 6 |
+
import time
|
| 7 |
+
import queue
|
| 8 |
+
import signal
|
| 9 |
+
from flask import Flask, render_template_string, request, jsonify
|
| 10 |
+
from flask_sock import Sock
|
| 11 |
+
import psutil
|
| 12 |
+
|
| 13 |
+
app = Flask(__name__)
|
| 14 |
+
sock = Sock(app)
|
| 15 |
+
|
| 16 |
+
mc_process = None
|
| 17 |
+
output_queue = queue.Queue()
|
| 18 |
+
command_queue = queue.Queue()
|
| 19 |
+
server_ready = threading.Event()
|
| 20 |
+
|
| 21 |
+
def start_minecraft():
|
| 22 |
+
global mc_process
|
| 23 |
+
mc_dir = "/app/mcserver"
|
| 24 |
+
print("[MC] Starting Minecraft server...", flush=True)
|
| 25 |
+
mc_process = subprocess.Popen(
|
| 26 |
+
["java", "-Xms1G", "-Xmx14G", "-XX:+UseG1GC",
|
| 27 |
+
"-XX:+ParallelRefProcEnabled", "-XX:MaxGCPauseMillis=200",
|
| 28 |
+
"-jar", "server.jar", "nogui"],
|
| 29 |
+
cwd=mc_dir,
|
| 30 |
+
stdin=subprocess.PIPE,
|
| 31 |
+
stdout=subprocess.PIPE,
|
| 32 |
+
stderr=subprocess.STDOUT,
|
| 33 |
+
text=True,
|
| 34 |
+
bufsize=1,
|
| 35 |
+
preexec_fn=os.setsid
|
| 36 |
+
)
|
| 37 |
+
print(f"[MC] Minecraft PID: {mc_process.pid}", flush=True)
|
| 38 |
+
|
| 39 |
+
def read_output():
|
| 40 |
+
try:
|
| 41 |
+
for line in mc_process.stdout:
|
| 42 |
+
output_queue.put(line)
|
| 43 |
+
if "Done" in line and "For help, type" in line:
|
| 44 |
+
server_ready.set()
|
| 45 |
+
print("[MC] Server is ready!", flush=True)
|
| 46 |
+
except Exception as e:
|
| 47 |
+
print(f"[MC] Output error: {e}", flush=True)
|
| 48 |
+
|
| 49 |
+
threading.Thread(target=read_output, daemon=True).start()
|
| 50 |
+
|
| 51 |
+
def process_commands():
|
| 52 |
+
while True:
|
| 53 |
+
try:
|
| 54 |
+
cmd = command_queue.get(timeout=1)
|
| 55 |
+
if mc_process and mc_process.poll() is None:
|
| 56 |
+
try:
|
| 57 |
+
mc_process.stdin.write(cmd + "\n")
|
| 58 |
+
mc_process.stdin.flush()
|
| 59 |
+
print(f"[MC] Command: {cmd}", flush=True)
|
| 60 |
+
except Exception as e:
|
| 61 |
+
print(f"[MC] Command error: {e}", flush=True)
|
| 62 |
+
except queue.Empty:
|
| 63 |
+
continue
|
| 64 |
+
except Exception as e:
|
| 65 |
+
print(f"[MC] Processor error: {e}", flush=True)
|
| 66 |
+
break
|
| 67 |
+
|
| 68 |
+
threading.Thread(target=process_commands, daemon=True).start()
|
| 69 |
+
|
| 70 |
+
HTML_TEMPLATE = """<!DOCTYPE html>
|
| 71 |
+
<html lang="en">
|
| 72 |
+
<head>
|
| 73 |
+
<meta charset="UTF-8">
|
| 74 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
|
| 75 |
+
<title>Minecraft Server - Web Console</title>
|
| 76 |
+
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
|
| 77 |
+
<style>
|
| 78 |
+
* { margin: 0; padding: 0; box-sizing: border-box; }
|
| 79 |
+
:root {
|
| 80 |
+
--bg-primary: #0f1419; --bg-secondary: #161b22; --bg-tertiary: #1c2128;
|
| 81 |
+
--bg-card: #21262d; --border-color: #30363d;
|
| 82 |
+
--text-primary: #f0f6fc; --text-secondary: #c9d1d9; --text-muted: #8b949e;
|
| 83 |
+
--accent-blue: #58a6ff; --accent-green: #3fb950; --accent-red: #f85149;
|
| 84 |
+
--accent-yellow: #d29922; --accent-purple: #a371f7; --accent-cyan: #39c5cf;
|
| 85 |
+
--accent-orange: #fb8500;
|
| 86 |
+
}
|
| 87 |
+
body {
|
| 88 |
+
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
|
| 89 |
+
background: var(--bg-primary); color: var(--text-primary);
|
| 90 |
+
height: 100vh; overflow: hidden; font-size: 14px;
|
| 91 |
+
}
|
| 92 |
+
.top-nav {
|
| 93 |
+
background: var(--bg-secondary); border-bottom: 1px solid var(--border-color);
|
| 94 |
+
padding: 0 15px; display: flex; align-items: center; height: 50px;
|
| 95 |
+
}
|
| 96 |
+
.nav-tabs { display: flex; height: 100%; }
|
| 97 |
+
.nav-tab {
|
| 98 |
+
padding: 0 18px; display: flex; align-items: center; gap: 8px;
|
| 99 |
+
color: var(--text-muted); font-size: 14px; font-weight: 500;
|
| 100 |
+
border-bottom: 2px solid transparent; cursor: pointer; text-decoration: none;
|
| 101 |
+
}
|
| 102 |
+
.nav-tab:hover { color: var(--text-primary); background: rgba(255,255,255,0.03); }
|
| 103 |
+
.nav-tab.active { color: var(--accent-blue); border-bottom-color: var(--accent-blue); background: rgba(88,166,255,0.08); }
|
| 104 |
+
.nav-right { margin-left: auto; display: flex; gap: 5px; }
|
| 105 |
+
.nav-btn { background: transparent; border: none; color: var(--text-muted); padding: 8px 10px; cursor: pointer; border-radius: 6px; }
|
| 106 |
+
.nav-btn:hover { color: var(--text-primary); background: rgba(255,255,255,0.08); }
|
| 107 |
+
.main-container { display: flex; height: calc(100vh - 50px); }
|
| 108 |
+
.content-area { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
|
| 109 |
+
.console-header {
|
| 110 |
+
background: var(--bg-secondary); padding: 12px 15px;
|
| 111 |
+
border-bottom: 1px solid var(--border-color);
|
| 112 |
+
display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 10px;
|
| 113 |
+
}
|
| 114 |
+
.server-title { font-size: 16px; font-weight: 600; display: flex; align-items: center; gap: 10px; }
|
| 115 |
+
.server-title i { color: var(--accent-blue); font-size: 18px; }
|
| 116 |
+
.control-buttons { display: flex; gap: 6px; }
|
| 117 |
+
.btn { padding: 8px 14px; border: none; border-radius: 6px; font-size: 13px; font-weight: 600; cursor: pointer; display: flex; align-items: center; gap: 6px; }
|
| 118 |
+
.btn-primary { background: var(--accent-blue); color: #fff; }
|
| 119 |
+
.btn-secondary { background: var(--bg-card); color: var(--text-secondary); border: 1px solid var(--border-color); }
|
| 120 |
+
.btn-danger { background: var(--accent-red); color: #fff; }
|
| 121 |
+
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
|
| 122 |
+
.terminal-container { flex: 1; background: var(--bg-primary); overflow: hidden; display: flex; flex-direction: column; }
|
| 123 |
+
.terminal {
|
| 124 |
+
flex: 1; padding: 12px 15px; font-family: 'SFMono-Regular', Consolas, monospace;
|
| 125 |
+
font-size: 13px; line-height: 1.6; color: var(--text-secondary);
|
| 126 |
+
overflow-y: auto; white-space: pre-wrap; word-wrap: break-word;
|
| 127 |
+
}
|
| 128 |
+
.log-line { margin: 1px 0; padding: 2px 0; border-radius: 3px; }
|
| 129 |
+
.log-line:hover { background: rgba(255,255,255,0.03); }
|
| 130 |
+
.log-debug { color: #6e7681; } .log-info { color: var(--accent-blue); }
|
| 131 |
+
.log-warn { color: var(--accent-yellow); } .log-error { color: var(--accent-red); font-weight: 500; }
|
| 132 |
+
.log-fatal { color: var(--accent-red); background: rgba(248,81,73,0.1); font-weight: 600; }
|
| 133 |
+
.log-success { color: var(--accent-green); } .log-chat { color: var(--accent-purple); }
|
| 134 |
+
.log-join { color: var(--accent-green); } .log-leave { color: var(--accent-orange); }
|
| 135 |
+
.log-time { color: #6e7681; font-size: 12px; }
|
| 136 |
+
.log-level { display: inline-block; padding: 0 6px; border-radius: 3px; font-size: 11px; font-weight: 700; margin-right: 6px; }
|
| 137 |
+
.level-info { background: rgba(88,166,255,0.2); color: var(--accent-blue); }
|
| 138 |
+
.level-warn { background: rgba(210,153,34,0.2); color: var(--accent-yellow); }
|
| 139 |
+
.level-error { background: rgba(248,81,73,0.2); color: var(--accent-red); }
|
| 140 |
+
.command-area {
|
| 141 |
+
background: var(--bg-secondary); border-top: 1px solid var(--border-color);
|
| 142 |
+
padding: 12px 15px; display: flex; gap: 10px;
|
| 143 |
+
}
|
| 144 |
+
.command-input-wrapper {
|
| 145 |
+
flex: 1; display: flex; align-items: center; background: var(--bg-primary);
|
| 146 |
+
border: 1px solid var(--border-color); border-radius: 8px; padding: 0 12px;
|
| 147 |
+
}
|
| 148 |
+
.command-input-wrapper:focus-within { border-color: var(--accent-blue); }
|
| 149 |
+
.command-input-wrapper i { color: var(--text-muted); margin-right: 10px; }
|
| 150 |
+
#commandInput { flex: 1; background: transparent; border: none; color: var(--text-primary); padding: 12px 0; font-size: 14px; outline: none; }
|
| 151 |
+
.send-btn { background: var(--accent-green); color: #fff; border: none; padding: 12px 20px; border-radius: 8px; cursor: pointer; font-weight: 600; }
|
| 152 |
+
.send-btn:disabled { opacity: 0.4; }
|
| 153 |
+
.sidebar {
|
| 154 |
+
width: 280px; background: var(--bg-secondary); border-left: 1px solid var(--border-color);
|
| 155 |
+
padding: 15px; overflow-y: auto; display: flex; flex-direction: column; gap: 10px;
|
| 156 |
+
}
|
| 157 |
+
.stat-card { background: var(--bg-card); border: 1px solid var(--border-color); border-radius: 10px; padding: 14px; display: flex; align-items: center; gap: 12px; }
|
| 158 |
+
.stat-card:hover { border-color: var(--accent-blue); }
|
| 159 |
+
.stat-icon { width: 40px; height: 40px; border-radius: 10px; display: flex; align-items: center; justify-content: center; font-size: 18px; }
|
| 160 |
+
.stat-icon.blue { background: rgba(88,166,255,0.15); color: var(--accent-blue); }
|
| 161 |
+
.stat-icon.green { background: rgba(63,185,80,0.15); color: var(--accent-green); }
|
| 162 |
+
.stat-icon.red { background: rgba(248,81,73,0.15); color: var(--accent-red); }
|
| 163 |
+
.stat-icon.yellow { background: rgba(210,153,34,0.15); color: var(--accent-yellow); }
|
| 164 |
+
.stat-icon.purple { background: rgba(163,113,247,0.15); color: var(--accent-purple); }
|
| 165 |
+
.stat-icon.cyan { background: rgba(57,197,207,0.15); color: var(--accent-cyan); }
|
| 166 |
+
.stat-info { flex: 1; }
|
| 167 |
+
.stat-label { font-size: 11px; color: var(--text-muted); text-transform: uppercase; margin-bottom: 3px; }
|
| 168 |
+
.stat-value { font-size: 16px; font-weight: 700; }
|
| 169 |
+
.stat-sub { font-size: 11px; color: var(--text-muted); }
|
| 170 |
+
.status-indicator { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 20px; font-size: 11px; font-weight: 700; text-transform: uppercase; }
|
| 171 |
+
.status-online { background: rgba(63,185,80,0.2); color: var(--accent-green); }
|
| 172 |
+
.status-offline { background: rgba(248,81,73,0.2); color: var(--accent-red); }
|
| 173 |
+
.pulse { width: 7px; height: 7px; border-radius: 50%; background: currentColor; animation: pulse 2s infinite; }
|
| 174 |
+
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.4; } }
|
| 175 |
+
.connection-bar { position: absolute; top: 0; left: 0; right: 0; padding: 8px 15px; font-size: 12px; font-weight: 600; display: flex; align-items: center; gap: 8px; z-index: 50; }
|
| 176 |
+
.connection-bar.connected { background: rgba(63,185,80,0.15); color: var(--accent-green); }
|
| 177 |
+
.connection-bar.disconnected { background: rgba(248,81,73,0.15); color: var(--accent-red); }
|
| 178 |
+
.connection-bar.connecting { background: rgba(210,153,34,0.15); color: var(--accent-yellow); }
|
| 179 |
+
.file-manager { flex: 1; display: none; flex-direction: column; background: var(--bg-primary); }
|
| 180 |
+
.file-manager.active { display: flex; }
|
| 181 |
+
.file-header { background: var(--bg-secondary); padding: 12px 15px; border-bottom: 1px solid var(--border-color); display: flex; align-items: center; gap: 10px; }
|
| 182 |
+
.breadcrumb { flex: 1; display: flex; align-items: center; gap: 5px; font-size: 14px; overflow-x: auto; }
|
| 183 |
+
.breadcrumb-item { white-space: nowrap; cursor: pointer; }
|
| 184 |
+
.breadcrumb-item:hover { color: var(--accent-blue); }
|
| 185 |
+
.breadcrumb-separator { color: var(--text-muted); }
|
| 186 |
+
.breadcrumb-item.active { color: var(--accent-blue); font-weight: 600; }
|
| 187 |
+
.file-actions { display: flex; gap: 8px; }
|
| 188 |
+
.file-btn { background: var(--bg-card); border: 1px solid var(--border-color); color: var(--text-secondary); padding: 8px 12px; border-radius: 6px; cursor: pointer; font-size: 13px; display: flex; align-items: center; gap: 6px; }
|
| 189 |
+
.file-btn:hover { background: var(--border-color); color: var(--text-primary); }
|
| 190 |
+
.file-list { flex: 1; overflow-y: auto; padding: 10px; }
|
| 191 |
+
.file-item { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 8px; cursor: pointer; margin-bottom: 2px; }
|
| 192 |
+
.file-item:hover { background: var(--bg-tertiary); }
|
| 193 |
+
.file-icon { width: 36px; height: 36px; border-radius: 8px; display: flex; align-items: center; justify-content: center; font-size: 16px; }
|
| 194 |
+
.file-icon.folder { background: rgba(88,166,255,0.15); color: var(--accent-blue); }
|
| 195 |
+
.file-icon.file { background: var(--bg-tertiary); color: var(--text-muted); }
|
| 196 |
+
.file-icon.image { background: rgba(163,113,247,0.15); color: var(--accent-purple); }
|
| 197 |
+
.file-icon.code { background: rgba(57,197,207,0.15); color: var(--accent-cyan); }
|
| 198 |
+
.file-icon.config { background: rgba(210,153,34,0.15); color: var(--accent-yellow); }
|
| 199 |
+
.file-info { flex: 1; }
|
| 200 |
+
.file-name { font-size: 14px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
|
| 201 |
+
.file-meta { font-size: 12px; color: var(--text-muted); }
|
| 202 |
+
.file-size { font-size: 12px; color: var(--text-muted); white-space: nowrap; }
|
| 203 |
+
::-webkit-scrollbar { width: 8px; height: 8px; }
|
| 204 |
+
::-webkit-scrollbar-track { background: var(--bg-primary); }
|
| 205 |
+
::-webkit-scrollbar-thumb { background: var(--border-color); border-radius: 4px; }
|
| 206 |
+
@media (max-width: 768px) {
|
| 207 |
+
.top-nav { height: 45px; }
|
| 208 |
+
.nav-tab { padding: 0 12px; font-size: 13px; }
|
| 209 |
+
.main-container { flex-direction: column; height: calc(100vh - 45px); }
|
| 210 |
+
.sidebar { width: 100%; border-left: none; border-top: 1px solid var(--border-color); padding: 10px; flex-direction: row; overflow-x: auto; gap: 8px; order: 2; min-height: 80px; }
|
| 211 |
+
.stat-card { min-width: 140px; padding: 10px; flex-direction: column; text-align: center; }
|
| 212 |
+
.stat-icon { width: 32px; height: 32px; }
|
| 213 |
+
.stat-sub { display: none; }
|
| 214 |
+
.content-area { order: 1; }
|
| 215 |
+
.console-header { padding: 10px; }
|
| 216 |
+
.server-title { font-size: 14px; }
|
| 217 |
+
.btn { padding: 6px 10px; font-size: 12px; }
|
| 218 |
+
.terminal { font-size: 12px; padding: 10px; }
|
| 219 |
+
.command-area { padding: 10px; }
|
| 220 |
+
#commandInput { padding: 10px 0; font-size: 13px; }
|
| 221 |
+
.send-btn { padding: 10px 14px; font-size: 13px; }
|
| 222 |
+
}
|
| 223 |
+
@media (max-width: 480px) {
|
| 224 |
+
.nav-tab span { display: none; }
|
| 225 |
+
.nav-tab { padding: 0 15px; }
|
| 226 |
+
.btn span { display: none; }
|
| 227 |
+
.btn { padding: 8px; }
|
| 228 |
+
.stat-card { min-width: 100px; }
|
| 229 |
+
.stat-icon { width: 28px; height: 28px; }
|
| 230 |
+
}
|
| 231 |
+
</style>
|
| 232 |
+
</head>
|
| 233 |
+
<body>
|
| 234 |
+
<nav class="top-nav">
|
| 235 |
+
<div class="nav-tabs">
|
| 236 |
+
<a class="nav-tab active" onclick="switchTab('console', this)" id="consoleTab">
|
| 237 |
+
<i class="fas fa-terminal"></i><span>Console</span>
|
| 238 |
+
</a>
|
| 239 |
+
<a class="nav-tab" onclick="switchTab('files', this)" id="filesTab">
|
| 240 |
+
<i class="fas fa-folder"></i><span>Files</span>
|
| 241 |
+
</a>
|
| 242 |
+
</div>
|
| 243 |
+
<div class="nav-right">
|
| 244 |
+
<button class="nav-btn" onclick="toggleSettings()"><i class="fas fa-cog"></i></button>
|
| 245 |
+
<button class="nav-btn" onclick="toggleFullscreen()"><i class="fas fa-expand"></i></button>
|
| 246 |
+
</div>
|
| 247 |
+
</nav>
|
| 248 |
+
<div class="main-container">
|
| 249 |
+
<div class="content-area">
|
| 250 |
+
<div class="console-section" id="consoleSection">
|
| 251 |
+
<div class="connection-bar connecting" id="connectionBar">
|
| 252 |
+
<i class="fas fa-circle-notch fa-spin"></i><span>Connecting...</span>
|
| 253 |
+
</div>
|
| 254 |
+
<div class="console-header">
|
| 255 |
+
<div class="server-title">
|
| 256 |
+
<i class="fas fa-cube"></i>
|
| 257 |
+
<span>Minecraft Server</span>
|
| 258 |
+
<span class="status-indicator status-offline" id="serverStatus">
|
| 259 |
+
<span class="pulse"></span><span>Offline</span>
|
| 260 |
+
</span>
|
| 261 |
+
</div>
|
| 262 |
+
<div class="control-buttons">
|
| 263 |
+
<button class="btn btn-primary" id="startBtn" onclick="sendCmd('start')" disabled><i class="fas fa-play"></i><span>Start</span></button>
|
| 264 |
+
<button class="btn btn-secondary" id="restartBtn" onclick="sendCmd('restart')" disabled><i class="fas fa-redo"></i><span>Restart</span></button>
|
| 265 |
+
<button class="btn btn-danger" id="stopBtn" onclick="sendCmd('stop')" disabled><i class="fas fa-stop"></i><span>Stop</span></button>
|
| 266 |
+
</div>
|
| 267 |
+
</div>
|
| 268 |
+
<div class="terminal-container">
|
| 269 |
+
<div class="terminal" id="terminal"></div>
|
| 270 |
+
</div>
|
| 271 |
+
<div class="command-area">
|
| 272 |
+
<div class="command-input-wrapper">
|
| 273 |
+
<i class="fas fa-angle-right"></i>
|
| 274 |
+
<input type="text" id="commandInput" placeholder="Type a command..." autocomplete="off" disabled>
|
| 275 |
+
</div>
|
| 276 |
+
<button class="send-btn" id="sendBtn" onclick="sendInput()" disabled><i class="fas fa-paper-plane"></i><span>Send</span></button>
|
| 277 |
+
</div>
|
| 278 |
+
</div>
|
| 279 |
+
<div class="file-manager" id="fileSection">
|
| 280 |
+
<div class="file-header">
|
| 281 |
+
<div class="breadcrumb" id="breadcrumb">
|
| 282 |
+
<span class="breadcrumb-item active" onclick="goHome()"><i class="fas fa-home"></i></span>
|
| 283 |
+
<span class="breadcrumb-separator">/</span>
|
| 284 |
+
<span class="breadcrumb-item active">mcserver</span>
|
| 285 |
+
</div>
|
| 286 |
+
<div class="file-actions">
|
| 287 |
+
<button class="file-btn" onclick="loadFiles()"><i class="fas fa-sync-alt"></i><span>Refresh</span></button>
|
| 288 |
+
<button class="file-btn" onclick="goBack()"><i class="fas fa-arrow-up"></i><span>Up</span></button>
|
| 289 |
+
</div>
|
| 290 |
+
</div>
|
| 291 |
+
<div class="file-list" id="fileList">
|
| 292 |
+
<div style="text-align: center; padding: 40px; color: var(--text-muted);">
|
| 293 |
+
<i class="fas fa-folder-open" style="font-size: 48px; margin-bottom: 15px; opacity: 0.5;"></i>
|
| 294 |
+
<p>Loading files...</p>
|
| 295 |
+
</div>
|
| 296 |
+
</div>
|
| 297 |
+
</div>
|
| 298 |
+
</div>
|
| 299 |
+
<div class="sidebar">
|
| 300 |
+
<div class="stat-card">
|
| 301 |
+
<div class="stat-icon blue"><i class="fas fa-network-wired"></i></div>
|
| 302 |
+
<div class="stat-info">
|
| 303 |
+
<div class="stat-label">Address</div>
|
| 304 |
+
<div class="stat-value" id="serverAddress" style="font-size: 13px;">--</div>
|
| 305 |
+
<div class="stat-sub">Port 25565</div>
|
| 306 |
+
</div>
|
| 307 |
+
</div>
|
| 308 |
+
<div class="stat-card">
|
| 309 |
+
<div class="stat-icon red"><i class="fas fa-clock"></i></div>
|
| 310 |
+
<div class="stat-info">
|
| 311 |
+
<div class="stat-label">Uptime</div>
|
| 312 |
+
<div class="stat-value" id="uptime">--</div>
|
| 313 |
+
<div class="stat-sub" id="uptimeSub">Not running</div>
|
| 314 |
+
</div>
|
| 315 |
+
</div>
|
| 316 |
+
<div class="stat-card">
|
| 317 |
+
<div class="stat-icon yellow"><i class="fas fa-microchip"></i></div>
|
| 318 |
+
<div class="stat-info">
|
| 319 |
+
<div class="stat-label">CPU Load</div>
|
| 320 |
+
<div class="stat-value" id="cpuLoad">--%</div>
|
| 321 |
+
<div class="stat-sub">System usage</div>
|
| 322 |
+
</div>
|
| 323 |
+
</div>
|
| 324 |
+
<div class="stat-card">
|
| 325 |
+
<div class="stat-icon purple"><i class="fas fa-memory"></i></div>
|
| 326 |
+
<div class="stat-info">
|
| 327 |
+
<div class="stat-label">Memory</div>
|
| 328 |
+
<div class="stat-value" id="memoryUsage">--%</div>
|
| 329 |
+
<div class="stat-sub" id="memorySub">-- / -- GB</div>
|
| 330 |
+
</div>
|
| 331 |
+
</div>
|
| 332 |
+
<div class="stat-card">
|
| 333 |
+
<div class="stat-icon cyan"><i class="fas fa-hdd"></i></div>
|
| 334 |
+
<div class="stat-info">
|
| 335 |
+
<div class="stat-label">Disk</div>
|
| 336 |
+
<div class="stat-value" id="diskUsage">-- MB</div>
|
| 337 |
+
<div class="stat-sub">Server size</div>
|
| 338 |
+
</div>
|
| 339 |
+
</div>
|
| 340 |
+
<div class="stat-card">
|
| 341 |
+
<div class="stat-icon green"><i class="fas fa-users"></i></div>
|
| 342 |
+
<div class="stat-info">
|
| 343 |
+
<div class="stat-label">Players</div>
|
| 344 |
+
<div class="stat-value" id="playerCount">--</div>
|
| 345 |
+
<div class="stat-sub">Online</div>
|
| 346 |
+
</div>
|
| 347 |
+
</div>
|
| 348 |
+
</div>
|
| 349 |
+
</div>
|
| 350 |
+
<script>
|
| 351 |
+
const terminal = document.getElementById('terminal');
|
| 352 |
+
const commandInput = document.getElementById('commandInput');
|
| 353 |
+
const sendBtn = document.getElementById('sendBtn');
|
| 354 |
+
const startBtn = document.getElementById('startBtn');
|
| 355 |
+
const restartBtn = document.getElementById('restartBtn');
|
| 356 |
+
const stopBtn = document.getElementById('stopBtn');
|
| 357 |
+
const connectionBar = document.getElementById('connectionBar');
|
| 358 |
+
let ws = null, reconnectAttempts = 0, maxReconnectAttempts = 10;
|
| 359 |
+
let serverStartTime = null, isServerRunning = false, currentPath = '/app/mcserver';
|
| 360 |
+
|
| 361 |
+
function getLogClass(text) {
|
| 362 |
+
if (text.includes('ERROR') || text.includes('Exception')) return 'log-error';
|
| 363 |
+
if (text.includes('WARN')) return 'log-warn';
|
| 364 |
+
if (text.includes('FATAL')) return 'log-fatal';
|
| 365 |
+
if (text.includes('joined') || text.includes('left')) return 'log-join';
|
| 366 |
+
if (text.includes('[CHAT]')) return 'log-chat';
|
| 367 |
+
if (text.includes('Done') || text.includes('Starting')) return 'log-success';
|
| 368 |
+
if (text.includes('INFO')) return 'log-info';
|
| 369 |
+
return '';
|
| 370 |
+
}
|
| 371 |
+
|
| 372 |
+
function updateConnectionStatus(status, message) {
|
| 373 |
+
connectionBar.className = 'connection-bar ' + status;
|
| 374 |
+
const icons = { 'connected': 'fa-check-circle', 'disconnected': 'fa-exclamation-triangle', 'connecting': 'fa-circle-notch fa-spin' };
|
| 375 |
+
connectionBar.innerHTML = '<i class="fas ' + icons[status] + '"></i><span>' + message + '</span>';
|
| 376 |
+
}
|
| 377 |
+
|
| 378 |
+
function updateServerStatus(running) {
|
| 379 |
+
isServerRunning = running;
|
| 380 |
+
const statusEl = document.getElementById('serverStatus');
|
| 381 |
+
if (running) {
|
| 382 |
+
statusEl.className = 'status-indicator status-online';
|
| 383 |
+
statusEl.innerHTML = '<span class="pulse"></span><span>Online</span>';
|
| 384 |
+
startBtn.disabled = true; restartBtn.disabled = false; stopBtn.disabled = false;
|
| 385 |
+
commandInput.disabled = false; sendBtn.disabled = false;
|
| 386 |
+
if (!serverStartTime) serverStartTime = Date.now();
|
| 387 |
+
} else {
|
| 388 |
+
statusEl.className = 'status-indicator status-offline';
|
| 389 |
+
statusEl.innerHTML = '<span class="pulse"></span><span>Offline</span>';
|
| 390 |
+
startBtn.disabled = false; restartBtn.disabled = true; stopBtn.disabled = true;
|
| 391 |
+
commandInput.disabled = true; sendBtn.disabled = true;
|
| 392 |
+
serverStartTime = null;
|
| 393 |
+
}
|
| 394 |
+
}
|
| 395 |
+
|
| 396 |
+
function addTerminalLine(text) {
|
| 397 |
+
const line = document.createElement('div');
|
| 398 |
+
line.className = 'log-line ' + getLogClass(text);
|
| 399 |
+
let formatted = text
|
| 400 |
+
.replace(/(\[\d{2}:\d{2}:\d{2}\])/g, '<span class="log-time">$1</span>')
|
| 401 |
+
.replace(/\[Server thread\/INFO\]:/g, '<span class="log-level level-info">INFO</span>')
|
| 402 |
+
.replace(/\[Server thread\/WARN\]:/g, '<span class="log-level level-warn">WARN</span>')
|
| 403 |
+
.replace(/\[Server thread\/ERROR\]:/g, '<span class="log-level level-error">ERROR</span>')
|
| 404 |
+
.replace(/\[Server thread\/FATAL\]:/g, '<span class="log-level level-error">FATAL</span>');
|
| 405 |
+
line.innerHTML = formatted;
|
| 406 |
+
terminal.appendChild(line);
|
| 407 |
+
terminal.scrollTop = terminal.scrollHeight;
|
| 408 |
+
while (terminal.children.length > 500) terminal.removeChild(terminal.firstChild);
|
| 409 |
+
}
|
| 410 |
+
|
| 411 |
+
function formatUptime(ms) {
|
| 412 |
+
const seconds = Math.floor(ms / 1000);
|
| 413 |
+
const minutes = Math.floor(seconds / 60);
|
| 414 |
+
const hours = Math.floor(minutes / 60);
|
| 415 |
+
const days = Math.floor(hours / 24);
|
| 416 |
+
if (days > 0) return days + 'd ' + (hours % 24) + 'h';
|
| 417 |
+
if (hours > 0) return hours + 'h ' + (minutes % 60) + 'm';
|
| 418 |
+
if (minutes > 0) return minutes + 'm ' + (seconds % 60) + 's';
|
| 419 |
+
return seconds + 's';
|
| 420 |
+
}
|
| 421 |
+
|
| 422 |
+
function updateUptime() {
|
| 423 |
+
if (serverStartTime && isServerRunning) {
|
| 424 |
+
document.getElementById('uptime').textContent = formatUptime(Date.now() - serverStartTime);
|
| 425 |
+
document.getElementById('uptimeSub').textContent = 'Running';
|
| 426 |
+
} else {
|
| 427 |
+
document.getElementById('uptime').textContent = '--';
|
| 428 |
+
document.getElementById('uptimeSub').textContent = 'Not running';
|
| 429 |
+
}
|
| 430 |
+
}
|
| 431 |
+
setInterval(updateUptime, 1000);
|
| 432 |
+
|
| 433 |
+
function connect() {
|
| 434 |
+
const protocol = window.location.protocol === 'https:' ? 'wss:' : 'ws:';
|
| 435 |
+
ws = new WebSocket(protocol + '//' + window.location.host + '/ws');
|
| 436 |
+
ws.onopen = () => {
|
| 437 |
+
reconnectAttempts = 0;
|
| 438 |
+
updateConnectionStatus('connected', 'Connected');
|
| 439 |
+
setTimeout(() => { connectionBar.style.display = 'none'; }, 2000);
|
| 440 |
+
};
|
| 441 |
+
ws.onmessage = (event) => {
|
| 442 |
+
const data = JSON.parse(event.data);
|
| 443 |
+
if (data.type === 'output') addTerminalLine(data.data);
|
| 444 |
+
else if (data.type === 'stats') {
|
| 445 |
+
document.getElementById('cpuLoad').textContent = data.cpu.toFixed(1) + '%';
|
| 446 |
+
document.getElementById('memoryUsage').textContent = data.memory.toFixed(1) + '%';
|
| 447 |
+
const memTotal = (data.memoryTotal / 1024 / 1024 / 1024).toFixed(2);
|
| 448 |
+
const memUsed = ((data.memoryTotal * data.memory / 100) / 1024 / 1024 / 1024).toFixed(2);
|
| 449 |
+
document.getElementById('memorySub').textContent = memUsed + ' / ' + memTotal + ' GB';
|
| 450 |
+
updateServerStatus(data.running);
|
| 451 |
+
if (data.players !== undefined) document.getElementById('playerCount').textContent = data.players;
|
| 452 |
+
if (data.disk !== undefined) document.getElementById('diskUsage').textContent = (data.disk / 1024 / 1024).toFixed(2) + ' MB';
|
| 453 |
+
}
|
| 454 |
+
};
|
| 455 |
+
ws.onclose = () => {
|
| 456 |
+
connectionBar.style.display = 'flex';
|
| 457 |
+
updateConnectionStatus('disconnected', 'Reconnecting...');
|
| 458 |
+
updateServerStatus(false);
|
| 459 |
+
if (reconnectAttempts < maxReconnectAttempts) {
|
| 460 |
+
reconnectAttempts++;
|
| 461 |
+
setTimeout(connect, 3000);
|
| 462 |
+
}
|
| 463 |
+
};
|
| 464 |
+
}
|
| 465 |
+
connect();
|
| 466 |
+
|
| 467 |
+
function sendInput() {
|
| 468 |
+
const cmd = commandInput.value.trim();
|
| 469 |
+
if (cmd && ws && ws.readyState === WebSocket.OPEN) {
|
| 470 |
+
ws.send(JSON.stringify({type: 'command', data: cmd}));
|
| 471 |
+
commandInput.value = '';
|
| 472 |
+
}
|
| 473 |
+
}
|
| 474 |
+
|
| 475 |
+
function sendCmd(cmd) {
|
| 476 |
+
if (ws && ws.readyState === WebSocket.OPEN) ws.send(JSON.stringify({type: 'command', data: cmd}));
|
| 477 |
+
}
|
| 478 |
+
|
| 479 |
+
commandInput.addEventListener('keypress', (e) => { if (e.key === 'Enter') sendInput(); });
|
| 480 |
+
|
| 481 |
+
function switchTab(tab, element) {
|
| 482 |
+
document.querySelectorAll('.nav-tab').forEach(t => t.classList.remove('active'));
|
| 483 |
+
element.classList.add('active');
|
| 484 |
+
if (tab === 'console') {
|
| 485 |
+
document.getElementById('consoleSection').style.display = 'flex';
|
| 486 |
+
document.getElementById('fileSection').classList.remove('active');
|
| 487 |
+
} else {
|
| 488 |
+
document.getElementById('consoleSection').style.display = 'none';
|
| 489 |
+
document.getElementById('fileSection').classList.add('active');
|
| 490 |
+
loadFiles();
|
| 491 |
+
}
|
| 492 |
+
}
|
| 493 |
+
|
| 494 |
+
function toggleFullscreen() {
|
| 495 |
+
if (!document.fullscreenElement) document.documentElement.requestFullscreen();
|
| 496 |
+
else document.exitFullscreen();
|
| 497 |
+
}
|
| 498 |
+
|
| 499 |
+
function toggleSettings() { alert('Settings coming soon!'); }
|
| 500 |
+
|
| 501 |
+
function getFileIconClass(filename, isDir) {
|
| 502 |
+
if (isDir) return 'folder';
|
| 503 |
+
const ext = filename.split('.').pop().toLowerCase();
|
| 504 |
+
if (['png','jpg','jpeg','gif','bmp','ico'].includes(ext)) return 'image';
|
| 505 |
+
if (['js','py','java','cpp','c','h','php','rb','go','rs'].includes(ext)) return 'code';
|
| 506 |
+
if (['json','xml','yml','yaml','properties','conf','cfg','ini'].includes(ext)) return 'config';
|
| 507 |
+
return 'file';
|
| 508 |
+
}
|
| 509 |
+
|
| 510 |
+
function getFileIcon(filename, isDir) {
|
| 511 |
+
if (isDir) return 'fa-folder';
|
| 512 |
+
const ext = filename.split('.').pop().toLowerCase();
|
| 513 |
+
const icons = { 'png': 'fa-file-image', 'jpg': 'fa-file-image', 'jpeg': 'fa-file-image', 'json': 'fa-file-code', 'xml': 'fa-file-code', 'yml': 'fa-file-code', 'properties': 'fa-file-cog', 'conf': 'fa-file-cog', 'cfg': 'fa-file-cog', 'txt': 'fa-file-alt', 'md': 'fa-file-alt', 'log': 'fa-file-alt', 'jar': 'fa-file-archive', 'zip': 'fa-file-archive', 'db': 'fa-database', 'sql': 'fa-database' };
|
| 514 |
+
return icons[ext] || 'fa-file';
|
| 515 |
+
}
|
| 516 |
+
|
| 517 |
+
function formatSize(bytes) {
|
| 518 |
+
if (bytes === 0) return '0 B';
|
| 519 |
+
const k = 1024;
|
| 520 |
+
const sizes = ['B', 'KB', 'MB', 'GB'];
|
| 521 |
+
const i = Math.floor(Math.log(bytes) / Math.log(k));
|
| 522 |
+
return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + ' ' + sizes[i];
|
| 523 |
+
}
|
| 524 |
+
|
| 525 |
+
async function loadFiles() {
|
| 526 |
+
const fileList = document.getElementById('fileList');
|
| 527 |
+
fileList.innerHTML = '<div style="text-align: center; padding: 40px; color: var(--text-muted);"><i class="fas fa-spinner fa-spin" style="font-size: 32px; margin-bottom: 15px;"></i><p>Loading...</p></div>';
|
| 528 |
+
try {
|
| 529 |
+
const response = await fetch('/api/files?path=' + encodeURIComponent(currentPath));
|
| 530 |
+
const files = await response.json();
|
| 531 |
+
if (files.length === 0) {
|
| 532 |
+
fileList.innerHTML = '<div style="text-align: center; padding: 40px; color: var(--text-muted);"><i class="fas fa-folder-open" style="font-size: 48px; margin-bottom: 15px; opacity: 0.5;"></i><p>Empty folder</p></div>';
|
| 533 |
+
return;
|
| 534 |
+
}
|
| 535 |
+
fileList.innerHTML = '';
|
| 536 |
+
files.sort((a, b) => { if (a.is_dir === b.is_dir) return a.name.localeCompare(b.name); return b.is_dir - a.is_dir; });
|
| 537 |
+
files.forEach(file => {
|
| 538 |
+
const item = document.createElement('div');
|
| 539 |
+
item.className = 'file-item';
|
| 540 |
+
const iconClass = getFileIconClass(file.name, file.is_dir);
|
| 541 |
+
const icon = getFileIcon(file.name, file.is_dir);
|
| 542 |
+
item.innerHTML = '<div class="file-icon ' + iconClass + '"><i class="fas ' + icon + '"></i></div><div class="file-info"><div class="file-name">' + file.name + '</div><div class="file-meta">' + (file.is_dir ? 'Folder' : formatSize(file.size)) + '</div></div><div class="file-size">' + (file.is_dir ? '' : formatSize(file.size)) + '</div>';
|
| 543 |
+
if (file.is_dir) item.onclick = () => { currentPath = file.path; updateBreadcrumb(); loadFiles(); };
|
| 544 |
+
fileList.appendChild(item);
|
| 545 |
+
});
|
| 546 |
+
} catch (error) {
|
| 547 |
+
fileList.innerHTML = '<div style="text-align: center; padding: 40px; color: var(--accent-red);"><i class="fas fa-exclamation-triangle" style="font-size: 32px; margin-bottom: 15px;"></i><p>Error loading files</p></div>';
|
| 548 |
+
}
|
| 549 |
+
}
|
| 550 |
+
|
| 551 |
+
function updateBreadcrumb() {
|
| 552 |
+
const parts = currentPath.replace('/app/mcserver', '').split('/').filter(p => p);
|
| 553 |
+
let html = '<span class="breadcrumb-item active" onclick="goHome()"><i class="fas fa-home"></i></span>';
|
| 554 |
+
if (parts.length === 0) {
|
| 555 |
+
html += '<span class="breadcrumb-separator">/</span><span class="breadcrumb-item active">mcserver</span>';
|
| 556 |
+
} else {
|
| 557 |
+
let path = '/app/mcserver';
|
| 558 |
+
html += '<span class="breadcrumb-separator">/</span><span class="breadcrumb-item" onclick="goHome()">mcserver</span>';
|
| 559 |
+
parts.forEach((part, i) => {
|
| 560 |
+
path += '/' + part;
|
| 561 |
+
const isLast = i === parts.length - 1;
|
| 562 |
+
html += '<span class="breadcrumb-separator">/</span><span class="breadcrumb-item ' + (isLast ? 'active' : '') + '" ' + (!isLast ? 'onclick="navigateTo(\'' + path + '\')"' : '') + '>' + part + '</span>';
|
| 563 |
+
});
|
| 564 |
+
}
|
| 565 |
+
document.getElementById('breadcrumb').innerHTML = html;
|
| 566 |
+
}
|
| 567 |
+
|
| 568 |
+
function goHome() { currentPath = '/app/mcserver'; updateBreadcrumb(); loadFiles(); }
|
| 569 |
+
function navigateTo(path) { currentPath = path; updateBreadcrumb(); loadFiles(); }
|
| 570 |
+
function goBack() {
|
| 571 |
+
if (currentPath === '/app/mcserver') return;
|
| 572 |
+
const parts = currentPath.split('/');
|
| 573 |
+
parts.pop();
|
| 574 |
+
currentPath = parts.join('/') || '/app/mcserver';
|
| 575 |
+
updateBreadcrumb();
|
| 576 |
+
loadFiles();
|
| 577 |
+
}
|
| 578 |
+
|
| 579 |
+
document.getElementById('serverAddress').textContent = window.location.hostname;
|
| 580 |
+
addTerminalLine('Connecting to Minecraft server...');
|
| 581 |
+
</script>
|
| 582 |
+
</body>
|
| 583 |
+
</html>"""
|
| 584 |
+
|
| 585 |
+
@app.route('/')
|
| 586 |
+
def index():
|
| 587 |
+
return render_template_string(HTML_TEMPLATE)
|
| 588 |
+
|
| 589 |
+
@app.route('/health')
|
| 590 |
+
def health():
|
| 591 |
+
return {'status': 'running', 'minecraft': mc_process is not None and mc_process.poll() is None}
|
| 592 |
+
|
| 593 |
+
@app.route('/api/files')
|
| 594 |
+
def get_files():
|
| 595 |
+
path = request.args.get('path', '/app/mcserver')
|
| 596 |
+
if not path.startswith('/app/mcserver'):
|
| 597 |
+
path = '/app/mcserver'
|
| 598 |
+
try:
|
| 599 |
+
files = []
|
| 600 |
+
for item in sorted(os.listdir(path)):
|
| 601 |
+
item_path = os.path.join(path, item)
|
| 602 |
+
is_dir = os.path.isdir(item_path)
|
| 603 |
+
size = os.path.getsize(item_path) if not is_dir else 0
|
| 604 |
+
files.append({'name': item, 'is_dir': is_dir, 'size': size, 'path': item_path})
|
| 605 |
+
return jsonify(files)
|
| 606 |
+
except Exception as e:
|
| 607 |
+
return jsonify({'error': str(e)}), 500
|
| 608 |
+
|
| 609 |
+
@sock.route('/ws')
|
| 610 |
+
def websocket(ws):
|
| 611 |
+
print("[WS] Client connected", flush=True)
|
| 612 |
+
history = []
|
| 613 |
+
temp_list = []
|
| 614 |
+
while not output_queue.empty() and len(temp_list) < 100:
|
| 615 |
+
try:
|
| 616 |
+
line = output_queue.get_nowait()
|
| 617 |
+
temp_list.append(line)
|
| 618 |
+
except:
|
| 619 |
+
break
|
| 620 |
+
for line in temp_list:
|
| 621 |
+
output_queue.put(line)
|
| 622 |
+
history.append(line)
|
| 623 |
+
for line in history[-50:]:
|
| 624 |
+
try:
|
| 625 |
+
ws.send(json.dumps({'type': 'output', 'data': line}))
|
| 626 |
+
except:
|
| 627 |
+
break
|
| 628 |
+
|
| 629 |
+
def send_stats():
|
| 630 |
+
while True:
|
| 631 |
+
try:
|
| 632 |
+
cpu = psutil.cpu_percent(interval=0.5)
|
| 633 |
+
memory = psutil.virtual_memory()
|
| 634 |
+
running = mc_process is not None and mc_process.poll() is None
|
| 635 |
+
disk_size = 0
|
| 636 |
+
try:
|
| 637 |
+
for dirpath, dirnames, filenames in os.walk('/app/mcserver'):
|
| 638 |
+
for f in filenames:
|
| 639 |
+
fp = os.path.join(dirpath, f)
|
| 640 |
+
if os.path.exists(fp):
|
| 641 |
+
disk_size += os.path.getsize(fp)
|
| 642 |
+
except:
|
| 643 |
+
pass
|
| 644 |
+
ws.send(json.dumps({
|
| 645 |
+
'type': 'stats',
|
| 646 |
+
'cpu': cpu,
|
| 647 |
+
'memory': memory.percent,
|
| 648 |
+
'memoryTotal': memory.total,
|
| 649 |
+
'running': running,
|
| 650 |
+
'players': 0,
|
| 651 |
+
'disk': disk_size
|
| 652 |
+
}))
|
| 653 |
+
except Exception as e:
|
| 654 |
+
print(f"[WS] Stats error: {e}", flush=True)
|
| 655 |
+
break
|
| 656 |
+
time.sleep(2)
|
| 657 |
+
|
| 658 |
+
threading.Thread(target=send_stats, daemon=True).start()
|
| 659 |
+
|
| 660 |
+
def send_output():
|
| 661 |
+
while True:
|
| 662 |
+
try:
|
| 663 |
+
line = output_queue.get(timeout=1)
|
| 664 |
+
try:
|
| 665 |
+
ws.send(json.dumps({'type': 'output', 'data': line}))
|
| 666 |
+
except:
|
| 667 |
+
break
|
| 668 |
+
except queue.Empty:
|
| 669 |
+
continue
|
| 670 |
+
except:
|
| 671 |
+
break
|
| 672 |
+
|
| 673 |
+
threading.Thread(target=send_output, daemon=True).start()
|
| 674 |
+
|
| 675 |
+
while True:
|
| 676 |
+
try:
|
| 677 |
+
data = ws.receive(timeout=5)
|
| 678 |
+
if data:
|
| 679 |
+
msg = json.loads(data)
|
| 680 |
+
if msg.get('type') == 'command':
|
| 681 |
+
cmd = msg.get('data', '').strip()
|
| 682 |
+
if cmd:
|
| 683 |
+
print(f"[WS] Command: {cmd}", flush=True)
|
| 684 |
+
command_queue.put(cmd)
|
| 685 |
+
except Exception as e:
|
| 686 |
+
if "Connection closed" in str(e):
|
| 687 |
+
break
|
| 688 |
+
continue
|
| 689 |
+
print("[WS] Client disconnected", flush=True)
|
| 690 |
+
|
| 691 |
+
def cleanup(signum=None, frame=None):
|
| 692 |
+
print("\n[MAIN] Shutting down...", flush=True)
|
| 693 |
+
if mc_process:
|
| 694 |
+
try:
|
| 695 |
+
mc_process.stdin.write("stop\n")
|
| 696 |
+
mc_process.stdin.flush()
|
| 697 |
+
mc_process.wait(timeout=30)
|
| 698 |
+
except:
|
| 699 |
+
try:
|
| 700 |
+
os.killpg(os.getpgid(mc_process.pid), signal.SIGTERM)
|
| 701 |
+
except:
|
| 702 |
+
pass
|
| 703 |
+
sys.exit(0)
|
| 704 |
+
|
| 705 |
+
signal.signal(signal.SIGTERM, cleanup)
|
| 706 |
+
signal.signal(signal.SIGINT, cleanup)
|
| 707 |
+
|
| 708 |
+
if __name__ == '__main__':
|
| 709 |
+
print("[MAIN] Starting web server...", flush=True)
|
| 710 |
+
mc_thread = threading.Thread(target=start_minecraft, daemon=True)
|
| 711 |
+
mc_thread.start()
|
| 712 |
+
from werkzeug.serving import run_simple
|
| 713 |
+
run_simple('0.0.0.0', 7860, app, threaded=True, use_reloader=False)
|