MSSQLLegacyRegionData.cs 83 KB

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