EstateSettings.cs 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557
  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 AddEstateUser(UUID avatarID)
  240. {
  241. if (avatarID == UUID.Zero)
  242. return;
  243. if (!l_EstateAccess.Contains(avatarID))
  244. l_EstateAccess.Add(avatarID);
  245. }
  246. public void RemoveEstateUser(UUID avatarID)
  247. {
  248. if (l_EstateAccess.Contains(avatarID))
  249. l_EstateAccess.Remove(avatarID);
  250. }
  251. public void AddEstateGroup(UUID avatarID)
  252. {
  253. if (avatarID == UUID.Zero)
  254. return;
  255. if (!l_EstateGroups.Contains(avatarID))
  256. l_EstateGroups.Add(avatarID);
  257. }
  258. public void RemoveEstateGroup(UUID avatarID)
  259. {
  260. if (l_EstateGroups.Contains(avatarID))
  261. l_EstateGroups.Remove(avatarID);
  262. }
  263. public void AddEstateManager(UUID avatarID)
  264. {
  265. if (avatarID == UUID.Zero)
  266. return;
  267. if (!l_EstateManagers.Contains(avatarID))
  268. l_EstateManagers.Add(avatarID);
  269. }
  270. public void RemoveEstateManager(UUID avatarID)
  271. {
  272. if (l_EstateManagers.Contains(avatarID))
  273. l_EstateManagers.Remove(avatarID);
  274. }
  275. public bool IsEstateManager(UUID avatarID)
  276. {
  277. if (IsEstateOwner(avatarID))
  278. return true;
  279. return l_EstateManagers.Contains(avatarID);
  280. }
  281. public bool IsEstateOwner(UUID avatarID)
  282. {
  283. if (avatarID == m_EstateOwner)
  284. return true;
  285. return false;
  286. }
  287. public bool IsBanned(UUID avatarID)
  288. {
  289. foreach (EstateBan ban in l_EstateBans)
  290. if (ban.BannedUserID == avatarID)
  291. return true;
  292. return false;
  293. }
  294. public void AddBan(EstateBan ban)
  295. {
  296. if (ban == null)
  297. return;
  298. if (!IsBanned(ban.BannedUserID))
  299. l_EstateBans.Add(ban);
  300. }
  301. public void ClearBans()
  302. {
  303. l_EstateBans.Clear();
  304. }
  305. public void RemoveBan(UUID avatarID)
  306. {
  307. foreach (EstateBan ban in new List<EstateBan>(l_EstateBans))
  308. if (ban.BannedUserID == avatarID)
  309. l_EstateBans.Remove(ban);
  310. }
  311. public bool HasAccess(UUID user)
  312. {
  313. if (IsEstateManager(user))
  314. return true;
  315. return l_EstateAccess.Contains(user);
  316. }
  317. public void loadConfigurationOptions()
  318. {
  319. configMember.addConfigurationOption("billable_factor",
  320. ConfigurationOption.ConfigurationTypes.TYPE_FLOAT,
  321. String.Empty, "0.0", true);
  322. // configMember.addConfigurationOption("estate_id",
  323. // ConfigurationOption.ConfigurationTypes.TYPE_UINT32,
  324. // String.Empty, "100", true);
  325. // configMember.addConfigurationOption("parent_estate_id",
  326. // ConfigurationOption.ConfigurationTypes.TYPE_UINT32,
  327. // String.Empty, "1", true);
  328. configMember.addConfigurationOption("redirect_grid_x",
  329. ConfigurationOption.ConfigurationTypes.TYPE_INT32,
  330. String.Empty, "0", true);
  331. configMember.addConfigurationOption("redirect_grid_y",
  332. ConfigurationOption.ConfigurationTypes.TYPE_INT32,
  333. String.Empty, "0", true);
  334. configMember.addConfigurationOption("price_per_meter",
  335. ConfigurationOption.ConfigurationTypes.TYPE_UINT32,
  336. String.Empty, "1", true);
  337. configMember.addConfigurationOption("estate_name",
  338. ConfigurationOption.ConfigurationTypes.TYPE_STRING,
  339. String.Empty, "My Estate", true);
  340. configMember.addConfigurationOption("estate_manager_0",
  341. ConfigurationOption.ConfigurationTypes.TYPE_UUID,
  342. String.Empty, "00000000-0000-0000-0000-000000000000", true);
  343. configMember.addConfigurationOption("estate_manager_1",
  344. ConfigurationOption.ConfigurationTypes.TYPE_UUID,
  345. String.Empty, "00000000-0000-0000-0000-000000000000", true);
  346. configMember.addConfigurationOption("estate_manager_2",
  347. ConfigurationOption.ConfigurationTypes.TYPE_UUID,
  348. String.Empty, "00000000-0000-0000-0000-000000000000", true);
  349. configMember.addConfigurationOption("estate_manager_3",
  350. ConfigurationOption.ConfigurationTypes.TYPE_UUID,
  351. String.Empty, "00000000-0000-0000-0000-000000000000", true);
  352. configMember.addConfigurationOption("estate_manager_4",
  353. ConfigurationOption.ConfigurationTypes.TYPE_UUID,
  354. String.Empty, "00000000-0000-0000-0000-000000000000", true);
  355. configMember.addConfigurationOption("estate_manager_5",
  356. ConfigurationOption.ConfigurationTypes.TYPE_UUID,
  357. String.Empty, "00000000-0000-0000-0000-000000000000", true);
  358. configMember.addConfigurationOption("estate_manager_6",
  359. ConfigurationOption.ConfigurationTypes.TYPE_UUID,
  360. String.Empty, "00000000-0000-0000-0000-000000000000", true);
  361. configMember.addConfigurationOption("estate_manager_7",
  362. ConfigurationOption.ConfigurationTypes.TYPE_UUID,
  363. String.Empty, "00000000-0000-0000-0000-000000000000", true);
  364. configMember.addConfigurationOption("estate_manager_8",
  365. ConfigurationOption.ConfigurationTypes.TYPE_UUID,
  366. String.Empty, "00000000-0000-0000-0000-000000000000", true);
  367. configMember.addConfigurationOption("estate_manager_9",
  368. ConfigurationOption.ConfigurationTypes.TYPE_UUID,
  369. String.Empty, "00000000-0000-0000-0000-000000000000", true);
  370. configMember.addConfigurationOption("region_flags",
  371. ConfigurationOption.ConfigurationTypes.TYPE_UINT32,
  372. String.Empty, "336723974", true);
  373. }
  374. public bool handleIncomingConfiguration(string configuration_key, object configuration_result)
  375. {
  376. switch (configuration_key)
  377. {
  378. case "region_flags":
  379. RegionFlags flags = (RegionFlags)(uint)configuration_result;
  380. if ((flags & (RegionFlags)(1<<29)) != 0)
  381. m_AllowVoice = true;
  382. if ((flags & RegionFlags.AllowDirectTeleport) != 0)
  383. m_AllowDirectTeleport = true;
  384. if ((flags & RegionFlags.DenyAnonymous) != 0)
  385. m_DenyAnonymous = true;
  386. if ((flags & RegionFlags.DenyIdentified) != 0)
  387. m_DenyIdentified = true;
  388. if ((flags & RegionFlags.DenyTransacted) != 0)
  389. m_DenyTransacted = true;
  390. if ((flags & RegionFlags.AbuseEmailToEstateOwner) != 0)
  391. m_AbuseEmailToEstateOwner = true;
  392. if ((flags & RegionFlags.BlockDwell) != 0)
  393. m_BlockDwell = true;
  394. if ((flags & RegionFlags.EstateSkipScripts) != 0)
  395. m_EstateSkipScripts = true;
  396. if ((flags & RegionFlags.ResetHomeOnTeleport) != 0)
  397. m_ResetHomeOnTeleport = true;
  398. if ((flags & RegionFlags.TaxFree) != 0)
  399. m_TaxFree = true;
  400. if ((flags & RegionFlags.PublicAllowed) != 0)
  401. m_PublicAccess = true;
  402. break;
  403. case "billable_factor":
  404. m_BillableFactor = (float) configuration_result;
  405. break;
  406. // case "estate_id":
  407. // m_EstateID = (uint) configuration_result;
  408. // break;
  409. // case "parent_estate_id":
  410. // m_ParentEstateID = (uint) configuration_result;
  411. // break;
  412. case "redirect_grid_x":
  413. m_RedirectGridX = (int) configuration_result;
  414. break;
  415. case "redirect_grid_y":
  416. m_RedirectGridY = (int) configuration_result;
  417. break;
  418. case "price_per_meter":
  419. m_PricePerMeter = Convert.ToInt32(configuration_result);
  420. break;
  421. case "estate_name":
  422. m_EstateName = (string) configuration_result;
  423. break;
  424. case "estate_manager_0":
  425. AddEstateManager((UUID)configuration_result);
  426. break;
  427. case "estate_manager_1":
  428. AddEstateManager((UUID)configuration_result);
  429. break;
  430. case "estate_manager_2":
  431. AddEstateManager((UUID)configuration_result);
  432. break;
  433. case "estate_manager_3":
  434. AddEstateManager((UUID)configuration_result);
  435. break;
  436. case "estate_manager_4":
  437. AddEstateManager((UUID)configuration_result);
  438. break;
  439. case "estate_manager_5":
  440. AddEstateManager((UUID)configuration_result);
  441. break;
  442. case "estate_manager_6":
  443. AddEstateManager((UUID)configuration_result);
  444. break;
  445. case "estate_manager_7":
  446. AddEstateManager((UUID)configuration_result);
  447. break;
  448. case "estate_manager_8":
  449. AddEstateManager((UUID)configuration_result);
  450. break;
  451. case "estate_manager_9":
  452. AddEstateManager((UUID)configuration_result);
  453. break;
  454. }
  455. return true;
  456. }
  457. }
  458. }