peng3dnet.packet
- Packet Classes¶
-
class
peng3dnet.packet.
Packet
(reg, peer, obj=None)[source]¶ Class representing a packet type.
reg
is an instance ofPacketRegistry
shared between all packet types registered with it.peer
is the peer this packet type belongs to.Todo
Find out what
obj
does… Seems to be an unused artifact from a test.-
_receive
(msg, cid=None)[source]¶ Internal handler called whenever a packet of this type is received.
By default, this method passes its arguments through to
receive()
.May be overridden by subclasses to prevent further processing.
-
_send
(msg, cid=None)[source]¶ Internal handler called whenever a packet of this type has been sent.
By default, this method passes its arguments through to
send()
.May be overridden by subclasses to prevent further processing.
-
receive
(msg, cid=None)[source]¶ Event handler called when a packet of this type is received.
Note that this method is usually called by
_receive()
, which may also decide to silently ignore a packet.msg
is the fully decoded message or payload, usually a dictionary.cid
is the ID of the peer that sent the message. If this isNone
, the packet was received on the client side, else it equals the client ID of the client.
-
send
(msg, cid=None)[source]¶ Event handler called when a packet of this type has been sent.
Note that this method is usually called by
_send()
, which may also decide to silently ignore a packet.msg
is the already encoded message.cid
is the ID of the peer that should receive the message. If this isNone
, the packet was sent on the client side, else it equals the client ID of the recipient.
-
-
class
peng3dnet.packet.
SmartPacket
(reg, peer, obj=None)[source]¶ Smart packet type allowing for various assertions.
This class is not intended to be used directly, use subclasses and override the class attributes for customization.
This class overrides the
_receive()
and_send()
methods to check that the connection is in a valid state for this packet.-
conntype
= None¶ Declares the required connection type for this packet to be sent or retrieved.
If this is
None
, this check will be skipped.Else, if the specified value does not match the actual value, the action specified in
invalid_action
is executed.
-
invalid_action
= 'ignore'¶ Specifies what to do if one of the conditions specified is not fulfilled.
Can be either
ignore
orclose
. A value ofignore
causes this packet to be ignored. Note that due to technical reasons, the packet may still be processed by other mechanisms. In contrast, a value ofclose
will cause the connection to be closed with the reasonsmartpacketinvalid
.If an invalid value is used, an
InvalidSmartPacketActionError
will be raised and the packet ignored.
-
min_sslsec_level
= 0¶ Declares the minimum level of SSL encryption required for this packet to be sent.
This is not checked on receival of a message, only during sending of the message.
Possible values are any of the
SSLSEC_*
constants.If the actual SSL security level is lower than the required level, the action specified in
invalid_action
is executed.
-
mode
= None¶ Specifies the connection mode required for this packet to be sent or received.
If this is
None
, this check will be skipped.Else, if the specified connection mode does not exactly match the actual connection mode, the action specified in
invalid_action
is executed.
-
side
= None¶ Specifies the side of the connection this packet can be received.
If this is
None
, it can be received on both ends of a connection. If this isSIDE_SERVER
orSIDE_CLIENT
, it can be received on the server or client side, respectively.Note that packets that can only be received on the client side can only be sent from the server side, and vice versa.
In the case that this condition does not match, the action specified in
invalid_action
is executed.
-
state
= 64¶ Specifies the connection state required for the packet, both on send and receive.
If the state does not match exactly, the action specified in
invalid_action
is executed.
-