moved dispatcher up, some scaffolding done
This commit is contained in:
parent
eb4a3beac3
commit
e8d27ca4b7
4 changed files with 42 additions and 5 deletions
|
@ -1,6 +1,5 @@
|
||||||
"""aiocraft is an asyncio-driven headless minecraft client"""
|
"""aiocraft is an asyncio-driven headless minecraft client"""
|
||||||
from .session import Session
|
from .session import Session
|
||||||
from .impl import *
|
|
||||||
from .mc import *
|
from .mc import *
|
||||||
|
|
||||||
__version__ = "0.0.1"
|
__version__ = "0.0.1"
|
||||||
|
|
42
aiocraft/dispatcher.py
Normal file
42
aiocraft/dispatcher.py
Normal file
|
@ -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()
|
||||||
|
|
||||||
|
|
|
@ -1 +0,0 @@
|
||||||
from .dispatcher import Dispatcher
|
|
|
@ -1,3 +0,0 @@
|
||||||
class Dispatcher:
|
|
||||||
pass
|
|
||||||
|
|
Loading…
Reference in a new issue