AttachmentsCommandModule.cs 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  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. HandleShowAttachmentsCommand);
  87. }
  88. protected void HandleShowAttachmentsCommand(string module, string[] cmd)
  89. {
  90. if (cmd.Length != 2 && cmd.Length < 4)
  91. {
  92. MainConsole.Instance.OutputFormat("Usage: attachments show [<first-name> <last-name>]");
  93. return;
  94. }
  95. bool targetNameSupplied = false;
  96. string optionalTargetFirstName = null;
  97. string optionalTargetLastName = null;
  98. if (cmd.Length >= 4)
  99. {
  100. targetNameSupplied = true;
  101. optionalTargetFirstName = cmd[2];
  102. optionalTargetLastName = cmd[3];
  103. }
  104. StringBuilder sb = new StringBuilder();
  105. lock (m_scenes)
  106. {
  107. foreach (Scene scene in m_scenes)
  108. {
  109. if (targetNameSupplied)
  110. {
  111. ScenePresence sp = scene.GetScenePresence(optionalTargetFirstName, optionalTargetLastName);
  112. if (sp != null && !sp.IsChildAgent)
  113. GetAttachmentsReport(sp, sb);
  114. }
  115. else
  116. {
  117. scene.ForEachRootScenePresence(sp => GetAttachmentsReport(sp, sb));
  118. }
  119. }
  120. }
  121. MainConsole.Instance.Output(sb.ToString());
  122. }
  123. private void GetAttachmentsReport(ScenePresence sp, StringBuilder sb)
  124. {
  125. sb.AppendFormat("Attachments for {0}\n", sp.Name);
  126. ConsoleDisplayTable ct = new ConsoleDisplayTable() { Indent = 2 };
  127. ct.Columns.Add(new ConsoleDisplayTableColumn("Attachment Name", 50));
  128. ct.Columns.Add(new ConsoleDisplayTableColumn("Local ID", 10));
  129. ct.Columns.Add(new ConsoleDisplayTableColumn("Item ID", 36));
  130. ct.Columns.Add(new ConsoleDisplayTableColumn("Attach Point", 14));
  131. ct.Columns.Add(new ConsoleDisplayTableColumn("Position", 15));
  132. // sb.AppendFormat(
  133. // " {0,-36} {1,-10} {2,-36} {3,-14} {4,-15}\n",
  134. // "Attachment Name", "Local ID", "Item ID", "Attach Point", "Position");
  135. List<SceneObjectGroup> attachmentObjects = sp.GetAttachments();
  136. foreach (SceneObjectGroup attachmentObject in attachmentObjects)
  137. {
  138. // InventoryItemBase attachmentItem
  139. // = m_scenes[0].InventoryService.GetItem(new InventoryItemBase(attachmentObject.FromItemID));
  140. // if (attachmentItem == null)
  141. // {
  142. // sb.AppendFormat(
  143. // "WARNING: Couldn't find attachment for item {0} at point {1}\n",
  144. // attachmentData.ItemID, (AttachmentPoint)attachmentData.AttachPoint);
  145. // continue;
  146. // }
  147. // else
  148. // {
  149. // sb.AppendFormat(
  150. // " {0,-36} {1,-10} {2,-36} {3,-14} {4,-15}\n",
  151. // attachmentObject.Name, attachmentObject.LocalId, attachmentObject.FromItemID,
  152. // (AttachmentPoint)attachmentObject.AttachmentPoint, attachmentObject.RootPart.AttachedPos);
  153. ct.Rows.Add(
  154. new ConsoleDisplayTableRow(
  155. new List<string>()
  156. {
  157. attachmentObject.Name,
  158. attachmentObject.LocalId.ToString(),
  159. attachmentObject.FromItemID.ToString(),
  160. ((AttachmentPoint)attachmentObject.AttachmentPoint).ToString(),
  161. attachmentObject.RootPart.AttachedPos.ToString()
  162. }));
  163. // }
  164. }
  165. ct.AddToStringBuilder(sb);
  166. sb.Append("\n");
  167. }
  168. }
  169. }