public bool StoreAsset(AssetBase asset)
 {
     try
     {
         if (asset.Name.Length > 64)
             asset.Name = asset.Name.Substring(0, 64);
         if (asset.Description.Length > 128)
             asset.Description = asset.Description.Substring(0, 128);
         if (ExistsAsset(asset.ID))
         {
             AssetBase oldAsset = GetAsset(asset.ID);
             if (oldAsset == null || (oldAsset.Flags & AssetFlags.Rewritable) == AssetFlags.Rewritable)
             {
                 MainConsole.Instance.Debug("[LocalAssetDatabase]: Asset already exists in the db, overwriting - " + asset.ID);
                 Delete(asset.ID, true);
                 InsertAsset(asset, asset.ID);
             }
             else
             {
                 MainConsole.Instance.Debug("[LocalAssetDatabase]: Asset already exists in the db, fixing ID... - " + asset.ID);
                 InsertAsset(asset, UUID.Random());
             }
         }
         else
         {
             InsertAsset(asset, asset.ID);
         }
     }
     catch (Exception e)
     {
         MainConsole.Instance.ErrorFormat("[LocalAssetDatabase]: Failure creating asset {0} with name \"{1}\". Error: {2}",
                           asset.ID, asset.Name, e);
     }
     return true;
 }
        public bool GetExists(string id)
        {
            Aurora.Framework.AssetBase asset = null;
            if (m_Cache != null)
            {
                asset = m_Cache.Get(id);
            }

            if (asset != null)
            {
                return(true);
            }

            List <string> serverURIs = m_registry.RequestModuleInterface <IConfigurationService>().FindValueOf("AssetServerURI");

            //if (m_serverURL != string.Empty)
            //    serverURIs = new List<string>(new string[1] { m_serverURL });
            foreach (string m_ServerURI in serverURIs)
            {
                string uri = m_ServerURI + "/" + id + "/exists";

                bool exists = SynchronousRestObjectRequester.
                              MakeRequest <int, bool>("GET", uri, 0);
                if (exists)
                {
                    return(exists);
                }
            }

            return(false);
        }
        void IAssetService.Get(string id, object sender, AssetRetrieved handler)
        {
            List <string> serverURIs = m_registry.RequestModuleInterface <IConfigurationService>().FindValueOf("AssetServerURI");

            //if (m_serverURL != string.Empty)
            //    serverURIs = new List<string>(new string[1] { m_serverURL });
            foreach (string m_ServerURI in serverURIs)
            {
                string uri = m_ServerURI + "/" + id;

                Aurora.Framework.AssetBase asset = null;
                if (m_Cache != null)
                {
                    asset = m_Cache.Get(id);
                }

                if (asset == null)
                {
                    AsynchronousRestObjectRequester.
                    MakeRequest <int, AssetBase>("GET", uri, 0,
                                                 delegate(AssetBase a)
                    {
                        handler(id, sender, TearDown(a));
                    });
                }
                else
                {
                    handler(id, sender, asset);
                }
            }
        }
Пример #4
0
        public UUID Store(Aurora.Framework.AssetBase asset)
        {
            AssetBase rasset = Build(asset);

            if ((asset.Flags & AssetFlags.Local) == AssetFlags.Local)
            {
                if (m_Cache != null)
                {
                    m_Cache.Cache(asset.IDString, asset);
                }

                return(asset.ID);
            }

            UUID          newID      = UUID.Zero;
            List <string> serverURIs =
                m_registry.RequestModuleInterface <IConfigurationService>().FindValueOf("AssetServerURI");

            if (m_serverURL != string.Empty)
            {
                serverURIs = new List <string>(new string[1] {
                    m_serverURL
                });
            }
            foreach (string mServerUri in serverURIs)
            {
                string uri = mServerUri + "/";
                try
                {
                    string request = SynchronousRestObjectRequester.MakeRequest <AssetBase, string>("POST", uri, rasset);

                    UUID.TryParse(request, out newID);
                }
                catch (Exception e)
                {
                    MainConsole.Instance.WarnFormat("[ASSET CONNECTOR]: Unable to send asset {0} to asset server. Reason: {1}", asset.ID, e.Message);
                }

                if (newID != UUID.Zero)
                {
                    // Placing this here, so that this work with old asset servers that don't send any reply back
                    // SynchronousRestObjectRequester returns somethins that is not an empty string
                    asset.ID = newID;

                    if (m_Cache != null)
                    {
                        m_Cache.Cache(asset.IDString, asset);
                    }
                }
                else
                {
                    return(asset.ID); //OPENSIM
                }
            }
            return(newID);
        }
Пример #5
0
        public bool Get(string id, object sender, AssetRetrieved handler)
        {
            List <string> serverURIs =
                m_registry.RequestModuleInterface <IConfigurationService>().FindValueOf("AssetServerURI");

            if (m_serverURL != string.Empty)
            {
                serverURIs = new List <string>(new string[1] {
                    m_serverURL
                });
            }
            foreach (string m_ServerURI in serverURIs)
            {
                string uri = m_ServerURI + "/" + id;

                Aurora.Framework.AssetBase asset = null;
                if (m_Cache != null)
                {
                    asset = m_Cache.Get(id);
                }

                if (asset == null)
                {
                    bool result = false;

                    AsynchronousRestObjectRequester.
                    MakeRequest("GET", uri, 0,
                                delegate(AssetBase aa)
                    {
                        Aurora.Framework.AssetBase a = TearDown(aa);
                        if (m_Cache != null)
                        {
                            m_Cache.Cache(a.IDString, a);
                        }
                        handler(id, sender, a);
                        result = true;
                    });

                    if (result)
                    {
                        return(result);
                    }
                }
                else
                {
                    handler(id, sender, asset);
                    return(true);
                }
            }

            return(false);
        }
Пример #6
0
        public UUID SaveBitmap(Bitmap data, bool lossless, bool temporary)
        {
            AssetBase asset = new AssetBase(UUID.Random(), "MRMDynamicImage", AssetType.Texture,
                                            m_scene.RegionInfo.RegionID)
                                  {
                                      Data = OpenJPEG.EncodeFromImage(data, lossless),
                                      Description = "MRM Image",
                                      Flags = (temporary) ? AssetFlags.Temperary : 0
                                  };
            asset.FillHash();
            asset.ID = m_scene.AssetService.Store(asset);

            return asset.ID;
        }
        public AssetBase Build(Aurora.Framework.AssetBase asset)
        {
            AssetBase r = new AssetBase
            {
                CreatorID   = asset.CreatorID.ToString(),
                Data        = asset.Data,
                Description = asset.Description,
                Flags       = asset.Flags,
                ID          = asset.ID.ToString(),
                Name        = asset.Name,
                Type        = (sbyte)asset.Type
            };

            return(r);
        }
Пример #8
0
        public byte[] GetData(string id)
        {
            if (m_Cache != null)
            {
                Aurora.Framework.AssetBase fullAsset = m_Cache.Get(id);

                if (fullAsset != null)
                {
                    return(fullAsset.Data);
                }
            }

            List <string> serverURIs = m_registry.RequestModuleInterface <IConfigurationService>().FindValueOf("AssetServerURI");

            if (m_serverURL != string.Empty)
            {
                serverURIs = new List <string>(new string[1] {
                    m_serverURL
                });
            }
            foreach (string m_ServerURI in serverURIs)
            {
                RestClient rc = new RestClient(m_ServerURI);
                rc.AddResourcePath("assets");
                rc.AddResourcePath(id);
                rc.AddResourcePath("data");

                rc.RequestMethod = "GET";

                System.IO.Stream s = rc.Request();

                if (s == null)
                {
                    return(null);
                }

                if (s.Length > 0)
                {
                    byte[] ret = new byte[s.Length];
                    s.Read(ret, 0, (int)s.Length);

                    return(ret);
                }
            }

            return(null);
        }
 public Aurora.Framework.AssetBase TearDown(AssetBase asset)
 {
     if (asset == null)
     {
         return(null);
     }
     Aurora.Framework.AssetBase r = new Aurora.Framework.AssetBase
     {
         CreatorID   = UUID.Parse(asset.CreatorID),
         Data        = asset.Data,
         Description = asset.Description,
         Flags       = asset.Flags,
         ID          = UUID.Parse(asset.ID),
         Name        = asset.Name,
         Type        = asset.Type
     };
     return(r);
 }
Пример #10
0
        public Aurora.Framework.AssetBase Get(string id)
        {
            Aurora.Framework.AssetBase asset = null;
            AssetBase rasset = null;

            if (m_Cache != null)
            {
                asset = m_Cache.Get(id);
                if ((asset != null) && ((asset.Data != null) && (asset.Data.Length != 0)))
                {
                    return(asset);
                }
            }

            List <string> serverURIs = m_registry == null
                                          ? null
                                          : m_registry.RequestModuleInterface <IConfigurationService>().FindValueOf(
                "AssetServerURI");

            if (m_serverURL != string.Empty)
            {
                serverURIs = new List <string>(new string[1] {
                    m_serverURL
                });
            }
            if (serverURIs != null)
            {
                foreach (string mServerUri in serverURIs)
                {
                    string uri = mServerUri + "/" + id;
                    rasset = SynchronousRestObjectRequester.MakeRequest <int, AssetBase>("GET", uri, 0);
                    asset  = TearDown(rasset);
                    if (m_Cache != null && asset != null)
                    {
                        m_Cache.Cache(asset.IDString, asset);
                    }
                    if (asset != null)
                    {
                        return(asset);
                    }
                }
            }
            return(null);
        }
