EstateManagementCommands.cs 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  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(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(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.",
  69. consoleSetTerrainHeights);
  70. Command showCommand
  71. = new Command("show", CommandIntentions.COMMAND_STATISTICAL, ShowEstatesCommand, "Shows all estates on the simulator.");
  72. m_commander.RegisterCommand("show", showCommand);
  73. m_module.Scene.RegisterModuleCommander(m_commander);
  74. m_module.Scene.EventManager.OnPluginConsole += EventManagerOnPluginConsole;
  75. }
  76. public void Close()
  77. {
  78. m_module.Scene.EventManager.OnPluginConsole -= EventManagerOnPluginConsole;
  79. m_module.Scene.UnregisterModuleCommander(m_commander.Name);
  80. }
  81. /// <summary>
  82. /// Processes commandline input. Do not call directly.
  83. /// </summary>
  84. /// <param name="args">Commandline arguments</param>
  85. protected void EventManagerOnPluginConsole(string[] args)
  86. {
  87. if (args[0] == "estate")
  88. {
  89. if (args.Length == 1)
  90. {
  91. m_commander.ProcessConsoleCommand("help", new string[0]);
  92. return;
  93. }
  94. string[] tmpArgs = new string[args.Length - 2];
  95. int i;
  96. for (i = 2; i < args.Length; i++)
  97. tmpArgs[i - 2] = args[i];
  98. m_commander.ProcessConsoleCommand(args[1], tmpArgs);
  99. }
  100. }
  101. protected void consoleSetTerrainTexture(string module, string[] args)
  102. {
  103. string num = args[3];
  104. string uuid = args[4];
  105. int x = (args.Length > 5 ? int.Parse(args[5]) : -1);
  106. int y = (args.Length > 6 ? int.Parse(args[6]) : -1);
  107. if (x == -1 || m_module.Scene.RegionInfo.RegionLocX == x)
  108. {
  109. if (y == -1 || m_module.Scene.RegionInfo.RegionLocY == y)
  110. {
  111. int corner = int.Parse(num);
  112. UUID texture = UUID.Parse(uuid);
  113. m_log.Debug("[ESTATEMODULE]: Setting terrain textures for " + m_module.Scene.RegionInfo.RegionName +
  114. string.Format(" (C#{0} = {1})", corner, texture));
  115. switch (corner)
  116. {
  117. case 0:
  118. m_module.Scene.RegionInfo.RegionSettings.TerrainTexture1 = texture;
  119. break;
  120. case 1:
  121. m_module.Scene.RegionInfo.RegionSettings.TerrainTexture2 = texture;
  122. break;
  123. case 2:
  124. m_module.Scene.RegionInfo.RegionSettings.TerrainTexture3 = texture;
  125. break;
  126. case 3:
  127. m_module.Scene.RegionInfo.RegionSettings.TerrainTexture4 = texture;
  128. break;
  129. }
  130. m_module.Scene.RegionInfo.RegionSettings.Save();
  131. m_module.TriggerRegionInfoChange();
  132. m_module.sendRegionInfoPacketToAll();
  133. }
  134. }
  135. }
  136. protected void consoleSetTerrainHeights(string module, string[] args)
  137. {
  138. string num = args[3];
  139. string min = args[4];
  140. string max = args[5];
  141. int x = (args.Length > 6 ? int.Parse(args[6]) : -1);
  142. int y = (args.Length > 7 ? int.Parse(args[7]) : -1);
  143. if (x == -1 || m_module.Scene.RegionInfo.RegionLocX == x)
  144. {
  145. if (y == -1 || m_module.Scene.RegionInfo.RegionLocY == y)
  146. {
  147. int corner = int.Parse(num);
  148. float lowValue = float.Parse(min, Culture.NumberFormatInfo);
  149. float highValue = float.Parse(max, Culture.NumberFormatInfo);
  150. m_log.Debug("[ESTATEMODULE]: Setting terrain heights " + m_module.Scene.RegionInfo.RegionName +
  151. string.Format(" (C{0}, {1}-{2}", corner, lowValue, highValue));
  152. switch (corner)
  153. {
  154. case 0:
  155. m_module.Scene.RegionInfo.RegionSettings.Elevation1SW = lowValue;
  156. m_module.Scene.RegionInfo.RegionSettings.Elevation2SW = highValue;
  157. break;
  158. case 1:
  159. m_module.Scene.RegionInfo.RegionSettings.Elevation1NW = lowValue;
  160. m_module.Scene.RegionInfo.RegionSettings.Elevation2NW = highValue;
  161. break;
  162. case 2:
  163. m_module.Scene.RegionInfo.RegionSettings.Elevation1SE = lowValue;
  164. m_module.Scene.RegionInfo.RegionSettings.Elevation2SE = highValue;
  165. break;
  166. case 3:
  167. m_module.Scene.RegionInfo.RegionSettings.Elevation1NE = lowValue;
  168. m_module.Scene.RegionInfo.RegionSettings.Elevation2NE = highValue;
  169. break;
  170. }
  171. m_module.Scene.RegionInfo.RegionSettings.Save();
  172. m_module.TriggerRegionInfoChange();
  173. m_module.sendRegionHandshakeToAll();
  174. }
  175. }
  176. }
  177. protected void ShowEstatesCommand(Object[] args)
  178. {
  179. StringBuilder report = new StringBuilder();
  180. RegionInfo ri = m_module.Scene.RegionInfo;
  181. EstateSettings es = ri.EstateSettings;
  182. report.AppendFormat("Estate information for region {0}\n", ri.RegionName);
  183. report.AppendFormat(
  184. "{0,-20} {1,-7} {2,-20}\n",
  185. "Estate Name",
  186. "ID",
  187. "Owner");
  188. report.AppendFormat(
  189. "{0,-20} {1,-7} {2,-20}\n",
  190. es.EstateName, es.EstateID, m_module.UserManager.GetUserName(es.EstateOwner));
  191. MainConsole.Instance.Output(report.ToString());
  192. }
  193. }
  194. }