MSSQLRegionData.cs 78 KB

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