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