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