TempAttachmentsModule.cs 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  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.Generic;
  29. using System.Linq;
  30. using System.Reflection;
  31. using System.Text;
  32. using log4net;
  33. using Mono.Addins;
  34. using Nini.Config;
  35. using OpenMetaverse;
  36. using OpenSim.Framework;
  37. using OpenSim.Framework.Console;
  38. using OpenSim.Framework.Monitoring;
  39. using OpenSim.Region.ClientStack.LindenUDP;
  40. using OpenSim.Region.Framework.Interfaces;
  41. using OpenSim.Region.Framework.Scenes;
  42. using PermissionMask = OpenSim.Framework.PermissionMask;
  43. namespace OpenSim.Region.OptionalModules.Avatar.Attachments
  44. {
  45. [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "TempAttachmentsModule")]
  46. public class TempAttachmentsModule : INonSharedRegionModule
  47. {
  48. private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  49. private Scene m_scene;
  50. private IRegionConsole m_console;
  51. public void Initialise(IConfigSource configSource)
  52. {
  53. }
  54. public void AddRegion(Scene scene)
  55. {
  56. }
  57. public void RemoveRegion(Scene scene)
  58. {
  59. }
  60. public void RegionLoaded(Scene scene)
  61. {
  62. m_scene = scene;
  63. IScriptModuleComms comms = scene.RequestModuleInterface<IScriptModuleComms>();
  64. if (comms != null)
  65. {
  66. comms.RegisterScriptInvocation( this, "llAttachToAvatarTemp");
  67. m_log.DebugFormat("[TEMP ATTACHS]: Registered script functions");
  68. m_console = scene.RequestModuleInterface<IRegionConsole>();
  69. if (m_console != null)
  70. {
  71. m_console.AddCommand("TempAttachModule", false, "set auto_grant_attach_perms", "set auto_grant_attach_perms true|false", "Allow objects owned by the region owner or estate managers to obtain attach permissions without asking the user", SetAutoGrantAttachPerms);
  72. }
  73. }
  74. else
  75. {
  76. m_log.ErrorFormat("[TEMP ATTACHS]: Failed to register script functions");
  77. }
  78. }
  79. public void Close()
  80. {
  81. }
  82. public Type ReplaceableInterface
  83. {
  84. get { return null; }
  85. }
  86. public string Name
  87. {
  88. get { return "TempAttachmentsModule"; }
  89. }
  90. private void SendConsoleOutput(UUID agentID, string text)
  91. {
  92. if (m_console == null)
  93. return;
  94. m_console.SendConsoleOutput(agentID, text);
  95. }
  96. private void SetAutoGrantAttachPerms(string module, string[] parms)
  97. {
  98. UUID agentID = new UUID(parms[parms.Length - 1]);
  99. Array.Resize(ref parms, parms.Length - 1);
  100. if (parms.Length != 3)
  101. {
  102. SendConsoleOutput(agentID, "Command parameter error");
  103. return;
  104. }
  105. string val = parms[2];
  106. if (val != "true" && val != "false")
  107. {
  108. SendConsoleOutput(agentID, "Command parameter error");
  109. return;
  110. }
  111. m_scene.StoreExtraSetting("auto_grant_attach_perms", val);
  112. SendConsoleOutput(agentID, String.Format("auto_grant_attach_perms set to {0}", val));
  113. }
  114. private int llAttachToAvatarTemp(UUID host, UUID script, int attachmentPoint)
  115. {
  116. SceneObjectPart hostPart = m_scene.GetSceneObjectPart(host);
  117. if (hostPart == null)
  118. return 0;
  119. if (hostPart.ParentGroup.IsAttachment)
  120. return 0;
  121. IAttachmentsModule attachmentsModule = m_scene.RequestModuleInterface<IAttachmentsModule>();
  122. if (attachmentsModule == null)
  123. return 0;
  124. TaskInventoryItem item = hostPart.Inventory.GetInventoryItem(script);
  125. if (item == null)
  126. return 0;
  127. if ((item.PermsMask & 32) == 0) // PERMISSION_ATTACH
  128. return 0;
  129. ScenePresence target;
  130. if (!m_scene.TryGetScenePresence(item.PermsGranter, out target))
  131. return 0;
  132. if (target.UUID != hostPart.ParentGroup.OwnerID)
  133. {
  134. uint effectivePerms = hostPart.ParentGroup.GetEffectivePermissions();
  135. if ((effectivePerms & (uint)PermissionMask.Transfer) == 0)
  136. return 0;
  137. hostPart.ParentGroup.SetOwnerId(target.UUID);
  138. hostPart.ParentGroup.SetRootPartOwner(hostPart.ParentGroup.RootPart, target.UUID, target.ControllingClient.ActiveGroupId);
  139. if (m_scene.Permissions.PropagatePermissions())
  140. {
  141. foreach (SceneObjectPart child in hostPart.ParentGroup.Parts)
  142. {
  143. child.Inventory.ChangeInventoryOwner(target.UUID);
  144. child.TriggerScriptChangedEvent(Changed.OWNER);
  145. child.ApplyNextOwnerPermissions();
  146. }
  147. }
  148. hostPart.ParentGroup.RootPart.ObjectSaleType = 0;
  149. hostPart.ParentGroup.RootPart.SalePrice = 10;
  150. hostPart.ParentGroup.HasGroupChanged = true;
  151. hostPart.ParentGroup.RootPart.SendPropertiesToClient(target.ControllingClient);
  152. hostPart.ParentGroup.RootPart.ScheduleFullUpdate();
  153. }
  154. return attachmentsModule.AttachObject(target, hostPart.ParentGroup, (uint)attachmentPoint, false, false, true) ? 1 : 0;
  155. }
  156. }
  157. }