TempAttachmentsModule.cs 7.0 KB

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