Option to not log ignored packets (default on)

This commit is contained in:
əlemi 2022-04-27 13:28:50 +02:00
parent 48ce1b8d5c
commit 7d05658fe9
No known key found for this signature in database
GPG key ID: BBCBFE5D7244634E

View file

@ -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)