EstateBan.cs 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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 EstateBan
  34. {
  35. private uint m_estateID = 1;
  36. /// <summary>
  37. /// ID of the estate this ban limits access to.
  38. /// </summary>
  39. public uint EstateID
  40. {
  41. get
  42. {
  43. return m_estateID;
  44. }
  45. set
  46. {
  47. m_estateID = value;
  48. }
  49. }
  50. private UUID m_bannedUserID = UUID.Zero;
  51. /// <summary>
  52. /// ID of the banned user.
  53. /// </summary>
  54. public UUID BannedUserID
  55. {
  56. get
  57. {
  58. return m_bannedUserID;
  59. }
  60. set
  61. {
  62. m_bannedUserID = value;
  63. }
  64. }
  65. private string m_bannedHostAddress = string.Empty;
  66. /// <summary>
  67. /// IP address or domain name of the banned client.
  68. /// </summary>
  69. public string BannedHostAddress
  70. {
  71. get
  72. {
  73. return m_bannedHostAddress;
  74. }
  75. set
  76. {
  77. m_bannedHostAddress = value;
  78. }
  79. }
  80. private string m_bannedHostIPMask = string.Empty;
  81. /// <summary>
  82. /// IP address mask for banning group of client hosts.
  83. /// </summary>
  84. public string BannedHostIPMask
  85. {
  86. get
  87. {
  88. return m_bannedHostIPMask;
  89. }
  90. set
  91. {
  92. m_bannedHostIPMask = value;
  93. }
  94. }
  95. private string m_bannedHostNameMask = string.Empty;
  96. /// <summary>
  97. /// Domain name mask for banning group of client hosts.
  98. /// </summary>
  99. public string BannedHostNameMask
  100. {
  101. get
  102. {
  103. return m_bannedHostNameMask;
  104. }
  105. set
  106. {
  107. m_bannedHostNameMask = value;
  108. }
  109. }
  110. public EstateBan() { }
  111. public Dictionary<string, object> ToMap()
  112. {
  113. Dictionary<string, object> map = new Dictionary<string, object>();
  114. PropertyInfo[] properties = this.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance);
  115. foreach (PropertyInfo p in properties)
  116. map[p.Name] = p.GetValue(this, null);
  117. return map;
  118. }
  119. public EstateBan(Dictionary<string, object> map)
  120. {
  121. foreach (KeyValuePair<string, object> kvp in map)
  122. {
  123. PropertyInfo p = this.GetType().GetProperty(kvp.Key, BindingFlags.Public | BindingFlags.Instance);
  124. if (p == null)
  125. continue;
  126. object value = p.GetValue(this, null);
  127. if (value is String)
  128. p.SetValue(this, map[p.Name], null);
  129. else if (value is UInt32)
  130. p.SetValue(this, UInt32.Parse((string)map[p.Name]), null);
  131. else if (value is Boolean)
  132. p.SetValue(this, Boolean.Parse((string)map[p.Name]), null);
  133. else if (value is UUID)
  134. p.SetValue(this, UUID.Parse((string)map[p.Name]), null);
  135. }
  136. }
  137. /// <summary>
  138. /// For debugging
  139. /// </summary>
  140. /// <returns></returns>
  141. public override string ToString()
  142. {
  143. Dictionary<string, object> map = ToMap();
  144. string result = string.Empty;
  145. foreach (KeyValuePair<string, object> kvp in map)
  146. result += string.Format("{0}: {1} {2}", kvp.Key, kvp.Value, Environment.NewLine);
  147. return result;
  148. }
  149. }
  150. }