PGSQLSimulationData.cs 103 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989
  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, ""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"",
  326. ""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,
  338. :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. ""environment"")
  679. VALUES
  680. (:UUID,:RegionUUID,:LocalLandID,:Bitmap,:Name,:Description,:OwnerUUID,:IsGroupOwned,:Area,:AuctionID,:Category,:ClaimDate,:ClaimPrice,
  681. :GroupUUID,:SalePrice,:LandStatus,:LandFlags,:LandingType,:MediaAutoScale,:MediaTextureUUID,:MediaURL,:MusicURL,:PassHours,:PassPrice,
  682. :SnapshotUUID,:UserLocationX,:UserLocationY,:UserLocationZ,:UserLookAtX,:UserLookAtY,:UserLookAtZ,:AuthbuyerID,:OtherCleanTime,:Dwell,
  683. :MediaType,:MediaDescription,:MediaWidth::text || ',' || :MediaHeight::text,:MediaLoop,:ObscureMusic,:ObscureMedia,:SeeAVs::int::smallint,
  684. :AnyAVSounds::int::smallint,:GroupAVSounds::int::smallint,:environment)";
  685. using (NpgsqlConnection conn = new NpgsqlConnection(m_connectionString))
  686. using (NpgsqlCommand cmd = new NpgsqlCommand(sql, conn))
  687. {
  688. cmd.Parameters.AddRange(CreateLandParameters(parcel.LandData, parcel.RegionUUID));
  689. conn.Open();
  690. cmd.ExecuteNonQuery();
  691. }
  692. sql = @"INSERT INTO landaccesslist (""LandUUID"",""AccessUUID"",""LandFlags"",""Expires"") VALUES (:LandUUID,:AccessUUID,:Flags,:Expires)";
  693. using (NpgsqlConnection conn = new NpgsqlConnection(m_connectionString))
  694. using (NpgsqlCommand cmd = new NpgsqlCommand(sql, conn))
  695. {
  696. conn.Open();
  697. foreach (LandAccessEntry parcelAccessEntry in parcel.LandData.ParcelAccessList)
  698. {
  699. cmd.Parameters.AddRange(CreateLandAccessParameters(parcelAccessEntry, parcel.RegionUUID));
  700. cmd.ExecuteNonQuery();
  701. cmd.Parameters.Clear();
  702. }
  703. }
  704. }
  705. /// <summary>
  706. /// Removes a land object from DB.
  707. /// </summary>
  708. /// <param name="globalID">UUID of landobject</param>
  709. public void RemoveLandObject(UUID globalID)
  710. {
  711. string sql = @"delete from land where ""UUID""=:UUID";
  712. using (NpgsqlConnection conn = new NpgsqlConnection(m_connectionString))
  713. using (NpgsqlCommand cmd = new NpgsqlCommand(sql, conn))
  714. {
  715. cmd.Parameters.Add(_Database.CreateParameter("UUID", globalID));
  716. conn.Open();
  717. cmd.ExecuteNonQuery();
  718. }
  719. sql = @"delete from landaccesslist where ""LandUUID""=:UUID";
  720. using (NpgsqlConnection conn = new NpgsqlConnection(m_connectionString))
  721. using (NpgsqlCommand cmd = new NpgsqlCommand(sql, conn))
  722. {
  723. cmd.Parameters.Add(_Database.CreateParameter("UUID", globalID));
  724. conn.Open();
  725. cmd.ExecuteNonQuery();
  726. }
  727. }
  728. #region Environment Settings
  729. public string LoadRegionEnvironmentSettings(UUID regionUUID)
  730. {
  731. string sql = "select * from regionenvironment where region_id = :region_id";
  732. using (NpgsqlConnection conn = new NpgsqlConnection(m_connectionString))
  733. using (NpgsqlCommand cmd = new NpgsqlCommand(sql, conn))
  734. {
  735. cmd.Parameters.Add(_Database.CreateParameter("region_id", regionUUID));
  736. conn.Open();
  737. using (NpgsqlDataReader result = cmd.ExecuteReader())
  738. {
  739. if (!result.Read())
  740. {
  741. return String.Empty;
  742. }
  743. else
  744. {
  745. return Convert.ToString(result["llsd_settings"]);
  746. }
  747. }
  748. }
  749. }
  750. public void StoreRegionEnvironmentSettings(UUID regionUUID, string settings)
  751. {
  752. {
  753. string sql = "DELETE FROM regionenvironment WHERE region_id = :region_id ;";
  754. using (NpgsqlConnection conn = new NpgsqlConnection(m_connectionString))
  755. using (NpgsqlCommand cmd = new NpgsqlCommand(sql, conn))
  756. {
  757. cmd.Parameters.Add(_Database.CreateParameter("region_id", regionUUID));
  758. conn.Open();
  759. cmd.ExecuteNonQuery();
  760. }
  761. sql = "INSERT INTO regionenvironment (region_id, llsd_settings) VALUES (:region_id, :llsd_settings) ;";
  762. using (NpgsqlConnection conn = new NpgsqlConnection(m_connectionString))
  763. using (NpgsqlCommand cmd = new NpgsqlCommand(sql, conn))
  764. {
  765. cmd.Parameters.Add(_Database.CreateParameter("region_id", regionUUID));
  766. cmd.Parameters.Add(_Database.CreateParameter("llsd_settings", settings));
  767. conn.Open();
  768. cmd.ExecuteNonQuery();
  769. }
  770. }
  771. }
  772. public void RemoveRegionEnvironmentSettings(UUID regionUUID)
  773. {
  774. string sql = "delete from regionenvironment where region_id = :region_id ;";
  775. using (NpgsqlConnection conn = new NpgsqlConnection(m_connectionString))
  776. using (NpgsqlCommand cmd = new NpgsqlCommand(sql, conn))
  777. {
  778. cmd.Parameters.Add(_Database.CreateParameter("region_id", regionUUID));
  779. conn.Open();
  780. cmd.ExecuteNonQuery();
  781. }
  782. }
  783. #endregion
  784. /// <summary>
  785. /// Loads the settings of a region.
  786. /// </summary>
  787. /// <param name="regionUUID">The region UUID.</param>
  788. /// <returns></returns>
  789. public RegionSettings LoadRegionSettings(UUID regionUUID)
  790. {
  791. string sql = @"select * from regionsettings where ""regionUUID"" = :regionUUID";
  792. RegionSettings regionSettings;
  793. using (NpgsqlConnection conn = new NpgsqlConnection(m_connectionString))
  794. using (NpgsqlCommand cmd = new NpgsqlCommand(sql, conn))
  795. {
  796. cmd.Parameters.Add(_Database.CreateParameter("regionUUID", regionUUID));
  797. conn.Open();
  798. using (NpgsqlDataReader reader = cmd.ExecuteReader())
  799. {
  800. if (reader.Read())
  801. {
  802. regionSettings = BuildRegionSettings(reader);
  803. regionSettings.OnSave += StoreRegionSettings;
  804. return regionSettings;
  805. }
  806. }
  807. }
  808. //If we reach this point then there are new region settings for that region
  809. regionSettings = new RegionSettings();
  810. regionSettings.RegionUUID = regionUUID;
  811. regionSettings.OnSave += StoreRegionSettings;
  812. //Store new values
  813. StoreNewRegionSettings(regionSettings);
  814. LoadSpawnPoints(regionSettings);
  815. return regionSettings;
  816. }
  817. /// <summary>
  818. /// Store region settings, need to check if the check is really necesary. If we can make something for creating new region.
  819. /// </summary>
  820. /// <param name="regionSettings">region settings.</param>
  821. public void StoreRegionSettings(RegionSettings regionSettings)
  822. {
  823. //Little check if regionUUID already exist in DB
  824. string regionUUID;
  825. string sql = @"SELECT ""regionUUID"" FROM regionsettings WHERE ""regionUUID"" = :regionUUID";
  826. using (NpgsqlConnection conn = new NpgsqlConnection(m_connectionString))
  827. using (NpgsqlCommand cmd = new NpgsqlCommand(sql, conn))
  828. {
  829. cmd.Parameters.Add(_Database.CreateParameter("regionUUID", regionSettings.RegionUUID));
  830. conn.Open();
  831. regionUUID = cmd.ExecuteScalar().ToString();
  832. }
  833. if (string.IsNullOrEmpty(regionUUID))
  834. {
  835. StoreNewRegionSettings(regionSettings);
  836. }
  837. else
  838. {
  839. //This method only updates region settings!!! First call LoadRegionSettings to create new region settings in DB
  840. sql =
  841. @"UPDATE regionsettings SET block_terraform = :block_terraform ,block_fly = :block_fly ,allow_damage = :allow_damage
  842. ,restrict_pushing = :restrict_pushing ,allow_land_resell = :allow_land_resell ,allow_land_join_divide = :allow_land_join_divide
  843. ,block_show_in_search = :block_show_in_search ,agent_limit = :agent_limit ,object_bonus = :object_bonus ,maturity = :maturity
  844. ,disable_scripts = :disable_scripts ,disable_collisions = :disable_collisions ,disable_physics = :disable_physics
  845. ,terrain_texture_1 = :terrain_texture_1 ,terrain_texture_2 = :terrain_texture_2 ,terrain_texture_3 = :terrain_texture_3
  846. ,terrain_texture_4 = :terrain_texture_4 ,elevation_1_nw = :elevation_1_nw ,elevation_2_nw = :elevation_2_nw
  847. ,elevation_1_ne = :elevation_1_ne ,elevation_2_ne = :elevation_2_ne ,elevation_1_se = :elevation_1_se ,elevation_2_se = :elevation_2_se
  848. ,elevation_1_sw = :elevation_1_sw ,elevation_2_sw = :elevation_2_sw ,water_height = :water_height ,terrain_raise_limit = :terrain_raise_limit
  849. ,terrain_lower_limit = :terrain_lower_limit ,use_estate_sun = :use_estate_sun ,fixed_sun = :fixed_sun ,sun_position = :sun_position
  850. ,covenant = :covenant ,covenant_datetime = :covenant_datetime, sunvectorx = :sunvectorx, sunvectory = :sunvectory, sunvectorz = :sunvectorz,
  851. ""Sandbox"" = :Sandbox, loaded_creation_datetime = :loaded_creation_datetime, loaded_creation_id = :loaded_creation_id, ""map_tile_ID"" = :TerrainImageID,
  852. ""TelehubObject"" = :telehubobject, ""parcel_tile_ID"" = :ParcelImageID, ""cacheID"" = :cacheID
  853. WHERE ""regionUUID"" = :regionUUID";
  854. using (NpgsqlConnection conn = new NpgsqlConnection(m_connectionString))
  855. using (NpgsqlCommand cmd = new NpgsqlCommand(sql, conn))
  856. {
  857. cmd.Parameters.AddRange(CreateRegionSettingParameters(regionSettings));
  858. conn.Open();
  859. cmd.ExecuteNonQuery();
  860. }
  861. }
  862. SaveSpawnPoints(regionSettings);
  863. }
  864. public void Shutdown()
  865. {
  866. //Not used??
  867. }
  868. #region Private Methods
  869. /// <summary>
  870. /// Stores new regionsettings.
  871. /// </summary>
  872. /// <param name="regionSettings">The region settings.</param>
  873. private void StoreNewRegionSettings(RegionSettings regionSettings)
  874. {
  875. string sql = @"INSERT INTO regionsettings
  876. (""regionUUID"",block_terraform,block_fly,allow_damage,restrict_pushing,allow_land_resell,allow_land_join_divide,
  877. block_show_in_search,agent_limit,object_bonus,maturity,disable_scripts,disable_collisions,disable_physics,
  878. terrain_texture_1,terrain_texture_2,terrain_texture_3,terrain_texture_4,elevation_1_nw,elevation_2_nw,elevation_1_ne,
  879. elevation_2_ne,elevation_1_se,elevation_2_se,elevation_1_sw,elevation_2_sw,water_height,terrain_raise_limit,
  880. terrain_lower_limit,use_estate_sun,fixed_sun,sun_position,covenant,covenant_datetime,sunvectorx, sunvectory, sunvectorz,
  881. ""Sandbox"", loaded_creation_datetime, loaded_creation_id
  882. )
  883. VALUES
  884. (:regionUUID,:block_terraform,:block_fly,:allow_damage,:restrict_pushing,:allow_land_resell,:allow_land_join_divide,
  885. :block_show_in_search,:agent_limit,:object_bonus,:maturity,:disable_scripts,:disable_collisions,:disable_physics,
  886. :terrain_texture_1,:terrain_texture_2,:terrain_texture_3,:terrain_texture_4,:elevation_1_nw,:elevation_2_nw,:elevation_1_ne,
  887. :elevation_2_ne,:elevation_1_se,:elevation_2_se,:elevation_1_sw,:elevation_2_sw,:water_height,:terrain_raise_limit,
  888. :terrain_lower_limit,:use_estate_sun,:fixed_sun,:sun_position,:covenant, :covenant_datetime, :sunvectorx,:sunvectory,
  889. :sunvectorz, :Sandbox, :loaded_creation_datetime, :loaded_creation_id )";
  890. using (NpgsqlConnection conn = new NpgsqlConnection(m_connectionString))
  891. using (NpgsqlCommand cmd = new NpgsqlCommand(sql, conn))
  892. {
  893. cmd.Parameters.AddRange(CreateRegionSettingParameters(regionSettings));
  894. conn.Open();
  895. cmd.ExecuteNonQuery();
  896. }
  897. }
  898. #region Private DataRecord conversion methods
  899. /// <summary>
  900. /// Builds the region settings from a datarecod.
  901. /// </summary>
  902. /// <param name="row">datarecord with regionsettings.</param>
  903. /// <returns></returns>
  904. private static RegionSettings BuildRegionSettings(IDataRecord row)
  905. {
  906. //TODO change this is some more generic code so we doesnt have to change it every time a new field is added?
  907. RegionSettings newSettings = new RegionSettings();
  908. newSettings.RegionUUID = new UUID((Guid)row["regionUUID"]);
  909. newSettings.BlockTerraform = Convert.ToBoolean(row["block_terraform"]);
  910. newSettings.AllowDamage = Convert.ToBoolean(row["allow_damage"]);
  911. newSettings.BlockFly = Convert.ToBoolean(row["block_fly"]);
  912. newSettings.RestrictPushing = Convert.ToBoolean(row["restrict_pushing"]);
  913. newSettings.AllowLandResell = Convert.ToBoolean(row["allow_land_resell"]);
  914. newSettings.AllowLandJoinDivide = Convert.ToBoolean(row["allow_land_join_divide"]);
  915. newSettings.BlockShowInSearch = Convert.ToBoolean(row["block_show_in_search"]);
  916. newSettings.AgentLimit = Convert.ToInt32(row["agent_limit"]);
  917. newSettings.ObjectBonus = Convert.ToDouble(row["object_bonus"]);
  918. newSettings.Maturity = Convert.ToInt32(row["maturity"]);
  919. newSettings.DisableScripts = Convert.ToBoolean(row["disable_scripts"]);
  920. newSettings.DisableCollisions = Convert.ToBoolean(row["disable_collisions"]);
  921. newSettings.DisablePhysics = Convert.ToBoolean(row["disable_physics"]);
  922. newSettings.TerrainTexture1 = new UUID((Guid)row["terrain_texture_1"]);
  923. newSettings.TerrainTexture2 = new UUID((Guid)row["terrain_texture_2"]);
  924. newSettings.TerrainTexture3 = new UUID((Guid)row["terrain_texture_3"]);
  925. newSettings.TerrainTexture4 = new UUID((Guid)row["terrain_texture_4"]);
  926. newSettings.Elevation1NW = Convert.ToDouble(row["elevation_1_nw"]);
  927. newSettings.Elevation2NW = Convert.ToDouble(row["elevation_2_nw"]);
  928. newSettings.Elevation1NE = Convert.ToDouble(row["elevation_1_ne"]);
  929. newSettings.Elevation2NE = Convert.ToDouble(row["elevation_2_ne"]);
  930. newSettings.Elevation1SE = Convert.ToDouble(row["elevation_1_se"]);
  931. newSettings.Elevation2SE = Convert.ToDouble(row["elevation_2_se"]);
  932. newSettings.Elevation1SW = Convert.ToDouble(row["elevation_1_sw"]);
  933. newSettings.Elevation2SW = Convert.ToDouble(row["elevation_2_sw"]);
  934. newSettings.WaterHeight = Convert.ToDouble(row["water_height"]);
  935. newSettings.TerrainRaiseLimit = Convert.ToDouble(row["terrain_raise_limit"]);
  936. newSettings.TerrainLowerLimit = Convert.ToDouble(row["terrain_lower_limit"]);
  937. newSettings.UseEstateSun = Convert.ToBoolean(row["use_estate_sun"]);
  938. newSettings.Sandbox = Convert.ToBoolean(row["Sandbox"]);
  939. newSettings.FixedSun = Convert.ToBoolean(row["fixed_sun"]);
  940. newSettings.SunPosition = Convert.ToDouble(row["sun_position"]);
  941. newSettings.SunVector = new Vector3(
  942. Convert.ToSingle(row["sunvectorx"]),
  943. Convert.ToSingle(row["sunvectory"]),
  944. Convert.ToSingle(row["sunvectorz"])
  945. );
  946. newSettings.Covenant = new UUID((Guid)row["covenant"]);
  947. newSettings.CovenantChangedDateTime = Convert.ToInt32(row["covenant_datetime"]);
  948. newSettings.LoadedCreationDateTime = Convert.ToInt32(row["loaded_creation_datetime"]);
  949. if (row["loaded_creation_id"] is DBNull)
  950. newSettings.LoadedCreationID = "";
  951. else
  952. newSettings.LoadedCreationID = (String)row["loaded_creation_id"];
  953. newSettings.TerrainImageID = new UUID((string)row["map_tile_ID"]);
  954. newSettings.ParcelImageID = new UUID((Guid)row["parcel_tile_ID"]);
  955. newSettings.TelehubObject = new UUID((Guid)row["TelehubObject"]);
  956. if (!(row["cacheID"] is DBNull))
  957. newSettings.CacheID = new UUID((Guid)row["cacheID"]);
  958. return newSettings;
  959. }
  960. /// <summary>
  961. /// Builds the land data from a datarecord.
  962. /// </summary>
  963. /// <param name="row">datarecord with land data</param>
  964. /// <returns></returns>
  965. private static LandData BuildLandData(IDataRecord row)
  966. {
  967. LandData newData = new LandData();
  968. newData.GlobalID = new UUID((Guid)row["UUID"]);
  969. newData.LocalID = Convert.ToInt32(row["LocalLandID"]);
  970. // Bitmap is a byte[512]
  971. newData.Bitmap = (Byte[])row["Bitmap"];
  972. newData.Name = (string)row["Name"];
  973. newData.Description = (string)row["Description"];
  974. newData.OwnerID = new UUID((Guid)row["OwnerUUID"]);
  975. newData.IsGroupOwned = Convert.ToBoolean(row["IsGroupOwned"]);
  976. newData.Area = Convert.ToInt32(row["Area"]);
  977. newData.AuctionID = Convert.ToUInt32(row["AuctionID"]); //Unemplemented
  978. newData.Category = (ParcelCategory)Convert.ToInt32(row["Category"]);
  979. //Enum libsecondlife.Parcel.ParcelCategory
  980. newData.ClaimDate = Convert.ToInt32(row["ClaimDate"]);
  981. newData.ClaimPrice = Convert.ToInt32(row["ClaimPrice"]);
  982. newData.GroupID = new UUID((Guid)row["GroupUUID"]);
  983. newData.SalePrice = Convert.ToInt32(row["SalePrice"]);
  984. newData.Status = (ParcelStatus)Convert.ToInt32(row["LandStatus"]);
  985. //Enum. libsecondlife.Parcel.ParcelStatus
  986. newData.Flags = Convert.ToUInt32(row["LandFlags"]);
  987. newData.LandingType = Convert.ToByte(row["LandingType"]);
  988. newData.MediaAutoScale = Convert.ToByte(row["MediaAutoScale"]);
  989. newData.MediaID = new UUID((Guid)row["MediaTextureUUID"]);
  990. newData.MediaURL = (string)row["MediaURL"];
  991. newData.MusicURL = (string)row["MusicURL"];
  992. newData.PassHours = Convert.ToSingle(row["PassHours"]);
  993. newData.PassPrice = Convert.ToInt32(row["PassPrice"]);
  994. // UUID authedbuyer;
  995. // UUID snapshotID;
  996. //
  997. // if (UUID.TryParse((string)row["AuthBuyerID"], out authedbuyer))
  998. // newData.AuthBuyerID = authedbuyer;
  999. //
  1000. // if (UUID.TryParse((string)row["SnapshotUUID"], out snapshotID))
  1001. // newData.SnapshotID = snapshotID;
  1002. newData.AuthBuyerID = new UUID((Guid)row["AuthBuyerID"]);
  1003. newData.SnapshotID = new UUID((Guid)row["SnapshotUUID"]);
  1004. newData.OtherCleanTime = Convert.ToInt32(row["OtherCleanTime"]);
  1005. newData.Dwell = Convert.ToSingle(row["Dwell"]);
  1006. try
  1007. {
  1008. newData.UserLocation =
  1009. new Vector3(Convert.ToSingle(row["UserLocationX"]), Convert.ToSingle(row["UserLocationY"]),
  1010. Convert.ToSingle(row["UserLocationZ"]));
  1011. newData.UserLookAt =
  1012. new Vector3(Convert.ToSingle(row["UserLookAtX"]), Convert.ToSingle(row["UserLookAtY"]),
  1013. Convert.ToSingle(row["UserLookAtZ"]));
  1014. }
  1015. catch (InvalidCastException)
  1016. {
  1017. newData.UserLocation = Vector3.Zero;
  1018. newData.UserLookAt = Vector3.Zero;
  1019. _Log.ErrorFormat("[PARCEL]: unable to get parcel telehub settings for {1}", newData.Name);
  1020. }
  1021. newData.ParcelAccessList = new List<LandAccessEntry>();
  1022. newData.MediaDescription = (string)row["MediaDescription"];
  1023. newData.MediaType = (string)row["MediaType"];
  1024. newData.MediaWidth = Convert.ToInt32((((string)row["MediaSize"]).Split(','))[0]);
  1025. newData.MediaHeight = Convert.ToInt32((((string)row["MediaSize"]).Split(','))[1]);
  1026. newData.MediaLoop = Convert.ToBoolean(row["MediaLoop"]);
  1027. newData.ObscureMusic = Convert.ToBoolean(row["ObscureMusic"]);
  1028. newData.ObscureMedia = Convert.ToBoolean(row["ObscureMedia"]);
  1029. newData.SeeAVs = Convert.ToBoolean(row["SeeAVs"]);
  1030. newData.AnyAVSounds = Convert.ToBoolean(row["AnyAVSounds"]);
  1031. newData.GroupAVSounds = Convert.ToBoolean(row["GroupAVSounds"]);
  1032. if (row["environment"] is DBNull)
  1033. {
  1034. newData.Environment = null;
  1035. newData.EnvironmentVersion = -1;
  1036. }
  1037. else
  1038. {
  1039. string env = (string)row["environment"];
  1040. if (string.IsNullOrEmpty(env))
  1041. {
  1042. newData.Environment = null;
  1043. newData.EnvironmentVersion = -1;
  1044. }
  1045. else
  1046. {
  1047. try
  1048. {
  1049. ViewerEnvironment VEnv = ViewerEnvironment.FromOSDString(env);
  1050. newData.Environment = VEnv;
  1051. newData.EnvironmentVersion = VEnv.version;
  1052. }
  1053. catch
  1054. {
  1055. newData.Environment = null;
  1056. newData.EnvironmentVersion = -1;
  1057. }
  1058. }
  1059. }
  1060. return newData;
  1061. }
  1062. /// <summary>
  1063. /// Builds the landaccess data from a data record.
  1064. /// </summary>
  1065. /// <param name="row">datarecord with landaccess data</param>
  1066. /// <returns></returns>
  1067. private static LandAccessEntry BuildLandAccessData(IDataRecord row)
  1068. {
  1069. LandAccessEntry entry = new LandAccessEntry();
  1070. entry.AgentID = new UUID((Guid)row["AccessUUID"]);
  1071. entry.Flags = (AccessList)Convert.ToInt32(row["Flags"]);
  1072. entry.Expires = Convert.ToInt32(row["Expires"]);
  1073. return entry;
  1074. }
  1075. /// <summary>
  1076. /// Builds the prim from a datarecord.
  1077. /// </summary>
  1078. /// <param name="primRow">datarecord</param>
  1079. /// <returns></returns>
  1080. private static SceneObjectPart BuildPrim(IDataRecord primRow)
  1081. {
  1082. SceneObjectPart prim = new SceneObjectPart();
  1083. prim.UUID = new UUID((Guid)primRow["UUID"]);
  1084. // explicit conversion of integers is required, which sort
  1085. // of sucks. No idea if there is a shortcut here or not.
  1086. prim.CreationDate = Convert.ToInt32(primRow["CreationDate"]);
  1087. prim.Name = (string)primRow["Name"];
  1088. // various text fields
  1089. prim.Text = (string)primRow["Text"];
  1090. prim.Color = Color.FromArgb(Convert.ToInt32(primRow["ColorA"]),
  1091. Convert.ToInt32(primRow["ColorR"]),
  1092. Convert.ToInt32(primRow["ColorG"]),
  1093. Convert.ToInt32(primRow["ColorB"]));
  1094. prim.Description = (string)primRow["Description"];
  1095. prim.SitName = (string)primRow["SitName"];
  1096. prim.TouchName = (string)primRow["TouchName"];
  1097. // permissions
  1098. prim.Flags = (PrimFlags)Convert.ToUInt32(primRow["ObjectFlags"]);
  1099. //prim.creatorID = new UUID((Guid)primRow["creatorID"]);
  1100. prim.CreatorIdentification = (string)primRow["CreatorID"].ToString();
  1101. prim.OwnerID = new UUID((Guid)primRow["OwnerID"]);
  1102. prim.GroupID = new UUID((Guid)primRow["GroupID"]);
  1103. prim.LastOwnerID = new UUID((Guid)primRow["LastOwnerID"]);
  1104. if (primRow["RezzerID"] != DBNull.Value)
  1105. prim.RezzerID = new UUID((Guid)primRow["RezzerID"]);
  1106. else
  1107. prim.RezzerID = UUID.Zero;
  1108. prim.OwnerMask = Convert.ToUInt32(primRow["OwnerMask"]);
  1109. prim.NextOwnerMask = Convert.ToUInt32(primRow["NextOwnerMask"]);
  1110. prim.GroupMask = Convert.ToUInt32(primRow["GroupMask"]);
  1111. prim.EveryoneMask = Convert.ToUInt32(primRow["EveryoneMask"]);
  1112. prim.BaseMask = Convert.ToUInt32(primRow["BaseMask"]);
  1113. // vectors
  1114. prim.OffsetPosition = new Vector3(
  1115. Convert.ToSingle(primRow["PositionX"]),
  1116. Convert.ToSingle(primRow["PositionY"]),
  1117. Convert.ToSingle(primRow["PositionZ"]));
  1118. prim.GroupPosition = new Vector3(
  1119. Convert.ToSingle(primRow["GroupPositionX"]),
  1120. Convert.ToSingle(primRow["GroupPositionY"]),
  1121. Convert.ToSingle(primRow["GroupPositionZ"]));
  1122. prim.Velocity = new Vector3(
  1123. Convert.ToSingle(primRow["VelocityX"]),
  1124. Convert.ToSingle(primRow["VelocityY"]),
  1125. Convert.ToSingle(primRow["VelocityZ"]));
  1126. prim.AngularVelocity = new Vector3(
  1127. Convert.ToSingle(primRow["AngularVelocityX"]),
  1128. Convert.ToSingle(primRow["AngularVelocityY"]),
  1129. Convert.ToSingle(primRow["AngularVelocityZ"]));
  1130. prim.Acceleration = new Vector3(
  1131. Convert.ToSingle(primRow["AccelerationX"]),
  1132. Convert.ToSingle(primRow["AccelerationY"]),
  1133. Convert.ToSingle(primRow["AccelerationZ"]));
  1134. // quaternions
  1135. prim.RotationOffset = new Quaternion(
  1136. Convert.ToSingle(primRow["RotationX"]),
  1137. Convert.ToSingle(primRow["RotationY"]),
  1138. Convert.ToSingle(primRow["RotationZ"]),
  1139. Convert.ToSingle(primRow["RotationW"]));
  1140. prim.SitTargetPositionLL = new Vector3(
  1141. Convert.ToSingle(primRow["SitTargetOffsetX"]),
  1142. Convert.ToSingle(primRow["SitTargetOffsetY"]),
  1143. Convert.ToSingle(primRow["SitTargetOffsetZ"]));
  1144. prim.SitTargetOrientationLL = new Quaternion(
  1145. Convert.ToSingle(primRow["SitTargetOrientX"]),
  1146. Convert.ToSingle(primRow["SitTargetOrientY"]),
  1147. Convert.ToSingle(primRow["SitTargetOrientZ"]),
  1148. Convert.ToSingle(primRow["SitTargetOrientW"]));
  1149. prim.StandOffset = new Vector3(
  1150. Convert.ToSingle(primRow["standtargetx"]),
  1151. Convert.ToSingle(primRow["standtargety"]),
  1152. Convert.ToSingle(primRow["standtargetz"]));
  1153. prim.SitActiveRange = Convert.ToSingle(primRow["sitactrange"]);
  1154. prim.PayPrice[0] = Convert.ToInt32(primRow["PayPrice"]);
  1155. prim.PayPrice[1] = Convert.ToInt32(primRow["PayButton1"]);
  1156. prim.PayPrice[2] = Convert.ToInt32(primRow["PayButton2"]);
  1157. prim.PayPrice[3] = Convert.ToInt32(primRow["PayButton3"]);
  1158. prim.PayPrice[4] = Convert.ToInt32(primRow["PayButton4"]);
  1159. prim.Sound = new UUID((Guid)primRow["LoopedSound"]);
  1160. prim.SoundGain = Convert.ToSingle(primRow["LoopedSoundGain"]);
  1161. if (prim.Sound != UUID.Zero)
  1162. prim.SoundFlags = 1; // If it's persisted at all, it's looped
  1163. else
  1164. prim.SoundFlags = 0;
  1165. if (!(primRow["TextureAnimation"] is DBNull))
  1166. prim.TextureAnimation = (Byte[])primRow["TextureAnimation"];
  1167. if (!(primRow["ParticleSystem"] is DBNull))
  1168. prim.ParticleSystem = (Byte[])primRow["ParticleSystem"];
  1169. prim.SetCameraEyeOffset(new Vector3(
  1170. Convert.ToSingle(primRow["CameraEyeOffsetX"]),
  1171. Convert.ToSingle(primRow["CameraEyeOffsetY"]),
  1172. Convert.ToSingle(primRow["CameraEyeOffsetZ"])
  1173. ));
  1174. prim.SetCameraAtOffset(new Vector3(
  1175. Convert.ToSingle(primRow["CameraAtOffsetX"]),
  1176. Convert.ToSingle(primRow["CameraAtOffsetY"]),
  1177. Convert.ToSingle(primRow["CameraAtOffsetZ"])
  1178. ));
  1179. if (Convert.ToInt16(primRow["ForceMouselook"]) != 0)
  1180. prim.SetForceMouselook(true);
  1181. prim.ScriptAccessPin = Convert.ToInt32(primRow["ScriptAccessPin"]);
  1182. if (Convert.ToInt16(primRow["AllowedDrop"]) != 0)
  1183. prim.AllowedDrop = true;
  1184. if (Convert.ToInt16(primRow["DieAtEdge"]) != 0)
  1185. prim.DIE_AT_EDGE = true;
  1186. prim.SalePrice = Convert.ToInt32(primRow["SalePrice"]);
  1187. prim.ObjectSaleType = Convert.ToByte(primRow["SaleType"]);
  1188. prim.Material = Convert.ToByte(primRow["Material"]);
  1189. if (!(primRow["ClickAction"] is DBNull))
  1190. prim.ClickAction = Convert.ToByte(primRow["ClickAction"]);
  1191. prim.CollisionSound = new UUID((Guid)primRow["CollisionSound"]);
  1192. prim.CollisionSoundVolume = Convert.ToSingle(primRow["CollisionSoundVolume"]);
  1193. prim.PassTouches = (bool)primRow["PassTouches"];
  1194. prim.PassCollisions = (bool)primRow["PassCollisions"];
  1195. if (!(primRow["MediaURL"] is System.DBNull))
  1196. prim.MediaUrl = (string)primRow["MediaURL"];
  1197. if (!(primRow["DynAttrs"] is System.DBNull) && (string)primRow["DynAttrs"] != "")
  1198. prim.DynAttrs = DAMap.FromXml((string)primRow["DynAttrs"]);
  1199. else
  1200. prim.DynAttrs = null;
  1201. prim.PhysicsShapeType = Convert.ToByte(primRow["PhysicsShapeType"]);
  1202. prim.Density = Convert.ToSingle(primRow["Density"]);
  1203. prim.GravityModifier = Convert.ToSingle(primRow["GravityModifier"]);
  1204. prim.Friction = Convert.ToSingle(primRow["Friction"]);
  1205. prim.Restitution = Convert.ToSingle(primRow["Restitution"]);
  1206. prim.RotationAxisLocks = Convert.ToByte(primRow["RotationAxisLocks"]);
  1207. SOPVehicle vehicle = null;
  1208. if (!(primRow["Vehicle"] is System.DBNull))
  1209. {
  1210. vehicle = SOPVehicle.FromXml2(primRow["Vehicle"].ToString());
  1211. if (vehicle != null)
  1212. prim.VehicleParams = vehicle;
  1213. }
  1214. PhysicsInertiaData pdata = null;
  1215. if (!(primRow["PhysInertia"] is System.DBNull))
  1216. pdata = PhysicsInertiaData.FromXml2(primRow["PhysInertia"].ToString());
  1217. prim.PhysicsInertia = pdata;
  1218. int pseudocrc = Convert.ToInt32(primRow["pseudocrc"]);
  1219. if(pseudocrc != 0)
  1220. prim.PseudoCRC = pseudocrc;
  1221. return prim;
  1222. }
  1223. /// <summary>
  1224. /// Builds the prim shape from a datarecord.
  1225. /// </summary>
  1226. /// <param name="shapeRow">The row.</param>
  1227. /// <returns></returns>
  1228. private static PrimitiveBaseShape BuildShape(IDataRecord shapeRow)
  1229. {
  1230. PrimitiveBaseShape baseShape = new PrimitiveBaseShape();
  1231. baseShape.Scale = new Vector3(
  1232. (float)Convert.ToDouble(shapeRow["ScaleX"]),
  1233. (float)Convert.ToDouble(shapeRow["ScaleY"]),
  1234. (float)Convert.ToDouble(shapeRow["ScaleZ"]));
  1235. // paths
  1236. baseShape.PCode = Convert.ToByte(shapeRow["PCode"]);
  1237. baseShape.PathBegin = Convert.ToUInt16(shapeRow["PathBegin"]);
  1238. baseShape.PathEnd = Convert.ToUInt16(shapeRow["PathEnd"]);
  1239. baseShape.PathScaleX = Convert.ToByte(shapeRow["PathScaleX"]);
  1240. baseShape.PathScaleY = Convert.ToByte(shapeRow["PathScaleY"]);
  1241. baseShape.PathShearX = Convert.ToByte(shapeRow["PathShearX"]);
  1242. baseShape.PathShearY = Convert.ToByte(shapeRow["PathShearY"]);
  1243. baseShape.PathSkew = Convert.ToSByte(shapeRow["PathSkew"]);
  1244. baseShape.PathCurve = Convert.ToByte(shapeRow["PathCurve"]);
  1245. baseShape.PathRadiusOffset = Convert.ToSByte(shapeRow["PathRadiusOffset"]);
  1246. baseShape.PathRevolutions = Convert.ToByte(shapeRow["PathRevolutions"]);
  1247. baseShape.PathTaperX = Convert.ToSByte(shapeRow["PathTaperX"]);
  1248. baseShape.PathTaperY = Convert.ToSByte(shapeRow["PathTaperY"]);
  1249. baseShape.PathTwist = Convert.ToSByte(shapeRow["PathTwist"]);
  1250. baseShape.PathTwistBegin = Convert.ToSByte(shapeRow["PathTwistBegin"]);
  1251. // profile
  1252. baseShape.ProfileBegin = Convert.ToUInt16(shapeRow["ProfileBegin"]);
  1253. baseShape.ProfileEnd = Convert.ToUInt16(shapeRow["ProfileEnd"]);
  1254. baseShape.ProfileCurve = Convert.ToByte(shapeRow["ProfileCurve"]);
  1255. baseShape.ProfileHollow = Convert.ToUInt16(shapeRow["ProfileHollow"]);
  1256. byte[] textureEntry = (byte[])shapeRow["Texture"];
  1257. baseShape.TextureEntry = textureEntry;
  1258. baseShape.ExtraParams = (byte[])shapeRow["ExtraParams"];
  1259. try
  1260. {
  1261. baseShape.State = Convert.ToByte(shapeRow["State"]);
  1262. }
  1263. catch (InvalidCastException)
  1264. {
  1265. }
  1266. if (!(shapeRow["Media"] is System.DBNull))
  1267. {
  1268. baseShape.Media = PrimitiveBaseShape.MediaList.FromXml((string)shapeRow["Media"]);
  1269. }
  1270. return baseShape;
  1271. }
  1272. /// <summary>
  1273. /// Build a prim inventory item from the persisted data.
  1274. /// </summary>
  1275. /// <param name="inventoryRow"></param>
  1276. /// <returns></returns>
  1277. private static TaskInventoryItem BuildItem(IDataRecord inventoryRow)
  1278. {
  1279. TaskInventoryItem taskItem = new TaskInventoryItem();
  1280. taskItem.ItemID = new UUID((Guid)inventoryRow["itemID"]);
  1281. taskItem.ParentPartID = new UUID((Guid)inventoryRow["primID"]);
  1282. taskItem.AssetID = new UUID((Guid)inventoryRow["assetID"]);
  1283. taskItem.ParentID = new UUID((Guid)inventoryRow["parentFolderID"]);
  1284. taskItem.InvType = Convert.ToInt32(inventoryRow["invType"]);
  1285. taskItem.Type = Convert.ToInt32(inventoryRow["assetType"]);
  1286. taskItem.Name = (string)inventoryRow["name"];
  1287. taskItem.Description = (string)inventoryRow["description"];
  1288. taskItem.CreationDate = Convert.ToUInt32(inventoryRow["creationDate"]);
  1289. //taskItem.creatorID = new UUID((Guid)inventoryRow["creatorID"]);
  1290. taskItem.CreatorIdentification = (string)inventoryRow["creatorID"].ToString();
  1291. taskItem.OwnerID = new UUID((Guid)inventoryRow["ownerID"]);
  1292. taskItem.LastOwnerID = new UUID((Guid)inventoryRow["lastOwnerID"]);
  1293. taskItem.GroupID = new UUID((Guid)inventoryRow["groupID"]);
  1294. taskItem.NextPermissions = Convert.ToUInt32(inventoryRow["nextPermissions"]);
  1295. taskItem.CurrentPermissions = Convert.ToUInt32(inventoryRow["currentPermissions"]);
  1296. taskItem.BasePermissions = Convert.ToUInt32(inventoryRow["basePermissions"]);
  1297. taskItem.EveryonePermissions = Convert.ToUInt32(inventoryRow["everyonePermissions"]);
  1298. taskItem.GroupPermissions = Convert.ToUInt32(inventoryRow["groupPermissions"]);
  1299. taskItem.Flags = Convert.ToUInt32(inventoryRow["flags"]);
  1300. return taskItem;
  1301. }
  1302. #endregion
  1303. #region Create parameters methods
  1304. /// <summary>
  1305. /// Creates the prim inventory parameters.
  1306. /// </summary>
  1307. /// <param name="taskItem">item in inventory.</param>
  1308. /// <returns></returns>
  1309. private NpgsqlParameter[] CreatePrimInventoryParameters(TaskInventoryItem taskItem)
  1310. {
  1311. List<NpgsqlParameter> parameters = new List<NpgsqlParameter>();
  1312. parameters.Add(_Database.CreateParameter("itemID", taskItem.ItemID));
  1313. parameters.Add(_Database.CreateParameter("primID", taskItem.ParentPartID));
  1314. parameters.Add(_Database.CreateParameter("assetID", taskItem.AssetID));
  1315. parameters.Add(_Database.CreateParameter("parentFolderID", taskItem.ParentID));
  1316. parameters.Add(_Database.CreateParameter("invType", taskItem.InvType));
  1317. parameters.Add(_Database.CreateParameter("assetType", taskItem.Type));
  1318. parameters.Add(_Database.CreateParameter("name", taskItem.Name));
  1319. parameters.Add(_Database.CreateParameter("description", taskItem.Description));
  1320. parameters.Add(_Database.CreateParameter("creationDate", taskItem.CreationDate));
  1321. parameters.Add(_Database.CreateParameter("creatorID", taskItem.CreatorID));
  1322. parameters.Add(_Database.CreateParameter("ownerID", taskItem.OwnerID));
  1323. parameters.Add(_Database.CreateParameter("lastOwnerID", taskItem.LastOwnerID));
  1324. parameters.Add(_Database.CreateParameter("groupID", taskItem.GroupID));
  1325. parameters.Add(_Database.CreateParameter("nextPermissions", taskItem.NextPermissions));
  1326. parameters.Add(_Database.CreateParameter("currentPermissions", taskItem.CurrentPermissions));
  1327. parameters.Add(_Database.CreateParameter("basePermissions", taskItem.BasePermissions));
  1328. parameters.Add(_Database.CreateParameter("everyonePermissions", taskItem.EveryonePermissions));
  1329. parameters.Add(_Database.CreateParameter("groupPermissions", taskItem.GroupPermissions));
  1330. parameters.Add(_Database.CreateParameter("flags", taskItem.Flags));
  1331. return parameters.ToArray();
  1332. }
  1333. /// <summary>
  1334. /// Creates the region setting parameters.
  1335. /// </summary>
  1336. /// <param name="settings">regionsettings.</param>
  1337. /// <returns></returns>
  1338. private NpgsqlParameter[] CreateRegionSettingParameters(RegionSettings settings)
  1339. {
  1340. List<NpgsqlParameter> parameters = new List<NpgsqlParameter>();
  1341. parameters.Add(_Database.CreateParameter("regionUUID", settings.RegionUUID));
  1342. parameters.Add(_Database.CreateParameter("block_terraform", settings.BlockTerraform));
  1343. parameters.Add(_Database.CreateParameter("block_fly", settings.BlockFly));
  1344. parameters.Add(_Database.CreateParameter("allow_damage", settings.AllowDamage));
  1345. parameters.Add(_Database.CreateParameter("restrict_pushing", settings.RestrictPushing));
  1346. parameters.Add(_Database.CreateParameter("allow_land_resell", settings.AllowLandResell));
  1347. parameters.Add(_Database.CreateParameter("allow_land_join_divide", settings.AllowLandJoinDivide));
  1348. parameters.Add(_Database.CreateParameter("block_show_in_search", settings.BlockShowInSearch));
  1349. parameters.Add(_Database.CreateParameter("agent_limit", settings.AgentLimit));
  1350. parameters.Add(_Database.CreateParameter("object_bonus", settings.ObjectBonus));
  1351. parameters.Add(_Database.CreateParameter("maturity", settings.Maturity));
  1352. parameters.Add(_Database.CreateParameter("disable_scripts", settings.DisableScripts));
  1353. parameters.Add(_Database.CreateParameter("disable_collisions", settings.DisableCollisions));
  1354. parameters.Add(_Database.CreateParameter("disable_physics", settings.DisablePhysics));
  1355. parameters.Add(_Database.CreateParameter("terrain_texture_1", settings.TerrainTexture1));
  1356. parameters.Add(_Database.CreateParameter("terrain_texture_2", settings.TerrainTexture2));
  1357. parameters.Add(_Database.CreateParameter("terrain_texture_3", settings.TerrainTexture3));
  1358. parameters.Add(_Database.CreateParameter("terrain_texture_4", settings.TerrainTexture4));
  1359. parameters.Add(_Database.CreateParameter("elevation_1_nw", settings.Elevation1NW));
  1360. parameters.Add(_Database.CreateParameter("elevation_2_nw", settings.Elevation2NW));
  1361. parameters.Add(_Database.CreateParameter("elevation_1_ne", settings.Elevation1NE));
  1362. parameters.Add(_Database.CreateParameter("elevation_2_ne", settings.Elevation2NE));
  1363. parameters.Add(_Database.CreateParameter("elevation_1_se", settings.Elevation1SE));
  1364. parameters.Add(_Database.CreateParameter("elevation_2_se", settings.Elevation2SE));
  1365. parameters.Add(_Database.CreateParameter("elevation_1_sw", settings.Elevation1SW));
  1366. parameters.Add(_Database.CreateParameter("elevation_2_sw", settings.Elevation2SW));
  1367. parameters.Add(_Database.CreateParameter("water_height", settings.WaterHeight));
  1368. parameters.Add(_Database.CreateParameter("terrain_raise_limit", settings.TerrainRaiseLimit));
  1369. parameters.Add(_Database.CreateParameter("terrain_lower_limit", settings.TerrainLowerLimit));
  1370. parameters.Add(_Database.CreateParameter("use_estate_sun", settings.UseEstateSun));
  1371. parameters.Add(_Database.CreateParameter("Sandbox", settings.Sandbox));
  1372. parameters.Add(_Database.CreateParameter("fixed_sun", settings.FixedSun));
  1373. parameters.Add(_Database.CreateParameter("sun_position", settings.SunPosition));
  1374. parameters.Add(_Database.CreateParameter("sunvectorx", settings.SunVector.X));
  1375. parameters.Add(_Database.CreateParameter("sunvectory", settings.SunVector.Y));
  1376. parameters.Add(_Database.CreateParameter("sunvectorz", settings.SunVector.Z));
  1377. parameters.Add(_Database.CreateParameter("covenant", settings.Covenant));
  1378. parameters.Add(_Database.CreateParameter("covenant_datetime", settings.CovenantChangedDateTime));
  1379. parameters.Add(_Database.CreateParameter("Loaded_Creation_DateTime", settings.LoadedCreationDateTime));
  1380. parameters.Add(_Database.CreateParameter("Loaded_Creation_ID", settings.LoadedCreationID));
  1381. parameters.Add(_Database.CreateParameter("TerrainImageID", settings.TerrainImageID));
  1382. parameters.Add(_Database.CreateParameter("ParcelImageID", settings.ParcelImageID));
  1383. parameters.Add(_Database.CreateParameter("TelehubObject", settings.TelehubObject));
  1384. parameters.Add(_Database.CreateParameter("cacheID", settings.CacheID));
  1385. return parameters.ToArray();
  1386. }
  1387. /// <summary>
  1388. /// Creates the land parameters.
  1389. /// </summary>
  1390. /// <param name="land">land parameters.</param>
  1391. /// <param name="regionUUID">region UUID.</param>
  1392. /// <returns></returns>
  1393. private NpgsqlParameter[] CreateLandParameters(LandData land, UUID regionUUID)
  1394. {
  1395. List<NpgsqlParameter> parameters = new List<NpgsqlParameter>();
  1396. parameters.Add(_Database.CreateParameter("UUID", land.GlobalID));
  1397. parameters.Add(_Database.CreateParameter("RegionUUID", regionUUID));
  1398. parameters.Add(_Database.CreateParameter("LocalLandID", land.LocalID));
  1399. // Bitmap is a byte[512]
  1400. parameters.Add(_Database.CreateParameter("Bitmap", land.Bitmap));
  1401. parameters.Add(_Database.CreateParameter("Name", land.Name));
  1402. parameters.Add(_Database.CreateParameter("Description", land.Description));
  1403. parameters.Add(_Database.CreateParameter("OwnerUUID", land.OwnerID));
  1404. parameters.Add(_Database.CreateParameter("IsGroupOwned", land.IsGroupOwned));
  1405. parameters.Add(_Database.CreateParameter("Area", land.Area));
  1406. parameters.Add(_Database.CreateParameter("AuctionID", land.AuctionID)); //Unemplemented
  1407. parameters.Add(_Database.CreateParameter("Category", (int)land.Category)); //Enum libsecondlife.Parcel.ParcelCategory
  1408. parameters.Add(_Database.CreateParameter("ClaimDate", land.ClaimDate));
  1409. parameters.Add(_Database.CreateParameter("ClaimPrice", land.ClaimPrice));
  1410. parameters.Add(_Database.CreateParameter("GroupUUID", land.GroupID));
  1411. parameters.Add(_Database.CreateParameter("SalePrice", land.SalePrice));
  1412. parameters.Add(_Database.CreateParameter("LandStatus", (int)land.Status)); //Enum. libsecondlife.Parcel.ParcelStatus
  1413. parameters.Add(_Database.CreateParameter("LandFlags", land.Flags));
  1414. parameters.Add(_Database.CreateParameter("LandingType", Convert.ToInt32( land.LandingType) ));
  1415. parameters.Add(_Database.CreateParameter("MediaAutoScale", Convert.ToInt32( land.MediaAutoScale )));
  1416. parameters.Add(_Database.CreateParameter("MediaTextureUUID", land.MediaID));
  1417. parameters.Add(_Database.CreateParameter("MediaURL", land.MediaURL));
  1418. parameters.Add(_Database.CreateParameter("MusicURL", land.MusicURL));
  1419. parameters.Add(_Database.CreateParameter("PassHours", land.PassHours));
  1420. parameters.Add(_Database.CreateParameter("PassPrice", land.PassPrice));
  1421. parameters.Add(_Database.CreateParameter("SnapshotUUID", land.SnapshotID));
  1422. parameters.Add(_Database.CreateParameter("UserLocationX", land.UserLocation.X));
  1423. parameters.Add(_Database.CreateParameter("UserLocationY", land.UserLocation.Y));
  1424. parameters.Add(_Database.CreateParameter("UserLocationZ", land.UserLocation.Z));
  1425. parameters.Add(_Database.CreateParameter("UserLookAtX", land.UserLookAt.X));
  1426. parameters.Add(_Database.CreateParameter("UserLookAtY", land.UserLookAt.Y));
  1427. parameters.Add(_Database.CreateParameter("UserLookAtZ", land.UserLookAt.Z));
  1428. parameters.Add(_Database.CreateParameter("AuthBuyerID", land.AuthBuyerID));
  1429. parameters.Add(_Database.CreateParameter("OtherCleanTime", land.OtherCleanTime));
  1430. parameters.Add(_Database.CreateParameter("Dwell", land.Dwell));
  1431. parameters.Add(_Database.CreateParameter("MediaDescription", land.MediaDescription));
  1432. parameters.Add(_Database.CreateParameter("MediaType", land.MediaType));
  1433. parameters.Add(_Database.CreateParameter("MediaWidth", land.MediaWidth));
  1434. parameters.Add(_Database.CreateParameter("MediaHeight", land.MediaHeight));
  1435. parameters.Add(_Database.CreateParameter("MediaLoop", land.MediaLoop));
  1436. parameters.Add(_Database.CreateParameter("ObscureMusic", land.ObscureMusic));
  1437. parameters.Add(_Database.CreateParameter("ObscureMedia", land.ObscureMedia));
  1438. parameters.Add(_Database.CreateParameter("SeeAVs", land.SeeAVs));
  1439. parameters.Add(_Database.CreateParameter("AnyAVSounds", land.AnyAVSounds));
  1440. parameters.Add(_Database.CreateParameter("GroupAVSounds", land.GroupAVSounds));
  1441. if (land.Environment == null)
  1442. parameters.Add(_Database.CreateParameter("environment", ""));
  1443. else
  1444. {
  1445. try
  1446. {
  1447. parameters.Add(_Database.CreateParameter("environment", ViewerEnvironment.ToOSDString(land.Environment)));
  1448. }
  1449. catch
  1450. {
  1451. parameters.Add(_Database.CreateParameter("environment", ""));
  1452. }
  1453. }
  1454. return parameters.ToArray();
  1455. }
  1456. /// <summary>
  1457. /// Creates the land access parameters.
  1458. /// </summary>
  1459. /// <param name="parcelAccessEntry">parcel access entry.</param>
  1460. /// <param name="parcelID">parcel ID.</param>
  1461. /// <returns></returns>
  1462. private NpgsqlParameter[] CreateLandAccessParameters(LandAccessEntry parcelAccessEntry, UUID parcelID)
  1463. {
  1464. List<NpgsqlParameter> parameters = new List<NpgsqlParameter>();
  1465. parameters.Add(_Database.CreateParameter("LandUUID", parcelID));
  1466. parameters.Add(_Database.CreateParameter("AccessUUID", parcelAccessEntry.AgentID));
  1467. parameters.Add(_Database.CreateParameter("Flags", parcelAccessEntry.Flags));
  1468. parameters.Add(_Database.CreateParameter("Expires", parcelAccessEntry.Expires));
  1469. return parameters.ToArray();
  1470. }
  1471. /// <summary>
  1472. /// Creates the prim parameters for storing in DB.
  1473. /// </summary>
  1474. /// <param name="prim">Basic data of SceneObjectpart prim.</param>
  1475. /// <param name="sceneGroupID">The scenegroup ID.</param>
  1476. /// <param name="regionUUID">The region ID.</param>
  1477. /// <returns></returns>
  1478. private NpgsqlParameter[] CreatePrimParameters(SceneObjectPart prim, UUID sceneGroupID, UUID regionUUID)
  1479. {
  1480. List<NpgsqlParameter> parameters = new List<NpgsqlParameter>();
  1481. parameters.Add(_Database.CreateParameter("UUID", prim.UUID));
  1482. parameters.Add(_Database.CreateParameter("RegionUUID", regionUUID));
  1483. parameters.Add(_Database.CreateParameter("CreationDate", prim.CreationDate));
  1484. parameters.Add(_Database.CreateParameter("Name", prim.Name));
  1485. parameters.Add(_Database.CreateParameter("SceneGroupID", sceneGroupID));
  1486. // the UUID of the root part for this SceneObjectGroup
  1487. // various text fields
  1488. parameters.Add(_Database.CreateParameter("Text", prim.Text));
  1489. parameters.Add(_Database.CreateParameter("ColorR", prim.Color.R));
  1490. parameters.Add(_Database.CreateParameter("ColorG", prim.Color.G));
  1491. parameters.Add(_Database.CreateParameter("ColorB", prim.Color.B));
  1492. parameters.Add(_Database.CreateParameter("ColorA", prim.Color.A));
  1493. parameters.Add(_Database.CreateParameter("Description", prim.Description));
  1494. parameters.Add(_Database.CreateParameter("SitName", prim.SitName));
  1495. parameters.Add(_Database.CreateParameter("TouchName", prim.TouchName));
  1496. // permissions
  1497. parameters.Add(_Database.CreateParameter("ObjectFlags", (uint)prim.Flags));
  1498. parameters.Add(_Database.CreateParameter("CreatorID", prim.CreatorID));
  1499. parameters.Add(_Database.CreateParameter("OwnerID", prim.OwnerID));
  1500. parameters.Add(_Database.CreateParameter("GroupID", prim.GroupID));
  1501. parameters.Add(_Database.CreateParameter("LastOwnerID", prim.LastOwnerID));
  1502. parameters.Add(_Database.CreateParameter("RezzerID", prim.RezzerID));
  1503. parameters.Add(_Database.CreateParameter("OwnerMask", prim.OwnerMask));
  1504. parameters.Add(_Database.CreateParameter("NextOwnerMask", prim.NextOwnerMask));
  1505. parameters.Add(_Database.CreateParameter("GroupMask", prim.GroupMask));
  1506. parameters.Add(_Database.CreateParameter("EveryoneMask", prim.EveryoneMask));
  1507. parameters.Add(_Database.CreateParameter("BaseMask", prim.BaseMask));
  1508. // vectors
  1509. parameters.Add(_Database.CreateParameter("PositionX", prim.OffsetPosition.X));
  1510. parameters.Add(_Database.CreateParameter("PositionY", prim.OffsetPosition.Y));
  1511. parameters.Add(_Database.CreateParameter("PositionZ", prim.OffsetPosition.Z));
  1512. parameters.Add(_Database.CreateParameter("GroupPositionX", prim.GroupPosition.X));
  1513. parameters.Add(_Database.CreateParameter("GroupPositionY", prim.GroupPosition.Y));
  1514. parameters.Add(_Database.CreateParameter("GroupPositionZ", prim.GroupPosition.Z));
  1515. parameters.Add(_Database.CreateParameter("VelocityX", prim.Velocity.X));
  1516. parameters.Add(_Database.CreateParameter("VelocityY", prim.Velocity.Y));
  1517. parameters.Add(_Database.CreateParameter("VelocityZ", prim.Velocity.Z));
  1518. parameters.Add(_Database.CreateParameter("AngularVelocityX", prim.AngularVelocity.X));
  1519. parameters.Add(_Database.CreateParameter("AngularVelocityY", prim.AngularVelocity.Y));
  1520. parameters.Add(_Database.CreateParameter("AngularVelocityZ", prim.AngularVelocity.Z));
  1521. parameters.Add(_Database.CreateParameter("AccelerationX", prim.Acceleration.X));
  1522. parameters.Add(_Database.CreateParameter("AccelerationY", prim.Acceleration.Y));
  1523. parameters.Add(_Database.CreateParameter("AccelerationZ", prim.Acceleration.Z));
  1524. // quaternions
  1525. parameters.Add(_Database.CreateParameter("RotationX", prim.RotationOffset.X));
  1526. parameters.Add(_Database.CreateParameter("RotationY", prim.RotationOffset.Y));
  1527. parameters.Add(_Database.CreateParameter("RotationZ", prim.RotationOffset.Z));
  1528. parameters.Add(_Database.CreateParameter("RotationW", prim.RotationOffset.W));
  1529. // Sit target
  1530. Vector3 sitTargetPos = prim.SitTargetPositionLL;
  1531. parameters.Add(_Database.CreateParameter("SitTargetOffsetX", sitTargetPos.X));
  1532. parameters.Add(_Database.CreateParameter("SitTargetOffsetY", sitTargetPos.Y));
  1533. parameters.Add(_Database.CreateParameter("SitTargetOffsetZ", sitTargetPos.Z));
  1534. Quaternion sitTargetOrient = prim.SitTargetOrientationLL;
  1535. parameters.Add(_Database.CreateParameter("SitTargetOrientW", sitTargetOrient.W));
  1536. parameters.Add(_Database.CreateParameter("SitTargetOrientX", sitTargetOrient.X));
  1537. parameters.Add(_Database.CreateParameter("SitTargetOrientY", sitTargetOrient.Y));
  1538. parameters.Add(_Database.CreateParameter("SitTargetOrientZ", sitTargetOrient.Z));
  1539. Vector3 standTargetPos = prim.StandOffset;
  1540. parameters.Add(_Database.CreateParameter("standtargetx", standTargetPos.X));
  1541. parameters.Add(_Database.CreateParameter("standtargety", standTargetPos.Y));
  1542. parameters.Add(_Database.CreateParameter("standtargetz", standTargetPos.Z));
  1543. parameters.Add(_Database.CreateParameter("sitactrange", prim.SitActiveRange));
  1544. parameters.Add(_Database.CreateParameter("PayPrice", prim.PayPrice[0]));
  1545. parameters.Add(_Database.CreateParameter("PayButton1", prim.PayPrice[1]));
  1546. parameters.Add(_Database.CreateParameter("PayButton2", prim.PayPrice[2]));
  1547. parameters.Add(_Database.CreateParameter("PayButton3", prim.PayPrice[3]));
  1548. parameters.Add(_Database.CreateParameter("PayButton4", prim.PayPrice[4]));
  1549. if ((prim.SoundFlags & 1) != 0) // Looped
  1550. {
  1551. parameters.Add(_Database.CreateParameter("LoopedSound", prim.Sound));
  1552. parameters.Add(_Database.CreateParameter("LoopedSoundGain", prim.SoundGain));
  1553. }
  1554. else
  1555. {
  1556. parameters.Add(_Database.CreateParameter("LoopedSound", UUID.Zero));
  1557. parameters.Add(_Database.CreateParameter("LoopedSoundGain", 0.0f));
  1558. }
  1559. parameters.Add(_Database.CreateParameter("TextureAnimation", prim.TextureAnimation));
  1560. parameters.Add(_Database.CreateParameter("ParticleSystem", prim.ParticleSystem));
  1561. parameters.Add(_Database.CreateParameter("CameraEyeOffsetX", prim.GetCameraEyeOffset().X));
  1562. parameters.Add(_Database.CreateParameter("CameraEyeOffsetY", prim.GetCameraEyeOffset().Y));
  1563. parameters.Add(_Database.CreateParameter("CameraEyeOffsetZ", prim.GetCameraEyeOffset().Z));
  1564. parameters.Add(_Database.CreateParameter("CameraAtOffsetX", prim.GetCameraAtOffset().X));
  1565. parameters.Add(_Database.CreateParameter("CameraAtOffsetY", prim.GetCameraAtOffset().Y));
  1566. parameters.Add(_Database.CreateParameter("CameraAtOffsetZ", prim.GetCameraAtOffset().Z));
  1567. if (prim.GetForceMouselook())
  1568. parameters.Add(_Database.CreateParameter("ForceMouselook", 1));
  1569. else
  1570. parameters.Add(_Database.CreateParameter("ForceMouselook", 0));
  1571. parameters.Add(_Database.CreateParameter("ScriptAccessPin", prim.ScriptAccessPin));
  1572. if (prim.AllowedDrop)
  1573. parameters.Add(_Database.CreateParameter("AllowedDrop", 1));
  1574. else
  1575. parameters.Add(_Database.CreateParameter("AllowedDrop", 0));
  1576. if (prim.DIE_AT_EDGE)
  1577. parameters.Add(_Database.CreateParameter("DieAtEdge", 1));
  1578. else
  1579. parameters.Add(_Database.CreateParameter("DieAtEdge", 0));
  1580. parameters.Add(_Database.CreateParameter("SalePrice", prim.SalePrice));
  1581. parameters.Add(_Database.CreateParameter("SaleType", prim.ObjectSaleType));
  1582. byte clickAction = prim.ClickAction;
  1583. parameters.Add(_Database.CreateParameter("ClickAction", clickAction));
  1584. parameters.Add(_Database.CreateParameter("Material", prim.Material));
  1585. parameters.Add(_Database.CreateParameter("CollisionSound", prim.CollisionSound));
  1586. parameters.Add(_Database.CreateParameter("CollisionSoundVolume", prim.CollisionSoundVolume));
  1587. parameters.Add(_Database.CreateParameter("PassTouches", (bool)prim.PassTouches));
  1588. parameters.Add(_Database.CreateParameter("PassCollisions", (bool)prim.PassCollisions));
  1589. if (prim.PassTouches)
  1590. parameters.Add(_Database.CreateParameter("PassTouches", true));
  1591. else
  1592. parameters.Add(_Database.CreateParameter("PassTouches", false));
  1593. if (prim.PassCollisions)
  1594. parameters.Add(_Database.CreateParameter("PassCollisions", true));
  1595. else
  1596. parameters.Add(_Database.CreateParameter("PassCollisions", false));
  1597. parameters.Add(_Database.CreateParameter("LinkNumber", prim.LinkNum));
  1598. parameters.Add(_Database.CreateParameter("MediaURL", prim.MediaUrl));
  1599. if (prim.VehicleParams != null)
  1600. parameters.Add(_Database.CreateParameter("Vehicle", prim.VehicleParams.ToXml2()));
  1601. else
  1602. parameters.Add(_Database.CreateParameter("Vehicle", string.Empty));
  1603. if (prim.PhysicsInertia != null)
  1604. parameters.Add(_Database.CreateParameter("PhysInertia", prim.PhysicsInertia.ToXml2()));
  1605. else
  1606. parameters.Add(_Database.CreateParameter("PhysInertia", string.Empty));
  1607. if (prim.DynAttrs != null && prim.DynAttrs.CountNamespaces > 0)
  1608. parameters.Add(_Database.CreateParameter("DynAttrs", prim.DynAttrs.ToXml()));
  1609. else
  1610. parameters.Add(_Database.CreateParameter("DynAttrs", null));
  1611. parameters.Add(_Database.CreateParameter("PhysicsShapeType", prim.PhysicsShapeType));
  1612. parameters.Add(_Database.CreateParameter("Density", (double)prim.Density));
  1613. parameters.Add(_Database.CreateParameter("GravityModifier", (double)prim.GravityModifier));
  1614. parameters.Add(_Database.CreateParameter("Friction", (double)prim.Friction));
  1615. parameters.Add(_Database.CreateParameter("Restitution", (double)prim.Restitution));
  1616. parameters.Add(_Database.CreateParameter("RotationAxisLocks", prim.RotationAxisLocks));
  1617. parameters.Add(_Database.CreateParameter("pseudocrc", prim.PseudoCRC));
  1618. return parameters.ToArray();
  1619. }
  1620. /// <summary>
  1621. /// Creates the primshape parameters for storing in DB.
  1622. /// </summary>
  1623. /// <param name="prim">Basic data of SceneObjectpart prim.</param>
  1624. /// <param name="sceneGroupID">The scene group ID.</param>
  1625. /// <param name="regionUUID">The region UUID.</param>
  1626. /// <returns></returns>
  1627. private NpgsqlParameter[] CreatePrimShapeParameters(SceneObjectPart prim, UUID sceneGroupID, UUID regionUUID)
  1628. {
  1629. List<NpgsqlParameter> parameters = new List<NpgsqlParameter>();
  1630. PrimitiveBaseShape s = prim.Shape;
  1631. parameters.Add(_Database.CreateParameter("UUID", prim.UUID));
  1632. // shape is an enum
  1633. parameters.Add(_Database.CreateParameter("Shape", 0));
  1634. // vectors
  1635. parameters.Add(_Database.CreateParameter("ScaleX", s.Scale.X));
  1636. parameters.Add(_Database.CreateParameter("ScaleY", s.Scale.Y));
  1637. parameters.Add(_Database.CreateParameter("ScaleZ", s.Scale.Z));
  1638. // paths
  1639. parameters.Add(_Database.CreateParameter("PCode", s.PCode));
  1640. parameters.Add(_Database.CreateParameter("PathBegin", s.PathBegin));
  1641. parameters.Add(_Database.CreateParameter("PathEnd", s.PathEnd));
  1642. parameters.Add(_Database.CreateParameter("PathScaleX", s.PathScaleX));
  1643. parameters.Add(_Database.CreateParameter("PathScaleY", s.PathScaleY));
  1644. parameters.Add(_Database.CreateParameter("PathShearX", s.PathShearX));
  1645. parameters.Add(_Database.CreateParameter("PathShearY", s.PathShearY));
  1646. parameters.Add(_Database.CreateParameter("PathSkew", s.PathSkew));
  1647. parameters.Add(_Database.CreateParameter("PathCurve", s.PathCurve));
  1648. parameters.Add(_Database.CreateParameter("PathRadiusOffset", s.PathRadiusOffset));
  1649. parameters.Add(_Database.CreateParameter("PathRevolutions", s.PathRevolutions));
  1650. parameters.Add(_Database.CreateParameter("PathTaperX", s.PathTaperX));
  1651. parameters.Add(_Database.CreateParameter("PathTaperY", s.PathTaperY));
  1652. parameters.Add(_Database.CreateParameter("PathTwist", s.PathTwist));
  1653. parameters.Add(_Database.CreateParameter("PathTwistBegin", s.PathTwistBegin));
  1654. // profile
  1655. parameters.Add(_Database.CreateParameter("ProfileBegin", s.ProfileBegin));
  1656. parameters.Add(_Database.CreateParameter("ProfileEnd", s.ProfileEnd));
  1657. parameters.Add(_Database.CreateParameter("ProfileCurve", s.ProfileCurve));
  1658. parameters.Add(_Database.CreateParameter("ProfileHollow", s.ProfileHollow));
  1659. parameters.Add(_Database.CreateParameter("Texture", s.TextureEntry));
  1660. parameters.Add(_Database.CreateParameter("ExtraParams", s.ExtraParams));
  1661. parameters.Add(_Database.CreateParameter("State", s.State));
  1662. if (null == s.Media)
  1663. {
  1664. parameters.Add(_Database.CreateParameter("Media", DBNull.Value));
  1665. }
  1666. else
  1667. {
  1668. parameters.Add(_Database.CreateParameter("Media", s.Media.ToXml()));
  1669. }
  1670. return parameters.ToArray();
  1671. }
  1672. #endregion
  1673. #endregion
  1674. private void LoadSpawnPoints(RegionSettings rs)
  1675. {
  1676. rs.ClearSpawnPoints();
  1677. string sql = @"SELECT ""Yaw"", ""Pitch"", ""Distance"" FROM spawn_points WHERE ""RegionUUID"" = :RegionUUID";
  1678. using (NpgsqlConnection conn = new NpgsqlConnection(m_connectionString))
  1679. using (NpgsqlCommand cmd = new NpgsqlCommand(sql, conn))
  1680. {
  1681. cmd.Parameters.Add(_Database.CreateParameter("RegionUUID", rs.RegionUUID));
  1682. conn.Open();
  1683. using (NpgsqlDataReader reader = cmd.ExecuteReader())
  1684. {
  1685. if (reader.Read())
  1686. {
  1687. SpawnPoint sp = new SpawnPoint();
  1688. sp.Yaw = (float)reader["Yaw"];
  1689. sp.Pitch = (float)reader["Pitch"];
  1690. sp.Distance = (float)reader["Distance"];
  1691. rs.AddSpawnPoint(sp);
  1692. }
  1693. }
  1694. }
  1695. }
  1696. private void SaveSpawnPoints(RegionSettings rs)
  1697. {
  1698. string sql = @"DELETE FROM spawn_points WHERE ""RegionUUID"" = :RegionUUID";
  1699. using (NpgsqlConnection conn = new NpgsqlConnection(m_connectionString))
  1700. using (NpgsqlCommand cmd = new NpgsqlCommand(sql, conn))
  1701. {
  1702. cmd.Parameters.Add(_Database.CreateParameter("RegionUUID", rs.RegionUUID));
  1703. conn.Open();
  1704. cmd.ExecuteNonQuery();
  1705. }
  1706. foreach (SpawnPoint p in rs.SpawnPoints())
  1707. {
  1708. sql = @"INSERT INTO spawn_points (""RegionUUID"", ""Yaw"", ""Pitch"", ""Distance"") VALUES (:RegionUUID, :Yaw, :Pitch, :Distance)";
  1709. using (NpgsqlConnection conn = new NpgsqlConnection(m_connectionString))
  1710. using (NpgsqlCommand cmd = new NpgsqlCommand(sql, conn))
  1711. {
  1712. cmd.Parameters.Add(_Database.CreateParameter("RegionUUID", rs.RegionUUID));
  1713. cmd.Parameters.Add(_Database.CreateParameter("Yaw", p.Yaw));
  1714. cmd.Parameters.Add(_Database.CreateParameter("Pitch", p.Pitch));
  1715. cmd.Parameters.Add(_Database.CreateParameter("Distance", p.Distance));
  1716. conn.Open();
  1717. cmd.ExecuteNonQuery();
  1718. }
  1719. }
  1720. }
  1721. public UUID[] GetObjectIDs(UUID regionID)
  1722. {
  1723. return new UUID[0];
  1724. }
  1725. public void SaveExtra(UUID regionID, string name, string value)
  1726. {
  1727. }
  1728. public void RemoveExtra(UUID regionID, string name)
  1729. {
  1730. }
  1731. public Dictionary<string, string> GetExtra(UUID regionID)
  1732. {
  1733. return null;
  1734. }
  1735. }
  1736. }