aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Data/MySQL/MySQLSimulationData.cs
diff options
context:
space:
mode:
authorJohn Hurliman2010-09-11 20:43:06 -0700
committerJohn Hurliman2010-09-11 20:43:06 -0700
commit109b51758398d24a96a16900e8feb24361aee29d (patch)
treeaa696571c44fcf7afdad1931137a51f3074cd524 /OpenSim/Data/MySQL/MySQLSimulationData.cs
parentRe-enabled asset last access time logging in MySQL (diff)
downloadopensim-SC-109b51758398d24a96a16900e8feb24361aee29d.zip
opensim-SC-109b51758398d24a96a16900e8feb24361aee29d.tar.gz
opensim-SC-109b51758398d24a96a16900e8feb24361aee29d.tar.bz2
opensim-SC-109b51758398d24a96a16900e8feb24361aee29d.tar.xz
Fixed the naming mess around data connectors for simulation data
Diffstat (limited to 'OpenSim/Data/MySQL/MySQLSimulationData.cs')
-rw-r--r--OpenSim/Data/MySQL/MySQLSimulationData.cs1820
1 files changed, 1820 insertions, 0 deletions
diff --git a/OpenSim/Data/MySQL/MySQLSimulationData.cs b/OpenSim/Data/MySQL/MySQLSimulationData.cs
new file mode 100644
index 0000000..36f73ef
--- /dev/null
+++ b/OpenSim/Data/MySQL/MySQLSimulationData.cs
@@ -0,0 +1,1820 @@
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
52 private string m_connectionString;
53 private object m_dbLock = new object();
54
55 public void Initialise(string connectionString)
56 {
57 m_connectionString = connectionString;
58
59 using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
60 {
61 dbcon.Open();
62
63 // Apply new Migrations
64 //
65 Assembly assem = GetType().Assembly;
66 Migration m = new Migration(dbcon, assem, "RegionStore");
67 m.Update();
68
69 // Clean dropped attachments
70 //
71 try
72 {
73 using (MySqlCommand cmd = dbcon.CreateCommand())
74 {
75 cmd.CommandText = "delete from prims, primshapes using prims " +
76 "left join primshapes on prims.uuid = primshapes.uuid " +
77 "where PCode = 9 and State <> 0";
78 ExecuteNonQuery(cmd);
79 }
80 }
81 catch (MySqlException ex)
82 {
83 m_log.Error("[REGION DB]: Error cleaning up dropped attachments: " + ex.Message);
84 }
85 }
86 }
87
88 private IDataReader ExecuteReader(MySqlCommand c)
89 {
90 IDataReader r = null;
91
92 try
93 {
94 r = c.ExecuteReader();
95 }
96 catch (Exception e)
97 {
98 m_log.Error("[REGION DB]: MySQL error in ExecuteReader: " + e.Message);
99 throw;
100 }
101
102 return r;
103 }
104
105 private void ExecuteNonQuery(MySqlCommand c)
106 {
107 try
108 {
109 c.ExecuteNonQuery();
110 }
111 catch (Exception e)
112 {
113 m_log.Error("[REGION DB]: MySQL error in ExecuteNonQuery: " + e.Message);
114 throw;
115 }
116 }
117
118 public void Dispose() {}
119
120 public void StoreObject(SceneObjectGroup obj, UUID regionUUID)
121 {
122 uint flags = obj.RootPart.GetEffectiveObjectFlags();
123
124 // Eligibility check
125 //
126 if ((flags & (uint)PrimFlags.Temporary) != 0)
127 return;
128 if ((flags & (uint)PrimFlags.TemporaryOnRez) != 0)
129 return;
130
131 lock (m_dbLock)
132 {
133 using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
134 {
135 dbcon.Open();
136 MySqlCommand cmd = dbcon.CreateCommand();
137
138 foreach (SceneObjectPart prim in obj.Children.Values)
139 {
140 cmd.Parameters.Clear();
141
142 cmd.CommandText = "replace into prims (" +
143 "UUID, CreationDate, " +
144 "Name, Text, Description, " +
145 "SitName, TouchName, ObjectFlags, " +
146 "OwnerMask, NextOwnerMask, GroupMask, " +
147 "EveryoneMask, BaseMask, PositionX, " +
148 "PositionY, PositionZ, GroupPositionX, " +
149 "GroupPositionY, GroupPositionZ, VelocityX, " +
150 "VelocityY, VelocityZ, AngularVelocityX, " +
151 "AngularVelocityY, AngularVelocityZ, " +
152 "AccelerationX, AccelerationY, " +
153 "AccelerationZ, RotationX, " +
154 "RotationY, RotationZ, " +
155 "RotationW, SitTargetOffsetX, " +
156 "SitTargetOffsetY, SitTargetOffsetZ, " +
157 "SitTargetOrientW, SitTargetOrientX, " +
158 "SitTargetOrientY, SitTargetOrientZ, " +
159 "RegionUUID, CreatorID, " +
160 "OwnerID, GroupID, " +
161 "LastOwnerID, SceneGroupID, " +
162 "PayPrice, PayButton1, " +
163 "PayButton2, PayButton3, " +
164 "PayButton4, LoopedSound, " +
165 "LoopedSoundGain, TextureAnimation, " +
166 "OmegaX, OmegaY, OmegaZ, " +
167 "CameraEyeOffsetX, CameraEyeOffsetY, " +
168 "CameraEyeOffsetZ, CameraAtOffsetX, " +
169 "CameraAtOffsetY, CameraAtOffsetZ, " +
170 "ForceMouselook, ScriptAccessPin, " +
171 "AllowedDrop, DieAtEdge, " +
172 "SalePrice, SaleType, " +
173 "ColorR, ColorG, ColorB, ColorA, " +
174 "ParticleSystem, ClickAction, Material, " +
175 "CollisionSound, CollisionSoundVolume, " +
176 "PassTouches, " +
177 "LinkNumber, MediaURL) values (" + "?UUID, " +
178 "?CreationDate, ?Name, ?Text, " +
179 "?Description, ?SitName, ?TouchName, " +
180 "?ObjectFlags, ?OwnerMask, ?NextOwnerMask, " +
181 "?GroupMask, ?EveryoneMask, ?BaseMask, " +
182 "?PositionX, ?PositionY, ?PositionZ, " +
183 "?GroupPositionX, ?GroupPositionY, " +
184 "?GroupPositionZ, ?VelocityX, " +
185 "?VelocityY, ?VelocityZ, ?AngularVelocityX, " +
186 "?AngularVelocityY, ?AngularVelocityZ, " +
187 "?AccelerationX, ?AccelerationY, " +
188 "?AccelerationZ, ?RotationX, " +
189 "?RotationY, ?RotationZ, " +
190 "?RotationW, ?SitTargetOffsetX, " +
191 "?SitTargetOffsetY, ?SitTargetOffsetZ, " +
192 "?SitTargetOrientW, ?SitTargetOrientX, " +
193 "?SitTargetOrientY, ?SitTargetOrientZ, " +
194 "?RegionUUID, ?CreatorID, ?OwnerID, " +
195 "?GroupID, ?LastOwnerID, ?SceneGroupID, " +
196 "?PayPrice, ?PayButton1, ?PayButton2, " +
197 "?PayButton3, ?PayButton4, ?LoopedSound, " +
198 "?LoopedSoundGain, ?TextureAnimation, " +
199 "?OmegaX, ?OmegaY, ?OmegaZ, " +
200 "?CameraEyeOffsetX, ?CameraEyeOffsetY, " +
201 "?CameraEyeOffsetZ, ?CameraAtOffsetX, " +
202 "?CameraAtOffsetY, ?CameraAtOffsetZ, " +
203 "?ForceMouselook, ?ScriptAccessPin, " +
204 "?AllowedDrop, ?DieAtEdge, ?SalePrice, " +
205 "?SaleType, ?ColorR, ?ColorG, " +
206 "?ColorB, ?ColorA, ?ParticleSystem, " +
207 "?ClickAction, ?Material, ?CollisionSound, " +
208 "?CollisionSoundVolume, ?PassTouches, ?LinkNumber, ?MediaURL)";
209
210 FillPrimCommand(cmd, prim, obj.UUID, regionUUID);
211
212 ExecuteNonQuery(cmd);
213
214 cmd.Parameters.Clear();
215
216 cmd.CommandText = "replace into primshapes (" +
217 "UUID, Shape, ScaleX, ScaleY, " +
218 "ScaleZ, PCode, PathBegin, PathEnd, " +
219 "PathScaleX, PathScaleY, PathShearX, " +
220 "PathShearY, PathSkew, PathCurve, " +
221 "PathRadiusOffset, PathRevolutions, " +
222 "PathTaperX, PathTaperY, PathTwist, " +
223 "PathTwistBegin, ProfileBegin, ProfileEnd, " +
224 "ProfileCurve, ProfileHollow, Texture, " +
225 "ExtraParams, State, Media) values (?UUID, " +
226 "?Shape, ?ScaleX, ?ScaleY, ?ScaleZ, " +
227 "?PCode, ?PathBegin, ?PathEnd, " +
228 "?PathScaleX, ?PathScaleY, " +
229 "?PathShearX, ?PathShearY, " +
230 "?PathSkew, ?PathCurve, ?PathRadiusOffset, " +
231 "?PathRevolutions, ?PathTaperX, " +
232 "?PathTaperY, ?PathTwist, " +
233 "?PathTwistBegin, ?ProfileBegin, " +
234 "?ProfileEnd, ?ProfileCurve, " +
235 "?ProfileHollow, ?Texture, ?ExtraParams, " +
236 "?State, ?Media)";
237
238 FillShapeCommand(cmd, prim);
239
240 ExecuteNonQuery(cmd);
241 }
242
243 cmd.Dispose();
244 }
245 }
246 }
247
248 public void RemoveObject(UUID obj, UUID regionUUID)
249 {
250// m_log.DebugFormat("[REGION DB]: Deleting scene object {0} from {1} in database", obj, regionUUID);
251
252 List<UUID> uuids = new List<UUID>();
253
254 // Formerly, this used to check the region UUID.
255 // That makes no sense, as we remove the contents of a prim
256 // unconditionally, but the prim dependent on the region ID.
257 // So, we would destroy an object and cause hard to detect
258 // issues if we delete the contents only. Deleting it all may
259 // cause the loss of a prim, but is cleaner.
260 // It's also faster because it uses the primary key.
261 //
262 lock (m_dbLock)
263 {
264 using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
265 {
266 dbcon.Open();
267
268 using (MySqlCommand cmd = dbcon.CreateCommand())
269 {
270 cmd.CommandText = "select UUID from prims where SceneGroupID= ?UUID";
271 cmd.Parameters.AddWithValue("UUID", obj.ToString());
272
273 using (IDataReader reader = ExecuteReader(cmd))
274 {
275 while (reader.Read())
276 uuids.Add(DBGuid.FromDB(reader["UUID"].ToString()));
277 }
278
279 // delete the main prims
280 cmd.CommandText = "delete from prims where SceneGroupID= ?UUID";
281 ExecuteNonQuery(cmd);
282 }
283 }
284 }
285
286 // there is no way this should be < 1 unless there is
287 // a very corrupt database, but in that case be extra
288 // safe anyway.
289 if (uuids.Count > 0)
290 {
291 RemoveShapes(uuids);
292 RemoveItems(uuids);
293 }
294 }
295
296 /// <summary>
297 /// Remove all persisted items of the given prim.
298 /// The caller must acquire the necessrary synchronization locks
299 /// </summary>
300 /// <param name="uuid">the Item UUID</param>
301 private void RemoveItems(UUID uuid)
302 {
303 lock (m_dbLock)
304 {
305 using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
306 {
307 dbcon.Open();
308
309 using (MySqlCommand cmd = dbcon.CreateCommand())
310 {
311 cmd.CommandText = "delete from primitems where PrimID = ?PrimID";
312 cmd.Parameters.AddWithValue("PrimID", uuid.ToString());
313
314 ExecuteNonQuery(cmd);
315 }
316 }
317 }
318 }
319
320 /// <summary>
321 /// Remove all persisted shapes for a list of prims
322 /// The caller must acquire the necessrary synchronization locks
323 /// </summary>
324 /// <param name="uuids">the list of UUIDs</param>
325 private void RemoveShapes(List<UUID> uuids)
326 {
327 lock (m_dbLock)
328 {
329 string sql = "delete from primshapes where ";
330 using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
331 {
332 dbcon.Open();
333
334 using (MySqlCommand cmd = dbcon.CreateCommand())
335 {
336 for (int i = 0; i < uuids.Count; i++)
337 {
338 if ((i + 1) == uuids.Count)
339 {// end of the list
340 sql += "(UUID = ?UUID" + i + ")";
341 }
342 else
343 {
344 sql += "(UUID = ?UUID" + i + ") or ";
345 }
346 }
347 cmd.CommandText = sql;
348
349 for (int i = 0; i < uuids.Count; i++)
350 cmd.Parameters.AddWithValue("UUID" + i, uuids[i].ToString());
351
352 ExecuteNonQuery(cmd);
353 }
354 }
355 }
356 }
357
358 /// <summary>
359 /// Remove all persisted items for a list of prims
360 /// The caller must acquire the necessrary synchronization locks
361 /// </summary>
362 /// <param name="uuids">the list of UUIDs</param>
363 private void RemoveItems(List<UUID> uuids)
364 {
365 lock (m_dbLock)
366 {
367 string sql = "delete from primitems where ";
368 using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
369 {
370 dbcon.Open();
371
372 using (MySqlCommand cmd = dbcon.CreateCommand())
373 {
374 for (int i = 0; i < uuids.Count; i++)
375 {
376 if ((i + 1) == uuids.Count)
377 {
378 // end of the list
379 sql += "(PrimID = ?PrimID" + i + ")";
380 }
381 else
382 {
383 sql += "(PrimID = ?PrimID" + i + ") or ";
384 }
385 }
386 cmd.CommandText = sql;
387
388 for (int i = 0; i < uuids.Count; i++)
389 cmd.Parameters.AddWithValue("PrimID" + i, uuids[i].ToString());
390
391 ExecuteNonQuery(cmd);
392 }
393 }
394 }
395 }
396
397 public List<SceneObjectGroup> LoadObjects(UUID regionID)
398 {
399 const int ROWS_PER_QUERY = 5000;
400
401 Dictionary<UUID, SceneObjectPart> prims = new Dictionary<UUID, SceneObjectPart>(ROWS_PER_QUERY);
402 Dictionary<UUID, SceneObjectGroup> objects = new Dictionary<UUID, SceneObjectGroup>();
403 int count = 0;
404
405 #region Prim Loading
406
407 lock (m_dbLock)
408 {
409 using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
410 {
411 dbcon.Open();
412
413 using (MySqlCommand cmd = dbcon.CreateCommand())
414 {
415 cmd.CommandText =
416 "SELECT * FROM prims LEFT JOIN primshapes ON prims.UUID = primshapes.UUID WHERE RegionUUID = ?RegionUUID";
417 cmd.Parameters.AddWithValue("RegionUUID", regionID.ToString());
418
419 using (IDataReader reader = ExecuteReader(cmd))
420 {
421 while (reader.Read())
422 {
423 SceneObjectPart prim = BuildPrim(reader);
424 if (reader["Shape"] is DBNull)
425 prim.Shape = PrimitiveBaseShape.Default;
426 else
427 prim.Shape = BuildShape(reader);
428
429 UUID parentID = DBGuid.FromDB(reader["SceneGroupID"].ToString());
430 if (parentID != prim.UUID)
431 prim.ParentUUID = parentID;
432
433 prims[prim.UUID] = prim;
434
435 ++count;
436 if (count % ROWS_PER_QUERY == 0)
437 m_log.Debug("[REGION DB]: Loaded " + count + " prims...");
438 }
439 }
440 }
441 }
442 }
443
444 #endregion Prim Loading
445
446 #region SceneObjectGroup Creation
447
448 // Create all of the SOGs from the root prims first
449 foreach (SceneObjectPart prim in prims.Values)
450 {
451 if (prim.ParentUUID == UUID.Zero)
452 objects[prim.UUID] = new SceneObjectGroup(prim);
453 }
454
455 // Add all of the children objects to the SOGs
456 foreach (SceneObjectPart prim in prims.Values)
457 {
458 SceneObjectGroup sog;
459 if (prim.UUID != prim.ParentUUID)
460 {
461 if (objects.TryGetValue(prim.ParentUUID, out sog))
462 {
463 int originalLinkNum = prim.LinkNum;
464
465 sog.AddPart(prim);
466
467 // SceneObjectGroup.AddPart() tries to be smart and automatically set the LinkNum.
468 // We override that here
469 if (originalLinkNum != 0)
470 prim.LinkNum = originalLinkNum;
471 }
472 else
473 {
474 m_log.WarnFormat(
475 "[REGION DB]: Database contains an orphan child prim {0} {1} in region {2} pointing to missing parent {3}. This prim will not be loaded.",
476 prim.Name, prim.UUID, regionID, prim.ParentUUID);
477 }
478 }
479 }
480
481 #endregion SceneObjectGroup Creation
482
483 m_log.DebugFormat("[REGION DB]: Loaded {0} objects using {1} prims", objects.Count, prims.Count);
484
485 #region Prim Inventory Loading
486
487 // Instead of attempting to LoadItems on every prim,
488 // most of which probably have no items... get a
489 // list from DB of all prims which have items and
490 // LoadItems only on those
491 List<SceneObjectPart> primsWithInventory = new List<SceneObjectPart>();
492 lock (m_dbLock)
493 {
494 using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
495 {
496 dbcon.Open();
497
498 using (MySqlCommand itemCmd = dbcon.CreateCommand())
499 {
500 itemCmd.CommandText = "SELECT DISTINCT primID FROM primitems";
501 using (IDataReader itemReader = ExecuteReader(itemCmd))
502 {
503 while (itemReader.Read())
504 {
505 if (!(itemReader["primID"] is DBNull))
506 {
507 UUID primID = DBGuid.FromDB(itemReader["primID"].ToString());
508 if (prims.ContainsKey(primID))
509 primsWithInventory.Add(prims[primID]);
510 }
511 }
512 }
513 }
514 }
515 }
516
517 foreach (SceneObjectPart prim in primsWithInventory)
518 {
519 LoadItems(prim);
520 }
521
522 #endregion Prim Inventory Loading
523
524 m_log.DebugFormat("[REGION DB]: Loaded inventory from {0} objects", primsWithInventory.Count);
525
526 return new List<SceneObjectGroup>(objects.Values);
527 }
528
529 /// <summary>
530 /// Load in a prim's persisted inventory.
531 /// </summary>
532 /// <param name="prim">The prim</param>
533 private void LoadItems(SceneObjectPart prim)
534 {
535 lock (m_dbLock)
536 {
537 List<TaskInventoryItem> inventory = new List<TaskInventoryItem>();
538
539 using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
540 {
541 dbcon.Open();
542
543 using (MySqlCommand cmd = dbcon.CreateCommand())
544 {
545 cmd.CommandText = "select * from primitems where PrimID = ?PrimID";
546 cmd.Parameters.AddWithValue("PrimID", prim.UUID.ToString());
547
548 using (IDataReader reader = ExecuteReader(cmd))
549 {
550 while (reader.Read())
551 {
552 TaskInventoryItem item = BuildItem(reader);
553
554 item.ParentID = prim.UUID; // Values in database are often wrong
555 inventory.Add(item);
556 }
557 }
558 }
559 }
560
561 prim.Inventory.RestoreInventoryItems(inventory);
562 }
563 }
564
565 public void StoreTerrain(double[,] ter, UUID regionID)
566 {
567 m_log.Info("[REGION DB]: Storing terrain");
568
569 lock (m_dbLock)
570 {
571 using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
572 {
573 dbcon.Open();
574
575 using (MySqlCommand cmd = dbcon.CreateCommand())
576 {
577 cmd.CommandText = "delete from terrain where RegionUUID = ?RegionUUID";
578 cmd.Parameters.AddWithValue("RegionUUID", regionID.ToString());
579
580 ExecuteNonQuery(cmd);
581
582 cmd.CommandText = "insert into terrain (RegionUUID, " +
583 "Revision, Heightfield) values (?RegionUUID, " +
584 "1, ?Heightfield)";
585
586 cmd.Parameters.AddWithValue("Heightfield", SerializeTerrain(ter));
587
588 ExecuteNonQuery(cmd);
589 }
590 }
591 }
592 }
593
594 public double[,] LoadTerrain(UUID regionID)
595 {
596 double[,] terrain = null;
597
598 lock (m_dbLock)
599 {
600 using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
601 {
602 dbcon.Open();
603
604 using (MySqlCommand cmd = dbcon.CreateCommand())
605 {
606 cmd.CommandText = "select RegionUUID, Revision, Heightfield " +
607 "from terrain where RegionUUID = ?RegionUUID " +
608 "order by Revision desc limit 1";
609 cmd.Parameters.AddWithValue("RegionUUID", regionID.ToString());
610
611 using (IDataReader reader = ExecuteReader(cmd))
612 {
613 while (reader.Read())
614 {
615 int rev = Convert.ToInt32(reader["Revision"]);
616
617 terrain = new double[(int)Constants.RegionSize, (int)Constants.RegionSize];
618 terrain.Initialize();
619
620 using (MemoryStream mstr = new MemoryStream((byte[])reader["Heightfield"]))
621 {
622 using (BinaryReader br = new BinaryReader(mstr))
623 {
624 for (int x = 0; x < (int)Constants.RegionSize; x++)
625 {
626 for (int y = 0; y < (int)Constants.RegionSize; y++)
627 {
628 terrain[x, y] = br.ReadDouble();
629 }
630 }
631 }
632
633 m_log.InfoFormat("[REGION DB]: Loaded terrain revision r{0}", rev);
634 }
635 }
636 }
637 }
638 }
639 }
640
641 return terrain;
642 }
643
644 public void RemoveLandObject(UUID globalID)
645 {
646 lock (m_dbLock)
647 {
648 using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
649 {
650 dbcon.Open();
651
652 using (MySqlCommand cmd = dbcon.CreateCommand())
653 {
654 cmd.CommandText = "delete from land where UUID = ?UUID";
655 cmd.Parameters.AddWithValue("UUID", globalID.ToString());
656
657 ExecuteNonQuery(cmd);
658 }
659 }
660 }
661 }
662
663 public void StoreLandObject(ILandObject parcel)
664 {
665 lock (m_dbLock)
666 {
667 using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
668 {
669 dbcon.Open();
670
671 using (MySqlCommand cmd = dbcon.CreateCommand())
672 {
673 cmd.CommandText = "replace into land (UUID, RegionUUID, " +
674 "LocalLandID, Bitmap, Name, Description, " +
675 "OwnerUUID, IsGroupOwned, Area, AuctionID, " +
676 "Category, ClaimDate, ClaimPrice, GroupUUID, " +
677 "SalePrice, LandStatus, LandFlags, LandingType, " +
678 "MediaAutoScale, MediaTextureUUID, MediaURL, " +
679 "MusicURL, PassHours, PassPrice, SnapshotUUID, " +
680 "UserLocationX, UserLocationY, UserLocationZ, " +
681 "UserLookAtX, UserLookAtY, UserLookAtZ, " +
682 "AuthbuyerID, OtherCleanTime, MediaType, MediaDescription, " +
683 "MediaSize, MediaLoop, ObscureMusic, ObscureMedia) values (" +
684 "?UUID, ?RegionUUID, " +
685 "?LocalLandID, ?Bitmap, ?Name, ?Description, " +
686 "?OwnerUUID, ?IsGroupOwned, ?Area, ?AuctionID, " +
687 "?Category, ?ClaimDate, ?ClaimPrice, ?GroupUUID, " +
688 "?SalePrice, ?LandStatus, ?LandFlags, ?LandingType, " +
689 "?MediaAutoScale, ?MediaTextureUUID, ?MediaURL, " +
690 "?MusicURL, ?PassHours, ?PassPrice, ?SnapshotUUID, " +
691 "?UserLocationX, ?UserLocationY, ?UserLocationZ, " +
692 "?UserLookAtX, ?UserLookAtY, ?UserLookAtZ, " +
693 "?AuthbuyerID, ?OtherCleanTime, ?MediaType, ?MediaDescription, "+
694 "CONCAT(?MediaWidth, ',', ?MediaHeight), ?MediaLoop, ?ObscureMusic, ?ObscureMedia)";
695
696 FillLandCommand(cmd, parcel.LandData, parcel.RegionUUID);
697
698 ExecuteNonQuery(cmd);
699
700 cmd.CommandText = "delete from landaccesslist where LandUUID = ?UUID";
701
702 ExecuteNonQuery(cmd);
703
704 cmd.Parameters.Clear();
705 cmd.CommandText = "insert into landaccesslist (LandUUID, " +
706 "AccessUUID, Flags) values (?LandUUID, ?AccessUUID, " +
707 "?Flags)";
708
709 foreach (ParcelManager.ParcelAccessEntry entry in parcel.LandData.ParcelAccessList)
710 {
711 FillLandAccessCommand(cmd, entry, parcel.LandData.GlobalID);
712 ExecuteNonQuery(cmd);
713 cmd.Parameters.Clear();
714 }
715 }
716 }
717 }
718 }
719
720 public RegionLightShareData LoadRegionWindlightSettings(UUID regionUUID)
721 {
722 RegionLightShareData nWP = new RegionLightShareData();
723 nWP.OnSave += StoreRegionWindlightSettings;
724
725 using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
726 {
727 dbcon.Open();
728
729 string command = "select * from `regionwindlight` where region_id = ?regionID";
730
731 using(MySqlCommand cmd = new MySqlCommand(command))
732 {
733 cmd.Connection = dbcon;
734
735 cmd.Parameters.AddWithValue("?regionID", regionUUID.ToString());
736
737 IDataReader result = ExecuteReader(cmd);
738 if (!result.Read())
739 {
740 //No result, so store our default windlight profile and return it
741 nWP.regionID = regionUUID;
742 StoreRegionWindlightSettings(nWP);
743 return nWP;
744 }
745 else
746 {
747 nWP.regionID = DBGuid.FromDB(result["region_id"]);
748 nWP.waterColor.X = Convert.ToSingle(result["water_color_r"]);
749 nWP.waterColor.Y = Convert.ToSingle(result["water_color_g"]);
750 nWP.waterColor.Z = Convert.ToSingle(result["water_color_b"]);
751 nWP.waterFogDensityExponent = Convert.ToSingle(result["water_fog_density_exponent"]);
752 nWP.underwaterFogModifier = Convert.ToSingle(result["underwater_fog_modifier"]);
753 nWP.reflectionWaveletScale.X = Convert.ToSingle(result["reflection_wavelet_scale_1"]);
754 nWP.reflectionWaveletScale.Y = Convert.ToSingle(result["reflection_wavelet_scale_2"]);
755 nWP.reflectionWaveletScale.Z = Convert.ToSingle(result["reflection_wavelet_scale_3"]);
756 nWP.fresnelScale = Convert.ToSingle(result["fresnel_scale"]);
757 nWP.fresnelOffset = Convert.ToSingle(result["fresnel_offset"]);
758 nWP.refractScaleAbove = Convert.ToSingle(result["refract_scale_above"]);
759 nWP.refractScaleBelow = Convert.ToSingle(result["refract_scale_below"]);
760 nWP.blurMultiplier = Convert.ToSingle(result["blur_multiplier"]);
761 nWP.bigWaveDirection.X = Convert.ToSingle(result["big_wave_direction_x"]);
762 nWP.bigWaveDirection.Y = Convert.ToSingle(result["big_wave_direction_y"]);
763 nWP.littleWaveDirection.X = Convert.ToSingle(result["little_wave_direction_x"]);
764 nWP.littleWaveDirection.Y = Convert.ToSingle(result["little_wave_direction_y"]);
765 UUID.TryParse(result["normal_map_texture"].ToString(), out nWP.normalMapTexture);
766 nWP.horizon.X = Convert.ToSingle(result["horizon_r"]);
767 nWP.horizon.Y = Convert.ToSingle(result["horizon_g"]);
768 nWP.horizon.Z = Convert.ToSingle(result["horizon_b"]);
769 nWP.horizon.W = Convert.ToSingle(result["horizon_i"]);
770 nWP.hazeHorizon = Convert.ToSingle(result["haze_horizon"]);
771 nWP.blueDensity.X = Convert.ToSingle(result["blue_density_r"]);
772 nWP.blueDensity.Y = Convert.ToSingle(result["blue_density_g"]);
773 nWP.blueDensity.Z = Convert.ToSingle(result["blue_density_b"]);
774 nWP.blueDensity.W = Convert.ToSingle(result["blue_density_i"]);
775 nWP.hazeDensity = Convert.ToSingle(result["haze_density"]);
776 nWP.densityMultiplier = Convert.ToSingle(result["density_multiplier"]);
777 nWP.distanceMultiplier = Convert.ToSingle(result["distance_multiplier"]);
778 nWP.maxAltitude = Convert.ToUInt16(result["max_altitude"]);
779 nWP.sunMoonColor.X = Convert.ToSingle(result["sun_moon_color_r"]);
780 nWP.sunMoonColor.Y = Convert.ToSingle(result["sun_moon_color_g"]);
781 nWP.sunMoonColor.Z = Convert.ToSingle(result["sun_moon_color_b"]);
782 nWP.sunMoonColor.W = Convert.ToSingle(result["sun_moon_color_i"]);
783 nWP.sunMoonPosition = Convert.ToSingle(result["sun_moon_position"]);
784 nWP.ambient.X = Convert.ToSingle(result["ambient_r"]);
785 nWP.ambient.Y = Convert.ToSingle(result["ambient_g"]);
786 nWP.ambient.Z = Convert.ToSingle(result["ambient_b"]);
787 nWP.ambient.W = Convert.ToSingle(result["ambient_i"]);
788 nWP.eastAngle = Convert.ToSingle(result["east_angle"]);
789 nWP.sunGlowFocus = Convert.ToSingle(result["sun_glow_focus"]);
790 nWP.sunGlowSize = Convert.ToSingle(result["sun_glow_size"]);
791 nWP.sceneGamma = Convert.ToSingle(result["scene_gamma"]);
792 nWP.starBrightness = Convert.ToSingle(result["star_brightness"]);
793 nWP.cloudColor.X = Convert.ToSingle(result["cloud_color_r"]);
794 nWP.cloudColor.Y = Convert.ToSingle(result["cloud_color_g"]);
795 nWP.cloudColor.Z = Convert.ToSingle(result["cloud_color_b"]);
796 nWP.cloudColor.W = Convert.ToSingle(result["cloud_color_i"]);
797 nWP.cloudXYDensity.X = Convert.ToSingle(result["cloud_x"]);
798 nWP.cloudXYDensity.Y = Convert.ToSingle(result["cloud_y"]);
799 nWP.cloudXYDensity.Z = Convert.ToSingle(result["cloud_density"]);
800 nWP.cloudCoverage = Convert.ToSingle(result["cloud_coverage"]);
801 nWP.cloudScale = Convert.ToSingle(result["cloud_scale"]);
802 nWP.cloudDetailXYDensity.X = Convert.ToSingle(result["cloud_detail_x"]);
803 nWP.cloudDetailXYDensity.Y = Convert.ToSingle(result["cloud_detail_y"]);
804 nWP.cloudDetailXYDensity.Z = Convert.ToSingle(result["cloud_detail_density"]);
805 nWP.cloudScrollX = Convert.ToSingle(result["cloud_scroll_x"]);
806 nWP.cloudScrollXLock = Convert.ToBoolean(result["cloud_scroll_x_lock"]);
807 nWP.cloudScrollY = Convert.ToSingle(result["cloud_scroll_y"]);
808 nWP.cloudScrollYLock = Convert.ToBoolean(result["cloud_scroll_y_lock"]);
809 nWP.drawClassicClouds = Convert.ToBoolean(result["draw_classic_clouds"]);
810 }
811 }
812 }
813 return nWP;
814 }
815
816 public RegionSettings LoadRegionSettings(UUID regionUUID)
817 {
818 RegionSettings rs = null;
819
820 lock (m_dbLock)
821 {
822 using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
823 {
824 dbcon.Open();
825
826 using (MySqlCommand cmd = dbcon.CreateCommand())
827 {
828 cmd.CommandText = "select * from regionsettings where regionUUID = ?RegionUUID";
829 cmd.Parameters.AddWithValue("regionUUID", regionUUID);
830
831 using (IDataReader reader = ExecuteReader(cmd))
832 {
833 if (reader.Read())
834 {
835 rs = BuildRegionSettings(reader);
836 rs.OnSave += StoreRegionSettings;
837 }
838 else
839 {
840 rs = new RegionSettings();
841 rs.RegionUUID = regionUUID;
842 rs.OnSave += StoreRegionSettings;
843
844 StoreRegionSettings(rs);
845 }
846 }
847 }
848 }
849 }
850
851 return rs;
852 }
853
854 public void StoreRegionWindlightSettings(RegionLightShareData wl)
855 {
856 using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
857 {
858 dbcon.Open();
859
860 using (MySqlCommand cmd = dbcon.CreateCommand())
861 {
862 cmd.CommandText = "REPLACE INTO `regionwindlight` (`region_id`, `water_color_r`, `water_color_g`, ";
863 cmd.CommandText += "`water_color_b`, `water_fog_density_exponent`, `underwater_fog_modifier`, ";
864 cmd.CommandText += "`reflection_wavelet_scale_1`, `reflection_wavelet_scale_2`, `reflection_wavelet_scale_3`, ";
865 cmd.CommandText += "`fresnel_scale`, `fresnel_offset`, `refract_scale_above`, `refract_scale_below`, ";
866 cmd.CommandText += "`blur_multiplier`, `big_wave_direction_x`, `big_wave_direction_y`, `little_wave_direction_x`, ";
867 cmd.CommandText += "`little_wave_direction_y`, `normal_map_texture`, `horizon_r`, `horizon_g`, `horizon_b`, ";
868 cmd.CommandText += "`horizon_i`, `haze_horizon`, `blue_density_r`, `blue_density_g`, `blue_density_b`, ";
869 cmd.CommandText += "`blue_density_i`, `haze_density`, `density_multiplier`, `distance_multiplier`, `max_altitude`, ";
870 cmd.CommandText += "`sun_moon_color_r`, `sun_moon_color_g`, `sun_moon_color_b`, `sun_moon_color_i`, `sun_moon_position`, ";
871 cmd.CommandText += "`ambient_r`, `ambient_g`, `ambient_b`, `ambient_i`, `east_angle`, `sun_glow_focus`, `sun_glow_size`, ";
872 cmd.CommandText += "`scene_gamma`, `star_brightness`, `cloud_color_r`, `cloud_color_g`, `cloud_color_b`, `cloud_color_i`, ";
873 cmd.CommandText += "`cloud_x`, `cloud_y`, `cloud_density`, `cloud_coverage`, `cloud_scale`, `cloud_detail_x`, ";
874 cmd.CommandText += "`cloud_detail_y`, `cloud_detail_density`, `cloud_scroll_x`, `cloud_scroll_x_lock`, `cloud_scroll_y`, ";
875 cmd.CommandText += "`cloud_scroll_y_lock`, `draw_classic_clouds`) VALUES (?region_id, ?water_color_r, ";
876 cmd.CommandText += "?water_color_g, ?water_color_b, ?water_fog_density_exponent, ?underwater_fog_modifier, ?reflection_wavelet_scale_1, ";
877 cmd.CommandText += "?reflection_wavelet_scale_2, ?reflection_wavelet_scale_3, ?fresnel_scale, ?fresnel_offset, ?refract_scale_above, ";
878 cmd.CommandText += "?refract_scale_below, ?blur_multiplier, ?big_wave_direction_x, ?big_wave_direction_y, ?little_wave_direction_x, ";
879 cmd.CommandText += "?little_wave_direction_y, ?normal_map_texture, ?horizon_r, ?horizon_g, ?horizon_b, ?horizon_i, ?haze_horizon, ";
880 cmd.CommandText += "?blue_density_r, ?blue_density_g, ?blue_density_b, ?blue_density_i, ?haze_density, ?density_multiplier, ";
881 cmd.CommandText += "?distance_multiplier, ?max_altitude, ?sun_moon_color_r, ?sun_moon_color_g, ?sun_moon_color_b, ";
882 cmd.CommandText += "?sun_moon_color_i, ?sun_moon_position, ?ambient_r, ?ambient_g, ?ambient_b, ?ambient_i, ?east_angle, ";
883 cmd.CommandText += "?sun_glow_focus, ?sun_glow_size, ?scene_gamma, ?star_brightness, ?cloud_color_r, ?cloud_color_g, ";
884 cmd.CommandText += "?cloud_color_b, ?cloud_color_i, ?cloud_x, ?cloud_y, ?cloud_density, ?cloud_coverage, ?cloud_scale, ";
885 cmd.CommandText += "?cloud_detail_x, ?cloud_detail_y, ?cloud_detail_density, ?cloud_scroll_x, ?cloud_scroll_x_lock, ";
886 cmd.CommandText += "?cloud_scroll_y, ?cloud_scroll_y_lock, ?draw_classic_clouds)";
887
888 cmd.Parameters.AddWithValue("region_id", wl.regionID);
889 cmd.Parameters.AddWithValue("water_color_r", wl.waterColor.X);
890 cmd.Parameters.AddWithValue("water_color_g", wl.waterColor.Y);
891 cmd.Parameters.AddWithValue("water_color_b", wl.waterColor.Z);
892 cmd.Parameters.AddWithValue("water_fog_density_exponent", wl.waterFogDensityExponent);
893 cmd.Parameters.AddWithValue("underwater_fog_modifier", wl.underwaterFogModifier);
894 cmd.Parameters.AddWithValue("reflection_wavelet_scale_1", wl.reflectionWaveletScale.X);
895 cmd.Parameters.AddWithValue("reflection_wavelet_scale_2", wl.reflectionWaveletScale.Y);
896 cmd.Parameters.AddWithValue("reflection_wavelet_scale_3", wl.reflectionWaveletScale.Z);
897 cmd.Parameters.AddWithValue("fresnel_scale", wl.fresnelScale);
898 cmd.Parameters.AddWithValue("fresnel_offset", wl.fresnelOffset);
899 cmd.Parameters.AddWithValue("refract_scale_above", wl.refractScaleAbove);
900 cmd.Parameters.AddWithValue("refract_scale_below", wl.refractScaleBelow);
901 cmd.Parameters.AddWithValue("blur_multiplier", wl.blurMultiplier);
902 cmd.Parameters.AddWithValue("big_wave_direction_x", wl.bigWaveDirection.X);
903 cmd.Parameters.AddWithValue("big_wave_direction_y", wl.bigWaveDirection.Y);
904 cmd.Parameters.AddWithValue("little_wave_direction_x", wl.littleWaveDirection.X);
905 cmd.Parameters.AddWithValue("little_wave_direction_y", wl.littleWaveDirection.Y);
906 cmd.Parameters.AddWithValue("normal_map_texture", wl.normalMapTexture);
907 cmd.Parameters.AddWithValue("horizon_r", wl.horizon.X);
908 cmd.Parameters.AddWithValue("horizon_g", wl.horizon.Y);
909 cmd.Parameters.AddWithValue("horizon_b", wl.horizon.Z);
910 cmd.Parameters.AddWithValue("horizon_i", wl.horizon.W);
911 cmd.Parameters.AddWithValue("haze_horizon", wl.hazeHorizon);
912 cmd.Parameters.AddWithValue("blue_density_r", wl.blueDensity.X);
913 cmd.Parameters.AddWithValue("blue_density_g", wl.blueDensity.Y);
914 cmd.Parameters.AddWithValue("blue_density_b", wl.blueDensity.Z);
915 cmd.Parameters.AddWithValue("blue_density_i", wl.blueDensity.W);
916 cmd.Parameters.AddWithValue("haze_density", wl.hazeDensity);
917 cmd.Parameters.AddWithValue("density_multiplier", wl.densityMultiplier);
918 cmd.Parameters.AddWithValue("distance_multiplier", wl.distanceMultiplier);
919 cmd.Parameters.AddWithValue("max_altitude", wl.maxAltitude);
920 cmd.Parameters.AddWithValue("sun_moon_color_r", wl.sunMoonColor.X);
921 cmd.Parameters.AddWithValue("sun_moon_color_g", wl.sunMoonColor.Y);
922 cmd.Parameters.AddWithValue("sun_moon_color_b", wl.sunMoonColor.Z);
923 cmd.Parameters.AddWithValue("sun_moon_color_i", wl.sunMoonColor.W);
924 cmd.Parameters.AddWithValue("sun_moon_position", wl.sunMoonPosition);
925 cmd.Parameters.AddWithValue("ambient_r", wl.ambient.X);
926 cmd.Parameters.AddWithValue("ambient_g", wl.ambient.Y);
927 cmd.Parameters.AddWithValue("ambient_b", wl.ambient.Z);
928 cmd.Parameters.AddWithValue("ambient_i", wl.ambient.W);
929 cmd.Parameters.AddWithValue("east_angle", wl.eastAngle);
930 cmd.Parameters.AddWithValue("sun_glow_focus", wl.sunGlowFocus);
931 cmd.Parameters.AddWithValue("sun_glow_size", wl.sunGlowSize);
932 cmd.Parameters.AddWithValue("scene_gamma", wl.sceneGamma);
933 cmd.Parameters.AddWithValue("star_brightness", wl.starBrightness);
934 cmd.Parameters.AddWithValue("cloud_color_r", wl.cloudColor.X);
935 cmd.Parameters.AddWithValue("cloud_color_g", wl.cloudColor.Y);
936 cmd.Parameters.AddWithValue("cloud_color_b", wl.cloudColor.Z);
937 cmd.Parameters.AddWithValue("cloud_color_i", wl.cloudColor.W);
938 cmd.Parameters.AddWithValue("cloud_x", wl.cloudXYDensity.X);
939 cmd.Parameters.AddWithValue("cloud_y", wl.cloudXYDensity.Y);
940 cmd.Parameters.AddWithValue("cloud_density", wl.cloudXYDensity.Z);
941 cmd.Parameters.AddWithValue("cloud_coverage", wl.cloudCoverage);
942 cmd.Parameters.AddWithValue("cloud_scale", wl.cloudScale);
943 cmd.Parameters.AddWithValue("cloud_detail_x", wl.cloudDetailXYDensity.X);
944 cmd.Parameters.AddWithValue("cloud_detail_y", wl.cloudDetailXYDensity.Y);
945 cmd.Parameters.AddWithValue("cloud_detail_density", wl.cloudDetailXYDensity.Z);
946 cmd.Parameters.AddWithValue("cloud_scroll_x", wl.cloudScrollX);
947 cmd.Parameters.AddWithValue("cloud_scroll_x_lock", wl.cloudScrollXLock);
948 cmd.Parameters.AddWithValue("cloud_scroll_y", wl.cloudScrollY);
949 cmd.Parameters.AddWithValue("cloud_scroll_y_lock", wl.cloudScrollYLock);
950 cmd.Parameters.AddWithValue("draw_classic_clouds", wl.drawClassicClouds);
951
952 ExecuteNonQuery(cmd);
953 }
954 }
955 }
956
957 public void StoreRegionSettings(RegionSettings rs)
958 {
959 lock (m_dbLock)
960 {
961 using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
962 {
963 dbcon.Open();
964
965 using (MySqlCommand cmd = dbcon.CreateCommand())
966 {
967 cmd.CommandText = "replace into regionsettings (regionUUID, " +
968 "block_terraform, block_fly, allow_damage, " +
969 "restrict_pushing, allow_land_resell, " +
970 "allow_land_join_divide, block_show_in_search, " +
971 "agent_limit, object_bonus, maturity, " +
972 "disable_scripts, disable_collisions, " +
973 "disable_physics, terrain_texture_1, " +
974 "terrain_texture_2, terrain_texture_3, " +
975 "terrain_texture_4, elevation_1_nw, " +
976 "elevation_2_nw, elevation_1_ne, " +
977 "elevation_2_ne, elevation_1_se, " +
978 "elevation_2_se, elevation_1_sw, " +
979 "elevation_2_sw, water_height, " +
980 "terrain_raise_limit, terrain_lower_limit, " +
981 "use_estate_sun, fixed_sun, sun_position, " +
982 "covenant, Sandbox, sunvectorx, sunvectory, " +
983 "sunvectorz, loaded_creation_datetime, " +
984 "loaded_creation_id, map_tile_ID) values (?RegionUUID, ?BlockTerraform, " +
985 "?BlockFly, ?AllowDamage, ?RestrictPushing, " +
986 "?AllowLandResell, ?AllowLandJoinDivide, " +
987 "?BlockShowInSearch, ?AgentLimit, ?ObjectBonus, " +
988 "?Maturity, ?DisableScripts, ?DisableCollisions, " +
989 "?DisablePhysics, ?TerrainTexture1, " +
990 "?TerrainTexture2, ?TerrainTexture3, " +
991 "?TerrainTexture4, ?Elevation1NW, ?Elevation2NW, " +
992 "?Elevation1NE, ?Elevation2NE, ?Elevation1SE, " +
993 "?Elevation2SE, ?Elevation1SW, ?Elevation2SW, " +
994 "?WaterHeight, ?TerrainRaiseLimit, " +
995 "?TerrainLowerLimit, ?UseEstateSun, ?FixedSun, " +
996 "?SunPosition, ?Covenant, ?Sandbox, " +
997 "?SunVectorX, ?SunVectorY, ?SunVectorZ, " +
998 "?LoadedCreationDateTime, ?LoadedCreationID, " +
999 "?TerrainImageID)";
1000
1001 FillRegionSettingsCommand(cmd, rs);
1002
1003 ExecuteNonQuery(cmd);
1004 }
1005 }
1006 }
1007 }
1008
1009 public List<LandData> LoadLandObjects(UUID regionUUID)
1010 {
1011 List<LandData> landData = new List<LandData>();
1012
1013 lock (m_dbLock)
1014 {
1015 using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
1016 {
1017 dbcon.Open();
1018
1019 using (MySqlCommand cmd = dbcon.CreateCommand())
1020 {
1021 cmd.CommandText = "select * from land where RegionUUID = ?RegionUUID";
1022 cmd.Parameters.AddWithValue("RegionUUID", regionUUID.ToString());
1023
1024 using (IDataReader reader = ExecuteReader(cmd))
1025 {
1026 while (reader.Read())
1027 {
1028 LandData newLand = BuildLandData(reader);
1029 landData.Add(newLand);
1030 }
1031 }
1032 }
1033
1034 using (MySqlCommand cmd = dbcon.CreateCommand())
1035 {
1036 foreach (LandData land in landData)
1037 {
1038 cmd.Parameters.Clear();
1039 cmd.CommandText = "select * from landaccesslist where LandUUID = ?LandUUID";
1040 cmd.Parameters.AddWithValue("LandUUID", land.GlobalID.ToString());
1041
1042 using (IDataReader reader = ExecuteReader(cmd))
1043 {
1044 while (reader.Read())
1045 {
1046 land.ParcelAccessList.Add(BuildLandAccessData(reader));
1047 }
1048 }
1049 }
1050 }
1051 }
1052 }
1053
1054 return landData;
1055 }
1056
1057 public void Shutdown()
1058 {
1059 }
1060
1061 private SceneObjectPart BuildPrim(IDataReader row)
1062 {
1063 SceneObjectPart prim = new SceneObjectPart();
1064
1065 // depending on the MySQL connector version, CHAR(36) may be already converted to Guid!
1066 prim.UUID = DBGuid.FromDB(row["UUID"]);
1067 prim.CreatorID = DBGuid.FromDB(row["CreatorID"]);
1068 prim.OwnerID = DBGuid.FromDB(row["OwnerID"]);
1069 prim.GroupID = DBGuid.FromDB(row["GroupID"]);
1070 prim.LastOwnerID = DBGuid.FromDB(row["LastOwnerID"]);
1071
1072 // explicit conversion of integers is required, which sort
1073 // of sucks. No idea if there is a shortcut here or not.
1074 prim.CreationDate = (int)row["CreationDate"];
1075 if (row["Name"] != DBNull.Value)
1076 prim.Name = (string)row["Name"];
1077 else
1078 prim.Name = String.Empty;
1079 // Various text fields
1080 prim.Text = (string)row["Text"];
1081 prim.Color = Color.FromArgb((int)row["ColorA"],
1082 (int)row["ColorR"],
1083 (int)row["ColorG"],
1084 (int)row["ColorB"]);
1085 prim.Description = (string)row["Description"];
1086 prim.SitName = (string)row["SitName"];
1087 prim.TouchName = (string)row["TouchName"];
1088 // Permissions
1089 prim.Flags = (PrimFlags)(int)row["ObjectFlags"];
1090 prim.OwnerMask = (uint)(int)row["OwnerMask"];
1091 prim.NextOwnerMask = (uint)(int)row["NextOwnerMask"];
1092 prim.GroupMask = (uint)(int)row["GroupMask"];
1093 prim.EveryoneMask = (uint)(int)row["EveryoneMask"];
1094 prim.BaseMask = (uint)(int)row["BaseMask"];
1095
1096 // Vectors
1097 prim.OffsetPosition = new Vector3(
1098 (float)(double)row["PositionX"],
1099 (float)(double)row["PositionY"],
1100 (float)(double)row["PositionZ"]
1101 );
1102 prim.GroupPosition = new Vector3(
1103 (float)(double)row["GroupPositionX"],
1104 (float)(double)row["GroupPositionY"],
1105 (float)(double)row["GroupPositionZ"]
1106 );
1107 prim.Velocity = new Vector3(
1108 (float)(double)row["VelocityX"],
1109 (float)(double)row["VelocityY"],
1110 (float)(double)row["VelocityZ"]
1111 );
1112 prim.AngularVelocity = new Vector3(
1113 (float)(double)row["AngularVelocityX"],
1114 (float)(double)row["AngularVelocityY"],
1115 (float)(double)row["AngularVelocityZ"]
1116 );
1117 prim.Acceleration = new Vector3(
1118 (float)(double)row["AccelerationX"],
1119 (float)(double)row["AccelerationY"],
1120 (float)(double)row["AccelerationZ"]
1121 );
1122 // quaternions
1123 prim.RotationOffset = new Quaternion(
1124 (float)(double)row["RotationX"],
1125 (float)(double)row["RotationY"],
1126 (float)(double)row["RotationZ"],
1127 (float)(double)row["RotationW"]
1128 );
1129 prim.SitTargetPositionLL = new Vector3(
1130 (float)(double)row["SitTargetOffsetX"],
1131 (float)(double)row["SitTargetOffsetY"],
1132 (float)(double)row["SitTargetOffsetZ"]
1133 );
1134 prim.SitTargetOrientationLL = new Quaternion(
1135 (float)(double)row["SitTargetOrientX"],
1136 (float)(double)row["SitTargetOrientY"],
1137 (float)(double)row["SitTargetOrientZ"],
1138 (float)(double)row["SitTargetOrientW"]
1139 );
1140
1141 prim.PayPrice[0] = (int)row["PayPrice"];
1142 prim.PayPrice[1] = (int)row["PayButton1"];
1143 prim.PayPrice[2] = (int)row["PayButton2"];
1144 prim.PayPrice[3] = (int)row["PayButton3"];
1145 prim.PayPrice[4] = (int)row["PayButton4"];
1146
1147 prim.Sound = DBGuid.FromDB(row["LoopedSound"].ToString());
1148 prim.SoundGain = (float)(double)row["LoopedSoundGain"];
1149 prim.SoundFlags = 1; // If it's persisted at all, it's looped
1150
1151 if (!(row["TextureAnimation"] is DBNull))
1152 prim.TextureAnimation = (byte[])row["TextureAnimation"];
1153 if (!(row["ParticleSystem"] is DBNull))
1154 prim.ParticleSystem = (byte[])row["ParticleSystem"];
1155
1156 prim.AngularVelocity = new Vector3(
1157 (float)(double)row["OmegaX"],
1158 (float)(double)row["OmegaY"],
1159 (float)(double)row["OmegaZ"]
1160 );
1161
1162 prim.SetCameraEyeOffset(new Vector3(
1163 (float)(double)row["CameraEyeOffsetX"],
1164 (float)(double)row["CameraEyeOffsetY"],
1165 (float)(double)row["CameraEyeOffsetZ"]
1166 ));
1167
1168 prim.SetCameraAtOffset(new Vector3(
1169 (float)(double)row["CameraAtOffsetX"],
1170 (float)(double)row["CameraAtOffsetY"],
1171 (float)(double)row["CameraAtOffsetZ"]
1172 ));
1173
1174 prim.SetForceMouselook((sbyte)row["ForceMouselook"] != 0);
1175 prim.ScriptAccessPin = (int)row["ScriptAccessPin"];
1176 prim.AllowedDrop = ((sbyte)row["AllowedDrop"] != 0);
1177 prim.DIE_AT_EDGE = ((sbyte)row["DieAtEdge"] != 0);
1178
1179 prim.SalePrice = (int)row["SalePrice"];
1180 prim.ObjectSaleType = unchecked((byte)(sbyte)row["SaleType"]);
1181
1182 prim.Material = unchecked((byte)(sbyte)row["Material"]);
1183
1184 if (!(row["ClickAction"] is DBNull))
1185 prim.ClickAction = unchecked((byte)(sbyte)row["ClickAction"]);
1186
1187 prim.CollisionSound = DBGuid.FromDB(row["CollisionSound"]);
1188 prim.CollisionSoundVolume = (float)(double)row["CollisionSoundVolume"];
1189
1190 prim.PassTouches = ((sbyte)row["PassTouches"] != 0);
1191 prim.LinkNum = (int)row["LinkNumber"];
1192
1193 if (!(row["MediaURL"] is System.DBNull))
1194 prim.MediaUrl = (string)row["MediaURL"];
1195
1196 return prim;
1197 }
1198
1199
1200 /// <summary>
1201 /// Build a prim inventory item from the persisted data.
1202 /// </summary>
1203 /// <param name="row"></param>
1204 /// <returns></returns>
1205 private static TaskInventoryItem BuildItem(IDataReader row)
1206 {
1207 TaskInventoryItem taskItem = new TaskInventoryItem();
1208
1209 taskItem.ItemID = DBGuid.FromDB(row["itemID"]);
1210 taskItem.ParentPartID = DBGuid.FromDB(row["primID"]);
1211 taskItem.AssetID = DBGuid.FromDB(row["assetID"]);
1212 taskItem.ParentID = DBGuid.FromDB(row["parentFolderID"]);
1213
1214 taskItem.InvType = Convert.ToInt32(row["invType"]);
1215 taskItem.Type = Convert.ToInt32(row["assetType"]);
1216
1217 taskItem.Name = (String)row["name"];
1218 taskItem.Description = (String)row["description"];
1219 taskItem.CreationDate = Convert.ToUInt32(row["creationDate"]);
1220 taskItem.CreatorID = DBGuid.FromDB(row["creatorID"]);
1221 taskItem.OwnerID = DBGuid.FromDB(row["ownerID"]);
1222 taskItem.LastOwnerID = DBGuid.FromDB(row["lastOwnerID"]);
1223 taskItem.GroupID = DBGuid.FromDB(row["groupID"]);
1224
1225 taskItem.NextPermissions = Convert.ToUInt32(row["nextPermissions"]);
1226 taskItem.CurrentPermissions = Convert.ToUInt32(row["currentPermissions"]);
1227 taskItem.BasePermissions = Convert.ToUInt32(row["basePermissions"]);
1228 taskItem.EveryonePermissions = Convert.ToUInt32(row["everyonePermissions"]);
1229 taskItem.GroupPermissions = Convert.ToUInt32(row["groupPermissions"]);
1230 taskItem.Flags = Convert.ToUInt32(row["flags"]);
1231
1232 return taskItem;
1233 }
1234
1235 private static RegionSettings BuildRegionSettings(IDataReader row)
1236 {
1237 RegionSettings newSettings = new RegionSettings();
1238
1239 newSettings.RegionUUID = DBGuid.FromDB(row["regionUUID"]);
1240 newSettings.BlockTerraform = Convert.ToBoolean(row["block_terraform"]);
1241 newSettings.AllowDamage = Convert.ToBoolean(row["allow_damage"]);
1242 newSettings.BlockFly = Convert.ToBoolean(row["block_fly"]);
1243 newSettings.RestrictPushing = Convert.ToBoolean(row["restrict_pushing"]);
1244 newSettings.AllowLandResell = Convert.ToBoolean(row["allow_land_resell"]);
1245 newSettings.AllowLandJoinDivide = Convert.ToBoolean(row["allow_land_join_divide"]);
1246 newSettings.BlockShowInSearch = Convert.ToBoolean(row["block_show_in_search"]);
1247 newSettings.AgentLimit = Convert.ToInt32(row["agent_limit"]);
1248 newSettings.ObjectBonus = Convert.ToDouble(row["object_bonus"]);
1249 newSettings.Maturity = Convert.ToInt32(row["maturity"]);
1250 newSettings.DisableScripts = Convert.ToBoolean(row["disable_scripts"]);
1251 newSettings.DisableCollisions = Convert.ToBoolean(row["disable_collisions"]);
1252 newSettings.DisablePhysics = Convert.ToBoolean(row["disable_physics"]);
1253 newSettings.TerrainTexture1 = DBGuid.FromDB(row["terrain_texture_1"]);
1254 newSettings.TerrainTexture2 = DBGuid.FromDB(row["terrain_texture_2"]);
1255 newSettings.TerrainTexture3 = DBGuid.FromDB(row["terrain_texture_3"]);
1256 newSettings.TerrainTexture4 = DBGuid.FromDB(row["terrain_texture_4"]);
1257 newSettings.Elevation1NW = Convert.ToDouble(row["elevation_1_nw"]);
1258 newSettings.Elevation2NW = Convert.ToDouble(row["elevation_2_nw"]);
1259 newSettings.Elevation1NE = Convert.ToDouble(row["elevation_1_ne"]);
1260 newSettings.Elevation2NE = Convert.ToDouble(row["elevation_2_ne"]);
1261 newSettings.Elevation1SE = Convert.ToDouble(row["elevation_1_se"]);
1262 newSettings.Elevation2SE = Convert.ToDouble(row["elevation_2_se"]);
1263 newSettings.Elevation1SW = Convert.ToDouble(row["elevation_1_sw"]);
1264 newSettings.Elevation2SW = Convert.ToDouble(row["elevation_2_sw"]);
1265 newSettings.WaterHeight = Convert.ToDouble(row["water_height"]);
1266 newSettings.TerrainRaiseLimit = Convert.ToDouble(row["terrain_raise_limit"]);
1267 newSettings.TerrainLowerLimit = Convert.ToDouble(row["terrain_lower_limit"]);
1268 newSettings.UseEstateSun = Convert.ToBoolean(row["use_estate_sun"]);
1269 newSettings.Sandbox = Convert.ToBoolean(row["sandbox"]);
1270 newSettings.SunVector = new Vector3 (
1271 Convert.ToSingle(row["sunvectorx"]),
1272 Convert.ToSingle(row["sunvectory"]),
1273 Convert.ToSingle(row["sunvectorz"])
1274 );
1275 newSettings.FixedSun = Convert.ToBoolean(row["fixed_sun"]);
1276 newSettings.SunPosition = Convert.ToDouble(row["sun_position"]);
1277 newSettings.Covenant = DBGuid.FromDB(row["covenant"]);
1278
1279 newSettings.LoadedCreationDateTime = Convert.ToInt32(row["loaded_creation_datetime"]);
1280
1281 if (row["loaded_creation_id"] is DBNull)
1282 newSettings.LoadedCreationID = "";
1283 else
1284 newSettings.LoadedCreationID = (String) row["loaded_creation_id"];
1285
1286 newSettings.TerrainImageID = DBGuid.FromDB(row["map_tile_ID"]);
1287
1288 return newSettings;
1289 }
1290
1291 /// <summary>
1292 ///
1293 /// </summary>
1294 /// <param name="row"></param>
1295 /// <returns></returns>
1296 private static LandData BuildLandData(IDataReader row)
1297 {
1298 LandData newData = new LandData();
1299
1300 newData.GlobalID = DBGuid.FromDB(row["UUID"]);
1301 newData.LocalID = Convert.ToInt32(row["LocalLandID"]);
1302
1303 // Bitmap is a byte[512]
1304 newData.Bitmap = (Byte[]) row["Bitmap"];
1305
1306 newData.Name = (String) row["Name"];
1307 newData.Description = (String) row["Description"];
1308 newData.OwnerID = DBGuid.FromDB(row["OwnerUUID"]);
1309 newData.IsGroupOwned = Convert.ToBoolean(row["IsGroupOwned"]);
1310 newData.Area = Convert.ToInt32(row["Area"]);
1311 newData.AuctionID = Convert.ToUInt32(row["AuctionID"]); //Unimplemented
1312 newData.Category = (ParcelCategory) Convert.ToInt32(row["Category"]);
1313 //Enum libsecondlife.Parcel.ParcelCategory
1314 newData.ClaimDate = Convert.ToInt32(row["ClaimDate"]);
1315 newData.ClaimPrice = Convert.ToInt32(row["ClaimPrice"]);
1316 newData.GroupID = DBGuid.FromDB(row["GroupUUID"]);
1317 newData.SalePrice = Convert.ToInt32(row["SalePrice"]);
1318 newData.Status = (ParcelStatus) Convert.ToInt32(row["LandStatus"]);
1319 //Enum. libsecondlife.Parcel.ParcelStatus
1320 newData.Flags = Convert.ToUInt32(row["LandFlags"]);
1321 newData.LandingType = Convert.ToByte(row["LandingType"]);
1322 newData.MediaAutoScale = Convert.ToByte(row["MediaAutoScale"]);
1323 newData.MediaID = DBGuid.FromDB(row["MediaTextureUUID"]);
1324 newData.MediaURL = (String) row["MediaURL"];
1325 newData.MusicURL = (String) row["MusicURL"];
1326 newData.PassHours = Convert.ToSingle(row["PassHours"]);
1327 newData.PassPrice = Convert.ToInt32(row["PassPrice"]);
1328 UUID authedbuyer = UUID.Zero;
1329 UUID snapshotID = UUID.Zero;
1330
1331 UUID.TryParse((string)row["AuthBuyerID"], out authedbuyer);
1332 UUID.TryParse((string)row["SnapshotUUID"], out snapshotID);
1333 newData.OtherCleanTime = Convert.ToInt32(row["OtherCleanTime"]);
1334
1335 newData.AuthBuyerID = authedbuyer;
1336 newData.SnapshotID = snapshotID;
1337 try
1338 {
1339 newData.UserLocation =
1340 new Vector3(Convert.ToSingle(row["UserLocationX"]), Convert.ToSingle(row["UserLocationY"]),
1341 Convert.ToSingle(row["UserLocationZ"]));
1342 newData.UserLookAt =
1343 new Vector3(Convert.ToSingle(row["UserLookAtX"]), Convert.ToSingle(row["UserLookAtY"]),
1344 Convert.ToSingle(row["UserLookAtZ"]));
1345 }
1346 catch (InvalidCastException)
1347 {
1348 newData.UserLocation = Vector3.Zero;
1349 newData.UserLookAt = Vector3.Zero;
1350 m_log.ErrorFormat("[PARCEL]: unable to get parcel telehub settings for {1}", newData.Name);
1351 }
1352
1353 newData.MediaDescription = (string) row["MediaDescription"];
1354 newData.MediaType = (string) row["MediaType"];
1355 newData.MediaWidth = Convert.ToInt32((((string) row["MediaSize"]).Split(','))[0]);
1356 newData.MediaHeight = Convert.ToInt32((((string) row["MediaSize"]).Split(','))[1]);
1357 newData.MediaLoop = Convert.ToBoolean(row["MediaLoop"]);
1358 newData.ObscureMusic = Convert.ToBoolean(row["ObscureMusic"]);
1359 newData.ObscureMedia = Convert.ToBoolean(row["ObscureMedia"]);
1360
1361 newData.ParcelAccessList = new List<ParcelManager.ParcelAccessEntry>();
1362
1363 return newData;
1364 }
1365
1366 /// <summary>
1367 ///
1368 /// </summary>
1369 /// <param name="row"></param>
1370 /// <returns></returns>
1371 private static ParcelManager.ParcelAccessEntry BuildLandAccessData(IDataReader row)
1372 {
1373 ParcelManager.ParcelAccessEntry entry = new ParcelManager.ParcelAccessEntry();
1374 entry.AgentID = DBGuid.FromDB(row["AccessUUID"]);
1375 entry.Flags = (AccessList) Convert.ToInt32(row["Flags"]);
1376 entry.Time = new DateTime();
1377 return entry;
1378 }
1379
1380 /// <summary>
1381 ///
1382 /// </summary>
1383 /// <param name="val"></param>
1384 /// <returns></returns>
1385 private static Array SerializeTerrain(double[,] val)
1386 {
1387 MemoryStream str = new MemoryStream(((int)Constants.RegionSize * (int)Constants.RegionSize) *sizeof (double));
1388 BinaryWriter bw = new BinaryWriter(str);
1389
1390 // TODO: COMPATIBILITY - Add byte-order conversions
1391 for (int x = 0; x < (int)Constants.RegionSize; x++)
1392 for (int y = 0; y < (int)Constants.RegionSize; y++)
1393 {
1394 double height = val[x, y];
1395 if (height == 0.0)
1396 height = double.Epsilon;
1397
1398 bw.Write(height);
1399 }
1400
1401 return str.ToArray();
1402 }
1403
1404 /// <summary>
1405 /// Fill the prim command with prim values
1406 /// </summary>
1407 /// <param name="row"></param>
1408 /// <param name="prim"></param>
1409 /// <param name="sceneGroupID"></param>
1410 /// <param name="regionUUID"></param>
1411 private void FillPrimCommand(MySqlCommand cmd, SceneObjectPart prim, UUID sceneGroupID, UUID regionUUID)
1412 {
1413 cmd.Parameters.AddWithValue("UUID", prim.UUID.ToString());
1414 cmd.Parameters.AddWithValue("RegionUUID", regionUUID.ToString());
1415 cmd.Parameters.AddWithValue("CreationDate", prim.CreationDate);
1416 cmd.Parameters.AddWithValue("Name", prim.Name);
1417 cmd.Parameters.AddWithValue("SceneGroupID", sceneGroupID.ToString());
1418 // the UUID of the root part for this SceneObjectGroup
1419 // various text fields
1420 cmd.Parameters.AddWithValue("Text", prim.Text);
1421 cmd.Parameters.AddWithValue("ColorR", prim.Color.R);
1422 cmd.Parameters.AddWithValue("ColorG", prim.Color.G);
1423 cmd.Parameters.AddWithValue("ColorB", prim.Color.B);
1424 cmd.Parameters.AddWithValue("ColorA", prim.Color.A);
1425 cmd.Parameters.AddWithValue("Description", prim.Description);
1426 cmd.Parameters.AddWithValue("SitName", prim.SitName);
1427 cmd.Parameters.AddWithValue("TouchName", prim.TouchName);
1428 // permissions
1429 cmd.Parameters.AddWithValue("ObjectFlags", (uint)prim.Flags);
1430 cmd.Parameters.AddWithValue("CreatorID", prim.CreatorID.ToString());
1431 cmd.Parameters.AddWithValue("OwnerID", prim.OwnerID.ToString());
1432 cmd.Parameters.AddWithValue("GroupID", prim.GroupID.ToString());
1433 cmd.Parameters.AddWithValue("LastOwnerID", prim.LastOwnerID.ToString());
1434 cmd.Parameters.AddWithValue("OwnerMask", prim.OwnerMask);
1435 cmd.Parameters.AddWithValue("NextOwnerMask", prim.NextOwnerMask);
1436 cmd.Parameters.AddWithValue("GroupMask", prim.GroupMask);
1437 cmd.Parameters.AddWithValue("EveryoneMask", prim.EveryoneMask);
1438 cmd.Parameters.AddWithValue("BaseMask", prim.BaseMask);
1439 // vectors
1440 cmd.Parameters.AddWithValue("PositionX", (double)prim.OffsetPosition.X);
1441 cmd.Parameters.AddWithValue("PositionY", (double)prim.OffsetPosition.Y);
1442 cmd.Parameters.AddWithValue("PositionZ", (double)prim.OffsetPosition.Z);
1443 cmd.Parameters.AddWithValue("GroupPositionX", (double)prim.GroupPosition.X);
1444 cmd.Parameters.AddWithValue("GroupPositionY", (double)prim.GroupPosition.Y);
1445 cmd.Parameters.AddWithValue("GroupPositionZ", (double)prim.GroupPosition.Z);
1446 cmd.Parameters.AddWithValue("VelocityX", (double)prim.Velocity.X);
1447 cmd.Parameters.AddWithValue("VelocityY", (double)prim.Velocity.Y);
1448 cmd.Parameters.AddWithValue("VelocityZ", (double)prim.Velocity.Z);
1449 cmd.Parameters.AddWithValue("AngularVelocityX", (double)prim.AngularVelocity.X);
1450 cmd.Parameters.AddWithValue("AngularVelocityY", (double)prim.AngularVelocity.Y);
1451 cmd.Parameters.AddWithValue("AngularVelocityZ", (double)prim.AngularVelocity.Z);
1452 cmd.Parameters.AddWithValue("AccelerationX", (double)prim.Acceleration.X);
1453 cmd.Parameters.AddWithValue("AccelerationY", (double)prim.Acceleration.Y);
1454 cmd.Parameters.AddWithValue("AccelerationZ", (double)prim.Acceleration.Z);
1455 // quaternions
1456 cmd.Parameters.AddWithValue("RotationX", (double)prim.RotationOffset.X);
1457 cmd.Parameters.AddWithValue("RotationY", (double)prim.RotationOffset.Y);
1458 cmd.Parameters.AddWithValue("RotationZ", (double)prim.RotationOffset.Z);
1459 cmd.Parameters.AddWithValue("RotationW", (double)prim.RotationOffset.W);
1460
1461 // Sit target
1462 Vector3 sitTargetPos = prim.SitTargetPositionLL;
1463 cmd.Parameters.AddWithValue("SitTargetOffsetX", (double)sitTargetPos.X);
1464 cmd.Parameters.AddWithValue("SitTargetOffsetY", (double)sitTargetPos.Y);
1465 cmd.Parameters.AddWithValue("SitTargetOffsetZ", (double)sitTargetPos.Z);
1466
1467 Quaternion sitTargetOrient = prim.SitTargetOrientationLL;
1468 cmd.Parameters.AddWithValue("SitTargetOrientW", (double)sitTargetOrient.W);
1469 cmd.Parameters.AddWithValue("SitTargetOrientX", (double)sitTargetOrient.X);
1470 cmd.Parameters.AddWithValue("SitTargetOrientY", (double)sitTargetOrient.Y);
1471 cmd.Parameters.AddWithValue("SitTargetOrientZ", (double)sitTargetOrient.Z);
1472
1473 cmd.Parameters.AddWithValue("PayPrice", prim.PayPrice[0]);
1474 cmd.Parameters.AddWithValue("PayButton1", prim.PayPrice[1]);
1475 cmd.Parameters.AddWithValue("PayButton2", prim.PayPrice[2]);
1476 cmd.Parameters.AddWithValue("PayButton3", prim.PayPrice[3]);
1477 cmd.Parameters.AddWithValue("PayButton4", prim.PayPrice[4]);
1478
1479 if ((prim.SoundFlags & 1) != 0) // Looped
1480 {
1481 cmd.Parameters.AddWithValue("LoopedSound", prim.Sound.ToString());
1482 cmd.Parameters.AddWithValue("LoopedSoundGain", prim.SoundGain);
1483 }
1484 else
1485 {
1486 cmd.Parameters.AddWithValue("LoopedSound", UUID.Zero);
1487 cmd.Parameters.AddWithValue("LoopedSoundGain", 0.0f);
1488 }
1489
1490 cmd.Parameters.AddWithValue("TextureAnimation", prim.TextureAnimation);
1491 cmd.Parameters.AddWithValue("ParticleSystem", prim.ParticleSystem);
1492
1493 cmd.Parameters.AddWithValue("OmegaX", (double)prim.AngularVelocity.X);
1494 cmd.Parameters.AddWithValue("OmegaY", (double)prim.AngularVelocity.Y);
1495 cmd.Parameters.AddWithValue("OmegaZ", (double)prim.AngularVelocity.Z);
1496
1497 cmd.Parameters.AddWithValue("CameraEyeOffsetX", (double)prim.GetCameraEyeOffset().X);
1498 cmd.Parameters.AddWithValue("CameraEyeOffsetY", (double)prim.GetCameraEyeOffset().Y);
1499 cmd.Parameters.AddWithValue("CameraEyeOffsetZ", (double)prim.GetCameraEyeOffset().Z);
1500
1501 cmd.Parameters.AddWithValue("CameraAtOffsetX", (double)prim.GetCameraAtOffset().X);
1502 cmd.Parameters.AddWithValue("CameraAtOffsetY", (double)prim.GetCameraAtOffset().Y);
1503 cmd.Parameters.AddWithValue("CameraAtOffsetZ", (double)prim.GetCameraAtOffset().Z);
1504
1505 if (prim.GetForceMouselook())
1506 cmd.Parameters.AddWithValue("ForceMouselook", 1);
1507 else
1508 cmd.Parameters.AddWithValue("ForceMouselook", 0);
1509
1510 cmd.Parameters.AddWithValue("ScriptAccessPin", prim.ScriptAccessPin);
1511
1512 if (prim.AllowedDrop)
1513 cmd.Parameters.AddWithValue("AllowedDrop", 1);
1514 else
1515 cmd.Parameters.AddWithValue("AllowedDrop", 0);
1516
1517 if (prim.DIE_AT_EDGE)
1518 cmd.Parameters.AddWithValue("DieAtEdge", 1);
1519 else
1520 cmd.Parameters.AddWithValue("DieAtEdge", 0);
1521
1522 cmd.Parameters.AddWithValue("SalePrice", prim.SalePrice);
1523 cmd.Parameters.AddWithValue("SaleType", unchecked((sbyte)(prim.ObjectSaleType)));
1524
1525 byte clickAction = prim.ClickAction;
1526 cmd.Parameters.AddWithValue("ClickAction", unchecked((sbyte)(clickAction)));
1527
1528 cmd.Parameters.AddWithValue("Material", unchecked((sbyte)(prim.Material)));
1529
1530 cmd.Parameters.AddWithValue("CollisionSound", prim.CollisionSound.ToString());
1531 cmd.Parameters.AddWithValue("CollisionSoundVolume", prim.CollisionSoundVolume);
1532
1533 if (prim.PassTouches)
1534 cmd.Parameters.AddWithValue("PassTouches", 1);
1535 else
1536 cmd.Parameters.AddWithValue("PassTouches", 0);
1537
1538 cmd.Parameters.AddWithValue("LinkNumber", prim.LinkNum);
1539 cmd.Parameters.AddWithValue("MediaURL", prim.MediaUrl);
1540 }
1541
1542 /// <summary>
1543 ///
1544 /// </summary>
1545 /// <param name="row"></param>
1546 /// <param name="taskItem"></param>
1547 private static void FillItemCommand(MySqlCommand cmd, TaskInventoryItem taskItem)
1548 {
1549 cmd.Parameters.AddWithValue("itemID", taskItem.ItemID);
1550 cmd.Parameters.AddWithValue("primID", taskItem.ParentPartID);
1551 cmd.Parameters.AddWithValue("assetID", taskItem.AssetID);
1552 cmd.Parameters.AddWithValue("parentFolderID", taskItem.ParentID);
1553
1554 cmd.Parameters.AddWithValue("invType", taskItem.InvType);
1555 cmd.Parameters.AddWithValue("assetType", taskItem.Type);
1556
1557 cmd.Parameters.AddWithValue("name", taskItem.Name);
1558 cmd.Parameters.AddWithValue("description", taskItem.Description);
1559 cmd.Parameters.AddWithValue("creationDate", taskItem.CreationDate);
1560 cmd.Parameters.AddWithValue("creatorID", taskItem.CreatorID);
1561 cmd.Parameters.AddWithValue("ownerID", taskItem.OwnerID);
1562 cmd.Parameters.AddWithValue("lastOwnerID", taskItem.LastOwnerID);
1563 cmd.Parameters.AddWithValue("groupID", taskItem.GroupID);
1564 cmd.Parameters.AddWithValue("nextPermissions", taskItem.NextPermissions);
1565 cmd.Parameters.AddWithValue("currentPermissions", taskItem.CurrentPermissions);
1566 cmd.Parameters.AddWithValue("basePermissions", taskItem.BasePermissions);
1567 cmd.Parameters.AddWithValue("everyonePermissions", taskItem.EveryonePermissions);
1568 cmd.Parameters.AddWithValue("groupPermissions", taskItem.GroupPermissions);
1569 cmd.Parameters.AddWithValue("flags", taskItem.Flags);
1570 }
1571
1572 /// <summary>
1573 ///
1574 /// </summary>
1575 private static void FillRegionSettingsCommand(MySqlCommand cmd, RegionSettings settings)
1576 {
1577 cmd.Parameters.AddWithValue("RegionUUID", settings.RegionUUID.ToString());
1578 cmd.Parameters.AddWithValue("BlockTerraform", settings.BlockTerraform);
1579 cmd.Parameters.AddWithValue("BlockFly", settings.BlockFly);
1580 cmd.Parameters.AddWithValue("AllowDamage", settings.AllowDamage);
1581 cmd.Parameters.AddWithValue("RestrictPushing", settings.RestrictPushing);
1582 cmd.Parameters.AddWithValue("AllowLandResell", settings.AllowLandResell);
1583 cmd.Parameters.AddWithValue("AllowLandJoinDivide", settings.AllowLandJoinDivide);
1584 cmd.Parameters.AddWithValue("BlockShowInSearch", settings.BlockShowInSearch);
1585 cmd.Parameters.AddWithValue("AgentLimit", settings.AgentLimit);
1586 cmd.Parameters.AddWithValue("ObjectBonus", settings.ObjectBonus);
1587 cmd.Parameters.AddWithValue("Maturity", settings.Maturity);
1588 cmd.Parameters.AddWithValue("DisableScripts", settings.DisableScripts);
1589 cmd.Parameters.AddWithValue("DisableCollisions", settings.DisableCollisions);
1590 cmd.Parameters.AddWithValue("DisablePhysics", settings.DisablePhysics);
1591 cmd.Parameters.AddWithValue("TerrainTexture1", settings.TerrainTexture1.ToString());
1592 cmd.Parameters.AddWithValue("TerrainTexture2", settings.TerrainTexture2.ToString());
1593 cmd.Parameters.AddWithValue("TerrainTexture3", settings.TerrainTexture3.ToString());
1594 cmd.Parameters.AddWithValue("TerrainTexture4", settings.TerrainTexture4.ToString());
1595 cmd.Parameters.AddWithValue("Elevation1NW", settings.Elevation1NW);
1596 cmd.Parameters.AddWithValue("Elevation2NW", settings.Elevation2NW);
1597 cmd.Parameters.AddWithValue("Elevation1NE", settings.Elevation1NE);
1598 cmd.Parameters.AddWithValue("Elevation2NE", settings.Elevation2NE);
1599 cmd.Parameters.AddWithValue("Elevation1SE", settings.Elevation1SE);
1600 cmd.Parameters.AddWithValue("Elevation2SE", settings.Elevation2SE);
1601 cmd.Parameters.AddWithValue("Elevation1SW", settings.Elevation1SW);
1602 cmd.Parameters.AddWithValue("Elevation2SW", settings.Elevation2SW);
1603 cmd.Parameters.AddWithValue("WaterHeight", settings.WaterHeight);
1604 cmd.Parameters.AddWithValue("TerrainRaiseLimit", settings.TerrainRaiseLimit);
1605 cmd.Parameters.AddWithValue("TerrainLowerLimit", settings.TerrainLowerLimit);
1606 cmd.Parameters.AddWithValue("UseEstateSun", settings.UseEstateSun);
1607 cmd.Parameters.AddWithValue("Sandbox", settings.Sandbox);
1608 cmd.Parameters.AddWithValue("SunVectorX", settings.SunVector.X);
1609 cmd.Parameters.AddWithValue("SunVectorY", settings.SunVector.Y);
1610 cmd.Parameters.AddWithValue("SunVectorZ", settings.SunVector.Z);
1611 cmd.Parameters.AddWithValue("FixedSun", settings.FixedSun);
1612 cmd.Parameters.AddWithValue("SunPosition", settings.SunPosition);
1613 cmd.Parameters.AddWithValue("Covenant", settings.Covenant.ToString());
1614 cmd.Parameters.AddWithValue("LoadedCreationDateTime", settings.LoadedCreationDateTime);
1615 cmd.Parameters.AddWithValue("LoadedCreationID", settings.LoadedCreationID);
1616 cmd.Parameters.AddWithValue("TerrainImageID", settings.TerrainImageID);
1617
1618 }
1619
1620 /// <summary>
1621 ///
1622 /// </summary>
1623 /// <param name="row"></param>
1624 /// <param name="land"></param>
1625 /// <param name="regionUUID"></param>
1626 private static void FillLandCommand(MySqlCommand cmd, LandData land, UUID regionUUID)
1627 {
1628 cmd.Parameters.AddWithValue("UUID", land.GlobalID.ToString());
1629 cmd.Parameters.AddWithValue("RegionUUID", regionUUID.ToString());
1630 cmd.Parameters.AddWithValue("LocalLandID", land.LocalID);
1631
1632 // Bitmap is a byte[512]
1633 cmd.Parameters.AddWithValue("Bitmap", land.Bitmap);
1634
1635 cmd.Parameters.AddWithValue("Name", land.Name);
1636 cmd.Parameters.AddWithValue("Description", land.Description);
1637 cmd.Parameters.AddWithValue("OwnerUUID", land.OwnerID.ToString());
1638 cmd.Parameters.AddWithValue("IsGroupOwned", land.IsGroupOwned);
1639 cmd.Parameters.AddWithValue("Area", land.Area);
1640 cmd.Parameters.AddWithValue("AuctionID", land.AuctionID); //Unemplemented
1641 cmd.Parameters.AddWithValue("Category", land.Category); //Enum libsecondlife.Parcel.ParcelCategory
1642 cmd.Parameters.AddWithValue("ClaimDate", land.ClaimDate);
1643 cmd.Parameters.AddWithValue("ClaimPrice", land.ClaimPrice);
1644 cmd.Parameters.AddWithValue("GroupUUID", land.GroupID.ToString());
1645 cmd.Parameters.AddWithValue("SalePrice", land.SalePrice);
1646 cmd.Parameters.AddWithValue("LandStatus", land.Status); //Enum. libsecondlife.Parcel.ParcelStatus
1647 cmd.Parameters.AddWithValue("LandFlags", land.Flags);
1648 cmd.Parameters.AddWithValue("LandingType", land.LandingType);
1649 cmd.Parameters.AddWithValue("MediaAutoScale", land.MediaAutoScale);
1650 cmd.Parameters.AddWithValue("MediaTextureUUID", land.MediaID.ToString());
1651 cmd.Parameters.AddWithValue("MediaURL", land.MediaURL);
1652 cmd.Parameters.AddWithValue("MusicURL", land.MusicURL);
1653 cmd.Parameters.AddWithValue("PassHours", land.PassHours);
1654 cmd.Parameters.AddWithValue("PassPrice", land.PassPrice);
1655 cmd.Parameters.AddWithValue("SnapshotUUID", land.SnapshotID.ToString());
1656 cmd.Parameters.AddWithValue("UserLocationX", land.UserLocation.X);
1657 cmd.Parameters.AddWithValue("UserLocationY", land.UserLocation.Y);
1658 cmd.Parameters.AddWithValue("UserLocationZ", land.UserLocation.Z);
1659 cmd.Parameters.AddWithValue("UserLookAtX", land.UserLookAt.X);
1660 cmd.Parameters.AddWithValue("UserLookAtY", land.UserLookAt.Y);
1661 cmd.Parameters.AddWithValue("UserLookAtZ", land.UserLookAt.Z);
1662 cmd.Parameters.AddWithValue("AuthBuyerID", land.AuthBuyerID);
1663 cmd.Parameters.AddWithValue("OtherCleanTime", land.OtherCleanTime);
1664 cmd.Parameters.AddWithValue("MediaDescription", land.MediaDescription);
1665 cmd.Parameters.AddWithValue("MediaType", land.MediaType);
1666 cmd.Parameters.AddWithValue("MediaWidth", land.MediaWidth);
1667 cmd.Parameters.AddWithValue("MediaHeight", land.MediaHeight);
1668 cmd.Parameters.AddWithValue("MediaLoop", land.MediaLoop);
1669 cmd.Parameters.AddWithValue("ObscureMusic", land.ObscureMusic);
1670 cmd.Parameters.AddWithValue("ObscureMedia", land.ObscureMedia);
1671
1672 }
1673
1674 /// <summary>
1675 ///
1676 /// </summary>
1677 /// <param name="row"></param>
1678 /// <param name="entry"></param>
1679 /// <param name="parcelID"></param>
1680 private static void FillLandAccessCommand(MySqlCommand cmd, ParcelManager.ParcelAccessEntry entry, UUID parcelID)
1681 {
1682 cmd.Parameters.AddWithValue("LandUUID", parcelID.ToString());
1683 cmd.Parameters.AddWithValue("AccessUUID", entry.AgentID.ToString());
1684 cmd.Parameters.AddWithValue("Flags", entry.Flags);
1685 }
1686
1687 /// <summary>
1688 ///
1689 /// </summary>
1690 /// <param name="row"></param>
1691 /// <returns></returns>
1692 private PrimitiveBaseShape BuildShape(IDataReader row)
1693 {
1694 PrimitiveBaseShape s = new PrimitiveBaseShape();
1695 s.Scale = new Vector3(
1696 (float)(double)row["ScaleX"],
1697 (float)(double)row["ScaleY"],
1698 (float)(double)row["ScaleZ"]
1699 );
1700 // paths
1701 s.PCode = (byte)(int)row["PCode"];
1702 s.PathBegin = (ushort)(int)row["PathBegin"];
1703 s.PathEnd = (ushort)(int)row["PathEnd"];
1704 s.PathScaleX = (byte)(int)row["PathScaleX"];
1705 s.PathScaleY = (byte)(int)row["PathScaleY"];
1706 s.PathShearX = (byte)(int)row["PathShearX"];
1707 s.PathShearY = (byte)(int)row["PathShearY"];
1708 s.PathSkew = (sbyte)(int)row["PathSkew"];
1709 s.PathCurve = (byte)(int)row["PathCurve"];
1710 s.PathRadiusOffset = (sbyte)(int)row["PathRadiusOffset"];
1711 s.PathRevolutions = (byte)(int)row["PathRevolutions"];
1712 s.PathTaperX = (sbyte)(int)row["PathTaperX"];
1713 s.PathTaperY = (sbyte)(int)row["PathTaperY"];
1714 s.PathTwist = (sbyte)(int)row["PathTwist"];
1715 s.PathTwistBegin = (sbyte)(int)row["PathTwistBegin"];
1716 // profile
1717 s.ProfileBegin = (ushort)(int)row["ProfileBegin"];
1718 s.ProfileEnd = (ushort)(int)row["ProfileEnd"];
1719 s.ProfileCurve = (byte)(int)row["ProfileCurve"];
1720 s.ProfileHollow = (ushort)(int)row["ProfileHollow"];
1721 s.TextureEntry = (byte[])row["Texture"];
1722
1723 s.ExtraParams = (byte[])row["ExtraParams"];
1724
1725 s.State = (byte)(int)row["State"];
1726
1727 if (!(row["Media"] is System.DBNull))
1728 s.Media = PrimitiveBaseShape.MediaList.FromXml((string)row["Media"]);
1729
1730 return s;
1731 }
1732
1733 /// <summary>
1734 ///
1735 /// </summary>
1736 /// <param name="row"></param>
1737 /// <param name="prim"></param>
1738 private void FillShapeCommand(MySqlCommand cmd, SceneObjectPart prim)
1739 {
1740 PrimitiveBaseShape s = prim.Shape;
1741 cmd.Parameters.AddWithValue("UUID", prim.UUID.ToString());
1742 // shape is an enum
1743 cmd.Parameters.AddWithValue("Shape", 0);
1744 // vectors
1745 cmd.Parameters.AddWithValue("ScaleX", (double)s.Scale.X);
1746 cmd.Parameters.AddWithValue("ScaleY", (double)s.Scale.Y);
1747 cmd.Parameters.AddWithValue("ScaleZ", (double)s.Scale.Z);
1748 // paths
1749 cmd.Parameters.AddWithValue("PCode", s.PCode);
1750 cmd.Parameters.AddWithValue("PathBegin", s.PathBegin);
1751 cmd.Parameters.AddWithValue("PathEnd", s.PathEnd);
1752 cmd.Parameters.AddWithValue("PathScaleX", s.PathScaleX);
1753 cmd.Parameters.AddWithValue("PathScaleY", s.PathScaleY);
1754 cmd.Parameters.AddWithValue("PathShearX", s.PathShearX);
1755 cmd.Parameters.AddWithValue("PathShearY", s.PathShearY);
1756 cmd.Parameters.AddWithValue("PathSkew", s.PathSkew);
1757 cmd.Parameters.AddWithValue("PathCurve", s.PathCurve);
1758 cmd.Parameters.AddWithValue("PathRadiusOffset", s.PathRadiusOffset);
1759 cmd.Parameters.AddWithValue("PathRevolutions", s.PathRevolutions);
1760 cmd.Parameters.AddWithValue("PathTaperX", s.PathTaperX);
1761 cmd.Parameters.AddWithValue("PathTaperY", s.PathTaperY);
1762 cmd.Parameters.AddWithValue("PathTwist", s.PathTwist);
1763 cmd.Parameters.AddWithValue("PathTwistBegin", s.PathTwistBegin);
1764 // profile
1765 cmd.Parameters.AddWithValue("ProfileBegin", s.ProfileBegin);
1766 cmd.Parameters.AddWithValue("ProfileEnd", s.ProfileEnd);
1767 cmd.Parameters.AddWithValue("ProfileCurve", s.ProfileCurve);
1768 cmd.Parameters.AddWithValue("ProfileHollow", s.ProfileHollow);
1769 cmd.Parameters.AddWithValue("Texture", s.TextureEntry);
1770 cmd.Parameters.AddWithValue("ExtraParams", s.ExtraParams);
1771 cmd.Parameters.AddWithValue("State", s.State);
1772 cmd.Parameters.AddWithValue("Media", null == s.Media ? null : s.Media.ToXml());
1773 }
1774
1775 public void StorePrimInventory(UUID primID, ICollection<TaskInventoryItem> items)
1776 {
1777 lock (m_dbLock)
1778 {
1779 RemoveItems(primID);
1780
1781 using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
1782 {
1783 dbcon.Open();
1784
1785 MySqlCommand cmd = dbcon.CreateCommand();
1786
1787 if (items.Count == 0)
1788 return;
1789
1790 cmd.CommandText = "insert into primitems (" +
1791 "invType, assetType, name, " +
1792 "description, creationDate, nextPermissions, " +
1793 "currentPermissions, basePermissions, " +
1794 "everyonePermissions, groupPermissions, " +
1795 "flags, itemID, primID, assetID, " +
1796 "parentFolderID, creatorID, ownerID, " +
1797 "groupID, lastOwnerID) values (?invType, " +
1798 "?assetType, ?name, ?description, " +
1799 "?creationDate, ?nextPermissions, " +
1800 "?currentPermissions, ?basePermissions, " +
1801 "?everyonePermissions, ?groupPermissions, " +
1802 "?flags, ?itemID, ?primID, ?assetID, " +
1803 "?parentFolderID, ?creatorID, ?ownerID, " +
1804 "?groupID, ?lastOwnerID)";
1805
1806 foreach (TaskInventoryItem item in items)
1807 {
1808 cmd.Parameters.Clear();
1809
1810 FillItemCommand(cmd, item);
1811
1812 ExecuteNonQuery(cmd);
1813 }
1814
1815 cmd.Dispose();
1816 }
1817 }
1818 }
1819 }
1820}