From 7d05658fe91a60ec127e7d7bb3e54d0647f8cccb Mon Sep 17 00:00:00 2001 From: alemidev Date: Wed, 27 Apr 2022 13:28:50 +0200 Subject: [PATCH] Option to not log ignored packets (default on) --- src/aiocraft/dispatcher.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/aiocraft/dispatcher.py b/src/aiocraft/dispatcher.py index 214ebd9..37c8ae4 100644 --- a/src/aiocraft/dispatcher.py +++ b/src/aiocraft/dispatcher.py @@ -43,6 +43,8 @@ class Dispatcher: _packet_whitelist : Optional[Set[Type[Packet]]] _packet_id_whitelist : Optional[Set[int]] + _log_ignored_packets : bool + host : str port : int @@ -61,6 +63,7 @@ class Dispatcher: self._dispatching = False self._packet_whitelist = None self._packet_id_whitelist = None + self._log_ignored_packets = False @property def is_server(self) -> bool: @@ -123,6 +126,10 @@ class Dispatcher: self.state = state or self.state return self + def log_ignored_packets(self, log:bool) -> 'Dispatcher': + self._log_ignored_packets = log + return self + async def connect(self, reader : Optional[StreamReader] = None, writer : Optional[StreamWriter] = None, @@ -241,7 +248,8 @@ class Dispatcher: packet_id = VarInt.read(buffer, Context(_proto=self.proto)) 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) + if self._log_ignored_packets: + 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) packet = cls.deserialize(self.proto, buffer)