aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Framework/EstateSettings.cs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--OpenSim/Framework/EstateSettings.cs530
1 files changed, 530 insertions, 0 deletions
diff --git a/OpenSim/Framework/EstateSettings.cs b/OpenSim/Framework/EstateSettings.cs
new file mode 100644
index 0000000..4df7860
--- /dev/null
+++ b/OpenSim/Framework/EstateSettings.cs
@@ -0,0 +1,530 @@
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
28using System;
29using System.Collections.Generic;
30using System.IO;
31using System.Reflection;
32using OpenMetaverse;
33
34namespace 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 foreach (EstateBan ban in l_EstateBans)
369 if (ban.BannedUserID == avatarID)
370 return true;
371 return false;
372 }
373
374 public void AddBan(EstateBan ban)
375 {
376 if (ban == null)
377 return;
378 if (!IsBanned(ban.BannedUserID))
379 l_EstateBans.Add(ban);
380 }
381
382 public void ClearBans()
383 {
384 l_EstateBans.Clear();
385 }
386
387 public void RemoveBan(UUID avatarID)
388 {
389 foreach (EstateBan ban in new List<EstateBan>(l_EstateBans))
390 if (ban.BannedUserID == avatarID)
391 l_EstateBans.Remove(ban);
392 }
393
394 public bool HasAccess(UUID user)
395 {
396 if (IsEstateManagerOrOwner(user))
397 return true;
398
399 return l_EstateAccess.Contains(user);
400 }
401
402 public void SetFromFlags(ulong regionFlags)
403 {
404 ResetHomeOnTeleport = ((regionFlags & (ulong)OpenMetaverse.RegionFlags.ResetHomeOnTeleport) == (ulong)OpenMetaverse.RegionFlags.ResetHomeOnTeleport);
405 BlockDwell = ((regionFlags & (ulong)OpenMetaverse.RegionFlags.BlockDwell) == (ulong)OpenMetaverse.RegionFlags.BlockDwell);
406 AllowLandmark = ((regionFlags & (ulong)OpenMetaverse.RegionFlags.AllowLandmark) == (ulong)OpenMetaverse.RegionFlags.AllowLandmark);
407 AllowParcelChanges = ((regionFlags & (ulong)OpenMetaverse.RegionFlags.AllowParcelChanges) == (ulong)OpenMetaverse.RegionFlags.AllowParcelChanges);
408 AllowSetHome = ((regionFlags & (ulong)OpenMetaverse.RegionFlags.AllowSetHome) == (ulong)OpenMetaverse.RegionFlags.AllowSetHome);
409 }
410
411 public bool GroupAccess(UUID groupID)
412 {
413 return l_EstateGroups.Contains(groupID);
414 }
415
416 public Dictionary<string, object> ToMap()
417 {
418 Dictionary<string, object> map = new Dictionary<string, object>();
419 PropertyInfo[] properties = this.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance);
420 foreach (PropertyInfo p in properties)
421 {
422 // EstateBans is a complex type, let's treat it as special
423 if (p.Name == "EstateBans")
424 continue;
425
426 object value = p.GetValue(this, null);
427 if (value != null)
428 {
429 if (p.PropertyType.IsArray) // of UUIDs
430 {
431 if (((Array)value).Length > 0)
432 {
433 string[] args = new string[((Array)value).Length];
434 int index = 0;
435 foreach (object o in (Array)value)
436 args[index++] = o.ToString();
437 map[p.Name] = String.Join(",", args);
438 }
439 }
440 else // simple types
441 map[p.Name] = value;
442 }
443 }
444
445 // EstateBans are special
446 if (EstateBans.Length > 0)
447 {
448 Dictionary<string, object> bans = new Dictionary<string, object>();
449 int i = 0;
450 foreach (EstateBan ban in EstateBans)
451 bans["ban" + i++] = ban.ToMap();
452 map["EstateBans"] = bans;
453 }
454
455 return map;
456 }
457
458 /// <summary>
459 /// For debugging
460 /// </summary>
461 /// <returns></returns>
462 public override string ToString()
463 {
464 Dictionary<string, object> map = ToMap();
465 String result = String.Empty;
466
467 foreach (KeyValuePair<string, object> kvp in map)
468 {
469 if (kvp.Key == "EstateBans")
470 {
471 result += "EstateBans:" + Environment.NewLine;
472 foreach (KeyValuePair<string, object> ban in (Dictionary<string, object>)kvp.Value)
473 result += ban.Value.ToString();
474 }
475 else
476 result += string.Format("{0}: {1} {2}", kvp.Key, kvp.Value.ToString(), Environment.NewLine);
477 }
478
479 return result;
480 }
481
482 public EstateSettings(Dictionary<string, object> map)
483 {
484 foreach (KeyValuePair<string, object> kvp in map)
485 {
486 PropertyInfo p = this.GetType().GetProperty(kvp.Key, BindingFlags.Public | BindingFlags.Instance);
487 if (p == null)
488 continue;
489
490 // EstateBans is a complex type, let's treat it as special
491 if (p.Name == "EstateBans")
492 continue;
493
494 if (p.PropertyType.IsArray)
495 {
496 string[] elements = ((string)map[p.Name]).Split(new char[] { ',' });
497 UUID[] uuids = new UUID[elements.Length];
498 int i = 0;
499 foreach (string e in elements)
500 uuids[i++] = new UUID(e);
501 p.SetValue(this, uuids, null);
502 }
503 else
504 {
505 object value = p.GetValue(this, null);
506 if (value is String)
507 p.SetValue(this, map[p.Name], null);
508 else if (value is UInt32)
509 p.SetValue(this, UInt32.Parse((string)map[p.Name]), null);
510 else if (value is Boolean)
511 p.SetValue(this, Boolean.Parse((string)map[p.Name]), null);
512 else if (value is UUID)
513 p.SetValue(this, UUID.Parse((string)map[p.Name]), null);
514 }
515 }
516
517 // EstateBans are special
518 if (map.ContainsKey("EstateBans"))
519 {
520 var banData = ((Dictionary<string, object>)map["EstateBans"]).Values;
521 EstateBan[] bans = new EstateBan[banData.Count];
522 int b = 0;
523 foreach (Dictionary<string, object> ban in banData)
524 bans[b++] = new EstateBan(ban);
525 PropertyInfo bansProperty = this.GetType().GetProperty("EstateBans", BindingFlags.Public | BindingFlags.Instance);
526 bansProperty.SetValue(this, bans, null);
527 }
528 }
529 }
530}