| import http.server |
| import socketserver |
| import subprocess |
| import threading |
| import os |
| import time |
|
|
| PORT = 7860 |
| logs = [] |
|
|
| def stream_process(proc, prefix): |
| for line in iter(proc.stdout.readline, ""): |
| if line: |
| formatted = f"[{prefix}] {line.strip()}" |
| print(formatted, flush=True) |
| logs.append(formatted) |
| if len(logs) > 200: |
| logs.pop(0) |
|
|
| def start_services(): |
| |
| playit_proc = subprocess.Popen( |
| ["playit"], |
| stdout=subprocess.PIPE, |
| stderr=subprocess.STDOUT, |
| text=True, |
| bufsize=1 |
| ) |
| threading.Thread(target=stream_process, args=(playit_proc, "PLAYIT"), daemon=True).start() |
|
|
| |
| env = os.environ.copy() |
| env["LD_LIBRARY_PATH"] = "/app" |
| bedrock_proc = subprocess.Popen( |
| ["./bedrock_server"], |
| cwd="/app", |
| env=env, |
| stdout=subprocess.PIPE, |
| stderr=subprocess.STDOUT, |
| text=True, |
| bufsize=1 |
| ) |
| threading.Thread(target=stream_process, args=(bedrock_proc, "BEDROCK"), daemon=True).start() |
|
|
| |
| start_services() |
|
|
| class WebHandler(http.server.SimpleHTTPRequestHandler): |
| def do_GET(self): |
| log_text = "\n".join(logs) |
| claim_url = "Looking for claim URL in logs..." |
| |
| for line in logs: |
| if "playit.gg/claim/" in line: |
| parts = line.split() |
| for p in parts: |
| if "playit.gg/claim/" in p: |
| claim_url = f'<a href="{p}" target="_blank" style="color:#4ade80;">{p}</a>' |
| break |
|
|
| html = f"""<!DOCTYPE html> |
| <html> |
| <head> |
| <title>Bedrock Server</title> |
| <meta http-equiv="refresh" content="3"> |
| <style> |
| body {{ background: #0f172a; color: #f8fafc; font-family: monospace; padding: 20px; }} |
| .card {{ background: #1e293b; border-radius: 8px; padding: 15px; margin-bottom: 15px; }} |
| pre {{ white-space: pre-wrap; font-size: 12px; color: #cbd5e1; }} |
| </style> |
| </head> |
| <body> |
| <h2>🎮 Minecraft Bedrock Server</h2> |
| <div class="card"> |
| <h3>🔗 Playit Claim Link:</h3> |
| <p>{claim_url}</p> |
| </div> |
| <div class="card"> |
| <h3>📜 Live Console Output:</h3> |
| <pre>{log_text if log_text else 'Starting processes...'}</pre> |
| </div> |
| </body> |
| </html>""" |
| self.send_response(200) |
| self.send_header("Content-type", "text/html; charset=utf-8") |
| self.end_headers() |
| self.wfile.write(html.encode("utf-8")) |
|
|
| with socketserver.TCPServer(("", PORT), WebHandler) as httpd: |
| print(f"Server console online at port {PORT}", flush=True) |
| httpd.serve_forever() |