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