Пример #11
0
        public UUID UpdateContent(UUID id, byte[] data)
        {
            Aurora.Framework.AssetBase asset = null;

            if (m_Cache != null)
            {
                asset = m_Cache.Get(id.ToString());
            }

            if (asset == null)
            {
                asset = Get(id.ToString());
                if (asset == null)
                {
                    return(UUID.Zero);
                }
            }
            asset.Data = data;

            List <string> serverURIs = m_registry.RequestModuleInterface <IConfigurationService>().FindValueOf("AssetServerURI");

            if (m_serverURL != string.Empty)
            {
                serverURIs = new List <string>(new string[1] {
                    m_serverURL
                });
            }
            foreach (string m_ServerURI in serverURIs)
            {
                string uri = m_ServerURI + "/" + id;

                if (SynchronousRestObjectRequester.
                    MakeRequest <AssetBase, bool>("POST", uri, Build(asset)))
                {
                    if (m_Cache != null)
                    {
                        m_Cache.Cache(asset.IDString, asset);
                    }

                    return(asset.ID);
                }
            }
            return(UUID.Zero);
        }
        public override byte[] Handle(string path, Stream request,
                                      OSHttpRequest httpRequest, OSHttpResponse httpResponse)
        {
            string body = GetBodyAsString(request);
            OSDMap map = WebUtils.GetOSDMap(Util.Decompress(body));
            IGridRegistrationService urlModule =
                m_registry.RequestModuleInterface<IGridRegistrationService>();
            if (m_SessionID != "" && urlModule != null)
                if (!urlModule.CheckThreatLevel(m_SessionID, "Asset_Update", ThreatLevel.High))
                    return new byte[0];
            UUID newID;
            if (map.ContainsKey("Method") && map["Method"] == "UpdateContent")
                m_AssetService.UpdateContent(map["ID"].AsUUID(), map["Data"].AsBinary(), out newID);
            else
            {
                AssetBase asset = new AssetBase();
                asset = asset.Unpack(map);
                newID = m_AssetService.Store(asset);
            }

            return Encoding.UTF8.GetBytes(newID.ToString());
        }
Пример #13
0
        public void AssetReceived(string id, Object sender, AssetBase asset)
        {
            if (asset != null)
            {
                this.Shape.SculptEntry = true;
                this.Shape.SculptData = asset.Data; //Set the asset data
            }

            bool isMesh = asset == null ? false : (asset.Type == (int) AssetType.Mesh);
            if (isMesh)
                this.Shape.SculptType = (byte)SculptType.Mesh;
            PrimitiveBaseShape shape = Shape.Copy();
            if ((bool) sender && this.PhysActor != null && (asset != null || (this.Shape.SculptData != null && this.Shape.SculptData.Length != 0))) //Update physics
            {
                //Get physics to update in a hackish way
                this.PhysActor.Shape = shape;
            }
            this.Shape = shape;
        }
        protected AssetBase CreateAsset(string assetIdStr, string name, string path, AssetType type)
        {
            AssetBase asset = new AssetBase(new UUID(assetIdStr), name, type, m_service.LibraryOwner);

            if (!String.IsNullOrEmpty(path))
            {
                //m_log.InfoFormat("[ASSETS]: Loading: [{0}][{1}]", name, path);

                LoadAsset(asset, path);
            }
            else
            {
                m_log.InfoFormat("[ASSETS]: Instantiated: [{0}]", name);
            }

            return asset;
        }
        protected static void LoadAsset(AssetBase info, string path)
        {
            //            bool image =
            //               (info.Type == (sbyte)AssetType.Texture ||
            //                info.Type == (sbyte)AssetType.TextureTGA ||
            //                info.Type == (sbyte)AssetType.ImageJPEG ||
            //                info.Type == (sbyte)AssetType.ImageTGA);

            FileInfo fInfo = new FileInfo(path);
            long numBytes = fInfo.Length;
            if (fInfo.Exists)
            {
                FileStream fStream = new FileStream(path, FileMode.Open, FileAccess.Read);
                byte[] idata = new byte[numBytes];
                BinaryReader br = new BinaryReader(fStream);
                idata = br.ReadBytes((int)numBytes);
                br.Close();
                fStream.Close();
                info.Data = idata;
                //info.loaded=true;
            }
            else
            {
                m_log.ErrorFormat("[ASSETS]: file: [{0}] not found !", path);
            }
        }
Пример #16
0
        public virtual UUID Store(AssetBase asset)
        {
            object remoteValue = DoRemote(asset);
            if (remoteValue != null || m_doRemoteOnly)
                asset.ID = (UUID)remoteValue;
            else
                //MainConsole.Instance.DebugFormat("[ASSET SERVICE]: Store asset {0} {1}", asset.Name, asset.ID);
                asset.ID = m_database.Store(asset);
            IImprovedAssetCache cache = m_registry.RequestModuleInterface<IImprovedAssetCache>();
            if (doDatabaseCaching && cache != null && asset != null && asset.Data != null && asset.Data.Length != 0)
            {
                cache.Expire(asset.ID.ToString());
                cache.Cache(asset.ID.ToString(), asset);
            }

            return asset != null ? asset.ID : UUID.Zero;
        }
Пример #17
0
 /// <summary>
 /// Create a new Inventory Item
 /// </summary>
 /// <param name="remoteClient"></param>
 /// <param name="creatorData"></param>
 /// <param name="folderID"></param>
 /// <param name="flags"></param>
 /// <param name="callbackID"></param>
 /// <param name="asset"></param>
 /// <param name="invType"></param>
 /// <param name="everyoneMask"></param>
 /// <param name="nextOwnerMask"></param>
 /// <param name="groupMask"></param>
 /// <param name="creationDate"></param>
 /// <param name="creatorID"></param>
 /// <param name="name"></param>
 /// <param name="baseMask"></param>
 /// <param name="currentMask"></param>
 protected void CreateNewInventoryItem(
     IClientAPI remoteClient, string creatorID, string creatorData, UUID folderID, string name, uint flags, uint callbackID, AssetBase asset, sbyte invType,
     uint baseMask, uint currentMask, uint everyoneMask, uint nextOwnerMask, uint groupMask, int creationDate)
 {
     InventoryItemBase item = new InventoryItemBase
                                  {
                                      Owner = remoteClient.AgentId,
                                      CreatorId = creatorID,
                                      CreatorData = creatorData,
                                      ID = UUID.Random(),
                                      AssetID = asset.ID,
                                      Description = asset.Description,
                                      Name = name,
                                      Flags = flags,
                                      AssetType = asset.Type,
                                      InvType = invType,
                                      Folder = folderID,
                                      CurrentPermissions = currentMask,
                                      NextPermissions = nextOwnerMask,
                                      EveryOnePermissions = everyoneMask,
                                      GroupPermissions = groupMask,
                                      BasePermissions = baseMask,
                                      CreationDate = creationDate
                                  };
     m_scene.InventoryService.AddItemAsync(item, (itm) =>
     {
         IAvatarFactory avFactory = m_scene.RequestModuleInterface<IAvatarFactory>();
         if (avFactory != null)
             avFactory.NewAppearanceLink(itm);
         remoteClient.SendInventoryItemCreateUpdate(itm, callbackID);
     });
 }
Пример #18
0
        /// <summary>
        /// Create a new 'link' to another inventory item
        /// Used in Viewer 2 for appearance.
        /// </summary>
        /// <param name="remoteClient"></param>
        /// <param name="transActionID"></param>
        /// <param name="folderID"></param>
        /// <param name="callbackID"></param>
        /// <param name="description"></param>
        /// <param name="name"></param>
        /// <param name="invType"></param>
        /// <param name="type"></param>
        /// <param name="olditemID"></param>
        protected void HandleLinkInventoryItem(IClientAPI remoteClient, UUID transActionID, UUID folderID,
                                             uint callbackID, string description, string name,
                                             sbyte invType, sbyte type, UUID olditemID)
        {
            //MainConsole.Instance.DebugFormat("[AGENT INVENTORY]: Received request to create inventory item link {0} in folder {1} pointing to {2}", name, folderID, olditemID);

            if (!m_scene.Permissions.CanCreateUserInventory(invType, remoteClient.AgentId))
                return;

            IScenePresence presence;
            if (m_scene.TryGetScenePresence(remoteClient.AgentId, out presence))
            {
                if (olditemID == AvatarWearable.DEFAULT_EYES_ITEM ||
                            olditemID == AvatarWearable.DEFAULT_BODY_ITEM ||
                            olditemID == AvatarWearable.DEFAULT_HAIR_ITEM ||
                            olditemID == AvatarWearable.DEFAULT_PANTS_ITEM ||
                            olditemID == AvatarWearable.DEFAULT_SHIRT_ITEM ||
                            olditemID == AvatarWearable.DEFAULT_SKIN_ITEM)
                {
                    return;
                }
                AssetBase asset = new AssetBase {ID = olditemID, Type = type, Name = name, Description = description};

                CreateNewInventoryItem(
                    remoteClient, remoteClient.AgentId.ToString(), "", folderID, name, 0, callbackID, asset, invType,
                    (uint)PermissionMask.All, (uint)PermissionMask.All, (uint)PermissionMask.All,
                    (uint)PermissionMask.All, (uint)PermissionMask.All, Util.UnixTimeSinceEpoch());
            }
            else
            {
                MainConsole.Instance.ErrorFormat(
                    "ScenePresence for agent uuid {0} unexpectedly not found in HandleLinkInventoryItem",
                    remoteClient.AgentId);
            }
        }
