BunchOfCaps.cs 48 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152
  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.Debug("[CAPS]: Seed Caps Request in region: " + m_regionName);
  219. if (!m_Scene.CheckClient(m_HostCapsObj.AgentID, httpRequest.RemoteIPEndPoint))
  220. {
  221. m_log.DebugFormat(
  222. "[CAPS]: Unauthorized CAPS client {0} from {1}",
  223. m_HostCapsObj.AgentID, httpRequest.RemoteIPEndPoint);
  224. return string.Empty;
  225. }
  226. Hashtable caps = m_HostCapsObj.CapsHandlers.GetCapsDetails(true);
  227. // Add the external too
  228. foreach (KeyValuePair<string, string> kvp in m_HostCapsObj.ExternalCapsHandlers)
  229. caps[kvp.Key] = kvp.Value;
  230. string result = LLSDHelpers.SerialiseLLSDReply(caps);
  231. //m_log.DebugFormat("[CAPS] CapsRequest {0}", result);
  232. return result;
  233. }
  234. /// <summary>
  235. /// Called by the script task update handler. Provides a URL to which the client can upload a new asset.
  236. /// </summary>
  237. /// <param name="request"></param>
  238. /// <param name="path"></param>
  239. /// <param name="param"></param>
  240. /// <param name="httpRequest">HTTP request header object</param>
  241. /// <param name="httpResponse">HTTP response header object</param>
  242. /// <returns></returns>
  243. public string ScriptTaskInventory(string request, string path, string param,
  244. IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
  245. {
  246. try
  247. {
  248. // m_log.Debug("[CAPS]: ScriptTaskInventory Request in region: " + m_regionName);
  249. //m_log.DebugFormat("[CAPS]: request: {0}, path: {1}, param: {2}", request, path, param);
  250. Hashtable hash = (Hashtable)LLSD.LLSDDeserialize(Utils.StringToBytes(request));
  251. LLSDTaskScriptUpdate llsdUpdateRequest = new LLSDTaskScriptUpdate();
  252. LLSDHelpers.DeserialiseOSDMap(hash, llsdUpdateRequest);
  253. string capsBase = "/CAPS/" + m_HostCapsObj.CapsObjectPath;
  254. string uploaderPath = Util.RandomClass.Next(5000, 8000).ToString("0000");
  255. TaskInventoryScriptUpdater uploader =
  256. new TaskInventoryScriptUpdater(
  257. llsdUpdateRequest.item_id,
  258. llsdUpdateRequest.task_id,
  259. llsdUpdateRequest.is_script_running,
  260. capsBase + uploaderPath,
  261. m_HostCapsObj.HttpListener,
  262. m_dumpAssetsToFile);
  263. uploader.OnUpLoad += TaskScriptUpdated;
  264. m_HostCapsObj.HttpListener.AddStreamHandler(
  265. new BinaryStreamHandler(
  266. "POST", capsBase + uploaderPath, uploader.uploaderCaps, "TaskInventoryScriptUpdater", null));
  267. string protocol = "http://";
  268. if (m_HostCapsObj.SSLCaps)
  269. protocol = "https://";
  270. string uploaderURL = protocol + m_HostCapsObj.HostName + ":" + m_HostCapsObj.Port.ToString() + capsBase +
  271. uploaderPath;
  272. LLSDAssetUploadResponse uploadResponse = new LLSDAssetUploadResponse();
  273. uploadResponse.uploader = uploaderURL;
  274. uploadResponse.state = "upload";
  275. // m_log.InfoFormat("[CAPS]: " +
  276. // "ScriptTaskInventory response: {0}",
  277. // LLSDHelpers.SerialiseLLSDReply(uploadResponse)));
  278. return LLSDHelpers.SerialiseLLSDReply(uploadResponse);
  279. }
  280. catch (Exception e)
  281. {
  282. m_log.Error("[CAPS]: " + e.ToString());
  283. }
  284. return null;
  285. }
  286. /// <summary>
  287. /// Called when new asset data for an agent inventory item update has been uploaded.
  288. /// </summary>
  289. /// <param name="itemID">Item to update</param>
  290. /// <param name="primID">Prim containing item to update</param>
  291. /// <param name="isScriptRunning">Signals whether the script to update is currently running</param>
  292. /// <param name="data">New asset data</param>
  293. public void TaskScriptUpdated(UUID itemID, UUID primID, bool isScriptRunning, byte[] data, ref ArrayList errors)
  294. {
  295. if (TaskScriptUpdatedCall != null)
  296. {
  297. ArrayList e = TaskScriptUpdatedCall(m_HostCapsObj.AgentID, itemID, primID, isScriptRunning, data);
  298. foreach (Object item in e)
  299. errors.Add(item);
  300. }
  301. }
  302. /// <summary>
  303. /// Called when new asset data for an agent inventory item update has been uploaded.
  304. /// </summary>
  305. /// <param name="itemID">Item to update</param>
  306. /// <param name="data">New asset data</param>
  307. /// <returns></returns>
  308. public UUID ItemUpdated(UUID itemID, byte[] data)
  309. {
  310. if (ItemUpdatedCall != null)
  311. {
  312. return ItemUpdatedCall(m_HostCapsObj.AgentID, itemID, data);
  313. }
  314. return UUID.Zero;
  315. }
  316. /// <summary>
  317. ///
  318. /// </summary>
  319. /// <param name="llsdRequest"></param>
  320. /// <returns></returns>
  321. public LLSDAssetUploadResponse NewAgentInventoryRequest(LLSDAssetUploadRequest llsdRequest)
  322. {
  323. //m_log.Debug("[CAPS]: NewAgentInventoryRequest Request is: " + llsdRequest.ToString());
  324. //m_log.Debug("asset upload request via CAPS" + llsdRequest.inventory_type + " , " + llsdRequest.asset_type);
  325. if (llsdRequest.asset_type == "texture" ||
  326. llsdRequest.asset_type == "animation" ||
  327. llsdRequest.asset_type == "sound")
  328. {
  329. ScenePresence avatar = null;
  330. IClientAPI client = null;
  331. m_Scene.TryGetScenePresence(m_HostCapsObj.AgentID, out avatar);
  332. // check user level
  333. if (avatar != null)
  334. {
  335. client = avatar.ControllingClient;
  336. if (avatar.UserLevel < m_levelUpload)
  337. {
  338. if (client != null)
  339. client.SendAgentAlertMessage("Unable to upload asset. Insufficient permissions.", false);
  340. LLSDAssetUploadResponse errorResponse = new LLSDAssetUploadResponse();
  341. errorResponse.uploader = "";
  342. errorResponse.state = "error";
  343. return errorResponse;
  344. }
  345. }
  346. // check funds
  347. if (client != null)
  348. {
  349. IMoneyModule mm = m_Scene.RequestModuleInterface<IMoneyModule>();
  350. if (mm != null)
  351. {
  352. if (!mm.UploadCovered(client.AgentId, mm.UploadCharge))
  353. {
  354. client.SendAgentAlertMessage("Unable to upload asset. Insufficient funds.", false);
  355. LLSDAssetUploadResponse errorResponse = new LLSDAssetUploadResponse();
  356. errorResponse.uploader = "";
  357. errorResponse.state = "error";
  358. return errorResponse;
  359. }
  360. }
  361. }
  362. }
  363. string assetName = llsdRequest.name;
  364. string assetDes = llsdRequest.description;
  365. string capsBase = "/CAPS/" + m_HostCapsObj.CapsObjectPath;
  366. UUID newAsset = UUID.Random();
  367. UUID newInvItem = UUID.Random();
  368. UUID parentFolder = llsdRequest.folder_id;
  369. string uploaderPath = Util.RandomClass.Next(5000, 8000).ToString("0000");
  370. AssetUploader uploader =
  371. new AssetUploader(assetName, assetDes, newAsset, newInvItem, parentFolder, llsdRequest.inventory_type,
  372. llsdRequest.asset_type, capsBase + uploaderPath, m_HostCapsObj.HttpListener, m_dumpAssetsToFile);
  373. m_HostCapsObj.HttpListener.AddStreamHandler(
  374. new BinaryStreamHandler(
  375. "POST",
  376. capsBase + uploaderPath,
  377. uploader.uploaderCaps,
  378. "NewAgentInventoryRequest",
  379. m_HostCapsObj.AgentID.ToString()));
  380. string protocol = "http://";
  381. if (m_HostCapsObj.SSLCaps)
  382. protocol = "https://";
  383. string uploaderURL = protocol + m_HostCapsObj.HostName + ":" + m_HostCapsObj.Port.ToString() + capsBase +
  384. uploaderPath;
  385. LLSDAssetUploadResponse uploadResponse = new LLSDAssetUploadResponse();
  386. uploadResponse.uploader = uploaderURL;
  387. uploadResponse.state = "upload";
  388. uploader.OnUpLoad += UploadCompleteHandler;
  389. return uploadResponse;
  390. }
  391. /// <summary>
  392. /// Convert raw uploaded data into the appropriate asset and item.
  393. /// </summary>
  394. /// <param name="assetID"></param>
  395. /// <param name="inventoryItem"></param>
  396. /// <param name="data"></param>
  397. public void UploadCompleteHandler(string assetName, string assetDescription, UUID assetID,
  398. UUID inventoryItem, UUID parentFolder, byte[] data, string inventoryType,
  399. string assetType)
  400. {
  401. m_log.DebugFormat(
  402. "[BUNCH OF CAPS]: Uploaded asset {0} for inventory item {1}, inv type {2}, asset type {3}",
  403. assetID, inventoryItem, inventoryType, assetType);
  404. sbyte assType = 0;
  405. sbyte inType = 0;
  406. if (inventoryType == "sound")
  407. {
  408. inType = 1;
  409. assType = 1;
  410. }
  411. else if (inventoryType == "animation")
  412. {
  413. inType = 19;
  414. assType = 20;
  415. }
  416. else if (inventoryType == "wearable")
  417. {
  418. inType = 18;
  419. switch (assetType)
  420. {
  421. case "bodypart":
  422. assType = 13;
  423. break;
  424. case "clothing":
  425. assType = 5;
  426. break;
  427. }
  428. }
  429. else if (inventoryType == "object")
  430. {
  431. inType = (sbyte)InventoryType.Object;
  432. assType = (sbyte)AssetType.Object;
  433. List<Vector3> positions = new List<Vector3>();
  434. List<Quaternion> rotations = new List<Quaternion>();
  435. OSDMap request = (OSDMap)OSDParser.DeserializeLLSDXml(data);
  436. OSDArray instance_list = (OSDArray)request["instance_list"];
  437. OSDArray mesh_list = (OSDArray)request["mesh_list"];
  438. OSDArray texture_list = (OSDArray)request["texture_list"];
  439. SceneObjectGroup grp = null;
  440. List<UUID> textures = new List<UUID>();
  441. for (int i = 0; i < texture_list.Count; i++)
  442. {
  443. AssetBase textureAsset = new AssetBase(UUID.Random(), assetName, (sbyte)AssetType.Texture, "");
  444. textureAsset.Data = texture_list[i].AsBinary();
  445. m_assetService.Store(textureAsset);
  446. textures.Add(textureAsset.FullID);
  447. }
  448. for (int i = 0; i < mesh_list.Count; i++)
  449. {
  450. PrimitiveBaseShape pbs = PrimitiveBaseShape.CreateBox();
  451. Primitive.TextureEntry textureEntry
  452. = new Primitive.TextureEntry(Primitive.TextureEntry.WHITE_TEXTURE);
  453. OSDMap inner_instance_list = (OSDMap)instance_list[i];
  454. OSDArray face_list = (OSDArray)inner_instance_list["face_list"];
  455. for (uint face = 0; face < face_list.Count; face++)
  456. {
  457. OSDMap faceMap = (OSDMap)face_list[(int)face];
  458. Primitive.TextureEntryFace f = pbs.Textures.CreateFace(face);
  459. if(faceMap.ContainsKey("fullbright"))
  460. f.Fullbright = faceMap["fullbright"].AsBoolean();
  461. if (faceMap.ContainsKey ("diffuse_color"))
  462. f.RGBA = faceMap["diffuse_color"].AsColor4();
  463. int textureNum = faceMap["image"].AsInteger();
  464. float imagerot = faceMap["imagerot"].AsInteger();
  465. float offsets = (float)faceMap["offsets"].AsReal();
  466. float offsett = (float)faceMap["offsett"].AsReal();
  467. float scales = (float)faceMap["scales"].AsReal();
  468. float scalet = (float)faceMap["scalet"].AsReal();
  469. if(imagerot != 0)
  470. f.Rotation = imagerot;
  471. if(offsets != 0)
  472. f.OffsetU = offsets;
  473. if (offsett != 0)
  474. f.OffsetV = offsett;
  475. if (scales != 0)
  476. f.RepeatU = scales;
  477. if (scalet != 0)
  478. f.RepeatV = scalet;
  479. if (textures.Count > textureNum)
  480. f.TextureID = textures[textureNum];
  481. else
  482. f.TextureID = Primitive.TextureEntry.WHITE_TEXTURE;
  483. textureEntry.FaceTextures[face] = f;
  484. }
  485. pbs.TextureEntry = textureEntry.GetBytes();
  486. AssetBase meshAsset = new AssetBase(UUID.Random(), assetName, (sbyte)AssetType.Mesh, "");
  487. meshAsset.Data = mesh_list[i].AsBinary();
  488. m_assetService.Store(meshAsset);
  489. pbs.SculptEntry = true;
  490. pbs.SculptTexture = meshAsset.FullID;
  491. pbs.SculptType = (byte)SculptType.Mesh;
  492. pbs.SculptData = meshAsset.Data;
  493. Vector3 position = inner_instance_list["position"].AsVector3();
  494. Vector3 scale = inner_instance_list["scale"].AsVector3();
  495. Quaternion rotation = inner_instance_list["rotation"].AsQuaternion();
  496. // no longer used - begin ------------------------
  497. // int physicsShapeType = inner_instance_list["physics_shape_type"].AsInteger();
  498. // int material = inner_instance_list["material"].AsInteger();
  499. // int mesh = inner_instance_list["mesh"].AsInteger();
  500. // OSDMap permissions = (OSDMap)inner_instance_list["permissions"];
  501. // int base_mask = permissions["base_mask"].AsInteger();
  502. // int everyone_mask = permissions["everyone_mask"].AsInteger();
  503. // UUID creator_id = permissions["creator_id"].AsUUID();
  504. // UUID group_id = permissions["group_id"].AsUUID();
  505. // int group_mask = permissions["group_mask"].AsInteger();
  506. // bool is_owner_group = permissions["is_owner_group"].AsBoolean();
  507. // UUID last_owner_id = permissions["last_owner_id"].AsUUID();
  508. // int next_owner_mask = permissions["next_owner_mask"].AsInteger();
  509. // UUID owner_id = permissions["owner_id"].AsUUID();
  510. // int owner_mask = permissions["owner_mask"].AsInteger();
  511. // no longer used - end ------------------------
  512. UUID owner_id = m_HostCapsObj.AgentID;
  513. SceneObjectPart prim
  514. = new SceneObjectPart(owner_id, pbs, position, Quaternion.Identity, Vector3.Zero);
  515. prim.Scale = scale;
  516. prim.OffsetPosition = position;
  517. rotations.Add(rotation);
  518. positions.Add(position);
  519. prim.UUID = UUID.Random();
  520. prim.CreatorID = owner_id;
  521. prim.OwnerID = owner_id;
  522. prim.GroupID = UUID.Zero;
  523. prim.LastOwnerID = prim.OwnerID;
  524. prim.CreationDate = Util.UnixTimeSinceEpoch();
  525. prim.Name = assetName;
  526. prim.Description = "";
  527. // prim.BaseMask = (uint)base_mask;
  528. // prim.EveryoneMask = (uint)everyone_mask;
  529. // prim.GroupMask = (uint)group_mask;
  530. // prim.NextOwnerMask = (uint)next_owner_mask;
  531. // prim.OwnerMask = (uint)owner_mask;
  532. if (grp == null)
  533. grp = new SceneObjectGroup(prim);
  534. else
  535. grp.AddPart(prim);
  536. }
  537. // Fix first link number
  538. if (grp.Parts.Length > 1)
  539. grp.RootPart.LinkNum++;
  540. Vector3 rootPos = positions[0];
  541. grp.AbsolutePosition = rootPos;
  542. for (int i = 0; i < positions.Count; i++)
  543. {
  544. Vector3 offset = positions[i] - rootPos;
  545. grp.Parts[i].OffsetPosition = offset;
  546. }
  547. for (int i = 0; i < rotations.Count; i++)
  548. {
  549. if (i != 0)
  550. grp.Parts[i].RotationOffset = rotations[i];
  551. }
  552. grp.UpdateGroupRotationR(rotations[0]);
  553. data = ASCIIEncoding.ASCII.GetBytes(SceneObjectSerializer.ToOriginalXmlFormat(grp));
  554. }
  555. AssetBase asset;
  556. asset = new AssetBase(assetID, assetName, assType, m_HostCapsObj.AgentID.ToString());
  557. asset.Data = data;
  558. if (AddNewAsset != null)
  559. AddNewAsset(asset);
  560. else if (m_assetService != null)
  561. m_assetService.Store(asset);
  562. InventoryItemBase item = new InventoryItemBase();
  563. item.Owner = m_HostCapsObj.AgentID;
  564. item.CreatorId = m_HostCapsObj.AgentID.ToString();
  565. item.CreatorData = String.Empty;
  566. item.ID = inventoryItem;
  567. item.AssetID = asset.FullID;
  568. item.Description = assetDescription;
  569. item.Name = assetName;
  570. item.AssetType = assType;
  571. item.InvType = inType;
  572. item.Folder = parentFolder;
  573. // If we set PermissionMask.All then when we rez the item the next permissions will replace the current
  574. // (owner) permissions. This becomes a problem if next permissions are changed.
  575. item.CurrentPermissions
  576. = (uint)(PermissionMask.Move | PermissionMask.Copy | PermissionMask.Modify | PermissionMask.Transfer);
  577. item.BasePermissions = (uint)PermissionMask.All;
  578. item.EveryOnePermissions = 0;
  579. item.NextPermissions = (uint)PermissionMask.All;
  580. item.CreationDate = Util.UnixTimeSinceEpoch();
  581. if (AddNewInventoryItem != null)
  582. {
  583. AddNewInventoryItem(m_HostCapsObj.AgentID, item);
  584. }
  585. }
  586. /// <summary>
  587. ///
  588. /// </summary>
  589. /// <param name="mapReq"></param>
  590. /// <returns></returns>
  591. public LLSDMapLayerResponse GetMapLayer(LLSDMapRequest mapReq)
  592. {
  593. m_log.Debug("[CAPS]: MapLayer Request in region: " + m_regionName);
  594. LLSDMapLayerResponse mapResponse = new LLSDMapLayerResponse();
  595. mapResponse.LayerData.Array.Add(GetOSDMapLayerResponse());
  596. return mapResponse;
  597. }
  598. /// <summary>
  599. ///
  600. /// </summary>
  601. /// <returns></returns>
  602. protected static OSDMapLayer GetOSDMapLayerResponse()
  603. {
  604. OSDMapLayer mapLayer = new OSDMapLayer();
  605. mapLayer.Right = 5000;
  606. mapLayer.Top = 5000;
  607. mapLayer.ImageID = new UUID("00000000-0000-1111-9999-000000000006");
  608. return mapLayer;
  609. }
  610. /// <summary>
  611. ///
  612. /// </summary>
  613. /// <param name="request"></param>
  614. /// <param name="path"></param>
  615. /// <param name="param"></param>
  616. /// <returns></returns>
  617. public string RequestTexture(string request, string path, string param)
  618. {
  619. m_log.Debug("texture request " + request);
  620. // Needs implementing (added to remove compiler warning)
  621. return String.Empty;
  622. }
  623. /// <summary>
  624. /// Called by the notecard update handler. Provides a URL to which the client can upload a new asset.
  625. /// </summary>
  626. /// <param name="request"></param>
  627. /// <param name="path"></param>
  628. /// <param name="param"></param>
  629. /// <returns></returns>
  630. public string NoteCardAgentInventory(string request, string path, string param,
  631. IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
  632. {
  633. //m_log.Debug("[CAPS]: NoteCardAgentInventory Request in region: " + m_regionName + "\n" + request);
  634. //m_log.Debug("[CAPS]: NoteCardAgentInventory Request is: " + request);
  635. //OpenMetaverse.StructuredData.OSDMap hash = (OpenMetaverse.StructuredData.OSDMap)OpenMetaverse.StructuredData.LLSDParser.DeserializeBinary(Utils.StringToBytes(request));
  636. Hashtable hash = (Hashtable)LLSD.LLSDDeserialize(Utils.StringToBytes(request));
  637. LLSDItemUpdate llsdRequest = new LLSDItemUpdate();
  638. LLSDHelpers.DeserialiseOSDMap(hash, llsdRequest);
  639. string capsBase = "/CAPS/" + m_HostCapsObj.CapsObjectPath;
  640. string uploaderPath = Util.RandomClass.Next(5000, 8000).ToString("0000");
  641. ItemUpdater uploader =
  642. new ItemUpdater(llsdRequest.item_id, capsBase + uploaderPath, m_HostCapsObj.HttpListener, m_dumpAssetsToFile);
  643. uploader.OnUpLoad += ItemUpdated;
  644. m_HostCapsObj.HttpListener.AddStreamHandler(
  645. new BinaryStreamHandler(
  646. "POST", capsBase + uploaderPath, uploader.uploaderCaps, "NoteCardAgentInventory", null));
  647. string protocol = "http://";
  648. if (m_HostCapsObj.SSLCaps)
  649. protocol = "https://";
  650. string uploaderURL = protocol + m_HostCapsObj.HostName + ":" + m_HostCapsObj.Port.ToString() + capsBase +
  651. uploaderPath;
  652. LLSDAssetUploadResponse uploadResponse = new LLSDAssetUploadResponse();
  653. uploadResponse.uploader = uploaderURL;
  654. uploadResponse.state = "upload";
  655. // m_log.InfoFormat("[CAPS]: " +
  656. // "NoteCardAgentInventory response: {0}",
  657. // LLSDHelpers.SerialiseLLSDReply(uploadResponse)));
  658. return LLSDHelpers.SerialiseLLSDReply(uploadResponse);
  659. }
  660. /// <summary>
  661. /// Called by the CopyInventoryFromNotecard caps handler.
  662. /// </summary>
  663. /// <param name="request"></param>
  664. /// <param name="path"></param>
  665. /// <param name="param"></param>
  666. public string CopyInventoryFromNotecard(string request, string path, string param,
  667. IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
  668. {
  669. Hashtable response = new Hashtable();
  670. response["int_response_code"] = 404;
  671. response["content_type"] = "text/plain";
  672. response["keepalive"] = false;
  673. response["str_response_string"] = "";
  674. try
  675. {
  676. OSDMap content = (OSDMap)OSDParser.DeserializeLLSDXml(request);
  677. UUID objectID = content["object-id"].AsUUID();
  678. UUID notecardID = content["notecard-id"].AsUUID();
  679. UUID folderID = content["folder-id"].AsUUID();
  680. UUID itemID = content["item-id"].AsUUID();
  681. // m_log.InfoFormat("[CAPS]: CopyInventoryFromNotecard, FolderID:{0}, ItemID:{1}, NotecardID:{2}, ObjectID:{3}", folderID, itemID, notecardID, objectID);
  682. if (objectID != UUID.Zero)
  683. {
  684. SceneObjectPart part = m_Scene.GetSceneObjectPart(objectID);
  685. if (part != null)
  686. {
  687. // TaskInventoryItem taskItem = part.Inventory.GetInventoryItem(notecardID);
  688. if (!m_Scene.Permissions.CanCopyObjectInventory(notecardID, objectID, m_HostCapsObj.AgentID))
  689. {
  690. return LLSDHelpers.SerialiseLLSDReply(response);
  691. }
  692. }
  693. }
  694. InventoryItemBase item = null;
  695. InventoryItemBase copyItem = null;
  696. IClientAPI client = null;
  697. m_Scene.TryGetClient(m_HostCapsObj.AgentID, out client);
  698. item = m_Scene.InventoryService.GetItem(new InventoryItemBase(itemID));
  699. if (item != null)
  700. {
  701. copyItem = m_Scene.GiveInventoryItem(m_HostCapsObj.AgentID, item.Owner, itemID, folderID);
  702. if (copyItem != null && client != null)
  703. {
  704. m_log.InfoFormat("[CAPS]: CopyInventoryFromNotecard, ItemID:{0}, FolderID:{1}", copyItem.ID, copyItem.Folder);
  705. client.SendBulkUpdateInventory(copyItem);
  706. }
  707. }
  708. else
  709. {
  710. m_log.ErrorFormat("[CAPS]: CopyInventoryFromNotecard - Failed to retrieve item {0} from notecard {1}", itemID, notecardID);
  711. if (client != null)
  712. client.SendAlertMessage("Failed to retrieve item");
  713. }
  714. }
  715. catch (Exception e)
  716. {
  717. m_log.ErrorFormat("[CAPS]: CopyInventoryFromNotecard : {0}", e.ToString());
  718. }
  719. response["int_response_code"] = 200;
  720. return LLSDHelpers.SerialiseLLSDReply(response);
  721. }
  722. }
  723. public class AssetUploader
  724. {
  725. public event UpLoadedAsset OnUpLoad;
  726. private UpLoadedAsset handlerUpLoad = null;
  727. private string uploaderPath = String.Empty;
  728. private UUID newAssetID;
  729. private UUID inventoryItemID;
  730. private UUID parentFolder;
  731. private IHttpServer httpListener;
  732. private bool m_dumpAssetsToFile;
  733. private string m_assetName = String.Empty;
  734. private string m_assetDes = String.Empty;
  735. private string m_invType = String.Empty;
  736. private string m_assetType = String.Empty;
  737. public AssetUploader(string assetName, string description, UUID assetID, UUID inventoryItem,
  738. UUID parentFolderID, string invType, string assetType, string path,
  739. IHttpServer httpServer, bool dumpAssetsToFile)
  740. {
  741. m_assetName = assetName;
  742. m_assetDes = description;
  743. newAssetID = assetID;
  744. inventoryItemID = inventoryItem;
  745. uploaderPath = path;
  746. httpListener = httpServer;
  747. parentFolder = parentFolderID;
  748. m_assetType = assetType;
  749. m_invType = invType;
  750. m_dumpAssetsToFile = dumpAssetsToFile;
  751. }
  752. /// <summary>
  753. /// Handle raw asset upload data via the capability.
  754. /// </summary>
  755. /// <param name="data"></param>
  756. /// <param name="path"></param>
  757. /// <param name="param"></param>
  758. /// <returns></returns>
  759. public string uploaderCaps(byte[] data, string path, string param)
  760. {
  761. UUID inv = inventoryItemID;
  762. string res = String.Empty;
  763. LLSDAssetUploadComplete uploadComplete = new LLSDAssetUploadComplete();
  764. uploadComplete.new_asset = newAssetID.ToString();
  765. uploadComplete.new_inventory_item = inv;
  766. uploadComplete.state = "complete";
  767. res = LLSDHelpers.SerialiseLLSDReply(uploadComplete);
  768. httpListener.RemoveStreamHandler("POST", uploaderPath);
  769. // TODO: probably make this a better set of extensions here
  770. string extension = ".jp2";
  771. if (m_invType != "image")
  772. {
  773. extension = ".dat";
  774. }
  775. if (m_dumpAssetsToFile)
  776. {
  777. SaveAssetToFile(m_assetName + extension, data);
  778. }
  779. handlerUpLoad = OnUpLoad;
  780. if (handlerUpLoad != null)
  781. {
  782. handlerUpLoad(m_assetName, m_assetDes, newAssetID, inv, parentFolder, data, m_invType, m_assetType);
  783. }
  784. return res;
  785. }
  786. ///Left this in and commented in case there are unforseen issues
  787. //private void SaveAssetToFile(string filename, byte[] data)
  788. //{
  789. // FileStream fs = File.Create(filename);
  790. // BinaryWriter bw = new BinaryWriter(fs);
  791. // bw.Write(data);
  792. // bw.Close();
  793. // fs.Close();
  794. //}
  795. private static void SaveAssetToFile(string filename, byte[] data)
  796. {
  797. string assetPath = "UserAssets";
  798. if (!Directory.Exists(assetPath))
  799. {
  800. Directory.CreateDirectory(assetPath);
  801. }
  802. FileStream fs = File.Create(Path.Combine(assetPath, Util.safeFileName(filename)));
  803. BinaryWriter bw = new BinaryWriter(fs);
  804. bw.Write(data);
  805. bw.Close();
  806. fs.Close();
  807. }
  808. }
  809. /// <summary>
  810. /// This class is a callback invoked when a client sends asset data to
  811. /// an agent inventory notecard update url
  812. /// </summary>
  813. public class ItemUpdater
  814. {
  815. public event UpdateItem OnUpLoad;
  816. private UpdateItem handlerUpdateItem = null;
  817. private string uploaderPath = String.Empty;
  818. private UUID inventoryItemID;
  819. private IHttpServer httpListener;
  820. private bool m_dumpAssetToFile;
  821. public ItemUpdater(UUID inventoryItem, string path, IHttpServer httpServer, bool dumpAssetToFile)
  822. {
  823. m_dumpAssetToFile = dumpAssetToFile;
  824. inventoryItemID = inventoryItem;
  825. uploaderPath = path;
  826. httpListener = httpServer;
  827. }
  828. /// <summary>
  829. /// Handle raw uploaded asset data.
  830. /// </summary>
  831. /// <param name="data"></param>
  832. /// <param name="path"></param>
  833. /// <param name="param"></param>
  834. /// <returns></returns>
  835. public string uploaderCaps(byte[] data, string path, string param)
  836. {
  837. UUID inv = inventoryItemID;
  838. string res = String.Empty;
  839. LLSDAssetUploadComplete uploadComplete = new LLSDAssetUploadComplete();
  840. UUID assetID = UUID.Zero;
  841. handlerUpdateItem = OnUpLoad;
  842. if (handlerUpdateItem != null)
  843. {
  844. assetID = handlerUpdateItem(inv, data);
  845. }
  846. uploadComplete.new_asset = assetID.ToString();
  847. uploadComplete.new_inventory_item = inv;
  848. uploadComplete.state = "complete";
  849. res = LLSDHelpers.SerialiseLLSDReply(uploadComplete);
  850. httpListener.RemoveStreamHandler("POST", uploaderPath);
  851. if (m_dumpAssetToFile)
  852. {
  853. SaveAssetToFile("updateditem" + Util.RandomClass.Next(1, 1000) + ".dat", data);
  854. }
  855. return res;
  856. }
  857. ///Left this in and commented in case there are unforseen issues
  858. //private void SaveAssetToFile(string filename, byte[] data)
  859. //{
  860. // FileStream fs = File.Create(filename);
  861. // BinaryWriter bw = new BinaryWriter(fs);
  862. // bw.Write(data);
  863. // bw.Close();
  864. // fs.Close();
  865. //}
  866. private static void SaveAssetToFile(string filename, byte[] data)
  867. {
  868. string assetPath = "UserAssets";
  869. if (!Directory.Exists(assetPath))
  870. {
  871. Directory.CreateDirectory(assetPath);
  872. }
  873. FileStream fs = File.Create(Path.Combine(assetPath, filename));
  874. BinaryWriter bw = new BinaryWriter(fs);
  875. bw.Write(data);
  876. bw.Close();
  877. fs.Close();
  878. }
  879. }
  880. /// <summary>
  881. /// This class is a callback invoked when a client sends asset data to
  882. /// a task inventory script update url
  883. /// </summary>
  884. public class TaskInventoryScriptUpdater
  885. {
  886. private static readonly ILog m_log =
  887. LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  888. public event UpdateTaskScript OnUpLoad;
  889. private UpdateTaskScript handlerUpdateTaskScript = null;
  890. private string uploaderPath = String.Empty;
  891. private UUID inventoryItemID;
  892. private UUID primID;
  893. private bool isScriptRunning;
  894. private IHttpServer httpListener;
  895. private bool m_dumpAssetToFile;
  896. public TaskInventoryScriptUpdater(UUID inventoryItemID, UUID primID, int isScriptRunning,
  897. string path, IHttpServer httpServer, bool dumpAssetToFile)
  898. {
  899. m_dumpAssetToFile = dumpAssetToFile;
  900. this.inventoryItemID = inventoryItemID;
  901. this.primID = primID;
  902. // This comes in over the packet as an integer, but actually appears to be treated as a bool
  903. this.isScriptRunning = (0 == isScriptRunning ? false : true);
  904. uploaderPath = path;
  905. httpListener = httpServer;
  906. }
  907. /// <summary>
  908. ///
  909. /// </summary>
  910. /// <param name="data"></param>
  911. /// <param name="path"></param>
  912. /// <param name="param"></param>
  913. /// <returns></returns>
  914. public string uploaderCaps(byte[] data, string path, string param)
  915. {
  916. try
  917. {
  918. // m_log.InfoFormat("[CAPS]: " +
  919. // "TaskInventoryScriptUpdater received data: {0}, path: {1}, param: {2}",
  920. // data, path, param));
  921. string res = String.Empty;
  922. LLSDTaskScriptUploadComplete uploadComplete = new LLSDTaskScriptUploadComplete();
  923. ArrayList errors = new ArrayList();
  924. handlerUpdateTaskScript = OnUpLoad;
  925. if (handlerUpdateTaskScript != null)
  926. {
  927. handlerUpdateTaskScript(inventoryItemID, primID, isScriptRunning, data, ref errors);
  928. }
  929. uploadComplete.new_asset = inventoryItemID;
  930. uploadComplete.compiled = errors.Count > 0 ? false : true;
  931. uploadComplete.state = "complete";
  932. uploadComplete.errors = new OpenSim.Framework.Capabilities.OSDArray();
  933. uploadComplete.errors.Array = errors;
  934. res = LLSDHelpers.SerialiseLLSDReply(uploadComplete);
  935. httpListener.RemoveStreamHandler("POST", uploaderPath);
  936. if (m_dumpAssetToFile)
  937. {
  938. SaveAssetToFile("updatedtaskscript" + Util.RandomClass.Next(1, 1000) + ".dat", data);
  939. }
  940. // m_log.InfoFormat("[CAPS]: TaskInventoryScriptUpdater.uploaderCaps res: {0}", res);
  941. return res;
  942. }
  943. catch (Exception e)
  944. {
  945. m_log.Error("[CAPS]: " + e.ToString());
  946. }
  947. // XXX Maybe this should be some meaningful error packet
  948. return null;
  949. }
  950. ///Left this in and commented in case there are unforseen issues
  951. //private void SaveAssetToFile(string filename, byte[] data)
  952. //{
  953. // FileStream fs = File.Create(filename);
  954. // BinaryWriter bw = new BinaryWriter(fs);
  955. // bw.Write(data);
  956. // bw.Close();
  957. // fs.Close();
  958. //}
  959. private static void SaveAssetToFile(string filename, byte[] data)
  960. {
  961. string assetPath = "UserAssets";
  962. if (!Directory.Exists(assetPath))
  963. {
  964. Directory.CreateDirectory(assetPath);
  965. }
  966. FileStream fs = File.Create(Path.Combine(assetPath, filename));
  967. BinaryWriter bw = new BinaryWriter(fs);
  968. bw.Write(data);
  969. bw.Close();
  970. fs.Close();
  971. }
  972. }
  973. }