Catch checklist exception on DummyEvent listeners

This commit is contained in:
Ben 2019-09-09 22:03:44 +01:00
parent aef99a11b6
commit 29706065ae

View File

@ -136,21 +136,27 @@ class Spheniscidae:
async def _client_connected(self): async def _client_connected(self):
self.logger.info('Client %s connected', self.peer_name) self.logger.info('Client %s connected', self.peer_name)
try:
dummy_event = DummyEventPacket('connected') dummy_event = DummyEventPacket('connected')
if dummy_event in self.server.dummy_event_listeners: if dummy_event in self.server.dummy_event_listeners:
dummy_event_listeners = self.server.dummy_event_listeners[dummy_event] dummy_event_listeners = self.server.dummy_event_listeners[dummy_event]
for listener in dummy_event_listeners: for listener in dummy_event_listeners:
await listener(self) await listener(self)
except ChecklistError:
self.logger.debug('{} sent a packet without meeting checklist requirements'.format(self))
async def _client_disconnected(self): async def _client_disconnected(self):
del self.server.peers_by_ip[self.peer_name] del self.server.peers_by_ip[self.peer_name]
self.logger.info('Client %s disconnected', self.peer_name) self.logger.info('Client %s disconnected', self.peer_name)
try:
dummy_event = DummyEventPacket('disconnected') dummy_event = DummyEventPacket('disconnected')
if dummy_event in self.server.dummy_event_listeners: if dummy_event in self.server.dummy_event_listeners:
dummy_event_listeners = self.server.dummy_event_listeners[dummy_event] dummy_event_listeners = self.server.dummy_event_listeners[dummy_event]
for listener in dummy_event_listeners: for listener in dummy_event_listeners:
await listener(self) await listener(self)
except ChecklistError:
self.logger.debug('{} sent a packet without meeting checklist requirements'.format(self))
async def __data_received(self, data): async def __data_received(self, data):
data = data.decode()[:-1] data = data.decode()[:-1]