MSSQLRegionData.cs 79 KB

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