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