From: ametama Date: Sun, 28 Dec 2025 15:27:45 +0000 (+0100) Subject: feat: operands X-Git-Url: https://git.wafflesoft.org/?a=commitdiff_plain;h=HEAD;p=tachyon.git feat: operands --- diff --git a/src/engine.py b/src/engine.py index 406d8bc..34a5681 100644 --- a/src/engine.py +++ b/src/engine.py @@ -18,22 +18,22 @@ class Engine(ABC): async def on_connection(self, socket: websockets.ServerConnection): try: - session_id = await socket.recv(decode=True) - session_id = int(session_id) + session_id = await socket.recv(decode=False) + session_id = int.from_bytes(session_id) challenge = self.challenge() await socket.send(challenge) signature = await socket.recv(decode=False) client = await self.authorize(socket, session_id, challenge, signature) await socket.send(str(client.user.id)) - async for data in socket: - if type(data) != str: continue - await self.on_message(client, data) + while data := await socket.recv(decode=False): await self.on_data(client, data) except: pass finally: await socket.close() - async def on_message(self, client: Client, message: str): - pass + async def on_data(self, client: Client, data: bytes): + if len(data) < 1: return + opcode = data[0] + operands = [int.from_bytes(data[k:k+8]) for k in range(1, len(data), 8)] async def authorize(self, socket: websockets.ServerConnection, session_id: int, challenge: bytes, signature: bytes): user, pkey = await self.fetch_session(session_id)