EstateManagementCommands.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  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("Regions", m_module, "set water height",
  71. "set water height <height> [<x>] [<y>]",
  72. "Sets the water height in meters. If <x> and <y> are specified, it will only set it on regions with a matching coordinate. " +
  73. "Specify -1 in <x> or <y> to wildcard that coordinate.",
  74. consoleSetWaterHeight);
  75. m_module.Scene.AddCommand(
  76. "Estates", m_module, "estate show", "estate show", "Shows all estates on the simulator.", ShowEstatesCommand);
  77. }
  78. public void Close() {}
  79. protected void consoleSetTerrainTexture(string module, string[] args)
  80. {
  81. string num = args[3];
  82. string uuid = args[4];
  83. int x = (args.Length > 5 ? int.Parse(args[5]) : -1);
  84. int y = (args.Length > 6 ? int.Parse(args[6]) : -1);
  85. if (x == -1 || m_module.Scene.RegionInfo.RegionLocX == x)
  86. {
  87. if (y == -1 || m_module.Scene.RegionInfo.RegionLocY == y)
  88. {
  89. int corner = int.Parse(num);
  90. UUID texture = UUID.Parse(uuid);
  91. m_log.Debug("[ESTATEMODULE]: Setting terrain textures for " + m_module.Scene.RegionInfo.RegionName +
  92. string.Format(" (C#{0} = {1})", corner, texture));
  93. switch (corner)
  94. {
  95. case 0:
  96. m_module.Scene.RegionInfo.RegionSettings.TerrainTexture1 = texture;
  97. break;
  98. case 1:
  99. m_module.Scene.RegionInfo.RegionSettings.TerrainTexture2 = texture;
  100. break;
  101. case 2:
  102. m_module.Scene.RegionInfo.RegionSettings.TerrainTexture3 = texture;
  103. break;
  104. case 3:
  105. m_module.Scene.RegionInfo.RegionSettings.TerrainTexture4 = texture;
  106. break;
  107. }
  108. m_module.Scene.RegionInfo.RegionSettings.Save();
  109. m_module.TriggerRegionInfoChange();
  110. m_module.sendRegionHandshakeToAll();
  111. }
  112. }
  113. }
  114. protected void consoleSetWaterHeight(string module, string[] args)
  115. {
  116. string heightstring = args[3];
  117. int x = (args.Length > 4 ? int.Parse(args[4]) : -1);
  118. int y = (args.Length > 5 ? int.Parse(args[5]) : -1);
  119. if (x == -1 || m_module.Scene.RegionInfo.RegionLocX == x)
  120. {
  121. if (y == -1 || m_module.Scene.RegionInfo.RegionLocY == y)
  122. {
  123. double selectedheight = double.Parse(heightstring);
  124. m_log.Debug("[ESTATEMODULE]: Setting water height in " + m_module.Scene.RegionInfo.RegionName + " to " +
  125. string.Format(" {0}", selectedheight));
  126. m_module.Scene.RegionInfo.RegionSettings.WaterHeight = selectedheight;
  127. m_module.Scene.RegionInfo.RegionSettings.Save();
  128. m_module.TriggerRegionInfoChange();
  129. m_module.sendRegionHandshakeToAll();
  130. }
  131. }
  132. }
  133. protected void consoleSetTerrainHeights(string module, string[] args)
  134. {
  135. string num = args[3];
  136. string min = args[4];
  137. string max = args[5];
  138. int x = (args.Length > 6 ? int.Parse(args[6]) : -1);
  139. int y = (args.Length > 7 ? int.Parse(args[7]) : -1);
  140. if (x == -1 || m_module.Scene.RegionInfo.RegionLocX == x)
  141. {
  142. if (y == -1 || m_module.Scene.RegionInfo.RegionLocY == y)
  143. {
  144. int corner = int.Parse(num);
  145. float lowValue = float.Parse(min, Culture.NumberFormatInfo);
  146. float highValue = float.Parse(max, Culture.NumberFormatInfo);
  147. m_log.Debug("[ESTATEMODULE]: Setting terrain heights " + m_module.Scene.RegionInfo.RegionName +
  148. string.Format(" (C{0}, {1}-{2}", corner, lowValue, highValue));
  149. switch (corner)
  150. {
  151. case -1:
  152. m_module.Scene.RegionInfo.RegionSettings.Elevation1SW = lowValue;
  153. m_module.Scene.RegionInfo.RegionSettings.Elevation2SW = highValue;
  154. m_module.Scene.RegionInfo.RegionSettings.Elevation1NW = lowValue;
  155. m_module.Scene.RegionInfo.RegionSettings.Elevation2NW = highValue;
  156. m_module.Scene.RegionInfo.RegionSettings.Elevation1SE = lowValue;
  157. m_module.Scene.RegionInfo.RegionSettings.Elevation2SE = highValue;
  158. m_module.Scene.RegionInfo.RegionSettings.Elevation1NE = lowValue;
  159. m_module.Scene.RegionInfo.RegionSettings.Elevation2NE = highValue;
  160. break;
  161. case 0:
  162. m_module.Scene.RegionInfo.RegionSettings.Elevation1SW = lowValue;
  163. m_module.Scene.RegionInfo.RegionSettings.Elevation2SW = highValue;
  164. break;
  165. case 1:
  166. m_module.Scene.RegionInfo.RegionSettings.Elevation1NW = lowValue;
  167. m_module.Scene.RegionInfo.RegionSettings.Elevation2NW = highValue;
  168. break;
  169. case 2:
  170. m_module.Scene.RegionInfo.RegionSettings.Elevation1SE = lowValue;
  171. m_module.Scene.RegionInfo.RegionSettings.Elevation2SE = highValue;
  172. break;
  173. case 3:
  174. m_module.Scene.RegionInfo.RegionSettings.Elevation1NE = lowValue;
  175. m_module.Scene.RegionInfo.RegionSettings.Elevation2NE = highValue;
  176. break;
  177. }
  178. m_module.Scene.RegionInfo.RegionSettings.Save();
  179. m_module.TriggerRegionInfoChange();
  180. m_module.sendRegionHandshakeToAll();
  181. }
  182. }
  183. }
  184. protected void ShowEstatesCommand(string module, string[] cmd)
  185. {
  186. StringBuilder report = new StringBuilder();
  187. RegionInfo ri = m_module.Scene.RegionInfo;
  188. EstateSettings es = ri.EstateSettings;
  189. report.AppendFormat("Estate information for region {0}\n", ri.RegionName);
  190. report.AppendFormat(
  191. "{0,-20} {1,-7} {2,-20}\n",
  192. "Estate Name",
  193. "ID",
  194. "Owner");
  195. report.AppendFormat(
  196. "{0,-20} {1,-7} {2,-20}\n",
  197. es.EstateName, es.EstateID, m_module.UserManager.GetUserName(es.EstateOwner));
  198. MainConsole.Instance.Output(report.ToString());
  199. }
  200. }
  201. }