some project sorting
This commit is contained in:
parent
c08f3b5153
commit
5cde07da56
6 changed files with 71 additions and 8 deletions
1
aiocraft/__main__.py
Normal file
1
aiocraft/__main__.py
Normal file
|
@ -0,0 +1 @@
|
||||||
|
print(":)")
|
2
aiocraft/impl/dispatcher.py
Normal file
2
aiocraft/impl/dispatcher.py
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
class Dispatcher:
|
||||||
|
|
|
@ -6,14 +6,17 @@ from typing import List, Dict
|
||||||
|
|
||||||
DIR_MAP = {"toClient": "clientbound", "toServer": "serverbound"}
|
DIR_MAP = {"toClient": "clientbound", "toServer": "serverbound"}
|
||||||
PREFACE = """\"\"\"[!] This file is autogenerated\"\"\"\n\n"""
|
PREFACE = """\"\"\"[!] This file is autogenerated\"\"\"\n\n"""
|
||||||
IMPORTS = """from .minecraft.packet import Packet\nfrom .minecraft.types import *\n"""
|
IMPORTS = """from typing import Tuple
|
||||||
|
from .minecraft.packet import Packet
|
||||||
|
from .minecraft.types import *\n"""
|
||||||
IMPORT_ALL = """from .* import * # TODO!\n"""
|
IMPORT_ALL = """from .* import * # TODO!\n"""
|
||||||
OBJECT = """
|
OBJECT = """
|
||||||
class {name}(Packet):
|
class {name}(Packet):
|
||||||
ID : int = 0x{id:X}
|
id : int = 0x{id:X}
|
||||||
SLOTS : list = (
|
_slots : Tuple[Tuple[str, Type]] = (
|
||||||
{slots}
|
{slots}
|
||||||
)
|
)
|
||||||
|
{fields}
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def snake_to_camel(name:str) -> str:
|
def snake_to_camel(name:str) -> str:
|
||||||
|
@ -30,6 +33,20 @@ def parse_slot(slot: dict) -> str:
|
||||||
return f"(\"anon\", {slot['type']})"
|
return f"(\"anon\", {slot['type']})"
|
||||||
else:
|
else:
|
||||||
return f"(\"anon\", [Special])"
|
return f"(\"anon\", [Special])"
|
||||||
|
return slot
|
||||||
|
|
||||||
|
def parse_field(slot: dict) -> str:
|
||||||
|
if "name" in slot:
|
||||||
|
if "type" in slot and isinstance(slot["type"], str):
|
||||||
|
return f"{slot['name']} : {slot['type'].pytype()}"
|
||||||
|
else:
|
||||||
|
return f"{slot['name']} : Any"
|
||||||
|
elif "anon" in slot:
|
||||||
|
if "type" in slot and isinstance(slot["type"], str):
|
||||||
|
return f"anon : {slot['type'].pytype()}"
|
||||||
|
else:
|
||||||
|
return f"anon : Any"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class PacketClassWriter:
|
class PacketClassWriter:
|
||||||
|
@ -43,7 +60,14 @@ class PacketClassWriter:
|
||||||
self.slots = slots
|
self.slots = slots
|
||||||
|
|
||||||
def compile(self) -> str:
|
def compile(self) -> str:
|
||||||
return PREFACE + IMPORTS + OBJECT.format(id=pid, name=self.title, slots=parse_slot(self.slots))
|
return PREFACE + \
|
||||||
|
IMPORTS + \
|
||||||
|
OBJECT.format(
|
||||||
|
id=pid,
|
||||||
|
name=self.title,
|
||||||
|
slots=parse_slot(self.slots),
|
||||||
|
fields=parse_field(self.slots),
|
||||||
|
)
|
||||||
|
|
||||||
def _make_module(path:str):
|
def _make_module(path:str):
|
||||||
os.mkdir(path)
|
os.mkdir(path)
|
||||||
|
@ -54,8 +78,8 @@ def _make_module(path:str):
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
# TODO load relatively!
|
# TODO load relatively!
|
||||||
# with open("???/minecraft-data/data/pc/1.12.2/protocol.json") as f:
|
with open("/home/alemi/projects/minecraft-data/data/pc/1.12.2/protocol.json") as f:
|
||||||
# data = json.load(f)
|
data = json.load(f)
|
||||||
|
|
||||||
_make_module("protocol")
|
_make_module("protocol")
|
||||||
for state in ("handshaking", "status", "login", "play"):
|
for state in ("handshaking", "status", "login", "play"):
|
||||||
|
|
|
@ -103,8 +103,6 @@ class EntityMetadata(Type):
|
||||||
class Slot(Type):
|
class Slot(Type):
|
||||||
# TODO
|
# TODO
|
||||||
pass
|
pass
|
||||||
if buf & 0b10000000 == 0:
|
|
||||||
break
|
|
||||||
|
|
||||||
class NBTTag(Type):
|
class NBTTag(Type):
|
||||||
# TODO
|
# TODO
|
21
aiocraft/minecraft/packet.py
Normal file
21
aiocraft/minecraft/packet.py
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
from typing import Tuple
|
||||||
|
|
||||||
|
from .mctypes import Type
|
||||||
|
|
||||||
|
class Packet:
|
||||||
|
id : int
|
||||||
|
_slots : Tuple[Tuple[str, Type]]
|
||||||
|
|
||||||
|
def serialize(self) -> bytes:
|
||||||
|
return b''.join(
|
||||||
|
slot[1].serialize(getattr(self, slot[0]))
|
||||||
|
for slot in self._slots
|
||||||
|
)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def deserialize(cls, data:bytes):
|
||||||
|
pkt = cls()
|
||||||
|
for slot in cls._slots:
|
||||||
|
setattr(pkt, slot[0], slot[1].deserialize(data))
|
||||||
|
return pkt
|
||||||
|
|
17
aiocraft/session.py
Normal file
17
aiocraft/session.py
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
|
||||||
|
|
||||||
|
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):
|
||||||
|
|
Loading…
Reference in a new issue