Пример #19
0
        ///<summary>
        ///</summary>
        ///<param name = "assetID"></param>
        ///<param name = "inventoryItem"></param>
        ///<param name = "data"></param>
        public UUID UploadCompleteHandler(string assetName, string assetDescription, UUID assetID,
                                          UUID inventoryItem, UUID parentFolder, byte[] data, string inventoryType,
                                          string assetType, uint everyone_mask, uint group_mask, uint next_owner_mask)
        {
            sbyte assType = 0;
            sbyte inType = 0;

            if (inventoryType == "sound")
            {
                inType = 1;
                assType = 1;
            }
            else if (inventoryType == "animation")
            {
                inType = 19;
                assType = 20;
            }
            else if (inventoryType == "snapshot")
            {
                inType = 15;
                assType = 0;
            }
            else if (inventoryType == "wearable")
            {
                inType = 18;
                switch (assetType)
                {
                    case "bodypart":
                        assType = 13;
                        break;
                    case "clothing":
                        assType = 5;
                        break;
                }
            }
            else if (inventoryType == "object")
            {
                inType = (sbyte) InventoryType.Object;
                assType = (sbyte) AssetType.Object;

                List<Vector3> positions = new List<Vector3>();
                List<Quaternion> rotations = new List<Quaternion>();
                OSDMap request = (OSDMap) OSDParser.DeserializeLLSDXml(data);
                OSDArray instance_list = (OSDArray) request["instance_list"];
                OSDArray mesh_list = (OSDArray) request["mesh_list"];
                OSDArray texture_list = (OSDArray) request["texture_list"];
                SceneObjectGroup grp = null;

                List<UUID> textures = new List<UUID>();
#if(!ISWIN)
                for (int i = 0; i < texture_list.Count; i++)
                {
                    AssetBase textureAsset = new AssetBase(UUID.Random(), assetName, AssetType.Texture, m_service.AgentID);
                    textureAsset.Data = texture_list[i].AsBinary();
                    textureAsset.ID = m_assetService.Store(textureAsset);
                    textures.Add(textureAsset.ID);
                }
#else
                foreach (AssetBase textureAsset in texture_list.Select(t => new AssetBase(UUID.Random(), assetName, AssetType.Texture,
                                                                                          m_service.AgentID) {Data = t.AsBinary()}))
                {
                    textureAsset.ID = m_assetService.Store(textureAsset);
                    textures.Add(textureAsset.ID);
                }
#endif
                InventoryFolderBase meshFolder = m_inventoryService.GetFolderForType(m_service.AgentID,
                                                                                     InventoryType.Mesh, AssetType.Mesh);
                for (int i = 0; i < mesh_list.Count; i++)
                {
                    PrimitiveBaseShape pbs = PrimitiveBaseShape.CreateBox();

                    Primitive.TextureEntry textureEntry =
                        new Primitive.TextureEntry(Primitive.TextureEntry.WHITE_TEXTURE);
                    OSDMap inner_instance_list = (OSDMap) instance_list[i];

                    OSDArray face_list = (OSDArray) inner_instance_list["face_list"];
                    for (uint face = 0; face < face_list.Count; face++)
                    {
                        OSDMap faceMap = (OSDMap) face_list[(int) face];
                        Primitive.TextureEntryFace f = pbs.Textures.CreateFace(face);
                        if (faceMap.ContainsKey("fullbright"))
                            f.Fullbright = faceMap["fullbright"].AsBoolean();
                        if (faceMap.ContainsKey("diffuse_color"))
                            f.RGBA = faceMap["diffuse_color"].AsColor4();

                        int textureNum = faceMap["image"].AsInteger();
                        float imagerot = faceMap["imagerot"].AsInteger();
                        float offsets = (float) faceMap["offsets"].AsReal();
                        float offsett = (float) faceMap["offsett"].AsReal();
                        float scales = (float) faceMap["scales"].AsReal();
                        float scalet = (float) faceMap["scalet"].AsReal();

                        if (imagerot != 0)
                            f.Rotation = imagerot;
                        if (offsets != 0)
                            f.OffsetU = offsets;
                        if (offsett != 0)
                            f.OffsetV = offsett;
                        if (scales != 0)
                            f.RepeatU = scales;
                        if (scalet != 0)
                            f.RepeatV = scalet;
                        f.TextureID = textures.Count > textureNum ? textures[textureNum] : Primitive.TextureEntry.WHITE_TEXTURE;
                        textureEntry.FaceTextures[face] = f;
                    }
                    pbs.TextureEntry = textureEntry.GetBytes();

                    AssetBase meshAsset = new AssetBase(UUID.Random(), assetName, AssetType.Mesh, m_service.AgentID)
                                              {Data = mesh_list[i].AsBinary()};
                    meshAsset.ID = m_assetService.Store(meshAsset);

                    if (meshFolder == null)
                    {
                        m_inventoryService.CreateUserInventory(m_service.AgentID, false);
                        meshFolder = m_inventoryService.GetFolderForType(m_service.AgentID, InventoryType.Mesh,
                                                                         AssetType.Mesh);
                    }

                    InventoryItemBase itemBase = new InventoryItemBase(UUID.Random(), m_service.AgentID)
                                                     {
                                                         AssetType = (sbyte) AssetType.Mesh,
                                                         AssetID = meshAsset.ID,
                                                         CreatorId = m_service.AgentID.ToString(),
                                                         Folder = meshFolder.ID,
                                                         InvType = (int) InventoryType.Texture,
                                                         Name = "(Mesh) - " + assetName,
                                                         CurrentPermissions = (uint) PermissionMask.All,
                                                         BasePermissions = (uint) PermissionMask.All,
                                                         EveryOnePermissions = everyone_mask,
                                                         GroupPermissions = group_mask,
                                                         NextPermissions = next_owner_mask
                                                     };
                    //Bad... but whatever
                    m_inventoryService.AddItem(itemBase);

                    pbs.SculptEntry = true;
                    pbs.SculptTexture = meshAsset.ID;
                    pbs.SculptType = (byte) SculptType.Mesh;
                    pbs.SculptData = meshAsset.Data;

                    Vector3 position = inner_instance_list["position"].AsVector3();
                    Vector3 scale = inner_instance_list["scale"].AsVector3();
                    Quaternion rotation = inner_instance_list["rotation"].AsQuaternion();

                    int physicsShapeType = inner_instance_list["physics_shape_type"].AsInteger();
                    int material = inner_instance_list["material"].AsInteger();
                    int mesh = inner_instance_list["mesh"].AsInteger();

                    UUID owner_id = m_service.AgentID;

                    IScene fakeScene = new Scene();
                    fakeScene.AddModuleInterfaces(m_service.Registry.GetInterfaces());

                    SceneObjectPart prim = new SceneObjectPart(owner_id, pbs, position, Quaternion.Identity,
                                                               Vector3.Zero, assetName, fakeScene)
                                               {Scale = scale, AbsolutePosition = position};

                    rotations.Add(rotation);
                    positions.Add(position);
                    prim.UUID = UUID.Random();
                    prim.CreatorID = owner_id;
                    prim.OwnerID = owner_id;
                    prim.GroupID = UUID.Zero;
                    prim.LastOwnerID = prim.OwnerID;
                    prim.CreationDate = Util.UnixTimeSinceEpoch();
                    prim.Name = assetName;
                    prim.Description = "";
                    prim.PhysicsType = (byte) physicsShapeType;

                    prim.BaseMask = (uint) PermissionMask.All;
                    prim.EveryoneMask = everyone_mask;
                    prim.NextOwnerMask = next_owner_mask;
                    prim.GroupMask = group_mask;
                    prim.OwnerMask = (uint) PermissionMask.All;

                    if (grp == null)
                        grp = new SceneObjectGroup(prim, fakeScene);
                    else
                        grp.AddChild(prim, i + 1);
                    grp.RootPart.IsAttachment = false;
                }
                if (grp.ChildrenList.Count > 1) //Fix first link #
                    grp.RootPart.LinkNum++;

                Vector3 rootPos = positions[0];
                grp.SetAbsolutePosition(false, rootPos);
                for (int i = 0; i < positions.Count; i++)
                {
                    Vector3 offset = positions[i] - rootPos;
                    grp.ChildrenList[i].SetOffsetPosition(offset);
                    Vector3 abs = grp.ChildrenList[i].AbsolutePosition;
                    Vector3 currentPos = positions[i];
                }
                //grp.Rotation = rotations[0];
                for (int i = 0; i < rotations.Count; i++)
                {
                    if (i != 0)
                        grp.ChildrenList[i].SetRotationOffset(false, rotations[i], false);
                }
                grp.UpdateGroupRotationR(rotations[0]);
                data = Encoding.ASCII.GetBytes(grp.ToXml2());
            }
            AssetBase asset = new AssetBase(assetID, assetName, (AssetType) assType, m_service.AgentID) {Data = data};
            asset.ID = m_assetService.Store(asset);
            assetID = asset.ID;

            InventoryItemBase item = new InventoryItemBase
                                         {
                                             Owner = m_service.AgentID,
                                             CreatorId = m_service.AgentID.ToString(),
                                             ID = inventoryItem,
                                             AssetID = asset.ID,
                                             Description = assetDescription,
                                             Name = assetName,
                                             AssetType = assType,
                                             InvType = inType,
                                             Folder = parentFolder,
                                             CurrentPermissions = (uint) PermissionMask.All,
                                             BasePermissions = (uint) PermissionMask.All,
                                             EveryOnePermissions = everyone_mask,
                                             NextPermissions = next_owner_mask,
                                             GroupPermissions = group_mask,
                                             CreationDate = Util.UnixTimeSinceEpoch()
                                         };

            m_inventoryService.AddItem(item);

            return assetID;
        }
Пример #20
0
 public UUID Store(AssetBase asset)
 {
     UUID retVal = m_localService.Store(asset);
     return retVal;
 }
Пример #21
0
 /*protected override void FixAssetID (ref AssetBase asset)
 {
     if (asset == null || asset.Metadata.URL != "")//Don't reappend
         return;
     asset.URL = MainServer.Instance.FullHostName + ":" + MainServer.Instance.Port + "/assets/" + asset.ID;
     //asset.ID = MainServer.Instance.FullHostName + ":" + MainServer.Instance.Port + "/assets/" + asset.ID;
 }*/
 protected void AdjustIdentifiers(AssetBase meta)
 {
     /*if (meta.CreatorID != null && meta.CreatorID != UUID.Zero)
     {
         UserAccount creator = m_UserAccountService.GetUserAccount (UUID.Zero, uuid);
         if (creator != null)
             meta.CreatorID = m_ProfileServiceURL + "/" + meta.CreatorID + ";" + creator.FirstName + " " + creator.LastName;
     }*/
 }
Пример #22
0
        /// <summary>
        ///   Cache asset.
        /// </summary>
        /// <param name = "asset">
        ///   The asset that is being cached.
        /// </param>
        public void Cache(AssetBase asset)
        {
            if (asset != null)
            {
//                MainConsole.Instance.DebugFormat("[CENOME ASSET CACHE]: Caching asset {0}", asset.IDString);

                long size = asset.Data != null ? asset.Data.Length : 1;
                m_cache.Set(asset.IDString, asset, size);
                m_cachedCount++;
            }
        }
Пример #23
0
        private void SaveFileCacheForAsset(UUID AssetId, OpenJPEG.J2KLayerInfo[] Layers)
        {
            if (m_useCache)
                m_decodedCache.AddOrUpdate(AssetId, Layers, TimeSpan.FromMinutes(10));

            if (m_cache != null)
            {
                string assetID = "j2kCache_" + AssetId.ToString();

                AssetBase layerDecodeAsset = new AssetBase(assetID, assetID, AssetType.Notecard,
                                                           UUID.Zero)
                                                 {Flags = AssetFlags.Local | AssetFlags.Temporary};

                #region Serialize Layer Data

                StringBuilder stringResult = new StringBuilder();
                string strEnd = "\n";
                for (int i = 0; i < Layers.Length; i++)
                {
                    if (i == Layers.Length - 1)
                        strEnd = String.Empty;

                    stringResult.AppendFormat("{0}|{1}|{2}{3}", Layers[i].Start, Layers[i].End,
                                              Layers[i].End - Layers[i].Start, strEnd);
                }

                layerDecodeAsset.Data = Util.UTF8.GetBytes(stringResult.ToString());

                #endregion Serialize Layer Data

                m_cache.Cache(layerDecodeAsset);
            }
        }
