diff --git a/.xdp-Wichtig_Linux.png-9QCW3k b/.xdp-Wichtig_Linux.png-9QCW3k new file mode 100644 index 0000000..01a589c Binary files /dev/null and b/.xdp-Wichtig_Linux.png-9QCW3k differ diff --git a/START_Linux.sh b/START_Linux.sh new file mode 100755 index 0000000..ec9e905 --- /dev/null +++ b/START_Linux.sh @@ -0,0 +1,21 @@ +#!/usr/bin/env bash +set -euo pipefail + +PORT=8000 +BASE="http://localhost:${PORT}" + +python3 server.py & +SERVER_PID=$! + +cleanup() { + kill "$SERVER_PID" 2>/dev/null || true +} +trap cleanup EXIT + +sleep 0.5 + +# Default-Browser öffnen (meist Tabs) +xdg-open "${BASE}/index.html" >/dev/null 2>&1 || true +xdg-open "${BASE}/spieler.html" >/dev/null 2>&1 || true + +wait "$SERVER_PID" diff --git a/START_Win.ps1 b/START_Win.ps1 new file mode 100644 index 0000000..07d8f87 --- /dev/null +++ b/START_Win.ps1 @@ -0,0 +1,14 @@ +$Port = 8000 +$Base = "http://localhost:$Port" + +# Server starten +$server = Start-Process -PassThru -NoNewWindow python "server.py" + +Start-Sleep -Milliseconds 500 + +# Öffnet im Standardbrowser +Start-Process "$Base/index.html" +Start-Process "$Base/spieler.html" + +Write-Host "Server läuft (PID $($server.Id)). Zum Beenden: Fenster schließen oder Prozess killen." +Wait-Process -Id $server.Id diff --git a/index.html b/index.html index 1e1ac5b..e7f3250 100644 --- a/index.html +++ b/index.html @@ -54,7 +54,7 @@ diff --git a/server.py b/server.py new file mode 100644 index 0000000..bb2f39e --- /dev/null +++ b/server.py @@ -0,0 +1,49 @@ +#!/usr/bin/env python3 +import json +import os +from http.server import ThreadingHTTPServer, SimpleHTTPRequestHandler +from urllib.parse import urlparse, unquote + +MAPS_DIR = "maps" +ALLOWED_EXT = {".png", ".jpg", ".jpeg", ".webp", ".gif"} + +class Handler(SimpleHTTPRequestHandler): + def do_GET(self): + parsed = urlparse(self.path) + + # API: list maps (used by index.html) + if parsed.path == "/list-maps": + self._handle_list_maps() + return + + # Convenience: "/" -> "/index.html" + if parsed.path == "/": + self.path = "/index.html" + + super().do_GET() + + def _handle_list_maps(self): + maps = [] + if os.path.isdir(MAPS_DIR): + for name in sorted(os.listdir(MAPS_DIR)): + p = os.path.join(MAPS_DIR, name) + ext = os.path.splitext(name)[1].lower() + if os.path.isfile(p) and ext in ALLOWED_EXT: + maps.append(f"{MAPS_DIR}/{name}") + + data = json.dumps(maps).encode("utf-8") + self.send_response(200) + self.send_header("Content-Type", "application/json; charset=utf-8") + self.send_header("Content-Length", str(len(data))) + self.end_headers() + self.wfile.write(data) + +def main(): + host = "0.0.0.0" + port = 8000 + httpd = ThreadingHTTPServer((host, port), Handler) + print(f"Serving on http://{host}:{port}") + httpd.serve_forever() + +if __name__ == "__main__": + main() diff --git a/spieler.html b/spieler.html index 855cd51..851889c 100644 --- a/spieler.html +++ b/spieler.html @@ -26,7 +26,7 @@