1
0

EstateSettings.cs 19 KB

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