aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Data/PGSQL/PGSQLSimulationData.cs
diff options
context:
space:
mode:
authorRobert Adams2013-10-16 07:53:44 -0700
committerRobert Adams2013-10-16 07:53:44 -0700
commit8937a2244d65ea71c402777bb68a986f60982e07 (patch)
tree03601074b85b0c41ff15f5155a4b14c197954450 /OpenSim/Data/PGSQL/PGSQLSimulationData.cs
parentvarregion: move the compressed heighmap compression factor from (diff)
parentBulletSim: implement the SL bug where VEHICLE_HOVER_UP_ONLY disables (diff)
downloadopensim-SC-8937a2244d65ea71c402777bb68a986f60982e07.zip
opensim-SC-8937a2244d65ea71c402777bb68a986f60982e07.tar.gz
opensim-SC-8937a2244d65ea71c402777bb68a986f60982e07.tar.bz2
opensim-SC-8937a2244d65ea71c402777bb68a986f60982e07.tar.xz
Merge branch 'master' into varregion
Diffstat (limited to 'OpenSim/Data/PGSQL/PGSQLSimulationData.cs')
-rw-r--r--OpenSim/Data/PGSQL/PGSQLSimulationData.cs2247
1 files changed, 2247 insertions, 0 deletions
diff --git a/OpenSim/Data/PGSQL/PGSQLSimulationData.cs b/OpenSim/Data/PGSQL/PGSQLSimulationData.cs
new file mode 100644
index 0000000..69b0beb
--- /dev/null
+++ b/OpenSim/Data/PGSQL/PGSQLSimulationData.cs
@@ -0,0 +1,2247 @@
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 count (region_id) from regionwindlight where ""region_id"" = :region_id ;";
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 exists = cmd.ExecuteNonQuery() > 0;
836 }
837 }
838 if (exists)
839 {
840 RemoveRegionWindlightSettings(wl.regionID);
841 }
842
843 // sql insert
844 sql = @"INSERT INTO regionwindlight
845 (region_id
846 ,water_color_r
847 ,water_color_g
848 ,water_color_b
849 ,water_fog_density_exponent
850 ,underwater_fog_modifier
851 ,reflection_wavelet_scale_1
852 ,reflection_wavelet_scale_2
853 ,reflection_wavelet_scale_3
854 ,fresnel_scale
855 ,fresnel_offset
856 ,refract_scale_above
857 ,refract_scale_below
858 ,blur_multiplier
859 ,big_wave_direction_x
860 ,big_wave_direction_y
861 ,little_wave_direction_x
862 ,little_wave_direction_y
863 ,normal_map_texture
864 ,horizon_r
865 ,horizon_g
866 ,horizon_b
867 ,horizon_i
868 ,haze_horizon
869 ,blue_density_r
870 ,blue_density_g
871 ,blue_density_b
872 ,blue_density_i
873 ,haze_density
874 ,density_multiplier
875 ,distance_multiplier
876 ,max_altitude
877 ,sun_moon_color_r
878 ,sun_moon_color_g
879 ,sun_moon_color_b
880 ,sun_moon_color_i
881 ,sun_moon_position
882 ,ambient_r
883 ,ambient_g
884 ,ambient_b
885 ,ambient_i
886 ,east_angle
887 ,sun_glow_focus
888 ,sun_glow_size
889 ,scene_gamma
890 ,star_brightness
891 ,cloud_color_r
892 ,cloud_color_g
893 ,cloud_color_b
894 ,cloud_color_i
895 ,cloud_x
896 ,cloud_y
897 ,cloud_density
898 ,cloud_coverage
899 ,cloud_scale
900 ,cloud_detail_x
901 ,cloud_detail_y
902 ,cloud_detail_density
903 ,cloud_scroll_x
904 ,cloud_scroll_x_lock
905 ,cloud_scroll_y
906 ,cloud_scroll_y_lock
907 ,draw_classic_clouds)
908 VALUES
909 (:region_id
910 ,:water_color_r
911 ,:water_color_g
912 ,:water_color_b
913 ,:water_fog_density_exponent
914 ,:underwater_fog_modifier
915 ,:reflection_wavelet_scale_1
916 ,:reflection_wavelet_scale_2
917 ,:reflection_wavelet_scale_3
918 ,:fresnel_scale
919 ,:fresnel_offset
920 ,:refract_scale_above
921 ,:refract_scale_below
922 ,:blur_multiplier
923 ,:big_wave_direction_x
924 ,:big_wave_direction_y
925 ,:little_wave_direction_x
926 ,:little_wave_direction_y
927 ,:normal_map_texture
928 ,:horizon_r
929 ,:horizon_g
930 ,:horizon_b
931 ,:horizon_i
932 ,:haze_horizon
933 ,:blue_density_r
934 ,:blue_density_g
935 ,:blue_density_b
936 ,:blue_density_i
937 ,:haze_density
938 ,:density_multiplier
939 ,:distance_multiplier
940 ,:max_altitude
941 ,:sun_moon_color_r
942 ,:sun_moon_color_g
943 ,:sun_moon_color_b
944 ,:sun_moon_color_i
945 ,:sun_moon_position
946 ,:ambient_r
947 ,:ambient_g
948 ,:ambient_b
949 ,:ambient_i
950 ,:east_angle
951 ,:sun_glow_focus
952 ,:sun_glow_size
953 ,:scene_gamma
954 ,:star_brightness
955 ,:cloud_color_r
956 ,:cloud_color_g
957 ,:cloud_color_b
958 ,:cloud_color_i
959 ,:cloud_x
960 ,:cloud_y
961 ,:cloud_density
962 ,:cloud_coverage
963 ,:cloud_scale
964 ,:cloud_detail_x
965 ,:cloud_detail_y
966 ,:cloud_detail_density
967 ,:cloud_scroll_x
968 ,:cloud_scroll_x_lock
969 ,:cloud_scroll_y
970 ,:cloud_scroll_y_lock
971 ,:draw_classic_clouds);";
972
973 using (NpgsqlConnection conn = new NpgsqlConnection(m_connectionString))
974 {
975 conn.Open();
976 using (NpgsqlCommand cmd = new NpgsqlCommand(sql, conn))
977 {
978 cmd.Parameters.Add(_Database.CreateParameter("region_id", wl.regionID));
979 cmd.Parameters.Add(_Database.CreateParameter("water_color_r", wl.waterColor.X));
980 cmd.Parameters.Add(_Database.CreateParameter("water_color_g", wl.waterColor.Y));
981 cmd.Parameters.Add(_Database.CreateParameter("water_color_b", wl.waterColor.Z));
982 cmd.Parameters.Add(_Database.CreateParameter("water_fog_density_exponent", wl.waterFogDensityExponent));
983 cmd.Parameters.Add(_Database.CreateParameter("underwater_fog_modifier", wl.underwaterFogModifier));
984 cmd.Parameters.Add(_Database.CreateParameter("reflection_wavelet_scale_1", wl.reflectionWaveletScale.X));
985 cmd.Parameters.Add(_Database.CreateParameter("reflection_wavelet_scale_2", wl.reflectionWaveletScale.Y));
986 cmd.Parameters.Add(_Database.CreateParameter("reflection_wavelet_scale_3", wl.reflectionWaveletScale.Z));
987 cmd.Parameters.Add(_Database.CreateParameter("fresnel_scale", wl.fresnelScale));
988 cmd.Parameters.Add(_Database.CreateParameter("fresnel_offset", wl.fresnelOffset));
989 cmd.Parameters.Add(_Database.CreateParameter("refract_scale_above", wl.refractScaleAbove));
990 cmd.Parameters.Add(_Database.CreateParameter("refract_scale_below", wl.refractScaleBelow));
991 cmd.Parameters.Add(_Database.CreateParameter("blur_multiplier", wl.blurMultiplier));
992 cmd.Parameters.Add(_Database.CreateParameter("big_wave_direction_x", wl.bigWaveDirection.X));
993 cmd.Parameters.Add(_Database.CreateParameter("big_wave_direction_y", wl.bigWaveDirection.Y));
994 cmd.Parameters.Add(_Database.CreateParameter("little_wave_direction_x", wl.littleWaveDirection.X));
995 cmd.Parameters.Add(_Database.CreateParameter("little_wave_direction_y", wl.littleWaveDirection.Y));
996 cmd.Parameters.Add(_Database.CreateParameter("normal_map_texture", wl.normalMapTexture));
997 cmd.Parameters.Add(_Database.CreateParameter("horizon_r", wl.horizon.X));
998 cmd.Parameters.Add(_Database.CreateParameter("horizon_g", wl.horizon.Y));
999 cmd.Parameters.Add(_Database.CreateParameter("horizon_b", wl.horizon.Z));
1000 cmd.Parameters.Add(_Database.CreateParameter("horizon_i", wl.horizon.W));
1001 cmd.Parameters.Add(_Database.CreateParameter("haze_horizon", wl.hazeHorizon));
1002 cmd.Parameters.Add(_Database.CreateParameter("blue_density_r", wl.blueDensity.X));
1003 cmd.Parameters.Add(_Database.CreateParameter("blue_density_g", wl.blueDensity.Y));
1004 cmd.Parameters.Add(_Database.CreateParameter("blue_density_b", wl.blueDensity.Z));
1005 cmd.Parameters.Add(_Database.CreateParameter("blue_density_i", wl.blueDensity.W));
1006 cmd.Parameters.Add(_Database.CreateParameter("haze_density", wl.hazeDensity));
1007 cmd.Parameters.Add(_Database.CreateParameter("density_multiplier", wl.densityMultiplier));
1008 cmd.Parameters.Add(_Database.CreateParameter("distance_multiplier", wl.distanceMultiplier));
1009 cmd.Parameters.Add(_Database.CreateParameter("max_altitude", wl.maxAltitude));
1010 cmd.Parameters.Add(_Database.CreateParameter("sun_moon_color_r", wl.sunMoonColor.X));
1011 cmd.Parameters.Add(_Database.CreateParameter("sun_moon_color_g", wl.sunMoonColor.Y));
1012 cmd.Parameters.Add(_Database.CreateParameter("sun_moon_color_b", wl.sunMoonColor.Z));
1013 cmd.Parameters.Add(_Database.CreateParameter("sun_moon_color_i", wl.sunMoonColor.W));
1014 cmd.Parameters.Add(_Database.CreateParameter("sun_moon_position", wl.sunMoonPosition));
1015 cmd.Parameters.Add(_Database.CreateParameter("ambient_r", wl.ambient.X));
1016 cmd.Parameters.Add(_Database.CreateParameter("ambient_g", wl.ambient.Y));
1017 cmd.Parameters.Add(_Database.CreateParameter("ambient_b", wl.ambient.Z));
1018 cmd.Parameters.Add(_Database.CreateParameter("ambient_i", wl.ambient.W));
1019 cmd.Parameters.Add(_Database.CreateParameter("east_angle", wl.eastAngle));
1020 cmd.Parameters.Add(_Database.CreateParameter("sun_glow_focus", wl.sunGlowFocus));
1021 cmd.Parameters.Add(_Database.CreateParameter("sun_glow_size", wl.sunGlowSize));
1022 cmd.Parameters.Add(_Database.CreateParameter("scene_gamma", wl.sceneGamma));
1023 cmd.Parameters.Add(_Database.CreateParameter("star_brightness", wl.starBrightness));
1024 cmd.Parameters.Add(_Database.CreateParameter("cloud_color_r", wl.cloudColor.X));
1025 cmd.Parameters.Add(_Database.CreateParameter("cloud_color_g", wl.cloudColor.Y));
1026 cmd.Parameters.Add(_Database.CreateParameter("cloud_color_b", wl.cloudColor.Z));
1027 cmd.Parameters.Add(_Database.CreateParameter("cloud_color_i", wl.cloudColor.W));
1028 cmd.Parameters.Add(_Database.CreateParameter("cloud_x", wl.cloudXYDensity.X));
1029 cmd.Parameters.Add(_Database.CreateParameter("cloud_y", wl.cloudXYDensity.Y));
1030 cmd.Parameters.Add(_Database.CreateParameter("cloud_density", wl.cloudXYDensity.Z));
1031 cmd.Parameters.Add(_Database.CreateParameter("cloud_coverage", wl.cloudCoverage));
1032 cmd.Parameters.Add(_Database.CreateParameter("cloud_scale", wl.cloudScale));
1033 cmd.Parameters.Add(_Database.CreateParameter("cloud_detail_x", wl.cloudDetailXYDensity.X));
1034 cmd.Parameters.Add(_Database.CreateParameter("cloud_detail_y", wl.cloudDetailXYDensity.Y));
1035 cmd.Parameters.Add(_Database.CreateParameter("cloud_detail_density", wl.cloudDetailXYDensity.Z));
1036 cmd.Parameters.Add(_Database.CreateParameter("cloud_scroll_x", wl.cloudScrollX));
1037 cmd.Parameters.Add(_Database.CreateParameter("cloud_scroll_x_lock", wl.cloudScrollXLock));
1038 cmd.Parameters.Add(_Database.CreateParameter("cloud_scroll_y", wl.cloudScrollY));
1039 cmd.Parameters.Add(_Database.CreateParameter("cloud_scroll_y_lock", wl.cloudScrollYLock));
1040 cmd.Parameters.Add(_Database.CreateParameter("draw_classic_clouds", wl.drawClassicClouds));
1041
1042 cmd.ExecuteNonQuery();
1043 }
1044 }
1045 #region update
1046 // }
1047 // else
1048 // {
1049 // // sql update
1050 // sql = @"UPDATE [OpenSim].[dbo].[regionwindlight]
1051 // SET [region_id] = @region_id
1052 // ,[water_color_r] = @water_color_r
1053 // ,[water_color_g] = @water_color_g
1054 // ,[water_color_b] = @water_color_b
1055 // ,[water_fog_density_exponent] = @water_fog_density_exponent
1056 // ,[underwater_fog_modifier] = @underwater_fog_modifier
1057 // ,[reflection_wavelet_scale_1] = @reflection_wavelet_scale_1
1058 // ,[reflection_wavelet_scale_2] = @reflection_wavelet_scale_2
1059 // ,[reflection_wavelet_scale_3] = @reflection_wavelet_scale_3
1060 // ,[fresnel_scale] = @fresnel_scale
1061 // ,[fresnel_offset] = @fresnel_offset
1062 // ,[refract_scale_above] = @refract_scale_above
1063 // ,[refract_scale_below] = @refract_scale_below
1064 // ,[blur_multiplier] = @blur_multiplier
1065 // ,[big_wave_direction_x] = @big_wave_direction_x
1066 // ,[big_wave_direction_y] = @big_wave_direction_y
1067 // ,[little_wave_direction_x] = @little_wave_direction_x
1068 // ,[little_wave_direction_y] = @little_wave_direction_y
1069 // ,[normal_map_texture] = @normal_map_texture
1070 // ,[horizon_r] = @horizon_r
1071 // ,[horizon_g] = @horizon_g
1072 // ,[horizon_b] = @horizon_b
1073 // ,[horizon_i] = @horizon_i
1074 // ,[haze_horizon] = @haze_horizon
1075 // ,[blue_density_r] = @blue_density_r
1076 // ,[blue_density_g] = @blue_density_g
1077 // ,[blue_density_b] = @blue_density_b
1078 // ,[blue_density_i] = @blue_density_i
1079 // ,[haze_density] = @haze_density
1080 // ,[density_multiplier] = @density_multiplier
1081 // ,[distance_multiplier] = @distance_multiplier
1082 // ,[max_altitude] = @max_altitude
1083 // ,[sun_moon_color_r] = @sun_moon_color_r
1084 // ,[sun_moon_color_g] = @sun_moon_color_g
1085 // ,[sun_moon_color_b] = @sun_moon_color_b
1086 // ,[sun_moon_color_i] = @sun_moon_color_i
1087 // ,[sun_moon_position] = @sun_moon_position
1088 // ,[ambient_r] = @ambient_r
1089 // ,[ambient_g] = @ambient_g
1090 // ,[ambient_b] = @ambient_b
1091 // ,[ambient_i] = @ambient_i
1092 // ,[east_angle] = @east_angle
1093 // ,[sun_glow_focus] = @sun_glow_focus
1094 // ,[sun_glow_size] = @sun_glow_size
1095 // ,[scene_gamma] = @scene_gamma
1096 // ,[star_brightness] = @star_brightness
1097 // ,[cloud_color_r] = @cloud_color_r
1098 // ,[cloud_color_g] = @cloud_color_g
1099 // ,[cloud_color_b] = @cloud_color_b
1100 // ,[cloud_color_i] = @cloud_color_i
1101 // ,[cloud_x] = @cloud_x
1102 // ,[cloud_y] = @cloud_y
1103 // ,[cloud_density] = @cloud_density
1104 // ,[cloud_coverage] = @cloud_coverage
1105 // ,[cloud_scale] = @cloud_scale
1106 // ,[cloud_detail_x] = @cloud_detail_x
1107 // ,[cloud_detail_y] = @cloud_detail_y
1108 // ,[cloud_detail_density] = @cloud_detail_density
1109 // ,[cloud_scroll_x] = @cloud_scroll_x
1110 // ,[cloud_scroll_x_lock] = @cloud_scroll_x_lock
1111 // ,[cloud_scroll_y] = @cloud_scroll_y
1112 // ,[cloud_scroll_y_lock] = @cloud_scroll_y_lock
1113 // ,[draw_classic_clouds] = @draw_classic_clouds
1114 // WHERE region_id = @region_id";
1115 // using (SqlConnection conn = new SqlConnection(m_connectionString))
1116 // {
1117 // conn.Open();
1118 // using (SqlCommand cmd = new SqlCommand(sql, conn))
1119 // {
1120 // cmd.Parameters.AddWithValue("region_id", wl.regionID);
1121 // cmd.Parameters.AddWithValue("water_color_r", wl.waterColor.X);
1122 // cmd.Parameters.AddWithValue("water_color_g", wl.waterColor.Y);
1123 // cmd.Parameters.AddWithValue("water_color_b", wl.waterColor.Z);
1124 // cmd.Parameters.AddWithValue("water_fog_density_exponent", wl.waterFogDensityExponent);
1125 // cmd.Parameters.AddWithValue("underwater_fog_modifier", wl.underwaterFogModifier);
1126 // cmd.Parameters.AddWithValue("reflection_wavelet_scale_1", wl.reflectionWaveletScale.X);
1127 // cmd.Parameters.AddWithValue("reflection_wavelet_scale_2", wl.reflectionWaveletScale.Y);
1128 // cmd.Parameters.AddWithValue("reflection_wavelet_scale_3", wl.reflectionWaveletScale.Z);
1129 // cmd.Parameters.AddWithValue("fresnel_scale", wl.fresnelScale);
1130 // cmd.Parameters.AddWithValue("fresnel_offset", wl.fresnelOffset);
1131 // cmd.Parameters.AddWithValue("refract_scale_above", wl.refractScaleAbove);
1132 // cmd.Parameters.AddWithValue("refract_scale_below", wl.refractScaleBelow);
1133 // cmd.Parameters.AddWithValue("blur_multiplier", wl.blurMultiplier);
1134 // cmd.Parameters.AddWithValue("big_wave_direction_x", wl.bigWaveDirection.X);
1135 // cmd.Parameters.AddWithValue("big_wave_direction_y", wl.bigWaveDirection.Y);
1136 // cmd.Parameters.AddWithValue("little_wave_direction_x", wl.littleWaveDirection.X);
1137 // cmd.Parameters.AddWithValue("little_wave_direction_y", wl.littleWaveDirection.Y);
1138 // cmd.Parameters.AddWithValue("normal_map_texture", wl.normalMapTexture);
1139 // cmd.Parameters.AddWithValue("horizon_r", wl.horizon.X);
1140 // cmd.Parameters.AddWithValue("horizon_g", wl.horizon.Y);
1141 // cmd.Parameters.AddWithValue("horizon_b", wl.horizon.Z);
1142 // cmd.Parameters.AddWithValue("horizon_i", wl.horizon.W);
1143 // cmd.Parameters.AddWithValue("haze_horizon", wl.hazeHorizon);
1144 // cmd.Parameters.AddWithValue("blue_density_r", wl.blueDensity.X);
1145 // cmd.Parameters.AddWithValue("blue_density_g", wl.blueDensity.Y);
1146 // cmd.Parameters.AddWithValue("blue_density_b", wl.blueDensity.Z);
1147 // cmd.Parameters.AddWithValue("blue_density_i", wl.blueDensity.W);
1148 // cmd.Parameters.AddWithValue("haze_density", wl.hazeDensity);
1149 // cmd.Parameters.AddWithValue("density_multiplier", wl.densityMultiplier);
1150 // cmd.Parameters.AddWithValue("distance_multiplier", wl.distanceMultiplier);
1151 // cmd.Parameters.AddWithValue("max_altitude", wl.maxAltitude);
1152 // cmd.Parameters.AddWithValue("sun_moon_color_r", wl.sunMoonColor.X);
1153 // cmd.Parameters.AddWithValue("sun_moon_color_g", wl.sunMoonColor.Y);
1154 // cmd.Parameters.AddWithValue("sun_moon_color_b", wl.sunMoonColor.Z);
1155 // cmd.Parameters.AddWithValue("sun_moon_color_i", wl.sunMoonColor.W);
1156 // cmd.Parameters.AddWithValue("sun_moon_position", wl.sunMoonPosition);
1157 // cmd.Parameters.AddWithValue("ambient_r", wl.ambient.X);
1158 // cmd.Parameters.AddWithValue("ambient_g", wl.ambient.Y);
1159 // cmd.Parameters.AddWithValue("ambient_b", wl.ambient.Z);
1160 // cmd.Parameters.AddWithValue("ambient_i", wl.ambient.W);
1161 // cmd.Parameters.AddWithValue("east_angle", wl.eastAngle);
1162 // cmd.Parameters.AddWithValue("sun_glow_focus", wl.sunGlowFocus);
1163 // cmd.Parameters.AddWithValue("sun_glow_size", wl.sunGlowSize);
1164 // cmd.Parameters.AddWithValue("scene_gamma", wl.sceneGamma);
1165 // cmd.Parameters.AddWithValue("star_brightness", wl.starBrightness);
1166 // cmd.Parameters.AddWithValue("cloud_color_r", wl.cloudColor.X);
1167 // cmd.Parameters.AddWithValue("cloud_color_g", wl.cloudColor.Y);
1168 // cmd.Parameters.AddWithValue("cloud_color_b", wl.cloudColor.Z);
1169 // cmd.Parameters.AddWithValue("cloud_color_i", wl.cloudColor.W);
1170 // cmd.Parameters.AddWithValue("cloud_x", wl.cloudXYDensity.X);
1171 // cmd.Parameters.AddWithValue("cloud_y", wl.cloudXYDensity.Y);
1172 // cmd.Parameters.AddWithValue("cloud_density", wl.cloudXYDensity.Z);
1173 // cmd.Parameters.AddWithValue("cloud_coverage", wl.cloudCoverage);
1174 // cmd.Parameters.AddWithValue("cloud_scale", wl.cloudScale);
1175 // cmd.Parameters.AddWithValue("cloud_detail_x", wl.cloudDetailXYDensity.X);
1176 // cmd.Parameters.AddWithValue("cloud_detail_y", wl.cloudDetailXYDensity.Y);
1177 // cmd.Parameters.AddWithValue("cloud_detail_density", wl.cloudDetailXYDensity.Z);
1178 // cmd.Parameters.AddWithValue("cloud_scroll_x", wl.cloudScrollX);
1179 // cmd.Parameters.AddWithValue("cloud_scroll_x_lock", wl.cloudScrollXLock);
1180 // cmd.Parameters.AddWithValue("cloud_scroll_y", wl.cloudScrollY);
1181 // cmd.Parameters.AddWithValue("cloud_scroll_y_lock", wl.cloudScrollYLock);
1182 // cmd.Parameters.AddWithValue("draw_classic_clouds", wl.drawClassicClouds);
1183
1184 // cmd.ExecuteNonQuery();
1185 // }
1186 // }
1187 // }
1188 #endregion
1189 }
1190
1191 #region Environment Settings
1192 public string LoadRegionEnvironmentSettings(UUID regionUUID)
1193 {
1194 string sql = "select * from regionenvironment where region_id = :region_id";
1195 using (NpgsqlConnection conn = new NpgsqlConnection(m_connectionString))
1196 using (NpgsqlCommand cmd = new NpgsqlCommand(sql, conn))
1197 {
1198 cmd.Parameters.Add(_Database.CreateParameter("region_id", regionUUID));
1199 conn.Open();
1200 using (NpgsqlDataReader result = cmd.ExecuteReader())
1201 {
1202 if (!result.Read())
1203 {
1204 return String.Empty;
1205 }
1206 else
1207 {
1208 return Convert.ToString(result["llsd_settings"]);
1209 }
1210 }
1211 }
1212 }
1213
1214 public void StoreRegionEnvironmentSettings(UUID regionUUID, string settings)
1215 {
1216 {
1217 string sql = "DELETE FROM regionenvironment WHERE region_id = :region_id ;";
1218
1219 using (NpgsqlConnection conn = new NpgsqlConnection(m_connectionString))
1220 using (NpgsqlCommand cmd = new NpgsqlCommand(sql, conn))
1221 {
1222 cmd.Parameters.Add(_Database.CreateParameter("region_id", regionUUID));
1223 conn.Open();
1224 cmd.ExecuteNonQuery();
1225 }
1226
1227 sql = "INSERT INTO regionenvironment (region_id, llsd_settings) VALUES (:region_id, :llsd_settings) ;";
1228
1229 using (NpgsqlConnection conn = new NpgsqlConnection(m_connectionString))
1230 using (NpgsqlCommand cmd = new NpgsqlCommand(sql, conn))
1231 {
1232 cmd.Parameters.Add(_Database.CreateParameter("region_id", regionUUID));
1233 cmd.Parameters.Add(_Database.CreateParameter("llsd_settings", settings));
1234
1235 conn.Open();
1236 cmd.ExecuteNonQuery();
1237 }
1238 }
1239 }
1240
1241 public void RemoveRegionEnvironmentSettings(UUID regionUUID)
1242 {
1243 string sql = "delete from regionenvironment where region_id = :region_id ;";
1244 using (NpgsqlConnection conn = new NpgsqlConnection(m_connectionString))
1245 using (NpgsqlCommand cmd = new NpgsqlCommand(sql, conn))
1246 {
1247 cmd.Parameters.Add(_Database.CreateParameter("region_id", regionUUID));
1248
1249 conn.Open();
1250 cmd.ExecuteNonQuery();
1251 }
1252 }
1253 #endregion
1254
1255 /// <summary>
1256 /// Loads the settings of a region.
1257 /// </summary>
1258 /// <param name="regionUUID">The region UUID.</param>
1259 /// <returns></returns>
1260 public RegionSettings LoadRegionSettings(UUID regionUUID)
1261 {
1262 string sql = @"select * from regionsettings where ""regionUUID"" = :regionUUID";
1263 RegionSettings regionSettings;
1264 using (NpgsqlConnection conn = new NpgsqlConnection(m_connectionString))
1265 using (NpgsqlCommand cmd = new NpgsqlCommand(sql, conn))
1266 {
1267 cmd.Parameters.Add(_Database.CreateParameter("regionUUID", regionUUID));
1268 conn.Open();
1269 using (NpgsqlDataReader reader = cmd.ExecuteReader())
1270 {
1271 if (reader.Read())
1272 {
1273 regionSettings = BuildRegionSettings(reader);
1274 regionSettings.OnSave += StoreRegionSettings;
1275
1276 return regionSettings;
1277 }
1278 }
1279 }
1280
1281 //If we reach this point then there are new region settings for that region
1282 regionSettings = new RegionSettings();
1283 regionSettings.RegionUUID = regionUUID;
1284 regionSettings.OnSave += StoreRegionSettings;
1285
1286 //Store new values
1287 StoreNewRegionSettings(regionSettings);
1288
1289 LoadSpawnPoints(regionSettings);
1290
1291 return regionSettings;
1292 }
1293
1294 /// <summary>
1295 /// Store region settings, need to check if the check is really necesary. If we can make something for creating new region.
1296 /// </summary>
1297 /// <param name="regionSettings">region settings.</param>
1298 public void StoreRegionSettings(RegionSettings regionSettings)
1299 {
1300 //Little check if regionUUID already exist in DB
1301 string regionUUID;
1302 string sql = @"SELECT ""regionUUID"" FROM regionsettings WHERE ""regionUUID"" = :regionUUID";
1303 using (NpgsqlConnection conn = new NpgsqlConnection(m_connectionString))
1304 using (NpgsqlCommand cmd = new NpgsqlCommand(sql, conn))
1305 {
1306 cmd.Parameters.Add(_Database.CreateParameter("regionUUID", regionSettings.RegionUUID));
1307 conn.Open();
1308 regionUUID = cmd.ExecuteScalar().ToString();
1309 }
1310
1311 if (string.IsNullOrEmpty(regionUUID))
1312 {
1313 StoreNewRegionSettings(regionSettings);
1314 }
1315 else
1316 {
1317 //This method only updates region settings!!! First call LoadRegionSettings to create new region settings in DB
1318 sql =
1319 @"UPDATE regionsettings SET block_terraform = :block_terraform ,block_fly = :block_fly ,allow_damage = :allow_damage
1320,restrict_pushing = :restrict_pushing ,allow_land_resell = :allow_land_resell ,allow_land_join_divide = :allow_land_join_divide
1321,block_show_in_search = :block_show_in_search ,agent_limit = :agent_limit ,object_bonus = :object_bonus ,maturity = :maturity
1322,disable_scripts = :disable_scripts ,disable_collisions = :disable_collisions ,disable_physics = :disable_physics
1323,terrain_texture_1 = :terrain_texture_1 ,terrain_texture_2 = :terrain_texture_2 ,terrain_texture_3 = :terrain_texture_3
1324,terrain_texture_4 = :terrain_texture_4 ,elevation_1_nw = :elevation_1_nw ,elevation_2_nw = :elevation_2_nw
1325,elevation_1_ne = :elevation_1_ne ,elevation_2_ne = :elevation_2_ne ,elevation_1_se = :elevation_1_se ,elevation_2_se = :elevation_2_se
1326,elevation_1_sw = :elevation_1_sw ,elevation_2_sw = :elevation_2_sw ,water_height = :water_height ,terrain_raise_limit = :terrain_raise_limit
1327,terrain_lower_limit = :terrain_lower_limit ,use_estate_sun = :use_estate_sun ,fixed_sun = :fixed_sun ,sun_position = :sun_position
1328,covenant = :covenant ,covenant_datetime = :covenant_datetime, sunvectorx = :sunvectorx, sunvectory = :sunvectory, sunvectorz = :sunvectorz,
1329""Sandbox"" = :Sandbox, loaded_creation_datetime = :loaded_creation_datetime, loaded_creation_id = :loaded_creation_id, ""map_tile_ID"" = :TerrainImageID,
1330""TelehubObject"" = :telehubobject, ""parcel_tile_ID"" = :ParcelImageID
1331 WHERE ""regionUUID"" = :regionUUID";
1332
1333 using (NpgsqlConnection conn = new NpgsqlConnection(m_connectionString))
1334 using (NpgsqlCommand cmd = new NpgsqlCommand(sql, conn))
1335 {
1336 cmd.Parameters.AddRange(CreateRegionSettingParameters(regionSettings));
1337 conn.Open();
1338 cmd.ExecuteNonQuery();
1339 }
1340 }
1341 SaveSpawnPoints(regionSettings);
1342 }
1343
1344 public void Shutdown()
1345 {
1346 //Not used??
1347 }
1348
1349 #region Private Methods
1350
1351 /// <summary>
1352 /// Serializes the terrain data for storage in DB.
1353 /// </summary>
1354 /// <param name="val">terrain data</param>
1355 /// <returns></returns>
1356 private static Array serializeTerrain(double[,] val)
1357 {
1358 MemoryStream str = new MemoryStream(((int)Constants.RegionSize * (int)Constants.RegionSize) * sizeof(double));
1359 BinaryWriter bw = new BinaryWriter(str);
1360
1361 // TODO: COMPATIBILITY - Add byte-order conversions
1362 for (int x = 0; x < (int)Constants.RegionSize; x++)
1363 for (int y = 0; y < (int)Constants.RegionSize; y++)
1364 {
1365 double height = val[x, y];
1366 if (height == 0.0)
1367 height = double.Epsilon;
1368
1369 bw.Write(height);
1370 }
1371
1372 return str.ToArray();
1373 }
1374
1375 /// <summary>
1376 /// Stores new regionsettings.
1377 /// </summary>
1378 /// <param name="regionSettings">The region settings.</param>
1379 private void StoreNewRegionSettings(RegionSettings regionSettings)
1380 {
1381 string sql = @"INSERT INTO regionsettings
1382 (""regionUUID"",block_terraform,block_fly,allow_damage,restrict_pushing,allow_land_resell,allow_land_join_divide,
1383 block_show_in_search,agent_limit,object_bonus,maturity,disable_scripts,disable_collisions,disable_physics,
1384 terrain_texture_1,terrain_texture_2,terrain_texture_3,terrain_texture_4,elevation_1_nw,elevation_2_nw,elevation_1_ne,
1385 elevation_2_ne,elevation_1_se,elevation_2_se,elevation_1_sw,elevation_2_sw,water_height,terrain_raise_limit,
1386 terrain_lower_limit,use_estate_sun,fixed_sun,sun_position,covenant,covenant_datetime,sunvectorx, sunvectory, sunvectorz,
1387 ""Sandbox"", loaded_creation_datetime, loaded_creation_id
1388 )
1389 VALUES
1390 (:regionUUID,:block_terraform,:block_fly,:allow_damage,:restrict_pushing,:allow_land_resell,:allow_land_join_divide,
1391 :block_show_in_search,:agent_limit,:object_bonus,:maturity,:disable_scripts,:disable_collisions,:disable_physics,
1392 :terrain_texture_1,:terrain_texture_2,:terrain_texture_3,:terrain_texture_4,:elevation_1_nw,:elevation_2_nw,:elevation_1_ne,
1393 :elevation_2_ne,:elevation_1_se,:elevation_2_se,:elevation_1_sw,:elevation_2_sw,:water_height,:terrain_raise_limit,
1394 :terrain_lower_limit,:use_estate_sun,:fixed_sun,:sun_position,:covenant, :covenant_datetime, :sunvectorx,:sunvectory,
1395 :sunvectorz, :Sandbox, :loaded_creation_datetime, :loaded_creation_id )";
1396
1397 using (NpgsqlConnection conn = new NpgsqlConnection(m_connectionString))
1398 using (NpgsqlCommand cmd = new NpgsqlCommand(sql, conn))
1399 {
1400 cmd.Parameters.AddRange(CreateRegionSettingParameters(regionSettings));
1401 conn.Open();
1402 cmd.ExecuteNonQuery();
1403 }
1404 }
1405
1406 #region Private DataRecord conversion methods
1407
1408 /// <summary>
1409 /// Builds the region settings from a datarecod.
1410 /// </summary>
1411 /// <param name="row">datarecord with regionsettings.</param>
1412 /// <returns></returns>
1413 private static RegionSettings BuildRegionSettings(IDataRecord row)
1414 {
1415 //TODO change this is some more generic code so we doesnt have to change it every time a new field is added?
1416 RegionSettings newSettings = new RegionSettings();
1417
1418 newSettings.RegionUUID = new UUID((Guid)row["regionUUID"]);
1419 newSettings.BlockTerraform = Convert.ToBoolean(row["block_terraform"]);
1420 newSettings.AllowDamage = Convert.ToBoolean(row["allow_damage"]);
1421 newSettings.BlockFly = Convert.ToBoolean(row["block_fly"]);
1422 newSettings.RestrictPushing = Convert.ToBoolean(row["restrict_pushing"]);
1423 newSettings.AllowLandResell = Convert.ToBoolean(row["allow_land_resell"]);
1424 newSettings.AllowLandJoinDivide = Convert.ToBoolean(row["allow_land_join_divide"]);
1425 newSettings.BlockShowInSearch = Convert.ToBoolean(row["block_show_in_search"]);
1426 newSettings.AgentLimit = Convert.ToInt32(row["agent_limit"]);
1427 newSettings.ObjectBonus = Convert.ToDouble(row["object_bonus"]);
1428 newSettings.Maturity = Convert.ToInt32(row["maturity"]);
1429 newSettings.DisableScripts = Convert.ToBoolean(row["disable_scripts"]);
1430 newSettings.DisableCollisions = Convert.ToBoolean(row["disable_collisions"]);
1431 newSettings.DisablePhysics = Convert.ToBoolean(row["disable_physics"]);
1432 newSettings.TerrainTexture1 = new UUID((Guid)row["terrain_texture_1"]);
1433 newSettings.TerrainTexture2 = new UUID((Guid)row["terrain_texture_2"]);
1434 newSettings.TerrainTexture3 = new UUID((Guid)row["terrain_texture_3"]);
1435 newSettings.TerrainTexture4 = new UUID((Guid)row["terrain_texture_4"]);
1436 newSettings.Elevation1NW = Convert.ToDouble(row["elevation_1_nw"]);
1437 newSettings.Elevation2NW = Convert.ToDouble(row["elevation_2_nw"]);
1438 newSettings.Elevation1NE = Convert.ToDouble(row["elevation_1_ne"]);
1439 newSettings.Elevation2NE = Convert.ToDouble(row["elevation_2_ne"]);
1440 newSettings.Elevation1SE = Convert.ToDouble(row["elevation_1_se"]);
1441 newSettings.Elevation2SE = Convert.ToDouble(row["elevation_2_se"]);
1442 newSettings.Elevation1SW = Convert.ToDouble(row["elevation_1_sw"]);
1443 newSettings.Elevation2SW = Convert.ToDouble(row["elevation_2_sw"]);
1444 newSettings.WaterHeight = Convert.ToDouble(row["water_height"]);
1445 newSettings.TerrainRaiseLimit = Convert.ToDouble(row["terrain_raise_limit"]);
1446 newSettings.TerrainLowerLimit = Convert.ToDouble(row["terrain_lower_limit"]);
1447 newSettings.UseEstateSun = Convert.ToBoolean(row["use_estate_sun"]);
1448 newSettings.Sandbox = Convert.ToBoolean(row["Sandbox"]);
1449 newSettings.FixedSun = Convert.ToBoolean(row["fixed_sun"]);
1450 newSettings.SunPosition = Convert.ToDouble(row["sun_position"]);
1451 newSettings.SunVector = new Vector3(
1452 Convert.ToSingle(row["sunvectorx"]),
1453 Convert.ToSingle(row["sunvectory"]),
1454 Convert.ToSingle(row["sunvectorz"])
1455 );
1456 newSettings.Covenant = new UUID((Guid)row["covenant"]);
1457 newSettings.CovenantChangedDateTime = Convert.ToInt32(row["covenant_datetime"]);
1458 newSettings.LoadedCreationDateTime = Convert.ToInt32(row["loaded_creation_datetime"]);
1459
1460 if (row["loaded_creation_id"] is DBNull)
1461 newSettings.LoadedCreationID = "";
1462 else
1463 newSettings.LoadedCreationID = (String)row["loaded_creation_id"];
1464
1465 newSettings.TerrainImageID = new UUID((string)row["map_tile_ID"]);
1466 newSettings.ParcelImageID = new UUID((Guid)row["parcel_tile_ID"]);
1467 newSettings.TelehubObject = new UUID((Guid)row["TelehubObject"]);
1468
1469 return newSettings;
1470 }
1471
1472 /// <summary>
1473 /// Builds the land data from a datarecord.
1474 /// </summary>
1475 /// <param name="row">datarecord with land data</param>
1476 /// <returns></returns>
1477 private static LandData BuildLandData(IDataRecord row)
1478 {
1479 LandData newData = new LandData();
1480
1481 newData.GlobalID = new UUID((Guid)row["UUID"]);
1482 newData.LocalID = Convert.ToInt32(row["LocalLandID"]);
1483
1484 // Bitmap is a byte[512]
1485 newData.Bitmap = (Byte[])row["Bitmap"];
1486
1487 newData.Name = (string)row["Name"];
1488 newData.Description = (string)row["Description"];
1489 newData.OwnerID = new UUID((Guid)row["OwnerUUID"]);
1490 newData.IsGroupOwned = Convert.ToBoolean(row["IsGroupOwned"]);
1491 newData.Area = Convert.ToInt32(row["Area"]);
1492 newData.AuctionID = Convert.ToUInt32(row["AuctionID"]); //Unemplemented
1493 newData.Category = (ParcelCategory)Convert.ToInt32(row["Category"]);
1494 //Enum libsecondlife.Parcel.ParcelCategory
1495 newData.ClaimDate = Convert.ToInt32(row["ClaimDate"]);
1496 newData.ClaimPrice = Convert.ToInt32(row["ClaimPrice"]);
1497 newData.GroupID = new UUID((Guid)row["GroupUUID"]);
1498 newData.SalePrice = Convert.ToInt32(row["SalePrice"]);
1499 newData.Status = (ParcelStatus)Convert.ToInt32(row["LandStatus"]);
1500 //Enum. libsecondlife.Parcel.ParcelStatus
1501 newData.Flags = Convert.ToUInt32(row["LandFlags"]);
1502 newData.LandingType = Convert.ToByte(row["LandingType"]);
1503 newData.MediaAutoScale = Convert.ToByte(row["MediaAutoScale"]);
1504 newData.MediaID = new UUID((Guid)row["MediaTextureUUID"]);
1505 newData.MediaURL = (string)row["MediaURL"];
1506 newData.MusicURL = (string)row["MusicURL"];
1507 newData.PassHours = Convert.ToSingle(row["PassHours"]);
1508 newData.PassPrice = Convert.ToInt32(row["PassPrice"]);
1509
1510 // UUID authedbuyer;
1511 // UUID snapshotID;
1512 //
1513 // if (UUID.TryParse((string)row["AuthBuyerID"], out authedbuyer))
1514 // newData.AuthBuyerID = authedbuyer;
1515 //
1516 // if (UUID.TryParse((string)row["SnapshotUUID"], out snapshotID))
1517 // newData.SnapshotID = snapshotID;
1518 newData.AuthBuyerID = new UUID((Guid)row["AuthBuyerID"]);
1519 newData.SnapshotID = new UUID((Guid)row["SnapshotUUID"]);
1520
1521 newData.OtherCleanTime = Convert.ToInt32(row["OtherCleanTime"]);
1522
1523 try
1524 {
1525 newData.UserLocation =
1526 new Vector3(Convert.ToSingle(row["UserLocationX"]), Convert.ToSingle(row["UserLocationY"]),
1527 Convert.ToSingle(row["UserLocationZ"]));
1528 newData.UserLookAt =
1529 new Vector3(Convert.ToSingle(row["UserLookAtX"]), Convert.ToSingle(row["UserLookAtY"]),
1530 Convert.ToSingle(row["UserLookAtZ"]));
1531 }
1532 catch (InvalidCastException)
1533 {
1534 newData.UserLocation = Vector3.Zero;
1535 newData.UserLookAt = Vector3.Zero;
1536 _Log.ErrorFormat("[PARCEL]: unable to get parcel telehub settings for {1}", newData.Name);
1537 }
1538
1539 newData.ParcelAccessList = new List<LandAccessEntry>();
1540 newData.MediaDescription = (string)row["MediaDescription"];
1541 newData.MediaType = (string)row["MediaType"];
1542 newData.MediaWidth = Convert.ToInt32((((string)row["MediaSize"]).Split(','))[0]);
1543 newData.MediaHeight = Convert.ToInt32((((string)row["MediaSize"]).Split(','))[1]);
1544 newData.MediaLoop = Convert.ToBoolean(row["MediaLoop"]);
1545 newData.ObscureMusic = Convert.ToBoolean(row["ObscureMusic"]);
1546 newData.ObscureMedia = Convert.ToBoolean(row["ObscureMedia"]);
1547
1548 return newData;
1549 }
1550
1551 /// <summary>
1552 /// Builds the landaccess data from a data record.
1553 /// </summary>
1554 /// <param name="row">datarecord with landaccess data</param>
1555 /// <returns></returns>
1556 private static LandAccessEntry BuildLandAccessData(IDataRecord row)
1557 {
1558 LandAccessEntry entry = new LandAccessEntry();
1559 entry.AgentID = new UUID((Guid)row["AccessUUID"]);
1560 entry.Flags = (AccessList)Convert.ToInt32(row["Flags"]);
1561 entry.Expires = Convert.ToInt32(row["Expires"]);
1562 return entry;
1563 }
1564
1565 /// <summary>
1566 /// Builds the prim from a datarecord.
1567 /// </summary>
1568 /// <param name="primRow">datarecord</param>
1569 /// <returns></returns>
1570 private static SceneObjectPart BuildPrim(IDataRecord primRow)
1571 {
1572 SceneObjectPart prim = new SceneObjectPart();
1573
1574 prim.UUID = new UUID((Guid)primRow["UUID"]);
1575 // explicit conversion of integers is required, which sort
1576 // of sucks. No idea if there is a shortcut here or not.
1577 prim.CreationDate = Convert.ToInt32(primRow["CreationDate"]);
1578 prim.Name = (string)primRow["Name"];
1579 // various text fields
1580 prim.Text = (string)primRow["Text"];
1581 prim.Color = Color.FromArgb(Convert.ToInt32(primRow["ColorA"]),
1582 Convert.ToInt32(primRow["ColorR"]),
1583 Convert.ToInt32(primRow["ColorG"]),
1584 Convert.ToInt32(primRow["ColorB"]));
1585 prim.Description = (string)primRow["Description"];
1586 prim.SitName = (string)primRow["SitName"];
1587 prim.TouchName = (string)primRow["TouchName"];
1588 // permissions
1589 prim.Flags = (PrimFlags)Convert.ToUInt32(primRow["ObjectFlags"]);
1590 //prim.creatorID = new UUID((Guid)primRow["creatorID"]);
1591 prim.CreatorIdentification = (string)primRow["CreatorID"].ToString();
1592 prim.OwnerID = new UUID((Guid)primRow["OwnerID"]);
1593 prim.GroupID = new UUID((Guid)primRow["GroupID"]);
1594 prim.LastOwnerID = new UUID((Guid)primRow["LastOwnerID"]);
1595 prim.OwnerMask = Convert.ToUInt32(primRow["OwnerMask"]);
1596 prim.NextOwnerMask = Convert.ToUInt32(primRow["NextOwnerMask"]);
1597 prim.GroupMask = Convert.ToUInt32(primRow["GroupMask"]);
1598 prim.EveryoneMask = Convert.ToUInt32(primRow["EveryoneMask"]);
1599 prim.BaseMask = Convert.ToUInt32(primRow["BaseMask"]);
1600 // vectors
1601 prim.OffsetPosition = new Vector3(
1602 Convert.ToSingle(primRow["PositionX"]),
1603 Convert.ToSingle(primRow["PositionY"]),
1604 Convert.ToSingle(primRow["PositionZ"]));
1605
1606 prim.GroupPosition = new Vector3(
1607 Convert.ToSingle(primRow["GroupPositionX"]),
1608 Convert.ToSingle(primRow["GroupPositionY"]),
1609 Convert.ToSingle(primRow["GroupPositionZ"]));
1610
1611 prim.Velocity = new Vector3(
1612 Convert.ToSingle(primRow["VelocityX"]),
1613 Convert.ToSingle(primRow["VelocityY"]),
1614 Convert.ToSingle(primRow["VelocityZ"]));
1615
1616 prim.AngularVelocity = new Vector3(
1617 Convert.ToSingle(primRow["AngularVelocityX"]),
1618 Convert.ToSingle(primRow["AngularVelocityY"]),
1619 Convert.ToSingle(primRow["AngularVelocityZ"]));
1620
1621 prim.Acceleration = new Vector3(
1622 Convert.ToSingle(primRow["AccelerationX"]),
1623 Convert.ToSingle(primRow["AccelerationY"]),
1624 Convert.ToSingle(primRow["AccelerationZ"]));
1625
1626 // quaternions
1627 prim.RotationOffset = new Quaternion(
1628 Convert.ToSingle(primRow["RotationX"]),
1629 Convert.ToSingle(primRow["RotationY"]),
1630 Convert.ToSingle(primRow["RotationZ"]),
1631 Convert.ToSingle(primRow["RotationW"]));
1632
1633 prim.SitTargetPositionLL = new Vector3(
1634 Convert.ToSingle(primRow["SitTargetOffsetX"]),
1635 Convert.ToSingle(primRow["SitTargetOffsetY"]),
1636 Convert.ToSingle(primRow["SitTargetOffsetZ"]));
1637
1638 prim.SitTargetOrientationLL = new Quaternion(
1639 Convert.ToSingle(primRow["SitTargetOrientX"]),
1640 Convert.ToSingle(primRow["SitTargetOrientY"]),
1641 Convert.ToSingle(primRow["SitTargetOrientZ"]),
1642 Convert.ToSingle(primRow["SitTargetOrientW"]));
1643
1644 prim.PayPrice[0] = Convert.ToInt32(primRow["PayPrice"]);
1645 prim.PayPrice[1] = Convert.ToInt32(primRow["PayButton1"]);
1646 prim.PayPrice[2] = Convert.ToInt32(primRow["PayButton2"]);
1647 prim.PayPrice[3] = Convert.ToInt32(primRow["PayButton3"]);
1648 prim.PayPrice[4] = Convert.ToInt32(primRow["PayButton4"]);
1649
1650 prim.Sound = new UUID((Guid)primRow["LoopedSound"]);
1651 prim.SoundGain = Convert.ToSingle(primRow["LoopedSoundGain"]);
1652 prim.SoundFlags = 1; // If it's persisted at all, it's looped
1653
1654 if (!(primRow["TextureAnimation"] is DBNull))
1655 prim.TextureAnimation = (Byte[])primRow["TextureAnimation"];
1656 if (!(primRow["ParticleSystem"] is DBNull))
1657 prim.ParticleSystem = (Byte[])primRow["ParticleSystem"];
1658
1659 prim.AngularVelocity = new Vector3(
1660 Convert.ToSingle(primRow["OmegaX"]),
1661 Convert.ToSingle(primRow["OmegaY"]),
1662 Convert.ToSingle(primRow["OmegaZ"]));
1663
1664 prim.SetCameraEyeOffset(new Vector3(
1665 Convert.ToSingle(primRow["CameraEyeOffsetX"]),
1666 Convert.ToSingle(primRow["CameraEyeOffsetY"]),
1667 Convert.ToSingle(primRow["CameraEyeOffsetZ"])
1668 ));
1669
1670 prim.SetCameraAtOffset(new Vector3(
1671 Convert.ToSingle(primRow["CameraAtOffsetX"]),
1672 Convert.ToSingle(primRow["CameraAtOffsetY"]),
1673 Convert.ToSingle(primRow["CameraAtOffsetZ"])
1674 ));
1675
1676 if (Convert.ToInt16(primRow["ForceMouselook"]) != 0)
1677 prim.SetForceMouselook(true);
1678
1679 prim.ScriptAccessPin = Convert.ToInt32(primRow["ScriptAccessPin"]);
1680
1681 if (Convert.ToInt16(primRow["AllowedDrop"]) != 0)
1682 prim.AllowedDrop = true;
1683
1684 if (Convert.ToInt16(primRow["DieAtEdge"]) != 0)
1685 prim.DIE_AT_EDGE = true;
1686
1687 prim.SalePrice = Convert.ToInt32(primRow["SalePrice"]);
1688 prim.ObjectSaleType = Convert.ToByte(primRow["SaleType"]);
1689
1690 prim.Material = Convert.ToByte(primRow["Material"]);
1691
1692 if (!(primRow["ClickAction"] is DBNull))
1693 prim.ClickAction = Convert.ToByte(primRow["ClickAction"]);
1694
1695 prim.CollisionSound = new UUID((Guid)primRow["CollisionSound"]);
1696 prim.CollisionSoundVolume = Convert.ToSingle(primRow["CollisionSoundVolume"]);
1697
1698 prim.PassTouches = (bool)primRow["PassTouches"];
1699
1700 if (!(primRow["MediaURL"] is System.DBNull))
1701 prim.MediaUrl = (string)primRow["MediaURL"];
1702
1703 if (!(primRow["DynAttrs"] is System.DBNull) && (string)primRow["DynAttrs"] != "")
1704 prim.DynAttrs = DAMap.FromXml((string)primRow["DynAttrs"]);
1705 else
1706 prim.DynAttrs = new DAMap();
1707
1708 prim.PhysicsShapeType = Convert.ToByte(primRow["PhysicsShapeType"]);
1709 prim.Density = Convert.ToSingle(primRow["Density"]);
1710 prim.GravityModifier = Convert.ToSingle(primRow["GravityModifier"]);
1711 prim.Friction = Convert.ToSingle(primRow["Friction"]);
1712 prim.Restitution = Convert.ToSingle(primRow["Restitution"]);
1713
1714 return prim;
1715 }
1716
1717 /// <summary>
1718 /// Builds the prim shape from a datarecord.
1719 /// </summary>
1720 /// <param name="shapeRow">The row.</param>
1721 /// <returns></returns>
1722 private static PrimitiveBaseShape BuildShape(IDataRecord shapeRow)
1723 {
1724 PrimitiveBaseShape baseShape = new PrimitiveBaseShape();
1725
1726 baseShape.Scale = new Vector3(
1727 (float)Convert.ToDouble(shapeRow["ScaleX"]),
1728 (float)Convert.ToDouble(shapeRow["ScaleY"]),
1729 (float)Convert.ToDouble(shapeRow["ScaleZ"]));
1730
1731 // paths
1732 baseShape.PCode = Convert.ToByte(shapeRow["PCode"]);
1733 baseShape.PathBegin = Convert.ToUInt16(shapeRow["PathBegin"]);
1734 baseShape.PathEnd = Convert.ToUInt16(shapeRow["PathEnd"]);
1735 baseShape.PathScaleX = Convert.ToByte(shapeRow["PathScaleX"]);
1736 baseShape.PathScaleY = Convert.ToByte(shapeRow["PathScaleY"]);
1737 baseShape.PathShearX = Convert.ToByte(shapeRow["PathShearX"]);
1738 baseShape.PathShearY = Convert.ToByte(shapeRow["PathShearY"]);
1739 baseShape.PathSkew = Convert.ToSByte(shapeRow["PathSkew"]);
1740 baseShape.PathCurve = Convert.ToByte(shapeRow["PathCurve"]);
1741 baseShape.PathRadiusOffset = Convert.ToSByte(shapeRow["PathRadiusOffset"]);
1742 baseShape.PathRevolutions = Convert.ToByte(shapeRow["PathRevolutions"]);
1743 baseShape.PathTaperX = Convert.ToSByte(shapeRow["PathTaperX"]);
1744 baseShape.PathTaperY = Convert.ToSByte(shapeRow["PathTaperY"]);
1745 baseShape.PathTwist = Convert.ToSByte(shapeRow["PathTwist"]);
1746 baseShape.PathTwistBegin = Convert.ToSByte(shapeRow["PathTwistBegin"]);
1747 // profile
1748 baseShape.ProfileBegin = Convert.ToUInt16(shapeRow["ProfileBegin"]);
1749 baseShape.ProfileEnd = Convert.ToUInt16(shapeRow["ProfileEnd"]);
1750 baseShape.ProfileCurve = Convert.ToByte(shapeRow["ProfileCurve"]);
1751 baseShape.ProfileHollow = Convert.ToUInt16(shapeRow["ProfileHollow"]);
1752
1753 byte[] textureEntry = (byte[])shapeRow["Texture"];
1754 baseShape.TextureEntry = textureEntry;
1755
1756 baseShape.ExtraParams = (byte[])shapeRow["ExtraParams"];
1757
1758 try
1759 {
1760 baseShape.State = Convert.ToByte(shapeRow["State"]);
1761 }
1762 catch (InvalidCastException)
1763 {
1764 }
1765
1766 if (!(shapeRow["Media"] is System.DBNull))
1767 {
1768 baseShape.Media = PrimitiveBaseShape.MediaList.FromXml((string)shapeRow["Media"]);
1769 }
1770
1771 return baseShape;
1772 }
1773
1774 /// <summary>
1775 /// Build a prim inventory item from the persisted data.
1776 /// </summary>
1777 /// <param name="inventoryRow"></param>
1778 /// <returns></returns>
1779 private static TaskInventoryItem BuildItem(IDataRecord inventoryRow)
1780 {
1781 TaskInventoryItem taskItem = new TaskInventoryItem();
1782
1783 taskItem.ItemID = new UUID((Guid)inventoryRow["itemID"]);
1784 taskItem.ParentPartID = new UUID((Guid)inventoryRow["primID"]);
1785 taskItem.AssetID = new UUID((Guid)inventoryRow["assetID"]);
1786 taskItem.ParentID = new UUID((Guid)inventoryRow["parentFolderID"]);
1787
1788 taskItem.InvType = Convert.ToInt32(inventoryRow["invType"]);
1789 taskItem.Type = Convert.ToInt32(inventoryRow["assetType"]);
1790
1791 taskItem.Name = (string)inventoryRow["name"];
1792 taskItem.Description = (string)inventoryRow["description"];
1793 taskItem.CreationDate = Convert.ToUInt32(inventoryRow["creationDate"]);
1794 //taskItem.creatorID = new UUID((Guid)inventoryRow["creatorID"]);
1795 taskItem.CreatorIdentification = (string)inventoryRow["creatorID"].ToString();
1796 taskItem.OwnerID = new UUID((Guid)inventoryRow["ownerID"]);
1797 taskItem.LastOwnerID = new UUID((Guid)inventoryRow["lastOwnerID"]);
1798 taskItem.GroupID = new UUID((Guid)inventoryRow["groupID"]);
1799
1800 taskItem.NextPermissions = Convert.ToUInt32(inventoryRow["nextPermissions"]);
1801 taskItem.CurrentPermissions = Convert.ToUInt32(inventoryRow["currentPermissions"]);
1802 taskItem.BasePermissions = Convert.ToUInt32(inventoryRow["basePermissions"]);
1803 taskItem.EveryonePermissions = Convert.ToUInt32(inventoryRow["everyonePermissions"]);
1804 taskItem.GroupPermissions = Convert.ToUInt32(inventoryRow["groupPermissions"]);
1805 taskItem.Flags = Convert.ToUInt32(inventoryRow["flags"]);
1806
1807 return taskItem;
1808 }
1809
1810 #endregion
1811
1812 #region Create parameters methods
1813
1814 /// <summary>
1815 /// Creates the prim inventory parameters.
1816 /// </summary>
1817 /// <param name="taskItem">item in inventory.</param>
1818 /// <returns></returns>
1819 private NpgsqlParameter[] CreatePrimInventoryParameters(TaskInventoryItem taskItem)
1820 {
1821 List<NpgsqlParameter> parameters = new List<NpgsqlParameter>();
1822
1823 parameters.Add(_Database.CreateParameter("itemID", taskItem.ItemID));
1824 parameters.Add(_Database.CreateParameter("primID", taskItem.ParentPartID));
1825 parameters.Add(_Database.CreateParameter("assetID", taskItem.AssetID));
1826 parameters.Add(_Database.CreateParameter("parentFolderID", taskItem.ParentID));
1827 parameters.Add(_Database.CreateParameter("invType", taskItem.InvType));
1828 parameters.Add(_Database.CreateParameter("assetType", taskItem.Type));
1829
1830 parameters.Add(_Database.CreateParameter("name", taskItem.Name));
1831 parameters.Add(_Database.CreateParameter("description", taskItem.Description));
1832 parameters.Add(_Database.CreateParameter("creationDate", taskItem.CreationDate));
1833 parameters.Add(_Database.CreateParameter("creatorID", taskItem.CreatorID));
1834 parameters.Add(_Database.CreateParameter("ownerID", taskItem.OwnerID));
1835 parameters.Add(_Database.CreateParameter("lastOwnerID", taskItem.LastOwnerID));
1836 parameters.Add(_Database.CreateParameter("groupID", taskItem.GroupID));
1837 parameters.Add(_Database.CreateParameter("nextPermissions", taskItem.NextPermissions));
1838 parameters.Add(_Database.CreateParameter("currentPermissions", taskItem.CurrentPermissions));
1839 parameters.Add(_Database.CreateParameter("basePermissions", taskItem.BasePermissions));
1840 parameters.Add(_Database.CreateParameter("everyonePermissions", taskItem.EveryonePermissions));
1841 parameters.Add(_Database.CreateParameter("groupPermissions", taskItem.GroupPermissions));
1842 parameters.Add(_Database.CreateParameter("flags", taskItem.Flags));
1843
1844 return parameters.ToArray();
1845 }
1846
1847 /// <summary>
1848 /// Creates the region setting parameters.
1849 /// </summary>
1850 /// <param name="settings">regionsettings.</param>
1851 /// <returns></returns>
1852 private NpgsqlParameter[] CreateRegionSettingParameters(RegionSettings settings)
1853 {
1854 List<NpgsqlParameter> parameters = new List<NpgsqlParameter>();
1855
1856 parameters.Add(_Database.CreateParameter("regionUUID", settings.RegionUUID));
1857 parameters.Add(_Database.CreateParameter("block_terraform", settings.BlockTerraform));
1858 parameters.Add(_Database.CreateParameter("block_fly", settings.BlockFly));
1859 parameters.Add(_Database.CreateParameter("allow_damage", settings.AllowDamage));
1860 parameters.Add(_Database.CreateParameter("restrict_pushing", settings.RestrictPushing));
1861 parameters.Add(_Database.CreateParameter("allow_land_resell", settings.AllowLandResell));
1862 parameters.Add(_Database.CreateParameter("allow_land_join_divide", settings.AllowLandJoinDivide));
1863 parameters.Add(_Database.CreateParameter("block_show_in_search", settings.BlockShowInSearch));
1864 parameters.Add(_Database.CreateParameter("agent_limit", settings.AgentLimit));
1865 parameters.Add(_Database.CreateParameter("object_bonus", settings.ObjectBonus));
1866 parameters.Add(_Database.CreateParameter("maturity", settings.Maturity));
1867 parameters.Add(_Database.CreateParameter("disable_scripts", settings.DisableScripts));
1868 parameters.Add(_Database.CreateParameter("disable_collisions", settings.DisableCollisions));
1869 parameters.Add(_Database.CreateParameter("disable_physics", settings.DisablePhysics));
1870 parameters.Add(_Database.CreateParameter("terrain_texture_1", settings.TerrainTexture1));
1871 parameters.Add(_Database.CreateParameter("terrain_texture_2", settings.TerrainTexture2));
1872 parameters.Add(_Database.CreateParameter("terrain_texture_3", settings.TerrainTexture3));
1873 parameters.Add(_Database.CreateParameter("terrain_texture_4", settings.TerrainTexture4));
1874 parameters.Add(_Database.CreateParameter("elevation_1_nw", settings.Elevation1NW));
1875 parameters.Add(_Database.CreateParameter("elevation_2_nw", settings.Elevation2NW));
1876 parameters.Add(_Database.CreateParameter("elevation_1_ne", settings.Elevation1NE));
1877 parameters.Add(_Database.CreateParameter("elevation_2_ne", settings.Elevation2NE));
1878 parameters.Add(_Database.CreateParameter("elevation_1_se", settings.Elevation1SE));
1879 parameters.Add(_Database.CreateParameter("elevation_2_se", settings.Elevation2SE));
1880 parameters.Add(_Database.CreateParameter("elevation_1_sw", settings.Elevation1SW));
1881 parameters.Add(_Database.CreateParameter("elevation_2_sw", settings.Elevation2SW));
1882 parameters.Add(_Database.CreateParameter("water_height", settings.WaterHeight));
1883 parameters.Add(_Database.CreateParameter("terrain_raise_limit", settings.TerrainRaiseLimit));
1884 parameters.Add(_Database.CreateParameter("terrain_lower_limit", settings.TerrainLowerLimit));
1885 parameters.Add(_Database.CreateParameter("use_estate_sun", settings.UseEstateSun));
1886 parameters.Add(_Database.CreateParameter("Sandbox", settings.Sandbox));
1887 parameters.Add(_Database.CreateParameter("fixed_sun", settings.FixedSun));
1888 parameters.Add(_Database.CreateParameter("sun_position", settings.SunPosition));
1889 parameters.Add(_Database.CreateParameter("sunvectorx", settings.SunVector.X));
1890 parameters.Add(_Database.CreateParameter("sunvectory", settings.SunVector.Y));
1891 parameters.Add(_Database.CreateParameter("sunvectorz", settings.SunVector.Z));
1892 parameters.Add(_Database.CreateParameter("covenant", settings.Covenant));
1893 parameters.Add(_Database.CreateParameter("covenant_datetime", settings.CovenantChangedDateTime));
1894 parameters.Add(_Database.CreateParameter("Loaded_Creation_DateTime", settings.LoadedCreationDateTime));
1895 parameters.Add(_Database.CreateParameter("Loaded_Creation_ID", settings.LoadedCreationID));
1896 parameters.Add(_Database.CreateParameter("TerrainImageID", settings.TerrainImageID));
1897 parameters.Add(_Database.CreateParameter("ParcelImageID", settings.ParcelImageID));
1898 parameters.Add(_Database.CreateParameter("TelehubObject", settings.TelehubObject));
1899
1900 return parameters.ToArray();
1901 }
1902
1903 /// <summary>
1904 /// Creates the land parameters.
1905 /// </summary>
1906 /// <param name="land">land parameters.</param>
1907 /// <param name="regionUUID">region UUID.</param>
1908 /// <returns></returns>
1909 private NpgsqlParameter[] CreateLandParameters(LandData land, UUID regionUUID)
1910 {
1911 List<NpgsqlParameter> parameters = new List<NpgsqlParameter>();
1912
1913 parameters.Add(_Database.CreateParameter("UUID", land.GlobalID));
1914 parameters.Add(_Database.CreateParameter("RegionUUID", regionUUID));
1915 parameters.Add(_Database.CreateParameter("LocalLandID", land.LocalID));
1916
1917 // Bitmap is a byte[512]
1918 parameters.Add(_Database.CreateParameter("Bitmap", land.Bitmap));
1919
1920 parameters.Add(_Database.CreateParameter("Name", land.Name));
1921 parameters.Add(_Database.CreateParameter("Description", land.Description));
1922 parameters.Add(_Database.CreateParameter("OwnerUUID", land.OwnerID));
1923 parameters.Add(_Database.CreateParameter("IsGroupOwned", land.IsGroupOwned));
1924 parameters.Add(_Database.CreateParameter("Area", land.Area));
1925 parameters.Add(_Database.CreateParameter("AuctionID", land.AuctionID)); //Unemplemented
1926 parameters.Add(_Database.CreateParameter("Category", (int)land.Category)); //Enum libsecondlife.Parcel.ParcelCategory
1927 parameters.Add(_Database.CreateParameter("ClaimDate", land.ClaimDate));
1928 parameters.Add(_Database.CreateParameter("ClaimPrice", land.ClaimPrice));
1929 parameters.Add(_Database.CreateParameter("GroupUUID", land.GroupID));
1930 parameters.Add(_Database.CreateParameter("SalePrice", land.SalePrice));
1931 parameters.Add(_Database.CreateParameter("LandStatus", (int)land.Status)); //Enum. libsecondlife.Parcel.ParcelStatus
1932 parameters.Add(_Database.CreateParameter("LandFlags", land.Flags));
1933 parameters.Add(_Database.CreateParameter("LandingType", Convert.ToInt32( land.LandingType) ));
1934 parameters.Add(_Database.CreateParameter("MediaAutoScale", Convert.ToInt32( land.MediaAutoScale )));
1935 parameters.Add(_Database.CreateParameter("MediaTextureUUID", land.MediaID));
1936 parameters.Add(_Database.CreateParameter("MediaURL", land.MediaURL));
1937 parameters.Add(_Database.CreateParameter("MusicURL", land.MusicURL));
1938 parameters.Add(_Database.CreateParameter("PassHours", land.PassHours));
1939 parameters.Add(_Database.CreateParameter("PassPrice", land.PassPrice));
1940 parameters.Add(_Database.CreateParameter("SnapshotUUID", land.SnapshotID));
1941 parameters.Add(_Database.CreateParameter("UserLocationX", land.UserLocation.X));
1942 parameters.Add(_Database.CreateParameter("UserLocationY", land.UserLocation.Y));
1943 parameters.Add(_Database.CreateParameter("UserLocationZ", land.UserLocation.Z));
1944 parameters.Add(_Database.CreateParameter("UserLookAtX", land.UserLookAt.X));
1945 parameters.Add(_Database.CreateParameter("UserLookAtY", land.UserLookAt.Y));
1946 parameters.Add(_Database.CreateParameter("UserLookAtZ", land.UserLookAt.Z));
1947 parameters.Add(_Database.CreateParameter("AuthBuyerID", land.AuthBuyerID));
1948 parameters.Add(_Database.CreateParameter("OtherCleanTime", land.OtherCleanTime));
1949
1950 return parameters.ToArray();
1951 }
1952
1953 /// <summary>
1954 /// Creates the land access parameters.
1955 /// </summary>
1956 /// <param name="parcelAccessEntry">parcel access entry.</param>
1957 /// <param name="parcelID">parcel ID.</param>
1958 /// <returns></returns>
1959 private NpgsqlParameter[] CreateLandAccessParameters(LandAccessEntry parcelAccessEntry, UUID parcelID)
1960 {
1961 List<NpgsqlParameter> parameters = new List<NpgsqlParameter>();
1962
1963 parameters.Add(_Database.CreateParameter("LandUUID", parcelID));
1964 parameters.Add(_Database.CreateParameter("AccessUUID", parcelAccessEntry.AgentID));
1965 parameters.Add(_Database.CreateParameter("Flags", parcelAccessEntry.Flags));
1966 parameters.Add(_Database.CreateParameter("Expires", parcelAccessEntry.Expires));
1967
1968 return parameters.ToArray();
1969 }
1970
1971 /// <summary>
1972 /// Creates the prim parameters for storing in DB.
1973 /// </summary>
1974 /// <param name="prim">Basic data of SceneObjectpart prim.</param>
1975 /// <param name="sceneGroupID">The scenegroup ID.</param>
1976 /// <param name="regionUUID">The region ID.</param>
1977 /// <returns></returns>
1978 private NpgsqlParameter[] CreatePrimParameters(SceneObjectPart prim, UUID sceneGroupID, UUID regionUUID)
1979 {
1980 List<NpgsqlParameter> parameters = new List<NpgsqlParameter>();
1981
1982 parameters.Add(_Database.CreateParameter("UUID", prim.UUID));
1983 parameters.Add(_Database.CreateParameter("RegionUUID", regionUUID));
1984 parameters.Add(_Database.CreateParameter("CreationDate", prim.CreationDate));
1985 parameters.Add(_Database.CreateParameter("Name", prim.Name));
1986 parameters.Add(_Database.CreateParameter("SceneGroupID", sceneGroupID));
1987 // the UUID of the root part for this SceneObjectGroup
1988 // various text fields
1989 parameters.Add(_Database.CreateParameter("Text", prim.Text));
1990 parameters.Add(_Database.CreateParameter("ColorR", prim.Color.R));
1991 parameters.Add(_Database.CreateParameter("ColorG", prim.Color.G));
1992 parameters.Add(_Database.CreateParameter("ColorB", prim.Color.B));
1993 parameters.Add(_Database.CreateParameter("ColorA", prim.Color.A));
1994 parameters.Add(_Database.CreateParameter("Description", prim.Description));
1995 parameters.Add(_Database.CreateParameter("SitName", prim.SitName));
1996 parameters.Add(_Database.CreateParameter("TouchName", prim.TouchName));
1997 // permissions
1998 parameters.Add(_Database.CreateParameter("ObjectFlags", (uint)prim.Flags));
1999 parameters.Add(_Database.CreateParameter("CreatorID", prim.CreatorID));
2000 parameters.Add(_Database.CreateParameter("OwnerID", prim.OwnerID));
2001 parameters.Add(_Database.CreateParameter("GroupID", prim.GroupID));
2002 parameters.Add(_Database.CreateParameter("LastOwnerID", prim.LastOwnerID));
2003 parameters.Add(_Database.CreateParameter("OwnerMask", prim.OwnerMask));
2004 parameters.Add(_Database.CreateParameter("NextOwnerMask", prim.NextOwnerMask));
2005 parameters.Add(_Database.CreateParameter("GroupMask", prim.GroupMask));
2006 parameters.Add(_Database.CreateParameter("EveryoneMask", prim.EveryoneMask));
2007 parameters.Add(_Database.CreateParameter("BaseMask", prim.BaseMask));
2008 // vectors
2009 parameters.Add(_Database.CreateParameter("PositionX", prim.OffsetPosition.X));
2010 parameters.Add(_Database.CreateParameter("PositionY", prim.OffsetPosition.Y));
2011 parameters.Add(_Database.CreateParameter("PositionZ", prim.OffsetPosition.Z));
2012 parameters.Add(_Database.CreateParameter("GroupPositionX", prim.GroupPosition.X));
2013 parameters.Add(_Database.CreateParameter("GroupPositionY", prim.GroupPosition.Y));
2014 parameters.Add(_Database.CreateParameter("GroupPositionZ", prim.GroupPosition.Z));
2015 parameters.Add(_Database.CreateParameter("VelocityX", prim.Velocity.X));
2016 parameters.Add(_Database.CreateParameter("VelocityY", prim.Velocity.Y));
2017 parameters.Add(_Database.CreateParameter("VelocityZ", prim.Velocity.Z));
2018 parameters.Add(_Database.CreateParameter("AngularVelocityX", prim.AngularVelocity.X));
2019 parameters.Add(_Database.CreateParameter("AngularVelocityY", prim.AngularVelocity.Y));
2020 parameters.Add(_Database.CreateParameter("AngularVelocityZ", prim.AngularVelocity.Z));
2021 parameters.Add(_Database.CreateParameter("AccelerationX", prim.Acceleration.X));
2022 parameters.Add(_Database.CreateParameter("AccelerationY", prim.Acceleration.Y));
2023 parameters.Add(_Database.CreateParameter("AccelerationZ", prim.Acceleration.Z));
2024 // quaternions
2025 parameters.Add(_Database.CreateParameter("RotationX", prim.RotationOffset.X));
2026 parameters.Add(_Database.CreateParameter("RotationY", prim.RotationOffset.Y));
2027 parameters.Add(_Database.CreateParameter("RotationZ", prim.RotationOffset.Z));
2028 parameters.Add(_Database.CreateParameter("RotationW", prim.RotationOffset.W));
2029
2030 // Sit target
2031 Vector3 sitTargetPos = prim.SitTargetPositionLL;
2032 parameters.Add(_Database.CreateParameter("SitTargetOffsetX", sitTargetPos.X));
2033 parameters.Add(_Database.CreateParameter("SitTargetOffsetY", sitTargetPos.Y));
2034 parameters.Add(_Database.CreateParameter("SitTargetOffsetZ", sitTargetPos.Z));
2035
2036 Quaternion sitTargetOrient = prim.SitTargetOrientationLL;
2037 parameters.Add(_Database.CreateParameter("SitTargetOrientW", sitTargetOrient.W));
2038 parameters.Add(_Database.CreateParameter("SitTargetOrientX", sitTargetOrient.X));
2039 parameters.Add(_Database.CreateParameter("SitTargetOrientY", sitTargetOrient.Y));
2040 parameters.Add(_Database.CreateParameter("SitTargetOrientZ", sitTargetOrient.Z));
2041
2042 parameters.Add(_Database.CreateParameter("PayPrice", prim.PayPrice[0]));
2043 parameters.Add(_Database.CreateParameter("PayButton1", prim.PayPrice[1]));
2044 parameters.Add(_Database.CreateParameter("PayButton2", prim.PayPrice[2]));
2045 parameters.Add(_Database.CreateParameter("PayButton3", prim.PayPrice[3]));
2046 parameters.Add(_Database.CreateParameter("PayButton4", prim.PayPrice[4]));
2047
2048 if ((prim.SoundFlags & 1) != 0) // Looped
2049 {
2050 parameters.Add(_Database.CreateParameter("LoopedSound", prim.Sound));
2051 parameters.Add(_Database.CreateParameter("LoopedSoundGain", prim.SoundGain));
2052 }
2053 else
2054 {
2055 parameters.Add(_Database.CreateParameter("LoopedSound", UUID.Zero));
2056 parameters.Add(_Database.CreateParameter("LoopedSoundGain", 0.0f));
2057 }
2058
2059 parameters.Add(_Database.CreateParameter("TextureAnimation", prim.TextureAnimation));
2060 parameters.Add(_Database.CreateParameter("ParticleSystem", prim.ParticleSystem));
2061
2062 parameters.Add(_Database.CreateParameter("OmegaX", prim.AngularVelocity.X));
2063 parameters.Add(_Database.CreateParameter("OmegaY", prim.AngularVelocity.Y));
2064 parameters.Add(_Database.CreateParameter("OmegaZ", prim.AngularVelocity.Z));
2065
2066 parameters.Add(_Database.CreateParameter("CameraEyeOffsetX", prim.GetCameraEyeOffset().X));
2067 parameters.Add(_Database.CreateParameter("CameraEyeOffsetY", prim.GetCameraEyeOffset().Y));
2068 parameters.Add(_Database.CreateParameter("CameraEyeOffsetZ", prim.GetCameraEyeOffset().Z));
2069
2070 parameters.Add(_Database.CreateParameter("CameraAtOffsetX", prim.GetCameraAtOffset().X));
2071 parameters.Add(_Database.CreateParameter("CameraAtOffsetY", prim.GetCameraAtOffset().Y));
2072 parameters.Add(_Database.CreateParameter("CameraAtOffsetZ", prim.GetCameraAtOffset().Z));
2073
2074 if (prim.GetForceMouselook())
2075 parameters.Add(_Database.CreateParameter("ForceMouselook", 1));
2076 else
2077 parameters.Add(_Database.CreateParameter("ForceMouselook", 0));
2078
2079 parameters.Add(_Database.CreateParameter("ScriptAccessPin", prim.ScriptAccessPin));
2080
2081 if (prim.AllowedDrop)
2082 parameters.Add(_Database.CreateParameter("AllowedDrop", 1));
2083 else
2084 parameters.Add(_Database.CreateParameter("AllowedDrop", 0));
2085
2086 if (prim.DIE_AT_EDGE)
2087 parameters.Add(_Database.CreateParameter("DieAtEdge", 1));
2088 else
2089 parameters.Add(_Database.CreateParameter("DieAtEdge", 0));
2090
2091 parameters.Add(_Database.CreateParameter("SalePrice", prim.SalePrice));
2092 parameters.Add(_Database.CreateParameter("SaleType", prim.ObjectSaleType));
2093
2094 byte clickAction = prim.ClickAction;
2095 parameters.Add(_Database.CreateParameter("ClickAction", clickAction));
2096
2097 parameters.Add(_Database.CreateParameter("Material", prim.Material));
2098
2099 parameters.Add(_Database.CreateParameter("CollisionSound", prim.CollisionSound));
2100 parameters.Add(_Database.CreateParameter("CollisionSoundVolume", prim.CollisionSoundVolume));
2101
2102 parameters.Add(_Database.CreateParameter("PassTouches", prim.PassTouches));
2103
2104 parameters.Add(_Database.CreateParameter("LinkNumber", prim.LinkNum));
2105 parameters.Add(_Database.CreateParameter("MediaURL", prim.MediaUrl));
2106
2107 if (prim.DynAttrs.CountNamespaces > 0)
2108 parameters.Add(_Database.CreateParameter("DynAttrs", prim.DynAttrs.ToXml()));
2109 else
2110 parameters.Add(_Database.CreateParameter("DynAttrs", null));
2111
2112 parameters.Add(_Database.CreateParameter("PhysicsShapeType", prim.PhysicsShapeType));
2113 parameters.Add(_Database.CreateParameter("Density", (double)prim.Density));
2114 parameters.Add(_Database.CreateParameter("GravityModifier", (double)prim.GravityModifier));
2115 parameters.Add(_Database.CreateParameter("Friction", (double)prim.Friction));
2116 parameters.Add(_Database.CreateParameter("Restitution", (double)prim.Restitution));
2117
2118 return parameters.ToArray();
2119 }
2120
2121 /// <summary>
2122 /// Creates the primshape parameters for stroing in DB.
2123 /// </summary>
2124 /// <param name="prim">Basic data of SceneObjectpart prim.</param>
2125 /// <param name="sceneGroupID">The scene group ID.</param>
2126 /// <param name="regionUUID">The region UUID.</param>
2127 /// <returns></returns>
2128 private NpgsqlParameter[] CreatePrimShapeParameters(SceneObjectPart prim, UUID sceneGroupID, UUID regionUUID)
2129 {
2130 List<NpgsqlParameter> parameters = new List<NpgsqlParameter>();
2131
2132 PrimitiveBaseShape s = prim.Shape;
2133 parameters.Add(_Database.CreateParameter("UUID", prim.UUID));
2134 // shape is an enum
2135 parameters.Add(_Database.CreateParameter("Shape", 0));
2136 // vectors
2137 parameters.Add(_Database.CreateParameter("ScaleX", s.Scale.X));
2138 parameters.Add(_Database.CreateParameter("ScaleY", s.Scale.Y));
2139 parameters.Add(_Database.CreateParameter("ScaleZ", s.Scale.Z));
2140 // paths
2141 parameters.Add(_Database.CreateParameter("PCode", s.PCode));
2142 parameters.Add(_Database.CreateParameter("PathBegin", s.PathBegin));
2143 parameters.Add(_Database.CreateParameter("PathEnd", s.PathEnd));
2144 parameters.Add(_Database.CreateParameter("PathScaleX", s.PathScaleX));
2145 parameters.Add(_Database.CreateParameter("PathScaleY", s.PathScaleY));
2146 parameters.Add(_Database.CreateParameter("PathShearX", s.PathShearX));
2147 parameters.Add(_Database.CreateParameter("PathShearY", s.PathShearY));
2148 parameters.Add(_Database.CreateParameter("PathSkew", s.PathSkew));
2149 parameters.Add(_Database.CreateParameter("PathCurve", s.PathCurve));
2150 parameters.Add(_Database.CreateParameter("PathRadiusOffset", s.PathRadiusOffset));
2151 parameters.Add(_Database.CreateParameter("PathRevolutions", s.PathRevolutions));
2152 parameters.Add(_Database.CreateParameter("PathTaperX", s.PathTaperX));
2153 parameters.Add(_Database.CreateParameter("PathTaperY", s.PathTaperY));
2154 parameters.Add(_Database.CreateParameter("PathTwist", s.PathTwist));
2155 parameters.Add(_Database.CreateParameter("PathTwistBegin", s.PathTwistBegin));
2156 // profile
2157 parameters.Add(_Database.CreateParameter("ProfileBegin", s.ProfileBegin));
2158 parameters.Add(_Database.CreateParameter("ProfileEnd", s.ProfileEnd));
2159 parameters.Add(_Database.CreateParameter("ProfileCurve", s.ProfileCurve));
2160 parameters.Add(_Database.CreateParameter("ProfileHollow", s.ProfileHollow));
2161 parameters.Add(_Database.CreateParameter("Texture", s.TextureEntry));
2162 parameters.Add(_Database.CreateParameter("ExtraParams", s.ExtraParams));
2163 parameters.Add(_Database.CreateParameter("State", s.State));
2164
2165 if (null == s.Media)
2166 {
2167 parameters.Add(_Database.CreateParameter("Media", DBNull.Value));
2168 }
2169 else
2170 {
2171 parameters.Add(_Database.CreateParameter("Media", s.Media.ToXml()));
2172 }
2173
2174 return parameters.ToArray();
2175 }
2176
2177 #endregion
2178
2179 #endregion
2180
2181 private void LoadSpawnPoints(RegionSettings rs)
2182 {
2183 rs.ClearSpawnPoints();
2184
2185 string sql = @"SELECT ""Yaw"", ""Pitch"", ""Distance"" FROM spawn_points WHERE ""RegionUUID"" = :RegionUUID";
2186
2187 using (NpgsqlConnection conn = new NpgsqlConnection(m_connectionString))
2188 using (NpgsqlCommand cmd = new NpgsqlCommand(sql, conn))
2189 {
2190 cmd.Parameters.Add(_Database.CreateParameter("RegionUUID", rs.RegionUUID));
2191 conn.Open();
2192 using (NpgsqlDataReader reader = cmd.ExecuteReader())
2193 {
2194 if (reader.Read())
2195 {
2196 SpawnPoint sp = new SpawnPoint();
2197
2198 sp.Yaw = (float)reader["Yaw"];
2199 sp.Pitch = (float)reader["Pitch"];
2200 sp.Distance = (float)reader["Distance"];
2201
2202 rs.AddSpawnPoint(sp);
2203 }
2204 }
2205 }
2206 }
2207
2208 private void SaveSpawnPoints(RegionSettings rs)
2209 {
2210 string sql = @"DELETE FROM spawn_points WHERE ""RegionUUID"" = :RegionUUID";
2211 using (NpgsqlConnection conn = new NpgsqlConnection(m_connectionString))
2212 using (NpgsqlCommand cmd = new NpgsqlCommand(sql, conn))
2213 {
2214 cmd.Parameters.Add(_Database.CreateParameter("RegionUUID", rs.RegionUUID));
2215 conn.Open();
2216 cmd.ExecuteNonQuery();
2217 }
2218 foreach (SpawnPoint p in rs.SpawnPoints())
2219 {
2220 sql = @"INSERT INTO spawn_points (""RegionUUID"", ""Yaw"", ""Pitch"", ""Distance"") VALUES (:RegionUUID, :Yaw, :Pitch, :Distance)";
2221 using (NpgsqlConnection conn = new NpgsqlConnection(m_connectionString))
2222 using (NpgsqlCommand cmd = new NpgsqlCommand(sql, conn))
2223 {
2224 cmd.Parameters.Add(_Database.CreateParameter("RegionUUID", rs.RegionUUID));
2225 cmd.Parameters.Add(_Database.CreateParameter("Yaw", p.Yaw));
2226 cmd.Parameters.Add(_Database.CreateParameter("Pitch", p.Pitch));
2227 cmd.Parameters.Add(_Database.CreateParameter("Distance", p.Distance));
2228 conn.Open();
2229 cmd.ExecuteNonQuery();
2230 }
2231 }
2232 }
2233
2234 public void SaveExtra(UUID regionID, string name, string value)
2235 {
2236 }
2237
2238 public void RemoveExtra(UUID regionID, string name)
2239 {
2240 }
2241
2242 public Dictionary<string, string> GetExtra(UUID regionID)
2243 {
2244 return null;
2245 }
2246 }
2247}