/// <summary> /// /// </summary> /// <param name="llsdRequest"></param> /// <returns></returns> public LLSDAssetUploadResponse NewAgentInventoryRequest(LLSDAssetUploadRequest llsdRequest) { //m_log.Debug("[CAPS]: NewAgentInventoryRequest Request is: " + llsdRequest.ToString()); //m_log.Debug("asset upload request via CAPS" + llsdRequest.inventory_type + " , " + llsdRequest.asset_type); // start by getting the client IClientAPI client = null; m_Scene.TryGetClient(m_HostCapsObj.AgentID, out client); // check current state so we only have one service at a time lock (m_ModelCost) { switch (m_FileAgentInventoryState) { case FileAgentInventoryState.processRequest: case FileAgentInventoryState.processUpload: LLSDAssetUploadError resperror = new LLSDAssetUploadError(); resperror.message = "Uploader busy processing previus request"; resperror.identifier = UUID.Zero; LLSDAssetUploadResponse errorResponse = new LLSDAssetUploadResponse(); errorResponse.uploader = ""; errorResponse.state = "error"; errorResponse.error = resperror; return errorResponse; break; case FileAgentInventoryState.waitUpload: // todo stop current uploader server break; case FileAgentInventoryState.idle: default: break; } m_FileAgentInventoryState = FileAgentInventoryState.processRequest; } int cost = 0; int nreqtextures = 0; int nreqmeshs= 0; int nreqinstances = 0; bool IsAtestUpload = false; string assetName = llsdRequest.name; LLSDAssetUploadResponseData meshcostdata = new LLSDAssetUploadResponseData(); if (llsdRequest.asset_type == "texture" || llsdRequest.asset_type == "animation" || llsdRequest.asset_type == "animatn" || // this is the asset name actually used by viewers llsdRequest.asset_type == "mesh" || llsdRequest.asset_type == "sound") { ScenePresence avatar = null; m_Scene.TryGetScenePresence(m_HostCapsObj.AgentID, out avatar); // check user level if (avatar != null) { if (avatar.UserLevel < m_levelUpload) { LLSDAssetUploadError resperror = new LLSDAssetUploadError(); resperror.message = "Insufficient permissions to upload"; resperror.identifier = UUID.Zero; LLSDAssetUploadResponse errorResponse = new LLSDAssetUploadResponse(); errorResponse.uploader = ""; errorResponse.state = "error"; errorResponse.error = resperror; lock (m_ModelCost) m_FileAgentInventoryState = FileAgentInventoryState.idle; return errorResponse; } } // check test upload and funds if (client != null) { IMoneyModule mm = m_Scene.RequestModuleInterface<IMoneyModule>(); int baseCost = 0; if (mm != null) baseCost = mm.UploadCharge; string warning = String.Empty; if (llsdRequest.asset_type == "mesh") { string error; int modelcost; if (!m_ModelCost.MeshModelCost(llsdRequest.asset_resources, baseCost, out modelcost, meshcostdata, out error, ref warning)) { LLSDAssetUploadError resperror = new LLSDAssetUploadError(); resperror.message = error; resperror.identifier = UUID.Zero; LLSDAssetUploadResponse errorResponse = new LLSDAssetUploadResponse(); errorResponse.uploader = ""; errorResponse.state = "error"; errorResponse.error = resperror; lock (m_ModelCost) m_FileAgentInventoryState = FileAgentInventoryState.idle; return errorResponse; } cost = modelcost; } else { cost = baseCost; } if (cost > 0 && mm != null) { // check for test upload if (m_ForceFreeTestUpload) // all are test { if (!(assetName.Length > 5 && assetName.StartsWith("TEST-"))) // has normal name lets change it assetName = "TEST-" + assetName; IsAtestUpload = true; } else if (m_enableFreeTestUpload) // only if prefixed with "TEST-" { IsAtestUpload = (assetName.Length > 5 && assetName.StartsWith("TEST-")); } if(IsAtestUpload) // let user know, still showing cost estimation warning += "Upload will have no cost, for testing purposes only. Other uses are prohibited. Items will not work after 48 hours or on other regions"; // check funds else { if (!mm.UploadCovered(client.AgentId, (int)cost)) { LLSDAssetUploadError resperror = new LLSDAssetUploadError(); resperror.message = "Insuficient funds"; resperror.identifier = UUID.Zero; LLSDAssetUploadResponse errorResponse = new LLSDAssetUploadResponse(); errorResponse.uploader = ""; errorResponse.state = "error"; errorResponse.error = resperror; lock (m_ModelCost) m_FileAgentInventoryState = FileAgentInventoryState.idle; return errorResponse; } } } if (client != null && warning != String.Empty) client.SendAgentAlertMessage(warning, true); } } string assetDes = llsdRequest.description; string capsBase = "/CAPS/" + m_HostCapsObj.CapsObjectPath; UUID newAsset = UUID.Random(); UUID newInvItem = UUID.Random(); UUID parentFolder = llsdRequest.folder_id; string uploaderPath = Util.RandomClass.Next(5000, 8000).ToString("0000"); UUID texturesFolder = UUID.Zero; if(!IsAtestUpload && m_enableModelUploadTextureToInventory) texturesFolder = llsdRequest.texture_folder_id; AssetUploader uploader = new AssetUploader(assetName, assetDes, newAsset, newInvItem, parentFolder, llsdRequest.inventory_type, llsdRequest.asset_type, capsBase + uploaderPath, m_HostCapsObj.HttpListener, m_dumpAssetsToFile, cost, texturesFolder, nreqtextures, nreqmeshs, nreqinstances, IsAtestUpload, llsdRequest.next_owner_mask, llsdRequest.group_mask, llsdRequest.everyone_mask); m_HostCapsObj.HttpListener.AddStreamHandler( new BinaryStreamHandler( "POST", capsBase + uploaderPath, uploader.uploaderCaps, "NewAgentInventoryRequest", m_HostCapsObj.AgentID.ToString())); string protocol = "http://"; if (m_HostCapsObj.SSLCaps) protocol = "https://"; string uploaderURL = protocol + m_HostCapsObj.HostName + ":" + m_HostCapsObj.Port.ToString() + capsBase + uploaderPath; LLSDAssetUploadResponse uploadResponse = new LLSDAssetUploadResponse(); uploadResponse.uploader = uploaderURL; uploadResponse.state = "upload"; uploadResponse.upload_price = (int)cost; if (llsdRequest.asset_type == "mesh") { uploadResponse.data = meshcostdata; } uploader.OnUpLoad += UploadCompleteHandler; lock (m_ModelCost) m_FileAgentInventoryState = FileAgentInventoryState.waitUpload; return uploadResponse; }
/// <summary> /// Handle raw asset upload data via the capability. /// </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.SerialiseLLSDReply(uploadComplete); */ m_timeoutTimer.Stop(); httpListener.RemoveStreamHandler("POST", uploaderPath); // TODO: probably make this a better set of extensions here string extension = ".jp2"; if (m_invType != "image") { extension = ".dat"; } if (m_dumpAssetsToFile) { SaveAssetToFile(m_assetName + extension, data); } handlerUpLoad = OnUpLoad; if (handlerUpLoad != null) { handlerUpLoad(m_assetName, m_assetDes, newAssetID, inv, parentFolder, data, m_invType, m_assetType, m_cost, m_texturesFolder, m_nreqtextures, m_nreqmeshs, m_nreqinstances, m_IsAtestUpload, ref m_error, ref m_nextOwnerMask, ref m_groupMask, ref m_everyoneMask); } uploadComplete.new_next_owner_mask = m_nextOwnerMask; uploadComplete.new_group_mask = m_groupMask; uploadComplete.new_everyone_mask = m_everyoneMask; if (m_IsAtestUpload) { LLSDAssetUploadError resperror = new LLSDAssetUploadError(); resperror.message = "Upload SUCESSEFULL for testing purposes only. Other uses are prohibited. Item will not work after 48 hours or on other regions"; resperror.identifier = inv; uploadComplete.error = resperror; uploadComplete.state = "Upload4Testing"; } else { if (m_error == String.Empty) { uploadComplete.new_asset = newAssetID.ToString(); uploadComplete.new_inventory_item = inv; // if (m_texturesFolder != UUID.Zero) // uploadComplete.new_texture_folder_id = m_texturesFolder; uploadComplete.state = "complete"; } else { LLSDAssetUploadError resperror = new LLSDAssetUploadError(); resperror.message = m_error; resperror.identifier = inv; uploadComplete.error = resperror; uploadComplete.state = "failed"; } } res = LLSDHelpers.SerialiseLLSDReply(uploadComplete); return res; }