1
0

BunchOfCaps.cs 48 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153
  1. /*
  2. * Copyright (c) Contributors, http://opensimulator.org/
  3. * See CONTRIBUTORS.TXT for a full list of copyright holders.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are met:
  7. * * Redistributions of source code must retain the above copyright
  8. * notice, this list of conditions and the following disclaimer.
  9. * * Redistributions in binary form must reproduce the above copyright
  10. * notice, this list of conditions and the following disclaimer in the
  11. * documentation and/or other materials provided with the distribution.
  12. * * Neither the name of the OpenSimulator Project nor the
  13. * names of its contributors may be used to endorse or promote products
  14. * derived from this software without specific prior written permission.
  15. *
  16. * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
  17. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  18. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  19. * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
  20. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  21. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  22. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  23. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  24. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  25. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. */
  27. using System;
  28. using System.Collections;
  29. using System.Collections.Generic;
  30. using System.IO;
  31. using System.Reflection;
  32. using System.Text;
  33. using OpenMetaverse;
  34. using OpenMetaverse.StructuredData;
  35. using Nini.Config;
  36. using log4net;
  37. using OpenSim.Framework;
  38. using OpenSim.Framework.Capabilities;
  39. using OpenSim.Region.Framework;
  40. using OpenSim.Region.Framework.Scenes;
  41. using OpenSim.Region.Framework.Scenes.Serialization;
  42. using OpenSim.Framework.Servers;
  43. using OpenSim.Framework.Servers.HttpServer;
  44. using OpenSim.Services.Interfaces;
  45. using Caps = OpenSim.Framework.Capabilities.Caps;
  46. using OSDArray = OpenMetaverse.StructuredData.OSDArray;
  47. using OSDMap = OpenMetaverse.StructuredData.OSDMap;
  48. namespace OpenSim.Region.ClientStack.Linden
  49. {
  50. public delegate void UpLoadedAsset(
  51. string assetName, string description, UUID assetID, UUID inventoryItem, UUID parentFolder,
  52. byte[] data, string inventoryType, string assetType);
  53. public delegate UUID UpdateItem(UUID itemID, byte[] data);
  54. public delegate void UpdateTaskScript(UUID itemID, UUID primID, bool isScriptRunning, byte[] data, ref ArrayList errors);
  55. public delegate void NewInventoryItem(UUID userID, InventoryItemBase item);
  56. public delegate void NewAsset(AssetBase asset);
  57. public delegate UUID ItemUpdatedCallback(UUID userID, UUID itemID, byte[] data);
  58. public delegate ArrayList TaskScriptUpdatedCallback(UUID userID, UUID itemID, UUID primID,
  59. bool isScriptRunning, byte[] data);
  60. public delegate InventoryCollection FetchInventoryDescendentsCAPS(UUID agentID, UUID folderID, UUID ownerID,
  61. bool fetchFolders, bool fetchItems, int sortOrder, out int version);
  62. /// <summary>
  63. /// XXX Probably not a particularly nice way of allow us to get the scene presence from the scene (chiefly so that
  64. /// we can popup a message on the user's client if the inventory service has permanently failed). But I didn't want
  65. /// to just pass the whole Scene into CAPS.
  66. /// </summary>
  67. public delegate IClientAPI GetClientDelegate(UUID agentID);
  68. public class BunchOfCaps
  69. {
  70. private static readonly ILog m_log =
  71. LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  72. private Scene m_Scene;
  73. private Caps m_HostCapsObj;
  74. private static readonly string m_requestPath = "0000/";
  75. // private static readonly string m_mapLayerPath = "0001/";
  76. private static readonly string m_newInventory = "0002/";
  77. //private static readonly string m_requestTexture = "0003/";
  78. private static readonly string m_notecardUpdatePath = "0004/";
  79. private static readonly string m_notecardTaskUpdatePath = "0005/";
  80. // private static readonly string m_fetchInventoryPath = "0006/";
  81. private static readonly string m_copyFromNotecardPath = "0007/";
  82. // private static readonly string m_remoteParcelRequestPath = "0009/";// This is in the LandManagementModule.
  83. // These are callbacks which will be setup by the scene so that we can update scene data when we
  84. // receive capability calls
  85. public NewInventoryItem AddNewInventoryItem = null;
  86. public NewAsset AddNewAsset = null;
  87. public ItemUpdatedCallback ItemUpdatedCall = null;
  88. public TaskScriptUpdatedCallback TaskScriptUpdatedCall = null;
  89. public FetchInventoryDescendentsCAPS CAPSFetchInventoryDescendents = null;
  90. public GetClientDelegate GetClient = null;
  91. private bool m_persistBakedTextures = false;
  92. private IAssetService m_assetService;
  93. private bool m_dumpAssetsToFile = false;
  94. private string m_regionName;
  95. private int m_levelUpload = 0;
  96. public BunchOfCaps(Scene scene, Caps caps)
  97. {
  98. m_Scene = scene;
  99. m_HostCapsObj = caps;
  100. IConfigSource config = m_Scene.Config;
  101. if (config != null)
  102. {
  103. IConfig sconfig = config.Configs["Startup"];
  104. if (sconfig != null)
  105. {
  106. m_levelUpload = sconfig.GetInt("LevelUpload", 0);
  107. }
  108. IConfig appearanceConfig = config.Configs["Appearance"];
  109. if (appearanceConfig != null)
  110. {
  111. m_persistBakedTextures = appearanceConfig.GetBoolean("PersistBakedTextures", m_persistBakedTextures);
  112. }
  113. }
  114. m_assetService = m_Scene.AssetService;
  115. m_regionName = m_Scene.RegionInfo.RegionName;
  116. RegisterHandlers();
  117. AddNewInventoryItem = m_Scene.AddUploadedInventoryItem;
  118. ItemUpdatedCall = m_Scene.CapsUpdateInventoryItemAsset;
  119. TaskScriptUpdatedCall = m_Scene.CapsUpdateTaskInventoryScriptAsset;
  120. GetClient = m_Scene.SceneGraph.GetControllingClient;
  121. }
  122. /// <summary>
  123. /// Register a bunch of CAPS http service handlers
  124. /// </summary>
  125. public void RegisterHandlers()
  126. {
  127. string capsBase = "/CAPS/" + m_HostCapsObj.CapsObjectPath;
  128. RegisterRegionServiceHandlers(capsBase);
  129. RegisterInventoryServiceHandlers(capsBase);
  130. }
  131. public void RegisterRegionServiceHandlers(string capsBase)
  132. {
  133. try
  134. {
  135. // the root of all evil
  136. m_HostCapsObj.RegisterHandler(
  137. "SEED", new RestStreamHandler("POST", capsBase + m_requestPath, SeedCapRequest, "SEED", null));
  138. // m_log.DebugFormat(
  139. // "[CAPS]: Registered seed capability {0} for {1}", capsBase + m_requestPath, m_HostCapsObj.AgentID);
  140. //m_capsHandlers["MapLayer"] =
  141. // new LLSDStreamhandler<OSDMapRequest, OSDMapLayerResponse>("POST",
  142. // capsBase + m_mapLayerPath,
  143. // GetMapLayer);
  144. IRequestHandler req
  145. = new RestStreamHandler(
  146. "POST", capsBase + m_notecardTaskUpdatePath, ScriptTaskInventory, "UpdateScript", null);
  147. m_HostCapsObj.RegisterHandler("UpdateScriptTaskInventory", req);
  148. m_HostCapsObj.RegisterHandler("UpdateScriptTask", req);
  149. }
  150. catch (Exception e)
  151. {
  152. m_log.Error("[CAPS]: " + e.ToString());
  153. }
  154. }
  155. public void RegisterInventoryServiceHandlers(string capsBase)
  156. {
  157. try
  158. {
  159. // I don't think this one works...
  160. m_HostCapsObj.RegisterHandler(
  161. "NewFileAgentInventory",
  162. new LLSDStreamhandler<LLSDAssetUploadRequest, LLSDAssetUploadResponse>(
  163. "POST",
  164. capsBase + m_newInventory,
  165. NewAgentInventoryRequest,
  166. "NewFileAgentInventory",
  167. null));
  168. IRequestHandler req
  169. = new RestStreamHandler(
  170. "POST", capsBase + m_notecardUpdatePath, NoteCardAgentInventory, "Update*", null);
  171. m_HostCapsObj.RegisterHandler("UpdateNotecardAgentInventory", req);
  172. m_HostCapsObj.RegisterHandler("UpdateScriptAgentInventory", req);
  173. m_HostCapsObj.RegisterHandler("UpdateScriptAgent", req);
  174. m_HostCapsObj.RegisterHandler(
  175. "CopyInventoryFromNotecard",
  176. new RestStreamHandler(
  177. "POST", capsBase + m_copyFromNotecardPath, CopyInventoryFromNotecard, "CopyInventoryFromNotecard", null));
  178. // As of RC 1.22.9 of the Linden client this is
  179. // supported
  180. //m_capsHandlers["WebFetchInventoryDescendents"] =new RestStreamHandler("POST", capsBase + m_fetchInventoryPath, FetchInventoryDescendentsRequest);
  181. // justincc: I've disabled the CAPS service for now to fix problems with selecting textures, and
  182. // subsequent inventory breakage, in the edit object pane (such as mantis 1085). This requires
  183. // enhancements (probably filling out the folder part of the LLSD reply) to our CAPS service,
  184. // but when I went on the Linden grid, the
  185. // simulators I visited (version 1.21) were, surprisingly, no longer supplying this capability. Instead,
  186. // the 1.19.1.4 client appeared to be happily flowing inventory data over UDP
  187. //
  188. // This is very probably just a temporary measure - once the CAPS service appears again on the Linden grid
  189. // we will be
  190. // able to get the data we need to implement the necessary part of the protocol to fix the issue above.
  191. // m_capsHandlers["FetchInventoryDescendents"] =
  192. // new RestStreamHandler("POST", capsBase + m_fetchInventoryPath, FetchInventoryRequest);
  193. // m_capsHandlers["FetchInventoryDescendents"] =
  194. // new LLSDStreamhandler<LLSDFetchInventoryDescendents, LLSDInventoryDescendents>("POST",
  195. // capsBase + m_fetchInventory,
  196. // FetchInventory));
  197. // m_capsHandlers["RequestTextureDownload"] = new RestStreamHandler("POST",
  198. // capsBase + m_requestTexture,
  199. // RequestTexture);
  200. }
  201. catch (Exception e)
  202. {
  203. m_log.Error("[CAPS]: " + e.ToString());
  204. }
  205. }
  206. /// <summary>
  207. /// Construct a client response detailing all the capabilities this server can provide.
  208. /// </summary>
  209. /// <param name="request"></param>
  210. /// <param name="path"></param>
  211. /// <param name="param"></param>
  212. /// <param name="httpRequest">HTTP request header object</param>
  213. /// <param name="httpResponse">HTTP response header object</param>
  214. /// <returns></returns>
  215. public string SeedCapRequest(string request, string path, string param,
  216. IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
  217. {
  218. m_log.DebugFormat(
  219. "[CAPS]: Received SEED caps request in {0} for agent {1}", m_regionName, m_HostCapsObj.AgentID);
  220. if (!m_Scene.CheckClient(m_HostCapsObj.AgentID, httpRequest.RemoteIPEndPoint))
  221. {
  222. m_log.WarnFormat(
  223. "[CAPS]: Unauthorized CAPS client {0} from {1}",
  224. m_HostCapsObj.AgentID, httpRequest.RemoteIPEndPoint);
  225. return string.Empty;
  226. }
  227. Hashtable caps = m_HostCapsObj.CapsHandlers.GetCapsDetails(true);
  228. // Add the external too
  229. foreach (KeyValuePair<string, string> kvp in m_HostCapsObj.ExternalCapsHandlers)
  230. caps[kvp.Key] = kvp.Value;
  231. string result = LLSDHelpers.SerialiseLLSDReply(caps);
  232. //m_log.DebugFormat("[CAPS] CapsRequest {0}", result);
  233. return result;
  234. }
  235. /// <summary>
  236. /// Called by the script task update handler. Provides a URL to which the client can upload a new asset.
  237. /// </summary>
  238. /// <param name="request"></param>
  239. /// <param name="path"></param>
  240. /// <param name="param"></param>
  241. /// <param name="httpRequest">HTTP request header object</param>
  242. /// <param name="httpResponse">HTTP response header object</param>
  243. /// <returns></returns>
  244. public string ScriptTaskInventory(string request, string path, string param,
  245. IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
  246. {
  247. try
  248. {
  249. // m_log.Debug("[CAPS]: ScriptTaskInventory Request in region: " + m_regionName);
  250. //m_log.DebugFormat("[CAPS]: request: {0}, path: {1}, param: {2}", request, path, param);
  251. Hashtable hash = (Hashtable)LLSD.LLSDDeserialize(Utils.StringToBytes(request));
  252. LLSDTaskScriptUpdate llsdUpdateRequest = new LLSDTaskScriptUpdate();
  253. LLSDHelpers.DeserialiseOSDMap(hash, llsdUpdateRequest);
  254. string capsBase = "/CAPS/" + m_HostCapsObj.CapsObjectPath;
  255. string uploaderPath = Util.RandomClass.Next(5000, 8000).ToString("0000");
  256. TaskInventoryScriptUpdater uploader =
  257. new TaskInventoryScriptUpdater(
  258. llsdUpdateRequest.item_id,
  259. llsdUpdateRequest.task_id,
  260. llsdUpdateRequest.is_script_running,
  261. capsBase + uploaderPath,
  262. m_HostCapsObj.HttpListener,
  263. m_dumpAssetsToFile);
  264. uploader.OnUpLoad += TaskScriptUpdated;
  265. m_HostCapsObj.HttpListener.AddStreamHandler(
  266. new BinaryStreamHandler(
  267. "POST", capsBase + uploaderPath, uploader.uploaderCaps, "TaskInventoryScriptUpdater", null));
  268. string protocol = "http://";
  269. if (m_HostCapsObj.SSLCaps)
  270. protocol = "https://";
  271. string uploaderURL = protocol + m_HostCapsObj.HostName + ":" + m_HostCapsObj.Port.ToString() + capsBase +
  272. uploaderPath;
  273. LLSDAssetUploadResponse uploadResponse = new LLSDAssetUploadResponse();
  274. uploadResponse.uploader = uploaderURL;
  275. uploadResponse.state = "upload";
  276. // m_log.InfoFormat("[CAPS]: " +
  277. // "ScriptTaskInventory response: {0}",
  278. // LLSDHelpers.SerialiseLLSDReply(uploadResponse)));
  279. return LLSDHelpers.SerialiseLLSDReply(uploadResponse);
  280. }
  281. catch (Exception e)
  282. {
  283. m_log.Error("[CAPS]: " + e.ToString());
  284. }
  285. return null;
  286. }
  287. /// <summary>
  288. /// Called when new asset data for an agent inventory item update has been uploaded.
  289. /// </summary>
  290. /// <param name="itemID">Item to update</param>
  291. /// <param name="primID">Prim containing item to update</param>
  292. /// <param name="isScriptRunning">Signals whether the script to update is currently running</param>
  293. /// <param name="data">New asset data</param>
  294. public void TaskScriptUpdated(UUID itemID, UUID primID, bool isScriptRunning, byte[] data, ref ArrayList errors)
  295. {
  296. if (TaskScriptUpdatedCall != null)
  297. {
  298. ArrayList e = TaskScriptUpdatedCall(m_HostCapsObj.AgentID, itemID, primID, isScriptRunning, data);
  299. foreach (Object item in e)
  300. errors.Add(item);
  301. }
  302. }
  303. /// <summary>
  304. /// Called when new asset data for an agent inventory item update has been uploaded.
  305. /// </summary>
  306. /// <param name="itemID">Item to update</param>
  307. /// <param name="data">New asset data</param>
  308. /// <returns></returns>
  309. public UUID ItemUpdated(UUID itemID, byte[] data)
  310. {
  311. if (ItemUpdatedCall != null)
  312. {
  313. return ItemUpdatedCall(m_HostCapsObj.AgentID, itemID, data);
  314. }
  315. return UUID.Zero;
  316. }
  317. /// <summary>
  318. ///
  319. /// </summary>
  320. /// <param name="llsdRequest"></param>
  321. /// <returns></returns>
  322. public LLSDAssetUploadResponse NewAgentInventoryRequest(LLSDAssetUploadRequest llsdRequest)
  323. {
  324. //m_log.Debug("[CAPS]: NewAgentInventoryRequest Request is: " + llsdRequest.ToString());
  325. //m_log.Debug("asset upload request via CAPS" + llsdRequest.inventory_type + " , " + llsdRequest.asset_type);
  326. if (llsdRequest.asset_type == "texture" ||
  327. llsdRequest.asset_type == "animation" ||
  328. llsdRequest.asset_type == "sound")
  329. {
  330. ScenePresence avatar = null;
  331. IClientAPI client = null;
  332. m_Scene.TryGetScenePresence(m_HostCapsObj.AgentID, out avatar);
  333. // check user level
  334. if (avatar != null)
  335. {
  336. client = avatar.ControllingClient;
  337. if (avatar.UserLevel < m_levelUpload)
  338. {
  339. if (client != null)
  340. client.SendAgentAlertMessage("Unable to upload asset. Insufficient permissions.", false);
  341. LLSDAssetUploadResponse errorResponse = new LLSDAssetUploadResponse();
  342. errorResponse.uploader = "";
  343. errorResponse.state = "error";
  344. return errorResponse;
  345. }
  346. }
  347. // check funds
  348. if (client != null)
  349. {
  350. IMoneyModule mm = m_Scene.RequestModuleInterface<IMoneyModule>();
  351. if (mm != null)
  352. {
  353. if (!mm.UploadCovered(client.AgentId, mm.UploadCharge))
  354. {
  355. client.SendAgentAlertMessage("Unable to upload asset. Insufficient funds.", false);
  356. LLSDAssetUploadResponse errorResponse = new LLSDAssetUploadResponse();
  357. errorResponse.uploader = "";
  358. errorResponse.state = "error";
  359. return errorResponse;
  360. }
  361. }
  362. }
  363. }
  364. string assetName = llsdRequest.name;
  365. string assetDes = llsdRequest.description;
  366. string capsBase = "/CAPS/" + m_HostCapsObj.CapsObjectPath;
  367. UUID newAsset = UUID.Random();
  368. UUID newInvItem = UUID.Random();
  369. UUID parentFolder = llsdRequest.folder_id;
  370. string uploaderPath = Util.RandomClass.Next(5000, 8000).ToString("0000");
  371. AssetUploader uploader =
  372. new AssetUploader(assetName, assetDes, newAsset, newInvItem, parentFolder, llsdRequest.inventory_type,
  373. llsdRequest.asset_type, capsBase + uploaderPath, m_HostCapsObj.HttpListener, m_dumpAssetsToFile);
  374. m_HostCapsObj.HttpListener.AddStreamHandler(
  375. new BinaryStreamHandler(
  376. "POST",
  377. capsBase + uploaderPath,
  378. uploader.uploaderCaps,
  379. "NewAgentInventoryRequest",
  380. m_HostCapsObj.AgentID.ToString()));
  381. string protocol = "http://";
  382. if (m_HostCapsObj.SSLCaps)
  383. protocol = "https://";
  384. string uploaderURL = protocol + m_HostCapsObj.HostName + ":" + m_HostCapsObj.Port.ToString() + capsBase +
  385. uploaderPath;
  386. LLSDAssetUploadResponse uploadResponse = new LLSDAssetUploadResponse();
  387. uploadResponse.uploader = uploaderURL;
  388. uploadResponse.state = "upload";
  389. uploader.OnUpLoad += UploadCompleteHandler;
  390. return uploadResponse;
  391. }
  392. /// <summary>
  393. /// Convert raw uploaded data into the appropriate asset and item.
  394. /// </summary>
  395. /// <param name="assetID"></param>
  396. /// <param name="inventoryItem"></param>
  397. /// <param name="data"></param>
  398. public void UploadCompleteHandler(string assetName, string assetDescription, UUID assetID,
  399. UUID inventoryItem, UUID parentFolder, byte[] data, string inventoryType,
  400. string assetType)
  401. {
  402. m_log.DebugFormat(
  403. "[BUNCH OF CAPS]: Uploaded asset {0} for inventory item {1}, inv type {2}, asset type {3}",
  404. assetID, inventoryItem, inventoryType, assetType);
  405. sbyte assType = 0;
  406. sbyte inType = 0;
  407. if (inventoryType == "sound")
  408. {
  409. inType = 1;
  410. assType = 1;
  411. }
  412. else if (inventoryType == "animation")
  413. {
  414. inType = 19;
  415. assType = 20;
  416. }
  417. else if (inventoryType == "wearable")
  418. {
  419. inType = 18;
  420. switch (assetType)
  421. {
  422. case "bodypart":
  423. assType = 13;
  424. break;
  425. case "clothing":
  426. assType = 5;
  427. break;
  428. }
  429. }
  430. else if (inventoryType == "object")
  431. {
  432. inType = (sbyte)InventoryType.Object;
  433. assType = (sbyte)AssetType.Object;
  434. List<Vector3> positions = new List<Vector3>();
  435. List<Quaternion> rotations = new List<Quaternion>();
  436. OSDMap request = (OSDMap)OSDParser.DeserializeLLSDXml(data);
  437. OSDArray instance_list = (OSDArray)request["instance_list"];
  438. OSDArray mesh_list = (OSDArray)request["mesh_list"];
  439. OSDArray texture_list = (OSDArray)request["texture_list"];
  440. SceneObjectGroup grp = null;
  441. List<UUID> textures = new List<UUID>();
  442. for (int i = 0; i < texture_list.Count; i++)
  443. {
  444. AssetBase textureAsset = new AssetBase(UUID.Random(), assetName, (sbyte)AssetType.Texture, "");
  445. textureAsset.Data = texture_list[i].AsBinary();
  446. m_assetService.Store(textureAsset);
  447. textures.Add(textureAsset.FullID);
  448. }
  449. for (int i = 0; i < mesh_list.Count; i++)
  450. {
  451. PrimitiveBaseShape pbs = PrimitiveBaseShape.CreateBox();
  452. Primitive.TextureEntry textureEntry
  453. = new Primitive.TextureEntry(Primitive.TextureEntry.WHITE_TEXTURE);
  454. OSDMap inner_instance_list = (OSDMap)instance_list[i];
  455. OSDArray face_list = (OSDArray)inner_instance_list["face_list"];
  456. for (uint face = 0; face < face_list.Count; face++)
  457. {
  458. OSDMap faceMap = (OSDMap)face_list[(int)face];
  459. Primitive.TextureEntryFace f = pbs.Textures.CreateFace(face);
  460. if(faceMap.ContainsKey("fullbright"))
  461. f.Fullbright = faceMap["fullbright"].AsBoolean();
  462. if (faceMap.ContainsKey ("diffuse_color"))
  463. f.RGBA = faceMap["diffuse_color"].AsColor4();
  464. int textureNum = faceMap["image"].AsInteger();
  465. float imagerot = faceMap["imagerot"].AsInteger();
  466. float offsets = (float)faceMap["offsets"].AsReal();
  467. float offsett = (float)faceMap["offsett"].AsReal();
  468. float scales = (float)faceMap["scales"].AsReal();
  469. float scalet = (float)faceMap["scalet"].AsReal();
  470. if(imagerot != 0)
  471. f.Rotation = imagerot;
  472. if(offsets != 0)
  473. f.OffsetU = offsets;
  474. if (offsett != 0)
  475. f.OffsetV = offsett;
  476. if (scales != 0)
  477. f.RepeatU = scales;
  478. if (scalet != 0)
  479. f.RepeatV = scalet;
  480. if (textures.Count > textureNum)
  481. f.TextureID = textures[textureNum];
  482. else
  483. f.TextureID = Primitive.TextureEntry.WHITE_TEXTURE;
  484. textureEntry.FaceTextures[face] = f;
  485. }
  486. pbs.TextureEntry = textureEntry.GetBytes();
  487. AssetBase meshAsset = new AssetBase(UUID.Random(), assetName, (sbyte)AssetType.Mesh, "");
  488. meshAsset.Data = mesh_list[i].AsBinary();
  489. m_assetService.Store(meshAsset);
  490. pbs.SculptEntry = true;
  491. pbs.SculptTexture = meshAsset.FullID;
  492. pbs.SculptType = (byte)SculptType.Mesh;
  493. pbs.SculptData = meshAsset.Data;
  494. Vector3 position = inner_instance_list["position"].AsVector3();
  495. Vector3 scale = inner_instance_list["scale"].AsVector3();
  496. Quaternion rotation = inner_instance_list["rotation"].AsQuaternion();
  497. // no longer used - begin ------------------------
  498. // int physicsShapeType = inner_instance_list["physics_shape_type"].AsInteger();
  499. // int material = inner_instance_list["material"].AsInteger();
  500. // int mesh = inner_instance_list["mesh"].AsInteger();
  501. // OSDMap permissions = (OSDMap)inner_instance_list["permissions"];
  502. // int base_mask = permissions["base_mask"].AsInteger();
  503. // int everyone_mask = permissions["everyone_mask"].AsInteger();
  504. // UUID creator_id = permissions["creator_id"].AsUUID();
  505. // UUID group_id = permissions["group_id"].AsUUID();
  506. // int group_mask = permissions["group_mask"].AsInteger();
  507. // bool is_owner_group = permissions["is_owner_group"].AsBoolean();
  508. // UUID last_owner_id = permissions["last_owner_id"].AsUUID();
  509. // int next_owner_mask = permissions["next_owner_mask"].AsInteger();
  510. // UUID owner_id = permissions["owner_id"].AsUUID();
  511. // int owner_mask = permissions["owner_mask"].AsInteger();
  512. // no longer used - end ------------------------
  513. UUID owner_id = m_HostCapsObj.AgentID;
  514. SceneObjectPart prim
  515. = new SceneObjectPart(owner_id, pbs, position, Quaternion.Identity, Vector3.Zero);
  516. prim.Scale = scale;
  517. prim.OffsetPosition = position;
  518. rotations.Add(rotation);
  519. positions.Add(position);
  520. prim.UUID = UUID.Random();
  521. prim.CreatorID = owner_id;
  522. prim.OwnerID = owner_id;
  523. prim.GroupID = UUID.Zero;
  524. prim.LastOwnerID = prim.OwnerID;
  525. prim.CreationDate = Util.UnixTimeSinceEpoch();
  526. prim.Name = assetName;
  527. prim.Description = "";
  528. // prim.BaseMask = (uint)base_mask;
  529. // prim.EveryoneMask = (uint)everyone_mask;
  530. // prim.GroupMask = (uint)group_mask;
  531. // prim.NextOwnerMask = (uint)next_owner_mask;
  532. // prim.OwnerMask = (uint)owner_mask;
  533. if (grp == null)
  534. grp = new SceneObjectGroup(prim);
  535. else
  536. grp.AddPart(prim);
  537. }
  538. // Fix first link number
  539. if (grp.Parts.Length > 1)
  540. grp.RootPart.LinkNum++;
  541. Vector3 rootPos = positions[0];
  542. grp.AbsolutePosition = rootPos;
  543. for (int i = 0; i < positions.Count; i++)
  544. {
  545. Vector3 offset = positions[i] - rootPos;
  546. grp.Parts[i].OffsetPosition = offset;
  547. }
  548. for (int i = 0; i < rotations.Count; i++)
  549. {
  550. if (i != 0)
  551. grp.Parts[i].RotationOffset = rotations[i];
  552. }
  553. grp.UpdateGroupRotationR(rotations[0]);
  554. data = ASCIIEncoding.ASCII.GetBytes(SceneObjectSerializer.ToOriginalXmlFormat(grp));
  555. }
  556. AssetBase asset;
  557. asset = new AssetBase(assetID, assetName, assType, m_HostCapsObj.AgentID.ToString());
  558. asset.Data = data;
  559. if (AddNewAsset != null)
  560. AddNewAsset(asset);
  561. else if (m_assetService != null)
  562. m_assetService.Store(asset);
  563. InventoryItemBase item = new InventoryItemBase();
  564. item.Owner = m_HostCapsObj.AgentID;
  565. item.CreatorId = m_HostCapsObj.AgentID.ToString();
  566. item.CreatorData = String.Empty;
  567. item.ID = inventoryItem;
  568. item.AssetID = asset.FullID;
  569. item.Description = assetDescription;
  570. item.Name = assetName;
  571. item.AssetType = assType;
  572. item.InvType = inType;
  573. item.Folder = parentFolder;
  574. // If we set PermissionMask.All then when we rez the item the next permissions will replace the current
  575. // (owner) permissions. This becomes a problem if next permissions are changed.
  576. item.CurrentPermissions
  577. = (uint)(PermissionMask.Move | PermissionMask.Copy | PermissionMask.Modify | PermissionMask.Transfer);
  578. item.BasePermissions = (uint)PermissionMask.All;
  579. item.EveryOnePermissions = 0;
  580. item.NextPermissions = (uint)PermissionMask.All;
  581. item.CreationDate = Util.UnixTimeSinceEpoch();
  582. if (AddNewInventoryItem != null)
  583. {
  584. AddNewInventoryItem(m_HostCapsObj.AgentID, item);
  585. }
  586. }
  587. /// <summary>
  588. ///
  589. /// </summary>
  590. /// <param name="mapReq"></param>
  591. /// <returns></returns>
  592. public LLSDMapLayerResponse GetMapLayer(LLSDMapRequest mapReq)
  593. {
  594. m_log.Debug("[CAPS]: MapLayer Request in region: " + m_regionName);
  595. LLSDMapLayerResponse mapResponse = new LLSDMapLayerResponse();
  596. mapResponse.LayerData.Array.Add(GetOSDMapLayerResponse());
  597. return mapResponse;
  598. }
  599. /// <summary>
  600. ///
  601. /// </summary>
  602. /// <returns></returns>
  603. protected static OSDMapLayer GetOSDMapLayerResponse()
  604. {
  605. OSDMapLayer mapLayer = new OSDMapLayer();
  606. mapLayer.Right = 5000;
  607. mapLayer.Top = 5000;
  608. mapLayer.ImageID = new UUID("00000000-0000-1111-9999-000000000006");
  609. return mapLayer;
  610. }
  611. /// <summary>
  612. ///
  613. /// </summary>
  614. /// <param name="request"></param>
  615. /// <param name="path"></param>
  616. /// <param name="param"></param>
  617. /// <returns></returns>
  618. public string RequestTexture(string request, string path, string param)
  619. {
  620. m_log.Debug("texture request " + request);
  621. // Needs implementing (added to remove compiler warning)
  622. return String.Empty;
  623. }
  624. /// <summary>
  625. /// Called by the notecard update handler. Provides a URL to which the client can upload a new asset.
  626. /// </summary>
  627. /// <param name="request"></param>
  628. /// <param name="path"></param>
  629. /// <param name="param"></param>
  630. /// <returns></returns>
  631. public string NoteCardAgentInventory(string request, string path, string param,
  632. IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
  633. {
  634. //m_log.Debug("[CAPS]: NoteCardAgentInventory Request in region: " + m_regionName + "\n" + request);
  635. //m_log.Debug("[CAPS]: NoteCardAgentInventory Request is: " + request);
  636. //OpenMetaverse.StructuredData.OSDMap hash = (OpenMetaverse.StructuredData.OSDMap)OpenMetaverse.StructuredData.LLSDParser.DeserializeBinary(Utils.StringToBytes(request));
  637. Hashtable hash = (Hashtable)LLSD.LLSDDeserialize(Utils.StringToBytes(request));
  638. LLSDItemUpdate llsdRequest = new LLSDItemUpdate();
  639. LLSDHelpers.DeserialiseOSDMap(hash, llsdRequest);
  640. string capsBase = "/CAPS/" + m_HostCapsObj.CapsObjectPath;
  641. string uploaderPath = Util.RandomClass.Next(5000, 8000).ToString("0000");
  642. ItemUpdater uploader =
  643. new ItemUpdater(llsdRequest.item_id, capsBase + uploaderPath, m_HostCapsObj.HttpListener, m_dumpAssetsToFile);
  644. uploader.OnUpLoad += ItemUpdated;
  645. m_HostCapsObj.HttpListener.AddStreamHandler(
  646. new BinaryStreamHandler(
  647. "POST", capsBase + uploaderPath, uploader.uploaderCaps, "NoteCardAgentInventory", null));
  648. string protocol = "http://";
  649. if (m_HostCapsObj.SSLCaps)
  650. protocol = "https://";
  651. string uploaderURL = protocol + m_HostCapsObj.HostName + ":" + m_HostCapsObj.Port.ToString() + capsBase +
  652. uploaderPath;
  653. LLSDAssetUploadResponse uploadResponse = new LLSDAssetUploadResponse();
  654. uploadResponse.uploader = uploaderURL;
  655. uploadResponse.state = "upload";
  656. // m_log.InfoFormat("[CAPS]: " +
  657. // "NoteCardAgentInventory response: {0}",
  658. // LLSDHelpers.SerialiseLLSDReply(uploadResponse)));
  659. return LLSDHelpers.SerialiseLLSDReply(uploadResponse);
  660. }
  661. /// <summary>
  662. /// Called by the CopyInventoryFromNotecard caps handler.
  663. /// </summary>
  664. /// <param name="request"></param>
  665. /// <param name="path"></param>
  666. /// <param name="param"></param>
  667. public string CopyInventoryFromNotecard(string request, string path, string param,
  668. IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
  669. {
  670. Hashtable response = new Hashtable();
  671. response["int_response_code"] = 404;
  672. response["content_type"] = "text/plain";
  673. response["keepalive"] = false;
  674. response["str_response_string"] = "";
  675. try
  676. {
  677. OSDMap content = (OSDMap)OSDParser.DeserializeLLSDXml(request);
  678. UUID objectID = content["object-id"].AsUUID();
  679. UUID notecardID = content["notecard-id"].AsUUID();
  680. UUID folderID = content["folder-id"].AsUUID();
  681. UUID itemID = content["item-id"].AsUUID();
  682. // m_log.InfoFormat("[CAPS]: CopyInventoryFromNotecard, FolderID:{0}, ItemID:{1}, NotecardID:{2}, ObjectID:{3}", folderID, itemID, notecardID, objectID);
  683. if (objectID != UUID.Zero)
  684. {
  685. SceneObjectPart part = m_Scene.GetSceneObjectPart(objectID);
  686. if (part != null)
  687. {
  688. // TaskInventoryItem taskItem = part.Inventory.GetInventoryItem(notecardID);
  689. if (!m_Scene.Permissions.CanCopyObjectInventory(notecardID, objectID, m_HostCapsObj.AgentID))
  690. {
  691. return LLSDHelpers.SerialiseLLSDReply(response);
  692. }
  693. }
  694. }
  695. InventoryItemBase item = null;
  696. InventoryItemBase copyItem = null;
  697. IClientAPI client = null;
  698. m_Scene.TryGetClient(m_HostCapsObj.AgentID, out client);
  699. item = m_Scene.InventoryService.GetItem(new InventoryItemBase(itemID));
  700. if (item != null)
  701. {
  702. copyItem = m_Scene.GiveInventoryItem(m_HostCapsObj.AgentID, item.Owner, itemID, folderID);
  703. if (copyItem != null && client != null)
  704. {
  705. m_log.InfoFormat("[CAPS]: CopyInventoryFromNotecard, ItemID:{0}, FolderID:{1}", copyItem.ID, copyItem.Folder);
  706. client.SendBulkUpdateInventory(copyItem);
  707. }
  708. }
  709. else
  710. {
  711. m_log.ErrorFormat("[CAPS]: CopyInventoryFromNotecard - Failed to retrieve item {0} from notecard {1}", itemID, notecardID);
  712. if (client != null)
  713. client.SendAlertMessage("Failed to retrieve item");
  714. }
  715. }
  716. catch (Exception e)
  717. {
  718. m_log.ErrorFormat("[CAPS]: CopyInventoryFromNotecard : {0}", e.ToString());
  719. }
  720. response["int_response_code"] = 200;
  721. return LLSDHelpers.SerialiseLLSDReply(response);
  722. }
  723. }
  724. public class AssetUploader
  725. {
  726. public event UpLoadedAsset OnUpLoad;
  727. private UpLoadedAsset handlerUpLoad = null;
  728. private string uploaderPath = String.Empty;
  729. private UUID newAssetID;
  730. private UUID inventoryItemID;
  731. private UUID parentFolder;
  732. private IHttpServer httpListener;
  733. private bool m_dumpAssetsToFile;
  734. private string m_assetName = String.Empty;
  735. private string m_assetDes = String.Empty;
  736. private string m_invType = String.Empty;
  737. private string m_assetType = String.Empty;
  738. public AssetUploader(string assetName, string description, UUID assetID, UUID inventoryItem,
  739. UUID parentFolderID, string invType, string assetType, string path,
  740. IHttpServer httpServer, bool dumpAssetsToFile)
  741. {
  742. m_assetName = assetName;
  743. m_assetDes = description;
  744. newAssetID = assetID;
  745. inventoryItemID = inventoryItem;
  746. uploaderPath = path;
  747. httpListener = httpServer;
  748. parentFolder = parentFolderID;
  749. m_assetType = assetType;
  750. m_invType = invType;
  751. m_dumpAssetsToFile = dumpAssetsToFile;
  752. }
  753. /// <summary>
  754. /// Handle raw asset upload data via the capability.
  755. /// </summary>
  756. /// <param name="data"></param>
  757. /// <param name="path"></param>
  758. /// <param name="param"></param>
  759. /// <returns></returns>
  760. public string uploaderCaps(byte[] data, string path, string param)
  761. {
  762. UUID inv = inventoryItemID;
  763. string res = String.Empty;
  764. LLSDAssetUploadComplete uploadComplete = new LLSDAssetUploadComplete();
  765. uploadComplete.new_asset = newAssetID.ToString();
  766. uploadComplete.new_inventory_item = inv;
  767. uploadComplete.state = "complete";
  768. res = LLSDHelpers.SerialiseLLSDReply(uploadComplete);
  769. httpListener.RemoveStreamHandler("POST", uploaderPath);
  770. // TODO: probably make this a better set of extensions here
  771. string extension = ".jp2";
  772. if (m_invType != "image")
  773. {
  774. extension = ".dat";
  775. }
  776. if (m_dumpAssetsToFile)
  777. {
  778. SaveAssetToFile(m_assetName + extension, data);
  779. }
  780. handlerUpLoad = OnUpLoad;
  781. if (handlerUpLoad != null)
  782. {
  783. handlerUpLoad(m_assetName, m_assetDes, newAssetID, inv, parentFolder, data, m_invType, m_assetType);
  784. }
  785. return res;
  786. }
  787. ///Left this in and commented in case there are unforseen issues
  788. //private void SaveAssetToFile(string filename, byte[] data)
  789. //{
  790. // FileStream fs = File.Create(filename);
  791. // BinaryWriter bw = new BinaryWriter(fs);
  792. // bw.Write(data);
  793. // bw.Close();
  794. // fs.Close();
  795. //}
  796. private static void SaveAssetToFile(string filename, byte[] data)
  797. {
  798. string assetPath = "UserAssets";
  799. if (!Directory.Exists(assetPath))
  800. {
  801. Directory.CreateDirectory(assetPath);
  802. }
  803. FileStream fs = File.Create(Path.Combine(assetPath, Util.safeFileName(filename)));
  804. BinaryWriter bw = new BinaryWriter(fs);
  805. bw.Write(data);
  806. bw.Close();
  807. fs.Close();
  808. }
  809. }
  810. /// <summary>
  811. /// This class is a callback invoked when a client sends asset data to
  812. /// an agent inventory notecard update url
  813. /// </summary>
  814. public class ItemUpdater
  815. {
  816. public event UpdateItem OnUpLoad;
  817. private UpdateItem handlerUpdateItem = null;
  818. private string uploaderPath = String.Empty;
  819. private UUID inventoryItemID;
  820. private IHttpServer httpListener;
  821. private bool m_dumpAssetToFile;
  822. public ItemUpdater(UUID inventoryItem, string path, IHttpServer httpServer, bool dumpAssetToFile)
  823. {
  824. m_dumpAssetToFile = dumpAssetToFile;
  825. inventoryItemID = inventoryItem;
  826. uploaderPath = path;
  827. httpListener = httpServer;
  828. }
  829. /// <summary>
  830. /// Handle raw uploaded asset data.
  831. /// </summary>
  832. /// <param name="data"></param>
  833. /// <param name="path"></param>
  834. /// <param name="param"></param>
  835. /// <returns></returns>
  836. public string uploaderCaps(byte[] data, string path, string param)
  837. {
  838. UUID inv = inventoryItemID;
  839. string res = String.Empty;
  840. LLSDAssetUploadComplete uploadComplete = new LLSDAssetUploadComplete();
  841. UUID assetID = UUID.Zero;
  842. handlerUpdateItem = OnUpLoad;
  843. if (handlerUpdateItem != null)
  844. {
  845. assetID = handlerUpdateItem(inv, data);
  846. }
  847. uploadComplete.new_asset = assetID.ToString();
  848. uploadComplete.new_inventory_item = inv;
  849. uploadComplete.state = "complete";
  850. res = LLSDHelpers.SerialiseLLSDReply(uploadComplete);
  851. httpListener.RemoveStreamHandler("POST", uploaderPath);
  852. if (m_dumpAssetToFile)
  853. {
  854. SaveAssetToFile("updateditem" + Util.RandomClass.Next(1, 1000) + ".dat", data);
  855. }
  856. return res;
  857. }
  858. ///Left this in and commented in case there are unforseen issues
  859. //private void SaveAssetToFile(string filename, byte[] data)
  860. //{
  861. // FileStream fs = File.Create(filename);
  862. // BinaryWriter bw = new BinaryWriter(fs);
  863. // bw.Write(data);
  864. // bw.Close();
  865. // fs.Close();
  866. //}
  867. private static void SaveAssetToFile(string filename, byte[] data)
  868. {
  869. string assetPath = "UserAssets";
  870. if (!Directory.Exists(assetPath))
  871. {
  872. Directory.CreateDirectory(assetPath);
  873. }
  874. FileStream fs = File.Create(Path.Combine(assetPath, filename));
  875. BinaryWriter bw = new BinaryWriter(fs);
  876. bw.Write(data);
  877. bw.Close();
  878. fs.Close();
  879. }
  880. }
  881. /// <summary>
  882. /// This class is a callback invoked when a client sends asset data to
  883. /// a task inventory script update url
  884. /// </summary>
  885. public class TaskInventoryScriptUpdater
  886. {
  887. private static readonly ILog m_log =
  888. LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  889. public event UpdateTaskScript OnUpLoad;
  890. private UpdateTaskScript handlerUpdateTaskScript = null;
  891. private string uploaderPath = String.Empty;
  892. private UUID inventoryItemID;
  893. private UUID primID;
  894. private bool isScriptRunning;
  895. private IHttpServer httpListener;
  896. private bool m_dumpAssetToFile;
  897. public TaskInventoryScriptUpdater(UUID inventoryItemID, UUID primID, int isScriptRunning,
  898. string path, IHttpServer httpServer, bool dumpAssetToFile)
  899. {
  900. m_dumpAssetToFile = dumpAssetToFile;
  901. this.inventoryItemID = inventoryItemID;
  902. this.primID = primID;
  903. // This comes in over the packet as an integer, but actually appears to be treated as a bool
  904. this.isScriptRunning = (0 == isScriptRunning ? false : true);
  905. uploaderPath = path;
  906. httpListener = httpServer;
  907. }
  908. /// <summary>
  909. ///
  910. /// </summary>
  911. /// <param name="data"></param>
  912. /// <param name="path"></param>
  913. /// <param name="param"></param>
  914. /// <returns></returns>
  915. public string uploaderCaps(byte[] data, string path, string param)
  916. {
  917. try
  918. {
  919. // m_log.InfoFormat("[CAPS]: " +
  920. // "TaskInventoryScriptUpdater received data: {0}, path: {1}, param: {2}",
  921. // data, path, param));
  922. string res = String.Empty;
  923. LLSDTaskScriptUploadComplete uploadComplete = new LLSDTaskScriptUploadComplete();
  924. ArrayList errors = new ArrayList();
  925. handlerUpdateTaskScript = OnUpLoad;
  926. if (handlerUpdateTaskScript != null)
  927. {
  928. handlerUpdateTaskScript(inventoryItemID, primID, isScriptRunning, data, ref errors);
  929. }
  930. uploadComplete.new_asset = inventoryItemID;
  931. uploadComplete.compiled = errors.Count > 0 ? false : true;
  932. uploadComplete.state = "complete";
  933. uploadComplete.errors = new OpenSim.Framework.Capabilities.OSDArray();
  934. uploadComplete.errors.Array = errors;
  935. res = LLSDHelpers.SerialiseLLSDReply(uploadComplete);
  936. httpListener.RemoveStreamHandler("POST", uploaderPath);
  937. if (m_dumpAssetToFile)
  938. {
  939. SaveAssetToFile("updatedtaskscript" + Util.RandomClass.Next(1, 1000) + ".dat", data);
  940. }
  941. // m_log.InfoFormat("[CAPS]: TaskInventoryScriptUpdater.uploaderCaps res: {0}", res);
  942. return res;
  943. }
  944. catch (Exception e)
  945. {
  946. m_log.Error("[CAPS]: " + e.ToString());
  947. }
  948. // XXX Maybe this should be some meaningful error packet
  949. return null;
  950. }
  951. ///Left this in and commented in case there are unforseen issues
  952. //private void SaveAssetToFile(string filename, byte[] data)
  953. //{
  954. // FileStream fs = File.Create(filename);
  955. // BinaryWriter bw = new BinaryWriter(fs);
  956. // bw.Write(data);
  957. // bw.Close();
  958. // fs.Close();
  959. //}
  960. private static void SaveAssetToFile(string filename, byte[] data)
  961. {
  962. string assetPath = "UserAssets";
  963. if (!Directory.Exists(assetPath))
  964. {
  965. Directory.CreateDirectory(assetPath);
  966. }
  967. FileStream fs = File.Create(Path.Combine(assetPath, filename));
  968. BinaryWriter bw = new BinaryWriter(fs);
  969. bw.Write(data);
  970. bw.Close();
  971. fs.Close();
  972. }
  973. }
  974. }