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