Ejemplo n.º 1
0
        private void NewFileAgentInventoryUploadHandler(NewFileAgentInventoryMessage message, Capability cap,
                                                        IHttpClientContext context, IHttpRequest request, IHttpResponse response)
        {
            byte[] assetData = request.GetBody();
            UUID   assetID   = UUID.Zero;
            UUID   itemID    = UUID.Zero;

            m_log.Debug("Received inventory asset upload from " + cap.OwnerID + " (" + assetData.Length + " bytes)");

            if (assetData != null && assetData.Length > 0)
            {
                string contentType = LLUtil.LLAssetTypeToContentType((int)message.AssetType);

                // Create the asset
                if (m_assetClient.StoreAsset(contentType, false, false, assetData, cap.OwnerID, out assetID))
                {
                    // Create the inventory item
                    LLInventoryItem item = new LLInventoryItem();
                    item.AssetID      = assetID;
                    item.ContentType  = contentType;
                    item.CreationDate = DateTime.UtcNow;
                    item.CreatorID    = cap.OwnerID;
                    item.Description  = message.Description;
                    item.ID           = UUID.Random();
                    item.Name         = message.Name;
                    item.OwnerID      = cap.OwnerID;
                    item.ParentID     = message.FolderID;
                    item.Permissions  = (m_permissions != null) ? m_permissions.GetDefaultPermissions() : Permissions.FullPermissions;
                    item.SalePrice    = 10;
                    item.SaleType     = SaleType.Not;

                    if (m_inventoryClient.TryCreateItem(cap.OwnerID, item))
                    {
                        itemID = item.ID;
                    }
                    else
                    {
                        m_log.Warn("Failed to create inventory item for uploaded asset " + assetID);
                    }
                }
                else
                {
                    m_log.WarnFormat("Failed to store uploaded inventory asset ({0} bytes)", assetData.Length);
                }
            }
            else
            {
                m_log.Warn("Inventory asset upload contained no data");
            }

            // Build the response message
            OSDMap reply = new OSDMap
            {
                { "state", OSD.FromString("complete") },
                { "new_asset", OSD.FromUUID(assetID) },
                { "new_inventory_item", OSD.FromUUID(itemID) }
            };

            LLUtil.SendLLSDXMLResponse(response, reply);
        }
