MSSQLRegionData.cs 78 KB

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