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