EstateManagementCommands.cs 13 KB

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