MSSQLSimulationData.cs 84 KB

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