MSSQLSimulationData.cs 116 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081
  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 MSSQLSimulationData : ISimulationDataStore
  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. protected virtual Assembly Assembly
  55. {
  56. get { return GetType().Assembly; }
  57. }
  58. public MSSQLSimulationData()
  59. {
  60. }
  61. public MSSQLSimulationData(string connectionString)
  62. {
  63. Initialise(connectionString);
  64. }
  65. /// <summary>
  66. /// Initialises the region datastore
  67. /// </summary>
  68. /// <param name="connectionString">The connection string.</param>
  69. public void Initialise(string connectionString)
  70. {
  71. m_connectionString = connectionString;
  72. _Database = new MSSQLManager(connectionString);
  73. using (SqlConnection conn = new SqlConnection(connectionString))
  74. {
  75. conn.Open();
  76. //New Migration settings
  77. Migration m = new Migration(conn, Assembly, "RegionStore");
  78. m.Update();
  79. // Clean dropped attachments
  80. //
  81. try
  82. {
  83. using (SqlCommand cmd = conn.CreateCommand())
  84. {
  85. cmd.CommandText = "delete from prims where prims.UUID in (select UUID from primshapes where PCode = 9 and State <> 0); delete from primshapes where PCode = 9 and State <> 0";
  86. cmd.ExecuteNonQuery();
  87. }
  88. }
  89. catch (Exception ex)
  90. {
  91. _Log.Error("[REGION DB]: Error cleaning up dropped attachments: " + ex.Message);
  92. }
  93. }
  94. }
  95. /// <summary>
  96. /// Dispose the database
  97. /// </summary>
  98. public void Dispose() { }
  99. #region SceneObjectGroup region for loading and Store of the scene.
  100. /// <summary>
  101. /// Loads the objects present in the region.
  102. /// </summary>
  103. /// <param name="regionUUID">The region UUID.</param>
  104. /// <returns></returns>
  105. public List<SceneObjectGroup> LoadObjects(UUID regionUUID)
  106. {
  107. UUID lastGroupID = UUID.Zero;
  108. Dictionary<UUID, SceneObjectPart> prims = new Dictionary<UUID, SceneObjectPart>();
  109. Dictionary<UUID, SceneObjectGroup> objects = new Dictionary<UUID, SceneObjectGroup>();
  110. SceneObjectGroup grp = null;
  111. string sql = "SELECT *, " +
  112. "sort = CASE WHEN prims.UUID = prims.SceneGroupID THEN 0 ELSE 1 END " +
  113. "FROM prims " +
  114. "LEFT JOIN primshapes ON prims.UUID = primshapes.UUID " +
  115. "WHERE RegionUUID = @RegionUUID " +
  116. "ORDER BY SceneGroupID asc, sort asc, LinkNumber asc";
  117. using (SqlConnection conn = new SqlConnection(m_connectionString))
  118. using (SqlCommand command = new SqlCommand(sql, conn))
  119. {
  120. command.Parameters.Add(_Database.CreateParameter("@regionUUID", regionUUID));
  121. conn.Open();
  122. using (SqlDataReader reader = command.ExecuteReader())
  123. {
  124. while (reader.Read())
  125. {
  126. SceneObjectPart sceneObjectPart = BuildPrim(reader);
  127. if (reader["Shape"] is DBNull)
  128. sceneObjectPart.Shape = PrimitiveBaseShape.Default;
  129. else
  130. sceneObjectPart.Shape = BuildShape(reader);
  131. prims[sceneObjectPart.UUID] = sceneObjectPart;
  132. UUID groupID = new UUID((Guid)reader["SceneGroupID"]);
  133. if (groupID != lastGroupID) // New SOG
  134. {
  135. if (grp != null)
  136. objects[grp.UUID] = grp;
  137. lastGroupID = groupID;
  138. // There sometimes exist OpenSim bugs that 'orphan groups' so that none of the prims are
  139. // recorded as the root prim (for which the UUID must equal the persisted group UUID). In
  140. // this case, force the UUID to be the same as the group UUID so that at least these can be
  141. // deleted (we need to change the UUID so that any other prims in the linkset can also be
  142. // deleted).
  143. if (sceneObjectPart.UUID != groupID && groupID != UUID.Zero)
  144. {
  145. _Log.WarnFormat(
  146. "[REGION DB]: Found root prim {0} {1} at {2} where group was actually {3}. Forcing UUID to group UUID",
  147. sceneObjectPart.Name, sceneObjectPart.UUID, sceneObjectPart.GroupPosition, groupID);
  148. sceneObjectPart.UUID = groupID;
  149. }
  150. grp = new SceneObjectGroup(sceneObjectPart);
  151. }
  152. else
  153. {
  154. // Black magic to preserve link numbers
  155. // Why is this needed, fix this in AddPart method.
  156. int link = sceneObjectPart.LinkNum;
  157. grp.AddPart(sceneObjectPart);
  158. if (link != 0)
  159. sceneObjectPart.LinkNum = link;
  160. }
  161. }
  162. }
  163. }
  164. if (grp != null)
  165. objects[grp.UUID] = grp;
  166. // Instead of attempting to LoadItems on every prim,
  167. // most of which probably have no items... get a
  168. // list from DB of all prims which have items and
  169. // LoadItems only on those
  170. List<SceneObjectPart> primsWithInventory = new List<SceneObjectPart>();
  171. string qry = "select distinct primID from primitems";
  172. using (SqlConnection conn = new SqlConnection(m_connectionString))
  173. using (SqlCommand command = new SqlCommand(qry, conn))
  174. {
  175. conn.Open();
  176. using (SqlDataReader itemReader = command.ExecuteReader())
  177. {
  178. while (itemReader.Read())
  179. {
  180. if (!(itemReader["primID"] is DBNull))
  181. {
  182. UUID primID = new UUID(itemReader["primID"].ToString());
  183. if (prims.ContainsKey(primID))
  184. {
  185. primsWithInventory.Add(prims[primID]);
  186. }
  187. }
  188. }
  189. }
  190. }
  191. LoadItems(primsWithInventory);
  192. _Log.DebugFormat("[REGION DB]: Loaded {0} objects using {1} prims", objects.Count, prims.Count);
  193. return new List<SceneObjectGroup>(objects.Values);
  194. }
  195. /// <summary>
  196. /// Load in the prim's persisted inventory.
  197. /// </summary>
  198. /// <param name="allPrims">all prims with inventory on a region</param>
  199. private void LoadItems(List<SceneObjectPart> allPrimsWithInventory)
  200. {
  201. string sql = "SELECT * FROM primitems WHERE PrimID = @PrimID";
  202. using (SqlConnection conn = new SqlConnection(m_connectionString))
  203. using (SqlCommand command = new SqlCommand(sql, conn))
  204. {
  205. conn.Open();
  206. foreach (SceneObjectPart objectPart in allPrimsWithInventory)
  207. {
  208. command.Parameters.Clear();
  209. command.Parameters.Add(_Database.CreateParameter("@PrimID", objectPart.UUID));
  210. List<TaskInventoryItem> inventory = new List<TaskInventoryItem>();
  211. using (SqlDataReader reader = command.ExecuteReader())
  212. {
  213. while (reader.Read())
  214. {
  215. TaskInventoryItem item = BuildItem(reader);
  216. item.ParentID = objectPart.UUID; // Values in database are
  217. // often wrong
  218. inventory.Add(item);
  219. }
  220. }
  221. objectPart.Inventory.RestoreInventoryItems(inventory);
  222. }
  223. }
  224. }
  225. /// <summary>
  226. /// Stores all object's details apart from inventory
  227. /// </summary>
  228. /// <param name="obj"></param>
  229. /// <param name="regionUUID"></param>
  230. public void StoreObject(SceneObjectGroup obj, UUID regionUUID)
  231. {
  232. uint flags = obj.RootPart.GetEffectiveObjectFlags();
  233. // Eligibility check
  234. //
  235. if ((flags & (uint)PrimFlags.Temporary) != 0)
  236. return;
  237. if ((flags & (uint)PrimFlags.TemporaryOnRez) != 0)
  238. return;
  239. _Log.DebugFormat("[MSSQL]: Adding/Changing SceneObjectGroup: {0} to region: {1}, object has {2} prims.", obj.UUID, regionUUID, obj.Parts.Length);
  240. using (SqlConnection conn = new SqlConnection(m_connectionString))
  241. {
  242. conn.Open();
  243. SqlTransaction transaction = conn.BeginTransaction();
  244. try
  245. {
  246. foreach (SceneObjectPart sceneObjectPart in obj.Parts)
  247. {
  248. //Update prim
  249. using (SqlCommand sqlCommand = conn.CreateCommand())
  250. {
  251. sqlCommand.Transaction = transaction;
  252. try
  253. {
  254. StoreSceneObjectPrim(sceneObjectPart, sqlCommand, obj.UUID, regionUUID);
  255. }
  256. catch (SqlException sqlEx)
  257. {
  258. _Log.ErrorFormat("[REGION DB]: Store SceneObjectPrim SQL error: {0} at line {1}", sqlEx.Message, sqlEx.LineNumber);
  259. throw;
  260. }
  261. }
  262. //Update primshapes
  263. using (SqlCommand sqlCommand = conn.CreateCommand())
  264. {
  265. sqlCommand.Transaction = transaction;
  266. try
  267. {
  268. StoreSceneObjectPrimShapes(sceneObjectPart, sqlCommand, obj.UUID, regionUUID);
  269. }
  270. catch (SqlException sqlEx)
  271. {
  272. _Log.ErrorFormat("[REGION DB]: Store SceneObjectPrimShapes SQL error: {0} at line {1}", sqlEx.Message, sqlEx.LineNumber);
  273. throw;
  274. }
  275. }
  276. }
  277. transaction.Commit();
  278. }
  279. catch (Exception ex)
  280. {
  281. _Log.ErrorFormat("[REGION DB]: Store SceneObjectGroup error: {0}, Rolling back...", ex.Message);
  282. try
  283. {
  284. transaction.Rollback();
  285. }
  286. catch (Exception ex2)
  287. {
  288. //Show error
  289. _Log.InfoFormat("[REGION DB]: Rollback of SceneObjectGroup store transaction failed with error: {0}", ex2.Message);
  290. }
  291. }
  292. }
  293. }
  294. /// <summary>
  295. /// Stores the prim of the sceneobjectpart.
  296. /// </summary>
  297. /// <param name="sceneObjectPart">The sceneobjectpart or prim.</param>
  298. /// <param name="sqlCommand">The SQL command with the transaction.</param>
  299. /// <param name="sceneGroupID">The scenegroup UUID.</param>
  300. /// <param name="regionUUID">The region UUID.</param>
  301. private void StoreSceneObjectPrim(SceneObjectPart sceneObjectPart, SqlCommand sqlCommand, UUID sceneGroupID, UUID regionUUID)
  302. {
  303. //Big query to update or insert a new prim.
  304. //Note for SQL Server 2008 this could be simplified
  305. string queryPrims = @"
  306. IF EXISTS (SELECT UUID FROM prims WHERE UUID = @UUID)
  307. BEGIN
  308. UPDATE prims SET
  309. CreationDate = @CreationDate, Name = @Name, Text = @Text, Description = @Description, SitName = @SitName,
  310. TouchName = @TouchName, ObjectFlags = @ObjectFlags, OwnerMask = @OwnerMask, NextOwnerMask = @NextOwnerMask, GroupMask = @GroupMask,
  311. EveryoneMask = @EveryoneMask, BaseMask = @BaseMask, PositionX = @PositionX, PositionY = @PositionY, PositionZ = @PositionZ,
  312. GroupPositionX = @GroupPositionX, GroupPositionY = @GroupPositionY, GroupPositionZ = @GroupPositionZ, VelocityX = @VelocityX,
  313. VelocityY = @VelocityY, VelocityZ = @VelocityZ, AngularVelocityX = @AngularVelocityX, AngularVelocityY = @AngularVelocityY,
  314. AngularVelocityZ = @AngularVelocityZ, AccelerationX = @AccelerationX, AccelerationY = @AccelerationY,
  315. AccelerationZ = @AccelerationZ, RotationX = @RotationX, RotationY = @RotationY, RotationZ = @RotationZ, RotationW = @RotationW,
  316. SitTargetOffsetX = @SitTargetOffsetX, SitTargetOffsetY = @SitTargetOffsetY, SitTargetOffsetZ = @SitTargetOffsetZ,
  317. SitTargetOrientW = @SitTargetOrientW, SitTargetOrientX = @SitTargetOrientX, SitTargetOrientY = @SitTargetOrientY,
  318. SitTargetOrientZ = @SitTargetOrientZ, RegionUUID = @RegionUUID, CreatorID = @CreatorID, OwnerID = @OwnerID, GroupID = @GroupID,
  319. LastOwnerID = @LastOwnerID, SceneGroupID = @SceneGroupID, PayPrice = @PayPrice, PayButton1 = @PayButton1, PayButton2 = @PayButton2,
  320. PayButton3 = @PayButton3, PayButton4 = @PayButton4, LoopedSound = @LoopedSound, LoopedSoundGain = @LoopedSoundGain,
  321. TextureAnimation = @TextureAnimation, OmegaX = @OmegaX, OmegaY = @OmegaY, OmegaZ = @OmegaZ, CameraEyeOffsetX = @CameraEyeOffsetX,
  322. CameraEyeOffsetY = @CameraEyeOffsetY, CameraEyeOffsetZ = @CameraEyeOffsetZ, CameraAtOffsetX = @CameraAtOffsetX,
  323. CameraAtOffsetY = @CameraAtOffsetY, CameraAtOffsetZ = @CameraAtOffsetZ, ForceMouselook = @ForceMouselook,
  324. ScriptAccessPin = @ScriptAccessPin, AllowedDrop = @AllowedDrop, DieAtEdge = @DieAtEdge, SalePrice = @SalePrice,
  325. SaleType = @SaleType, ColorR = @ColorR, ColorG = @ColorG, ColorB = @ColorB, ColorA = @ColorA, ParticleSystem = @ParticleSystem,
  326. ClickAction = @ClickAction, Material = @Material, CollisionSound = @CollisionSound, CollisionSoundVolume = @CollisionSoundVolume, PassTouches = @PassTouches,
  327. LinkNumber = @LinkNumber, MediaURL = @MediaURL
  328. WHERE UUID = @UUID
  329. END
  330. ELSE
  331. BEGIN
  332. INSERT INTO
  333. prims (
  334. UUID, CreationDate, Name, Text, Description, SitName, TouchName, ObjectFlags, OwnerMask, NextOwnerMask, GroupMask,
  335. EveryoneMask, BaseMask, PositionX, PositionY, PositionZ, GroupPositionX, GroupPositionY, GroupPositionZ, VelocityX,
  336. VelocityY, VelocityZ, AngularVelocityX, AngularVelocityY, AngularVelocityZ, AccelerationX, AccelerationY, AccelerationZ,
  337. RotationX, RotationY, RotationZ, RotationW, SitTargetOffsetX, SitTargetOffsetY, SitTargetOffsetZ, SitTargetOrientW,
  338. SitTargetOrientX, SitTargetOrientY, SitTargetOrientZ, RegionUUID, CreatorID, OwnerID, GroupID, LastOwnerID, SceneGroupID,
  339. PayPrice, PayButton1, PayButton2, PayButton3, PayButton4, LoopedSound, LoopedSoundGain, TextureAnimation, OmegaX,
  340. OmegaY, OmegaZ, CameraEyeOffsetX, CameraEyeOffsetY, CameraEyeOffsetZ, CameraAtOffsetX, CameraAtOffsetY, CameraAtOffsetZ,
  341. ForceMouselook, ScriptAccessPin, AllowedDrop, DieAtEdge, SalePrice, SaleType, ColorR, ColorG, ColorB, ColorA,
  342. ParticleSystem, ClickAction, Material, CollisionSound, CollisionSoundVolume, PassTouches, LinkNumber, MediaURL
  343. ) VALUES (
  344. @UUID, @CreationDate, @Name, @Text, @Description, @SitName, @TouchName, @ObjectFlags, @OwnerMask, @NextOwnerMask, @GroupMask,
  345. @EveryoneMask, @BaseMask, @PositionX, @PositionY, @PositionZ, @GroupPositionX, @GroupPositionY, @GroupPositionZ, @VelocityX,
  346. @VelocityY, @VelocityZ, @AngularVelocityX, @AngularVelocityY, @AngularVelocityZ, @AccelerationX, @AccelerationY, @AccelerationZ,
  347. @RotationX, @RotationY, @RotationZ, @RotationW, @SitTargetOffsetX, @SitTargetOffsetY, @SitTargetOffsetZ, @SitTargetOrientW,
  348. @SitTargetOrientX, @SitTargetOrientY, @SitTargetOrientZ, @RegionUUID, @CreatorID, @OwnerID, @GroupID, @LastOwnerID, @SceneGroupID,
  349. @PayPrice, @PayButton1, @PayButton2, @PayButton3, @PayButton4, @LoopedSound, @LoopedSoundGain, @TextureAnimation, @OmegaX,
  350. @OmegaY, @OmegaZ, @CameraEyeOffsetX, @CameraEyeOffsetY, @CameraEyeOffsetZ, @CameraAtOffsetX, @CameraAtOffsetY, @CameraAtOffsetZ,
  351. @ForceMouselook, @ScriptAccessPin, @AllowedDrop, @DieAtEdge, @SalePrice, @SaleType, @ColorR, @ColorG, @ColorB, @ColorA,
  352. @ParticleSystem, @ClickAction, @Material, @CollisionSound, @CollisionSoundVolume, @PassTouches, @LinkNumber, @MediaURL
  353. )
  354. END";
  355. //Set commandtext.
  356. sqlCommand.CommandText = queryPrims;
  357. //Add parameters
  358. sqlCommand.Parameters.AddRange(CreatePrimParameters(sceneObjectPart, sceneGroupID, regionUUID));
  359. //Execute the query. If it fails then error is trapped in calling function
  360. sqlCommand.ExecuteNonQuery();
  361. }
  362. /// <summary>
  363. /// Stores the scene object prim shapes.
  364. /// </summary>
  365. /// <param name="sceneObjectPart">The sceneobjectpart containing prim shape.</param>
  366. /// <param name="sqlCommand">The SQL command with the transaction.</param>
  367. /// <param name="sceneGroupID">The scenegroup UUID.</param>
  368. /// <param name="regionUUID">The region UUID.</param>
  369. private void StoreSceneObjectPrimShapes(SceneObjectPart sceneObjectPart, SqlCommand sqlCommand, UUID sceneGroupID, UUID regionUUID)
  370. {
  371. //Big query to or insert or update primshapes
  372. //Note for SQL Server 2008 this can be simplified
  373. string queryPrimShapes = @"
  374. IF EXISTS (SELECT UUID FROM primshapes WHERE UUID = @UUID)
  375. BEGIN
  376. UPDATE primshapes SET
  377. Shape = @Shape, ScaleX = @ScaleX, ScaleY = @ScaleY, ScaleZ = @ScaleZ, PCode = @PCode, PathBegin = @PathBegin,
  378. PathEnd = @PathEnd, PathScaleX = @PathScaleX, PathScaleY = @PathScaleY, PathShearX = @PathShearX, PathShearY = @PathShearY,
  379. PathSkew = @PathSkew, PathCurve = @PathCurve, PathRadiusOffset = @PathRadiusOffset, PathRevolutions = @PathRevolutions,
  380. PathTaperX = @PathTaperX, PathTaperY = @PathTaperY, PathTwist = @PathTwist, PathTwistBegin = @PathTwistBegin,
  381. ProfileBegin = @ProfileBegin, ProfileEnd = @ProfileEnd, ProfileCurve = @ProfileCurve, ProfileHollow = @ProfileHollow,
  382. Texture = @Texture, ExtraParams = @ExtraParams, State = @State, Media = @Media
  383. WHERE UUID = @UUID
  384. END
  385. ELSE
  386. BEGIN
  387. INSERT INTO
  388. primshapes (
  389. UUID, Shape, ScaleX, ScaleY, ScaleZ, PCode, PathBegin, PathEnd, PathScaleX, PathScaleY, PathShearX, PathShearY,
  390. PathSkew, PathCurve, PathRadiusOffset, PathRevolutions, PathTaperX, PathTaperY, PathTwist, PathTwistBegin, ProfileBegin,
  391. ProfileEnd, ProfileCurve, ProfileHollow, Texture, ExtraParams, State, Media
  392. ) VALUES (
  393. @UUID, @Shape, @ScaleX, @ScaleY, @ScaleZ, @PCode, @PathBegin, @PathEnd, @PathScaleX, @PathScaleY, @PathShearX, @PathShearY,
  394. @PathSkew, @PathCurve, @PathRadiusOffset, @PathRevolutions, @PathTaperX, @PathTaperY, @PathTwist, @PathTwistBegin, @ProfileBegin,
  395. @ProfileEnd, @ProfileCurve, @ProfileHollow, @Texture, @ExtraParams, @State, @Media
  396. )
  397. END";
  398. //Set commandtext.
  399. sqlCommand.CommandText = queryPrimShapes;
  400. //Add parameters
  401. sqlCommand.Parameters.AddRange(CreatePrimShapeParameters(sceneObjectPart, sceneGroupID, regionUUID));
  402. //Execute the query. If it fails then error is trapped in calling function
  403. sqlCommand.ExecuteNonQuery();
  404. }
  405. /// <summary>
  406. /// Removes a object from the database.
  407. /// Meaning removing it from tables Prims, PrimShapes and PrimItems
  408. /// </summary>
  409. /// <param name="objectID">id of scenegroup</param>
  410. /// <param name="regionUUID">regionUUID (is this used anyway</param>
  411. public void RemoveObject(UUID objectID, UUID regionUUID)
  412. {
  413. _Log.InfoFormat("[MSSQL]: Removing obj: {0} from region: {1}", objectID, regionUUID);
  414. //Remove from prims and primsitem table
  415. string sqlPrims = "DELETE FROM PRIMS WHERE SceneGroupID = @objectID";
  416. string sqlPrimItems = "DELETE FROM PRIMITEMS WHERE primID in (SELECT UUID FROM PRIMS WHERE SceneGroupID = @objectID)";
  417. string sqlPrimShapes = "DELETE FROM PRIMSHAPES WHERE uuid in (SELECT UUID FROM PRIMS WHERE SceneGroupID = @objectID)";
  418. lock (_Database)
  419. {
  420. //Using the non transaction mode.
  421. using (SqlConnection conn = new SqlConnection(m_connectionString))
  422. using (SqlCommand cmd = new SqlCommand())
  423. {
  424. cmd.Connection = conn;
  425. cmd.CommandText = sqlPrimShapes;
  426. conn.Open();
  427. cmd.Parameters.Add(_Database.CreateParameter("objectID", objectID));
  428. cmd.ExecuteNonQuery();
  429. cmd.CommandText = sqlPrimItems;
  430. cmd.ExecuteNonQuery();
  431. cmd.CommandText = sqlPrims;
  432. cmd.ExecuteNonQuery();
  433. }
  434. }
  435. }
  436. /// <summary>
  437. /// Store the inventory of a prim. Warning deletes everything first and then adds all again.
  438. /// </summary>
  439. /// <param name="primID"></param>
  440. /// <param name="items"></param>
  441. public void StorePrimInventory(UUID primID, ICollection<TaskInventoryItem> items)
  442. {
  443. //_Log.InfoFormat("[REGION DB: Persisting Prim Inventory with prim ID {0}", primID);
  444. //Statement from MySQL section!
  445. // For now, we're just going to crudely remove all the previous inventory items
  446. // no matter whether they have changed or not, and replace them with the current set.
  447. //Delete everything from PrimID
  448. //TODO add index on PrimID in DB, if not already exist
  449. string sql = "DELETE PRIMITEMS WHERE primID = @primID";
  450. using (SqlConnection conn = new SqlConnection(m_connectionString))
  451. using (SqlCommand cmd = new SqlCommand(sql, conn))
  452. {
  453. cmd.Parameters.Add(_Database.CreateParameter("@primID", primID));
  454. conn.Open();
  455. cmd.ExecuteNonQuery();
  456. }
  457. sql =
  458. @"INSERT INTO primitems (
  459. itemID,primID,assetID,parentFolderID,invType,assetType,name,description,creationDate,creatorID,ownerID,lastOwnerID,groupID,
  460. nextPermissions,currentPermissions,basePermissions,everyonePermissions,groupPermissions,flags)
  461. VALUES (@itemID,@primID,@assetID,@parentFolderID,@invType,@assetType,@name,@description,@creationDate,@creatorID,@ownerID,
  462. @lastOwnerID,@groupID,@nextPermissions,@currentPermissions,@basePermissions,@everyonePermissions,@groupPermissions,@flags)";
  463. using (SqlConnection conn = new SqlConnection(m_connectionString))
  464. using (SqlCommand cmd = new SqlCommand(sql, conn))
  465. {
  466. conn.Open();
  467. foreach (TaskInventoryItem taskItem in items)
  468. {
  469. cmd.Parameters.AddRange(CreatePrimInventoryParameters(taskItem));
  470. cmd.ExecuteNonQuery();
  471. cmd.Parameters.Clear();
  472. }
  473. }
  474. }
  475. #endregion
  476. /// <summary>
  477. /// Loads the terrain map.
  478. /// </summary>
  479. /// <param name="regionID">regionID.</param>
  480. /// <returns></returns>
  481. public double[,] LoadTerrain(UUID regionID)
  482. {
  483. double[,] terrain = new double[(int)Constants.RegionSize, (int)Constants.RegionSize];
  484. terrain.Initialize();
  485. string sql = "select top 1 RegionUUID, Revision, Heightfield from terrain where RegionUUID = @RegionUUID order by Revision desc";
  486. using (SqlConnection conn = new SqlConnection(m_connectionString))
  487. using (SqlCommand cmd = new SqlCommand(sql, conn))
  488. {
  489. // MySqlParameter param = new MySqlParameter();
  490. cmd.Parameters.Add(_Database.CreateParameter("@RegionUUID", regionID));
  491. conn.Open();
  492. using (SqlDataReader reader = cmd.ExecuteReader())
  493. {
  494. int rev;
  495. if (reader.Read())
  496. {
  497. MemoryStream str = new MemoryStream((byte[])reader["Heightfield"]);
  498. BinaryReader br = new BinaryReader(str);
  499. for (int x = 0; x < (int)Constants.RegionSize; x++)
  500. {
  501. for (int y = 0; y < (int)Constants.RegionSize; y++)
  502. {
  503. terrain[x, y] = br.ReadDouble();
  504. }
  505. }
  506. rev = (int)reader["Revision"];
  507. }
  508. else
  509. {
  510. _Log.Info("[REGION DB]: No terrain found for region");
  511. return null;
  512. }
  513. _Log.Info("[REGION DB]: Loaded terrain revision r" + rev);
  514. }
  515. }
  516. return terrain;
  517. }
  518. /// <summary>
  519. /// Stores the terrain map to DB.
  520. /// </summary>
  521. /// <param name="terrain">terrain map data.</param>
  522. /// <param name="regionID">regionID.</param>
  523. public void StoreTerrain(double[,] terrain, UUID regionID)
  524. {
  525. int revision = Util.UnixTimeSinceEpoch();
  526. //Delete old terrain map
  527. string sql = "delete from terrain where RegionUUID=@RegionUUID";
  528. using (SqlConnection conn = new SqlConnection(m_connectionString))
  529. using (SqlCommand cmd = new SqlCommand(sql, conn))
  530. {
  531. cmd.Parameters.Add(_Database.CreateParameter("@RegionUUID", regionID));
  532. conn.Open();
  533. cmd.ExecuteNonQuery();
  534. }
  535. sql = "insert into terrain(RegionUUID, Revision, Heightfield) values(@RegionUUID, @Revision, @Heightfield)";
  536. using (SqlConnection conn = new SqlConnection(m_connectionString))
  537. using (SqlCommand cmd = new SqlCommand(sql, conn))
  538. {
  539. cmd.Parameters.Add(_Database.CreateParameter("@RegionUUID", regionID));
  540. cmd.Parameters.Add(_Database.CreateParameter("@Revision", revision));
  541. cmd.Parameters.Add(_Database.CreateParameter("@Heightfield", serializeTerrain(terrain)));
  542. conn.Open();
  543. cmd.ExecuteNonQuery();
  544. }
  545. _Log.Info("[REGION DB]: Stored terrain revision r " + revision);
  546. }
  547. /// <summary>
  548. /// Loads all the land objects of a region.
  549. /// </summary>
  550. /// <param name="regionUUID">The region UUID.</param>
  551. /// <returns></returns>
  552. public List<LandData> LoadLandObjects(UUID regionUUID)
  553. {
  554. List<LandData> LandDataForRegion = new List<LandData>();
  555. string sql = "select * from land where RegionUUID = @RegionUUID";
  556. //Retrieve all land data from region
  557. using (SqlConnection conn = new SqlConnection(m_connectionString))
  558. using (SqlCommand cmd = new SqlCommand(sql, conn))
  559. {
  560. cmd.Parameters.Add(_Database.CreateParameter("@RegionUUID", regionUUID));
  561. conn.Open();
  562. using (SqlDataReader readerLandData = cmd.ExecuteReader())
  563. {
  564. while (readerLandData.Read())
  565. {
  566. LandDataForRegion.Add(BuildLandData(readerLandData));
  567. }
  568. }
  569. }
  570. //Retrieve all accesslist data for all landdata
  571. foreach (LandData LandData in LandDataForRegion)
  572. {
  573. sql = "select * from landaccesslist where LandUUID = @LandUUID";
  574. using (SqlConnection conn = new SqlConnection(m_connectionString))
  575. using (SqlCommand cmd = new SqlCommand(sql, conn))
  576. {
  577. cmd.Parameters.Add(_Database.CreateParameter("@LandUUID", LandData.GlobalID));
  578. conn.Open();
  579. using (SqlDataReader readerAccessList = cmd.ExecuteReader())
  580. {
  581. while (readerAccessList.Read())
  582. {
  583. LandData.ParcelAccessList.Add(BuildLandAccessData(readerAccessList));
  584. }
  585. }
  586. }
  587. }
  588. //Return data
  589. return LandDataForRegion;
  590. }
  591. /// <summary>
  592. /// Stores land object with landaccess list.
  593. /// </summary>
  594. /// <param name="parcel">parcel data.</param>
  595. public void StoreLandObject(ILandObject parcel)
  596. {
  597. //As this is only one record in land table I just delete all and then add a new record.
  598. //As the delete landaccess is already in the mysql code
  599. //Delete old values
  600. RemoveLandObject(parcel.LandData.GlobalID);
  601. //Insert new values
  602. string sql = @"INSERT INTO [land]
  603. ([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])
  604. VALUES
  605. (@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)";
  606. using (SqlConnection conn = new SqlConnection(m_connectionString))
  607. using (SqlCommand cmd = new SqlCommand(sql, conn))
  608. {
  609. cmd.Parameters.AddRange(CreateLandParameters(parcel.LandData, parcel.RegionUUID));
  610. conn.Open();
  611. cmd.ExecuteNonQuery();
  612. }
  613. sql = "INSERT INTO [landaccesslist] ([LandUUID],[AccessUUID],[Flags]) VALUES (@LandUUID,@AccessUUID,@Flags)";
  614. using (SqlConnection conn = new SqlConnection(m_connectionString))
  615. using (SqlCommand cmd = new SqlCommand(sql, conn))
  616. {
  617. conn.Open();
  618. foreach (ParcelManager.ParcelAccessEntry parcelAccessEntry in parcel.LandData.ParcelAccessList)
  619. {
  620. cmd.Parameters.AddRange(CreateLandAccessParameters(parcelAccessEntry, parcel.RegionUUID));
  621. cmd.ExecuteNonQuery();
  622. cmd.Parameters.Clear();
  623. }
  624. }
  625. }
  626. /// <summary>
  627. /// Removes a land object from DB.
  628. /// </summary>
  629. /// <param name="globalID">UUID of landobject</param>
  630. public void RemoveLandObject(UUID globalID)
  631. {
  632. string sql = "delete from land where UUID=@UUID";
  633. using (SqlConnection conn = new SqlConnection(m_connectionString))
  634. using (SqlCommand cmd = new SqlCommand(sql, conn))
  635. {
  636. cmd.Parameters.Add(_Database.CreateParameter("@UUID", globalID));
  637. conn.Open();
  638. cmd.ExecuteNonQuery();
  639. }
  640. sql = "delete from landaccesslist where LandUUID=@UUID";
  641. using (SqlConnection conn = new SqlConnection(m_connectionString))
  642. using (SqlCommand cmd = new SqlCommand(sql, conn))
  643. {
  644. cmd.Parameters.Add(_Database.CreateParameter("@UUID", globalID));
  645. conn.Open();
  646. cmd.ExecuteNonQuery();
  647. }
  648. }
  649. public RegionLightShareData LoadRegionWindlightSettings(UUID regionUUID)
  650. {
  651. RegionLightShareData nWP = new RegionLightShareData();
  652. nWP.OnSave += StoreRegionWindlightSettings;
  653. string sql = "select * from [regionwindlight] where region_id = @regionID";
  654. using (SqlConnection conn = new SqlConnection(m_connectionString))
  655. using (SqlCommand cmd = new SqlCommand(sql, conn))
  656. {
  657. cmd.Parameters.Add(_Database.CreateParameter("@regionID", regionUUID));
  658. conn.Open();
  659. using (SqlDataReader result = cmd.ExecuteReader())
  660. {
  661. if (!result.Read())
  662. {
  663. //No result, so store our default windlight profile and return it
  664. nWP.regionID = regionUUID;
  665. StoreRegionWindlightSettings(nWP);
  666. return nWP;
  667. }
  668. else
  669. {
  670. nWP.regionID = DBGuid.FromDB(result["region_id"]);
  671. nWP.waterColor.X = Convert.ToSingle(result["water_color_r"]);
  672. nWP.waterColor.Y = Convert.ToSingle(result["water_color_g"]);
  673. nWP.waterColor.Z = Convert.ToSingle(result["water_color_b"]);
  674. nWP.waterFogDensityExponent = Convert.ToSingle(result["water_fog_density_exponent"]);
  675. nWP.underwaterFogModifier = Convert.ToSingle(result["underwater_fog_modifier"]);
  676. nWP.reflectionWaveletScale.X = Convert.ToSingle(result["reflection_wavelet_scale_1"]);
  677. nWP.reflectionWaveletScale.Y = Convert.ToSingle(result["reflection_wavelet_scale_2"]);
  678. nWP.reflectionWaveletScale.Z = Convert.ToSingle(result["reflection_wavelet_scale_3"]);
  679. nWP.fresnelScale = Convert.ToSingle(result["fresnel_scale"]);
  680. nWP.fresnelOffset = Convert.ToSingle(result["fresnel_offset"]);
  681. nWP.refractScaleAbove = Convert.ToSingle(result["refract_scale_above"]);
  682. nWP.refractScaleBelow = Convert.ToSingle(result["refract_scale_below"]);
  683. nWP.blurMultiplier = Convert.ToSingle(result["blur_multiplier"]);
  684. nWP.bigWaveDirection.X = Convert.ToSingle(result["big_wave_direction_x"]);
  685. nWP.bigWaveDirection.Y = Convert.ToSingle(result["big_wave_direction_y"]);
  686. nWP.littleWaveDirection.X = Convert.ToSingle(result["little_wave_direction_x"]);
  687. nWP.littleWaveDirection.Y = Convert.ToSingle(result["little_wave_direction_y"]);
  688. UUID.TryParse(result["normal_map_texture"].ToString(), out nWP.normalMapTexture);
  689. nWP.horizon.X = Convert.ToSingle(result["horizon_r"]);
  690. nWP.horizon.Y = Convert.ToSingle(result["horizon_g"]);
  691. nWP.horizon.Z = Convert.ToSingle(result["horizon_b"]);
  692. nWP.horizon.W = Convert.ToSingle(result["horizon_i"]);
  693. nWP.hazeHorizon = Convert.ToSingle(result["haze_horizon"]);
  694. nWP.blueDensity.X = Convert.ToSingle(result["blue_density_r"]);
  695. nWP.blueDensity.Y = Convert.ToSingle(result["blue_density_g"]);
  696. nWP.blueDensity.Z = Convert.ToSingle(result["blue_density_b"]);
  697. nWP.blueDensity.W = Convert.ToSingle(result["blue_density_i"]);
  698. nWP.hazeDensity = Convert.ToSingle(result["haze_density"]);
  699. nWP.densityMultiplier = Convert.ToSingle(result["density_multiplier"]);
  700. nWP.distanceMultiplier = Convert.ToSingle(result["distance_multiplier"]);
  701. nWP.maxAltitude = Convert.ToUInt16(result["max_altitude"]);
  702. nWP.sunMoonColor.X = Convert.ToSingle(result["sun_moon_color_r"]);
  703. nWP.sunMoonColor.Y = Convert.ToSingle(result["sun_moon_color_g"]);
  704. nWP.sunMoonColor.Z = Convert.ToSingle(result["sun_moon_color_b"]);
  705. nWP.sunMoonColor.W = Convert.ToSingle(result["sun_moon_color_i"]);
  706. nWP.sunMoonPosition = Convert.ToSingle(result["sun_moon_position"]);
  707. nWP.ambient.X = Convert.ToSingle(result["ambient_r"]);
  708. nWP.ambient.Y = Convert.ToSingle(result["ambient_g"]);
  709. nWP.ambient.Z = Convert.ToSingle(result["ambient_b"]);
  710. nWP.ambient.W = Convert.ToSingle(result["ambient_i"]);
  711. nWP.eastAngle = Convert.ToSingle(result["east_angle"]);
  712. nWP.sunGlowFocus = Convert.ToSingle(result["sun_glow_focus"]);
  713. nWP.sunGlowSize = Convert.ToSingle(result["sun_glow_size"]);
  714. nWP.sceneGamma = Convert.ToSingle(result["scene_gamma"]);
  715. nWP.starBrightness = Convert.ToSingle(result["star_brightness"]);
  716. nWP.cloudColor.X = Convert.ToSingle(result["cloud_color_r"]);
  717. nWP.cloudColor.Y = Convert.ToSingle(result["cloud_color_g"]);
  718. nWP.cloudColor.Z = Convert.ToSingle(result["cloud_color_b"]);
  719. nWP.cloudColor.W = Convert.ToSingle(result["cloud_color_i"]);
  720. nWP.cloudXYDensity.X = Convert.ToSingle(result["cloud_x"]);
  721. nWP.cloudXYDensity.Y = Convert.ToSingle(result["cloud_y"]);
  722. nWP.cloudXYDensity.Z = Convert.ToSingle(result["cloud_density"]);
  723. nWP.cloudCoverage = Convert.ToSingle(result["cloud_coverage"]);
  724. nWP.cloudScale = Convert.ToSingle(result["cloud_scale"]);
  725. nWP.cloudDetailXYDensity.X = Convert.ToSingle(result["cloud_detail_x"]);
  726. nWP.cloudDetailXYDensity.Y = Convert.ToSingle(result["cloud_detail_y"]);
  727. nWP.cloudDetailXYDensity.Z = Convert.ToSingle(result["cloud_detail_density"]);
  728. nWP.cloudScrollX = Convert.ToSingle(result["cloud_scroll_x"]);
  729. nWP.cloudScrollXLock = Convert.ToBoolean(result["cloud_scroll_x_lock"]);
  730. nWP.cloudScrollY = Convert.ToSingle(result["cloud_scroll_y"]);
  731. nWP.cloudScrollYLock = Convert.ToBoolean(result["cloud_scroll_y_lock"]);
  732. nWP.drawClassicClouds = Convert.ToBoolean(result["draw_classic_clouds"]);
  733. nWP.valid = true;
  734. }
  735. }
  736. }
  737. return nWP;
  738. }
  739. public void RemoveRegionWindlightSettings(UUID regionID)
  740. {
  741. string sql = "delete from [regionwindlight] where region_id = @region_id";
  742. using (SqlConnection conn = new SqlConnection(m_connectionString))
  743. using (SqlCommand cmd = new SqlCommand(sql, conn))
  744. {
  745. conn.Open();
  746. cmd.Parameters.Add(_Database.CreateParameter("@region_id", regionID));
  747. cmd.ExecuteNonQuery();
  748. }
  749. }
  750. public void StoreRegionWindlightSettings(RegionLightShareData wl)
  751. {
  752. string sql = "select count (region_id) from regionwindlight where region_id = @region_id";
  753. bool exists = false;
  754. using (SqlConnection conn = new SqlConnection(m_connectionString))
  755. {
  756. conn.Open();
  757. using (SqlCommand cmd = new SqlCommand(sql, conn))
  758. {
  759. cmd.Parameters.Add(_Database.CreateParameter("@region_id", wl.regionID));
  760. exists = (int)cmd.ExecuteScalar() > 0;
  761. }
  762. }
  763. if (exists)
  764. {
  765. RemoveRegionWindlightSettings(wl.regionID);
  766. }
  767. // sql insert
  768. sql = @"INSERT INTO [regionwindlight]
  769. ([region_id]
  770. ,[water_color_r]
  771. ,[water_color_g]
  772. ,[water_color_b]
  773. ,[water_fog_density_exponent]
  774. ,[underwater_fog_modifier]
  775. ,[reflection_wavelet_scale_1]
  776. ,[reflection_wavelet_scale_2]
  777. ,[reflection_wavelet_scale_3]
  778. ,[fresnel_scale]
  779. ,[fresnel_offset]
  780. ,[refract_scale_above]
  781. ,[refract_scale_below]
  782. ,[blur_multiplier]
  783. ,[big_wave_direction_x]
  784. ,[big_wave_direction_y]
  785. ,[little_wave_direction_x]
  786. ,[little_wave_direction_y]
  787. ,[normal_map_texture]
  788. ,[horizon_r]
  789. ,[horizon_g]
  790. ,[horizon_b]
  791. ,[horizon_i]
  792. ,[haze_horizon]
  793. ,[blue_density_r]
  794. ,[blue_density_g]
  795. ,[blue_density_b]
  796. ,[blue_density_i]
  797. ,[haze_density]
  798. ,[density_multiplier]
  799. ,[distance_multiplier]
  800. ,[max_altitude]
  801. ,[sun_moon_color_r]
  802. ,[sun_moon_color_g]
  803. ,[sun_moon_color_b]
  804. ,[sun_moon_color_i]
  805. ,[sun_moon_position]
  806. ,[ambient_r]
  807. ,[ambient_g]
  808. ,[ambient_b]
  809. ,[ambient_i]
  810. ,[east_angle]
  811. ,[sun_glow_focus]
  812. ,[sun_glow_size]
  813. ,[scene_gamma]
  814. ,[star_brightness]
  815. ,[cloud_color_r]
  816. ,[cloud_color_g]
  817. ,[cloud_color_b]
  818. ,[cloud_color_i]
  819. ,[cloud_x]
  820. ,[cloud_y]
  821. ,[cloud_density]
  822. ,[cloud_coverage]
  823. ,[cloud_scale]
  824. ,[cloud_detail_x]
  825. ,[cloud_detail_y]
  826. ,[cloud_detail_density]
  827. ,[cloud_scroll_x]
  828. ,[cloud_scroll_x_lock]
  829. ,[cloud_scroll_y]
  830. ,[cloud_scroll_y_lock]
  831. ,[draw_classic_clouds])
  832. VALUES
  833. (@region_id
  834. ,@water_color_r
  835. ,@water_color_g
  836. ,@water_color_b
  837. ,@water_fog_density_exponent
  838. ,@underwater_fog_modifier
  839. ,@reflection_wavelet_scale_1
  840. ,@reflection_wavelet_scale_2
  841. ,@reflection_wavelet_scale_3
  842. ,@fresnel_scale
  843. ,@fresnel_offset
  844. ,@refract_scale_above
  845. ,@refract_scale_below
  846. ,@blur_multiplier
  847. ,@big_wave_direction_x
  848. ,@big_wave_direction_y
  849. ,@little_wave_direction_x
  850. ,@little_wave_direction_y
  851. ,@normal_map_texture
  852. ,@horizon_r
  853. ,@horizon_g
  854. ,@horizon_b
  855. ,@horizon_i
  856. ,@haze_horizon
  857. ,@blue_density_r
  858. ,@blue_density_g
  859. ,@blue_density_b
  860. ,@blue_density_i
  861. ,@haze_density
  862. ,@density_multiplier
  863. ,@distance_multiplier
  864. ,@max_altitude
  865. ,@sun_moon_color_r
  866. ,@sun_moon_color_g
  867. ,@sun_moon_color_b
  868. ,@sun_moon_color_i
  869. ,@sun_moon_position
  870. ,@ambient_r
  871. ,@ambient_g
  872. ,@ambient_b
  873. ,@ambient_i
  874. ,@east_angle
  875. ,@sun_glow_focus
  876. ,@sun_glow_size
  877. ,@scene_gamma
  878. ,@star_brightness
  879. ,@cloud_color_r
  880. ,@cloud_color_g
  881. ,@cloud_color_b
  882. ,@cloud_color_i
  883. ,@cloud_x
  884. ,@cloud_y
  885. ,@cloud_density
  886. ,@cloud_coverage
  887. ,@cloud_scale
  888. ,@cloud_detail_x
  889. ,@cloud_detail_y
  890. ,@cloud_detail_density
  891. ,@cloud_scroll_x
  892. ,@cloud_scroll_x_lock
  893. ,@cloud_scroll_y
  894. ,@cloud_scroll_y_lock
  895. ,@draw_classic_clouds)";
  896. using (SqlConnection conn = new SqlConnection(m_connectionString))
  897. {
  898. conn.Open();
  899. using (SqlCommand cmd = new SqlCommand(sql, conn))
  900. {
  901. cmd.Parameters.Add(_Database.CreateParameter("region_id", wl.regionID));
  902. cmd.Parameters.Add(_Database.CreateParameter("water_color_r", wl.waterColor.X));
  903. cmd.Parameters.Add(_Database.CreateParameter("water_color_g", wl.waterColor.Y));
  904. cmd.Parameters.Add(_Database.CreateParameter("water_color_b", wl.waterColor.Z));
  905. cmd.Parameters.Add(_Database.CreateParameter("water_fog_density_exponent", wl.waterFogDensityExponent));
  906. cmd.Parameters.Add(_Database.CreateParameter("underwater_fog_modifier", wl.underwaterFogModifier));
  907. cmd.Parameters.Add(_Database.CreateParameter("reflection_wavelet_scale_1", wl.reflectionWaveletScale.X));
  908. cmd.Parameters.Add(_Database.CreateParameter("reflection_wavelet_scale_2", wl.reflectionWaveletScale.Y));
  909. cmd.Parameters.Add(_Database.CreateParameter("reflection_wavelet_scale_3", wl.reflectionWaveletScale.Z));
  910. cmd.Parameters.Add(_Database.CreateParameter("fresnel_scale", wl.fresnelScale));
  911. cmd.Parameters.Add(_Database.CreateParameter("fresnel_offset", wl.fresnelOffset));
  912. cmd.Parameters.Add(_Database.CreateParameter("refract_scale_above", wl.refractScaleAbove));
  913. cmd.Parameters.Add(_Database.CreateParameter("refract_scale_below", wl.refractScaleBelow));
  914. cmd.Parameters.Add(_Database.CreateParameter("blur_multiplier", wl.blurMultiplier));
  915. cmd.Parameters.Add(_Database.CreateParameter("big_wave_direction_x", wl.bigWaveDirection.X));
  916. cmd.Parameters.Add(_Database.CreateParameter("big_wave_direction_y", wl.bigWaveDirection.Y));
  917. cmd.Parameters.Add(_Database.CreateParameter("little_wave_direction_x", wl.littleWaveDirection.X));
  918. cmd.Parameters.Add(_Database.CreateParameter("little_wave_direction_y", wl.littleWaveDirection.Y));
  919. cmd.Parameters.Add(_Database.CreateParameter("normal_map_texture", wl.normalMapTexture));
  920. cmd.Parameters.Add(_Database.CreateParameter("horizon_r", wl.horizon.X));
  921. cmd.Parameters.Add(_Database.CreateParameter("horizon_g", wl.horizon.Y));
  922. cmd.Parameters.Add(_Database.CreateParameter("horizon_b", wl.horizon.Z));
  923. cmd.Parameters.Add(_Database.CreateParameter("horizon_i", wl.horizon.W));
  924. cmd.Parameters.Add(_Database.CreateParameter("haze_horizon", wl.hazeHorizon));
  925. cmd.Parameters.Add(_Database.CreateParameter("blue_density_r", wl.blueDensity.X));
  926. cmd.Parameters.Add(_Database.CreateParameter("blue_density_g", wl.blueDensity.Y));
  927. cmd.Parameters.Add(_Database.CreateParameter("blue_density_b", wl.blueDensity.Z));
  928. cmd.Parameters.Add(_Database.CreateParameter("blue_density_i", wl.blueDensity.W));
  929. cmd.Parameters.Add(_Database.CreateParameter("haze_density", wl.hazeDensity));
  930. cmd.Parameters.Add(_Database.CreateParameter("density_multiplier", wl.densityMultiplier));
  931. cmd.Parameters.Add(_Database.CreateParameter("distance_multiplier", wl.distanceMultiplier));
  932. cmd.Parameters.Add(_Database.CreateParameter("max_altitude", wl.maxAltitude));
  933. cmd.Parameters.Add(_Database.CreateParameter("sun_moon_color_r", wl.sunMoonColor.X));
  934. cmd.Parameters.Add(_Database.CreateParameter("sun_moon_color_g", wl.sunMoonColor.Y));
  935. cmd.Parameters.Add(_Database.CreateParameter("sun_moon_color_b", wl.sunMoonColor.Z));
  936. cmd.Parameters.Add(_Database.CreateParameter("sun_moon_color_i", wl.sunMoonColor.W));
  937. cmd.Parameters.Add(_Database.CreateParameter("sun_moon_position", wl.sunMoonPosition));
  938. cmd.Parameters.Add(_Database.CreateParameter("ambient_r", wl.ambient.X));
  939. cmd.Parameters.Add(_Database.CreateParameter("ambient_g", wl.ambient.Y));
  940. cmd.Parameters.Add(_Database.CreateParameter("ambient_b", wl.ambient.Z));
  941. cmd.Parameters.Add(_Database.CreateParameter("ambient_i", wl.ambient.W));
  942. cmd.Parameters.Add(_Database.CreateParameter("east_angle", wl.eastAngle));
  943. cmd.Parameters.Add(_Database.CreateParameter("sun_glow_focus", wl.sunGlowFocus));
  944. cmd.Parameters.Add(_Database.CreateParameter("sun_glow_size", wl.sunGlowSize));
  945. cmd.Parameters.Add(_Database.CreateParameter("scene_gamma", wl.sceneGamma));
  946. cmd.Parameters.Add(_Database.CreateParameter("star_brightness", wl.starBrightness));
  947. cmd.Parameters.Add(_Database.CreateParameter("cloud_color_r", wl.cloudColor.X));
  948. cmd.Parameters.Add(_Database.CreateParameter("cloud_color_g", wl.cloudColor.Y));
  949. cmd.Parameters.Add(_Database.CreateParameter("cloud_color_b", wl.cloudColor.Z));
  950. cmd.Parameters.Add(_Database.CreateParameter("cloud_color_i", wl.cloudColor.W));
  951. cmd.Parameters.Add(_Database.CreateParameter("cloud_x", wl.cloudXYDensity.X));
  952. cmd.Parameters.Add(_Database.CreateParameter("cloud_y", wl.cloudXYDensity.Y));
  953. cmd.Parameters.Add(_Database.CreateParameter("cloud_density", wl.cloudXYDensity.Z));
  954. cmd.Parameters.Add(_Database.CreateParameter("cloud_coverage", wl.cloudCoverage));
  955. cmd.Parameters.Add(_Database.CreateParameter("cloud_scale", wl.cloudScale));
  956. cmd.Parameters.Add(_Database.CreateParameter("cloud_detail_x", wl.cloudDetailXYDensity.X));
  957. cmd.Parameters.Add(_Database.CreateParameter("cloud_detail_y", wl.cloudDetailXYDensity.Y));
  958. cmd.Parameters.Add(_Database.CreateParameter("cloud_detail_density", wl.cloudDetailXYDensity.Z));
  959. cmd.Parameters.Add(_Database.CreateParameter("cloud_scroll_x", wl.cloudScrollX));
  960. cmd.Parameters.Add(_Database.CreateParameter("cloud_scroll_x_lock", wl.cloudScrollXLock));
  961. cmd.Parameters.Add(_Database.CreateParameter("cloud_scroll_y", wl.cloudScrollY));
  962. cmd.Parameters.Add(_Database.CreateParameter("cloud_scroll_y_lock", wl.cloudScrollYLock));
  963. cmd.Parameters.Add(_Database.CreateParameter("draw_classic_clouds", wl.drawClassicClouds));
  964. cmd.ExecuteNonQuery();
  965. }
  966. }
  967. #region update
  968. // }
  969. // else
  970. // {
  971. // // sql update
  972. // sql = @"UPDATE [OpenSim].[dbo].[regionwindlight]
  973. // SET [region_id] = @region_id
  974. // ,[water_color_r] = @water_color_r
  975. // ,[water_color_g] = @water_color_g
  976. // ,[water_color_b] = @water_color_b
  977. // ,[water_fog_density_exponent] = @water_fog_density_exponent
  978. // ,[underwater_fog_modifier] = @underwater_fog_modifier
  979. // ,[reflection_wavelet_scale_1] = @reflection_wavelet_scale_1
  980. // ,[reflection_wavelet_scale_2] = @reflection_wavelet_scale_2
  981. // ,[reflection_wavelet_scale_3] = @reflection_wavelet_scale_3
  982. // ,[fresnel_scale] = @fresnel_scale
  983. // ,[fresnel_offset] = @fresnel_offset
  984. // ,[refract_scale_above] = @refract_scale_above
  985. // ,[refract_scale_below] = @refract_scale_below
  986. // ,[blur_multiplier] = @blur_multiplier
  987. // ,[big_wave_direction_x] = @big_wave_direction_x
  988. // ,[big_wave_direction_y] = @big_wave_direction_y
  989. // ,[little_wave_direction_x] = @little_wave_direction_x
  990. // ,[little_wave_direction_y] = @little_wave_direction_y
  991. // ,[normal_map_texture] = @normal_map_texture
  992. // ,[horizon_r] = @horizon_r
  993. // ,[horizon_g] = @horizon_g
  994. // ,[horizon_b] = @horizon_b
  995. // ,[horizon_i] = @horizon_i
  996. // ,[haze_horizon] = @haze_horizon
  997. // ,[blue_density_r] = @blue_density_r
  998. // ,[blue_density_g] = @blue_density_g
  999. // ,[blue_density_b] = @blue_density_b
  1000. // ,[blue_density_i] = @blue_density_i
  1001. // ,[haze_density] = @haze_density
  1002. // ,[density_multiplier] = @density_multiplier
  1003. // ,[distance_multiplier] = @distance_multiplier
  1004. // ,[max_altitude] = @max_altitude
  1005. // ,[sun_moon_color_r] = @sun_moon_color_r
  1006. // ,[sun_moon_color_g] = @sun_moon_color_g
  1007. // ,[sun_moon_color_b] = @sun_moon_color_b
  1008. // ,[sun_moon_color_i] = @sun_moon_color_i
  1009. // ,[sun_moon_position] = @sun_moon_position
  1010. // ,[ambient_r] = @ambient_r
  1011. // ,[ambient_g] = @ambient_g
  1012. // ,[ambient_b] = @ambient_b
  1013. // ,[ambient_i] = @ambient_i
  1014. // ,[east_angle] = @east_angle
  1015. // ,[sun_glow_focus] = @sun_glow_focus
  1016. // ,[sun_glow_size] = @sun_glow_size
  1017. // ,[scene_gamma] = @scene_gamma
  1018. // ,[star_brightness] = @star_brightness
  1019. // ,[cloud_color_r] = @cloud_color_r
  1020. // ,[cloud_color_g] = @cloud_color_g
  1021. // ,[cloud_color_b] = @cloud_color_b
  1022. // ,[cloud_color_i] = @cloud_color_i
  1023. // ,[cloud_x] = @cloud_x
  1024. // ,[cloud_y] = @cloud_y
  1025. // ,[cloud_density] = @cloud_density
  1026. // ,[cloud_coverage] = @cloud_coverage
  1027. // ,[cloud_scale] = @cloud_scale
  1028. // ,[cloud_detail_x] = @cloud_detail_x
  1029. // ,[cloud_detail_y] = @cloud_detail_y
  1030. // ,[cloud_detail_density] = @cloud_detail_density
  1031. // ,[cloud_scroll_x] = @cloud_scroll_x
  1032. // ,[cloud_scroll_x_lock] = @cloud_scroll_x_lock
  1033. // ,[cloud_scroll_y] = @cloud_scroll_y
  1034. // ,[cloud_scroll_y_lock] = @cloud_scroll_y_lock
  1035. // ,[draw_classic_clouds] = @draw_classic_clouds
  1036. // WHERE region_id = @region_id";
  1037. // using (SqlConnection conn = new SqlConnection(m_connectionString))
  1038. // {
  1039. // conn.Open();
  1040. // using (SqlCommand cmd = new SqlCommand(sql, conn))
  1041. // {
  1042. // cmd.Parameters.AddWithValue("region_id", wl.regionID);
  1043. // cmd.Parameters.AddWithValue("water_color_r", wl.waterColor.X);
  1044. // cmd.Parameters.AddWithValue("water_color_g", wl.waterColor.Y);
  1045. // cmd.Parameters.AddWithValue("water_color_b", wl.waterColor.Z);
  1046. // cmd.Parameters.AddWithValue("water_fog_density_exponent", wl.waterFogDensityExponent);
  1047. // cmd.Parameters.AddWithValue("underwater_fog_modifier", wl.underwaterFogModifier);
  1048. // cmd.Parameters.AddWithValue("reflection_wavelet_scale_1", wl.reflectionWaveletScale.X);
  1049. // cmd.Parameters.AddWithValue("reflection_wavelet_scale_2", wl.reflectionWaveletScale.Y);
  1050. // cmd.Parameters.AddWithValue("reflection_wavelet_scale_3", wl.reflectionWaveletScale.Z);
  1051. // cmd.Parameters.AddWithValue("fresnel_scale", wl.fresnelScale);
  1052. // cmd.Parameters.AddWithValue("fresnel_offset", wl.fresnelOffset);
  1053. // cmd.Parameters.AddWithValue("refract_scale_above", wl.refractScaleAbove);
  1054. // cmd.Parameters.AddWithValue("refract_scale_below", wl.refractScaleBelow);
  1055. // cmd.Parameters.AddWithValue("blur_multiplier", wl.blurMultiplier);
  1056. // cmd.Parameters.AddWithValue("big_wave_direction_x", wl.bigWaveDirection.X);
  1057. // cmd.Parameters.AddWithValue("big_wave_direction_y", wl.bigWaveDirection.Y);
  1058. // cmd.Parameters.AddWithValue("little_wave_direction_x", wl.littleWaveDirection.X);
  1059. // cmd.Parameters.AddWithValue("little_wave_direction_y", wl.littleWaveDirection.Y);
  1060. // cmd.Parameters.AddWithValue("normal_map_texture", wl.normalMapTexture);
  1061. // cmd.Parameters.AddWithValue("horizon_r", wl.horizon.X);
  1062. // cmd.Parameters.AddWithValue("horizon_g", wl.horizon.Y);
  1063. // cmd.Parameters.AddWithValue("horizon_b", wl.horizon.Z);
  1064. // cmd.Parameters.AddWithValue("horizon_i", wl.horizon.W);
  1065. // cmd.Parameters.AddWithValue("haze_horizon", wl.hazeHorizon);
  1066. // cmd.Parameters.AddWithValue("blue_density_r", wl.blueDensity.X);
  1067. // cmd.Parameters.AddWithValue("blue_density_g", wl.blueDensity.Y);
  1068. // cmd.Parameters.AddWithValue("blue_density_b", wl.blueDensity.Z);
  1069. // cmd.Parameters.AddWithValue("blue_density_i", wl.blueDensity.W);
  1070. // cmd.Parameters.AddWithValue("haze_density", wl.hazeDensity);
  1071. // cmd.Parameters.AddWithValue("density_multiplier", wl.densityMultiplier);
  1072. // cmd.Parameters.AddWithValue("distance_multiplier", wl.distanceMultiplier);
  1073. // cmd.Parameters.AddWithValue("max_altitude", wl.maxAltitude);
  1074. // cmd.Parameters.AddWithValue("sun_moon_color_r", wl.sunMoonColor.X);
  1075. // cmd.Parameters.AddWithValue("sun_moon_color_g", wl.sunMoonColor.Y);
  1076. // cmd.Parameters.AddWithValue("sun_moon_color_b", wl.sunMoonColor.Z);
  1077. // cmd.Parameters.AddWithValue("sun_moon_color_i", wl.sunMoonColor.W);
  1078. // cmd.Parameters.AddWithValue("sun_moon_position", wl.sunMoonPosition);
  1079. // cmd.Parameters.AddWithValue("ambient_r", wl.ambient.X);
  1080. // cmd.Parameters.AddWithValue("ambient_g", wl.ambient.Y);
  1081. // cmd.Parameters.AddWithValue("ambient_b", wl.ambient.Z);
  1082. // cmd.Parameters.AddWithValue("ambient_i", wl.ambient.W);
  1083. // cmd.Parameters.AddWithValue("east_angle", wl.eastAngle);
  1084. // cmd.Parameters.AddWithValue("sun_glow_focus", wl.sunGlowFocus);
  1085. // cmd.Parameters.AddWithValue("sun_glow_size", wl.sunGlowSize);
  1086. // cmd.Parameters.AddWithValue("scene_gamma", wl.sceneGamma);
  1087. // cmd.Parameters.AddWithValue("star_brightness", wl.starBrightness);
  1088. // cmd.Parameters.AddWithValue("cloud_color_r", wl.cloudColor.X);
  1089. // cmd.Parameters.AddWithValue("cloud_color_g", wl.cloudColor.Y);
  1090. // cmd.Parameters.AddWithValue("cloud_color_b", wl.cloudColor.Z);
  1091. // cmd.Parameters.AddWithValue("cloud_color_i", wl.cloudColor.W);
  1092. // cmd.Parameters.AddWithValue("cloud_x", wl.cloudXYDensity.X);
  1093. // cmd.Parameters.AddWithValue("cloud_y", wl.cloudXYDensity.Y);
  1094. // cmd.Parameters.AddWithValue("cloud_density", wl.cloudXYDensity.Z);
  1095. // cmd.Parameters.AddWithValue("cloud_coverage", wl.cloudCoverage);
  1096. // cmd.Parameters.AddWithValue("cloud_scale", wl.cloudScale);
  1097. // cmd.Parameters.AddWithValue("cloud_detail_x", wl.cloudDetailXYDensity.X);
  1098. // cmd.Parameters.AddWithValue("cloud_detail_y", wl.cloudDetailXYDensity.Y);
  1099. // cmd.Parameters.AddWithValue("cloud_detail_density", wl.cloudDetailXYDensity.Z);
  1100. // cmd.Parameters.AddWithValue("cloud_scroll_x", wl.cloudScrollX);
  1101. // cmd.Parameters.AddWithValue("cloud_scroll_x_lock", wl.cloudScrollXLock);
  1102. // cmd.Parameters.AddWithValue("cloud_scroll_y", wl.cloudScrollY);
  1103. // cmd.Parameters.AddWithValue("cloud_scroll_y_lock", wl.cloudScrollYLock);
  1104. // cmd.Parameters.AddWithValue("draw_classic_clouds", wl.drawClassicClouds);
  1105. // cmd.ExecuteNonQuery();
  1106. // }
  1107. // }
  1108. // }
  1109. #endregion
  1110. }
  1111. /// <summary>
  1112. /// Loads the settings of a region.
  1113. /// </summary>
  1114. /// <param name="regionUUID">The region UUID.</param>
  1115. /// <returns></returns>
  1116. public RegionSettings LoadRegionSettings(UUID regionUUID)
  1117. {
  1118. string sql = "select * from regionsettings where regionUUID = @regionUUID";
  1119. RegionSettings regionSettings;
  1120. using (SqlConnection conn = new SqlConnection(m_connectionString))
  1121. using (SqlCommand cmd = new SqlCommand(sql, conn))
  1122. {
  1123. cmd.Parameters.Add(_Database.CreateParameter("@regionUUID", regionUUID));
  1124. conn.Open();
  1125. using (SqlDataReader reader = cmd.ExecuteReader())
  1126. {
  1127. if (reader.Read())
  1128. {
  1129. regionSettings = BuildRegionSettings(reader);
  1130. regionSettings.OnSave += StoreRegionSettings;
  1131. return regionSettings;
  1132. }
  1133. }
  1134. }
  1135. //If we reach this point then there are new region settings for that region
  1136. regionSettings = new RegionSettings();
  1137. regionSettings.RegionUUID = regionUUID;
  1138. regionSettings.OnSave += StoreRegionSettings;
  1139. //Store new values
  1140. StoreNewRegionSettings(regionSettings);
  1141. return regionSettings;
  1142. }
  1143. /// <summary>
  1144. /// Store region settings, need to check if the check is really necesary. If we can make something for creating new region.
  1145. /// </summary>
  1146. /// <param name="regionSettings">region settings.</param>
  1147. public void StoreRegionSettings(RegionSettings regionSettings)
  1148. {
  1149. //Little check if regionUUID already exist in DB
  1150. string regionUUID;
  1151. string sql = "SELECT regionUUID FROM regionsettings WHERE regionUUID = @regionUUID";
  1152. using (SqlConnection conn = new SqlConnection(m_connectionString))
  1153. using (SqlCommand cmd = new SqlCommand(sql, conn))
  1154. {
  1155. cmd.Parameters.Add(_Database.CreateParameter("@regionUUID", regionSettings.RegionUUID));
  1156. conn.Open();
  1157. regionUUID = cmd.ExecuteScalar().ToString();
  1158. }
  1159. if (string.IsNullOrEmpty(regionUUID))
  1160. {
  1161. StoreNewRegionSettings(regionSettings);
  1162. }
  1163. else
  1164. {
  1165. //This method only updates region settings!!! First call LoadRegionSettings to create new region settings in DB
  1166. sql =
  1167. @"UPDATE [regionsettings] SET [block_terraform] = @block_terraform ,[block_fly] = @block_fly ,[allow_damage] = @allow_damage
  1168. ,[restrict_pushing] = @restrict_pushing ,[allow_land_resell] = @allow_land_resell ,[allow_land_join_divide] = @allow_land_join_divide
  1169. ,[block_show_in_search] = @block_show_in_search ,[agent_limit] = @agent_limit ,[object_bonus] = @object_bonus ,[maturity] = @maturity
  1170. ,[disable_scripts] = @disable_scripts ,[disable_collisions] = @disable_collisions ,[disable_physics] = @disable_physics
  1171. ,[terrain_texture_1] = @terrain_texture_1 ,[terrain_texture_2] = @terrain_texture_2 ,[terrain_texture_3] = @terrain_texture_3
  1172. ,[terrain_texture_4] = @terrain_texture_4 ,[elevation_1_nw] = @elevation_1_nw ,[elevation_2_nw] = @elevation_2_nw
  1173. ,[elevation_1_ne] = @elevation_1_ne ,[elevation_2_ne] = @elevation_2_ne ,[elevation_1_se] = @elevation_1_se ,[elevation_2_se] = @elevation_2_se
  1174. ,[elevation_1_sw] = @elevation_1_sw ,[elevation_2_sw] = @elevation_2_sw ,[water_height] = @water_height ,[terrain_raise_limit] = @terrain_raise_limit
  1175. ,[terrain_lower_limit] = @terrain_lower_limit ,[use_estate_sun] = @use_estate_sun ,[fixed_sun] = @fixed_sun ,[sun_position] = @sun_position
  1176. ,[covenant] = @covenant , [sunvectorx] = @sunvectorx, [sunvectory] = @sunvectory, [sunvectorz] = @sunvectorz, [Sandbox] = @Sandbox, [loaded_creation_datetime] = @loaded_creation_datetime, [loaded_creation_id] = @loaded_creation_id
  1177. WHERE [regionUUID] = @regionUUID";
  1178. using (SqlConnection conn = new SqlConnection(m_connectionString))
  1179. using (SqlCommand cmd = new SqlCommand(sql, conn))
  1180. {
  1181. cmd.Parameters.AddRange(CreateRegionSettingParameters(regionSettings));
  1182. conn.Open();
  1183. cmd.ExecuteNonQuery();
  1184. }
  1185. }
  1186. }
  1187. public void Shutdown()
  1188. {
  1189. //Not used??
  1190. }
  1191. #region Private Methods
  1192. /// <summary>
  1193. /// Serializes the terrain data for storage in DB.
  1194. /// </summary>
  1195. /// <param name="val">terrain data</param>
  1196. /// <returns></returns>
  1197. private static Array serializeTerrain(double[,] val)
  1198. {
  1199. MemoryStream str = new MemoryStream(((int)Constants.RegionSize * (int)Constants.RegionSize) * sizeof(double));
  1200. BinaryWriter bw = new BinaryWriter(str);
  1201. // TODO: COMPATIBILITY - Add byte-order conversions
  1202. for (int x = 0; x < (int)Constants.RegionSize; x++)
  1203. for (int y = 0; y < (int)Constants.RegionSize; y++)
  1204. {
  1205. double height = val[x, y];
  1206. if (height == 0.0)
  1207. height = double.Epsilon;
  1208. bw.Write(height);
  1209. }
  1210. return str.ToArray();
  1211. }
  1212. /// <summary>
  1213. /// Stores new regionsettings.
  1214. /// </summary>
  1215. /// <param name="regionSettings">The region settings.</param>
  1216. private void StoreNewRegionSettings(RegionSettings regionSettings)
  1217. {
  1218. string sql = @"INSERT INTO [regionsettings]
  1219. ([regionUUID],[block_terraform],[block_fly],[allow_damage],[restrict_pushing],[allow_land_resell],[allow_land_join_divide],
  1220. [block_show_in_search],[agent_limit],[object_bonus],[maturity],[disable_scripts],[disable_collisions],[disable_physics],
  1221. [terrain_texture_1],[terrain_texture_2],[terrain_texture_3],[terrain_texture_4],[elevation_1_nw],[elevation_2_nw],[elevation_1_ne],
  1222. [elevation_2_ne],[elevation_1_se],[elevation_2_se],[elevation_1_sw],[elevation_2_sw],[water_height],[terrain_raise_limit],
  1223. [terrain_lower_limit],[use_estate_sun],[fixed_sun],[sun_position],[covenant],[sunvectorx], [sunvectory], [sunvectorz],[Sandbox], [loaded_creation_datetime], [loaded_creation_id]
  1224. )
  1225. VALUES
  1226. (@regionUUID,@block_terraform,@block_fly,@allow_damage,@restrict_pushing,@allow_land_resell,@allow_land_join_divide,
  1227. @block_show_in_search,@agent_limit,@object_bonus,@maturity,@disable_scripts,@disable_collisions,@disable_physics,
  1228. @terrain_texture_1,@terrain_texture_2,@terrain_texture_3,@terrain_texture_4,@elevation_1_nw,@elevation_2_nw,@elevation_1_ne,
  1229. @elevation_2_ne,@elevation_1_se,@elevation_2_se,@elevation_1_sw,@elevation_2_sw,@water_height,@terrain_raise_limit,
  1230. @terrain_lower_limit,@use_estate_sun,@fixed_sun,@sun_position,@covenant,@sunvectorx,@sunvectory, @sunvectorz, @Sandbox, @loaded_creation_datetime, @loaded_creation_id)";
  1231. using (SqlConnection conn = new SqlConnection(m_connectionString))
  1232. using (SqlCommand cmd = new SqlCommand(sql, conn))
  1233. {
  1234. cmd.Parameters.AddRange(CreateRegionSettingParameters(regionSettings));
  1235. conn.Open();
  1236. cmd.ExecuteNonQuery();
  1237. }
  1238. }
  1239. #region Private DataRecord conversion methods
  1240. /// <summary>
  1241. /// Builds the region settings from a datarecod.
  1242. /// </summary>
  1243. /// <param name="row">datarecord with regionsettings.</param>
  1244. /// <returns></returns>
  1245. private static RegionSettings BuildRegionSettings(IDataRecord row)
  1246. {
  1247. //TODO change this is some more generic code so we doesnt have to change it every time a new field is added?
  1248. RegionSettings newSettings = new RegionSettings();
  1249. newSettings.RegionUUID = new UUID((Guid)row["regionUUID"]);
  1250. newSettings.BlockTerraform = Convert.ToBoolean(row["block_terraform"]);
  1251. newSettings.AllowDamage = Convert.ToBoolean(row["allow_damage"]);
  1252. newSettings.BlockFly = Convert.ToBoolean(row["block_fly"]);
  1253. newSettings.RestrictPushing = Convert.ToBoolean(row["restrict_pushing"]);
  1254. newSettings.AllowLandResell = Convert.ToBoolean(row["allow_land_resell"]);
  1255. newSettings.AllowLandJoinDivide = Convert.ToBoolean(row["allow_land_join_divide"]);
  1256. newSettings.BlockShowInSearch = Convert.ToBoolean(row["block_show_in_search"]);
  1257. newSettings.AgentLimit = Convert.ToInt32(row["agent_limit"]);
  1258. newSettings.ObjectBonus = Convert.ToDouble(row["object_bonus"]);
  1259. newSettings.Maturity = Convert.ToInt32(row["maturity"]);
  1260. newSettings.DisableScripts = Convert.ToBoolean(row["disable_scripts"]);
  1261. newSettings.DisableCollisions = Convert.ToBoolean(row["disable_collisions"]);
  1262. newSettings.DisablePhysics = Convert.ToBoolean(row["disable_physics"]);
  1263. newSettings.TerrainTexture1 = new UUID((Guid)row["terrain_texture_1"]);
  1264. newSettings.TerrainTexture2 = new UUID((Guid)row["terrain_texture_2"]);
  1265. newSettings.TerrainTexture3 = new UUID((Guid)row["terrain_texture_3"]);
  1266. newSettings.TerrainTexture4 = new UUID((Guid)row["terrain_texture_4"]);
  1267. newSettings.Elevation1NW = Convert.ToDouble(row["elevation_1_nw"]);
  1268. newSettings.Elevation2NW = Convert.ToDouble(row["elevation_2_nw"]);
  1269. newSettings.Elevation1NE = Convert.ToDouble(row["elevation_1_ne"]);
  1270. newSettings.Elevation2NE = Convert.ToDouble(row["elevation_2_ne"]);
  1271. newSettings.Elevation1SE = Convert.ToDouble(row["elevation_1_se"]);
  1272. newSettings.Elevation2SE = Convert.ToDouble(row["elevation_2_se"]);
  1273. newSettings.Elevation1SW = Convert.ToDouble(row["elevation_1_sw"]);
  1274. newSettings.Elevation2SW = Convert.ToDouble(row["elevation_2_sw"]);
  1275. newSettings.WaterHeight = Convert.ToDouble(row["water_height"]);
  1276. newSettings.TerrainRaiseLimit = Convert.ToDouble(row["terrain_raise_limit"]);
  1277. newSettings.TerrainLowerLimit = Convert.ToDouble(row["terrain_lower_limit"]);
  1278. newSettings.UseEstateSun = Convert.ToBoolean(row["use_estate_sun"]);
  1279. newSettings.Sandbox = Convert.ToBoolean(row["sandbox"]);
  1280. newSettings.FixedSun = Convert.ToBoolean(row["fixed_sun"]);
  1281. newSettings.SunPosition = Convert.ToDouble(row["sun_position"]);
  1282. newSettings.SunVector = new Vector3(
  1283. Convert.ToSingle(row["sunvectorx"]),
  1284. Convert.ToSingle(row["sunvectory"]),
  1285. Convert.ToSingle(row["sunvectorz"])
  1286. );
  1287. newSettings.Covenant = new UUID((Guid)row["covenant"]);
  1288. newSettings.LoadedCreationDateTime = Convert.ToInt32(row["loaded_creation_datetime"]);
  1289. if (row["loaded_creation_id"] is DBNull)
  1290. newSettings.LoadedCreationID = "";
  1291. else
  1292. newSettings.LoadedCreationID = (String)row["loaded_creation_id"];
  1293. return newSettings;
  1294. }
  1295. /// <summary>
  1296. /// Builds the land data from a datarecord.
  1297. /// </summary>
  1298. /// <param name="row">datarecord with land data</param>
  1299. /// <returns></returns>
  1300. private static LandData BuildLandData(IDataRecord row)
  1301. {
  1302. LandData newData = new LandData();
  1303. newData.GlobalID = new UUID((Guid)row["UUID"]);
  1304. newData.LocalID = Convert.ToInt32(row["LocalLandID"]);
  1305. // Bitmap is a byte[512]
  1306. newData.Bitmap = (Byte[])row["Bitmap"];
  1307. newData.Name = (string)row["Name"];
  1308. newData.Description = (string)row["Description"];
  1309. newData.OwnerID = new UUID((Guid)row["OwnerUUID"]);
  1310. newData.IsGroupOwned = Convert.ToBoolean(row["IsGroupOwned"]);
  1311. newData.Area = Convert.ToInt32(row["Area"]);
  1312. newData.AuctionID = Convert.ToUInt32(row["AuctionID"]); //Unemplemented
  1313. newData.Category = (ParcelCategory)Convert.ToInt32(row["Category"]);
  1314. //Enum libsecondlife.Parcel.ParcelCategory
  1315. newData.ClaimDate = Convert.ToInt32(row["ClaimDate"]);
  1316. newData.ClaimPrice = Convert.ToInt32(row["ClaimPrice"]);
  1317. newData.GroupID = new UUID((Guid)row["GroupUUID"]);
  1318. newData.SalePrice = Convert.ToInt32(row["SalePrice"]);
  1319. newData.Status = (ParcelStatus)Convert.ToInt32(row["LandStatus"]);
  1320. //Enum. libsecondlife.Parcel.ParcelStatus
  1321. newData.Flags = Convert.ToUInt32(row["LandFlags"]);
  1322. newData.LandingType = Convert.ToByte(row["LandingType"]);
  1323. newData.MediaAutoScale = Convert.ToByte(row["MediaAutoScale"]);
  1324. newData.MediaID = new UUID((Guid)row["MediaTextureUUID"]);
  1325. newData.MediaURL = (string)row["MediaURL"];
  1326. newData.MusicURL = (string)row["MusicURL"];
  1327. newData.PassHours = Convert.ToSingle(row["PassHours"]);
  1328. newData.PassPrice = Convert.ToInt32(row["PassPrice"]);
  1329. // UUID authedbuyer;
  1330. // UUID snapshotID;
  1331. //
  1332. // if (UUID.TryParse((string)row["AuthBuyerID"], out authedbuyer))
  1333. // newData.AuthBuyerID = authedbuyer;
  1334. //
  1335. // if (UUID.TryParse((string)row["SnapshotUUID"], out snapshotID))
  1336. // newData.SnapshotID = snapshotID;
  1337. newData.AuthBuyerID = new UUID((Guid)row["AuthBuyerID"]);
  1338. newData.SnapshotID = new UUID((Guid)row["SnapshotUUID"]);
  1339. newData.OtherCleanTime = Convert.ToInt32(row["OtherCleanTime"]);
  1340. try
  1341. {
  1342. newData.UserLocation =
  1343. new Vector3(Convert.ToSingle(row["UserLocationX"]), Convert.ToSingle(row["UserLocationY"]),
  1344. Convert.ToSingle(row["UserLocationZ"]));
  1345. newData.UserLookAt =
  1346. new Vector3(Convert.ToSingle(row["UserLookAtX"]), Convert.ToSingle(row["UserLookAtY"]),
  1347. Convert.ToSingle(row["UserLookAtZ"]));
  1348. }
  1349. catch (InvalidCastException)
  1350. {
  1351. newData.UserLocation = Vector3.Zero;
  1352. newData.UserLookAt = Vector3.Zero;
  1353. _Log.ErrorFormat("[PARCEL]: unable to get parcel telehub settings for {1}", newData.Name);
  1354. }
  1355. newData.ParcelAccessList = new List<ParcelManager.ParcelAccessEntry>();
  1356. return newData;
  1357. }
  1358. /// <summary>
  1359. /// Builds the landaccess data from a data record.
  1360. /// </summary>
  1361. /// <param name="row">datarecord with landaccess data</param>
  1362. /// <returns></returns>
  1363. private static ParcelManager.ParcelAccessEntry BuildLandAccessData(IDataRecord row)
  1364. {
  1365. ParcelManager.ParcelAccessEntry entry = new ParcelManager.ParcelAccessEntry();
  1366. entry.AgentID = new UUID((Guid)row["AccessUUID"]);
  1367. entry.Flags = (AccessList)Convert.ToInt32(row["Flags"]);
  1368. entry.Time = new DateTime();
  1369. return entry;
  1370. }
  1371. /// <summary>
  1372. /// Builds the prim from a datarecord.
  1373. /// </summary>
  1374. /// <param name="primRow">datarecord</param>
  1375. /// <returns></returns>
  1376. private static SceneObjectPart BuildPrim(IDataRecord primRow)
  1377. {
  1378. SceneObjectPart prim = new SceneObjectPart();
  1379. prim.UUID = new UUID((Guid)primRow["UUID"]);
  1380. // explicit conversion of integers is required, which sort
  1381. // of sucks. No idea if there is a shortcut here or not.
  1382. prim.CreationDate = Convert.ToInt32(primRow["CreationDate"]);
  1383. prim.Name = (string)primRow["Name"];
  1384. // various text fields
  1385. prim.Text = (string)primRow["Text"];
  1386. prim.Color = Color.FromArgb(Convert.ToInt32(primRow["ColorA"]),
  1387. Convert.ToInt32(primRow["ColorR"]),
  1388. Convert.ToInt32(primRow["ColorG"]),
  1389. Convert.ToInt32(primRow["ColorB"]));
  1390. prim.Description = (string)primRow["Description"];
  1391. prim.SitName = (string)primRow["SitName"];
  1392. prim.TouchName = (string)primRow["TouchName"];
  1393. // permissions
  1394. prim.Flags = (PrimFlags)Convert.ToUInt32(primRow["ObjectFlags"]);
  1395. prim.CreatorID = new UUID((Guid)primRow["CreatorID"]);
  1396. prim.OwnerID = new UUID((Guid)primRow["OwnerID"]);
  1397. prim.GroupID = new UUID((Guid)primRow["GroupID"]);
  1398. prim.LastOwnerID = new UUID((Guid)primRow["LastOwnerID"]);
  1399. prim.OwnerMask = Convert.ToUInt32(primRow["OwnerMask"]);
  1400. prim.NextOwnerMask = Convert.ToUInt32(primRow["NextOwnerMask"]);
  1401. prim.GroupMask = Convert.ToUInt32(primRow["GroupMask"]);
  1402. prim.EveryoneMask = Convert.ToUInt32(primRow["EveryoneMask"]);
  1403. prim.BaseMask = Convert.ToUInt32(primRow["BaseMask"]);
  1404. // vectors
  1405. prim.OffsetPosition = new Vector3(
  1406. Convert.ToSingle(primRow["PositionX"]),
  1407. Convert.ToSingle(primRow["PositionY"]),
  1408. Convert.ToSingle(primRow["PositionZ"]));
  1409. prim.GroupPosition = new Vector3(
  1410. Convert.ToSingle(primRow["GroupPositionX"]),
  1411. Convert.ToSingle(primRow["GroupPositionY"]),
  1412. Convert.ToSingle(primRow["GroupPositionZ"]));
  1413. prim.Velocity = new Vector3(
  1414. Convert.ToSingle(primRow["VelocityX"]),
  1415. Convert.ToSingle(primRow["VelocityY"]),
  1416. Convert.ToSingle(primRow["VelocityZ"]));
  1417. prim.AngularVelocity = new Vector3(
  1418. Convert.ToSingle(primRow["AngularVelocityX"]),
  1419. Convert.ToSingle(primRow["AngularVelocityY"]),
  1420. Convert.ToSingle(primRow["AngularVelocityZ"]));
  1421. prim.Acceleration = new Vector3(
  1422. Convert.ToSingle(primRow["AccelerationX"]),
  1423. Convert.ToSingle(primRow["AccelerationY"]),
  1424. Convert.ToSingle(primRow["AccelerationZ"]));
  1425. // quaternions
  1426. prim.RotationOffset = new Quaternion(
  1427. Convert.ToSingle(primRow["RotationX"]),
  1428. Convert.ToSingle(primRow["RotationY"]),
  1429. Convert.ToSingle(primRow["RotationZ"]),
  1430. Convert.ToSingle(primRow["RotationW"]));
  1431. prim.SitTargetPositionLL = new Vector3(
  1432. Convert.ToSingle(primRow["SitTargetOffsetX"]),
  1433. Convert.ToSingle(primRow["SitTargetOffsetY"]),
  1434. Convert.ToSingle(primRow["SitTargetOffsetZ"]));
  1435. prim.SitTargetOrientationLL = new Quaternion(
  1436. Convert.ToSingle(primRow["SitTargetOrientX"]),
  1437. Convert.ToSingle(primRow["SitTargetOrientY"]),
  1438. Convert.ToSingle(primRow["SitTargetOrientZ"]),
  1439. Convert.ToSingle(primRow["SitTargetOrientW"]));
  1440. prim.PayPrice[0] = Convert.ToInt32(primRow["PayPrice"]);
  1441. prim.PayPrice[1] = Convert.ToInt32(primRow["PayButton1"]);
  1442. prim.PayPrice[2] = Convert.ToInt32(primRow["PayButton2"]);
  1443. prim.PayPrice[3] = Convert.ToInt32(primRow["PayButton3"]);
  1444. prim.PayPrice[4] = Convert.ToInt32(primRow["PayButton4"]);
  1445. prim.Sound = new UUID((Guid)primRow["LoopedSound"]);
  1446. prim.SoundGain = Convert.ToSingle(primRow["LoopedSoundGain"]);
  1447. prim.SoundFlags = 1; // If it's persisted at all, it's looped
  1448. if (!(primRow["TextureAnimation"] is DBNull))
  1449. prim.TextureAnimation = (Byte[])primRow["TextureAnimation"];
  1450. if (!(primRow["ParticleSystem"] is DBNull))
  1451. prim.ParticleSystem = (Byte[])primRow["ParticleSystem"];
  1452. prim.AngularVelocity = new Vector3(
  1453. Convert.ToSingle(primRow["OmegaX"]),
  1454. Convert.ToSingle(primRow["OmegaY"]),
  1455. Convert.ToSingle(primRow["OmegaZ"]));
  1456. prim.SetCameraEyeOffset(new Vector3(
  1457. Convert.ToSingle(primRow["CameraEyeOffsetX"]),
  1458. Convert.ToSingle(primRow["CameraEyeOffsetY"]),
  1459. Convert.ToSingle(primRow["CameraEyeOffsetZ"])
  1460. ));
  1461. prim.SetCameraAtOffset(new Vector3(
  1462. Convert.ToSingle(primRow["CameraAtOffsetX"]),
  1463. Convert.ToSingle(primRow["CameraAtOffsetY"]),
  1464. Convert.ToSingle(primRow["CameraAtOffsetZ"])
  1465. ));
  1466. if (Convert.ToInt16(primRow["ForceMouselook"]) != 0)
  1467. prim.SetForceMouselook(true);
  1468. prim.ScriptAccessPin = Convert.ToInt32(primRow["ScriptAccessPin"]);
  1469. if (Convert.ToInt16(primRow["AllowedDrop"]) != 0)
  1470. prim.AllowedDrop = true;
  1471. if (Convert.ToInt16(primRow["DieAtEdge"]) != 0)
  1472. prim.DIE_AT_EDGE = true;
  1473. prim.SalePrice = Convert.ToInt32(primRow["SalePrice"]);
  1474. prim.ObjectSaleType = Convert.ToByte(primRow["SaleType"]);
  1475. prim.Material = Convert.ToByte(primRow["Material"]);
  1476. if (!(primRow["ClickAction"] is DBNull))
  1477. prim.ClickAction = Convert.ToByte(primRow["ClickAction"]);
  1478. prim.CollisionSound = new UUID((Guid)primRow["CollisionSound"]);
  1479. prim.CollisionSoundVolume = Convert.ToSingle(primRow["CollisionSoundVolume"]);
  1480. if (Convert.ToInt16(primRow["PassTouches"]) != 0)
  1481. prim.PassTouches = true;
  1482. prim.LinkNum = Convert.ToInt32(primRow["LinkNumber"]);
  1483. if (!(primRow["MediaURL"] is System.DBNull))
  1484. prim.MediaUrl = (string)primRow["MediaURL"];
  1485. return prim;
  1486. }
  1487. /// <summary>
  1488. /// Builds the prim shape from a datarecord.
  1489. /// </summary>
  1490. /// <param name="shapeRow">The row.</param>
  1491. /// <returns></returns>
  1492. private static PrimitiveBaseShape BuildShape(IDataRecord shapeRow)
  1493. {
  1494. PrimitiveBaseShape baseShape = new PrimitiveBaseShape();
  1495. baseShape.Scale = new Vector3(
  1496. (float)Convert.ToDouble(shapeRow["ScaleX"]),
  1497. (float)Convert.ToDouble(shapeRow["ScaleY"]),
  1498. (float)Convert.ToDouble(shapeRow["ScaleZ"]));
  1499. // paths
  1500. baseShape.PCode = Convert.ToByte(shapeRow["PCode"]);
  1501. baseShape.PathBegin = Convert.ToUInt16(shapeRow["PathBegin"]);
  1502. baseShape.PathEnd = Convert.ToUInt16(shapeRow["PathEnd"]);
  1503. baseShape.PathScaleX = Convert.ToByte(shapeRow["PathScaleX"]);
  1504. baseShape.PathScaleY = Convert.ToByte(shapeRow["PathScaleY"]);
  1505. baseShape.PathShearX = Convert.ToByte(shapeRow["PathShearX"]);
  1506. baseShape.PathShearY = Convert.ToByte(shapeRow["PathShearY"]);
  1507. baseShape.PathSkew = Convert.ToSByte(shapeRow["PathSkew"]);
  1508. baseShape.PathCurve = Convert.ToByte(shapeRow["PathCurve"]);
  1509. baseShape.PathRadiusOffset = Convert.ToSByte(shapeRow["PathRadiusOffset"]);
  1510. baseShape.PathRevolutions = Convert.ToByte(shapeRow["PathRevolutions"]);
  1511. baseShape.PathTaperX = Convert.ToSByte(shapeRow["PathTaperX"]);
  1512. baseShape.PathTaperY = Convert.ToSByte(shapeRow["PathTaperY"]);
  1513. baseShape.PathTwist = Convert.ToSByte(shapeRow["PathTwist"]);
  1514. baseShape.PathTwistBegin = Convert.ToSByte(shapeRow["PathTwistBegin"]);
  1515. // profile
  1516. baseShape.ProfileBegin = Convert.ToUInt16(shapeRow["ProfileBegin"]);
  1517. baseShape.ProfileEnd = Convert.ToUInt16(shapeRow["ProfileEnd"]);
  1518. baseShape.ProfileCurve = Convert.ToByte(shapeRow["ProfileCurve"]);
  1519. baseShape.ProfileHollow = Convert.ToUInt16(shapeRow["ProfileHollow"]);
  1520. byte[] textureEntry = (byte[])shapeRow["Texture"];
  1521. baseShape.TextureEntry = textureEntry;
  1522. baseShape.ExtraParams = (byte[])shapeRow["ExtraParams"];
  1523. try
  1524. {
  1525. baseShape.State = Convert.ToByte(shapeRow["State"]);
  1526. }
  1527. catch (InvalidCastException)
  1528. {
  1529. }
  1530. if (!(shapeRow["Media"] is System.DBNull))
  1531. {
  1532. baseShape.Media = PrimitiveBaseShape.MediaList.FromXml((string)shapeRow["Media"]);
  1533. }
  1534. return baseShape;
  1535. }
  1536. /// <summary>
  1537. /// Build a prim inventory item from the persisted data.
  1538. /// </summary>
  1539. /// <param name="inventoryRow"></param>
  1540. /// <returns></returns>
  1541. private static TaskInventoryItem BuildItem(IDataRecord inventoryRow)
  1542. {
  1543. TaskInventoryItem taskItem = new TaskInventoryItem();
  1544. taskItem.ItemID = new UUID((Guid)inventoryRow["itemID"]);
  1545. taskItem.ParentPartID = new UUID((Guid)inventoryRow["primID"]);
  1546. taskItem.AssetID = new UUID((Guid)inventoryRow["assetID"]);
  1547. taskItem.ParentID = new UUID((Guid)inventoryRow["parentFolderID"]);
  1548. taskItem.InvType = Convert.ToInt32(inventoryRow["invType"]);
  1549. taskItem.Type = Convert.ToInt32(inventoryRow["assetType"]);
  1550. taskItem.Name = (string)inventoryRow["name"];
  1551. taskItem.Description = (string)inventoryRow["description"];
  1552. taskItem.CreationDate = Convert.ToUInt32(inventoryRow["creationDate"]);
  1553. taskItem.CreatorID = new UUID((Guid)inventoryRow["creatorID"]);
  1554. taskItem.OwnerID = new UUID((Guid)inventoryRow["ownerID"]);
  1555. taskItem.LastOwnerID = new UUID((Guid)inventoryRow["lastOwnerID"]);
  1556. taskItem.GroupID = new UUID((Guid)inventoryRow["groupID"]);
  1557. taskItem.NextPermissions = Convert.ToUInt32(inventoryRow["nextPermissions"]);
  1558. taskItem.CurrentPermissions = Convert.ToUInt32(inventoryRow["currentPermissions"]);
  1559. taskItem.BasePermissions = Convert.ToUInt32(inventoryRow["basePermissions"]);
  1560. taskItem.EveryonePermissions = Convert.ToUInt32(inventoryRow["everyonePermissions"]);
  1561. taskItem.GroupPermissions = Convert.ToUInt32(inventoryRow["groupPermissions"]);
  1562. taskItem.Flags = Convert.ToUInt32(inventoryRow["flags"]);
  1563. return taskItem;
  1564. }
  1565. #endregion
  1566. #region Create parameters methods
  1567. /// <summary>
  1568. /// Creates the prim inventory parameters.
  1569. /// </summary>
  1570. /// <param name="taskItem">item in inventory.</param>
  1571. /// <returns></returns>
  1572. private SqlParameter[] CreatePrimInventoryParameters(TaskInventoryItem taskItem)
  1573. {
  1574. List<SqlParameter> parameters = new List<SqlParameter>();
  1575. parameters.Add(_Database.CreateParameter("itemID", taskItem.ItemID));
  1576. parameters.Add(_Database.CreateParameter("primID", taskItem.ParentPartID));
  1577. parameters.Add(_Database.CreateParameter("assetID", taskItem.AssetID));
  1578. parameters.Add(_Database.CreateParameter("parentFolderID", taskItem.ParentID));
  1579. parameters.Add(_Database.CreateParameter("invType", taskItem.InvType));
  1580. parameters.Add(_Database.CreateParameter("assetType", taskItem.Type));
  1581. parameters.Add(_Database.CreateParameter("name", taskItem.Name));
  1582. parameters.Add(_Database.CreateParameter("description", taskItem.Description));
  1583. parameters.Add(_Database.CreateParameter("creationDate", taskItem.CreationDate));
  1584. parameters.Add(_Database.CreateParameter("creatorID", taskItem.CreatorID));
  1585. parameters.Add(_Database.CreateParameter("ownerID", taskItem.OwnerID));
  1586. parameters.Add(_Database.CreateParameter("lastOwnerID", taskItem.LastOwnerID));
  1587. parameters.Add(_Database.CreateParameter("groupID", taskItem.GroupID));
  1588. parameters.Add(_Database.CreateParameter("nextPermissions", taskItem.NextPermissions));
  1589. parameters.Add(_Database.CreateParameter("currentPermissions", taskItem.CurrentPermissions));
  1590. parameters.Add(_Database.CreateParameter("basePermissions", taskItem.BasePermissions));
  1591. parameters.Add(_Database.CreateParameter("everyonePermissions", taskItem.EveryonePermissions));
  1592. parameters.Add(_Database.CreateParameter("groupPermissions", taskItem.GroupPermissions));
  1593. parameters.Add(_Database.CreateParameter("flags", taskItem.Flags));
  1594. return parameters.ToArray();
  1595. }
  1596. /// <summary>
  1597. /// Creates the region setting parameters.
  1598. /// </summary>
  1599. /// <param name="settings">regionsettings.</param>
  1600. /// <returns></returns>
  1601. private SqlParameter[] CreateRegionSettingParameters(RegionSettings settings)
  1602. {
  1603. List<SqlParameter> parameters = new List<SqlParameter>();
  1604. parameters.Add(_Database.CreateParameter("regionUUID", settings.RegionUUID));
  1605. parameters.Add(_Database.CreateParameter("block_terraform", settings.BlockTerraform));
  1606. parameters.Add(_Database.CreateParameter("block_fly", settings.BlockFly));
  1607. parameters.Add(_Database.CreateParameter("allow_damage", settings.AllowDamage));
  1608. parameters.Add(_Database.CreateParameter("restrict_pushing", settings.RestrictPushing));
  1609. parameters.Add(_Database.CreateParameter("allow_land_resell", settings.AllowLandResell));
  1610. parameters.Add(_Database.CreateParameter("allow_land_join_divide", settings.AllowLandJoinDivide));
  1611. parameters.Add(_Database.CreateParameter("block_show_in_search", settings.BlockShowInSearch));
  1612. parameters.Add(_Database.CreateParameter("agent_limit", settings.AgentLimit));
  1613. parameters.Add(_Database.CreateParameter("object_bonus", settings.ObjectBonus));
  1614. parameters.Add(_Database.CreateParameter("maturity", settings.Maturity));
  1615. parameters.Add(_Database.CreateParameter("disable_scripts", settings.DisableScripts));
  1616. parameters.Add(_Database.CreateParameter("disable_collisions", settings.DisableCollisions));
  1617. parameters.Add(_Database.CreateParameter("disable_physics", settings.DisablePhysics));
  1618. parameters.Add(_Database.CreateParameter("terrain_texture_1", settings.TerrainTexture1));
  1619. parameters.Add(_Database.CreateParameter("terrain_texture_2", settings.TerrainTexture2));
  1620. parameters.Add(_Database.CreateParameter("terrain_texture_3", settings.TerrainTexture3));
  1621. parameters.Add(_Database.CreateParameter("terrain_texture_4", settings.TerrainTexture4));
  1622. parameters.Add(_Database.CreateParameter("elevation_1_nw", settings.Elevation1NW));
  1623. parameters.Add(_Database.CreateParameter("elevation_2_nw", settings.Elevation2NW));
  1624. parameters.Add(_Database.CreateParameter("elevation_1_ne", settings.Elevation1NE));
  1625. parameters.Add(_Database.CreateParameter("elevation_2_ne", settings.Elevation2NE));
  1626. parameters.Add(_Database.CreateParameter("elevation_1_se", settings.Elevation1SE));
  1627. parameters.Add(_Database.CreateParameter("elevation_2_se", settings.Elevation2SE));
  1628. parameters.Add(_Database.CreateParameter("elevation_1_sw", settings.Elevation1SW));
  1629. parameters.Add(_Database.CreateParameter("elevation_2_sw", settings.Elevation2SW));
  1630. parameters.Add(_Database.CreateParameter("water_height", settings.WaterHeight));
  1631. parameters.Add(_Database.CreateParameter("terrain_raise_limit", settings.TerrainRaiseLimit));
  1632. parameters.Add(_Database.CreateParameter("terrain_lower_limit", settings.TerrainLowerLimit));
  1633. parameters.Add(_Database.CreateParameter("use_estate_sun", settings.UseEstateSun));
  1634. parameters.Add(_Database.CreateParameter("sandbox", settings.Sandbox));
  1635. parameters.Add(_Database.CreateParameter("fixed_sun", settings.FixedSun));
  1636. parameters.Add(_Database.CreateParameter("sun_position", settings.SunPosition));
  1637. parameters.Add(_Database.CreateParameter("sunvectorx", settings.SunVector.X));
  1638. parameters.Add(_Database.CreateParameter("sunvectory", settings.SunVector.Y));
  1639. parameters.Add(_Database.CreateParameter("sunvectorz", settings.SunVector.Z));
  1640. parameters.Add(_Database.CreateParameter("covenant", settings.Covenant));
  1641. parameters.Add(_Database.CreateParameter("Loaded_Creation_DateTime", settings.LoadedCreationDateTime));
  1642. parameters.Add(_Database.CreateParameter("Loaded_Creation_ID", settings.LoadedCreationID));
  1643. return parameters.ToArray();
  1644. }
  1645. /// <summary>
  1646. /// Creates the land parameters.
  1647. /// </summary>
  1648. /// <param name="land">land parameters.</param>
  1649. /// <param name="regionUUID">region UUID.</param>
  1650. /// <returns></returns>
  1651. private SqlParameter[] CreateLandParameters(LandData land, UUID regionUUID)
  1652. {
  1653. List<SqlParameter> parameters = new List<SqlParameter>();
  1654. parameters.Add(_Database.CreateParameter("UUID", land.GlobalID));
  1655. parameters.Add(_Database.CreateParameter("RegionUUID", regionUUID));
  1656. parameters.Add(_Database.CreateParameter("LocalLandID", land.LocalID));
  1657. // Bitmap is a byte[512]
  1658. parameters.Add(_Database.CreateParameter("Bitmap", land.Bitmap));
  1659. parameters.Add(_Database.CreateParameter("Name", land.Name));
  1660. parameters.Add(_Database.CreateParameter("Description", land.Description));
  1661. parameters.Add(_Database.CreateParameter("OwnerUUID", land.OwnerID));
  1662. parameters.Add(_Database.CreateParameter("IsGroupOwned", land.IsGroupOwned));
  1663. parameters.Add(_Database.CreateParameter("Area", land.Area));
  1664. parameters.Add(_Database.CreateParameter("AuctionID", land.AuctionID)); //Unemplemented
  1665. parameters.Add(_Database.CreateParameter("Category", (int)land.Category)); //Enum libsecondlife.Parcel.ParcelCategory
  1666. parameters.Add(_Database.CreateParameter("ClaimDate", land.ClaimDate));
  1667. parameters.Add(_Database.CreateParameter("ClaimPrice", land.ClaimPrice));
  1668. parameters.Add(_Database.CreateParameter("GroupUUID", land.GroupID));
  1669. parameters.Add(_Database.CreateParameter("SalePrice", land.SalePrice));
  1670. parameters.Add(_Database.CreateParameter("LandStatus", (int)land.Status)); //Enum. libsecondlife.Parcel.ParcelStatus
  1671. parameters.Add(_Database.CreateParameter("LandFlags", land.Flags));
  1672. parameters.Add(_Database.CreateParameter("LandingType", land.LandingType));
  1673. parameters.Add(_Database.CreateParameter("MediaAutoScale", land.MediaAutoScale));
  1674. parameters.Add(_Database.CreateParameter("MediaTextureUUID", land.MediaID));
  1675. parameters.Add(_Database.CreateParameter("MediaURL", land.MediaURL));
  1676. parameters.Add(_Database.CreateParameter("MusicURL", land.MusicURL));
  1677. parameters.Add(_Database.CreateParameter("PassHours", land.PassHours));
  1678. parameters.Add(_Database.CreateParameter("PassPrice", land.PassPrice));
  1679. parameters.Add(_Database.CreateParameter("SnapshotUUID", land.SnapshotID));
  1680. parameters.Add(_Database.CreateParameter("UserLocationX", land.UserLocation.X));
  1681. parameters.Add(_Database.CreateParameter("UserLocationY", land.UserLocation.Y));
  1682. parameters.Add(_Database.CreateParameter("UserLocationZ", land.UserLocation.Z));
  1683. parameters.Add(_Database.CreateParameter("UserLookAtX", land.UserLookAt.X));
  1684. parameters.Add(_Database.CreateParameter("UserLookAtY", land.UserLookAt.Y));
  1685. parameters.Add(_Database.CreateParameter("UserLookAtZ", land.UserLookAt.Z));
  1686. parameters.Add(_Database.CreateParameter("AuthBuyerID", land.AuthBuyerID));
  1687. parameters.Add(_Database.CreateParameter("OtherCleanTime", land.OtherCleanTime));
  1688. return parameters.ToArray();
  1689. }
  1690. /// <summary>
  1691. /// Creates the land access parameters.
  1692. /// </summary>
  1693. /// <param name="parcelAccessEntry">parcel access entry.</param>
  1694. /// <param name="parcelID">parcel ID.</param>
  1695. /// <returns></returns>
  1696. private SqlParameter[] CreateLandAccessParameters(ParcelManager.ParcelAccessEntry parcelAccessEntry, UUID parcelID)
  1697. {
  1698. List<SqlParameter> parameters = new List<SqlParameter>();
  1699. parameters.Add(_Database.CreateParameter("LandUUID", parcelID));
  1700. parameters.Add(_Database.CreateParameter("AccessUUID", parcelAccessEntry.AgentID));
  1701. parameters.Add(_Database.CreateParameter("Flags", parcelAccessEntry.Flags));
  1702. return parameters.ToArray();
  1703. }
  1704. /// <summary>
  1705. /// Creates the prim parameters for storing in DB.
  1706. /// </summary>
  1707. /// <param name="prim">Basic data of SceneObjectpart prim.</param>
  1708. /// <param name="sceneGroupID">The scenegroup ID.</param>
  1709. /// <param name="regionUUID">The region ID.</param>
  1710. /// <returns></returns>
  1711. private SqlParameter[] CreatePrimParameters(SceneObjectPart prim, UUID sceneGroupID, UUID regionUUID)
  1712. {
  1713. List<SqlParameter> parameters = new List<SqlParameter>();
  1714. parameters.Add(_Database.CreateParameter("UUID", prim.UUID));
  1715. parameters.Add(_Database.CreateParameter("RegionUUID", regionUUID));
  1716. parameters.Add(_Database.CreateParameter("CreationDate", prim.CreationDate));
  1717. parameters.Add(_Database.CreateParameter("Name", prim.Name));
  1718. parameters.Add(_Database.CreateParameter("SceneGroupID", sceneGroupID));
  1719. // the UUID of the root part for this SceneObjectGroup
  1720. // various text fields
  1721. parameters.Add(_Database.CreateParameter("Text", prim.Text));
  1722. parameters.Add(_Database.CreateParameter("ColorR", prim.Color.R));
  1723. parameters.Add(_Database.CreateParameter("ColorG", prim.Color.G));
  1724. parameters.Add(_Database.CreateParameter("ColorB", prim.Color.B));
  1725. parameters.Add(_Database.CreateParameter("ColorA", prim.Color.A));
  1726. parameters.Add(_Database.CreateParameter("Description", prim.Description));
  1727. parameters.Add(_Database.CreateParameter("SitName", prim.SitName));
  1728. parameters.Add(_Database.CreateParameter("TouchName", prim.TouchName));
  1729. // permissions
  1730. parameters.Add(_Database.CreateParameter("ObjectFlags", (uint)prim.Flags));
  1731. parameters.Add(_Database.CreateParameter("CreatorID", prim.CreatorID));
  1732. parameters.Add(_Database.CreateParameter("OwnerID", prim.OwnerID));
  1733. parameters.Add(_Database.CreateParameter("GroupID", prim.GroupID));
  1734. parameters.Add(_Database.CreateParameter("LastOwnerID", prim.LastOwnerID));
  1735. parameters.Add(_Database.CreateParameter("OwnerMask", prim.OwnerMask));
  1736. parameters.Add(_Database.CreateParameter("NextOwnerMask", prim.NextOwnerMask));
  1737. parameters.Add(_Database.CreateParameter("GroupMask", prim.GroupMask));
  1738. parameters.Add(_Database.CreateParameter("EveryoneMask", prim.EveryoneMask));
  1739. parameters.Add(_Database.CreateParameter("BaseMask", prim.BaseMask));
  1740. // vectors
  1741. parameters.Add(_Database.CreateParameter("PositionX", prim.OffsetPosition.X));
  1742. parameters.Add(_Database.CreateParameter("PositionY", prim.OffsetPosition.Y));
  1743. parameters.Add(_Database.CreateParameter("PositionZ", prim.OffsetPosition.Z));
  1744. parameters.Add(_Database.CreateParameter("GroupPositionX", prim.GroupPosition.X));
  1745. parameters.Add(_Database.CreateParameter("GroupPositionY", prim.GroupPosition.Y));
  1746. parameters.Add(_Database.CreateParameter("GroupPositionZ", prim.GroupPosition.Z));
  1747. parameters.Add(_Database.CreateParameter("VelocityX", prim.Velocity.X));
  1748. parameters.Add(_Database.CreateParameter("VelocityY", prim.Velocity.Y));
  1749. parameters.Add(_Database.CreateParameter("VelocityZ", prim.Velocity.Z));
  1750. parameters.Add(_Database.CreateParameter("AngularVelocityX", prim.AngularVelocity.X));
  1751. parameters.Add(_Database.CreateParameter("AngularVelocityY", prim.AngularVelocity.Y));
  1752. parameters.Add(_Database.CreateParameter("AngularVelocityZ", prim.AngularVelocity.Z));
  1753. parameters.Add(_Database.CreateParameter("AccelerationX", prim.Acceleration.X));
  1754. parameters.Add(_Database.CreateParameter("AccelerationY", prim.Acceleration.Y));
  1755. parameters.Add(_Database.CreateParameter("AccelerationZ", prim.Acceleration.Z));
  1756. // quaternions
  1757. parameters.Add(_Database.CreateParameter("RotationX", prim.RotationOffset.X));
  1758. parameters.Add(_Database.CreateParameter("RotationY", prim.RotationOffset.Y));
  1759. parameters.Add(_Database.CreateParameter("RotationZ", prim.RotationOffset.Z));
  1760. parameters.Add(_Database.CreateParameter("RotationW", prim.RotationOffset.W));
  1761. // Sit target
  1762. Vector3 sitTargetPos = prim.SitTargetPositionLL;
  1763. parameters.Add(_Database.CreateParameter("SitTargetOffsetX", sitTargetPos.X));
  1764. parameters.Add(_Database.CreateParameter("SitTargetOffsetY", sitTargetPos.Y));
  1765. parameters.Add(_Database.CreateParameter("SitTargetOffsetZ", sitTargetPos.Z));
  1766. Quaternion sitTargetOrient = prim.SitTargetOrientationLL;
  1767. parameters.Add(_Database.CreateParameter("SitTargetOrientW", sitTargetOrient.W));
  1768. parameters.Add(_Database.CreateParameter("SitTargetOrientX", sitTargetOrient.X));
  1769. parameters.Add(_Database.CreateParameter("SitTargetOrientY", sitTargetOrient.Y));
  1770. parameters.Add(_Database.CreateParameter("SitTargetOrientZ", sitTargetOrient.Z));
  1771. parameters.Add(_Database.CreateParameter("PayPrice", prim.PayPrice[0]));
  1772. parameters.Add(_Database.CreateParameter("PayButton1", prim.PayPrice[1]));
  1773. parameters.Add(_Database.CreateParameter("PayButton2", prim.PayPrice[2]));
  1774. parameters.Add(_Database.CreateParameter("PayButton3", prim.PayPrice[3]));
  1775. parameters.Add(_Database.CreateParameter("PayButton4", prim.PayPrice[4]));
  1776. if ((prim.SoundFlags & 1) != 0) // Looped
  1777. {
  1778. parameters.Add(_Database.CreateParameter("LoopedSound", prim.Sound));
  1779. parameters.Add(_Database.CreateParameter("LoopedSoundGain", prim.SoundGain));
  1780. }
  1781. else
  1782. {
  1783. parameters.Add(_Database.CreateParameter("LoopedSound", UUID.Zero));
  1784. parameters.Add(_Database.CreateParameter("LoopedSoundGain", 0.0f));
  1785. }
  1786. parameters.Add(_Database.CreateParameter("TextureAnimation", prim.TextureAnimation));
  1787. parameters.Add(_Database.CreateParameter("ParticleSystem", prim.ParticleSystem));
  1788. parameters.Add(_Database.CreateParameter("OmegaX", prim.AngularVelocity.X));
  1789. parameters.Add(_Database.CreateParameter("OmegaY", prim.AngularVelocity.Y));
  1790. parameters.Add(_Database.CreateParameter("OmegaZ", prim.AngularVelocity.Z));
  1791. parameters.Add(_Database.CreateParameter("CameraEyeOffsetX", prim.GetCameraEyeOffset().X));
  1792. parameters.Add(_Database.CreateParameter("CameraEyeOffsetY", prim.GetCameraEyeOffset().Y));
  1793. parameters.Add(_Database.CreateParameter("CameraEyeOffsetZ", prim.GetCameraEyeOffset().Z));
  1794. parameters.Add(_Database.CreateParameter("CameraAtOffsetX", prim.GetCameraAtOffset().X));
  1795. parameters.Add(_Database.CreateParameter("CameraAtOffsetY", prim.GetCameraAtOffset().Y));
  1796. parameters.Add(_Database.CreateParameter("CameraAtOffsetZ", prim.GetCameraAtOffset().Z));
  1797. if (prim.GetForceMouselook())
  1798. parameters.Add(_Database.CreateParameter("ForceMouselook", 1));
  1799. else
  1800. parameters.Add(_Database.CreateParameter("ForceMouselook", 0));
  1801. parameters.Add(_Database.CreateParameter("ScriptAccessPin", prim.ScriptAccessPin));
  1802. if (prim.AllowedDrop)
  1803. parameters.Add(_Database.CreateParameter("AllowedDrop", 1));
  1804. else
  1805. parameters.Add(_Database.CreateParameter("AllowedDrop", 0));
  1806. if (prim.DIE_AT_EDGE)
  1807. parameters.Add(_Database.CreateParameter("DieAtEdge", 1));
  1808. else
  1809. parameters.Add(_Database.CreateParameter("DieAtEdge", 0));
  1810. parameters.Add(_Database.CreateParameter("SalePrice", prim.SalePrice));
  1811. parameters.Add(_Database.CreateParameter("SaleType", prim.ObjectSaleType));
  1812. byte clickAction = prim.ClickAction;
  1813. parameters.Add(_Database.CreateParameter("ClickAction", clickAction));
  1814. parameters.Add(_Database.CreateParameter("Material", prim.Material));
  1815. parameters.Add(_Database.CreateParameter("CollisionSound", prim.CollisionSound));
  1816. parameters.Add(_Database.CreateParameter("CollisionSoundVolume", prim.CollisionSoundVolume));
  1817. if (prim.PassTouches)
  1818. parameters.Add(_Database.CreateParameter("PassTouches", 1));
  1819. else
  1820. parameters.Add(_Database.CreateParameter("PassTouches", 0));
  1821. parameters.Add(_Database.CreateParameter("LinkNumber", prim.LinkNum));
  1822. parameters.Add(_Database.CreateParameter("MediaURL", prim.MediaUrl));
  1823. return parameters.ToArray();
  1824. }
  1825. /// <summary>
  1826. /// Creates the primshape parameters for stroing in DB.
  1827. /// </summary>
  1828. /// <param name="prim">Basic data of SceneObjectpart prim.</param>
  1829. /// <param name="sceneGroupID">The scene group ID.</param>
  1830. /// <param name="regionUUID">The region UUID.</param>
  1831. /// <returns></returns>
  1832. private SqlParameter[] CreatePrimShapeParameters(SceneObjectPart prim, UUID sceneGroupID, UUID regionUUID)
  1833. {
  1834. List<SqlParameter> parameters = new List<SqlParameter>();
  1835. PrimitiveBaseShape s = prim.Shape;
  1836. parameters.Add(_Database.CreateParameter("UUID", prim.UUID));
  1837. // shape is an enum
  1838. parameters.Add(_Database.CreateParameter("Shape", 0));
  1839. // vectors
  1840. parameters.Add(_Database.CreateParameter("ScaleX", s.Scale.X));
  1841. parameters.Add(_Database.CreateParameter("ScaleY", s.Scale.Y));
  1842. parameters.Add(_Database.CreateParameter("ScaleZ", s.Scale.Z));
  1843. // paths
  1844. parameters.Add(_Database.CreateParameter("PCode", s.PCode));
  1845. parameters.Add(_Database.CreateParameter("PathBegin", s.PathBegin));
  1846. parameters.Add(_Database.CreateParameter("PathEnd", s.PathEnd));
  1847. parameters.Add(_Database.CreateParameter("PathScaleX", s.PathScaleX));
  1848. parameters.Add(_Database.CreateParameter("PathScaleY", s.PathScaleY));
  1849. parameters.Add(_Database.CreateParameter("PathShearX", s.PathShearX));
  1850. parameters.Add(_Database.CreateParameter("PathShearY", s.PathShearY));
  1851. parameters.Add(_Database.CreateParameter("PathSkew", s.PathSkew));
  1852. parameters.Add(_Database.CreateParameter("PathCurve", s.PathCurve));
  1853. parameters.Add(_Database.CreateParameter("PathRadiusOffset", s.PathRadiusOffset));
  1854. parameters.Add(_Database.CreateParameter("PathRevolutions", s.PathRevolutions));
  1855. parameters.Add(_Database.CreateParameter("PathTaperX", s.PathTaperX));
  1856. parameters.Add(_Database.CreateParameter("PathTaperY", s.PathTaperY));
  1857. parameters.Add(_Database.CreateParameter("PathTwist", s.PathTwist));
  1858. parameters.Add(_Database.CreateParameter("PathTwistBegin", s.PathTwistBegin));
  1859. // profile
  1860. parameters.Add(_Database.CreateParameter("ProfileBegin", s.ProfileBegin));
  1861. parameters.Add(_Database.CreateParameter("ProfileEnd", s.ProfileEnd));
  1862. parameters.Add(_Database.CreateParameter("ProfileCurve", s.ProfileCurve));
  1863. parameters.Add(_Database.CreateParameter("ProfileHollow", s.ProfileHollow));
  1864. parameters.Add(_Database.CreateParameter("Texture", s.TextureEntry));
  1865. parameters.Add(_Database.CreateParameter("ExtraParams", s.ExtraParams));
  1866. parameters.Add(_Database.CreateParameter("State", s.State));
  1867. if (null == s.Media)
  1868. {
  1869. parameters.Add(_Database.CreateParameter("Media", DBNull.Value));
  1870. }
  1871. else
  1872. {
  1873. parameters.Add(_Database.CreateParameter("Media", s.Media.ToXml()));
  1874. }
  1875. return parameters.ToArray();
  1876. }
  1877. #endregion
  1878. #endregion
  1879. }
  1880. }