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