Пример #24
0
        public virtual UUID Store(AssetBase asset)
        {
            object remoteValue = DoRemote(asset);
            if (remoteValue != null || m_doRemoteOnly)
            {
                if (remoteValue == null)
                    return UUID.Zero;
                asset.ID = (UUID)remoteValue;
            }
            else
                asset.ID = m_database.Store(asset);
            IImprovedAssetCache cache = m_registry.RequestModuleInterface<IImprovedAssetCache>();
            if (doDatabaseCaching && cache != null && asset != null && asset.Data != null && asset.Data.Length != 0)
            {
                cache.Expire(asset.ID.ToString());
                cache.Cache(asset.ID.ToString(), asset);
            }

            return asset != null ? asset.ID : UUID.Zero;
        }
Пример #25
0
        /// <summary>
        /// Load an asset
        /// </summary>
        /// <param name="assetPath"></param>
        /// <param name="data"></param>
        /// <returns>true if asset was successfully loaded, false otherwise</returns>
        private bool LoadAsset(string assetPath, byte[] data)
        {
            // Right now we're nastily obtaining the UUID from the filename
            string filename = assetPath.Remove(0, ArchiveConstants.ASSETS_PATH.Length);
            int i = filename.LastIndexOf(ArchiveConstants.ASSET_EXTENSION_SEPARATOR);

            if (i == -1)
            {
                MainConsole.Instance.ErrorFormat(
                    "[ARCHIVER]: Could not find extension information in asset path {0} since it's missing the separator {1}.  Skipping",
                    assetPath, ArchiveConstants.ASSET_EXTENSION_SEPARATOR);

                return false;
            }

            string extension = filename.Substring(i);
            string uuid = filename.Remove(filename.Length - extension.Length);

            if (ArchiveConstants.EXTENSION_TO_ASSET_TYPE.ContainsKey(extension))
            {
                AssetType assetType = ArchiveConstants.EXTENSION_TO_ASSET_TYPE[extension];

                if (assetType == AssetType.Unknown)
                    MainConsole.Instance.WarnFormat("[ARCHIVER]: Importing {0} byte asset {1} with unknown type", data.Length, uuid);

                //MainConsole.Instance.DebugFormat("[ARCHIVER]: Importing asset {0}, type {1}", uuid, assetType);
                AssetBase asset = new AssetBase(UUID.Parse(uuid), String.Empty, assetType, UUID.Zero)
                                      {Data = data};

                // We're relying on the asset service to do the sensible thing and not store the asset if it already
                // exists.
                if (m_useAsync)
                    lock (AssetsToAdd)
                        AssetsToAdd.Add(asset);
                else
                    asset.ID = m_scene.AssetService.Store(asset);

                /**
                 * Create layers on decode for image assets.  This is likely to significantly increase the time to load archives so
                 * it might be best done when dearchive takes place on a separate thread
                if (asset.Type=AssetType.Texture)
                {
                    IJ2KDecoder cacheLayerDecode = scene.RequestModuleInterface<IJ2KDecoder>();
                    if (cacheLayerDecode != null)
                        cacheLayerDecode.syncdecode(asset.FullID, asset.Data);
                }
                */

                return true;
            }
            MainConsole.Instance.ErrorFormat(
                "[ARCHIVER]: Tried to dearchive data with path {0} with an unknown type extension {1}",
                assetPath, extension);

            return false;
        }
Пример #26
0
        public void CreateMapTileAsync(object worthless)
        {
            IMapImageGenerator terrain = m_scene.RequestModuleInterface<IMapImageGenerator>();

            if (terrain == null)
                return;

            bool changed = false;
            byte[] terraindata, mapdata;
            terrain.CreateMapTile(out terraindata, out mapdata);
            if (terraindata != null)
            {
                UUID newID = UUID.Zero;
                if (m_scene.RegionInfo.RegionSettings.TerrainMapImageID != UUID.Zero)
                {
                    m_scene.AssetService.UpdateContent(m_scene.RegionInfo.RegionSettings.TerrainMapImageID, terraindata, out newID);
                    m_scene.RegionInfo.RegionSettings.TerrainMapImageID = newID;
                    changed = true;
                }

                if (m_scene.RegionInfo.RegionSettings.TerrainMapImageID == UUID.Zero)
                {
                    AssetBase Terrainasset = new AssetBase(
                        UUID.Random(),
                        "terrainMapImage_" + m_scene.RegionInfo.RegionID.ToString(),
                        AssetType.Simstate,
                        m_scene.RegionInfo.RegionID)
                    {
                        Data = terraindata,
                        Description = m_scene.RegionInfo.RegionName,
                        Flags = AssetFlags.Deletable | AssetFlags.Rewritable | AssetFlags.Maptile
                    };
                    newID = m_scene.AssetService.Store(Terrainasset);
                }

                if (m_scene.RegionInfo.RegionSettings.TerrainMapImageID != newID)
                {
                    m_scene.RegionInfo.RegionSettings.TerrainMapImageID = newID;
                    changed = true;
                }
            }

            if (mapdata != null)
            {
                UUID newID = UUID.Zero;
                if (m_scene.RegionInfo.RegionSettings.TerrainImageID != UUID.Zero)
                {
                    m_scene.AssetService.UpdateContent(m_scene.RegionInfo.RegionSettings.TerrainImageID, mapdata, out newID);
                    m_scene.RegionInfo.RegionSettings.TerrainImageID = newID;
                    changed = true;
                }

                if (m_scene.RegionInfo.RegionSettings.TerrainImageID == UUID.Zero)
                {
                    AssetBase Mapasset = new AssetBase(
                        UUID.Random(),
                        "terrainImage_" + m_scene.RegionInfo.RegionID.ToString(),
                        AssetType.Simstate,
                        m_scene.RegionInfo.RegionID)
                    {
                        Data = mapdata,
                        Description = m_scene.RegionInfo.RegionName,
                        Flags = AssetFlags.Deletable | AssetFlags.Rewritable | AssetFlags.Maptile
                    };
                    newID = m_scene.AssetService.Store(Mapasset);
                }

                if (m_scene.RegionInfo.RegionSettings.TerrainImageID != newID)
                {
                    m_scene.RegionInfo.RegionSettings.TerrainImageID = newID;
                    changed = true;
                }
            }

            if (changed)//Make sure to update the db with the new settings
                m_scene.RegionInfo.RegionSettings.Save();

            //Update the grid map
            IGridRegisterModule gridRegModule = m_scene.RequestModuleInterface<IGridRegisterModule>();
            if (gridRegModule != null)
                gridRegModule.UpdateGridRegion(m_scene);
        }
Пример #27
0
            /// <summary>
            ///   Called once new texture data has been received for this updater.
            /// </summary>
            public void DataReceived(byte[] data, IScene scene)
            {
                ISceneChildEntity part = scene.GetSceneObjectPart(PrimID);

                if (part == null || data == null || data.Length <= 1)
                {
                    string msg =
                        String.Format("DynamicTextureModule: Error preparing image using URL {0}", Url);
                    IChatModule chatModule = scene.RequestModuleInterface<IChatModule>();
                    if (chatModule != null)
                        chatModule.SimChat(msg, ChatTypeEnum.Say, 0,
                                           part.ParentEntity.AbsolutePosition, part.Name, part.UUID, false, scene);
                    return;
                }

                byte[] assetData = null;
                AssetBase oldAsset = null;

                if (BlendWithOldTexture)
                {
                    Primitive.TextureEntryFace defaultFace = part.Shape.Textures.DefaultTexture;
                    if (defaultFace != null)
                    {
                        oldAsset = scene.AssetService.Get(defaultFace.TextureID.ToString());

                        if (oldAsset != null)
                            assetData = BlendTextures(data, oldAsset.Data, SetNewFrontAlpha, FrontAlpha, scene);
                    }
                }

                if (assetData == null)
                {
                    assetData = new byte[data.Length];
                    Array.Copy(data, assetData, data.Length);
                }

                AssetBase asset = null;

                if (LastAssetID != UUID.Zero)
                {
                    asset = scene.AssetService.Get(LastAssetID.ToString());
                    asset.Description = String.Format("URL image : {0}", Url);
                    asset.Data = assetData;
                    if ((asset.Flags & AssetFlags.Local) == AssetFlags.Local)
                    {
                        asset.Flags = asset.Flags & ~AssetFlags.Local;
                    }
                    if (((asset.Flags & AssetFlags.Temperary) == AssetFlags.Temperary) != ((Disp & DISP_TEMP) != 0))
                    {
                        if ((Disp & DISP_TEMP) != 0) asset.Flags |= AssetFlags.Temperary;
                        else asset.Flags = asset.Flags & ~AssetFlags.Temperary;
                    }
                    asset.ID = scene.AssetService.Store(asset);
                }
                else
                {
                    // Create a new asset for user
                    asset = new AssetBase(UUID.Random(), "DynamicImage" + Util.RandomClass.Next(1, 10000),
                                          AssetType.Texture,
                                          scene.RegionInfo.RegionID)
                                {Data = assetData, Description = String.Format("URL image : {0}", Url)};
                    if ((Disp & DISP_TEMP) != 0) asset.Flags = AssetFlags.Temperary;
                    asset.ID = scene.AssetService.Store(asset);
                }

                IJ2KDecoder cacheLayerDecode = scene.RequestModuleInterface<IJ2KDecoder>();
                if (cacheLayerDecode != null)
                {
                    cacheLayerDecode.Decode(asset.ID, asset.Data);
                    cacheLayerDecode = null;
                    LastAssetID = asset.ID;
                }

                UUID oldID = UUID.Zero;

                lock (part)
                {
                    // mostly keep the values from before
                    Primitive.TextureEntry tmptex = part.Shape.Textures;

                    // remove the old asset from the cache
                    oldID = tmptex.DefaultTexture.TextureID;

                    if (Face == ALL_SIDES)
                    {
                        tmptex.DefaultTexture.TextureID = asset.ID;
                    }
                    else
                    {
                        try
                        {
                            Primitive.TextureEntryFace texface = tmptex.CreateFace((uint) Face);
                            texface.TextureID = asset.ID;
                            tmptex.FaceTextures[Face] = texface;
                        }
                        catch (Exception)
                        {
                            tmptex.DefaultTexture.TextureID = asset.ID;
                        }
                    }

                    // I'm pretty sure we always want to force this to true
                    // I'm pretty sure noone whats to set fullbright true if it wasn't true before.
                    // tmptex.DefaultTexture.Fullbright = true;

                    part.UpdateTexture(tmptex);
                }

                if (oldID != UUID.Zero && ((Disp & DISP_EXPIRE) != 0))
                {
                    if (oldAsset == null) oldAsset = scene.AssetService.Get(oldID.ToString());
                    if (oldAsset != null)
                    {
                        if ((oldAsset.Flags & AssetFlags.Temperary) == AssetFlags.Temperary)
                        {
                            scene.AssetService.Delete(oldID);
                        }
                    }
                }
            }