Ejemplo n.º 2
0
        private void UploadObjectAssetHandler(Capability cap, IHttpClientContext context, IHttpRequest request, IHttpResponse response)
        {
            UploadObjectAssetMessage message;

            if (LLUtil.TryGetMessage <UploadObjectAssetMessage>(request.Body, out message))
            {
                LLPrimitive parent = null;

                // Build the linkset
                for (int i = 0; i < message.Objects.Length; i++)
                {
                    UploadObjectAssetMessage.Object obj = message.Objects[i];

                    #region Primitive Creation

                    Primitive prim = new Primitive();
                    prim.Properties = new Primitive.ObjectProperties();
                    prim.Sculpt     = new Primitive.SculptData();
                    prim.Textures   = new Primitive.TextureEntry(UUID.Zero);

                    prim.Flags     = PrimFlags.CastShadows | PrimFlags.InventoryEmpty | PrimFlags.CreateSelected;
                    prim.ID        = UUID.Random();
                    prim.MediaURL  = String.Empty;
                    prim.OwnerID   = cap.OwnerID;
                    prim.GroupID   = obj.GroupID;
                    prim.TextColor = Color4.Black;

                    prim.Properties.CreationDate = DateTime.UtcNow;
                    prim.Properties.CreatorID    = cap.OwnerID;
                    prim.Properties.Description  = String.Empty;
                    prim.Properties.GroupID      = obj.GroupID;
                    prim.Properties.LastOwnerID  = cap.OwnerID;
                    prim.Properties.Name         = obj.Name;
                    prim.Properties.ObjectID     = prim.ID;
                    prim.Properties.OwnerID      = prim.OwnerID;
                    prim.Properties.Permissions  = (m_permissions != null) ?
                                                   m_permissions.GetDefaultPermissions() :
                                                   Permissions.FullPermissions;
                    prim.Properties.SalePrice = 10;

                    prim.PrimData.PCode            = PCode.Prim;
                    prim.PrimData.Material         = obj.Material;
                    prim.PrimData.PathBegin        = obj.PathBegin;
                    prim.PrimData.PathCurve        = (PathCurve)obj.PathCurve;
                    prim.PrimData.PathEnd          = obj.PathEnd;
                    prim.PrimData.ProfileBegin     = obj.ProfileBegin;
                    prim.PrimData.ProfileCurve     = (ProfileCurve)obj.ProfileCurve;
                    prim.PrimData.ProfileEnd       = obj.ProfileEnd;
                    prim.PrimData.ProfileHollow    = obj.ProfileHollow;
                    prim.PrimData.PathRadiusOffset = obj.RadiusOffset;
                    prim.PrimData.PathRevolutions  = obj.Revolutions;
                    prim.PrimData.PathScaleX       = obj.ScaleX;
                    prim.PrimData.PathScaleY       = obj.ScaleY;
                    prim.PrimData.PathShearX       = obj.ShearX;
                    prim.PrimData.PathShearY       = obj.ShearY;
                    prim.PrimData.PathSkew         = obj.Skew;
                    prim.PrimData.PathTaperX       = obj.TaperX;
                    prim.PrimData.PathTaperY       = obj.TaperY;
                    prim.PrimData.PathTwist        = obj.Twist;
                    prim.PrimData.PathTwistBegin   = obj.TwistBegin;

                    // Extra parameters
                    for (int j = 0; j < obj.ExtraParams.Length; j++)
                    {
                        UploadObjectAssetMessage.Object.ExtraParam extraParam = obj.ExtraParams[j];

                        switch (extraParam.Type)
                        {
                        case ExtraParamType.Flexible:
                            prim.Flexible = new Primitive.FlexibleData(extraParam.ExtraParamData, 0);
                            break;

                        case ExtraParamType.Light:
                            prim.Light = new Primitive.LightData(extraParam.ExtraParamData, 0);
                            break;

                        case ExtraParamType.Sculpt:
                            prim.Sculpt = new Primitive.SculptData(extraParam.ExtraParamData, 0);
                            break;
                        }
                    }

                    // Faces
                    for (int j = 0; j < obj.Faces.Length; j++)
                    {
                        UploadObjectAssetMessage.Object.Face face = obj.Faces[j];

                        Primitive.TextureEntryFace primFace = prim.Textures.GetFace(0);
                        primFace.Bump       = face.Bump;
                        primFace.RGBA       = face.Color;
                        primFace.Fullbright = face.Fullbright;
                        primFace.Glow       = face.Glow;
                        primFace.TextureID  = face.ImageID;
                        primFace.Rotation   = face.ImageRot;
                        primFace.MediaFlags = ((face.MediaFlags & MEDIA_MASK) != 0);

                        primFace.OffsetU    = face.OffsetS;
                        primFace.OffsetV    = face.OffsetT;
                        primFace.RepeatU    = face.ScaleS;
                        primFace.RepeatV    = face.ScaleT;
                        primFace.TexMapType = (MappingType)(face.MediaFlags & TEX_MAP_MASK);
                    }

                    prim.Sculpt.SculptTexture = obj.SculptID;
                    prim.Sculpt.Type          = obj.SculptType;

                    #endregion Primitive Creation

                    LLPrimitive llprim = new LLPrimitive(prim, m_scene, m_primMesher);
                    llprim.Scale = obj.Scale;

                    // Link children prims to the parent
                    if (i == 0)
                    {
                        llprim.RelativePosition = obj.Position;
                        llprim.RelativeRotation = obj.Rotation;
                        m_scene.EntityAddOrUpdate(this, llprim, UpdateFlags.FullUpdate, 0);

                        parent = llprim;
                    }
                    else
                    {
                        llprim.RelativePosition = obj.Position;
                        llprim.RelativeRotation = obj.Rotation;
                        llprim.SetParent(parent, true, false);
                        m_scene.EntityAddOrUpdate(this, llprim, UpdateFlags.FullUpdate, 0);
                    }
                }
            }
            else
            {
                m_log.Warn("Received invalid data for UploadObjectAsset");
                response.Status = System.Net.HttpStatusCode.BadRequest;
            }
        }