diff options
Diffstat (limited to 'OpenSim/Data/SQLiteLegacy/SQLiteSimulationData.cs')
-rw-r--r-- | OpenSim/Data/SQLiteLegacy/SQLiteSimulationData.cs | 2268 |
1 files changed, 2268 insertions, 0 deletions
diff --git a/OpenSim/Data/SQLiteLegacy/SQLiteSimulationData.cs b/OpenSim/Data/SQLiteLegacy/SQLiteSimulationData.cs new file mode 100644 index 0000000..2dde926 --- /dev/null +++ b/OpenSim/Data/SQLiteLegacy/SQLiteSimulationData.cs | |||
@@ -0,0 +1,2268 @@ | |||
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 log4net; | ||
35 | using Mono.Data.SqliteClient; | ||
36 | using OpenMetaverse; | ||
37 | using OpenSim.Framework; | ||
38 | using OpenSim.Region.Framework.Interfaces; | ||
39 | using OpenSim.Region.Framework.Scenes; | ||
40 | |||
41 | namespace OpenSim.Data.SQLiteLegacy | ||
42 | { | ||
43 | /// <summary> | ||
44 | /// A RegionData Interface to the SQLite database | ||
45 | /// </summary> | ||
46 | public class SQLiteSimulationData : ISimulationDataStore | ||
47 | { | ||
48 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
49 | |||
50 | private const string primSelect = "select * from prims"; | ||
51 | private const string shapeSelect = "select * from primshapes"; | ||
52 | private const string itemsSelect = "select * from primitems"; | ||
53 | private const string terrainSelect = "select * from terrain limit 1"; | ||
54 | private const string landSelect = "select * from land"; | ||
55 | private const string landAccessListSelect = "select distinct * from landaccesslist"; | ||
56 | private const string regionbanListSelect = "select * from regionban"; | ||
57 | private const string regionSettingsSelect = "select * from regionsettings"; | ||
58 | |||
59 | private DataSet ds; | ||
60 | private SqliteDataAdapter primDa; | ||
61 | private SqliteDataAdapter shapeDa; | ||
62 | private SqliteDataAdapter itemsDa; | ||
63 | private SqliteDataAdapter terrainDa; | ||
64 | private SqliteDataAdapter landDa; | ||
65 | private SqliteDataAdapter landAccessListDa; | ||
66 | private SqliteDataAdapter regionSettingsDa; | ||
67 | |||
68 | private SqliteConnection m_conn; | ||
69 | |||
70 | private String m_connectionString; | ||
71 | |||
72 | public SQLiteSimulationData() | ||
73 | { | ||
74 | } | ||
75 | |||
76 | public SQLiteSimulationData(string connectionString) | ||
77 | { | ||
78 | Initialise(connectionString); | ||
79 | } | ||
80 | |||
81 | // Temporary attribute while this is experimental | ||
82 | |||
83 | /*********************************************************************** | ||
84 | * | ||
85 | * Public Interface Functions | ||
86 | * | ||
87 | **********************************************************************/ | ||
88 | |||
89 | /// <summary> | ||
90 | /// <list type="bullet"> | ||
91 | /// <item>Initialises RegionData Interface</item> | ||
92 | /// <item>Loads and initialises a new SQLite connection and maintains it.</item> | ||
93 | /// </list> | ||
94 | /// </summary> | ||
95 | /// <param name="connectionString">the connection string</param> | ||
96 | public void Initialise(string connectionString) | ||
97 | { | ||
98 | m_connectionString = connectionString; | ||
99 | |||
100 | ds = new DataSet(); | ||
101 | |||
102 | m_log.Info("[REGION DB]: Sqlite - connecting: " + connectionString); | ||
103 | m_conn = new SqliteConnection(m_connectionString); | ||
104 | m_conn.Open(); | ||
105 | |||
106 | |||
107 | |||
108 | SqliteCommand primSelectCmd = new SqliteCommand(primSelect, m_conn); | ||
109 | primDa = new SqliteDataAdapter(primSelectCmd); | ||
110 | // SqliteCommandBuilder primCb = new SqliteCommandBuilder(primDa); | ||
111 | |||
112 | SqliteCommand shapeSelectCmd = new SqliteCommand(shapeSelect, m_conn); | ||
113 | shapeDa = new SqliteDataAdapter(shapeSelectCmd); | ||
114 | // SqliteCommandBuilder shapeCb = new SqliteCommandBuilder(shapeDa); | ||
115 | |||
116 | SqliteCommand itemsSelectCmd = new SqliteCommand(itemsSelect, m_conn); | ||
117 | itemsDa = new SqliteDataAdapter(itemsSelectCmd); | ||
118 | |||
119 | SqliteCommand terrainSelectCmd = new SqliteCommand(terrainSelect, m_conn); | ||
120 | terrainDa = new SqliteDataAdapter(terrainSelectCmd); | ||
121 | |||
122 | SqliteCommand landSelectCmd = new SqliteCommand(landSelect, m_conn); | ||
123 | landDa = new SqliteDataAdapter(landSelectCmd); | ||
124 | |||
125 | SqliteCommand landAccessListSelectCmd = new SqliteCommand(landAccessListSelect, m_conn); | ||
126 | landAccessListDa = new SqliteDataAdapter(landAccessListSelectCmd); | ||
127 | |||
128 | SqliteCommand regionSettingsSelectCmd = new SqliteCommand(regionSettingsSelect, m_conn); | ||
129 | regionSettingsDa = new SqliteDataAdapter(regionSettingsSelectCmd); | ||
130 | // This actually does the roll forward assembly stuff | ||
131 | Assembly assem = GetType().Assembly; | ||
132 | Migration m = new Migration(m_conn, assem, "RegionStore"); | ||
133 | m.Update(); | ||
134 | |||
135 | lock (ds) | ||
136 | { | ||
137 | ds.Tables.Add(createPrimTable()); | ||
138 | setupPrimCommands(primDa, m_conn); | ||
139 | primDa.Fill(ds.Tables["prims"]); | ||
140 | |||
141 | ds.Tables.Add(createShapeTable()); | ||
142 | setupShapeCommands(shapeDa, m_conn); | ||
143 | |||
144 | ds.Tables.Add(createItemsTable()); | ||
145 | setupItemsCommands(itemsDa, m_conn); | ||
146 | itemsDa.Fill(ds.Tables["primitems"]); | ||
147 | |||
148 | ds.Tables.Add(createTerrainTable()); | ||
149 | setupTerrainCommands(terrainDa, m_conn); | ||
150 | |||
151 | ds.Tables.Add(createLandTable()); | ||
152 | setupLandCommands(landDa, m_conn); | ||
153 | |||
154 | ds.Tables.Add(createLandAccessListTable()); | ||
155 | setupLandAccessCommands(landAccessListDa, m_conn); | ||
156 | |||
157 | ds.Tables.Add(createRegionSettingsTable()); | ||
158 | |||
159 | setupRegionSettingsCommands(regionSettingsDa, m_conn); | ||
160 | |||
161 | // WORKAROUND: This is a work around for sqlite on | ||
162 | // windows, which gets really unhappy with blob columns | ||
163 | // that have no sample data in them. At some point we | ||
164 | // need to actually find a proper way to handle this. | ||
165 | try | ||
166 | { | ||
167 | shapeDa.Fill(ds.Tables["primshapes"]); | ||
168 | } | ||
169 | catch (Exception) | ||
170 | { | ||
171 | m_log.Info("[REGION DB]: Caught fill error on primshapes table"); | ||
172 | } | ||
173 | |||
174 | try | ||
175 | { | ||
176 | terrainDa.Fill(ds.Tables["terrain"]); | ||
177 | } | ||
178 | catch (Exception) | ||
179 | { | ||
180 | m_log.Info("[REGION DB]: Caught fill error on terrain table"); | ||
181 | } | ||
182 | |||
183 | try | ||
184 | { | ||
185 | landDa.Fill(ds.Tables["land"]); | ||
186 | } | ||
187 | catch (Exception) | ||
188 | { | ||
189 | m_log.Info("[REGION DB]: Caught fill error on land table"); | ||
190 | } | ||
191 | |||
192 | try | ||
193 | { | ||
194 | landAccessListDa.Fill(ds.Tables["landaccesslist"]); | ||
195 | } | ||
196 | catch (Exception) | ||
197 | { | ||
198 | m_log.Info("[REGION DB]: Caught fill error on landaccesslist table"); | ||
199 | } | ||
200 | |||
201 | try | ||
202 | { | ||
203 | regionSettingsDa.Fill(ds.Tables["regionsettings"]); | ||
204 | } | ||
205 | catch (Exception) | ||
206 | { | ||
207 | m_log.Info("[REGION DB]: Caught fill error on regionsettings table"); | ||
208 | } | ||
209 | return; | ||
210 | } | ||
211 | } | ||
212 | |||
213 | public void Dispose() | ||
214 | { | ||
215 | if (m_conn != null) | ||
216 | { | ||
217 | m_conn.Close(); | ||
218 | m_conn = null; | ||
219 | } | ||
220 | if (ds != null) | ||
221 | { | ||
222 | ds.Dispose(); | ||
223 | ds = null; | ||
224 | } | ||
225 | if (primDa != null) | ||
226 | { | ||
227 | primDa.Dispose(); | ||
228 | primDa = null; | ||
229 | } | ||
230 | if (shapeDa != null) | ||
231 | { | ||
232 | shapeDa.Dispose(); | ||
233 | shapeDa = null; | ||
234 | } | ||
235 | if (itemsDa != null) | ||
236 | { | ||
237 | itemsDa.Dispose(); | ||
238 | itemsDa = null; | ||
239 | } | ||
240 | if (terrainDa != null) | ||
241 | { | ||
242 | terrainDa.Dispose(); | ||
243 | terrainDa = null; | ||
244 | } | ||
245 | if (landDa != null) | ||
246 | { | ||
247 | landDa.Dispose(); | ||
248 | landDa = null; | ||
249 | } | ||
250 | if (landAccessListDa != null) | ||
251 | { | ||
252 | landAccessListDa.Dispose(); | ||
253 | landAccessListDa = null; | ||
254 | } | ||
255 | if (regionSettingsDa != null) | ||
256 | { | ||
257 | regionSettingsDa.Dispose(); | ||
258 | regionSettingsDa = null; | ||
259 | } | ||
260 | } | ||
261 | |||
262 | public void StoreRegionSettings(RegionSettings rs) | ||
263 | { | ||
264 | lock (ds) | ||
265 | { | ||
266 | DataTable regionsettings = ds.Tables["regionsettings"]; | ||
267 | |||
268 | DataRow settingsRow = regionsettings.Rows.Find(rs.RegionUUID.ToString()); | ||
269 | if (settingsRow == null) | ||
270 | { | ||
271 | settingsRow = regionsettings.NewRow(); | ||
272 | fillRegionSettingsRow(settingsRow, rs); | ||
273 | regionsettings.Rows.Add(settingsRow); | ||
274 | } | ||
275 | else | ||
276 | { | ||
277 | fillRegionSettingsRow(settingsRow, rs); | ||
278 | } | ||
279 | |||
280 | Commit(); | ||
281 | } | ||
282 | } | ||
283 | public RegionLightShareData LoadRegionWindlightSettings(UUID regionUUID) | ||
284 | { | ||
285 | //This connector doesn't support the windlight module yet | ||
286 | //Return default LL windlight settings | ||
287 | return new RegionLightShareData(); | ||
288 | } | ||
289 | public void StoreRegionWindlightSettings(RegionLightShareData wl) | ||
290 | { | ||
291 | //This connector doesn't support the windlight module yet | ||
292 | } | ||
293 | public RegionSettings LoadRegionSettings(UUID regionUUID) | ||
294 | { | ||
295 | lock (ds) | ||
296 | { | ||
297 | DataTable regionsettings = ds.Tables["regionsettings"]; | ||
298 | |||
299 | string searchExp = "regionUUID = '" + regionUUID.ToString() + "'"; | ||
300 | DataRow[] rawsettings = regionsettings.Select(searchExp); | ||
301 | if (rawsettings.Length == 0) | ||
302 | { | ||
303 | RegionSettings rs = new RegionSettings(); | ||
304 | rs.RegionUUID = regionUUID; | ||
305 | rs.OnSave += StoreRegionSettings; | ||
306 | |||
307 | StoreRegionSettings(rs); | ||
308 | |||
309 | return rs; | ||
310 | } | ||
311 | DataRow row = rawsettings[0]; | ||
312 | |||
313 | RegionSettings newSettings = buildRegionSettings(row); | ||
314 | newSettings.OnSave += StoreRegionSettings; | ||
315 | |||
316 | return newSettings; | ||
317 | } | ||
318 | } | ||
319 | |||
320 | /// <summary> | ||
321 | /// Adds an object into region storage | ||
322 | /// </summary> | ||
323 | /// <param name="obj">the object</param> | ||
324 | /// <param name="regionUUID">the region UUID</param> | ||
325 | public void StoreObject(SceneObjectGroup obj, UUID regionUUID) | ||
326 | { | ||
327 | uint flags = obj.RootPart.GetEffectiveObjectFlags(); | ||
328 | |||
329 | // Eligibility check | ||
330 | // | ||
331 | if ((flags & (uint)PrimFlags.Temporary) != 0) | ||
332 | return; | ||
333 | if ((flags & (uint)PrimFlags.TemporaryOnRez) != 0) | ||
334 | return; | ||
335 | |||
336 | lock (ds) | ||
337 | { | ||
338 | foreach (SceneObjectPart prim in obj.Children.Values) | ||
339 | { | ||
340 | // m_log.Info("[REGION DB]: Adding obj: " + obj.UUID + " to region: " + regionUUID); | ||
341 | addPrim(prim, obj.UUID, regionUUID); | ||
342 | } | ||
343 | } | ||
344 | |||
345 | Commit(); | ||
346 | // m_log.Info("[Dump of prims]: " + ds.GetXml()); | ||
347 | } | ||
348 | |||
349 | /// <summary> | ||
350 | /// Removes an object from region storage | ||
351 | /// </summary> | ||
352 | /// <param name="obj">the object</param> | ||
353 | /// <param name="regionUUID">the region UUID</param> | ||
354 | public void RemoveObject(UUID obj, UUID regionUUID) | ||
355 | { | ||
356 | // m_log.InfoFormat("[REGION DB]: Removing obj: {0} from region: {1}", obj.Guid, regionUUID); | ||
357 | |||
358 | DataTable prims = ds.Tables["prims"]; | ||
359 | DataTable shapes = ds.Tables["primshapes"]; | ||
360 | |||
361 | string selectExp = "SceneGroupID = '" + obj + "' and RegionUUID = '" + regionUUID + "'"; | ||
362 | lock (ds) | ||
363 | { | ||
364 | DataRow[] primRows = prims.Select(selectExp); | ||
365 | foreach (DataRow row in primRows) | ||
366 | { | ||
367 | // Remove shape rows | ||
368 | UUID uuid = new UUID((string) row["UUID"]); | ||
369 | DataRow shapeRow = shapes.Rows.Find(uuid.ToString()); | ||
370 | if (shapeRow != null) | ||
371 | { | ||
372 | shapeRow.Delete(); | ||
373 | } | ||
374 | |||
375 | RemoveItems(uuid); | ||
376 | |||
377 | // Remove prim row | ||
378 | row.Delete(); | ||
379 | } | ||
380 | } | ||
381 | |||
382 | Commit(); | ||
383 | } | ||
384 | |||
385 | /// <summary> | ||
386 | /// Remove all persisted items of the given prim. | ||
387 | /// The caller must acquire the necessrary synchronization locks and commit or rollback changes. | ||
388 | /// </summary> | ||
389 | /// <param name="uuid">The item UUID</param> | ||
390 | private void RemoveItems(UUID uuid) | ||
391 | { | ||
392 | DataTable items = ds.Tables["primitems"]; | ||
393 | |||
394 | String sql = String.Format("primID = '{0}'", uuid); | ||
395 | DataRow[] itemRows = items.Select(sql); | ||
396 | |||
397 | foreach (DataRow itemRow in itemRows) | ||
398 | { | ||
399 | itemRow.Delete(); | ||
400 | } | ||
401 | } | ||
402 | |||
403 | /// <summary> | ||
404 | /// Load persisted objects from region storage. | ||
405 | /// </summary> | ||
406 | /// <param name="regionUUID">The region UUID</param> | ||
407 | /// <returns>List of loaded groups</returns> | ||
408 | public List<SceneObjectGroup> LoadObjects(UUID regionUUID) | ||
409 | { | ||
410 | Dictionary<UUID, SceneObjectGroup> createdObjects = new Dictionary<UUID, SceneObjectGroup>(); | ||
411 | |||
412 | List<SceneObjectGroup> retvals = new List<SceneObjectGroup>(); | ||
413 | |||
414 | DataTable prims = ds.Tables["prims"]; | ||
415 | DataTable shapes = ds.Tables["primshapes"]; | ||
416 | |||
417 | string byRegion = "RegionUUID = '" + regionUUID + "'"; | ||
418 | |||
419 | lock (ds) | ||
420 | { | ||
421 | DataRow[] primsForRegion = prims.Select(byRegion); | ||
422 | m_log.Info("[REGION DB]: Loaded " + primsForRegion.Length + " prims for region: " + regionUUID); | ||
423 | |||
424 | // First, create all groups | ||
425 | foreach (DataRow primRow in primsForRegion) | ||
426 | { | ||
427 | try | ||
428 | { | ||
429 | SceneObjectPart prim = null; | ||
430 | |||
431 | string uuid = (string) primRow["UUID"]; | ||
432 | string objID = (string) primRow["SceneGroupID"]; | ||
433 | |||
434 | if (uuid == objID) //is new SceneObjectGroup ? | ||
435 | { | ||
436 | prim = buildPrim(primRow); | ||
437 | DataRow shapeRow = shapes.Rows.Find(prim.UUID.ToString()); | ||
438 | if (shapeRow != null) | ||
439 | { | ||
440 | prim.Shape = buildShape(shapeRow); | ||
441 | } | ||
442 | else | ||
443 | { | ||
444 | m_log.Info( | ||
445 | "[REGION DB]: No shape found for prim in storage, so setting default box shape"); | ||
446 | prim.Shape = PrimitiveBaseShape.Default; | ||
447 | } | ||
448 | |||
449 | SceneObjectGroup group = new SceneObjectGroup(prim); | ||
450 | createdObjects.Add(group.UUID, group); | ||
451 | retvals.Add(group); | ||
452 | LoadItems(prim); | ||
453 | } | ||
454 | } | ||
455 | catch (Exception e) | ||
456 | { | ||
457 | m_log.Error("[REGION DB]: Failed create prim object in new group, exception and data follows"); | ||
458 | m_log.Info("[REGION DB]: " + e.ToString()); | ||
459 | foreach (DataColumn col in prims.Columns) | ||
460 | { | ||
461 | m_log.Info("[REGION DB]: Col: " + col.ColumnName + " => " + primRow[col]); | ||
462 | } | ||
463 | } | ||
464 | } | ||
465 | |||
466 | // Now fill the groups with part data | ||
467 | foreach (DataRow primRow in primsForRegion) | ||
468 | { | ||
469 | try | ||
470 | { | ||
471 | SceneObjectPart prim = null; | ||
472 | |||
473 | string uuid = (string) primRow["UUID"]; | ||
474 | string objID = (string) primRow["SceneGroupID"]; | ||
475 | if (uuid != objID) //is new SceneObjectGroup ? | ||
476 | { | ||
477 | prim = buildPrim(primRow); | ||
478 | DataRow shapeRow = shapes.Rows.Find(prim.UUID.ToString()); | ||
479 | if (shapeRow != null) | ||
480 | { | ||
481 | prim.Shape = buildShape(shapeRow); | ||
482 | } | ||
483 | else | ||
484 | { | ||
485 | m_log.Warn( | ||
486 | "[REGION DB]: No shape found for prim in storage, so setting default box shape"); | ||
487 | prim.Shape = PrimitiveBaseShape.Default; | ||
488 | } | ||
489 | |||
490 | createdObjects[new UUID(objID)].AddPart(prim); | ||
491 | LoadItems(prim); | ||
492 | } | ||
493 | } | ||
494 | catch (Exception e) | ||
495 | { | ||
496 | m_log.Error("[REGION DB]: Failed create prim object in group, exception and data follows"); | ||
497 | m_log.Info("[REGION DB]: " + e.ToString()); | ||
498 | foreach (DataColumn col in prims.Columns) | ||
499 | { | ||
500 | m_log.Info("[REGION DB]: Col: " + col.ColumnName + " => " + primRow[col]); | ||
501 | } | ||
502 | } | ||
503 | } | ||
504 | } | ||
505 | return retvals; | ||
506 | } | ||
507 | |||
508 | /// <summary> | ||
509 | /// Load in a prim's persisted inventory. | ||
510 | /// </summary> | ||
511 | /// <param name="prim">the prim</param> | ||
512 | private void LoadItems(SceneObjectPart prim) | ||
513 | { | ||
514 | //m_log.DebugFormat("[DATASTORE]: Loading inventory for {0}, {1}", prim.Name, prim.UUID); | ||
515 | |||
516 | DataTable dbItems = ds.Tables["primitems"]; | ||
517 | String sql = String.Format("primID = '{0}'", prim.UUID.ToString()); | ||
518 | DataRow[] dbItemRows = dbItems.Select(sql); | ||
519 | IList<TaskInventoryItem> inventory = new List<TaskInventoryItem>(); | ||
520 | |||
521 | foreach (DataRow row in dbItemRows) | ||
522 | { | ||
523 | TaskInventoryItem item = buildItem(row); | ||
524 | inventory.Add(item); | ||
525 | |||
526 | //m_log.DebugFormat("[DATASTORE]: Restored item {0}, {1}", item.Name, item.ItemID); | ||
527 | } | ||
528 | |||
529 | prim.Inventory.RestoreInventoryItems(inventory); | ||
530 | } | ||
531 | |||
532 | /// <summary> | ||
533 | /// Store a terrain revision in region storage | ||
534 | /// </summary> | ||
535 | /// <param name="ter">terrain heightfield</param> | ||
536 | /// <param name="regionID">region UUID</param> | ||
537 | public void StoreTerrain(double[,] ter, UUID regionID) | ||
538 | { | ||
539 | lock (ds) | ||
540 | { | ||
541 | int revision = Util.UnixTimeSinceEpoch(); | ||
542 | |||
543 | // This is added to get rid of the infinitely growing | ||
544 | // terrain databases which negatively impact on SQLite | ||
545 | // over time. Before reenabling this feature there | ||
546 | // needs to be a limitter put on the number of | ||
547 | // revisions in the database, as this old | ||
548 | // implementation is a DOS attack waiting to happen. | ||
549 | |||
550 | using ( | ||
551 | SqliteCommand cmd = | ||
552 | new SqliteCommand("delete from terrain where RegionUUID=:RegionUUID and Revision <= :Revision", | ||
553 | m_conn)) | ||
554 | { | ||
555 | cmd.Parameters.Add(new SqliteParameter(":RegionUUID", regionID.ToString())); | ||
556 | cmd.Parameters.Add(new SqliteParameter(":Revision", revision)); | ||
557 | cmd.ExecuteNonQuery(); | ||
558 | } | ||
559 | |||
560 | // the following is an work around for .NET. The perf | ||
561 | // issues associated with it aren't as bad as you think. | ||
562 | m_log.Info("[REGION DB]: Storing terrain revision r" + revision.ToString()); | ||
563 | String sql = "insert into terrain(RegionUUID, Revision, Heightfield)" + | ||
564 | " values(:RegionUUID, :Revision, :Heightfield)"; | ||
565 | |||
566 | using (SqliteCommand cmd = new SqliteCommand(sql, m_conn)) | ||
567 | { | ||
568 | cmd.Parameters.Add(new SqliteParameter(":RegionUUID", regionID.ToString())); | ||
569 | cmd.Parameters.Add(new SqliteParameter(":Revision", revision)); | ||
570 | cmd.Parameters.Add(new SqliteParameter(":Heightfield", serializeTerrain(ter))); | ||
571 | cmd.ExecuteNonQuery(); | ||
572 | } | ||
573 | } | ||
574 | } | ||
575 | |||
576 | /// <summary> | ||
577 | /// Load the latest terrain revision from region storage | ||
578 | /// </summary> | ||
579 | /// <param name="regionID">the region UUID</param> | ||
580 | /// <returns>Heightfield data</returns> | ||
581 | public double[,] LoadTerrain(UUID regionID) | ||
582 | { | ||
583 | lock (ds) | ||
584 | { | ||
585 | double[,] terret = new double[(int)Constants.RegionSize, (int)Constants.RegionSize]; | ||
586 | terret.Initialize(); | ||
587 | |||
588 | String sql = "select RegionUUID, Revision, Heightfield from terrain" + | ||
589 | " where RegionUUID=:RegionUUID order by Revision desc"; | ||
590 | |||
591 | using (SqliteCommand cmd = new SqliteCommand(sql, m_conn)) | ||
592 | { | ||
593 | cmd.Parameters.Add(new SqliteParameter(":RegionUUID", regionID.ToString())); | ||
594 | |||
595 | using (IDataReader row = cmd.ExecuteReader()) | ||
596 | { | ||
597 | int rev = 0; | ||
598 | if (row.Read()) | ||
599 | { | ||
600 | // TODO: put this into a function | ||
601 | using (MemoryStream str = new MemoryStream((byte[])row["Heightfield"])) | ||
602 | { | ||
603 | using (BinaryReader br = new BinaryReader(str)) | ||
604 | { | ||
605 | for (int x = 0; x < (int)Constants.RegionSize; x++) | ||
606 | { | ||
607 | for (int y = 0; y < (int)Constants.RegionSize; y++) | ||
608 | { | ||
609 | terret[x, y] = br.ReadDouble(); | ||
610 | } | ||
611 | } | ||
612 | } | ||
613 | } | ||
614 | rev = (int) row["Revision"]; | ||
615 | } | ||
616 | else | ||
617 | { | ||
618 | m_log.Info("[REGION DB]: No terrain found for region"); | ||
619 | return null; | ||
620 | } | ||
621 | |||
622 | m_log.Info("[REGION DB]: Loaded terrain revision r" + rev.ToString()); | ||
623 | } | ||
624 | } | ||
625 | return terret; | ||
626 | } | ||
627 | } | ||
628 | |||
629 | /// <summary> | ||
630 | /// | ||
631 | /// </summary> | ||
632 | /// <param name="globalID"></param> | ||
633 | public void RemoveLandObject(UUID globalID) | ||
634 | { | ||
635 | lock (ds) | ||
636 | { | ||
637 | // Can't use blanket SQL statements when using SqlAdapters unless you re-read the data into the adapter | ||
638 | // after you're done. | ||
639 | // replaced below code with the SqliteAdapter version. | ||
640 | //using (SqliteCommand cmd = new SqliteCommand("delete from land where UUID=:UUID", m_conn)) | ||
641 | //{ | ||
642 | // cmd.Parameters.Add(new SqliteParameter(":UUID", globalID.ToString())); | ||
643 | // cmd.ExecuteNonQuery(); | ||
644 | //} | ||
645 | |||
646 | //using (SqliteCommand cmd = new SqliteCommand("delete from landaccesslist where LandUUID=:UUID", m_conn)) | ||
647 | //{ | ||
648 | // cmd.Parameters.Add(new SqliteParameter(":UUID", globalID.ToString())); | ||
649 | // cmd.ExecuteNonQuery(); | ||
650 | //} | ||
651 | |||
652 | DataTable land = ds.Tables["land"]; | ||
653 | DataTable landaccesslist = ds.Tables["landaccesslist"]; | ||
654 | DataRow landRow = land.Rows.Find(globalID.ToString()); | ||
655 | if (landRow != null) | ||
656 | { | ||
657 | land.Rows.Remove(landRow); | ||
658 | } | ||
659 | List<DataRow> rowsToDelete = new List<DataRow>(); | ||
660 | foreach (DataRow rowToCheck in landaccesslist.Rows) | ||
661 | { | ||
662 | if (rowToCheck["LandUUID"].ToString() == globalID.ToString()) | ||
663 | rowsToDelete.Add(rowToCheck); | ||
664 | } | ||
665 | for (int iter = 0; iter < rowsToDelete.Count; iter++) | ||
666 | { | ||
667 | landaccesslist.Rows.Remove(rowsToDelete[iter]); | ||
668 | } | ||
669 | |||
670 | |||
671 | } | ||
672 | Commit(); | ||
673 | } | ||
674 | |||
675 | /// <summary> | ||
676 | /// | ||
677 | /// </summary> | ||
678 | /// <param name="parcel"></param> | ||
679 | public void StoreLandObject(ILandObject parcel) | ||
680 | { | ||
681 | lock (ds) | ||
682 | { | ||
683 | DataTable land = ds.Tables["land"]; | ||
684 | DataTable landaccesslist = ds.Tables["landaccesslist"]; | ||
685 | |||
686 | DataRow landRow = land.Rows.Find(parcel.LandData.GlobalID.ToString()); | ||
687 | if (landRow == null) | ||
688 | { | ||
689 | landRow = land.NewRow(); | ||
690 | fillLandRow(landRow, parcel.LandData, parcel.RegionUUID); | ||
691 | land.Rows.Add(landRow); | ||
692 | } | ||
693 | else | ||
694 | { | ||
695 | fillLandRow(landRow, parcel.LandData, parcel.RegionUUID); | ||
696 | } | ||
697 | |||
698 | // I know this caused someone issues before, but OpenSim is unusable if we leave this stuff around | ||
699 | //using (SqliteCommand cmd = new SqliteCommand("delete from landaccesslist where LandUUID=:LandUUID", m_conn)) | ||
700 | //{ | ||
701 | // cmd.Parameters.Add(new SqliteParameter(":LandUUID", parcel.LandData.GlobalID.ToString())); | ||
702 | // cmd.ExecuteNonQuery(); | ||
703 | |||
704 | // } | ||
705 | |||
706 | // This is the slower.. but more appropriate thing to do | ||
707 | |||
708 | // We can't modify the table with direct queries before calling Commit() and re-filling them. | ||
709 | List<DataRow> rowsToDelete = new List<DataRow>(); | ||
710 | foreach (DataRow rowToCheck in landaccesslist.Rows) | ||
711 | { | ||
712 | if (rowToCheck["LandUUID"].ToString() == parcel.LandData.GlobalID.ToString()) | ||
713 | rowsToDelete.Add(rowToCheck); | ||
714 | } | ||
715 | for (int iter = 0; iter < rowsToDelete.Count; iter++) | ||
716 | { | ||
717 | landaccesslist.Rows.Remove(rowsToDelete[iter]); | ||
718 | } | ||
719 | rowsToDelete.Clear(); | ||
720 | foreach (ParcelManager.ParcelAccessEntry entry in parcel.LandData.ParcelAccessList) | ||
721 | { | ||
722 | DataRow newAccessRow = landaccesslist.NewRow(); | ||
723 | fillLandAccessRow(newAccessRow, entry, parcel.LandData.GlobalID); | ||
724 | landaccesslist.Rows.Add(newAccessRow); | ||
725 | } | ||
726 | } | ||
727 | |||
728 | Commit(); | ||
729 | } | ||
730 | |||
731 | /// <summary> | ||
732 | /// | ||
733 | /// </summary> | ||
734 | /// <param name="regionUUID"></param> | ||
735 | /// <returns></returns> | ||
736 | public List<LandData> LoadLandObjects(UUID regionUUID) | ||
737 | { | ||
738 | List<LandData> landDataForRegion = new List<LandData>(); | ||
739 | lock (ds) | ||
740 | { | ||
741 | DataTable land = ds.Tables["land"]; | ||
742 | DataTable landaccesslist = ds.Tables["landaccesslist"]; | ||
743 | string searchExp = "RegionUUID = '" + regionUUID + "'"; | ||
744 | DataRow[] rawDataForRegion = land.Select(searchExp); | ||
745 | foreach (DataRow rawDataLand in rawDataForRegion) | ||
746 | { | ||
747 | LandData newLand = buildLandData(rawDataLand); | ||
748 | string accessListSearchExp = "LandUUID = '" + newLand.GlobalID + "'"; | ||
749 | DataRow[] rawDataForLandAccessList = landaccesslist.Select(accessListSearchExp); | ||
750 | foreach (DataRow rawDataLandAccess in rawDataForLandAccessList) | ||
751 | { | ||
752 | newLand.ParcelAccessList.Add(buildLandAccessData(rawDataLandAccess)); | ||
753 | } | ||
754 | |||
755 | landDataForRegion.Add(newLand); | ||
756 | } | ||
757 | } | ||
758 | return landDataForRegion; | ||
759 | } | ||
760 | |||
761 | /// <summary> | ||
762 | /// | ||
763 | /// </summary> | ||
764 | public void Commit() | ||
765 | { | ||
766 | lock (ds) | ||
767 | { | ||
768 | primDa.Update(ds, "prims"); | ||
769 | shapeDa.Update(ds, "primshapes"); | ||
770 | |||
771 | itemsDa.Update(ds, "primitems"); | ||
772 | |||
773 | terrainDa.Update(ds, "terrain"); | ||
774 | landDa.Update(ds, "land"); | ||
775 | landAccessListDa.Update(ds, "landaccesslist"); | ||
776 | try | ||
777 | { | ||
778 | regionSettingsDa.Update(ds, "regionsettings"); | ||
779 | } | ||
780 | catch (SqliteExecutionException SqlEx) | ||
781 | { | ||
782 | if (SqlEx.Message.Contains("logic error")) | ||
783 | { | ||
784 | throw new Exception( | ||
785 | "There was a SQL error or connection string configuration error when saving the region settings. This could be a bug, it could also happen if ConnectionString is defined in the [DatabaseService] section of StandaloneCommon.ini in the config_include folder. This could also happen if the config_include folder doesn't exist or if the OpenSim.ini [Architecture] section isn't set. If this is your first time running OpenSimulator, please restart the simulator and bug a developer to fix this!", | ||
786 | SqlEx); | ||
787 | } | ||
788 | else | ||
789 | { | ||
790 | throw SqlEx; | ||
791 | } | ||
792 | } | ||
793 | ds.AcceptChanges(); | ||
794 | } | ||
795 | } | ||
796 | |||
797 | /// <summary> | ||
798 | /// See <see cref="Commit"/> | ||
799 | /// </summary> | ||
800 | public void Shutdown() | ||
801 | { | ||
802 | Commit(); | ||
803 | } | ||
804 | |||
805 | /*********************************************************************** | ||
806 | * | ||
807 | * Database Definition Functions | ||
808 | * | ||
809 | * This should be db agnostic as we define them in ADO.NET terms | ||
810 | * | ||
811 | **********************************************************************/ | ||
812 | |||
813 | /// <summary> | ||
814 | /// | ||
815 | /// </summary> | ||
816 | /// <param name="dt"></param> | ||
817 | /// <param name="name"></param> | ||
818 | /// <param name="type"></param> | ||
819 | private static void createCol(DataTable dt, string name, Type type) | ||
820 | { | ||
821 | DataColumn col = new DataColumn(name, type); | ||
822 | dt.Columns.Add(col); | ||
823 | } | ||
824 | |||
825 | /// <summary> | ||
826 | /// Creates the "terrain" table | ||
827 | /// </summary> | ||
828 | /// <returns>terrain table DataTable</returns> | ||
829 | private static DataTable createTerrainTable() | ||
830 | { | ||
831 | DataTable terrain = new DataTable("terrain"); | ||
832 | |||
833 | createCol(terrain, "RegionUUID", typeof (String)); | ||
834 | createCol(terrain, "Revision", typeof (Int32)); | ||
835 | createCol(terrain, "Heightfield", typeof (Byte[])); | ||
836 | |||
837 | return terrain; | ||
838 | } | ||
839 | |||
840 | /// <summary> | ||
841 | /// Creates the "prims" table | ||
842 | /// </summary> | ||
843 | /// <returns>prim table DataTable</returns> | ||
844 | private static DataTable createPrimTable() | ||
845 | { | ||
846 | DataTable prims = new DataTable("prims"); | ||
847 | |||
848 | createCol(prims, "UUID", typeof (String)); | ||
849 | createCol(prims, "RegionUUID", typeof (String)); | ||
850 | createCol(prims, "CreationDate", typeof (Int32)); | ||
851 | createCol(prims, "Name", typeof (String)); | ||
852 | createCol(prims, "SceneGroupID", typeof (String)); | ||
853 | // various text fields | ||
854 | createCol(prims, "Text", typeof (String)); | ||
855 | createCol(prims, "ColorR", typeof (Int32)); | ||
856 | createCol(prims, "ColorG", typeof (Int32)); | ||
857 | createCol(prims, "ColorB", typeof (Int32)); | ||
858 | createCol(prims, "ColorA", typeof (Int32)); | ||
859 | createCol(prims, "Description", typeof (String)); | ||
860 | createCol(prims, "SitName", typeof (String)); | ||
861 | createCol(prims, "TouchName", typeof (String)); | ||
862 | // permissions | ||
863 | createCol(prims, "ObjectFlags", typeof (Int32)); | ||
864 | createCol(prims, "CreatorID", typeof (String)); | ||
865 | createCol(prims, "OwnerID", typeof (String)); | ||
866 | createCol(prims, "GroupID", typeof (String)); | ||
867 | createCol(prims, "LastOwnerID", typeof (String)); | ||
868 | createCol(prims, "OwnerMask", typeof (Int32)); | ||
869 | createCol(prims, "NextOwnerMask", typeof (Int32)); | ||
870 | createCol(prims, "GroupMask", typeof (Int32)); | ||
871 | createCol(prims, "EveryoneMask", typeof (Int32)); | ||
872 | createCol(prims, "BaseMask", typeof (Int32)); | ||
873 | // vectors | ||
874 | createCol(prims, "PositionX", typeof (Double)); | ||
875 | createCol(prims, "PositionY", typeof (Double)); | ||
876 | createCol(prims, "PositionZ", typeof (Double)); | ||
877 | createCol(prims, "GroupPositionX", typeof (Double)); | ||
878 | createCol(prims, "GroupPositionY", typeof (Double)); | ||
879 | createCol(prims, "GroupPositionZ", typeof (Double)); | ||
880 | createCol(prims, "VelocityX", typeof (Double)); | ||
881 | createCol(prims, "VelocityY", typeof (Double)); | ||
882 | createCol(prims, "VelocityZ", typeof (Double)); | ||
883 | createCol(prims, "AngularVelocityX", typeof (Double)); | ||
884 | createCol(prims, "AngularVelocityY", typeof (Double)); | ||
885 | createCol(prims, "AngularVelocityZ", typeof (Double)); | ||
886 | createCol(prims, "AccelerationX", typeof (Double)); | ||
887 | createCol(prims, "AccelerationY", typeof (Double)); | ||
888 | createCol(prims, "AccelerationZ", typeof (Double)); | ||
889 | // quaternions | ||
890 | createCol(prims, "RotationX", typeof (Double)); | ||
891 | createCol(prims, "RotationY", typeof (Double)); | ||
892 | createCol(prims, "RotationZ", typeof (Double)); | ||
893 | createCol(prims, "RotationW", typeof (Double)); | ||
894 | |||
895 | // sit target | ||
896 | createCol(prims, "SitTargetOffsetX", typeof (Double)); | ||
897 | createCol(prims, "SitTargetOffsetY", typeof (Double)); | ||
898 | createCol(prims, "SitTargetOffsetZ", typeof (Double)); | ||
899 | |||
900 | createCol(prims, "SitTargetOrientW", typeof (Double)); | ||
901 | createCol(prims, "SitTargetOrientX", typeof (Double)); | ||
902 | createCol(prims, "SitTargetOrientY", typeof (Double)); | ||
903 | createCol(prims, "SitTargetOrientZ", typeof (Double)); | ||
904 | |||
905 | createCol(prims, "PayPrice", typeof(Int32)); | ||
906 | createCol(prims, "PayButton1", typeof(Int32)); | ||
907 | createCol(prims, "PayButton2", typeof(Int32)); | ||
908 | createCol(prims, "PayButton3", typeof(Int32)); | ||
909 | createCol(prims, "PayButton4", typeof(Int32)); | ||
910 | |||
911 | createCol(prims, "LoopedSound", typeof(String)); | ||
912 | createCol(prims, "LoopedSoundGain", typeof(Double)); | ||
913 | createCol(prims, "TextureAnimation", typeof(String)); | ||
914 | createCol(prims, "ParticleSystem", typeof(String)); | ||
915 | |||
916 | createCol(prims, "OmegaX", typeof(Double)); | ||
917 | createCol(prims, "OmegaY", typeof(Double)); | ||
918 | createCol(prims, "OmegaZ", typeof(Double)); | ||
919 | |||
920 | createCol(prims, "CameraEyeOffsetX", typeof(Double)); | ||
921 | createCol(prims, "CameraEyeOffsetY", typeof(Double)); | ||
922 | createCol(prims, "CameraEyeOffsetZ", typeof(Double)); | ||
923 | |||
924 | createCol(prims, "CameraAtOffsetX", typeof(Double)); | ||
925 | createCol(prims, "CameraAtOffsetY", typeof(Double)); | ||
926 | createCol(prims, "CameraAtOffsetZ", typeof(Double)); | ||
927 | |||
928 | createCol(prims, "ForceMouselook", typeof(Int16)); | ||
929 | |||
930 | createCol(prims, "ScriptAccessPin", typeof(Int32)); | ||
931 | |||
932 | createCol(prims, "AllowedDrop", typeof(Int16)); | ||
933 | createCol(prims, "DieAtEdge", typeof(Int16)); | ||
934 | |||
935 | createCol(prims, "SalePrice", typeof(Int32)); | ||
936 | createCol(prims, "SaleType", typeof(Int16)); | ||
937 | |||
938 | // click action | ||
939 | createCol(prims, "ClickAction", typeof (Byte)); | ||
940 | |||
941 | createCol(prims, "Material", typeof(Byte)); | ||
942 | |||
943 | createCol(prims, "CollisionSound", typeof(String)); | ||
944 | createCol(prims, "CollisionSoundVolume", typeof(Double)); | ||
945 | |||
946 | createCol(prims, "VolumeDetect", typeof(Int16)); | ||
947 | |||
948 | // Add in contraints | ||
949 | prims.PrimaryKey = new DataColumn[] {prims.Columns["UUID"]}; | ||
950 | |||
951 | return prims; | ||
952 | } | ||
953 | |||
954 | /// <summary> | ||
955 | /// Creates "primshapes" table | ||
956 | /// </summary> | ||
957 | /// <returns>shape table DataTable</returns> | ||
958 | private static DataTable createShapeTable() | ||
959 | { | ||
960 | DataTable shapes = new DataTable("primshapes"); | ||
961 | createCol(shapes, "UUID", typeof (String)); | ||
962 | // shape is an enum | ||
963 | createCol(shapes, "Shape", typeof (Int32)); | ||
964 | // vectors | ||
965 | createCol(shapes, "ScaleX", typeof (Double)); | ||
966 | createCol(shapes, "ScaleY", typeof (Double)); | ||
967 | createCol(shapes, "ScaleZ", typeof (Double)); | ||
968 | // paths | ||
969 | createCol(shapes, "PCode", typeof (Int32)); | ||
970 | createCol(shapes, "PathBegin", typeof (Int32)); | ||
971 | createCol(shapes, "PathEnd", typeof (Int32)); | ||
972 | createCol(shapes, "PathScaleX", typeof (Int32)); | ||
973 | createCol(shapes, "PathScaleY", typeof (Int32)); | ||
974 | createCol(shapes, "PathShearX", typeof (Int32)); | ||
975 | createCol(shapes, "PathShearY", typeof (Int32)); | ||
976 | createCol(shapes, "PathSkew", typeof (Int32)); | ||
977 | createCol(shapes, "PathCurve", typeof (Int32)); | ||
978 | createCol(shapes, "PathRadiusOffset", typeof (Int32)); | ||
979 | createCol(shapes, "PathRevolutions", typeof (Int32)); | ||
980 | createCol(shapes, "PathTaperX", typeof (Int32)); | ||
981 | createCol(shapes, "PathTaperY", typeof (Int32)); | ||
982 | createCol(shapes, "PathTwist", typeof (Int32)); | ||
983 | createCol(shapes, "PathTwistBegin", typeof (Int32)); | ||
984 | // profile | ||
985 | createCol(shapes, "ProfileBegin", typeof (Int32)); | ||
986 | createCol(shapes, "ProfileEnd", typeof (Int32)); | ||
987 | createCol(shapes, "ProfileCurve", typeof (Int32)); | ||
988 | createCol(shapes, "ProfileHollow", typeof (Int32)); | ||
989 | createCol(shapes, "State", typeof(Int32)); | ||
990 | // text TODO: this isn't right, but I'm not sure the right | ||
991 | // way to specify this as a blob atm | ||
992 | createCol(shapes, "Texture", typeof (Byte[])); | ||
993 | createCol(shapes, "ExtraParams", typeof (Byte[])); | ||
994 | |||
995 | shapes.PrimaryKey = new DataColumn[] {shapes.Columns["UUID"]}; | ||
996 | |||
997 | return shapes; | ||
998 | } | ||
999 | |||
1000 | /// <summary> | ||
1001 | /// creates "primitems" table | ||
1002 | /// </summary> | ||
1003 | /// <returns>item table DataTable</returns> | ||
1004 | private static DataTable createItemsTable() | ||
1005 | { | ||
1006 | DataTable items = new DataTable("primitems"); | ||
1007 | |||
1008 | createCol(items, "itemID", typeof (String)); | ||
1009 | createCol(items, "primID", typeof (String)); | ||
1010 | createCol(items, "assetID", typeof (String)); | ||
1011 | createCol(items, "parentFolderID", typeof (String)); | ||
1012 | |||
1013 | createCol(items, "invType", typeof (Int32)); | ||
1014 | createCol(items, "assetType", typeof (Int32)); | ||
1015 | |||
1016 | createCol(items, "name", typeof (String)); | ||
1017 | createCol(items, "description", typeof (String)); | ||
1018 | |||
1019 | createCol(items, "creationDate", typeof (Int64)); | ||
1020 | createCol(items, "creatorID", typeof (String)); | ||
1021 | createCol(items, "ownerID", typeof (String)); | ||
1022 | createCol(items, "lastOwnerID", typeof (String)); | ||
1023 | createCol(items, "groupID", typeof (String)); | ||
1024 | |||
1025 | createCol(items, "nextPermissions", typeof (UInt32)); | ||
1026 | createCol(items, "currentPermissions", typeof (UInt32)); | ||
1027 | createCol(items, "basePermissions", typeof (UInt32)); | ||
1028 | createCol(items, "everyonePermissions", typeof (UInt32)); | ||
1029 | createCol(items, "groupPermissions", typeof (UInt32)); | ||
1030 | createCol(items, "flags", typeof (UInt32)); | ||
1031 | |||
1032 | items.PrimaryKey = new DataColumn[] { items.Columns["itemID"] }; | ||
1033 | |||
1034 | return items; | ||
1035 | } | ||
1036 | |||
1037 | /// <summary> | ||
1038 | /// Creates "land" table | ||
1039 | /// </summary> | ||
1040 | /// <returns>land table DataTable</returns> | ||
1041 | private static DataTable createLandTable() | ||
1042 | { | ||
1043 | DataTable land = new DataTable("land"); | ||
1044 | createCol(land, "UUID", typeof (String)); | ||
1045 | createCol(land, "RegionUUID", typeof (String)); | ||
1046 | createCol(land, "LocalLandID", typeof (UInt32)); | ||
1047 | |||
1048 | // Bitmap is a byte[512] | ||
1049 | createCol(land, "Bitmap", typeof (Byte[])); | ||
1050 | |||
1051 | createCol(land, "Name", typeof (String)); | ||
1052 | createCol(land, "Desc", typeof (String)); | ||
1053 | createCol(land, "OwnerUUID", typeof (String)); | ||
1054 | createCol(land, "IsGroupOwned", typeof (Boolean)); | ||
1055 | createCol(land, "Area", typeof (Int32)); | ||
1056 | createCol(land, "AuctionID", typeof (Int32)); //Unemplemented | ||
1057 | createCol(land, "Category", typeof (Int32)); //Enum OpenMetaverse.Parcel.ParcelCategory | ||
1058 | createCol(land, "ClaimDate", typeof (Int32)); | ||
1059 | createCol(land, "ClaimPrice", typeof (Int32)); | ||
1060 | createCol(land, "GroupUUID", typeof (string)); | ||
1061 | createCol(land, "SalePrice", typeof (Int32)); | ||
1062 | createCol(land, "LandStatus", typeof (Int32)); //Enum. OpenMetaverse.Parcel.ParcelStatus | ||
1063 | createCol(land, "LandFlags", typeof (UInt32)); | ||
1064 | createCol(land, "LandingType", typeof (Byte)); | ||
1065 | createCol(land, "MediaAutoScale", typeof (Byte)); | ||
1066 | createCol(land, "MediaTextureUUID", typeof (String)); | ||
1067 | createCol(land, "MediaURL", typeof (String)); | ||
1068 | createCol(land, "MusicURL", typeof (String)); | ||
1069 | createCol(land, "PassHours", typeof (Double)); | ||
1070 | createCol(land, "PassPrice", typeof (UInt32)); | ||
1071 | createCol(land, "SnapshotUUID", typeof (String)); | ||
1072 | createCol(land, "UserLocationX", typeof (Double)); | ||
1073 | createCol(land, "UserLocationY", typeof (Double)); | ||
1074 | createCol(land, "UserLocationZ", typeof (Double)); | ||
1075 | createCol(land, "UserLookAtX", typeof (Double)); | ||
1076 | createCol(land, "UserLookAtY", typeof (Double)); | ||
1077 | createCol(land, "UserLookAtZ", typeof (Double)); | ||
1078 | createCol(land, "AuthbuyerID", typeof(String)); | ||
1079 | createCol(land, "OtherCleanTime", typeof(Int32)); | ||
1080 | |||
1081 | land.PrimaryKey = new DataColumn[] {land.Columns["UUID"]}; | ||
1082 | |||
1083 | return land; | ||
1084 | } | ||
1085 | |||
1086 | /// <summary> | ||
1087 | /// create "landaccesslist" table | ||
1088 | /// </summary> | ||
1089 | /// <returns>Landacceslist DataTable</returns> | ||
1090 | private static DataTable createLandAccessListTable() | ||
1091 | { | ||
1092 | DataTable landaccess = new DataTable("landaccesslist"); | ||
1093 | createCol(landaccess, "LandUUID", typeof (String)); | ||
1094 | createCol(landaccess, "AccessUUID", typeof (String)); | ||
1095 | createCol(landaccess, "Flags", typeof (UInt32)); | ||
1096 | |||
1097 | return landaccess; | ||
1098 | } | ||
1099 | |||
1100 | private static DataTable createRegionSettingsTable() | ||
1101 | { | ||
1102 | DataTable regionsettings = new DataTable("regionsettings"); | ||
1103 | createCol(regionsettings, "regionUUID", typeof(String)); | ||
1104 | createCol(regionsettings, "block_terraform", typeof (Int32)); | ||
1105 | createCol(regionsettings, "block_fly", typeof (Int32)); | ||
1106 | createCol(regionsettings, "allow_damage", typeof (Int32)); | ||
1107 | createCol(regionsettings, "restrict_pushing", typeof (Int32)); | ||
1108 | createCol(regionsettings, "allow_land_resell", typeof (Int32)); | ||
1109 | createCol(regionsettings, "allow_land_join_divide", typeof (Int32)); | ||
1110 | createCol(regionsettings, "block_show_in_search", typeof (Int32)); | ||
1111 | createCol(regionsettings, "agent_limit", typeof (Int32)); | ||
1112 | createCol(regionsettings, "object_bonus", typeof (Double)); | ||
1113 | createCol(regionsettings, "maturity", typeof (Int32)); | ||
1114 | createCol(regionsettings, "disable_scripts", typeof (Int32)); | ||
1115 | createCol(regionsettings, "disable_collisions", typeof (Int32)); | ||
1116 | createCol(regionsettings, "disable_physics", typeof (Int32)); | ||
1117 | createCol(regionsettings, "terrain_texture_1", typeof(String)); | ||
1118 | createCol(regionsettings, "terrain_texture_2", typeof(String)); | ||
1119 | createCol(regionsettings, "terrain_texture_3", typeof(String)); | ||
1120 | createCol(regionsettings, "terrain_texture_4", typeof(String)); | ||
1121 | createCol(regionsettings, "elevation_1_nw", typeof (Double)); | ||
1122 | createCol(regionsettings, "elevation_2_nw", typeof (Double)); | ||
1123 | createCol(regionsettings, "elevation_1_ne", typeof (Double)); | ||
1124 | createCol(regionsettings, "elevation_2_ne", typeof (Double)); | ||
1125 | createCol(regionsettings, "elevation_1_se", typeof (Double)); | ||
1126 | createCol(regionsettings, "elevation_2_se", typeof (Double)); | ||
1127 | createCol(regionsettings, "elevation_1_sw", typeof (Double)); | ||
1128 | createCol(regionsettings, "elevation_2_sw", typeof (Double)); | ||
1129 | createCol(regionsettings, "water_height", typeof (Double)); | ||
1130 | createCol(regionsettings, "terrain_raise_limit", typeof (Double)); | ||
1131 | createCol(regionsettings, "terrain_lower_limit", typeof (Double)); | ||
1132 | createCol(regionsettings, "use_estate_sun", typeof (Int32)); | ||
1133 | createCol(regionsettings, "sandbox", typeof (Int32)); | ||
1134 | createCol(regionsettings, "sunvectorx",typeof (Double)); | ||
1135 | createCol(regionsettings, "sunvectory",typeof (Double)); | ||
1136 | createCol(regionsettings, "sunvectorz",typeof (Double)); | ||
1137 | createCol(regionsettings, "fixed_sun", typeof (Int32)); | ||
1138 | createCol(regionsettings, "sun_position", typeof (Double)); | ||
1139 | createCol(regionsettings, "covenant", typeof(String)); | ||
1140 | regionsettings.PrimaryKey = new DataColumn[] { regionsettings.Columns["regionUUID"] }; | ||
1141 | return regionsettings; | ||
1142 | } | ||
1143 | |||
1144 | /*********************************************************************** | ||
1145 | * | ||
1146 | * Convert between ADO.NET <=> OpenSim Objects | ||
1147 | * | ||
1148 | * These should be database independant | ||
1149 | * | ||
1150 | **********************************************************************/ | ||
1151 | |||
1152 | /// <summary> | ||
1153 | /// | ||
1154 | /// </summary> | ||
1155 | /// <param name="row"></param> | ||
1156 | /// <returns></returns> | ||
1157 | private SceneObjectPart buildPrim(DataRow row) | ||
1158 | { | ||
1159 | // Code commented. Uncomment to test the unit test inline. | ||
1160 | |||
1161 | // The unit test mentions this commented code for the purposes | ||
1162 | // of debugging a unit test failure | ||
1163 | |||
1164 | // SceneObjectGroup sog = new SceneObjectGroup(); | ||
1165 | // SceneObjectPart sop = new SceneObjectPart(); | ||
1166 | // sop.LocalId = 1; | ||
1167 | // sop.Name = "object1"; | ||
1168 | // sop.Description = "object1"; | ||
1169 | // sop.Text = ""; | ||
1170 | // sop.SitName = ""; | ||
1171 | // sop.TouchName = ""; | ||
1172 | // sop.UUID = UUID.Random(); | ||
1173 | // sop.Shape = PrimitiveBaseShape.Default; | ||
1174 | // sog.SetRootPart(sop); | ||
1175 | // Add breakpoint in above line. Check sop fields. | ||
1176 | |||
1177 | // TODO: this doesn't work yet because something more | ||
1178 | // interesting has to be done to actually get these values | ||
1179 | // back out. Not enough time to figure it out yet. | ||
1180 | |||
1181 | SceneObjectPart prim = new SceneObjectPart(); | ||
1182 | prim.UUID = new UUID((String) row["UUID"]); | ||
1183 | // explicit conversion of integers is required, which sort | ||
1184 | // of sucks. No idea if there is a shortcut here or not. | ||
1185 | prim.CreationDate = Convert.ToInt32(row["CreationDate"]); | ||
1186 | prim.Name = row["Name"] == DBNull.Value ? string.Empty : (string)row["Name"]; | ||
1187 | // various text fields | ||
1188 | prim.Text = (String) row["Text"]; | ||
1189 | prim.Color = Color.FromArgb(Convert.ToInt32(row["ColorA"]), | ||
1190 | Convert.ToInt32(row["ColorR"]), | ||
1191 | Convert.ToInt32(row["ColorG"]), | ||
1192 | Convert.ToInt32(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)Convert.ToUInt32(row["ObjectFlags"]); | ||
1198 | prim.CreatorID = new UUID((String) row["CreatorID"]); | ||
1199 | prim.OwnerID = new UUID((String) row["OwnerID"]); | ||
1200 | prim.GroupID = new UUID((String) row["GroupID"]); | ||
1201 | prim.LastOwnerID = new UUID((String) row["LastOwnerID"]); | ||
1202 | prim.OwnerMask = Convert.ToUInt32(row["OwnerMask"]); | ||
1203 | prim.NextOwnerMask = Convert.ToUInt32(row["NextOwnerMask"]); | ||
1204 | prim.GroupMask = Convert.ToUInt32(row["GroupMask"]); | ||
1205 | prim.EveryoneMask = Convert.ToUInt32(row["EveryoneMask"]); | ||
1206 | prim.BaseMask = Convert.ToUInt32(row["BaseMask"]); | ||
1207 | // vectors | ||
1208 | prim.OffsetPosition = new Vector3( | ||
1209 | Convert.ToSingle(row["PositionX"]), | ||
1210 | Convert.ToSingle(row["PositionY"]), | ||
1211 | Convert.ToSingle(row["PositionZ"]) | ||
1212 | ); | ||
1213 | prim.GroupPosition = new Vector3( | ||
1214 | Convert.ToSingle(row["GroupPositionX"]), | ||
1215 | Convert.ToSingle(row["GroupPositionY"]), | ||
1216 | Convert.ToSingle(row["GroupPositionZ"]) | ||
1217 | ); | ||
1218 | prim.Velocity = new Vector3( | ||
1219 | Convert.ToSingle(row["VelocityX"]), | ||
1220 | Convert.ToSingle(row["VelocityY"]), | ||
1221 | Convert.ToSingle(row["VelocityZ"]) | ||
1222 | ); | ||
1223 | prim.AngularVelocity = new Vector3( | ||
1224 | Convert.ToSingle(row["AngularVelocityX"]), | ||
1225 | Convert.ToSingle(row["AngularVelocityY"]), | ||
1226 | Convert.ToSingle(row["AngularVelocityZ"]) | ||
1227 | ); | ||
1228 | prim.Acceleration = new Vector3( | ||
1229 | Convert.ToSingle(row["AccelerationX"]), | ||
1230 | Convert.ToSingle(row["AccelerationY"]), | ||
1231 | Convert.ToSingle(row["AccelerationZ"]) | ||
1232 | ); | ||
1233 | // quaternions | ||
1234 | prim.RotationOffset = new Quaternion( | ||
1235 | Convert.ToSingle(row["RotationX"]), | ||
1236 | Convert.ToSingle(row["RotationY"]), | ||
1237 | Convert.ToSingle(row["RotationZ"]), | ||
1238 | Convert.ToSingle(row["RotationW"]) | ||
1239 | ); | ||
1240 | |||
1241 | prim.SitTargetPositionLL = new Vector3( | ||
1242 | Convert.ToSingle(row["SitTargetOffsetX"]), | ||
1243 | Convert.ToSingle(row["SitTargetOffsetY"]), | ||
1244 | Convert.ToSingle(row["SitTargetOffsetZ"])); | ||
1245 | prim.SitTargetOrientationLL = new Quaternion( | ||
1246 | Convert.ToSingle( | ||
1247 | row["SitTargetOrientX"]), | ||
1248 | Convert.ToSingle( | ||
1249 | row["SitTargetOrientY"]), | ||
1250 | Convert.ToSingle( | ||
1251 | row["SitTargetOrientZ"]), | ||
1252 | Convert.ToSingle( | ||
1253 | row["SitTargetOrientW"])); | ||
1254 | |||
1255 | prim.ClickAction = Convert.ToByte(row["ClickAction"]); | ||
1256 | prim.PayPrice[0] = Convert.ToInt32(row["PayPrice"]); | ||
1257 | prim.PayPrice[1] = Convert.ToInt32(row["PayButton1"]); | ||
1258 | prim.PayPrice[2] = Convert.ToInt32(row["PayButton2"]); | ||
1259 | prim.PayPrice[3] = Convert.ToInt32(row["PayButton3"]); | ||
1260 | prim.PayPrice[4] = Convert.ToInt32(row["PayButton4"]); | ||
1261 | |||
1262 | prim.Sound = new UUID(row["LoopedSound"].ToString()); | ||
1263 | prim.SoundGain = Convert.ToSingle(row["LoopedSoundGain"]); | ||
1264 | prim.SoundFlags = 1; // If it's persisted at all, it's looped | ||
1265 | |||
1266 | if (!row.IsNull("TextureAnimation")) | ||
1267 | prim.TextureAnimation = Convert.FromBase64String(row["TextureAnimation"].ToString()); | ||
1268 | if (!row.IsNull("ParticleSystem")) | ||
1269 | prim.ParticleSystem = Convert.FromBase64String(row["ParticleSystem"].ToString()); | ||
1270 | |||
1271 | prim.AngularVelocity = new Vector3( | ||
1272 | Convert.ToSingle(row["OmegaX"]), | ||
1273 | Convert.ToSingle(row["OmegaY"]), | ||
1274 | Convert.ToSingle(row["OmegaZ"]) | ||
1275 | ); | ||
1276 | |||
1277 | prim.SetCameraEyeOffset(new Vector3( | ||
1278 | Convert.ToSingle(row["CameraEyeOffsetX"]), | ||
1279 | Convert.ToSingle(row["CameraEyeOffsetY"]), | ||
1280 | Convert.ToSingle(row["CameraEyeOffsetZ"]) | ||
1281 | )); | ||
1282 | |||
1283 | prim.SetCameraAtOffset(new Vector3( | ||
1284 | Convert.ToSingle(row["CameraAtOffsetX"]), | ||
1285 | Convert.ToSingle(row["CameraAtOffsetY"]), | ||
1286 | Convert.ToSingle(row["CameraAtOffsetZ"]) | ||
1287 | )); | ||
1288 | |||
1289 | if (Convert.ToInt16(row["ForceMouselook"]) != 0) | ||
1290 | prim.SetForceMouselook(true); | ||
1291 | |||
1292 | prim.ScriptAccessPin = Convert.ToInt32(row["ScriptAccessPin"]); | ||
1293 | |||
1294 | if (Convert.ToInt16(row["AllowedDrop"]) != 0) | ||
1295 | prim.AllowedDrop = true; | ||
1296 | |||
1297 | if (Convert.ToInt16(row["DieAtEdge"]) != 0) | ||
1298 | prim.DIE_AT_EDGE = true; | ||
1299 | |||
1300 | prim.SalePrice = Convert.ToInt32(row["SalePrice"]); | ||
1301 | prim.ObjectSaleType = Convert.ToByte(row["SaleType"]); | ||
1302 | |||
1303 | prim.Material = Convert.ToByte(row["Material"]); | ||
1304 | |||
1305 | prim.CollisionSound = new UUID(row["CollisionSound"].ToString()); | ||
1306 | prim.CollisionSoundVolume = Convert.ToSingle(row["CollisionSoundVolume"]); | ||
1307 | |||
1308 | if (Convert.ToInt16(row["VolumeDetect"]) != 0) | ||
1309 | prim.VolumeDetectActive = true; | ||
1310 | |||
1311 | return prim; | ||
1312 | } | ||
1313 | |||
1314 | /// <summary> | ||
1315 | /// Build a prim inventory item from the persisted data. | ||
1316 | /// </summary> | ||
1317 | /// <param name="row"></param> | ||
1318 | /// <returns></returns> | ||
1319 | private static TaskInventoryItem buildItem(DataRow row) | ||
1320 | { | ||
1321 | TaskInventoryItem taskItem = new TaskInventoryItem(); | ||
1322 | |||
1323 | taskItem.ItemID = new UUID((String)row["itemID"]); | ||
1324 | taskItem.ParentPartID = new UUID((String)row["primID"]); | ||
1325 | taskItem.AssetID = new UUID((String)row["assetID"]); | ||
1326 | taskItem.ParentID = new UUID((String)row["parentFolderID"]); | ||
1327 | |||
1328 | taskItem.InvType = Convert.ToInt32(row["invType"]); | ||
1329 | taskItem.Type = Convert.ToInt32(row["assetType"]); | ||
1330 | |||
1331 | taskItem.Name = (String)row["name"]; | ||
1332 | taskItem.Description = (String)row["description"]; | ||
1333 | taskItem.CreationDate = Convert.ToUInt32(row["creationDate"]); | ||
1334 | taskItem.CreatorID = new UUID((String)row["creatorID"]); | ||
1335 | taskItem.OwnerID = new UUID((String)row["ownerID"]); | ||
1336 | taskItem.LastOwnerID = new UUID((String)row["lastOwnerID"]); | ||
1337 | taskItem.GroupID = new UUID((String)row["groupID"]); | ||
1338 | |||
1339 | taskItem.NextPermissions = Convert.ToUInt32(row["nextPermissions"]); | ||
1340 | taskItem.CurrentPermissions = Convert.ToUInt32(row["currentPermissions"]); | ||
1341 | taskItem.BasePermissions = Convert.ToUInt32(row["basePermissions"]); | ||
1342 | taskItem.EveryonePermissions = Convert.ToUInt32(row["everyonePermissions"]); | ||
1343 | taskItem.GroupPermissions = Convert.ToUInt32(row["groupPermissions"]); | ||
1344 | taskItem.Flags = Convert.ToUInt32(row["flags"]); | ||
1345 | |||
1346 | return taskItem; | ||
1347 | } | ||
1348 | |||
1349 | /// <summary> | ||
1350 | /// Build a Land Data from the persisted data. | ||
1351 | /// </summary> | ||
1352 | /// <param name="row"></param> | ||
1353 | /// <returns></returns> | ||
1354 | private LandData buildLandData(DataRow row) | ||
1355 | { | ||
1356 | LandData newData = new LandData(); | ||
1357 | |||
1358 | newData.GlobalID = new UUID((String) row["UUID"]); | ||
1359 | newData.LocalID = Convert.ToInt32(row["LocalLandID"]); | ||
1360 | |||
1361 | // Bitmap is a byte[512] | ||
1362 | newData.Bitmap = (Byte[]) row["Bitmap"]; | ||
1363 | |||
1364 | newData.Name = (String) row["Name"]; | ||
1365 | newData.Description = (String) row["Desc"]; | ||
1366 | newData.OwnerID = (UUID)(String) row["OwnerUUID"]; | ||
1367 | newData.IsGroupOwned = (Boolean) row["IsGroupOwned"]; | ||
1368 | newData.Area = Convert.ToInt32(row["Area"]); | ||
1369 | newData.AuctionID = Convert.ToUInt32(row["AuctionID"]); //Unemplemented | ||
1370 | newData.Category = (ParcelCategory) Convert.ToInt32(row["Category"]); | ||
1371 | //Enum OpenMetaverse.Parcel.ParcelCategory | ||
1372 | newData.ClaimDate = Convert.ToInt32(row["ClaimDate"]); | ||
1373 | newData.ClaimPrice = Convert.ToInt32(row["ClaimPrice"]); | ||
1374 | newData.GroupID = new UUID((String) row["GroupUUID"]); | ||
1375 | newData.SalePrice = Convert.ToInt32(row["SalePrice"]); | ||
1376 | newData.Status = (ParcelStatus) Convert.ToInt32(row["LandStatus"]); | ||
1377 | //Enum. OpenMetaverse.Parcel.ParcelStatus | ||
1378 | newData.Flags = Convert.ToUInt32(row["LandFlags"]); | ||
1379 | newData.LandingType = (Byte) row["LandingType"]; | ||
1380 | newData.MediaAutoScale = (Byte) row["MediaAutoScale"]; | ||
1381 | newData.MediaID = new UUID((String) row["MediaTextureUUID"]); | ||
1382 | newData.MediaURL = (String) row["MediaURL"]; | ||
1383 | newData.MusicURL = (String) row["MusicURL"]; | ||
1384 | newData.PassHours = Convert.ToSingle(row["PassHours"]); | ||
1385 | newData.PassPrice = Convert.ToInt32(row["PassPrice"]); | ||
1386 | newData.SnapshotID = (UUID)(String) row["SnapshotUUID"]; | ||
1387 | try | ||
1388 | { | ||
1389 | |||
1390 | newData.UserLocation = | ||
1391 | new Vector3(Convert.ToSingle(row["UserLocationX"]), Convert.ToSingle(row["UserLocationY"]), | ||
1392 | Convert.ToSingle(row["UserLocationZ"])); | ||
1393 | newData.UserLookAt = | ||
1394 | new Vector3(Convert.ToSingle(row["UserLookAtX"]), Convert.ToSingle(row["UserLookAtY"]), | ||
1395 | Convert.ToSingle(row["UserLookAtZ"])); | ||
1396 | |||
1397 | } | ||
1398 | catch (InvalidCastException) | ||
1399 | { | ||
1400 | m_log.ErrorFormat("[PARCEL]: unable to get parcel telehub settings for {1}", newData.Name); | ||
1401 | newData.UserLocation = Vector3.Zero; | ||
1402 | newData.UserLookAt = Vector3.Zero; | ||
1403 | } | ||
1404 | newData.ParcelAccessList = new List<ParcelManager.ParcelAccessEntry>(); | ||
1405 | UUID authBuyerID = UUID.Zero; | ||
1406 | |||
1407 | UUID.TryParse((string)row["AuthbuyerID"], out authBuyerID); | ||
1408 | |||
1409 | newData.OtherCleanTime = Convert.ToInt32(row["OtherCleanTime"]); | ||
1410 | |||
1411 | return newData; | ||
1412 | } | ||
1413 | |||
1414 | private RegionSettings buildRegionSettings(DataRow row) | ||
1415 | { | ||
1416 | RegionSettings newSettings = new RegionSettings(); | ||
1417 | |||
1418 | newSettings.RegionUUID = new UUID((string) row["regionUUID"]); | ||
1419 | newSettings.BlockTerraform = Convert.ToBoolean(row["block_terraform"]); | ||
1420 | newSettings.AllowDamage = Convert.ToBoolean(row["allow_damage"]); | ||
1421 | newSettings.BlockFly = Convert.ToBoolean(row["block_fly"]); | ||
1422 | newSettings.RestrictPushing = Convert.ToBoolean(row["restrict_pushing"]); | ||
1423 | newSettings.AllowLandResell = Convert.ToBoolean(row["allow_land_resell"]); | ||
1424 | newSettings.AllowLandJoinDivide = Convert.ToBoolean(row["allow_land_join_divide"]); | ||
1425 | newSettings.BlockShowInSearch = Convert.ToBoolean(row["block_show_in_search"]); | ||
1426 | newSettings.AgentLimit = Convert.ToInt32(row["agent_limit"]); | ||
1427 | newSettings.ObjectBonus = Convert.ToDouble(row["object_bonus"]); | ||
1428 | newSettings.Maturity = Convert.ToInt32(row["maturity"]); | ||
1429 | newSettings.DisableScripts = Convert.ToBoolean(row["disable_scripts"]); | ||
1430 | newSettings.DisableCollisions = Convert.ToBoolean(row["disable_collisions"]); | ||
1431 | newSettings.DisablePhysics = Convert.ToBoolean(row["disable_physics"]); | ||
1432 | newSettings.TerrainTexture1 = new UUID((String) row["terrain_texture_1"]); | ||
1433 | newSettings.TerrainTexture2 = new UUID((String) row["terrain_texture_2"]); | ||
1434 | newSettings.TerrainTexture3 = new UUID((String) row["terrain_texture_3"]); | ||
1435 | newSettings.TerrainTexture4 = new UUID((String) row["terrain_texture_4"]); | ||
1436 | newSettings.Elevation1NW = Convert.ToDouble(row["elevation_1_nw"]); | ||
1437 | newSettings.Elevation2NW = Convert.ToDouble(row["elevation_2_nw"]); | ||
1438 | newSettings.Elevation1NE = Convert.ToDouble(row["elevation_1_ne"]); | ||
1439 | newSettings.Elevation2NE = Convert.ToDouble(row["elevation_2_ne"]); | ||
1440 | newSettings.Elevation1SE = Convert.ToDouble(row["elevation_1_se"]); | ||
1441 | newSettings.Elevation2SE = Convert.ToDouble(row["elevation_2_se"]); | ||
1442 | newSettings.Elevation1SW = Convert.ToDouble(row["elevation_1_sw"]); | ||
1443 | newSettings.Elevation2SW = Convert.ToDouble(row["elevation_2_sw"]); | ||
1444 | newSettings.WaterHeight = Convert.ToDouble(row["water_height"]); | ||
1445 | newSettings.TerrainRaiseLimit = Convert.ToDouble(row["terrain_raise_limit"]); | ||
1446 | newSettings.TerrainLowerLimit = Convert.ToDouble(row["terrain_lower_limit"]); | ||
1447 | newSettings.UseEstateSun = Convert.ToBoolean(row["use_estate_sun"]); | ||
1448 | newSettings.Sandbox = Convert.ToBoolean(row["sandbox"]); | ||
1449 | newSettings.SunVector = new Vector3 ( | ||
1450 | Convert.ToSingle(row["sunvectorx"]), | ||
1451 | Convert.ToSingle(row["sunvectory"]), | ||
1452 | Convert.ToSingle(row["sunvectorz"]) | ||
1453 | ); | ||
1454 | newSettings.FixedSun = Convert.ToBoolean(row["fixed_sun"]); | ||
1455 | newSettings.SunPosition = Convert.ToDouble(row["sun_position"]); | ||
1456 | newSettings.Covenant = new UUID((String) row["covenant"]); | ||
1457 | |||
1458 | return newSettings; | ||
1459 | } | ||
1460 | |||
1461 | /// <summary> | ||
1462 | /// Build a land access entry from the persisted data. | ||
1463 | /// </summary> | ||
1464 | /// <param name="row"></param> | ||
1465 | /// <returns></returns> | ||
1466 | private static ParcelManager.ParcelAccessEntry buildLandAccessData(DataRow row) | ||
1467 | { | ||
1468 | ParcelManager.ParcelAccessEntry entry = new ParcelManager.ParcelAccessEntry(); | ||
1469 | entry.AgentID = new UUID((string) row["AccessUUID"]); | ||
1470 | entry.Flags = (AccessList) row["Flags"]; | ||
1471 | entry.Time = new DateTime(); | ||
1472 | return entry; | ||
1473 | } | ||
1474 | |||
1475 | /// <summary> | ||
1476 | /// | ||
1477 | /// </summary> | ||
1478 | /// <param name="val"></param> | ||
1479 | /// <returns></returns> | ||
1480 | private static Array serializeTerrain(double[,] val) | ||
1481 | { | ||
1482 | MemoryStream str = new MemoryStream(((int)Constants.RegionSize * (int)Constants.RegionSize) *sizeof (double)); | ||
1483 | BinaryWriter bw = new BinaryWriter(str); | ||
1484 | |||
1485 | // TODO: COMPATIBILITY - Add byte-order conversions | ||
1486 | for (int x = 0; x < (int)Constants.RegionSize; x++) | ||
1487 | for (int y = 0; y < (int)Constants.RegionSize; y++) | ||
1488 | bw.Write(val[x, y]); | ||
1489 | |||
1490 | return str.ToArray(); | ||
1491 | } | ||
1492 | |||
1493 | // private void fillTerrainRow(DataRow row, UUID regionUUID, int rev, double[,] val) | ||
1494 | // { | ||
1495 | // row["RegionUUID"] = regionUUID; | ||
1496 | // row["Revision"] = rev; | ||
1497 | |||
1498 | // MemoryStream str = new MemoryStream(((int)Constants.RegionSize * (int)Constants.RegionSize)*sizeof (double)); | ||
1499 | // BinaryWriter bw = new BinaryWriter(str); | ||
1500 | |||
1501 | // // TODO: COMPATIBILITY - Add byte-order conversions | ||
1502 | // for (int x = 0; x < (int)Constants.RegionSize; x++) | ||
1503 | // for (int y = 0; y < (int)Constants.RegionSize; y++) | ||
1504 | // bw.Write(val[x, y]); | ||
1505 | |||
1506 | // row["Heightfield"] = str.ToArray(); | ||
1507 | // } | ||
1508 | |||
1509 | /// <summary> | ||
1510 | /// | ||
1511 | /// </summary> | ||
1512 | /// <param name="row"></param> | ||
1513 | /// <param name="prim"></param> | ||
1514 | /// <param name="sceneGroupID"></param> | ||
1515 | /// <param name="regionUUID"></param> | ||
1516 | private static void fillPrimRow(DataRow row, SceneObjectPart prim, UUID sceneGroupID, UUID regionUUID) | ||
1517 | { | ||
1518 | row["UUID"] = prim.UUID.ToString(); | ||
1519 | row["RegionUUID"] = regionUUID.ToString(); | ||
1520 | row["CreationDate"] = prim.CreationDate; | ||
1521 | row["Name"] = prim.Name; | ||
1522 | row["SceneGroupID"] = sceneGroupID.ToString(); | ||
1523 | // the UUID of the root part for this SceneObjectGroup | ||
1524 | // various text fields | ||
1525 | row["Text"] = prim.Text; | ||
1526 | row["Description"] = prim.Description; | ||
1527 | row["SitName"] = prim.SitName; | ||
1528 | row["TouchName"] = prim.TouchName; | ||
1529 | // permissions | ||
1530 | row["ObjectFlags"] = (uint)prim.Flags; | ||
1531 | row["CreatorID"] = prim.CreatorID.ToString(); | ||
1532 | row["OwnerID"] = prim.OwnerID.ToString(); | ||
1533 | row["GroupID"] = prim.GroupID.ToString(); | ||
1534 | row["LastOwnerID"] = prim.LastOwnerID.ToString(); | ||
1535 | row["OwnerMask"] = prim.OwnerMask; | ||
1536 | row["NextOwnerMask"] = prim.NextOwnerMask; | ||
1537 | row["GroupMask"] = prim.GroupMask; | ||
1538 | row["EveryoneMask"] = prim.EveryoneMask; | ||
1539 | row["BaseMask"] = prim.BaseMask; | ||
1540 | // vectors | ||
1541 | row["PositionX"] = prim.OffsetPosition.X; | ||
1542 | row["PositionY"] = prim.OffsetPosition.Y; | ||
1543 | row["PositionZ"] = prim.OffsetPosition.Z; | ||
1544 | row["GroupPositionX"] = prim.GroupPosition.X; | ||
1545 | row["GroupPositionY"] = prim.GroupPosition.Y; | ||
1546 | row["GroupPositionZ"] = prim.GroupPosition.Z; | ||
1547 | row["VelocityX"] = prim.Velocity.X; | ||
1548 | row["VelocityY"] = prim.Velocity.Y; | ||
1549 | row["VelocityZ"] = prim.Velocity.Z; | ||
1550 | row["AngularVelocityX"] = prim.AngularVelocity.X; | ||
1551 | row["AngularVelocityY"] = prim.AngularVelocity.Y; | ||
1552 | row["AngularVelocityZ"] = prim.AngularVelocity.Z; | ||
1553 | row["AccelerationX"] = prim.Acceleration.X; | ||
1554 | row["AccelerationY"] = prim.Acceleration.Y; | ||
1555 | row["AccelerationZ"] = prim.Acceleration.Z; | ||
1556 | // quaternions | ||
1557 | row["RotationX"] = prim.RotationOffset.X; | ||
1558 | row["RotationY"] = prim.RotationOffset.Y; | ||
1559 | row["RotationZ"] = prim.RotationOffset.Z; | ||
1560 | row["RotationW"] = prim.RotationOffset.W; | ||
1561 | |||
1562 | // Sit target | ||
1563 | Vector3 sitTargetPos = prim.SitTargetPositionLL; | ||
1564 | row["SitTargetOffsetX"] = sitTargetPos.X; | ||
1565 | row["SitTargetOffsetY"] = sitTargetPos.Y; | ||
1566 | row["SitTargetOffsetZ"] = sitTargetPos.Z; | ||
1567 | |||
1568 | Quaternion sitTargetOrient = prim.SitTargetOrientationLL; | ||
1569 | row["SitTargetOrientW"] = sitTargetOrient.W; | ||
1570 | row["SitTargetOrientX"] = sitTargetOrient.X; | ||
1571 | row["SitTargetOrientY"] = sitTargetOrient.Y; | ||
1572 | row["SitTargetOrientZ"] = sitTargetOrient.Z; | ||
1573 | row["ColorR"] = Convert.ToInt32(prim.Color.R); | ||
1574 | row["ColorG"] = Convert.ToInt32(prim.Color.G); | ||
1575 | row["ColorB"] = Convert.ToInt32(prim.Color.B); | ||
1576 | row["ColorA"] = Convert.ToInt32(prim.Color.A); | ||
1577 | row["PayPrice"] = prim.PayPrice[0]; | ||
1578 | row["PayButton1"] = prim.PayPrice[1]; | ||
1579 | row["PayButton2"] = prim.PayPrice[2]; | ||
1580 | row["PayButton3"] = prim.PayPrice[3]; | ||
1581 | row["PayButton4"] = prim.PayPrice[4]; | ||
1582 | |||
1583 | |||
1584 | row["TextureAnimation"] = Convert.ToBase64String(prim.TextureAnimation); | ||
1585 | row["ParticleSystem"] = Convert.ToBase64String(prim.ParticleSystem); | ||
1586 | |||
1587 | row["OmegaX"] = prim.AngularVelocity.X; | ||
1588 | row["OmegaY"] = prim.AngularVelocity.Y; | ||
1589 | row["OmegaZ"] = prim.AngularVelocity.Z; | ||
1590 | |||
1591 | row["CameraEyeOffsetX"] = prim.GetCameraEyeOffset().X; | ||
1592 | row["CameraEyeOffsetY"] = prim.GetCameraEyeOffset().Y; | ||
1593 | row["CameraEyeOffsetZ"] = prim.GetCameraEyeOffset().Z; | ||
1594 | |||
1595 | row["CameraAtOffsetX"] = prim.GetCameraAtOffset().X; | ||
1596 | row["CameraAtOffsetY"] = prim.GetCameraAtOffset().Y; | ||
1597 | row["CameraAtOffsetZ"] = prim.GetCameraAtOffset().Z; | ||
1598 | |||
1599 | |||
1600 | if ((prim.SoundFlags & 1) != 0) // Looped | ||
1601 | { | ||
1602 | row["LoopedSound"] = prim.Sound.ToString(); | ||
1603 | row["LoopedSoundGain"] = prim.SoundGain; | ||
1604 | } | ||
1605 | else | ||
1606 | { | ||
1607 | row["LoopedSound"] = UUID.Zero.ToString(); | ||
1608 | row["LoopedSoundGain"] = 0.0f; | ||
1609 | } | ||
1610 | |||
1611 | if (prim.GetForceMouselook()) | ||
1612 | row["ForceMouselook"] = 1; | ||
1613 | else | ||
1614 | row["ForceMouselook"] = 0; | ||
1615 | |||
1616 | row["ScriptAccessPin"] = prim.ScriptAccessPin; | ||
1617 | |||
1618 | if (prim.AllowedDrop) | ||
1619 | row["AllowedDrop"] = 1; | ||
1620 | else | ||
1621 | row["AllowedDrop"] = 0; | ||
1622 | |||
1623 | if (prim.DIE_AT_EDGE) | ||
1624 | row["DieAtEdge"] = 1; | ||
1625 | else | ||
1626 | row["DieAtEdge"] = 0; | ||
1627 | |||
1628 | row["SalePrice"] = prim.SalePrice; | ||
1629 | row["SaleType"] = Convert.ToInt16(prim.ObjectSaleType); | ||
1630 | |||
1631 | // click action | ||
1632 | row["ClickAction"] = prim.ClickAction; | ||
1633 | |||
1634 | row["SalePrice"] = prim.SalePrice; | ||
1635 | row["Material"] = prim.Material; | ||
1636 | |||
1637 | row["CollisionSound"] = prim.CollisionSound.ToString(); | ||
1638 | row["CollisionSoundVolume"] = prim.CollisionSoundVolume; | ||
1639 | if (prim.VolumeDetectActive) | ||
1640 | row["VolumeDetect"] = 1; | ||
1641 | else | ||
1642 | row["VolumeDetect"] = 0; | ||
1643 | |||
1644 | } | ||
1645 | |||
1646 | /// <summary> | ||
1647 | /// | ||
1648 | /// </summary> | ||
1649 | /// <param name="row"></param> | ||
1650 | /// <param name="taskItem"></param> | ||
1651 | private static void fillItemRow(DataRow row, TaskInventoryItem taskItem) | ||
1652 | { | ||
1653 | row["itemID"] = taskItem.ItemID.ToString(); | ||
1654 | row["primID"] = taskItem.ParentPartID.ToString(); | ||
1655 | row["assetID"] = taskItem.AssetID.ToString(); | ||
1656 | row["parentFolderID"] = taskItem.ParentID.ToString(); | ||
1657 | |||
1658 | row["invType"] = taskItem.InvType; | ||
1659 | row["assetType"] = taskItem.Type; | ||
1660 | |||
1661 | row["name"] = taskItem.Name; | ||
1662 | row["description"] = taskItem.Description; | ||
1663 | row["creationDate"] = taskItem.CreationDate; | ||
1664 | row["creatorID"] = taskItem.CreatorID.ToString(); | ||
1665 | row["ownerID"] = taskItem.OwnerID.ToString(); | ||
1666 | row["lastOwnerID"] = taskItem.LastOwnerID.ToString(); | ||
1667 | row["groupID"] = taskItem.GroupID.ToString(); | ||
1668 | row["nextPermissions"] = taskItem.NextPermissions; | ||
1669 | row["currentPermissions"] = taskItem.CurrentPermissions; | ||
1670 | row["basePermissions"] = taskItem.BasePermissions; | ||
1671 | row["everyonePermissions"] = taskItem.EveryonePermissions; | ||
1672 | row["groupPermissions"] = taskItem.GroupPermissions; | ||
1673 | row["flags"] = taskItem.Flags; | ||
1674 | } | ||
1675 | |||
1676 | /// <summary> | ||
1677 | /// | ||
1678 | /// </summary> | ||
1679 | /// <param name="row"></param> | ||
1680 | /// <param name="land"></param> | ||
1681 | /// <param name="regionUUID"></param> | ||
1682 | private static void fillLandRow(DataRow row, LandData land, UUID regionUUID) | ||
1683 | { | ||
1684 | row["UUID"] = land.GlobalID.ToString(); | ||
1685 | row["RegionUUID"] = regionUUID.ToString(); | ||
1686 | row["LocalLandID"] = land.LocalID; | ||
1687 | |||
1688 | // Bitmap is a byte[512] | ||
1689 | row["Bitmap"] = land.Bitmap; | ||
1690 | |||
1691 | row["Name"] = land.Name; | ||
1692 | row["Desc"] = land.Description; | ||
1693 | row["OwnerUUID"] = land.OwnerID.ToString(); | ||
1694 | row["IsGroupOwned"] = land.IsGroupOwned; | ||
1695 | row["Area"] = land.Area; | ||
1696 | row["AuctionID"] = land.AuctionID; //Unemplemented | ||
1697 | row["Category"] = land.Category; //Enum OpenMetaverse.Parcel.ParcelCategory | ||
1698 | row["ClaimDate"] = land.ClaimDate; | ||
1699 | row["ClaimPrice"] = land.ClaimPrice; | ||
1700 | row["GroupUUID"] = land.GroupID.ToString(); | ||
1701 | row["SalePrice"] = land.SalePrice; | ||
1702 | row["LandStatus"] = land.Status; //Enum. OpenMetaverse.Parcel.ParcelStatus | ||
1703 | row["LandFlags"] = land.Flags; | ||
1704 | row["LandingType"] = land.LandingType; | ||
1705 | row["MediaAutoScale"] = land.MediaAutoScale; | ||
1706 | row["MediaTextureUUID"] = land.MediaID.ToString(); | ||
1707 | row["MediaURL"] = land.MediaURL; | ||
1708 | row["MusicURL"] = land.MusicURL; | ||
1709 | row["PassHours"] = land.PassHours; | ||
1710 | row["PassPrice"] = land.PassPrice; | ||
1711 | row["SnapshotUUID"] = land.SnapshotID.ToString(); | ||
1712 | row["UserLocationX"] = land.UserLocation.X; | ||
1713 | row["UserLocationY"] = land.UserLocation.Y; | ||
1714 | row["UserLocationZ"] = land.UserLocation.Z; | ||
1715 | row["UserLookAtX"] = land.UserLookAt.X; | ||
1716 | row["UserLookAtY"] = land.UserLookAt.Y; | ||
1717 | row["UserLookAtZ"] = land.UserLookAt.Z; | ||
1718 | row["AuthbuyerID"] = land.AuthBuyerID.ToString(); | ||
1719 | row["OtherCleanTime"] = land.OtherCleanTime; | ||
1720 | } | ||
1721 | |||
1722 | /// <summary> | ||
1723 | /// | ||
1724 | /// </summary> | ||
1725 | /// <param name="row"></param> | ||
1726 | /// <param name="entry"></param> | ||
1727 | /// <param name="parcelID"></param> | ||
1728 | private static void fillLandAccessRow(DataRow row, ParcelManager.ParcelAccessEntry entry, UUID parcelID) | ||
1729 | { | ||
1730 | row["LandUUID"] = parcelID.ToString(); | ||
1731 | row["AccessUUID"] = entry.AgentID.ToString(); | ||
1732 | row["Flags"] = entry.Flags; | ||
1733 | } | ||
1734 | |||
1735 | private static void fillRegionSettingsRow(DataRow row, RegionSettings settings) | ||
1736 | { | ||
1737 | row["regionUUID"] = settings.RegionUUID.ToString(); | ||
1738 | row["block_terraform"] = settings.BlockTerraform; | ||
1739 | row["block_fly"] = settings.BlockFly; | ||
1740 | row["allow_damage"] = settings.AllowDamage; | ||
1741 | row["restrict_pushing"] = settings.RestrictPushing; | ||
1742 | row["allow_land_resell"] = settings.AllowLandResell; | ||
1743 | row["allow_land_join_divide"] = settings.AllowLandJoinDivide; | ||
1744 | row["block_show_in_search"] = settings.BlockShowInSearch; | ||
1745 | row["agent_limit"] = settings.AgentLimit; | ||
1746 | row["object_bonus"] = settings.ObjectBonus; | ||
1747 | row["maturity"] = settings.Maturity; | ||
1748 | row["disable_scripts"] = settings.DisableScripts; | ||
1749 | row["disable_collisions"] = settings.DisableCollisions; | ||
1750 | row["disable_physics"] = settings.DisablePhysics; | ||
1751 | row["terrain_texture_1"] = settings.TerrainTexture1.ToString(); | ||
1752 | row["terrain_texture_2"] = settings.TerrainTexture2.ToString(); | ||
1753 | row["terrain_texture_3"] = settings.TerrainTexture3.ToString(); | ||
1754 | row["terrain_texture_4"] = settings.TerrainTexture4.ToString(); | ||
1755 | row["elevation_1_nw"] = settings.Elevation1NW; | ||
1756 | row["elevation_2_nw"] = settings.Elevation2NW; | ||
1757 | row["elevation_1_ne"] = settings.Elevation1NE; | ||
1758 | row["elevation_2_ne"] = settings.Elevation2NE; | ||
1759 | row["elevation_1_se"] = settings.Elevation1SE; | ||
1760 | row["elevation_2_se"] = settings.Elevation2SE; | ||
1761 | row["elevation_1_sw"] = settings.Elevation1SW; | ||
1762 | row["elevation_2_sw"] = settings.Elevation2SW; | ||
1763 | row["water_height"] = settings.WaterHeight; | ||
1764 | row["terrain_raise_limit"] = settings.TerrainRaiseLimit; | ||
1765 | row["terrain_lower_limit"] = settings.TerrainLowerLimit; | ||
1766 | row["use_estate_sun"] = settings.UseEstateSun; | ||
1767 | row["Sandbox"] = settings.Sandbox; // database uses upper case S for sandbox | ||
1768 | row["sunvectorx"] = settings.SunVector.X; | ||
1769 | row["sunvectory"] = settings.SunVector.Y; | ||
1770 | row["sunvectorz"] = settings.SunVector.Z; | ||
1771 | row["fixed_sun"] = settings.FixedSun; | ||
1772 | row["sun_position"] = settings.SunPosition; | ||
1773 | row["covenant"] = settings.Covenant.ToString(); | ||
1774 | } | ||
1775 | |||
1776 | /// <summary> | ||
1777 | /// | ||
1778 | /// </summary> | ||
1779 | /// <param name="row"></param> | ||
1780 | /// <returns></returns> | ||
1781 | private PrimitiveBaseShape buildShape(DataRow row) | ||
1782 | { | ||
1783 | PrimitiveBaseShape s = new PrimitiveBaseShape(); | ||
1784 | s.Scale = new Vector3( | ||
1785 | Convert.ToSingle(row["ScaleX"]), | ||
1786 | Convert.ToSingle(row["ScaleY"]), | ||
1787 | Convert.ToSingle(row["ScaleZ"]) | ||
1788 | ); | ||
1789 | // paths | ||
1790 | s.PCode = Convert.ToByte(row["PCode"]); | ||
1791 | s.PathBegin = Convert.ToUInt16(row["PathBegin"]); | ||
1792 | s.PathEnd = Convert.ToUInt16(row["PathEnd"]); | ||
1793 | s.PathScaleX = Convert.ToByte(row["PathScaleX"]); | ||
1794 | s.PathScaleY = Convert.ToByte(row["PathScaleY"]); | ||
1795 | s.PathShearX = Convert.ToByte(row["PathShearX"]); | ||
1796 | s.PathShearY = Convert.ToByte(row["PathShearY"]); | ||
1797 | s.PathSkew = Convert.ToSByte(row["PathSkew"]); | ||
1798 | s.PathCurve = Convert.ToByte(row["PathCurve"]); | ||
1799 | s.PathRadiusOffset = Convert.ToSByte(row["PathRadiusOffset"]); | ||
1800 | s.PathRevolutions = Convert.ToByte(row["PathRevolutions"]); | ||
1801 | s.PathTaperX = Convert.ToSByte(row["PathTaperX"]); | ||
1802 | s.PathTaperY = Convert.ToSByte(row["PathTaperY"]); | ||
1803 | s.PathTwist = Convert.ToSByte(row["PathTwist"]); | ||
1804 | s.PathTwistBegin = Convert.ToSByte(row["PathTwistBegin"]); | ||
1805 | // profile | ||
1806 | s.ProfileBegin = Convert.ToUInt16(row["ProfileBegin"]); | ||
1807 | s.ProfileEnd = Convert.ToUInt16(row["ProfileEnd"]); | ||
1808 | s.ProfileCurve = Convert.ToByte(row["ProfileCurve"]); | ||
1809 | s.ProfileHollow = Convert.ToUInt16(row["ProfileHollow"]); | ||
1810 | s.State = Convert.ToByte(row["State"]); | ||
1811 | |||
1812 | byte[] textureEntry = (byte[])row["Texture"]; | ||
1813 | s.TextureEntry = textureEntry; | ||
1814 | |||
1815 | s.ExtraParams = (byte[]) row["ExtraParams"]; | ||
1816 | return s; | ||
1817 | } | ||
1818 | |||
1819 | /// <summary> | ||
1820 | /// | ||
1821 | /// </summary> | ||
1822 | /// <param name="row"></param> | ||
1823 | /// <param name="prim"></param> | ||
1824 | private static void fillShapeRow(DataRow row, SceneObjectPart prim) | ||
1825 | { | ||
1826 | PrimitiveBaseShape s = prim.Shape; | ||
1827 | row["UUID"] = prim.UUID.ToString(); | ||
1828 | // shape is an enum | ||
1829 | row["Shape"] = 0; | ||
1830 | // vectors | ||
1831 | row["ScaleX"] = s.Scale.X; | ||
1832 | row["ScaleY"] = s.Scale.Y; | ||
1833 | row["ScaleZ"] = s.Scale.Z; | ||
1834 | // paths | ||
1835 | row["PCode"] = s.PCode; | ||
1836 | row["PathBegin"] = s.PathBegin; | ||
1837 | row["PathEnd"] = s.PathEnd; | ||
1838 | row["PathScaleX"] = s.PathScaleX; | ||
1839 | row["PathScaleY"] = s.PathScaleY; | ||
1840 | row["PathShearX"] = s.PathShearX; | ||
1841 | row["PathShearY"] = s.PathShearY; | ||
1842 | row["PathSkew"] = s.PathSkew; | ||
1843 | row["PathCurve"] = s.PathCurve; | ||
1844 | row["PathRadiusOffset"] = s.PathRadiusOffset; | ||
1845 | row["PathRevolutions"] = s.PathRevolutions; | ||
1846 | row["PathTaperX"] = s.PathTaperX; | ||
1847 | row["PathTaperY"] = s.PathTaperY; | ||
1848 | row["PathTwist"] = s.PathTwist; | ||
1849 | row["PathTwistBegin"] = s.PathTwistBegin; | ||
1850 | // profile | ||
1851 | row["ProfileBegin"] = s.ProfileBegin; | ||
1852 | row["ProfileEnd"] = s.ProfileEnd; | ||
1853 | row["ProfileCurve"] = s.ProfileCurve; | ||
1854 | row["ProfileHollow"] = s.ProfileHollow; | ||
1855 | row["State"] = s.State; | ||
1856 | |||
1857 | row["Texture"] = s.TextureEntry; | ||
1858 | row["ExtraParams"] = s.ExtraParams; | ||
1859 | } | ||
1860 | |||
1861 | /// <summary> | ||
1862 | /// | ||
1863 | /// </summary> | ||
1864 | /// <param name="prim"></param> | ||
1865 | /// <param name="sceneGroupID"></param> | ||
1866 | /// <param name="regionUUID"></param> | ||
1867 | private void addPrim(SceneObjectPart prim, UUID sceneGroupID, UUID regionUUID) | ||
1868 | { | ||
1869 | |||
1870 | DataTable prims = ds.Tables["prims"]; | ||
1871 | DataTable shapes = ds.Tables["primshapes"]; | ||
1872 | |||
1873 | DataRow primRow = prims.Rows.Find(prim.UUID.ToString()); | ||
1874 | if (primRow == null) | ||
1875 | { | ||
1876 | primRow = prims.NewRow(); | ||
1877 | fillPrimRow(primRow, prim, sceneGroupID, regionUUID); | ||
1878 | prims.Rows.Add(primRow); | ||
1879 | } | ||
1880 | else | ||
1881 | { | ||
1882 | fillPrimRow(primRow, prim, sceneGroupID, regionUUID); | ||
1883 | } | ||
1884 | |||
1885 | DataRow shapeRow = shapes.Rows.Find(prim.UUID.ToString()); | ||
1886 | if (shapeRow == null) | ||
1887 | { | ||
1888 | shapeRow = shapes.NewRow(); | ||
1889 | fillShapeRow(shapeRow, prim); | ||
1890 | shapes.Rows.Add(shapeRow); | ||
1891 | } | ||
1892 | else | ||
1893 | { | ||
1894 | fillShapeRow(shapeRow, prim); | ||
1895 | } | ||
1896 | } | ||
1897 | |||
1898 | /// <summary> | ||
1899 | /// </summary> | ||
1900 | /// <param name="primID"></param> | ||
1901 | /// <param name="items"></param> | ||
1902 | public void StorePrimInventory(UUID primID, ICollection<TaskInventoryItem> items) | ||
1903 | { | ||
1904 | m_log.InfoFormat("[REGION DB]: Entered StorePrimInventory with prim ID {0}", primID); | ||
1905 | |||
1906 | DataTable dbItems = ds.Tables["primitems"]; | ||
1907 | |||
1908 | // For now, we're just going to crudely remove all the previous inventory items | ||
1909 | // no matter whether they have changed or not, and replace them with the current set. | ||
1910 | lock (ds) | ||
1911 | { | ||
1912 | RemoveItems(primID); | ||
1913 | |||
1914 | // repalce with current inventory details | ||
1915 | foreach (TaskInventoryItem newItem in items) | ||
1916 | { | ||
1917 | // m_log.InfoFormat( | ||
1918 | // "[DATASTORE]: ", | ||
1919 | // "Adding item {0}, {1} to prim ID {2}", | ||
1920 | // newItem.Name, newItem.ItemID, newItem.ParentPartID); | ||
1921 | |||
1922 | DataRow newItemRow = dbItems.NewRow(); | ||
1923 | fillItemRow(newItemRow, newItem); | ||
1924 | dbItems.Rows.Add(newItemRow); | ||
1925 | } | ||
1926 | } | ||
1927 | |||
1928 | Commit(); | ||
1929 | } | ||
1930 | |||
1931 | /*********************************************************************** | ||
1932 | * | ||
1933 | * SQL Statement Creation Functions | ||
1934 | * | ||
1935 | * These functions create SQL statements for update, insert, and create. | ||
1936 | * They can probably be factored later to have a db independant | ||
1937 | * portion and a db specific portion | ||
1938 | * | ||
1939 | **********************************************************************/ | ||
1940 | |||
1941 | /// <summary> | ||
1942 | /// Create an insert command | ||
1943 | /// </summary> | ||
1944 | /// <param name="table">table name</param> | ||
1945 | /// <param name="dt">data table</param> | ||
1946 | /// <returns>the created command</returns> | ||
1947 | /// <remarks> | ||
1948 | /// This is subtle enough to deserve some commentary. | ||
1949 | /// Instead of doing *lots* and *lots of hardcoded strings | ||
1950 | /// for database definitions we'll use the fact that | ||
1951 | /// realistically all insert statements look like "insert | ||
1952 | /// into A(b, c) values(:b, :c) on the parameterized query | ||
1953 | /// front. If we just have a list of b, c, etc... we can | ||
1954 | /// generate these strings instead of typing them out. | ||
1955 | /// </remarks> | ||
1956 | private static SqliteCommand createInsertCommand(string table, DataTable dt) | ||
1957 | { | ||
1958 | string[] cols = new string[dt.Columns.Count]; | ||
1959 | for (int i = 0; i < dt.Columns.Count; i++) | ||
1960 | { | ||
1961 | DataColumn col = dt.Columns[i]; | ||
1962 | cols[i] = col.ColumnName; | ||
1963 | } | ||
1964 | |||
1965 | string sql = "insert into " + table + "("; | ||
1966 | sql += String.Join(", ", cols); | ||
1967 | // important, the first ':' needs to be here, the rest get added in the join | ||
1968 | sql += ") values (:"; | ||
1969 | sql += String.Join(", :", cols); | ||
1970 | sql += ")"; | ||
1971 | SqliteCommand cmd = new SqliteCommand(sql); | ||
1972 | |||
1973 | // this provides the binding for all our parameters, so | ||
1974 | // much less code than it used to be | ||
1975 | foreach (DataColumn col in dt.Columns) | ||
1976 | { | ||
1977 | cmd.Parameters.Add(createSqliteParameter(col.ColumnName, col.DataType)); | ||
1978 | } | ||
1979 | return cmd; | ||
1980 | } | ||
1981 | |||
1982 | |||
1983 | /// <summary> | ||
1984 | /// create an update command | ||
1985 | /// </summary> | ||
1986 | /// <param name="table">table name</param> | ||
1987 | /// <param name="pk"></param> | ||
1988 | /// <param name="dt"></param> | ||
1989 | /// <returns>the created command</returns> | ||
1990 | private static SqliteCommand createUpdateCommand(string table, string pk, DataTable dt) | ||
1991 | { | ||
1992 | string sql = "update " + table + " set "; | ||
1993 | string subsql = String.Empty; | ||
1994 | foreach (DataColumn col in dt.Columns) | ||
1995 | { | ||
1996 | if (subsql.Length > 0) | ||
1997 | { | ||
1998 | // a map function would rock so much here | ||
1999 | subsql += ", "; | ||
2000 | } | ||
2001 | subsql += col.ColumnName + "= :" + col.ColumnName; | ||
2002 | } | ||
2003 | sql += subsql; | ||
2004 | sql += " where " + pk; | ||
2005 | SqliteCommand cmd = new SqliteCommand(sql); | ||
2006 | |||
2007 | // this provides the binding for all our parameters, so | ||
2008 | // much less code than it used to be | ||
2009 | |||
2010 | foreach (DataColumn col in dt.Columns) | ||
2011 | { | ||
2012 | cmd.Parameters.Add(createSqliteParameter(col.ColumnName, col.DataType)); | ||
2013 | } | ||
2014 | return cmd; | ||
2015 | } | ||
2016 | |||
2017 | /// <summary> | ||
2018 | /// create an update command | ||
2019 | /// </summary> | ||
2020 | /// <param name="table">table name</param> | ||
2021 | /// <param name="pk"></param> | ||
2022 | /// <param name="dt"></param> | ||
2023 | /// <returns>the created command</returns> | ||
2024 | private static SqliteCommand createUpdateCommand(string table, string pk1, string pk2, DataTable dt) | ||
2025 | { | ||
2026 | string sql = "update " + table + " set "; | ||
2027 | string subsql = String.Empty; | ||
2028 | foreach (DataColumn col in dt.Columns) | ||
2029 | { | ||
2030 | if (subsql.Length > 0) | ||
2031 | { | ||
2032 | // a map function would rock so much here | ||
2033 | subsql += ", "; | ||
2034 | } | ||
2035 | subsql += col.ColumnName + "= :" + col.ColumnName; | ||
2036 | } | ||
2037 | sql += subsql; | ||
2038 | sql += " where " + pk1 + " and " + pk2; | ||
2039 | SqliteCommand cmd = new SqliteCommand(sql); | ||
2040 | |||
2041 | // this provides the binding for all our parameters, so | ||
2042 | // much less code than it used to be | ||
2043 | |||
2044 | foreach (DataColumn col in dt.Columns) | ||
2045 | { | ||
2046 | cmd.Parameters.Add(createSqliteParameter(col.ColumnName, col.DataType)); | ||
2047 | } | ||
2048 | return cmd; | ||
2049 | } | ||
2050 | |||
2051 | /// <summary> | ||
2052 | /// | ||
2053 | /// </summary> | ||
2054 | /// <param name="dt">Data Table</param> | ||
2055 | /// <returns></returns> | ||
2056 | // private static string defineTable(DataTable dt) | ||
2057 | // { | ||
2058 | // string sql = "create table " + dt.TableName + "("; | ||
2059 | // string subsql = String.Empty; | ||
2060 | // foreach (DataColumn col in dt.Columns) | ||
2061 | // { | ||
2062 | // if (subsql.Length > 0) | ||
2063 | // { | ||
2064 | // // a map function would rock so much here | ||
2065 | // subsql += ",\n"; | ||
2066 | // } | ||
2067 | // subsql += col.ColumnName + " " + sqliteType(col.DataType); | ||
2068 | // if (dt.PrimaryKey.Length > 0 && col == dt.PrimaryKey[0]) | ||
2069 | // { | ||
2070 | // subsql += " primary key"; | ||
2071 | // } | ||
2072 | // } | ||
2073 | // sql += subsql; | ||
2074 | // sql += ")"; | ||
2075 | // return sql; | ||
2076 | // } | ||
2077 | |||
2078 | /*********************************************************************** | ||
2079 | * | ||
2080 | * Database Binding functions | ||
2081 | * | ||
2082 | * These will be db specific due to typing, and minor differences | ||
2083 | * in databases. | ||
2084 | * | ||
2085 | **********************************************************************/ | ||
2086 | |||
2087 | ///<summary> | ||
2088 | /// This is a convenience function that collapses 5 repetitive | ||
2089 | /// lines for defining SqliteParameters to 2 parameters: | ||
2090 | /// column name and database type. | ||
2091 | /// | ||
2092 | /// It assumes certain conventions like :param as the param | ||
2093 | /// name to replace in parametrized queries, and that source | ||
2094 | /// version is always current version, both of which are fine | ||
2095 | /// for us. | ||
2096 | ///</summary> | ||
2097 | ///<returns>a built sqlite parameter</returns> | ||
2098 | private static SqliteParameter createSqliteParameter(string name, Type type) | ||
2099 | { | ||
2100 | SqliteParameter param = new SqliteParameter(); | ||
2101 | param.ParameterName = ":" + name; | ||
2102 | param.DbType = dbtypeFromType(type); | ||
2103 | param.SourceColumn = name; | ||
2104 | param.SourceVersion = DataRowVersion.Current; | ||
2105 | return param; | ||
2106 | } | ||
2107 | |||
2108 | /// <summary> | ||
2109 | /// | ||
2110 | /// </summary> | ||
2111 | /// <param name="da"></param> | ||
2112 | /// <param name="conn"></param> | ||
2113 | private void setupPrimCommands(SqliteDataAdapter da, SqliteConnection conn) | ||
2114 | { | ||
2115 | da.InsertCommand = createInsertCommand("prims", ds.Tables["prims"]); | ||
2116 | da.InsertCommand.Connection = conn; | ||
2117 | |||
2118 | da.UpdateCommand = createUpdateCommand("prims", "UUID=:UUID", ds.Tables["prims"]); | ||
2119 | da.UpdateCommand.Connection = conn; | ||
2120 | |||
2121 | SqliteCommand delete = new SqliteCommand("delete from prims where UUID = :UUID"); | ||
2122 | delete.Parameters.Add(createSqliteParameter("UUID", typeof (String))); | ||
2123 | delete.Connection = conn; | ||
2124 | da.DeleteCommand = delete; | ||
2125 | } | ||
2126 | |||
2127 | /// <summary> | ||
2128 | /// | ||
2129 | /// </summary> | ||
2130 | /// <param name="da"></param> | ||
2131 | /// <param name="conn"></param> | ||
2132 | private void setupItemsCommands(SqliteDataAdapter da, SqliteConnection conn) | ||
2133 | { | ||
2134 | da.InsertCommand = createInsertCommand("primitems", ds.Tables["primitems"]); | ||
2135 | da.InsertCommand.Connection = conn; | ||
2136 | |||
2137 | da.UpdateCommand = createUpdateCommand("primitems", "itemID = :itemID", ds.Tables["primitems"]); | ||
2138 | da.UpdateCommand.Connection = conn; | ||
2139 | |||
2140 | SqliteCommand delete = new SqliteCommand("delete from primitems where itemID = :itemID"); | ||
2141 | delete.Parameters.Add(createSqliteParameter("itemID", typeof (String))); | ||
2142 | delete.Connection = conn; | ||
2143 | da.DeleteCommand = delete; | ||
2144 | } | ||
2145 | |||
2146 | /// <summary> | ||
2147 | /// | ||
2148 | /// </summary> | ||
2149 | /// <param name="da"></param> | ||
2150 | /// <param name="conn"></param> | ||
2151 | private void setupTerrainCommands(SqliteDataAdapter da, SqliteConnection conn) | ||
2152 | { | ||
2153 | da.InsertCommand = createInsertCommand("terrain", ds.Tables["terrain"]); | ||
2154 | da.InsertCommand.Connection = conn; | ||
2155 | } | ||
2156 | |||
2157 | /// <summary> | ||
2158 | /// | ||
2159 | /// </summary> | ||
2160 | /// <param name="da"></param> | ||
2161 | /// <param name="conn"></param> | ||
2162 | private void setupLandCommands(SqliteDataAdapter da, SqliteConnection conn) | ||
2163 | { | ||
2164 | da.InsertCommand = createInsertCommand("land", ds.Tables["land"]); | ||
2165 | da.InsertCommand.Connection = conn; | ||
2166 | |||
2167 | da.UpdateCommand = createUpdateCommand("land", "UUID=:UUID", ds.Tables["land"]); | ||
2168 | da.UpdateCommand.Connection = conn; | ||
2169 | |||
2170 | SqliteCommand delete = new SqliteCommand("delete from land where UUID=:UUID"); | ||
2171 | delete.Parameters.Add(createSqliteParameter("UUID", typeof(String))); | ||
2172 | da.DeleteCommand = delete; | ||
2173 | da.DeleteCommand.Connection = conn; | ||
2174 | } | ||
2175 | |||
2176 | /// <summary> | ||
2177 | /// | ||
2178 | /// </summary> | ||
2179 | /// <param name="da"></param> | ||
2180 | /// <param name="conn"></param> | ||
2181 | private void setupLandAccessCommands(SqliteDataAdapter da, SqliteConnection conn) | ||
2182 | { | ||
2183 | da.InsertCommand = createInsertCommand("landaccesslist", ds.Tables["landaccesslist"]); | ||
2184 | da.InsertCommand.Connection = conn; | ||
2185 | |||
2186 | da.UpdateCommand = createUpdateCommand("landaccesslist", "LandUUID=:landUUID", "AccessUUID=:AccessUUID", ds.Tables["landaccesslist"]); | ||
2187 | da.UpdateCommand.Connection = conn; | ||
2188 | |||
2189 | SqliteCommand delete = new SqliteCommand("delete from landaccesslist where LandUUID= :LandUUID and AccessUUID= :AccessUUID"); | ||
2190 | delete.Parameters.Add(createSqliteParameter("LandUUID", typeof(String))); | ||
2191 | delete.Parameters.Add(createSqliteParameter("AccessUUID", typeof(String))); | ||
2192 | da.DeleteCommand = delete; | ||
2193 | da.DeleteCommand.Connection = conn; | ||
2194 | |||
2195 | } | ||
2196 | |||
2197 | private void setupRegionSettingsCommands(SqliteDataAdapter da, SqliteConnection conn) | ||
2198 | { | ||
2199 | da.InsertCommand = createInsertCommand("regionsettings", ds.Tables["regionsettings"]); | ||
2200 | da.InsertCommand.Connection = conn; | ||
2201 | da.UpdateCommand = createUpdateCommand("regionsettings", "regionUUID=:regionUUID", ds.Tables["regionsettings"]); | ||
2202 | da.UpdateCommand.Connection = conn; | ||
2203 | } | ||
2204 | |||
2205 | /// <summary> | ||
2206 | /// | ||
2207 | /// </summary> | ||
2208 | /// <param name="da"></param> | ||
2209 | /// <param name="conn"></param> | ||
2210 | private void setupShapeCommands(SqliteDataAdapter da, SqliteConnection conn) | ||
2211 | { | ||
2212 | da.InsertCommand = createInsertCommand("primshapes", ds.Tables["primshapes"]); | ||
2213 | da.InsertCommand.Connection = conn; | ||
2214 | |||
2215 | da.UpdateCommand = createUpdateCommand("primshapes", "UUID=:UUID", ds.Tables["primshapes"]); | ||
2216 | da.UpdateCommand.Connection = conn; | ||
2217 | |||
2218 | SqliteCommand delete = new SqliteCommand("delete from primshapes where UUID = :UUID"); | ||
2219 | delete.Parameters.Add(createSqliteParameter("UUID", typeof (String))); | ||
2220 | delete.Connection = conn; | ||
2221 | da.DeleteCommand = delete; | ||
2222 | } | ||
2223 | |||
2224 | /*********************************************************************** | ||
2225 | * | ||
2226 | * Type conversion functions | ||
2227 | * | ||
2228 | **********************************************************************/ | ||
2229 | |||
2230 | /// <summary> | ||
2231 | /// Type conversion function | ||
2232 | /// </summary> | ||
2233 | /// <param name="type"></param> | ||
2234 | /// <returns></returns> | ||
2235 | private static DbType dbtypeFromType(Type type) | ||
2236 | { | ||
2237 | if (type == typeof (String)) | ||
2238 | { | ||
2239 | return DbType.String; | ||
2240 | } | ||
2241 | else if (type == typeof (Int32)) | ||
2242 | { | ||
2243 | return DbType.Int32; | ||
2244 | } | ||
2245 | else if (type == typeof (Double)) | ||
2246 | { | ||
2247 | return DbType.Double; | ||
2248 | } | ||
2249 | else if (type == typeof (Byte)) | ||
2250 | { | ||
2251 | return DbType.Byte; | ||
2252 | } | ||
2253 | else if (type == typeof (Double)) | ||
2254 | { | ||
2255 | return DbType.Double; | ||
2256 | } | ||
2257 | else if (type == typeof (Byte[])) | ||
2258 | { | ||
2259 | return DbType.Binary; | ||
2260 | } | ||
2261 | else | ||
2262 | { | ||
2263 | return DbType.String; | ||
2264 | } | ||
2265 | } | ||
2266 | |||
2267 | } | ||
2268 | } | ||