EstateSettings.cs 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523
  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 OpenSim 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.IO;
  29. using System.Reflection;
  30. using System.Collections.Generic;
  31. using OpenMetaverse;
  32. using log4net;
  33. namespace OpenSim.Framework
  34. {
  35. public class EstateSettings
  36. {
  37. // private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  38. private ConfigurationMember configMember;
  39. public delegate void SaveDelegate(EstateSettings rs);
  40. public event SaveDelegate OnSave;
  41. // Only the client uses these
  42. //
  43. private uint m_EstateID = 100;
  44. public uint EstateID
  45. {
  46. get { return m_EstateID; }
  47. set { m_EstateID = value; }
  48. }
  49. private string m_EstateName;
  50. public string EstateName
  51. {
  52. get { return m_EstateName; }
  53. set { m_EstateName = value; }
  54. }
  55. private uint m_ParentEstateID = 100;
  56. public uint ParentEstateID
  57. {
  58. get { return m_ParentEstateID; }
  59. set { m_ParentEstateID = value; }
  60. }
  61. private float m_BillableFactor;
  62. public float BillableFactor
  63. {
  64. get { return m_BillableFactor; }
  65. set { m_BillableFactor = value; }
  66. }
  67. private int m_PricePerMeter;
  68. public int PricePerMeter
  69. {
  70. get { return m_PricePerMeter; }
  71. set { m_PricePerMeter = value; }
  72. }
  73. private int m_RedirectGridX;
  74. public int RedirectGridX
  75. {
  76. get { return m_RedirectGridX; }
  77. set { m_RedirectGridX = value; }
  78. }
  79. private int m_RedirectGridY;
  80. public int RedirectGridY
  81. {
  82. get { return m_RedirectGridY; }
  83. set { m_RedirectGridY = value; }
  84. }
  85. // Used by the sim
  86. //
  87. private bool m_UseGlobalTime = true;
  88. public bool UseGlobalTime
  89. {
  90. get { return m_UseGlobalTime; }
  91. set { m_UseGlobalTime = value; }
  92. }
  93. private bool m_FixedSun = false;
  94. public bool FixedSun
  95. {
  96. get { return m_FixedSun; }
  97. set { m_FixedSun = value; }
  98. }
  99. private double m_SunPosition = 0.0;
  100. public double SunPosition
  101. {
  102. get { return m_SunPosition; }
  103. set { m_SunPosition = value; }
  104. }
  105. private bool m_AllowVoice = true;
  106. public bool AllowVoice
  107. {
  108. get { return m_AllowVoice; }
  109. set { m_AllowVoice = value; }
  110. }
  111. private bool m_AllowDirectTeleport = true;
  112. public bool AllowDirectTeleport
  113. {
  114. get { return m_AllowDirectTeleport; }
  115. set { m_AllowDirectTeleport = value; }
  116. }
  117. private bool m_DenyAnonymous = false;
  118. public bool DenyAnonymous
  119. {
  120. get { return m_DenyAnonymous; }
  121. set { m_DenyAnonymous = value; }
  122. }
  123. private bool m_DenyIdentified = false;
  124. public bool DenyIdentified
  125. {
  126. get { return m_DenyIdentified; }
  127. set { m_DenyIdentified = value; }
  128. }
  129. private bool m_DenyTransacted = false;
  130. public bool DenyTransacted
  131. {
  132. get { return m_DenyTransacted; }
  133. set { m_DenyTransacted = value; }
  134. }
  135. private bool m_AbuseEmailToEstateOwner = false;
  136. public bool AbuseEmailToEstateOwner
  137. {
  138. get { return m_AbuseEmailToEstateOwner; }
  139. set { m_AbuseEmailToEstateOwner = value; }
  140. }
  141. private bool m_BlockDwell = false;
  142. public bool BlockDwell
  143. {
  144. get { return m_BlockDwell; }
  145. set { m_BlockDwell = value; }
  146. }
  147. private bool m_EstateSkipScripts = false;
  148. public bool EstateSkipScripts
  149. {
  150. get { return m_EstateSkipScripts; }
  151. set { m_EstateSkipScripts = value; }
  152. }
  153. private bool m_ResetHomeOnTeleport = false;
  154. public bool ResetHomeOnTeleport
  155. {
  156. get { return m_ResetHomeOnTeleport; }
  157. set { m_ResetHomeOnTeleport = value; }
  158. }
  159. private bool m_TaxFree = false;
  160. public bool TaxFree
  161. {
  162. get { return m_TaxFree; }
  163. set { m_TaxFree = value; }
  164. }
  165. private bool m_PublicAccess = true;
  166. public bool PublicAccess
  167. {
  168. get { return m_PublicAccess; }
  169. set { m_PublicAccess = value; }
  170. }
  171. private string m_AbuseEmail = String.Empty;
  172. public string AbuseEmail
  173. {
  174. get { return m_AbuseEmail; }
  175. set { m_AbuseEmail= value; }
  176. }
  177. private UUID m_EstateOwner = UUID.Zero;
  178. public UUID EstateOwner
  179. {
  180. get { return m_EstateOwner; }
  181. set { m_EstateOwner = value; }
  182. }
  183. private bool m_DenyMinors = false;
  184. public bool DenyMinors
  185. {
  186. get { return m_DenyMinors; }
  187. set { m_DenyMinors = value; }
  188. }
  189. // All those lists...
  190. //
  191. private List<UUID> l_EstateManagers = new List<UUID>();
  192. public UUID[] EstateManagers
  193. {
  194. get { return l_EstateManagers.ToArray(); }
  195. set { l_EstateManagers = new List<UUID>(value); }
  196. }
  197. private List<EstateBan> l_EstateBans = new List<EstateBan>();
  198. public EstateBan[] EstateBans
  199. {
  200. get { return l_EstateBans.ToArray(); }
  201. set { l_EstateBans = new List<EstateBan>(value); }
  202. }
  203. private List<UUID> l_EstateAccess = new List<UUID>();
  204. public UUID[] EstateAccess
  205. {
  206. get { return l_EstateAccess.ToArray(); }
  207. set { l_EstateAccess = new List<UUID>(value); }
  208. }
  209. private List<UUID> l_EstateGroups = new List<UUID>();
  210. public UUID[] EstateGroups
  211. {
  212. get { return l_EstateGroups.ToArray(); }
  213. set { l_EstateGroups = new List<UUID>(value); }
  214. }
  215. public EstateSettings()
  216. {
  217. if (configMember == null)
  218. {
  219. try
  220. {
  221. // Load legacy defaults
  222. //
  223. configMember =
  224. new ConfigurationMember(Path.Combine(Util.configDir(),
  225. "estate_settings.xml"), "ESTATE SETTINGS",
  226. loadConfigurationOptions,
  227. handleIncomingConfiguration, true);
  228. l_EstateManagers.Clear();
  229. configMember.performConfigurationRetrieve();
  230. }
  231. catch (Exception)
  232. {
  233. }
  234. }
  235. }
  236. public void Save()
  237. {
  238. if (OnSave != null)
  239. OnSave(this);
  240. }
  241. public void AddEstateManager(UUID avatarID)
  242. {
  243. if (avatarID == UUID.Zero)
  244. return;
  245. if (!l_EstateManagers.Contains(avatarID))
  246. l_EstateManagers.Add(avatarID);
  247. }
  248. public void RemoveEstateManager(UUID avatarID)
  249. {
  250. if (l_EstateManagers.Contains(avatarID))
  251. l_EstateManagers.Remove(avatarID);
  252. }
  253. public bool IsEstateManager(UUID avatarID)
  254. {
  255. if (IsEstateOwner(avatarID))
  256. return true;
  257. return l_EstateManagers.Contains(avatarID);
  258. }
  259. public bool IsEstateOwner(UUID avatarID)
  260. {
  261. if (avatarID == m_EstateOwner)
  262. return true;
  263. return false;
  264. }
  265. public bool IsBanned(UUID avatarID)
  266. {
  267. foreach (EstateBan ban in l_EstateBans)
  268. if (ban.bannedUUID == avatarID)
  269. return true;
  270. return false;
  271. }
  272. public void AddBan(EstateBan ban)
  273. {
  274. if (ban == null)
  275. return;
  276. if (!IsBanned(ban.bannedUUID))
  277. l_EstateBans.Add(ban);
  278. }
  279. public void ClearBans()
  280. {
  281. l_EstateBans.Clear();
  282. }
  283. public void RemoveBan(UUID avatarID)
  284. {
  285. foreach (EstateBan ban in new List<EstateBan>(l_EstateBans))
  286. if (ban.bannedUUID == avatarID)
  287. l_EstateBans.Remove(ban);
  288. }
  289. public void loadConfigurationOptions()
  290. {
  291. configMember.addConfigurationOption("billable_factor",
  292. ConfigurationOption.ConfigurationTypes.TYPE_FLOAT,
  293. String.Empty, "0.0", true);
  294. // configMember.addConfigurationOption("estate_id",
  295. // ConfigurationOption.ConfigurationTypes.TYPE_UINT32,
  296. // String.Empty, "100", true);
  297. // configMember.addConfigurationOption("parent_estate_id",
  298. // ConfigurationOption.ConfigurationTypes.TYPE_UINT32,
  299. // String.Empty, "1", true);
  300. configMember.addConfigurationOption("redirect_grid_x",
  301. ConfigurationOption.ConfigurationTypes.TYPE_INT32,
  302. String.Empty, "0", true);
  303. configMember.addConfigurationOption("redirect_grid_y",
  304. ConfigurationOption.ConfigurationTypes.TYPE_INT32,
  305. String.Empty, "0", true);
  306. configMember.addConfigurationOption("price_per_meter",
  307. ConfigurationOption.ConfigurationTypes.TYPE_UINT32,
  308. String.Empty, "1", true);
  309. configMember.addConfigurationOption("estate_name",
  310. ConfigurationOption.ConfigurationTypes.TYPE_STRING,
  311. String.Empty, "My Estate", true);
  312. configMember.addConfigurationOption("estate_manager_0",
  313. ConfigurationOption.ConfigurationTypes.TYPE_UUID,
  314. String.Empty, "00000000-0000-0000-0000-000000000000", true);
  315. configMember.addConfigurationOption("estate_manager_1",
  316. ConfigurationOption.ConfigurationTypes.TYPE_UUID,
  317. String.Empty, "00000000-0000-0000-0000-000000000000", true);
  318. configMember.addConfigurationOption("estate_manager_2",
  319. ConfigurationOption.ConfigurationTypes.TYPE_UUID,
  320. String.Empty, "00000000-0000-0000-0000-000000000000", true);
  321. configMember.addConfigurationOption("estate_manager_3",
  322. ConfigurationOption.ConfigurationTypes.TYPE_UUID,
  323. String.Empty, "00000000-0000-0000-0000-000000000000", true);
  324. configMember.addConfigurationOption("estate_manager_4",
  325. ConfigurationOption.ConfigurationTypes.TYPE_UUID,
  326. String.Empty, "00000000-0000-0000-0000-000000000000", true);
  327. configMember.addConfigurationOption("estate_manager_5",
  328. ConfigurationOption.ConfigurationTypes.TYPE_UUID,
  329. String.Empty, "00000000-0000-0000-0000-000000000000", true);
  330. configMember.addConfigurationOption("estate_manager_6",
  331. ConfigurationOption.ConfigurationTypes.TYPE_UUID,
  332. String.Empty, "00000000-0000-0000-0000-000000000000", true);
  333. configMember.addConfigurationOption("estate_manager_7",
  334. ConfigurationOption.ConfigurationTypes.TYPE_UUID,
  335. String.Empty, "00000000-0000-0000-0000-000000000000", true);
  336. configMember.addConfigurationOption("estate_manager_8",
  337. ConfigurationOption.ConfigurationTypes.TYPE_UUID,
  338. String.Empty, "00000000-0000-0000-0000-000000000000", true);
  339. configMember.addConfigurationOption("estate_manager_9",
  340. ConfigurationOption.ConfigurationTypes.TYPE_UUID,
  341. String.Empty, "00000000-0000-0000-0000-000000000000", true);
  342. configMember.addConfigurationOption("region_flags",
  343. ConfigurationOption.ConfigurationTypes.TYPE_UINT32,
  344. String.Empty, "336723974", true);
  345. }
  346. public bool handleIncomingConfiguration(string configuration_key, object configuration_result)
  347. {
  348. switch (configuration_key)
  349. {
  350. case "region_flags":
  351. RegionFlags flags = (RegionFlags)(uint)configuration_result;
  352. if ((flags & (RegionFlags)(1<<29)) != 0)
  353. m_AllowVoice = true;
  354. if ((flags & RegionFlags.AllowDirectTeleport) != 0)
  355. m_AllowDirectTeleport = true;
  356. if ((flags & RegionFlags.DenyAnonymous) != 0)
  357. m_DenyAnonymous = true;
  358. if ((flags & RegionFlags.DenyIdentified) != 0)
  359. m_DenyIdentified = true;
  360. if ((flags & RegionFlags.DenyTransacted) != 0)
  361. m_DenyTransacted = true;
  362. if ((flags & RegionFlags.AbuseEmailToEstateOwner) != 0)
  363. m_AbuseEmailToEstateOwner = true;
  364. if ((flags & RegionFlags.BlockDwell) != 0)
  365. m_BlockDwell = true;
  366. if ((flags & RegionFlags.EstateSkipScripts) != 0)
  367. m_EstateSkipScripts = true;
  368. if ((flags & RegionFlags.ResetHomeOnTeleport) != 0)
  369. m_ResetHomeOnTeleport = true;
  370. if ((flags & RegionFlags.TaxFree) != 0)
  371. m_TaxFree = true;
  372. if ((flags & RegionFlags.PublicAllowed) != 0)
  373. m_PublicAccess = true;
  374. break;
  375. case "billable_factor":
  376. m_BillableFactor = (float) configuration_result;
  377. break;
  378. // case "estate_id":
  379. // m_EstateID = (uint) configuration_result;
  380. // break;
  381. // case "parent_estate_id":
  382. // m_ParentEstateID = (uint) configuration_result;
  383. // break;
  384. case "redirect_grid_x":
  385. m_RedirectGridX = (int) configuration_result;
  386. break;
  387. case "redirect_grid_y":
  388. m_RedirectGridY = (int) configuration_result;
  389. break;
  390. case "price_per_meter":
  391. m_PricePerMeter = Convert.ToInt32(configuration_result);
  392. break;
  393. case "estate_name":
  394. m_EstateName = (string) configuration_result;
  395. break;
  396. case "estate_manager_0":
  397. AddEstateManager((UUID)configuration_result);
  398. break;
  399. case "estate_manager_1":
  400. AddEstateManager((UUID)configuration_result);
  401. break;
  402. case "estate_manager_2":
  403. AddEstateManager((UUID)configuration_result);
  404. break;
  405. case "estate_manager_3":
  406. AddEstateManager((UUID)configuration_result);
  407. break;
  408. case "estate_manager_4":
  409. AddEstateManager((UUID)configuration_result);
  410. break;
  411. case "estate_manager_5":
  412. AddEstateManager((UUID)configuration_result);
  413. break;
  414. case "estate_manager_6":
  415. AddEstateManager((UUID)configuration_result);
  416. break;
  417. case "estate_manager_7":
  418. AddEstateManager((UUID)configuration_result);
  419. break;
  420. case "estate_manager_8":
  421. AddEstateManager((UUID)configuration_result);
  422. break;
  423. case "estate_manager_9":
  424. AddEstateManager((UUID)configuration_result);
  425. break;
  426. }
  427. return true;
  428. }
  429. }
  430. }