EstateChangeInfo.cs 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  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.Text;
  31. using System.Reflection;
  32. using log4net;
  33. using Nini.Config;
  34. using OpenMetaverse;
  35. using OpenMetaverse.StructuredData;
  36. using Mono.Addins;
  37. using OpenSim.Framework;
  38. using OpenSim.Framework.Servers.HttpServer;
  39. using OpenSim.Region.Framework.Interfaces;
  40. using OpenSim.Region.Framework.Scenes;
  41. using Caps=OpenSim.Framework.Capabilities.Caps;
  42. namespace OpenSim.Region.ClientStack.Linden
  43. {
  44. [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "EstateChangeInfoCapModule")]
  45. public class EstateChangeInfoCapModule : INonSharedRegionModule
  46. {
  47. private static readonly ILog m_log =
  48. LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  49. private Scene m_scene;
  50. private bool m_Enabled = false;
  51. private string m_capUrl;
  52. IEstateModule m_EstateModule;
  53. #region INonSharedRegionModule Members
  54. public void Initialise(IConfigSource pSource)
  55. {
  56. IConfig config = pSource.Configs["ClientStack.LindenCaps"];
  57. if (config == null)
  58. return;
  59. m_capUrl = config.GetString("Cap_EstateChangeInfo", string.Empty);
  60. if (!String.IsNullOrEmpty(m_capUrl) && m_capUrl.Equals("localhost"))
  61. m_Enabled = true;
  62. }
  63. public void AddRegion(Scene scene)
  64. {
  65. if (!m_Enabled)
  66. return;
  67. m_scene = scene;
  68. }
  69. public void RemoveRegion(Scene scene)
  70. {
  71. if (!m_Enabled)
  72. return;
  73. if (m_scene == scene)
  74. {
  75. m_scene.EventManager.OnRegisterCaps -= RegisterCaps;
  76. m_scene = null;
  77. }
  78. }
  79. public void RegionLoaded(Scene scene)
  80. {
  81. if (!m_Enabled)
  82. return;
  83. if (scene.RegionInfo == null || scene.RegionInfo.EstateSettings == null)
  84. {
  85. m_Enabled = false;
  86. return;
  87. }
  88. m_EstateModule = scene.RequestModuleInterface<IEstateModule>();
  89. if(m_EstateModule == null)
  90. {
  91. m_Enabled = false;
  92. return;
  93. }
  94. scene.EventManager.OnRegisterCaps += RegisterCaps;
  95. }
  96. public void Close()
  97. {
  98. }
  99. public string Name
  100. {
  101. get { return "EstateChangeInfoCapModule"; }
  102. }
  103. public Type ReplaceableInterface
  104. {
  105. get { return null; }
  106. }
  107. #endregion
  108. public void RegisterCaps(UUID agentID, Caps caps)
  109. {
  110. string capUrl = "/CAPS/" + UUID.Random() + "/";
  111. caps.RegisterHandler(
  112. "EstateChangeInfo",
  113. new RestHTTPHandler(
  114. "POST",
  115. capUrl,
  116. httpMethod => ProcessRequest(httpMethod, agentID, caps),
  117. "EstateChangeInfo",
  118. agentID.ToString())); ;
  119. }
  120. public Hashtable ProcessRequest(Hashtable request, UUID AgentId, Caps cap)
  121. {
  122. Hashtable responsedata = new Hashtable();
  123. ScenePresence avatar;
  124. if (!m_scene.TryGetScenePresence(AgentId, out avatar) || !m_scene.Permissions.CanIssueEstateCommand(AgentId, false))
  125. {
  126. responsedata["int_response_code"] = 401;
  127. responsedata["str_response_string"] = LLSDxmlEncode.LLSDEmpty;
  128. responsedata["keepalive"] = false;
  129. return responsedata;
  130. }
  131. if (m_scene.RegionInfo == null
  132. || m_scene.RegionInfo.EstateSettings == null)
  133. {
  134. responsedata["int_response_code"] = 501;
  135. responsedata["str_response_string"] = LLSDxmlEncode.LLSDEmpty;
  136. responsedata["keepalive"] = false;
  137. return responsedata;
  138. }
  139. OSDMap r;
  140. try
  141. {
  142. r = (OSDMap)OSDParser.Deserialize((string)request["requestbody"]);
  143. }
  144. catch (Exception ex)
  145. {
  146. m_log.Error("[UPLOAD OBJECT ASSET MODULE]: Error deserializing message " + ex.ToString());
  147. r = null;
  148. }
  149. if (r == null)
  150. {
  151. responsedata["int_response_code"] = 400; //501; //410; //404;
  152. responsedata["content_type"] = "text/plain";
  153. responsedata["keepalive"] = false;
  154. responsedata["str_response_string"] = LLSDxmlEncode.LLSDEmpty;
  155. return responsedata;
  156. }
  157. bool ok = true;
  158. try
  159. {
  160. string estateName = r["estate_name"].AsString();
  161. UUID invoice = r["invoice"].AsUUID();
  162. int sunHour = r["sun_hour"].AsInteger();
  163. bool sunFixed = r["is_sun_fixed"].AsBoolean();
  164. bool externallyVisible = r["is_externally_visible"].AsBoolean();
  165. bool allowDirectTeleport = r["allow_direct_teleport"].AsBoolean();
  166. bool denyAnonymous = r["deny_anonymous"].AsBoolean();
  167. bool denyAgeUnverified = r["deny_age_unverified"].AsBoolean();
  168. bool alloVoiceChat = r["allow_voice_chat"].AsBoolean();
  169. // taxfree is now AllowAccessOverride
  170. bool overridePublicAccess = m_scene.RegionInfo.EstateSettings.TaxFree;
  171. if (r.ContainsKey("override_public_access"))
  172. overridePublicAccess = r["override_public_access"].AsBoolean();
  173. ok = m_EstateModule.handleEstateChangeInfoCap(estateName, invoice, sunHour, sunFixed,
  174. externallyVisible, allowDirectTeleport, denyAnonymous, denyAgeUnverified,
  175. alloVoiceChat, overridePublicAccess);
  176. }
  177. catch
  178. {
  179. ok = false;
  180. }
  181. if(ok)
  182. {
  183. responsedata["int_response_code"] = 200;
  184. responsedata["content_type"] = "text/plain";
  185. responsedata["str_response_string"] = LLSDxmlEncode.LLSDEmpty;
  186. }
  187. else
  188. {
  189. responsedata["int_response_code"] = 400; //501; //410; //404;
  190. responsedata["content_type"] = "text/plain";
  191. responsedata["keepalive"] = false;
  192. responsedata["str_response_string"] = LLSDxmlEncode.LLSDEmpty;
  193. }
  194. return responsedata;
  195. }
  196. }
  197. }