MockRegionDataPlugin.cs 13 KB

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