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