MSSQLSimulationData.cs 124 KB

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