peng3dnet.conntypes
- Connection Types¶
-
class
peng3dnet.conntypes.
ConnectionType
(peer)[source]¶ Class representing a Connection Type implementation.
Connection Types are identified by their name, usually a lowercase string.
See
Client()
for how to specify the connection type used.To use a custom connection type, it must be registered on both server and client via
Server.addConnType()
orClient.addConnType()
, respectively.peer
is an instance of eitherClient()
orServer()
.Note that a single instance of this class will be shared between all connections of the type implemented by this class. Distinguishing single connections is possible via the
cid
parameter given to most methods. On the client side, this parameter will always beNone
.-
init
(cid)[source]¶ Called when the
SetTypePacket()
is received on the server side, or sent on the client side.Detecting which side of the connection is managed can be done by checking the
cid
parameter, if it isNone
, the client side is represented, else it represents the ID of the connected client.
-
receive
(msg, pid, flags, cid)[source]¶ Called whenever a packet is received via connection of the type represented by this class.
msg
is the already decoded message or payload.pid
is the ID of the packet type.flags
is the flags portion of the header, containing a bitfield with various internal flags.cid
is the ID of the connected peer, if it isNone
, the peer is a server.If the return value of this method equals to
True
, further processing of the packet will be prevented.
-
send
(data, pid, cid)[source]¶ Called whenever a packet has been sent via a connection of the type represented by this class.
data
is the fully encoded data that has been sent.pid
is the packet type, as received by eitherServer.send_message()
orClient.send_message()
.cid
is the ID of the connected peer, it if isNone
, the peer is a server.If the return value of this method equals to
True
, no further event handlers will be called.
-
-
class
peng3dnet.conntypes.
ClassicConnectionType
(peer)[source]¶ Classic Connection Type representing a typical connection.
Currently adds no further processing to packets and starts a handshake by sending a
HandshakePacket()
from the server to the client.The handshake allows the client to copy the registry of the server, preventing bugs with mismatching packet IDs.