This repository has been archived on 2020-03-29. You can view files and clone it, but cannot push or open issues or pull requests.
sampy_archive/sampy/handlers/mainHandler.py

32 lines
714 B
Python

from importlib import reload
import random
import logging
import struct
from . import handshakeHandler
from . import unknownHandler
from . import queueHandler
from ..helpers.byteFormater import readable_bytes
logger = logging.getLogger(__name__)
HANDLERS = {
0x18: handshakeHandler.handle,
0x00: unknownHandler.handle,
0xe3: queueHandler.handle
}
def handle(client: "Client", data: bytes) -> bytes:
out: bytes = HANDLERS.get(data[0], unimplemented)(client, data)
return out
def unimplemented(client: "Client", data: bytes) -> bytes:
logger.debug("[%s] sent unhandled data: %s" % (client.addr, readable_bytes(data)))
return bytes([x for x in range(1,32,1)])
def restart():
reload(handshakeHandler)