Пример #28
0
 public override UUID Store(AssetBase asset)
 {
     return base.Store(asset);
 }
Пример #29
0
        /// <summary>
        /// Update the attachment asset for the new sog details if they have changed.
        /// </summary>
        /// 
        /// This is essential for preserving attachment attributes such as permission.  Unlike normal scene objects,
        /// these details are not stored on the region.
        /// 
        /// <param name="remoteClient"></param>
        /// <param name="grp"></param>
        /// <param name="itemID"></param>
        /// <param name="agentID"></param>
        protected void UpdateKnownItem (IClientAPI remoteClient, ISceneEntity grp, UUID itemID, UUID agentID)
        {
            if (grp != null)
            {
                if (!grp.HasGroupChanged)
                {
                    //MainConsole.Instance.WarnFormat("[ATTACHMENTS MODULE]: Save request for {0} which is unchanged", grp.UUID);
                    return;
                }

                //let things like state saves and another async things be performed before we serialize the object
                grp.BackupPreparation();

                MainConsole.Instance.InfoFormat(
                    "[ATTACHMENTS MODULE]: Updating asset for attachment {0}, attachpoint {1}",
                    grp.UUID, grp.GetAttachmentPoint());

                string sceneObjectXml = SceneObjectSerializer.ToOriginalXmlFormat((SceneObjectGroup)grp);

                InventoryItemBase item = new InventoryItemBase(itemID, remoteClient.AgentId);
                item = m_scene.InventoryService.GetItem(item);

                if (item != null)
                {
                    AssetBase asset = new AssetBase(UUID.Random(), grp.Name,
                                                    AssetType.Object, remoteClient.AgentId)
                                          {
                                              Description = grp.RootChild.Description,
                                              Data = Utils.StringToBytes(sceneObjectXml)
                                          };
                    asset.ID = m_scene.AssetService.Store(asset);

                    if (item.Folder == UUID.Zero)
                    {
                        InventoryFolderBase folder = m_scene.InventoryService.GetFolderForType (remoteClient.AgentId, InventoryType.Unknown, AssetType.Object);
                        if (folder == null)
                            return;//Probably a non user (bot)
                        item.Folder = folder.ID;
                    }

                    item.AssetID = asset.ID;
                    item.Description = asset.Description;
                    item.Name = asset.Name;
                    item.AssetType = asset.Type;
                    item.InvType = (int)InventoryType.Object;

                    m_scene.InventoryService.UpdateItem(item);

                    // this gets called when the agent logs off!
                    remoteClient.SendInventoryItemCreateUpdate(item, 0);
                }
                else
                {
                    MainConsole.Instance.Warn("[AttachmentModule]: Could not find inventory item for attachment to update!");
                }
            }
        }
        public UUID GetMapImage(UUID regionID, string imageURL, string storagePath)
        {
            if (m_AssetService == null)
            {
                MainConsole.Instance.DebugFormat ("[GATEKEEPER SERVICE CONNECTOR]: No AssetService defined. Map tile not retrieved.");
                return m_HGMapImage;
            }

            UUID mapTile = m_HGMapImage;
            string filename = string.Empty;
            Bitmap bitmap = null;
            try
            {
                WebClient c = new WebClient ();
                string name = regionID.ToString ();
                filename = Path.Combine (storagePath, name + ".jpg");
                MainConsole.Instance.DebugFormat ("[GATEKEEPER SERVICE CONNECTOR]: Map image at {0}, cached at {1}", imageURL, filename);
                if (!File.Exists (filename))
                {
                    MainConsole.Instance.DebugFormat ("[GATEKEEPER SERVICE CONNECTOR]: downloading...");
                    c.DownloadFile (imageURL, filename);
                }
                else
                    MainConsole.Instance.DebugFormat ("[GATEKEEPER SERVICE CONNECTOR]: using cached image");

                bitmap = new Bitmap (filename);
                //MainConsole.Instance.Debug("Size: " + m.PhysicalDimension.Height + "-" + m.PhysicalDimension.Width);
                byte[] imageData = OpenJPEG.EncodeFromImage (bitmap, true);
                AssetBase ass = new AssetBase (UUID.Random (), "region " + name, AssetType.Texture, regionID);

                // !!! for now
                //info.RegionSettings.TerrainImageID = ass.FullID;

                ass.Data = imageData;

                mapTile = ass.ID;

                // finally
                mapTile = m_AssetService.Store(ass);

            }
            catch // LEGIT: Catching problems caused by OpenJPEG p/invoke
            {
                MainConsole.Instance.Info ("[GATEKEEPER SERVICE CONNECTOR]: Failed getting/storing map image, because it is probably already in the cache");
            }
            return mapTile;
        }
Пример #31
0
 private void WriteAsset(string id, AssetBase asset, TarArchiveWriter writer)
 {
     if (asset != null)
         writer.WriteFile("assets/" + asset.ID, OSDParser.SerializeJsonString(asset.ToOSD()));
     else
         MainConsole.Instance.WarnFormat("[FileBasedSimulationData]: Could not find asset {0} to save.", id);
 }
        /// <summary>
        ///   Update what the avatar is wearing using an item from their inventory.
        /// </summary>
        /// <param name = "client"></param>
        /// <param name = "e"></param>
        public void AvatarIsWearing(IClientAPI client, AvatarWearingArgs e)
        {
            IScenePresence sp = m_scene.GetScenePresence(client.AgentId);
            if (sp == null)
            {
                MainConsole.Instance.WarnFormat("[AvatarFactory]: AvatarIsWearing unable to find presence for {0}", client.AgentId);
                return;
            }

            MainConsole.Instance.DebugFormat("[AvatarFactory]: AvatarIsWearing called for {0}", client.AgentId);

            // operate on a copy of the appearance so we don't have to lock anything
            IAvatarAppearanceModule appearance = sp.RequestModuleInterface<IAvatarAppearanceModule>();
            AvatarAppearance avatAppearance = new AvatarAppearance(appearance.Appearance, false);

            IOpenRegionSettingsModule module = m_scene.RequestModuleInterface<IOpenRegionSettingsModule>();

            bool NeedsRebake = false;
            if (module != null && module.EnableTeenMode)
            {
                foreach (AvatarWearingArgs.Wearable wear in e.NowWearing)
                {
                    if (wear.Type == 10 & wear.ItemID == UUID.Zero && module.DefaultUnderpants != UUID.Zero)
                    {
                        NeedsRebake = true;
                        wear.ItemID = module.DefaultUnderpants;
                        InventoryItemBase item = new InventoryItemBase(UUID.Random())
                                                     {
                                                         InvType = (int) InventoryType.Wearable,
                                                         AssetType = (int) AssetType.Clothing,
                                                         Name = "Default Underpants",
                                                         Folder =
                                                             m_scene.InventoryService.GetFolderForType(client.AgentId,
                                                                                                       InventoryType.
                                                                                                           Wearable,
                                                                                                       AssetType.
                                                                                                           Clothing).ID,
                                                         Owner = client.AgentId,
                                                         CurrentPermissions = 0,
                                                         CreatorId = UUID.Zero.ToString(),
                                                         AssetID = module.DefaultUnderpants
                                                     };
                        //Locked
                        client.SendInventoryItemCreateUpdate(item, 0);
                    }
                    else if (wear.Type == 10 & wear.ItemID == UUID.Zero)
                    {
                        NeedsRebake = true;
                        InventoryItemBase item = new InventoryItemBase(UUID.Random())
                                                     {
                                                         InvType = (int) InventoryType.Wearable,
                                                         AssetType = (int) AssetType.Clothing,
                                                         Name = "Default Underpants",
                                                         Folder =
                                                             m_scene.InventoryService.GetFolderForType(client.AgentId,
                                                                                                       InventoryType.
                                                                                                           Wearable,
                                                                                                       AssetType.
                                                                                                           Clothing).ID,
                                                         Owner = client.AgentId,
                                                         CurrentPermissions = 0
                                                     };
                        //Locked
                        if (m_underPantsUUID == UUID.Zero)
                        {
                            m_underPantsUUID = UUID.Random();
                            AssetBase asset = new AssetBase(m_underPantsUUID, "Default Underpants", AssetType.Clothing,
                                                            UUID.Zero) {Data = Utils.StringToBytes(m_defaultUnderPants)};
                            asset.FillHash();
                            asset.ID = m_scene.AssetService.Store(asset);
                            m_underPantsUUID = asset.ID;
                        }
                        item.CreatorId = UUID.Zero.ToString();
                        item.AssetID = m_underPantsUUID;
                        m_scene.InventoryService.AddItem(item);
                        client.SendInventoryItemCreateUpdate(item, 0);
                        wear.ItemID = item.ID;
                    }
                    if (wear.Type == 11 && wear.ItemID == UUID.Zero && module.DefaultUndershirt != UUID.Zero)
                    {
                        NeedsRebake = true;
                        wear.ItemID = module.DefaultUndershirt;
                        InventoryItemBase item = new InventoryItemBase(UUID.Random())
                                                     {
                                                         InvType = (int) InventoryType.Wearable,
                                                         AssetType = (int) AssetType.Clothing,
                                                         Name = "Default Undershirt",
                                                         Folder =
                                                             m_scene.InventoryService.GetFolderForType(client.AgentId,
                                                                                                       InventoryType.
                                                                                                           Wearable,
                                                                                                       AssetType.
                                                                                                           Clothing).ID,
                                                         Owner = client.AgentId,
                                                         CurrentPermissions = 0,
                                                         CreatorId = UUID.Zero.ToString(),
                                                         AssetID = module.DefaultUndershirt
                                                     };
                        //Locked
                        client.SendInventoryItemCreateUpdate(item, 0);
                    }
                    else if (wear.Type == 11 & wear.ItemID == UUID.Zero)
                    {
                        NeedsRebake = true;
                        InventoryItemBase item = new InventoryItemBase(UUID.Random())
                                                     {
                                                         InvType = (int) InventoryType.Wearable,
                                                         AssetType = (int) AssetType.Clothing,
                                                         Name = "Default Undershirt",
                                                         Folder =
                                                             m_scene.InventoryService.GetFolderForType(client.AgentId,
                                                                                                       InventoryType.
                                                                                                           Wearable,
                                                                                                       AssetType.
                                                                                                           Clothing).ID,
                                                         Owner = client.AgentId,
                                                         CurrentPermissions = 0
                                                     };
                        //Locked
                        if (m_underShirtUUID == UUID.Zero)
                        {
                            m_underShirtUUID = UUID.Random();
                            AssetBase asset = new AssetBase(m_underShirtUUID, "Default Undershirt", AssetType.Clothing,
                                                            UUID.Zero) {Data = Utils.StringToBytes(m_defaultUnderShirt)};
                            asset.FillHash();
                            asset.ID = m_scene.AssetService.Store(asset);
                            m_underShirtUUID = asset.ID;
                        }
                        item.CreatorId = UUID.Zero.ToString();
                        item.AssetID = m_underShirtUUID;
                        m_scene.InventoryService.AddItem(item);
                        client.SendInventoryItemCreateUpdate(item, 0);
                        wear.ItemID = item.ID;
                    }
                }
            }

#if (!ISWIN)
            foreach (AvatarWearingArgs.Wearable wear in e.NowWearing)
            {
                if (wear.Type < AvatarWearable.MAX_WEARABLES)
                {
                    /*if (incomingLinks.ContainsKey (wear.ItemID))
                    {
                        wear.ItemID = incomingLinks[wear.ItemID];
                    }*/
                    avatAppearance.Wearables[wear.Type].Add(wear.ItemID, UUID.Zero);
                }
            }
#else
            foreach (AvatarWearingArgs.Wearable wear in e.NowWearing.Where(wear => wear.Type < AvatarWearable.MAX_WEARABLES))
            {
                avatAppearance.Wearables[wear.Type].Add(wear.ItemID, UUID.Zero);
            }
#endif

            avatAppearance.GetAssetsFrom(appearance.Appearance);

            // This could take awhile since it needs to pull inventory
            SetAppearanceAssets(sp.UUID, e.NowWearing, appearance.Appearance, ref avatAppearance);

            // could get fancier with the locks here, but in the spirit of "last write wins"
            // this should work correctly, also, we don't need to send the appearance here
            // since the "iswearing" will trigger a new set of visual param and baked texture changes
            // when those complete, the new appearance will be sent
            appearance.Appearance = avatAppearance;
            if (NeedsRebake)
            {
                //Tell the client about the new things it is wearing
                sp.ControllingClient.SendWearables(appearance.Appearance.Wearables, appearance.Appearance.Serial);
                //Then forcefully tell it to rebake
#if (!ISWIN)
                foreach (Primitive.TextureEntryFace t in appearance.Appearance.Texture.FaceTextures)
                {
                    Primitive.TextureEntryFace face = (t);
                    if (face != null)
                    {
                        sp.ControllingClient.SendRebakeAvatarTextures(face.TextureID);
                    }
                }
#else
                foreach (Primitive.TextureEntryFace face in appearance.Appearance.Texture.FaceTextures.Select(t => (t)).Where(face => face != null))
                {
                    sp.ControllingClient.SendRebakeAvatarTextures(face.TextureID);
                }
#endif
            }
            QueueAppearanceSave(sp.UUID);
            //Send the wearables HERE so that the client knows what it is wearing
            //sp.ControllingClient.SendWearables(sp.Appearance.Wearables, sp.Appearance.Serial);
            //Do not save or send the appearance! The client loops back and sends a bunch of SetAppearance
            //  (handled above) and that takes care of it
        }
