File size: 2,737 Bytes
6f8fe2b
 
4941a65
 
6f8fe2b
4941a65
6f8fe2b
 
4941a65
6f8fe2b
4941a65
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6f8fe2b
 
4941a65
6f8fe2b
 
4941a65
 
 
6f8fe2b
 
 
4941a65
 
 
 
6f8fe2b
4941a65
fda6080
4941a65
6f8fe2b
 
4941a65
6f8fe2b
 
 
 
 
4941a65
 
6f8fe2b
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
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():
    # 1. Start playit tunnel
    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()

    # 2. Start Bedrock server
    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 background services
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()