EstateBan.cs 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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. public UUID BanningUserID { get; set; }
  66. public int BanTime { get; set; }
  67. private string m_bannedHostAddress = string.Empty;
  68. /// <summary>
  69. /// IP address or domain name of the banned client.
  70. /// </summary>
  71. public string BannedHostAddress
  72. {
  73. get
  74. {
  75. return m_bannedHostAddress;
  76. }
  77. set
  78. {
  79. m_bannedHostAddress = value;
  80. }
  81. }
  82. private string m_bannedHostIPMask = string.Empty;
  83. /// <summary>
  84. /// IP address mask for banning group of client hosts.
  85. /// </summary>
  86. public string BannedHostIPMask
  87. {
  88. get
  89. {
  90. return m_bannedHostIPMask;
  91. }
  92. set
  93. {
  94. m_bannedHostIPMask = value;
  95. }
  96. }
  97. private string m_bannedHostNameMask = string.Empty;
  98. /// <summary>
  99. /// Domain name mask for banning group of client hosts.
  100. /// </summary>
  101. public string BannedHostNameMask
  102. {
  103. get
  104. {
  105. return m_bannedHostNameMask;
  106. }
  107. set
  108. {
  109. m_bannedHostNameMask = value;
  110. }
  111. }
  112. public EstateBan() { }
  113. public Dictionary<string, object> ToMap()
  114. {
  115. Dictionary<string, object> map = new Dictionary<string, object>();
  116. PropertyInfo[] properties = this.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance);
  117. foreach (PropertyInfo p in properties)
  118. map[p.Name] = p.GetValue(this, null);
  119. return map;
  120. }
  121. public EstateBan(Dictionary<string, object> map)
  122. {
  123. foreach (KeyValuePair<string, object> kvp in map)
  124. {
  125. PropertyInfo p = this.GetType().GetProperty(kvp.Key, BindingFlags.Public | BindingFlags.Instance);
  126. if (p == null)
  127. continue;
  128. object value = p.GetValue(this, null);
  129. if (value is String)
  130. p.SetValue(this, map[p.Name], null);
  131. else if (value is Int32)
  132. p.SetValue(this, Int32.Parse((string)map[p.Name]), null);
  133. else if (value is UInt32)
  134. p.SetValue(this, UInt32.Parse((string)map[p.Name]), null);
  135. else if (value is Boolean)
  136. p.SetValue(this, Boolean.Parse((string)map[p.Name]), null);
  137. else if (value is UUID)
  138. p.SetValue(this, UUID.Parse((string)map[p.Name]), null);
  139. }
  140. }
  141. /// <summary>
  142. /// For debugging
  143. /// </summary>
  144. /// <returns></returns>
  145. public override string ToString()
  146. {
  147. Dictionary<string, object> map = ToMap();
  148. string result = string.Empty;
  149. foreach (KeyValuePair<string, object> kvp in map)
  150. result += string.Format("{0}: {1} {2}", kvp.Key, kvp.Value, Environment.NewLine);
  151. return result;
  152. }
  153. }
  154. }