1
0

MockRegionDataPlugin.cs 12 KB

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