AttachmentsCommandModule.cs 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  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. /// <summary>
  45. /// A module that just holds commands for inspecting avatar appearance.
  46. /// </summary>
  47. [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "AttachmentsCommandModule")]
  48. public class AttachmentsCommandModule : ISharedRegionModule
  49. {
  50. // private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  51. private List<Scene> m_scenes = new List<Scene>();
  52. // private IAvatarFactoryModule m_avatarFactory;
  53. public string Name { get { return "Attachments Command Module"; } }
  54. public Type ReplaceableInterface { get { return null; } }
  55. public void Initialise(IConfigSource source)
  56. {
  57. // m_log.DebugFormat("[ATTACHMENTS COMMAND MODULE]: INITIALIZED MODULE");
  58. }
  59. public void PostInitialise()
  60. {
  61. // m_log.DebugFormat("[ATTACHMENTS COMMAND MODULE]: POST INITIALIZED MODULE");
  62. }
  63. public void Close()
  64. {
  65. // m_log.DebugFormat("[ATTACHMENTS COMMAND MODULE]: CLOSED MODULE");
  66. }
  67. public void AddRegion(Scene scene)
  68. {
  69. // m_log.DebugFormat("[ATTACHMENTS COMMAND MODULE]: REGION {0} ADDED", scene.RegionInfo.RegionName);
  70. }
  71. public void RemoveRegion(Scene scene)
  72. {
  73. // m_log.DebugFormat("[ATTACHMENTS COMMAND MODULE]: REGION {0} REMOVED", scene.RegionInfo.RegionName);
  74. lock (m_scenes)
  75. m_scenes.Remove(scene);
  76. }
  77. public void RegionLoaded(Scene scene)
  78. {
  79. // m_log.DebugFormat("[ATTACHMENTS COMMAND MODULE]: REGION {0} LOADED", scene.RegionInfo.RegionName);
  80. lock (m_scenes)
  81. m_scenes.Add(scene);
  82. scene.AddCommand(
  83. "Users", this, "attachments show",
  84. "attachments show [<first-name> <last-name>]",
  85. "Show attachment information for avatars in this simulator.",
  86. "If no name is supplied then information for all avatars is shown.",
  87. HandleShowAttachmentsCommand);
  88. }
  89. protected void HandleShowAttachmentsCommand(string module, string[] cmd)
  90. {
  91. if (cmd.Length != 2 && cmd.Length < 4)
  92. {
  93. MainConsole.Instance.OutputFormat("Usage: attachments show [<first-name> <last-name>]");
  94. return;
  95. }
  96. bool targetNameSupplied = false;
  97. string optionalTargetFirstName = null;
  98. string optionalTargetLastName = null;
  99. if (cmd.Length >= 4)
  100. {
  101. targetNameSupplied = true;
  102. optionalTargetFirstName = cmd[2];
  103. optionalTargetLastName = cmd[3];
  104. }
  105. StringBuilder sb = new StringBuilder();
  106. lock (m_scenes)
  107. {
  108. foreach (Scene scene in m_scenes)
  109. {
  110. if (targetNameSupplied)
  111. {
  112. ScenePresence sp = scene.GetScenePresence(optionalTargetFirstName, optionalTargetLastName);
  113. if (sp != null && !sp.IsChildAgent)
  114. GetAttachmentsReport(sp, sb);
  115. }
  116. else
  117. {
  118. scene.ForEachRootScenePresence(sp => GetAttachmentsReport(sp, sb));
  119. }
  120. }
  121. }
  122. MainConsole.Instance.Output(sb.ToString());
  123. }
  124. private void GetAttachmentsReport(ScenePresence sp, StringBuilder sb)
  125. {
  126. sb.AppendFormat("Attachments for {0}\n\n", sp.Name);
  127. ConsoleDisplayList ct = new ConsoleDisplayList();
  128. // sb.AppendFormat(
  129. // " {0,-36} {1,-10} {2,-36} {3,-14} {4,-15}\n",
  130. // "Attachment Name", "Local ID", "Item ID", "Attach Point", "Position");
  131. List<SceneObjectGroup> attachmentObjects = sp.GetAttachments();
  132. foreach (SceneObjectGroup attachmentObject in attachmentObjects)
  133. {
  134. // InventoryItemBase attachmentItem
  135. // = m_scenes[0].InventoryService.GetItem(new InventoryItemBase(attachmentObject.FromItemID));
  136. // if (attachmentItem == null)
  137. // {
  138. // sb.AppendFormat(
  139. // "WARNING: Couldn't find attachment for item {0} at point {1}\n",
  140. // attachmentData.ItemID, (AttachmentPoint)attachmentData.AttachPoint);
  141. // continue;
  142. // }
  143. // else
  144. // {
  145. // sb.AppendFormat(
  146. // " {0,-36} {1,-10} {2,-36} {3,-14} {4,-15}\n",
  147. // attachmentObject.Name, attachmentObject.LocalId, attachmentObject.FromItemID,
  148. // (AttachmentPoint)attachmentObject.AttachmentPoint, attachmentObject.RootPart.AttachedPos);
  149. ct.Indent = 2;
  150. ct.AddRow("Attachment Name", attachmentObject.Name);
  151. ct.AddRow("Local ID", attachmentObject.LocalId);
  152. ct.AddRow("Item ID", attachmentObject.UUID);
  153. ct.AddRow("From Item ID", attachmentObject.FromItemID);
  154. ct.AddRow("Attach Point", ((AttachmentPoint)attachmentObject.AttachmentPoint));
  155. ct.AddRow("Position", attachmentObject.RootPart.AttachedPos + "\n\n");
  156. // }
  157. }
  158. ct.AddToStringBuilder(sb);
  159. }
  160. }
  161. }