opensim – Blame information for rev 1

Subversion Repositories:
Rev:
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 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.Framework.Interfaces;
41 using OpenSim.Region.Framework.Scenes;
42  
43 namespace OpenSim.Region.OptionalModules.Avatar.Attachments
44 {
45 /// <summary>
46 /// A module that just holds commands for inspecting avatar appearance.
47 /// </summary>
48 [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "SceneCommandsModule")]
49 public class SceneCommandsModule : ISceneCommandsModule, INonSharedRegionModule
50 {
51 // private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
52  
53 private Scene m_scene;
54  
55 public string Name { get { return "Scene Commands Module"; } }
56  
57 public Type ReplaceableInterface { get { return null; } }
58  
59 public void Initialise(IConfigSource source)
60 {
61 // m_log.DebugFormat("[SCENE COMMANDS MODULE]: INITIALIZED MODULE");
62 }
63  
64 public void PostInitialise()
65 {
66 // m_log.DebugFormat("[SCENE COMMANDS MODULE]: POST INITIALIZED MODULE");
67 }
68  
69 public void Close()
70 {
71 // m_log.DebugFormat("[SCENE COMMANDS MODULE]: CLOSED MODULE");
72 }
73  
74 public void AddRegion(Scene scene)
75 {
76 // m_log.DebugFormat("[SCENE COMMANDS MODULE]: REGION {0} ADDED", scene.RegionInfo.RegionName);
77  
78 m_scene = scene;
79  
80 m_scene.RegisterModuleInterface<ISceneCommandsModule>(this);
81 }
82  
83 public void RemoveRegion(Scene scene)
84 {
85 // m_log.DebugFormat("[SCENE COMMANDS MODULE]: REGION {0} REMOVED", scene.RegionInfo.RegionName);
86 }
87  
88 public void RegionLoaded(Scene scene)
89 {
90 // m_log.DebugFormat("[ATTACHMENTS COMMAND MODULE]: REGION {0} LOADED", scene.RegionInfo.RegionName);
91  
92 scene.AddCommand(
93 "Debug", this, "debug scene get",
94 "debug scene get",
95 "List current scene options.",
96 "If active is false then main scene update and maintenance loops are suspended.\n"
97 + "If animations is true then extra animations debug information is logged.\n"
98 + "If collisions is false then collisions with other objects are turned off.\n"
99 + "If pbackup is false then periodic scene backup is turned off.\n"
100 + "If physics is false then all physics objects are non-physical.\n"
101 + "If scripting is false then no scripting operations happen.\n"
102 + "If teleport is true then some extra teleport debug information is logged.\n"
103 + "If updates is true then any frame which exceeds double the maximum desired frame time is logged.",
104 HandleDebugSceneGetCommand);
105  
106 scene.AddCommand(
107 "Debug", this, "debug scene set",
108 "debug scene set active|collisions|pbackup|physics|scripting|teleport|updates true|false",
109 "Turn on scene debugging options.",
110 "If active is false then main scene update and maintenance loops are suspended.\n"
111 + "If animations is true then extra animations debug information is logged.\n"
112 + "If collisions is false then collisions with other objects are turned off.\n"
113 + "If pbackup is false then periodic scene backup is turned off.\n"
114 + "If physics is false then all physics objects are non-physical.\n"
115 + "If scripting is false then no scripting operations happen.\n"
116 + "If teleport is true then some extra teleport debug information is logged.\n"
117 + "If updates is true then any frame which exceeds double the maximum desired frame time is logged.",
118 HandleDebugSceneSetCommand);
119  
120 scene.AddCommand(
121 "Regions",
122 this, "show borders", "show borders", "Show border information for regions", HandleShowBordersCommand);
123 }
124  
125 private void HandleShowBordersCommand(string module, string[] args)
126 {
127 StringBuilder sb = new StringBuilder();
128 sb.AppendFormat("Borders for {0}:\n", m_scene.Name);
129  
130 ConsoleDisplayTable cdt = new ConsoleDisplayTable();
131 cdt.AddColumn("Cross Direction", 15);
132 cdt.AddColumn("Line", 34);
133 cdt.AddColumn("Trigger Region", 14);
134  
135 foreach (Border b in m_scene.NorthBorders)
136 cdt.AddRow(b.CrossDirection, b.BorderLine, string.Format("{0}, {1}", b.TriggerRegionX, b.TriggerRegionY));
137  
138 foreach (Border b in m_scene.EastBorders)
139 cdt.AddRow(b.CrossDirection, b.BorderLine, string.Format("{0}, {1}", b.TriggerRegionX, b.TriggerRegionY));
140  
141 foreach (Border b in m_scene.SouthBorders)
142 cdt.AddRow(b.CrossDirection, b.BorderLine, string.Format("{0}, {1}", b.TriggerRegionX, b.TriggerRegionY));
143  
144 foreach (Border b in m_scene.WestBorders)
145 cdt.AddRow(b.CrossDirection, b.BorderLine, string.Format("{0}, {1}", b.TriggerRegionX, b.TriggerRegionY));
146  
147 cdt.AddToStringBuilder(sb);
148  
149 MainConsole.Instance.Output(sb.ToString());
150 }
151  
152 private void HandleDebugSceneGetCommand(string module, string[] args)
153 {
154 if (args.Length == 3)
155 {
156 if (MainConsole.Instance.ConsoleScene != m_scene && MainConsole.Instance.ConsoleScene != null)
157 return;
158  
159 OutputSceneDebugOptions();
160 }
161 else
162 {
163 MainConsole.Instance.Output("Usage: debug scene get");
164 }
165 }
166  
167 private void OutputSceneDebugOptions()
168 {
169 ConsoleDisplayList cdl = new ConsoleDisplayList();
170 cdl.AddRow("active", m_scene.Active);
171 cdl.AddRow("animations", m_scene.DebugAnimations);
172 cdl.AddRow("pbackup", m_scene.PeriodicBackup);
173 cdl.AddRow("physics", m_scene.PhysicsEnabled);
174 cdl.AddRow("scripting", m_scene.ScriptsEnabled);
175 cdl.AddRow("teleport", m_scene.DebugTeleporting);
176 cdl.AddRow("updates", m_scene.DebugUpdates);
177  
178 MainConsole.Instance.OutputFormat("Scene {0} options:", m_scene.Name);
179 MainConsole.Instance.Output(cdl.ToString());
180 }
181  
182 private void HandleDebugSceneSetCommand(string module, string[] args)
183 {
184 if (args.Length == 5)
185 {
186 if (MainConsole.Instance.ConsoleScene != m_scene && MainConsole.Instance.ConsoleScene != null)
187 return;
188  
189 string key = args[3];
190 string value = args[4];
191 SetSceneDebugOptions(new Dictionary<string, string>() { { key, value } });
192  
193 MainConsole.Instance.OutputFormat("Set {0} debug scene {1} = {2}", m_scene.Name, key, value);
194 }
195 else
196 {
197 MainConsole.Instance.Output(
198 "Usage: debug scene set active|collisions|pbackup|physics|scripting|teleport|updates true|false");
199 }
200 }
201  
202 public void SetSceneDebugOptions(Dictionary<string, string> options)
203 {
204 if (options.ContainsKey("active"))
205 {
206 bool active;
207  
208 if (bool.TryParse(options["active"], out active))
209 m_scene.Active = active;
210 }
211  
212 if (options.ContainsKey("animations"))
213 {
214 bool active;
215  
216 if (bool.TryParse(options["animations"], out active))
217 m_scene.DebugAnimations = active;
218 }
219  
220 if (options.ContainsKey("pbackup"))
221 {
222 bool active;
223  
224 if (bool.TryParse(options["pbackup"], out active))
225 m_scene.PeriodicBackup = active;
226 }
227  
228 if (options.ContainsKey("scripting"))
229 {
230 bool enableScripts = true;
231 if (bool.TryParse(options["scripting"], out enableScripts))
232 m_scene.ScriptsEnabled = enableScripts;
233 }
234  
235 if (options.ContainsKey("physics"))
236 {
237 bool enablePhysics;
238 if (bool.TryParse(options["physics"], out enablePhysics))
239 m_scene.PhysicsEnabled = enablePhysics;
240 }
241  
242 // if (options.ContainsKey("collisions"))
243 // {
244 // // TODO: Implement. If false, should stop objects colliding, though possibly should still allow
245 // // the avatar themselves to collide with the ground.
246 // }
247  
248 if (options.ContainsKey("teleport"))
249 {
250 bool enableTeleportDebugging;
251 if (bool.TryParse(options["teleport"], out enableTeleportDebugging))
252 m_scene.DebugTeleporting = enableTeleportDebugging;
253 }
254  
255 if (options.ContainsKey("updates"))
256 {
257 bool enableUpdateDebugging;
258 if (bool.TryParse(options["updates"], out enableUpdateDebugging))
259 {
260 m_scene.DebugUpdates = enableUpdateDebugging;
261 GcNotify.Enabled = enableUpdateDebugging;
262 }
263 }
264 }
265 }
266 }