PGSQLSimulationData.cs 134 KB

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