mirror of
https://github.com/solero/houdini.git
synced 2024-11-13 22:28:21 +00:00
Custom exceptions now raised for cooldown and authentication
This commit is contained in:
parent
0f09cabe00
commit
df8f6a917b
@ -16,19 +16,12 @@ def get_relative_function_path(function_obj):
|
|||||||
return rel_function_file
|
return rel_function_file
|
||||||
|
|
||||||
|
|
||||||
def get_converter(component):
|
class ChecklistError(Exception):
|
||||||
if component.annotation is component.empty:
|
"""Raised when a checklist fails"""
|
||||||
return str
|
|
||||||
return component.annotation
|
|
||||||
|
|
||||||
|
|
||||||
async def do_conversion(converter, p, component_data):
|
class AuthorityError(Exception):
|
||||||
if IConverter.implementedBy(converter):
|
"""Raised when a packet is received but user has not yet authenticated"""
|
||||||
converter_instance = converter(p, component_data)
|
|
||||||
if asyncio.iscoroutinefunction(converter_instance.convert):
|
|
||||||
return await converter_instance.convert()
|
|
||||||
return converter_instance.convert()
|
|
||||||
return converter(component_data)
|
|
||||||
|
|
||||||
|
|
||||||
class _Packet:
|
class _Packet:
|
||||||
@ -98,14 +91,21 @@ class _Listener:
|
|||||||
def __name__(self):
|
def __name__(self):
|
||||||
return "{}.{}".format(self.handler.__module__, self.handler.__name__)
|
return "{}.{}".format(self.handler.__module__, self.handler.__name__)
|
||||||
|
|
||||||
def __call__(self, p, packet_data):
|
async def __call__(self, p, packet_data):
|
||||||
|
if isinstance(self.packet, XTPacket) and not self.pre_login and not p.joined_world:
|
||||||
|
await p.close()
|
||||||
|
raise AuthorityError('{} tried sending XT packet before authentication!'.format(p))
|
||||||
|
|
||||||
if self.cooldown is not None:
|
if self.cooldown is not None:
|
||||||
bucket = self.cooldown.get_bucket(p)
|
bucket = self.cooldown.get_bucket(p)
|
||||||
if bucket.is_cooling:
|
if bucket.is_cooling:
|
||||||
raise RuntimeError('{} sent packet during cooldown'.format(p.peer_name))
|
if self.cooldown.callback is not None:
|
||||||
|
await self.cooldown.callback(*[self.plugin, p] if self.plugin is not None else p)
|
||||||
|
else:
|
||||||
|
raise CooldownError('{} sent packet during cooldown'.format(p))
|
||||||
|
|
||||||
if not self._can_run(p):
|
if not self._can_run(p):
|
||||||
raise RuntimeError('Could not handle packet due to checklist failure')
|
raise ChecklistError('Could not handle packet due to checklist failure')
|
||||||
|
|
||||||
|
|
||||||
class _XTListener(_Listener):
|
class _XTListener(_Listener):
|
||||||
|
Loading…
Reference in New Issue
Block a user