Ejemplo n.º 1
0
 def addPacket(packet: DataPacket):
     if not packet.canBeBatched():
         raise Exception(
             str(type(packet).__name__) +
             " cannot be put inside a BatchPacket")
     if not packet.isEncoded:
         packet.encode()
     self.payload += Binary.writeUnsignedVarInt(len(
         packet.buffer)) + packet.buffer
Ejemplo n.º 2
0
 def putPacket(self,
               player: Player,
               packet: DataPacket,
               needACK: bool = False,
               immediate: bool = True):
     if Utils.searchList(self.identifers, player) == True:
         identifier = self.identifiers[Utils.getKeyInListFromItem(
             self.identifers, player)]
         if not packet.isEncoded:
             packet.encode()
         if isinstance(packet, BatchPacket):
             if needACK:
                 pk = EncapsulatedPacket()
                 pk.identifierACK = self.identifiersACK[identifier]
                 self.identifiersACK[identifier] += 1
                 pk.buffer = packet.buffer
                 pk.reliability = 3
                 pk.orderChannel = 0
             else:
                 try:
                     packet._encapsulatedPacket
                 except:
                     packet._encapsulatedPacket = CachedEncapsulatedPacket()
                     packet._encapsulatedPacket.identifierACK = None
                     packet._encapsulatedPacket.buffer = packet.buffer
                     packet._encapsulatedPacket.reliability = 3
                     packet._encapsulatedPacket.orderChannel = 0
                 pk = packet._encapsulatedPacket
             self.interface.sendEncapsulated(
                 identifier, pk, (PyRakLib.FLAG_NEED_ACK if needACK else 0)
                 | (PyRakLib.PRIORITY_IMMEDIATE
                    if immediate else PyRakLib.PRIORITY_NORMAL))
             return pk.identifierACK
         else:
             #self.server.batchPackets([player], [packet], True, immediate)
             return None
     return None