1
0

AnimationsCommandModule.cs 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  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 OpenSim.Region.Framework.Scenes.Animation;
  43. using OpenSim.Services.Interfaces;
  44. namespace OpenSim.Region.OptionalModules.Avatar.Animations
  45. {
  46. /// <summary>
  47. /// A module that just holds commands for inspecting avatar animations.
  48. /// </summary>
  49. [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "AnimationsCommandModule")]
  50. public class AnimationsCommandModule : ISharedRegionModule
  51. {
  52. // private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  53. private List<Scene> m_scenes = new List<Scene>();
  54. public string Name { get { return "Animations Command Module"; } }
  55. public Type ReplaceableInterface { get { return null; } }
  56. public void Initialise(IConfigSource source)
  57. {
  58. // m_log.DebugFormat("[ANIMATIONS COMMAND MODULE]: INITIALIZED MODULE");
  59. }
  60. public void PostInitialise()
  61. {
  62. // m_log.DebugFormat("[ANIMATIONS COMMAND MODULE]: POST INITIALIZED MODULE");
  63. }
  64. public void Close()
  65. {
  66. // m_log.DebugFormat("[ANIMATIONS COMMAND MODULE]: CLOSED MODULE");
  67. }
  68. public void AddRegion(Scene scene)
  69. {
  70. // m_log.DebugFormat("[ANIMATIONS COMMAND MODULE]: REGION {0} ADDED", scene.RegionInfo.RegionName);
  71. }
  72. public void RemoveRegion(Scene scene)
  73. {
  74. // m_log.DebugFormat("[ATTACHMENTS COMMAND MODULE]: REGION {0} REMOVED", scene.RegionInfo.RegionName);
  75. lock (m_scenes)
  76. m_scenes.Remove(scene);
  77. }
  78. public void RegionLoaded(Scene scene)
  79. {
  80. // m_log.DebugFormat("[ANIMATIONS COMMAND MODULE]: REGION {0} LOADED", scene.RegionInfo.RegionName);
  81. lock (m_scenes)
  82. m_scenes.Add(scene);
  83. scene.AddCommand(
  84. "Users", this, "show animations",
  85. "show animations [<first-name> <last-name>]",
  86. "Show animation information for avatars in this simulator.",
  87. "If no name is supplied then information for all avatars is shown.\n"
  88. + "Please note that for inventory animations, the animation name is the name under which the animation was originally uploaded\n"
  89. + ", which is not necessarily the current inventory name.",
  90. HandleShowAnimationsCommand);
  91. }
  92. protected void HandleShowAnimationsCommand(string module, string[] cmd)
  93. {
  94. if (cmd.Length != 2 && cmd.Length < 4)
  95. {
  96. MainConsole.Instance.OutputFormat("Usage: show animations [<first-name> <last-name>]");
  97. return;
  98. }
  99. bool targetNameSupplied = false;
  100. string optionalTargetFirstName = null;
  101. string optionalTargetLastName = null;
  102. if (cmd.Length >= 4)
  103. {
  104. targetNameSupplied = true;
  105. optionalTargetFirstName = cmd[2];
  106. optionalTargetLastName = cmd[3];
  107. }
  108. StringBuilder sb = new StringBuilder();
  109. lock (m_scenes)
  110. {
  111. foreach (Scene scene in m_scenes)
  112. {
  113. if (targetNameSupplied)
  114. {
  115. ScenePresence sp = scene.GetScenePresence(optionalTargetFirstName, optionalTargetLastName);
  116. if (sp != null && !sp.IsChildAgent)
  117. GetAttachmentsReport(sp, sb);
  118. }
  119. else
  120. {
  121. scene.ForEachRootScenePresence(sp => GetAttachmentsReport(sp, sb));
  122. }
  123. }
  124. }
  125. MainConsole.Instance.Output(sb.ToString());
  126. }
  127. private void GetAttachmentsReport(ScenePresence sp, StringBuilder sb)
  128. {
  129. sb.AppendFormat("Animations for {0}\n", sp.Name);
  130. ConsoleDisplayList cdl = new ConsoleDisplayList() { Indent = 2 };
  131. ScenePresenceAnimator spa = sp.Animator;
  132. AnimationSet anims = sp.Animator.Animations;
  133. string cma = spa.CurrentMovementAnimation;
  134. cdl.AddRow(
  135. "Current movement anim",
  136. string.Format("{0}, {1}", DefaultAvatarAnimations.GetDefaultAnimation(cma), cma));
  137. UUID defaultAnimId = anims.DefaultAnimation.AnimID;
  138. cdl.AddRow(
  139. "Default anim",
  140. string.Format("{0}, {1}", defaultAnimId, sp.Animator.GetAnimName(defaultAnimId)));
  141. UUID implicitDefaultAnimId = anims.ImplicitDefaultAnimation.AnimID;
  142. cdl.AddRow(
  143. "Implicit default anim",
  144. string.Format("{0}, {1}",
  145. implicitDefaultAnimId, sp.Animator.GetAnimName(implicitDefaultAnimId)));
  146. cdl.AddToStringBuilder(sb);
  147. ConsoleDisplayTable cdt = new ConsoleDisplayTable() { Indent = 2 };
  148. cdt.AddColumn("Animation ID", 36);
  149. cdt.AddColumn("Name", 20);
  150. cdt.AddColumn("Seq", 3);
  151. cdt.AddColumn("Object ID", 36);
  152. UUID[] animIds;
  153. int[] sequenceNumbers;
  154. UUID[] objectIds;
  155. sp.Animator.Animations.GetArrays(out animIds, out sequenceNumbers, out objectIds);
  156. for (int i = 0; i < animIds.Length; i++)
  157. {
  158. UUID animId = animIds[i];
  159. string animName = sp.Animator.GetAnimName(animId);
  160. int seq = sequenceNumbers[i];
  161. UUID objectId = objectIds[i];
  162. cdt.AddRow(animId, animName, seq, objectId);
  163. }
  164. cdt.AddToStringBuilder(sb);
  165. sb.Append("\n");
  166. }
  167. }
  168. }