diff --git a/aiocraft/client.py b/aiocraft/client.py new file mode 100644 index 0000000..6b52392 --- /dev/null +++ b/aiocraft/client.py @@ -0,0 +1,52 @@ +import asyncio +from asyncio import Task +from enum import Enum + +from .dispatcher import Dispatcher +from .mc.mctypes import VarInt + +class ConnectionState(Enum): + HANDSHAKING = 0 + STATUS = 1 + LOGIN = 2 + PLAY = 3 + +class Client: + host:str + port:int + + dispatcher : Dispatcher + state : ConnectionState + _processing : bool + _worker : Task + + def __init__( + self, + username : str, + password : str, + host: str = "localhost", + port: int = 25565, + ): + self.host = host + self.port = port + + self.state = ConnectionState.HANDSHAKING + self.dispatcher = Dispatcher(host, port) + self._processing = False + + + async def run(self): + await self.dispatcher.run() + self._processing = True + self._worker = asyncio.get_event_loop().create_task(self._logic_worker()) + + + async def _logic_worker(self): + while self._processing: + buffer = await self.dispatcher.incoming.get() + packet_id = VarInt.deserialize(buffer) + cls = PacketRegistry.state(self.state).clientbound.get(packet_id) + packet = cls(buffer) + # Process packets? switch state, invoke callbacks? Maybe implement Reactors? + + diff --git a/aiocraft/session.py b/aiocraft/session.py deleted file mode 100644 index dd066fe..0000000 --- a/aiocraft/session.py +++ /dev/null @@ -1,16 +0,0 @@ -class Session: - host:str - port:int - - def __init__( - self, - host: str = "localhost", - port: int = 25565, - ): - self.host = host - self.port = port - - - async def run(self): - pass -