SceneCommandsModule.cs 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  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.Framework.Interfaces;
  40. using OpenSim.Region.Framework.Scenes;
  41. namespace OpenSim.Region.OptionalModules.Avatar.Attachments
  42. {
  43. /// <summary>
  44. /// A module that just holds commands for inspecting avatar appearance.
  45. /// </summary>
  46. [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "SceneCommandsModule")]
  47. public class SceneCommandsModule : ISceneCommandsModule, INonSharedRegionModule
  48. {
  49. // private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  50. private Scene m_scene;
  51. public string Name { get { return "Scene Commands Module"; } }
  52. public Type ReplaceableInterface { get { return null; } }
  53. public void Initialise(IConfigSource source)
  54. {
  55. // m_log.DebugFormat("[SCENE COMMANDS MODULE]: INITIALIZED MODULE");
  56. }
  57. public void PostInitialise()
  58. {
  59. // m_log.DebugFormat("[SCENE COMMANDS MODULE]: POST INITIALIZED MODULE");
  60. }
  61. public void Close()
  62. {
  63. // m_log.DebugFormat("[SCENE COMMANDS MODULE]: CLOSED MODULE");
  64. }
  65. public void AddRegion(Scene scene)
  66. {
  67. // m_log.DebugFormat("[SCENE COMMANDS MODULE]: REGION {0} ADDED", scene.RegionInfo.RegionName);
  68. m_scene = scene;
  69. m_scene.RegisterModuleInterface<ISceneCommandsModule>(this);
  70. }
  71. public void RemoveRegion(Scene scene)
  72. {
  73. // m_log.DebugFormat("[SCENE COMMANDS MODULE]: REGION {0} REMOVED", scene.RegionInfo.RegionName);
  74. }
  75. public void RegionLoaded(Scene scene)
  76. {
  77. // m_log.DebugFormat("[ATTACHMENTS COMMAND MODULE]: REGION {0} LOADED", scene.RegionInfo.RegionName);
  78. scene.AddCommand(
  79. "Debug", this, "debug scene get",
  80. "debug scene get",
  81. "List current scene options.",
  82. "If active is false then main scene update and maintenance loops are suspended.\n"
  83. + "If animations is true then extra animations debug information is logged.\n"
  84. + "If collisions is false then collisions with other objects are turned off.\n"
  85. + "If pbackup is false then periodic scene backup is turned off.\n"
  86. + "If physics is false then all physics objects are non-physical.\n"
  87. + "If scripting is false then no scripting operations happen.\n"
  88. + "If teleport is true then some extra teleport debug information is logged.\n"
  89. + "If updates is true then any frame which exceeds double the maximum desired frame time is logged.",
  90. HandleDebugSceneGetCommand);
  91. scene.AddCommand(
  92. "Debug", this, "debug scene set",
  93. "debug scene set active|collisions|pbackup|physics|scripting|teleport|updates true|false",
  94. "Turn on scene debugging options.",
  95. "If active is false then main scene update and maintenance loops are suspended.\n"
  96. + "If animations is true then extra animations debug information is logged.\n"
  97. + "If collisions is false then collisions with other objects are turned off.\n"
  98. + "If pbackup is false then periodic scene backup is turned off.\n"
  99. + "If physics is false then all physics objects are non-physical.\n"
  100. + "If scripting is false then no scripting operations happen.\n"
  101. + "If teleport is true then some extra teleport debug information is logged.\n"
  102. + "If updates is true then any frame which exceeds double the maximum desired frame time is logged.",
  103. HandleDebugSceneSetCommand);
  104. }
  105. private void HandleDebugSceneGetCommand(string module, string[] args)
  106. {
  107. if (args.Length == 3)
  108. {
  109. if (MainConsole.Instance.ConsoleScene != m_scene && MainConsole.Instance.ConsoleScene != null)
  110. return;
  111. OutputSceneDebugOptions();
  112. }
  113. else
  114. {
  115. MainConsole.Instance.Output("Usage: debug scene get");
  116. }
  117. }
  118. private void OutputSceneDebugOptions()
  119. {
  120. ConsoleDisplayList cdl = new ConsoleDisplayList();
  121. cdl.AddRow("active", m_scene.Active);
  122. cdl.AddRow("animations", m_scene.DebugAnimations);
  123. cdl.AddRow("pbackup", m_scene.PeriodicBackup);
  124. cdl.AddRow("physics", m_scene.PhysicsEnabled);
  125. cdl.AddRow("scripting", m_scene.ScriptsEnabled);
  126. cdl.AddRow("teleport", m_scene.DebugTeleporting);
  127. cdl.AddRow("updates", m_scene.DebugUpdates);
  128. MainConsole.Instance.OutputFormat("Scene {0} options:", m_scene.Name);
  129. MainConsole.Instance.Output(cdl.ToString());
  130. }
  131. private void HandleDebugSceneSetCommand(string module, string[] args)
  132. {
  133. if (args.Length == 5)
  134. {
  135. if (MainConsole.Instance.ConsoleScene != m_scene && MainConsole.Instance.ConsoleScene != null)
  136. return;
  137. string key = args[3];
  138. string value = args[4];
  139. SetSceneDebugOptions(new Dictionary<string, string>() { { key, value } });
  140. MainConsole.Instance.OutputFormat("Set {0} debug scene {1} = {2}", m_scene.Name, key, value);
  141. }
  142. else
  143. {
  144. MainConsole.Instance.Output(
  145. "Usage: debug scene set active|collisions|pbackup|physics|scripting|teleport|updates true|false");
  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. GcNotify.Enabled = enableUpdateDebugging;
  198. }
  199. }
  200. }
  201. }
  202. }