SceneCommandsModule.cs 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  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 System.Threading;
  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. 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 = "SceneCommandsModule")]
  48. public class SceneCommandsModule : ISceneCommandsModule, INonSharedRegionModule
  49. {
  50. // private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  51. private Scene m_scene;
  52. public string Name { get { return "Scene Commands Module"; } }
  53. public Type ReplaceableInterface { get { return null; } }
  54. public void Initialise(IConfigSource source)
  55. {
  56. // m_log.DebugFormat("[SCENE COMMANDS MODULE]: INITIALIZED MODULE");
  57. }
  58. public void PostInitialise()
  59. {
  60. // m_log.DebugFormat("[SCENE COMMANDS MODULE]: POST INITIALIZED MODULE");
  61. }
  62. public void Close()
  63. {
  64. // m_log.DebugFormat("[SCENE COMMANDS MODULE]: CLOSED MODULE");
  65. }
  66. public void AddRegion(Scene scene)
  67. {
  68. // m_log.DebugFormat("[SCENE COMMANDS MODULE]: REGION {0} ADDED", scene.RegionInfo.RegionName);
  69. m_scene = scene;
  70. m_scene.RegisterModuleInterface<ISceneCommandsModule>(this);
  71. }
  72. public void RemoveRegion(Scene scene)
  73. {
  74. // m_log.DebugFormat("[SCENE COMMANDS MODULE]: REGION {0} REMOVED", scene.RegionInfo.RegionName);
  75. }
  76. public void RegionLoaded(Scene scene)
  77. {
  78. // m_log.DebugFormat("[ATTACHMENTS COMMAND MODULE]: REGION {0} LOADED", scene.RegionInfo.RegionName);
  79. scene.AddCommand(
  80. "Debug", this, "debug scene get",
  81. "debug scene get",
  82. "List current scene options.",
  83. "active - if false then main scene update and maintenance loops are suspended.\n"
  84. + "animations - if true then extra animations debug information is logged.\n"
  85. + "collisions - if false then collisions with other objects are turned off.\n"
  86. + "pbackup - if false then periodic scene backup is turned off.\n"
  87. + "physics - if false then all physics objects are non-physical.\n"
  88. + "scripting - if false then no scripting operations happen.\n"
  89. + "teleport - if true then some extra teleport debug information is logged.\n"
  90. + "updates - if true then any frame which exceeds double the maximum desired frame time is logged.",
  91. HandleDebugSceneGetCommand);
  92. scene.AddCommand(
  93. "Debug", this, "debug scene set",
  94. "debug scene set <param> <value>",
  95. "Turn on scene debugging options.",
  96. "active - if false then main scene update and maintenance loops are suspended.\n"
  97. + "animations - if true then extra animations debug information is logged.\n"
  98. + "collisions - if false then collisions with other objects are turned off.\n"
  99. + "pbackup - if false then periodic scene backup is turned off.\n"
  100. + "physics - if false then all physics objects are non-physical.\n"
  101. + "scripting - if false then no scripting operations happen.\n"
  102. + "teleport - if true then some extra teleport debug information is logged.\n"
  103. + "updates - if true then any frame which exceeds double the maximum desired frame time is logged.",
  104. HandleDebugSceneSetCommand);
  105. }
  106. private void HandleDebugSceneGetCommand(string module, string[] args)
  107. {
  108. if (args.Length == 3)
  109. {
  110. if (MainConsole.Instance.ConsoleScene != m_scene && MainConsole.Instance.ConsoleScene != null)
  111. return;
  112. OutputSceneDebugOptions();
  113. }
  114. else
  115. {
  116. MainConsole.Instance.Output("Usage: debug scene get");
  117. }
  118. }
  119. private void OutputSceneDebugOptions()
  120. {
  121. ConsoleDisplayList cdl = new ConsoleDisplayList();
  122. cdl.AddRow("active", m_scene.Active);
  123. cdl.AddRow("animations", m_scene.DebugAnimations);
  124. cdl.AddRow("pbackup", m_scene.PeriodicBackup);
  125. cdl.AddRow("physics", m_scene.PhysicsEnabled);
  126. cdl.AddRow("scripting", m_scene.ScriptsEnabled);
  127. cdl.AddRow("teleport", m_scene.DebugTeleporting);
  128. cdl.AddRow("updates", m_scene.DebugUpdates);
  129. MainConsole.Instance.OutputFormat("Scene {0} options:", m_scene.Name);
  130. MainConsole.Instance.Output(cdl.ToString());
  131. }
  132. private void HandleDebugSceneSetCommand(string module, string[] args)
  133. {
  134. if (args.Length == 5)
  135. {
  136. if (MainConsole.Instance.ConsoleScene != m_scene && MainConsole.Instance.ConsoleScene != null)
  137. return;
  138. string key = args[3];
  139. string value = args[4];
  140. SetSceneDebugOptions(new Dictionary<string, string>() { { key, value } });
  141. MainConsole.Instance.OutputFormat("Set {0} debug scene {1} = {2}", m_scene.Name, key, value);
  142. }
  143. else
  144. {
  145. MainConsole.Instance.Output("Usage: debug scene set <param> <value>");
  146. }
  147. }
  148. public void SetSceneDebugOptions(Dictionary<string, string> options)
  149. {
  150. if (options.ContainsKey("active"))
  151. {
  152. bool active;
  153. if (bool.TryParse(options["active"], out active))
  154. m_scene.Active = active;
  155. }
  156. if (options.ContainsKey("animations"))
  157. {
  158. bool active;
  159. if (bool.TryParse(options["animations"], out active))
  160. m_scene.DebugAnimations = active;
  161. }
  162. if (options.ContainsKey("pbackup"))
  163. {
  164. bool active;
  165. if (bool.TryParse(options["pbackup"], out active))
  166. m_scene.PeriodicBackup = active;
  167. }
  168. if (options.ContainsKey("scripting"))
  169. {
  170. bool enableScripts = true;
  171. if (bool.TryParse(options["scripting"], out enableScripts))
  172. m_scene.ScriptsEnabled = enableScripts;
  173. }
  174. if (options.ContainsKey("physics"))
  175. {
  176. bool enablePhysics;
  177. if (bool.TryParse(options["physics"], out enablePhysics))
  178. m_scene.PhysicsEnabled = enablePhysics;
  179. }
  180. // if (options.ContainsKey("collisions"))
  181. // {
  182. // // TODO: Implement. If false, should stop objects colliding, though possibly should still allow
  183. // // the avatar themselves to collide with the ground.
  184. // }
  185. if (options.ContainsKey("teleport"))
  186. {
  187. bool enableTeleportDebugging;
  188. if (bool.TryParse(options["teleport"], out enableTeleportDebugging))
  189. m_scene.DebugTeleporting = enableTeleportDebugging;
  190. }
  191. if (options.ContainsKey("updates"))
  192. {
  193. bool enableUpdateDebugging;
  194. if (bool.TryParse(options["updates"], out enableUpdateDebugging))
  195. {
  196. m_scene.DebugUpdates = enableUpdateDebugging;
  197. }
  198. }
  199. }
  200. }
  201. }