Example #1
0
 def object_created(object_info):
     prim = object_info.payload['object']
     matches = client.inventory.search_inventory(
         client.inventory.folders, name="Objects")
     folder = matches.pop()
     transaction_id = UUID()
     transaction_id.random()
     prim.derez(client, DeRezDestination.TakeIntoAgentInventory,
                folder.FolderID, transaction_id, client.active_group_id)
     s.signal()
    def test_onObjectUpdate_selected(self):

        self.object_store.agent = Agent()
        fake_uuid = UUID()
        fake_uuid.random()
        packet = Message(
            'ObjectUpdate', Block('RegionData', RegionHandle=0,
                                  TimeDilation=0),
            Block('ObjectData',
                  ID=1,
                  State=1,
                  FullID=fake_uuid,
                  CRC=0,
                  PCode=0,
                  Material=0,
                  ClickAction=0,
                  Scale=Vector3(X=0.0, Y=0.0, Z=0.0),
                  ObjectData='',
                  ParentID=fake_uuid,
                  UpdateFlags=0,
                  ProfileCurve=0,
                  PathBegin=0.0,
                  PathEnd=0.0,
                  PathScaleX=0.0,
                  PathScaleY=0.0,
                  PathShearX=0.0,
                  PathShearY=0.0,
                  PathTwist=-1,
                  PathTwistBegin=-1,
                  PathRadiusOffset=-1,
                  PathTaperX=-1,
                  PathTaperY=-1,
                  PathRevolutions=0,
                  PathSkew=-1,
                  ProfileBegin=0,
                  ProfileEnd=0,
                  ProfileHollow=0,
                  TextureEntry='',
                  TextureAnim='',
                  NameValue='Test',
                  Data='',
                  Text='',
                  TextColor=0x0,
                  MedialURL=''))

        def callback(payload):
            self.data.append("foo")

        object_handler = self.object_store.agent.events_handler.register(
            "ObjectSelected")
        object_handler.subscribe(callback)
        self.object_store.region.message_handler.handle(packet)
        self.assertTrue(self.data.pop, "foo")
Example #3
0
    def create_new_item(self, folder, name, desc, asset_type, inv_type,
                        wearable_type, next_owner_permission, callback=None):
        """
        Creates a new item in folder.
        """
        transaction_id = UUID()
        transaction_id.random()

        updateCreateInventoryHandler = self.agent.region.message_handler.register('UpdateCreateInventoryItem')

        def onUpdateCreateInventoryItem(packet):
            if str(transaction_id) != str(packet['AgentData'][0]['TransactionID']):
                inv_data = packet['InventoryData'][0]
                item = InventoryItem(inv_data['ItemID'],
                                     inv_data['FolderID'],
                                     inv_data['CreatorID'],
                                     inv_data['OwnerID'],
                                     inv_data['GroupID'],
                                     inv_data['BaseMask'],
                                     inv_data['OwnerMask'],
                                     inv_data['GroupMask'],
                                     inv_data['EveryoneMask'],
                                     inv_data['NextOwnerMask'],
                                     inv_data['GroupOwned'],
                                     inv_data['AssetID'],
                                     inv_data['Type'],
                                     inv_data['InvType'],
                                     inv_data['Flags'],
                                     inv_data['SaleType'],
                                     inv_data['SalePrice'],
                                     inv_data['Name'],
                                     inv_data['Description'],
                                     inv_data['CreationDate'],
                                     inv_data['CRC'])

                self._store_inventory_item(item)
                updateCreateInventoryHandler.unsubscribe(onUpdateCreateInventoryItem)
                if callback != None:
                    callback(item)

        updateCreateInventoryHandler.subscribe(onUpdateCreateInventoryItem) 

        self.send_CreateInventoryItem(self.agent.agent_id,
                                      self.agent.session_id,
                                      0,
                                      folder.FolderID,
                                      transaction_id,
                                      next_owner_permission,
                                      asset_type,
                                      inv_type,
                                      wearable_type,
                                      name,
                                      desc)
