Exemplo n.º 1
0
                /// <summary>
                /// Handle raw uploaded baked texture data.
                /// </summary>
                /// <param name="data"></param>
                /// <param name="path"></param>
                /// <param name="param"></param>
                /// <returns></returns>
                public string BakedTextureUploaded(byte[] data, string path, string param)
                {
                    String result;
                    bool decodeFailed = false;
                    UUID newAssetID = UUID.Random();

                    if (data.Length <= 0)
                    {
                        m_log.ErrorFormat("[CAPS]: Invalid length {0} on UploadBakeRequestPut for {1}", data.Length, path);
                        decodeFailed = true;
                    }
                    else if (m_layerDecoder != null)
                    {
                        decodeFailed = (m_layerDecoder.Decode(newAssetID, data) == false);
                    }

                    if (decodeFailed)
                    {
                        Hashtable badReply = new Hashtable();
                        badReply["state"] = "error";
                        badReply["new_asset"] = UUID.Zero;
                        result = LLSDHelpers.SerialiseLLSDReply(badReply);
                    }
                    else
                    {
                        AssetBase asset = new AssetBase(newAssetID, "Baked Texture", (sbyte)AssetType.Texture, m_Caps.AgentID.ToString());
                        asset.Data = data;
                        //Persist baked textures as we will use them in the baked texture cache
                        //asset.Temporary = true;
                        asset.Local = true;
                        m_assetCache.AddAsset(asset, AssetRequestInfo.GenericNetRequest());

                        LLSDAssetUploadComplete uploadComplete = new LLSDAssetUploadComplete();
                        uploadComplete.new_asset = newAssetID.ToString();
                        uploadComplete.new_inventory_item = UUID.Zero;
                        uploadComplete.state = "complete";

                        result = LLSDHelpers.SerialiseLLSDReply(uploadComplete);
                        // m_log.DebugFormat("[BAKED TEXTURE UPLOADER]: baked texture upload completed for {0}", newAssetID);
                    }

                    m_Caps.HttpListener.RemoveStreamHandler("POST", m_uploaderPath);
                    return (result);
                }
                /// <summary>
                ///
                /// </summary>
                /// <param name="data"></param>
                /// <param name="path"></param>
                /// <param name="param"></param>
                /// <returns></returns>
                public string uploaderCaps(byte[] data, string path, string param)
                {
                    UUID inv = inventoryItemID;
                    string res = String.Empty;

                    UpdateItemResponse response = new UpdateItemResponse();
                    handlerUpdateItem = OnUpLoad;
                    if (handlerUpdateItem != null)
                    {
                        response = handlerUpdateItem(inv, data);
                    }

                    if (response.AssetKind == AssetType.LSLText)
                    {
                        if (response.SaveErrors != null && response.SaveErrors.Count > 0)
                        {
                            LLSDScriptCompileFail compFail = new LLSDScriptCompileFail();
                            compFail.new_asset = response.AssetId.ToString();
                            compFail.new_inventory_item = inv;
                            compFail.state = "complete";

                            foreach (string str in response.SaveErrors)
                            {
                                compFail.errors.Array.Add(str);
                            }

                            res = LLSDHelpers.SerializeLLSDReply(compFail);
                        }
                        else
                        {
                            LLSDScriptCompileSuccess compSuccess = new LLSDScriptCompileSuccess();
                            compSuccess.new_asset = response.AssetId.ToString();
                            compSuccess.new_inventory_item = inv;
                            compSuccess.state = "complete";

                            res = LLSDHelpers.SerializeLLSDReply(compSuccess);
                        }
                    }
                    else
                    {
                        LLSDAssetUploadComplete uploadComplete = new LLSDAssetUploadComplete();
                        uploadComplete.new_asset = response.AssetId.ToString();
                        uploadComplete.new_inventory_item = inv;
                        uploadComplete.state = "complete";

                        res = LLSDHelpers.SerializeLLSDReply(uploadComplete);
                    }

                    httpListener.RemoveStreamHandler("POST", uploaderPath);

                    return res;
                }
            /// <summary>
            ///
            /// </summary>
            /// <param name="data"></param>
            /// <param name="path"></param>
            /// <param name="param"></param>
            /// <returns></returns>
            public string uploaderCaps(byte[] data, string path, string param)
            {
                try
                {
                    //                    m_log.InfoFormat("[CAPS]: " +
                    //                                     "TaskInventoryScriptUpdater received data: {0}, path: {1}, param: {2}",
                    //                                     data, path, param));

                    string res = String.Empty;

                    UpdateItemResponse response = new UpdateItemResponse();

                    handlerUpdateTaskScript = OnUpLoad;
                    if (handlerUpdateTaskScript != null)
                    {
                        response = handlerUpdateTaskScript(inventoryItemID, primID, isScriptRunning, data);
                    }

                    if (response.AssetKind == AssetType.LSLText)
                    {
                        if (response.SaveErrors != null && response.SaveErrors.Count > 0)
                        {
                            LLSDScriptCompileFail compFail = new LLSDScriptCompileFail();
                            compFail.new_asset = response.AssetId.ToString();
                            compFail.state = "complete";

                            foreach (string str in response.SaveErrors)
                            {
                                compFail.errors.Array.Add(str);
                            }

                            res = LLSDHelpers.SerializeLLSDReply(compFail);
                        }
                        else
                        {
                            LLSDScriptCompileSuccess compSuccess = new LLSDScriptCompileSuccess();
                            compSuccess.new_asset = response.AssetId.ToString();
                            compSuccess.state = "complete";

                            res = LLSDHelpers.SerializeLLSDReply(compSuccess);
                        }
                    }
                    else
                    {
                        LLSDAssetUploadComplete uploadComplete = new LLSDAssetUploadComplete();
                        uploadComplete.new_asset = response.AssetId.ToString();
                        uploadComplete.state = "complete";

                        res = LLSDHelpers.SerializeLLSDReply(uploadComplete);
                    }

                    httpListener.RemoveStreamHandler("POST", uploaderPath);

                    // m_log.InfoFormat("[CAPS]: TaskInventoryScriptUpdater.uploaderCaps res: {0}", res);

                    return res;
                }
                catch (Exception e)
                {
                    m_log.Error("[CAPS]: " + e.ToString());
                }

                // XXX Maybe this should be some meaningful error packet
                return null;
            }
                /// <summary>
                ///
                /// </summary>
                /// <param name="data"></param>
                /// <param name="path"></param>
                /// <param name="param"></param>
                /// <returns></returns>
                public string uploaderCaps(byte[] data, string path, string param)
                {
                    UUID inv = inventoryItemID;
                    string res = String.Empty;
                    LLSDAssetUploadComplete uploadComplete = new LLSDAssetUploadComplete();
                    uploadComplete.new_asset = newAssetID.ToString();
                    uploadComplete.new_inventory_item = inv;
                    uploadComplete.state = "complete";

                    res = LLSDHelpers.SerializeLLSDReply(uploadComplete);

                    httpListener.RemoveStreamHandler("POST", uploaderPath);

                    handlerUpLoad = OnUpLoad;
                    if (handlerUpLoad != null)
                    {
                        handlerUpLoad(m_assetName, m_assetDes, newAssetID, inv, parentFolder, data, m_invType, m_assetType);
                    }

                    return res;
                }