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)