Example #4
0
    def sendCreateObject(self, objId, pos, rot, scale, tok):
        RayTargetID = UUID()
        RayTargetID.random()

        client = self.manager.client
        client.region.objects.object_add(client.agent_id, client.session_id,
                        PCodeEnum.Primitive,
                        Material = 3, AddFlags = 2, PathCurve = 16,
                        ProfileCurve = 1, PathBegin = 0, PathEnd = 0,
                        PathScaleX = 100, PathScaleY = 100, PathShearX = 0,
                        PathShearY = 0, PathTwist = 0, PathTwistBegin = 0,
                        PathRadiusOffset = 0, PathTaperX = 0, PathTaperY = 0,
                        PathRevolutions = 0, PathSkew = 0, ProfileBegin = 0,
                        ProfileEnd = 0, ProfileHollow = tok, BypassRaycast = 1,
                        RayStart = pos, RayEnd = pos,
                        RayTargetID = RayTargetID, RayEndIsIntersection = 0,
                        Scale = scale, Rotation = rot,
                        State = 0)
Example #5
0
    def sendCreateObject(self, objId, pos, rot, scale, tok):
        RayTargetID = UUID()
        RayTargetID.random()

        client = self.manager.client
        client.region.objects.object_add(client.agent_id, client.session_id,
                        PCodeEnum.Primitive,
                        Material = 3, AddFlags = 2, PathCurve = 16,
                        ProfileCurve = 1, PathBegin = 0, PathEnd = 0,
                        PathScaleX = 100, PathScaleY = 100, PathShearX = 0,
                        PathShearY = 0, PathTwist = 0, PathTwistBegin = 0,
                        PathRadiusOffset = 0, PathTaperX = 0, PathTaperY = 0,
                        PathRevolutions = 0, PathSkew = 0, ProfileBegin = 0,
                        ProfileEnd = 0, ProfileHollow = tok, BypassRaycast = 1,
                        RayStart = pos, RayEnd = pos,
                        RayTargetID = RayTargetID, RayEndIsIntersection = 0,
                        Scale = scale, Rotation = rot,
                        State = 0)
Example #6
0
    def uploadAsset(self, assetType, data, cb):
        """
        Request an asset upload from the simulator
        """
        tr_uuid = UUID()
        tr_uuid.random()
        init_data = None
        assetID = uuid_combine(tr_uuid, self._agent.secure_session_id)

        #if len(data) < 1024:
        #    init_data = array('c', data)
        #else:
        newuploader = XferUploader(data, cb, tr_uuid)
        self._uploaders[str(assetID)] = newuploader

        self._agent.asset_manager.upload_asset(tr_uuid,
                                               assetType,
                                               False, # tempfile
                                               False, # storelocal
                                               init_data) # asset_data
        return  assetID
Example #7
0
    def uploadAsset(self, assetType, data, cb):
        """
        Request an asset upload from the simulator
        """
        tr_uuid = UUID()
        tr_uuid.random()
        init_data = None
        assetID = uuid_combine(tr_uuid, self._agent.secure_session_id)

        #if len(data) < 1024:
        #    init_data = array('c', data)
        #else:
        newuploader = XferUploader(data, cb, tr_uuid)
        self._uploaders[str(assetID)] = newuploader

        self._agent.asset_manager.upload_asset(
            tr_uuid,
            assetType,
            False,  # tempfile
            False,  # storelocal
            init_data)  # asset_data
        return assetID
