MSSQLSimulationData.cs 115 KB

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