RegionCommandsModule.cs 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379
  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.Reflection;
  30. using System.Text;
  31. using System.Text.RegularExpressions;
  32. using log4net;
  33. using Mono.Addins;
  34. using NDesk.Options;
  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. using GridRegion = OpenSim.Services.Interfaces.GridRegion;
  43. namespace OpenSim.Region.CoreModules.World.Objects.Commands
  44. {
  45. /// <summary>
  46. /// A module that holds commands for manipulating objects in the scene.
  47. /// </summary>
  48. [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "RegionCommandsModule")]
  49. public class RegionCommandsModule : INonSharedRegionModule
  50. {
  51. private Scene m_scene;
  52. private ICommandConsole m_console;
  53. public string Name { get { return "Region Commands Module"; } }
  54. public Type ReplaceableInterface { get { return null; } }
  55. public void Initialise(IConfigSource source)
  56. {
  57. // m_log.DebugFormat("[REGION COMMANDS MODULE]: INITIALIZED MODULE");
  58. }
  59. public void PostInitialise()
  60. {
  61. // m_log.DebugFormat("[REGION COMMANDS MODULE]: POST INITIALIZED MODULE");
  62. }
  63. public void Close()
  64. {
  65. // m_log.DebugFormat("[REGION COMMANDS MODULE]: CLOSED MODULE");
  66. }
  67. public void AddRegion(Scene scene)
  68. {
  69. // m_log.DebugFormat("[REGION COMMANDS MODULE]: REGION {0} ADDED", scene.RegionInfo.RegionName);
  70. m_scene = scene;
  71. m_console = MainConsole.Instance;
  72. m_console.Commands.AddCommand(
  73. "Regions", false, "show scene",
  74. "show scene",
  75. "Show live information for the currently selected scene (fps, prims, etc.).", HandleShowScene);
  76. m_console.Commands.AddCommand(
  77. "Regions", false, "show region",
  78. "show region",
  79. "Show control information for the currently selected region (host name, max physical prim size, etc).",
  80. "A synonym for \"region get\"",
  81. HandleShowRegion);
  82. m_console.Commands.AddCommand(
  83. "Regions", false, "region get",
  84. "region get",
  85. "Show control information for the currently selected region (host name, max physical prim size, etc).",
  86. "Some parameters can be set with the \"region set\" command.\n"
  87. + "Others must be changed via a viewer (usually via the region/estate dialog box).",
  88. HandleShowRegion);
  89. m_console.Commands.AddCommand(
  90. "Regions", false, "region set",
  91. "region set",
  92. "Set control information for the currently selected region.",
  93. "Currently, the following parameters can be set:\n"
  94. + "agent-limit <int> - Current root agent limit. This is persisted over restart.\n"
  95. + "max-agent-limit <int> - Maximum root agent limit. agent-limit cannot exceed this."
  96. + " This is not persisted over restart - to set it every time you must add a MaxAgents entry to your regions file.",
  97. HandleRegionSet);
  98. m_console.Commands.AddCommand("Regions", false, "show neighbours",
  99. "show neighbours",
  100. "Shows the local region neighbours", HandleShowNeighboursCommand);
  101. m_console.Commands.AddCommand("Regions", false, "show regionsinview",
  102. "show regionsinview",
  103. "Shows regions that can be seen from a region", HandleShowRegionsInViewCommand);
  104. }
  105. public void RemoveRegion(Scene scene)
  106. {
  107. // m_log.DebugFormat("[REGION COMMANDS MODULE]: REGION {0} REMOVED", scene.RegionInfo.RegionName);
  108. }
  109. public void RegionLoaded(Scene scene)
  110. {
  111. // m_log.DebugFormat("[REGION COMMANDS MODULE]: REGION {0} LOADED", scene.RegionInfo.RegionName);
  112. }
  113. private void HandleShowRegion(string module, string[] cmd)
  114. {
  115. if (!(MainConsole.Instance.ConsoleScene == null || MainConsole.Instance.ConsoleScene == m_scene))
  116. return;
  117. RegionInfo ri = m_scene.RegionInfo;
  118. RegionSettings rs = ri.RegionSettings;
  119. StringBuilder sb = new StringBuilder();
  120. sb.AppendFormat("Region information for {0}\n", m_scene.Name);
  121. ConsoleDisplayList dispList = new ConsoleDisplayList();
  122. dispList.AddRow("Region ID", ri.RegionID);
  123. dispList.AddRow("Region handle", ri.RegionHandle);
  124. dispList.AddRow("Region location", string.Format("{0},{1}", ri.RegionLocX, ri.RegionLocY));
  125. dispList.AddRow("Region size", string.Format("{0}x{1}", ri.RegionSizeX, ri.RegionSizeY));
  126. //dispList.AddRow("Region type", ri.RegionType);
  127. dispList.AddRow("Maturity", rs.Maturity);
  128. dispList.AddRow("Region address", ri.ServerURI);
  129. dispList.AddRow("From region file", ri.RegionFile);
  130. dispList.AddRow("External endpoint", ri.ExternalEndPoint);
  131. dispList.AddRow("Internal endpoint", ri.InternalEndPoint);
  132. dispList.AddRow("Access level", ri.AccessLevel);
  133. dispList.AddRow("Agent limit", rs.AgentLimit);
  134. dispList.AddRow("Max agent limit", ri.AgentCapacity);
  135. dispList.AddRow("Linkset capacity", ri.LinksetCapacity <= 0 ? "not set" : ri.LinksetCapacity.ToString());
  136. dispList.AddRow("Prim capacity", ri.ObjectCapacity);
  137. dispList.AddRow("Prim bonus", rs.ObjectBonus);
  138. dispList.AddRow("Max prims per user", ri.MaxPrimsPerUser < 0 ? "n/a" : ri.MaxPrimsPerUser.ToString());
  139. dispList.AddRow("Clamp prim size", ri.ClampPrimSize);
  140. dispList.AddRow("Non physical prim min size", ri.NonphysPrimMin <= 0 ? "not set" : string.Format("{0} m", ri.NonphysPrimMin));
  141. dispList.AddRow("Non physical prim max size", ri.NonphysPrimMax <= 0 ? "not set" : string.Format("{0} m", ri.NonphysPrimMax));
  142. dispList.AddRow("Physical prim min size", ri.PhysPrimMin <= 0 ? "not set" : string.Format("{0} m", ri.PhysPrimMin));
  143. dispList.AddRow("Physical prim max size", ri.PhysPrimMax <= 0 ? "not set" : string.Format("{0} m", ri.PhysPrimMax));
  144. dispList.AddRow("Allow Damage", rs.AllowDamage);
  145. dispList.AddRow("Allow Land join/divide", rs.AllowLandJoinDivide);
  146. dispList.AddRow("Allow land resell", rs.AllowLandResell);
  147. dispList.AddRow("Block fly", rs.BlockFly);
  148. dispList.AddRow("Block show in search", rs.BlockShowInSearch);
  149. dispList.AddRow("Block terraform", rs.BlockTerraform);
  150. dispList.AddRow("Covenant UUID", rs.Covenant);
  151. dispList.AddRow("Convenant change Unix time", rs.CovenantChangedDateTime);
  152. dispList.AddRow("Disable collisions", rs.DisableCollisions);
  153. dispList.AddRow("Disable physics", rs.DisablePhysics);
  154. dispList.AddRow("Disable scripts", rs.DisableScripts);
  155. dispList.AddRow("Restrict pushing", rs.RestrictPushing);
  156. dispList.AddRow("Fixed sun", rs.FixedSun);
  157. dispList.AddRow("Sun position", rs.SunPosition);
  158. dispList.AddRow("Sun vector", rs.SunVector);
  159. dispList.AddRow("Use estate sun", rs.UseEstateSun);
  160. dispList.AddRow("Telehub UUID", rs.TelehubObject);
  161. dispList.AddRow("Terrain lower limit", string.Format("{0} m", rs.TerrainLowerLimit));
  162. dispList.AddRow("Terrain raise limit", string.Format("{0} m", rs.TerrainRaiseLimit));
  163. dispList.AddRow("Water height", string.Format("{0} m", rs.WaterHeight));
  164. dispList.AddRow("Maptile static file", ri.MaptileStaticFile);
  165. dispList.AddRow("Maptile static UUID", ri.MaptileStaticUUID);
  166. dispList.AddRow("Last map refresh", ri.lastMapRefresh);
  167. dispList.AddRow("Last map UUID", ri.lastMapUUID);
  168. dispList.AddToStringBuilder(sb);
  169. MainConsole.Instance.Output(sb.ToString());
  170. }
  171. private void HandleRegionSet(string module, string[] args)
  172. {
  173. if (!(MainConsole.Instance.ConsoleScene == null || MainConsole.Instance.ConsoleScene == m_scene))
  174. return;
  175. if (args.Length != 4)
  176. {
  177. MainConsole.Instance.Output("Usage: region set <param> <value>");
  178. return;
  179. }
  180. string param = args[2];
  181. string rawValue = args[3];
  182. if (!(MainConsole.Instance.ConsoleScene == null || MainConsole.Instance.ConsoleScene == m_scene))
  183. return;
  184. RegionInfo ri = m_scene.RegionInfo;
  185. RegionSettings rs = ri.RegionSettings;
  186. if (param == "agent-limit")
  187. {
  188. int newValue;
  189. if (!ConsoleUtil.TryParseConsoleNaturalInt(MainConsole.Instance, rawValue, out newValue))
  190. return;
  191. if (newValue > ri.AgentCapacity)
  192. {
  193. MainConsole.Instance.Output(
  194. "Cannot set {0} to {1} in {2} as max-agent-limit is {3}", "agent-limit",
  195. null,
  196. newValue, m_scene.Name, ri.AgentCapacity);
  197. }
  198. else
  199. {
  200. rs.AgentLimit = newValue;
  201. MainConsole.Instance.Output(
  202. "{0} set to {1} in {2}", "agent-limit", null, newValue, m_scene.Name);
  203. }
  204. rs.Save();
  205. }
  206. else if (param == "max-agent-limit")
  207. {
  208. int newValue;
  209. if (!ConsoleUtil.TryParseConsoleNaturalInt(MainConsole.Instance, rawValue, out newValue))
  210. return;
  211. ri.AgentCapacity = newValue;
  212. MainConsole.Instance.Output(
  213. "{0} set to {1} in {2}", "max-agent-limit", null, newValue, m_scene.Name);
  214. if (ri.AgentCapacity < rs.AgentLimit)
  215. {
  216. rs.AgentLimit = ri.AgentCapacity;
  217. MainConsole.Instance.Output(
  218. "Reducing {0} to {1} in {2}", null, "agent-limit", rs.AgentLimit, m_scene.Name);
  219. }
  220. rs.Save();
  221. }
  222. }
  223. private void HandleShowScene(string module, string[] cmd)
  224. {
  225. if (!(MainConsole.Instance.ConsoleScene == null || MainConsole.Instance.ConsoleScene == m_scene))
  226. return;
  227. SimStatsReporter r = m_scene.StatsReporter;
  228. float[] stats = r.LastReportedSimStats;
  229. float timeDilation = stats[0];
  230. float simFps = stats[1];
  231. float physicsFps = stats[2];
  232. float agentUpdates = stats[3];
  233. float rootAgents = stats[4];
  234. float childAgents = stats[5];
  235. float totalPrims = stats[6];
  236. float activePrims = stats[7];
  237. float totalFrameTime = stats[8];
  238. // float netFrameTime = stats.StatsBlock[9].StatValue; // Ignored - not used by OpenSimulator
  239. float physicsFrameTime = stats[10];
  240. float otherFrameTime = stats[12];
  241. // float imageFrameTime = stats.StatsBlock[11].StatValue; // Ignored
  242. float inPacketsPerSecond = stats[13];
  243. float outPacketsPerSecond = stats[14];
  244. float unackedBytes = stats[15];
  245. // float agentFrameTime = stats.StatsBlock[16].StatValue; // Not really used
  246. float pendingDownloads = stats[17];
  247. float pendingUploads = stats[18];
  248. float activeScripts = stats[19];
  249. float scriptLinesPerSecond = stats[23];
  250. StringBuilder sb = new StringBuilder();
  251. sb.AppendFormat("Scene statistics for {0}\n", m_scene.RegionInfo.RegionName);
  252. ConsoleDisplayList dispList = new ConsoleDisplayList();
  253. dispList.AddRow("Time Dilation", timeDilation);
  254. dispList.AddRow("Sim FPS", simFps);
  255. dispList.AddRow("Physics FPS", physicsFps);
  256. dispList.AddRow("Avatars", rootAgents);
  257. dispList.AddRow("Child agents", childAgents);
  258. dispList.AddRow("Total prims", totalPrims);
  259. dispList.AddRow("Scripts", activeScripts);
  260. dispList.AddRow("Script lines processed per second", scriptLinesPerSecond);
  261. dispList.AddRow("Physics enabled prims", activePrims);
  262. dispList.AddRow("Total frame time", totalFrameTime);
  263. dispList.AddRow("Physics frame time", physicsFrameTime);
  264. dispList.AddRow("Other frame time", otherFrameTime);
  265. dispList.AddRow("Agent Updates per second", agentUpdates);
  266. dispList.AddRow("Packets processed from clients per second", inPacketsPerSecond);
  267. dispList.AddRow("Packets sent to clients per second", outPacketsPerSecond);
  268. dispList.AddRow("Bytes unacknowledged by clients", unackedBytes);
  269. dispList.AddRow("Pending asset downloads to clients", pendingDownloads);
  270. dispList.AddRow("Pending asset uploads from clients", pendingUploads);
  271. dispList.AddToStringBuilder(sb);
  272. MainConsole.Instance.Output(sb.ToString());
  273. }
  274. public void HandleShowNeighboursCommand(string module, string[] cmdparams)
  275. {
  276. if(m_scene == null)
  277. return;
  278. if (!(MainConsole.Instance.ConsoleScene == null || MainConsole.Instance.ConsoleScene == m_scene))
  279. return;
  280. System.Text.StringBuilder caps = new System.Text.StringBuilder();
  281. RegionInfo sr = m_scene.RegionInfo;
  282. caps.AppendFormat("*** Neighbours of {0} ({1}) ***\n", sr.RegionName, sr.RegionID);
  283. List<GridRegion> regions = m_scene.GridService.GetNeighbours(sr.ScopeID, sr.RegionID);
  284. foreach (GridRegion r in regions)
  285. caps.AppendFormat(" {0} @ {1}-{2}\n", r.RegionName, Util.WorldToRegionLoc((uint)r.RegionLocX), Util.WorldToRegionLoc((uint)r.RegionLocY));
  286. MainConsole.Instance.Output(caps.ToString());
  287. }
  288. public void HandleShowRegionsInViewCommand(string module, string[] cmdparams)
  289. {
  290. if(m_scene == null)
  291. return;
  292. if (!(MainConsole.Instance.ConsoleScene == null || MainConsole.Instance.ConsoleScene == m_scene))
  293. return;
  294. System.Text.StringBuilder caps = new System.Text.StringBuilder();
  295. int maxview = (int)m_scene.MaxRegionViewDistance;
  296. RegionInfo sr = m_scene.RegionInfo;
  297. caps.AppendFormat("*** Regions that can be seen from {0} ({1}) (MaxRegionViewDistance {2}m) ***\n", sr.RegionName, sr.RegionID, maxview);
  298. int startX = (int)sr.WorldLocX;
  299. int endX = startX + (int)sr.RegionSizeX;
  300. int startY = (int)sr.WorldLocY;
  301. int endY = startY + (int)sr.RegionSizeY;
  302. startX -= maxview;
  303. if(startX < 0 )
  304. startX = 0;
  305. startY -= maxview;
  306. if(startY < 0)
  307. startY = 0;
  308. endX += maxview;
  309. endY += maxview;
  310. List<GridRegion> regions = m_scene.GridService.GetRegionRange(sr.ScopeID, startX, endX, startY, endY);
  311. foreach (GridRegion r in regions)
  312. {
  313. if(r.RegionHandle == sr.RegionHandle)
  314. continue;
  315. caps.AppendFormat(" {0} @ {1}-{2}\n", r.RegionName, Util.WorldToRegionLoc((uint)r.RegionLocX), Util.WorldToRegionLoc((uint)r.RegionLocY));
  316. }
  317. MainConsole.Instance.Output(caps.ToString());
  318. }
  319. }
  320. }