From e8d27ca4b7d1c17885a4746fce15fecb18d75622 Mon Sep 17 00:00:00 2001 From: alemi Date: Sun, 10 Oct 2021 16:20:32 +0200 Subject: [PATCH] moved dispatcher up, some scaffolding done --- aiocraft/__init__.py | 1 - aiocraft/dispatcher.py | 42 +++++++++++++++++++++++++++++++++++++ aiocraft/impl/__init__.py | 1 - aiocraft/impl/dispatcher.py | 3 --- 4 files changed, 42 insertions(+), 5 deletions(-) create mode 100644 aiocraft/dispatcher.py delete mode 100644 aiocraft/impl/__init__.py delete mode 100644 aiocraft/impl/dispatcher.py diff --git a/aiocraft/__init__.py b/aiocraft/__init__.py index 2822f9a..70a7d58 100644 --- a/aiocraft/__init__.py +++ b/aiocraft/__init__.py @@ -1,6 +1,5 @@ """aiocraft is an asyncio-driven headless minecraft client""" from .session import Session -from .impl import * from .mc import * __version__ = "0.0.1" diff --git a/aiocraft/dispatcher.py b/aiocraft/dispatcher.py new file mode 100644 index 0000000..0dbc727 --- /dev/null +++ b/aiocraft/dispatcher.py @@ -0,0 +1,42 @@ +import asyncio +from asyncio import StreamReader, StreamWriter +from enum import Enum + +class ConnectionState(Enum): + HANDSHAKING = 0 + STATUS = 1 + LOGIN = 2 + PLAY = 3 + +class InvalidState(Exception): + pass + +class Dispatcher: + connected : bool + down : StreamReader + up : StreamWriter + host : str + port : int + + def __init__(self, host:str, port:int): + self.host = host + self.port = port + self.connected = False + + async def _connect(self): + self.down, self.up = await asyncio.open_connection( + host=self.host, + port=self.port, + ) + self.connected = True + + async def _work(self): + while True: + buf = await self.down. + + async def run(self): + if self.connected: + raise InvalidState("Dispatcher already connected") + await self._connect() + + diff --git a/aiocraft/impl/__init__.py b/aiocraft/impl/__init__.py deleted file mode 100644 index e1a5824..0000000 --- a/aiocraft/impl/__init__.py +++ /dev/null @@ -1 +0,0 @@ -from .dispatcher import Dispatcher diff --git a/aiocraft/impl/dispatcher.py b/aiocraft/impl/dispatcher.py deleted file mode 100644 index e563010..0000000 --- a/aiocraft/impl/dispatcher.py +++ /dev/null @@ -1,3 +0,0 @@ -class Dispatcher: - pass -