MSSQLSimulationData.cs 124 KB

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