MockRegionDataPlugin.cs 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  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. public class NullDataService : ISimulationDataService
  37. {
  38. private NullDataStore m_store;
  39. public NullDataService()
  40. {
  41. m_store = new NullDataStore();
  42. }
  43. public void StoreObject(SceneObjectGroup obj, UUID regionUUID)
  44. {
  45. m_store.StoreObject(obj, regionUUID);
  46. }
  47. public void RemoveObject(UUID uuid, UUID regionUUID)
  48. {
  49. m_store.RemoveObject(uuid, regionUUID);
  50. }
  51. public void StorePrimInventory(UUID primID, ICollection<TaskInventoryItem> items)
  52. {
  53. m_store.StorePrimInventory(primID, items);
  54. }
  55. public List<SceneObjectGroup> LoadObjects(UUID regionUUID)
  56. {
  57. return m_store.LoadObjects(regionUUID);
  58. }
  59. public void StoreTerrain(double[,] terrain, UUID regionID)
  60. {
  61. m_store.StoreTerrain(terrain, regionID);
  62. }
  63. public double[,] LoadTerrain(UUID regionID)
  64. {
  65. return m_store.LoadTerrain(regionID);
  66. }
  67. public void StoreLandObject(ILandObject Parcel)
  68. {
  69. m_store.StoreLandObject(Parcel);
  70. }
  71. public void RemoveLandObject(UUID globalID)
  72. {
  73. m_store.RemoveLandObject(globalID);
  74. }
  75. public List<LandData> LoadLandObjects(UUID regionUUID)
  76. {
  77. return m_store.LoadLandObjects(regionUUID);
  78. }
  79. public void StoreRegionSettings(RegionSettings rs)
  80. {
  81. m_store.StoreRegionSettings(rs);
  82. }
  83. public RegionSettings LoadRegionSettings(UUID regionUUID)
  84. {
  85. return m_store.LoadRegionSettings(regionUUID);
  86. }
  87. public RegionLightShareData LoadRegionWindlightSettings(UUID regionUUID)
  88. {
  89. return m_store.LoadRegionWindlightSettings(regionUUID);
  90. }
  91. public void RemoveRegionWindlightSettings(UUID regionID)
  92. {
  93. }
  94. public void StoreRegionWindlightSettings(RegionLightShareData wl)
  95. {
  96. m_store.StoreRegionWindlightSettings(wl);
  97. }
  98. }
  99. /// <summary>
  100. /// Mock region data plugin. This obeys the api contract for persistence but stores everything in memory, so that
  101. /// tests can check correct persistence.
  102. /// </summary>
  103. public class NullDataStore : ISimulationDataStore
  104. {
  105. private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  106. protected Dictionary<UUID, RegionSettings> m_regionSettings = new Dictionary<UUID, RegionSettings>();
  107. protected Dictionary<UUID, SceneObjectPart> m_sceneObjectParts = new Dictionary<UUID, SceneObjectPart>();
  108. protected Dictionary<UUID, ICollection<TaskInventoryItem>> m_primItems
  109. = new Dictionary<UUID, ICollection<TaskInventoryItem>>();
  110. protected Dictionary<UUID, double[,]> m_terrains = new Dictionary<UUID, double[,]>();
  111. protected Dictionary<UUID, LandData> m_landData = new Dictionary<UUID, LandData>();
  112. public void Initialise(string dbfile)
  113. {
  114. return;
  115. }
  116. public void Dispose()
  117. {
  118. }
  119. public void StoreRegionSettings(RegionSettings rs)
  120. {
  121. m_regionSettings[rs.RegionUUID] = rs;
  122. }
  123. public RegionLightShareData LoadRegionWindlightSettings(UUID regionUUID)
  124. {
  125. //This connector doesn't support the windlight module yet
  126. //Return default LL windlight settings
  127. return new RegionLightShareData();
  128. }
  129. public void RemoveRegionWindlightSettings(UUID regionID)
  130. {
  131. }
  132. public void StoreRegionWindlightSettings(RegionLightShareData wl)
  133. {
  134. //This connector doesn't support the windlight module yet
  135. }
  136. public RegionSettings LoadRegionSettings(UUID regionUUID)
  137. {
  138. RegionSettings rs = null;
  139. m_regionSettings.TryGetValue(regionUUID, out rs);
  140. if (rs == null)
  141. rs = new RegionSettings();
  142. return rs;
  143. }
  144. public void StoreObject(SceneObjectGroup obj, UUID regionUUID)
  145. {
  146. // We can't simply store groups here because on delinking, OpenSim will not update the original group
  147. // directly. Rather, the newly delinked parts will be updated to be in their own scene object group
  148. // Therefore, we need to store parts rather than groups.
  149. foreach (SceneObjectPart prim in obj.Parts)
  150. {
  151. m_log.DebugFormat(
  152. "[MOCK REGION DATA PLUGIN]: Storing part {0} {1} in object {2} {3} in region {4}",
  153. prim.Name, prim.UUID, obj.Name, obj.UUID, regionUUID);
  154. m_sceneObjectParts[prim.UUID] = prim;
  155. }
  156. }
  157. public void RemoveObject(UUID obj, UUID regionUUID)
  158. {
  159. // All parts belonging to the object with the uuid are removed.
  160. List<SceneObjectPart> parts = new List<SceneObjectPart>(m_sceneObjectParts.Values);
  161. foreach (SceneObjectPart part in parts)
  162. {
  163. if (part.ParentGroup.UUID == obj)
  164. {
  165. m_log.DebugFormat(
  166. "[MOCK REGION DATA PLUGIN]: Removing part {0} {1} as part of object {2} from {3}",
  167. part.Name, part.UUID, obj, regionUUID);
  168. m_sceneObjectParts.Remove(part.UUID);
  169. }
  170. }
  171. }
  172. public void StorePrimInventory(UUID primID, ICollection<TaskInventoryItem> items)
  173. {
  174. m_primItems[primID] = items;
  175. }
  176. public List<SceneObjectGroup> LoadObjects(UUID regionUUID)
  177. {
  178. Dictionary<UUID, SceneObjectGroup> objects = new Dictionary<UUID, SceneObjectGroup>();
  179. // Create all of the SOGs from the root prims first
  180. foreach (SceneObjectPart prim in m_sceneObjectParts.Values)
  181. {
  182. if (prim.IsRoot)
  183. {
  184. m_log.DebugFormat(
  185. "[MOCK REGION DATA PLUGIN]: Loading root part {0} {1} in {2}", prim.Name, prim.UUID, regionUUID);
  186. objects[prim.UUID] = new SceneObjectGroup(prim);
  187. }
  188. }
  189. // Add all of the children objects to the SOGs
  190. foreach (SceneObjectPart prim in m_sceneObjectParts.Values)
  191. {
  192. SceneObjectGroup sog;
  193. if (prim.UUID != prim.ParentUUID)
  194. {
  195. if (objects.TryGetValue(prim.ParentUUID, out sog))
  196. {
  197. int originalLinkNum = prim.LinkNum;
  198. sog.AddPart(prim);
  199. // SceneObjectGroup.AddPart() tries to be smart and automatically set the LinkNum.
  200. // We override that here
  201. if (originalLinkNum != 0)
  202. prim.LinkNum = originalLinkNum;
  203. }
  204. else
  205. {
  206. m_log.WarnFormat(
  207. "[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.",
  208. prim.Name, prim.UUID, regionUUID, prim.ParentUUID);
  209. }
  210. }
  211. }
  212. // TODO: Load items. This is assymetric - we store items as a separate method but don't retrieve them that
  213. // way!
  214. return new List<SceneObjectGroup>(objects.Values);
  215. }
  216. public void StoreTerrain(double[,] ter, UUID regionID)
  217. {
  218. m_terrains[regionID] = ter;
  219. }
  220. public double[,] LoadTerrain(UUID regionID)
  221. {
  222. if (m_terrains.ContainsKey(regionID))
  223. return m_terrains[regionID];
  224. else
  225. return null;
  226. }
  227. public void RemoveLandObject(UUID globalID)
  228. {
  229. if (m_landData.ContainsKey(globalID))
  230. m_landData.Remove(globalID);
  231. }
  232. public void StoreLandObject(ILandObject land)
  233. {
  234. m_landData[land.LandData.GlobalID] = land.LandData;
  235. }
  236. public List<LandData> LoadLandObjects(UUID regionUUID)
  237. {
  238. return new List<LandData>(m_landData.Values);
  239. }
  240. public void Shutdown()
  241. {
  242. }
  243. }
  244. }