EstateChangeInfo.cs 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  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.Net;
  29. using System.Reflection;
  30. using log4net;
  31. using Nini.Config;
  32. using OpenMetaverse;
  33. using OpenMetaverse.StructuredData;
  34. using Mono.Addins;
  35. using OpenSim.Framework.Servers.HttpServer;
  36. using OpenSim.Region.Framework.Interfaces;
  37. using OpenSim.Region.Framework.Scenes;
  38. using Caps=OpenSim.Framework.Capabilities.Caps;
  39. namespace OpenSim.Region.ClientStack.Linden
  40. {
  41. [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "EstateChangeInfoCapModule")]
  42. public class EstateChangeInfoCapModule : INonSharedRegionModule
  43. {
  44. private static readonly ILog m_log =
  45. LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  46. private Scene m_scene;
  47. private bool m_Enabled = false;
  48. private string m_capUrl;
  49. IEstateModule m_EstateModule;
  50. #region INonSharedRegionModule Members
  51. public void Initialise(IConfigSource pSource)
  52. {
  53. IConfig config = pSource.Configs["ClientStack.LindenCaps"];
  54. if (config == null)
  55. return;
  56. m_capUrl = config.GetString("Cap_EstateChangeInfo", string.Empty);
  57. if (!String.IsNullOrEmpty(m_capUrl) && m_capUrl.Equals("localhost"))
  58. m_Enabled = true;
  59. }
  60. public void AddRegion(Scene scene)
  61. {
  62. if (!m_Enabled)
  63. return;
  64. m_scene = scene;
  65. }
  66. public void RemoveRegion(Scene scene)
  67. {
  68. if (!m_Enabled)
  69. return;
  70. if (m_scene == scene)
  71. {
  72. m_scene.EventManager.OnRegisterCaps -= RegisterCaps;
  73. m_scene = null;
  74. }
  75. }
  76. public void RegionLoaded(Scene scene)
  77. {
  78. if (!m_Enabled)
  79. return;
  80. if (scene.RegionInfo == null || scene.RegionInfo.EstateSettings == null)
  81. {
  82. m_Enabled = false;
  83. return;
  84. }
  85. m_EstateModule = scene.RequestModuleInterface<IEstateModule>();
  86. if(m_EstateModule == null)
  87. {
  88. m_Enabled = false;
  89. return;
  90. }
  91. scene.EventManager.OnRegisterCaps += RegisterCaps;
  92. }
  93. public void Close()
  94. {
  95. }
  96. public string Name
  97. {
  98. get { return "EstateChangeInfoCapModule"; }
  99. }
  100. public Type ReplaceableInterface
  101. {
  102. get { return null; }
  103. }
  104. #endregion
  105. public void RegisterCaps(UUID agentID, Caps caps)
  106. {
  107. caps.RegisterSimpleHandler("EstateChangeInfo",
  108. new SimpleStreamHandler("/" + UUID.Random(), delegate (IOSHttpRequest httpRequest, IOSHttpResponse httpResponse)
  109. {
  110. ProcessRequest(httpRequest, httpResponse, agentID, caps);
  111. }));
  112. }
  113. public void ProcessRequest(IOSHttpRequest request, IOSHttpResponse response, UUID AgentId, Caps cap)
  114. {
  115. if(request.HttpMethod != "POST")
  116. {
  117. response.StatusCode = (int)HttpStatusCode.NotFound;
  118. return;
  119. }
  120. if (!m_scene.TryGetScenePresence(AgentId, out ScenePresence _) || !m_scene.Permissions.CanIssueEstateCommand(AgentId, false))
  121. {
  122. response.StatusCode = (int)HttpStatusCode.Unauthorized;
  123. return;
  124. }
  125. if (m_scene.RegionInfo == null || m_scene.RegionInfo.EstateSettings == null)
  126. {
  127. response.StatusCode = (int)HttpStatusCode.NotImplemented;
  128. return;
  129. }
  130. OSDMap r;
  131. try
  132. {
  133. r = (OSDMap)OSDParser.Deserialize(request.InputStream);
  134. }
  135. catch (Exception ex)
  136. {
  137. m_log.Error("[UPLOAD OBJECT ASSET MODULE]: Error deserializing message " + ex.ToString());
  138. response.StatusCode = (int)HttpStatusCode.BadRequest;
  139. return;
  140. }
  141. bool ok = true;
  142. try
  143. {
  144. string estateName = r["estate_name"].AsString();
  145. UUID invoice = r["invoice"].AsUUID();
  146. //int sunHour = r["sun_hour"].AsInteger();
  147. //bool sunFixed = r["is_sun_fixed"].AsBoolean();
  148. bool externallyVisible = r["is_externally_visible"].AsBoolean();
  149. bool allowDirectTeleport = r["allow_direct_teleport"].AsBoolean();
  150. bool denyAnonymous = r["deny_anonymous"].AsBoolean();
  151. bool denyAgeUnverified = r["deny_age_unverified"].AsBoolean();
  152. bool alloVoiceChat = r["allow_voice_chat"].AsBoolean();
  153. // taxfree is now !AllowAccessOverride
  154. OSD tmp;
  155. bool overridePublicAccess = !m_scene.RegionInfo.EstateSettings.TaxFree;
  156. if (r.TryGetValue("override_public_access", out tmp))
  157. overridePublicAccess = !tmp.AsBoolean();
  158. bool allowEnvironmentOverride = m_scene.RegionInfo.EstateSettings.AllowEnvironmentOverride;
  159. if (r.TryGetValue("override_environment", out tmp))
  160. allowEnvironmentOverride = tmp.AsBoolean();
  161. ok = m_EstateModule.handleEstateChangeInfoCap(estateName, invoice,
  162. externallyVisible, allowDirectTeleport, denyAnonymous, denyAgeUnverified,
  163. alloVoiceChat, overridePublicAccess, allowEnvironmentOverride);
  164. }
  165. catch
  166. {
  167. ok = false;
  168. }
  169. response.StatusCode = ok ? (int)HttpStatusCode.OK : (int)HttpStatusCode.BadRequest;
  170. }
  171. }
  172. }