EstateSettings.cs 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562
  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. private bool m_DenyIdentified = false;
  140. public bool DenyIdentified
  141. {
  142. get { return m_DenyIdentified; }
  143. set { m_DenyIdentified = value; }
  144. }
  145. private bool m_DenyTransacted = false;
  146. public bool DenyTransacted
  147. {
  148. get { return m_DenyTransacted; }
  149. set { m_DenyTransacted = value; }
  150. }
  151. private bool m_AbuseEmailToEstateOwner = false;
  152. public bool AbuseEmailToEstateOwner
  153. {
  154. get { return m_AbuseEmailToEstateOwner; }
  155. set { m_AbuseEmailToEstateOwner = value; }
  156. }
  157. private bool m_BlockDwell = false;
  158. public bool BlockDwell
  159. {
  160. get { return m_BlockDwell; }
  161. set { m_BlockDwell = value; }
  162. }
  163. private bool m_EstateSkipScripts = false;
  164. public bool EstateSkipScripts
  165. {
  166. get { return m_EstateSkipScripts; }
  167. set { m_EstateSkipScripts = value; }
  168. }
  169. private bool m_ResetHomeOnTeleport = false;
  170. public bool ResetHomeOnTeleport
  171. {
  172. get { return m_ResetHomeOnTeleport; }
  173. set { m_ResetHomeOnTeleport = value; }
  174. }
  175. private bool m_TaxFree = false;
  176. public bool TaxFree
  177. {
  178. get { return m_TaxFree; }
  179. set { m_TaxFree = value; }
  180. }
  181. private bool m_PublicAccess = true;
  182. public bool PublicAccess
  183. {
  184. get { return m_PublicAccess; }
  185. set { m_PublicAccess = value; }
  186. }
  187. private string m_AbuseEmail = String.Empty;
  188. public string AbuseEmail
  189. {
  190. get { return m_AbuseEmail; }
  191. set { m_AbuseEmail= value; }
  192. }
  193. private UUID m_EstateOwner = UUID.Zero;
  194. public UUID EstateOwner
  195. {
  196. get { return m_EstateOwner; }
  197. set { m_EstateOwner = value; }
  198. }
  199. private bool m_DenyMinors = false;
  200. public bool DenyMinors
  201. {
  202. get { return m_DenyMinors; }
  203. set { m_DenyMinors = value; }
  204. }
  205. // All those lists...
  206. //
  207. private List<UUID> l_EstateManagers = new List<UUID>();
  208. public UUID[] EstateManagers
  209. {
  210. get { return l_EstateManagers.ToArray(); }
  211. set { l_EstateManagers = new List<UUID>(value); }
  212. }
  213. private List<EstateBan> l_EstateBans = new List<EstateBan>();
  214. public EstateBan[] EstateBans
  215. {
  216. get { return l_EstateBans.ToArray(); }
  217. set { l_EstateBans = new List<EstateBan>(value); }
  218. }
  219. private List<UUID> l_EstateAccess = new List<UUID>();
  220. public UUID[] EstateAccess
  221. {
  222. get { return l_EstateAccess.ToArray(); }
  223. set { l_EstateAccess = new List<UUID>(value); }
  224. }
  225. private List<UUID> l_EstateGroups = new List<UUID>();
  226. public UUID[] EstateGroups
  227. {
  228. get { return l_EstateGroups.ToArray(); }
  229. set { l_EstateGroups = new List<UUID>(value); }
  230. }
  231. public EstateSettings()
  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 IsEstateManagerOrOwner(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. if (!IsEstateManagerOrOwner(avatarID))
  290. {
  291. foreach (EstateBan ban in l_EstateBans)
  292. if (ban.BannedUserID == avatarID)
  293. return true;
  294. }
  295. return false;
  296. }
  297. public bool IsBanned(UUID avatarID, int userFlags)
  298. {
  299. if (!IsEstateManagerOrOwner(avatarID))
  300. {
  301. foreach (EstateBan ban in l_EstateBans)
  302. if (ban.BannedUserID == avatarID)
  303. return true;
  304. if (!HasAccess(avatarID))
  305. {
  306. if (DenyMinors)
  307. {
  308. if ((userFlags & 32) == 0)
  309. {
  310. return true;
  311. }
  312. }
  313. if (DenyAnonymous)
  314. {
  315. if ((userFlags & 4) == 0)
  316. {
  317. return true;
  318. }
  319. }
  320. }
  321. }
  322. return false;
  323. }
  324. public void AddBan(EstateBan ban)
  325. {
  326. if (ban == null)
  327. return;
  328. if (!IsBanned(ban.BannedUserID, 32)) //Ignore age-based bans
  329. l_EstateBans.Add(ban);
  330. }
  331. public void ClearBans()
  332. {
  333. l_EstateBans.Clear();
  334. }
  335. public void RemoveBan(UUID avatarID)
  336. {
  337. foreach (EstateBan ban in new List<EstateBan>(l_EstateBans))
  338. if (ban.BannedUserID == avatarID)
  339. l_EstateBans.Remove(ban);
  340. }
  341. public bool HasAccess(UUID user)
  342. {
  343. if (IsEstateManagerOrOwner(user))
  344. return true;
  345. return l_EstateAccess.Contains(user);
  346. }
  347. public void SetFromFlags(ulong regionFlags)
  348. {
  349. ResetHomeOnTeleport = ((regionFlags & (ulong)OpenMetaverse.RegionFlags.ResetHomeOnTeleport) == (ulong)OpenMetaverse.RegionFlags.ResetHomeOnTeleport);
  350. BlockDwell = ((regionFlags & (ulong)OpenMetaverse.RegionFlags.BlockDwell) == (ulong)OpenMetaverse.RegionFlags.BlockDwell);
  351. AllowLandmark = ((regionFlags & (ulong)OpenMetaverse.RegionFlags.AllowLandmark) == (ulong)OpenMetaverse.RegionFlags.AllowLandmark);
  352. AllowParcelChanges = ((regionFlags & (ulong)OpenMetaverse.RegionFlags.AllowParcelChanges) == (ulong)OpenMetaverse.RegionFlags.AllowParcelChanges);
  353. AllowSetHome = ((regionFlags & (ulong)OpenMetaverse.RegionFlags.AllowSetHome) == (ulong)OpenMetaverse.RegionFlags.AllowSetHome);
  354. }
  355. public bool GroupAccess(UUID groupID)
  356. {
  357. return l_EstateGroups.Contains(groupID);
  358. }
  359. public Dictionary<string, object> ToMap()
  360. {
  361. Dictionary<string, object> map = new Dictionary<string, object>();
  362. PropertyInfo[] properties = this.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance);
  363. foreach (PropertyInfo p in properties)
  364. {
  365. // EstateBans is a complex type, let's treat it as special
  366. if (p.Name == "EstateBans")
  367. continue;
  368. object value = p.GetValue(this, null);
  369. if (value != null)
  370. {
  371. if (p.PropertyType.IsArray) // of UUIDs
  372. {
  373. if (((Array)value).Length > 0)
  374. {
  375. string[] args = new string[((Array)value).Length];
  376. int index = 0;
  377. foreach (object o in (Array)value)
  378. args[index++] = o.ToString();
  379. map[p.Name] = String.Join(",", args);
  380. }
  381. }
  382. else // simple types
  383. map[p.Name] = value;
  384. }
  385. }
  386. // EstateBans are special
  387. if (EstateBans.Length > 0)
  388. {
  389. Dictionary<string, object> bans = new Dictionary<string, object>();
  390. int i = 0;
  391. foreach (EstateBan ban in EstateBans)
  392. bans["ban" + i++] = ban.ToMap();
  393. map["EstateBans"] = bans;
  394. }
  395. return map;
  396. }
  397. /// <summary>
  398. /// For debugging
  399. /// </summary>
  400. /// <returns></returns>
  401. public override string ToString()
  402. {
  403. Dictionary<string, object> map = ToMap();
  404. String result = String.Empty;
  405. foreach (KeyValuePair<string, object> kvp in map)
  406. {
  407. if (kvp.Key == "EstateBans")
  408. {
  409. result += "EstateBans:" + Environment.NewLine;
  410. foreach (KeyValuePair<string, object> ban in (Dictionary<string, object>)kvp.Value)
  411. result += ban.Value.ToString();
  412. }
  413. else
  414. result += string.Format("{0}: {1} {2}", kvp.Key, kvp.Value.ToString(), Environment.NewLine);
  415. }
  416. return result;
  417. }
  418. public EstateSettings(Dictionary<string, object> map)
  419. {
  420. foreach (KeyValuePair<string, object> kvp in map)
  421. {
  422. PropertyInfo p = this.GetType().GetProperty(kvp.Key, BindingFlags.Public | BindingFlags.Instance);
  423. if (p == null)
  424. continue;
  425. // EstateBans is a complex type, let's treat it as special
  426. if (p.Name == "EstateBans")
  427. continue;
  428. if (p.PropertyType.IsArray)
  429. {
  430. string[] elements = ((string)map[p.Name]).Split(new char[] { ',' });
  431. UUID[] uuids = new UUID[elements.Length];
  432. int i = 0;
  433. foreach (string e in elements)
  434. uuids[i++] = new UUID(e);
  435. p.SetValue(this, uuids, null);
  436. }
  437. else
  438. {
  439. object value = p.GetValue(this, null);
  440. if (value is String)
  441. p.SetValue(this, map[p.Name], null);
  442. else if (value is UInt32)
  443. p.SetValue(this, UInt32.Parse((string)map[p.Name]), null);
  444. else if (value is Boolean)
  445. p.SetValue(this, Boolean.Parse((string)map[p.Name]), null);
  446. else if (value is UUID)
  447. p.SetValue(this, UUID.Parse((string)map[p.Name]), null);
  448. }
  449. }
  450. // EstateBans are special
  451. if (map.ContainsKey("EstateBans"))
  452. {
  453. var banData = ((Dictionary<string, object>)map["EstateBans"]).Values;
  454. EstateBan[] bans = new EstateBan[banData.Count];
  455. int b = 0;
  456. foreach (Dictionary<string, object> ban in banData)
  457. bans[b++] = new EstateBan(ban);
  458. PropertyInfo bansProperty = this.GetType().GetProperty("EstateBans", BindingFlags.Public | BindingFlags.Instance);
  459. bansProperty.SetValue(this, bans, null);
  460. }
  461. }
  462. }
  463. }