EstateSettings.cs 18 KB

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