EstateSettings.cs 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600
  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 = false;
  104. public bool UseGlobalTime
  105. {
  106. get { return m_UseGlobalTime; }
  107. //set { m_UseGlobalTime = value; }
  108. set { m_UseGlobalTime = false; }
  109. }
  110. private bool m_FixedSun = false;
  111. public bool FixedSun
  112. {
  113. get { return m_FixedSun; }
  114. // set { m_FixedSun = value; }
  115. set { m_FixedSun = false; }
  116. }
  117. private double m_SunPosition = 0.0;
  118. public double SunPosition
  119. {
  120. get { return m_SunPosition; }
  121. //set { m_SunPosition = value; }
  122. set { m_SunPosition = 0; }
  123. }
  124. private bool m_AllowVoice = true;
  125. public bool AllowVoice
  126. {
  127. get { return m_AllowVoice; }
  128. set { m_AllowVoice = value; }
  129. }
  130. private bool m_AllowDirectTeleport = true;
  131. public bool AllowDirectTeleport
  132. {
  133. get { return m_AllowDirectTeleport; }
  134. set { m_AllowDirectTeleport = value; }
  135. }
  136. private bool m_DenyAnonymous = false;
  137. public bool DenyAnonymous
  138. {
  139. get { return (DoDenyAnonymous && m_DenyAnonymous); }
  140. set { m_DenyAnonymous = value; }
  141. }
  142. // no longer in used, may be reassigned
  143. private bool m_DenyIdentified = false;
  144. public bool DenyIdentified
  145. {
  146. get { return m_DenyIdentified; }
  147. set { m_DenyIdentified = value; }
  148. }
  149. // no longer in used, may be reassigned
  150. private bool m_DenyTransacted = false;
  151. public bool DenyTransacted
  152. {
  153. get { return m_DenyTransacted; }
  154. set { m_DenyTransacted = value; }
  155. }
  156. private bool m_AbuseEmailToEstateOwner = false;
  157. public bool AbuseEmailToEstateOwner
  158. {
  159. get { return m_AbuseEmailToEstateOwner; }
  160. set { m_AbuseEmailToEstateOwner = value; }
  161. }
  162. private bool m_BlockDwell = false;
  163. public bool BlockDwell
  164. {
  165. get { return m_BlockDwell; }
  166. set { m_BlockDwell = value; }
  167. }
  168. private bool m_EstateSkipScripts = false;
  169. public bool EstateSkipScripts
  170. {
  171. get { return m_EstateSkipScripts; }
  172. set { m_EstateSkipScripts = value; }
  173. }
  174. private bool m_ResetHomeOnTeleport = false;
  175. public bool ResetHomeOnTeleport
  176. {
  177. get { return m_ResetHomeOnTeleport; }
  178. set { m_ResetHomeOnTeleport = value; }
  179. }
  180. private bool m_TaxFree = false;
  181. public bool TaxFree // this is now !AllowAccessOverride, keeping same name to reuse DB entries
  182. {
  183. get { return m_TaxFree; }
  184. set { m_TaxFree = value; }
  185. }
  186. private bool m_PublicAccess = true;
  187. public bool PublicAccess
  188. {
  189. get { return m_PublicAccess; }
  190. set { m_PublicAccess = value; }
  191. }
  192. private string m_AbuseEmail = String.Empty;
  193. public string AbuseEmail
  194. {
  195. get { return m_AbuseEmail; }
  196. set { m_AbuseEmail= value; }
  197. }
  198. private UUID m_EstateOwner = UUID.Zero;
  199. public UUID EstateOwner
  200. {
  201. get { return m_EstateOwner; }
  202. set { m_EstateOwner = value; }
  203. }
  204. private bool m_DenyMinors = false;
  205. public bool DenyMinors
  206. {
  207. get { return (DoDenyMinors && m_DenyMinors); }
  208. set { m_DenyMinors = value; }
  209. }
  210. private bool m_AllowEnviromentOverride = false; //keep the mispell so not to go change the dbs
  211. public bool AllowEnvironmentOverride
  212. {
  213. get { return m_AllowEnviromentOverride; }
  214. set { m_AllowEnviromentOverride = value; }
  215. }
  216. // All those lists...
  217. //
  218. private List<UUID> l_EstateManagers = new List<UUID>();
  219. public UUID[] EstateManagers
  220. {
  221. get { return l_EstateManagers.ToArray(); }
  222. set { l_EstateManagers = new List<UUID>(value); }
  223. }
  224. private List<EstateBan> l_EstateBans = new List<EstateBan>();
  225. public EstateBan[] EstateBans
  226. {
  227. get { return l_EstateBans.ToArray(); }
  228. set { l_EstateBans = new List<EstateBan>(value); }
  229. }
  230. private List<UUID> l_EstateAccess = new List<UUID>();
  231. public UUID[] EstateAccess
  232. {
  233. get { return l_EstateAccess.ToArray(); }
  234. set { l_EstateAccess = new List<UUID>(value); }
  235. }
  236. private List<UUID> l_EstateGroups = new List<UUID>();
  237. public UUID[] EstateGroups
  238. {
  239. get { return l_EstateGroups.ToArray(); }
  240. set { l_EstateGroups = new List<UUID>(value); }
  241. }
  242. public bool DoDenyMinors = true;
  243. public bool DoDenyAnonymous = true;
  244. public EstateSettings()
  245. {
  246. }
  247. public void Save()
  248. {
  249. if (OnSave != null)
  250. OnSave(this);
  251. }
  252. public int EstateUsersCount()
  253. {
  254. return l_EstateAccess.Count;
  255. }
  256. public void AddEstateUser(UUID avatarID)
  257. {
  258. if (avatarID.IsZero())
  259. return;
  260. if (!l_EstateAccess.Contains(avatarID) &&
  261. (l_EstateAccess.Count < (int)Constants.EstateAccessLimits.AllowedAccess))
  262. l_EstateAccess.Add(avatarID);
  263. }
  264. public void RemoveEstateUser(UUID avatarID)
  265. {
  266. if (l_EstateAccess.Contains(avatarID))
  267. l_EstateAccess.Remove(avatarID);
  268. }
  269. public int EstateGroupsCount()
  270. {
  271. return l_EstateGroups.Count;
  272. }
  273. public void AddEstateGroup(UUID avatarID)
  274. {
  275. if (avatarID.IsZero())
  276. return;
  277. if (!l_EstateGroups.Contains(avatarID) &&
  278. (l_EstateGroups.Count < (int)Constants.EstateAccessLimits.AllowedGroups))
  279. l_EstateGroups.Add(avatarID);
  280. }
  281. public void RemoveEstateGroup(UUID avatarID)
  282. {
  283. if (l_EstateGroups.Contains(avatarID))
  284. l_EstateGroups.Remove(avatarID);
  285. }
  286. public int EstateManagersCount()
  287. {
  288. return l_EstateManagers.Count;
  289. }
  290. public void AddEstateManager(UUID avatarID)
  291. {
  292. if (avatarID.IsZero())
  293. return;
  294. if (!l_EstateManagers.Contains(avatarID) &&
  295. (l_EstateManagers.Count < (int)Constants.EstateAccessLimits.EstateManagers))
  296. l_EstateManagers.Add(avatarID);
  297. }
  298. public void RemoveEstateManager(UUID avatarID)
  299. {
  300. if (l_EstateManagers.Contains(avatarID))
  301. l_EstateManagers.Remove(avatarID);
  302. }
  303. public bool IsEstateManagerOrOwner(UUID avatarID)
  304. {
  305. if (IsEstateOwner(avatarID))
  306. return true;
  307. return l_EstateManagers.Contains(avatarID);
  308. }
  309. public bool IsEstateOwner(UUID avatarID)
  310. {
  311. if (avatarID == m_EstateOwner)
  312. return true;
  313. return false;
  314. }
  315. public bool IsBanned(UUID avatarID)
  316. {
  317. if (!IsEstateManagerOrOwner(avatarID))
  318. {
  319. foreach (EstateBan ban in l_EstateBans)
  320. if (ban.BannedUserID == avatarID)
  321. return true;
  322. }
  323. return false;
  324. }
  325. public bool IsBanned(UUID avatarID, int userFlags)
  326. {
  327. if (!IsEstateManagerOrOwner(avatarID))
  328. {
  329. foreach (EstateBan ban in l_EstateBans)
  330. if (ban.BannedUserID == avatarID)
  331. return true;
  332. if (!HasAccess(avatarID))
  333. {
  334. if (DenyMinors)
  335. {
  336. if ((userFlags & 32) == 0)
  337. {
  338. return true;
  339. }
  340. }
  341. if (DenyAnonymous)
  342. {
  343. if ((userFlags & 4) == 0)
  344. {
  345. return true;
  346. }
  347. }
  348. }
  349. }
  350. return false;
  351. }
  352. public int EstateBansCount()
  353. {
  354. return l_EstateBans.Count;
  355. }
  356. public void AddBan(EstateBan ban)
  357. {
  358. if (ban == null)
  359. return;
  360. if (!IsBanned(ban.BannedUserID, 32) &&
  361. (l_EstateBans.Count < (int)Constants.EstateAccessLimits.EstateBans)) //Ignore age-based bans
  362. l_EstateBans.Add(ban);
  363. }
  364. public void ClearBans()
  365. {
  366. l_EstateBans.Clear();
  367. }
  368. public void RemoveBan(UUID avatarID)
  369. {
  370. foreach (EstateBan ban in new List<EstateBan>(l_EstateBans))
  371. if (ban.BannedUserID == avatarID)
  372. l_EstateBans.Remove(ban);
  373. }
  374. public bool HasAccess(UUID user)
  375. {
  376. if (IsEstateManagerOrOwner(user))
  377. return true;
  378. return l_EstateAccess.Contains(user);
  379. }
  380. public void SetFromFlags(ulong regionFlags)
  381. {
  382. ResetHomeOnTeleport = ((regionFlags & (ulong)OpenMetaverse.RegionFlags.ResetHomeOnTeleport) == (ulong)OpenMetaverse.RegionFlags.ResetHomeOnTeleport);
  383. BlockDwell = ((regionFlags & (ulong)OpenMetaverse.RegionFlags.BlockDwell) == (ulong)OpenMetaverse.RegionFlags.BlockDwell);
  384. AllowLandmark = ((regionFlags & (ulong)OpenMetaverse.RegionFlags.AllowLandmark) == (ulong)OpenMetaverse.RegionFlags.AllowLandmark);
  385. AllowParcelChanges = ((regionFlags & (ulong)OpenMetaverse.RegionFlags.AllowParcelChanges) == (ulong)OpenMetaverse.RegionFlags.AllowParcelChanges);
  386. AllowSetHome = ((regionFlags & (ulong)OpenMetaverse.RegionFlags.AllowSetHome) == (ulong)OpenMetaverse.RegionFlags.AllowSetHome);
  387. }
  388. public bool GroupAccess(UUID groupID)
  389. {
  390. return l_EstateGroups.Contains(groupID);
  391. }
  392. public Dictionary<string, object> ToMap()
  393. {
  394. Dictionary<string, object> map = new Dictionary<string, object>();
  395. PropertyInfo[] properties = this.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance);
  396. foreach (PropertyInfo p in properties)
  397. {
  398. // EstateBans is a complex type, let's treat it as special
  399. if (p.Name == "EstateBans")
  400. continue;
  401. object value = p.GetValue(this, null);
  402. if (value != null)
  403. {
  404. if (p.PropertyType.IsArray) // of UUIDs
  405. {
  406. if (((Array)value).Length > 0)
  407. {
  408. string[] args = new string[((Array)value).Length];
  409. int index = 0;
  410. foreach (object o in (Array)value)
  411. args[index++] = o.ToString();
  412. map[p.Name] = String.Join(",", args);
  413. }
  414. }
  415. else // simple types
  416. map[p.Name] = value;
  417. }
  418. }
  419. // EstateBans are special
  420. if (EstateBans.Length > 0)
  421. {
  422. Dictionary<string, object> bans = new Dictionary<string, object>();
  423. int i = 0;
  424. foreach (EstateBan ban in EstateBans)
  425. bans["ban" + i++] = ban.ToMap();
  426. map["EstateBans"] = bans;
  427. }
  428. return map;
  429. }
  430. /// <summary>
  431. /// For debugging
  432. /// </summary>
  433. /// <returns></returns>
  434. public override string ToString()
  435. {
  436. Dictionary<string, object> map = ToMap();
  437. String result = String.Empty;
  438. foreach (KeyValuePair<string, object> kvp in map)
  439. {
  440. if (kvp.Key == "EstateBans")
  441. {
  442. result += "EstateBans:" + Environment.NewLine;
  443. foreach (KeyValuePair<string, object> ban in (Dictionary<string, object>)kvp.Value)
  444. result += ban.Value.ToString();
  445. }
  446. else
  447. result += string.Format("{0}: {1} {2}", kvp.Key, kvp.Value.ToString(), Environment.NewLine);
  448. }
  449. return result;
  450. }
  451. public EstateSettings(Dictionary<string, object> map)
  452. {
  453. foreach (KeyValuePair<string, object> kvp in map)
  454. {
  455. PropertyInfo p = this.GetType().GetProperty(kvp.Key, BindingFlags.Public | BindingFlags.Instance);
  456. if (p == null)
  457. continue;
  458. // EstateBans is a complex type, let's treat it as special
  459. if (p.Name == "EstateBans")
  460. continue;
  461. if (p.PropertyType.IsArray)
  462. {
  463. string[] elements = ((string)map[p.Name]).Split(new char[] { ',' });
  464. UUID[] uuids = new UUID[elements.Length];
  465. int i = 0;
  466. foreach (string e in elements)
  467. uuids[i++] = new UUID(e);
  468. p.SetValue(this, uuids, null);
  469. }
  470. else
  471. {
  472. object value = p.GetValue(this, null);
  473. if (value is String)
  474. p.SetValue(this, map[p.Name], null);
  475. else if (value is UInt32)
  476. p.SetValue(this, UInt32.Parse((string)map[p.Name]), null);
  477. else if (value is Boolean)
  478. p.SetValue(this, Boolean.Parse((string)map[p.Name]), null);
  479. else if (value is UUID)
  480. p.SetValue(this, UUID.Parse((string)map[p.Name]), null);
  481. }
  482. }
  483. // EstateBans are special
  484. if (map.ContainsKey("EstateBans"))
  485. {
  486. if(map["EstateBans"] is string)
  487. {
  488. // JSON encoded bans map
  489. Dictionary<string, EstateBan> bdata = new Dictionary<string, EstateBan>();
  490. try
  491. {
  492. // bypass libovm, we dont need even more useless high level maps
  493. // this should only be called once.. but no problem, i hope
  494. // (other uses may need more..)
  495. LitJson.JsonMapper.RegisterImporter<string, UUID>((input) => new UUID(input));
  496. bdata = LitJson.JsonMapper.ToObject<Dictionary<string,EstateBan>>((string)map["EstateBans"]);
  497. }
  498. // catch(Exception e)
  499. catch
  500. {
  501. return;
  502. }
  503. EstateBan[] jbans = new EstateBan[bdata.Count];
  504. bdata.Values.CopyTo(jbans,0);
  505. PropertyInfo jbansProperty = this.GetType().GetProperty("EstateBans", BindingFlags.Public | BindingFlags.Instance);
  506. jbansProperty.SetValue(this, jbans, null);
  507. }
  508. else
  509. {
  510. var banData = ((Dictionary<string, object>)map["EstateBans"]).Values;
  511. EstateBan[] bans = new EstateBan[banData.Count];
  512. int b = 0;
  513. foreach (Dictionary<string, object> ban in banData)
  514. bans[b++] = new EstateBan(ban);
  515. PropertyInfo bansProperty = this.GetType().GetProperty("EstateBans", BindingFlags.Public | BindingFlags.Instance);
  516. bansProperty.SetValue(this, bans, null);
  517. }
  518. }
  519. }
  520. }
  521. }