mirror of
https://github.com/solero/houdini.git
synced 2024-11-22 05:27:23 +00:00
Catch ChecklistError & CooldownError on every listener call
This commit is contained in:
parent
551cf016b4
commit
3f1dd2a2f1
@ -3,8 +3,9 @@ import enum
|
||||
import itertools
|
||||
from types import FunctionType
|
||||
|
||||
from houdini.converters import _listener, _ArgumentDeserializer, get_converter, do_conversion, _ConverterContext
|
||||
from houdini.cooldown import _Cooldown, _CooldownMapping, BucketType
|
||||
from houdini.converters import _listener, _ArgumentDeserializer, get_converter, \
|
||||
do_conversion, _ConverterContext, ChecklistError
|
||||
from houdini.cooldown import _Cooldown, _CooldownMapping, BucketType, CooldownError
|
||||
from houdini import plugins, _AbstractManager, get_package_modules
|
||||
|
||||
|
||||
@ -73,6 +74,7 @@ class _XTListener(_Listener):
|
||||
self.pre_login = kwargs.get('pre_login')
|
||||
|
||||
async def __call__(self, p, packet_data):
|
||||
try:
|
||||
if not self.pre_login and not p.joined_world:
|
||||
await p.close()
|
||||
raise AuthorityError(f'{p} tried sending XT packet before authentication!')
|
||||
@ -81,6 +83,10 @@ class _XTListener(_Listener):
|
||||
super()._check_list(p)
|
||||
|
||||
await super().__call__(p, packet_data)
|
||||
except CooldownError:
|
||||
p.logger.debug(f'{p} tried to send a packet during a cooldown')
|
||||
except ChecklistError:
|
||||
p.logger.debug(f'{p} sent a packet without meeting checklist requirements')
|
||||
|
||||
|
||||
class _XMLListener(_Listener):
|
||||
@ -89,6 +95,7 @@ class _XMLListener(_Listener):
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
async def __call__(self, p, packet_data):
|
||||
try:
|
||||
await super()._check_cooldown(p)
|
||||
super()._check_list(p)
|
||||
|
||||
@ -103,13 +110,20 @@ class _XMLListener(_Listener):
|
||||
|
||||
handler_call_arguments.append(await do_conversion(converter, ctx))
|
||||
return await self.callback(*handler_call_arguments)
|
||||
except CooldownError:
|
||||
p.logger.debug(f'{p} tried to send a packet during a cooldown')
|
||||
except ChecklistError:
|
||||
p.logger.debug(f'{p} sent a packet without meeting checklist requirements')
|
||||
|
||||
|
||||
class _DummyListener(_Listener):
|
||||
async def __call__(self, p, *_):
|
||||
try:
|
||||
super()._check_list(p)
|
||||
handler_call_arguments = [self.instance, p] if self.instance is not None else [p]
|
||||
return await self.callback(*handler_call_arguments)
|
||||
except ChecklistError:
|
||||
p.logger.debug(f'{p} sent a packet without meeting checklist requirements')
|
||||
|
||||
|
||||
class _ListenerManager(_AbstractManager):
|
||||
|
@ -7,8 +7,6 @@ from xml.etree.cElementTree import Element, SubElement, tostring
|
||||
|
||||
from houdini.constants import ClientType
|
||||
from houdini.handlers import AuthorityError, DummyEventPacket
|
||||
from houdini.converters import ChecklistError
|
||||
from houdini.cooldown import CooldownError
|
||||
|
||||
|
||||
class Spheniscidae:
|
||||
@ -142,27 +140,21 @@ class Spheniscidae:
|
||||
async def _client_connected(self):
|
||||
self.logger.info(f'Client {self.peer_name} connected')
|
||||
|
||||
try:
|
||||
dummy_event = DummyEventPacket('connected')
|
||||
if dummy_event in self.server.dummy_event_listeners:
|
||||
dummy_event_listeners = self.server.dummy_event_listeners[dummy_event]
|
||||
for listener in dummy_event_listeners:
|
||||
await listener(self)
|
||||
except ChecklistError:
|
||||
self.logger.debug(f'{self} sent a packet without meeting checklist requirements')
|
||||
|
||||
async def _client_disconnected(self):
|
||||
del self.server.peers_by_ip[self.peer_name]
|
||||
self.logger.info(f'Client {self.peer_name} disconnected')
|
||||
|
||||
try:
|
||||
dummy_event = DummyEventPacket('disconnected')
|
||||
if dummy_event in self.server.dummy_event_listeners:
|
||||
dummy_event_listeners = self.server.dummy_event_listeners[dummy_event]
|
||||
for listener in dummy_event_listeners:
|
||||
await listener(self)
|
||||
except ChecklistError:
|
||||
self.logger.debug(f'{self} sent a packet without meeting checklist requirements')
|
||||
|
||||
async def __data_received(self, data):
|
||||
data = data.decode()[:-1]
|
||||
@ -173,10 +165,6 @@ class Spheniscidae:
|
||||
await self.__handle_xt_data(data)
|
||||
except AuthorityError:
|
||||
self.logger.debug(f'{self} tried to send game packet before authentication')
|
||||
except CooldownError:
|
||||
self.logger.debug(f'{self} tried to send a packet during a cooldown')
|
||||
except ChecklistError:
|
||||
self.logger.debug(f'{self} sent a packet without meeting checklist requirements')
|
||||
|
||||
async def run(self):
|
||||
await self._client_connected()
|
||||
|
Loading…
Reference in New Issue
Block a user