More debugging

This commit is contained in:
oitsjustjose 2025-06-14 15:34:36 -05:00
commit 03e5b7e7d8
6 changed files with 17 additions and 14 deletions

View file

@ -11,7 +11,7 @@ import asyncio
from flask_cors import CORS
from websockets.asyncio.server import serve, ServerConnection
from common import get_server_info
from common import list_servers
import docker
from docker import DockerClient
@ -27,7 +27,7 @@ class RestServer:
def index(self):
try:
data = get_server_info(self._client, all=bool(request.args.get("all")))
data = list_servers(self._client, all=bool(request.args.get("all")))
if request.args.get("sort"):
data = sorted(data, key=lambda x: x[request.args.get("sort")])
@ -48,7 +48,7 @@ class RestServer:
class WebSocketServer:
def __init__(self, docker_client: DockerClient):
self._client = docker_client
self.cache = json.dumps(get_server_info(self._client, all=True))
self.cache = json.dumps(list_servers(self._client, all=True))
async def __loop_infinitely(self, conn: ServerConnection):
while True:
@ -61,11 +61,11 @@ class WebSocketServer:
await asyncio.Future()
async def __wait_for_change(self, conn: ServerConnection):
new = json.dumps(get_server_info(self._client, all=True))
new = json.dumps(list_servers(self._client, all=True))
while new == self.cache:
await asyncio.sleep(1)
new = json.dumps(get_server_info(self._client, all=True))
new = json.dumps(list_servers(self._client, all=True))
self.cache = new
await conn.send(new)
@ -89,7 +89,7 @@ def main() -> None:
wss_thread.start()
RestServer(client).run(host="0.0.0.0", port=int(env["REST_PORT"]) if "REST_PORT" in env else 9090)
# wss_thread.join()
wss_thread.join()
if __name__ == "__main__":

View file

@ -23,7 +23,7 @@ def parse_server(attrs: dict) -> Union[Server, None]:
return Server(params) if params else None
def get_server_info(client: DockerClient, all: bool = False) -> List[dict]:
def list_servers(client: DockerClient, all: bool = False) -> List[dict]:
"""
Distills the container data for all servers on the current host into a usable format
Arguments:

View file

@ -78,7 +78,7 @@ def ping(ip, port=25565):
while len(data) != length:
chunk = sock.recv(length - len(data))
if not chunk:
raise ValueError("connection abborted")
raise ValueError("connection aborted")
data += chunk
try:

View file

@ -10,7 +10,7 @@ import docker
from flask import Flask, jsonify, request
from flask_cors import CORS
from common import get_server_info
from common import list_servers
client = docker.from_env()
app = Flask(__name__)
@ -20,7 +20,7 @@ CORS(app)
@app.route("/")
def index():
try:
data = get_server_info(client, all=bool(request.args.get("all")))
data = list_servers(client, all=bool(request.args.get("all")))
if request.args.get("sort"):
data = sorted(data, key=lambda x: x[request.args.get("sort")])

View file

@ -12,11 +12,11 @@ import docker
from docker import DockerClient
from websockets.asyncio.server import ServerConnection, serve
from common import get_server_info
from common import list_servers
def __fetch(client: DockerClient):
return json.dumps(get_server_info(client, all=True))
return json.dumps(list_servers(client, all=True))
CLIENT = docker.from_env()
@ -38,11 +38,11 @@ async def __setup(host: str, port: int = 8008):
async def __wait_for_change(conn: ServerConnection):
global CACHE
new = json.dumps(get_server_info(CLIENT, all=True))
new = json.dumps(list_servers(CLIENT, all=True))
while new == CACHE:
await asyncio.sleep(1)
new = json.dumps(get_server_info(CLIENT, all=True))
new = json.dumps(list_servers(CLIENT, all=True))
CACHE = new
await conn.send(new)

View file

@ -72,7 +72,9 @@ class Server:
continue
try:
print(f"Pinging localhost:{int(port)}")
server_ping_info = ping_server("localhost", port=int(port))
print(f"Pinged: {server_ping_info}")
except ValueError:
continue
@ -83,6 +85,7 @@ class Server:
return None
log_info = Server.parse_log_for_info(attrs["State"]["Health"]["Log"][-1]["Output"])
print(f"Log Info is done! \n\tlog_info.max={log_info.max}\n\tlog_info.motd={log_info.motd}\n\tlog_info.version={log_info.version}")
players = [Player(name=pl.name, uuid=pl.id) for pl in server_ping_info.players]
return ServerConstructorParams(