opensim – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | eva | 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 System.Text.RegularExpressions; |
||
34 | using log4net; |
||
35 | using Mono.Addins; |
||
36 | using NDesk.Options; |
||
37 | using Nini.Config; |
||
38 | using OpenMetaverse; |
||
39 | using OpenSim.Framework; |
||
40 | using OpenSim.Framework.Console; |
||
41 | using OpenSim.Region.Framework.Interfaces; |
||
42 | using OpenSim.Region.Framework.Scenes; |
||
43 | |||
44 | namespace OpenSim.Region.OptionalModules.Avatar.SitStand |
||
45 | { |
||
46 | /// <summary> |
||
47 | /// A module that just holds commands for changing avatar sitting and standing states. |
||
48 | /// </summary> |
||
49 | [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "AnimationsCommandModule")] |
||
50 | public class SitStandCommandModule : INonSharedRegionModule |
||
51 | { |
||
52 | // private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); |
||
53 | |||
54 | private Scene m_scene; |
||
55 | |||
56 | public string Name { get { return "SitStand Command Module"; } } |
||
57 | |||
58 | public Type ReplaceableInterface { get { return null; } } |
||
59 | |||
60 | public void Initialise(IConfigSource source) |
||
61 | { |
||
62 | // m_log.DebugFormat("[ANIMATIONS COMMAND MODULE]: INITIALIZED MODULE"); |
||
63 | } |
||
64 | |||
65 | public void PostInitialise() |
||
66 | { |
||
67 | // m_log.DebugFormat("[ANIMATIONS COMMAND MODULE]: POST INITIALIZED MODULE"); |
||
68 | } |
||
69 | |||
70 | public void Close() |
||
71 | { |
||
72 | // m_log.DebugFormat("[ANIMATIONS COMMAND MODULE]: CLOSED MODULE"); |
||
73 | } |
||
74 | |||
75 | public void AddRegion(Scene scene) |
||
76 | { |
||
77 | // m_log.DebugFormat("[ANIMATIONS COMMAND MODULE]: REGION {0} ADDED", scene.RegionInfo.RegionName); |
||
78 | } |
||
79 | |||
80 | public void RemoveRegion(Scene scene) |
||
81 | { |
||
82 | // m_log.DebugFormat("[ATTACHMENTS COMMAND MODULE]: REGION {0} REMOVED", scene.RegionInfo.RegionName); |
||
83 | } |
||
84 | |||
85 | public void RegionLoaded(Scene scene) |
||
86 | { |
||
87 | // m_log.DebugFormat("[ANIMATIONS COMMAND MODULE]: REGION {0} LOADED", scene.RegionInfo.RegionName); |
||
88 | |||
89 | m_scene = scene; |
||
90 | |||
91 | scene.AddCommand( |
||
92 | "Users", this, "sit user name", |
||
93 | "sit user name [--regex] <first-name> <last-name>", |
||
94 | "Sit the named user on an unoccupied object with a sit target.", |
||
95 | "If there are no such objects then nothing happens.\n" |
||
96 | + "If --regex is specified then the names are treated as regular expressions.", |
||
97 | HandleSitUserNameCommand); |
||
98 | |||
99 | scene.AddCommand( |
||
100 | "Users", this, "stand user name", |
||
101 | "stand user name [--regex] <first-name> <last-name>", |
||
102 | "Stand the named user.", |
||
103 | "If --regex is specified then the names are treated as regular expressions.", |
||
104 | HandleStandUserNameCommand); |
||
105 | } |
||
106 | |||
107 | private void HandleSitUserNameCommand(string module, string[] cmd) |
||
108 | { |
||
109 | if (MainConsole.Instance.ConsoleScene != m_scene && MainConsole.Instance.ConsoleScene != null) |
||
110 | return; |
||
111 | |||
112 | if (cmd.Length < 5) |
||
113 | { |
||
114 | MainConsole.Instance.Output("Usage: sit user name [--regex] <first-name> <last-name>"); |
||
115 | return; |
||
116 | } |
||
117 | |||
118 | List<ScenePresence> scenePresences = GetScenePresences(cmd); |
||
119 | |||
120 | foreach (ScenePresence sp in scenePresences) |
||
121 | { |
||
122 | if (sp.SitGround || sp.IsSatOnObject) |
||
123 | continue; |
||
124 | |||
125 | SceneObjectPart sitPart = null; |
||
126 | List<SceneObjectGroup> sceneObjects = m_scene.GetSceneObjectGroups(); |
||
127 | |||
128 | foreach (SceneObjectGroup sceneObject in sceneObjects) |
||
129 | { |
||
130 | if (sceneObject.IsAttachment) |
||
131 | continue; |
||
132 | |||
133 | foreach (SceneObjectPart part in sceneObject.Parts) |
||
134 | { |
||
135 | if (part.IsSitTargetSet && part.SitTargetAvatar == UUID.Zero) |
||
136 | { |
||
137 | sitPart = part; |
||
138 | break; |
||
139 | } |
||
140 | } |
||
141 | } |
||
142 | |||
143 | if (sitPart != null) |
||
144 | { |
||
145 | MainConsole.Instance.OutputFormat( |
||
146 | "Sitting {0} on {1} {2} in {3}", |
||
147 | sp.Name, sitPart.ParentGroup.Name, sitPart.ParentGroup.UUID, m_scene.Name); |
||
148 | |||
149 | sp.HandleAgentRequestSit(sp.ControllingClient, sp.UUID, sitPart.UUID, Vector3.Zero); |
||
150 | sp.HandleAgentSit(sp.ControllingClient, sp.UUID); |
||
151 | } |
||
152 | else |
||
153 | { |
||
154 | MainConsole.Instance.OutputFormat( |
||
155 | "Could not find any unoccupied set seat on which to sit {0} in {1}. Aborting", |
||
156 | sp.Name, m_scene.Name); |
||
157 | |||
158 | break; |
||
159 | } |
||
160 | } |
||
161 | } |
||
162 | |||
163 | private void HandleStandUserNameCommand(string module, string[] cmd) |
||
164 | { |
||
165 | if (MainConsole.Instance.ConsoleScene != m_scene && MainConsole.Instance.ConsoleScene != null) |
||
166 | return; |
||
167 | |||
168 | if (cmd.Length < 5) |
||
169 | { |
||
170 | MainConsole.Instance.Output("Usage: stand user name [--regex] <first-name> <last-name>"); |
||
171 | return; |
||
172 | } |
||
173 | |||
174 | List<ScenePresence> scenePresences = GetScenePresences(cmd); |
||
175 | |||
176 | foreach (ScenePresence sp in scenePresences) |
||
177 | { |
||
178 | if (sp.SitGround || sp.IsSatOnObject) |
||
179 | { |
||
180 | MainConsole.Instance.OutputFormat("Standing {0} in {1}", sp.Name, m_scene.Name); |
||
181 | sp.StandUp(); |
||
182 | } |
||
183 | } |
||
184 | } |
||
185 | |||
186 | private List<ScenePresence> GetScenePresences(string[] cmdParams) |
||
187 | { |
||
188 | bool useRegex = false; |
||
189 | OptionSet options = new OptionSet().Add("regex", v=> useRegex = v != null ); |
||
190 | |||
191 | List<string> mainParams = options.Parse(cmdParams); |
||
192 | |||
193 | string firstName = mainParams[3]; |
||
194 | string lastName = mainParams[4]; |
||
195 | |||
196 | List<ScenePresence> scenePresencesMatched = new List<ScenePresence>(); |
||
197 | |||
198 | if (useRegex) |
||
199 | { |
||
200 | Regex nameRegex = new Regex(string.Format("{0} {1}", firstName, lastName)); |
||
201 | List<ScenePresence> scenePresences = m_scene.GetScenePresences(); |
||
202 | |||
203 | foreach (ScenePresence sp in scenePresences) |
||
204 | { |
||
205 | if (!sp.IsChildAgent && nameRegex.IsMatch(sp.Name)) |
||
206 | scenePresencesMatched.Add(sp); |
||
207 | } |
||
208 | } |
||
209 | else |
||
210 | { |
||
211 | ScenePresence sp = m_scene.GetScenePresence(firstName, lastName); |
||
212 | |||
213 | if (sp != null && !sp.IsChildAgent) |
||
214 | scenePresencesMatched.Add(sp); |
||
215 | } |
||
216 | |||
217 | return scenePresencesMatched; |
||
218 | } |
||
219 | } |
||
220 | } |