コード例 #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
コード例 #2
0
 def getPackets(self):
     stream = DataPacket.BinaryStream(self.payload)
     count = 0
     while not stream.feof():
         count += 1
         if count >= 500:
             raise Exception("Too many packets in a single batch")
         yield stream.getString()
コード例 #3
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
コード例 #4
0
 def decodePayload(self):
     self.protocol = self.getInt()
     try:
         buffer = DataPacket.BinaryStream(self.getString())
         self.chainData = json.loads(buffer.get(buffer.getLInt()))
         hasExtraData = False
         for chain in self.chainData["chain"]:
             webtoken = Utils.decodeJWT(chain)
             if webtoken["extraData"] in locals(
             ) or webtoken["extraData"] in globals():
                 if hasExtraData:
                     raise Exception(
                         "Found 'extraData' multiple times in key chain")
                 hasExtraData = True
                 if webtoken["extraData"]["displayName"] in locals(
                 ) or webtoken["extraData"]["displayName"] in globals():
                     self.username = webtoken["extraData"]["displayName"]
                 if webtoken["extraData"]["identity"] in locals(
                 ) or webtoken["extraData"]["identity"] in globals():
                     self.clientUUID = webtoken["extraData"]["identity"]
                 if webtoken["extraData"]["XUID"] in locals(
                 ) or webtoken["extraData"]["XUID"] in globals():
                     self.xuid = webtoken["extraData"]["XUID"]
             if webtoken["identityPublicKey"] in locals(
             ) or webtoken["identityPublicKey"] in globals():
                 self.identityPublicKey = webtoken["identityPublicKey"]
         self.clientDataJwt = buffer.get(buffer.getLInt())
         self.clientData = Utils.decodeJWT(self.clientDataJwt)
         self.clientId = self.clientData[
             "ClientRandomId"] if self.clientData[
                 "ClientRandomId"] != None else None
         self.serverAddress = self.clientData[
             "ServerAddress"] if self.clientData[
                 "ServerAddress"] != None else None
         self.locale = self.clientData["LanguageCode"] if self.clientData[
             "LanguageCode"] != None else None
     except:
         if self.protocol == ProtocolInfo.MCBE_PROTOCOL_VERSION:
             raise Exception("Error")