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