1
0

NullRegionData.cs 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  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. string cleanname = regionName.Replace("%", "");
  58. m_log.DebugFormat("[NULL REGION DATA]: comparing {0} to {1}", cleanname.ToLower(), r.RegionName.ToLower());
  59. if (r.RegionName.ToLower().Contains(cleanname.ToLower()))
  60. ret.Add(r);
  61. }
  62. else
  63. {
  64. if (r.RegionName.ToLower() == regionName.ToLower())
  65. ret.Add(r);
  66. }
  67. }
  68. if (ret.Count > 0)
  69. return ret;
  70. return null;
  71. }
  72. public RegionData Get(int posX, int posY, UUID scopeID)
  73. {
  74. if (Instance != this)
  75. return Instance.Get(posX, posY, scopeID);
  76. List<RegionData> ret = new List<RegionData>();
  77. foreach (RegionData r in m_regionData.Values)
  78. {
  79. if (r.posX == posX && r.posY == posY)
  80. ret.Add(r);
  81. }
  82. if (ret.Count > 0)
  83. return ret[0];
  84. return null;
  85. }
  86. public RegionData Get(UUID regionID, UUID scopeID)
  87. {
  88. if (Instance != this)
  89. return Instance.Get(regionID, scopeID);
  90. if (m_regionData.ContainsKey(regionID))
  91. return m_regionData[regionID];
  92. return null;
  93. }
  94. public List<RegionData> Get(int startX, int startY, int endX, int endY, UUID scopeID)
  95. {
  96. if (Instance != this)
  97. return Instance.Get(startX, startY, endX, endY, scopeID);
  98. List<RegionData> ret = new List<RegionData>();
  99. foreach (RegionData r in m_regionData.Values)
  100. {
  101. if (r.posX >= startX && r.posX <= endX && r.posY >= startY && r.posY <= endY)
  102. ret.Add(r);
  103. }
  104. return ret;
  105. }
  106. public bool Store(RegionData data)
  107. {
  108. if (Instance != this)
  109. return Instance.Store(data);
  110. m_regionData[data.RegionID] = data;
  111. return true;
  112. }
  113. public bool SetDataItem(UUID regionID, string item, string value)
  114. {
  115. if (Instance != this)
  116. return Instance.SetDataItem(regionID, item, value);
  117. if (!m_regionData.ContainsKey(regionID))
  118. return false;
  119. m_regionData[regionID].Data[item] = value;
  120. return true;
  121. }
  122. public bool Delete(UUID regionID)
  123. {
  124. if (Instance != this)
  125. return Instance.Delete(regionID);
  126. if (!m_regionData.ContainsKey(regionID))
  127. return false;
  128. m_regionData.Remove(regionID);
  129. return true;
  130. }
  131. public List<RegionData> GetDefaultRegions(UUID scopeID)
  132. {
  133. return Get((int)RegionFlags.DefaultRegion, scopeID);
  134. }
  135. public List<RegionData> GetFallbackRegions(UUID scopeID, int x, int y)
  136. {
  137. List<RegionData> regions = Get((int)RegionFlags.FallbackRegion, scopeID);
  138. RegionDataDistanceCompare distanceComparer = new RegionDataDistanceCompare(x, y);
  139. regions.Sort(distanceComparer);
  140. return regions;
  141. }
  142. public List<RegionData> GetHyperlinks(UUID scopeID)
  143. {
  144. return Get((int)RegionFlags.Hyperlink, scopeID);
  145. }
  146. private List<RegionData> Get(int regionFlags, UUID scopeID)
  147. {
  148. if (Instance != this)
  149. return Instance.Get(regionFlags, scopeID);
  150. List<RegionData> ret = new List<RegionData>();
  151. foreach (RegionData r in m_regionData.Values)
  152. {
  153. if ((Convert.ToInt32(r.Data["flags"]) & regionFlags) != 0)
  154. ret.Add(r);
  155. }
  156. return ret;
  157. }
  158. }
  159. }