PGSQLSimulationData.cs 125 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248
  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.Drawing;
  31. using System.IO;
  32. using System.Reflection;
  33. using log4net;
  34. using OpenMetaverse;
  35. using OpenSim.Framework;
  36. using OpenSim.Region.Framework.Interfaces;
  37. using OpenSim.Region.Framework.Scenes;
  38. using Npgsql;
  39. namespace OpenSim.Data.PGSQL
  40. {
  41. /// <summary>
  42. /// A PGSQL Interface for the Region Server.
  43. /// </summary>
  44. public class PGSQLSimulationData : ISimulationDataStore
  45. {
  46. private const string _migrationStore = "RegionStore";
  47. private const string LogHeader = "[REGION DB PGSQL]";
  48. // private static FileSystemDataStore Instance = new FileSystemDataStore();
  49. private static readonly ILog _Log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  50. /// <summary>
  51. /// The database manager
  52. /// </summary>
  53. private PGSQLManager _Database;
  54. private string m_connectionString;
  55. protected virtual Assembly Assembly
  56. {
  57. get { return GetType().Assembly; }
  58. }
  59. public PGSQLSimulationData()
  60. {
  61. }
  62. public PGSQLSimulationData(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 PGSQLManager(connectionString);
  74. using (NpgsqlConnection conn = new NpgsqlConnection(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. CASE WHEN prims.""UUID"" = prims.""SceneGroupID"" THEN 0 ELSE 1 END as sort
  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 (NpgsqlConnection conn = new NpgsqlConnection(m_connectionString))
  105. using (NpgsqlCommand command = new NpgsqlCommand(sql, conn))
  106. {
  107. command.Parameters.Add(_Database.CreateParameter("regionUUID", regionUUID));
  108. conn.Open();
  109. using (NpgsqlDataReader 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 (NpgsqlConnection conn = new NpgsqlConnection(m_connectionString))
  160. using (NpgsqlCommand command = new NpgsqlCommand(qry, conn))
  161. {
  162. conn.Open();
  163. using (NpgsqlDataReader 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 (NpgsqlConnection conn = new NpgsqlConnection(m_connectionString))
  190. using (NpgsqlCommand command = new NpgsqlCommand(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 (NpgsqlDataReader 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("[PGSQL]: Adding/Changing SceneObjectGroup: {0} to region: {1}, object has {2} prims.", obj.UUID, regionUUID, obj.Parts.Length);
  227. using (NpgsqlConnection conn = new NpgsqlConnection(m_connectionString))
  228. {
  229. conn.Open();
  230. NpgsqlTransaction transaction = conn.BeginTransaction();
  231. try
  232. {
  233. foreach (SceneObjectPart sceneObjectPart in obj.Parts)
  234. {
  235. //Update prim
  236. using (NpgsqlCommand sqlCommand = conn.CreateCommand())
  237. {
  238. sqlCommand.Transaction = transaction;
  239. try
  240. {
  241. StoreSceneObjectPrim(sceneObjectPart, sqlCommand, obj.UUID, regionUUID);
  242. }
  243. catch (NpgsqlException sqlEx)
  244. {
  245. _Log.ErrorFormat("[REGION DB]: Store SceneObjectPrim SQL error: {0} at line {1}", sqlEx.Message, sqlEx.Line);
  246. throw;
  247. }
  248. }
  249. //Update primshapes
  250. using (NpgsqlCommand sqlCommand = conn.CreateCommand())
  251. {
  252. sqlCommand.Transaction = transaction;
  253. try
  254. {
  255. StoreSceneObjectPrimShapes(sceneObjectPart, sqlCommand, obj.UUID, regionUUID);
  256. }
  257. catch (NpgsqlException sqlEx)
  258. {
  259. _Log.ErrorFormat("[REGION DB]: Store SceneObjectPrimShapes SQL error: {0} at line {1}", sqlEx.Message, sqlEx.Line);
  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, NpgsqlCommand sqlCommand, UUID sceneGroupID, UUID regionUUID)
  289. {
  290. //Big query to update or insert a new prim.
  291. string queryPrims = @"
  292. UPDATE prims SET
  293. ""CreationDate"" = :CreationDate, ""Name"" = :Name, ""Text"" = :Text, ""Description"" = :Description, ""SitName"" = :SitName,
  294. ""TouchName"" = :TouchName, ""ObjectFlags"" = :ObjectFlags, ""OwnerMask"" = :OwnerMask, ""NextOwnerMask"" = :NextOwnerMask, ""GroupMask"" = :GroupMask,
  295. ""EveryoneMask"" = :EveryoneMask, ""BaseMask"" = :BaseMask, ""PositionX"" = :PositionX, ""PositionY"" = :PositionY, ""PositionZ"" = :PositionZ,
  296. ""GroupPositionX"" = :GroupPositionX, ""GroupPositionY"" = :GroupPositionY, ""GroupPositionZ"" = :GroupPositionZ, ""VelocityX"" = :VelocityX,
  297. ""VelocityY"" = :VelocityY, ""VelocityZ"" = :VelocityZ, ""AngularVelocityX"" = :AngularVelocityX, ""AngularVelocityY"" = :AngularVelocityY,
  298. ""AngularVelocityZ"" = :AngularVelocityZ, ""AccelerationX"" = :AccelerationX, ""AccelerationY"" = :AccelerationY,
  299. ""AccelerationZ"" = :AccelerationZ, ""RotationX"" = :RotationX, ""RotationY"" = :RotationY, ""RotationZ"" = :RotationZ, ""RotationW"" = :RotationW,
  300. ""SitTargetOffsetX"" = :SitTargetOffsetX, ""SitTargetOffsetY"" = :SitTargetOffsetY, ""SitTargetOffsetZ"" = :SitTargetOffsetZ,
  301. ""SitTargetOrientW"" = :SitTargetOrientW, ""SitTargetOrientX"" = :SitTargetOrientX, ""SitTargetOrientY"" = :SitTargetOrientY,
  302. ""SitTargetOrientZ"" = :SitTargetOrientZ, ""RegionUUID"" = :RegionUUID, ""CreatorID"" = :CreatorID, ""OwnerID"" = :OwnerID, ""GroupID"" = :GroupID,
  303. ""LastOwnerID"" = :LastOwnerID, ""SceneGroupID"" = :SceneGroupID, ""PayPrice"" = :PayPrice, ""PayButton1"" = :PayButton1, ""PayButton2"" = :PayButton2,
  304. ""PayButton3"" = :PayButton3, ""PayButton4"" = :PayButton4, ""LoopedSound"" = :LoopedSound, ""LoopedSoundGain"" = :LoopedSoundGain,
  305. ""TextureAnimation"" = :TextureAnimation, ""OmegaX"" = :OmegaX, ""OmegaY"" = :OmegaY, ""OmegaZ"" = :OmegaZ, ""CameraEyeOffsetX"" = :CameraEyeOffsetX,
  306. ""CameraEyeOffsetY"" = :CameraEyeOffsetY, ""CameraEyeOffsetZ"" = :CameraEyeOffsetZ, ""CameraAtOffsetX"" = :CameraAtOffsetX,
  307. ""CameraAtOffsetY"" = :CameraAtOffsetY, ""CameraAtOffsetZ"" = :CameraAtOffsetZ, ""ForceMouselook"" = :ForceMouselook,
  308. ""ScriptAccessPin"" = :ScriptAccessPin, ""AllowedDrop"" = :AllowedDrop, ""DieAtEdge"" = :DieAtEdge, ""SalePrice"" = :SalePrice,
  309. ""SaleType"" = :SaleType, ""ColorR"" = :ColorR, ""ColorG"" = :ColorG, ""ColorB"" = :ColorB, ""ColorA"" = :ColorA, ""ParticleSystem"" = :ParticleSystem,
  310. ""ClickAction"" = :ClickAction, ""Material"" = :Material, ""CollisionSound"" = :CollisionSound, ""CollisionSoundVolume"" = :CollisionSoundVolume, ""PassTouches"" = :PassTouches,
  311. ""LinkNumber"" = :LinkNumber, ""MediaURL"" = :MediaURL, ""DynAttrs"" = :DynAttrs,
  312. ""PhysicsShapeType"" = :PhysicsShapeType, ""Density"" = :Density, ""GravityModifier"" = :GravityModifier, ""Friction"" = :Friction, ""Restitution"" = :Restitution
  313. WHERE ""UUID"" = :UUID ;
  314. INSERT INTO
  315. prims (
  316. ""UUID"", ""CreationDate"", ""Name"", ""Text"", ""Description"", ""SitName"", ""TouchName"", ""ObjectFlags"", ""OwnerMask"", ""NextOwnerMask"", ""GroupMask"",
  317. ""EveryoneMask"", ""BaseMask"", ""PositionX"", ""PositionY"", ""PositionZ"", ""GroupPositionX"", ""GroupPositionY"", ""GroupPositionZ"", ""VelocityX"",
  318. ""VelocityY"", ""VelocityZ"", ""AngularVelocityX"", ""AngularVelocityY"", ""AngularVelocityZ"", ""AccelerationX"", ""AccelerationY"", ""AccelerationZ"",
  319. ""RotationX"", ""RotationY"", ""RotationZ"", ""RotationW"", ""SitTargetOffsetX"", ""SitTargetOffsetY"", ""SitTargetOffsetZ"", ""SitTargetOrientW"",
  320. ""SitTargetOrientX"", ""SitTargetOrientY"", ""SitTargetOrientZ"", ""RegionUUID"", ""CreatorID"", ""OwnerID"", ""GroupID"", ""LastOwnerID"", ""SceneGroupID"",
  321. ""PayPrice"", ""PayButton1"", ""PayButton2"", ""PayButton3"", ""PayButton4"", ""LoopedSound"", ""LoopedSoundGain"", ""TextureAnimation"", ""OmegaX"",
  322. ""OmegaY"", ""OmegaZ"", ""CameraEyeOffsetX"", ""CameraEyeOffsetY"", ""CameraEyeOffsetZ"", ""CameraAtOffsetX"", ""CameraAtOffsetY"", ""CameraAtOffsetZ"",
  323. ""ForceMouselook"", ""ScriptAccessPin"", ""AllowedDrop"", ""DieAtEdge"", ""SalePrice"", ""SaleType"", ""ColorR"", ""ColorG"", ""ColorB"", ""ColorA"",
  324. ""ParticleSystem"", ""ClickAction"", ""Material"", ""CollisionSound"", ""CollisionSoundVolume"", ""PassTouches"", ""LinkNumber"", ""MediaURL"", ""DynAttrs"",
  325. ""PhysicsShapeType"", ""Density"", ""GravityModifier"", ""Friction"", ""Restitution""
  326. ) Select
  327. :UUID, :CreationDate, :Name, :Text, :Description, :SitName, :TouchName, :ObjectFlags, :OwnerMask, :NextOwnerMask, :GroupMask,
  328. :EveryoneMask, :BaseMask, :PositionX, :PositionY, :PositionZ, :GroupPositionX, :GroupPositionY, :GroupPositionZ, :VelocityX,
  329. :VelocityY, :VelocityZ, :AngularVelocityX, :AngularVelocityY, :AngularVelocityZ, :AccelerationX, :AccelerationY, :AccelerationZ,
  330. :RotationX, :RotationY, :RotationZ, :RotationW, :SitTargetOffsetX, :SitTargetOffsetY, :SitTargetOffsetZ, :SitTargetOrientW,
  331. :SitTargetOrientX, :SitTargetOrientY, :SitTargetOrientZ, :RegionUUID, :CreatorID, :OwnerID, :GroupID, :LastOwnerID, :SceneGroupID,
  332. :PayPrice, :PayButton1, :PayButton2, :PayButton3, :PayButton4, :LoopedSound, :LoopedSoundGain, :TextureAnimation, :OmegaX,
  333. :OmegaY, :OmegaZ, :CameraEyeOffsetX, :CameraEyeOffsetY, :CameraEyeOffsetZ, :CameraAtOffsetX, :CameraAtOffsetY, :CameraAtOffsetZ,
  334. :ForceMouselook, :ScriptAccessPin, :AllowedDrop, :DieAtEdge, :SalePrice, :SaleType, :ColorR, :ColorG, :ColorB, :ColorA,
  335. :ParticleSystem, :ClickAction, :Material, :CollisionSound, :CollisionSoundVolume, :PassTouches, :LinkNumber, :MediaURL, :DynAttrs,
  336. :PhysicsShapeType, :Density, :GravityModifier, :Friction, :Restitution
  337. where not EXISTS (SELECT ""UUID"" FROM prims WHERE ""UUID"" = :UUID);
  338. ";
  339. //Set commandtext.
  340. sqlCommand.CommandText = queryPrims;
  341. //Add parameters
  342. sqlCommand.Parameters.AddRange(CreatePrimParameters(sceneObjectPart, sceneGroupID, regionUUID));
  343. //Execute the query. If it fails then error is trapped in calling function
  344. sqlCommand.ExecuteNonQuery();
  345. }
  346. /// <summary>
  347. /// Stores the scene object prim shapes.
  348. /// </summary>
  349. /// <param name="sceneObjectPart">The sceneobjectpart containing prim shape.</param>
  350. /// <param name="sqlCommand">The SQL command with the transaction.</param>
  351. /// <param name="sceneGroupID">The scenegroup UUID.</param>
  352. /// <param name="regionUUID">The region UUID.</param>
  353. private void StoreSceneObjectPrimShapes(SceneObjectPart sceneObjectPart, NpgsqlCommand sqlCommand, UUID sceneGroupID, UUID regionUUID)
  354. {
  355. //Big query to or insert or update primshapes
  356. string queryPrimShapes = @"
  357. UPDATE primshapes SET
  358. ""Shape"" = :Shape, ""ScaleX"" = :ScaleX, ""ScaleY"" = :ScaleY, ""ScaleZ"" = :ScaleZ, ""PCode"" = :PCode, ""PathBegin"" = :PathBegin,
  359. ""PathEnd"" = :PathEnd, ""PathScaleX"" = :PathScaleX, ""PathScaleY"" = :PathScaleY, ""PathShearX"" = :PathShearX, ""PathShearY"" = :PathShearY,
  360. ""PathSkew"" = :PathSkew, ""PathCurve"" = :PathCurve, ""PathRadiusOffset"" = :PathRadiusOffset, ""PathRevolutions"" = :PathRevolutions,
  361. ""PathTaperX"" = :PathTaperX, ""PathTaperY"" = :PathTaperY, ""PathTwist"" = :PathTwist, ""PathTwistBegin"" = :PathTwistBegin,
  362. ""ProfileBegin"" = :ProfileBegin, ""ProfileEnd"" = :ProfileEnd, ""ProfileCurve"" = :ProfileCurve, ""ProfileHollow"" = :ProfileHollow,
  363. ""Texture"" = :Texture, ""ExtraParams"" = :ExtraParams, ""State"" = :State, ""Media"" = :Media
  364. WHERE ""UUID"" = :UUID ;
  365. INSERT INTO
  366. primshapes (
  367. ""UUID"", ""Shape"", ""ScaleX"", ""ScaleY"", ""ScaleZ"", ""PCode"", ""PathBegin"", ""PathEnd"", ""PathScaleX"", ""PathScaleY"", ""PathShearX"", ""PathShearY"",
  368. ""PathSkew"", ""PathCurve"", ""PathRadiusOffset"", ""PathRevolutions"", ""PathTaperX"", ""PathTaperY"", ""PathTwist"", ""PathTwistBegin"", ""ProfileBegin"",
  369. ""ProfileEnd"", ""ProfileCurve"", ""ProfileHollow"", ""Texture"", ""ExtraParams"", ""State"", ""Media""
  370. )
  371. Select
  372. :UUID, :Shape, :ScaleX, :ScaleY, :ScaleZ, :PCode, :PathBegin, :PathEnd, :PathScaleX, :PathScaleY, :PathShearX, :PathShearY,
  373. :PathSkew, :PathCurve, :PathRadiusOffset, :PathRevolutions, :PathTaperX, :PathTaperY, :PathTwist, :PathTwistBegin, :ProfileBegin,
  374. :ProfileEnd, :ProfileCurve, :ProfileHollow, :Texture, :ExtraParams, :State, :Media
  375. where not EXISTS (SELECT ""UUID"" FROM primshapes WHERE ""UUID"" = :UUID);
  376. ";
  377. //Set commandtext.
  378. sqlCommand.CommandText = queryPrimShapes;
  379. //Add parameters
  380. sqlCommand.Parameters.AddRange(CreatePrimShapeParameters(sceneObjectPart, sceneGroupID, regionUUID));
  381. //Execute the query. If it fails then error is trapped in calling function
  382. sqlCommand.ExecuteNonQuery();
  383. }
  384. /// <summary>
  385. /// Removes a object from the database.
  386. /// Meaning removing it from tables Prims, PrimShapes and PrimItems
  387. /// </summary>
  388. /// <param name="objectID">id of scenegroup</param>
  389. /// <param name="regionUUID">regionUUID (is this used anyway</param>
  390. public void RemoveObject(UUID objectID, UUID regionUUID)
  391. {
  392. //_Log.InfoFormat("[PGSQL]: Removing obj: {0} from region: {1}", objectID, regionUUID);
  393. //Remove from prims and primsitem table
  394. string sqlPrims = @"DELETE FROM PRIMS WHERE ""SceneGroupID"" = :objectID";
  395. string sqlPrimItems = @"DELETE FROM PRIMITEMS WHERE ""primID"" in (SELECT ""UUID"" FROM PRIMS WHERE ""SceneGroupID"" = :objectID)";
  396. string sqlPrimShapes = @"DELETE FROM PRIMSHAPES WHERE ""UUID"" in (SELECT ""UUID"" FROM PRIMS WHERE ""SceneGroupID"" = :objectID)";
  397. lock (_Database)
  398. {
  399. //Using the non transaction mode.
  400. using (NpgsqlConnection conn = new NpgsqlConnection(m_connectionString))
  401. using (NpgsqlCommand cmd = new NpgsqlCommand())
  402. {
  403. cmd.Connection = conn;
  404. cmd.CommandText = sqlPrimShapes;
  405. conn.Open();
  406. cmd.Parameters.Add(_Database.CreateParameter("objectID", objectID));
  407. cmd.ExecuteNonQuery();
  408. cmd.CommandText = sqlPrimItems;
  409. cmd.ExecuteNonQuery();
  410. cmd.CommandText = sqlPrims;
  411. cmd.ExecuteNonQuery();
  412. }
  413. }
  414. }
  415. /// <summary>
  416. /// Store the inventory of a prim. Warning deletes everything first and then adds all again.
  417. /// </summary>
  418. /// <param name="primID"></param>
  419. /// <param name="items"></param>
  420. public void StorePrimInventory(UUID primID, ICollection<TaskInventoryItem> items)
  421. {
  422. //_Log.InfoFormat("[REGION DB: Persisting Prim Inventory with prim ID {0}", primID);
  423. //Statement from PGSQL section!
  424. // For now, we're just going to crudely remove all the previous inventory items
  425. // no matter whether they have changed or not, and replace them with the current set.
  426. //Delete everything from PrimID
  427. //TODO add index on PrimID in DB, if not already exist
  428. string sql = @"delete from primitems where ""primID"" = :primID";
  429. using (NpgsqlConnection conn = new NpgsqlConnection(m_connectionString))
  430. using (NpgsqlCommand cmd = new NpgsqlCommand(sql, conn))
  431. {
  432. cmd.Parameters.Add(_Database.CreateParameter("primID", primID));
  433. conn.Open();
  434. cmd.ExecuteNonQuery();
  435. }
  436. sql =
  437. @"INSERT INTO primitems (
  438. ""itemID"",""primID"",""assetID"",""parentFolderID"",""invType"",""assetType"",""name"",""description"",""creationDate"",""creatorID"",""ownerID"",""lastOwnerID"",""groupID"",
  439. ""nextPermissions"",""currentPermissions"",""basePermissions"",""everyonePermissions"",""groupPermissions"",""flags"")
  440. VALUES (:itemID,:primID,:assetID,:parentFolderID,:invType,:assetType,:name,:description,:creationDate,:creatorID,:ownerID,
  441. :lastOwnerID,:groupID,:nextPermissions,:currentPermissions,:basePermissions,:everyonePermissions,:groupPermissions,:flags)";
  442. using (NpgsqlConnection conn = new NpgsqlConnection(m_connectionString))
  443. using (NpgsqlCommand cmd = new NpgsqlCommand(sql, conn))
  444. {
  445. conn.Open();
  446. foreach (TaskInventoryItem taskItem in items)
  447. {
  448. cmd.Parameters.AddRange(CreatePrimInventoryParameters(taskItem));
  449. cmd.ExecuteNonQuery();
  450. cmd.Parameters.Clear();
  451. }
  452. }
  453. }
  454. #endregion
  455. /// <summary>
  456. /// Loads the terrain map.
  457. /// </summary>
  458. /// <param name="regionID">regionID.</param>
  459. /// <returns></returns>
  460. public double[,] LoadTerrain(UUID regionID)
  461. {
  462. double[,] ret = null;
  463. TerrainData terrData = LoadTerrain(regionID, (int)Constants.RegionSize, (int)Constants.RegionSize, (int)Constants.RegionHeight);
  464. if (terrData != null)
  465. ret = terrData.GetDoubles();
  466. return ret;
  467. }
  468. // Returns 'null' if region not found
  469. public TerrainData LoadTerrain(UUID regionID, int pSizeX, int pSizeY, int pSizeZ)
  470. {
  471. TerrainData terrData = null;
  472. string sql = @"select ""RegionUUID"", ""Revision"", ""Heightfield"" from terrain
  473. where ""RegionUUID"" = :RegionUUID order by ""Revision"" desc limit 1; ";
  474. using (NpgsqlConnection conn = new NpgsqlConnection(m_connectionString))
  475. {
  476. using (NpgsqlCommand cmd = new NpgsqlCommand(sql, conn))
  477. {
  478. // PGSqlParameter param = new PGSqlParameter();
  479. cmd.Parameters.Add(_Database.CreateParameter("RegionUUID", regionID));
  480. conn.Open();
  481. using (NpgsqlDataReader reader = cmd.ExecuteReader())
  482. {
  483. int rev;
  484. if (reader.Read())
  485. {
  486. rev = Convert.ToInt32(reader["Revision"]);
  487. byte[] blob = (byte[])reader["Heightfield"];
  488. terrData = TerrainData.CreateFromDatabaseBlobFactory(pSizeX, pSizeY, pSizeZ, rev, blob);
  489. }
  490. else
  491. {
  492. _Log.Info("[REGION DB]: No terrain found for region");
  493. return null;
  494. }
  495. _Log.Info("[REGION DB]: Loaded terrain revision r" + rev);
  496. }
  497. }
  498. }
  499. return terrData;
  500. }
  501. // Legacy entry point for when terrain was always a 256x256 heightmap
  502. public void StoreTerrain(double[,] terrain, UUID regionID)
  503. {
  504. StoreTerrain(new HeightmapTerrainData(terrain), regionID);
  505. }
  506. /// <summary>
  507. /// Stores the terrain map to DB.
  508. /// </summary>
  509. /// <param name="terrain">terrain map data.</param>
  510. /// <param name="regionID">regionID.</param>
  511. public void StoreTerrain(TerrainData terrData, UUID regionID)
  512. {
  513. //Delete old terrain map
  514. string sql = @"delete from terrain where ""RegionUUID""=:RegionUUID";
  515. using (NpgsqlConnection conn = new NpgsqlConnection(m_connectionString))
  516. {
  517. using (NpgsqlCommand cmd = new NpgsqlCommand(sql, conn))
  518. {
  519. cmd.Parameters.Add(_Database.CreateParameter("RegionUUID", regionID));
  520. conn.Open();
  521. cmd.ExecuteNonQuery();
  522. _Log.InfoFormat("{0} Deleted terrain revision id = {1}", LogHeader, regionID);
  523. }
  524. }
  525. int terrainDBRevision;
  526. Array terrainDBblob;
  527. terrData.GetDatabaseBlob(out terrainDBRevision, out terrainDBblob);
  528. sql = @"insert into terrain(""RegionUUID"", ""Revision"", ""Heightfield"") values(:RegionUUID, :Revision, :Heightfield)";
  529. using (NpgsqlConnection conn = new NpgsqlConnection(m_connectionString))
  530. {
  531. using (NpgsqlCommand cmd = new NpgsqlCommand(sql, conn))
  532. {
  533. cmd.Parameters.Add(_Database.CreateParameter("RegionUUID", regionID));
  534. cmd.Parameters.Add(_Database.CreateParameter("Revision", terrainDBRevision));
  535. cmd.Parameters.Add(_Database.CreateParameter("Heightfield", terrainDBblob));
  536. conn.Open();
  537. cmd.ExecuteNonQuery();
  538. _Log.InfoFormat("{0} Stored terrain id = {1}, terrainSize = <{2},{3}>",
  539. LogHeader, regionID, terrData.SizeX, terrData.SizeY);
  540. }
  541. }
  542. }
  543. /// <summary>
  544. /// Loads all the land objects of a region.
  545. /// </summary>
  546. /// <param name="regionUUID">The region UUID.</param>
  547. /// <returns></returns>
  548. public List<LandData> LoadLandObjects(UUID regionUUID)
  549. {
  550. List<LandData> LandDataForRegion = new List<LandData>();
  551. string sql = @"select * from land where ""RegionUUID"" = :RegionUUID";
  552. //Retrieve all land data from region
  553. using (NpgsqlConnection conn = new NpgsqlConnection(m_connectionString))
  554. using (NpgsqlCommand cmd = new NpgsqlCommand(sql, conn))
  555. {
  556. cmd.Parameters.Add(_Database.CreateParameter("RegionUUID", regionUUID));
  557. conn.Open();
  558. using (NpgsqlDataReader readerLandData = cmd.ExecuteReader())
  559. {
  560. while (readerLandData.Read())
  561. {
  562. LandDataForRegion.Add(BuildLandData(readerLandData));
  563. }
  564. }
  565. }
  566. //Retrieve all accesslist data for all landdata
  567. foreach (LandData LandData in LandDataForRegion)
  568. {
  569. sql = @"select * from landaccesslist where ""LandUUID"" = :LandUUID";
  570. using (NpgsqlConnection conn = new NpgsqlConnection(m_connectionString))
  571. using (NpgsqlCommand cmd = new NpgsqlCommand(sql, conn))
  572. {
  573. cmd.Parameters.Add(_Database.CreateParameter("LandUUID", LandData.GlobalID));
  574. conn.Open();
  575. using (NpgsqlDataReader readerAccessList = cmd.ExecuteReader())
  576. {
  577. while (readerAccessList.Read())
  578. {
  579. LandData.ParcelAccessList.Add(BuildLandAccessData(readerAccessList));
  580. }
  581. }
  582. }
  583. }
  584. //Return data
  585. return LandDataForRegion;
  586. }
  587. /// <summary>
  588. /// Stores land object with landaccess list.
  589. /// </summary>
  590. /// <param name="parcel">parcel data.</param>
  591. public void StoreLandObject(ILandObject parcel)
  592. {
  593. //As this is only one record in land table I just delete all and then add a new record.
  594. //As the delete landaccess is already in the pgsql code
  595. //Delete old values
  596. RemoveLandObject(parcel.LandData.GlobalID);
  597. //Insert new values
  598. string sql = @"INSERT INTO land
  599. (""UUID"",""RegionUUID"",""LocalLandID"",""Bitmap"",""Name"",""Description"",""OwnerUUID"",""IsGroupOwned"",""Area"",""AuctionID"",""Category"",""ClaimDate"",""ClaimPrice"",
  600. ""GroupUUID"",""SalePrice"",""LandStatus"",""LandFlags"",""LandingType"",""MediaAutoScale"",""MediaTextureUUID"",""MediaURL"",""MusicURL"",""PassHours"",""PassPrice"",
  601. ""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,
  604. :GroupUUID,:SalePrice,:LandStatus,:LandFlags,:LandingType,:MediaAutoScale,:MediaTextureUUID,:MediaURL,:MusicURL,:PassHours,:PassPrice,
  605. :SnapshotUUID,:UserLocationX,:UserLocationY,:UserLocationZ,:UserLookAtX,:UserLookAtY,:UserLookAtZ,:AuthbuyerID,:OtherCleanTime)";
  606. using (NpgsqlConnection conn = new NpgsqlConnection(m_connectionString))
  607. using (NpgsqlCommand cmd = new NpgsqlCommand(sql, conn))
  608. {
  609. cmd.Parameters.AddRange(CreateLandParameters(parcel.LandData, parcel.RegionUUID));
  610. conn.Open();
  611. cmd.ExecuteNonQuery();
  612. }
  613. sql = @"INSERT INTO landaccesslist (""LandUUID"",""AccessUUID"",""LandFlags"",""Expires"") VALUES (:LandUUID,:AccessUUID,:Flags,:Expires)";
  614. using (NpgsqlConnection conn = new NpgsqlConnection(m_connectionString))
  615. using (NpgsqlCommand cmd = new NpgsqlCommand(sql, conn))
  616. {
  617. conn.Open();
  618. foreach (LandAccessEntry parcelAccessEntry in parcel.LandData.ParcelAccessList)
  619. {
  620. cmd.Parameters.AddRange(CreateLandAccessParameters(parcelAccessEntry, parcel.RegionUUID));
  621. cmd.ExecuteNonQuery();
  622. cmd.Parameters.Clear();
  623. }
  624. }
  625. }
  626. /// <summary>
  627. /// Removes a land object from DB.
  628. /// </summary>
  629. /// <param name="globalID">UUID of landobject</param>
  630. public void RemoveLandObject(UUID globalID)
  631. {
  632. string sql = @"delete from land where ""UUID""=:UUID";
  633. using (NpgsqlConnection conn = new NpgsqlConnection(m_connectionString))
  634. using (NpgsqlCommand cmd = new NpgsqlCommand(sql, conn))
  635. {
  636. cmd.Parameters.Add(_Database.CreateParameter("UUID", globalID));
  637. conn.Open();
  638. cmd.ExecuteNonQuery();
  639. }
  640. sql = @"delete from landaccesslist where ""LandUUID""=:UUID";
  641. using (NpgsqlConnection conn = new NpgsqlConnection(m_connectionString))
  642. using (NpgsqlCommand cmd = new NpgsqlCommand(sql, conn))
  643. {
  644. cmd.Parameters.Add(_Database.CreateParameter("UUID", globalID));
  645. conn.Open();
  646. cmd.ExecuteNonQuery();
  647. }
  648. }
  649. public RegionLightShareData LoadRegionWindlightSettings(UUID regionUUID)
  650. {
  651. RegionLightShareData nWP = new RegionLightShareData();
  652. nWP.OnSave += StoreRegionWindlightSettings;
  653. string sql = @"select * from regionwindlight where ""region_id"" = :regionID";
  654. using (NpgsqlConnection conn = new NpgsqlConnection(m_connectionString))
  655. using (NpgsqlCommand cmd = new NpgsqlCommand(sql, conn))
  656. {
  657. cmd.Parameters.Add(_Database.CreateParameter("regionID", regionUUID.ToString() ));
  658. conn.Open();
  659. using (NpgsqlDataReader result = cmd.ExecuteReader())
  660. {
  661. if (!result.Read())
  662. {
  663. //No result, so store our default windlight profile and return it
  664. nWP.regionID = regionUUID;
  665. StoreRegionWindlightSettings(nWP);
  666. return nWP;
  667. }
  668. else
  669. {
  670. nWP.regionID = DBGuid.FromDB(result["region_id"]);
  671. nWP.waterColor.X = Convert.ToSingle(result["water_color_r"]);
  672. nWP.waterColor.Y = Convert.ToSingle(result["water_color_g"]);
  673. nWP.waterColor.Z = Convert.ToSingle(result["water_color_b"]);
  674. nWP.waterFogDensityExponent = Convert.ToSingle(result["water_fog_density_exponent"]);
  675. nWP.underwaterFogModifier = Convert.ToSingle(result["underwater_fog_modifier"]);
  676. nWP.reflectionWaveletScale.X = Convert.ToSingle(result["reflection_wavelet_scale_1"]);
  677. nWP.reflectionWaveletScale.Y = Convert.ToSingle(result["reflection_wavelet_scale_2"]);
  678. nWP.reflectionWaveletScale.Z = Convert.ToSingle(result["reflection_wavelet_scale_3"]);
  679. nWP.fresnelScale = Convert.ToSingle(result["fresnel_scale"]);
  680. nWP.fresnelOffset = Convert.ToSingle(result["fresnel_offset"]);
  681. nWP.refractScaleAbove = Convert.ToSingle(result["refract_scale_above"]);
  682. nWP.refractScaleBelow = Convert.ToSingle(result["refract_scale_below"]);
  683. nWP.blurMultiplier = Convert.ToSingle(result["blur_multiplier"]);
  684. nWP.bigWaveDirection.X = Convert.ToSingle(result["big_wave_direction_x"]);
  685. nWP.bigWaveDirection.Y = Convert.ToSingle(result["big_wave_direction_y"]);
  686. nWP.littleWaveDirection.X = Convert.ToSingle(result["little_wave_direction_x"]);
  687. nWP.littleWaveDirection.Y = Convert.ToSingle(result["little_wave_direction_y"]);
  688. UUID.TryParse(result["normal_map_texture"].ToString(), out nWP.normalMapTexture);
  689. nWP.horizon.X = Convert.ToSingle(result["horizon_r"]);
  690. nWP.horizon.Y = Convert.ToSingle(result["horizon_g"]);
  691. nWP.horizon.Z = Convert.ToSingle(result["horizon_b"]);
  692. nWP.horizon.W = Convert.ToSingle(result["horizon_i"]);
  693. nWP.hazeHorizon = Convert.ToSingle(result["haze_horizon"]);
  694. nWP.blueDensity.X = Convert.ToSingle(result["blue_density_r"]);
  695. nWP.blueDensity.Y = Convert.ToSingle(result["blue_density_g"]);
  696. nWP.blueDensity.Z = Convert.ToSingle(result["blue_density_b"]);
  697. nWP.blueDensity.W = Convert.ToSingle(result["blue_density_i"]);
  698. nWP.hazeDensity = Convert.ToSingle(result["haze_density"]);
  699. nWP.densityMultiplier = Convert.ToSingle(result["density_multiplier"]);
  700. nWP.distanceMultiplier = Convert.ToSingle(result["distance_multiplier"]);
  701. nWP.maxAltitude = Convert.ToUInt16(result["max_altitude"]);
  702. nWP.sunMoonColor.X = Convert.ToSingle(result["sun_moon_color_r"]);
  703. nWP.sunMoonColor.Y = Convert.ToSingle(result["sun_moon_color_g"]);
  704. nWP.sunMoonColor.Z = Convert.ToSingle(result["sun_moon_color_b"]);
  705. nWP.sunMoonColor.W = Convert.ToSingle(result["sun_moon_color_i"]);
  706. nWP.sunMoonPosition = Convert.ToSingle(result["sun_moon_position"]);
  707. nWP.ambient.X = Convert.ToSingle(result["ambient_r"]);
  708. nWP.ambient.Y = Convert.ToSingle(result["ambient_g"]);
  709. nWP.ambient.Z = Convert.ToSingle(result["ambient_b"]);
  710. nWP.ambient.W = Convert.ToSingle(result["ambient_i"]);
  711. nWP.eastAngle = Convert.ToSingle(result["east_angle"]);
  712. nWP.sunGlowFocus = Convert.ToSingle(result["sun_glow_focus"]);
  713. nWP.sunGlowSize = Convert.ToSingle(result["sun_glow_size"]);
  714. nWP.sceneGamma = Convert.ToSingle(result["scene_gamma"]);
  715. nWP.starBrightness = Convert.ToSingle(result["star_brightness"]);
  716. nWP.cloudColor.X = Convert.ToSingle(result["cloud_color_r"]);
  717. nWP.cloudColor.Y = Convert.ToSingle(result["cloud_color_g"]);
  718. nWP.cloudColor.Z = Convert.ToSingle(result["cloud_color_b"]);
  719. nWP.cloudColor.W = Convert.ToSingle(result["cloud_color_i"]);
  720. nWP.cloudXYDensity.X = Convert.ToSingle(result["cloud_x"]);
  721. nWP.cloudXYDensity.Y = Convert.ToSingle(result["cloud_y"]);
  722. nWP.cloudXYDensity.Z = Convert.ToSingle(result["cloud_density"]);
  723. nWP.cloudCoverage = Convert.ToSingle(result["cloud_coverage"]);
  724. nWP.cloudScale = Convert.ToSingle(result["cloud_scale"]);
  725. nWP.cloudDetailXYDensity.X = Convert.ToSingle(result["cloud_detail_x"]);
  726. nWP.cloudDetailXYDensity.Y = Convert.ToSingle(result["cloud_detail_y"]);
  727. nWP.cloudDetailXYDensity.Z = Convert.ToSingle(result["cloud_detail_density"]);
  728. nWP.cloudScrollX = Convert.ToSingle(result["cloud_scroll_x"]);
  729. nWP.cloudScrollXLock = Convert.ToBoolean(result["cloud_scroll_x_lock"]);
  730. nWP.cloudScrollY = Convert.ToSingle(result["cloud_scroll_y"]);
  731. nWP.cloudScrollYLock = Convert.ToBoolean(result["cloud_scroll_y_lock"]);
  732. nWP.drawClassicClouds = Convert.ToBoolean(result["draw_classic_clouds"]);
  733. nWP.valid = true;
  734. }
  735. }
  736. }
  737. return nWP;
  738. }
  739. public void RemoveRegionWindlightSettings(UUID regionID)
  740. {
  741. string sql = @"delete from regionwindlight where ""region_id"" = :region_id";
  742. using (NpgsqlConnection conn = new NpgsqlConnection(m_connectionString))
  743. using (NpgsqlCommand cmd = new NpgsqlCommand(sql, conn))
  744. {
  745. conn.Open();
  746. cmd.Parameters.Add(_Database.CreateParameter("region_id", regionID.ToString()));
  747. cmd.ExecuteNonQuery();
  748. }
  749. }
  750. public void StoreRegionWindlightSettings(RegionLightShareData wl)
  751. {
  752. string sql = @"select region_id from regionwindlight where ""region_id"" = :region_id limit 1;";
  753. bool exists = false;
  754. using (NpgsqlConnection conn = new NpgsqlConnection(m_connectionString))
  755. {
  756. conn.Open();
  757. using (NpgsqlCommand cmd = new NpgsqlCommand(sql, conn))
  758. {
  759. cmd.Parameters.Add(_Database.CreateParameter("region_id", wl.regionID.ToString() ));
  760. NpgsqlDataReader dr = cmd.ExecuteReader();
  761. exists = dr.Read();
  762. }
  763. }
  764. if (exists)
  765. {
  766. RemoveRegionWindlightSettings(wl.regionID);
  767. }
  768. // sql insert
  769. sql = @"INSERT INTO regionwindlight
  770. (region_id
  771. ,water_color_r
  772. ,water_color_g
  773. ,water_color_b
  774. ,water_fog_density_exponent
  775. ,underwater_fog_modifier
  776. ,reflection_wavelet_scale_1
  777. ,reflection_wavelet_scale_2
  778. ,reflection_wavelet_scale_3
  779. ,fresnel_scale
  780. ,fresnel_offset
  781. ,refract_scale_above
  782. ,refract_scale_below
  783. ,blur_multiplier
  784. ,big_wave_direction_x
  785. ,big_wave_direction_y
  786. ,little_wave_direction_x
  787. ,little_wave_direction_y
  788. ,normal_map_texture
  789. ,horizon_r
  790. ,horizon_g
  791. ,horizon_b
  792. ,horizon_i
  793. ,haze_horizon
  794. ,blue_density_r
  795. ,blue_density_g
  796. ,blue_density_b
  797. ,blue_density_i
  798. ,haze_density
  799. ,density_multiplier
  800. ,distance_multiplier
  801. ,max_altitude
  802. ,sun_moon_color_r
  803. ,sun_moon_color_g
  804. ,sun_moon_color_b
  805. ,sun_moon_color_i
  806. ,sun_moon_position
  807. ,ambient_r
  808. ,ambient_g
  809. ,ambient_b
  810. ,ambient_i
  811. ,east_angle
  812. ,sun_glow_focus
  813. ,sun_glow_size
  814. ,scene_gamma
  815. ,star_brightness
  816. ,cloud_color_r
  817. ,cloud_color_g
  818. ,cloud_color_b
  819. ,cloud_color_i
  820. ,cloud_x
  821. ,cloud_y
  822. ,cloud_density
  823. ,cloud_coverage
  824. ,cloud_scale
  825. ,cloud_detail_x
  826. ,cloud_detail_y
  827. ,cloud_detail_density
  828. ,cloud_scroll_x
  829. ,cloud_scroll_x_lock
  830. ,cloud_scroll_y
  831. ,cloud_scroll_y_lock
  832. ,draw_classic_clouds)
  833. VALUES
  834. (:region_id
  835. ,:water_color_r
  836. ,:water_color_g
  837. ,:water_color_b
  838. ,:water_fog_density_exponent
  839. ,:underwater_fog_modifier
  840. ,:reflection_wavelet_scale_1
  841. ,:reflection_wavelet_scale_2
  842. ,:reflection_wavelet_scale_3
  843. ,:fresnel_scale
  844. ,:fresnel_offset
  845. ,:refract_scale_above
  846. ,:refract_scale_below
  847. ,:blur_multiplier
  848. ,:big_wave_direction_x
  849. ,:big_wave_direction_y
  850. ,:little_wave_direction_x
  851. ,:little_wave_direction_y
  852. ,:normal_map_texture
  853. ,:horizon_r
  854. ,:horizon_g
  855. ,:horizon_b
  856. ,:horizon_i
  857. ,:haze_horizon
  858. ,:blue_density_r
  859. ,:blue_density_g
  860. ,:blue_density_b
  861. ,:blue_density_i
  862. ,:haze_density
  863. ,:density_multiplier
  864. ,:distance_multiplier
  865. ,:max_altitude
  866. ,:sun_moon_color_r
  867. ,:sun_moon_color_g
  868. ,:sun_moon_color_b
  869. ,:sun_moon_color_i
  870. ,:sun_moon_position
  871. ,:ambient_r
  872. ,:ambient_g
  873. ,:ambient_b
  874. ,:ambient_i
  875. ,:east_angle
  876. ,:sun_glow_focus
  877. ,:sun_glow_size
  878. ,:scene_gamma
  879. ,:star_brightness
  880. ,:cloud_color_r
  881. ,:cloud_color_g
  882. ,:cloud_color_b
  883. ,:cloud_color_i
  884. ,:cloud_x
  885. ,:cloud_y
  886. ,:cloud_density
  887. ,:cloud_coverage
  888. ,:cloud_scale
  889. ,:cloud_detail_x
  890. ,:cloud_detail_y
  891. ,:cloud_detail_density
  892. ,:cloud_scroll_x
  893. ,:cloud_scroll_x_lock
  894. ,:cloud_scroll_y
  895. ,:cloud_scroll_y_lock
  896. ,:draw_classic_clouds);";
  897. using (NpgsqlConnection conn = new NpgsqlConnection(m_connectionString))
  898. {
  899. conn.Open();
  900. using (NpgsqlCommand cmd = new NpgsqlCommand(sql, conn))
  901. {
  902. cmd.Parameters.Add(_Database.CreateParameter("region_id", wl.regionID.ToString()));
  903. cmd.Parameters.Add(_Database.CreateParameter("water_color_r", wl.waterColor.X));
  904. cmd.Parameters.Add(_Database.CreateParameter("water_color_g", wl.waterColor.Y));
  905. cmd.Parameters.Add(_Database.CreateParameter("water_color_b", wl.waterColor.Z));
  906. cmd.Parameters.Add(_Database.CreateParameter("water_fog_density_exponent", wl.waterFogDensityExponent));
  907. cmd.Parameters.Add(_Database.CreateParameter("underwater_fog_modifier", wl.underwaterFogModifier));
  908. cmd.Parameters.Add(_Database.CreateParameter("reflection_wavelet_scale_1", wl.reflectionWaveletScale.X));
  909. cmd.Parameters.Add(_Database.CreateParameter("reflection_wavelet_scale_2", wl.reflectionWaveletScale.Y));
  910. cmd.Parameters.Add(_Database.CreateParameter("reflection_wavelet_scale_3", wl.reflectionWaveletScale.Z));
  911. cmd.Parameters.Add(_Database.CreateParameter("fresnel_scale", wl.fresnelScale));
  912. cmd.Parameters.Add(_Database.CreateParameter("fresnel_offset", wl.fresnelOffset));
  913. cmd.Parameters.Add(_Database.CreateParameter("refract_scale_above", wl.refractScaleAbove));
  914. cmd.Parameters.Add(_Database.CreateParameter("refract_scale_below", wl.refractScaleBelow));
  915. cmd.Parameters.Add(_Database.CreateParameter("blur_multiplier", wl.blurMultiplier));
  916. cmd.Parameters.Add(_Database.CreateParameter("big_wave_direction_x", wl.bigWaveDirection.X));
  917. cmd.Parameters.Add(_Database.CreateParameter("big_wave_direction_y", wl.bigWaveDirection.Y));
  918. cmd.Parameters.Add(_Database.CreateParameter("little_wave_direction_x", wl.littleWaveDirection.X));
  919. cmd.Parameters.Add(_Database.CreateParameter("little_wave_direction_y", wl.littleWaveDirection.Y));
  920. cmd.Parameters.Add(_Database.CreateParameter("normal_map_texture", wl.normalMapTexture.ToString()));
  921. cmd.Parameters.Add(_Database.CreateParameter("horizon_r", wl.horizon.X));
  922. cmd.Parameters.Add(_Database.CreateParameter("horizon_g", wl.horizon.Y));
  923. cmd.Parameters.Add(_Database.CreateParameter("horizon_b", wl.horizon.Z));
  924. cmd.Parameters.Add(_Database.CreateParameter("horizon_i", wl.horizon.W));
  925. cmd.Parameters.Add(_Database.CreateParameter("haze_horizon", wl.hazeHorizon));
  926. cmd.Parameters.Add(_Database.CreateParameter("blue_density_r", wl.blueDensity.X));
  927. cmd.Parameters.Add(_Database.CreateParameter("blue_density_g", wl.blueDensity.Y));
  928. cmd.Parameters.Add(_Database.CreateParameter("blue_density_b", wl.blueDensity.Z));
  929. cmd.Parameters.Add(_Database.CreateParameter("blue_density_i", wl.blueDensity.W));
  930. cmd.Parameters.Add(_Database.CreateParameter("haze_density", wl.hazeDensity));
  931. cmd.Parameters.Add(_Database.CreateParameter("density_multiplier", wl.densityMultiplier));
  932. cmd.Parameters.Add(_Database.CreateParameter("distance_multiplier", wl.distanceMultiplier));
  933. cmd.Parameters.Add(_Database.CreateParameter("max_altitude", wl.maxAltitude));
  934. cmd.Parameters.Add(_Database.CreateParameter("sun_moon_color_r", wl.sunMoonColor.X));
  935. cmd.Parameters.Add(_Database.CreateParameter("sun_moon_color_g", wl.sunMoonColor.Y));
  936. cmd.Parameters.Add(_Database.CreateParameter("sun_moon_color_b", wl.sunMoonColor.Z));
  937. cmd.Parameters.Add(_Database.CreateParameter("sun_moon_color_i", wl.sunMoonColor.W));
  938. cmd.Parameters.Add(_Database.CreateParameter("sun_moon_position", wl.sunMoonPosition));
  939. cmd.Parameters.Add(_Database.CreateParameter("ambient_r", wl.ambient.X));
  940. cmd.Parameters.Add(_Database.CreateParameter("ambient_g", wl.ambient.Y));
  941. cmd.Parameters.Add(_Database.CreateParameter("ambient_b", wl.ambient.Z));
  942. cmd.Parameters.Add(_Database.CreateParameter("ambient_i", wl.ambient.W));
  943. cmd.Parameters.Add(_Database.CreateParameter("east_angle", wl.eastAngle));
  944. cmd.Parameters.Add(_Database.CreateParameter("sun_glow_focus", wl.sunGlowFocus));
  945. cmd.Parameters.Add(_Database.CreateParameter("sun_glow_size", wl.sunGlowSize));
  946. cmd.Parameters.Add(_Database.CreateParameter("scene_gamma", wl.sceneGamma));
  947. cmd.Parameters.Add(_Database.CreateParameter("star_brightness", wl.starBrightness));
  948. cmd.Parameters.Add(_Database.CreateParameter("cloud_color_r", wl.cloudColor.X));
  949. cmd.Parameters.Add(_Database.CreateParameter("cloud_color_g", wl.cloudColor.Y));
  950. cmd.Parameters.Add(_Database.CreateParameter("cloud_color_b", wl.cloudColor.Z));
  951. cmd.Parameters.Add(_Database.CreateParameter("cloud_color_i", wl.cloudColor.W));
  952. cmd.Parameters.Add(_Database.CreateParameter("cloud_x", wl.cloudXYDensity.X));
  953. cmd.Parameters.Add(_Database.CreateParameter("cloud_y", wl.cloudXYDensity.Y));
  954. cmd.Parameters.Add(_Database.CreateParameter("cloud_density", wl.cloudXYDensity.Z));
  955. cmd.Parameters.Add(_Database.CreateParameter("cloud_coverage", wl.cloudCoverage));
  956. cmd.Parameters.Add(_Database.CreateParameter("cloud_scale", wl.cloudScale));
  957. cmd.Parameters.Add(_Database.CreateParameter("cloud_detail_x", wl.cloudDetailXYDensity.X));
  958. cmd.Parameters.Add(_Database.CreateParameter("cloud_detail_y", wl.cloudDetailXYDensity.Y));
  959. cmd.Parameters.Add(_Database.CreateParameter("cloud_detail_density", wl.cloudDetailXYDensity.Z));
  960. cmd.Parameters.Add(_Database.CreateParameter("cloud_scroll_x", wl.cloudScrollX));
  961. cmd.Parameters.Add(_Database.CreateParameter("cloud_scroll_x_lock", wl.cloudScrollXLock));
  962. cmd.Parameters.Add(_Database.CreateParameter("cloud_scroll_y", wl.cloudScrollY));
  963. cmd.Parameters.Add(_Database.CreateParameter("cloud_scroll_y_lock", wl.cloudScrollYLock));
  964. cmd.Parameters.Add(_Database.CreateParameter("draw_classic_clouds", wl.drawClassicClouds));
  965. cmd.ExecuteNonQuery();
  966. }
  967. }
  968. #region update
  969. // }
  970. // else
  971. // {
  972. // // sql update
  973. // sql = @"UPDATE [OpenSim].[dbo].[regionwindlight]
  974. // SET [region_id] = @region_id
  975. // ,[water_color_r] = @water_color_r
  976. // ,[water_color_g] = @water_color_g
  977. // ,[water_color_b] = @water_color_b
  978. // ,[water_fog_density_exponent] = @water_fog_density_exponent
  979. // ,[underwater_fog_modifier] = @underwater_fog_modifier
  980. // ,[reflection_wavelet_scale_1] = @reflection_wavelet_scale_1
  981. // ,[reflection_wavelet_scale_2] = @reflection_wavelet_scale_2
  982. // ,[reflection_wavelet_scale_3] = @reflection_wavelet_scale_3
  983. // ,[fresnel_scale] = @fresnel_scale
  984. // ,[fresnel_offset] = @fresnel_offset
  985. // ,[refract_scale_above] = @refract_scale_above
  986. // ,[refract_scale_below] = @refract_scale_below
  987. // ,[blur_multiplier] = @blur_multiplier
  988. // ,[big_wave_direction_x] = @big_wave_direction_x
  989. // ,[big_wave_direction_y] = @big_wave_direction_y
  990. // ,[little_wave_direction_x] = @little_wave_direction_x
  991. // ,[little_wave_direction_y] = @little_wave_direction_y
  992. // ,[normal_map_texture] = @normal_map_texture
  993. // ,[horizon_r] = @horizon_r
  994. // ,[horizon_g] = @horizon_g
  995. // ,[horizon_b] = @horizon_b
  996. // ,[horizon_i] = @horizon_i
  997. // ,[haze_horizon] = @haze_horizon
  998. // ,[blue_density_r] = @blue_density_r
  999. // ,[blue_density_g] = @blue_density_g
  1000. // ,[blue_density_b] = @blue_density_b
  1001. // ,[blue_density_i] = @blue_density_i
  1002. // ,[haze_density] = @haze_density
  1003. // ,[density_multiplier] = @density_multiplier
  1004. // ,[distance_multiplier] = @distance_multiplier
  1005. // ,[max_altitude] = @max_altitude
  1006. // ,[sun_moon_color_r] = @sun_moon_color_r
  1007. // ,[sun_moon_color_g] = @sun_moon_color_g
  1008. // ,[sun_moon_color_b] = @sun_moon_color_b
  1009. // ,[sun_moon_color_i] = @sun_moon_color_i
  1010. // ,[sun_moon_position] = @sun_moon_position
  1011. // ,[ambient_r] = @ambient_r
  1012. // ,[ambient_g] = @ambient_g
  1013. // ,[ambient_b] = @ambient_b
  1014. // ,[ambient_i] = @ambient_i
  1015. // ,[east_angle] = @east_angle
  1016. // ,[sun_glow_focus] = @sun_glow_focus
  1017. // ,[sun_glow_size] = @sun_glow_size
  1018. // ,[scene_gamma] = @scene_gamma
  1019. // ,[star_brightness] = @star_brightness
  1020. // ,[cloud_color_r] = @cloud_color_r
  1021. // ,[cloud_color_g] = @cloud_color_g
  1022. // ,[cloud_color_b] = @cloud_color_b
  1023. // ,[cloud_color_i] = @cloud_color_i
  1024. // ,[cloud_x] = @cloud_x
  1025. // ,[cloud_y] = @cloud_y
  1026. // ,[cloud_density] = @cloud_density
  1027. // ,[cloud_coverage] = @cloud_coverage
  1028. // ,[cloud_scale] = @cloud_scale
  1029. // ,[cloud_detail_x] = @cloud_detail_x
  1030. // ,[cloud_detail_y] = @cloud_detail_y
  1031. // ,[cloud_detail_density] = @cloud_detail_density
  1032. // ,[cloud_scroll_x] = @cloud_scroll_x
  1033. // ,[cloud_scroll_x_lock] = @cloud_scroll_x_lock
  1034. // ,[cloud_scroll_y] = @cloud_scroll_y
  1035. // ,[cloud_scroll_y_lock] = @cloud_scroll_y_lock
  1036. // ,[draw_classic_clouds] = @draw_classic_clouds
  1037. // WHERE region_id = @region_id";
  1038. // using (SqlConnection conn = new SqlConnection(m_connectionString))
  1039. // {
  1040. // conn.Open();
  1041. // using (SqlCommand cmd = new SqlCommand(sql, conn))
  1042. // {
  1043. // cmd.Parameters.AddWithValue("region_id", wl.regionID);
  1044. // cmd.Parameters.AddWithValue("water_color_r", wl.waterColor.X);
  1045. // cmd.Parameters.AddWithValue("water_color_g", wl.waterColor.Y);
  1046. // cmd.Parameters.AddWithValue("water_color_b", wl.waterColor.Z);
  1047. // cmd.Parameters.AddWithValue("water_fog_density_exponent", wl.waterFogDensityExponent);
  1048. // cmd.Parameters.AddWithValue("underwater_fog_modifier", wl.underwaterFogModifier);
  1049. // cmd.Parameters.AddWithValue("reflection_wavelet_scale_1", wl.reflectionWaveletScale.X);
  1050. // cmd.Parameters.AddWithValue("reflection_wavelet_scale_2", wl.reflectionWaveletScale.Y);
  1051. // cmd.Parameters.AddWithValue("reflection_wavelet_scale_3", wl.reflectionWaveletScale.Z);
  1052. // cmd.Parameters.AddWithValue("fresnel_scale", wl.fresnelScale);
  1053. // cmd.Parameters.AddWithValue("fresnel_offset", wl.fresnelOffset);
  1054. // cmd.Parameters.AddWithValue("refract_scale_above", wl.refractScaleAbove);
  1055. // cmd.Parameters.AddWithValue("refract_scale_below", wl.refractScaleBelow);
  1056. // cmd.Parameters.AddWithValue("blur_multiplier", wl.blurMultiplier);
  1057. // cmd.Parameters.AddWithValue("big_wave_direction_x", wl.bigWaveDirection.X);
  1058. // cmd.Parameters.AddWithValue("big_wave_direction_y", wl.bigWaveDirection.Y);
  1059. // cmd.Parameters.AddWithValue("little_wave_direction_x", wl.littleWaveDirection.X);
  1060. // cmd.Parameters.AddWithValue("little_wave_direction_y", wl.littleWaveDirection.Y);
  1061. // cmd.Parameters.AddWithValue("normal_map_texture", wl.normalMapTexture);
  1062. // cmd.Parameters.AddWithValue("horizon_r", wl.horizon.X);
  1063. // cmd.Parameters.AddWithValue("horizon_g", wl.horizon.Y);
  1064. // cmd.Parameters.AddWithValue("horizon_b", wl.horizon.Z);
  1065. // cmd.Parameters.AddWithValue("horizon_i", wl.horizon.W);
  1066. // cmd.Parameters.AddWithValue("haze_horizon", wl.hazeHorizon);
  1067. // cmd.Parameters.AddWithValue("blue_density_r", wl.blueDensity.X);
  1068. // cmd.Parameters.AddWithValue("blue_density_g", wl.blueDensity.Y);
  1069. // cmd.Parameters.AddWithValue("blue_density_b", wl.blueDensity.Z);
  1070. // cmd.Parameters.AddWithValue("blue_density_i", wl.blueDensity.W);
  1071. // cmd.Parameters.AddWithValue("haze_density", wl.hazeDensity);
  1072. // cmd.Parameters.AddWithValue("density_multiplier", wl.densityMultiplier);
  1073. // cmd.Parameters.AddWithValue("distance_multiplier", wl.distanceMultiplier);
  1074. // cmd.Parameters.AddWithValue("max_altitude", wl.maxAltitude);
  1075. // cmd.Parameters.AddWithValue("sun_moon_color_r", wl.sunMoonColor.X);
  1076. // cmd.Parameters.AddWithValue("sun_moon_color_g", wl.sunMoonColor.Y);
  1077. // cmd.Parameters.AddWithValue("sun_moon_color_b", wl.sunMoonColor.Z);
  1078. // cmd.Parameters.AddWithValue("sun_moon_color_i", wl.sunMoonColor.W);
  1079. // cmd.Parameters.AddWithValue("sun_moon_position", wl.sunMoonPosition);
  1080. // cmd.Parameters.AddWithValue("ambient_r", wl.ambient.X);
  1081. // cmd.Parameters.AddWithValue("ambient_g", wl.ambient.Y);
  1082. // cmd.Parameters.AddWithValue("ambient_b", wl.ambient.Z);
  1083. // cmd.Parameters.AddWithValue("ambient_i", wl.ambient.W);
  1084. // cmd.Parameters.AddWithValue("east_angle", wl.eastAngle);
  1085. // cmd.Parameters.AddWithValue("sun_glow_focus", wl.sunGlowFocus);
  1086. // cmd.Parameters.AddWithValue("sun_glow_size", wl.sunGlowSize);
  1087. // cmd.Parameters.AddWithValue("scene_gamma", wl.sceneGamma);
  1088. // cmd.Parameters.AddWithValue("star_brightness", wl.starBrightness);
  1089. // cmd.Parameters.AddWithValue("cloud_color_r", wl.cloudColor.X);
  1090. // cmd.Parameters.AddWithValue("cloud_color_g", wl.cloudColor.Y);
  1091. // cmd.Parameters.AddWithValue("cloud_color_b", wl.cloudColor.Z);
  1092. // cmd.Parameters.AddWithValue("cloud_color_i", wl.cloudColor.W);
  1093. // cmd.Parameters.AddWithValue("cloud_x", wl.cloudXYDensity.X);
  1094. // cmd.Parameters.AddWithValue("cloud_y", wl.cloudXYDensity.Y);
  1095. // cmd.Parameters.AddWithValue("cloud_density", wl.cloudXYDensity.Z);
  1096. // cmd.Parameters.AddWithValue("cloud_coverage", wl.cloudCoverage);
  1097. // cmd.Parameters.AddWithValue("cloud_scale", wl.cloudScale);
  1098. // cmd.Parameters.AddWithValue("cloud_detail_x", wl.cloudDetailXYDensity.X);
  1099. // cmd.Parameters.AddWithValue("cloud_detail_y", wl.cloudDetailXYDensity.Y);
  1100. // cmd.Parameters.AddWithValue("cloud_detail_density", wl.cloudDetailXYDensity.Z);
  1101. // cmd.Parameters.AddWithValue("cloud_scroll_x", wl.cloudScrollX);
  1102. // cmd.Parameters.AddWithValue("cloud_scroll_x_lock", wl.cloudScrollXLock);
  1103. // cmd.Parameters.AddWithValue("cloud_scroll_y", wl.cloudScrollY);
  1104. // cmd.Parameters.AddWithValue("cloud_scroll_y_lock", wl.cloudScrollYLock);
  1105. // cmd.Parameters.AddWithValue("draw_classic_clouds", wl.drawClassicClouds);
  1106. // cmd.ExecuteNonQuery();
  1107. // }
  1108. // }
  1109. // }
  1110. #endregion
  1111. }
  1112. #region Environment Settings
  1113. public string LoadRegionEnvironmentSettings(UUID regionUUID)
  1114. {
  1115. string sql = "select * from regionenvironment where region_id = :region_id";
  1116. using (NpgsqlConnection conn = new NpgsqlConnection(m_connectionString))
  1117. using (NpgsqlCommand cmd = new NpgsqlCommand(sql, conn))
  1118. {
  1119. cmd.Parameters.Add(_Database.CreateParameter("region_id", regionUUID));
  1120. conn.Open();
  1121. using (NpgsqlDataReader result = cmd.ExecuteReader())
  1122. {
  1123. if (!result.Read())
  1124. {
  1125. return String.Empty;
  1126. }
  1127. else
  1128. {
  1129. return Convert.ToString(result["llsd_settings"]);
  1130. }
  1131. }
  1132. }
  1133. }
  1134. public void StoreRegionEnvironmentSettings(UUID regionUUID, string settings)
  1135. {
  1136. {
  1137. string sql = "DELETE FROM regionenvironment WHERE region_id = :region_id ;";
  1138. using (NpgsqlConnection conn = new NpgsqlConnection(m_connectionString))
  1139. using (NpgsqlCommand cmd = new NpgsqlCommand(sql, conn))
  1140. {
  1141. cmd.Parameters.Add(_Database.CreateParameter("region_id", regionUUID));
  1142. conn.Open();
  1143. cmd.ExecuteNonQuery();
  1144. }
  1145. sql = "INSERT INTO regionenvironment (region_id, llsd_settings) VALUES (:region_id, :llsd_settings) ;";
  1146. using (NpgsqlConnection conn = new NpgsqlConnection(m_connectionString))
  1147. using (NpgsqlCommand cmd = new NpgsqlCommand(sql, conn))
  1148. {
  1149. cmd.Parameters.Add(_Database.CreateParameter("region_id", regionUUID));
  1150. cmd.Parameters.Add(_Database.CreateParameter("llsd_settings", settings));
  1151. conn.Open();
  1152. cmd.ExecuteNonQuery();
  1153. }
  1154. }
  1155. }
  1156. public void RemoveRegionEnvironmentSettings(UUID regionUUID)
  1157. {
  1158. string sql = "delete from regionenvironment where region_id = :region_id ;";
  1159. using (NpgsqlConnection conn = new NpgsqlConnection(m_connectionString))
  1160. using (NpgsqlCommand cmd = new NpgsqlCommand(sql, conn))
  1161. {
  1162. cmd.Parameters.Add(_Database.CreateParameter("region_id", regionUUID));
  1163. conn.Open();
  1164. cmd.ExecuteNonQuery();
  1165. }
  1166. }
  1167. #endregion
  1168. /// <summary>
  1169. /// Loads the settings of a region.
  1170. /// </summary>
  1171. /// <param name="regionUUID">The region UUID.</param>
  1172. /// <returns></returns>
  1173. public RegionSettings LoadRegionSettings(UUID regionUUID)
  1174. {
  1175. string sql = @"select * from regionsettings where ""regionUUID"" = :regionUUID";
  1176. RegionSettings regionSettings;
  1177. using (NpgsqlConnection conn = new NpgsqlConnection(m_connectionString))
  1178. using (NpgsqlCommand cmd = new NpgsqlCommand(sql, conn))
  1179. {
  1180. cmd.Parameters.Add(_Database.CreateParameter("regionUUID", regionUUID));
  1181. conn.Open();
  1182. using (NpgsqlDataReader reader = cmd.ExecuteReader())
  1183. {
  1184. if (reader.Read())
  1185. {
  1186. regionSettings = BuildRegionSettings(reader);
  1187. regionSettings.OnSave += StoreRegionSettings;
  1188. return regionSettings;
  1189. }
  1190. }
  1191. }
  1192. //If we reach this point then there are new region settings for that region
  1193. regionSettings = new RegionSettings();
  1194. regionSettings.RegionUUID = regionUUID;
  1195. regionSettings.OnSave += StoreRegionSettings;
  1196. //Store new values
  1197. StoreNewRegionSettings(regionSettings);
  1198. LoadSpawnPoints(regionSettings);
  1199. return regionSettings;
  1200. }
  1201. /// <summary>
  1202. /// Store region settings, need to check if the check is really necesary. If we can make something for creating new region.
  1203. /// </summary>
  1204. /// <param name="regionSettings">region settings.</param>
  1205. public void StoreRegionSettings(RegionSettings regionSettings)
  1206. {
  1207. //Little check if regionUUID already exist in DB
  1208. string regionUUID;
  1209. string sql = @"SELECT ""regionUUID"" FROM regionsettings WHERE ""regionUUID"" = :regionUUID";
  1210. using (NpgsqlConnection conn = new NpgsqlConnection(m_connectionString))
  1211. using (NpgsqlCommand cmd = new NpgsqlCommand(sql, conn))
  1212. {
  1213. cmd.Parameters.Add(_Database.CreateParameter("regionUUID", regionSettings.RegionUUID));
  1214. conn.Open();
  1215. regionUUID = cmd.ExecuteScalar().ToString();
  1216. }
  1217. if (string.IsNullOrEmpty(regionUUID))
  1218. {
  1219. StoreNewRegionSettings(regionSettings);
  1220. }
  1221. else
  1222. {
  1223. //This method only updates region settings!!! First call LoadRegionSettings to create new region settings in DB
  1224. sql =
  1225. @"UPDATE regionsettings SET block_terraform = :block_terraform ,block_fly = :block_fly ,allow_damage = :allow_damage
  1226. ,restrict_pushing = :restrict_pushing ,allow_land_resell = :allow_land_resell ,allow_land_join_divide = :allow_land_join_divide
  1227. ,block_show_in_search = :block_show_in_search ,agent_limit = :agent_limit ,object_bonus = :object_bonus ,maturity = :maturity
  1228. ,disable_scripts = :disable_scripts ,disable_collisions = :disable_collisions ,disable_physics = :disable_physics
  1229. ,terrain_texture_1 = :terrain_texture_1 ,terrain_texture_2 = :terrain_texture_2 ,terrain_texture_3 = :terrain_texture_3
  1230. ,terrain_texture_4 = :terrain_texture_4 ,elevation_1_nw = :elevation_1_nw ,elevation_2_nw = :elevation_2_nw
  1231. ,elevation_1_ne = :elevation_1_ne ,elevation_2_ne = :elevation_2_ne ,elevation_1_se = :elevation_1_se ,elevation_2_se = :elevation_2_se
  1232. ,elevation_1_sw = :elevation_1_sw ,elevation_2_sw = :elevation_2_sw ,water_height = :water_height ,terrain_raise_limit = :terrain_raise_limit
  1233. ,terrain_lower_limit = :terrain_lower_limit ,use_estate_sun = :use_estate_sun ,fixed_sun = :fixed_sun ,sun_position = :sun_position
  1234. ,covenant = :covenant ,covenant_datetime = :covenant_datetime, sunvectorx = :sunvectorx, sunvectory = :sunvectory, sunvectorz = :sunvectorz,
  1235. ""Sandbox"" = :Sandbox, loaded_creation_datetime = :loaded_creation_datetime, loaded_creation_id = :loaded_creation_id, ""map_tile_ID"" = :TerrainImageID,
  1236. ""TelehubObject"" = :telehubobject, ""parcel_tile_ID"" = :ParcelImageID
  1237. WHERE ""regionUUID"" = :regionUUID";
  1238. using (NpgsqlConnection conn = new NpgsqlConnection(m_connectionString))
  1239. using (NpgsqlCommand cmd = new NpgsqlCommand(sql, conn))
  1240. {
  1241. cmd.Parameters.AddRange(CreateRegionSettingParameters(regionSettings));
  1242. conn.Open();
  1243. cmd.ExecuteNonQuery();
  1244. }
  1245. }
  1246. SaveSpawnPoints(regionSettings);
  1247. }
  1248. public void Shutdown()
  1249. {
  1250. //Not used??
  1251. }
  1252. #region Private Methods
  1253. /// <summary>
  1254. /// Stores new regionsettings.
  1255. /// </summary>
  1256. /// <param name="regionSettings">The region settings.</param>
  1257. private void StoreNewRegionSettings(RegionSettings regionSettings)
  1258. {
  1259. string sql = @"INSERT INTO regionsettings
  1260. (""regionUUID"",block_terraform,block_fly,allow_damage,restrict_pushing,allow_land_resell,allow_land_join_divide,
  1261. block_show_in_search,agent_limit,object_bonus,maturity,disable_scripts,disable_collisions,disable_physics,
  1262. terrain_texture_1,terrain_texture_2,terrain_texture_3,terrain_texture_4,elevation_1_nw,elevation_2_nw,elevation_1_ne,
  1263. elevation_2_ne,elevation_1_se,elevation_2_se,elevation_1_sw,elevation_2_sw,water_height,terrain_raise_limit,
  1264. terrain_lower_limit,use_estate_sun,fixed_sun,sun_position,covenant,covenant_datetime,sunvectorx, sunvectory, sunvectorz,
  1265. ""Sandbox"", loaded_creation_datetime, loaded_creation_id
  1266. )
  1267. VALUES
  1268. (:regionUUID,:block_terraform,:block_fly,:allow_damage,:restrict_pushing,:allow_land_resell,:allow_land_join_divide,
  1269. :block_show_in_search,:agent_limit,:object_bonus,:maturity,:disable_scripts,:disable_collisions,:disable_physics,
  1270. :terrain_texture_1,:terrain_texture_2,:terrain_texture_3,:terrain_texture_4,:elevation_1_nw,:elevation_2_nw,:elevation_1_ne,
  1271. :elevation_2_ne,:elevation_1_se,:elevation_2_se,:elevation_1_sw,:elevation_2_sw,:water_height,:terrain_raise_limit,
  1272. :terrain_lower_limit,:use_estate_sun,:fixed_sun,:sun_position,:covenant, :covenant_datetime, :sunvectorx,:sunvectory,
  1273. :sunvectorz, :Sandbox, :loaded_creation_datetime, :loaded_creation_id )";
  1274. using (NpgsqlConnection conn = new NpgsqlConnection(m_connectionString))
  1275. using (NpgsqlCommand cmd = new NpgsqlCommand(sql, conn))
  1276. {
  1277. cmd.Parameters.AddRange(CreateRegionSettingParameters(regionSettings));
  1278. conn.Open();
  1279. cmd.ExecuteNonQuery();
  1280. }
  1281. }
  1282. #region Private DataRecord conversion methods
  1283. /// <summary>
  1284. /// Builds the region settings from a datarecod.
  1285. /// </summary>
  1286. /// <param name="row">datarecord with regionsettings.</param>
  1287. /// <returns></returns>
  1288. private static RegionSettings BuildRegionSettings(IDataRecord row)
  1289. {
  1290. //TODO change this is some more generic code so we doesnt have to change it every time a new field is added?
  1291. RegionSettings newSettings = new RegionSettings();
  1292. newSettings.RegionUUID = new UUID((Guid)row["regionUUID"]);
  1293. newSettings.BlockTerraform = Convert.ToBoolean(row["block_terraform"]);
  1294. newSettings.AllowDamage = Convert.ToBoolean(row["allow_damage"]);
  1295. newSettings.BlockFly = Convert.ToBoolean(row["block_fly"]);
  1296. newSettings.RestrictPushing = Convert.ToBoolean(row["restrict_pushing"]);
  1297. newSettings.AllowLandResell = Convert.ToBoolean(row["allow_land_resell"]);
  1298. newSettings.AllowLandJoinDivide = Convert.ToBoolean(row["allow_land_join_divide"]);
  1299. newSettings.BlockShowInSearch = Convert.ToBoolean(row["block_show_in_search"]);
  1300. newSettings.AgentLimit = Convert.ToInt32(row["agent_limit"]);
  1301. newSettings.ObjectBonus = Convert.ToDouble(row["object_bonus"]);
  1302. newSettings.Maturity = Convert.ToInt32(row["maturity"]);
  1303. newSettings.DisableScripts = Convert.ToBoolean(row["disable_scripts"]);
  1304. newSettings.DisableCollisions = Convert.ToBoolean(row["disable_collisions"]);
  1305. newSettings.DisablePhysics = Convert.ToBoolean(row["disable_physics"]);
  1306. newSettings.TerrainTexture1 = new UUID((Guid)row["terrain_texture_1"]);
  1307. newSettings.TerrainTexture2 = new UUID((Guid)row["terrain_texture_2"]);
  1308. newSettings.TerrainTexture3 = new UUID((Guid)row["terrain_texture_3"]);
  1309. newSettings.TerrainTexture4 = new UUID((Guid)row["terrain_texture_4"]);
  1310. newSettings.Elevation1NW = Convert.ToDouble(row["elevation_1_nw"]);
  1311. newSettings.Elevation2NW = Convert.ToDouble(row["elevation_2_nw"]);
  1312. newSettings.Elevation1NE = Convert.ToDouble(row["elevation_1_ne"]);
  1313. newSettings.Elevation2NE = Convert.ToDouble(row["elevation_2_ne"]);
  1314. newSettings.Elevation1SE = Convert.ToDouble(row["elevation_1_se"]);
  1315. newSettings.Elevation2SE = Convert.ToDouble(row["elevation_2_se"]);
  1316. newSettings.Elevation1SW = Convert.ToDouble(row["elevation_1_sw"]);
  1317. newSettings.Elevation2SW = Convert.ToDouble(row["elevation_2_sw"]);
  1318. newSettings.WaterHeight = Convert.ToDouble(row["water_height"]);
  1319. newSettings.TerrainRaiseLimit = Convert.ToDouble(row["terrain_raise_limit"]);
  1320. newSettings.TerrainLowerLimit = Convert.ToDouble(row["terrain_lower_limit"]);
  1321. newSettings.UseEstateSun = Convert.ToBoolean(row["use_estate_sun"]);
  1322. newSettings.Sandbox = Convert.ToBoolean(row["Sandbox"]);
  1323. newSettings.FixedSun = Convert.ToBoolean(row["fixed_sun"]);
  1324. newSettings.SunPosition = Convert.ToDouble(row["sun_position"]);
  1325. newSettings.SunVector = new Vector3(
  1326. Convert.ToSingle(row["sunvectorx"]),
  1327. Convert.ToSingle(row["sunvectory"]),
  1328. Convert.ToSingle(row["sunvectorz"])
  1329. );
  1330. newSettings.Covenant = new UUID((Guid)row["covenant"]);
  1331. newSettings.CovenantChangedDateTime = Convert.ToInt32(row["covenant_datetime"]);
  1332. newSettings.LoadedCreationDateTime = Convert.ToInt32(row["loaded_creation_datetime"]);
  1333. if (row["loaded_creation_id"] is DBNull)
  1334. newSettings.LoadedCreationID = "";
  1335. else
  1336. newSettings.LoadedCreationID = (String)row["loaded_creation_id"];
  1337. newSettings.TerrainImageID = new UUID((string)row["map_tile_ID"]);
  1338. newSettings.ParcelImageID = new UUID((Guid)row["parcel_tile_ID"]);
  1339. newSettings.TelehubObject = new UUID((Guid)row["TelehubObject"]);
  1340. return newSettings;
  1341. }
  1342. /// <summary>
  1343. /// Builds the land data from a datarecord.
  1344. /// </summary>
  1345. /// <param name="row">datarecord with land data</param>
  1346. /// <returns></returns>
  1347. private static LandData BuildLandData(IDataRecord row)
  1348. {
  1349. LandData newData = new LandData();
  1350. newData.GlobalID = new UUID((Guid)row["UUID"]);
  1351. newData.LocalID = Convert.ToInt32(row["LocalLandID"]);
  1352. // Bitmap is a byte[512]
  1353. newData.Bitmap = (Byte[])row["Bitmap"];
  1354. newData.Name = (string)row["Name"];
  1355. newData.Description = (string)row["Description"];
  1356. newData.OwnerID = new UUID((Guid)row["OwnerUUID"]);
  1357. newData.IsGroupOwned = Convert.ToBoolean(row["IsGroupOwned"]);
  1358. newData.Area = Convert.ToInt32(row["Area"]);
  1359. newData.AuctionID = Convert.ToUInt32(row["AuctionID"]); //Unemplemented
  1360. newData.Category = (ParcelCategory)Convert.ToInt32(row["Category"]);
  1361. //Enum libsecondlife.Parcel.ParcelCategory
  1362. newData.ClaimDate = Convert.ToInt32(row["ClaimDate"]);
  1363. newData.ClaimPrice = Convert.ToInt32(row["ClaimPrice"]);
  1364. newData.GroupID = new UUID((Guid)row["GroupUUID"]);
  1365. newData.SalePrice = Convert.ToInt32(row["SalePrice"]);
  1366. newData.Status = (ParcelStatus)Convert.ToInt32(row["LandStatus"]);
  1367. //Enum. libsecondlife.Parcel.ParcelStatus
  1368. newData.Flags = Convert.ToUInt32(row["LandFlags"]);
  1369. newData.LandingType = Convert.ToByte(row["LandingType"]);
  1370. newData.MediaAutoScale = Convert.ToByte(row["MediaAutoScale"]);
  1371. newData.MediaID = new UUID((Guid)row["MediaTextureUUID"]);
  1372. newData.MediaURL = (string)row["MediaURL"];
  1373. newData.MusicURL = (string)row["MusicURL"];
  1374. newData.PassHours = Convert.ToSingle(row["PassHours"]);
  1375. newData.PassPrice = Convert.ToInt32(row["PassPrice"]);
  1376. // UUID authedbuyer;
  1377. // UUID snapshotID;
  1378. //
  1379. // if (UUID.TryParse((string)row["AuthBuyerID"], out authedbuyer))
  1380. // newData.AuthBuyerID = authedbuyer;
  1381. //
  1382. // if (UUID.TryParse((string)row["SnapshotUUID"], out snapshotID))
  1383. // newData.SnapshotID = snapshotID;
  1384. newData.AuthBuyerID = new UUID((Guid)row["AuthBuyerID"]);
  1385. newData.SnapshotID = new UUID((Guid)row["SnapshotUUID"]);
  1386. newData.OtherCleanTime = Convert.ToInt32(row["OtherCleanTime"]);
  1387. try
  1388. {
  1389. newData.UserLocation =
  1390. new Vector3(Convert.ToSingle(row["UserLocationX"]), Convert.ToSingle(row["UserLocationY"]),
  1391. Convert.ToSingle(row["UserLocationZ"]));
  1392. newData.UserLookAt =
  1393. new Vector3(Convert.ToSingle(row["UserLookAtX"]), Convert.ToSingle(row["UserLookAtY"]),
  1394. Convert.ToSingle(row["UserLookAtZ"]));
  1395. }
  1396. catch (InvalidCastException)
  1397. {
  1398. newData.UserLocation = Vector3.Zero;
  1399. newData.UserLookAt = Vector3.Zero;
  1400. _Log.ErrorFormat("[PARCEL]: unable to get parcel telehub settings for {1}", newData.Name);
  1401. }
  1402. newData.ParcelAccessList = new List<LandAccessEntry>();
  1403. newData.MediaDescription = (string)row["MediaDescription"];
  1404. newData.MediaType = (string)row["MediaType"];
  1405. newData.MediaWidth = Convert.ToInt32((((string)row["MediaSize"]).Split(','))[0]);
  1406. newData.MediaHeight = Convert.ToInt32((((string)row["MediaSize"]).Split(','))[1]);
  1407. newData.MediaLoop = Convert.ToBoolean(row["MediaLoop"]);
  1408. newData.ObscureMusic = Convert.ToBoolean(row["ObscureMusic"]);
  1409. newData.ObscureMedia = Convert.ToBoolean(row["ObscureMedia"]);
  1410. return newData;
  1411. }
  1412. /// <summary>
  1413. /// Builds the landaccess data from a data record.
  1414. /// </summary>
  1415. /// <param name="row">datarecord with landaccess data</param>
  1416. /// <returns></returns>
  1417. private static LandAccessEntry BuildLandAccessData(IDataRecord row)
  1418. {
  1419. LandAccessEntry entry = new LandAccessEntry();
  1420. entry.AgentID = new UUID((Guid)row["AccessUUID"]);
  1421. entry.Flags = (AccessList)Convert.ToInt32(row["Flags"]);
  1422. entry.Expires = Convert.ToInt32(row["Expires"]);
  1423. return entry;
  1424. }
  1425. /// <summary>
  1426. /// Builds the prim from a datarecord.
  1427. /// </summary>
  1428. /// <param name="primRow">datarecord</param>
  1429. /// <returns></returns>
  1430. private static SceneObjectPart BuildPrim(IDataRecord primRow)
  1431. {
  1432. SceneObjectPart prim = new SceneObjectPart();
  1433. prim.UUID = new UUID((Guid)primRow["UUID"]);
  1434. // explicit conversion of integers is required, which sort
  1435. // of sucks. No idea if there is a shortcut here or not.
  1436. prim.CreationDate = Convert.ToInt32(primRow["CreationDate"]);
  1437. prim.Name = (string)primRow["Name"];
  1438. // various text fields
  1439. prim.Text = (string)primRow["Text"];
  1440. prim.Color = Color.FromArgb(Convert.ToInt32(primRow["ColorA"]),
  1441. Convert.ToInt32(primRow["ColorR"]),
  1442. Convert.ToInt32(primRow["ColorG"]),
  1443. Convert.ToInt32(primRow["ColorB"]));
  1444. prim.Description = (string)primRow["Description"];
  1445. prim.SitName = (string)primRow["SitName"];
  1446. prim.TouchName = (string)primRow["TouchName"];
  1447. // permissions
  1448. prim.Flags = (PrimFlags)Convert.ToUInt32(primRow["ObjectFlags"]);
  1449. //prim.creatorID = new UUID((Guid)primRow["creatorID"]);
  1450. prim.CreatorIdentification = (string)primRow["CreatorID"].ToString();
  1451. prim.OwnerID = new UUID((Guid)primRow["OwnerID"]);
  1452. prim.GroupID = new UUID((Guid)primRow["GroupID"]);
  1453. prim.LastOwnerID = new UUID((Guid)primRow["LastOwnerID"]);
  1454. prim.OwnerMask = Convert.ToUInt32(primRow["OwnerMask"]);
  1455. prim.NextOwnerMask = Convert.ToUInt32(primRow["NextOwnerMask"]);
  1456. prim.GroupMask = Convert.ToUInt32(primRow["GroupMask"]);
  1457. prim.EveryoneMask = Convert.ToUInt32(primRow["EveryoneMask"]);
  1458. prim.BaseMask = Convert.ToUInt32(primRow["BaseMask"]);
  1459. // vectors
  1460. prim.OffsetPosition = new Vector3(
  1461. Convert.ToSingle(primRow["PositionX"]),
  1462. Convert.ToSingle(primRow["PositionY"]),
  1463. Convert.ToSingle(primRow["PositionZ"]));
  1464. prim.GroupPosition = new Vector3(
  1465. Convert.ToSingle(primRow["GroupPositionX"]),
  1466. Convert.ToSingle(primRow["GroupPositionY"]),
  1467. Convert.ToSingle(primRow["GroupPositionZ"]));
  1468. prim.Velocity = new Vector3(
  1469. Convert.ToSingle(primRow["VelocityX"]),
  1470. Convert.ToSingle(primRow["VelocityY"]),
  1471. Convert.ToSingle(primRow["VelocityZ"]));
  1472. prim.AngularVelocity = new Vector3(
  1473. Convert.ToSingle(primRow["AngularVelocityX"]),
  1474. Convert.ToSingle(primRow["AngularVelocityY"]),
  1475. Convert.ToSingle(primRow["AngularVelocityZ"]));
  1476. prim.Acceleration = new Vector3(
  1477. Convert.ToSingle(primRow["AccelerationX"]),
  1478. Convert.ToSingle(primRow["AccelerationY"]),
  1479. Convert.ToSingle(primRow["AccelerationZ"]));
  1480. // quaternions
  1481. prim.RotationOffset = new Quaternion(
  1482. Convert.ToSingle(primRow["RotationX"]),
  1483. Convert.ToSingle(primRow["RotationY"]),
  1484. Convert.ToSingle(primRow["RotationZ"]),
  1485. Convert.ToSingle(primRow["RotationW"]));
  1486. prim.SitTargetPositionLL = new Vector3(
  1487. Convert.ToSingle(primRow["SitTargetOffsetX"]),
  1488. Convert.ToSingle(primRow["SitTargetOffsetY"]),
  1489. Convert.ToSingle(primRow["SitTargetOffsetZ"]));
  1490. prim.SitTargetOrientationLL = new Quaternion(
  1491. Convert.ToSingle(primRow["SitTargetOrientX"]),
  1492. Convert.ToSingle(primRow["SitTargetOrientY"]),
  1493. Convert.ToSingle(primRow["SitTargetOrientZ"]),
  1494. Convert.ToSingle(primRow["SitTargetOrientW"]));
  1495. prim.PayPrice[0] = Convert.ToInt32(primRow["PayPrice"]);
  1496. prim.PayPrice[1] = Convert.ToInt32(primRow["PayButton1"]);
  1497. prim.PayPrice[2] = Convert.ToInt32(primRow["PayButton2"]);
  1498. prim.PayPrice[3] = Convert.ToInt32(primRow["PayButton3"]);
  1499. prim.PayPrice[4] = Convert.ToInt32(primRow["PayButton4"]);
  1500. prim.Sound = new UUID((Guid)primRow["LoopedSound"]);
  1501. prim.SoundGain = Convert.ToSingle(primRow["LoopedSoundGain"]);
  1502. prim.SoundFlags = 1; // If it's persisted at all, it's looped
  1503. if (!(primRow["TextureAnimation"] is DBNull))
  1504. prim.TextureAnimation = (Byte[])primRow["TextureAnimation"];
  1505. if (!(primRow["ParticleSystem"] is DBNull))
  1506. prim.ParticleSystem = (Byte[])primRow["ParticleSystem"];
  1507. prim.AngularVelocity = new Vector3(
  1508. Convert.ToSingle(primRow["OmegaX"]),
  1509. Convert.ToSingle(primRow["OmegaY"]),
  1510. Convert.ToSingle(primRow["OmegaZ"]));
  1511. prim.SetCameraEyeOffset(new Vector3(
  1512. Convert.ToSingle(primRow["CameraEyeOffsetX"]),
  1513. Convert.ToSingle(primRow["CameraEyeOffsetY"]),
  1514. Convert.ToSingle(primRow["CameraEyeOffsetZ"])
  1515. ));
  1516. prim.SetCameraAtOffset(new Vector3(
  1517. Convert.ToSingle(primRow["CameraAtOffsetX"]),
  1518. Convert.ToSingle(primRow["CameraAtOffsetY"]),
  1519. Convert.ToSingle(primRow["CameraAtOffsetZ"])
  1520. ));
  1521. if (Convert.ToInt16(primRow["ForceMouselook"]) != 0)
  1522. prim.SetForceMouselook(true);
  1523. prim.ScriptAccessPin = Convert.ToInt32(primRow["ScriptAccessPin"]);
  1524. if (Convert.ToInt16(primRow["AllowedDrop"]) != 0)
  1525. prim.AllowedDrop = true;
  1526. if (Convert.ToInt16(primRow["DieAtEdge"]) != 0)
  1527. prim.DIE_AT_EDGE = true;
  1528. prim.SalePrice = Convert.ToInt32(primRow["SalePrice"]);
  1529. prim.ObjectSaleType = Convert.ToByte(primRow["SaleType"]);
  1530. prim.Material = Convert.ToByte(primRow["Material"]);
  1531. if (!(primRow["ClickAction"] is DBNull))
  1532. prim.ClickAction = Convert.ToByte(primRow["ClickAction"]);
  1533. prim.CollisionSound = new UUID((Guid)primRow["CollisionSound"]);
  1534. prim.CollisionSoundVolume = Convert.ToSingle(primRow["CollisionSoundVolume"]);
  1535. prim.PassTouches = (bool)primRow["PassTouches"];
  1536. if (!(primRow["MediaURL"] is System.DBNull))
  1537. prim.MediaUrl = (string)primRow["MediaURL"];
  1538. if (!(primRow["DynAttrs"] is System.DBNull) && (string)primRow["DynAttrs"] != "")
  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"].ToString();
  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 NpgsqlParameter[] CreatePrimInventoryParameters(TaskInventoryItem taskItem)
  1636. {
  1637. List<NpgsqlParameter> parameters = new List<NpgsqlParameter>();
  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 NpgsqlParameter[] CreateRegionSettingParameters(RegionSettings settings)
  1665. {
  1666. List<NpgsqlParameter> parameters = new List<NpgsqlParameter>();
  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 NpgsqlParameter[] CreateLandParameters(LandData land, UUID regionUUID)
  1719. {
  1720. List<NpgsqlParameter> parameters = new List<NpgsqlParameter>();
  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", Convert.ToInt32( land.LandingType) ));
  1740. parameters.Add(_Database.CreateParameter("MediaAutoScale", Convert.ToInt32( 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 NpgsqlParameter[] CreateLandAccessParameters(LandAccessEntry parcelAccessEntry, UUID parcelID)
  1764. {
  1765. List<NpgsqlParameter> parameters = new List<NpgsqlParameter>();
  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 NpgsqlParameter[] CreatePrimParameters(SceneObjectPart prim, UUID sceneGroupID, UUID regionUUID)
  1780. {
  1781. List<NpgsqlParameter> parameters = new List<NpgsqlParameter>();
  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. parameters.Add(_Database.CreateParameter("PassTouches", prim.PassTouches));
  1886. parameters.Add(_Database.CreateParameter("LinkNumber", prim.LinkNum));
  1887. parameters.Add(_Database.CreateParameter("MediaURL", prim.MediaUrl));
  1888. if (prim.DynAttrs.CountNamespaces > 0)
  1889. parameters.Add(_Database.CreateParameter("DynAttrs", prim.DynAttrs.ToXml()));
  1890. else
  1891. parameters.Add(_Database.CreateParameter("DynAttrs", null));
  1892. parameters.Add(_Database.CreateParameter("PhysicsShapeType", prim.PhysicsShapeType));
  1893. parameters.Add(_Database.CreateParameter("Density", (double)prim.Density));
  1894. parameters.Add(_Database.CreateParameter("GravityModifier", (double)prim.GravityModifier));
  1895. parameters.Add(_Database.CreateParameter("Friction", (double)prim.Friction));
  1896. parameters.Add(_Database.CreateParameter("Restitution", (double)prim.Restitution));
  1897. return parameters.ToArray();
  1898. }
  1899. /// <summary>
  1900. /// Creates the primshape parameters for stroing in DB.
  1901. /// </summary>
  1902. /// <param name="prim">Basic data of SceneObjectpart prim.</param>
  1903. /// <param name="sceneGroupID">The scene group ID.</param>
  1904. /// <param name="regionUUID">The region UUID.</param>
  1905. /// <returns></returns>
  1906. private NpgsqlParameter[] CreatePrimShapeParameters(SceneObjectPart prim, UUID sceneGroupID, UUID regionUUID)
  1907. {
  1908. List<NpgsqlParameter> parameters = new List<NpgsqlParameter>();
  1909. PrimitiveBaseShape s = prim.Shape;
  1910. parameters.Add(_Database.CreateParameter("UUID", prim.UUID));
  1911. // shape is an enum
  1912. parameters.Add(_Database.CreateParameter("Shape", 0));
  1913. // vectors
  1914. parameters.Add(_Database.CreateParameter("ScaleX", s.Scale.X));
  1915. parameters.Add(_Database.CreateParameter("ScaleY", s.Scale.Y));
  1916. parameters.Add(_Database.CreateParameter("ScaleZ", s.Scale.Z));
  1917. // paths
  1918. parameters.Add(_Database.CreateParameter("PCode", s.PCode));
  1919. parameters.Add(_Database.CreateParameter("PathBegin", s.PathBegin));
  1920. parameters.Add(_Database.CreateParameter("PathEnd", s.PathEnd));
  1921. parameters.Add(_Database.CreateParameter("PathScaleX", s.PathScaleX));
  1922. parameters.Add(_Database.CreateParameter("PathScaleY", s.PathScaleY));
  1923. parameters.Add(_Database.CreateParameter("PathShearX", s.PathShearX));
  1924. parameters.Add(_Database.CreateParameter("PathShearY", s.PathShearY));
  1925. parameters.Add(_Database.CreateParameter("PathSkew", s.PathSkew));
  1926. parameters.Add(_Database.CreateParameter("PathCurve", s.PathCurve));
  1927. parameters.Add(_Database.CreateParameter("PathRadiusOffset", s.PathRadiusOffset));
  1928. parameters.Add(_Database.CreateParameter("PathRevolutions", s.PathRevolutions));
  1929. parameters.Add(_Database.CreateParameter("PathTaperX", s.PathTaperX));
  1930. parameters.Add(_Database.CreateParameter("PathTaperY", s.PathTaperY));
  1931. parameters.Add(_Database.CreateParameter("PathTwist", s.PathTwist));
  1932. parameters.Add(_Database.CreateParameter("PathTwistBegin", s.PathTwistBegin));
  1933. // profile
  1934. parameters.Add(_Database.CreateParameter("ProfileBegin", s.ProfileBegin));
  1935. parameters.Add(_Database.CreateParameter("ProfileEnd", s.ProfileEnd));
  1936. parameters.Add(_Database.CreateParameter("ProfileCurve", s.ProfileCurve));
  1937. parameters.Add(_Database.CreateParameter("ProfileHollow", s.ProfileHollow));
  1938. parameters.Add(_Database.CreateParameter("Texture", s.TextureEntry));
  1939. parameters.Add(_Database.CreateParameter("ExtraParams", s.ExtraParams));
  1940. parameters.Add(_Database.CreateParameter("State", s.State));
  1941. if (null == s.Media)
  1942. {
  1943. parameters.Add(_Database.CreateParameter("Media", DBNull.Value));
  1944. }
  1945. else
  1946. {
  1947. parameters.Add(_Database.CreateParameter("Media", s.Media.ToXml()));
  1948. }
  1949. return parameters.ToArray();
  1950. }
  1951. #endregion
  1952. #endregion
  1953. private void LoadSpawnPoints(RegionSettings rs)
  1954. {
  1955. rs.ClearSpawnPoints();
  1956. string sql = @"SELECT ""Yaw"", ""Pitch"", ""Distance"" FROM spawn_points WHERE ""RegionUUID"" = :RegionUUID";
  1957. using (NpgsqlConnection conn = new NpgsqlConnection(m_connectionString))
  1958. using (NpgsqlCommand cmd = new NpgsqlCommand(sql, conn))
  1959. {
  1960. cmd.Parameters.Add(_Database.CreateParameter("RegionUUID", rs.RegionUUID));
  1961. conn.Open();
  1962. using (NpgsqlDataReader reader = cmd.ExecuteReader())
  1963. {
  1964. if (reader.Read())
  1965. {
  1966. SpawnPoint sp = new SpawnPoint();
  1967. sp.Yaw = (float)reader["Yaw"];
  1968. sp.Pitch = (float)reader["Pitch"];
  1969. sp.Distance = (float)reader["Distance"];
  1970. rs.AddSpawnPoint(sp);
  1971. }
  1972. }
  1973. }
  1974. }
  1975. private void SaveSpawnPoints(RegionSettings rs)
  1976. {
  1977. string sql = @"DELETE FROM spawn_points WHERE ""RegionUUID"" = :RegionUUID";
  1978. using (NpgsqlConnection conn = new NpgsqlConnection(m_connectionString))
  1979. using (NpgsqlCommand cmd = new NpgsqlCommand(sql, conn))
  1980. {
  1981. cmd.Parameters.Add(_Database.CreateParameter("RegionUUID", rs.RegionUUID));
  1982. conn.Open();
  1983. cmd.ExecuteNonQuery();
  1984. }
  1985. foreach (SpawnPoint p in rs.SpawnPoints())
  1986. {
  1987. sql = @"INSERT INTO spawn_points (""RegionUUID"", ""Yaw"", ""Pitch"", ""Distance"") VALUES (:RegionUUID, :Yaw, :Pitch, :Distance)";
  1988. using (NpgsqlConnection conn = new NpgsqlConnection(m_connectionString))
  1989. using (NpgsqlCommand cmd = new NpgsqlCommand(sql, conn))
  1990. {
  1991. cmd.Parameters.Add(_Database.CreateParameter("RegionUUID", rs.RegionUUID));
  1992. cmd.Parameters.Add(_Database.CreateParameter("Yaw", p.Yaw));
  1993. cmd.Parameters.Add(_Database.CreateParameter("Pitch", p.Pitch));
  1994. cmd.Parameters.Add(_Database.CreateParameter("Distance", p.Distance));
  1995. conn.Open();
  1996. cmd.ExecuteNonQuery();
  1997. }
  1998. }
  1999. }
  2000. public UUID[] GetObjectIDs(UUID regionID)
  2001. {
  2002. return new UUID[0];
  2003. }
  2004. public void SaveExtra(UUID regionID, string name, string value)
  2005. {
  2006. }
  2007. public void RemoveExtra(UUID regionID, string name)
  2008. {
  2009. }
  2010. public Dictionary<string, string> GetExtra(UUID regionID)
  2011. {
  2012. return null;
  2013. }
  2014. }
  2015. }