MSSQLRegionData.cs 74 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550
  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 OpenSim 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. using System;
  28. using System.Collections.Generic;
  29. using System.Data;
  30. using System.Data.SqlClient;
  31. using System.Drawing;
  32. using System.IO;
  33. using System.Reflection;
  34. using OpenMetaverse;
  35. using log4net;
  36. using OpenSim.Framework;
  37. using OpenSim.Region.Environment.Interfaces;
  38. using OpenSim.Region.Environment.Scenes;
  39. namespace OpenSim.Data.MSSQL
  40. {
  41. /// <summary>
  42. /// A MSSQL Interface for the Region Server.
  43. /// </summary>
  44. public class MSSQLRegionDataStore : IRegionDataStore
  45. {
  46. private const string _migrationStore = "RegionStore";
  47. // private static FileSystemDataStore Instance = new FileSystemDataStore();
  48. private static readonly ILog _Log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  49. /// <summary>
  50. /// The database manager
  51. /// </summary>
  52. private MSSQLManager _Database;
  53. /// <summary>
  54. /// Const for the prim store..
  55. /// </summary>
  56. private const string _PrimSelect = "SELECT * FROM PRIMS WHERE RegionUUID = @RegionUUID"; //" AND UUID IN (@UUID)"; //SceneGroupID LIKE @SceneGroupID OR
  57. private const string _ShapeSelect = "SELECT * FROM PRIMSHAPES WHERE UUID in (SELECT UUID FROM PRIMS WHERE RegionUUID = @RegionUUID)"; // AND UUID IN (@UUID))"; //(SceneGroupID LIKE @SceneGroupID OR
  58. private const string _ItemsSelect = "SELECT * FROM PRIMITEMS WHERE primID in (SELECT UUID FROM PRIMS WHERE RegionUUID = @RegionUUID)"; // AND UUID IN (@UUID))"; //(SceneGroupID LIKE @SceneGroupID OR
  59. private DataSet _PrimsDataSet;
  60. private SqlDataAdapter _PrimDataAdapter;
  61. private SqlDataAdapter _ShapeDataAdapter;
  62. private SqlDataAdapter _ItemsDataAdapter;
  63. /// <summary>
  64. /// Initialises the region datastore
  65. /// </summary>
  66. /// <param name="connectionString">The connection string.</param>
  67. public void Initialise(string connectionString)
  68. {
  69. if (!string.IsNullOrEmpty(connectionString))
  70. {
  71. //Add MSSQLManager (dont know if we need it)
  72. _Database = new MSSQLManager(connectionString);
  73. }
  74. else
  75. {
  76. IniFile iniFile = new IniFile("mssql_connection.ini");
  77. string settingDataSource = iniFile.ParseFileReadValue("data_source");
  78. string settingInitialCatalog = iniFile.ParseFileReadValue("initial_catalog");
  79. string settingPersistSecurityInfo = iniFile.ParseFileReadValue("persist_security_info");
  80. string settingUserId = iniFile.ParseFileReadValue("user_id");
  81. string settingPassword = iniFile.ParseFileReadValue("password");
  82. _Database = new MSSQLManager(settingDataSource, settingInitialCatalog, settingPersistSecurityInfo, settingUserId, settingPassword);
  83. }
  84. //Migration settings
  85. _Database.CheckMigration(_migrationStore);
  86. using (SqlConnection connection = _Database.DatabaseConnection())
  87. {
  88. //Create Dataset. Not filled!!!
  89. _PrimsDataSet = new DataSet("primsdata");
  90. using (SqlCommand primSelectCmd = new SqlCommand(_PrimSelect, connection))
  91. {
  92. primSelectCmd.Parameters.AddWithValue("@RegionUUID", "");
  93. _PrimDataAdapter = new SqlDataAdapter(primSelectCmd);
  94. DataTable primDataTable = new DataTable("prims");
  95. _PrimDataAdapter.Fill(primDataTable);
  96. primDataTable.PrimaryKey = new DataColumn[] { primDataTable.Columns["UUID"] };
  97. _PrimsDataSet.Tables.Add(primDataTable);
  98. SetupCommands(_PrimDataAdapter);
  99. primDataTable.Clear();
  100. }
  101. using (SqlCommand shapeSelectCmd = new SqlCommand(_ShapeSelect, connection))
  102. {
  103. shapeSelectCmd.Parameters.AddWithValue("@RegionUUID", "");
  104. _ShapeDataAdapter = new SqlDataAdapter(shapeSelectCmd);
  105. DataTable shapeDataTable = new DataTable("primshapes");
  106. _ShapeDataAdapter.Fill(shapeDataTable);
  107. shapeDataTable.PrimaryKey = new DataColumn[] { shapeDataTable.Columns["UUID"] };
  108. _PrimsDataSet.Tables.Add(shapeDataTable);
  109. SetupCommands(_ShapeDataAdapter);
  110. shapeDataTable.Clear();
  111. }
  112. using (SqlCommand itemSelectCmd = new SqlCommand(_ItemsSelect, connection))
  113. {
  114. itemSelectCmd.Parameters.AddWithValue("@RegionUUID", "");
  115. _ItemsDataAdapter = new SqlDataAdapter(itemSelectCmd);
  116. DataTable itemsDataTable = new DataTable("primitems");
  117. _ItemsDataAdapter.Fill(itemsDataTable);
  118. itemsDataTable.PrimaryKey = new DataColumn[] { itemsDataTable.Columns["itemID"] };
  119. _PrimsDataSet.Tables.Add(itemsDataTable);
  120. SetupCommands(_ItemsDataAdapter);
  121. itemsDataTable.Clear();
  122. }
  123. connection.Close();
  124. }
  125. //After this we have a empty fully configured DataSet.
  126. }
  127. /// <summary>
  128. /// Dispose the database
  129. /// </summary>
  130. public void Dispose() { }
  131. /// <summary>
  132. /// Loads the objects present in the region.
  133. /// </summary>
  134. /// <param name="regionUUID">The region UUID.</param>
  135. /// <returns></returns>
  136. public List<SceneObjectGroup> LoadObjects(UUID regionUUID)
  137. {
  138. Dictionary<UUID, SceneObjectGroup> createdObjects = new Dictionary<UUID, SceneObjectGroup>();
  139. //Retrieve all values of current region
  140. RetrievePrimsDataForRegion(regionUUID, UUID.Zero, "");
  141. List<SceneObjectGroup> retvals = new List<SceneObjectGroup>();
  142. DataTable prims = _PrimsDataSet.Tables["prims"];
  143. DataTable shapes = _PrimsDataSet.Tables["primshapes"];
  144. lock (_PrimsDataSet)
  145. {
  146. DataRow[] primsForRegion = prims.Select("", "ParentID ASC"); //.Select(byRegion, orderByParent);
  147. _Log.Info("[REGION DB]: " + "Loaded " + primsForRegion.Length + " prims for region: " + regionUUID);
  148. foreach (DataRow primRow in primsForRegion)
  149. {
  150. try
  151. {
  152. string uuid = (string)primRow["UUID"];
  153. string objID = (string)primRow["SceneGroupID"];
  154. SceneObjectPart prim = buildPrim(primRow);
  155. if (uuid == objID) //is new SceneObjectGroup ?
  156. {
  157. SceneObjectGroup group = new SceneObjectGroup();
  158. DataRow shapeRow = shapes.Rows.Find(prim.UUID.ToString());
  159. if (shapeRow != null)
  160. {
  161. prim.Shape = buildShape(shapeRow);
  162. }
  163. else
  164. {
  165. _Log.Info(
  166. "No shape found for prim in storage, so setting default box shape");
  167. prim.Shape = PrimitiveBaseShape.Default;
  168. }
  169. group.SetRootPart(prim);
  170. createdObjects.Add(group.UUID, group);
  171. retvals.Add(group);
  172. }
  173. else
  174. {
  175. DataRow shapeRow = shapes.Rows.Find(prim.UUID.ToString());
  176. if (shapeRow != null)
  177. {
  178. prim.Shape = buildShape(shapeRow);
  179. }
  180. else
  181. {
  182. _Log.Info(
  183. "No shape found for prim in storage, so setting default box shape");
  184. prim.Shape = PrimitiveBaseShape.Default;
  185. }
  186. createdObjects[new UUID(objID)].AddPart(prim);
  187. }
  188. LoadItems(prim);
  189. }
  190. catch (Exception e)
  191. {
  192. _Log.Error("[REGION DB]: Failed create prim object, exception and data follows");
  193. _Log.Info("[REGION DB]: " + e.Message);
  194. foreach (DataColumn col in prims.Columns)
  195. {
  196. _Log.Info("[REGION DB]: Col: " + col.ColumnName + " => " + primRow[col]);
  197. }
  198. }
  199. }
  200. _PrimsDataSet.Tables["prims"].Clear();
  201. _PrimsDataSet.Tables["primshapes"].Clear();
  202. _PrimsDataSet.Tables["primitems"].Clear();
  203. }
  204. return retvals;
  205. #region Experimental
  206. //
  207. // //Get all prims
  208. // string sql = "select * from prims where RegionUUID = @RegionUUID";
  209. //
  210. // using (AutoClosingSqlCommand cmdPrims = _Database.Query(sql))
  211. // {
  212. // cmdPrims.Parameters.AddWithValue("@RegionUUID", regionUUID.ToString());
  213. // using (SqlDataReader readerPrims = cmdPrims.ExecuteReader())
  214. // {
  215. // while (readerPrims.Read())
  216. // {
  217. // string uuid = (string)readerPrims["UUID"];
  218. // string objID = (string)readerPrims["SceneGroupID"];
  219. // SceneObjectPart prim = buildPrim(readerPrims);
  220. //
  221. // //Setting default shape, will change shape ltr
  222. // prim.Shape = PrimitiveBaseShape.Default;
  223. //
  224. // //Load inventory items of prim
  225. // //LoadItems(prim);
  226. //
  227. // if (uuid == objID)
  228. // {
  229. // SceneObjectGroup group = new SceneObjectGroup();
  230. //
  231. // group.AddPart(prim);
  232. // group.RootPart = prim;
  233. //
  234. // createdObjects.Add(group.UUID, group);
  235. // retvals.Add(group);
  236. // }
  237. // else
  238. // {
  239. // createdObjects[new UUID(objID)].AddPart(prim);
  240. // }
  241. // }
  242. // }
  243. // }
  244. // m_log.Info("[REGION DB]: Loaded " + retvals.Count + " prim objects for region: " + regionUUID);
  245. //
  246. // //Find all shapes related with prims
  247. // sql = "select * from primshapes";
  248. // using (AutoClosingSqlCommand cmdShapes = _Database.Query(sql))
  249. // {
  250. // using (SqlDataReader readerShapes = cmdShapes.ExecuteReader())
  251. // {
  252. // while (readerShapes.Read())
  253. // {
  254. // UUID UUID = new UUID((string) readerShapes["UUID"]);
  255. //
  256. // foreach (SceneObjectGroup objectGroup in createdObjects.Values)
  257. // {
  258. // if (objectGroup.Children.ContainsKey(UUID))
  259. // {
  260. // objectGroup.Children[UUID].Shape = buildShape(readerShapes);
  261. // }
  262. // }
  263. // }
  264. // }
  265. // }
  266. // return retvals;
  267. #endregion
  268. }
  269. /// <summary>
  270. /// Stores all object's details apart from inventory
  271. /// </summary>
  272. /// <param name="obj"></param>
  273. /// <param name="regionUUID"></param>
  274. public void StoreObject(SceneObjectGroup obj, UUID regionUUID)
  275. {
  276. //Retrieve all values of current region, and current scene/or prims
  277. //Build primID's, we use IN so I can select all prims from objgroup
  278. string primID = "";
  279. lock (_Database)
  280. {
  281. RetrievePrimsDataForRegion(regionUUID, obj.UUID, primID);
  282. _Log.InfoFormat("[REGION DB]: Adding/Changing SceneObjectGroup: {0} to region: {1}, object has {2} prims.", obj.UUID, regionUUID, obj.Children.Count);
  283. DataTable prims = _PrimsDataSet.Tables["prims"];
  284. DataTable shapes = _PrimsDataSet.Tables["primshapes"];
  285. foreach (SceneObjectPart prim in obj.Children.Values)
  286. {
  287. if ((prim.GetEffectiveObjectFlags() & (uint)PrimFlags.Temporary) == 0
  288. && (prim.GetEffectiveObjectFlags() & (uint)PrimFlags.TemporaryOnRez) == 0)
  289. {
  290. DataRow primRow = prims.Rows.Find(prim.UUID.ToString());
  291. if (primRow == null)
  292. {
  293. primRow = prims.NewRow();
  294. fillPrimRow(primRow, prim, obj.UUID, regionUUID);
  295. prims.Rows.Add(primRow);
  296. }
  297. else
  298. {
  299. fillPrimRow(primRow, prim, obj.UUID, regionUUID);
  300. }
  301. DataRow shapeRow = shapes.Rows.Find(prim.UUID.ToString());
  302. if (shapeRow == null)
  303. {
  304. shapeRow = shapes.NewRow();
  305. fillShapeRow(shapeRow, prim);
  306. shapes.Rows.Add(shapeRow);
  307. }
  308. else
  309. {
  310. fillShapeRow(shapeRow, prim);
  311. }
  312. }
  313. }
  314. //Save changes
  315. CommitDataSet();
  316. }
  317. }
  318. /// <summary>
  319. /// Removes a object from the database.
  320. /// Meaning removing it from tables Prims, PrimShapes and PrimItems
  321. /// </summary>
  322. /// <param name="objectID">id of scenegroup</param>
  323. /// <param name="regionUUID">regionUUID (is this used anyway</param>
  324. public void RemoveObject(UUID objectID, UUID regionUUID)
  325. {
  326. _Log.InfoFormat("[REGION DB]: Removing obj: {0} from region: {1}", objectID, regionUUID);
  327. //Remove from prims and primsitem table
  328. string sqlPrims = string.Format("DELETE FROM PRIMS WHERE SceneGroupID = '{0}'", objectID);
  329. string sqlPrimItems = string.Format("DELETE FROM PRIMITEMS WHERE primID in (SELECT UUID FROM PRIMS WHERE SceneGroupID = '{0}')", objectID);
  330. string sqlPrimShapes = string.Format("DELETE FROM PRIMSHAPES WHERE uuid in (SELECT UUID FROM PRIMS WHERE SceneGroupID = '{0}')", objectID);
  331. lock (_Database)
  332. {
  333. //Using the non transaction mode.
  334. using (AutoClosingSqlCommand cmd = _Database.Query(sqlPrimShapes))
  335. {
  336. cmd.ExecuteNonQuery();
  337. cmd.CommandText = sqlPrimItems;
  338. cmd.ExecuteNonQuery();
  339. cmd.CommandText = sqlPrims;
  340. cmd.ExecuteNonQuery();
  341. }
  342. }
  343. }
  344. /// <summary>
  345. /// Store the inventory of a prim. Warning deletes everything first and then adds all again.
  346. /// </summary>
  347. /// <param name="primID"></param>
  348. /// <param name="items"></param>
  349. public void StorePrimInventory(UUID primID, ICollection<TaskInventoryItem> items)
  350. {
  351. //_Log.InfoFormat("[REGION DB]: Persisting Prim Inventory with prim ID {0}", primID);
  352. //Statement from MySQL section!
  353. // For now, we're just going to crudely remove all the previous inventory items
  354. // no matter whether they have changed or not, and replace them with the current set.
  355. //Delete everything from PrimID
  356. //TODO add index on PrimID in DB, if not already exist
  357. using (AutoClosingSqlCommand cmd = _Database.Query("DELETE PRIMITEMS WHERE primID = @primID"))
  358. {
  359. cmd.Parameters.Add(_Database.CreateParameter("@primID", primID));
  360. cmd.ExecuteNonQuery();
  361. }
  362. string sql =
  363. "INSERT INTO [primitems] ([itemID],[primID],[assetID],[parentFolderID],[invType],[assetType],[name],[description],[creationDate],[creatorID],[ownerID],[lastOwnerID],[groupID],[nextPermissions],[currentPermissions],[basePermissions],[everyonePermissions],[groupPermissions],[flags]) VALUES (@itemID,@primID,@assetID,@parentFolderID,@invType,@assetType,@name,@description,@creationDate,@creatorID,@ownerID,@lastOwnerID,@groupID,@nextPermissions,@currentPermissions,@basePermissions,@everyonePermissions,@groupPermissions,@flags)";
  364. using (AutoClosingSqlCommand cmd = _Database.Query(sql))
  365. {
  366. foreach (TaskInventoryItem taskItem in items)
  367. {
  368. cmd.Parameters.AddRange(CreatePrimInventoryParameters(taskItem));
  369. cmd.ExecuteNonQuery();
  370. cmd.Parameters.Clear();
  371. }
  372. }
  373. }
  374. /// <summary>
  375. /// Loads the terrain map.
  376. /// </summary>
  377. /// <param name="regionID">regionID.</param>
  378. /// <returns></returns>
  379. public double[,] LoadTerrain(UUID regionID)
  380. {
  381. double[,] terrain = new double[256, 256];
  382. terrain.Initialize();
  383. string sql = "select top 1 RegionUUID, Revision, Heightfield from terrain where RegionUUID = @RegionUUID order by Revision desc";
  384. using (AutoClosingSqlCommand cmd = _Database.Query(sql))
  385. {
  386. // MySqlParameter param = new MySqlParameter();
  387. cmd.Parameters.AddWithValue("@RegionUUID", regionID.ToString());
  388. using (SqlDataReader reader = cmd.ExecuteReader())
  389. {
  390. int rev;
  391. if (reader.Read())
  392. {
  393. MemoryStream str = new MemoryStream((byte[])reader["Heightfield"]);
  394. BinaryReader br = new BinaryReader(str);
  395. for (int x = 0; x < 256; x++)
  396. {
  397. for (int y = 0; y < 256; y++)
  398. {
  399. terrain[x, y] = br.ReadDouble();
  400. }
  401. }
  402. rev = (int)reader["Revision"];
  403. }
  404. else
  405. {
  406. _Log.Info("[REGION DB]: No terrain found for region");
  407. return null;
  408. }
  409. _Log.Info("[REGION DB]: Loaded terrain revision r" + rev);
  410. }
  411. }
  412. return terrain;
  413. }
  414. /// <summary>
  415. /// Stores the terrain map to DB.
  416. /// </summary>
  417. /// <param name="terrain">terrain map data.</param>
  418. /// <param name="regionID">regionID.</param>
  419. public void StoreTerrain(double[,] terrain, UUID regionID)
  420. {
  421. int revision = Util.UnixTimeSinceEpoch();
  422. //Delete old terrain map
  423. string sql = "delete from terrain where RegionUUID=@RegionUUID";
  424. using (AutoClosingSqlCommand cmd = _Database.Query(sql))
  425. {
  426. cmd.Parameters.Add(_Database.CreateParameter("@RegionUUID", regionID));
  427. cmd.ExecuteNonQuery();
  428. }
  429. sql = "insert into terrain(RegionUUID, Revision, Heightfield) values(@RegionUUID, @Revision, @Heightfield)";
  430. using (AutoClosingSqlCommand cmd = _Database.Query(sql))
  431. {
  432. cmd.Parameters.Add(_Database.CreateParameter("@RegionUUID", regionID));
  433. cmd.Parameters.Add(_Database.CreateParameter("@Revision", revision));
  434. cmd.Parameters.Add(_Database.CreateParameter("@Heightfield", serializeTerrain(terrain)));
  435. cmd.ExecuteNonQuery();
  436. }
  437. _Log.Info("[REGION DB]: Stored terrain revision r " + revision);
  438. }
  439. /// <summary>
  440. /// Loads all the land objects of a region.
  441. /// </summary>
  442. /// <param name="regionUUID">The region UUID.</param>
  443. /// <returns></returns>
  444. public List<LandData> LoadLandObjects(UUID regionUUID)
  445. {
  446. List<LandData> landDataForRegion = new List<LandData>();
  447. string sql = "select * from land where RegionUUID = @RegionUUID";
  448. //Retrieve all land data from region
  449. using (AutoClosingSqlCommand cmdLandData = _Database.Query(sql))
  450. {
  451. cmdLandData.Parameters.Add(_Database.CreateParameter("@RegionUUID", regionUUID));
  452. using (SqlDataReader readerLandData = cmdLandData.ExecuteReader())
  453. {
  454. while (readerLandData.Read())
  455. {
  456. landDataForRegion.Add(buildLandData(readerLandData));
  457. }
  458. }
  459. }
  460. //Retrieve all accesslist data for all landdata
  461. foreach (LandData landData in landDataForRegion)
  462. {
  463. sql = "select * from landaccesslist where LandUUID = @LandUUID";
  464. using (AutoClosingSqlCommand cmdAccessList = _Database.Query(sql))
  465. {
  466. cmdAccessList.Parameters.Add(_Database.CreateParameter("@LandUUID", landData.GlobalID));
  467. using (SqlDataReader readerAccessList = cmdAccessList.ExecuteReader())
  468. {
  469. while (readerAccessList.Read())
  470. {
  471. landData.ParcelAccessList.Add(buildLandAccessData(readerAccessList));
  472. }
  473. }
  474. }
  475. }
  476. //Return data
  477. return landDataForRegion;
  478. }
  479. /// <summary>
  480. /// Stores land object with landaccess list.
  481. /// </summary>
  482. /// <param name="parcel">parcel data.</param>
  483. public void StoreLandObject(ILandObject parcel)
  484. {
  485. //As this is only one record in land table I just delete all and then add a new record.
  486. //As the delete landaccess is already in the mysql code
  487. //Delete old values
  488. RemoveLandObject(parcel.landData.GlobalID);
  489. //Insert new values
  490. string sql = @"INSERT INTO [land]
  491. ([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])
  492. VALUES
  493. (@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)";
  494. using (AutoClosingSqlCommand cmd = _Database.Query(sql))
  495. {
  496. cmd.Parameters.AddRange(CreateLandParameters(parcel.landData, parcel.regionUUID));
  497. cmd.ExecuteNonQuery();
  498. }
  499. sql = "INSERT INTO [landaccesslist] ([LandUUID],[AccessUUID],[Flags]) VALUES (@LandUUID,@AccessUUID,@Flags)";
  500. using (AutoClosingSqlCommand cmd = _Database.Query(sql))
  501. {
  502. foreach (ParcelManager.ParcelAccessEntry parcelAccessEntry in parcel.landData.ParcelAccessList)
  503. {
  504. cmd.Parameters.AddRange(CreateLandAccessParameters(parcelAccessEntry, parcel.regionUUID));
  505. cmd.ExecuteNonQuery();
  506. cmd.Parameters.Clear();
  507. }
  508. }
  509. }
  510. /// <summary>
  511. /// Removes a land object from DB.
  512. /// </summary>
  513. /// <param name="globalID">UUID of landobject</param>
  514. public void RemoveLandObject(UUID globalID)
  515. {
  516. using (AutoClosingSqlCommand cmd = _Database.Query("delete from land where UUID=@UUID"))
  517. {
  518. cmd.Parameters.Add(_Database.CreateParameter("@UUID", globalID));
  519. cmd.ExecuteNonQuery();
  520. }
  521. using (AutoClosingSqlCommand cmd = _Database.Query("delete from landaccesslist where LandUUID=@UUID"))
  522. {
  523. cmd.Parameters.Add(_Database.CreateParameter("@UUID", globalID));
  524. cmd.ExecuteNonQuery();
  525. }
  526. }
  527. /// <summary>
  528. /// Loads the settings of a region.
  529. /// </summary>
  530. /// <param name="regionUUID">The region UUID.</param>
  531. /// <returns></returns>
  532. public RegionSettings LoadRegionSettings(UUID regionUUID)
  533. {
  534. string sql = "select * from regionsettings where regionUUID = @regionUUID";
  535. RegionSettings regionSettings;
  536. using (AutoClosingSqlCommand cmd = _Database.Query(sql))
  537. {
  538. cmd.Parameters.Add(_Database.CreateParameter("@regionUUID", regionUUID));
  539. using (SqlDataReader reader = cmd.ExecuteReader())
  540. {
  541. if (reader.Read())
  542. {
  543. regionSettings = buildRegionSettings(reader);
  544. regionSettings.OnSave += StoreRegionSettings;
  545. return regionSettings;
  546. }
  547. }
  548. }
  549. //If comes here then there is now region setting for that region
  550. regionSettings = new RegionSettings();
  551. regionSettings.RegionUUID = regionUUID;
  552. regionSettings.OnSave += StoreRegionSettings;
  553. //Store new values
  554. StoreNewRegionSettings(regionSettings);
  555. return regionSettings;
  556. }
  557. /// <summary>
  558. /// Store region settings, need to check if the check is really necesary. If we can make something for creating new region.
  559. /// </summary>
  560. /// <param name="regionSettings">region settings.</param>
  561. public void StoreRegionSettings(RegionSettings regionSettings)
  562. {
  563. //Little check if regionUUID already exist in DB
  564. string regionUUID;
  565. using (AutoClosingSqlCommand cmd = _Database.Query("SELECT regionUUID FROM regionsettings WHERE regionUUID = @regionUUID"))
  566. {
  567. cmd.Parameters.Add(_Database.CreateParameter("@regionUUID", regionSettings.RegionUUID));
  568. regionUUID = cmd.ExecuteScalar().ToString();
  569. }
  570. if (string.IsNullOrEmpty(regionUUID))
  571. {
  572. StoreNewRegionSettings(regionSettings);
  573. }
  574. else
  575. {
  576. //This method only updates region settings!!! First call LoadRegionSettings to create new region settings in DB
  577. string sql =
  578. @"UPDATE [regionsettings] SET [block_terraform] = @block_terraform ,[block_fly] = @block_fly ,[allow_damage] = @allow_damage
  579. ,[restrict_pushing] = @restrict_pushing ,[allow_land_resell] = @allow_land_resell ,[allow_land_join_divide] = @allow_land_join_divide
  580. ,[block_show_in_search] = @block_show_in_search ,[agent_limit] = @agent_limit ,[object_bonus] = @object_bonus ,[maturity] = @maturity
  581. ,[disable_scripts] = @disable_scripts ,[disable_collisions] = @disable_collisions ,[disable_physics] = @disable_physics
  582. ,[terrain_texture_1] = @terrain_texture_1 ,[terrain_texture_2] = @terrain_texture_2 ,[terrain_texture_3] = @terrain_texture_3
  583. ,[terrain_texture_4] = @terrain_texture_4 ,[elevation_1_nw] = @elevation_1_nw ,[elevation_2_nw] = @elevation_2_nw
  584. ,[elevation_1_ne] = @elevation_1_ne ,[elevation_2_ne] = @elevation_2_ne ,[elevation_1_se] = @elevation_1_se ,[elevation_2_se] = @elevation_2_se
  585. ,[elevation_1_sw] = @elevation_1_sw ,[elevation_2_sw] = @elevation_2_sw ,[water_height] = @water_height ,[terrain_raise_limit] = @terrain_raise_limit
  586. ,[terrain_lower_limit] = @terrain_lower_limit ,[use_estate_sun] = @use_estate_sun ,[fixed_sun] = @fixed_sun ,[sun_position] = @sun_position
  587. ,[covenant] = @covenant , [sunvectorx] = @sunvectorx, [sunvectory] = @sunvectory, [sunvectorz] = @sunvectorz, [Sandbox] = @Sandbox WHERE [regionUUID] = @regionUUID";
  588. using (AutoClosingSqlCommand cmd = _Database.Query(sql))
  589. {
  590. cmd.Parameters.AddRange(CreateRegionSettingParameters(regionSettings));
  591. cmd.ExecuteNonQuery();
  592. }
  593. }
  594. }
  595. public void Shutdown()
  596. {
  597. //Not used??
  598. }
  599. #region Private Methods
  600. /// <summary>
  601. /// Load in a prim's persisted inventory.
  602. /// </summary>
  603. /// <param name="prim">The prim</param>
  604. private void LoadItems(SceneObjectPart prim)
  605. {
  606. DataTable dbItems = _PrimsDataSet.Tables["primitems"];
  607. String sql = String.Format("primID = '{0}'", prim.UUID);
  608. DataRow[] dbItemRows = dbItems.Select(sql);
  609. IList<TaskInventoryItem> inventory = new List<TaskInventoryItem>();
  610. foreach (DataRow row in dbItemRows)
  611. {
  612. TaskInventoryItem item = buildItem(row);
  613. inventory.Add(item);
  614. //m_log.DebugFormat("[DATASTORE]: Restored item {0}, {1}", item.Name, item.ItemID);
  615. }
  616. prim.Inventory.RestoreInventoryItems(inventory);
  617. // XXX A nasty little hack to recover the folder id for the prim (which is currently stored in
  618. // every item). This data should really be stored in the prim table itself.
  619. if (dbItemRows.Length > 0)
  620. {
  621. prim.FolderID = inventory[0].ParentID;
  622. }
  623. }
  624. /// <summary>
  625. /// Serializes the terrain data for storage in DB.
  626. /// </summary>
  627. /// <param name="val">terrain data</param>
  628. /// <returns></returns>
  629. private static Array serializeTerrain(double[,] val)
  630. {
  631. MemoryStream str = new MemoryStream(65536 * sizeof(double));
  632. BinaryWriter bw = new BinaryWriter(str);
  633. // TODO: COMPATIBILITY - Add byte-order conversions
  634. for (int x = 0; x < 256; x++)
  635. for (int y = 0; y < 256; y++)
  636. {
  637. double height = val[x, y];
  638. if (height == 0.0)
  639. height = double.Epsilon;
  640. bw.Write(height);
  641. }
  642. return str.ToArray();
  643. }
  644. /// <summary>
  645. /// Stores new regionsettings.
  646. /// </summary>
  647. /// <param name="regionSettings">The region settings.</param>
  648. private void StoreNewRegionSettings(RegionSettings regionSettings)
  649. {
  650. string sql = @"INSERT INTO [regionsettings]
  651. ([regionUUID],[block_terraform],[block_fly],[allow_damage],[restrict_pushing],[allow_land_resell],[allow_land_join_divide],
  652. [block_show_in_search],[agent_limit],[object_bonus],[maturity],[disable_scripts],[disable_collisions],[disable_physics],
  653. [terrain_texture_1],[terrain_texture_2],[terrain_texture_3],[terrain_texture_4],[elevation_1_nw],[elevation_2_nw],[elevation_1_ne],
  654. [elevation_2_ne],[elevation_1_se],[elevation_2_se],[elevation_1_sw],[elevation_2_sw],[water_height],[terrain_raise_limit],
  655. [terrain_lower_limit],[use_estate_sun],[fixed_sun],[sun_position],[covenant],[sunvectorx], [sunvectory], [sunvectorz],[Sandbox])
  656. VALUES
  657. (@regionUUID,@block_terraform,@block_fly,@allow_damage,@restrict_pushing,@allow_land_resell,@allow_land_join_divide,
  658. @block_show_in_search,@agent_limit,@object_bonus,@maturity,@disable_scripts,@disable_collisions,@disable_physics,
  659. @terrain_texture_1,@terrain_texture_2,@terrain_texture_3,@terrain_texture_4,@elevation_1_nw,@elevation_2_nw,@elevation_1_ne,
  660. @elevation_2_ne,@elevation_1_se,@elevation_2_se,@elevation_1_sw,@elevation_2_sw,@water_height,@terrain_raise_limit,
  661. @terrain_lower_limit,@use_estate_sun,@fixed_sun,@sun_position,@covenant,@sunvectorx,@sunvectory, @sunvectorz, @Sandbox)";
  662. using (AutoClosingSqlCommand cmd = _Database.Query(sql))
  663. {
  664. cmd.Parameters.AddRange(CreateRegionSettingParameters(regionSettings));
  665. cmd.ExecuteNonQuery();
  666. }
  667. }
  668. #region Private DataRecord conversion methods
  669. /// <summary>
  670. /// Builds the region settings from a datarecod.
  671. /// </summary>
  672. /// <param name="row">datarecord with regionsettings.</param>
  673. /// <returns></returns>
  674. private static RegionSettings buildRegionSettings(IDataRecord row)
  675. {
  676. //TODO change this is some more generic code so we doesnt have to change it every time a new field is added?
  677. RegionSettings newSettings = new RegionSettings();
  678. newSettings.RegionUUID = new UUID((string)row["regionUUID"]);
  679. newSettings.BlockTerraform = Convert.ToBoolean(row["block_terraform"]);
  680. newSettings.AllowDamage = Convert.ToBoolean(row["allow_damage"]);
  681. newSettings.BlockFly = Convert.ToBoolean(row["block_fly"]);
  682. newSettings.RestrictPushing = Convert.ToBoolean(row["restrict_pushing"]);
  683. newSettings.AllowLandResell = Convert.ToBoolean(row["allow_land_resell"]);
  684. newSettings.AllowLandJoinDivide = Convert.ToBoolean(row["allow_land_join_divide"]);
  685. newSettings.BlockShowInSearch = Convert.ToBoolean(row["block_show_in_search"]);
  686. newSettings.AgentLimit = Convert.ToInt32(row["agent_limit"]);
  687. newSettings.ObjectBonus = Convert.ToDouble(row["object_bonus"]);
  688. newSettings.Maturity = Convert.ToInt32(row["maturity"]);
  689. newSettings.DisableScripts = Convert.ToBoolean(row["disable_scripts"]);
  690. newSettings.DisableCollisions = Convert.ToBoolean(row["disable_collisions"]);
  691. newSettings.DisablePhysics = Convert.ToBoolean(row["disable_physics"]);
  692. newSettings.TerrainTexture1 = new UUID((String)row["terrain_texture_1"]);
  693. newSettings.TerrainTexture2 = new UUID((String)row["terrain_texture_2"]);
  694. newSettings.TerrainTexture3 = new UUID((String)row["terrain_texture_3"]);
  695. newSettings.TerrainTexture4 = new UUID((String)row["terrain_texture_4"]);
  696. newSettings.Elevation1NW = Convert.ToDouble(row["elevation_1_nw"]);
  697. newSettings.Elevation2NW = Convert.ToDouble(row["elevation_2_nw"]);
  698. newSettings.Elevation1NE = Convert.ToDouble(row["elevation_1_ne"]);
  699. newSettings.Elevation2NE = Convert.ToDouble(row["elevation_2_ne"]);
  700. newSettings.Elevation1SE = Convert.ToDouble(row["elevation_1_se"]);
  701. newSettings.Elevation2SE = Convert.ToDouble(row["elevation_2_se"]);
  702. newSettings.Elevation1SW = Convert.ToDouble(row["elevation_1_sw"]);
  703. newSettings.Elevation2SW = Convert.ToDouble(row["elevation_2_sw"]);
  704. newSettings.WaterHeight = Convert.ToDouble(row["water_height"]);
  705. newSettings.TerrainRaiseLimit = Convert.ToDouble(row["terrain_raise_limit"]);
  706. newSettings.TerrainLowerLimit = Convert.ToDouble(row["terrain_lower_limit"]);
  707. newSettings.UseEstateSun = Convert.ToBoolean(row["use_estate_sun"]);
  708. newSettings.Sandbox = Convert.ToBoolean(row["sandbox"]);
  709. newSettings.FixedSun = Convert.ToBoolean(row["fixed_sun"]);
  710. newSettings.SunPosition = Convert.ToDouble(row["sun_position"]);
  711. newSettings.SunVector = new Vector3(
  712. Convert.ToSingle(row["sunvectorx"]),
  713. Convert.ToSingle(row["sunvectory"]),
  714. Convert.ToSingle(row["sunvectorz"])
  715. );
  716. newSettings.Covenant = new UUID((String)row["covenant"]);
  717. return newSettings;
  718. }
  719. /// <summary>
  720. /// Builds the land data from a datarecord.
  721. /// </summary>
  722. /// <param name="row">datarecord with land data</param>
  723. /// <returns></returns>
  724. private static LandData buildLandData(IDataRecord row)
  725. {
  726. LandData newData = new LandData();
  727. newData.GlobalID = new UUID((String)row["UUID"]);
  728. newData.LocalID = Convert.ToInt32(row["LocalLandID"]);
  729. // Bitmap is a byte[512]
  730. newData.Bitmap = (Byte[])row["Bitmap"];
  731. newData.Name = (String)row["Name"];
  732. newData.Description = (String)row["Description"];
  733. newData.OwnerID = (UUID)(String)row["OwnerUUID"];
  734. newData.IsGroupOwned = Convert.ToBoolean(row["IsGroupOwned"]);
  735. newData.Area = Convert.ToInt32(row["Area"]);
  736. newData.AuctionID = Convert.ToUInt32(row["AuctionID"]); //Unemplemented
  737. newData.Category = (Parcel.ParcelCategory)Convert.ToInt32(row["Category"]);
  738. //Enum libsecondlife.Parcel.ParcelCategory
  739. newData.ClaimDate = Convert.ToInt32(row["ClaimDate"]);
  740. newData.ClaimPrice = Convert.ToInt32(row["ClaimPrice"]);
  741. newData.GroupID = new UUID((String)row["GroupUUID"]);
  742. newData.SalePrice = Convert.ToInt32(row["SalePrice"]);
  743. newData.Status = (Parcel.ParcelStatus)Convert.ToInt32(row["LandStatus"]);
  744. //Enum. libsecondlife.Parcel.ParcelStatus
  745. newData.Flags = Convert.ToUInt32(row["LandFlags"]);
  746. newData.LandingType = Convert.ToByte(row["LandingType"]);
  747. newData.MediaAutoScale = Convert.ToByte(row["MediaAutoScale"]);
  748. newData.MediaID = new UUID((String)row["MediaTextureUUID"]);
  749. newData.MediaURL = (String)row["MediaURL"];
  750. newData.MusicURL = (String)row["MusicURL"];
  751. newData.PassHours = Convert.ToSingle(row["PassHours"]);
  752. newData.PassPrice = Convert.ToInt32(row["PassPrice"]);
  753. UUID authedbuyer;
  754. UUID snapshotID;
  755. if (UUID.TryParse((string)row["AuthBuyerID"], out authedbuyer))
  756. newData.AuthBuyerID = authedbuyer;
  757. if (UUID.TryParse((string)row["SnapshotUUID"], out snapshotID))
  758. newData.SnapshotID = snapshotID;
  759. newData.OtherCleanTime = Convert.ToInt32(row["OtherCleanTime"]);
  760. newData.Dwell = Convert.ToInt32(row["Dwell"]);
  761. try
  762. {
  763. newData.UserLocation =
  764. new Vector3(Convert.ToSingle(row["UserLocationX"]), Convert.ToSingle(row["UserLocationY"]),
  765. Convert.ToSingle(row["UserLocationZ"]));
  766. newData.UserLookAt =
  767. new Vector3(Convert.ToSingle(row["UserLookAtX"]), Convert.ToSingle(row["UserLookAtY"]),
  768. Convert.ToSingle(row["UserLookAtZ"]));
  769. }
  770. catch (InvalidCastException)
  771. {
  772. newData.UserLocation = Vector3.Zero;
  773. newData.UserLookAt = Vector3.Zero;
  774. _Log.ErrorFormat("[PARCEL]: unable to get parcel telehub settings for {1}", newData.Name);
  775. }
  776. newData.ParcelAccessList = new List<ParcelManager.ParcelAccessEntry>();
  777. return newData;
  778. }
  779. /// <summary>
  780. /// Builds the landaccess data from a data record.
  781. /// </summary>
  782. /// <param name="row">datarecord with landaccess data</param>
  783. /// <returns></returns>
  784. private static ParcelManager.ParcelAccessEntry buildLandAccessData(IDataRecord row)
  785. {
  786. ParcelManager.ParcelAccessEntry entry = new ParcelManager.ParcelAccessEntry();
  787. entry.AgentID = new UUID((string)row["AccessUUID"]);
  788. entry.Flags = (AccessList)Convert.ToInt32(row["Flags"]);
  789. entry.Time = new DateTime();
  790. return entry;
  791. }
  792. /// <summary>
  793. /// Builds the prim from a datarecord.
  794. /// </summary>
  795. /// <param name="primRow">datarecord</param>
  796. /// <returns></returns>
  797. private static SceneObjectPart buildPrim(DataRow primRow)
  798. {
  799. SceneObjectPart prim = new SceneObjectPart();
  800. prim.UUID = new UUID((String)primRow["UUID"]);
  801. // explicit conversion of integers is required, which sort
  802. // of sucks. No idea if there is a shortcut here or not.
  803. prim.ParentID = (uint)Convert.ToInt32(primRow["ParentID"]);
  804. prim.CreationDate = Convert.ToInt32(primRow["CreationDate"]);
  805. prim.Name = (String)primRow["Name"];
  806. // various text fields
  807. prim.Text = (String)primRow["Text"];
  808. prim.Color = Color.FromArgb(Convert.ToInt32(primRow["ColorA"]),
  809. Convert.ToInt32(primRow["ColorR"]),
  810. Convert.ToInt32(primRow["ColorG"]),
  811. Convert.ToInt32(primRow["ColorB"]));
  812. prim.Description = (String)primRow["Description"];
  813. prim.SitName = (String)primRow["SitName"];
  814. prim.TouchName = (String)primRow["TouchName"];
  815. // permissions
  816. prim.ObjectFlags = Convert.ToUInt32(primRow["ObjectFlags"]);
  817. prim.CreatorID = new UUID((String)primRow["CreatorID"]);
  818. prim.OwnerID = new UUID((String)primRow["OwnerID"]);
  819. prim.GroupID = new UUID((String)primRow["GroupID"]);
  820. prim.LastOwnerID = new UUID((String)primRow["LastOwnerID"]);
  821. prim.OwnerMask = Convert.ToUInt32(primRow["OwnerMask"]);
  822. prim.NextOwnerMask = Convert.ToUInt32(primRow["NextOwnerMask"]);
  823. prim.GroupMask = Convert.ToUInt32(primRow["GroupMask"]);
  824. prim.EveryoneMask = Convert.ToUInt32(primRow["EveryoneMask"]);
  825. prim.BaseMask = Convert.ToUInt32(primRow["BaseMask"]);
  826. // vectors
  827. prim.OffsetPosition = new Vector3(
  828. Convert.ToSingle(primRow["PositionX"]),
  829. Convert.ToSingle(primRow["PositionY"]),
  830. Convert.ToSingle(primRow["PositionZ"]));
  831. prim.GroupPosition = new Vector3(
  832. Convert.ToSingle(primRow["GroupPositionX"]),
  833. Convert.ToSingle(primRow["GroupPositionY"]),
  834. Convert.ToSingle(primRow["GroupPositionZ"]));
  835. prim.Velocity = new Vector3(
  836. Convert.ToSingle(primRow["VelocityX"]),
  837. Convert.ToSingle(primRow["VelocityY"]),
  838. Convert.ToSingle(primRow["VelocityZ"]));
  839. prim.AngularVelocity = new Vector3(
  840. Convert.ToSingle(primRow["AngularVelocityX"]),
  841. Convert.ToSingle(primRow["AngularVelocityY"]),
  842. Convert.ToSingle(primRow["AngularVelocityZ"]));
  843. prim.Acceleration = new Vector3(
  844. Convert.ToSingle(primRow["AccelerationX"]),
  845. Convert.ToSingle(primRow["AccelerationY"]),
  846. Convert.ToSingle(primRow["AccelerationZ"]));
  847. // quaternions
  848. prim.RotationOffset = new Quaternion(
  849. Convert.ToSingle(primRow["RotationX"]),
  850. Convert.ToSingle(primRow["RotationY"]),
  851. Convert.ToSingle(primRow["RotationZ"]),
  852. Convert.ToSingle(primRow["RotationW"]));
  853. prim.SitTargetPositionLL = new Vector3(
  854. Convert.ToSingle(primRow["SitTargetOffsetX"]),
  855. Convert.ToSingle(primRow["SitTargetOffsetY"]),
  856. Convert.ToSingle(primRow["SitTargetOffsetZ"]));
  857. prim.SitTargetOrientationLL = new Quaternion(
  858. Convert.ToSingle(primRow["SitTargetOrientX"]),
  859. Convert.ToSingle(primRow["SitTargetOrientY"]),
  860. Convert.ToSingle(primRow["SitTargetOrientZ"]),
  861. Convert.ToSingle(primRow["SitTargetOrientW"]));
  862. prim.PayPrice[0] = Convert.ToInt32(primRow["PayPrice"]);
  863. prim.PayPrice[1] = Convert.ToInt32(primRow["PayButton1"]);
  864. prim.PayPrice[2] = Convert.ToInt32(primRow["PayButton2"]);
  865. prim.PayPrice[3] = Convert.ToInt32(primRow["PayButton3"]);
  866. prim.PayPrice[4] = Convert.ToInt32(primRow["PayButton4"]);
  867. prim.Sound = new UUID(primRow["LoopedSound"].ToString());
  868. prim.SoundGain = Convert.ToSingle(primRow["LoopedSoundGain"]);
  869. prim.SoundFlags = 1; // If it's persisted at all, it's looped
  870. if (!primRow.IsNull("TextureAnimation") && primRow["TextureAnimation"] != DBNull.Value)
  871. prim.TextureAnimation = (Byte[])primRow["TextureAnimation"];
  872. if (!primRow.IsNull("ParticleSystem"))
  873. prim.ParticleSystem = (Byte[])primRow["ParticleSystem"];
  874. prim.RotationalVelocity = new Vector3(
  875. Convert.ToSingle(primRow["OmegaX"]),
  876. Convert.ToSingle(primRow["OmegaY"]),
  877. Convert.ToSingle(primRow["OmegaZ"]));
  878. prim.SetCameraEyeOffset(new Vector3(
  879. Convert.ToSingle(primRow["CameraEyeOffsetX"]),
  880. Convert.ToSingle(primRow["CameraEyeOffsetY"]),
  881. Convert.ToSingle(primRow["CameraEyeOffsetZ"])
  882. ));
  883. prim.SetCameraAtOffset(new Vector3(
  884. Convert.ToSingle(primRow["CameraAtOffsetX"]),
  885. Convert.ToSingle(primRow["CameraAtOffsetY"]),
  886. Convert.ToSingle(primRow["CameraAtOffsetZ"])
  887. ));
  888. if (Convert.ToInt16(primRow["ForceMouselook"]) != 0)
  889. prim.SetForceMouselook(true);
  890. prim.ScriptAccessPin = Convert.ToInt32(primRow["ScriptAccessPin"]);
  891. if (Convert.ToInt16(primRow["AllowedDrop"]) != 0)
  892. prim.AllowedDrop = true;
  893. if (Convert.ToInt16(primRow["DieAtEdge"]) != 0)
  894. prim.DIE_AT_EDGE = true;
  895. prim.SalePrice = Convert.ToInt32(primRow["SalePrice"]);
  896. prim.ObjectSaleType = Convert.ToByte(primRow["SaleType"]);
  897. prim.Material = Convert.ToByte(primRow["Material"]);
  898. if (!primRow.IsNull("ClickAction"))
  899. prim.ClickAction = Convert.ToByte(primRow["ClickAction"]);
  900. prim.CollisionSound = new UUID(primRow["CollisionSound"].ToString());
  901. prim.CollisionSoundVolume = Convert.ToSingle(primRow["CollisionSoundVolume"]);
  902. return prim;
  903. }
  904. /// <summary>
  905. /// Builds the prim shape from a datarecord.
  906. /// </summary>
  907. /// <param name="row">The row.</param>
  908. /// <returns></returns>
  909. private static PrimitiveBaseShape buildShape(DataRow row)
  910. {
  911. PrimitiveBaseShape s = new PrimitiveBaseShape();
  912. s.Scale = new Vector3(
  913. Convert.ToSingle(row["ScaleX"]),
  914. Convert.ToSingle(row["ScaleY"]),
  915. Convert.ToSingle(row["ScaleZ"]));
  916. // paths
  917. s.PCode = Convert.ToByte(row["PCode"]);
  918. s.PathBegin = Convert.ToUInt16(row["PathBegin"]);
  919. s.PathEnd = Convert.ToUInt16(row["PathEnd"]);
  920. s.PathScaleX = Convert.ToByte(row["PathScaleX"]);
  921. s.PathScaleY = Convert.ToByte(row["PathScaleY"]);
  922. s.PathShearX = Convert.ToByte(row["PathShearX"]);
  923. s.PathShearY = Convert.ToByte(row["PathShearY"]);
  924. s.PathSkew = Convert.ToSByte(row["PathSkew"]);
  925. s.PathCurve = Convert.ToByte(row["PathCurve"]);
  926. s.PathRadiusOffset = Convert.ToSByte(row["PathRadiusOffset"]);
  927. s.PathRevolutions = Convert.ToByte(row["PathRevolutions"]);
  928. s.PathTaperX = Convert.ToSByte(row["PathTaperX"]);
  929. s.PathTaperY = Convert.ToSByte(row["PathTaperY"]);
  930. s.PathTwist = Convert.ToSByte(row["PathTwist"]);
  931. s.PathTwistBegin = Convert.ToSByte(row["PathTwistBegin"]);
  932. // profile
  933. s.ProfileBegin = Convert.ToUInt16(row["ProfileBegin"]);
  934. s.ProfileEnd = Convert.ToUInt16(row["ProfileEnd"]);
  935. s.ProfileCurve = Convert.ToByte(row["ProfileCurve"]);
  936. s.ProfileHollow = Convert.ToUInt16(row["ProfileHollow"]);
  937. byte[] textureEntry = (byte[])row["Texture"];
  938. s.TextureEntry = textureEntry;
  939. s.ExtraParams = (byte[])row["ExtraParams"];
  940. try
  941. {
  942. s.State = Convert.ToByte(row["State"]);
  943. }
  944. catch (InvalidCastException)
  945. {
  946. }
  947. return s;
  948. }
  949. /// <summary>
  950. /// Build a prim inventory item from the persisted data.
  951. /// </summary>
  952. /// <param name="row"></param>
  953. /// <returns></returns>
  954. private static TaskInventoryItem buildItem(DataRow row)
  955. {
  956. TaskInventoryItem taskItem = new TaskInventoryItem();
  957. taskItem.ItemID = new UUID((String)row["itemID"]);
  958. taskItem.ParentPartID = new UUID((String)row["primID"]);
  959. taskItem.AssetID = new UUID((String)row["assetID"]);
  960. taskItem.ParentID = new UUID((String)row["parentFolderID"]);
  961. taskItem.InvType = Convert.ToInt32(row["invType"]);
  962. taskItem.Type = Convert.ToInt32(row["assetType"]);
  963. taskItem.Name = (String)row["name"];
  964. taskItem.Description = (String)row["description"];
  965. taskItem.CreationDate = Convert.ToUInt32(row["creationDate"]);
  966. taskItem.CreatorID = new UUID((String)row["creatorID"]);
  967. taskItem.OwnerID = new UUID((String)row["ownerID"]);
  968. taskItem.LastOwnerID = new UUID((String)row["lastOwnerID"]);
  969. taskItem.GroupID = new UUID((String)row["groupID"]);
  970. taskItem.NextPermissions = Convert.ToUInt32(row["nextPermissions"]);
  971. taskItem.CurrentPermissions = Convert.ToUInt32(row["currentPermissions"]);
  972. taskItem.BasePermissions = Convert.ToUInt32(row["basePermissions"]);
  973. taskItem.EveryonePermissions = Convert.ToUInt32(row["everyonePermissions"]);
  974. taskItem.GroupPermissions = Convert.ToUInt32(row["groupPermissions"]);
  975. taskItem.Flags = Convert.ToUInt32(row["flags"]);
  976. return taskItem;
  977. }
  978. #endregion
  979. #region Create parameters methods
  980. /// <summary>
  981. /// Creates the prim inventory parameters.
  982. /// </summary>
  983. /// <param name="taskItem">item in inventory.</param>
  984. /// <returns></returns>
  985. private SqlParameter[] CreatePrimInventoryParameters(TaskInventoryItem taskItem)
  986. {
  987. SqlParameter[] parameters = new SqlParameter[19];
  988. parameters[0] = _Database.CreateParameter("itemID", taskItem.ItemID);
  989. parameters[1] = _Database.CreateParameter("primID", taskItem.ParentPartID);
  990. parameters[2] = _Database.CreateParameter("assetID", taskItem.AssetID);
  991. parameters[3] = _Database.CreateParameter("parentFolderID", taskItem.ParentID);
  992. parameters[4] = _Database.CreateParameter("invType", taskItem.InvType);
  993. parameters[5] = _Database.CreateParameter("assetType", taskItem.Type);
  994. parameters[6] = _Database.CreateParameter("name", taskItem.Name);
  995. parameters[7] = _Database.CreateParameter("description", taskItem.Description);
  996. parameters[8] = _Database.CreateParameter("creationDate", taskItem.CreationDate);
  997. parameters[9] = _Database.CreateParameter("creatorID", taskItem.CreatorID);
  998. parameters[10] = _Database.CreateParameter("ownerID", taskItem.OwnerID);
  999. parameters[11] = _Database.CreateParameter("lastOwnerID", taskItem.LastOwnerID);
  1000. parameters[12] = _Database.CreateParameter("groupID", taskItem.GroupID);
  1001. parameters[13] = _Database.CreateParameter("nextPermissions", taskItem.NextPermissions);
  1002. parameters[14] = _Database.CreateParameter("currentPermissions", taskItem.CurrentPermissions);
  1003. parameters[15] = _Database.CreateParameter("basePermissions", taskItem.BasePermissions);
  1004. parameters[16] = _Database.CreateParameter("everyonePermissions", taskItem.EveryonePermissions);
  1005. parameters[17] = _Database.CreateParameter("groupPermissions", taskItem.GroupPermissions);
  1006. parameters[18] = _Database.CreateParameter("flags", taskItem.Flags);
  1007. return parameters;
  1008. }
  1009. /// <summary>
  1010. /// Creates the region setting parameters.
  1011. /// </summary>
  1012. /// <param name="settings">regionsettings.</param>
  1013. /// <returns></returns>
  1014. private SqlParameter[] CreateRegionSettingParameters(RegionSettings settings)
  1015. {
  1016. SqlParameter[] parameters = new SqlParameter[37];
  1017. parameters[0] = _Database.CreateParameter("regionUUID", settings.RegionUUID);
  1018. parameters[1] = _Database.CreateParameter("block_terraform", settings.BlockTerraform);
  1019. parameters[2] = _Database.CreateParameter("block_fly", settings.BlockFly);
  1020. parameters[3] = _Database.CreateParameter("allow_damage", settings.AllowDamage);
  1021. parameters[4] = _Database.CreateParameter("restrict_pushing", settings.RestrictPushing);
  1022. parameters[5] = _Database.CreateParameter("allow_land_resell", settings.AllowLandResell);
  1023. parameters[6] = _Database.CreateParameter("allow_land_join_divide", settings.AllowLandJoinDivide);
  1024. parameters[7] = _Database.CreateParameter("block_show_in_search", settings.BlockShowInSearch);
  1025. parameters[8] = _Database.CreateParameter("agent_limit", settings.AgentLimit);
  1026. parameters[9] = _Database.CreateParameter("object_bonus", settings.ObjectBonus);
  1027. parameters[10] = _Database.CreateParameter("maturity", settings.Maturity);
  1028. parameters[11] = _Database.CreateParameter("disable_scripts", settings.DisableScripts);
  1029. parameters[12] = _Database.CreateParameter("disable_collisions", settings.DisableCollisions);
  1030. parameters[13] = _Database.CreateParameter("disable_physics", settings.DisablePhysics);
  1031. parameters[14] = _Database.CreateParameter("terrain_texture_1", settings.TerrainTexture1);
  1032. parameters[15] = _Database.CreateParameter("terrain_texture_2", settings.TerrainTexture2);
  1033. parameters[16] = _Database.CreateParameter("terrain_texture_3", settings.TerrainTexture3);
  1034. parameters[17] = _Database.CreateParameter("terrain_texture_4", settings.TerrainTexture4);
  1035. parameters[18] = _Database.CreateParameter("elevation_1_nw", settings.Elevation1NW);
  1036. parameters[19] = _Database.CreateParameter("elevation_2_nw", settings.Elevation2NW);
  1037. parameters[20] = _Database.CreateParameter("elevation_1_ne", settings.Elevation1NE);
  1038. parameters[21] = _Database.CreateParameter("elevation_2_ne", settings.Elevation2NE);
  1039. parameters[22] = _Database.CreateParameter("elevation_1_se", settings.Elevation1SE);
  1040. parameters[23] = _Database.CreateParameter("elevation_2_se", settings.Elevation2SE);
  1041. parameters[24] = _Database.CreateParameter("elevation_1_sw", settings.Elevation1SW);
  1042. parameters[25] = _Database.CreateParameter("elevation_2_sw", settings.Elevation2SW);
  1043. parameters[26] = _Database.CreateParameter("water_height", settings.WaterHeight);
  1044. parameters[27] = _Database.CreateParameter("terrain_raise_limit", settings.TerrainRaiseLimit);
  1045. parameters[28] = _Database.CreateParameter("terrain_lower_limit", settings.TerrainLowerLimit);
  1046. parameters[29] = _Database.CreateParameter("use_estate_sun", settings.UseEstateSun);
  1047. parameters[30] = _Database.CreateParameter("sandbox", settings.Sandbox);
  1048. parameters[31] = _Database.CreateParameter("fixed_sun", settings.FixedSun);
  1049. parameters[32] = _Database.CreateParameter("sun_position", settings.SunPosition);
  1050. parameters[33] = _Database.CreateParameter("sunvectorx", settings.SunVector.X);
  1051. parameters[34] = _Database.CreateParameter("sunvectory", settings.SunVector.Y);
  1052. parameters[35] = _Database.CreateParameter("sunvectorz", settings.SunVector.Z);
  1053. parameters[36] = _Database.CreateParameter("covenant", settings.Covenant);
  1054. return parameters;
  1055. }
  1056. /// <summary>
  1057. /// Creates the land parameters.
  1058. /// </summary>
  1059. /// <param name="land">land parameters.</param>
  1060. /// <param name="regionUUID">region UUID.</param>
  1061. /// <returns></returns>
  1062. private SqlParameter[] CreateLandParameters(LandData land, UUID regionUUID)
  1063. {
  1064. SqlParameter[] parameters = new SqlParameter[34];
  1065. parameters[0] = _Database.CreateParameter("UUID", land.GlobalID);
  1066. parameters[1] = _Database.CreateParameter("RegionUUID", regionUUID);
  1067. parameters[2] = _Database.CreateParameter("LocalLandID", land.LocalID);
  1068. // Bitmap is a byte[512]
  1069. parameters[3] = _Database.CreateParameter("Bitmap", land.Bitmap);
  1070. parameters[4] = _Database.CreateParameter("Name", land.Name);
  1071. parameters[5] = _Database.CreateParameter("Description", land.Description);
  1072. parameters[6] = _Database.CreateParameter("OwnerUUID", land.OwnerID);
  1073. parameters[7] = _Database.CreateParameter("IsGroupOwned", land.IsGroupOwned);
  1074. parameters[8] = _Database.CreateParameter("Area", land.Area);
  1075. parameters[9] = _Database.CreateParameter("AuctionID", land.AuctionID); //Unemplemented
  1076. parameters[10] = _Database.CreateParameter("Category", (int)land.Category); //Enum libsecondlife.Parcel.ParcelCategory
  1077. parameters[11] = _Database.CreateParameter("ClaimDate", land.ClaimDate);
  1078. parameters[12] = _Database.CreateParameter("ClaimPrice", land.ClaimPrice);
  1079. parameters[13] = _Database.CreateParameter("GroupUUID", land.GroupID);
  1080. parameters[14] = _Database.CreateParameter("SalePrice", land.SalePrice);
  1081. parameters[15] = _Database.CreateParameter("LandStatus", (int)land.Status); //Enum. libsecondlife.Parcel.ParcelStatus
  1082. parameters[16] = _Database.CreateParameter("LandFlags", land.Flags);
  1083. parameters[17] = _Database.CreateParameter("LandingType", land.LandingType);
  1084. parameters[18] = _Database.CreateParameter("MediaAutoScale", land.MediaAutoScale);
  1085. parameters[19] = _Database.CreateParameter("MediaTextureUUID", land.MediaID);
  1086. parameters[20] = _Database.CreateParameter("MediaURL", land.MediaURL);
  1087. parameters[21] = _Database.CreateParameter("MusicURL", land.MusicURL);
  1088. parameters[22] = _Database.CreateParameter("PassHours", land.PassHours);
  1089. parameters[23] = _Database.CreateParameter("PassPrice", land.PassPrice);
  1090. parameters[24] = _Database.CreateParameter("SnapshotUUID", land.SnapshotID);
  1091. parameters[25] = _Database.CreateParameter("UserLocationX", land.UserLocation.X);
  1092. parameters[26] = _Database.CreateParameter("UserLocationY", land.UserLocation.Y);
  1093. parameters[27] = _Database.CreateParameter("UserLocationZ", land.UserLocation.Z);
  1094. parameters[28] = _Database.CreateParameter("UserLookAtX", land.UserLookAt.X);
  1095. parameters[29] = _Database.CreateParameter("UserLookAtY", land.UserLookAt.Y);
  1096. parameters[30] = _Database.CreateParameter("UserLookAtZ", land.UserLookAt.Z);
  1097. parameters[31] = _Database.CreateParameter("AuthBuyerID", land.AuthBuyerID);
  1098. parameters[32] = _Database.CreateParameter("OtherCleanTime", land.OtherCleanTime);
  1099. parameters[33] = _Database.CreateParameter("Dwell", land.Dwell);
  1100. return parameters;
  1101. }
  1102. /// <summary>
  1103. /// Creates the land access parameters.
  1104. /// </summary>
  1105. /// <param name="parcelAccessEntry">parcel access entry.</param>
  1106. /// <param name="parcelID">parcel ID.</param>
  1107. /// <returns></returns>
  1108. private SqlParameter[] CreateLandAccessParameters(ParcelManager.ParcelAccessEntry parcelAccessEntry, UUID parcelID)
  1109. {
  1110. SqlParameter[] parameters = new SqlParameter[3];
  1111. parameters[0] = _Database.CreateParameter("LandUUID", parcelID);
  1112. parameters[1] = _Database.CreateParameter("AccessUUID", parcelAccessEntry.AgentID);
  1113. parameters[2] = _Database.CreateParameter("Flags", parcelAccessEntry.Flags);
  1114. return parameters;
  1115. }
  1116. /// <summary>
  1117. /// <summary>
  1118. /// Fills/Updates the prim datarow.
  1119. /// </summary>
  1120. /// <param name="row">datarow.</param>
  1121. /// <param name="prim">prim data.</param>
  1122. /// <param name="sceneGroupID">scenegroup ID.</param>
  1123. /// <param name="regionUUID">regionUUID.</param>
  1124. private static void fillPrimRow(DataRow row, SceneObjectPart prim, UUID sceneGroupID, UUID regionUUID)
  1125. {
  1126. row["UUID"] = prim.UUID.ToString();
  1127. row["RegionUUID"] = regionUUID.ToString();
  1128. row["ParentID"] = (int)prim.ParentID;
  1129. row["CreationDate"] = prim.CreationDate;
  1130. row["Name"] = prim.Name;
  1131. row["SceneGroupID"] = sceneGroupID.ToString();
  1132. // the UUID of the root part for this SceneObjectGroup
  1133. // various text fields
  1134. row["Text"] = prim.Text;
  1135. row["ColorR"] = prim.Color.R;
  1136. row["ColorG"] = prim.Color.G;
  1137. row["ColorB"] = prim.Color.B;
  1138. row["ColorA"] = prim.Color.A;
  1139. row["Description"] = prim.Description;
  1140. row["SitName"] = prim.SitName;
  1141. row["TouchName"] = prim.TouchName;
  1142. // permissions
  1143. row["ObjectFlags"] = prim.ObjectFlags;
  1144. row["CreatorID"] = prim.CreatorID.ToString();
  1145. row["OwnerID"] = prim.OwnerID.ToString();
  1146. row["GroupID"] = prim.GroupID.ToString();
  1147. row["LastOwnerID"] = prim.LastOwnerID.ToString();
  1148. row["OwnerMask"] = prim.OwnerMask;
  1149. row["NextOwnerMask"] = prim.NextOwnerMask;
  1150. row["GroupMask"] = prim.GroupMask;
  1151. row["EveryoneMask"] = prim.EveryoneMask;
  1152. row["BaseMask"] = prim.BaseMask;
  1153. // vectors
  1154. row["PositionX"] = prim.OffsetPosition.X;
  1155. row["PositionY"] = prim.OffsetPosition.Y;
  1156. row["PositionZ"] = prim.OffsetPosition.Z;
  1157. row["GroupPositionX"] = prim.GroupPosition.X;
  1158. row["GroupPositionY"] = prim.GroupPosition.Y;
  1159. row["GroupPositionZ"] = prim.GroupPosition.Z;
  1160. row["VelocityX"] = prim.Velocity.X;
  1161. row["VelocityY"] = prim.Velocity.Y;
  1162. row["VelocityZ"] = prim.Velocity.Z;
  1163. row["AngularVelocityX"] = prim.AngularVelocity.X;
  1164. row["AngularVelocityY"] = prim.AngularVelocity.Y;
  1165. row["AngularVelocityZ"] = prim.AngularVelocity.Z;
  1166. row["AccelerationX"] = prim.Acceleration.X;
  1167. row["AccelerationY"] = prim.Acceleration.Y;
  1168. row["AccelerationZ"] = prim.Acceleration.Z;
  1169. // quaternions
  1170. row["RotationX"] = prim.RotationOffset.X;
  1171. row["RotationY"] = prim.RotationOffset.Y;
  1172. row["RotationZ"] = prim.RotationOffset.Z;
  1173. row["RotationW"] = prim.RotationOffset.W;
  1174. // Sit target
  1175. Vector3 sitTargetPos = prim.SitTargetPositionLL;
  1176. row["SitTargetOffsetX"] = sitTargetPos.X;
  1177. row["SitTargetOffsetY"] = sitTargetPos.Y;
  1178. row["SitTargetOffsetZ"] = sitTargetPos.Z;
  1179. Quaternion sitTargetOrient = prim.SitTargetOrientationLL;
  1180. row["SitTargetOrientW"] = sitTargetOrient.W;
  1181. row["SitTargetOrientX"] = sitTargetOrient.X;
  1182. row["SitTargetOrientY"] = sitTargetOrient.Y;
  1183. row["SitTargetOrientZ"] = sitTargetOrient.Z;
  1184. row["PayPrice"] = prim.PayPrice[0];
  1185. row["PayButton1"] = prim.PayPrice[1];
  1186. row["PayButton2"] = prim.PayPrice[2];
  1187. row["PayButton3"] = prim.PayPrice[3];
  1188. row["PayButton4"] = prim.PayPrice[4];
  1189. if ((prim.SoundFlags & 1) != 0) // Looped
  1190. {
  1191. row["LoopedSound"] = prim.Sound.ToString();
  1192. row["LoopedSoundGain"] = prim.SoundGain;
  1193. }
  1194. else
  1195. {
  1196. row["LoopedSound"] = UUID.Zero;
  1197. row["LoopedSoundGain"] = 0.0f;
  1198. }
  1199. row["TextureAnimation"] = prim.TextureAnimation;
  1200. row["ParticleSystem"] = prim.ParticleSystem;
  1201. row["OmegaX"] = prim.RotationalVelocity.X;
  1202. row["OmegaY"] = prim.RotationalVelocity.Y;
  1203. row["OmegaZ"] = prim.RotationalVelocity.Z;
  1204. row["CameraEyeOffsetX"] = prim.GetCameraEyeOffset().X;
  1205. row["CameraEyeOffsetY"] = prim.GetCameraEyeOffset().Y;
  1206. row["CameraEyeOffsetZ"] = prim.GetCameraEyeOffset().Z;
  1207. row["CameraAtOffsetX"] = prim.GetCameraAtOffset().X;
  1208. row["CameraAtOffsetY"] = prim.GetCameraAtOffset().Y;
  1209. row["CameraAtOffsetZ"] = prim.GetCameraAtOffset().Z;
  1210. if (prim.GetForceMouselook())
  1211. row["ForceMouselook"] = 1;
  1212. else
  1213. row["ForceMouselook"] = 0;
  1214. row["ScriptAccessPin"] = prim.ScriptAccessPin;
  1215. if (prim.AllowedDrop)
  1216. row["AllowedDrop"] = 1;
  1217. else
  1218. row["AllowedDrop"] = 0;
  1219. if (prim.DIE_AT_EDGE)
  1220. row["DieAtEdge"] = 1;
  1221. else
  1222. row["DieAtEdge"] = 0;
  1223. row["SalePrice"] = prim.SalePrice;
  1224. row["SaleType"] = Convert.ToInt16(prim.ObjectSaleType);
  1225. byte clickAction = prim.ClickAction;
  1226. row["ClickAction"] = clickAction;
  1227. row["Material"] = prim.Material;
  1228. row["CollisionSound"] = prim.CollisionSound.ToString();
  1229. row["CollisionSoundVolume"] = prim.CollisionSoundVolume;
  1230. }
  1231. /// <summary>
  1232. /// Fills/Updates the shape datarow.
  1233. /// </summary>
  1234. /// <param name="row">datarow to fill/update.</param>
  1235. /// <param name="prim">prim shape data.</param>
  1236. private static void fillShapeRow(DataRow row, SceneObjectPart prim)
  1237. {
  1238. PrimitiveBaseShape s = prim.Shape;
  1239. row["UUID"] = prim.UUID.ToString();
  1240. // shape is an enum
  1241. row["Shape"] = 0;
  1242. // vectors
  1243. row["ScaleX"] = s.Scale.X;
  1244. row["ScaleY"] = s.Scale.Y;
  1245. row["ScaleZ"] = s.Scale.Z;
  1246. // paths
  1247. row["PCode"] = s.PCode;
  1248. row["PathBegin"] = s.PathBegin;
  1249. row["PathEnd"] = s.PathEnd;
  1250. row["PathScaleX"] = s.PathScaleX;
  1251. row["PathScaleY"] = s.PathScaleY;
  1252. row["PathShearX"] = s.PathShearX;
  1253. row["PathShearY"] = s.PathShearY;
  1254. row["PathSkew"] = s.PathSkew;
  1255. row["PathCurve"] = s.PathCurve;
  1256. row["PathRadiusOffset"] = s.PathRadiusOffset;
  1257. row["PathRevolutions"] = s.PathRevolutions;
  1258. row["PathTaperX"] = s.PathTaperX;
  1259. row["PathTaperY"] = s.PathTaperY;
  1260. row["PathTwist"] = s.PathTwist;
  1261. row["PathTwistBegin"] = s.PathTwistBegin;
  1262. // profile
  1263. row["ProfileBegin"] = s.ProfileBegin;
  1264. row["ProfileEnd"] = s.ProfileEnd;
  1265. row["ProfileCurve"] = s.ProfileCurve;
  1266. row["ProfileHollow"] = s.ProfileHollow;
  1267. row["Texture"] = s.TextureEntry;
  1268. row["ExtraParams"] = s.ExtraParams;
  1269. row["State"] = s.State;
  1270. }
  1271. #endregion
  1272. /// <summary>
  1273. /// Retrieves the prims data for region.
  1274. /// </summary>
  1275. /// <param name="regionUUID">The region UUID.</param>
  1276. /// <param name="sceneGroupID">The scene group ID.</param>
  1277. /// <param name="primID">The prim ID.</param>
  1278. private void RetrievePrimsDataForRegion(UUID regionUUID, UUID sceneGroupID, string primID)
  1279. {
  1280. using (SqlConnection connection = _Database.DatabaseConnection())
  1281. {
  1282. _PrimDataAdapter.SelectCommand.Connection = connection;
  1283. _PrimDataAdapter.SelectCommand.Parameters["@RegionUUID"].Value = regionUUID.ToString();
  1284. _PrimDataAdapter.Fill(_PrimsDataSet, "prims");
  1285. _Log.Debug("Prim row count: " + _PrimsDataSet.Tables["prims"].Rows.Count);
  1286. _ShapeDataAdapter.SelectCommand.Connection = connection;
  1287. _ShapeDataAdapter.SelectCommand.Parameters["@RegionUUID"].Value = regionUUID.ToString();
  1288. _ShapeDataAdapter.Fill(_PrimsDataSet, "primshapes");
  1289. _ItemsDataAdapter.SelectCommand.Connection = connection;
  1290. _ItemsDataAdapter.SelectCommand.Parameters["@RegionUUID"].Value = regionUUID.ToString();
  1291. _ItemsDataAdapter.Fill(_PrimsDataSet, "primitems");
  1292. }
  1293. }
  1294. /// <summary>
  1295. /// Commits the dataset.
  1296. /// </summary>
  1297. private void CommitDataSet()
  1298. {
  1299. try
  1300. {
  1301. using (SqlConnection connection = _Database.DatabaseConnection())
  1302. {
  1303. _PrimDataAdapter.InsertCommand.Connection = connection;
  1304. _PrimDataAdapter.UpdateCommand.Connection = connection;
  1305. _PrimDataAdapter.DeleteCommand.Connection = connection;
  1306. _ShapeDataAdapter.InsertCommand.Connection = connection;
  1307. _ShapeDataAdapter.UpdateCommand.Connection = connection;
  1308. _ShapeDataAdapter.DeleteCommand.Connection = connection;
  1309. _ItemsDataAdapter.InsertCommand.Connection = connection;
  1310. _ItemsDataAdapter.UpdateCommand.Connection = connection;
  1311. _ItemsDataAdapter.DeleteCommand.Connection = connection;
  1312. _PrimDataAdapter.Update(_PrimsDataSet.Tables["prims"]);
  1313. _ShapeDataAdapter.Update(_PrimsDataSet.Tables["primshapes"]);
  1314. _ItemsDataAdapter.Update(_PrimsDataSet.Tables["primitems"]);
  1315. }
  1316. }
  1317. finally
  1318. {
  1319. _PrimsDataSet.AcceptChanges();
  1320. _PrimsDataSet.Tables["prims"].Clear();
  1321. _PrimsDataSet.Tables["primshapes"].Clear();
  1322. _PrimsDataSet.Tables["primitems"].Clear();
  1323. }
  1324. }
  1325. /// <summary>
  1326. /// Create commands for a dataadapter.
  1327. /// </summary>
  1328. /// <param name="dataAdapter">The data adapter.</param>
  1329. private static void SetupCommands(SqlDataAdapter dataAdapter)
  1330. {
  1331. SqlCommandBuilder commandBuilder = new SqlCommandBuilder(dataAdapter);
  1332. dataAdapter.InsertCommand = commandBuilder.GetInsertCommand(true);
  1333. dataAdapter.UpdateCommand = commandBuilder.GetUpdateCommand(true);
  1334. dataAdapter.DeleteCommand = commandBuilder.GetDeleteCommand(true);
  1335. }
  1336. #endregion
  1337. }
  1338. }