Пример #33
0
        /// <summary>
        /// This method is called if a given model avatar name can not be found. If the external
        /// file has already been loaded once, then control returns immediately. If not, then it
        /// looks for a default appearance file. This file contains XML definitions of zero or more named
        /// avatars, each avatar can specify zero or more "outfits". Each outfit is a collection
        /// of items that together, define a particular ensemble for the avatar. Each avatar should
        /// indicate which outfit is the default, and this outfit will be automatically worn. The
        /// other outfits are provided to allow "real" avatars a way to easily change their outfits.
        /// </summary>

        private bool CreateDefaultAvatars()
        {
            // Only load once
            if (m_defaultAvatarsLoaded)
            {
                return false;
            }

            MainConsole.Instance.DebugFormat("[RADMIN] Creating default avatar entries");

            m_defaultAvatarsLoaded = true;

            // Load processing starts here...

            try
            {
                string defaultAppearanceFileName = null;

                //m_config may be null if RemoteAdmin configuration secition is missing or disabled in Aurora.ini
                if (m_config != null)
                {
                    defaultAppearanceFileName = m_config.GetString("default_appearance", "default_appearance.xml");
                }

                if (File.Exists(defaultAppearanceFileName))
                {
                    XmlDocument doc = new XmlDocument();
                    string name     = "*unknown*";
                    string email    = "anon@anon";
                    uint   regionXLocation     = 1000;
                    uint   regionYLocation     = 1000;
                    string password   = UUID.Random().ToString(); // No requirement to sign-in.
                    UUID ID = UUID.Zero;
                    XmlNode perms = null;

                    IScene scene = manager.CurrentOrFirstScene;
                    IInventoryService inventoryService = scene.InventoryService;
                    IAssetService assetService = scene.AssetService;

                    doc.LoadXml(File.ReadAllText(defaultAppearanceFileName));

                    // Load up any included assets. Duplicates will be ignored
                    XmlNodeList assets = doc.GetElementsByTagName("RequiredAsset");
                    foreach (XmlNode assetNode in assets)
                    {
                        AssetBase asset = new AssetBase(UUID.Random(), GetStringAttribute(assetNode, "name", ""),
                                                        (AssetType)
                                                        SByte.Parse(GetStringAttribute(assetNode, "type", "")),
                                                        UUID.Zero)
                                              {
                                                  Description = GetStringAttribute(assetNode, "desc", ""),
                                                  Data = Convert.FromBase64String(assetNode.InnerText),
                                                  Flags = ((Boolean.Parse(GetStringAttribute(assetNode, "local", "")))
                                                               ? AssetFlags.Local
                                                               : AssetFlags.Normal) |
                                                          ((Boolean.Parse(GetStringAttribute(assetNode, "temporary", "")))
                                                               ? AssetFlags.Temperary
                                                               : AssetFlags.Normal)
                                              };

                        asset.FillHash();
                        asset.ID = assetService.Store(asset);
                    }

                    XmlNodeList avatars = doc.GetElementsByTagName("Avatar");

                    // The document may contain multiple avatars

                    foreach (XmlElement avatar in avatars)
                    {
                        MainConsole.Instance.DebugFormat("[RADMIN] Loading appearance for {0}, gender = {1}",
                            GetStringAttribute(avatar,"name","?"), GetStringAttribute(avatar,"gender","?"));

                        // Create the user identified by the avatar entry

                        bool include = false;
                        try
                        {
                            // Only the name value is mandatory
                            name   = GetStringAttribute(avatar,"name",name);
                            email  = GetStringAttribute(avatar,"email",email);
                            regionXLocation   = GetUnsignedAttribute(avatar,"regx",regionXLocation);
                            regionYLocation   = GetUnsignedAttribute(avatar,"regy",regionYLocation);
                            password = GetStringAttribute(avatar,"password",password);

                            string[] names = name.Split();
                            UUID scopeID = scene.RegionInfo.ScopeID;
                            UserAccount account = scene.UserAccountService.GetUserAccount(scopeID, names[0], names[1]);
                            if (null == account)
                            {
                                account = CreateUser(scopeID, names[0], names[1], password, email);
                                if (null == account)
                                {
                                    MainConsole.Instance.ErrorFormat("[RADMIN] Avatar {0} {1} was not created", names[0], names[1]);
                                    return false;
                                }
                            }

                            // Set home position

                            GridRegion home = scene.GridService.GetRegionByPosition(scopeID, 
                                (int)(regionXLocation * Constants.RegionSize), (int)(regionYLocation * Constants.RegionSize));
                            if (null == home) {
                                MainConsole.Instance.WarnFormat("[RADMIN]: Unable to set home region for newly created user account {0} {1}", names[0], names[1]);
                            } else {
                                IAgentInfoService agentInfoService = scene.RequestModuleInterface<IAgentInfoService>();
                                agentInfoService.SetHomePosition(account.PrincipalID.ToString(), home.RegionID, new Vector3(128, 128, 0), new Vector3(0, 1, 0));
                                MainConsole.Instance.DebugFormat("[RADMIN]: Set home region {0} for updated user account {1} {2}", home.RegionID, names[0], names[1]);
                            }

                            ID = account.PrincipalID;

                            MainConsole.Instance.DebugFormat("[RADMIN] User {0}[{1}] created or retrieved", name, ID);
                            include = true;
                        }
                        catch (Exception e)
                        {
                            MainConsole.Instance.DebugFormat("[RADMIN] Error creating user {0} : {1}", name, e.Message);
                            include = false;
                        }

                        // OK, User has been created OK, now we can install the inventory.
                        // First retrieve the current inventory (the user may already exist)
                        // Note that althought he inventory is retrieved, the hierarchy has
                        // not been interpreted at all.

                        if (include)
                        {
                            // Setup for appearance processing
                            AvatarData avatarData = scene.AvatarService.GetAvatar(ID);
                            AvatarAppearance avatarAppearance = avatarData != null
                                                                    ? avatarData.ToAvatarAppearance(ID)
                                                                    : new AvatarAppearance();

                            AvatarWearable[] wearables = avatarAppearance.Wearables;
                            for (int i=0; i<wearables.Length; i++)
                            {
                                wearables[i] = new AvatarWearable();
                            }

                            try
                            {
                                // MainConsole.Instance.DebugFormat("[RADMIN] {0} folders, {1} items in inventory",
                                //   uic.folders.Count, uic.items.Count);

                                InventoryFolderBase clothingFolder = inventoryService.GetFolderForType (ID, InventoryType.Wearable, AssetType.Clothing);

                                // This should *never* be the case
                                if (clothingFolder == null || clothingFolder.Type != (short)AssetType.Clothing)
                                {
                                    clothingFolder = new InventoryFolderBase
                                                         {
                                                             ID = UUID.Random(),
                                                             Name = "Clothing",
                                                             Owner = ID,
                                                             Type = (short) AssetType.Clothing,
                                                             ParentID = inventoryService.GetRootFolder(ID).ID,
                                                             Version = 1
                                                         };
                                    inventoryService.AddFolder(clothingFolder);     // store base record
                                    MainConsole.Instance.ErrorFormat("[RADMIN] Created clothing folder for {0}/{1}", name, ID);
                                }

                                // OK, now we have an inventory for the user, read in the outfits from the
                                // default appearance XMl file.

                                XmlNodeList outfits = avatar.GetElementsByTagName("Ensemble");

                                foreach (XmlElement outfit in outfits)
                                {
                                    MainConsole.Instance.DebugFormat("[RADMIN] Loading outfit {0} for {1}",
                                        GetStringAttribute(outfit,"name","?"), GetStringAttribute(avatar,"name","?"));

                                    string outfitName = GetStringAttribute(outfit,"name","");
                                    bool select  = (GetStringAttribute(outfit,"default","no") == "yes");

                                    // If the folder already exists, re-use it. The defaults may
                                    // change over time. Augment only.

                                    List<InventoryFolderBase> folders = inventoryService.GetFolderContent(ID, clothingFolder.ID).Folders;
#if (!ISWIN)
                                    InventoryFolderBase extraFolder = null;
                                    foreach (InventoryFolderBase folder in folders)
                                    {
                                        if (folder.Name == outfitName)
                                        {
                                            extraFolder = folder;
                                            break;
                                        }
                                    }
#else
                                    InventoryFolderBase extraFolder = folders.FirstOrDefault(folder => folder.Name == outfitName);
#endif

                                    // Otherwise, we must create the folder.
                                    if (extraFolder == null)
                                    {
                                        MainConsole.Instance.DebugFormat("[RADMIN] Creating outfit folder {0} for {1}", outfitName, name);
                                        extraFolder = new InventoryFolderBase
                                                          {
                                                              ID = UUID.Random(),
                                                              Name = outfitName,
                                                              Owner = ID,
                                                              Type = (short) AssetType.Clothing,
                                                              Version = 1,
                                                              ParentID = clothingFolder.ID
                                                          };
                                        inventoryService.AddFolder(extraFolder);
                                        MainConsole.Instance.DebugFormat("[RADMIN] Adding outfile folder {0} to folder {1}", extraFolder.ID, clothingFolder.ID);
                                    }

                                    // Now get the pieces that make up the outfit
                                    XmlNodeList items = outfit.GetElementsByTagName("Item");

                                    foreach (XmlElement item in items)
                                    {
                                        UUID assetid = UUID.Zero;
                                        XmlNodeList children = item.ChildNodes;
                                        foreach (XmlNode child in children)
                                        {
                                            switch (child.Name)
                                            {
                                                case "Permissions" :
                                                    MainConsole.Instance.DebugFormat("[RADMIN] Permissions specified");
                                                    perms = child;
                                                    break;
                                                case "Asset" :
                                                    assetid = new UUID(child.InnerText);
                                                    break;
                                            }
                                        }

                                        InventoryItemBase inventoryItem = null;

                                        // Check if asset is in inventory already
                                        List<InventoryItemBase> inventoryItems = inventoryService.GetFolderContent(ID, extraFolder.ID).Items;

#if (!ISWIN)
                                        inventoryItem = null;
                                        foreach (InventoryItemBase listItem in inventoryItems)
                                        {
                                            if (listItem.AssetID == assetid)
                                            {
                                                inventoryItem = listItem;
                                                break;
                                            }
                                        }
#else
                                        inventoryItem = inventoryItems.FirstOrDefault(listItem => listItem.AssetID == assetid);
#endif

                                        // Create inventory item
                                        if (inventoryItem == null)
                                        {
                                            inventoryItem = new InventoryItemBase(UUID.Random(), ID)
                                                                {
                                                                    Name = GetStringAttribute(item, "name", ""),
                                                                    Description = GetStringAttribute(item, "desc", ""),
                                                                    InvType = GetIntegerAttribute(item, "invtype", -1),
                                                                    CreatorId =
                                                                        GetStringAttribute(item, "creatorid", ""),
                                                                    CreatorIdAsUuid =
                                                                        (UUID)
                                                                        GetStringAttribute(item, "creatoruuid", ""),
                                                                    NextPermissions =
                                                                        GetUnsignedAttribute(perms, "next", 0x7fffffff),
                                                                    CurrentPermissions =
                                                                        GetUnsignedAttribute(perms, "current",
                                                                                             0x7fffffff),
                                                                    BasePermissions =
                                                                        GetUnsignedAttribute(perms, "base", 0x7fffffff),
                                                                    EveryOnePermissions =
                                                                        GetUnsignedAttribute(perms, "everyone",
                                                                                             0x7fffffff),
                                                                    GroupPermissions =
                                                                        GetUnsignedAttribute(perms, "group", 0x7fffffff),
                                                                    AssetType =
                                                                        GetIntegerAttribute(item, "assettype", -1),
                                                                    AssetID = assetid,
                                                                    GroupID =
                                                                        (UUID) GetStringAttribute(item, "groupid", ""),
                                                                    GroupOwned =
                                                                        (GetStringAttribute(item, "groupowned", "false") ==
                                                                         "true"),
                                                                    SalePrice =
                                                                        GetIntegerAttribute(item, "saleprice", 0),
                                                                    SaleType =
                                                                        (byte) GetIntegerAttribute(item, "saletype", 0),
                                                                    Flags = GetUnsignedAttribute(item, "flags", 0),
                                                                    CreationDate =
                                                                        GetIntegerAttribute(item, "creationdate",
                                                                                            Util.UnixTimeSinceEpoch()),
                                                                    Folder = extraFolder.ID
                                                                };
                                            // associated asset
                                            // Parent folder

                                            ILLClientInventory inventoryModule = manager.CurrentOrFirstScene.RequestModuleInterface<ILLClientInventory>();
                                            if (inventoryModule != null)
                                                inventoryModule.AddInventoryItem(inventoryItem);
                                            MainConsole.Instance.DebugFormat("[RADMIN] Added item {0} to folder {1}", inventoryItem.ID, extraFolder.ID);
                                        }

                                        // Attach item, if attachpoint is specified
                                        int attachpoint = GetIntegerAttribute(item,"attachpoint",0);
                                        if (attachpoint != 0)
                                        {
                                            avatarAppearance.SetAttachment(attachpoint, inventoryItem.ID, inventoryItem.AssetID);
                                            MainConsole.Instance.DebugFormat("[RADMIN] Attached {0}", inventoryItem.ID);
                                        }

                                        // Record whether or not the item is to be initially worn
                                        try
                                        {
                                            if (select && (GetStringAttribute(item, "wear", "false") == "true"))
                                            {
                                                avatarAppearance.Wearables[inventoryItem.Flags].Wear(inventoryItem.ID, inventoryItem.AssetID);
                                            }
                                        }
                                        catch (Exception e)
                                        {
                                            MainConsole.Instance.WarnFormat("[RADMIN] Error wearing item {0} : {1}", inventoryItem.ID, e.Message);
                                        }
                                    } // foreach item in outfit
                                    MainConsole.Instance.DebugFormat("[RADMIN] Outfit {0} load completed", outfitName);
                                } // foreach outfit
                                MainConsole.Instance.DebugFormat("[RADMIN] Inventory update complete for {0}", name);
                                AvatarData avatarData2 = new AvatarData(avatarAppearance);
                                scene.AvatarService.SetAvatar(ID, avatarData2);
                            }
                            catch (Exception e)
                            {
                                MainConsole.Instance.WarnFormat("[RADMIN] Inventory processing incomplete for user {0} : {1}",
                                    name, e.Message);
                            }
                        } // End of include
                    }
                    MainConsole.Instance.DebugFormat("[RADMIN] Default avatar loading complete");
                }
                else
                {
                    MainConsole.Instance.DebugFormat("[RADMIN] No default avatar information available");
                    return false;
                }
            }
            catch (Exception e)
            {
                MainConsole.Instance.WarnFormat("[RADMIN] Exception whilst loading default avatars ; {0}", e.Message);
                return false;
            }

            return true;
        }
