From f70121f2c12f27bc7230e04f26ca2e90dea3ad0d Mon Sep 17 00:00:00 2001 From: alemidev Date: Fri, 17 Dec 2021 14:01:08 +0100 Subject: [PATCH] fixed packet whitelist --- aiocraft/dispatcher.py | 3 ++- aiocraft/traits/callbacks.py | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/aiocraft/dispatcher.py b/aiocraft/dispatcher.py index 9aebbfe..1a005ab 100644 --- a/aiocraft/dispatcher.py +++ b/aiocraft/dispatcher.py @@ -228,7 +228,8 @@ class Dispatcher: buffer = io.BytesIO(decompressed_data) packet_id = VarInt.read(buffer) - if self._packet_id_whitelist and packet_id in self._packet_id_whitelist: + if self.state == ConnectionState.PLAY and self._packet_id_whitelist \ + and packet_id not in self._packet_id_whitelist: self._logger.debug("[<--] Received | Packet(0x%02x) (ignored)", packet_id) continue # ignore this packet, we rarely need them all, should improve performance cls = self._packet_type_from_registry(packet_id) diff --git a/aiocraft/traits/callbacks.py b/aiocraft/traits/callbacks.py index 14ad8f3..6bd2499 100644 --- a/aiocraft/traits/callbacks.py +++ b/aiocraft/traits/callbacks.py @@ -2,6 +2,7 @@ import asyncio import uuid import logging +from inspect import isclass from typing import Dict, List, Set, Any, Callable, Type class CallbacksHolder: @@ -17,7 +18,7 @@ class CallbacksHolder: self._tasks = {} def callback_keys(self, filter:Type = None) -> Set[Any]: - return set(x for x in self._callbacks.keys() if not filter or issubclass(x, filter)) + return set(x for x in self._callbacks.keys() if not filter or (isclass(x) and issubclass(x, filter))) def register(self, key:Any, callback:Callable): if key not in self._callbacks: