PageRenderTime 56ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 1ms

/OpenMetaverse/Modules/EstateTools.cs

https://bitbucket.org/VirtualReality/3rdparty-addon-modules
C# | 1235 lines | 752 code | 129 blank | 354 comment | 71 complexity | b2e12ed5bc108f49c88e2163393663bd MD5 | raw file

Large files files are truncated, but you can click here to view the full file

  1. /*
  2. * Copyright (c) 2006-2008, openmetaverse.org
  3. * All rights reserved.
  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. *
  8. * - Redistributions of source code must retain the above copyright notice, this
  9. * list of conditions and the following disclaimer.
  10. * - Neither the name of the openmetaverse.org nor the names
  11. * of its contributors may be used to endorse or promote products derived from
  12. * this software without specific prior written permission.
  13. *
  14. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  15. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  16. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  17. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  18. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  19. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  20. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  21. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  22. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  23. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  24. * POSSIBILITY OF SUCH DAMAGE.
  25. */
  26. using System;
  27. using OpenMetaverse.Packets;
  28. using OpenMetaverse.Interfaces;
  29. using OpenMetaverse.Messages.Linden;
  30. using System.Collections.Generic;
  31. namespace OpenMetaverse
  32. {
  33. /// <summary>Describes tasks returned in LandStatReply</summary>
  34. public class EstateTask
  35. {
  36. public Vector3 Position;
  37. public float Score;
  38. public float MonoScore;
  39. public UUID TaskID;
  40. public uint TaskLocalID;
  41. public string TaskName;
  42. public string OwnerName;
  43. }
  44. /// <summary>
  45. /// Estate level administration and utilities
  46. /// </summary>
  47. public class EstateTools
  48. {
  49. private GridClient Client;
  50. /// <summary>Textures for each of the four terrain height levels</summary>
  51. public GroundTextureSettings GroundTextures;
  52. /// <summary>Upper/lower texture boundaries for each corner of the sim</summary>
  53. public GroundTextureHeightSettings GroundTextureLimits;
  54. /// <summary>
  55. /// Constructor for EstateTools class
  56. /// </summary>
  57. /// <param name="client"></param>
  58. public EstateTools(GridClient client)
  59. {
  60. GroundTextures = new GroundTextureSettings();
  61. GroundTextureLimits = new GroundTextureHeightSettings();
  62. Client = client;
  63. Client.Network.RegisterCallback(PacketType.LandStatReply, LandStatReplyHandler);
  64. Client.Network.RegisterCallback(PacketType.EstateOwnerMessage, EstateOwnerMessageHandler);
  65. Client.Network.RegisterCallback(PacketType.EstateCovenantReply, EstateCovenantReplyHandler);
  66. Client.Network.RegisterEventCallback("LandStatReply", new Caps.EventQueueCallback(LandStatCapsReplyHandler));
  67. }
  68. #region Enums
  69. /// <summary>Used in the ReportType field of a LandStatRequest</summary>
  70. public enum LandStatReportType
  71. {
  72. TopScripts = 0,
  73. TopColliders = 1
  74. }
  75. /// <summary>Used by EstateOwnerMessage packets</summary>
  76. public enum EstateAccessDelta : uint
  77. {
  78. BanUser = 64,
  79. BanUserAllEstates = 66,
  80. UnbanUser = 128,
  81. UnbanUserAllEstates = 130,
  82. AddManager = 256,
  83. AddManagerAllEstates = 257,
  84. RemoveManager = 512,
  85. RemoveManagerAllEstates = 513,
  86. AddUserAsAllowed = 4,
  87. AddAllowedAllEstates = 6,
  88. RemoveUserAsAllowed = 8,
  89. RemoveUserAllowedAllEstates = 10,
  90. AddGroupAsAllowed = 16,
  91. AddGroupAllowedAllEstates = 18,
  92. RemoveGroupAsAllowed = 32,
  93. RemoveGroupAllowedAllEstates = 34
  94. }
  95. /// <summary>Used by EstateOwnerMessage packets</summary>
  96. public enum EstateAccessReplyDelta : uint
  97. {
  98. AllowedUsers = 17,
  99. AllowedGroups = 18,
  100. EstateBans = 20,
  101. EstateManagers = 24
  102. }
  103. /// <summary>
  104. ///
  105. /// </summary>
  106. [Flags]
  107. public enum EstateReturnFlags : uint
  108. {
  109. /// <summary>No flags set</summary>
  110. None = 2,
  111. /// <summary>Only return targets scripted objects</summary>
  112. ReturnScripted = 6,
  113. /// <summary>Only return targets objects if on others land</summary>
  114. ReturnOnOthersLand = 3,
  115. /// <summary>Returns target's scripted objects and objects on other parcels</summary>
  116. ReturnScriptedAndOnOthers = 7
  117. }
  118. #endregion
  119. #region Structs
  120. /// <summary>Ground texture settings for each corner of the region</summary>
  121. // TODO: maybe move this class to the Simulator object and implement it there too
  122. public struct GroundTextureSettings
  123. {
  124. public UUID Low;
  125. public UUID MidLow;
  126. public UUID MidHigh;
  127. public UUID High;
  128. }
  129. /// <summary>Used by GroundTextureHeightSettings</summary>
  130. public struct GroundTextureHeight
  131. {
  132. public float Low;
  133. public float High;
  134. }
  135. /// <summary>The high and low texture thresholds for each corner of the sim</summary>
  136. public struct GroundTextureHeightSettings
  137. {
  138. public GroundTextureHeight SW;
  139. public GroundTextureHeight NW;
  140. public GroundTextureHeight SE;
  141. public GroundTextureHeight NE;
  142. }
  143. #endregion
  144. #region Event delegates, Raise Events
  145. /// <summary>The event subscribers. null if no subcribers</summary>
  146. private EventHandler<TopCollidersReplyEventArgs> m_TopCollidersReply;
  147. /// <summary>Raises the TopCollidersReply event</summary>
  148. /// <param name="e">A TopCollidersReplyEventArgs object containing the
  149. /// data returned from the data server</param>
  150. protected virtual void OnTopCollidersReply(TopCollidersReplyEventArgs e)
  151. {
  152. EventHandler<TopCollidersReplyEventArgs> handler = m_TopCollidersReply;
  153. if (handler != null)
  154. handler(this, e);
  155. }
  156. /// <summary>Thread sync lock object</summary>
  157. private readonly object m_TopCollidersReply_Lock = new object();
  158. /// <summary>Raised when the data server responds to a <see cref="LandStatRequest"/> request.</summary>
  159. public event EventHandler<TopCollidersReplyEventArgs> TopCollidersReply
  160. {
  161. add { lock (m_TopCollidersReply_Lock) { m_TopCollidersReply += value; } }
  162. remove { lock (m_TopCollidersReply_Lock) { m_TopCollidersReply -= value; } }
  163. }
  164. /// <summary>The event subscribers. null if no subcribers</summary>
  165. private EventHandler<TopScriptsReplyEventArgs> m_TopScriptsReply;
  166. /// <summary>Raises the TopScriptsReply event</summary>
  167. /// <param name="e">A TopScriptsReplyEventArgs object containing the
  168. /// data returned from the data server</param>
  169. protected virtual void OnTopScriptsReply(TopScriptsReplyEventArgs e)
  170. {
  171. EventHandler<TopScriptsReplyEventArgs> handler = m_TopScriptsReply;
  172. if (handler != null)
  173. handler(this, e);
  174. }
  175. /// <summary>Thread sync lock object</summary>
  176. private readonly object m_TopScriptsReply_Lock = new object();
  177. /// <summary>Raised when the data server responds to a <see cref="LandStatRequest"/> request.</summary>
  178. public event EventHandler<TopScriptsReplyEventArgs> TopScriptsReply
  179. {
  180. add { lock (m_TopScriptsReply_Lock) { m_TopScriptsReply += value; } }
  181. remove { lock (m_TopScriptsReply_Lock) { m_TopScriptsReply -= value; } }
  182. }
  183. /// <summary>The event subscribers. null if no subcribers</summary>
  184. private EventHandler<EstateUsersReplyEventArgs> m_EstateUsersReply;
  185. /// <summary>Raises the EstateUsersReply event</summary>
  186. /// <param name="e">A EstateUsersReplyEventArgs object containing the
  187. /// data returned from the data server</param>
  188. protected virtual void OnEstateUsersReply(EstateUsersReplyEventArgs e)
  189. {
  190. EventHandler<EstateUsersReplyEventArgs> handler = m_EstateUsersReply;
  191. if (handler != null)
  192. handler(this, e);
  193. }
  194. /// <summary>Thread sync lock object</summary>
  195. private readonly object m_EstateUsersReply_Lock = new object();
  196. /// <summary>Raised when the data server responds to a <see cref="LandStatRequest"/> request.</summary>
  197. public event EventHandler<EstateUsersReplyEventArgs> EstateUsersReply
  198. {
  199. add { lock (m_EstateUsersReply_Lock) { m_EstateUsersReply += value; } }
  200. remove { lock (m_EstateUsersReply_Lock) { m_EstateUsersReply -= value; } }
  201. }
  202. /// <summary>The event subscribers. null if no subcribers</summary>
  203. private EventHandler<EstateGroupsReplyEventArgs> m_EstateGroupsReply;
  204. /// <summary>Raises the EstateGroupsReply event</summary>
  205. /// <param name="e">A EstateGroupsReplyEventArgs object containing the
  206. /// data returned from the data server</param>
  207. protected virtual void OnEstateGroupsReply(EstateGroupsReplyEventArgs e)
  208. {
  209. EventHandler<EstateGroupsReplyEventArgs> handler = m_EstateGroupsReply;
  210. if (handler != null)
  211. handler(this, e);
  212. }
  213. /// <summary>Thread sync lock object</summary>
  214. private readonly object m_EstateGroupsReply_Lock = new object();
  215. /// <summary>Raised when the data server responds to a <see cref="LandStatRequest"/> request.</summary>
  216. public event EventHandler<EstateGroupsReplyEventArgs> EstateGroupsReply
  217. {
  218. add { lock (m_EstateGroupsReply_Lock) { m_EstateGroupsReply += value; } }
  219. remove { lock (m_EstateGroupsReply_Lock) { m_EstateGroupsReply -= value; } }
  220. }
  221. /// <summary>The event subscribers. null if no subcribers</summary>
  222. private EventHandler<EstateManagersReplyEventArgs> m_EstateManagersReply;
  223. /// <summary>Raises the EstateManagersReply event</summary>
  224. /// <param name="e">A EstateManagersReplyEventArgs object containing the
  225. /// data returned from the data server</param>
  226. protected virtual void OnEstateManagersReply(EstateManagersReplyEventArgs e)
  227. {
  228. EventHandler<EstateManagersReplyEventArgs> handler = m_EstateManagersReply;
  229. if (handler != null)
  230. handler(this, e);
  231. }
  232. /// <summary>Thread sync lock object</summary>
  233. private readonly object m_EstateManagersReply_Lock = new object();
  234. /// <summary>Raised when the data server responds to a <see cref="LandStatRequest"/> request.</summary>
  235. public event EventHandler<EstateManagersReplyEventArgs> EstateManagersReply
  236. {
  237. add { lock (m_EstateManagersReply_Lock) { m_EstateManagersReply += value; } }
  238. remove { lock (m_EstateManagersReply_Lock) { m_EstateManagersReply -= value; } }
  239. }
  240. /// <summary>The event subscribers. null if no subcribers</summary>
  241. private EventHandler<EstateBansReplyEventArgs> m_EstateBansReply;
  242. /// <summary>Raises the EstateBansReply event</summary>
  243. /// <param name="e">A EstateBansReplyEventArgs object containing the
  244. /// data returned from the data server</param>
  245. protected virtual void OnEstateBansReply(EstateBansReplyEventArgs e)
  246. {
  247. EventHandler<EstateBansReplyEventArgs> handler = m_EstateBansReply;
  248. if (handler != null)
  249. handler(this, e);
  250. }
  251. /// <summary>Thread sync lock object</summary>
  252. private readonly object m_EstateBansReply_Lock = new object();
  253. /// <summary>Raised when the data server responds to a <see cref="LandStatRequest"/> request.</summary>
  254. public event EventHandler<EstateBansReplyEventArgs> EstateBansReply
  255. {
  256. add { lock (m_EstateBansReply_Lock) { m_EstateBansReply += value; } }
  257. remove { lock (m_EstateBansReply_Lock) { m_EstateBansReply -= value; } }
  258. }
  259. /// <summary>The event subscribers. null if no subcribers</summary>
  260. private EventHandler<EstateCovenantReplyEventArgs> m_EstateCovenantReply;
  261. /// <summary>Raises the EstateCovenantReply event</summary>
  262. /// <param name="e">A EstateCovenantReplyEventArgs object containing the
  263. /// data returned from the data server</param>
  264. protected virtual void OnEstateCovenantReply(EstateCovenantReplyEventArgs e)
  265. {
  266. EventHandler<EstateCovenantReplyEventArgs> handler = m_EstateCovenantReply;
  267. if (handler != null)
  268. handler(this, e);
  269. }
  270. /// <summary>Thread sync lock object</summary>
  271. private readonly object m_EstateCovenantReply_Lock = new object();
  272. /// <summary>Raised when the data server responds to a <see cref="LandStatRequest"/> request.</summary>
  273. public event EventHandler<EstateCovenantReplyEventArgs> EstateCovenantReply
  274. {
  275. add { lock (m_EstateCovenantReply_Lock) { m_EstateCovenantReply += value; } }
  276. remove { lock (m_EstateCovenantReply_Lock) { m_EstateCovenantReply -= value; } }
  277. }
  278. /// <summary>The event subscribers. null if no subcribers</summary>
  279. private EventHandler<EstateUpdateInfoReplyEventArgs> m_EstateUpdateInfoReply;
  280. /// <summary>Raises the EstateUpdateInfoReply event</summary>
  281. /// <param name="e">A EstateUpdateInfoReplyEventArgs object containing the
  282. /// data returned from the data server</param>
  283. protected virtual void OnEstateUpdateInfoReply(EstateUpdateInfoReplyEventArgs e)
  284. {
  285. EventHandler<EstateUpdateInfoReplyEventArgs> handler = m_EstateUpdateInfoReply;
  286. if (handler != null)
  287. handler(this, e);
  288. }
  289. /// <summary>Thread sync lock object</summary>
  290. private readonly object m_EstateUpdateInfoReply_Lock = new object();
  291. /// <summary>Raised when the data server responds to a <see cref="LandStatRequest"/> request.</summary>
  292. public event EventHandler<EstateUpdateInfoReplyEventArgs> EstateUpdateInfoReply
  293. {
  294. add { lock (m_EstateUpdateInfoReply_Lock) { m_EstateUpdateInfoReply += value; } }
  295. remove { lock (m_EstateUpdateInfoReply_Lock) { m_EstateUpdateInfoReply -= value; } }
  296. }
  297. #endregion
  298. #region Public Methods
  299. /// <summary>
  300. /// Requests estate information such as top scripts and colliders
  301. /// </summary>
  302. /// <param name="parcelLocalID"></param>
  303. /// <param name="reportType"></param>
  304. /// <param name="requestFlags"></param>
  305. /// <param name="filter"></param>
  306. public void LandStatRequest(int parcelLocalID, LandStatReportType reportType, uint requestFlags, string filter)
  307. {
  308. LandStatRequestPacket p = new LandStatRequestPacket();
  309. p.AgentData.AgentID = Client.Self.AgentID;
  310. p.AgentData.SessionID = Client.Self.SessionID;
  311. p.RequestData.Filter = Utils.StringToBytes(filter);
  312. p.RequestData.ParcelLocalID = parcelLocalID;
  313. p.RequestData.ReportType = (uint)reportType;
  314. p.RequestData.RequestFlags = requestFlags;
  315. Client.Network.SendPacket(p);
  316. }
  317. /// <summary>Requests estate settings, including estate manager and access/ban lists</summary>
  318. public void RequestInfo()
  319. {
  320. EstateOwnerMessage("getinfo", "");
  321. }
  322. /// <summary>Requests the "Top Scripts" list for the current region</summary>
  323. public void RequestTopScripts()
  324. {
  325. //EstateOwnerMessage("scripts", "");
  326. LandStatRequest(0, LandStatReportType.TopScripts, 0, "");
  327. }
  328. /// <summary>Requests the "Top Colliders" list for the current region</summary>
  329. public void RequestTopColliders()
  330. {
  331. //EstateOwnerMessage("colliders", "");
  332. LandStatRequest(0, LandStatReportType.TopColliders, 0, "");
  333. }
  334. /// <summary>
  335. /// Set several estate specific configuration variables
  336. /// </summary>
  337. /// <param name="WaterHeight">The Height of the waterlevel over the entire estate. Defaults to 20</param>
  338. /// <param name="TerrainRaiseLimit">The maximum height change allowed above the baked terrain. Defaults to 4</param>
  339. /// <param name="TerrainLowerLimit">The minimum height change allowed below the baked terrain. Defaults to -4</param>
  340. /// <param name="UseEstateSun">true to use</param>
  341. /// <param name="FixedSun">if True forces the sun position to the position in SunPosition</param>
  342. /// <param name="SunPosition">The current position of the sun on the estate, or when FixedSun is true the static position
  343. /// the sun will remain. <remarks>6.0 = Sunrise, 30.0 = Sunset</remarks></param>
  344. public void SetTerrainVariables(float WaterHeight, float TerrainRaiseLimit,
  345. float TerrainLowerLimit, bool UseEstateSun, bool FixedSun, float SunPosition)
  346. {
  347. List<string> simVariables = new List<string>();
  348. simVariables.Add(WaterHeight.ToString(Utils.EnUsCulture));
  349. simVariables.Add(TerrainRaiseLimit.ToString(Utils.EnUsCulture));
  350. simVariables.Add(TerrainLowerLimit.ToString(Utils.EnUsCulture));
  351. simVariables.Add(UseEstateSun ? "Y" : "N");
  352. simVariables.Add(FixedSun ? "Y" : "N");
  353. simVariables.Add(SunPosition.ToString(Utils.EnUsCulture));
  354. simVariables.Add("Y"); //Not used?
  355. simVariables.Add("N"); //Not used?
  356. simVariables.Add("0.00"); //Also not used?
  357. EstateOwnerMessage("setregionterrain", simVariables);
  358. }
  359. /// <summary>
  360. /// Request return of objects owned by specified avatar
  361. /// </summary>
  362. /// <param name="Target">The Agents <see cref="UUID"/> owning the primitives to return</param>
  363. /// <param name="flag">specify the coverage and type of objects to be included in the return</param>
  364. /// <param name="EstateWide">true to perform return on entire estate</param>
  365. public void SimWideReturn(UUID Target, EstateReturnFlags flag, bool EstateWide)
  366. {
  367. if (EstateWide)
  368. {
  369. List<string> param = new List<string>();
  370. param.Add(flag.ToString());
  371. param.Add(Target.ToString());
  372. EstateOwnerMessage("estateobjectreturn", param);
  373. }
  374. else
  375. {
  376. SimWideDeletesPacket simDelete = new SimWideDeletesPacket();
  377. simDelete.AgentData.AgentID = Client.Self.AgentID;
  378. simDelete.AgentData.SessionID = Client.Self.SessionID;
  379. simDelete.DataBlock.TargetID = Target;
  380. simDelete.DataBlock.Flags = (uint)flag;
  381. Client.Network.SendPacket(simDelete);
  382. }
  383. }
  384. /// <summary></summary>
  385. /// <param name="method"></param>
  386. /// <param name="param"></param>
  387. public void EstateOwnerMessage(string method, string param)
  388. {
  389. List<string> listParams = new List<string>();
  390. listParams.Add(param);
  391. EstateOwnerMessage(method, listParams);
  392. }
  393. /// <summary>
  394. /// Used for setting and retrieving various estate panel settings
  395. /// </summary>
  396. /// <param name="method">EstateOwnerMessage Method field</param>
  397. /// <param name="listParams">List of parameters to include</param>
  398. public void EstateOwnerMessage(string method, List<string> listParams)
  399. {
  400. EstateOwnerMessagePacket estate = new EstateOwnerMessagePacket();
  401. estate.AgentData.AgentID = Client.Self.AgentID;
  402. estate.AgentData.SessionID = Client.Self.SessionID;
  403. estate.AgentData.TransactionID = UUID.Zero;
  404. estate.MethodData.Invoice = UUID.Random();
  405. estate.MethodData.Method = Utils.StringToBytes(method);
  406. estate.ParamList = new EstateOwnerMessagePacket.ParamListBlock[listParams.Count];
  407. for (int i = 0; i < listParams.Count; i++)
  408. {
  409. estate.ParamList[i] = new EstateOwnerMessagePacket.ParamListBlock();
  410. estate.ParamList[i].Parameter = Utils.StringToBytes(listParams[i]);
  411. }
  412. Client.Network.SendPacket((Packet)estate);
  413. }
  414. /// <summary>
  415. /// Kick an avatar from an estate
  416. /// </summary>
  417. /// <param name="userID">Key of Agent to remove</param>
  418. public void KickUser(UUID userID)
  419. {
  420. EstateOwnerMessage("kickestate", userID.ToString());
  421. }
  422. /// <summary>
  423. /// Ban an avatar from an estate</summary>
  424. /// <param name="userID">Key of Agent to remove</param>
  425. /// <param name="allEstates">Ban user from this estate and all others owned by the estate owner</param>
  426. public void BanUser(UUID userID, bool allEstates)
  427. {
  428. List<string> listParams = new List<string>();
  429. uint flag = allEstates ? (uint)EstateAccessDelta.BanUserAllEstates : (uint)EstateAccessDelta.BanUser;
  430. listParams.Add(Client.Self.AgentID.ToString());
  431. listParams.Add(flag.ToString());
  432. listParams.Add(userID.ToString());
  433. EstateOwnerMessage("estateaccessdelta", listParams);
  434. }
  435. /// <summary>Unban an avatar from an estate</summary>
  436. /// <param name="userID">Key of Agent to remove</param>
  437. /// /// <param name="allEstates">Unban user from this estate and all others owned by the estate owner</param>
  438. public void UnbanUser(UUID userID, bool allEstates)
  439. {
  440. List<string> listParams = new List<string>();
  441. uint flag = allEstates ? (uint)EstateAccessDelta.UnbanUserAllEstates : (uint)EstateAccessDelta.UnbanUser;
  442. listParams.Add(Client.Self.AgentID.ToString());
  443. listParams.Add(flag.ToString());
  444. listParams.Add(userID.ToString());
  445. EstateOwnerMessage("estateaccessdelta", listParams);
  446. }
  447. /// <summary>
  448. /// Send a message dialog to everyone in an entire estate
  449. /// </summary>
  450. /// <param name="message">Message to send all users in the estate</param>
  451. public void EstateMessage(string message)
  452. {
  453. List<string> listParams = new List<string>();
  454. listParams.Add(Client.Self.FirstName + " " + Client.Self.LastName);
  455. listParams.Add(message);
  456. EstateOwnerMessage("instantmessage", listParams);
  457. }
  458. /// <summary>
  459. /// Send a message dialog to everyone in a simulator
  460. /// </summary>
  461. /// <param name="message">Message to send all users in the simulator</param>
  462. public void SimulatorMessage(string message)
  463. {
  464. List<string> listParams = new List<string>();
  465. listParams.Add("-1");
  466. listParams.Add("-1");
  467. listParams.Add(Client.Self.AgentID.ToString());
  468. listParams.Add(Client.Self.FirstName + " " + Client.Self.LastName);
  469. listParams.Add(message);
  470. EstateOwnerMessage("simulatormessage", listParams);
  471. }
  472. /// <summary>
  473. /// Send an avatar back to their home location
  474. /// </summary>
  475. /// <param name="pest">Key of avatar to send home</param>
  476. public void TeleportHomeUser(UUID pest)
  477. {
  478. List<string> listParams = new List<string>();
  479. listParams.Add(Client.Self.AgentID.ToString());
  480. listParams.Add(pest.ToString());
  481. EstateOwnerMessage("teleporthomeuser", listParams);
  482. }
  483. /// <summary>
  484. /// Begin the region restart process
  485. /// </summary>
  486. public void RestartRegion()
  487. {
  488. EstateOwnerMessage("restart", "120");
  489. }
  490. /// <summary>
  491. /// Cancels a region restart
  492. /// </summary>
  493. public void CancelRestart()
  494. {
  495. EstateOwnerMessage("restart", "-1");
  496. }
  497. /// <summary>Estate panel "Region" tab settings</summary>
  498. public void SetRegionInfo(bool blockTerraform, bool blockFly, bool allowDamage, bool allowLandResell, bool restrictPushing, bool allowParcelJoinDivide, float agentLimit, float objectBonus, bool mature)
  499. {
  500. List<string> listParams = new List<string>();
  501. if (blockTerraform) listParams.Add("Y"); else listParams.Add("N");
  502. if (blockFly) listParams.Add("Y"); else listParams.Add("N");
  503. if (allowDamage) listParams.Add("Y"); else listParams.Add("N");
  504. if (allowLandResell) listParams.Add("Y"); else listParams.Add("N");
  505. listParams.Add(agentLimit.ToString());
  506. listParams.Add(objectBonus.ToString());
  507. if (mature) listParams.Add("21"); else listParams.Add("13"); //FIXME - enumerate these settings
  508. if (restrictPushing) listParams.Add("Y"); else listParams.Add("N");
  509. if (allowParcelJoinDivide) listParams.Add("Y"); else listParams.Add("N");
  510. EstateOwnerMessage("setregioninfo", listParams);
  511. }
  512. /// <summary>Estate panel "Debug" tab settings</summary>
  513. public void SetRegionDebug(bool disableScripts, bool disableCollisions, bool disablePhysics)
  514. {
  515. List<string> listParams = new List<string>();
  516. if (disableScripts) listParams.Add("Y"); else listParams.Add("N");
  517. if (disableCollisions) listParams.Add("Y"); else listParams.Add("N");
  518. if (disablePhysics) listParams.Add("Y"); else listParams.Add("N");
  519. EstateOwnerMessage("setregiondebug", listParams);
  520. }
  521. /// <summary>Used for setting the region's terrain textures for its four height levels</summary>
  522. /// <param name="low"></param>
  523. /// <param name="midLow"></param>
  524. /// <param name="midHigh"></param>
  525. /// <param name="high"></param>
  526. public void SetRegionTerrain(UUID low, UUID midLow, UUID midHigh, UUID high)
  527. {
  528. List<string> listParams = new List<string>();
  529. listParams.Add("0 " + low.ToString());
  530. listParams.Add("1 " + midLow.ToString());
  531. listParams.Add("2 " + midHigh.ToString());
  532. listParams.Add("3 " + high.ToString());
  533. EstateOwnerMessage("texturedetail", listParams);
  534. EstateOwnerMessage("texturecommit", "");
  535. }
  536. /// <summary>Used for setting sim terrain texture heights</summary>
  537. public void SetRegionTerrainHeights(float lowSW, float highSW, float lowNW, float highNW, float lowSE, float highSE, float lowNE, float highNE)
  538. {
  539. List<string> listParams = new List<string>();
  540. listParams.Add("0 " + lowSW.ToString(Utils.EnUsCulture) + " " + highSW.ToString(Utils.EnUsCulture)); //SW low-high
  541. listParams.Add("1 " + lowNW.ToString(Utils.EnUsCulture) + " " + highNW.ToString(Utils.EnUsCulture)); //NW low-high
  542. listParams.Add("2 " + lowSE.ToString(Utils.EnUsCulture) + " " + highSE.ToString(Utils.EnUsCulture)); //SE low-high
  543. listParams.Add("3 " + lowNE.ToString(Utils.EnUsCulture) + " " + highNE.ToString(Utils.EnUsCulture)); //NE low-high
  544. EstateOwnerMessage("textureheights", listParams);
  545. EstateOwnerMessage("texturecommit", "");
  546. }
  547. /// <summary>Requests the estate covenant</summary>
  548. public void RequestCovenant()
  549. {
  550. EstateCovenantRequestPacket req = new EstateCovenantRequestPacket();
  551. req.AgentData.AgentID = Client.Self.AgentID;
  552. req.AgentData.SessionID = Client.Self.SessionID;
  553. Client.Network.SendPacket(req);
  554. }
  555. /// <summary>
  556. /// Upload a terrain RAW file
  557. /// </summary>
  558. /// <param name="fileData">A byte array containing the encoded terrain data</param>
  559. /// <param name="fileName">The name of the file being uploaded</param>
  560. /// <returns>The Id of the transfer request</returns>
  561. public UUID UploadTerrain(byte[] fileData, string fileName)
  562. {
  563. AssetUpload upload = new AssetUpload();
  564. upload.AssetData = fileData;
  565. upload.AssetType = AssetType.Unknown;
  566. upload.Size = fileData.Length;
  567. upload.ID = UUID.Random();
  568. // Tell the library we have a pending file to upload
  569. Client.Assets.SetPendingAssetUploadData(upload);
  570. // Create and populate a list with commands specific to uploading a raw terrain file
  571. List<String> paramList = new List<string>();
  572. paramList.Add("upload filename");
  573. paramList.Add(fileName);
  574. // Tell the simulator we have a new raw file to upload
  575. Client.Estate.EstateOwnerMessage("terrain", paramList);
  576. return upload.ID;
  577. }
  578. /// <summary>
  579. /// Teleports all users home in current Estate
  580. /// </summary>
  581. public void TeleportHomeAllUsers()
  582. {
  583. List<string> Params = new List<string>();
  584. Params.Add(Client.Self.AgentID.ToString());
  585. EstateOwnerMessage("teleporthomeallusers", Params);
  586. }
  587. /// <summary>
  588. /// Remove estate manager</summary>
  589. /// <param name="userID">Key of Agent to Remove</param>
  590. /// <param name="allEstates">removes manager to this estate and all others owned by the estate owner</param>
  591. public void RemoveEstateManager(UUID userID, bool allEstates)
  592. {
  593. List<string> listParams = new List<string>();
  594. uint flag = allEstates ? (uint)EstateAccessDelta.RemoveManagerAllEstates : (uint)EstateAccessDelta.RemoveManager;
  595. listParams.Add(Client.Self.AgentID.ToString());
  596. listParams.Add(flag.ToString());
  597. listParams.Add(userID.ToString());
  598. EstateOwnerMessage("estateaccessdelta", listParams);
  599. }
  600. /// <summary>
  601. /// Add estate manager</summary>
  602. /// <param name="userID">Key of Agent to Add</param>
  603. /// <param name="allEstates">Add agent as manager to this estate and all others owned by the estate owner</param>
  604. public void AddEstateManager(UUID userID, bool allEstates)
  605. {
  606. List<string> listParams = new List<string>();
  607. uint flag = allEstates ? (uint)EstateAccessDelta.AddManagerAllEstates : (uint)EstateAccessDelta.AddManager;
  608. listParams.Add(Client.Self.AgentID.ToString());
  609. listParams.Add(flag.ToString());
  610. listParams.Add(userID.ToString());
  611. EstateOwnerMessage("estateaccessdelta", listParams);
  612. }
  613. /// <summary>
  614. /// Add's an agent to the estate Allowed list</summary>
  615. /// <param name="userID">Key of Agent to Add</param>
  616. /// <param name="allEstates">Add agent as an allowed reisdent to All estates if true</param>
  617. public void AddAllowedUser(UUID userID, bool allEstates)
  618. {
  619. List<string> listParams = new List<string>();
  620. uint flag = allEstates ? (uint)EstateAccessDelta.AddAllowedAllEstates : (uint)EstateAccessDelta.AddUserAsAllowed;
  621. listParams.Add(Client.Self.AgentID.ToString());
  622. listParams.Add(flag.ToString());
  623. listParams.Add(userID.ToString());
  624. EstateOwnerMessage("estateaccessdelta", listParams);
  625. }
  626. /// <summary>
  627. /// Removes an agent from the estate Allowed list</summary>
  628. /// <param name="userID">Key of Agent to Remove</param>
  629. /// <param name="allEstates">Removes agent as an allowed reisdent from All estates if true</param>
  630. public void RemoveAllowedUser(UUID userID, bool allEstates)
  631. {
  632. List<string> listParams = new List<string>();
  633. uint flag = allEstates ? (uint)EstateAccessDelta.RemoveUserAllowedAllEstates : (uint)EstateAccessDelta.RemoveUserAsAllowed;
  634. listParams.Add(Client.Self.AgentID.ToString());
  635. listParams.Add(flag.ToString());
  636. listParams.Add(userID.ToString());
  637. EstateOwnerMessage("estateaccessdelta", listParams);
  638. }
  639. ///
  640. /// <summary>
  641. /// Add's a group to the estate Allowed list</summary>
  642. /// <param name="groupID">Key of Group to Add</param>
  643. /// <param name="allEstates">Add Group as an allowed group to All estates if true</param>
  644. public void AddAllowedGroup(UUID groupID, bool allEstates)
  645. {
  646. List<string> listParams = new List<string>();
  647. uint flag = allEstates ? (uint)EstateAccessDelta.AddGroupAllowedAllEstates : (uint)EstateAccessDelta.AddAllowedAllEstates;
  648. listParams.Add(Client.Self.AgentID.ToString());
  649. listParams.Add(flag.ToString());
  650. listParams.Add(groupID.ToString());
  651. EstateOwnerMessage("estateaccessdelta", listParams);
  652. }
  653. ///
  654. /// <summary>
  655. /// Removes a group from the estate Allowed list</summary>
  656. /// <param name="groupID">Key of Group to Remove</param>
  657. /// <param name="allEstates">Removes Group as an allowed Group from All estates if true</param>
  658. public void RemoveAllowedGroup(UUID groupID, bool allEstates)
  659. {
  660. List<string> listParams = new List<string>();
  661. uint flag = allEstates ? (uint)EstateAccessDelta.RemoveGroupAllowedAllEstates : (uint)EstateAccessDelta.RemoveGroupAsAllowed;
  662. listParams.Add(Client.Self.AgentID.ToString());
  663. listParams.Add(flag.ToString());
  664. listParams.Add(groupID.ToString());
  665. EstateOwnerMessage("estateaccessdelta", listParams);
  666. }
  667. #endregion
  668. #region Packet Handlers
  669. /// <summary>Process an incoming packet and raise the appropriate events</summary>
  670. /// <param name="sender">The sender</param>
  671. /// <param name="e">The EventArgs object containing the packet data</param>
  672. protected void EstateCovenantReplyHandler(object sender, PacketReceivedEventArgs e)
  673. {
  674. EstateCovenantReplyPacket reply = (EstateCovenantReplyPacket)e.Packet;
  675. OnEstateCovenantReply(new EstateCovenantReplyEventArgs(
  676. reply.Data.CovenantID,
  677. reply.Data.CovenantTimestamp,
  678. Utils.BytesToString(reply.Data.EstateName),
  679. reply.Data.EstateOwnerID));
  680. }
  681. /// <summary>Process an incoming packet and raise the appropriate events</summary>
  682. /// <param name="sender">The sender</param>
  683. /// <param name="e">The EventArgs object containing the packet data</param>
  684. protected void EstateOwnerMessageHandler(object sender, PacketReceivedEventArgs e)
  685. {
  686. EstateOwnerMessagePacket message = (EstateOwnerMessagePacket)e.Packet;
  687. uint estateID;
  688. string method = Utils.BytesToString(message.MethodData.Method);
  689. //List<string> parameters = new List<string>();
  690. if (method == "estateupdateinfo")
  691. {
  692. string estateName = Utils.BytesToString(message.ParamList[0].Parameter);
  693. UUID estateOwner = new UUID(Utils.BytesToString(message.ParamList[1].Parameter));
  694. estateID = Utils.BytesToUInt(message.ParamList[2].Parameter);
  695. /*
  696. foreach (EstateOwnerMessagePacket.ParamListBlock param in message.ParamList)
  697. {
  698. parameters.Add(Utils.BytesToString(param.Parameter));
  699. }
  700. */
  701. bool denyNoPaymentInfo;
  702. if (Utils.BytesToUInt(message.ParamList[8].Parameter) == 0) denyNoPaymentInfo = true;
  703. else denyNoPaymentInfo = false;
  704. OnEstateUpdateInfoReply(new EstateUpdateInfoReplyEventArgs(estateName, estateOwner, estateID, denyNoPaymentInfo));
  705. }
  706. else if (method == "setaccess")
  707. {
  708. int count;
  709. estateID = Utils.BytesToUInt(message.ParamList[0].Parameter);
  710. if (message.ParamList.Length > 1)
  711. {
  712. //param comes in as a string for some reason
  713. uint param;
  714. if (!uint.TryParse(Utils.BytesToString(message.ParamList[1].Parameter), out param)) return;
  715. EstateAccessReplyDelta accessType = (EstateAccessReplyDelta)param;
  716. switch (accessType)
  717. {
  718. case EstateAccessReplyDelta.EstateManagers:
  719. //if (OnGetEstateManagers != null)
  720. {
  721. if (message.ParamList.Length > 5)
  722. {
  723. if (!int.TryParse(Utils.BytesToString(message.ParamList[5].Parameter), out count)) return;
  724. List<UUID> managers = new List<UUID>();
  725. for (int i = 6; i < message.ParamList.Length; i++)
  726. {
  727. try
  728. {
  729. UUID managerID = new UUID(message.ParamList[i].Parameter, 0);
  730. managers.Add(managerID);
  731. }
  732. catch (Exception ex) { Logger.Log(ex.Message, Helpers.LogLevel.Error, Client, ex); }
  733. }
  734. OnEstateManagersReply(new EstateManagersReplyEventArgs(estateID, count, managers));
  735. }
  736. }
  737. break;
  738. case EstateAccessReplyDelta.EstateBans:
  739. //if (OnGetEstateBans != null)
  740. {
  741. if (message.ParamList.Length > 5)
  742. {
  743. if (!int.TryParse(Utils.BytesToString(message.ParamList[4].Parameter), out count)) return;
  744. List<UUID> bannedUsers = new List<UUID>();
  745. for (int i = 6; i < message.ParamList.Length; i++)
  746. {
  747. try
  748. {
  749. UUID bannedID = new UUID(message.ParamList[i].Parameter, 0);
  750. bannedUsers.Add(bannedID);
  751. }
  752. catch (Exception ex) { Logger.Log(ex.Message, Helpers.LogLevel.Error, Client, ex); }
  753. }
  754. OnEstateBansReply(new EstateBansReplyEventArgs(estateID, count, bannedUsers));
  755. }
  756. }
  757. break;
  758. case EstateAccessReplyDelta.AllowedUsers:
  759. //if (OnGetAllowedUsers != null)
  760. {
  761. if (message.ParamList.Length > 5)
  762. {
  763. if (!int.TryParse(Utils.BytesToString(message.ParamList[2].Parameter), out count)) return;
  764. List<UUID> allowedUsers = new List<UUID>();
  765. for (int i = 6; i < message.ParamList.Length; i++)
  766. {
  767. try
  768. {
  769. UUID allowedID = new UUID(message.ParamList[i].Parameter, 0);
  770. allowedUsers.Add(allowedID);
  771. }
  772. catch (Exception ex) { Logger.Log(ex.Message, Helpers.LogLevel.Error, Client, ex); }
  773. }
  774. OnEstateUsersReply(new EstateUsersReplyEventArgs(estateID, count, allowedUsers));
  775. }
  776. }
  777. break;
  778. case EstateAccessReplyDelta.AllowedGroups:
  779. //if (OnGetAllowedGroups != null)
  780. {
  781. if (message.ParamList.Length > 5)
  782. {
  783. if (!int.TryParse(Utils.BytesToString(message.ParamList[3].Parameter), out count)) return;
  784. List<UUID> allowedGroups = new List<UUID>();
  785. for (int i = 6; i < message.ParamList.Length; i++)
  786. {
  787. try
  788. {
  789. UUID groupID = new UUID(message.ParamList[i].Parameter, 0);
  790. allowedGroups.Add(groupID);
  791. }
  792. catch (Exception ex) { Logger.Log(ex.Message, Helpers.LogLevel.Error, Client, ex); }
  793. }
  794. OnEstateGroupsReply(new EstateGroupsReplyEventArgs(estateID, count, allowedGroups));
  795. }
  796. }
  797. break;
  798. }
  799. }
  800. }
  801. }
  802. /// <summary>Process an incoming packet and raise the appropriate events</summary>
  803. /// <param name="sender">The sender</param>
  804. /// <param name="e">The EventArgs object containing the packet data</param>
  805. protected void LandStatReplyHandler(object sender, PacketReceivedEventArgs e)
  806. {
  807. //if (OnLandStatReply != null || OnGetTopScripts != null || OnGetTopColliders != null)
  808. //if (OnGetTopScripts != null || OnGetTopColliders != null)
  809. {
  810. LandStatReplyPacket p = (LandStatReplyPacket)e.Packet;
  811. Dictionary<UUID, EstateTask> Tasks = new Dictionary<UUID, EstateTask>();
  812. foreach (LandStatReplyPacket.ReportDataBlock rep in p.ReportData)
  813. {
  814. EstateTask task = new EstateTask();
  815. task.Position = new Vector3(rep.LocationX, rep.LocationY, rep.LocationZ);
  816. task.Score = rep.Score;
  817. task.TaskID = rep.TaskID;
  818. task.TaskLocalID = rep.TaskLocalID;
  819. task.TaskName = Utils.BytesToString(rep.TaskName);
  820. task.OwnerName = Utils.BytesToString(rep.OwnerName);
  821. Tasks.Add(task.TaskID, task);
  822. }
  823. LandStatReportType type = (LandStatReportType)p.RequestData.ReportType;
  824. if (type == LandStatReportType.TopScripts)
  825. {
  826. OnTopScriptsReply(new TopScriptsReplyEventArgs((int)p.RequestData.TotalObjectCount, Tasks));
  827. }
  828. else if (type == LandStatReportType.TopColliders)
  829. {
  830. OnTopCollidersReply(new TopCollidersReplyEventArgs((int) p.RequestData.TotalObjectCount, Tasks));
  831. }
  832. /*
  833. if (OnGetTopColliders != null)
  834. {
  835. //FIXME - System.UnhandledExceptionEventArgs
  836. OnLandStatReply(
  837. type,
  838. p.RequestData.RequestFlags,
  839. (int)p.RequestData.TotalObjectCount,
  840. Tasks
  841. );
  842. }
  843. */
  844. }
  845. }
  846. private void LandStatCapsReplyHandler(string capsKey, IMessage message, Simulator simulator)
  847. {
  848. LandStatReplyMessage m = (LandStatReplyMessage)message;
  849. Dictionary<UUID, EstateTask> Tasks = new Dictionary<UUID, EstateTask>();
  850. foreach (LandStatReplyMessage.ReportDataBlock rep in m.ReportDataBlocks)
  851. {
  852. EstateTask task = new EstateTask();
  853. task.Position = rep.Location;
  854. task.Score = rep.Score;
  855. task.MonoScore = rep.MonoScore;
  856. task.TaskID = rep.TaskID;
  857. task.TaskLocalID = rep.TaskLocalID;
  858. task.TaskName = rep.TaskName;
  859. task.OwnerName = rep.OwnerName;
  860. Tasks.Add(task.TaskID, task);
  861. }
  862. LandStatReportType type = (LandStatReportType)m.ReportType;
  863. if (type == LandStatReportType.TopScripts)
  864. {
  865. OnTopScriptsReply(new TopScriptsReplyEventArgs((int)m.TotalObjectCount, Tasks));
  866. }
  867. else if (type == LandStatReportType.TopColliders)
  868. {
  869. OnTopCollidersReply(new TopCollidersReplyEventArgs((int)m.TotalObjectCount, Tasks));
  870. }
  871. }
  872. #endregion
  873. }
  874. #region EstateTools EventArgs Classes
  875. /// <summary>Raised on LandStatReply when the report type is for "top colliders"</summary>
  876. public class TopCollidersReplyEventArgs : EventArgs
  877. {
  878. private readonly int m_objectCount;
  879. private readonly Dictionary<UUID, EstateTask> m_Tasks;
  880. /// <summary>
  881. /// The number of returned items in LandStatReply
  882. /// </summary>
  883. public int ObjectCount { get { return m_objectCount; } }
  884. /// <summary>
  885. /// A Dictionary of Object UUIDs to tasks returned in LandStatReply
  886. /// </summary>
  887. public Dictionary<UUID, EstateTask> Tasks { get { return m_Tasks; } }
  888. /// <summary>Construct a new instance of the TopCollidersReplyEventArgs class</summary>
  889. /// <param name="objectCount">The number of returned items in LandStatReply</param>
  890. /// <param name="tasks">Dictionary of Object UUIDs to tasks returned in LandStatReply</param>
  891. public TopCollidersReplyEventArgs(int objectCount, Dictionary<UUID, EstateTask> tasks)
  892. {
  893. this.m_objectCount = objectCount;
  894. this.m_Tasks = tasks;
  895. }
  896. }
  897. /// <summary>Raised on LandStatReply when the report type is for "top Scripts"</summary>
  898. public class TopScriptsReplyEventArgs : EventArgs
  899. {
  900. private readonly int m_objectCount;
  901. private readonly Dictionary<UUID, EstateTask> m_Tasks;
  902. /// <summary>
  903. /// The number of scripts returned in LandStatReply
  904. /// </summary>
  905. public int ObjectCount { get { return m_objectCount; } }
  906. /// <summary>
  907. /// A Dictionary of Object UUIDs to tasks returned in LandStatReply
  908. /// </summary>
  909. public Dictionary<UUID, EstateTask> Tasks { get { return m_Tasks; } }
  910. /// <summary>Construct a new instance of the TopScriptsReplyEventArgs class</summary>
  911. /// <param name="objectCount">The number of returned items in LandStatReply</param>
  912. /// <param name="tasks">Dictionary of Object UUIDs to tasks returned in LandStatReply</param>
  913. public TopScriptsReplyEventArgs(int objectCount, Dictionary<UUID, EstateTask> tasks)
  914. {
  915. this.m_objectCount = objectCount;
  916. this.m_Tasks = tasks;
  917. }
  918. }
  919. /// <summary>Returned, along with other info, upon a successful .RequestInfo()</summary>
  920. public class EstateBansReplyEventArgs : EventArgs
  921. {
  922. private readonly uint m_estateID;
  923. private readonly int m_count;
  924. private readonly List<UUID> m_banned;
  925. /// <summary>
  926. /// The identifier of the estate
  927. /// </summary>
  928. public uint EstateID { get { return m_estateID; } }
  929. /// <summary>
  930. /// The number of returned itmes
  931. /// </summary>
  932. public int Count { get { return m_count; } }
  933. /// <summary>
  934. /// List of UUIDs of Banned Users
  935. /// </summary>
  936. public List<UUID> Banned { get { return m_banned; } }
  937. /// <summary>Construct a new instance of the EstateBansReplyEventArgs class</summary>
  938. /// <param name="estateID">The estate's identifier on the grid</param>
  939. /// <param name="count">The number of returned items in LandStatReply</param>
  940. /// <param name="banned">User UUIDs banned</param>
  941. public EstateBansReplyEventArgs(uint estateID, int count, List<UUID> banned)
  942. {
  943. this.m_estateID = estateID;
  944. this.m_count = count;
  945. this.m_banned = banned;
  946. }
  947. }
  948. /// <summary>Returned, along with other info, upon a successful .RequestInfo()</summary>
  949. public class EstateUsersReplyEventArgs : EventArgs
  950. {
  951. private readonly uint m_estateID;
  952. private readonly int m_count;
  953. private readonly List<UUID> m_allowedUsers;
  954. /// <summary>
  955. /// The identifier of the estate
  956. /// </summary>
  957. public uint EstateID { get { return m_estateID; } }
  958. /// <summary>
  959. /// The number of returned…

Large files files are truncated, but you can click here to view the full file