MockRegionDataPlugin.cs 14 KB

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