Пример #34
0
        /// <summary>
        /// Rez a script into a prim's inventory, either ex nihilo or from an existing avatar inventory
        /// </summary>
        /// <param name="remoteClient"></param>
        /// <param name="transactionID"></param>
        /// <param name="localID"></param>
        /// <param name="itemBase"></param>
        protected void RezScript(IClientAPI remoteClient, InventoryItemBase itemBase, UUID transactionID, uint localID)
        {
            UUID itemID = itemBase.ID;
            UUID copyID = UUID.Random();

            if (itemID != UUID.Zero)  // transferred from an avatar inventory to the prim's inventory
            {
                InventoryItemBase item = new InventoryItemBase(itemID, remoteClient.AgentId);
                item = m_scene.InventoryService.GetItem(item);

                if (item != null)
                {
                    ISceneChildEntity part = m_scene.GetSceneObjectPart (localID);
                    if (part != null)
                    {
                        if (!m_scene.Permissions.CanEditObjectInventory(part.UUID, remoteClient.AgentId))
                            return;

                        part.ParentEntity.AddInventoryItem (remoteClient, localID, item, copyID);
                        part.Inventory.CreateScriptInstance(copyID, 0, false, 0);

                        //                        MainConsole.Instance.InfoFormat("[PRIMINVENTORY]: " +
                        //                                         "Rezzed script {0} into prim local ID {1} for user {2}",
                        //                                         item.inventoryName, localID, remoteClient.Name);
                        part.GetProperties(remoteClient);
                    }
                    else
                    {
                        MainConsole.Instance.ErrorFormat(
                            "[PRIM INVENTORY]: " +
                            "Could not rez script {0} into prim local ID {1} for user {2}"
                            + " because the prim could not be found in the region!",
                            item.Name, localID, remoteClient.Name);
                    }
                }
                else
                {
                    MainConsole.Instance.ErrorFormat(
                        "[PRIM INVENTORY]: Could not find script inventory item {0} to rez for {1}!",
                        itemID, remoteClient.Name);
                }
            }
            else  // script has been rezzed directly into a prim's inventory
            {
                ISceneChildEntity part = m_scene.GetSceneObjectPart (itemBase.Folder);
                if (part == null)
                    return;

                if (!m_scene.Permissions.CanCreateObjectInventory(
                    itemBase.InvType, part.UUID, remoteClient.AgentId))
                    return;

                AssetBase asset = new AssetBase(UUID.Random(), itemBase.Name, (AssetType)itemBase.AssetType,
                                                remoteClient.AgentId)
                                      {
                                          Description = itemBase.Description,
                                          Data = Encoding.ASCII.GetBytes(DefaultLSLScript)
                                      };
                asset.ID = m_scene.AssetService.Store(asset);

                TaskInventoryItem taskItem = new TaskInventoryItem();

                taskItem.ResetIDs(itemBase.Folder);
                taskItem.ParentID = itemBase.Folder;
                taskItem.CreationDate = (uint)itemBase.CreationDate;
                taskItem.Name = itemBase.Name;
                taskItem.Description = itemBase.Description;
                taskItem.Type = itemBase.AssetType;
                taskItem.InvType = itemBase.InvType;
                taskItem.OwnerID = itemBase.Owner;
                taskItem.CreatorID = itemBase.CreatorIdAsUuid;
                taskItem.CreatorData = itemBase.CreatorData;
                taskItem.BasePermissions = itemBase.BasePermissions;
                taskItem.CurrentPermissions = itemBase.CurrentPermissions;
                taskItem.EveryonePermissions = itemBase.EveryOnePermissions;
                taskItem.GroupPermissions = itemBase.GroupPermissions;
                taskItem.NextPermissions = itemBase.NextPermissions;
                taskItem.GroupID = itemBase.GroupID;
                taskItem.GroupPermissions = 0;
                taskItem.Flags = itemBase.Flags;
                taskItem.PermsGranter = UUID.Zero;
                taskItem.PermsMask = 0;
                taskItem.AssetID = asset.ID;
                taskItem.SalePrice = itemBase.SalePrice;
                taskItem.SaleType = itemBase.SaleType;

                part.Inventory.AddInventoryItem(taskItem, false);
                part.GetProperties(remoteClient);

                part.Inventory.CreateScriptInstance(taskItem, 0, false, StateSource.NewRez);
            }
        }
