MockRegionDataPlugin.cs 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  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.Reflection;
  28. using System.Collections.Generic;
  29. using log4net;
  30. using OpenMetaverse;
  31. using OpenSim.Framework;
  32. using OpenSim.Region.Framework.Interfaces;
  33. using OpenSim.Region.Framework.Scenes;
  34. namespace OpenSim.Data.Null
  35. {
  36. /// <summary>
  37. /// Mock region data plugin. This obeys the api contract for persistence but stores everything in memory, so that
  38. /// tests can check correct persistence.
  39. /// </summary>
  40. public class NullDataStore : IRegionDataStore
  41. {
  42. private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  43. protected Dictionary<UUID, RegionSettings> m_regionSettings = new Dictionary<UUID, RegionSettings>();
  44. protected Dictionary<UUID, SceneObjectPart> m_sceneObjectParts = new Dictionary<UUID, SceneObjectPart>();
  45. protected Dictionary<UUID, ICollection<TaskInventoryItem>> m_primItems
  46. = new Dictionary<UUID, ICollection<TaskInventoryItem>>();
  47. protected Dictionary<UUID, double[,]> m_terrains = new Dictionary<UUID, double[,]>();
  48. protected Dictionary<UUID, LandData> m_landData = new Dictionary<UUID, LandData>();
  49. public void Initialise(string dbfile)
  50. {
  51. return;
  52. }
  53. public void Dispose()
  54. {
  55. }
  56. public void StoreRegionSettings(RegionSettings rs)
  57. {
  58. m_regionSettings[rs.RegionUUID] = rs;
  59. }
  60. public RegionLightShareData LoadRegionWindlightSettings(UUID regionUUID)
  61. {
  62. //This connector doesn't support the windlight module yet
  63. //Return default LL windlight settings
  64. return new RegionLightShareData();
  65. }
  66. public void StoreRegionWindlightSettings(RegionLightShareData wl)
  67. {
  68. //This connector doesn't support the windlight module yet
  69. }
  70. public RegionSettings LoadRegionSettings(UUID regionUUID)
  71. {
  72. RegionSettings rs = null;
  73. m_regionSettings.TryGetValue(regionUUID, out rs);
  74. return rs;
  75. }
  76. public void StoreObject(SceneObjectGroup obj, UUID regionUUID)
  77. {
  78. // We can't simply store groups here because on delinking, OpenSim will not update the original group
  79. // directly. Rather, the newly delinked parts will be updated to be in their own scene object group
  80. // Therefore, we need to store parts rather than groups.
  81. foreach (SceneObjectPart prim in obj.Children.Values)
  82. {
  83. m_log.DebugFormat(
  84. "[MOCK REGION DATA PLUGIN]: Storing part {0} {1} in object {2} {3} in region {4}",
  85. prim.Name, prim.UUID, obj.Name, obj.UUID, regionUUID);
  86. m_sceneObjectParts[prim.UUID] = prim;
  87. }
  88. }
  89. public void RemoveObject(UUID obj, UUID regionUUID)
  90. {
  91. // All parts belonging to the object with the uuid are removed.
  92. List<SceneObjectPart> parts = new List<SceneObjectPart>(m_sceneObjectParts.Values);
  93. foreach (SceneObjectPart part in parts)
  94. {
  95. if (part.ParentGroup.UUID == obj)
  96. {
  97. m_log.DebugFormat(
  98. "[MOCK REGION DATA PLUGIN]: Removing part {0} {1} as part of object {2} from {3}",
  99. part.Name, part.UUID, obj, regionUUID);
  100. m_sceneObjectParts.Remove(part.UUID);
  101. }
  102. }
  103. }
  104. // see IRegionDatastore
  105. public void StorePrimInventory(UUID primID, ICollection<TaskInventoryItem> items)
  106. {
  107. m_primItems[primID] = items;
  108. }
  109. public List<SceneObjectGroup> LoadObjects(UUID regionUUID)
  110. {
  111. Dictionary<UUID, SceneObjectGroup> objects = new Dictionary<UUID, SceneObjectGroup>();
  112. // Create all of the SOGs from the root prims first
  113. foreach (SceneObjectPart prim in m_sceneObjectParts.Values)
  114. {
  115. if (prim.IsRoot)
  116. {
  117. m_log.DebugFormat(
  118. "[MOCK REGION DATA PLUGIN]: Loading root part {0} {1} in {2}", prim.Name, prim.UUID, regionUUID);
  119. objects[prim.UUID] = new SceneObjectGroup(prim);
  120. }
  121. }
  122. // Add all of the children objects to the SOGs
  123. foreach (SceneObjectPart prim in m_sceneObjectParts.Values)
  124. {
  125. SceneObjectGroup sog;
  126. if (prim.UUID != prim.ParentUUID)
  127. {
  128. if (objects.TryGetValue(prim.ParentUUID, out sog))
  129. {
  130. int originalLinkNum = prim.LinkNum;
  131. sog.AddPart(prim);
  132. // SceneObjectGroup.AddPart() tries to be smart and automatically set the LinkNum.
  133. // We override that here
  134. if (originalLinkNum != 0)
  135. prim.LinkNum = originalLinkNum;
  136. }
  137. else
  138. {
  139. m_log.WarnFormat(
  140. "[MOCK REGION DATA PLUGIN]: Database contains an orphan child prim {0} {1} in region {2} pointing to missing parent {3}. This prim will not be loaded.",
  141. prim.Name, prim.UUID, regionUUID, prim.ParentUUID);
  142. }
  143. }
  144. }
  145. // TODO: Load items. This is assymetric - we store items as a separate method but don't retrieve them that
  146. // way!
  147. return new List<SceneObjectGroup>(objects.Values);
  148. }
  149. public void StoreTerrain(double[,] ter, UUID regionID)
  150. {
  151. m_terrains[regionID] = ter;
  152. }
  153. public double[,] LoadTerrain(UUID regionID)
  154. {
  155. if (m_terrains.ContainsKey(regionID))
  156. return m_terrains[regionID];
  157. else
  158. return null;
  159. }
  160. public void RemoveLandObject(UUID globalID)
  161. {
  162. if (m_landData.ContainsKey(globalID))
  163. m_landData.Remove(globalID);
  164. }
  165. public void StoreLandObject(ILandObject land)
  166. {
  167. m_landData[land.LandData.GlobalID] = land.LandData;
  168. }
  169. public List<LandData> LoadLandObjects(UUID regionUUID)
  170. {
  171. return new List<LandData>(m_landData.Values);
  172. }
  173. public void Shutdown()
  174. {
  175. }
  176. }
  177. }