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/handlers/mainHandler.py

30 lines
657 B
Python
Raw Normal View History

2019-12-14 20:08:34 +01:00
from importlib import reload
import random
import logging
import struct
2018-09-24 11:37:21 +02:00
from . import handshakeHandler
2019-12-14 20:08:34 +01:00
from . import unknownHandler
from helpers.byteFormater import readable_bytes
logger = logging.getLogger(__name__)
HANDLERS = {
0x18: handshakeHandler.handle,
0x00: unknownHandler.handle
}
def handle(client: "Client", data: bytes) -> bytes:
out: bytes = HANDLERS.get(data[0], unimplemented)(client, data)
2018-09-24 11:37:21 +02:00
2019-12-14 20:08:34 +01:00
return out
2018-09-24 11:37:21 +02:00
2019-12-14 20:08:34 +01:00
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)])
2018-09-24 11:37:21 +02:00
2019-12-14 20:08:34 +01:00
def restart():
reload(handshakeHandler)