Example #8
0
    def request_asset(self,
                      assetID,
                      assetType,
                      isPriority,
                      callback=None,
                      itemID=None):
        """
        Sends a TransferRequest to the sim for asset assetID with type assetType,
        will call callback with the assetID and True with the asset received or False
        if request failed.  On successful request the asset is store in
        self.assets 
        TODO add a timeout
        """
        transferID = UUID()  #associate the assetID with the transferID
        transferID.random()
        transferInfoHandler = self.agent.region.message_handler.register(
            'TransferInfo')
        transferPacketHandler = self.agent.region.message_handler.register(
            'TransferPacket')

        def onTransferPacket(packet):
            """
            TransferPacket of a successful TransferRequest
            """
            # fill in data for Asset in the requests queue and pop it off and story in assets dict
            if str(transferID) == str(packet['TransferData'][0]['TransferID']):

                # insert packet
                self.assets[str(assetID)].store_packet(
                    packet['TransferData'][0]['Packet'],
                    packet['TransferData'][0]['Data'],
                    packet['TransferData'][0]['Status'])
                if self.assets[str(assetID)].is_downloaded():
                    self.assets[str(assetID)].assemble_data()
                    if callback != None:
                        callback(assetID, True)
                    transferPacketHandler.unsubscribe(onTransferPacket)
                else:
                    pass
                    # wait for more packets

        def onTransferInfo(packet):
            """
            Status of TransferRequest
            Account for size and multiple packets
            """
            if not self.assets.has_key(str(assetID)):
                self.assets[str(assetID)] = Asset(assetID, assetType)

            if str(transferID) == str(packet['TransferInfo'][0]['TransferID']):
                status = packet['TransferInfo'][0]["Status"]
                if status != TransferStatus.OK:
                    logger.warning("Request for asset %s failed with status %s" \
                        % (assetID, status))
                    if callback != None:
                        callback(assetID, False)
                    transferPacketHandler.unsubscribe(onTransferPacket)
                else:
                    self.assets[str(
                        assetID)].size = packet['TransferInfo'][0]['Size']
                transferInfoHandler.unsubscribe(onTransferInfo)

        transferInfoHandler.subscribe(onTransferInfo)
        transferPacketHandler.subscribe(onTransferPacket)

        if isPriority:
            priority = 1.0
        else:
            priority = 0.0

        params = ''
        if itemID != None:
            params += self.agent.agent_id.get_bytes() + \
                      self.agent.session_id.get_bytes() + \
                      self.agent.agent_id.get_bytes() + \
                      UUID().get_bytes() + \
                      itemID.get_bytes()
        params += assetID.get_bytes() + \
                  Helpers().int_to_bytes(assetType)

        self.send_TransferRequest(transferID, TransferChannelType.Asset,
                                  TransferSourceType.Asset, priority, params)
Example #9
0
    def test_create_new_item(self):

        self.inventory.agent = Agent()
        agent_id = UUID()
        agent_id.random()
        self.inventory.agent.agent_id = agent_id

        self.inventory.agent.region = DummyRegion()

        matches = self.inventory.search_inventory(self.inventory.folders,
                                                  name='My Inventory')
        self.assertEqual(len(matches), 1)
        folder = matches.pop()
        self.inventory.create_new_item(folder, "Name", "Desc",
                                       AssetType.LSLText, InventoryType.LSL,
                                       WearablesIndex.WT_SHAPE, 0)
        packet = self.inventory.agent.region.dummy_packet_holder.pop()
        self.assertEqual(packet.name, "CreateInventoryItem")

        self.assertEqual(packet['InventoryBlock'][0]['FolderID'],
                         folder.FolderID)
        self.assertEqual(packet['InventoryBlock'][0]['Name'], 'Name')
        self.assertEqual(packet['InventoryBlock'][0]['Description'], 'Desc')

        fake_uuid = UUID()
        fake_uuid.random()
        packet = Message(
            'UpdateCreateInventoryItem',
            Block('AgentData',
                  AgentID=UUID(),
                  SimApproved=True,
                  TransactionID=UUID()),
            Block('InventoryData',
                  ItemID=fake_uuid,
                  FolderID=folder.FolderID,
                  CallbackID=0,
                  CreatorID=agent_id,
                  OwnerID=agent_id,
                  GroupID=UUID(),
                  BaseMask=Permissions.All,
                  OwnerMask=Permissions.All,
                  GroupMask=Permissions.None_,
                  EveryoneMask=Permissions.None_,
                  NextOwnerMask=Permissions.None_,
                  GroupOwned=False,
                  AssetID=UUID(),
                  Type=AssetType.LSLText,
                  InvType=InventoryType.LSL,
                  Flags=0,
                  SaleType=0,
                  SalePrice=0,
                  Name="Name",
                  Description="Desc",
                  CreationDate=0,
                  CRC=0))
        self.inventory.agent.region.message_handler.handle(packet)
        matches = self.inventory.search_inventory(self.inventory.folders,
                                                  name="Name")
        self.assertEqual(len(matches), 1)
        item = matches.pop()
        self.assertEqual(item.Name, "Name")