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. using OpenSim.Services.Interfaces;
  42. namespace OpenSim.Region.CoreModules.World.Estate
  43. {
  44. /// <summary>
  45. /// Estate management console commands.
  46. /// </summary>
  47. public class EstateManagementCommands
  48. {
  49. private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  50. protected EstateManagementModule m_module;
  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. #region CommandHandlers
  80. protected void consoleSetTerrainTexture(string module, string[] args)
  81. {
  82. string num = args[3];
  83. string uuid = args[4];
  84. int x = (args.Length > 5 ? int.Parse(args[5]) : -1);
  85. int y = (args.Length > 6 ? int.Parse(args[6]) : -1);
  86. if (x == -1 || m_module.Scene.RegionInfo.RegionLocX == x)
  87. {
  88. if (y == -1 || m_module.Scene.RegionInfo.RegionLocY == y)
  89. {
  90. int corner = int.Parse(num);
  91. UUID texture = UUID.Parse(uuid);
  92. m_log.Debug("[ESTATEMODULE]: Setting terrain textures for " + m_module.Scene.RegionInfo.RegionName +
  93. string.Format(" (C#{0} = {1})", corner, texture));
  94. switch (corner)
  95. {
  96. case 0:
  97. m_module.Scene.RegionInfo.RegionSettings.TerrainTexture1 = texture;
  98. break;
  99. case 1:
  100. m_module.Scene.RegionInfo.RegionSettings.TerrainTexture2 = texture;
  101. break;
  102. case 2:
  103. m_module.Scene.RegionInfo.RegionSettings.TerrainTexture3 = texture;
  104. break;
  105. case 3:
  106. m_module.Scene.RegionInfo.RegionSettings.TerrainTexture4 = texture;
  107. break;
  108. }
  109. m_module.Scene.RegionInfo.RegionSettings.Save();
  110. m_module.TriggerRegionInfoChange();
  111. m_module.sendRegionHandshakeToAll();
  112. }
  113. }
  114. }
  115. protected void consoleSetWaterHeight(string module, string[] args)
  116. {
  117. string heightstring = args[3];
  118. int x = (args.Length > 4 ? int.Parse(args[4]) : -1);
  119. int y = (args.Length > 5 ? int.Parse(args[5]) : -1);
  120. if (x == -1 || m_module.Scene.RegionInfo.RegionLocX == x)
  121. {
  122. if (y == -1 || m_module.Scene.RegionInfo.RegionLocY == y)
  123. {
  124. double selectedheight = double.Parse(heightstring);
  125. m_log.Debug("[ESTATEMODULE]: Setting water height in " + m_module.Scene.RegionInfo.RegionName + " to " +
  126. string.Format(" {0}", selectedheight));
  127. m_module.Scene.RegionInfo.RegionSettings.WaterHeight = selectedheight;
  128. m_module.Scene.RegionInfo.RegionSettings.Save();
  129. m_module.TriggerRegionInfoChange();
  130. m_module.sendRegionHandshakeToAll();
  131. }
  132. }
  133. }
  134. protected void consoleSetTerrainHeights(string module, string[] args)
  135. {
  136. string num = args[3];
  137. string min = args[4];
  138. string max = args[5];
  139. int x = (args.Length > 6 ? int.Parse(args[6]) : -1);
  140. int y = (args.Length > 7 ? int.Parse(args[7]) : -1);
  141. if (x == -1 || m_module.Scene.RegionInfo.RegionLocX == x)
  142. {
  143. if (y == -1 || m_module.Scene.RegionInfo.RegionLocY == y)
  144. {
  145. int corner = int.Parse(num);
  146. float lowValue = float.Parse(min, Culture.NumberFormatInfo);
  147. float highValue = float.Parse(max, Culture.NumberFormatInfo);
  148. m_log.Debug("[ESTATEMODULE]: Setting terrain heights " + m_module.Scene.RegionInfo.RegionName +
  149. string.Format(" (C{0}, {1}-{2}", corner, lowValue, highValue));
  150. switch (corner)
  151. {
  152. case -1:
  153. m_module.Scene.RegionInfo.RegionSettings.Elevation1SW = lowValue;
  154. m_module.Scene.RegionInfo.RegionSettings.Elevation2SW = highValue;
  155. m_module.Scene.RegionInfo.RegionSettings.Elevation1NW = lowValue;
  156. m_module.Scene.RegionInfo.RegionSettings.Elevation2NW = highValue;
  157. m_module.Scene.RegionInfo.RegionSettings.Elevation1SE = lowValue;
  158. m_module.Scene.RegionInfo.RegionSettings.Elevation2SE = highValue;
  159. m_module.Scene.RegionInfo.RegionSettings.Elevation1NE = lowValue;
  160. m_module.Scene.RegionInfo.RegionSettings.Elevation2NE = highValue;
  161. break;
  162. case 0:
  163. m_module.Scene.RegionInfo.RegionSettings.Elevation1SW = lowValue;
  164. m_module.Scene.RegionInfo.RegionSettings.Elevation2SW = highValue;
  165. break;
  166. case 1:
  167. m_module.Scene.RegionInfo.RegionSettings.Elevation1NW = lowValue;
  168. m_module.Scene.RegionInfo.RegionSettings.Elevation2NW = highValue;
  169. break;
  170. case 2:
  171. m_module.Scene.RegionInfo.RegionSettings.Elevation1SE = lowValue;
  172. m_module.Scene.RegionInfo.RegionSettings.Elevation2SE = highValue;
  173. break;
  174. case 3:
  175. m_module.Scene.RegionInfo.RegionSettings.Elevation1NE = lowValue;
  176. m_module.Scene.RegionInfo.RegionSettings.Elevation2NE = highValue;
  177. break;
  178. }
  179. m_module.Scene.RegionInfo.RegionSettings.Save();
  180. m_module.TriggerRegionInfoChange();
  181. m_module.sendRegionHandshakeToAll();
  182. }
  183. }
  184. }
  185. protected void ShowEstatesCommand(string module, string[] cmd)
  186. {
  187. StringBuilder report = new StringBuilder();
  188. RegionInfo ri = m_module.Scene.RegionInfo;
  189. EstateSettings es = ri.EstateSettings;
  190. report.AppendFormat("Estate information for region {0}\n", ri.RegionName);
  191. report.AppendFormat(
  192. "{0,-20} {1,-7} {2,-20}\n",
  193. "Estate Name",
  194. "ID",
  195. "Owner");
  196. report.AppendFormat(
  197. "{0,-20} {1,-7} {2,-20}\n",
  198. es.EstateName, es.EstateID, m_module.UserManager.GetUserName(es.EstateOwner));
  199. MainConsole.Instance.Output(report.ToString());
  200. }
  201. #endregion
  202. }
  203. }