MockRegionDataPlugin.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375
  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 void StoreTerrain(TerrainData terrain, UUID regionID)
  64. {
  65. m_store.StoreTerrain(terrain, regionID);
  66. }
  67. public void StoreBakedTerrain(TerrainData terrain, UUID regionID)
  68. {
  69. m_store.StoreBakedTerrain(terrain, regionID);
  70. }
  71. public double[,] LoadTerrain(UUID regionID)
  72. {
  73. return m_store.LoadTerrain(regionID);
  74. }
  75. public TerrainData LoadTerrain(UUID regionID, int pSizeX, int pSizeY, int pSizeZ)
  76. {
  77. return m_store.LoadTerrain(regionID, pSizeX, pSizeY, pSizeZ);
  78. }
  79. public TerrainData LoadBakedTerrain(UUID regionID, int pSizeX, int pSizeY, int pSizeZ)
  80. {
  81. return m_store.LoadBakedTerrain(regionID, pSizeX, pSizeY, pSizeZ);
  82. }
  83. public void StoreLandObject(ILandObject Parcel)
  84. {
  85. m_store.StoreLandObject(Parcel);
  86. }
  87. public void RemoveLandObject(UUID globalID)
  88. {
  89. m_store.RemoveLandObject(globalID);
  90. }
  91. public List<LandData> LoadLandObjects(UUID regionUUID)
  92. {
  93. return m_store.LoadLandObjects(regionUUID);
  94. }
  95. public void StoreRegionSettings(RegionSettings rs)
  96. {
  97. m_store.StoreRegionSettings(rs);
  98. }
  99. public RegionSettings LoadRegionSettings(UUID regionUUID)
  100. {
  101. return m_store.LoadRegionSettings(regionUUID);
  102. }
  103. public string LoadRegionEnvironmentSettings(UUID regionUUID)
  104. {
  105. return m_store.LoadRegionEnvironmentSettings(regionUUID);
  106. }
  107. public void StoreRegionEnvironmentSettings(UUID regionUUID, string settings)
  108. {
  109. m_store.StoreRegionEnvironmentSettings(regionUUID, settings);
  110. }
  111. public void RemoveRegionEnvironmentSettings(UUID regionUUID)
  112. {
  113. m_store.RemoveRegionEnvironmentSettings(regionUUID);
  114. }
  115. public UUID[] GetObjectIDs(UUID regionID)
  116. {
  117. return new UUID[0];
  118. }
  119. public void SaveExtra(UUID regionID, string name, string value)
  120. {
  121. }
  122. public void RemoveExtra(UUID regionID, string name)
  123. {
  124. }
  125. public Dictionary<string, string> GetExtra(UUID regionID)
  126. {
  127. return null;
  128. }
  129. }
  130. /// <summary>
  131. /// Mock region data plugin. This obeys the api contract for persistence but stores everything in memory, so that
  132. /// tests can check correct persistence.
  133. /// </summary>
  134. public class NullDataStore : ISimulationDataStore
  135. {
  136. // private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  137. protected Dictionary<UUID, RegionSettings> m_regionSettings = new Dictionary<UUID, RegionSettings>();
  138. protected Dictionary<UUID, SceneObjectPart> m_sceneObjectParts = new Dictionary<UUID, SceneObjectPart>();
  139. protected Dictionary<UUID, ICollection<TaskInventoryItem>> m_primItems
  140. = new Dictionary<UUID, ICollection<TaskInventoryItem>>();
  141. protected Dictionary<UUID, TerrainData> m_terrains = new Dictionary<UUID, TerrainData>();
  142. protected Dictionary<UUID, TerrainData> m_bakedterrains = new Dictionary<UUID, TerrainData>();
  143. protected Dictionary<UUID, LandData> m_landData = new Dictionary<UUID, LandData>();
  144. public void Initialise(string dbfile)
  145. {
  146. return;
  147. }
  148. public void Dispose()
  149. {
  150. }
  151. public void StoreRegionSettings(RegionSettings rs)
  152. {
  153. m_regionSettings[rs.RegionUUID] = rs;
  154. }
  155. #region Environment Settings
  156. public string LoadRegionEnvironmentSettings(UUID regionUUID)
  157. {
  158. //This connector doesn't support the Environment module yet
  159. return string.Empty;
  160. }
  161. public void StoreRegionEnvironmentSettings(UUID regionUUID, string settings)
  162. {
  163. //This connector doesn't support the Environment module yet
  164. }
  165. public void RemoveRegionEnvironmentSettings(UUID regionUUID)
  166. {
  167. //This connector doesn't support the Environment module yet
  168. }
  169. #endregion
  170. public RegionSettings LoadRegionSettings(UUID regionUUID)
  171. {
  172. RegionSettings rs = null;
  173. m_regionSettings.TryGetValue(regionUUID, out rs);
  174. if (rs == null)
  175. rs = new RegionSettings();
  176. return rs;
  177. }
  178. public void StoreObject(SceneObjectGroup obj, UUID regionUUID)
  179. {
  180. // We can't simply store groups here because on delinking, OpenSim will not update the original group
  181. // directly. Rather, the newly delinked parts will be updated to be in their own scene object group
  182. // Therefore, we need to store parts rather than groups.
  183. foreach (SceneObjectPart prim in obj.Parts)
  184. {
  185. // m_log.DebugFormat(
  186. // "[MOCK REGION DATA PLUGIN]: Storing part {0} {1} in object {2} {3} in region {4}",
  187. // prim.Name, prim.UUID, obj.Name, obj.UUID, regionUUID);
  188. m_sceneObjectParts[prim.UUID] = prim;
  189. }
  190. }
  191. public void RemoveObject(UUID obj, UUID regionUUID)
  192. {
  193. // All parts belonging to the object with the uuid are removed.
  194. List<SceneObjectPart> parts = new List<SceneObjectPart>(m_sceneObjectParts.Values);
  195. foreach (SceneObjectPart part in parts)
  196. {
  197. if (part.ParentGroup.UUID == obj)
  198. {
  199. // m_log.DebugFormat(
  200. // "[MOCK REGION DATA PLUGIN]: Removing part {0} {1} as part of object {2} from {3}",
  201. // part.Name, part.UUID, obj, regionUUID);
  202. m_sceneObjectParts.Remove(part.UUID);
  203. }
  204. }
  205. }
  206. public void StorePrimInventory(UUID primID, ICollection<TaskInventoryItem> items)
  207. {
  208. m_primItems[primID] = items;
  209. }
  210. public List<SceneObjectGroup> LoadObjects(UUID regionUUID)
  211. {
  212. Dictionary<UUID, SceneObjectGroup> objects = new Dictionary<UUID, SceneObjectGroup>();
  213. // Create all of the SOGs from the root prims first
  214. foreach (SceneObjectPart prim in m_sceneObjectParts.Values)
  215. {
  216. if (prim.IsRoot)
  217. {
  218. // m_log.DebugFormat(
  219. // "[MOCK REGION DATA PLUGIN]: Loading root part {0} {1} in {2}", prim.Name, prim.UUID, regionUUID);
  220. objects[prim.UUID] = new SceneObjectGroup(prim);
  221. }
  222. }
  223. // Add all of the children objects to the SOGs
  224. foreach (SceneObjectPart prim in m_sceneObjectParts.Values)
  225. {
  226. SceneObjectGroup sog;
  227. if (prim.UUID != prim.ParentUUID)
  228. {
  229. if (objects.TryGetValue(prim.ParentUUID, out sog))
  230. {
  231. int originalLinkNum = prim.LinkNum;
  232. sog.AddPart(prim);
  233. // SceneObjectGroup.AddPart() tries to be smart and automatically set the LinkNum.
  234. // We override that here
  235. if (originalLinkNum != 0)
  236. prim.LinkNum = originalLinkNum;
  237. }
  238. else
  239. {
  240. // m_log.WarnFormat(
  241. // "[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.",
  242. // prim.Name, prim.UUID, regionUUID, prim.ParentUUID);
  243. }
  244. }
  245. }
  246. // TODO: Load items. This is assymetric - we store items as a separate method but don't retrieve them that
  247. // way!
  248. return new List<SceneObjectGroup>(objects.Values);
  249. }
  250. public void StoreTerrain(TerrainData ter, UUID regionID)
  251. {
  252. m_terrains[regionID] = ter;
  253. }
  254. public void StoreBakedTerrain(TerrainData ter, UUID regionID)
  255. {
  256. m_bakedterrains[regionID] = ter;
  257. }
  258. public void StoreTerrain(double[,] ter, UUID regionID)
  259. {
  260. m_terrains[regionID] = new TerrainData(ter);
  261. }
  262. public TerrainData LoadTerrain(UUID regionID, int pSizeX, int pSizeY, int pSizeZ)
  263. {
  264. if (m_terrains.ContainsKey(regionID))
  265. return m_terrains[regionID];
  266. else
  267. return null;
  268. }
  269. public TerrainData LoadBakedTerrain(UUID regionID, int pSizeX, int pSizeY, int pSizeZ)
  270. {
  271. if (m_bakedterrains.ContainsKey(regionID))
  272. return m_bakedterrains[regionID];
  273. else
  274. return null;
  275. }
  276. public double[,] LoadTerrain(UUID regionID)
  277. {
  278. if (m_terrains.ContainsKey(regionID))
  279. return m_terrains[regionID].GetDoubles();
  280. else
  281. return null;
  282. }
  283. public void RemoveLandObject(UUID globalID)
  284. {
  285. if (m_landData.ContainsKey(globalID))
  286. m_landData.Remove(globalID);
  287. }
  288. public void StoreLandObject(ILandObject land)
  289. {
  290. m_landData[land.LandData.GlobalID] = land.LandData;
  291. }
  292. public List<LandData> LoadLandObjects(UUID regionUUID)
  293. {
  294. return new List<LandData>(m_landData.Values);
  295. }
  296. public void Shutdown()
  297. {
  298. }
  299. public UUID[] GetObjectIDs(UUID regionID)
  300. {
  301. return new UUID[0];
  302. }
  303. public void SaveExtra(UUID regionID, string name, string value)
  304. {
  305. }
  306. public void RemoveExtra(UUID regionID, string name)
  307. {
  308. }
  309. public Dictionary<string, string> GetExtra(UUID regionID)
  310. {
  311. return null;
  312. }
  313. }
  314. }