feat: operands master
authorametama <ametama@wafflesoft.org>
Sun, 28 Dec 2025 15:27:45 +0000 (16:27 +0100)
committerametama <ametama@wafflesoft.org>
Sun, 28 Dec 2025 15:27:45 +0000 (16:27 +0100)
src/engine.py

index 406d8bc065cc2ca645314a110fe93f334e5b215e..34a56814cc4e45d00427db9fdaacea821afba49d 100644 (file)
@@ -18,22 +18,22 @@ class Engine(ABC):
 
     async def on_connection(self, socket: websockets.ServerConnection):
         try:
 
     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))
             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()
 
         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)
 
     async def authorize(self, socket: websockets.ServerConnection, session_id: int, challenge: bytes, signature: bytes):
         user, pkey = await self.fetch_session(session_id)