1
0

SimulatorFeaturesModule.cs 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  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.Reflection;
  30. using log4net;
  31. using Nini.Config;
  32. using Mono.Addins;
  33. using OpenMetaverse;
  34. using OpenMetaverse.StructuredData;
  35. using OpenSim.Framework;
  36. using OpenSim.Framework.Servers.HttpServer;
  37. using OpenSim.Region.Framework.Interfaces;
  38. using OpenSim.Region.Framework.Scenes;
  39. using OpenSim.Services.Interfaces;
  40. using Caps = OpenSim.Framework.Capabilities.Caps;
  41. namespace OpenSim.Region.ClientStack.Linden
  42. {
  43. /// <summary>
  44. /// SimulatorFeatures capability.
  45. /// </summary>
  46. /// <remarks>
  47. /// This is required for uploading Mesh.
  48. /// Since is accepts an open-ended response, we also send more information
  49. /// for viewers that care to interpret it.
  50. ///
  51. /// NOTE: Part of this code was adapted from the Aurora project, specifically
  52. /// the normal part of the response in the capability handler.
  53. /// </remarks>
  54. [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule")]
  55. public class SimulatorFeaturesModule : ISharedRegionModule, ISimulatorFeaturesModule
  56. {
  57. // private static readonly ILog m_log =
  58. // LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  59. private Scene m_scene;
  60. /// <summary>
  61. /// Simulator features
  62. /// </summary>
  63. private OSDMap m_features = new OSDMap();
  64. private string m_MapImageServerURL = string.Empty;
  65. private string m_SearchURL = string.Empty;
  66. #region ISharedRegionModule Members
  67. public void Initialise(IConfigSource source)
  68. {
  69. IConfig config = source.Configs["SimulatorFeatures"];
  70. if (config != null)
  71. {
  72. m_MapImageServerURL = config.GetString("MapImageServerURI", string.Empty);
  73. if (m_MapImageServerURL != string.Empty)
  74. {
  75. m_MapImageServerURL = m_MapImageServerURL.Trim();
  76. if (!m_MapImageServerURL.EndsWith("/"))
  77. m_MapImageServerURL = m_MapImageServerURL + "/";
  78. }
  79. m_SearchURL = config.GetString("SearchServerURI", string.Empty);
  80. }
  81. AddDefaultFeatures();
  82. }
  83. public void AddRegion(Scene s)
  84. {
  85. m_scene = s;
  86. m_scene.EventManager.OnRegisterCaps += RegisterCaps;
  87. }
  88. public void RemoveRegion(Scene s)
  89. {
  90. m_scene.EventManager.OnRegisterCaps -= RegisterCaps;
  91. }
  92. public void RegionLoaded(Scene s)
  93. {
  94. }
  95. public void PostInitialise()
  96. {
  97. }
  98. public void Close() { }
  99. public string Name { get { return "SimulatorFeaturesModule"; } }
  100. public Type ReplaceableInterface
  101. {
  102. get { return null; }
  103. }
  104. #endregion
  105. /// <summary>
  106. /// Add default features
  107. /// </summary>
  108. /// <remarks>
  109. /// TODO: These should be added from other modules rather than hardcoded.
  110. /// </remarks>
  111. private void AddDefaultFeatures()
  112. {
  113. lock (m_features)
  114. {
  115. m_features["MeshRezEnabled"] = true;
  116. m_features["MeshUploadEnabled"] = true;
  117. m_features["MeshXferEnabled"] = true;
  118. m_features["PhysicsMaterialsEnabled"] = true;
  119. OSDMap typesMap = new OSDMap();
  120. typesMap["convex"] = true;
  121. typesMap["none"] = true;
  122. typesMap["prim"] = true;
  123. m_features["PhysicsShapeTypes"] = typesMap;
  124. // Extra information for viewers that want to use it
  125. OSDMap gridServicesMap = new OSDMap();
  126. if (m_MapImageServerURL != string.Empty)
  127. gridServicesMap["map-server-url"] = m_MapImageServerURL;
  128. if (m_SearchURL != string.Empty)
  129. gridServicesMap["search"] = m_SearchURL;
  130. m_features["GridServices"] = gridServicesMap;
  131. }
  132. }
  133. public void RegisterCaps(UUID agentID, Caps caps)
  134. {
  135. IRequestHandler reqHandler
  136. = new RestHTTPHandler(
  137. "GET", "/CAPS/" + UUID.Random(),
  138. HandleSimulatorFeaturesRequest, "SimulatorFeatures", agentID.ToString());
  139. caps.RegisterHandler("SimulatorFeatures", reqHandler);
  140. }
  141. public void AddFeature(string name, OSD value)
  142. {
  143. lock (m_features)
  144. m_features[name] = value;
  145. }
  146. public bool RemoveFeature(string name)
  147. {
  148. lock (m_features)
  149. return m_features.Remove(name);
  150. }
  151. public bool TryGetFeature(string name, out OSD value)
  152. {
  153. lock (m_features)
  154. return m_features.TryGetValue(name, out value);
  155. }
  156. public OSDMap GetFeatures()
  157. {
  158. lock (m_features)
  159. return new OSDMap(m_features);
  160. }
  161. private Hashtable HandleSimulatorFeaturesRequest(Hashtable mDhttpMethod)
  162. {
  163. // m_log.DebugFormat("[SIMULATOR FEATURES MODULE]: SimulatorFeatures request");
  164. //Send back data
  165. Hashtable responsedata = new Hashtable();
  166. responsedata["int_response_code"] = 200;
  167. responsedata["content_type"] = "text/plain";
  168. responsedata["keepalive"] = false;
  169. lock (m_features)
  170. responsedata["str_response_string"] = OSDParser.SerializeLLSDXmlString(m_features);
  171. return responsedata;
  172. }
  173. }
  174. }