MSSQLLegacyRegionData.cs 81 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531
  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;
  28. using System.Collections.Generic;
  29. using System.Data;
  30. using System.Data.SqlClient;
  31. using System.Drawing;
  32. using System.IO;
  33. using System.Reflection;
  34. using log4net;
  35. using OpenMetaverse;
  36. using OpenSim.Framework;
  37. using OpenSim.Region.Framework.Interfaces;
  38. using OpenSim.Region.Framework.Scenes;
  39. namespace OpenSim.Data.MSSQL
  40. {
  41. /// <summary>
  42. /// A MSSQL Interface for the Region Server.
  43. /// </summary>
  44. public class MSSQLRegionDataStore : IRegionDataStore
  45. {
  46. private const string _migrationStore = "RegionStore";
  47. // private static FileSystemDataStore Instance = new FileSystemDataStore();
  48. private static readonly ILog _Log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  49. /// <summary>
  50. /// The database manager
  51. /// </summary>
  52. private MSSQLManager _Database;
  53. /// <summary>
  54. /// Initialises the region datastore
  55. /// </summary>
  56. /// <param name="connectionString">The connection string.</param>
  57. public void Initialise(string connectionString)
  58. {
  59. if (!string.IsNullOrEmpty(connectionString))
  60. {
  61. _Database = new MSSQLManager(connectionString);
  62. }
  63. else
  64. {
  65. IniFile iniFile = new IniFile("mssql_connection.ini");
  66. string settingDataSource = iniFile.ParseFileReadValue("data_source");
  67. string settingInitialCatalog = iniFile.ParseFileReadValue("initial_catalog");
  68. string settingPersistSecurityInfo = iniFile.ParseFileReadValue("persist_security_info");
  69. string settingUserId = iniFile.ParseFileReadValue("user_id");
  70. string settingPassword = iniFile.ParseFileReadValue("password");
  71. _Database = new MSSQLManager(settingDataSource, settingInitialCatalog, settingPersistSecurityInfo, settingUserId, settingPassword);
  72. }
  73. //Migration settings
  74. _Database.CheckMigration(_migrationStore);
  75. }
  76. /// <summary>
  77. /// Dispose the database
  78. /// </summary>
  79. public void Dispose() { }
  80. #region SceneObjectGroup region for loading and Store of the scene.
  81. /// <summary>
  82. /// Loads the objects present in the region.
  83. /// </summary>
  84. /// <param name="regionUUID">The region UUID.</param>
  85. /// <returns></returns>
  86. public List<SceneObjectGroup> LoadObjects(UUID regionUUID)
  87. {
  88. UUID lastGroupID = UUID.Zero;
  89. Dictionary<UUID, SceneObjectPart> prims = new Dictionary<UUID, SceneObjectPart>();
  90. Dictionary<UUID, SceneObjectGroup> objects = new Dictionary<UUID, SceneObjectGroup>();
  91. SceneObjectGroup grp = null;
  92. string query = "SELECT *, " +
  93. "sort = CASE WHEN prims.UUID = prims.SceneGroupID THEN 0 ELSE 1 END " +
  94. "FROM prims " +
  95. "LEFT JOIN primshapes ON prims.UUID = primshapes.UUID " +
  96. "WHERE RegionUUID = @RegionUUID " +
  97. "ORDER BY SceneGroupID asc, sort asc, LinkNumber asc";
  98. using (AutoClosingSqlCommand command = _Database.Query(query))
  99. {
  100. command.Parameters.Add(_Database.CreateParameter("@regionUUID", regionUUID));
  101. using (SqlDataReader reader = command.ExecuteReader())
  102. {
  103. while (reader.Read())
  104. {
  105. SceneObjectPart sceneObjectPart = BuildPrim(reader);
  106. if (reader["Shape"] is DBNull)
  107. sceneObjectPart.Shape = PrimitiveBaseShape.Default;
  108. else
  109. sceneObjectPart.Shape = BuildShape(reader);
  110. prims[sceneObjectPart.UUID] = sceneObjectPart;
  111. UUID groupID = new UUID((Guid)reader["SceneGroupID"]);
  112. if (groupID != lastGroupID) // New SOG
  113. {
  114. if (grp != null)
  115. objects[grp.UUID] = grp;
  116. lastGroupID = groupID;
  117. // There sometimes exist OpenSim bugs that 'orphan groups' so that none of the prims are
  118. // recorded as the root prim (for which the UUID must equal the persisted group UUID). In
  119. // this case, force the UUID to be the same as the group UUID so that at least these can be
  120. // deleted (we need to change the UUID so that any other prims in the linkset can also be
  121. // deleted).
  122. if (sceneObjectPart.UUID != groupID && groupID != UUID.Zero)
  123. {
  124. _Log.WarnFormat(
  125. "[REGION DB]: Found root prim {0} {1} at {2} where group was actually {3}. Forcing UUID to group UUID",
  126. sceneObjectPart.Name, sceneObjectPart.UUID, sceneObjectPart.GroupPosition, groupID);
  127. sceneObjectPart.UUID = groupID;
  128. }
  129. grp = new SceneObjectGroup(sceneObjectPart);
  130. }
  131. else
  132. {
  133. // Black magic to preserve link numbers
  134. // Why is this needed, fix this in AddPart method.
  135. int link = sceneObjectPart.LinkNum;
  136. grp.AddPart(sceneObjectPart);
  137. if (link != 0)
  138. sceneObjectPart.LinkNum = link;
  139. }
  140. }
  141. }
  142. }
  143. if (grp != null)
  144. objects[grp.UUID] = grp;
  145. // Instead of attempting to LoadItems on every prim,
  146. // most of which probably have no items... get a
  147. // list from DB of all prims which have items and
  148. // LoadItems only on those
  149. List<SceneObjectPart> primsWithInventory = new List<SceneObjectPart>();
  150. string qry = "select distinct primID from primitems";
  151. using (AutoClosingSqlCommand command = _Database.Query(qry))
  152. {
  153. using (SqlDataReader itemReader = command.ExecuteReader())
  154. {
  155. while (itemReader.Read())
  156. {
  157. if (!(itemReader["primID"] is DBNull))
  158. {
  159. UUID primID = new UUID(itemReader["primID"].ToString());
  160. if (prims.ContainsKey(primID))
  161. {
  162. primsWithInventory.Add(prims[primID]);
  163. }
  164. }
  165. }
  166. }
  167. }
  168. LoadItems(primsWithInventory);
  169. _Log.DebugFormat("[REGION DB]: Loaded {0} objects using {1} prims", objects.Count, prims.Count);
  170. return new List<SceneObjectGroup>(objects.Values);
  171. }
  172. /// <summary>
  173. /// Load in the prim's persisted inventory.
  174. /// </summary>
  175. /// <param name="allPrims">all prims with inventory on a region</param>
  176. private void LoadItems(List<SceneObjectPart> allPrimsWithInventory)
  177. {
  178. using (AutoClosingSqlCommand command = _Database.Query("SELECT * FROM primitems WHERE PrimID = @PrimID"))
  179. {
  180. foreach (SceneObjectPart objectPart in allPrimsWithInventory)
  181. {
  182. command.Parameters.Clear();
  183. command.Parameters.Add(_Database.CreateParameter("@PrimID", objectPart.UUID));
  184. List<TaskInventoryItem> inventory = new List<TaskInventoryItem>();
  185. using (SqlDataReader reader = command.ExecuteReader())
  186. {
  187. while (reader.Read())
  188. {
  189. TaskInventoryItem item = BuildItem(reader);
  190. item.ParentID = objectPart.UUID; // Values in database are
  191. // often wrong
  192. inventory.Add(item);
  193. }
  194. }
  195. objectPart.Inventory.RestoreInventoryItems(inventory);
  196. }
  197. }
  198. }
  199. /// <summary>
  200. /// Stores all object's details apart from inventory
  201. /// </summary>
  202. /// <param name="obj"></param>
  203. /// <param name="regionUUID"></param>
  204. public void StoreObject(SceneObjectGroup obj, UUID regionUUID)
  205. {
  206. _Log.InfoFormat("[MSSQL]: Adding/Changing SceneObjectGroup: {0} to region: {1}, object has {2} prims.", obj.UUID, regionUUID, obj.Children.Count);
  207. using (SqlConnection conn = _Database.DatabaseConnection())
  208. {
  209. SqlTransaction transaction = conn.BeginTransaction();
  210. try
  211. {
  212. foreach (SceneObjectPart sceneObjectPart in obj.Children.Values)
  213. {
  214. //Update prim
  215. using (SqlCommand sqlCommand = conn.CreateCommand())
  216. {
  217. sqlCommand.Transaction = transaction;
  218. try
  219. {
  220. StoreSceneObjectPrim(sceneObjectPart, sqlCommand, obj.UUID, regionUUID);
  221. }
  222. catch (SqlException sqlEx)
  223. {
  224. _Log.ErrorFormat("[REGION DB]: Store SceneObjectPrim SQL error: {0} at line {1}", sqlEx.Message, sqlEx.LineNumber);
  225. throw;
  226. }
  227. }
  228. //Update primshapes
  229. using (SqlCommand sqlCommand = conn.CreateCommand())
  230. {
  231. sqlCommand.Transaction = transaction;
  232. try
  233. {
  234. StoreSceneObjectPrimShapes(sceneObjectPart, sqlCommand, obj.UUID, regionUUID);
  235. }
  236. catch (SqlException sqlEx)
  237. {
  238. _Log.ErrorFormat("[REGION DB]: Store SceneObjectPrimShapes SQL error: {0} at line {1}", sqlEx.Message, sqlEx.LineNumber);
  239. throw;
  240. }
  241. }
  242. }
  243. transaction.Commit();
  244. }
  245. catch (Exception ex)
  246. {
  247. _Log.ErrorFormat("[REGION DB]: Store SceneObjectGroup error: {0}, Rolling back...", ex.Message);
  248. try
  249. {
  250. transaction.Rollback();
  251. }
  252. catch (Exception ex2)
  253. {
  254. //Show error
  255. _Log.InfoFormat("[REGION DB]: Rollback of SceneObjectGroup store transaction failed with error: {0}", ex2.Message);
  256. }
  257. }
  258. }
  259. }
  260. /// <summary>
  261. /// Stores the prim of the sceneobjectpart.
  262. /// </summary>
  263. /// <param name="sceneObjectPart">The sceneobjectpart or prim.</param>
  264. /// <param name="sqlCommand">The SQL command with the transaction.</param>
  265. /// <param name="sceneGroupID">The scenegroup UUID.</param>
  266. /// <param name="regionUUID">The region UUID.</param>
  267. private void StoreSceneObjectPrim(SceneObjectPart sceneObjectPart, SqlCommand sqlCommand, UUID sceneGroupID, UUID regionUUID)
  268. {
  269. //Big query to update or insert a new prim.
  270. //Note for SQL Server 2008 this could be simplified
  271. string queryPrims = @"
  272. IF EXISTS (SELECT UUID FROM prims WHERE UUID = @UUID)
  273. BEGIN
  274. UPDATE prims SET
  275. CreationDate = @CreationDate, Name = @Name, Text = @Text, Description = @Description, SitName = @SitName,
  276. TouchName = @TouchName, ObjectFlags = @ObjectFlags, OwnerMask = @OwnerMask, NextOwnerMask = @NextOwnerMask, GroupMask = @GroupMask,
  277. EveryoneMask = @EveryoneMask, BaseMask = @BaseMask, PositionX = @PositionX, PositionY = @PositionY, PositionZ = @PositionZ,
  278. GroupPositionX = @GroupPositionX, GroupPositionY = @GroupPositionY, GroupPositionZ = @GroupPositionZ, VelocityX = @VelocityX,
  279. VelocityY = @VelocityY, VelocityZ = @VelocityZ, AngularVelocityX = @AngularVelocityX, AngularVelocityY = @AngularVelocityY,
  280. AngularVelocityZ = @AngularVelocityZ, AccelerationX = @AccelerationX, AccelerationY = @AccelerationY,
  281. AccelerationZ = @AccelerationZ, RotationX = @RotationX, RotationY = @RotationY, RotationZ = @RotationZ, RotationW = @RotationW,
  282. SitTargetOffsetX = @SitTargetOffsetX, SitTargetOffsetY = @SitTargetOffsetY, SitTargetOffsetZ = @SitTargetOffsetZ,
  283. SitTargetOrientW = @SitTargetOrientW, SitTargetOrientX = @SitTargetOrientX, SitTargetOrientY = @SitTargetOrientY,
  284. SitTargetOrientZ = @SitTargetOrientZ, RegionUUID = @RegionUUID, CreatorID = @CreatorID, OwnerID = @OwnerID, GroupID = @GroupID,
  285. LastOwnerID = @LastOwnerID, SceneGroupID = @SceneGroupID, PayPrice = @PayPrice, PayButton1 = @PayButton1, PayButton2 = @PayButton2,
  286. PayButton3 = @PayButton3, PayButton4 = @PayButton4, LoopedSound = @LoopedSound, LoopedSoundGain = @LoopedSoundGain,
  287. TextureAnimation = @TextureAnimation, OmegaX = @OmegaX, OmegaY = @OmegaY, OmegaZ = @OmegaZ, CameraEyeOffsetX = @CameraEyeOffsetX,
  288. CameraEyeOffsetY = @CameraEyeOffsetY, CameraEyeOffsetZ = @CameraEyeOffsetZ, CameraAtOffsetX = @CameraAtOffsetX,
  289. CameraAtOffsetY = @CameraAtOffsetY, CameraAtOffsetZ = @CameraAtOffsetZ, ForceMouselook = @ForceMouselook,
  290. ScriptAccessPin = @ScriptAccessPin, AllowedDrop = @AllowedDrop, DieAtEdge = @DieAtEdge, SalePrice = @SalePrice,
  291. SaleType = @SaleType, ColorR = @ColorR, ColorG = @ColorG, ColorB = @ColorB, ColorA = @ColorA, ParticleSystem = @ParticleSystem,
  292. ClickAction = @ClickAction, Material = @Material, CollisionSound = @CollisionSound, CollisionSoundVolume = @CollisionSoundVolume, PassTouches = @PassTouches,
  293. LinkNumber = @LinkNumber
  294. WHERE UUID = @UUID
  295. END
  296. ELSE
  297. BEGIN
  298. INSERT INTO
  299. prims (
  300. UUID, CreationDate, Name, Text, Description, SitName, TouchName, ObjectFlags, OwnerMask, NextOwnerMask, GroupMask,
  301. EveryoneMask, BaseMask, PositionX, PositionY, PositionZ, GroupPositionX, GroupPositionY, GroupPositionZ, VelocityX,
  302. VelocityY, VelocityZ, AngularVelocityX, AngularVelocityY, AngularVelocityZ, AccelerationX, AccelerationY, AccelerationZ,
  303. RotationX, RotationY, RotationZ, RotationW, SitTargetOffsetX, SitTargetOffsetY, SitTargetOffsetZ, SitTargetOrientW,
  304. SitTargetOrientX, SitTargetOrientY, SitTargetOrientZ, RegionUUID, CreatorID, OwnerID, GroupID, LastOwnerID, SceneGroupID,
  305. PayPrice, PayButton1, PayButton2, PayButton3, PayButton4, LoopedSound, LoopedSoundGain, TextureAnimation, OmegaX,
  306. OmegaY, OmegaZ, CameraEyeOffsetX, CameraEyeOffsetY, CameraEyeOffsetZ, CameraAtOffsetX, CameraAtOffsetY, CameraAtOffsetZ,
  307. ForceMouselook, ScriptAccessPin, AllowedDrop, DieAtEdge, SalePrice, SaleType, ColorR, ColorG, ColorB, ColorA,
  308. ParticleSystem, ClickAction, Material, CollisionSound, CollisionSoundVolume, PassTouches, LinkNumber
  309. ) VALUES (
  310. @UUID, @CreationDate, @Name, @Text, @Description, @SitName, @TouchName, @ObjectFlags, @OwnerMask, @NextOwnerMask, @GroupMask,
  311. @EveryoneMask, @BaseMask, @PositionX, @PositionY, @PositionZ, @GroupPositionX, @GroupPositionY, @GroupPositionZ, @VelocityX,
  312. @VelocityY, @VelocityZ, @AngularVelocityX, @AngularVelocityY, @AngularVelocityZ, @AccelerationX, @AccelerationY, @AccelerationZ,
  313. @RotationX, @RotationY, @RotationZ, @RotationW, @SitTargetOffsetX, @SitTargetOffsetY, @SitTargetOffsetZ, @SitTargetOrientW,
  314. @SitTargetOrientX, @SitTargetOrientY, @SitTargetOrientZ, @RegionUUID, @CreatorID, @OwnerID, @GroupID, @LastOwnerID, @SceneGroupID,
  315. @PayPrice, @PayButton1, @PayButton2, @PayButton3, @PayButton4, @LoopedSound, @LoopedSoundGain, @TextureAnimation, @OmegaX,
  316. @OmegaY, @OmegaZ, @CameraEyeOffsetX, @CameraEyeOffsetY, @CameraEyeOffsetZ, @CameraAtOffsetX, @CameraAtOffsetY, @CameraAtOffsetZ,
  317. @ForceMouselook, @ScriptAccessPin, @AllowedDrop, @DieAtEdge, @SalePrice, @SaleType, @ColorR, @ColorG, @ColorB, @ColorA,
  318. @ParticleSystem, @ClickAction, @Material, @CollisionSound, @CollisionSoundVolume, @PassTouches, @LinkNumber
  319. )
  320. END";
  321. //Set commandtext.
  322. sqlCommand.CommandText = queryPrims;
  323. //Add parameters
  324. sqlCommand.Parameters.AddRange(CreatePrimParameters(sceneObjectPart, sceneGroupID, regionUUID));
  325. //Execute the query. If it fails then error is trapped in calling function
  326. sqlCommand.ExecuteNonQuery();
  327. }
  328. /// <summary>
  329. /// Stores the scene object prim shapes.
  330. /// </summary>
  331. /// <param name="sceneObjectPart">The sceneobjectpart containing prim shape.</param>
  332. /// <param name="sqlCommand">The SQL command with the transaction.</param>
  333. /// <param name="sceneGroupID">The scenegroup UUID.</param>
  334. /// <param name="regionUUID">The region UUID.</param>
  335. private void StoreSceneObjectPrimShapes(SceneObjectPart sceneObjectPart, SqlCommand sqlCommand, UUID sceneGroupID, UUID regionUUID)
  336. {
  337. //Big query to or insert or update primshapes
  338. //Note for SQL Server 2008 this can be simplified
  339. string queryPrimShapes = @"
  340. IF EXISTS (SELECT UUID FROM primshapes WHERE UUID = @UUID)
  341. BEGIN
  342. UPDATE primshapes SET
  343. Shape = @Shape, ScaleX = @ScaleX, ScaleY = @ScaleY, ScaleZ = @ScaleZ, PCode = @PCode, PathBegin = @PathBegin,
  344. PathEnd = @PathEnd, PathScaleX = @PathScaleX, PathScaleY = @PathScaleY, PathShearX = @PathShearX, PathShearY = @PathShearY,
  345. PathSkew = @PathSkew, PathCurve = @PathCurve, PathRadiusOffset = @PathRadiusOffset, PathRevolutions = @PathRevolutions,
  346. PathTaperX = @PathTaperX, PathTaperY = @PathTaperY, PathTwist = @PathTwist, PathTwistBegin = @PathTwistBegin,
  347. ProfileBegin = @ProfileBegin, ProfileEnd = @ProfileEnd, ProfileCurve = @ProfileCurve, ProfileHollow = @ProfileHollow,
  348. Texture = @Texture, ExtraParams = @ExtraParams, State = @State
  349. WHERE UUID = @UUID
  350. END
  351. ELSE
  352. BEGIN
  353. INSERT INTO
  354. primshapes (
  355. UUID, Shape, ScaleX, ScaleY, ScaleZ, PCode, PathBegin, PathEnd, PathScaleX, PathScaleY, PathShearX, PathShearY,
  356. PathSkew, PathCurve, PathRadiusOffset, PathRevolutions, PathTaperX, PathTaperY, PathTwist, PathTwistBegin, ProfileBegin,
  357. ProfileEnd, ProfileCurve, ProfileHollow, Texture, ExtraParams, State
  358. ) VALUES (
  359. @UUID, @Shape, @ScaleX, @ScaleY, @ScaleZ, @PCode, @PathBegin, @PathEnd, @PathScaleX, @PathScaleY, @PathShearX, @PathShearY,
  360. @PathSkew, @PathCurve, @PathRadiusOffset, @PathRevolutions, @PathTaperX, @PathTaperY, @PathTwist, @PathTwistBegin, @ProfileBegin,
  361. @ProfileEnd, @ProfileCurve, @ProfileHollow, @Texture, @ExtraParams, @State
  362. )
  363. END";
  364. //Set commandtext.
  365. sqlCommand.CommandText = queryPrimShapes;
  366. //Add parameters
  367. sqlCommand.Parameters.AddRange(CreatePrimShapeParameters(sceneObjectPart, sceneGroupID, regionUUID));
  368. //Execute the query. If it fails then error is trapped in calling function
  369. sqlCommand.ExecuteNonQuery();
  370. }
  371. /// <summary>
  372. /// Removes a object from the database.
  373. /// Meaning removing it from tables Prims, PrimShapes and PrimItems
  374. /// </summary>
  375. /// <param name="objectID">id of scenegroup</param>
  376. /// <param name="regionUUID">regionUUID (is this used anyway</param>
  377. public void RemoveObject(UUID objectID, UUID regionUUID)
  378. {
  379. _Log.InfoFormat("[MSSQL]: Removing obj: {0} from region: {1}", objectID, regionUUID);
  380. //Remove from prims and primsitem table
  381. string sqlPrims = "DELETE FROM PRIMS WHERE SceneGroupID = @objectID";
  382. string sqlPrimItems = "DELETE FROM PRIMITEMS WHERE primID in (SELECT UUID FROM PRIMS WHERE SceneGroupID = @objectID)";
  383. string sqlPrimShapes = "DELETE FROM PRIMSHAPES WHERE uuid in (SELECT UUID FROM PRIMS WHERE SceneGroupID = @objectID)";
  384. lock (_Database)
  385. {
  386. //Using the non transaction mode.
  387. using (AutoClosingSqlCommand cmd = _Database.Query(sqlPrimShapes))
  388. {
  389. cmd.Parameters.Add(_Database.CreateParameter("objectID", objectID));
  390. cmd.ExecuteNonQuery();
  391. cmd.CommandText = sqlPrimItems;
  392. cmd.ExecuteNonQuery();
  393. cmd.CommandText = sqlPrims;
  394. cmd.ExecuteNonQuery();
  395. }
  396. }
  397. }
  398. /// <summary>
  399. /// Store the inventory of a prim. Warning deletes everything first and then adds all again.
  400. /// </summary>
  401. /// <param name="primID"></param>
  402. /// <param name="items"></param>
  403. public void StorePrimInventory(UUID primID, ICollection<TaskInventoryItem> items)
  404. {
  405. //_Log.InfoFormat("[REGION DB: Persisting Prim Inventory with prim ID {0}", primID);
  406. //Statement from MySQL section!
  407. // For now, we're just going to crudely remove all the previous inventory items
  408. // no matter whether they have changed or not, and replace them with the current set.
  409. //Delete everything from PrimID
  410. //TODO add index on PrimID in DB, if not already exist
  411. using (AutoClosingSqlCommand cmd = _Database.Query("DELETE PRIMITEMS WHERE primID = @primID"))
  412. {
  413. cmd.Parameters.Add(_Database.CreateParameter("@primID", primID));
  414. cmd.ExecuteNonQuery();
  415. }
  416. string sql =
  417. @"INSERT INTO primitems (
  418. itemID,primID,assetID,parentFolderID,invType,assetType,name,description,creationDate,creatorID,ownerID,lastOwnerID,groupID,
  419. nextPermissions,currentPermissions,basePermissions,everyonePermissions,groupPermissions,flags)
  420. VALUES (@itemID,@primID,@assetID,@parentFolderID,@invType,@assetType,@name,@description,@creationDate,@creatorID,@ownerID,
  421. @lastOwnerID,@groupID,@nextPermissions,@currentPermissions,@basePermissions,@everyonePermissions,@groupPermissions,@flags)";
  422. using (AutoClosingSqlCommand cmd = _Database.Query(sql))
  423. {
  424. foreach (TaskInventoryItem taskItem in items)
  425. {
  426. cmd.Parameters.AddRange(CreatePrimInventoryParameters(taskItem));
  427. cmd.ExecuteNonQuery();
  428. cmd.Parameters.Clear();
  429. }
  430. }
  431. }
  432. #endregion
  433. /// <summary>
  434. /// Loads the terrain map.
  435. /// </summary>
  436. /// <param name="regionID">regionID.</param>
  437. /// <returns></returns>
  438. public double[,] LoadTerrain(UUID regionID)
  439. {
  440. double[,] terrain = new double[(int)Constants.RegionSize, (int)Constants.RegionSize];
  441. terrain.Initialize();
  442. string sql = "select top 1 RegionUUID, Revision, Heightfield from terrain where RegionUUID = @RegionUUID order by Revision desc";
  443. using (AutoClosingSqlCommand cmd = _Database.Query(sql))
  444. {
  445. // MySqlParameter param = new MySqlParameter();
  446. cmd.Parameters.Add(_Database.CreateParameter("@RegionUUID", regionID));
  447. using (SqlDataReader reader = cmd.ExecuteReader())
  448. {
  449. int rev;
  450. if (reader.Read())
  451. {
  452. MemoryStream str = new MemoryStream((byte[])reader["Heightfield"]);
  453. BinaryReader br = new BinaryReader(str);
  454. for (int x = 0; x < (int)Constants.RegionSize; x++)
  455. {
  456. for (int y = 0; y < (int)Constants.RegionSize; y++)
  457. {
  458. terrain[x, y] = br.ReadDouble();
  459. }
  460. }
  461. rev = (int)reader["Revision"];
  462. }
  463. else
  464. {
  465. _Log.Info("[REGION DB]: No terrain found for region");
  466. return null;
  467. }
  468. _Log.Info("[REGION DB]: Loaded terrain revision r" + rev);
  469. }
  470. }
  471. return terrain;
  472. }
  473. /// <summary>
  474. /// Stores the terrain map to DB.
  475. /// </summary>
  476. /// <param name="terrain">terrain map data.</param>
  477. /// <param name="regionID">regionID.</param>
  478. public void StoreTerrain(double[,] terrain, UUID regionID)
  479. {
  480. int revision = Util.UnixTimeSinceEpoch();
  481. //Delete old terrain map
  482. string sql = "delete from terrain where RegionUUID=@RegionUUID";
  483. using (AutoClosingSqlCommand cmd = _Database.Query(sql))
  484. {
  485. cmd.Parameters.Add(_Database.CreateParameter("@RegionUUID", regionID));
  486. cmd.ExecuteNonQuery();
  487. }
  488. sql = "insert into terrain(RegionUUID, Revision, Heightfield) values(@RegionUUID, @Revision, @Heightfield)";
  489. using (AutoClosingSqlCommand cmd = _Database.Query(sql))
  490. {
  491. cmd.Parameters.Add(_Database.CreateParameter("@RegionUUID", regionID));
  492. cmd.Parameters.Add(_Database.CreateParameter("@Revision", revision));
  493. cmd.Parameters.Add(_Database.CreateParameter("@Heightfield", serializeTerrain(terrain)));
  494. cmd.ExecuteNonQuery();
  495. }
  496. _Log.Info("[REGION DB]: Stored terrain revision r " + revision);
  497. }
  498. /// <summary>
  499. /// Loads all the land objects of a region.
  500. /// </summary>
  501. /// <param name="regionUUID">The region UUID.</param>
  502. /// <returns></returns>
  503. public List<LandData> LoadLandObjects(UUID regionUUID)
  504. {
  505. List<LandData> LandDataForRegion = new List<LandData>();
  506. string sql = "select * from land where RegionUUID = @RegionUUID";
  507. //Retrieve all land data from region
  508. using (AutoClosingSqlCommand cmdLandData = _Database.Query(sql))
  509. {
  510. cmdLandData.Parameters.Add(_Database.CreateParameter("@RegionUUID", regionUUID));
  511. using (SqlDataReader readerLandData = cmdLandData.ExecuteReader())
  512. {
  513. while (readerLandData.Read())
  514. {
  515. LandDataForRegion.Add(BuildLandData(readerLandData));
  516. }
  517. }
  518. }
  519. //Retrieve all accesslist data for all landdata
  520. foreach (LandData LandData in LandDataForRegion)
  521. {
  522. sql = "select * from landaccesslist where LandUUID = @LandUUID";
  523. using (AutoClosingSqlCommand cmdAccessList = _Database.Query(sql))
  524. {
  525. cmdAccessList.Parameters.Add(_Database.CreateParameter("@LandUUID", LandData.GlobalID));
  526. using (SqlDataReader readerAccessList = cmdAccessList.ExecuteReader())
  527. {
  528. while (readerAccessList.Read())
  529. {
  530. LandData.ParcelAccessList.Add(BuildLandAccessData(readerAccessList));
  531. }
  532. }
  533. }
  534. }
  535. //Return data
  536. return LandDataForRegion;
  537. }
  538. /// <summary>
  539. /// Stores land object with landaccess list.
  540. /// </summary>
  541. /// <param name="parcel">parcel data.</param>
  542. public void StoreLandObject(ILandObject parcel)
  543. {
  544. //As this is only one record in land table I just delete all and then add a new record.
  545. //As the delete landaccess is already in the mysql code
  546. //Delete old values
  547. RemoveLandObject(parcel.LandData.GlobalID);
  548. //Insert new values
  549. string sql = @"INSERT INTO [land]
  550. ([UUID],[RegionUUID],[LocalLandID],[Bitmap],[Name],[Description],[OwnerUUID],[IsGroupOwned],[Area],[AuctionID],[Category],[ClaimDate],[ClaimPrice],[GroupUUID],[SalePrice],[LandStatus],[LandFlags],[LandingType],[MediaAutoScale],[MediaTextureUUID],[MediaURL],[MusicURL],[PassHours],[PassPrice],[SnapshotUUID],[UserLocationX],[UserLocationY],[UserLocationZ],[UserLookAtX],[UserLookAtY],[UserLookAtZ],[AuthbuyerID],[OtherCleanTime],[Dwell])
  551. VALUES
  552. (@UUID,@RegionUUID,@LocalLandID,@Bitmap,@Name,@Description,@OwnerUUID,@IsGroupOwned,@Area,@AuctionID,@Category,@ClaimDate,@ClaimPrice,@GroupUUID,@SalePrice,@LandStatus,@LandFlags,@LandingType,@MediaAutoScale,@MediaTextureUUID,@MediaURL,@MusicURL,@PassHours,@PassPrice,@SnapshotUUID,@UserLocationX,@UserLocationY,@UserLocationZ,@UserLookAtX,@UserLookAtY,@UserLookAtZ,@AuthbuyerID,@OtherCleanTime,@Dwell)";
  553. using (AutoClosingSqlCommand cmd = _Database.Query(sql))
  554. {
  555. cmd.Parameters.AddRange(CreateLandParameters(parcel.LandData, parcel.RegionUUID));
  556. cmd.ExecuteNonQuery();
  557. }
  558. sql = "INSERT INTO [landaccesslist] ([LandUUID],[AccessUUID],[Flags]) VALUES (@LandUUID,@AccessUUID,@Flags)";
  559. using (AutoClosingSqlCommand cmd = _Database.Query(sql))
  560. {
  561. foreach (ParcelManager.ParcelAccessEntry parcelAccessEntry in parcel.LandData.ParcelAccessList)
  562. {
  563. cmd.Parameters.AddRange(CreateLandAccessParameters(parcelAccessEntry, parcel.RegionUUID));
  564. cmd.ExecuteNonQuery();
  565. cmd.Parameters.Clear();
  566. }
  567. }
  568. }
  569. /// <summary>
  570. /// Removes a land object from DB.
  571. /// </summary>
  572. /// <param name="globalID">UUID of landobject</param>
  573. public void RemoveLandObject(UUID globalID)
  574. {
  575. using (AutoClosingSqlCommand cmd = _Database.Query("delete from land where UUID=@UUID"))
  576. {
  577. cmd.Parameters.Add(_Database.CreateParameter("@UUID", globalID));
  578. cmd.ExecuteNonQuery();
  579. }
  580. using (AutoClosingSqlCommand cmd = _Database.Query("delete from landaccesslist where LandUUID=@UUID"))
  581. {
  582. cmd.Parameters.Add(_Database.CreateParameter("@UUID", globalID));
  583. cmd.ExecuteNonQuery();
  584. }
  585. }
  586. /// <summary>
  587. /// Loads the settings of a region.
  588. /// </summary>
  589. /// <param name="regionUUID">The region UUID.</param>
  590. /// <returns></returns>
  591. public RegionSettings LoadRegionSettings(UUID regionUUID)
  592. {
  593. string sql = "select * from regionsettings where regionUUID = @regionUUID";
  594. RegionSettings regionSettings;
  595. using (AutoClosingSqlCommand cmd = _Database.Query(sql))
  596. {
  597. cmd.Parameters.Add(_Database.CreateParameter("@regionUUID", regionUUID));
  598. using (SqlDataReader reader = cmd.ExecuteReader())
  599. {
  600. if (reader.Read())
  601. {
  602. regionSettings = BuildRegionSettings(reader);
  603. regionSettings.OnSave += StoreRegionSettings;
  604. return regionSettings;
  605. }
  606. }
  607. }
  608. //If comes here then there is now region setting for that region
  609. regionSettings = new RegionSettings();
  610. regionSettings.RegionUUID = regionUUID;
  611. regionSettings.OnSave += StoreRegionSettings;
  612. //Store new values
  613. StoreNewRegionSettings(regionSettings);
  614. return regionSettings;
  615. }
  616. /// <summary>
  617. /// Store region settings, need to check if the check is really necesary. If we can make something for creating new region.
  618. /// </summary>
  619. /// <param name="regionSettings">region settings.</param>
  620. public void StoreRegionSettings(RegionSettings regionSettings)
  621. {
  622. //Little check if regionUUID already exist in DB
  623. string regionUUID;
  624. using (AutoClosingSqlCommand cmd = _Database.Query("SELECT regionUUID FROM regionsettings WHERE regionUUID = @regionUUID"))
  625. {
  626. cmd.Parameters.Add(_Database.CreateParameter("@regionUUID", regionSettings.RegionUUID));
  627. regionUUID = cmd.ExecuteScalar().ToString();
  628. }
  629. if (string.IsNullOrEmpty(regionUUID))
  630. {
  631. StoreNewRegionSettings(regionSettings);
  632. }
  633. else
  634. {
  635. //This method only updates region settings!!! First call LoadRegionSettings to create new region settings in DB
  636. string sql =
  637. @"UPDATE [regionsettings] SET [block_terraform] = @block_terraform ,[block_fly] = @block_fly ,[allow_damage] = @allow_damage
  638. ,[restrict_pushing] = @restrict_pushing ,[allow_land_resell] = @allow_land_resell ,[allow_land_join_divide] = @allow_land_join_divide
  639. ,[block_show_in_search] = @block_show_in_search ,[agent_limit] = @agent_limit ,[object_bonus] = @object_bonus ,[maturity] = @maturity
  640. ,[disable_scripts] = @disable_scripts ,[disable_collisions] = @disable_collisions ,[disable_physics] = @disable_physics
  641. ,[terrain_texture_1] = @terrain_texture_1 ,[terrain_texture_2] = @terrain_texture_2 ,[terrain_texture_3] = @terrain_texture_3
  642. ,[terrain_texture_4] = @terrain_texture_4 ,[elevation_1_nw] = @elevation_1_nw ,[elevation_2_nw] = @elevation_2_nw
  643. ,[elevation_1_ne] = @elevation_1_ne ,[elevation_2_ne] = @elevation_2_ne ,[elevation_1_se] = @elevation_1_se ,[elevation_2_se] = @elevation_2_se
  644. ,[elevation_1_sw] = @elevation_1_sw ,[elevation_2_sw] = @elevation_2_sw ,[water_height] = @water_height ,[terrain_raise_limit] = @terrain_raise_limit
  645. ,[terrain_lower_limit] = @terrain_lower_limit ,[use_estate_sun] = @use_estate_sun ,[fixed_sun] = @fixed_sun ,[sun_position] = @sun_position
  646. ,[covenant] = @covenant , [sunvectorx] = @sunvectorx, [sunvectory] = @sunvectory, [sunvectorz] = @sunvectorz, [Sandbox] = @Sandbox, [loaded_creation_datetime] = @loaded_creation_datetime, [loaded_creation_id] = @loaded_creation_id
  647. WHERE [regionUUID] = @regionUUID";
  648. using (AutoClosingSqlCommand cmd = _Database.Query(sql))
  649. {
  650. cmd.Parameters.AddRange(CreateRegionSettingParameters(regionSettings));
  651. cmd.ExecuteNonQuery();
  652. }
  653. }
  654. }
  655. public void Shutdown()
  656. {
  657. //Not used??
  658. }
  659. #region Private Methods
  660. /// <summary>
  661. /// Serializes the terrain data for storage in DB.
  662. /// </summary>
  663. /// <param name="val">terrain data</param>
  664. /// <returns></returns>
  665. private static Array serializeTerrain(double[,] val)
  666. {
  667. MemoryStream str = new MemoryStream(((int)Constants.RegionSize * (int)Constants.RegionSize) * sizeof(double));
  668. BinaryWriter bw = new BinaryWriter(str);
  669. // TODO: COMPATIBILITY - Add byte-order conversions
  670. for (int x = 0; x < (int)Constants.RegionSize; x++)
  671. for (int y = 0; y < (int)Constants.RegionSize; y++)
  672. {
  673. double height = val[x, y];
  674. if (height == 0.0)
  675. height = double.Epsilon;
  676. bw.Write(height);
  677. }
  678. return str.ToArray();
  679. }
  680. /// <summary>
  681. /// Stores new regionsettings.
  682. /// </summary>
  683. /// <param name="regionSettings">The region settings.</param>
  684. private void StoreNewRegionSettings(RegionSettings regionSettings)
  685. {
  686. string sql = @"INSERT INTO [regionsettings]
  687. ([regionUUID],[block_terraform],[block_fly],[allow_damage],[restrict_pushing],[allow_land_resell],[allow_land_join_divide],
  688. [block_show_in_search],[agent_limit],[object_bonus],[maturity],[disable_scripts],[disable_collisions],[disable_physics],
  689. [terrain_texture_1],[terrain_texture_2],[terrain_texture_3],[terrain_texture_4],[elevation_1_nw],[elevation_2_nw],[elevation_1_ne],
  690. [elevation_2_ne],[elevation_1_se],[elevation_2_se],[elevation_1_sw],[elevation_2_sw],[water_height],[terrain_raise_limit],
  691. [terrain_lower_limit],[use_estate_sun],[fixed_sun],[sun_position],[covenant],[sunvectorx], [sunvectory], [sunvectorz],[Sandbox], [loaded_creation_datetime], [loaded_creation_id]
  692. )
  693. VALUES
  694. (@regionUUID,@block_terraform,@block_fly,@allow_damage,@restrict_pushing,@allow_land_resell,@allow_land_join_divide,
  695. @block_show_in_search,@agent_limit,@object_bonus,@maturity,@disable_scripts,@disable_collisions,@disable_physics,
  696. @terrain_texture_1,@terrain_texture_2,@terrain_texture_3,@terrain_texture_4,@elevation_1_nw,@elevation_2_nw,@elevation_1_ne,
  697. @elevation_2_ne,@elevation_1_se,@elevation_2_se,@elevation_1_sw,@elevation_2_sw,@water_height,@terrain_raise_limit,
  698. @terrain_lower_limit,@use_estate_sun,@fixed_sun,@sun_position,@covenant,@sunvectorx,@sunvectory, @sunvectorz, @Sandbox, @loaded_creation_datetime, @loaded_creation_id)";
  699. using (AutoClosingSqlCommand cmd = _Database.Query(sql))
  700. {
  701. cmd.Parameters.AddRange(CreateRegionSettingParameters(regionSettings));
  702. cmd.ExecuteNonQuery();
  703. }
  704. }
  705. #region Private DataRecord conversion methods
  706. /// <summary>
  707. /// Builds the region settings from a datarecod.
  708. /// </summary>
  709. /// <param name="row">datarecord with regionsettings.</param>
  710. /// <returns></returns>
  711. private static RegionSettings BuildRegionSettings(IDataRecord row)
  712. {
  713. //TODO change this is some more generic code so we doesnt have to change it every time a new field is added?
  714. RegionSettings newSettings = new RegionSettings();
  715. newSettings.RegionUUID = new UUID((Guid)row["regionUUID"]);
  716. newSettings.BlockTerraform = Convert.ToBoolean(row["block_terraform"]);
  717. newSettings.AllowDamage = Convert.ToBoolean(row["allow_damage"]);
  718. newSettings.BlockFly = Convert.ToBoolean(row["block_fly"]);
  719. newSettings.RestrictPushing = Convert.ToBoolean(row["restrict_pushing"]);
  720. newSettings.AllowLandResell = Convert.ToBoolean(row["allow_land_resell"]);
  721. newSettings.AllowLandJoinDivide = Convert.ToBoolean(row["allow_land_join_divide"]);
  722. newSettings.BlockShowInSearch = Convert.ToBoolean(row["block_show_in_search"]);
  723. newSettings.AgentLimit = Convert.ToInt32(row["agent_limit"]);
  724. newSettings.ObjectBonus = Convert.ToDouble(row["object_bonus"]);
  725. newSettings.Maturity = Convert.ToInt32(row["maturity"]);
  726. newSettings.DisableScripts = Convert.ToBoolean(row["disable_scripts"]);
  727. newSettings.DisableCollisions = Convert.ToBoolean(row["disable_collisions"]);
  728. newSettings.DisablePhysics = Convert.ToBoolean(row["disable_physics"]);
  729. newSettings.TerrainTexture1 = new UUID((Guid)row["terrain_texture_1"]);
  730. newSettings.TerrainTexture2 = new UUID((Guid)row["terrain_texture_2"]);
  731. newSettings.TerrainTexture3 = new UUID((Guid)row["terrain_texture_3"]);
  732. newSettings.TerrainTexture4 = new UUID((Guid)row["terrain_texture_4"]);
  733. newSettings.Elevation1NW = Convert.ToDouble(row["elevation_1_nw"]);
  734. newSettings.Elevation2NW = Convert.ToDouble(row["elevation_2_nw"]);
  735. newSettings.Elevation1NE = Convert.ToDouble(row["elevation_1_ne"]);
  736. newSettings.Elevation2NE = Convert.ToDouble(row["elevation_2_ne"]);
  737. newSettings.Elevation1SE = Convert.ToDouble(row["elevation_1_se"]);
  738. newSettings.Elevation2SE = Convert.ToDouble(row["elevation_2_se"]);
  739. newSettings.Elevation1SW = Convert.ToDouble(row["elevation_1_sw"]);
  740. newSettings.Elevation2SW = Convert.ToDouble(row["elevation_2_sw"]);
  741. newSettings.WaterHeight = Convert.ToDouble(row["water_height"]);
  742. newSettings.TerrainRaiseLimit = Convert.ToDouble(row["terrain_raise_limit"]);
  743. newSettings.TerrainLowerLimit = Convert.ToDouble(row["terrain_lower_limit"]);
  744. newSettings.UseEstateSun = Convert.ToBoolean(row["use_estate_sun"]);
  745. newSettings.Sandbox = Convert.ToBoolean(row["sandbox"]);
  746. newSettings.FixedSun = Convert.ToBoolean(row["fixed_sun"]);
  747. newSettings.SunPosition = Convert.ToDouble(row["sun_position"]);
  748. newSettings.SunVector = new Vector3(
  749. Convert.ToSingle(row["sunvectorx"]),
  750. Convert.ToSingle(row["sunvectory"]),
  751. Convert.ToSingle(row["sunvectorz"])
  752. );
  753. newSettings.Covenant = new UUID((Guid)row["covenant"]);
  754. newSettings.LoadedCreationDateTime = Convert.ToInt32(row["loaded_creation_datetime"]);
  755. if (row["loaded_creation_id"] is DBNull)
  756. newSettings.LoadedCreationID = "";
  757. else
  758. newSettings.LoadedCreationID = (String)row["loaded_creation_id"];
  759. return newSettings;
  760. }
  761. /// <summary>
  762. /// Builds the land data from a datarecord.
  763. /// </summary>
  764. /// <param name="row">datarecord with land data</param>
  765. /// <returns></returns>
  766. private static LandData BuildLandData(IDataRecord row)
  767. {
  768. LandData newData = new LandData();
  769. newData.GlobalID = new UUID((Guid)row["UUID"]);
  770. newData.LocalID = Convert.ToInt32(row["LocalLandID"]);
  771. // Bitmap is a byte[512]
  772. newData.Bitmap = (Byte[])row["Bitmap"];
  773. newData.Name = (string)row["Name"];
  774. newData.Description = (string)row["Description"];
  775. newData.OwnerID = new UUID((Guid)row["OwnerUUID"]);
  776. newData.IsGroupOwned = Convert.ToBoolean(row["IsGroupOwned"]);
  777. newData.Area = Convert.ToInt32(row["Area"]);
  778. newData.AuctionID = Convert.ToUInt32(row["AuctionID"]); //Unemplemented
  779. newData.Category = (ParcelCategory)Convert.ToInt32(row["Category"]);
  780. //Enum libsecondlife.Parcel.ParcelCategory
  781. newData.ClaimDate = Convert.ToInt32(row["ClaimDate"]);
  782. newData.ClaimPrice = Convert.ToInt32(row["ClaimPrice"]);
  783. newData.GroupID = new UUID((Guid)row["GroupUUID"]);
  784. newData.SalePrice = Convert.ToInt32(row["SalePrice"]);
  785. newData.Status = (ParcelStatus)Convert.ToInt32(row["LandStatus"]);
  786. //Enum. libsecondlife.Parcel.ParcelStatus
  787. newData.Flags = Convert.ToUInt32(row["LandFlags"]);
  788. newData.LandingType = Convert.ToByte(row["LandingType"]);
  789. newData.MediaAutoScale = Convert.ToByte(row["MediaAutoScale"]);
  790. newData.MediaID = new UUID((Guid)row["MediaTextureUUID"]);
  791. newData.MediaURL = (string)row["MediaURL"];
  792. newData.MusicURL = (string)row["MusicURL"];
  793. newData.PassHours = Convert.ToSingle(row["PassHours"]);
  794. newData.PassPrice = Convert.ToInt32(row["PassPrice"]);
  795. // UUID authedbuyer;
  796. // UUID snapshotID;
  797. //
  798. // if (UUID.TryParse((string)row["AuthBuyerID"], out authedbuyer))
  799. // newData.AuthBuyerID = authedbuyer;
  800. //
  801. // if (UUID.TryParse((string)row["SnapshotUUID"], out snapshotID))
  802. // newData.SnapshotID = snapshotID;
  803. newData.AuthBuyerID = new UUID((Guid) row["AuthBuyerID"]);
  804. newData.SnapshotID = new UUID((Guid)row["SnapshotUUID"]);
  805. newData.OtherCleanTime = Convert.ToInt32(row["OtherCleanTime"]);
  806. newData.Dwell = Convert.ToInt32(row["Dwell"]);
  807. try
  808. {
  809. newData.UserLocation =
  810. new Vector3(Convert.ToSingle(row["UserLocationX"]), Convert.ToSingle(row["UserLocationY"]),
  811. Convert.ToSingle(row["UserLocationZ"]));
  812. newData.UserLookAt =
  813. new Vector3(Convert.ToSingle(row["UserLookAtX"]), Convert.ToSingle(row["UserLookAtY"]),
  814. Convert.ToSingle(row["UserLookAtZ"]));
  815. }
  816. catch (InvalidCastException)
  817. {
  818. newData.UserLocation = Vector3.Zero;
  819. newData.UserLookAt = Vector3.Zero;
  820. _Log.ErrorFormat("[PARCEL]: unable to get parcel telehub settings for {1}", newData.Name);
  821. }
  822. newData.ParcelAccessList = new List<ParcelManager.ParcelAccessEntry>();
  823. return newData;
  824. }
  825. /// <summary>
  826. /// Builds the landaccess data from a data record.
  827. /// </summary>
  828. /// <param name="row">datarecord with landaccess data</param>
  829. /// <returns></returns>
  830. private static ParcelManager.ParcelAccessEntry BuildLandAccessData(IDataRecord row)
  831. {
  832. ParcelManager.ParcelAccessEntry entry = new ParcelManager.ParcelAccessEntry();
  833. entry.AgentID = new UUID((Guid)row["AccessUUID"]);
  834. entry.Flags = (AccessList)Convert.ToInt32(row["Flags"]);
  835. entry.Time = new DateTime();
  836. return entry;
  837. }
  838. /// <summary>
  839. /// Builds the prim from a datarecord.
  840. /// </summary>
  841. /// <param name="primRow">datarecord</param>
  842. /// <returns></returns>
  843. private static SceneObjectPart BuildPrim(IDataRecord primRow)
  844. {
  845. SceneObjectPart prim = new SceneObjectPart();
  846. prim.UUID = new UUID((Guid)primRow["UUID"]);
  847. // explicit conversion of integers is required, which sort
  848. // of sucks. No idea if there is a shortcut here or not.
  849. prim.CreationDate = Convert.ToInt32(primRow["CreationDate"]);
  850. prim.Name = (string)primRow["Name"];
  851. // various text fields
  852. prim.Text = (string)primRow["Text"];
  853. prim.Color = Color.FromArgb(Convert.ToInt32(primRow["ColorA"]),
  854. Convert.ToInt32(primRow["ColorR"]),
  855. Convert.ToInt32(primRow["ColorG"]),
  856. Convert.ToInt32(primRow["ColorB"]));
  857. prim.Description = (string)primRow["Description"];
  858. prim.SitName = (string)primRow["SitName"];
  859. prim.TouchName = (string)primRow["TouchName"];
  860. // permissions
  861. prim.ObjectFlags = Convert.ToUInt32(primRow["ObjectFlags"]);
  862. prim.CreatorID = new UUID((Guid)primRow["CreatorID"]);
  863. prim.OwnerID = new UUID((Guid)primRow["OwnerID"]);
  864. prim.GroupID = new UUID((Guid)primRow["GroupID"]);
  865. prim.LastOwnerID = new UUID((Guid)primRow["LastOwnerID"]);
  866. prim.OwnerMask = Convert.ToUInt32(primRow["OwnerMask"]);
  867. prim.NextOwnerMask = Convert.ToUInt32(primRow["NextOwnerMask"]);
  868. prim.GroupMask = Convert.ToUInt32(primRow["GroupMask"]);
  869. prim.EveryoneMask = Convert.ToUInt32(primRow["EveryoneMask"]);
  870. prim.BaseMask = Convert.ToUInt32(primRow["BaseMask"]);
  871. // vectors
  872. prim.OffsetPosition = new Vector3(
  873. Convert.ToSingle(primRow["PositionX"]),
  874. Convert.ToSingle(primRow["PositionY"]),
  875. Convert.ToSingle(primRow["PositionZ"]));
  876. prim.GroupPosition = new Vector3(
  877. Convert.ToSingle(primRow["GroupPositionX"]),
  878. Convert.ToSingle(primRow["GroupPositionY"]),
  879. Convert.ToSingle(primRow["GroupPositionZ"]));
  880. prim.Velocity = new Vector3(
  881. Convert.ToSingle(primRow["VelocityX"]),
  882. Convert.ToSingle(primRow["VelocityY"]),
  883. Convert.ToSingle(primRow["VelocityZ"]));
  884. prim.AngularVelocity = new Vector3(
  885. Convert.ToSingle(primRow["AngularVelocityX"]),
  886. Convert.ToSingle(primRow["AngularVelocityY"]),
  887. Convert.ToSingle(primRow["AngularVelocityZ"]));
  888. prim.Acceleration = new Vector3(
  889. Convert.ToSingle(primRow["AccelerationX"]),
  890. Convert.ToSingle(primRow["AccelerationY"]),
  891. Convert.ToSingle(primRow["AccelerationZ"]));
  892. // quaternions
  893. prim.RotationOffset = new Quaternion(
  894. Convert.ToSingle(primRow["RotationX"]),
  895. Convert.ToSingle(primRow["RotationY"]),
  896. Convert.ToSingle(primRow["RotationZ"]),
  897. Convert.ToSingle(primRow["RotationW"]));
  898. prim.SitTargetPositionLL = new Vector3(
  899. Convert.ToSingle(primRow["SitTargetOffsetX"]),
  900. Convert.ToSingle(primRow["SitTargetOffsetY"]),
  901. Convert.ToSingle(primRow["SitTargetOffsetZ"]));
  902. prim.SitTargetOrientationLL = new Quaternion(
  903. Convert.ToSingle(primRow["SitTargetOrientX"]),
  904. Convert.ToSingle(primRow["SitTargetOrientY"]),
  905. Convert.ToSingle(primRow["SitTargetOrientZ"]),
  906. Convert.ToSingle(primRow["SitTargetOrientW"]));
  907. prim.PayPrice[0] = Convert.ToInt32(primRow["PayPrice"]);
  908. prim.PayPrice[1] = Convert.ToInt32(primRow["PayButton1"]);
  909. prim.PayPrice[2] = Convert.ToInt32(primRow["PayButton2"]);
  910. prim.PayPrice[3] = Convert.ToInt32(primRow["PayButton3"]);
  911. prim.PayPrice[4] = Convert.ToInt32(primRow["PayButton4"]);
  912. prim.Sound = new UUID((Guid)primRow["LoopedSound"]);
  913. prim.SoundGain = Convert.ToSingle(primRow["LoopedSoundGain"]);
  914. prim.SoundFlags = 1; // If it's persisted at all, it's looped
  915. if (!(primRow["TextureAnimation"] is DBNull))
  916. prim.TextureAnimation = (Byte[])primRow["TextureAnimation"];
  917. if (!(primRow["ParticleSystem"] is DBNull))
  918. prim.ParticleSystem = (Byte[])primRow["ParticleSystem"];
  919. prim.AngularVelocity = new Vector3(
  920. Convert.ToSingle(primRow["OmegaX"]),
  921. Convert.ToSingle(primRow["OmegaY"]),
  922. Convert.ToSingle(primRow["OmegaZ"]));
  923. prim.SetCameraEyeOffset(new Vector3(
  924. Convert.ToSingle(primRow["CameraEyeOffsetX"]),
  925. Convert.ToSingle(primRow["CameraEyeOffsetY"]),
  926. Convert.ToSingle(primRow["CameraEyeOffsetZ"])
  927. ));
  928. prim.SetCameraAtOffset(new Vector3(
  929. Convert.ToSingle(primRow["CameraAtOffsetX"]),
  930. Convert.ToSingle(primRow["CameraAtOffsetY"]),
  931. Convert.ToSingle(primRow["CameraAtOffsetZ"])
  932. ));
  933. if (Convert.ToInt16(primRow["ForceMouselook"]) != 0)
  934. prim.SetForceMouselook(true);
  935. prim.ScriptAccessPin = Convert.ToInt32(primRow["ScriptAccessPin"]);
  936. if (Convert.ToInt16(primRow["AllowedDrop"]) != 0)
  937. prim.AllowedDrop = true;
  938. if (Convert.ToInt16(primRow["DieAtEdge"]) != 0)
  939. prim.DIE_AT_EDGE = true;
  940. prim.SalePrice = Convert.ToInt32(primRow["SalePrice"]);
  941. prim.ObjectSaleType = Convert.ToByte(primRow["SaleType"]);
  942. prim.Material = Convert.ToByte(primRow["Material"]);
  943. if (!(primRow["ClickAction"] is DBNull))
  944. prim.ClickAction = Convert.ToByte(primRow["ClickAction"]);
  945. prim.CollisionSound = new UUID((Guid)primRow["CollisionSound"]);
  946. prim.CollisionSoundVolume = Convert.ToSingle(primRow["CollisionSoundVolume"]);
  947. if (Convert.ToInt16(primRow["PassTouches"]) != 0)
  948. prim.PassTouches = true;
  949. prim.LinkNum = Convert.ToInt32(primRow["LinkNumber"]);
  950. return prim;
  951. }
  952. /// <summary>
  953. /// Builds the prim shape from a datarecord.
  954. /// </summary>
  955. /// <param name="shapeRow">The row.</param>
  956. /// <returns></returns>
  957. private static PrimitiveBaseShape BuildShape(IDataRecord shapeRow)
  958. {
  959. PrimitiveBaseShape baseShape = new PrimitiveBaseShape();
  960. baseShape.Scale = new Vector3(
  961. Convert.ToSingle(shapeRow["ScaleX"]),
  962. Convert.ToSingle(shapeRow["ScaleY"]),
  963. Convert.ToSingle(shapeRow["ScaleZ"]));
  964. // paths
  965. baseShape.PCode = Convert.ToByte(shapeRow["PCode"]);
  966. baseShape.PathBegin = Convert.ToUInt16(shapeRow["PathBegin"]);
  967. baseShape.PathEnd = Convert.ToUInt16(shapeRow["PathEnd"]);
  968. baseShape.PathScaleX = Convert.ToByte(shapeRow["PathScaleX"]);
  969. baseShape.PathScaleY = Convert.ToByte(shapeRow["PathScaleY"]);
  970. baseShape.PathShearX = Convert.ToByte(shapeRow["PathShearX"]);
  971. baseShape.PathShearY = Convert.ToByte(shapeRow["PathShearY"]);
  972. baseShape.PathSkew = Convert.ToSByte(shapeRow["PathSkew"]);
  973. baseShape.PathCurve = Convert.ToByte(shapeRow["PathCurve"]);
  974. baseShape.PathRadiusOffset = Convert.ToSByte(shapeRow["PathRadiusOffset"]);
  975. baseShape.PathRevolutions = Convert.ToByte(shapeRow["PathRevolutions"]);
  976. baseShape.PathTaperX = Convert.ToSByte(shapeRow["PathTaperX"]);
  977. baseShape.PathTaperY = Convert.ToSByte(shapeRow["PathTaperY"]);
  978. baseShape.PathTwist = Convert.ToSByte(shapeRow["PathTwist"]);
  979. baseShape.PathTwistBegin = Convert.ToSByte(shapeRow["PathTwistBegin"]);
  980. // profile
  981. baseShape.ProfileBegin = Convert.ToUInt16(shapeRow["ProfileBegin"]);
  982. baseShape.ProfileEnd = Convert.ToUInt16(shapeRow["ProfileEnd"]);
  983. baseShape.ProfileCurve = Convert.ToByte(shapeRow["ProfileCurve"]);
  984. baseShape.ProfileHollow = Convert.ToUInt16(shapeRow["ProfileHollow"]);
  985. byte[] textureEntry = (byte[])shapeRow["Texture"];
  986. baseShape.TextureEntry = textureEntry;
  987. baseShape.ExtraParams = (byte[])shapeRow["ExtraParams"];
  988. try
  989. {
  990. baseShape.State = Convert.ToByte(shapeRow["State"]);
  991. }
  992. catch (InvalidCastException)
  993. {
  994. }
  995. return baseShape;
  996. }
  997. /// <summary>
  998. /// Build a prim inventory item from the persisted data.
  999. /// </summary>
  1000. /// <param name="inventoryRow"></param>
  1001. /// <returns></returns>
  1002. private static TaskInventoryItem BuildItem(IDataRecord inventoryRow)
  1003. {
  1004. TaskInventoryItem taskItem = new TaskInventoryItem();
  1005. taskItem.ItemID = new UUID((Guid)inventoryRow["itemID"]);
  1006. taskItem.ParentPartID = new UUID((Guid)inventoryRow["primID"]);
  1007. taskItem.AssetID = new UUID((Guid)inventoryRow["assetID"]);
  1008. taskItem.ParentID = new UUID((Guid)inventoryRow["parentFolderID"]);
  1009. taskItem.InvType = Convert.ToInt32(inventoryRow["invType"]);
  1010. taskItem.Type = Convert.ToInt32(inventoryRow["assetType"]);
  1011. taskItem.Name = (string)inventoryRow["name"];
  1012. taskItem.Description = (string)inventoryRow["description"];
  1013. taskItem.CreationDate = Convert.ToUInt32(inventoryRow["creationDate"]);
  1014. taskItem.CreatorID = new UUID((Guid)inventoryRow["creatorID"]);
  1015. taskItem.OwnerID = new UUID((Guid)inventoryRow["ownerID"]);
  1016. taskItem.LastOwnerID = new UUID((Guid)inventoryRow["lastOwnerID"]);
  1017. taskItem.GroupID = new UUID((Guid)inventoryRow["groupID"]);
  1018. taskItem.NextPermissions = Convert.ToUInt32(inventoryRow["nextPermissions"]);
  1019. taskItem.CurrentPermissions = Convert.ToUInt32(inventoryRow["currentPermissions"]);
  1020. taskItem.BasePermissions = Convert.ToUInt32(inventoryRow["basePermissions"]);
  1021. taskItem.EveryonePermissions = Convert.ToUInt32(inventoryRow["everyonePermissions"]);
  1022. taskItem.GroupPermissions = Convert.ToUInt32(inventoryRow["groupPermissions"]);
  1023. taskItem.Flags = Convert.ToUInt32(inventoryRow["flags"]);
  1024. return taskItem;
  1025. }
  1026. #endregion
  1027. #region Create parameters methods
  1028. /// <summary>
  1029. /// Creates the prim inventory parameters.
  1030. /// </summary>
  1031. /// <param name="taskItem">item in inventory.</param>
  1032. /// <returns></returns>
  1033. private SqlParameter[] CreatePrimInventoryParameters(TaskInventoryItem taskItem)
  1034. {
  1035. List<SqlParameter> parameters = new List<SqlParameter>();
  1036. parameters.Add(_Database.CreateParameter("itemID", taskItem.ItemID));
  1037. parameters.Add(_Database.CreateParameter("primID", taskItem.ParentPartID));
  1038. parameters.Add(_Database.CreateParameter("assetID", taskItem.AssetID));
  1039. parameters.Add(_Database.CreateParameter("parentFolderID", taskItem.ParentID));
  1040. parameters.Add(_Database.CreateParameter("invType", taskItem.InvType));
  1041. parameters.Add(_Database.CreateParameter("assetType", taskItem.Type));
  1042. parameters.Add(_Database.CreateParameter("name", taskItem.Name));
  1043. parameters.Add(_Database.CreateParameter("description", taskItem.Description));
  1044. parameters.Add(_Database.CreateParameter("creationDate", taskItem.CreationDate));
  1045. parameters.Add(_Database.CreateParameter("creatorID", taskItem.CreatorID));
  1046. parameters.Add(_Database.CreateParameter("ownerID", taskItem.OwnerID));
  1047. parameters.Add(_Database.CreateParameter("lastOwnerID", taskItem.LastOwnerID));
  1048. parameters.Add(_Database.CreateParameter("groupID", taskItem.GroupID));
  1049. parameters.Add(_Database.CreateParameter("nextPermissions", taskItem.NextPermissions));
  1050. parameters.Add(_Database.CreateParameter("currentPermissions", taskItem.CurrentPermissions));
  1051. parameters.Add(_Database.CreateParameter("basePermissions", taskItem.BasePermissions));
  1052. parameters.Add(_Database.CreateParameter("everyonePermissions", taskItem.EveryonePermissions));
  1053. parameters.Add(_Database.CreateParameter("groupPermissions", taskItem.GroupPermissions));
  1054. parameters.Add(_Database.CreateParameter("flags", taskItem.Flags));
  1055. return parameters.ToArray();
  1056. }
  1057. /// <summary>
  1058. /// Creates the region setting parameters.
  1059. /// </summary>
  1060. /// <param name="settings">regionsettings.</param>
  1061. /// <returns></returns>
  1062. private SqlParameter[] CreateRegionSettingParameters(RegionSettings settings)
  1063. {
  1064. List<SqlParameter> parameters = new List<SqlParameter>();
  1065. parameters.Add(_Database.CreateParameter("regionUUID", settings.RegionUUID));
  1066. parameters.Add(_Database.CreateParameter("block_terraform", settings.BlockTerraform));
  1067. parameters.Add(_Database.CreateParameter("block_fly", settings.BlockFly));
  1068. parameters.Add(_Database.CreateParameter("allow_damage", settings.AllowDamage));
  1069. parameters.Add(_Database.CreateParameter("restrict_pushing", settings.RestrictPushing));
  1070. parameters.Add(_Database.CreateParameter("allow_land_resell", settings.AllowLandResell));
  1071. parameters.Add(_Database.CreateParameter("allow_land_join_divide", settings.AllowLandJoinDivide));
  1072. parameters.Add(_Database.CreateParameter("block_show_in_search", settings.BlockShowInSearch));
  1073. parameters.Add(_Database.CreateParameter("agent_limit", settings.AgentLimit));
  1074. parameters.Add(_Database.CreateParameter("object_bonus", settings.ObjectBonus));
  1075. parameters.Add(_Database.CreateParameter("maturity", settings.Maturity));
  1076. parameters.Add(_Database.CreateParameter("disable_scripts", settings.DisableScripts));
  1077. parameters.Add(_Database.CreateParameter("disable_collisions", settings.DisableCollisions));
  1078. parameters.Add(_Database.CreateParameter("disable_physics", settings.DisablePhysics));
  1079. parameters.Add(_Database.CreateParameter("terrain_texture_1", settings.TerrainTexture1));
  1080. parameters.Add(_Database.CreateParameter("terrain_texture_2", settings.TerrainTexture2));
  1081. parameters.Add(_Database.CreateParameter("terrain_texture_3", settings.TerrainTexture3));
  1082. parameters.Add(_Database.CreateParameter("terrain_texture_4", settings.TerrainTexture4));
  1083. parameters.Add(_Database.CreateParameter("elevation_1_nw", settings.Elevation1NW));
  1084. parameters.Add(_Database.CreateParameter("elevation_2_nw", settings.Elevation2NW));
  1085. parameters.Add(_Database.CreateParameter("elevation_1_ne", settings.Elevation1NE));
  1086. parameters.Add(_Database.CreateParameter("elevation_2_ne", settings.Elevation2NE));
  1087. parameters.Add(_Database.CreateParameter("elevation_1_se", settings.Elevation1SE));
  1088. parameters.Add(_Database.CreateParameter("elevation_2_se", settings.Elevation2SE));
  1089. parameters.Add(_Database.CreateParameter("elevation_1_sw", settings.Elevation1SW));
  1090. parameters.Add(_Database.CreateParameter("elevation_2_sw", settings.Elevation2SW));
  1091. parameters.Add(_Database.CreateParameter("water_height", settings.WaterHeight));
  1092. parameters.Add(_Database.CreateParameter("terrain_raise_limit", settings.TerrainRaiseLimit));
  1093. parameters.Add(_Database.CreateParameter("terrain_lower_limit", settings.TerrainLowerLimit));
  1094. parameters.Add(_Database.CreateParameter("use_estate_sun", settings.UseEstateSun));
  1095. parameters.Add(_Database.CreateParameter("sandbox", settings.Sandbox));
  1096. parameters.Add(_Database.CreateParameter("fixed_sun", settings.FixedSun));
  1097. parameters.Add(_Database.CreateParameter("sun_position", settings.SunPosition));
  1098. parameters.Add(_Database.CreateParameter("sunvectorx", settings.SunVector.X));
  1099. parameters.Add(_Database.CreateParameter("sunvectory", settings.SunVector.Y));
  1100. parameters.Add(_Database.CreateParameter("sunvectorz", settings.SunVector.Z));
  1101. parameters.Add(_Database.CreateParameter("covenant", settings.Covenant));
  1102. parameters.Add(_Database.CreateParameter("Loaded_Creation_DateTime", settings.LoadedCreationDateTime));
  1103. parameters.Add(_Database.CreateParameter("Loaded_Creation_ID", settings.LoadedCreationID));
  1104. return parameters.ToArray();
  1105. }
  1106. /// <summary>
  1107. /// Creates the land parameters.
  1108. /// </summary>
  1109. /// <param name="land">land parameters.</param>
  1110. /// <param name="regionUUID">region UUID.</param>
  1111. /// <returns></returns>
  1112. private SqlParameter[] CreateLandParameters(LandData land, UUID regionUUID)
  1113. {
  1114. List<SqlParameter> parameters = new List<SqlParameter>();
  1115. parameters.Add(_Database.CreateParameter("UUID", land.GlobalID));
  1116. parameters.Add(_Database.CreateParameter("RegionUUID", regionUUID));
  1117. parameters.Add(_Database.CreateParameter("LocalLandID", land.LocalID));
  1118. // Bitmap is a byte[512]
  1119. parameters.Add(_Database.CreateParameter("Bitmap", land.Bitmap));
  1120. parameters.Add(_Database.CreateParameter("Name", land.Name));
  1121. parameters.Add(_Database.CreateParameter("Description", land.Description));
  1122. parameters.Add(_Database.CreateParameter("OwnerUUID", land.OwnerID));
  1123. parameters.Add(_Database.CreateParameter("IsGroupOwned", land.IsGroupOwned));
  1124. parameters.Add(_Database.CreateParameter("Area", land.Area));
  1125. parameters.Add(_Database.CreateParameter("AuctionID", land.AuctionID)); //Unemplemented
  1126. parameters.Add(_Database.CreateParameter("Category", (int)land.Category)); //Enum libsecondlife.Parcel.ParcelCategory
  1127. parameters.Add(_Database.CreateParameter("ClaimDate", land.ClaimDate));
  1128. parameters.Add(_Database.CreateParameter("ClaimPrice", land.ClaimPrice));
  1129. parameters.Add(_Database.CreateParameter("GroupUUID", land.GroupID));
  1130. parameters.Add(_Database.CreateParameter("SalePrice", land.SalePrice));
  1131. parameters.Add(_Database.CreateParameter("LandStatus", (int)land.Status)); //Enum. libsecondlife.Parcel.ParcelStatus
  1132. parameters.Add(_Database.CreateParameter("LandFlags", land.Flags));
  1133. parameters.Add(_Database.CreateParameter("LandingType", land.LandingType));
  1134. parameters.Add(_Database.CreateParameter("MediaAutoScale", land.MediaAutoScale));
  1135. parameters.Add(_Database.CreateParameter("MediaTextureUUID", land.MediaID));
  1136. parameters.Add(_Database.CreateParameter("MediaURL", land.MediaURL));
  1137. parameters.Add(_Database.CreateParameter("MusicURL", land.MusicURL));
  1138. parameters.Add(_Database.CreateParameter("PassHours", land.PassHours));
  1139. parameters.Add(_Database.CreateParameter("PassPrice", land.PassPrice));
  1140. parameters.Add(_Database.CreateParameter("SnapshotUUID", land.SnapshotID));
  1141. parameters.Add(_Database.CreateParameter("UserLocationX", land.UserLocation.X));
  1142. parameters.Add(_Database.CreateParameter("UserLocationY", land.UserLocation.Y));
  1143. parameters.Add(_Database.CreateParameter("UserLocationZ", land.UserLocation.Z));
  1144. parameters.Add(_Database.CreateParameter("UserLookAtX", land.UserLookAt.X));
  1145. parameters.Add(_Database.CreateParameter("UserLookAtY", land.UserLookAt.Y));
  1146. parameters.Add(_Database.CreateParameter("UserLookAtZ", land.UserLookAt.Z));
  1147. parameters.Add(_Database.CreateParameter("AuthBuyerID", land.AuthBuyerID));
  1148. parameters.Add(_Database.CreateParameter("OtherCleanTime", land.OtherCleanTime));
  1149. parameters.Add(_Database.CreateParameter("Dwell", land.Dwell));
  1150. return parameters.ToArray();
  1151. }
  1152. /// <summary>
  1153. /// Creates the land access parameters.
  1154. /// </summary>
  1155. /// <param name="parcelAccessEntry">parcel access entry.</param>
  1156. /// <param name="parcelID">parcel ID.</param>
  1157. /// <returns></returns>
  1158. private SqlParameter[] CreateLandAccessParameters(ParcelManager.ParcelAccessEntry parcelAccessEntry, UUID parcelID)
  1159. {
  1160. List<SqlParameter> parameters = new List<SqlParameter>();
  1161. parameters.Add(_Database.CreateParameter("LandUUID", parcelID));
  1162. parameters.Add(_Database.CreateParameter("AccessUUID", parcelAccessEntry.AgentID));
  1163. parameters.Add(_Database.CreateParameter("Flags", parcelAccessEntry.Flags));
  1164. return parameters.ToArray();
  1165. }
  1166. /// <summary>
  1167. /// Creates the prim parameters for storing in DB.
  1168. /// </summary>
  1169. /// <param name="prim">Basic data of SceneObjectpart prim.</param>
  1170. /// <param name="sceneGroupID">The scenegroup ID.</param>
  1171. /// <param name="regionUUID">The region ID.</param>
  1172. /// <returns></returns>
  1173. private SqlParameter[] CreatePrimParameters(SceneObjectPart prim, UUID sceneGroupID, UUID regionUUID)
  1174. {
  1175. List<SqlParameter> parameters = new List<SqlParameter>();
  1176. parameters.Add(_Database.CreateParameter("UUID", prim.UUID));
  1177. parameters.Add(_Database.CreateParameter("RegionUUID", regionUUID));
  1178. parameters.Add(_Database.CreateParameter("CreationDate", prim.CreationDate));
  1179. parameters.Add(_Database.CreateParameter("Name", prim.Name));
  1180. parameters.Add(_Database.CreateParameter("SceneGroupID", sceneGroupID));
  1181. // the UUID of the root part for this SceneObjectGroup
  1182. // various text fields
  1183. parameters.Add(_Database.CreateParameter("Text", prim.Text));
  1184. parameters.Add(_Database.CreateParameter("ColorR", prim.Color.R));
  1185. parameters.Add(_Database.CreateParameter("ColorG", prim.Color.G));
  1186. parameters.Add(_Database.CreateParameter("ColorB", prim.Color.B));
  1187. parameters.Add(_Database.CreateParameter("ColorA", prim.Color.A));
  1188. parameters.Add(_Database.CreateParameter("Description", prim.Description));
  1189. parameters.Add(_Database.CreateParameter("SitName", prim.SitName));
  1190. parameters.Add(_Database.CreateParameter("TouchName", prim.TouchName));
  1191. // permissions
  1192. parameters.Add(_Database.CreateParameter("ObjectFlags", prim.ObjectFlags));
  1193. parameters.Add(_Database.CreateParameter("CreatorID", prim.CreatorID));
  1194. parameters.Add(_Database.CreateParameter("OwnerID", prim.OwnerID));
  1195. parameters.Add(_Database.CreateParameter("GroupID", prim.GroupID));
  1196. parameters.Add(_Database.CreateParameter("LastOwnerID", prim.LastOwnerID));
  1197. parameters.Add(_Database.CreateParameter("OwnerMask", prim.OwnerMask));
  1198. parameters.Add(_Database.CreateParameter("NextOwnerMask", prim.NextOwnerMask));
  1199. parameters.Add(_Database.CreateParameter("GroupMask", prim.GroupMask));
  1200. parameters.Add(_Database.CreateParameter("EveryoneMask", prim.EveryoneMask));
  1201. parameters.Add(_Database.CreateParameter("BaseMask", prim.BaseMask));
  1202. // vectors
  1203. parameters.Add(_Database.CreateParameter("PositionX", prim.OffsetPosition.X));
  1204. parameters.Add(_Database.CreateParameter("PositionY", prim.OffsetPosition.Y));
  1205. parameters.Add(_Database.CreateParameter("PositionZ", prim.OffsetPosition.Z));
  1206. parameters.Add(_Database.CreateParameter("GroupPositionX", prim.GroupPosition.X));
  1207. parameters.Add(_Database.CreateParameter("GroupPositionY", prim.GroupPosition.Y));
  1208. parameters.Add(_Database.CreateParameter("GroupPositionZ", prim.GroupPosition.Z));
  1209. parameters.Add(_Database.CreateParameter("VelocityX", prim.Velocity.X));
  1210. parameters.Add(_Database.CreateParameter("VelocityY", prim.Velocity.Y));
  1211. parameters.Add(_Database.CreateParameter("VelocityZ", prim.Velocity.Z));
  1212. parameters.Add(_Database.CreateParameter("AngularVelocityX", prim.AngularVelocity.X));
  1213. parameters.Add(_Database.CreateParameter("AngularVelocityY", prim.AngularVelocity.Y));
  1214. parameters.Add(_Database.CreateParameter("AngularVelocityZ", prim.AngularVelocity.Z));
  1215. parameters.Add(_Database.CreateParameter("AccelerationX", prim.Acceleration.X));
  1216. parameters.Add(_Database.CreateParameter("AccelerationY", prim.Acceleration.Y));
  1217. parameters.Add(_Database.CreateParameter("AccelerationZ", prim.Acceleration.Z));
  1218. // quaternions
  1219. parameters.Add(_Database.CreateParameter("RotationX", prim.RotationOffset.X));
  1220. parameters.Add(_Database.CreateParameter("RotationY", prim.RotationOffset.Y));
  1221. parameters.Add(_Database.CreateParameter("RotationZ", prim.RotationOffset.Z));
  1222. parameters.Add(_Database.CreateParameter("RotationW", prim.RotationOffset.W));
  1223. // Sit target
  1224. Vector3 sitTargetPos = prim.SitTargetPositionLL;
  1225. parameters.Add(_Database.CreateParameter("SitTargetOffsetX", sitTargetPos.X));
  1226. parameters.Add(_Database.CreateParameter("SitTargetOffsetY", sitTargetPos.Y));
  1227. parameters.Add(_Database.CreateParameter("SitTargetOffsetZ", sitTargetPos.Z));
  1228. Quaternion sitTargetOrient = prim.SitTargetOrientationLL;
  1229. parameters.Add(_Database.CreateParameter("SitTargetOrientW", sitTargetOrient.W));
  1230. parameters.Add(_Database.CreateParameter("SitTargetOrientX", sitTargetOrient.X));
  1231. parameters.Add(_Database.CreateParameter("SitTargetOrientY", sitTargetOrient.Y));
  1232. parameters.Add(_Database.CreateParameter("SitTargetOrientZ", sitTargetOrient.Z));
  1233. parameters.Add(_Database.CreateParameter("PayPrice", prim.PayPrice[0]));
  1234. parameters.Add(_Database.CreateParameter("PayButton1", prim.PayPrice[1]));
  1235. parameters.Add(_Database.CreateParameter("PayButton2", prim.PayPrice[2]));
  1236. parameters.Add(_Database.CreateParameter("PayButton3", prim.PayPrice[3]));
  1237. parameters.Add(_Database.CreateParameter("PayButton4", prim.PayPrice[4]));
  1238. if ((prim.SoundFlags & 1) != 0) // Looped
  1239. {
  1240. parameters.Add(_Database.CreateParameter("LoopedSound", prim.Sound));
  1241. parameters.Add(_Database.CreateParameter("LoopedSoundGain", prim.SoundGain));
  1242. }
  1243. else
  1244. {
  1245. parameters.Add(_Database.CreateParameter("LoopedSound", UUID.Zero));
  1246. parameters.Add(_Database.CreateParameter("LoopedSoundGain", 0.0f));
  1247. }
  1248. parameters.Add(_Database.CreateParameter("TextureAnimation", prim.TextureAnimation));
  1249. parameters.Add(_Database.CreateParameter("ParticleSystem", prim.ParticleSystem));
  1250. parameters.Add(_Database.CreateParameter("OmegaX", prim.AngularVelocity.X));
  1251. parameters.Add(_Database.CreateParameter("OmegaY", prim.AngularVelocity.Y));
  1252. parameters.Add(_Database.CreateParameter("OmegaZ", prim.AngularVelocity.Z));
  1253. parameters.Add(_Database.CreateParameter("CameraEyeOffsetX", prim.GetCameraEyeOffset().X));
  1254. parameters.Add(_Database.CreateParameter("CameraEyeOffsetY", prim.GetCameraEyeOffset().Y));
  1255. parameters.Add(_Database.CreateParameter("CameraEyeOffsetZ", prim.GetCameraEyeOffset().Z));
  1256. parameters.Add(_Database.CreateParameter("CameraAtOffsetX", prim.GetCameraAtOffset().X));
  1257. parameters.Add(_Database.CreateParameter("CameraAtOffsetY", prim.GetCameraAtOffset().Y));
  1258. parameters.Add(_Database.CreateParameter("CameraAtOffsetZ", prim.GetCameraAtOffset().Z));
  1259. if (prim.GetForceMouselook())
  1260. parameters.Add(_Database.CreateParameter("ForceMouselook", 1));
  1261. else
  1262. parameters.Add(_Database.CreateParameter("ForceMouselook", 0));
  1263. parameters.Add(_Database.CreateParameter("ScriptAccessPin", prim.ScriptAccessPin));
  1264. if (prim.AllowedDrop)
  1265. parameters.Add(_Database.CreateParameter("AllowedDrop", 1));
  1266. else
  1267. parameters.Add(_Database.CreateParameter("AllowedDrop", 0));
  1268. if (prim.DIE_AT_EDGE)
  1269. parameters.Add(_Database.CreateParameter("DieAtEdge", 1));
  1270. else
  1271. parameters.Add(_Database.CreateParameter("DieAtEdge", 0));
  1272. parameters.Add(_Database.CreateParameter("SalePrice", prim.SalePrice));
  1273. parameters.Add(_Database.CreateParameter("SaleType", prim.ObjectSaleType));
  1274. byte clickAction = prim.ClickAction;
  1275. parameters.Add(_Database.CreateParameter("ClickAction", clickAction));
  1276. parameters.Add(_Database.CreateParameter("Material", prim.Material));
  1277. parameters.Add(_Database.CreateParameter("CollisionSound", prim.CollisionSound));
  1278. parameters.Add(_Database.CreateParameter("CollisionSoundVolume", prim.CollisionSoundVolume));
  1279. if (prim.PassTouches)
  1280. parameters.Add(_Database.CreateParameter("PassTouches", 1));
  1281. else
  1282. parameters.Add(_Database.CreateParameter("PassTouches", 0));
  1283. parameters.Add(_Database.CreateParameter("LinkNumber", prim.LinkNum));
  1284. return parameters.ToArray();
  1285. }
  1286. /// <summary>
  1287. /// Creates the primshape parameters for stroing in DB.
  1288. /// </summary>
  1289. /// <param name="prim">Basic data of SceneObjectpart prim.</param>
  1290. /// <param name="sceneGroupID">The scene group ID.</param>
  1291. /// <param name="regionUUID">The region UUID.</param>
  1292. /// <returns></returns>
  1293. private SqlParameter[] CreatePrimShapeParameters(SceneObjectPart prim, UUID sceneGroupID, UUID regionUUID)
  1294. {
  1295. List<SqlParameter> parameters = new List<SqlParameter>();
  1296. PrimitiveBaseShape s = prim.Shape;
  1297. parameters.Add(_Database.CreateParameter("UUID", prim.UUID));
  1298. // shape is an enum
  1299. parameters.Add(_Database.CreateParameter("Shape", 0));
  1300. // vectors
  1301. parameters.Add(_Database.CreateParameter("ScaleX", s.Scale.X));
  1302. parameters.Add(_Database.CreateParameter("ScaleY", s.Scale.Y));
  1303. parameters.Add(_Database.CreateParameter("ScaleZ", s.Scale.Z));
  1304. // paths
  1305. parameters.Add(_Database.CreateParameter("PCode", s.PCode));
  1306. parameters.Add(_Database.CreateParameter("PathBegin", s.PathBegin));
  1307. parameters.Add(_Database.CreateParameter("PathEnd", s.PathEnd));
  1308. parameters.Add(_Database.CreateParameter("PathScaleX", s.PathScaleX));
  1309. parameters.Add(_Database.CreateParameter("PathScaleY", s.PathScaleY));
  1310. parameters.Add(_Database.CreateParameter("PathShearX", s.PathShearX));
  1311. parameters.Add(_Database.CreateParameter("PathShearY", s.PathShearY));
  1312. parameters.Add(_Database.CreateParameter("PathSkew", s.PathSkew));
  1313. parameters.Add(_Database.CreateParameter("PathCurve", s.PathCurve));
  1314. parameters.Add(_Database.CreateParameter("PathRadiusOffset", s.PathRadiusOffset));
  1315. parameters.Add(_Database.CreateParameter("PathRevolutions", s.PathRevolutions));
  1316. parameters.Add(_Database.CreateParameter("PathTaperX", s.PathTaperX));
  1317. parameters.Add(_Database.CreateParameter("PathTaperY", s.PathTaperY));
  1318. parameters.Add(_Database.CreateParameter("PathTwist", s.PathTwist));
  1319. parameters.Add(_Database.CreateParameter("PathTwistBegin", s.PathTwistBegin));
  1320. // profile
  1321. parameters.Add(_Database.CreateParameter("ProfileBegin", s.ProfileBegin));
  1322. parameters.Add(_Database.CreateParameter("ProfileEnd", s.ProfileEnd));
  1323. parameters.Add(_Database.CreateParameter("ProfileCurve", s.ProfileCurve));
  1324. parameters.Add(_Database.CreateParameter("ProfileHollow", s.ProfileHollow));
  1325. parameters.Add(_Database.CreateParameter("Texture", s.TextureEntry));
  1326. parameters.Add(_Database.CreateParameter("ExtraParams", s.ExtraParams));
  1327. parameters.Add(_Database.CreateParameter("State", s.State));
  1328. return parameters.ToArray();
  1329. }
  1330. #endregion
  1331. #endregion
  1332. }
  1333. }