1
0

GetMeshHandler.cs 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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.Specialized;
  30. using System.Reflection;
  31. using System.IO;
  32. using System.Web;
  33. using log4net;
  34. using Nini.Config;
  35. using OpenMetaverse;
  36. using OpenMetaverse.StructuredData;
  37. using OpenSim.Framework;
  38. using OpenSim.Framework.Servers;
  39. using OpenSim.Framework.Servers.HttpServer;
  40. using OpenSim.Services.Interfaces;
  41. using Caps = OpenSim.Framework.Capabilities.Caps;
  42. namespace OpenSim.Capabilities.Handlers
  43. {
  44. public class GetMeshHandler
  45. {
  46. // private static readonly ILog m_log =
  47. // LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  48. private IAssetService m_assetService;
  49. public GetMeshHandler(IAssetService assService)
  50. {
  51. m_assetService = assService;
  52. }
  53. public Hashtable ProcessGetMesh(Hashtable request, UUID AgentId, Caps cap)
  54. {
  55. Hashtable responsedata = new Hashtable();
  56. responsedata["int_response_code"] = 400; //501; //410; //404;
  57. responsedata["content_type"] = "text/plain";
  58. responsedata["keepalive"] = false;
  59. responsedata["str_response_string"] = "Request wasn't what was expected";
  60. string meshStr = string.Empty;
  61. if (request.ContainsKey("mesh_id"))
  62. meshStr = request["mesh_id"].ToString();
  63. UUID meshID = UUID.Zero;
  64. if (!String.IsNullOrEmpty(meshStr) && UUID.TryParse(meshStr, out meshID))
  65. {
  66. if (m_assetService == null)
  67. {
  68. responsedata["int_response_code"] = 404; //501; //410; //404;
  69. responsedata["content_type"] = "text/plain";
  70. responsedata["keepalive"] = false;
  71. responsedata["str_response_string"] = "The asset service is unavailable. So is your mesh.";
  72. return responsedata;
  73. }
  74. AssetBase mesh = m_assetService.Get(meshID.ToString());
  75. if (mesh != null)
  76. {
  77. if (mesh.Type == (SByte)AssetType.Mesh)
  78. {
  79. responsedata["str_response_string"] = Convert.ToBase64String(mesh.Data);
  80. responsedata["content_type"] = "application/vnd.ll.mesh";
  81. responsedata["int_response_code"] = 200;
  82. }
  83. // Optionally add additional mesh types here
  84. else
  85. {
  86. responsedata["int_response_code"] = 404; //501; //410; //404;
  87. responsedata["content_type"] = "text/plain";
  88. responsedata["keepalive"] = false;
  89. responsedata["str_response_string"] = "Unfortunately, this asset isn't a mesh.";
  90. return responsedata;
  91. }
  92. }
  93. else
  94. {
  95. responsedata["int_response_code"] = 404; //501; //410; //404;
  96. responsedata["content_type"] = "text/plain";
  97. responsedata["keepalive"] = false;
  98. responsedata["str_response_string"] = "Your Mesh wasn't found. Sorry!";
  99. return responsedata;
  100. }
  101. }
  102. return responsedata;
  103. }
  104. }
  105. }