aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Data/MSSQL/MSSQLLegacyRegionData.cs
diff options
context:
space:
mode:
authorunknown2009-10-05 17:04:36 +0100
committerMelanie2009-10-05 16:08:35 +0100
commit7c3e5afc0c983e490401253e16c49ff401e61b65 (patch)
treeab79044f36f2ed16a18a0d561682c23f9d9f5fee /OpenSim/Data/MSSQL/MSSQLLegacyRegionData.cs
parentEliminate pinned Mesh data on managed heap by using IntPtrs to memory allocat... (diff)
downloadopensim-SC-7c3e5afc0c983e490401253e16c49ff401e61b65.zip
opensim-SC-7c3e5afc0c983e490401253e16c49ff401e61b65.tar.gz
opensim-SC-7c3e5afc0c983e490401253e16c49ff401e61b65.tar.bz2
opensim-SC-7c3e5afc0c983e490401253e16c49ff401e61b65.tar.xz
MSSQL changes for Grid server in ROBUST plus some code tweaks 'n tidy up
Diffstat (limited to '')
-rw-r--r--OpenSim/Data/MSSQL/MSSQLLegacyRegionData.cs1531
1 files changed, 1531 insertions, 0 deletions
diff --git a/OpenSim/Data/MSSQL/MSSQLLegacyRegionData.cs b/OpenSim/Data/MSSQL/MSSQLLegacyRegionData.cs
new file mode 100644
index 0000000..adedcce
--- /dev/null
+++ b/OpenSim/Data/MSSQL/MSSQLLegacyRegionData.cs
@@ -0,0 +1,1531 @@
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 MSSQLRegionDataStore : IRegionDataStore
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
58 /// <summary>
59 /// Initialises the region datastore
60 /// </summary>
61 /// <param name="connectionString">The connection string.</param>
62 public void Initialise(string connectionString)
63 {
64 if (!string.IsNullOrEmpty(connectionString))
65 {
66 _Database = new MSSQLManager(connectionString);
67 }
68 else
69 {
70 IniFile iniFile = new IniFile("mssql_connection.ini");
71 string settingDataSource = iniFile.ParseFileReadValue("data_source");
72 string settingInitialCatalog = iniFile.ParseFileReadValue("initial_catalog");
73 string settingPersistSecurityInfo = iniFile.ParseFileReadValue("persist_security_info");
74 string settingUserId = iniFile.ParseFileReadValue("user_id");
75 string settingPassword = iniFile.ParseFileReadValue("password");
76
77 _Database = new MSSQLManager(settingDataSource, settingInitialCatalog, settingPersistSecurityInfo, settingUserId, settingPassword);
78 }
79
80 //Migration settings
81 _Database.CheckMigration(_migrationStore);
82 }
83
84 /// <summary>
85 /// Dispose the database
86 /// </summary>
87 public void Dispose() { }
88
89 #region SceneObjectGroup region for loading and Store of the scene.
90
91 /// <summary>
92 /// Loads the objects present in the region.
93 /// </summary>
94 /// <param name="regionUUID">The region UUID.</param>
95 /// <returns></returns>
96 public List<SceneObjectGroup> LoadObjects(UUID regionUUID)
97 {
98 UUID lastGroupID = UUID.Zero;
99
100 Dictionary<UUID, SceneObjectPart> prims = new Dictionary<UUID, SceneObjectPart>();
101 Dictionary<UUID, SceneObjectGroup> objects = new Dictionary<UUID, SceneObjectGroup>();
102 SceneObjectGroup grp = null;
103
104
105 string query = "SELECT *, " +
106 "sort = CASE WHEN prims.UUID = prims.SceneGroupID THEN 0 ELSE 1 END " +
107 "FROM prims " +
108 "LEFT JOIN primshapes ON prims.UUID = primshapes.UUID " +
109 "WHERE RegionUUID = @RegionUUID " +
110 "ORDER BY SceneGroupID asc, sort asc, LinkNumber asc";
111
112 using (AutoClosingSqlCommand command = _Database.Query(query))
113 {
114 command.Parameters.Add(_Database.CreateParameter("@regionUUID", regionUUID));
115
116 using (SqlDataReader reader = command.ExecuteReader())
117 {
118 while (reader.Read())
119 {
120 SceneObjectPart sceneObjectPart = BuildPrim(reader);
121 if (reader["Shape"] is DBNull)
122 sceneObjectPart.Shape = PrimitiveBaseShape.Default;
123 else
124 sceneObjectPart.Shape = BuildShape(reader);
125
126 prims[sceneObjectPart.UUID] = sceneObjectPart;
127
128 UUID groupID = new UUID((Guid)reader["SceneGroupID"]);
129
130 if (groupID != lastGroupID) // New SOG
131 {
132 if (grp != null)
133 objects[grp.UUID] = grp;
134
135 lastGroupID = groupID;
136
137 // There sometimes exist OpenSim bugs that 'orphan groups' so that none of the prims are
138 // recorded as the root prim (for which the UUID must equal the persisted group UUID). In
139 // this case, force the UUID to be the same as the group UUID so that at least these can be
140 // deleted (we need to change the UUID so that any other prims in the linkset can also be
141 // deleted).
142 if (sceneObjectPart.UUID != groupID && groupID != UUID.Zero)
143 {
144 _Log.WarnFormat(
145 "[REGION DB]: Found root prim {0} {1} at {2} where group was actually {3}. Forcing UUID to group UUID",
146 sceneObjectPart.Name, sceneObjectPart.UUID, sceneObjectPart.GroupPosition, groupID);
147
148 sceneObjectPart.UUID = groupID;
149 }
150
151 grp = new SceneObjectGroup(sceneObjectPart);
152 }
153 else
154 {
155 // Black magic to preserve link numbers
156 // Why is this needed, fix this in AddPart method.
157 int link = sceneObjectPart.LinkNum;
158
159 grp.AddPart(sceneObjectPart);
160
161 if (link != 0)
162 sceneObjectPart.LinkNum = link;
163 }
164 }
165 }
166 }
167
168 if (grp != null)
169 objects[grp.UUID] = grp;
170
171 // Instead of attempting to LoadItems on every prim,
172 // most of which probably have no items... get a
173 // list from DB of all prims which have items and
174 // LoadItems only on those
175 List<SceneObjectPart> primsWithInventory = new List<SceneObjectPart>();
176 string qry = "select distinct primID from primitems";
177 using (AutoClosingSqlCommand command = _Database.Query(qry))
178 {
179 using (SqlDataReader itemReader = command.ExecuteReader())
180 {
181 while (itemReader.Read())
182 {
183 if (!(itemReader["primID"] is DBNull))
184 {
185 UUID primID = new UUID(itemReader["primID"].ToString());
186 if (prims.ContainsKey(primID))
187 {
188 primsWithInventory.Add(prims[primID]);
189 }
190 }
191 }
192 }
193 }
194
195 LoadItems(primsWithInventory);
196
197 _Log.DebugFormat("[REGION DB]: Loaded {0} objects using {1} prims", objects.Count, prims.Count);
198
199 return new List<SceneObjectGroup>(objects.Values);
200 }
201
202 /// <summary>
203 /// Load in the prim's persisted inventory.
204 /// </summary>
205 /// <param name="allPrims">all prims with inventory on a region</param>
206 private void LoadItems(List<SceneObjectPart> allPrimsWithInventory)
207 {
208
209 using (AutoClosingSqlCommand command = _Database.Query("SELECT * FROM primitems WHERE PrimID = @PrimID"))
210 {
211 foreach (SceneObjectPart objectPart in allPrimsWithInventory)
212 {
213 command.Parameters.Clear();
214 command.Parameters.Add(_Database.CreateParameter("@PrimID", objectPart.UUID));
215
216 List<TaskInventoryItem> inventory = new List<TaskInventoryItem>();
217
218 using (SqlDataReader reader = command.ExecuteReader())
219 {
220 while (reader.Read())
221 {
222 TaskInventoryItem item = BuildItem(reader);
223
224 item.ParentID = objectPart.UUID; // Values in database are
225 // often wrong
226 inventory.Add(item);
227 }
228 }
229
230 objectPart.Inventory.RestoreInventoryItems(inventory);
231 }
232 }
233 }
234
235 /// <summary>
236 /// Stores all object's details apart from inventory
237 /// </summary>
238 /// <param name="obj"></param>
239 /// <param name="regionUUID"></param>
240 public void StoreObject(SceneObjectGroup obj, UUID regionUUID)
241 {
242 _Log.InfoFormat("[MSSQL]: Adding/Changing SceneObjectGroup: {0} to region: {1}, object has {2} prims.", obj.UUID, regionUUID, obj.Children.Count);
243
244 using (SqlConnection conn = _Database.DatabaseConnection())
245 {
246 SqlTransaction transaction = conn.BeginTransaction();
247
248 try
249 {
250 foreach (SceneObjectPart sceneObjectPart in obj.Children.Values)
251 {
252 //Update prim
253 using (SqlCommand sqlCommand = conn.CreateCommand())
254 {
255 sqlCommand.Transaction = transaction;
256 try
257 {
258 StoreSceneObjectPrim(sceneObjectPart, sqlCommand, obj.UUID, regionUUID);
259 }
260 catch (SqlException sqlEx)
261 {
262 _Log.ErrorFormat("[REGION DB]: Store SceneObjectPrim SQL error: {0} at line {1}", sqlEx.Message, sqlEx.LineNumber);
263 throw;
264 }
265 }
266
267 //Update primshapes
268 using (SqlCommand sqlCommand = conn.CreateCommand())
269 {
270 sqlCommand.Transaction = transaction;
271 try
272 {
273 StoreSceneObjectPrimShapes(sceneObjectPart, sqlCommand, obj.UUID, regionUUID);
274 }
275 catch (SqlException sqlEx)
276 {
277 _Log.ErrorFormat("[REGION DB]: Store SceneObjectPrimShapes SQL error: {0} at line {1}", sqlEx.Message, sqlEx.LineNumber);
278 throw;
279 }
280 }
281 }
282
283 transaction.Commit();
284 }
285 catch (Exception ex)
286 {
287 _Log.ErrorFormat("[REGION DB]: Store SceneObjectGroup error: {0}, Rolling back...", ex.Message);
288 try
289 {
290 transaction.Rollback();
291 }
292 catch (Exception ex2)
293 {
294 //Show error
295 _Log.InfoFormat("[REGION DB]: Rollback of SceneObjectGroup store transaction failed with error: {0}", ex2.Message);
296
297 }
298 }
299 }
300
301 }
302
303 /// <summary>
304 /// Stores the prim of the sceneobjectpart.
305 /// </summary>
306 /// <param name="sceneObjectPart">The sceneobjectpart or prim.</param>
307 /// <param name="sqlCommand">The SQL command with the transaction.</param>
308 /// <param name="sceneGroupID">The scenegroup UUID.</param>
309 /// <param name="regionUUID">The region UUID.</param>
310 private void StoreSceneObjectPrim(SceneObjectPart sceneObjectPart, SqlCommand sqlCommand, UUID sceneGroupID, UUID regionUUID)
311 {
312 //Big query to update or insert a new prim.
313 //Note for SQL Server 2008 this could be simplified
314 string queryPrims = @"
315IF EXISTS (SELECT UUID FROM prims WHERE UUID = @UUID)
316 BEGIN
317 UPDATE prims SET
318 CreationDate = @CreationDate, Name = @Name, Text = @Text, Description = @Description, SitName = @SitName,
319 TouchName = @TouchName, ObjectFlags = @ObjectFlags, OwnerMask = @OwnerMask, NextOwnerMask = @NextOwnerMask, GroupMask = @GroupMask,
320 EveryoneMask = @EveryoneMask, BaseMask = @BaseMask, PositionX = @PositionX, PositionY = @PositionY, PositionZ = @PositionZ,
321 GroupPositionX = @GroupPositionX, GroupPositionY = @GroupPositionY, GroupPositionZ = @GroupPositionZ, VelocityX = @VelocityX,
322 VelocityY = @VelocityY, VelocityZ = @VelocityZ, AngularVelocityX = @AngularVelocityX, AngularVelocityY = @AngularVelocityY,
323 AngularVelocityZ = @AngularVelocityZ, AccelerationX = @AccelerationX, AccelerationY = @AccelerationY,
324 AccelerationZ = @AccelerationZ, RotationX = @RotationX, RotationY = @RotationY, RotationZ = @RotationZ, RotationW = @RotationW,
325 SitTargetOffsetX = @SitTargetOffsetX, SitTargetOffsetY = @SitTargetOffsetY, SitTargetOffsetZ = @SitTargetOffsetZ,
326 SitTargetOrientW = @SitTargetOrientW, SitTargetOrientX = @SitTargetOrientX, SitTargetOrientY = @SitTargetOrientY,
327 SitTargetOrientZ = @SitTargetOrientZ, RegionUUID = @RegionUUID, CreatorID = @CreatorID, OwnerID = @OwnerID, GroupID = @GroupID,
328 LastOwnerID = @LastOwnerID, SceneGroupID = @SceneGroupID, PayPrice = @PayPrice, PayButton1 = @PayButton1, PayButton2 = @PayButton2,
329 PayButton3 = @PayButton3, PayButton4 = @PayButton4, LoopedSound = @LoopedSound, LoopedSoundGain = @LoopedSoundGain,
330 TextureAnimation = @TextureAnimation, OmegaX = @OmegaX, OmegaY = @OmegaY, OmegaZ = @OmegaZ, CameraEyeOffsetX = @CameraEyeOffsetX,
331 CameraEyeOffsetY = @CameraEyeOffsetY, CameraEyeOffsetZ = @CameraEyeOffsetZ, CameraAtOffsetX = @CameraAtOffsetX,
332 CameraAtOffsetY = @CameraAtOffsetY, CameraAtOffsetZ = @CameraAtOffsetZ, ForceMouselook = @ForceMouselook,
333 ScriptAccessPin = @ScriptAccessPin, AllowedDrop = @AllowedDrop, DieAtEdge = @DieAtEdge, SalePrice = @SalePrice,
334 SaleType = @SaleType, ColorR = @ColorR, ColorG = @ColorG, ColorB = @ColorB, ColorA = @ColorA, ParticleSystem = @ParticleSystem,
335 ClickAction = @ClickAction, Material = @Material, CollisionSound = @CollisionSound, CollisionSoundVolume = @CollisionSoundVolume, PassTouches = @PassTouches,
336 LinkNumber = @LinkNumber
337 WHERE UUID = @UUID
338 END
339ELSE
340 BEGIN
341 INSERT INTO
342 prims (
343 UUID, CreationDate, Name, Text, Description, SitName, TouchName, ObjectFlags, OwnerMask, NextOwnerMask, GroupMask,
344 EveryoneMask, BaseMask, PositionX, PositionY, PositionZ, GroupPositionX, GroupPositionY, GroupPositionZ, VelocityX,
345 VelocityY, VelocityZ, AngularVelocityX, AngularVelocityY, AngularVelocityZ, AccelerationX, AccelerationY, AccelerationZ,
346 RotationX, RotationY, RotationZ, RotationW, SitTargetOffsetX, SitTargetOffsetY, SitTargetOffsetZ, SitTargetOrientW,
347 SitTargetOrientX, SitTargetOrientY, SitTargetOrientZ, RegionUUID, CreatorID, OwnerID, GroupID, LastOwnerID, SceneGroupID,
348 PayPrice, PayButton1, PayButton2, PayButton3, PayButton4, LoopedSound, LoopedSoundGain, TextureAnimation, OmegaX,
349 OmegaY, OmegaZ, CameraEyeOffsetX, CameraEyeOffsetY, CameraEyeOffsetZ, CameraAtOffsetX, CameraAtOffsetY, CameraAtOffsetZ,
350 ForceMouselook, ScriptAccessPin, AllowedDrop, DieAtEdge, SalePrice, SaleType, ColorR, ColorG, ColorB, ColorA,
351 ParticleSystem, ClickAction, Material, CollisionSound, CollisionSoundVolume, PassTouches, LinkNumber
352 ) VALUES (
353 @UUID, @CreationDate, @Name, @Text, @Description, @SitName, @TouchName, @ObjectFlags, @OwnerMask, @NextOwnerMask, @GroupMask,
354 @EveryoneMask, @BaseMask, @PositionX, @PositionY, @PositionZ, @GroupPositionX, @GroupPositionY, @GroupPositionZ, @VelocityX,
355 @VelocityY, @VelocityZ, @AngularVelocityX, @AngularVelocityY, @AngularVelocityZ, @AccelerationX, @AccelerationY, @AccelerationZ,
356 @RotationX, @RotationY, @RotationZ, @RotationW, @SitTargetOffsetX, @SitTargetOffsetY, @SitTargetOffsetZ, @SitTargetOrientW,
357 @SitTargetOrientX, @SitTargetOrientY, @SitTargetOrientZ, @RegionUUID, @CreatorID, @OwnerID, @GroupID, @LastOwnerID, @SceneGroupID,
358 @PayPrice, @PayButton1, @PayButton2, @PayButton3, @PayButton4, @LoopedSound, @LoopedSoundGain, @TextureAnimation, @OmegaX,
359 @OmegaY, @OmegaZ, @CameraEyeOffsetX, @CameraEyeOffsetY, @CameraEyeOffsetZ, @CameraAtOffsetX, @CameraAtOffsetY, @CameraAtOffsetZ,
360 @ForceMouselook, @ScriptAccessPin, @AllowedDrop, @DieAtEdge, @SalePrice, @SaleType, @ColorR, @ColorG, @ColorB, @ColorA,
361 @ParticleSystem, @ClickAction, @Material, @CollisionSound, @CollisionSoundVolume, @PassTouches, @LinkNumber
362 )
363 END";
364
365 //Set commandtext.
366 sqlCommand.CommandText = queryPrims;
367 //Add parameters
368 sqlCommand.Parameters.AddRange(CreatePrimParameters(sceneObjectPart, sceneGroupID, regionUUID));
369
370 //Execute the query. If it fails then error is trapped in calling function
371 sqlCommand.ExecuteNonQuery();
372 }
373
374 /// <summary>
375 /// Stores the scene object prim shapes.
376 /// </summary>
377 /// <param name="sceneObjectPart">The sceneobjectpart containing prim shape.</param>
378 /// <param name="sqlCommand">The SQL command with the transaction.</param>
379 /// <param name="sceneGroupID">The scenegroup UUID.</param>
380 /// <param name="regionUUID">The region UUID.</param>
381 private void StoreSceneObjectPrimShapes(SceneObjectPart sceneObjectPart, SqlCommand sqlCommand, UUID sceneGroupID, UUID regionUUID)
382 {
383 //Big query to or insert or update primshapes
384 //Note for SQL Server 2008 this can be simplified
385 string queryPrimShapes = @"
386IF EXISTS (SELECT UUID FROM primshapes WHERE UUID = @UUID)
387 BEGIN
388 UPDATE primshapes SET
389 Shape = @Shape, ScaleX = @ScaleX, ScaleY = @ScaleY, ScaleZ = @ScaleZ, PCode = @PCode, PathBegin = @PathBegin,
390 PathEnd = @PathEnd, PathScaleX = @PathScaleX, PathScaleY = @PathScaleY, PathShearX = @PathShearX, PathShearY = @PathShearY,
391 PathSkew = @PathSkew, PathCurve = @PathCurve, PathRadiusOffset = @PathRadiusOffset, PathRevolutions = @PathRevolutions,
392 PathTaperX = @PathTaperX, PathTaperY = @PathTaperY, PathTwist = @PathTwist, PathTwistBegin = @PathTwistBegin,
393 ProfileBegin = @ProfileBegin, ProfileEnd = @ProfileEnd, ProfileCurve = @ProfileCurve, ProfileHollow = @ProfileHollow,
394 Texture = @Texture, ExtraParams = @ExtraParams, State = @State
395 WHERE UUID = @UUID
396 END
397ELSE
398 BEGIN
399 INSERT INTO
400 primshapes (
401 UUID, Shape, ScaleX, ScaleY, ScaleZ, PCode, PathBegin, PathEnd, PathScaleX, PathScaleY, PathShearX, PathShearY,
402 PathSkew, PathCurve, PathRadiusOffset, PathRevolutions, PathTaperX, PathTaperY, PathTwist, PathTwistBegin, ProfileBegin,
403 ProfileEnd, ProfileCurve, ProfileHollow, Texture, ExtraParams, State
404 ) VALUES (
405 @UUID, @Shape, @ScaleX, @ScaleY, @ScaleZ, @PCode, @PathBegin, @PathEnd, @PathScaleX, @PathScaleY, @PathShearX, @PathShearY,
406 @PathSkew, @PathCurve, @PathRadiusOffset, @PathRevolutions, @PathTaperX, @PathTaperY, @PathTwist, @PathTwistBegin, @ProfileBegin,
407 @ProfileEnd, @ProfileCurve, @ProfileHollow, @Texture, @ExtraParams, @State
408 )
409 END";
410
411 //Set commandtext.
412 sqlCommand.CommandText = queryPrimShapes;
413
414 //Add parameters
415 sqlCommand.Parameters.AddRange(CreatePrimShapeParameters(sceneObjectPart, sceneGroupID, regionUUID));
416
417 //Execute the query. If it fails then error is trapped in calling function
418 sqlCommand.ExecuteNonQuery();
419
420 }
421
422 /// <summary>
423 /// Removes a object from the database.
424 /// Meaning removing it from tables Prims, PrimShapes and PrimItems
425 /// </summary>
426 /// <param name="objectID">id of scenegroup</param>
427 /// <param name="regionUUID">regionUUID (is this used anyway</param>
428 public void RemoveObject(UUID objectID, UUID regionUUID)
429 {
430 _Log.InfoFormat("[MSSQL]: Removing obj: {0} from region: {1}", objectID, regionUUID);
431
432 //Remove from prims and primsitem table
433 string sqlPrims = "DELETE FROM PRIMS WHERE SceneGroupID = @objectID";
434 string sqlPrimItems = "DELETE FROM PRIMITEMS WHERE primID in (SELECT UUID FROM PRIMS WHERE SceneGroupID = @objectID)";
435 string sqlPrimShapes = "DELETE FROM PRIMSHAPES WHERE uuid in (SELECT UUID FROM PRIMS WHERE SceneGroupID = @objectID)";
436
437 lock (_Database)
438 {
439 //Using the non transaction mode.
440 using (AutoClosingSqlCommand cmd = _Database.Query(sqlPrimShapes))
441 {
442 cmd.Parameters.Add(_Database.CreateParameter("objectID", objectID));
443 cmd.ExecuteNonQuery();
444
445 cmd.CommandText = sqlPrimItems;
446 cmd.ExecuteNonQuery();
447
448 cmd.CommandText = sqlPrims;
449 cmd.ExecuteNonQuery();
450 }
451 }
452 }
453
454 /// <summary>
455 /// Store the inventory of a prim. Warning deletes everything first and then adds all again.
456 /// </summary>
457 /// <param name="primID"></param>
458 /// <param name="items"></param>
459 public void StorePrimInventory(UUID primID, ICollection<TaskInventoryItem> items)
460 {
461 //_Log.InfoFormat("[REGION DB: Persisting Prim Inventory with prim ID {0}", primID);
462
463 //Statement from MySQL section!
464 // For now, we're just going to crudely remove all the previous inventory items
465 // no matter whether they have changed or not, and replace them with the current set.
466
467 //Delete everything from PrimID
468 //TODO add index on PrimID in DB, if not already exist
469 using (AutoClosingSqlCommand cmd = _Database.Query("DELETE PRIMITEMS WHERE primID = @primID"))
470 {
471 cmd.Parameters.Add(_Database.CreateParameter("@primID", primID));
472 cmd.ExecuteNonQuery();
473 }
474
475 string sql =
476 @"INSERT INTO primitems (
477 itemID,primID,assetID,parentFolderID,invType,assetType,name,description,creationDate,creatorID,ownerID,lastOwnerID,groupID,
478 nextPermissions,currentPermissions,basePermissions,everyonePermissions,groupPermissions,flags)
479 VALUES (@itemID,@primID,@assetID,@parentFolderID,@invType,@assetType,@name,@description,@creationDate,@creatorID,@ownerID,
480 @lastOwnerID,@groupID,@nextPermissions,@currentPermissions,@basePermissions,@everyonePermissions,@groupPermissions,@flags)";
481
482 using (AutoClosingSqlCommand cmd = _Database.Query(sql))
483 {
484 foreach (TaskInventoryItem taskItem in items)
485 {
486 cmd.Parameters.AddRange(CreatePrimInventoryParameters(taskItem));
487 cmd.ExecuteNonQuery();
488
489 cmd.Parameters.Clear();
490 }
491 }
492 }
493
494 #endregion
495
496 /// <summary>
497 /// Loads the terrain map.
498 /// </summary>
499 /// <param name="regionID">regionID.</param>
500 /// <returns></returns>
501 public double[,] LoadTerrain(UUID regionID)
502 {
503 double[,] terrain = new double[(int)Constants.RegionSize, (int)Constants.RegionSize];
504 terrain.Initialize();
505
506 string sql = "select top 1 RegionUUID, Revision, Heightfield from terrain where RegionUUID = @RegionUUID order by Revision desc";
507
508 using (AutoClosingSqlCommand cmd = _Database.Query(sql))
509 {
510 // MySqlParameter param = new MySqlParameter();
511 cmd.Parameters.Add(_Database.CreateParameter("@RegionUUID", regionID));
512
513 using (SqlDataReader reader = cmd.ExecuteReader())
514 {
515 int rev;
516 if (reader.Read())
517 {
518 MemoryStream str = new MemoryStream((byte[])reader["Heightfield"]);
519 BinaryReader br = new BinaryReader(str);
520 for (int x = 0; x < (int)Constants.RegionSize; x++)
521 {
522 for (int y = 0; y < (int)Constants.RegionSize; y++)
523 {
524 terrain[x, y] = br.ReadDouble();
525 }
526 }
527 rev = (int)reader["Revision"];
528 }
529 else
530 {
531 _Log.Info("[REGION DB]: No terrain found for region");
532 return null;
533 }
534 _Log.Info("[REGION DB]: Loaded terrain revision r" + rev);
535 }
536 }
537
538 return terrain;
539 }
540
541 /// <summary>
542 /// Stores the terrain map to DB.
543 /// </summary>
544 /// <param name="terrain">terrain map data.</param>
545 /// <param name="regionID">regionID.</param>
546 public void StoreTerrain(double[,] terrain, UUID regionID)
547 {
548 int revision = Util.UnixTimeSinceEpoch();
549
550 //Delete old terrain map
551 string sql = "delete from terrain where RegionUUID=@RegionUUID";
552 using (AutoClosingSqlCommand cmd = _Database.Query(sql))
553 {
554 cmd.Parameters.Add(_Database.CreateParameter("@RegionUUID", regionID));
555 cmd.ExecuteNonQuery();
556 }
557
558 sql = "insert into terrain(RegionUUID, Revision, Heightfield) values(@RegionUUID, @Revision, @Heightfield)";
559
560 using (AutoClosingSqlCommand cmd = _Database.Query(sql))
561 {
562 cmd.Parameters.Add(_Database.CreateParameter("@RegionUUID", regionID));
563 cmd.Parameters.Add(_Database.CreateParameter("@Revision", revision));
564 cmd.Parameters.Add(_Database.CreateParameter("@Heightfield", serializeTerrain(terrain)));
565 cmd.ExecuteNonQuery();
566 }
567
568 _Log.Info("[REGION DB]: Stored terrain revision r " + revision);
569 }
570
571 /// <summary>
572 /// Loads all the land objects of a region.
573 /// </summary>
574 /// <param name="regionUUID">The region UUID.</param>
575 /// <returns></returns>
576 public List<LandData> LoadLandObjects(UUID regionUUID)
577 {
578 List<LandData> landDataForRegion = new List<LandData>();
579
580 string sql = "select * from land where RegionUUID = @RegionUUID";
581
582 //Retrieve all land data from region
583 using (AutoClosingSqlCommand cmdLandData = _Database.Query(sql))
584 {
585 cmdLandData.Parameters.Add(_Database.CreateParameter("@RegionUUID", regionUUID));
586
587 using (SqlDataReader readerLandData = cmdLandData.ExecuteReader())
588 {
589 while (readerLandData.Read())
590 {
591 landDataForRegion.Add(BuildLandData(readerLandData));
592 }
593 }
594 }
595
596 //Retrieve all accesslist data for all landdata
597 foreach (LandData landData in landDataForRegion)
598 {
599 sql = "select * from landaccesslist where LandUUID = @LandUUID";
600 using (AutoClosingSqlCommand cmdAccessList = _Database.Query(sql))
601 {
602 cmdAccessList.Parameters.Add(_Database.CreateParameter("@LandUUID", landData.GlobalID));
603 using (SqlDataReader readerAccessList = cmdAccessList.ExecuteReader())
604 {
605 while (readerAccessList.Read())
606 {
607 landData.ParcelAccessList.Add(BuildLandAccessData(readerAccessList));
608 }
609 }
610 }
611 }
612
613 //Return data
614 return landDataForRegion;
615 }
616
617 /// <summary>
618 /// Stores land object with landaccess list.
619 /// </summary>
620 /// <param name="parcel">parcel data.</param>
621 public void StoreLandObject(ILandObject parcel)
622 {
623 //As this is only one record in land table I just delete all and then add a new record.
624 //As the delete landaccess is already in the mysql code
625
626 //Delete old values
627 RemoveLandObject(parcel.landData.GlobalID);
628
629 //Insert new values
630 string sql = @"INSERT INTO [land]
631([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],[Dwell])
632VALUES
633(@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,@Dwell)";
634
635 using (AutoClosingSqlCommand cmd = _Database.Query(sql))
636 {
637 cmd.Parameters.AddRange(CreateLandParameters(parcel.landData, parcel.regionUUID));
638
639 cmd.ExecuteNonQuery();
640 }
641
642 sql = "INSERT INTO [landaccesslist] ([LandUUID],[AccessUUID],[Flags]) VALUES (@LandUUID,@AccessUUID,@Flags)";
643
644 using (AutoClosingSqlCommand cmd = _Database.Query(sql))
645 {
646 foreach (ParcelManager.ParcelAccessEntry parcelAccessEntry in parcel.landData.ParcelAccessList)
647 {
648 cmd.Parameters.AddRange(CreateLandAccessParameters(parcelAccessEntry, parcel.regionUUID));
649
650 cmd.ExecuteNonQuery();
651 cmd.Parameters.Clear();
652 }
653 }
654 }
655
656 /// <summary>
657 /// Removes a land object from DB.
658 /// </summary>
659 /// <param name="globalID">UUID of landobject</param>
660 public void RemoveLandObject(UUID globalID)
661 {
662 using (AutoClosingSqlCommand cmd = _Database.Query("delete from land where UUID=@UUID"))
663 {
664 cmd.Parameters.Add(_Database.CreateParameter("@UUID", globalID));
665 cmd.ExecuteNonQuery();
666 }
667
668 using (AutoClosingSqlCommand cmd = _Database.Query("delete from landaccesslist where LandUUID=@UUID"))
669 {
670 cmd.Parameters.Add(_Database.CreateParameter("@UUID", globalID));
671 cmd.ExecuteNonQuery();
672 }
673 }
674
675 /// <summary>
676 /// Loads the settings of a region.
677 /// </summary>
678 /// <param name="regionUUID">The region UUID.</param>
679 /// <returns></returns>
680 public RegionSettings LoadRegionSettings(UUID regionUUID)
681 {
682 string sql = "select * from regionsettings where regionUUID = @regionUUID";
683 RegionSettings regionSettings;
684 using (AutoClosingSqlCommand cmd = _Database.Query(sql))
685 {
686 cmd.Parameters.Add(_Database.CreateParameter("@regionUUID", regionUUID));
687 using (SqlDataReader reader = cmd.ExecuteReader())
688 {
689 if (reader.Read())
690 {
691 regionSettings = BuildRegionSettings(reader);
692 regionSettings.OnSave += StoreRegionSettings;
693
694 return regionSettings;
695 }
696 }
697 }
698
699 //If comes here then there is now region setting for that region
700 regionSettings = new RegionSettings();
701 regionSettings.RegionUUID = regionUUID;
702 regionSettings.OnSave += StoreRegionSettings;
703
704 //Store new values
705 StoreNewRegionSettings(regionSettings);
706
707 return regionSettings;
708 }
709
710 /// <summary>
711 /// Store region settings, need to check if the check is really necesary. If we can make something for creating new region.
712 /// </summary>
713 /// <param name="regionSettings">region settings.</param>
714 public void StoreRegionSettings(RegionSettings regionSettings)
715 {
716 //Little check if regionUUID already exist in DB
717 string regionUUID;
718 using (AutoClosingSqlCommand cmd = _Database.Query("SELECT regionUUID FROM regionsettings WHERE regionUUID = @regionUUID"))
719 {
720 cmd.Parameters.Add(_Database.CreateParameter("@regionUUID", regionSettings.RegionUUID));
721 regionUUID = cmd.ExecuteScalar().ToString();
722 }
723
724 if (string.IsNullOrEmpty(regionUUID))
725 {
726 StoreNewRegionSettings(regionSettings);
727 }
728 else
729 {
730 //This method only updates region settings!!! First call LoadRegionSettings to create new region settings in DB
731 string sql =
732 @"UPDATE [regionsettings] SET [block_terraform] = @block_terraform ,[block_fly] = @block_fly ,[allow_damage] = @allow_damage
733,[restrict_pushing] = @restrict_pushing ,[allow_land_resell] = @allow_land_resell ,[allow_land_join_divide] = @allow_land_join_divide
734,[block_show_in_search] = @block_show_in_search ,[agent_limit] = @agent_limit ,[object_bonus] = @object_bonus ,[maturity] = @maturity
735,[disable_scripts] = @disable_scripts ,[disable_collisions] = @disable_collisions ,[disable_physics] = @disable_physics
736,[terrain_texture_1] = @terrain_texture_1 ,[terrain_texture_2] = @terrain_texture_2 ,[terrain_texture_3] = @terrain_texture_3
737,[terrain_texture_4] = @terrain_texture_4 ,[elevation_1_nw] = @elevation_1_nw ,[elevation_2_nw] = @elevation_2_nw
738,[elevation_1_ne] = @elevation_1_ne ,[elevation_2_ne] = @elevation_2_ne ,[elevation_1_se] = @elevation_1_se ,[elevation_2_se] = @elevation_2_se
739,[elevation_1_sw] = @elevation_1_sw ,[elevation_2_sw] = @elevation_2_sw ,[water_height] = @water_height ,[terrain_raise_limit] = @terrain_raise_limit
740,[terrain_lower_limit] = @terrain_lower_limit ,[use_estate_sun] = @use_estate_sun ,[fixed_sun] = @fixed_sun ,[sun_position] = @sun_position
741,[covenant] = @covenant , [sunvectorx] = @sunvectorx, [sunvectory] = @sunvectory, [sunvectorz] = @sunvectorz, [Sandbox] = @Sandbox, [loaded_creation_datetime] = @loaded_creation_datetime, [loaded_creation_id] = @loaded_creation_id
742 WHERE [regionUUID] = @regionUUID";
743
744 using (AutoClosingSqlCommand cmd = _Database.Query(sql))
745 {
746 cmd.Parameters.AddRange(CreateRegionSettingParameters(regionSettings));
747
748 cmd.ExecuteNonQuery();
749 }
750 }
751 }
752
753 public void Shutdown()
754 {
755 //Not used??
756 }
757
758 #region Private Methods
759
760 /// <summary>
761 /// Serializes the terrain data for storage in DB.
762 /// </summary>
763 /// <param name="val">terrain data</param>
764 /// <returns></returns>
765 private static Array serializeTerrain(double[,] val)
766 {
767 MemoryStream str = new MemoryStream(((int)Constants.RegionSize * (int)Constants.RegionSize) * sizeof(double));
768 BinaryWriter bw = new BinaryWriter(str);
769
770 // TODO: COMPATIBILITY - Add byte-order conversions
771 for (int x = 0; x < (int)Constants.RegionSize; x++)
772 for (int y = 0; y < (int)Constants.RegionSize; y++)
773 {
774 double height = val[x, y];
775 if (height == 0.0)
776 height = double.Epsilon;
777
778 bw.Write(height);
779 }
780
781 return str.ToArray();
782 }
783
784 /// <summary>
785 /// Stores new regionsettings.
786 /// </summary>
787 /// <param name="regionSettings">The region settings.</param>
788 private void StoreNewRegionSettings(RegionSettings regionSettings)
789 {
790 string sql = @"INSERT INTO [regionsettings]
791 ([regionUUID],[block_terraform],[block_fly],[allow_damage],[restrict_pushing],[allow_land_resell],[allow_land_join_divide],
792 [block_show_in_search],[agent_limit],[object_bonus],[maturity],[disable_scripts],[disable_collisions],[disable_physics],
793 [terrain_texture_1],[terrain_texture_2],[terrain_texture_3],[terrain_texture_4],[elevation_1_nw],[elevation_2_nw],[elevation_1_ne],
794 [elevation_2_ne],[elevation_1_se],[elevation_2_se],[elevation_1_sw],[elevation_2_sw],[water_height],[terrain_raise_limit],
795 [terrain_lower_limit],[use_estate_sun],[fixed_sun],[sun_position],[covenant],[sunvectorx], [sunvectory], [sunvectorz],[Sandbox], [loaded_creation_datetime], [loaded_creation_id]
796 )
797 VALUES
798 (@regionUUID,@block_terraform,@block_fly,@allow_damage,@restrict_pushing,@allow_land_resell,@allow_land_join_divide,
799 @block_show_in_search,@agent_limit,@object_bonus,@maturity,@disable_scripts,@disable_collisions,@disable_physics,
800 @terrain_texture_1,@terrain_texture_2,@terrain_texture_3,@terrain_texture_4,@elevation_1_nw,@elevation_2_nw,@elevation_1_ne,
801 @elevation_2_ne,@elevation_1_se,@elevation_2_se,@elevation_1_sw,@elevation_2_sw,@water_height,@terrain_raise_limit,
802 @terrain_lower_limit,@use_estate_sun,@fixed_sun,@sun_position,@covenant,@sunvectorx,@sunvectory, @sunvectorz, @Sandbox, @loaded_creation_datetime, @loaded_creation_id)";
803
804 using (AutoClosingSqlCommand cmd = _Database.Query(sql))
805 {
806 cmd.Parameters.AddRange(CreateRegionSettingParameters(regionSettings));
807 cmd.ExecuteNonQuery();
808 }
809 }
810
811 #region Private DataRecord conversion methods
812
813 /// <summary>
814 /// Builds the region settings from a datarecod.
815 /// </summary>
816 /// <param name="row">datarecord with regionsettings.</param>
817 /// <returns></returns>
818 private static RegionSettings BuildRegionSettings(IDataRecord row)
819 {
820 //TODO change this is some more generic code so we doesnt have to change it every time a new field is added?
821 RegionSettings newSettings = new RegionSettings();
822
823 newSettings.RegionUUID = new UUID((Guid)row["regionUUID"]);
824 newSettings.BlockTerraform = Convert.ToBoolean(row["block_terraform"]);
825 newSettings.AllowDamage = Convert.ToBoolean(row["allow_damage"]);
826 newSettings.BlockFly = Convert.ToBoolean(row["block_fly"]);
827 newSettings.RestrictPushing = Convert.ToBoolean(row["restrict_pushing"]);
828 newSettings.AllowLandResell = Convert.ToBoolean(row["allow_land_resell"]);
829 newSettings.AllowLandJoinDivide = Convert.ToBoolean(row["allow_land_join_divide"]);
830 newSettings.BlockShowInSearch = Convert.ToBoolean(row["block_show_in_search"]);
831 newSettings.AgentLimit = Convert.ToInt32(row["agent_limit"]);
832 newSettings.ObjectBonus = Convert.ToDouble(row["object_bonus"]);
833 newSettings.Maturity = Convert.ToInt32(row["maturity"]);
834 newSettings.DisableScripts = Convert.ToBoolean(row["disable_scripts"]);
835 newSettings.DisableCollisions = Convert.ToBoolean(row["disable_collisions"]);
836 newSettings.DisablePhysics = Convert.ToBoolean(row["disable_physics"]);
837 newSettings.TerrainTexture1 = new UUID((Guid)row["terrain_texture_1"]);
838 newSettings.TerrainTexture2 = new UUID((Guid)row["terrain_texture_2"]);
839 newSettings.TerrainTexture3 = new UUID((Guid)row["terrain_texture_3"]);
840 newSettings.TerrainTexture4 = new UUID((Guid)row["terrain_texture_4"]);
841 newSettings.Elevation1NW = Convert.ToDouble(row["elevation_1_nw"]);
842 newSettings.Elevation2NW = Convert.ToDouble(row["elevation_2_nw"]);
843 newSettings.Elevation1NE = Convert.ToDouble(row["elevation_1_ne"]);
844 newSettings.Elevation2NE = Convert.ToDouble(row["elevation_2_ne"]);
845 newSettings.Elevation1SE = Convert.ToDouble(row["elevation_1_se"]);
846 newSettings.Elevation2SE = Convert.ToDouble(row["elevation_2_se"]);
847 newSettings.Elevation1SW = Convert.ToDouble(row["elevation_1_sw"]);
848 newSettings.Elevation2SW = Convert.ToDouble(row["elevation_2_sw"]);
849 newSettings.WaterHeight = Convert.ToDouble(row["water_height"]);
850 newSettings.TerrainRaiseLimit = Convert.ToDouble(row["terrain_raise_limit"]);
851 newSettings.TerrainLowerLimit = Convert.ToDouble(row["terrain_lower_limit"]);
852 newSettings.UseEstateSun = Convert.ToBoolean(row["use_estate_sun"]);
853 newSettings.Sandbox = Convert.ToBoolean(row["sandbox"]);
854 newSettings.FixedSun = Convert.ToBoolean(row["fixed_sun"]);
855 newSettings.SunPosition = Convert.ToDouble(row["sun_position"]);
856 newSettings.SunVector = new Vector3(
857 Convert.ToSingle(row["sunvectorx"]),
858 Convert.ToSingle(row["sunvectory"]),
859 Convert.ToSingle(row["sunvectorz"])
860 );
861 newSettings.Covenant = new UUID((Guid)row["covenant"]);
862
863 newSettings.LoadedCreationDateTime = Convert.ToInt32(row["loaded_creation_datetime"]);
864
865 if (row["loaded_creation_id"] is DBNull)
866 newSettings.LoadedCreationID = "";
867 else
868 newSettings.LoadedCreationID = (String)row["loaded_creation_id"];
869 return newSettings;
870 }
871
872 /// <summary>
873 /// Builds the land data from a datarecord.
874 /// </summary>
875 /// <param name="row">datarecord with land data</param>
876 /// <returns></returns>
877 private static LandData BuildLandData(IDataRecord row)
878 {
879 LandData newData = new LandData();
880
881 newData.GlobalID = new UUID((Guid)row["UUID"]);
882 newData.LocalID = Convert.ToInt32(row["LocalLandID"]);
883
884 // Bitmap is a byte[512]
885 newData.Bitmap = (Byte[])row["Bitmap"];
886
887 newData.Name = (string)row["Name"];
888 newData.Description = (string)row["Description"];
889 newData.OwnerID = new UUID((Guid)row["OwnerUUID"]);
890 newData.IsGroupOwned = Convert.ToBoolean(row["IsGroupOwned"]);
891 newData.Area = Convert.ToInt32(row["Area"]);
892 newData.AuctionID = Convert.ToUInt32(row["AuctionID"]); //Unemplemented
893 newData.Category = (ParcelCategory)Convert.ToInt32(row["Category"]);
894 //Enum libsecondlife.Parcel.ParcelCategory
895 newData.ClaimDate = Convert.ToInt32(row["ClaimDate"]);
896 newData.ClaimPrice = Convert.ToInt32(row["ClaimPrice"]);
897 newData.GroupID = new UUID((Guid)row["GroupUUID"]);
898 newData.SalePrice = Convert.ToInt32(row["SalePrice"]);
899 newData.Status = (ParcelStatus)Convert.ToInt32(row["LandStatus"]);
900 //Enum. libsecondlife.Parcel.ParcelStatus
901 newData.Flags = Convert.ToUInt32(row["LandFlags"]);
902 newData.LandingType = Convert.ToByte(row["LandingType"]);
903 newData.MediaAutoScale = Convert.ToByte(row["MediaAutoScale"]);
904 newData.MediaID = new UUID((Guid)row["MediaTextureUUID"]);
905 newData.MediaURL = (string)row["MediaURL"];
906 newData.MusicURL = (string)row["MusicURL"];
907 newData.PassHours = Convert.ToSingle(row["PassHours"]);
908 newData.PassPrice = Convert.ToInt32(row["PassPrice"]);
909
910// UUID authedbuyer;
911// UUID snapshotID;
912//
913// if (UUID.TryParse((string)row["AuthBuyerID"], out authedbuyer))
914// newData.AuthBuyerID = authedbuyer;
915//
916// if (UUID.TryParse((string)row["SnapshotUUID"], out snapshotID))
917// newData.SnapshotID = snapshotID;
918 newData.AuthBuyerID = new UUID((Guid) row["AuthBuyerID"]);
919 newData.SnapshotID = new UUID((Guid)row["SnapshotUUID"]);
920
921 newData.OtherCleanTime = Convert.ToInt32(row["OtherCleanTime"]);
922 newData.Dwell = Convert.ToInt32(row["Dwell"]);
923
924 try
925 {
926 newData.UserLocation =
927 new Vector3(Convert.ToSingle(row["UserLocationX"]), Convert.ToSingle(row["UserLocationY"]),
928 Convert.ToSingle(row["UserLocationZ"]));
929 newData.UserLookAt =
930 new Vector3(Convert.ToSingle(row["UserLookAtX"]), Convert.ToSingle(row["UserLookAtY"]),
931 Convert.ToSingle(row["UserLookAtZ"]));
932 }
933 catch (InvalidCastException)
934 {
935 newData.UserLocation = Vector3.Zero;
936 newData.UserLookAt = Vector3.Zero;
937 _Log.ErrorFormat("[PARCEL]: unable to get parcel telehub settings for {1}", newData.Name);
938 }
939
940 newData.ParcelAccessList = new List<ParcelManager.ParcelAccessEntry>();
941
942 return newData;
943 }
944
945 /// <summary>
946 /// Builds the landaccess data from a data record.
947 /// </summary>
948 /// <param name="row">datarecord with landaccess data</param>
949 /// <returns></returns>
950 private static ParcelManager.ParcelAccessEntry BuildLandAccessData(IDataRecord row)
951 {
952 ParcelManager.ParcelAccessEntry entry = new ParcelManager.ParcelAccessEntry();
953 entry.AgentID = new UUID((Guid)row["AccessUUID"]);
954 entry.Flags = (AccessList)Convert.ToInt32(row["Flags"]);
955 entry.Time = new DateTime();
956 return entry;
957 }
958
959 /// <summary>
960 /// Builds the prim from a datarecord.
961 /// </summary>
962 /// <param name="primRow">datarecord</param>
963 /// <returns></returns>
964 private static SceneObjectPart BuildPrim(IDataRecord primRow)
965 {
966 SceneObjectPart prim = new SceneObjectPart();
967
968 prim.UUID = new UUID((Guid)primRow["UUID"]);
969 // explicit conversion of integers is required, which sort
970 // of sucks. No idea if there is a shortcut here or not.
971 prim.CreationDate = Convert.ToInt32(primRow["CreationDate"]);
972 prim.Name = (string)primRow["Name"];
973 // various text fields
974 prim.Text = (string)primRow["Text"];
975 prim.Color = Color.FromArgb(Convert.ToInt32(primRow["ColorA"]),
976 Convert.ToInt32(primRow["ColorR"]),
977 Convert.ToInt32(primRow["ColorG"]),
978 Convert.ToInt32(primRow["ColorB"]));
979 prim.Description = (string)primRow["Description"];
980 prim.SitName = (string)primRow["SitName"];
981 prim.TouchName = (string)primRow["TouchName"];
982 // permissions
983 prim.ObjectFlags = Convert.ToUInt32(primRow["ObjectFlags"]);
984 prim.CreatorID = new UUID((Guid)primRow["CreatorID"]);
985 prim.OwnerID = new UUID((Guid)primRow["OwnerID"]);
986 prim.GroupID = new UUID((Guid)primRow["GroupID"]);
987 prim.LastOwnerID = new UUID((Guid)primRow["LastOwnerID"]);
988 prim.OwnerMask = Convert.ToUInt32(primRow["OwnerMask"]);
989 prim.NextOwnerMask = Convert.ToUInt32(primRow["NextOwnerMask"]);
990 prim.GroupMask = Convert.ToUInt32(primRow["GroupMask"]);
991 prim.EveryoneMask = Convert.ToUInt32(primRow["EveryoneMask"]);
992 prim.BaseMask = Convert.ToUInt32(primRow["BaseMask"]);
993 // vectors
994 prim.OffsetPosition = new Vector3(
995 Convert.ToSingle(primRow["PositionX"]),
996 Convert.ToSingle(primRow["PositionY"]),
997 Convert.ToSingle(primRow["PositionZ"]));
998
999 prim.GroupPosition = new Vector3(
1000 Convert.ToSingle(primRow["GroupPositionX"]),
1001 Convert.ToSingle(primRow["GroupPositionY"]),
1002 Convert.ToSingle(primRow["GroupPositionZ"]));
1003
1004 prim.Velocity = new Vector3(
1005 Convert.ToSingle(primRow["VelocityX"]),
1006 Convert.ToSingle(primRow["VelocityY"]),
1007 Convert.ToSingle(primRow["VelocityZ"]));
1008
1009 prim.AngularVelocity = new Vector3(
1010 Convert.ToSingle(primRow["AngularVelocityX"]),
1011 Convert.ToSingle(primRow["AngularVelocityY"]),
1012 Convert.ToSingle(primRow["AngularVelocityZ"]));
1013
1014 prim.Acceleration = new Vector3(
1015 Convert.ToSingle(primRow["AccelerationX"]),
1016 Convert.ToSingle(primRow["AccelerationY"]),
1017 Convert.ToSingle(primRow["AccelerationZ"]));
1018
1019 // quaternions
1020 prim.RotationOffset = new Quaternion(
1021 Convert.ToSingle(primRow["RotationX"]),
1022 Convert.ToSingle(primRow["RotationY"]),
1023 Convert.ToSingle(primRow["RotationZ"]),
1024 Convert.ToSingle(primRow["RotationW"]));
1025
1026 prim.SitTargetPositionLL = new Vector3(
1027 Convert.ToSingle(primRow["SitTargetOffsetX"]),
1028 Convert.ToSingle(primRow["SitTargetOffsetY"]),
1029 Convert.ToSingle(primRow["SitTargetOffsetZ"]));
1030
1031 prim.SitTargetOrientationLL = new Quaternion(
1032 Convert.ToSingle(primRow["SitTargetOrientX"]),
1033 Convert.ToSingle(primRow["SitTargetOrientY"]),
1034 Convert.ToSingle(primRow["SitTargetOrientZ"]),
1035 Convert.ToSingle(primRow["SitTargetOrientW"]));
1036
1037 prim.PayPrice[0] = Convert.ToInt32(primRow["PayPrice"]);
1038 prim.PayPrice[1] = Convert.ToInt32(primRow["PayButton1"]);
1039 prim.PayPrice[2] = Convert.ToInt32(primRow["PayButton2"]);
1040 prim.PayPrice[3] = Convert.ToInt32(primRow["PayButton3"]);
1041 prim.PayPrice[4] = Convert.ToInt32(primRow["PayButton4"]);
1042
1043 prim.Sound = new UUID((Guid)primRow["LoopedSound"]);
1044 prim.SoundGain = Convert.ToSingle(primRow["LoopedSoundGain"]);
1045 prim.SoundFlags = 1; // If it's persisted at all, it's looped
1046
1047 if (!(primRow["TextureAnimation"] is DBNull))
1048 prim.TextureAnimation = (Byte[])primRow["TextureAnimation"];
1049 if (!(primRow["ParticleSystem"] is DBNull))
1050 prim.ParticleSystem = (Byte[])primRow["ParticleSystem"];
1051
1052 prim.RotationalVelocity = new Vector3(
1053 Convert.ToSingle(primRow["OmegaX"]),
1054 Convert.ToSingle(primRow["OmegaY"]),
1055 Convert.ToSingle(primRow["OmegaZ"]));
1056
1057 prim.SetCameraEyeOffset(new Vector3(
1058 Convert.ToSingle(primRow["CameraEyeOffsetX"]),
1059 Convert.ToSingle(primRow["CameraEyeOffsetY"]),
1060 Convert.ToSingle(primRow["CameraEyeOffsetZ"])
1061 ));
1062
1063 prim.SetCameraAtOffset(new Vector3(
1064 Convert.ToSingle(primRow["CameraAtOffsetX"]),
1065 Convert.ToSingle(primRow["CameraAtOffsetY"]),
1066 Convert.ToSingle(primRow["CameraAtOffsetZ"])
1067 ));
1068
1069 if (Convert.ToInt16(primRow["ForceMouselook"]) != 0)
1070 prim.SetForceMouselook(true);
1071
1072 prim.ScriptAccessPin = Convert.ToInt32(primRow["ScriptAccessPin"]);
1073
1074 if (Convert.ToInt16(primRow["AllowedDrop"]) != 0)
1075 prim.AllowedDrop = true;
1076
1077 if (Convert.ToInt16(primRow["DieAtEdge"]) != 0)
1078 prim.DIE_AT_EDGE = true;
1079
1080 prim.SalePrice = Convert.ToInt32(primRow["SalePrice"]);
1081 prim.ObjectSaleType = Convert.ToByte(primRow["SaleType"]);
1082
1083 prim.Material = Convert.ToByte(primRow["Material"]);
1084
1085 if (!(primRow["ClickAction"] is DBNull))
1086 prim.ClickAction = Convert.ToByte(primRow["ClickAction"]);
1087
1088 prim.CollisionSound = new UUID((Guid)primRow["CollisionSound"]);
1089 prim.CollisionSoundVolume = Convert.ToSingle(primRow["CollisionSoundVolume"]);
1090 if (Convert.ToInt16(primRow["PassTouches"]) != 0)
1091 prim.PassTouches = true;
1092 prim.LinkNum = Convert.ToInt32(primRow["LinkNumber"]);
1093
1094 return prim;
1095 }
1096
1097 /// <summary>
1098 /// Builds the prim shape from a datarecord.
1099 /// </summary>
1100 /// <param name="shapeRow">The row.</param>
1101 /// <returns></returns>
1102 private static PrimitiveBaseShape BuildShape(IDataRecord shapeRow)
1103 {
1104 PrimitiveBaseShape baseShape = new PrimitiveBaseShape();
1105
1106 baseShape.Scale = new Vector3(
1107 Convert.ToSingle(shapeRow["ScaleX"]),
1108 Convert.ToSingle(shapeRow["ScaleY"]),
1109 Convert.ToSingle(shapeRow["ScaleZ"]));
1110
1111 // paths
1112 baseShape.PCode = Convert.ToByte(shapeRow["PCode"]);
1113 baseShape.PathBegin = Convert.ToUInt16(shapeRow["PathBegin"]);
1114 baseShape.PathEnd = Convert.ToUInt16(shapeRow["PathEnd"]);
1115 baseShape.PathScaleX = Convert.ToByte(shapeRow["PathScaleX"]);
1116 baseShape.PathScaleY = Convert.ToByte(shapeRow["PathScaleY"]);
1117 baseShape.PathShearX = Convert.ToByte(shapeRow["PathShearX"]);
1118 baseShape.PathShearY = Convert.ToByte(shapeRow["PathShearY"]);
1119 baseShape.PathSkew = Convert.ToSByte(shapeRow["PathSkew"]);
1120 baseShape.PathCurve = Convert.ToByte(shapeRow["PathCurve"]);
1121 baseShape.PathRadiusOffset = Convert.ToSByte(shapeRow["PathRadiusOffset"]);
1122 baseShape.PathRevolutions = Convert.ToByte(shapeRow["PathRevolutions"]);
1123 baseShape.PathTaperX = Convert.ToSByte(shapeRow["PathTaperX"]);
1124 baseShape.PathTaperY = Convert.ToSByte(shapeRow["PathTaperY"]);
1125 baseShape.PathTwist = Convert.ToSByte(shapeRow["PathTwist"]);
1126 baseShape.PathTwistBegin = Convert.ToSByte(shapeRow["PathTwistBegin"]);
1127 // profile
1128 baseShape.ProfileBegin = Convert.ToUInt16(shapeRow["ProfileBegin"]);
1129 baseShape.ProfileEnd = Convert.ToUInt16(shapeRow["ProfileEnd"]);
1130 baseShape.ProfileCurve = Convert.ToByte(shapeRow["ProfileCurve"]);
1131 baseShape.ProfileHollow = Convert.ToUInt16(shapeRow["ProfileHollow"]);
1132
1133 byte[] textureEntry = (byte[])shapeRow["Texture"];
1134 baseShape.TextureEntry = textureEntry;
1135
1136 baseShape.ExtraParams = (byte[])shapeRow["ExtraParams"];
1137
1138 try
1139 {
1140 baseShape.State = Convert.ToByte(shapeRow["State"]);
1141 }
1142 catch (InvalidCastException)
1143 {
1144 }
1145
1146 return baseShape;
1147 }
1148
1149 /// <summary>
1150 /// Build a prim inventory item from the persisted data.
1151 /// </summary>
1152 /// <param name="inventoryRow"></param>
1153 /// <returns></returns>
1154 private static TaskInventoryItem BuildItem(IDataRecord inventoryRow)
1155 {
1156 TaskInventoryItem taskItem = new TaskInventoryItem();
1157
1158 taskItem.ItemID = new UUID((Guid)inventoryRow["itemID"]);
1159 taskItem.ParentPartID = new UUID((Guid)inventoryRow["primID"]);
1160 taskItem.AssetID = new UUID((Guid)inventoryRow["assetID"]);
1161 taskItem.ParentID = new UUID((Guid)inventoryRow["parentFolderID"]);
1162
1163 taskItem.InvType = Convert.ToInt32(inventoryRow["invType"]);
1164 taskItem.Type = Convert.ToInt32(inventoryRow["assetType"]);
1165
1166 taskItem.Name = (string)inventoryRow["name"];
1167 taskItem.Description = (string)inventoryRow["description"];
1168 taskItem.CreationDate = Convert.ToUInt32(inventoryRow["creationDate"]);
1169 taskItem.CreatorID = new UUID((Guid)inventoryRow["creatorID"]);
1170 taskItem.OwnerID = new UUID((Guid)inventoryRow["ownerID"]);
1171 taskItem.LastOwnerID = new UUID((Guid)inventoryRow["lastOwnerID"]);
1172 taskItem.GroupID = new UUID((Guid)inventoryRow["groupID"]);
1173
1174 taskItem.NextPermissions = Convert.ToUInt32(inventoryRow["nextPermissions"]);
1175 taskItem.CurrentPermissions = Convert.ToUInt32(inventoryRow["currentPermissions"]);
1176 taskItem.BasePermissions = Convert.ToUInt32(inventoryRow["basePermissions"]);
1177 taskItem.EveryonePermissions = Convert.ToUInt32(inventoryRow["everyonePermissions"]);
1178 taskItem.GroupPermissions = Convert.ToUInt32(inventoryRow["groupPermissions"]);
1179 taskItem.Flags = Convert.ToUInt32(inventoryRow["flags"]);
1180
1181 return taskItem;
1182 }
1183
1184 #endregion
1185
1186 #region Create parameters methods
1187
1188 /// <summary>
1189 /// Creates the prim inventory parameters.
1190 /// </summary>
1191 /// <param name="taskItem">item in inventory.</param>
1192 /// <returns></returns>
1193 private SqlParameter[] CreatePrimInventoryParameters(TaskInventoryItem taskItem)
1194 {
1195 List<SqlParameter> parameters = new List<SqlParameter>();
1196
1197 parameters.Add(_Database.CreateParameter("itemID", taskItem.ItemID));
1198 parameters.Add(_Database.CreateParameter("primID", taskItem.ParentPartID));
1199 parameters.Add(_Database.CreateParameter("assetID", taskItem.AssetID));
1200 parameters.Add(_Database.CreateParameter("parentFolderID", taskItem.ParentID));
1201 parameters.Add(_Database.CreateParameter("invType", taskItem.InvType));
1202 parameters.Add(_Database.CreateParameter("assetType", taskItem.Type));
1203
1204 parameters.Add(_Database.CreateParameter("name", taskItem.Name));
1205 parameters.Add(_Database.CreateParameter("description", taskItem.Description));
1206 parameters.Add(_Database.CreateParameter("creationDate", taskItem.CreationDate));
1207 parameters.Add(_Database.CreateParameter("creatorID", taskItem.CreatorID));
1208 parameters.Add(_Database.CreateParameter("ownerID", taskItem.OwnerID));
1209 parameters.Add(_Database.CreateParameter("lastOwnerID", taskItem.LastOwnerID));
1210 parameters.Add(_Database.CreateParameter("groupID", taskItem.GroupID));
1211 parameters.Add(_Database.CreateParameter("nextPermissions", taskItem.NextPermissions));
1212 parameters.Add(_Database.CreateParameter("currentPermissions", taskItem.CurrentPermissions));
1213 parameters.Add(_Database.CreateParameter("basePermissions", taskItem.BasePermissions));
1214 parameters.Add(_Database.CreateParameter("everyonePermissions", taskItem.EveryonePermissions));
1215 parameters.Add(_Database.CreateParameter("groupPermissions", taskItem.GroupPermissions));
1216 parameters.Add(_Database.CreateParameter("flags", taskItem.Flags));
1217
1218 return parameters.ToArray();
1219 }
1220
1221 /// <summary>
1222 /// Creates the region setting parameters.
1223 /// </summary>
1224 /// <param name="settings">regionsettings.</param>
1225 /// <returns></returns>
1226 private SqlParameter[] CreateRegionSettingParameters(RegionSettings settings)
1227 {
1228 List<SqlParameter> parameters = new List<SqlParameter>();
1229
1230 parameters.Add(_Database.CreateParameter("regionUUID", settings.RegionUUID));
1231 parameters.Add(_Database.CreateParameter("block_terraform", settings.BlockTerraform));
1232 parameters.Add(_Database.CreateParameter("block_fly", settings.BlockFly));
1233 parameters.Add(_Database.CreateParameter("allow_damage", settings.AllowDamage));
1234 parameters.Add(_Database.CreateParameter("restrict_pushing", settings.RestrictPushing));
1235 parameters.Add(_Database.CreateParameter("allow_land_resell", settings.AllowLandResell));
1236 parameters.Add(_Database.CreateParameter("allow_land_join_divide", settings.AllowLandJoinDivide));
1237 parameters.Add(_Database.CreateParameter("block_show_in_search", settings.BlockShowInSearch));
1238 parameters.Add(_Database.CreateParameter("agent_limit", settings.AgentLimit));
1239 parameters.Add(_Database.CreateParameter("object_bonus", settings.ObjectBonus));
1240 parameters.Add(_Database.CreateParameter("maturity", settings.Maturity));
1241 parameters.Add(_Database.CreateParameter("disable_scripts", settings.DisableScripts));
1242 parameters.Add(_Database.CreateParameter("disable_collisions", settings.DisableCollisions));
1243 parameters.Add(_Database.CreateParameter("disable_physics", settings.DisablePhysics));
1244 parameters.Add(_Database.CreateParameter("terrain_texture_1", settings.TerrainTexture1));
1245 parameters.Add(_Database.CreateParameter("terrain_texture_2", settings.TerrainTexture2));
1246 parameters.Add(_Database.CreateParameter("terrain_texture_3", settings.TerrainTexture3));
1247 parameters.Add(_Database.CreateParameter("terrain_texture_4", settings.TerrainTexture4));
1248 parameters.Add(_Database.CreateParameter("elevation_1_nw", settings.Elevation1NW));
1249 parameters.Add(_Database.CreateParameter("elevation_2_nw", settings.Elevation2NW));
1250 parameters.Add(_Database.CreateParameter("elevation_1_ne", settings.Elevation1NE));
1251 parameters.Add(_Database.CreateParameter("elevation_2_ne", settings.Elevation2NE));
1252 parameters.Add(_Database.CreateParameter("elevation_1_se", settings.Elevation1SE));
1253 parameters.Add(_Database.CreateParameter("elevation_2_se", settings.Elevation2SE));
1254 parameters.Add(_Database.CreateParameter("elevation_1_sw", settings.Elevation1SW));
1255 parameters.Add(_Database.CreateParameter("elevation_2_sw", settings.Elevation2SW));
1256 parameters.Add(_Database.CreateParameter("water_height", settings.WaterHeight));
1257 parameters.Add(_Database.CreateParameter("terrain_raise_limit", settings.TerrainRaiseLimit));
1258 parameters.Add(_Database.CreateParameter("terrain_lower_limit", settings.TerrainLowerLimit));
1259 parameters.Add(_Database.CreateParameter("use_estate_sun", settings.UseEstateSun));
1260 parameters.Add(_Database.CreateParameter("sandbox", settings.Sandbox));
1261 parameters.Add(_Database.CreateParameter("fixed_sun", settings.FixedSun));
1262 parameters.Add(_Database.CreateParameter("sun_position", settings.SunPosition));
1263 parameters.Add(_Database.CreateParameter("sunvectorx", settings.SunVector.X));
1264 parameters.Add(_Database.CreateParameter("sunvectory", settings.SunVector.Y));
1265 parameters.Add(_Database.CreateParameter("sunvectorz", settings.SunVector.Z));
1266 parameters.Add(_Database.CreateParameter("covenant", settings.Covenant));
1267 parameters.Add(_Database.CreateParameter("Loaded_Creation_DateTime", settings.LoadedCreationDateTime));
1268 parameters.Add(_Database.CreateParameter("Loaded_Creation_ID", settings.LoadedCreationID));
1269
1270 return parameters.ToArray();
1271 }
1272
1273 /// <summary>
1274 /// Creates the land parameters.
1275 /// </summary>
1276 /// <param name="land">land parameters.</param>
1277 /// <param name="regionUUID">region UUID.</param>
1278 /// <returns></returns>
1279 private SqlParameter[] CreateLandParameters(LandData land, UUID regionUUID)
1280 {
1281 List<SqlParameter> parameters = new List<SqlParameter>();
1282
1283 parameters.Add(_Database.CreateParameter("UUID", land.GlobalID));
1284 parameters.Add(_Database.CreateParameter("RegionUUID", regionUUID));
1285 parameters.Add(_Database.CreateParameter("LocalLandID", land.LocalID));
1286
1287 // Bitmap is a byte[512]
1288 parameters.Add(_Database.CreateParameter("Bitmap", land.Bitmap));
1289
1290 parameters.Add(_Database.CreateParameter("Name", land.Name));
1291 parameters.Add(_Database.CreateParameter("Description", land.Description));
1292 parameters.Add(_Database.CreateParameter("OwnerUUID", land.OwnerID));
1293 parameters.Add(_Database.CreateParameter("IsGroupOwned", land.IsGroupOwned));
1294 parameters.Add(_Database.CreateParameter("Area", land.Area));
1295 parameters.Add(_Database.CreateParameter("AuctionID", land.AuctionID)); //Unemplemented
1296 parameters.Add(_Database.CreateParameter("Category", (int)land.Category)); //Enum libsecondlife.Parcel.ParcelCategory
1297 parameters.Add(_Database.CreateParameter("ClaimDate", land.ClaimDate));
1298 parameters.Add(_Database.CreateParameter("ClaimPrice", land.ClaimPrice));
1299 parameters.Add(_Database.CreateParameter("GroupUUID", land.GroupID));
1300 parameters.Add(_Database.CreateParameter("SalePrice", land.SalePrice));
1301 parameters.Add(_Database.CreateParameter("LandStatus", (int)land.Status)); //Enum. libsecondlife.Parcel.ParcelStatus
1302 parameters.Add(_Database.CreateParameter("LandFlags", land.Flags));
1303 parameters.Add(_Database.CreateParameter("LandingType", land.LandingType));
1304 parameters.Add(_Database.CreateParameter("MediaAutoScale", land.MediaAutoScale));
1305 parameters.Add(_Database.CreateParameter("MediaTextureUUID", land.MediaID));
1306 parameters.Add(_Database.CreateParameter("MediaURL", land.MediaURL));
1307 parameters.Add(_Database.CreateParameter("MusicURL", land.MusicURL));
1308 parameters.Add(_Database.CreateParameter("PassHours", land.PassHours));
1309 parameters.Add(_Database.CreateParameter("PassPrice", land.PassPrice));
1310 parameters.Add(_Database.CreateParameter("SnapshotUUID", land.SnapshotID));
1311 parameters.Add(_Database.CreateParameter("UserLocationX", land.UserLocation.X));
1312 parameters.Add(_Database.CreateParameter("UserLocationY", land.UserLocation.Y));
1313 parameters.Add(_Database.CreateParameter("UserLocationZ", land.UserLocation.Z));
1314 parameters.Add(_Database.CreateParameter("UserLookAtX", land.UserLookAt.X));
1315 parameters.Add(_Database.CreateParameter("UserLookAtY", land.UserLookAt.Y));
1316 parameters.Add(_Database.CreateParameter("UserLookAtZ", land.UserLookAt.Z));
1317 parameters.Add(_Database.CreateParameter("AuthBuyerID", land.AuthBuyerID));
1318 parameters.Add(_Database.CreateParameter("OtherCleanTime", land.OtherCleanTime));
1319 parameters.Add(_Database.CreateParameter("Dwell", land.Dwell));
1320
1321 return parameters.ToArray();
1322 }
1323
1324 /// <summary>
1325 /// Creates the land access parameters.
1326 /// </summary>
1327 /// <param name="parcelAccessEntry">parcel access entry.</param>
1328 /// <param name="parcelID">parcel ID.</param>
1329 /// <returns></returns>
1330 private SqlParameter[] CreateLandAccessParameters(ParcelManager.ParcelAccessEntry parcelAccessEntry, UUID parcelID)
1331 {
1332 List<SqlParameter> parameters = new List<SqlParameter>();
1333
1334 parameters.Add(_Database.CreateParameter("LandUUID", parcelID));
1335 parameters.Add(_Database.CreateParameter("AccessUUID", parcelAccessEntry.AgentID));
1336 parameters.Add(_Database.CreateParameter("Flags", parcelAccessEntry.Flags));
1337
1338 return parameters.ToArray();
1339 }
1340
1341 /// <summary>
1342 /// Creates the prim parameters for storing in DB.
1343 /// </summary>
1344 /// <param name="prim">Basic data of SceneObjectpart prim.</param>
1345 /// <param name="sceneGroupID">The scenegroup ID.</param>
1346 /// <param name="regionUUID">The region ID.</param>
1347 /// <returns></returns>
1348 private SqlParameter[] CreatePrimParameters(SceneObjectPart prim, UUID sceneGroupID, UUID regionUUID)
1349 {
1350 List<SqlParameter> parameters = new List<SqlParameter>();
1351
1352 parameters.Add(_Database.CreateParameter("UUID", prim.UUID));
1353 parameters.Add(_Database.CreateParameter("RegionUUID", regionUUID));
1354 parameters.Add(_Database.CreateParameter("CreationDate", prim.CreationDate));
1355 parameters.Add(_Database.CreateParameter("Name", prim.Name));
1356 parameters.Add(_Database.CreateParameter("SceneGroupID", sceneGroupID));
1357 // the UUID of the root part for this SceneObjectGroup
1358 // various text fields
1359 parameters.Add(_Database.CreateParameter("Text", prim.Text));
1360 parameters.Add(_Database.CreateParameter("ColorR", prim.Color.R));
1361 parameters.Add(_Database.CreateParameter("ColorG", prim.Color.G));
1362 parameters.Add(_Database.CreateParameter("ColorB", prim.Color.B));
1363 parameters.Add(_Database.CreateParameter("ColorA", prim.Color.A));
1364 parameters.Add(_Database.CreateParameter("Description", prim.Description));
1365 parameters.Add(_Database.CreateParameter("SitName", prim.SitName));
1366 parameters.Add(_Database.CreateParameter("TouchName", prim.TouchName));
1367 // permissions
1368 parameters.Add(_Database.CreateParameter("ObjectFlags", prim.ObjectFlags));
1369 parameters.Add(_Database.CreateParameter("CreatorID", prim.CreatorID));
1370 parameters.Add(_Database.CreateParameter("OwnerID", prim.OwnerID));
1371 parameters.Add(_Database.CreateParameter("GroupID", prim.GroupID));
1372 parameters.Add(_Database.CreateParameter("LastOwnerID", prim.LastOwnerID));
1373 parameters.Add(_Database.CreateParameter("OwnerMask", prim.OwnerMask));
1374 parameters.Add(_Database.CreateParameter("NextOwnerMask", prim.NextOwnerMask));
1375 parameters.Add(_Database.CreateParameter("GroupMask", prim.GroupMask));
1376 parameters.Add(_Database.CreateParameter("EveryoneMask", prim.EveryoneMask));
1377 parameters.Add(_Database.CreateParameter("BaseMask", prim.BaseMask));
1378 // vectors
1379 parameters.Add(_Database.CreateParameter("PositionX", prim.OffsetPosition.X));
1380 parameters.Add(_Database.CreateParameter("PositionY", prim.OffsetPosition.Y));
1381 parameters.Add(_Database.CreateParameter("PositionZ", prim.OffsetPosition.Z));
1382 parameters.Add(_Database.CreateParameter("GroupPositionX", prim.GroupPosition.X));
1383 parameters.Add(_Database.CreateParameter("GroupPositionY", prim.GroupPosition.Y));
1384 parameters.Add(_Database.CreateParameter("GroupPositionZ", prim.GroupPosition.Z));
1385 parameters.Add(_Database.CreateParameter("VelocityX", prim.Velocity.X));
1386 parameters.Add(_Database.CreateParameter("VelocityY", prim.Velocity.Y));
1387 parameters.Add(_Database.CreateParameter("VelocityZ", prim.Velocity.Z));
1388 parameters.Add(_Database.CreateParameter("AngularVelocityX", prim.AngularVelocity.X));
1389 parameters.Add(_Database.CreateParameter("AngularVelocityY", prim.AngularVelocity.Y));
1390 parameters.Add(_Database.CreateParameter("AngularVelocityZ", prim.AngularVelocity.Z));
1391 parameters.Add(_Database.CreateParameter("AccelerationX", prim.Acceleration.X));
1392 parameters.Add(_Database.CreateParameter("AccelerationY", prim.Acceleration.Y));
1393 parameters.Add(_Database.CreateParameter("AccelerationZ", prim.Acceleration.Z));
1394 // quaternions
1395 parameters.Add(_Database.CreateParameter("RotationX", prim.RotationOffset.X));
1396 parameters.Add(_Database.CreateParameter("RotationY", prim.RotationOffset.Y));
1397 parameters.Add(_Database.CreateParameter("RotationZ", prim.RotationOffset.Z));
1398 parameters.Add(_Database.CreateParameter("RotationW", prim.RotationOffset.W));
1399
1400 // Sit target
1401 Vector3 sitTargetPos = prim.SitTargetPositionLL;
1402 parameters.Add(_Database.CreateParameter("SitTargetOffsetX", sitTargetPos.X));
1403 parameters.Add(_Database.CreateParameter("SitTargetOffsetY", sitTargetPos.Y));
1404 parameters.Add(_Database.CreateParameter("SitTargetOffsetZ", sitTargetPos.Z));
1405
1406 Quaternion sitTargetOrient = prim.SitTargetOrientationLL;
1407 parameters.Add(_Database.CreateParameter("SitTargetOrientW", sitTargetOrient.W));
1408 parameters.Add(_Database.CreateParameter("SitTargetOrientX", sitTargetOrient.X));
1409 parameters.Add(_Database.CreateParameter("SitTargetOrientY", sitTargetOrient.Y));
1410 parameters.Add(_Database.CreateParameter("SitTargetOrientZ", sitTargetOrient.Z));
1411
1412 parameters.Add(_Database.CreateParameter("PayPrice", prim.PayPrice[0]));
1413 parameters.Add(_Database.CreateParameter("PayButton1", prim.PayPrice[1]));
1414 parameters.Add(_Database.CreateParameter("PayButton2", prim.PayPrice[2]));
1415 parameters.Add(_Database.CreateParameter("PayButton3", prim.PayPrice[3]));
1416 parameters.Add(_Database.CreateParameter("PayButton4", prim.PayPrice[4]));
1417
1418 if ((prim.SoundFlags & 1) != 0) // Looped
1419 {
1420 parameters.Add(_Database.CreateParameter("LoopedSound", prim.Sound));
1421 parameters.Add(_Database.CreateParameter("LoopedSoundGain", prim.SoundGain));
1422 }
1423 else
1424 {
1425 parameters.Add(_Database.CreateParameter("LoopedSound", UUID.Zero));
1426 parameters.Add(_Database.CreateParameter("LoopedSoundGain", 0.0f));
1427 }
1428
1429 parameters.Add(_Database.CreateParameter("TextureAnimation", prim.TextureAnimation));
1430 parameters.Add(_Database.CreateParameter("ParticleSystem", prim.ParticleSystem));
1431
1432 parameters.Add(_Database.CreateParameter("OmegaX", prim.RotationalVelocity.X));
1433 parameters.Add(_Database.CreateParameter("OmegaY", prim.RotationalVelocity.Y));
1434 parameters.Add(_Database.CreateParameter("OmegaZ", prim.RotationalVelocity.Z));
1435
1436 parameters.Add(_Database.CreateParameter("CameraEyeOffsetX", prim.GetCameraEyeOffset().X));
1437 parameters.Add(_Database.CreateParameter("CameraEyeOffsetY", prim.GetCameraEyeOffset().Y));
1438 parameters.Add(_Database.CreateParameter("CameraEyeOffsetZ", prim.GetCameraEyeOffset().Z));
1439
1440 parameters.Add(_Database.CreateParameter("CameraAtOffsetX", prim.GetCameraAtOffset().X));
1441 parameters.Add(_Database.CreateParameter("CameraAtOffsetY", prim.GetCameraAtOffset().Y));
1442 parameters.Add(_Database.CreateParameter("CameraAtOffsetZ", prim.GetCameraAtOffset().Z));
1443
1444 if (prim.GetForceMouselook())
1445 parameters.Add(_Database.CreateParameter("ForceMouselook", 1));
1446 else
1447 parameters.Add(_Database.CreateParameter("ForceMouselook", 0));
1448
1449 parameters.Add(_Database.CreateParameter("ScriptAccessPin", prim.ScriptAccessPin));
1450
1451 if (prim.AllowedDrop)
1452 parameters.Add(_Database.CreateParameter("AllowedDrop", 1));
1453 else
1454 parameters.Add(_Database.CreateParameter("AllowedDrop", 0));
1455
1456 if (prim.DIE_AT_EDGE)
1457 parameters.Add(_Database.CreateParameter("DieAtEdge", 1));
1458 else
1459 parameters.Add(_Database.CreateParameter("DieAtEdge", 0));
1460
1461 parameters.Add(_Database.CreateParameter("SalePrice", prim.SalePrice));
1462 parameters.Add(_Database.CreateParameter("SaleType", prim.ObjectSaleType));
1463
1464 byte clickAction = prim.ClickAction;
1465 parameters.Add(_Database.CreateParameter("ClickAction", clickAction));
1466
1467 parameters.Add(_Database.CreateParameter("Material", prim.Material));
1468
1469 parameters.Add(_Database.CreateParameter("CollisionSound", prim.CollisionSound));
1470 parameters.Add(_Database.CreateParameter("CollisionSoundVolume", prim.CollisionSoundVolume));
1471 if (prim.PassTouches)
1472 parameters.Add(_Database.CreateParameter("PassTouches", 1));
1473 else
1474 parameters.Add(_Database.CreateParameter("PassTouches", 0));
1475 parameters.Add(_Database.CreateParameter("LinkNumber", prim.LinkNum));
1476
1477 return parameters.ToArray();
1478 }
1479
1480 /// <summary>
1481 /// Creates the primshape parameters for stroing in DB.
1482 /// </summary>
1483 /// <param name="prim">Basic data of SceneObjectpart prim.</param>
1484 /// <param name="sceneGroupID">The scene group ID.</param>
1485 /// <param name="regionUUID">The region UUID.</param>
1486 /// <returns></returns>
1487 private SqlParameter[] CreatePrimShapeParameters(SceneObjectPart prim, UUID sceneGroupID, UUID regionUUID)
1488 {
1489 List<SqlParameter> parameters = new List<SqlParameter>();
1490
1491 PrimitiveBaseShape s = prim.Shape;
1492 parameters.Add(_Database.CreateParameter("UUID", prim.UUID));
1493 // shape is an enum
1494 parameters.Add(_Database.CreateParameter("Shape", 0));
1495 // vectors
1496 parameters.Add(_Database.CreateParameter("ScaleX", s.Scale.X));
1497 parameters.Add(_Database.CreateParameter("ScaleY", s.Scale.Y));
1498 parameters.Add(_Database.CreateParameter("ScaleZ", s.Scale.Z));
1499 // paths
1500 parameters.Add(_Database.CreateParameter("PCode", s.PCode));
1501 parameters.Add(_Database.CreateParameter("PathBegin", s.PathBegin));
1502 parameters.Add(_Database.CreateParameter("PathEnd", s.PathEnd));
1503 parameters.Add(_Database.CreateParameter("PathScaleX", s.PathScaleX));
1504 parameters.Add(_Database.CreateParameter("PathScaleY", s.PathScaleY));
1505 parameters.Add(_Database.CreateParameter("PathShearX", s.PathShearX));
1506 parameters.Add(_Database.CreateParameter("PathShearY", s.PathShearY));
1507 parameters.Add(_Database.CreateParameter("PathSkew", s.PathSkew));
1508 parameters.Add(_Database.CreateParameter("PathCurve", s.PathCurve));
1509 parameters.Add(_Database.CreateParameter("PathRadiusOffset", s.PathRadiusOffset));
1510 parameters.Add(_Database.CreateParameter("PathRevolutions", s.PathRevolutions));
1511 parameters.Add(_Database.CreateParameter("PathTaperX", s.PathTaperX));
1512 parameters.Add(_Database.CreateParameter("PathTaperY", s.PathTaperY));
1513 parameters.Add(_Database.CreateParameter("PathTwist", s.PathTwist));
1514 parameters.Add(_Database.CreateParameter("PathTwistBegin", s.PathTwistBegin));
1515 // profile
1516 parameters.Add(_Database.CreateParameter("ProfileBegin", s.ProfileBegin));
1517 parameters.Add(_Database.CreateParameter("ProfileEnd", s.ProfileEnd));
1518 parameters.Add(_Database.CreateParameter("ProfileCurve", s.ProfileCurve));
1519 parameters.Add(_Database.CreateParameter("ProfileHollow", s.ProfileHollow));
1520 parameters.Add(_Database.CreateParameter("Texture", s.TextureEntry));
1521 parameters.Add(_Database.CreateParameter("ExtraParams", s.ExtraParams));
1522 parameters.Add(_Database.CreateParameter("State", s.State));
1523
1524 return parameters.ToArray();
1525 }
1526
1527 #endregion
1528
1529 #endregion
1530 }
1531}