dolor.packet_handler¶
Code for packet handling.
- packet_listener(*checkers, **kwargs)[source]¶
Decorator for internal packet listeners, packet listeners that are methods.
- Parameters
*checkers – See
PacketHandler.register_packet_listener().**kwargs – See
PacketHandler.register_packet_listener().
- Returns
The actual decorator to be used.
- Return type
function
Examples
>>> import dolor >>> class MyPacketHandler(dolor.packet_handler.PacketHandler): ... @dolor.packet_listener(dolor.packets.Packet) ... async def my_listener(self, p): ... pass ...
- class PacketHandler[source]¶
Bases:
abc.ABCA generic packet handler.
- to_real_packet_checker(checker)[source]¶
Turns a packet checker into a function that checks a packet.
- Parameters
checker – See
register_packet_listener().- Returns
A
functionthat returns abooland takes two arguments, the first being the relevantConnection, and the second being the packet to check.- Return type
function
- join_checkers(first, second)[source]¶
Joins two real packet checkers into one.
- Parameters
first (
function) – A real packet checker returned fromto_real_packet_checker().second (
function) – A real packet checker returned fromto_real_packet_checker().
- Returns
- Return type
function
- register_packet_listener(func, *checkers, **kwargs)[source]¶
Registers a packet listener.
- Parameters
func (coroutine function) – The packet listener.
*checkers (subclass of
Packetorintorfunction) –If a subclass of
Packet, then the listener will be called if the packet is an instance of that class.If an
int, then the listener will be called if the id of the packet is equal to the passedint.If a
function, then the function can either return abooland take one argument, which represents the packet to check, or it can return abooland take two arguments, the first being the relevantConnection, and the second being the packet to check.**kwargs – Keyword arguments that must match the keyword arguments passed to
listeners_for_packet()for the packet listener to be included in its return.
- Raises
TypeError – If
funcisn’t a coroutine function.ValueError – If no checkers are specified.
- unregister_packet_listener(func)[source]¶
Unregisters a packet listener.
- Parameters
func (coroutine function) – The listener registered with
register_packet_listener().
- external_packet_listener(*checkers, **kwargs)[source]¶
Decorator for external packet listeners.
For internal packet listeners, packet listeners that are methods, see
packet_listener().- Parameters
*checkers – See
register_packet_listener().**kwargs – See
register_packet_listener().
- Returns
The actual decorator to be used.
- Return type
function
Examples
>>> import dolor >>> class MyPacketHandler(dolor.packet_handler.PacketHandler): ... pass ... >>> handler = MyPacketHandler() >>> @handler.external_packet_listener ... def my_listener(p): ... pass ...
- register_internal_listeners()[source]¶
Registers internal packet listeners.
See
packet_listener().Called on
__init__().
- listeners_for_packet(c, p, **kwargs)[source]¶
Gets the packet listeners for a packet.
- Parameters
c (
Connection) – The relevant connection.p (
Packet) – The packet to check.**kwargs – The keyword arguments that should’ve been used to register the packet listener in
register_packet_listener().
- Returns
The list of packet listeners for the packet.
- Return type
list