EstateManagementCommands.cs 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  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.IO;
  30. using System.Reflection;
  31. using System.Security;
  32. using System.Text;
  33. using log4net;
  34. using Nini.Config;
  35. using OpenMetaverse;
  36. using OpenSim.Framework;
  37. using OpenSim.Framework.Console;
  38. using OpenSim.Region.CoreModules.Framework.InterfaceCommander;
  39. using OpenSim.Region.Framework.Interfaces;
  40. using OpenSim.Region.Framework.Scenes;
  41. namespace OpenSim.Region.CoreModules.World.Estate
  42. {
  43. /// <summary>
  44. /// Estate management console commands.
  45. /// </summary>
  46. public class EstateManagementCommands
  47. {
  48. private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  49. protected EstateManagementModule m_module;
  50. protected Commander m_commander = new Commander("estate");
  51. public EstateManagementCommands(EstateManagementModule module)
  52. {
  53. m_module = module;
  54. }
  55. public void Initialise()
  56. {
  57. m_log.DebugFormat("[ESTATE MODULE]: Setting up estate commands for region {0}", m_module.Scene.RegionInfo.RegionName);
  58. m_module.Scene.AddCommand("Regions", m_module, "set terrain texture",
  59. "set terrain texture <number> <uuid> [<x>] [<y>]",
  60. "Sets the terrain <number> to <uuid>, if <x> or <y> are specified, it will only " +
  61. "set it on regions with a matching coordinate. Specify -1 in <x> or <y> to wildcard" +
  62. " that coordinate.",
  63. consoleSetTerrainTexture);
  64. m_module.Scene.AddCommand("Regions", m_module, "set terrain heights",
  65. "set terrain heights <corner> <min> <max> [<x>] [<y>]",
  66. "Sets the terrain texture heights on corner #<corner> to <min>/<max>, if <x> or <y> are specified, it will only " +
  67. "set it on regions with a matching coordinate. Specify -1 in <x> or <y> to wildcard" +
  68. " that coordinate. Corner # SW = 0, NW = 1, SE = 2, NE = 3, all corners = -1.",
  69. consoleSetTerrainHeights);
  70. m_module.Scene.AddCommand(
  71. "Estates", m_module, "estate show", "estate show", "Shows all estates on the simulator.", ShowEstatesCommand);
  72. }
  73. public void Close() {}
  74. protected void consoleSetTerrainTexture(string module, string[] args)
  75. {
  76. string num = args[3];
  77. string uuid = args[4];
  78. int x = (args.Length > 5 ? int.Parse(args[5]) : -1);
  79. int y = (args.Length > 6 ? int.Parse(args[6]) : -1);
  80. if (x == -1 || m_module.Scene.RegionInfo.RegionLocX == x)
  81. {
  82. if (y == -1 || m_module.Scene.RegionInfo.RegionLocY == y)
  83. {
  84. int corner = int.Parse(num);
  85. UUID texture = UUID.Parse(uuid);
  86. m_log.Debug("[ESTATEMODULE]: Setting terrain textures for " + m_module.Scene.RegionInfo.RegionName +
  87. string.Format(" (C#{0} = {1})", corner, texture));
  88. switch (corner)
  89. {
  90. case 0:
  91. m_module.Scene.RegionInfo.RegionSettings.TerrainTexture1 = texture;
  92. break;
  93. case 1:
  94. m_module.Scene.RegionInfo.RegionSettings.TerrainTexture2 = texture;
  95. break;
  96. case 2:
  97. m_module.Scene.RegionInfo.RegionSettings.TerrainTexture3 = texture;
  98. break;
  99. case 3:
  100. m_module.Scene.RegionInfo.RegionSettings.TerrainTexture4 = texture;
  101. break;
  102. }
  103. m_module.Scene.RegionInfo.RegionSettings.Save();
  104. m_module.TriggerRegionInfoChange();
  105. m_module.sendRegionHandshakeToAll();
  106. }
  107. }
  108. }
  109. protected void consoleSetTerrainHeights(string module, string[] args)
  110. {
  111. string num = args[3];
  112. string min = args[4];
  113. string max = args[5];
  114. int x = (args.Length > 6 ? int.Parse(args[6]) : -1);
  115. int y = (args.Length > 7 ? int.Parse(args[7]) : -1);
  116. if (x == -1 || m_module.Scene.RegionInfo.RegionLocX == x)
  117. {
  118. if (y == -1 || m_module.Scene.RegionInfo.RegionLocY == y)
  119. {
  120. int corner = int.Parse(num);
  121. float lowValue = float.Parse(min, Culture.NumberFormatInfo);
  122. float highValue = float.Parse(max, Culture.NumberFormatInfo);
  123. m_log.Debug("[ESTATEMODULE]: Setting terrain heights " + m_module.Scene.RegionInfo.RegionName +
  124. string.Format(" (C{0}, {1}-{2}", corner, lowValue, highValue));
  125. switch (corner)
  126. {
  127. case -1:
  128. m_module.Scene.RegionInfo.RegionSettings.Elevation1SW = lowValue;
  129. m_module.Scene.RegionInfo.RegionSettings.Elevation2SW = highValue;
  130. m_module.Scene.RegionInfo.RegionSettings.Elevation1NW = lowValue;
  131. m_module.Scene.RegionInfo.RegionSettings.Elevation2NW = highValue;
  132. m_module.Scene.RegionInfo.RegionSettings.Elevation1SE = lowValue;
  133. m_module.Scene.RegionInfo.RegionSettings.Elevation2SE = highValue;
  134. m_module.Scene.RegionInfo.RegionSettings.Elevation1NE = lowValue;
  135. m_module.Scene.RegionInfo.RegionSettings.Elevation2NE = highValue;
  136. break;
  137. case 0:
  138. m_module.Scene.RegionInfo.RegionSettings.Elevation1SW = lowValue;
  139. m_module.Scene.RegionInfo.RegionSettings.Elevation2SW = highValue;
  140. break;
  141. case 1:
  142. m_module.Scene.RegionInfo.RegionSettings.Elevation1NW = lowValue;
  143. m_module.Scene.RegionInfo.RegionSettings.Elevation2NW = highValue;
  144. break;
  145. case 2:
  146. m_module.Scene.RegionInfo.RegionSettings.Elevation1SE = lowValue;
  147. m_module.Scene.RegionInfo.RegionSettings.Elevation2SE = highValue;
  148. break;
  149. case 3:
  150. m_module.Scene.RegionInfo.RegionSettings.Elevation1NE = lowValue;
  151. m_module.Scene.RegionInfo.RegionSettings.Elevation2NE = highValue;
  152. break;
  153. }
  154. m_module.Scene.RegionInfo.RegionSettings.Save();
  155. m_module.TriggerRegionInfoChange();
  156. m_module.sendRegionHandshakeToAll();
  157. }
  158. }
  159. }
  160. protected void ShowEstatesCommand(string module, string[] cmd)
  161. {
  162. StringBuilder report = new StringBuilder();
  163. RegionInfo ri = m_module.Scene.RegionInfo;
  164. EstateSettings es = ri.EstateSettings;
  165. report.AppendFormat("Estate information for region {0}\n", ri.RegionName);
  166. report.AppendFormat(
  167. "{0,-20} {1,-7} {2,-20}\n",
  168. "Estate Name",
  169. "ID",
  170. "Owner");
  171. report.AppendFormat(
  172. "{0,-20} {1,-7} {2,-20}\n",
  173. es.EstateName, es.EstateID, m_module.UserManager.GetUserName(es.EstateOwner));
  174. MainConsole.Instance.Output(report.ToString());
  175. }
  176. }
  177. }