EstateChangeInfo.cs 7.4 KB

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