AttachmentsCommandModule.cs 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  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", sp.Name);
  127. ConsoleDisplayTable ct = new ConsoleDisplayTable() { Indent = 2 };
  128. ct.Columns.Add(new ConsoleDisplayTableColumn("Attachment Name", 50));
  129. ct.Columns.Add(new ConsoleDisplayTableColumn("Local ID", 10));
  130. ct.Columns.Add(new ConsoleDisplayTableColumn("Item ID", 36));
  131. ct.Columns.Add(new ConsoleDisplayTableColumn("Attach Point", 14));
  132. ct.Columns.Add(new ConsoleDisplayTableColumn("Position", 15));
  133. // sb.AppendFormat(
  134. // " {0,-36} {1,-10} {2,-36} {3,-14} {4,-15}\n",
  135. // "Attachment Name", "Local ID", "Item ID", "Attach Point", "Position");
  136. List<SceneObjectGroup> attachmentObjects = sp.GetAttachments();
  137. foreach (SceneObjectGroup attachmentObject in attachmentObjects)
  138. {
  139. // InventoryItemBase attachmentItem
  140. // = m_scenes[0].InventoryService.GetItem(new InventoryItemBase(attachmentObject.FromItemID));
  141. // if (attachmentItem == null)
  142. // {
  143. // sb.AppendFormat(
  144. // "WARNING: Couldn't find attachment for item {0} at point {1}\n",
  145. // attachmentData.ItemID, (AttachmentPoint)attachmentData.AttachPoint);
  146. // continue;
  147. // }
  148. // else
  149. // {
  150. // sb.AppendFormat(
  151. // " {0,-36} {1,-10} {2,-36} {3,-14} {4,-15}\n",
  152. // attachmentObject.Name, attachmentObject.LocalId, attachmentObject.FromItemID,
  153. // (AttachmentPoint)attachmentObject.AttachmentPoint, attachmentObject.RootPart.AttachedPos);
  154. ct.Rows.Add(
  155. new ConsoleDisplayTableRow(
  156. new List<string>()
  157. {
  158. attachmentObject.Name,
  159. attachmentObject.LocalId.ToString(),
  160. attachmentObject.FromItemID.ToString(),
  161. ((AttachmentPoint)attachmentObject.AttachmentPoint).ToString(),
  162. attachmentObject.RootPart.AttachedPos.ToString()
  163. }));
  164. // }
  165. }
  166. ct.AddToStringBuilder(sb);
  167. sb.Append("\n");
  168. }
  169. }
  170. }