forked from hkc/cc-stuff
1
0
Fork 0
cc-stuff/mess/libcloudcatcher.py

66 lines
1.4 KiB
Python

from typing import Any, Literal
from websockets import connect
HexDigit = Literal[
"0", "1", "2", "3", "4", "5", "6", "7",
"8", "9", "a", "b", "c", "d", "e", "f"
]
class Packet:
packet_id: int
side: Literal["client", "server"]
def __init_subclass__(cls, packet_id: int, side: Literal["client", "server"]) -> None:
cls.packet_id = packet_id
cls.side = side
class PacketServerPing(Packet, packet_id=2, side="server"):
pass
class PacketClientPong(Packet, packet_id=2, side="client"):
pass
class PacketServerCapabilities(Packet, packet_id=0, side="server"):
clients: int
capabilities: list[str]
class PacketServerComputer(Packet, packet_id=18, side="server"):
id: int
label: str
class PacketServerScreen(Packet, packet_id=16, side="server"):
cursorBlink: bool
width: int
height: int
cursorX: int
cursorY: int
curFore: HexDigit
curBack: HexDigit
text: list[str]
back: list[str]
fore: list[str]
palette: list[int]
class CCEvent:
name: str
args: list[Any]
class PacketClientEvent(Packet, packet_id=17, side="client"):
events: list[CCEvent]
class CCAction:
action: int
def __init_subclass__(cls, action: int) -> None:
cls.action = action
class CCActionFile(CCAction, action=0):
file: str
contents: str
checksum: int
class PacketServerFile(Packet, packet_id=34, side="server"):
actions: list[CCAction]