NullRegionData.cs 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  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;
  29. using System.Collections.Generic;
  30. using OpenMetaverse;
  31. using OpenSim.Framework;
  32. using OpenSim.Data;
  33. using System.Reflection;
  34. using log4net;
  35. namespace OpenSim.Data.Null
  36. {
  37. public class NullRegionData : IRegionData
  38. {
  39. private static NullRegionData Instance = null;
  40. // private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  41. Dictionary<UUID, RegionData> m_regionData = new Dictionary<UUID, RegionData>();
  42. public NullRegionData(string connectionString, string realm)
  43. {
  44. if (Instance == null)
  45. Instance = this;
  46. //Console.WriteLine("[XXX] NullRegionData constructor");
  47. }
  48. public List<RegionData> Get(string regionName, UUID scopeID)
  49. {
  50. if (Instance != this)
  51. return Instance.Get(regionName, scopeID);
  52. List<RegionData> ret = new List<RegionData>();
  53. foreach (RegionData r in m_regionData.Values)
  54. {
  55. if (regionName.Contains("%"))
  56. {
  57. if (r.RegionName.Contains(regionName.Replace("%", "")))
  58. ret.Add(r);
  59. }
  60. else
  61. {
  62. if (r.RegionName == regionName)
  63. ret.Add(r);
  64. }
  65. }
  66. if (ret.Count > 0)
  67. return ret;
  68. return null;
  69. }
  70. public RegionData Get(int posX, int posY, UUID scopeID)
  71. {
  72. if (Instance != this)
  73. return Instance.Get(posX, posY, scopeID);
  74. List<RegionData> ret = new List<RegionData>();
  75. foreach (RegionData r in m_regionData.Values)
  76. {
  77. if (r.posX == posX && r.posY == posY)
  78. ret.Add(r);
  79. }
  80. if (ret.Count > 0)
  81. return ret[0];
  82. return null;
  83. }
  84. public RegionData Get(UUID regionID, UUID scopeID)
  85. {
  86. if (Instance != this)
  87. return Instance.Get(regionID, scopeID);
  88. if (m_regionData.ContainsKey(regionID))
  89. return m_regionData[regionID];
  90. return null;
  91. }
  92. public List<RegionData> Get(int startX, int startY, int endX, int endY, UUID scopeID)
  93. {
  94. if (Instance != this)
  95. return Instance.Get(startX, startY, endX, endY, scopeID);
  96. List<RegionData> ret = new List<RegionData>();
  97. foreach (RegionData r in m_regionData.Values)
  98. {
  99. if (r.posX >= startX && r.posX <= endX && r.posY >= startY && r.posY <= endY)
  100. ret.Add(r);
  101. }
  102. return ret;
  103. }
  104. public bool Store(RegionData data)
  105. {
  106. if (Instance != this)
  107. return Instance.Store(data);
  108. m_regionData[data.RegionID] = data;
  109. return true;
  110. }
  111. public bool SetDataItem(UUID regionID, string item, string value)
  112. {
  113. if (Instance != this)
  114. return Instance.SetDataItem(regionID, item, value);
  115. if (!m_regionData.ContainsKey(regionID))
  116. return false;
  117. m_regionData[regionID].Data[item] = value;
  118. return true;
  119. }
  120. public bool Delete(UUID regionID)
  121. {
  122. if (Instance != this)
  123. return Instance.Delete(regionID);
  124. if (!m_regionData.ContainsKey(regionID))
  125. return false;
  126. m_regionData.Remove(regionID);
  127. return true;
  128. }
  129. public List<RegionData> GetDefaultRegions(UUID scopeID)
  130. {
  131. if (Instance != this)
  132. return Instance.GetDefaultRegions(scopeID);
  133. List<RegionData> ret = new List<RegionData>();
  134. foreach (RegionData r in m_regionData.Values)
  135. {
  136. if ((Convert.ToInt32(r.Data["flags"]) & 1) != 0)
  137. ret.Add(r);
  138. }
  139. return ret;
  140. }
  141. public List<RegionData> GetFallbackRegions(UUID scopeID, int x, int y)
  142. {
  143. if (Instance != this)
  144. return Instance.GetFallbackRegions(scopeID, x, y);
  145. List<RegionData> ret = new List<RegionData>();
  146. foreach (RegionData r in m_regionData.Values)
  147. {
  148. if ((Convert.ToInt32(r.Data["flags"]) & 2) != 0)
  149. ret.Add(r);
  150. }
  151. return ret;
  152. }
  153. }
  154. }