Пример #35
0
        private void AssetDataCallback(UUID AssetID, AssetBase asset)
        {
            HasAsset = true;

            if (asset == null || asset.Data == null || asset.Type == (int)AssetType.Mesh)
            {
                if (m_imageManager.MissingImage != null)
                {
                    m_asset = m_imageManager.MissingImage.Data;
                }
                else
                {
                    m_asset = null;
                    IsDecoded = true;
                }
            }
            else
            {
                m_asset = asset.Data;
                asset = null;
            }

            RunUpdate();
        }
Пример #36
0
        /// <summary>
        /// Create a new inventory item.  Called when the client creates a new item directly within their
        /// inventory (e.g. by selecting a context inventory menu option).
        /// </summary>
        /// <param name="remoteClient"></param>
        /// <param name="transactionID"></param>
        /// <param name="folderID"></param>
        /// <param name="callbackID"></param>
        /// <param name="description"></param>
        /// <param name="name"></param>
        /// <param name="invType"></param>
        /// <param name="assetType"></param>
        /// <param name="wearableType"></param>
        /// <param name="nextOwnerMask"></param>
        /// <param name="creationDate"></param>
        protected void CreateNewInventoryItem(IClientAPI remoteClient, UUID transactionID, UUID folderID,
                                           uint callbackID, string description, string name, sbyte invType,
                                           sbyte assetType,
                                           byte wearableType, uint nextOwnerMask, int creationDate)
        {
            //MainConsole.Instance.DebugFormat("[AGENT INVENTORY]: Received request to create inventory item {0} in folder {1}", name, folderID);

            if (!m_scene.Permissions.CanCreateUserInventory(invType, remoteClient.AgentId))
                return;

            if (transactionID == UUID.Zero)
            {
                IScenePresence presence;
                if (m_scene.TryGetScenePresence(remoteClient.AgentId, out presence))
                {
                    byte[] data = null;

                    if (invType == (sbyte)InventoryType.Landmark && presence != null)
                    {
                        if (m_scene.Permissions.CanTakeLandmark(remoteClient.AgentId))
                        {
                            data = BuildLandmark (presence);
                        }
                        else
                        {
                            remoteClient.SendAlertMessage("You cannot create a landmark here.");
                        }
                    }
                    if(invType == (sbyte)InventoryType.LSL)
                    {
                        data = Encoding.ASCII.GetBytes(DefaultLSLScript);
                    }
                    if(invType == (sbyte)InventoryType.CallingCard)
                    {
                        return;
                    }
                    if (invType == (sbyte)InventoryType.Notecard)
                    {
                        data = Encoding.ASCII.GetBytes(" ");
                    }
                    if (invType == (sbyte)InventoryType.Gesture)
                    {
                        data = /*Default empty gesture*/ new byte[13] { 50, 10, 50, 53, 53, 10, 48, 10, 10, 10, 48, 10, 0 };
                    }

                    AssetBase asset = new AssetBase(UUID.Random(), name, (AssetType)assetType,
                                                    remoteClient.AgentId) {Data = data, Description = description};
                    asset.ID = m_scene.AssetService.Store(asset);

                    CreateNewInventoryItem(
                        remoteClient, remoteClient.AgentId.ToString(), "", folderID, name, 0, callbackID, asset, invType,
                        (uint)PermissionMask.All, (uint)PermissionMask.All, 0, nextOwnerMask, 0, creationDate);
                }
                else
                {
                    MainConsole.Instance.ErrorFormat(
                        "ScenePresence for agent uuid {0} unexpectedly not found in CreateNewInventoryItem",
                        remoteClient.AgentId);
                }
            }
            else
            {
                IAgentAssetTransactions agentTransactions = m_scene.RequestModuleInterface<IAgentAssetTransactions>();
                if (agentTransactions != null)
                {
                    agentTransactions.HandleItemCreationFromTransaction(
                        remoteClient, transactionID, folderID, callbackID, description,
                        name, invType, assetType, wearableType, nextOwnerMask);
                }
            }
        }
Пример #37
0
        private void AssetReceived(string id, Object sender, AssetBase asset)
        {
            UUID assetID = UUID.Zero;
            if (asset != null)
                assetID = asset.ID;
            else if ((InventoryAccessModule != null) && (sender != InventoryAccessModule))
            {
                // Unfortunately we need this here, there's no other way.
                // This is due to the fact that textures opened directly from the agent's inventory
                // don't have any distinguishing feature. As such, in order to serve those when the
                // foreign user is visiting, we need to try again after the first fail to the local
                // asset service.
                string assetServerURL = string.Empty;
                if (InventoryAccessModule.IsForeignUser(AgentID, out assetServerURL))
                {
                    MainConsole.Instance.DebugFormat(
                        "[J2KIMAGE]: texture {0} not found in local asset storage. Trying user's storage.", id);
                    AssetService.Get(assetServerURL + "/" + id, InventoryAccessModule, AssetReceived);
                    return;
                }
            }

            AssetDataCallback(assetID, asset);
        }
Пример #38
0
        ////////////////////////////////////////////////////////////
        // IImprovedAssetCache
        //

        public void Cache(AssetBase asset)
        {
            if (asset != null)
                m_Cache.AddOrUpdate(asset.IDString, asset);
        }
Пример #39
0
        // This needs ThreatLevel high. It is an excellent griefer tool,
        // In a loop, it can cause asset bloat and DOS levels of asset
        // writes.
        //
        public void osMakeNotecard(string notecardName, LSL_List contents)
        {
            if (!ScriptProtection.CheckThreatLevel(ThreatLevel.High, "osMakeNotecard", m_host, "OSSL", m_itemID))
                return;


            // Create new asset
            AssetBase asset = new AssetBase(UUID.Random(), notecardName, AssetType.Notecard, m_host.OwnerID) { Description = "Script Generated Notecard" };
            string notecardData = String.Empty;

            for (int i = 0; i < contents.Length; i++)
            {
                notecardData += contents.GetLSLStringItem(i) + "\n";
            }

            int textLength = notecardData.Length;
            notecardData = "Linden text version 2\n{\nLLEmbeddedItems version 1\n{\ncount 0\n}\nText length "
                           + textLength.ToString(CultureInfo.InvariantCulture) + "\n" + notecardData + "}\n";

            asset.Data = Util.UTF8.GetBytes(notecardData);
            asset.FillHash();
            asset.ID = World.AssetService.Store(asset);

            // Create Task Entry
            TaskInventoryItem taskItem = new TaskInventoryItem();

            taskItem.ResetIDs(m_host.UUID);
            taskItem.ParentID = m_host.UUID;
            taskItem.CreationDate = (uint)Util.UnixTimeSinceEpoch();
            taskItem.Name = asset.Name;
            taskItem.Description = asset.Description;
            taskItem.Type = (int)AssetType.Notecard;
            taskItem.InvType = (int)InventoryType.Notecard;
            taskItem.OwnerID = m_host.OwnerID;
            taskItem.CreatorID = m_host.OwnerID;
            taskItem.BasePermissions = (uint)PermissionMask.All;
            taskItem.CurrentPermissions = (uint)PermissionMask.All;
            taskItem.EveryonePermissions = 0;
            taskItem.NextPermissions = (uint)PermissionMask.All;
            taskItem.GroupID = m_host.GroupID;
            taskItem.GroupPermissions = 0;
            taskItem.Flags = 0;
            taskItem.SalePrice = 0;
            taskItem.SaleType = 0;
            taskItem.PermsGranter = UUID.Zero;
            taskItem.PermsMask = 0;
            taskItem.AssetID = asset.ID;

            m_host.Inventory.AddInventoryItem(taskItem, false);
        }