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