Option to not log ignored packets (default on)
This commit is contained in:
parent
48ce1b8d5c
commit
7d05658fe9
1 changed files with 9 additions and 1 deletions
|
@ -43,6 +43,8 @@ class Dispatcher:
|
||||||
_packet_whitelist : Optional[Set[Type[Packet]]]
|
_packet_whitelist : Optional[Set[Type[Packet]]]
|
||||||
_packet_id_whitelist : Optional[Set[int]]
|
_packet_id_whitelist : Optional[Set[int]]
|
||||||
|
|
||||||
|
_log_ignored_packets : bool
|
||||||
|
|
||||||
host : str
|
host : str
|
||||||
port : int
|
port : int
|
||||||
|
|
||||||
|
@ -61,6 +63,7 @@ class Dispatcher:
|
||||||
self._dispatching = False
|
self._dispatching = False
|
||||||
self._packet_whitelist = None
|
self._packet_whitelist = None
|
||||||
self._packet_id_whitelist = None
|
self._packet_id_whitelist = None
|
||||||
|
self._log_ignored_packets = False
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_server(self) -> bool:
|
def is_server(self) -> bool:
|
||||||
|
@ -123,6 +126,10 @@ class Dispatcher:
|
||||||
self.state = state or self.state
|
self.state = state or self.state
|
||||||
return self
|
return self
|
||||||
|
|
||||||
|
def log_ignored_packets(self, log:bool) -> 'Dispatcher':
|
||||||
|
self._log_ignored_packets = log
|
||||||
|
return self
|
||||||
|
|
||||||
async def connect(self,
|
async def connect(self,
|
||||||
reader : Optional[StreamReader] = None,
|
reader : Optional[StreamReader] = None,
|
||||||
writer : Optional[StreamWriter] = None,
|
writer : Optional[StreamWriter] = None,
|
||||||
|
@ -241,6 +248,7 @@ class Dispatcher:
|
||||||
packet_id = VarInt.read(buffer, Context(_proto=self.proto))
|
packet_id = VarInt.read(buffer, Context(_proto=self.proto))
|
||||||
if self.state == ConnectionState.PLAY and self._packet_id_whitelist \
|
if self.state == ConnectionState.PLAY and self._packet_id_whitelist \
|
||||||
and packet_id not in self._packet_id_whitelist:
|
and packet_id not in self._packet_id_whitelist:
|
||||||
|
if self._log_ignored_packets:
|
||||||
self.logger.debug("[<--] Received | Packet(0x%02x) (ignored)", packet_id)
|
self.logger.debug("[<--] Received | Packet(0x%02x) (ignored)", packet_id)
|
||||||
continue # ignore this packet, we rarely need them all, should improve performance
|
continue # ignore this packet, we rarely need them all, should improve performance
|
||||||
cls = self._packet_type_from_registry(packet_id)
|
cls = self._packet_type_from_registry(packet_id)
|
||||||
|
|
Loading…
Reference in a new issue