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