EstateSettings.cs 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590
  1. /*
  2. * Copyright (c) Contributors, http://opensimulator.org/
  3. * See CONTRIBUTORS.TXT for a full list of copyright holders.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are met:
  7. * * Redistributions of source code must retain the above copyright
  8. * notice, this list of conditions and the following disclaimer.
  9. * * Redistributions in binary form must reproduce the above copyright
  10. * notice, this list of conditions and the following disclaimer in the
  11. * documentation and/or other materials provided with the distribution.
  12. * * Neither the name of the OpenSimulator Project nor the
  13. * names of its contributors may be used to endorse or promote products
  14. * derived from this software without specific prior written permission.
  15. *
  16. * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
  17. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  18. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  19. * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
  20. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  21. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  22. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  23. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  24. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  25. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. */
  27. using System;
  28. using System.Collections.Generic;
  29. using System.IO;
  30. using System.Reflection;
  31. using OpenMetaverse;
  32. namespace OpenSim.Framework
  33. {
  34. public class EstateSettings
  35. {
  36. // private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  37. public delegate void SaveDelegate(EstateSettings rs);
  38. public event SaveDelegate OnSave;
  39. // Only the client uses these
  40. //
  41. private uint m_EstateID = 0;
  42. public uint EstateID
  43. {
  44. get { return m_EstateID; }
  45. set { m_EstateID = value; }
  46. }
  47. private string m_EstateName = "My Estate";
  48. public string EstateName
  49. {
  50. get { return m_EstateName; }
  51. set { m_EstateName = value; }
  52. }
  53. private bool m_AllowLandmark = true;
  54. public bool AllowLandmark
  55. {
  56. get { return m_AllowLandmark; }
  57. set { m_AllowLandmark = value; }
  58. }
  59. private bool m_AllowParcelChanges = true;
  60. public bool AllowParcelChanges
  61. {
  62. get { return m_AllowParcelChanges; }
  63. set { m_AllowParcelChanges = value; }
  64. }
  65. private bool m_AllowSetHome = true;
  66. public bool AllowSetHome
  67. {
  68. get { return m_AllowSetHome; }
  69. set { m_AllowSetHome = value; }
  70. }
  71. private uint m_ParentEstateID = 1;
  72. public uint ParentEstateID
  73. {
  74. get { return m_ParentEstateID; }
  75. set { m_ParentEstateID = value; }
  76. }
  77. private float m_BillableFactor = 0.0f;
  78. public float BillableFactor
  79. {
  80. get { return m_BillableFactor; }
  81. set { m_BillableFactor = value; }
  82. }
  83. private int m_PricePerMeter = 1;
  84. public int PricePerMeter
  85. {
  86. get { return m_PricePerMeter; }
  87. set { m_PricePerMeter = value; }
  88. }
  89. private int m_RedirectGridX = 0;
  90. public int RedirectGridX
  91. {
  92. get { return m_RedirectGridX; }
  93. set { m_RedirectGridX = value; }
  94. }
  95. private int m_RedirectGridY = 0;
  96. public int RedirectGridY
  97. {
  98. get { return m_RedirectGridY; }
  99. set { m_RedirectGridY = value; }
  100. }
  101. // Used by the sim
  102. //
  103. private bool m_UseGlobalTime = true;
  104. public bool UseGlobalTime
  105. {
  106. get { return m_UseGlobalTime; }
  107. set { m_UseGlobalTime = value; }
  108. }
  109. private bool m_FixedSun = false;
  110. public bool FixedSun
  111. {
  112. get { return m_FixedSun; }
  113. set { m_FixedSun = value; }
  114. }
  115. private double m_SunPosition = 0.0;
  116. public double SunPosition
  117. {
  118. get { return m_SunPosition; }
  119. set { m_SunPosition = value; }
  120. }
  121. private bool m_AllowVoice = true;
  122. public bool AllowVoice
  123. {
  124. get { return m_AllowVoice; }
  125. set { m_AllowVoice = value; }
  126. }
  127. private bool m_AllowDirectTeleport = true;
  128. public bool AllowDirectTeleport
  129. {
  130. get { return m_AllowDirectTeleport; }
  131. set { m_AllowDirectTeleport = value; }
  132. }
  133. private bool m_DenyAnonymous = false;
  134. public bool DenyAnonymous
  135. {
  136. get { return m_DenyAnonymous; }
  137. set { m_DenyAnonymous = value; }
  138. }
  139. // no longer in used, may be reassigned
  140. private bool m_DenyIdentified = false;
  141. public bool DenyIdentified
  142. {
  143. get { return m_DenyIdentified; }
  144. set { m_DenyIdentified = value; }
  145. }
  146. // no longer in used, may be reassigned
  147. private bool m_DenyTransacted = false;
  148. public bool DenyTransacted
  149. {
  150. get { return m_DenyTransacted; }
  151. set { m_DenyTransacted = value; }
  152. }
  153. private bool m_AbuseEmailToEstateOwner = false;
  154. public bool AbuseEmailToEstateOwner
  155. {
  156. get { return m_AbuseEmailToEstateOwner; }
  157. set { m_AbuseEmailToEstateOwner = value; }
  158. }
  159. private bool m_BlockDwell = false;
  160. public bool BlockDwell
  161. {
  162. get { return m_BlockDwell; }
  163. set { m_BlockDwell = value; }
  164. }
  165. private bool m_EstateSkipScripts = false;
  166. public bool EstateSkipScripts
  167. {
  168. get { return m_EstateSkipScripts; }
  169. set { m_EstateSkipScripts = value; }
  170. }
  171. private bool m_ResetHomeOnTeleport = false;
  172. public bool ResetHomeOnTeleport
  173. {
  174. get { return m_ResetHomeOnTeleport; }
  175. set { m_ResetHomeOnTeleport = value; }
  176. }
  177. private bool m_TaxFree = false;
  178. public bool TaxFree // this is now AllowAccessOverride, keeping same name to reuse DB entries
  179. {
  180. get { return m_TaxFree; }
  181. set { m_TaxFree = value; }
  182. }
  183. private bool m_PublicAccess = true;
  184. public bool PublicAccess
  185. {
  186. get { return m_PublicAccess; }
  187. set { m_PublicAccess = value; }
  188. }
  189. private string m_AbuseEmail = String.Empty;
  190. public string AbuseEmail
  191. {
  192. get { return m_AbuseEmail; }
  193. set { m_AbuseEmail= value; }
  194. }
  195. private UUID m_EstateOwner = UUID.Zero;
  196. public UUID EstateOwner
  197. {
  198. get { return m_EstateOwner; }
  199. set { m_EstateOwner = value; }
  200. }
  201. private bool m_DenyMinors = false;
  202. public bool DenyMinors
  203. {
  204. get { return m_DenyMinors; }
  205. set { m_DenyMinors = value; }
  206. }
  207. // All those lists...
  208. //
  209. private List<UUID> l_EstateManagers = new List<UUID>();
  210. public UUID[] EstateManagers
  211. {
  212. get { return l_EstateManagers.ToArray(); }
  213. set { l_EstateManagers = new List<UUID>(value); }
  214. }
  215. private List<EstateBan> l_EstateBans = new List<EstateBan>();
  216. public EstateBan[] EstateBans
  217. {
  218. get { return l_EstateBans.ToArray(); }
  219. set { l_EstateBans = new List<EstateBan>(value); }
  220. }
  221. private List<UUID> l_EstateAccess = new List<UUID>();
  222. public UUID[] EstateAccess
  223. {
  224. get { return l_EstateAccess.ToArray(); }
  225. set { l_EstateAccess = new List<UUID>(value); }
  226. }
  227. private List<UUID> l_EstateGroups = new List<UUID>();
  228. public UUID[] EstateGroups
  229. {
  230. get { return l_EstateGroups.ToArray(); }
  231. set { l_EstateGroups = new List<UUID>(value); }
  232. }
  233. public bool DoDenyMinors = true;
  234. public bool DoDenyAnonymous = true;
  235. public EstateSettings()
  236. {
  237. }
  238. public void Save()
  239. {
  240. if (OnSave != null)
  241. OnSave(this);
  242. }
  243. public int EstateUsersCount()
  244. {
  245. return l_EstateAccess.Count;
  246. }
  247. public void AddEstateUser(UUID avatarID)
  248. {
  249. if (avatarID == UUID.Zero)
  250. return;
  251. if (!l_EstateAccess.Contains(avatarID) &&
  252. (l_EstateAccess.Count < (int)Constants.EstateAccessLimits.AllowedAccess))
  253. l_EstateAccess.Add(avatarID);
  254. }
  255. public void RemoveEstateUser(UUID avatarID)
  256. {
  257. if (l_EstateAccess.Contains(avatarID))
  258. l_EstateAccess.Remove(avatarID);
  259. }
  260. public int EstateGroupsCount()
  261. {
  262. return l_EstateGroups.Count;
  263. }
  264. public void AddEstateGroup(UUID avatarID)
  265. {
  266. if (avatarID == UUID.Zero)
  267. return;
  268. if (!l_EstateGroups.Contains(avatarID) &&
  269. (l_EstateGroups.Count < (int)Constants.EstateAccessLimits.AllowedGroups))
  270. l_EstateGroups.Add(avatarID);
  271. }
  272. public void RemoveEstateGroup(UUID avatarID)
  273. {
  274. if (l_EstateGroups.Contains(avatarID))
  275. l_EstateGroups.Remove(avatarID);
  276. }
  277. public int EstateManagersCount()
  278. {
  279. return l_EstateManagers.Count;
  280. }
  281. public void AddEstateManager(UUID avatarID)
  282. {
  283. if (avatarID == UUID.Zero)
  284. return;
  285. if (!l_EstateManagers.Contains(avatarID) &&
  286. (l_EstateManagers.Count < (int)Constants.EstateAccessLimits.EstateManagers))
  287. l_EstateManagers.Add(avatarID);
  288. }
  289. public void RemoveEstateManager(UUID avatarID)
  290. {
  291. if (l_EstateManagers.Contains(avatarID))
  292. l_EstateManagers.Remove(avatarID);
  293. }
  294. public bool IsEstateManagerOrOwner(UUID avatarID)
  295. {
  296. if (IsEstateOwner(avatarID))
  297. return true;
  298. return l_EstateManagers.Contains(avatarID);
  299. }
  300. public bool IsEstateOwner(UUID avatarID)
  301. {
  302. if (avatarID == m_EstateOwner)
  303. return true;
  304. return false;
  305. }
  306. public bool IsBanned(UUID avatarID)
  307. {
  308. if (!IsEstateManagerOrOwner(avatarID))
  309. {
  310. foreach (EstateBan ban in l_EstateBans)
  311. if (ban.BannedUserID == avatarID)
  312. return true;
  313. }
  314. return false;
  315. }
  316. public bool IsBanned(UUID avatarID, int userFlags)
  317. {
  318. if (!IsEstateManagerOrOwner(avatarID))
  319. {
  320. foreach (EstateBan ban in l_EstateBans)
  321. if (ban.BannedUserID == avatarID)
  322. return true;
  323. if (!HasAccess(avatarID))
  324. {
  325. if (DoDenyMinors && DenyMinors)
  326. {
  327. if ((userFlags & 32) == 0)
  328. {
  329. return true;
  330. }
  331. }
  332. if (DoDenyAnonymous && DenyAnonymous)
  333. {
  334. if ((userFlags & 4) == 0)
  335. {
  336. return true;
  337. }
  338. }
  339. }
  340. }
  341. return false;
  342. }
  343. public int EstateBansCount()
  344. {
  345. return l_EstateBans.Count;
  346. }
  347. public void AddBan(EstateBan ban)
  348. {
  349. if (ban == null)
  350. return;
  351. if (!IsBanned(ban.BannedUserID, 32) &&
  352. (l_EstateBans.Count < (int)Constants.EstateAccessLimits.EstateBans)) //Ignore age-based bans
  353. l_EstateBans.Add(ban);
  354. }
  355. public void ClearBans()
  356. {
  357. l_EstateBans.Clear();
  358. }
  359. public void RemoveBan(UUID avatarID)
  360. {
  361. foreach (EstateBan ban in new List<EstateBan>(l_EstateBans))
  362. if (ban.BannedUserID == avatarID)
  363. l_EstateBans.Remove(ban);
  364. }
  365. public bool HasAccess(UUID user)
  366. {
  367. if (IsEstateManagerOrOwner(user))
  368. return true;
  369. return l_EstateAccess.Contains(user);
  370. }
  371. public void SetFromFlags(ulong regionFlags)
  372. {
  373. ResetHomeOnTeleport = ((regionFlags & (ulong)OpenMetaverse.RegionFlags.ResetHomeOnTeleport) == (ulong)OpenMetaverse.RegionFlags.ResetHomeOnTeleport);
  374. BlockDwell = ((regionFlags & (ulong)OpenMetaverse.RegionFlags.BlockDwell) == (ulong)OpenMetaverse.RegionFlags.BlockDwell);
  375. AllowLandmark = ((regionFlags & (ulong)OpenMetaverse.RegionFlags.AllowLandmark) == (ulong)OpenMetaverse.RegionFlags.AllowLandmark);
  376. AllowParcelChanges = ((regionFlags & (ulong)OpenMetaverse.RegionFlags.AllowParcelChanges) == (ulong)OpenMetaverse.RegionFlags.AllowParcelChanges);
  377. AllowSetHome = ((regionFlags & (ulong)OpenMetaverse.RegionFlags.AllowSetHome) == (ulong)OpenMetaverse.RegionFlags.AllowSetHome);
  378. }
  379. public bool GroupAccess(UUID groupID)
  380. {
  381. return l_EstateGroups.Contains(groupID);
  382. }
  383. public Dictionary<string, object> ToMap()
  384. {
  385. Dictionary<string, object> map = new Dictionary<string, object>();
  386. PropertyInfo[] properties = this.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance);
  387. foreach (PropertyInfo p in properties)
  388. {
  389. // EstateBans is a complex type, let's treat it as special
  390. if (p.Name == "EstateBans")
  391. continue;
  392. object value = p.GetValue(this, null);
  393. if (value != null)
  394. {
  395. if (p.PropertyType.IsArray) // of UUIDs
  396. {
  397. if (((Array)value).Length > 0)
  398. {
  399. string[] args = new string[((Array)value).Length];
  400. int index = 0;
  401. foreach (object o in (Array)value)
  402. args[index++] = o.ToString();
  403. map[p.Name] = String.Join(",", args);
  404. }
  405. }
  406. else // simple types
  407. map[p.Name] = value;
  408. }
  409. }
  410. // EstateBans are special
  411. if (EstateBans.Length > 0)
  412. {
  413. Dictionary<string, object> bans = new Dictionary<string, object>();
  414. int i = 0;
  415. foreach (EstateBan ban in EstateBans)
  416. bans["ban" + i++] = ban.ToMap();
  417. map["EstateBans"] = bans;
  418. }
  419. return map;
  420. }
  421. /// <summary>
  422. /// For debugging
  423. /// </summary>
  424. /// <returns></returns>
  425. public override string ToString()
  426. {
  427. Dictionary<string, object> map = ToMap();
  428. String result = String.Empty;
  429. foreach (KeyValuePair<string, object> kvp in map)
  430. {
  431. if (kvp.Key == "EstateBans")
  432. {
  433. result += "EstateBans:" + Environment.NewLine;
  434. foreach (KeyValuePair<string, object> ban in (Dictionary<string, object>)kvp.Value)
  435. result += ban.Value.ToString();
  436. }
  437. else
  438. result += string.Format("{0}: {1} {2}", kvp.Key, kvp.Value.ToString(), Environment.NewLine);
  439. }
  440. return result;
  441. }
  442. public EstateSettings(Dictionary<string, object> map)
  443. {
  444. foreach (KeyValuePair<string, object> kvp in map)
  445. {
  446. PropertyInfo p = this.GetType().GetProperty(kvp.Key, BindingFlags.Public | BindingFlags.Instance);
  447. if (p == null)
  448. continue;
  449. // EstateBans is a complex type, let's treat it as special
  450. if (p.Name == "EstateBans")
  451. continue;
  452. if (p.PropertyType.IsArray)
  453. {
  454. string[] elements = ((string)map[p.Name]).Split(new char[] { ',' });
  455. UUID[] uuids = new UUID[elements.Length];
  456. int i = 0;
  457. foreach (string e in elements)
  458. uuids[i++] = new UUID(e);
  459. p.SetValue(this, uuids, null);
  460. }
  461. else
  462. {
  463. object value = p.GetValue(this, null);
  464. if (value is String)
  465. p.SetValue(this, map[p.Name], null);
  466. else if (value is UInt32)
  467. p.SetValue(this, UInt32.Parse((string)map[p.Name]), null);
  468. else if (value is Boolean)
  469. p.SetValue(this, Boolean.Parse((string)map[p.Name]), null);
  470. else if (value is UUID)
  471. p.SetValue(this, UUID.Parse((string)map[p.Name]), null);
  472. }
  473. }
  474. // EstateBans are special
  475. if (map.ContainsKey("EstateBans"))
  476. {
  477. if(map["EstateBans"] is string)
  478. {
  479. // JSON encoded bans map
  480. Dictionary<string, EstateBan> bdata = new Dictionary<string, EstateBan>();
  481. try
  482. {
  483. // bypass libovm, we dont need even more useless high level maps
  484. // this should only be called once.. but no problem, i hope
  485. // (other uses may need more..)
  486. LitJson.JsonMapper.RegisterImporter<string, UUID>((input) => new UUID(input));
  487. bdata = LitJson.JsonMapper.ToObject<Dictionary<string,EstateBan>>((string)map["EstateBans"]);
  488. }
  489. // catch(Exception e)
  490. catch
  491. {
  492. return;
  493. }
  494. EstateBan[] jbans = new EstateBan[bdata.Count];
  495. bdata.Values.CopyTo(jbans,0);
  496. PropertyInfo jbansProperty = this.GetType().GetProperty("EstateBans", BindingFlags.Public | BindingFlags.Instance);
  497. jbansProperty.SetValue(this, jbans, null);
  498. }
  499. else
  500. {
  501. var banData = ((Dictionary<string, object>)map["EstateBans"]).Values;
  502. EstateBan[] bans = new EstateBan[banData.Count];
  503. int b = 0;
  504. foreach (Dictionary<string, object> ban in banData)
  505. bans[b++] = new EstateBan(ban);
  506. PropertyInfo bansProperty = this.GetType().GetProperty("EstateBans", BindingFlags.Public | BindingFlags.Instance);
  507. bansProperty.SetValue(this, bans, null);
  508. }
  509. }
  510. }
  511. }
  512. }