MSSQLRegionData.cs 80 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516
  1. /*
  2. * Copyright (c) Contributors, http://opensimulator.org/
  3. * See CONTRIBUTORS.TXT for a full list of copyright holders.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are met:
  7. * * Redistributions of source code must retain the above copyright
  8. * notice, this list of conditions and the following disclaimer.
  9. * * Redistributions in binary form must reproduce the above copyright
  10. * notice, this list of conditions and the following disclaimer in the
  11. * documentation and/or other materials provided with the distribution.
  12. * * Neither the name of the OpenSimulator Project nor the
  13. * names of its contributors may be used to endorse or promote products
  14. * derived from this software without specific prior written permission.
  15. *
  16. * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
  17. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  18. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  19. * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
  20. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  21. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  22. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  23. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  24. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  25. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. */
  27. using System;
  28. using System.Collections.Generic;
  29. using System.Data;
  30. using System.Data.SqlClient;
  31. using System.Drawing;
  32. using System.IO;
  33. using System.Reflection;
  34. using log4net;
  35. using OpenMetaverse;
  36. using OpenSim.Framework;
  37. using OpenSim.Region.Framework.Interfaces;
  38. using OpenSim.Region.Framework.Scenes;
  39. namespace OpenSim.Data.MSSQL
  40. {
  41. /// <summary>
  42. /// A MSSQL Interface for the Region Server.
  43. /// </summary>
  44. public class MSSQLRegionDataStore : IRegionDataStore
  45. {
  46. private const string _migrationStore = "RegionStore";
  47. // private static FileSystemDataStore Instance = new FileSystemDataStore();
  48. private static readonly ILog _Log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  49. /// <summary>
  50. /// The database manager
  51. /// </summary>
  52. private MSSQLManager _Database;
  53. /// <summary>
  54. /// Initialises the region datastore
  55. /// </summary>
  56. /// <param name="connectionString">The connection string.</param>
  57. public void Initialise(string connectionString)
  58. {
  59. if (!string.IsNullOrEmpty(connectionString))
  60. {
  61. _Database = new MSSQLManager(connectionString);
  62. }
  63. else
  64. {
  65. IniFile iniFile = new IniFile("mssql_connection.ini");
  66. string settingDataSource = iniFile.ParseFileReadValue("data_source");
  67. string settingInitialCatalog = iniFile.ParseFileReadValue("initial_catalog");
  68. string settingPersistSecurityInfo = iniFile.ParseFileReadValue("persist_security_info");
  69. string settingUserId = iniFile.ParseFileReadValue("user_id");
  70. string settingPassword = iniFile.ParseFileReadValue("password");
  71. _Database = new MSSQLManager(settingDataSource, settingInitialCatalog, settingPersistSecurityInfo, settingUserId, settingPassword);
  72. }
  73. //Migration settings
  74. _Database.CheckMigration(_migrationStore);
  75. }
  76. /// <summary>
  77. /// Dispose the database
  78. /// </summary>
  79. public void Dispose() { }
  80. #region SceneObjectGroup region for loading and Store of the scene.
  81. /// <summary>
  82. /// Loads the objects present in the region.
  83. /// </summary>
  84. /// <param name="regionUUID">The region UUID.</param>
  85. /// <returns></returns>
  86. public List<SceneObjectGroup> LoadObjects(UUID regionUUID)
  87. {
  88. UUID lastGroupID = UUID.Zero;
  89. 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, PassTouches = @PassTouches,
  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, PassTouches, 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, @PassTouches, @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[(int)Constants.RegionSize, (int)Constants.RegionSize];
  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 < (int)Constants.RegionSize; x++)
  441. {
  442. for (int y = 0; y < (int)Constants.RegionSize; 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, [loaded_creation_datetime] = @loaded_creation_datetime, [loaded_creation_id] = @loaded_creation_id
  633. WHERE [regionUUID] = @regionUUID";
  634. using (AutoClosingSqlCommand cmd = _Database.Query(sql))
  635. {
  636. cmd.Parameters.AddRange(CreateRegionSettingParameters(regionSettings));
  637. cmd.ExecuteNonQuery();
  638. }
  639. }
  640. }
  641. public void Shutdown()
  642. {
  643. //Not used??
  644. }
  645. #region Private Methods
  646. /// <summary>
  647. /// Serializes the terrain data for storage in DB.
  648. /// </summary>
  649. /// <param name="val">terrain data</param>
  650. /// <returns></returns>
  651. private static Array serializeTerrain(double[,] val)
  652. {
  653. MemoryStream str = new MemoryStream(((int)Constants.RegionSize * (int)Constants.RegionSize) * sizeof(double));
  654. BinaryWriter bw = new BinaryWriter(str);
  655. // TODO: COMPATIBILITY - Add byte-order conversions
  656. for (int x = 0; x < (int)Constants.RegionSize; x++)
  657. for (int y = 0; y < (int)Constants.RegionSize; y++)
  658. {
  659. double height = val[x, y];
  660. if (height == 0.0)
  661. height = double.Epsilon;
  662. bw.Write(height);
  663. }
  664. return str.ToArray();
  665. }
  666. /// <summary>
  667. /// Stores new regionsettings.
  668. /// </summary>
  669. /// <param name="regionSettings">The region settings.</param>
  670. private void StoreNewRegionSettings(RegionSettings regionSettings)
  671. {
  672. string sql = @"INSERT INTO [regionsettings]
  673. ([regionUUID],[block_terraform],[block_fly],[allow_damage],[restrict_pushing],[allow_land_resell],[allow_land_join_divide],
  674. [block_show_in_search],[agent_limit],[object_bonus],[maturity],[disable_scripts],[disable_collisions],[disable_physics],
  675. [terrain_texture_1],[terrain_texture_2],[terrain_texture_3],[terrain_texture_4],[elevation_1_nw],[elevation_2_nw],[elevation_1_ne],
  676. [elevation_2_ne],[elevation_1_se],[elevation_2_se],[elevation_1_sw],[elevation_2_sw],[water_height],[terrain_raise_limit],
  677. [terrain_lower_limit],[use_estate_sun],[fixed_sun],[sun_position],[covenant],[sunvectorx], [sunvectory], [sunvectorz],[Sandbox], [loaded_creation_datetime], [loaded_creation_id]
  678. )
  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, @loaded_creation_datetime, @loaded_creation_id)";
  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((Guid)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((Guid)row["terrain_texture_1"]);
  716. newSettings.TerrainTexture2 = new UUID((Guid)row["terrain_texture_2"]);
  717. newSettings.TerrainTexture3 = new UUID((Guid)row["terrain_texture_3"]);
  718. newSettings.TerrainTexture4 = new UUID((Guid)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((Guid)row["covenant"]);
  740. newSettings.LoadedCreationDateTime = Convert.ToInt32(row["loaded_creation_datetime"]);
  741. if (row["loaded_creation_id"] is DBNull)
  742. newSettings.LoadedCreationID = "";
  743. else
  744. newSettings.LoadedCreationID = (String)row["loaded_creation_id"];
  745. return newSettings;
  746. }
  747. /// <summary>
  748. /// Builds the land data from a datarecord.
  749. /// </summary>
  750. /// <param name="row">datarecord with land data</param>
  751. /// <returns></returns>
  752. private static LandData BuildLandData(IDataRecord row)
  753. {
  754. LandData newData = new LandData();
  755. newData.GlobalID = new UUID((Guid)row["UUID"]);
  756. newData.LocalID = Convert.ToInt32(row["LocalLandID"]);
  757. // Bitmap is a byte[512]
  758. newData.Bitmap = (Byte[])row["Bitmap"];
  759. newData.Name = (string)row["Name"];
  760. newData.Description = (string)row["Description"];
  761. newData.OwnerID = new UUID((Guid)row["OwnerUUID"]);
  762. newData.IsGroupOwned = Convert.ToBoolean(row["IsGroupOwned"]);
  763. newData.Area = Convert.ToInt32(row["Area"]);
  764. newData.AuctionID = Convert.ToUInt32(row["AuctionID"]); //Unemplemented
  765. newData.Category = (ParcelCategory)Convert.ToInt32(row["Category"]);
  766. //Enum libsecondlife.Parcel.ParcelCategory
  767. newData.ClaimDate = Convert.ToInt32(row["ClaimDate"]);
  768. newData.ClaimPrice = Convert.ToInt32(row["ClaimPrice"]);
  769. newData.GroupID = new UUID((Guid)row["GroupUUID"]);
  770. newData.SalePrice = Convert.ToInt32(row["SalePrice"]);
  771. newData.Status = (ParcelStatus)Convert.ToInt32(row["LandStatus"]);
  772. //Enum. libsecondlife.Parcel.ParcelStatus
  773. newData.Flags = Convert.ToUInt32(row["LandFlags"]);
  774. newData.LandingType = Convert.ToByte(row["LandingType"]);
  775. newData.MediaAutoScale = Convert.ToByte(row["MediaAutoScale"]);
  776. newData.MediaID = new UUID((Guid)row["MediaTextureUUID"]);
  777. newData.MediaURL = (string)row["MediaURL"];
  778. newData.MusicURL = (string)row["MusicURL"];
  779. newData.PassHours = Convert.ToSingle(row["PassHours"]);
  780. newData.PassPrice = Convert.ToInt32(row["PassPrice"]);
  781. // UUID authedbuyer;
  782. // UUID snapshotID;
  783. //
  784. // if (UUID.TryParse((string)row["AuthBuyerID"], out authedbuyer))
  785. // newData.AuthBuyerID = authedbuyer;
  786. //
  787. // if (UUID.TryParse((string)row["SnapshotUUID"], out snapshotID))
  788. // newData.SnapshotID = snapshotID;
  789. newData.AuthBuyerID = new UUID((Guid) row["AuthBuyerID"]);
  790. newData.SnapshotID = new UUID((Guid)row["SnapshotUUID"]);
  791. newData.OtherCleanTime = Convert.ToInt32(row["OtherCleanTime"]);
  792. newData.Dwell = Convert.ToInt32(row["Dwell"]);
  793. try
  794. {
  795. newData.UserLocation =
  796. new Vector3(Convert.ToSingle(row["UserLocationX"]), Convert.ToSingle(row["UserLocationY"]),
  797. Convert.ToSingle(row["UserLocationZ"]));
  798. newData.UserLookAt =
  799. new Vector3(Convert.ToSingle(row["UserLookAtX"]), Convert.ToSingle(row["UserLookAtY"]),
  800. Convert.ToSingle(row["UserLookAtZ"]));
  801. }
  802. catch (InvalidCastException)
  803. {
  804. newData.UserLocation = Vector3.Zero;
  805. newData.UserLookAt = Vector3.Zero;
  806. _Log.ErrorFormat("[PARCEL]: unable to get parcel telehub settings for {1}", newData.Name);
  807. }
  808. newData.ParcelAccessList = new List<ParcelManager.ParcelAccessEntry>();
  809. return newData;
  810. }
  811. /// <summary>
  812. /// Builds the landaccess data from a data record.
  813. /// </summary>
  814. /// <param name="row">datarecord with landaccess data</param>
  815. /// <returns></returns>
  816. private static ParcelManager.ParcelAccessEntry BuildLandAccessData(IDataRecord row)
  817. {
  818. ParcelManager.ParcelAccessEntry entry = new ParcelManager.ParcelAccessEntry();
  819. entry.AgentID = new UUID((Guid)row["AccessUUID"]);
  820. entry.Flags = (AccessList)Convert.ToInt32(row["Flags"]);
  821. entry.Time = new DateTime();
  822. return entry;
  823. }
  824. /// <summary>
  825. /// Builds the prim from a datarecord.
  826. /// </summary>
  827. /// <param name="primRow">datarecord</param>
  828. /// <returns></returns>
  829. private static SceneObjectPart BuildPrim(IDataRecord primRow)
  830. {
  831. SceneObjectPart prim = new SceneObjectPart();
  832. prim.UUID = new UUID((Guid)primRow["UUID"]);
  833. // explicit conversion of integers is required, which sort
  834. // of sucks. No idea if there is a shortcut here or not.
  835. prim.CreationDate = Convert.ToInt32(primRow["CreationDate"]);
  836. prim.Name = (string)primRow["Name"];
  837. // various text fields
  838. prim.Text = (string)primRow["Text"];
  839. prim.Color = Color.FromArgb(Convert.ToInt32(primRow["ColorA"]),
  840. Convert.ToInt32(primRow["ColorR"]),
  841. Convert.ToInt32(primRow["ColorG"]),
  842. Convert.ToInt32(primRow["ColorB"]));
  843. prim.Description = (string)primRow["Description"];
  844. prim.SitName = (string)primRow["SitName"];
  845. prim.TouchName = (string)primRow["TouchName"];
  846. // permissions
  847. prim.ObjectFlags = Convert.ToUInt32(primRow["ObjectFlags"]);
  848. prim.CreatorID = new UUID((Guid)primRow["CreatorID"]);
  849. prim.OwnerID = new UUID((Guid)primRow["OwnerID"]);
  850. prim.GroupID = new UUID((Guid)primRow["GroupID"]);
  851. prim.LastOwnerID = new UUID((Guid)primRow["LastOwnerID"]);
  852. prim.OwnerMask = Convert.ToUInt32(primRow["OwnerMask"]);
  853. prim.NextOwnerMask = Convert.ToUInt32(primRow["NextOwnerMask"]);
  854. prim.GroupMask = Convert.ToUInt32(primRow["GroupMask"]);
  855. prim.EveryoneMask = Convert.ToUInt32(primRow["EveryoneMask"]);
  856. prim.BaseMask = Convert.ToUInt32(primRow["BaseMask"]);
  857. // vectors
  858. prim.OffsetPosition = new Vector3(
  859. Convert.ToSingle(primRow["PositionX"]),
  860. Convert.ToSingle(primRow["PositionY"]),
  861. Convert.ToSingle(primRow["PositionZ"]));
  862. prim.GroupPosition = new Vector3(
  863. Convert.ToSingle(primRow["GroupPositionX"]),
  864. Convert.ToSingle(primRow["GroupPositionY"]),
  865. Convert.ToSingle(primRow["GroupPositionZ"]));
  866. prim.Velocity = new Vector3(
  867. Convert.ToSingle(primRow["VelocityX"]),
  868. Convert.ToSingle(primRow["VelocityY"]),
  869. Convert.ToSingle(primRow["VelocityZ"]));
  870. prim.AngularVelocity = new Vector3(
  871. Convert.ToSingle(primRow["AngularVelocityX"]),
  872. Convert.ToSingle(primRow["AngularVelocityY"]),
  873. Convert.ToSingle(primRow["AngularVelocityZ"]));
  874. prim.Acceleration = new Vector3(
  875. Convert.ToSingle(primRow["AccelerationX"]),
  876. Convert.ToSingle(primRow["AccelerationY"]),
  877. Convert.ToSingle(primRow["AccelerationZ"]));
  878. // quaternions
  879. prim.RotationOffset = new Quaternion(
  880. Convert.ToSingle(primRow["RotationX"]),
  881. Convert.ToSingle(primRow["RotationY"]),
  882. Convert.ToSingle(primRow["RotationZ"]),
  883. Convert.ToSingle(primRow["RotationW"]));
  884. prim.SitTargetPositionLL = new Vector3(
  885. Convert.ToSingle(primRow["SitTargetOffsetX"]),
  886. Convert.ToSingle(primRow["SitTargetOffsetY"]),
  887. Convert.ToSingle(primRow["SitTargetOffsetZ"]));
  888. prim.SitTargetOrientationLL = new Quaternion(
  889. Convert.ToSingle(primRow["SitTargetOrientX"]),
  890. Convert.ToSingle(primRow["SitTargetOrientY"]),
  891. Convert.ToSingle(primRow["SitTargetOrientZ"]),
  892. Convert.ToSingle(primRow["SitTargetOrientW"]));
  893. prim.PayPrice[0] = Convert.ToInt32(primRow["PayPrice"]);
  894. prim.PayPrice[1] = Convert.ToInt32(primRow["PayButton1"]);
  895. prim.PayPrice[2] = Convert.ToInt32(primRow["PayButton2"]);
  896. prim.PayPrice[3] = Convert.ToInt32(primRow["PayButton3"]);
  897. prim.PayPrice[4] = Convert.ToInt32(primRow["PayButton4"]);
  898. prim.Sound = new UUID((Guid)primRow["LoopedSound"]);
  899. prim.SoundGain = Convert.ToSingle(primRow["LoopedSoundGain"]);
  900. prim.SoundFlags = 1; // If it's persisted at all, it's looped
  901. if (!(primRow["TextureAnimation"] is DBNull))
  902. prim.TextureAnimation = (Byte[])primRow["TextureAnimation"];
  903. if (!(primRow["ParticleSystem"] is DBNull))
  904. prim.ParticleSystem = (Byte[])primRow["ParticleSystem"];
  905. prim.RotationalVelocity = new Vector3(
  906. Convert.ToSingle(primRow["OmegaX"]),
  907. Convert.ToSingle(primRow["OmegaY"]),
  908. Convert.ToSingle(primRow["OmegaZ"]));
  909. prim.SetCameraEyeOffset(new Vector3(
  910. Convert.ToSingle(primRow["CameraEyeOffsetX"]),
  911. Convert.ToSingle(primRow["CameraEyeOffsetY"]),
  912. Convert.ToSingle(primRow["CameraEyeOffsetZ"])
  913. ));
  914. prim.SetCameraAtOffset(new Vector3(
  915. Convert.ToSingle(primRow["CameraAtOffsetX"]),
  916. Convert.ToSingle(primRow["CameraAtOffsetY"]),
  917. Convert.ToSingle(primRow["CameraAtOffsetZ"])
  918. ));
  919. if (Convert.ToInt16(primRow["ForceMouselook"]) != 0)
  920. prim.SetForceMouselook(true);
  921. prim.ScriptAccessPin = Convert.ToInt32(primRow["ScriptAccessPin"]);
  922. if (Convert.ToInt16(primRow["AllowedDrop"]) != 0)
  923. prim.AllowedDrop = true;
  924. if (Convert.ToInt16(primRow["DieAtEdge"]) != 0)
  925. prim.DIE_AT_EDGE = true;
  926. prim.SalePrice = Convert.ToInt32(primRow["SalePrice"]);
  927. prim.ObjectSaleType = Convert.ToByte(primRow["SaleType"]);
  928. prim.Material = Convert.ToByte(primRow["Material"]);
  929. if (!(primRow["ClickAction"] is DBNull))
  930. prim.ClickAction = Convert.ToByte(primRow["ClickAction"]);
  931. prim.CollisionSound = new UUID((Guid)primRow["CollisionSound"]);
  932. prim.CollisionSoundVolume = Convert.ToSingle(primRow["CollisionSoundVolume"]);
  933. if (Convert.ToInt16(primRow["PassTouches"]) != 0)
  934. prim.PassTouches = true;
  935. prim.LinkNum = Convert.ToInt32(primRow["LinkNumber"]);
  936. return prim;
  937. }
  938. /// <summary>
  939. /// Builds the prim shape from a datarecord.
  940. /// </summary>
  941. /// <param name="shapeRow">The row.</param>
  942. /// <returns></returns>
  943. private static PrimitiveBaseShape BuildShape(IDataRecord shapeRow)
  944. {
  945. PrimitiveBaseShape baseShape = new PrimitiveBaseShape();
  946. baseShape.Scale = new Vector3(
  947. Convert.ToSingle(shapeRow["ScaleX"]),
  948. Convert.ToSingle(shapeRow["ScaleY"]),
  949. Convert.ToSingle(shapeRow["ScaleZ"]));
  950. // paths
  951. baseShape.PCode = Convert.ToByte(shapeRow["PCode"]);
  952. baseShape.PathBegin = Convert.ToUInt16(shapeRow["PathBegin"]);
  953. baseShape.PathEnd = Convert.ToUInt16(shapeRow["PathEnd"]);
  954. baseShape.PathScaleX = Convert.ToByte(shapeRow["PathScaleX"]);
  955. baseShape.PathScaleY = Convert.ToByte(shapeRow["PathScaleY"]);
  956. baseShape.PathShearX = Convert.ToByte(shapeRow["PathShearX"]);
  957. baseShape.PathShearY = Convert.ToByte(shapeRow["PathShearY"]);
  958. baseShape.PathSkew = Convert.ToSByte(shapeRow["PathSkew"]);
  959. baseShape.PathCurve = Convert.ToByte(shapeRow["PathCurve"]);
  960. baseShape.PathRadiusOffset = Convert.ToSByte(shapeRow["PathRadiusOffset"]);
  961. baseShape.PathRevolutions = Convert.ToByte(shapeRow["PathRevolutions"]);
  962. baseShape.PathTaperX = Convert.ToSByte(shapeRow["PathTaperX"]);
  963. baseShape.PathTaperY = Convert.ToSByte(shapeRow["PathTaperY"]);
  964. baseShape.PathTwist = Convert.ToSByte(shapeRow["PathTwist"]);
  965. baseShape.PathTwistBegin = Convert.ToSByte(shapeRow["PathTwistBegin"]);
  966. // profile
  967. baseShape.ProfileBegin = Convert.ToUInt16(shapeRow["ProfileBegin"]);
  968. baseShape.ProfileEnd = Convert.ToUInt16(shapeRow["ProfileEnd"]);
  969. baseShape.ProfileCurve = Convert.ToByte(shapeRow["ProfileCurve"]);
  970. baseShape.ProfileHollow = Convert.ToUInt16(shapeRow["ProfileHollow"]);
  971. byte[] textureEntry = (byte[])shapeRow["Texture"];
  972. baseShape.TextureEntry = textureEntry;
  973. baseShape.ExtraParams = (byte[])shapeRow["ExtraParams"];
  974. try
  975. {
  976. baseShape.State = Convert.ToByte(shapeRow["State"]);
  977. }
  978. catch (InvalidCastException)
  979. {
  980. }
  981. return baseShape;
  982. }
  983. /// <summary>
  984. /// Build a prim inventory item from the persisted data.
  985. /// </summary>
  986. /// <param name="inventoryRow"></param>
  987. /// <returns></returns>
  988. private static TaskInventoryItem BuildItem(IDataRecord inventoryRow)
  989. {
  990. TaskInventoryItem taskItem = new TaskInventoryItem();
  991. taskItem.ItemID = new UUID((Guid)inventoryRow["itemID"]);
  992. taskItem.ParentPartID = new UUID((Guid)inventoryRow["primID"]);
  993. taskItem.AssetID = new UUID((Guid)inventoryRow["assetID"]);
  994. taskItem.ParentID = new UUID((Guid)inventoryRow["parentFolderID"]);
  995. taskItem.InvType = Convert.ToInt32(inventoryRow["invType"]);
  996. taskItem.Type = Convert.ToInt32(inventoryRow["assetType"]);
  997. taskItem.Name = (string)inventoryRow["name"];
  998. taskItem.Description = (string)inventoryRow["description"];
  999. taskItem.CreationDate = Convert.ToUInt32(inventoryRow["creationDate"]);
  1000. taskItem.CreatorID = new UUID((Guid)inventoryRow["creatorID"]);
  1001. taskItem.OwnerID = new UUID((Guid)inventoryRow["ownerID"]);
  1002. taskItem.LastOwnerID = new UUID((Guid)inventoryRow["lastOwnerID"]);
  1003. taskItem.GroupID = new UUID((Guid)inventoryRow["groupID"]);
  1004. taskItem.NextPermissions = Convert.ToUInt32(inventoryRow["nextPermissions"]);
  1005. taskItem.CurrentPermissions = Convert.ToUInt32(inventoryRow["currentPermissions"]);
  1006. taskItem.BasePermissions = Convert.ToUInt32(inventoryRow["basePermissions"]);
  1007. taskItem.EveryonePermissions = Convert.ToUInt32(inventoryRow["everyonePermissions"]);
  1008. taskItem.GroupPermissions = Convert.ToUInt32(inventoryRow["groupPermissions"]);
  1009. taskItem.Flags = Convert.ToUInt32(inventoryRow["flags"]);
  1010. return taskItem;
  1011. }
  1012. #endregion
  1013. #region Create parameters methods
  1014. /// <summary>
  1015. /// Creates the prim inventory parameters.
  1016. /// </summary>
  1017. /// <param name="taskItem">item in inventory.</param>
  1018. /// <returns></returns>
  1019. private SqlParameter[] CreatePrimInventoryParameters(TaskInventoryItem taskItem)
  1020. {
  1021. List<SqlParameter> parameters = new List<SqlParameter>();
  1022. parameters.Add(_Database.CreateParameter("itemID", taskItem.ItemID));
  1023. parameters.Add(_Database.CreateParameter("primID", taskItem.ParentPartID));
  1024. parameters.Add(_Database.CreateParameter("assetID", taskItem.AssetID));
  1025. parameters.Add(_Database.CreateParameter("parentFolderID", taskItem.ParentID));
  1026. parameters.Add(_Database.CreateParameter("invType", taskItem.InvType));
  1027. parameters.Add(_Database.CreateParameter("assetType", taskItem.Type));
  1028. parameters.Add(_Database.CreateParameter("name", taskItem.Name));
  1029. parameters.Add(_Database.CreateParameter("description", taskItem.Description));
  1030. parameters.Add(_Database.CreateParameter("creationDate", taskItem.CreationDate));
  1031. parameters.Add(_Database.CreateParameter("creatorID", taskItem.CreatorID));
  1032. parameters.Add(_Database.CreateParameter("ownerID", taskItem.OwnerID));
  1033. parameters.Add(_Database.CreateParameter("lastOwnerID", taskItem.LastOwnerID));
  1034. parameters.Add(_Database.CreateParameter("groupID", taskItem.GroupID));
  1035. parameters.Add(_Database.CreateParameter("nextPermissions", taskItem.NextPermissions));
  1036. parameters.Add(_Database.CreateParameter("currentPermissions", taskItem.CurrentPermissions));
  1037. parameters.Add(_Database.CreateParameter("basePermissions", taskItem.BasePermissions));
  1038. parameters.Add(_Database.CreateParameter("everyonePermissions", taskItem.EveryonePermissions));
  1039. parameters.Add(_Database.CreateParameter("groupPermissions", taskItem.GroupPermissions));
  1040. parameters.Add(_Database.CreateParameter("flags", taskItem.Flags));
  1041. return parameters.ToArray();
  1042. }
  1043. /// <summary>
  1044. /// Creates the region setting parameters.
  1045. /// </summary>
  1046. /// <param name="settings">regionsettings.</param>
  1047. /// <returns></returns>
  1048. private SqlParameter[] CreateRegionSettingParameters(RegionSettings settings)
  1049. {
  1050. List<SqlParameter> parameters = new List<SqlParameter>();
  1051. parameters.Add(_Database.CreateParameter("regionUUID", settings.RegionUUID));
  1052. parameters.Add(_Database.CreateParameter("block_terraform", settings.BlockTerraform));
  1053. parameters.Add(_Database.CreateParameter("block_fly", settings.BlockFly));
  1054. parameters.Add(_Database.CreateParameter("allow_damage", settings.AllowDamage));
  1055. parameters.Add(_Database.CreateParameter("restrict_pushing", settings.RestrictPushing));
  1056. parameters.Add(_Database.CreateParameter("allow_land_resell", settings.AllowLandResell));
  1057. parameters.Add(_Database.CreateParameter("allow_land_join_divide", settings.AllowLandJoinDivide));
  1058. parameters.Add(_Database.CreateParameter("block_show_in_search", settings.BlockShowInSearch));
  1059. parameters.Add(_Database.CreateParameter("agent_limit", settings.AgentLimit));
  1060. parameters.Add(_Database.CreateParameter("object_bonus", settings.ObjectBonus));
  1061. parameters.Add(_Database.CreateParameter("maturity", settings.Maturity));
  1062. parameters.Add(_Database.CreateParameter("disable_scripts", settings.DisableScripts));
  1063. parameters.Add(_Database.CreateParameter("disable_collisions", settings.DisableCollisions));
  1064. parameters.Add(_Database.CreateParameter("disable_physics", settings.DisablePhysics));
  1065. parameters.Add(_Database.CreateParameter("terrain_texture_1", settings.TerrainTexture1));
  1066. parameters.Add(_Database.CreateParameter("terrain_texture_2", settings.TerrainTexture2));
  1067. parameters.Add(_Database.CreateParameter("terrain_texture_3", settings.TerrainTexture3));
  1068. parameters.Add(_Database.CreateParameter("terrain_texture_4", settings.TerrainTexture4));
  1069. parameters.Add(_Database.CreateParameter("elevation_1_nw", settings.Elevation1NW));
  1070. parameters.Add(_Database.CreateParameter("elevation_2_nw", settings.Elevation2NW));
  1071. parameters.Add(_Database.CreateParameter("elevation_1_ne", settings.Elevation1NE));
  1072. parameters.Add(_Database.CreateParameter("elevation_2_ne", settings.Elevation2NE));
  1073. parameters.Add(_Database.CreateParameter("elevation_1_se", settings.Elevation1SE));
  1074. parameters.Add(_Database.CreateParameter("elevation_2_se", settings.Elevation2SE));
  1075. parameters.Add(_Database.CreateParameter("elevation_1_sw", settings.Elevation1SW));
  1076. parameters.Add(_Database.CreateParameter("elevation_2_sw", settings.Elevation2SW));
  1077. parameters.Add(_Database.CreateParameter("water_height", settings.WaterHeight));
  1078. parameters.Add(_Database.CreateParameter("terrain_raise_limit", settings.TerrainRaiseLimit));
  1079. parameters.Add(_Database.CreateParameter("terrain_lower_limit", settings.TerrainLowerLimit));
  1080. parameters.Add(_Database.CreateParameter("use_estate_sun", settings.UseEstateSun));
  1081. parameters.Add(_Database.CreateParameter("sandbox", settings.Sandbox));
  1082. parameters.Add(_Database.CreateParameter("fixed_sun", settings.FixedSun));
  1083. parameters.Add(_Database.CreateParameter("sun_position", settings.SunPosition));
  1084. parameters.Add(_Database.CreateParameter("sunvectorx", settings.SunVector.X));
  1085. parameters.Add(_Database.CreateParameter("sunvectory", settings.SunVector.Y));
  1086. parameters.Add(_Database.CreateParameter("sunvectorz", settings.SunVector.Z));
  1087. parameters.Add(_Database.CreateParameter("covenant", settings.Covenant));
  1088. parameters.Add(_Database.CreateParameter("Loaded_Creation_DateTime", settings.LoadedCreationDateTime));
  1089. parameters.Add(_Database.CreateParameter("Loaded_Creation_ID", settings.LoadedCreationID));
  1090. return parameters.ToArray();
  1091. }
  1092. /// <summary>
  1093. /// Creates the land parameters.
  1094. /// </summary>
  1095. /// <param name="land">land parameters.</param>
  1096. /// <param name="regionUUID">region UUID.</param>
  1097. /// <returns></returns>
  1098. private SqlParameter[] CreateLandParameters(LandData land, UUID regionUUID)
  1099. {
  1100. List<SqlParameter> parameters = new List<SqlParameter>();
  1101. parameters.Add(_Database.CreateParameter("UUID", land.GlobalID));
  1102. parameters.Add(_Database.CreateParameter("RegionUUID", regionUUID));
  1103. parameters.Add(_Database.CreateParameter("LocalLandID", land.LocalID));
  1104. // Bitmap is a byte[512]
  1105. parameters.Add(_Database.CreateParameter("Bitmap", land.Bitmap));
  1106. parameters.Add(_Database.CreateParameter("Name", land.Name));
  1107. parameters.Add(_Database.CreateParameter("Description", land.Description));
  1108. parameters.Add(_Database.CreateParameter("OwnerUUID", land.OwnerID));
  1109. parameters.Add(_Database.CreateParameter("IsGroupOwned", land.IsGroupOwned));
  1110. parameters.Add(_Database.CreateParameter("Area", land.Area));
  1111. parameters.Add(_Database.CreateParameter("AuctionID", land.AuctionID)); //Unemplemented
  1112. parameters.Add(_Database.CreateParameter("Category", (int)land.Category)); //Enum libsecondlife.Parcel.ParcelCategory
  1113. parameters.Add(_Database.CreateParameter("ClaimDate", land.ClaimDate));
  1114. parameters.Add(_Database.CreateParameter("ClaimPrice", land.ClaimPrice));
  1115. parameters.Add(_Database.CreateParameter("GroupUUID", land.GroupID));
  1116. parameters.Add(_Database.CreateParameter("SalePrice", land.SalePrice));
  1117. parameters.Add(_Database.CreateParameter("LandStatus", (int)land.Status)); //Enum. libsecondlife.Parcel.ParcelStatus
  1118. parameters.Add(_Database.CreateParameter("LandFlags", land.Flags));
  1119. parameters.Add(_Database.CreateParameter("LandingType", land.LandingType));
  1120. parameters.Add(_Database.CreateParameter("MediaAutoScale", land.MediaAutoScale));
  1121. parameters.Add(_Database.CreateParameter("MediaTextureUUID", land.MediaID));
  1122. parameters.Add(_Database.CreateParameter("MediaURL", land.MediaURL));
  1123. parameters.Add(_Database.CreateParameter("MusicURL", land.MusicURL));
  1124. parameters.Add(_Database.CreateParameter("PassHours", land.PassHours));
  1125. parameters.Add(_Database.CreateParameter("PassPrice", land.PassPrice));
  1126. parameters.Add(_Database.CreateParameter("SnapshotUUID", land.SnapshotID));
  1127. parameters.Add(_Database.CreateParameter("UserLocationX", land.UserLocation.X));
  1128. parameters.Add(_Database.CreateParameter("UserLocationY", land.UserLocation.Y));
  1129. parameters.Add(_Database.CreateParameter("UserLocationZ", land.UserLocation.Z));
  1130. parameters.Add(_Database.CreateParameter("UserLookAtX", land.UserLookAt.X));
  1131. parameters.Add(_Database.CreateParameter("UserLookAtY", land.UserLookAt.Y));
  1132. parameters.Add(_Database.CreateParameter("UserLookAtZ", land.UserLookAt.Z));
  1133. parameters.Add(_Database.CreateParameter("AuthBuyerID", land.AuthBuyerID));
  1134. parameters.Add(_Database.CreateParameter("OtherCleanTime", land.OtherCleanTime));
  1135. parameters.Add(_Database.CreateParameter("Dwell", land.Dwell));
  1136. return parameters.ToArray();
  1137. }
  1138. /// <summary>
  1139. /// Creates the land access parameters.
  1140. /// </summary>
  1141. /// <param name="parcelAccessEntry">parcel access entry.</param>
  1142. /// <param name="parcelID">parcel ID.</param>
  1143. /// <returns></returns>
  1144. private SqlParameter[] CreateLandAccessParameters(ParcelManager.ParcelAccessEntry parcelAccessEntry, UUID parcelID)
  1145. {
  1146. List<SqlParameter> parameters = new List<SqlParameter>();
  1147. parameters.Add(_Database.CreateParameter("LandUUID", parcelID));
  1148. parameters.Add(_Database.CreateParameter("AccessUUID", parcelAccessEntry.AgentID));
  1149. parameters.Add(_Database.CreateParameter("Flags", parcelAccessEntry.Flags));
  1150. return parameters.ToArray();
  1151. }
  1152. /// <summary>
  1153. /// Creates the prim parameters for storing in DB.
  1154. /// </summary>
  1155. /// <param name="prim">Basic data of SceneObjectpart prim.</param>
  1156. /// <param name="sceneGroupID">The scenegroup ID.</param>
  1157. /// <param name="regionUUID">The region ID.</param>
  1158. /// <returns></returns>
  1159. private SqlParameter[] CreatePrimParameters(SceneObjectPart prim, UUID sceneGroupID, UUID regionUUID)
  1160. {
  1161. List<SqlParameter> parameters = new List<SqlParameter>();
  1162. parameters.Add(_Database.CreateParameter("UUID", prim.UUID));
  1163. parameters.Add(_Database.CreateParameter("RegionUUID", regionUUID));
  1164. parameters.Add(_Database.CreateParameter("CreationDate", prim.CreationDate));
  1165. parameters.Add(_Database.CreateParameter("Name", prim.Name));
  1166. parameters.Add(_Database.CreateParameter("SceneGroupID", sceneGroupID));
  1167. // the UUID of the root part for this SceneObjectGroup
  1168. // various text fields
  1169. parameters.Add(_Database.CreateParameter("Text", prim.Text));
  1170. parameters.Add(_Database.CreateParameter("ColorR", prim.Color.R));
  1171. parameters.Add(_Database.CreateParameter("ColorG", prim.Color.G));
  1172. parameters.Add(_Database.CreateParameter("ColorB", prim.Color.B));
  1173. parameters.Add(_Database.CreateParameter("ColorA", prim.Color.A));
  1174. parameters.Add(_Database.CreateParameter("Description", prim.Description));
  1175. parameters.Add(_Database.CreateParameter("SitName", prim.SitName));
  1176. parameters.Add(_Database.CreateParameter("TouchName", prim.TouchName));
  1177. // permissions
  1178. parameters.Add(_Database.CreateParameter("ObjectFlags", prim.ObjectFlags));
  1179. parameters.Add(_Database.CreateParameter("CreatorID", prim.CreatorID));
  1180. parameters.Add(_Database.CreateParameter("OwnerID", prim.OwnerID));
  1181. parameters.Add(_Database.CreateParameter("GroupID", prim.GroupID));
  1182. parameters.Add(_Database.CreateParameter("LastOwnerID", prim.LastOwnerID));
  1183. parameters.Add(_Database.CreateParameter("OwnerMask", prim.OwnerMask));
  1184. parameters.Add(_Database.CreateParameter("NextOwnerMask", prim.NextOwnerMask));
  1185. parameters.Add(_Database.CreateParameter("GroupMask", prim.GroupMask));
  1186. parameters.Add(_Database.CreateParameter("EveryoneMask", prim.EveryoneMask));
  1187. parameters.Add(_Database.CreateParameter("BaseMask", prim.BaseMask));
  1188. // vectors
  1189. parameters.Add(_Database.CreateParameter("PositionX", prim.OffsetPosition.X));
  1190. parameters.Add(_Database.CreateParameter("PositionY", prim.OffsetPosition.Y));
  1191. parameters.Add(_Database.CreateParameter("PositionZ", prim.OffsetPosition.Z));
  1192. parameters.Add(_Database.CreateParameter("GroupPositionX", prim.GroupPosition.X));
  1193. parameters.Add(_Database.CreateParameter("GroupPositionY", prim.GroupPosition.Y));
  1194. parameters.Add(_Database.CreateParameter("GroupPositionZ", prim.GroupPosition.Z));
  1195. parameters.Add(_Database.CreateParameter("VelocityX", prim.Velocity.X));
  1196. parameters.Add(_Database.CreateParameter("VelocityY", prim.Velocity.Y));
  1197. parameters.Add(_Database.CreateParameter("VelocityZ", prim.Velocity.Z));
  1198. parameters.Add(_Database.CreateParameter("AngularVelocityX", prim.AngularVelocity.X));
  1199. parameters.Add(_Database.CreateParameter("AngularVelocityY", prim.AngularVelocity.Y));
  1200. parameters.Add(_Database.CreateParameter("AngularVelocityZ", prim.AngularVelocity.Z));
  1201. parameters.Add(_Database.CreateParameter("AccelerationX", prim.Acceleration.X));
  1202. parameters.Add(_Database.CreateParameter("AccelerationY", prim.Acceleration.Y));
  1203. parameters.Add(_Database.CreateParameter("AccelerationZ", prim.Acceleration.Z));
  1204. // quaternions
  1205. parameters.Add(_Database.CreateParameter("RotationX", prim.RotationOffset.X));
  1206. parameters.Add(_Database.CreateParameter("RotationY", prim.RotationOffset.Y));
  1207. parameters.Add(_Database.CreateParameter("RotationZ", prim.RotationOffset.Z));
  1208. parameters.Add(_Database.CreateParameter("RotationW", prim.RotationOffset.W));
  1209. // Sit target
  1210. Vector3 sitTargetPos = prim.SitTargetPositionLL;
  1211. parameters.Add(_Database.CreateParameter("SitTargetOffsetX", sitTargetPos.X));
  1212. parameters.Add(_Database.CreateParameter("SitTargetOffsetY", sitTargetPos.Y));
  1213. parameters.Add(_Database.CreateParameter("SitTargetOffsetZ", sitTargetPos.Z));
  1214. Quaternion sitTargetOrient = prim.SitTargetOrientationLL;
  1215. parameters.Add(_Database.CreateParameter("SitTargetOrientW", sitTargetOrient.W));
  1216. parameters.Add(_Database.CreateParameter("SitTargetOrientX", sitTargetOrient.X));
  1217. parameters.Add(_Database.CreateParameter("SitTargetOrientY", sitTargetOrient.Y));
  1218. parameters.Add(_Database.CreateParameter("SitTargetOrientZ", sitTargetOrient.Z));
  1219. parameters.Add(_Database.CreateParameter("PayPrice", prim.PayPrice[0]));
  1220. parameters.Add(_Database.CreateParameter("PayButton1", prim.PayPrice[1]));
  1221. parameters.Add(_Database.CreateParameter("PayButton2", prim.PayPrice[2]));
  1222. parameters.Add(_Database.CreateParameter("PayButton3", prim.PayPrice[3]));
  1223. parameters.Add(_Database.CreateParameter("PayButton4", prim.PayPrice[4]));
  1224. if ((prim.SoundFlags & 1) != 0) // Looped
  1225. {
  1226. parameters.Add(_Database.CreateParameter("LoopedSound", prim.Sound));
  1227. parameters.Add(_Database.CreateParameter("LoopedSoundGain", prim.SoundGain));
  1228. }
  1229. else
  1230. {
  1231. parameters.Add(_Database.CreateParameter("LoopedSound", UUID.Zero));
  1232. parameters.Add(_Database.CreateParameter("LoopedSoundGain", 0.0f));
  1233. }
  1234. parameters.Add(_Database.CreateParameter("TextureAnimation", prim.TextureAnimation));
  1235. parameters.Add(_Database.CreateParameter("ParticleSystem", prim.ParticleSystem));
  1236. parameters.Add(_Database.CreateParameter("OmegaX", prim.RotationalVelocity.X));
  1237. parameters.Add(_Database.CreateParameter("OmegaY", prim.RotationalVelocity.Y));
  1238. parameters.Add(_Database.CreateParameter("OmegaZ", prim.RotationalVelocity.Z));
  1239. parameters.Add(_Database.CreateParameter("CameraEyeOffsetX", prim.GetCameraEyeOffset().X));
  1240. parameters.Add(_Database.CreateParameter("CameraEyeOffsetY", prim.GetCameraEyeOffset().Y));
  1241. parameters.Add(_Database.CreateParameter("CameraEyeOffsetZ", prim.GetCameraEyeOffset().Z));
  1242. parameters.Add(_Database.CreateParameter("CameraAtOffsetX", prim.GetCameraAtOffset().X));
  1243. parameters.Add(_Database.CreateParameter("CameraAtOffsetY", prim.GetCameraAtOffset().Y));
  1244. parameters.Add(_Database.CreateParameter("CameraAtOffsetZ", prim.GetCameraAtOffset().Z));
  1245. if (prim.GetForceMouselook())
  1246. parameters.Add(_Database.CreateParameter("ForceMouselook", 1));
  1247. else
  1248. parameters.Add(_Database.CreateParameter("ForceMouselook", 0));
  1249. parameters.Add(_Database.CreateParameter("ScriptAccessPin", prim.ScriptAccessPin));
  1250. if (prim.AllowedDrop)
  1251. parameters.Add(_Database.CreateParameter("AllowedDrop", 1));
  1252. else
  1253. parameters.Add(_Database.CreateParameter("AllowedDrop", 0));
  1254. if (prim.DIE_AT_EDGE)
  1255. parameters.Add(_Database.CreateParameter("DieAtEdge", 1));
  1256. else
  1257. parameters.Add(_Database.CreateParameter("DieAtEdge", 0));
  1258. parameters.Add(_Database.CreateParameter("SalePrice", prim.SalePrice));
  1259. parameters.Add(_Database.CreateParameter("SaleType", prim.ObjectSaleType));
  1260. byte clickAction = prim.ClickAction;
  1261. parameters.Add(_Database.CreateParameter("ClickAction", clickAction));
  1262. parameters.Add(_Database.CreateParameter("Material", prim.Material));
  1263. parameters.Add(_Database.CreateParameter("CollisionSound", prim.CollisionSound));
  1264. parameters.Add(_Database.CreateParameter("CollisionSoundVolume", prim.CollisionSoundVolume));
  1265. if (prim.PassTouches)
  1266. parameters.Add(_Database.CreateParameter("PassTouches", 1));
  1267. else
  1268. parameters.Add(_Database.CreateParameter("PassTouches", 0));
  1269. parameters.Add(_Database.CreateParameter("LinkNumber", prim.LinkNum));
  1270. return parameters.ToArray();
  1271. }
  1272. /// <summary>
  1273. /// Creates the primshape parameters for stroing in DB.
  1274. /// </summary>
  1275. /// <param name="prim">Basic data of SceneObjectpart prim.</param>
  1276. /// <param name="sceneGroupID">The scene group ID.</param>
  1277. /// <param name="regionUUID">The region UUID.</param>
  1278. /// <returns></returns>
  1279. private SqlParameter[] CreatePrimShapeParameters(SceneObjectPart prim, UUID sceneGroupID, UUID regionUUID)
  1280. {
  1281. List<SqlParameter> parameters = new List<SqlParameter>();
  1282. PrimitiveBaseShape s = prim.Shape;
  1283. parameters.Add(_Database.CreateParameter("UUID", prim.UUID));
  1284. // shape is an enum
  1285. parameters.Add(_Database.CreateParameter("Shape", 0));
  1286. // vectors
  1287. parameters.Add(_Database.CreateParameter("ScaleX", s.Scale.X));
  1288. parameters.Add(_Database.CreateParameter("ScaleY", s.Scale.Y));
  1289. parameters.Add(_Database.CreateParameter("ScaleZ", s.Scale.Z));
  1290. // paths
  1291. parameters.Add(_Database.CreateParameter("PCode", s.PCode));
  1292. parameters.Add(_Database.CreateParameter("PathBegin", s.PathBegin));
  1293. parameters.Add(_Database.CreateParameter("PathEnd", s.PathEnd));
  1294. parameters.Add(_Database.CreateParameter("PathScaleX", s.PathScaleX));
  1295. parameters.Add(_Database.CreateParameter("PathScaleY", s.PathScaleY));
  1296. parameters.Add(_Database.CreateParameter("PathShearX", s.PathShearX));
  1297. parameters.Add(_Database.CreateParameter("PathShearY", s.PathShearY));
  1298. parameters.Add(_Database.CreateParameter("PathSkew", s.PathSkew));
  1299. parameters.Add(_Database.CreateParameter("PathCurve", s.PathCurve));
  1300. parameters.Add(_Database.CreateParameter("PathRadiusOffset", s.PathRadiusOffset));
  1301. parameters.Add(_Database.CreateParameter("PathRevolutions", s.PathRevolutions));
  1302. parameters.Add(_Database.CreateParameter("PathTaperX", s.PathTaperX));
  1303. parameters.Add(_Database.CreateParameter("PathTaperY", s.PathTaperY));
  1304. parameters.Add(_Database.CreateParameter("PathTwist", s.PathTwist));
  1305. parameters.Add(_Database.CreateParameter("PathTwistBegin", s.PathTwistBegin));
  1306. // profile
  1307. parameters.Add(_Database.CreateParameter("ProfileBegin", s.ProfileBegin));
  1308. parameters.Add(_Database.CreateParameter("ProfileEnd", s.ProfileEnd));
  1309. parameters.Add(_Database.CreateParameter("ProfileCurve", s.ProfileCurve));
  1310. parameters.Add(_Database.CreateParameter("ProfileHollow", s.ProfileHollow));
  1311. parameters.Add(_Database.CreateParameter("Texture", s.TextureEntry));
  1312. parameters.Add(_Database.CreateParameter("ExtraParams", s.ExtraParams));
  1313. parameters.Add(_Database.CreateParameter("State", s.State));
  1314. return parameters.ToArray();
  1315. }
  1316. #endregion
  1317. #endregion
  1318. }
  1319. }