Temporary solution for "matching" packet data to handlers

This commit is contained in:
Ben 2020-04-02 23:08:22 +01:00
parent fed5cf01ec
commit dde08459e9

View File

@ -66,12 +66,13 @@ class _Listener(_ArgumentDeserializer):
class _XTListener(_Listener): class _XTListener(_Listener):
__slots__ = ['pre_login'] __slots__ = ['pre_login', 'match']
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs) super().__init__(*args, **kwargs)
self.pre_login = kwargs.get('pre_login') self.pre_login = kwargs.get('pre_login')
self.match = kwargs.get('match')
async def __call__(self, p, packet_data): async def __call__(self, p, packet_data):
try: try:
@ -79,10 +80,11 @@ class _XTListener(_Listener):
await p.close() await p.close()
raise AuthorityError(f'{p} tried sending XT packet before authentication!') raise AuthorityError(f'{p} tried sending XT packet before authentication!')
await super()._check_cooldown(p) if self.match is None or packet_data[:len(self.match)] == self.match:
super()._check_list(p) await super()._check_cooldown(p)
super()._check_list(p)
await super().__call__(p, packet_data) await super().__call__(p, packet_data)
except CooldownError: except CooldownError:
p.logger.debug(f'{p} tried to send a packet during a cooldown') p.logger.debug(f'{p} tried to send a packet during a cooldown')
except ChecklistError: except ChecklistError: