diff options
Diffstat (limited to 'OpenSim/Region/OptionalModules/Avatar/Animations/AnimationsCommandModule.cs')
-rw-r--r-- | OpenSim/Region/OptionalModules/Avatar/Animations/AnimationsCommandModule.cs | 200 |
1 files changed, 200 insertions, 0 deletions
diff --git a/OpenSim/Region/OptionalModules/Avatar/Animations/AnimationsCommandModule.cs b/OpenSim/Region/OptionalModules/Avatar/Animations/AnimationsCommandModule.cs new file mode 100644 index 0000000..84211a9 --- /dev/null +++ b/OpenSim/Region/OptionalModules/Avatar/Animations/AnimationsCommandModule.cs | |||
@@ -0,0 +1,200 @@ | |||
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 | |||
28 | using System; | ||
29 | using System.Collections.Generic; | ||
30 | using System.Linq; | ||
31 | using System.Reflection; | ||
32 | using System.Text; | ||
33 | using log4net; | ||
34 | using Mono.Addins; | ||
35 | using Nini.Config; | ||
36 | using OpenMetaverse; | ||
37 | using OpenSim.Framework; | ||
38 | using OpenSim.Framework.Console; | ||
39 | using OpenSim.Framework.Monitoring; | ||
40 | using OpenSim.Region.ClientStack.LindenUDP; | ||
41 | using OpenSim.Region.Framework.Interfaces; | ||
42 | using OpenSim.Region.Framework.Scenes; | ||
43 | using OpenSim.Region.Framework.Scenes.Animation; | ||
44 | using OpenSim.Services.Interfaces; | ||
45 | |||
46 | namespace OpenSim.Region.OptionalModules.Avatar.Animations | ||
47 | { | ||
48 | /// <summary> | ||
49 | /// A module that just holds commands for inspecting avatar animations. | ||
50 | /// </summary> | ||
51 | [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "AnimationsCommandModule")] | ||
52 | public class AnimationsCommandModule : ISharedRegionModule | ||
53 | { | ||
54 | // private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
55 | |||
56 | private List<Scene> m_scenes = new List<Scene>(); | ||
57 | |||
58 | public string Name { get { return "Animations Command Module"; } } | ||
59 | |||
60 | public Type ReplaceableInterface { get { return null; } } | ||
61 | |||
62 | public void Initialise(IConfigSource source) | ||
63 | { | ||
64 | // m_log.DebugFormat("[ANIMATIONS COMMAND MODULE]: INITIALIZED MODULE"); | ||
65 | } | ||
66 | |||
67 | public void PostInitialise() | ||
68 | { | ||
69 | // m_log.DebugFormat("[ANIMATIONS COMMAND MODULE]: POST INITIALIZED MODULE"); | ||
70 | } | ||
71 | |||
72 | public void Close() | ||
73 | { | ||
74 | // m_log.DebugFormat("[ANIMATIONS COMMAND MODULE]: CLOSED MODULE"); | ||
75 | } | ||
76 | |||
77 | public void AddRegion(Scene scene) | ||
78 | { | ||
79 | // m_log.DebugFormat("[ANIMATIONS COMMAND MODULE]: REGION {0} ADDED", scene.RegionInfo.RegionName); | ||
80 | } | ||
81 | |||
82 | public void RemoveRegion(Scene scene) | ||
83 | { | ||
84 | // m_log.DebugFormat("[ATTACHMENTS COMMAND MODULE]: REGION {0} REMOVED", scene.RegionInfo.RegionName); | ||
85 | |||
86 | lock (m_scenes) | ||
87 | m_scenes.Remove(scene); | ||
88 | } | ||
89 | |||
90 | public void RegionLoaded(Scene scene) | ||
91 | { | ||
92 | // m_log.DebugFormat("[ANIMATIONS COMMAND MODULE]: REGION {0} LOADED", scene.RegionInfo.RegionName); | ||
93 | |||
94 | lock (m_scenes) | ||
95 | m_scenes.Add(scene); | ||
96 | |||
97 | scene.AddCommand( | ||
98 | "Users", this, "show animations", | ||
99 | "show animations [<first-name> <last-name>]", | ||
100 | "Show animation information for avatars in this simulator.", | ||
101 | "If no name is supplied then information for all avatars is shown.\n" | ||
102 | + "Please note that for inventory animations, the animation name is the name under which the animation was originally uploaded\n" | ||
103 | + ", which is not necessarily the current inventory name.", | ||
104 | HandleShowAnimationsCommand); | ||
105 | } | ||
106 | |||
107 | protected void HandleShowAnimationsCommand(string module, string[] cmd) | ||
108 | { | ||
109 | if (cmd.Length != 2 && cmd.Length < 4) | ||
110 | { | ||
111 | MainConsole.Instance.OutputFormat("Usage: show animations [<first-name> <last-name>]"); | ||
112 | return; | ||
113 | } | ||
114 | |||
115 | bool targetNameSupplied = false; | ||
116 | string optionalTargetFirstName = null; | ||
117 | string optionalTargetLastName = null; | ||
118 | |||
119 | if (cmd.Length >= 4) | ||
120 | { | ||
121 | targetNameSupplied = true; | ||
122 | optionalTargetFirstName = cmd[2]; | ||
123 | optionalTargetLastName = cmd[3]; | ||
124 | } | ||
125 | |||
126 | StringBuilder sb = new StringBuilder(); | ||
127 | |||
128 | lock (m_scenes) | ||
129 | { | ||
130 | foreach (Scene scene in m_scenes) | ||
131 | { | ||
132 | if (targetNameSupplied) | ||
133 | { | ||
134 | ScenePresence sp = scene.GetScenePresence(optionalTargetFirstName, optionalTargetLastName); | ||
135 | if (sp != null && !sp.IsChildAgent) | ||
136 | GetAttachmentsReport(sp, sb); | ||
137 | } | ||
138 | else | ||
139 | { | ||
140 | scene.ForEachRootScenePresence(sp => GetAttachmentsReport(sp, sb)); | ||
141 | } | ||
142 | } | ||
143 | } | ||
144 | |||
145 | MainConsole.Instance.Output(sb.ToString()); | ||
146 | } | ||
147 | |||
148 | private void GetAttachmentsReport(ScenePresence sp, StringBuilder sb) | ||
149 | { | ||
150 | sb.AppendFormat("Animations for {0}\n", sp.Name); | ||
151 | |||
152 | ConsoleDisplayList cdl = new ConsoleDisplayList() { Indent = 2 }; | ||
153 | ScenePresenceAnimator spa = sp.Animator; | ||
154 | AnimationSet anims = sp.Animator.Animations; | ||
155 | |||
156 | string cma = spa.CurrentMovementAnimation; | ||
157 | cdl.AddRow( | ||
158 | "Current movement anim", | ||
159 | string.Format("{0}, {1}", DefaultAvatarAnimations.GetDefaultAnimation(cma), cma)); | ||
160 | |||
161 | UUID defaultAnimId = anims.DefaultAnimation.AnimID; | ||
162 | cdl.AddRow( | ||
163 | "Default anim", | ||
164 | string.Format("{0}, {1}", defaultAnimId, sp.Animator.GetAnimName(defaultAnimId))); | ||
165 | |||
166 | UUID implicitDefaultAnimId = anims.ImplicitDefaultAnimation.AnimID; | ||
167 | cdl.AddRow( | ||
168 | "Implicit default anim", | ||
169 | string.Format("{0}, {1}", | ||
170 | implicitDefaultAnimId, sp.Animator.GetAnimName(implicitDefaultAnimId))); | ||
171 | |||
172 | cdl.AddToStringBuilder(sb); | ||
173 | |||
174 | ConsoleDisplayTable cdt = new ConsoleDisplayTable() { Indent = 2 }; | ||
175 | cdt.AddColumn("Animation ID", 36); | ||
176 | cdt.AddColumn("Name", 20); | ||
177 | cdt.AddColumn("Seq", 3); | ||
178 | cdt.AddColumn("Object ID", 36); | ||
179 | |||
180 | UUID[] animIds; | ||
181 | int[] sequenceNumbers; | ||
182 | UUID[] objectIds; | ||
183 | |||
184 | sp.Animator.Animations.GetArrays(out animIds, out sequenceNumbers, out objectIds); | ||
185 | |||
186 | for (int i = 0; i < animIds.Length; i++) | ||
187 | { | ||
188 | UUID animId = animIds[i]; | ||
189 | string animName = sp.Animator.GetAnimName(animId); | ||
190 | int seq = sequenceNumbers[i]; | ||
191 | UUID objectId = objectIds[i]; | ||
192 | |||
193 | cdt.AddRow(animId, animName, seq, objectId); | ||
194 | } | ||
195 | |||
196 | cdt.AddToStringBuilder(sb); | ||
197 | sb.Append("\n"); | ||
198 | } | ||
199 | } | ||
200 | } \ No newline at end of file | ||