MySQLLegacyRegionData.cs 90 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801
  1. /*
  2. * Copyright (c) Contributors, http://opensimulator.org/
  3. * See CONTRIBUTORS.TXT for a full list of copyright holders.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are met:
  7. * * Redistributions of source code must retain the above copyright
  8. * notice, this list of conditions and the following disclaimer.
  9. * * Redistributions in binary form must reproduce the above copyright
  10. * notice, this list of conditions and the following disclaimer in the
  11. * documentation and/or other materials provided with the distribution.
  12. * * Neither the name of the OpenSimulator Project nor the
  13. * names of its contributors may be used to endorse or promote products
  14. * derived from this software without specific prior written permission.
  15. *
  16. * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
  17. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  18. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  19. * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
  20. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  21. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  22. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  23. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  24. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  25. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. */
  27. using System;
  28. using System.Collections.Generic;
  29. using System.Data;
  30. using System.Drawing;
  31. using System.IO;
  32. using System.Reflection;
  33. using System.Threading;
  34. using log4net;
  35. using MySql.Data.MySqlClient;
  36. using OpenMetaverse;
  37. using OpenSim.Framework;
  38. using OpenSim.Region.Framework.Interfaces;
  39. using OpenSim.Region.Framework.Scenes;
  40. using OpenSim.Data;
  41. namespace OpenSim.Data.MySQL
  42. {
  43. /// <summary>
  44. /// A MySQL Interface for the Region Server
  45. /// </summary>
  46. public class MySQLDataStore : IRegionDataStore
  47. {
  48. private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  49. private string m_connectionString;
  50. private object m_dbLock = new object();
  51. public void Initialise(string connectionString)
  52. {
  53. m_connectionString = connectionString;
  54. using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
  55. {
  56. dbcon.Open();
  57. // Apply new Migrations
  58. //
  59. Assembly assem = GetType().Assembly;
  60. Migration m = new Migration(dbcon, assem, "RegionStore");
  61. m.Update();
  62. // Clean dropped attachments
  63. //
  64. try
  65. {
  66. using (MySqlCommand cmd = dbcon.CreateCommand())
  67. {
  68. cmd.CommandText = "delete from prims, primshapes using prims " +
  69. "left join primshapes on prims.uuid = primshapes.uuid " +
  70. "where PCode = 9 and State <> 0";
  71. ExecuteNonQuery(cmd);
  72. }
  73. }
  74. catch (MySqlException ex)
  75. {
  76. m_log.Error("[REGION DB]: Error cleaning up dropped attachments: " + ex.Message);
  77. }
  78. }
  79. }
  80. private IDataReader ExecuteReader(MySqlCommand c)
  81. {
  82. IDataReader r = null;
  83. try
  84. {
  85. r = c.ExecuteReader();
  86. }
  87. catch (Exception e)
  88. {
  89. m_log.Error("[REGION DB]: MySQL error in ExecuteReader: " + e.Message);
  90. throw;
  91. }
  92. return r;
  93. }
  94. private void ExecuteNonQuery(MySqlCommand c)
  95. {
  96. try
  97. {
  98. c.ExecuteNonQuery();
  99. }
  100. catch (Exception e)
  101. {
  102. m_log.Error("[REGION DB]: MySQL error in ExecuteNonQuery: " + e.Message);
  103. throw;
  104. }
  105. }
  106. public void Dispose() {}
  107. public void StoreObject(SceneObjectGroup obj, UUID regionUUID)
  108. {
  109. uint flags = obj.RootPart.GetEffectiveObjectFlags();
  110. // Eligibility check
  111. //
  112. if ((flags & (uint)PrimFlags.Temporary) != 0)
  113. return;
  114. if ((flags & (uint)PrimFlags.TemporaryOnRez) != 0)
  115. return;
  116. lock (m_dbLock)
  117. {
  118. using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
  119. {
  120. dbcon.Open();
  121. MySqlCommand cmd = dbcon.CreateCommand();
  122. foreach (SceneObjectPart prim in obj.Children.Values)
  123. {
  124. cmd.Parameters.Clear();
  125. cmd.CommandText = "replace into prims (" +
  126. "UUID, CreationDate, " +
  127. "Name, Text, Description, " +
  128. "SitName, TouchName, ObjectFlags, " +
  129. "OwnerMask, NextOwnerMask, GroupMask, " +
  130. "EveryoneMask, BaseMask, PositionX, " +
  131. "PositionY, PositionZ, GroupPositionX, " +
  132. "GroupPositionY, GroupPositionZ, VelocityX, " +
  133. "VelocityY, VelocityZ, AngularVelocityX, " +
  134. "AngularVelocityY, AngularVelocityZ, " +
  135. "AccelerationX, AccelerationY, " +
  136. "AccelerationZ, RotationX, " +
  137. "RotationY, RotationZ, " +
  138. "RotationW, SitTargetOffsetX, " +
  139. "SitTargetOffsetY, SitTargetOffsetZ, " +
  140. "SitTargetOrientW, SitTargetOrientX, " +
  141. "SitTargetOrientY, SitTargetOrientZ, " +
  142. "RegionUUID, CreatorID, " +
  143. "OwnerID, GroupID, " +
  144. "LastOwnerID, SceneGroupID, " +
  145. "PayPrice, PayButton1, " +
  146. "PayButton2, PayButton3, " +
  147. "PayButton4, LoopedSound, " +
  148. "LoopedSoundGain, TextureAnimation, " +
  149. "OmegaX, OmegaY, OmegaZ, " +
  150. "CameraEyeOffsetX, CameraEyeOffsetY, " +
  151. "CameraEyeOffsetZ, CameraAtOffsetX, " +
  152. "CameraAtOffsetY, CameraAtOffsetZ, " +
  153. "ForceMouselook, ScriptAccessPin, " +
  154. "AllowedDrop, DieAtEdge, " +
  155. "SalePrice, SaleType, " +
  156. "ColorR, ColorG, ColorB, ColorA, " +
  157. "ParticleSystem, ClickAction, Material, " +
  158. "CollisionSound, CollisionSoundVolume, " +
  159. "PassTouches, " +
  160. "LinkNumber, MediaURL) values (" + "?UUID, " +
  161. "?CreationDate, ?Name, ?Text, " +
  162. "?Description, ?SitName, ?TouchName, " +
  163. "?ObjectFlags, ?OwnerMask, ?NextOwnerMask, " +
  164. "?GroupMask, ?EveryoneMask, ?BaseMask, " +
  165. "?PositionX, ?PositionY, ?PositionZ, " +
  166. "?GroupPositionX, ?GroupPositionY, " +
  167. "?GroupPositionZ, ?VelocityX, " +
  168. "?VelocityY, ?VelocityZ, ?AngularVelocityX, " +
  169. "?AngularVelocityY, ?AngularVelocityZ, " +
  170. "?AccelerationX, ?AccelerationY, " +
  171. "?AccelerationZ, ?RotationX, " +
  172. "?RotationY, ?RotationZ, " +
  173. "?RotationW, ?SitTargetOffsetX, " +
  174. "?SitTargetOffsetY, ?SitTargetOffsetZ, " +
  175. "?SitTargetOrientW, ?SitTargetOrientX, " +
  176. "?SitTargetOrientY, ?SitTargetOrientZ, " +
  177. "?RegionUUID, ?CreatorID, ?OwnerID, " +
  178. "?GroupID, ?LastOwnerID, ?SceneGroupID, " +
  179. "?PayPrice, ?PayButton1, ?PayButton2, " +
  180. "?PayButton3, ?PayButton4, ?LoopedSound, " +
  181. "?LoopedSoundGain, ?TextureAnimation, " +
  182. "?OmegaX, ?OmegaY, ?OmegaZ, " +
  183. "?CameraEyeOffsetX, ?CameraEyeOffsetY, " +
  184. "?CameraEyeOffsetZ, ?CameraAtOffsetX, " +
  185. "?CameraAtOffsetY, ?CameraAtOffsetZ, " +
  186. "?ForceMouselook, ?ScriptAccessPin, " +
  187. "?AllowedDrop, ?DieAtEdge, ?SalePrice, " +
  188. "?SaleType, ?ColorR, ?ColorG, " +
  189. "?ColorB, ?ColorA, ?ParticleSystem, " +
  190. "?ClickAction, ?Material, ?CollisionSound, " +
  191. "?CollisionSoundVolume, ?PassTouches, ?LinkNumber, ?MediaURL)";
  192. FillPrimCommand(cmd, prim, obj.UUID, regionUUID);
  193. ExecuteNonQuery(cmd);
  194. cmd.Parameters.Clear();
  195. cmd.CommandText = "replace into primshapes (" +
  196. "UUID, Shape, ScaleX, ScaleY, " +
  197. "ScaleZ, PCode, PathBegin, PathEnd, " +
  198. "PathScaleX, PathScaleY, PathShearX, " +
  199. "PathShearY, PathSkew, PathCurve, " +
  200. "PathRadiusOffset, PathRevolutions, " +
  201. "PathTaperX, PathTaperY, PathTwist, " +
  202. "PathTwistBegin, ProfileBegin, ProfileEnd, " +
  203. "ProfileCurve, ProfileHollow, Texture, " +
  204. "ExtraParams, State, Media) values (?UUID, " +
  205. "?Shape, ?ScaleX, ?ScaleY, ?ScaleZ, " +
  206. "?PCode, ?PathBegin, ?PathEnd, " +
  207. "?PathScaleX, ?PathScaleY, " +
  208. "?PathShearX, ?PathShearY, " +
  209. "?PathSkew, ?PathCurve, ?PathRadiusOffset, " +
  210. "?PathRevolutions, ?PathTaperX, " +
  211. "?PathTaperY, ?PathTwist, " +
  212. "?PathTwistBegin, ?ProfileBegin, " +
  213. "?ProfileEnd, ?ProfileCurve, " +
  214. "?ProfileHollow, ?Texture, ?ExtraParams, " +
  215. "?State, ?Media)";
  216. FillShapeCommand(cmd, prim);
  217. ExecuteNonQuery(cmd);
  218. }
  219. cmd.Dispose();
  220. }
  221. }
  222. }
  223. public void RemoveObject(UUID obj, UUID regionUUID)
  224. {
  225. List<UUID> uuids = new List<UUID>();
  226. // Formerly, this used to check the region UUID.
  227. // That makes no sense, as we remove the contents of a prim
  228. // unconditionally, but the prim dependent on the region ID.
  229. // So, we would destroy an object and cause hard to detect
  230. // issues if we delete the contents only. Deleting it all may
  231. // cause the loss of a prim, but is cleaner.
  232. // It's also faster because it uses the primary key.
  233. //
  234. lock (m_dbLock)
  235. {
  236. using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
  237. {
  238. dbcon.Open();
  239. using (MySqlCommand cmd = dbcon.CreateCommand())
  240. {
  241. cmd.CommandText = "select UUID from prims where SceneGroupID= ?UUID";
  242. cmd.Parameters.AddWithValue("UUID", obj.ToString());
  243. using (IDataReader reader = ExecuteReader(cmd))
  244. {
  245. while (reader.Read())
  246. uuids.Add(DBGuid.FromDB(reader["UUID"].ToString()));
  247. }
  248. // delete the main prims
  249. cmd.CommandText = "delete from prims where SceneGroupID= ?UUID";
  250. ExecuteNonQuery(cmd);
  251. }
  252. }
  253. }
  254. // there is no way this should be < 1 unless there is
  255. // a very corrupt database, but in that case be extra
  256. // safe anyway.
  257. if (uuids.Count > 0)
  258. {
  259. RemoveShapes(uuids);
  260. RemoveItems(uuids);
  261. }
  262. }
  263. /// <summary>
  264. /// Remove all persisted items of the given prim.
  265. /// The caller must acquire the necessrary synchronization locks
  266. /// </summary>
  267. /// <param name="uuid">the Item UUID</param>
  268. private void RemoveItems(UUID uuid)
  269. {
  270. lock (m_dbLock)
  271. {
  272. using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
  273. {
  274. dbcon.Open();
  275. using (MySqlCommand cmd = dbcon.CreateCommand())
  276. {
  277. cmd.CommandText = "delete from primitems where PrimID = ?PrimID";
  278. cmd.Parameters.AddWithValue("PrimID", uuid.ToString());
  279. ExecuteNonQuery(cmd);
  280. }
  281. }
  282. }
  283. }
  284. /// <summary>
  285. /// Remove all persisted shapes for a list of prims
  286. /// The caller must acquire the necessrary synchronization locks
  287. /// </summary>
  288. /// <param name="uuids">the list of UUIDs</param>
  289. private void RemoveShapes(List<UUID> uuids)
  290. {
  291. lock (m_dbLock)
  292. {
  293. string sql = "delete from primshapes where ";
  294. using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
  295. {
  296. dbcon.Open();
  297. using (MySqlCommand cmd = dbcon.CreateCommand())
  298. {
  299. for (int i = 0; i < uuids.Count; i++)
  300. {
  301. if ((i + 1) == uuids.Count)
  302. {// end of the list
  303. sql += "(UUID = ?UUID" + i + ")";
  304. }
  305. else
  306. {
  307. sql += "(UUID = ?UUID" + i + ") or ";
  308. }
  309. }
  310. cmd.CommandText = sql;
  311. for (int i = 0; i < uuids.Count; i++)
  312. cmd.Parameters.AddWithValue("UUID" + i, uuids[i].ToString());
  313. ExecuteNonQuery(cmd);
  314. }
  315. }
  316. }
  317. }
  318. /// <summary>
  319. /// Remove all persisted items for a list of prims
  320. /// The caller must acquire the necessrary synchronization locks
  321. /// </summary>
  322. /// <param name="uuids">the list of UUIDs</param>
  323. private void RemoveItems(List<UUID> uuids)
  324. {
  325. lock (m_dbLock)
  326. {
  327. string sql = "delete from primitems where ";
  328. using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
  329. {
  330. dbcon.Open();
  331. using (MySqlCommand cmd = dbcon.CreateCommand())
  332. {
  333. for (int i = 0; i < uuids.Count; i++)
  334. {
  335. if ((i + 1) == uuids.Count)
  336. {
  337. // end of the list
  338. sql += "(PrimID = ?PrimID" + i + ")";
  339. }
  340. else
  341. {
  342. sql += "(PrimID = ?PrimID" + i + ") or ";
  343. }
  344. }
  345. cmd.CommandText = sql;
  346. for (int i = 0; i < uuids.Count; i++)
  347. cmd.Parameters.AddWithValue("PrimID" + i, uuids[i].ToString());
  348. ExecuteNonQuery(cmd);
  349. }
  350. }
  351. }
  352. }
  353. public List<SceneObjectGroup> LoadObjects(UUID regionID)
  354. {
  355. const int ROWS_PER_QUERY = 5000;
  356. Dictionary<UUID, SceneObjectPart> prims = new Dictionary<UUID, SceneObjectPart>(ROWS_PER_QUERY);
  357. Dictionary<UUID, SceneObjectGroup> objects = new Dictionary<UUID, SceneObjectGroup>();
  358. int count = 0;
  359. #region Prim Loading
  360. lock (m_dbLock)
  361. {
  362. using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
  363. {
  364. dbcon.Open();
  365. using (MySqlCommand cmd = dbcon.CreateCommand())
  366. {
  367. cmd.CommandText =
  368. "SELECT * FROM prims LEFT JOIN primshapes ON prims.UUID = primshapes.UUID WHERE RegionUUID = ?RegionUUID";
  369. cmd.Parameters.AddWithValue("RegionUUID", regionID.ToString());
  370. using (IDataReader reader = ExecuteReader(cmd))
  371. {
  372. while (reader.Read())
  373. {
  374. SceneObjectPart prim = BuildPrim(reader);
  375. if (reader["Shape"] is DBNull)
  376. prim.Shape = PrimitiveBaseShape.Default;
  377. else
  378. prim.Shape = BuildShape(reader);
  379. UUID parentID = DBGuid.FromDB(reader["SceneGroupID"].ToString());
  380. if (parentID != prim.UUID)
  381. prim.ParentUUID = parentID;
  382. prims[prim.UUID] = prim;
  383. ++count;
  384. if (count % ROWS_PER_QUERY == 0)
  385. m_log.Debug("[REGION DB]: Loaded " + count + " prims...");
  386. }
  387. }
  388. }
  389. }
  390. }
  391. #endregion Prim Loading
  392. #region SceneObjectGroup Creation
  393. // Create all of the SOGs from the root prims first
  394. foreach (SceneObjectPart prim in prims.Values)
  395. {
  396. if (prim.ParentUUID == UUID.Zero)
  397. objects[prim.UUID] = new SceneObjectGroup(prim);
  398. }
  399. // Add all of the children objects to the SOGs
  400. foreach (SceneObjectPart prim in prims.Values)
  401. {
  402. SceneObjectGroup sog;
  403. if (prim.UUID != prim.ParentUUID)
  404. {
  405. if (objects.TryGetValue(prim.ParentUUID, out sog))
  406. {
  407. int originalLinkNum = prim.LinkNum;
  408. sog.AddPart(prim);
  409. // SceneObjectGroup.AddPart() tries to be smart and automatically set the LinkNum.
  410. // We override that here
  411. if (originalLinkNum != 0)
  412. prim.LinkNum = originalLinkNum;
  413. }
  414. else
  415. {
  416. m_log.WarnFormat(
  417. "[REGION DB]: Database contains an orphan child prim {0} {1} in region {2} pointing to missing parent {3}. This prim will not be loaded.",
  418. prim.Name, prim.UUID, regionID, prim.ParentUUID);
  419. }
  420. }
  421. }
  422. #endregion SceneObjectGroup Creation
  423. m_log.DebugFormat("[REGION DB]: Loaded {0} objects using {1} prims", objects.Count, prims.Count);
  424. #region Prim Inventory Loading
  425. // Instead of attempting to LoadItems on every prim,
  426. // most of which probably have no items... get a
  427. // list from DB of all prims which have items and
  428. // LoadItems only on those
  429. List<SceneObjectPart> primsWithInventory = new List<SceneObjectPart>();
  430. lock (m_dbLock)
  431. {
  432. using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
  433. {
  434. dbcon.Open();
  435. using (MySqlCommand itemCmd = dbcon.CreateCommand())
  436. {
  437. itemCmd.CommandText = "SELECT DISTINCT primID FROM primitems";
  438. using (IDataReader itemReader = ExecuteReader(itemCmd))
  439. {
  440. while (itemReader.Read())
  441. {
  442. if (!(itemReader["primID"] is DBNull))
  443. {
  444. UUID primID = DBGuid.FromDB(itemReader["primID"].ToString());
  445. if (prims.ContainsKey(primID))
  446. primsWithInventory.Add(prims[primID]);
  447. }
  448. }
  449. }
  450. }
  451. }
  452. }
  453. foreach (SceneObjectPart prim in primsWithInventory)
  454. {
  455. LoadItems(prim);
  456. }
  457. #endregion Prim Inventory Loading
  458. m_log.DebugFormat("[REGION DB]: Loaded inventory from {0} objects", primsWithInventory.Count);
  459. return new List<SceneObjectGroup>(objects.Values);
  460. }
  461. /// <summary>
  462. /// Load in a prim's persisted inventory.
  463. /// </summary>
  464. /// <param name="prim">The prim</param>
  465. private void LoadItems(SceneObjectPart prim)
  466. {
  467. lock (m_dbLock)
  468. {
  469. List<TaskInventoryItem> inventory = new List<TaskInventoryItem>();
  470. using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
  471. {
  472. dbcon.Open();
  473. using (MySqlCommand cmd = dbcon.CreateCommand())
  474. {
  475. cmd.CommandText = "select * from primitems where PrimID = ?PrimID";
  476. cmd.Parameters.AddWithValue("PrimID", prim.UUID.ToString());
  477. using (IDataReader reader = ExecuteReader(cmd))
  478. {
  479. while (reader.Read())
  480. {
  481. TaskInventoryItem item = BuildItem(reader);
  482. item.ParentID = prim.UUID; // Values in database are often wrong
  483. inventory.Add(item);
  484. }
  485. }
  486. }
  487. }
  488. prim.Inventory.RestoreInventoryItems(inventory);
  489. }
  490. }
  491. public void StoreTerrain(double[,] ter, UUID regionID)
  492. {
  493. m_log.Info("[REGION DB]: Storing terrain");
  494. lock (m_dbLock)
  495. {
  496. using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
  497. {
  498. dbcon.Open();
  499. using (MySqlCommand cmd = dbcon.CreateCommand())
  500. {
  501. cmd.CommandText = "delete from terrain where RegionUUID = ?RegionUUID";
  502. cmd.Parameters.AddWithValue("RegionUUID", regionID.ToString());
  503. ExecuteNonQuery(cmd);
  504. cmd.CommandText = "insert into terrain (RegionUUID, " +
  505. "Revision, Heightfield) values (?RegionUUID, " +
  506. "1, ?Heightfield)";
  507. cmd.Parameters.AddWithValue("Heightfield", SerializeTerrain(ter));
  508. ExecuteNonQuery(cmd);
  509. }
  510. }
  511. }
  512. }
  513. public double[,] LoadTerrain(UUID regionID)
  514. {
  515. double[,] terrain = null;
  516. lock (m_dbLock)
  517. {
  518. using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
  519. {
  520. dbcon.Open();
  521. using (MySqlCommand cmd = dbcon.CreateCommand())
  522. {
  523. cmd.CommandText = "select RegionUUID, Revision, Heightfield " +
  524. "from terrain where RegionUUID = ?RegionUUID " +
  525. "order by Revision desc limit 1";
  526. cmd.Parameters.AddWithValue("RegionUUID", regionID.ToString());
  527. using (IDataReader reader = ExecuteReader(cmd))
  528. {
  529. while (reader.Read())
  530. {
  531. int rev = Convert.ToInt32(reader["Revision"]);
  532. terrain = new double[(int)Constants.RegionSize, (int)Constants.RegionSize];
  533. terrain.Initialize();
  534. using (MemoryStream mstr = new MemoryStream((byte[])reader["Heightfield"]))
  535. {
  536. using (BinaryReader br = new BinaryReader(mstr))
  537. {
  538. for (int x = 0; x < (int)Constants.RegionSize; x++)
  539. {
  540. for (int y = 0; y < (int)Constants.RegionSize; y++)
  541. {
  542. terrain[x, y] = br.ReadDouble();
  543. }
  544. }
  545. }
  546. m_log.InfoFormat("[REGION DB]: Loaded terrain revision r{0}", rev);
  547. }
  548. }
  549. }
  550. }
  551. }
  552. }
  553. return terrain;
  554. }
  555. public void RemoveLandObject(UUID globalID)
  556. {
  557. lock (m_dbLock)
  558. {
  559. using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
  560. {
  561. dbcon.Open();
  562. using (MySqlCommand cmd = dbcon.CreateCommand())
  563. {
  564. cmd.CommandText = "delete from land where UUID = ?UUID";
  565. cmd.Parameters.AddWithValue("UUID", globalID.ToString());
  566. ExecuteNonQuery(cmd);
  567. }
  568. }
  569. }
  570. }
  571. public void StoreLandObject(ILandObject parcel)
  572. {
  573. lock (m_dbLock)
  574. {
  575. using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
  576. {
  577. dbcon.Open();
  578. using (MySqlCommand cmd = dbcon.CreateCommand())
  579. {
  580. cmd.CommandText = "replace into land (UUID, RegionUUID, " +
  581. "LocalLandID, Bitmap, Name, Description, " +
  582. "OwnerUUID, IsGroupOwned, Area, AuctionID, " +
  583. "Category, ClaimDate, ClaimPrice, GroupUUID, " +
  584. "SalePrice, LandStatus, LandFlags, LandingType, " +
  585. "MediaAutoScale, MediaTextureUUID, MediaURL, " +
  586. "MusicURL, PassHours, PassPrice, SnapshotUUID, " +
  587. "UserLocationX, UserLocationY, UserLocationZ, " +
  588. "UserLookAtX, UserLookAtY, UserLookAtZ, " +
  589. "AuthbuyerID, OtherCleanTime, Dwell) values (" +
  590. "?UUID, ?RegionUUID, " +
  591. "?LocalLandID, ?Bitmap, ?Name, ?Description, " +
  592. "?OwnerUUID, ?IsGroupOwned, ?Area, ?AuctionID, " +
  593. "?Category, ?ClaimDate, ?ClaimPrice, ?GroupUUID, " +
  594. "?SalePrice, ?LandStatus, ?LandFlags, ?LandingType, " +
  595. "?MediaAutoScale, ?MediaTextureUUID, ?MediaURL, " +
  596. "?MusicURL, ?PassHours, ?PassPrice, ?SnapshotUUID, " +
  597. "?UserLocationX, ?UserLocationY, ?UserLocationZ, " +
  598. "?UserLookAtX, ?UserLookAtY, ?UserLookAtZ, " +
  599. "?AuthbuyerID, ?OtherCleanTime, ?Dwell)";
  600. FillLandCommand(cmd, parcel.LandData, parcel.RegionUUID);
  601. ExecuteNonQuery(cmd);
  602. cmd.CommandText = "delete from landaccesslist where LandUUID = ?UUID";
  603. ExecuteNonQuery(cmd);
  604. cmd.Parameters.Clear();
  605. cmd.CommandText = "insert into landaccesslist (LandUUID, " +
  606. "AccessUUID, Flags) values (?LandUUID, ?AccessUUID, " +
  607. "?Flags)";
  608. foreach (ParcelManager.ParcelAccessEntry entry in parcel.LandData.ParcelAccessList)
  609. {
  610. FillLandAccessCommand(cmd, entry, parcel.LandData.GlobalID);
  611. ExecuteNonQuery(cmd);
  612. cmd.Parameters.Clear();
  613. }
  614. }
  615. }
  616. }
  617. }
  618. public RegionLightShareData LoadRegionWindlightSettings(UUID regionUUID)
  619. {
  620. RegionLightShareData nWP = new RegionLightShareData();
  621. nWP.OnSave += StoreRegionWindlightSettings;
  622. using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
  623. {
  624. dbcon.Open();
  625. string command = "select * from `regionwindlight` where region_id = ?regionID";
  626. using(MySqlCommand cmd = new MySqlCommand(command))
  627. {
  628. cmd.Connection = dbcon;
  629. cmd.Parameters.AddWithValue("?regionID", regionUUID.ToString());
  630. IDataReader result = ExecuteReader(cmd);
  631. if (!result.Read())
  632. {
  633. //No result, so store our default windlight profile and return it
  634. nWP.regionID = regionUUID;
  635. StoreRegionWindlightSettings(nWP);
  636. return nWP;
  637. }
  638. else
  639. {
  640. nWP.regionID = DBGuid.FromDB(result["region_id"]);
  641. nWP.waterColor.X = Convert.ToSingle(result["water_color_r"]);
  642. nWP.waterColor.Y = Convert.ToSingle(result["water_color_g"]);
  643. nWP.waterColor.Z = Convert.ToSingle(result["water_color_b"]);
  644. nWP.waterFogDensityExponent = Convert.ToSingle(result["water_fog_density_exponent"]);
  645. nWP.underwaterFogModifier = Convert.ToSingle(result["underwater_fog_modifier"]);
  646. nWP.reflectionWaveletScale.X = Convert.ToSingle(result["reflection_wavelet_scale_1"]);
  647. nWP.reflectionWaveletScale.Y = Convert.ToSingle(result["reflection_wavelet_scale_2"]);
  648. nWP.reflectionWaveletScale.Z = Convert.ToSingle(result["reflection_wavelet_scale_3"]);
  649. nWP.fresnelScale = Convert.ToSingle(result["fresnel_scale"]);
  650. nWP.fresnelOffset = Convert.ToSingle(result["fresnel_offset"]);
  651. nWP.refractScaleAbove = Convert.ToSingle(result["refract_scale_above"]);
  652. nWP.refractScaleBelow = Convert.ToSingle(result["refract_scale_below"]);
  653. nWP.blurMultiplier = Convert.ToSingle(result["blur_multiplier"]);
  654. nWP.bigWaveDirection.X = Convert.ToSingle(result["big_wave_direction_x"]);
  655. nWP.bigWaveDirection.Y = Convert.ToSingle(result["big_wave_direction_y"]);
  656. nWP.littleWaveDirection.X = Convert.ToSingle(result["little_wave_direction_x"]);
  657. nWP.littleWaveDirection.Y = Convert.ToSingle(result["little_wave_direction_y"]);
  658. UUID.TryParse(result["normal_map_texture"].ToString(), out nWP.normalMapTexture);
  659. nWP.horizon.X = Convert.ToSingle(result["horizon_r"]);
  660. nWP.horizon.Y = Convert.ToSingle(result["horizon_g"]);
  661. nWP.horizon.Z = Convert.ToSingle(result["horizon_b"]);
  662. nWP.horizon.W = Convert.ToSingle(result["horizon_i"]);
  663. nWP.hazeHorizon = Convert.ToSingle(result["haze_horizon"]);
  664. nWP.blueDensity.X = Convert.ToSingle(result["blue_density_r"]);
  665. nWP.blueDensity.Y = Convert.ToSingle(result["blue_density_g"]);
  666. nWP.blueDensity.Z = Convert.ToSingle(result["blue_density_b"]);
  667. nWP.blueDensity.W = Convert.ToSingle(result["blue_density_i"]);
  668. nWP.hazeDensity = Convert.ToSingle(result["haze_density"]);
  669. nWP.densityMultiplier = Convert.ToSingle(result["density_multiplier"]);
  670. nWP.distanceMultiplier = Convert.ToSingle(result["distance_multiplier"]);
  671. nWP.maxAltitude = Convert.ToUInt16(result["max_altitude"]);
  672. nWP.sunMoonColor.X = Convert.ToSingle(result["sun_moon_color_r"]);
  673. nWP.sunMoonColor.Y = Convert.ToSingle(result["sun_moon_color_g"]);
  674. nWP.sunMoonColor.Z = Convert.ToSingle(result["sun_moon_color_b"]);
  675. nWP.sunMoonColor.W = Convert.ToSingle(result["sun_moon_color_i"]);
  676. nWP.sunMoonPosition = Convert.ToSingle(result["sun_moon_position"]);
  677. nWP.ambient.X = Convert.ToSingle(result["ambient_r"]);
  678. nWP.ambient.Y = Convert.ToSingle(result["ambient_g"]);
  679. nWP.ambient.Z = Convert.ToSingle(result["ambient_b"]);
  680. nWP.ambient.W = Convert.ToSingle(result["ambient_i"]);
  681. nWP.eastAngle = Convert.ToSingle(result["east_angle"]);
  682. nWP.sunGlowFocus = Convert.ToSingle(result["sun_glow_focus"]);
  683. nWP.sunGlowSize = Convert.ToSingle(result["sun_glow_size"]);
  684. nWP.sceneGamma = Convert.ToSingle(result["scene_gamma"]);
  685. nWP.starBrightness = Convert.ToSingle(result["star_brightness"]);
  686. nWP.cloudColor.X = Convert.ToSingle(result["cloud_color_r"]);
  687. nWP.cloudColor.Y = Convert.ToSingle(result["cloud_color_g"]);
  688. nWP.cloudColor.Z = Convert.ToSingle(result["cloud_color_b"]);
  689. nWP.cloudColor.W = Convert.ToSingle(result["cloud_color_i"]);
  690. nWP.cloudXYDensity.X = Convert.ToSingle(result["cloud_x"]);
  691. nWP.cloudXYDensity.Y = Convert.ToSingle(result["cloud_y"]);
  692. nWP.cloudXYDensity.Z = Convert.ToSingle(result["cloud_density"]);
  693. nWP.cloudCoverage = Convert.ToSingle(result["cloud_coverage"]);
  694. nWP.cloudScale = Convert.ToSingle(result["cloud_scale"]);
  695. nWP.cloudDetailXYDensity.X = Convert.ToSingle(result["cloud_detail_x"]);
  696. nWP.cloudDetailXYDensity.Y = Convert.ToSingle(result["cloud_detail_y"]);
  697. nWP.cloudDetailXYDensity.Z = Convert.ToSingle(result["cloud_detail_density"]);
  698. nWP.cloudScrollX = Convert.ToSingle(result["cloud_scroll_x"]);
  699. nWP.cloudScrollXLock = Convert.ToBoolean(result["cloud_scroll_x_lock"]);
  700. nWP.cloudScrollY = Convert.ToSingle(result["cloud_scroll_y"]);
  701. nWP.cloudScrollYLock = Convert.ToBoolean(result["cloud_scroll_y_lock"]);
  702. nWP.drawClassicClouds = Convert.ToBoolean(result["draw_classic_clouds"]);
  703. }
  704. }
  705. }
  706. return nWP;
  707. }
  708. public RegionSettings LoadRegionSettings(UUID regionUUID)
  709. {
  710. RegionSettings rs = null;
  711. lock (m_dbLock)
  712. {
  713. using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
  714. {
  715. dbcon.Open();
  716. using (MySqlCommand cmd = dbcon.CreateCommand())
  717. {
  718. cmd.CommandText = "select * from regionsettings where regionUUID = ?RegionUUID";
  719. cmd.Parameters.AddWithValue("regionUUID", regionUUID);
  720. using (IDataReader reader = ExecuteReader(cmd))
  721. {
  722. if (reader.Read())
  723. {
  724. rs = BuildRegionSettings(reader);
  725. rs.OnSave += StoreRegionSettings;
  726. }
  727. else
  728. {
  729. rs = new RegionSettings();
  730. rs.RegionUUID = regionUUID;
  731. rs.OnSave += StoreRegionSettings;
  732. StoreRegionSettings(rs);
  733. }
  734. }
  735. }
  736. }
  737. }
  738. return rs;
  739. }
  740. public void StoreRegionWindlightSettings(RegionLightShareData wl)
  741. {
  742. using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
  743. {
  744. dbcon.Open();
  745. using (MySqlCommand cmd = dbcon.CreateCommand())
  746. {
  747. cmd.CommandText = "REPLACE INTO `regionwindlight` (`region_id`, `water_color_r`, `water_color_g`, ";
  748. cmd.CommandText += "`water_color_b`, `water_fog_density_exponent`, `underwater_fog_modifier`, ";
  749. cmd.CommandText += "`reflection_wavelet_scale_1`, `reflection_wavelet_scale_2`, `reflection_wavelet_scale_3`, ";
  750. cmd.CommandText += "`fresnel_scale`, `fresnel_offset`, `refract_scale_above`, `refract_scale_below`, ";
  751. cmd.CommandText += "`blur_multiplier`, `big_wave_direction_x`, `big_wave_direction_y`, `little_wave_direction_x`, ";
  752. cmd.CommandText += "`little_wave_direction_y`, `normal_map_texture`, `horizon_r`, `horizon_g`, `horizon_b`, ";
  753. cmd.CommandText += "`horizon_i`, `haze_horizon`, `blue_density_r`, `blue_density_g`, `blue_density_b`, ";
  754. cmd.CommandText += "`blue_density_i`, `haze_density`, `density_multiplier`, `distance_multiplier`, `max_altitude`, ";
  755. cmd.CommandText += "`sun_moon_color_r`, `sun_moon_color_g`, `sun_moon_color_b`, `sun_moon_color_i`, `sun_moon_position`, ";
  756. cmd.CommandText += "`ambient_r`, `ambient_g`, `ambient_b`, `ambient_i`, `east_angle`, `sun_glow_focus`, `sun_glow_size`, ";
  757. cmd.CommandText += "`scene_gamma`, `star_brightness`, `cloud_color_r`, `cloud_color_g`, `cloud_color_b`, `cloud_color_i`, ";
  758. cmd.CommandText += "`cloud_x`, `cloud_y`, `cloud_density`, `cloud_coverage`, `cloud_scale`, `cloud_detail_x`, ";
  759. cmd.CommandText += "`cloud_detail_y`, `cloud_detail_density`, `cloud_scroll_x`, `cloud_scroll_x_lock`, `cloud_scroll_y`, ";
  760. cmd.CommandText += "`cloud_scroll_y_lock`, `draw_classic_clouds`) VALUES (?region_id, ?water_color_r, ";
  761. cmd.CommandText += "?water_color_g, ?water_color_b, ?water_fog_density_exponent, ?underwater_fog_modifier, ?reflection_wavelet_scale_1, ";
  762. cmd.CommandText += "?reflection_wavelet_scale_2, ?reflection_wavelet_scale_3, ?fresnel_scale, ?fresnel_offset, ?refract_scale_above, ";
  763. cmd.CommandText += "?refract_scale_below, ?blur_multiplier, ?big_wave_direction_x, ?big_wave_direction_y, ?little_wave_direction_x, ";
  764. cmd.CommandText += "?little_wave_direction_y, ?normal_map_texture, ?horizon_r, ?horizon_g, ?horizon_b, ?horizon_i, ?haze_horizon, ";
  765. cmd.CommandText += "?blue_density_r, ?blue_density_g, ?blue_density_b, ?blue_density_i, ?haze_density, ?density_multiplier, ";
  766. cmd.CommandText += "?distance_multiplier, ?max_altitude, ?sun_moon_color_r, ?sun_moon_color_g, ?sun_moon_color_b, ";
  767. cmd.CommandText += "?sun_moon_color_i, ?sun_moon_position, ?ambient_r, ?ambient_g, ?ambient_b, ?ambient_i, ?east_angle, ";
  768. cmd.CommandText += "?sun_glow_focus, ?sun_glow_size, ?scene_gamma, ?star_brightness, ?cloud_color_r, ?cloud_color_g, ";
  769. cmd.CommandText += "?cloud_color_b, ?cloud_color_i, ?cloud_x, ?cloud_y, ?cloud_density, ?cloud_coverage, ?cloud_scale, ";
  770. cmd.CommandText += "?cloud_detail_x, ?cloud_detail_y, ?cloud_detail_density, ?cloud_scroll_x, ?cloud_scroll_x_lock, ";
  771. cmd.CommandText += "?cloud_scroll_y, ?cloud_scroll_y_lock, ?draw_classic_clouds)";
  772. cmd.Parameters.AddWithValue("region_id", wl.regionID);
  773. cmd.Parameters.AddWithValue("water_color_r", wl.waterColor.X);
  774. cmd.Parameters.AddWithValue("water_color_g", wl.waterColor.Y);
  775. cmd.Parameters.AddWithValue("water_color_b", wl.waterColor.Z);
  776. cmd.Parameters.AddWithValue("water_fog_density_exponent", wl.waterFogDensityExponent);
  777. cmd.Parameters.AddWithValue("underwater_fog_modifier", wl.underwaterFogModifier);
  778. cmd.Parameters.AddWithValue("reflection_wavelet_scale_1", wl.reflectionWaveletScale.X);
  779. cmd.Parameters.AddWithValue("reflection_wavelet_scale_2", wl.reflectionWaveletScale.Y);
  780. cmd.Parameters.AddWithValue("reflection_wavelet_scale_3", wl.reflectionWaveletScale.Z);
  781. cmd.Parameters.AddWithValue("fresnel_scale", wl.fresnelScale);
  782. cmd.Parameters.AddWithValue("fresnel_offset", wl.fresnelOffset);
  783. cmd.Parameters.AddWithValue("refract_scale_above", wl.refractScaleAbove);
  784. cmd.Parameters.AddWithValue("refract_scale_below", wl.refractScaleBelow);
  785. cmd.Parameters.AddWithValue("blur_multiplier", wl.blurMultiplier);
  786. cmd.Parameters.AddWithValue("big_wave_direction_x", wl.bigWaveDirection.X);
  787. cmd.Parameters.AddWithValue("big_wave_direction_y", wl.bigWaveDirection.Y);
  788. cmd.Parameters.AddWithValue("little_wave_direction_x", wl.littleWaveDirection.X);
  789. cmd.Parameters.AddWithValue("little_wave_direction_y", wl.littleWaveDirection.Y);
  790. cmd.Parameters.AddWithValue("normal_map_texture", wl.normalMapTexture);
  791. cmd.Parameters.AddWithValue("horizon_r", wl.horizon.X);
  792. cmd.Parameters.AddWithValue("horizon_g", wl.horizon.Y);
  793. cmd.Parameters.AddWithValue("horizon_b", wl.horizon.Z);
  794. cmd.Parameters.AddWithValue("horizon_i", wl.horizon.W);
  795. cmd.Parameters.AddWithValue("haze_horizon", wl.hazeHorizon);
  796. cmd.Parameters.AddWithValue("blue_density_r", wl.blueDensity.X);
  797. cmd.Parameters.AddWithValue("blue_density_g", wl.blueDensity.Y);
  798. cmd.Parameters.AddWithValue("blue_density_b", wl.blueDensity.Z);
  799. cmd.Parameters.AddWithValue("blue_density_i", wl.blueDensity.W);
  800. cmd.Parameters.AddWithValue("haze_density", wl.hazeDensity);
  801. cmd.Parameters.AddWithValue("density_multiplier", wl.densityMultiplier);
  802. cmd.Parameters.AddWithValue("distance_multiplier", wl.distanceMultiplier);
  803. cmd.Parameters.AddWithValue("max_altitude", wl.maxAltitude);
  804. cmd.Parameters.AddWithValue("sun_moon_color_r", wl.sunMoonColor.X);
  805. cmd.Parameters.AddWithValue("sun_moon_color_g", wl.sunMoonColor.Y);
  806. cmd.Parameters.AddWithValue("sun_moon_color_b", wl.sunMoonColor.Z);
  807. cmd.Parameters.AddWithValue("sun_moon_color_i", wl.sunMoonColor.W);
  808. cmd.Parameters.AddWithValue("sun_moon_position", wl.sunMoonPosition);
  809. cmd.Parameters.AddWithValue("ambient_r", wl.ambient.X);
  810. cmd.Parameters.AddWithValue("ambient_g", wl.ambient.Y);
  811. cmd.Parameters.AddWithValue("ambient_b", wl.ambient.Z);
  812. cmd.Parameters.AddWithValue("ambient_i", wl.ambient.W);
  813. cmd.Parameters.AddWithValue("east_angle", wl.eastAngle);
  814. cmd.Parameters.AddWithValue("sun_glow_focus", wl.sunGlowFocus);
  815. cmd.Parameters.AddWithValue("sun_glow_size", wl.sunGlowSize);
  816. cmd.Parameters.AddWithValue("scene_gamma", wl.sceneGamma);
  817. cmd.Parameters.AddWithValue("star_brightness", wl.starBrightness);
  818. cmd.Parameters.AddWithValue("cloud_color_r", wl.cloudColor.X);
  819. cmd.Parameters.AddWithValue("cloud_color_g", wl.cloudColor.Y);
  820. cmd.Parameters.AddWithValue("cloud_color_b", wl.cloudColor.Z);
  821. cmd.Parameters.AddWithValue("cloud_color_i", wl.cloudColor.W);
  822. cmd.Parameters.AddWithValue("cloud_x", wl.cloudXYDensity.X);
  823. cmd.Parameters.AddWithValue("cloud_y", wl.cloudXYDensity.Y);
  824. cmd.Parameters.AddWithValue("cloud_density", wl.cloudXYDensity.Z);
  825. cmd.Parameters.AddWithValue("cloud_coverage", wl.cloudCoverage);
  826. cmd.Parameters.AddWithValue("cloud_scale", wl.cloudScale);
  827. cmd.Parameters.AddWithValue("cloud_detail_x", wl.cloudDetailXYDensity.X);
  828. cmd.Parameters.AddWithValue("cloud_detail_y", wl.cloudDetailXYDensity.Y);
  829. cmd.Parameters.AddWithValue("cloud_detail_density", wl.cloudDetailXYDensity.Z);
  830. cmd.Parameters.AddWithValue("cloud_scroll_x", wl.cloudScrollX);
  831. cmd.Parameters.AddWithValue("cloud_scroll_x_lock", wl.cloudScrollXLock);
  832. cmd.Parameters.AddWithValue("cloud_scroll_y", wl.cloudScrollY);
  833. cmd.Parameters.AddWithValue("cloud_scroll_y_lock", wl.cloudScrollYLock);
  834. cmd.Parameters.AddWithValue("draw_classic_clouds", wl.drawClassicClouds);
  835. ExecuteNonQuery(cmd);
  836. }
  837. }
  838. }
  839. public void StoreRegionSettings(RegionSettings rs)
  840. {
  841. lock (m_dbLock)
  842. {
  843. using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
  844. {
  845. dbcon.Open();
  846. using (MySqlCommand cmd = dbcon.CreateCommand())
  847. {
  848. cmd.CommandText = "replace into regionsettings (regionUUID, " +
  849. "block_terraform, block_fly, allow_damage, " +
  850. "restrict_pushing, allow_land_resell, " +
  851. "allow_land_join_divide, block_show_in_search, " +
  852. "agent_limit, object_bonus, maturity, " +
  853. "disable_scripts, disable_collisions, " +
  854. "disable_physics, terrain_texture_1, " +
  855. "terrain_texture_2, terrain_texture_3, " +
  856. "terrain_texture_4, elevation_1_nw, " +
  857. "elevation_2_nw, elevation_1_ne, " +
  858. "elevation_2_ne, elevation_1_se, " +
  859. "elevation_2_se, elevation_1_sw, " +
  860. "elevation_2_sw, water_height, " +
  861. "terrain_raise_limit, terrain_lower_limit, " +
  862. "use_estate_sun, fixed_sun, sun_position, " +
  863. "covenant, Sandbox, sunvectorx, sunvectory, " +
  864. "sunvectorz, loaded_creation_datetime, " +
  865. "loaded_creation_id, map_tile_ID) values (?RegionUUID, ?BlockTerraform, " +
  866. "?BlockFly, ?AllowDamage, ?RestrictPushing, " +
  867. "?AllowLandResell, ?AllowLandJoinDivide, " +
  868. "?BlockShowInSearch, ?AgentLimit, ?ObjectBonus, " +
  869. "?Maturity, ?DisableScripts, ?DisableCollisions, " +
  870. "?DisablePhysics, ?TerrainTexture1, " +
  871. "?TerrainTexture2, ?TerrainTexture3, " +
  872. "?TerrainTexture4, ?Elevation1NW, ?Elevation2NW, " +
  873. "?Elevation1NE, ?Elevation2NE, ?Elevation1SE, " +
  874. "?Elevation2SE, ?Elevation1SW, ?Elevation2SW, " +
  875. "?WaterHeight, ?TerrainRaiseLimit, " +
  876. "?TerrainLowerLimit, ?UseEstateSun, ?FixedSun, " +
  877. "?SunPosition, ?Covenant, ?Sandbox, " +
  878. "?SunVectorX, ?SunVectorY, ?SunVectorZ, " +
  879. "?LoadedCreationDateTime, ?LoadedCreationID, " +
  880. "?TerrainImageID)";
  881. FillRegionSettingsCommand(cmd, rs);
  882. ExecuteNonQuery(cmd);
  883. }
  884. }
  885. }
  886. }
  887. public List<LandData> LoadLandObjects(UUID regionUUID)
  888. {
  889. List<LandData> landData = new List<LandData>();
  890. lock (m_dbLock)
  891. {
  892. using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
  893. {
  894. dbcon.Open();
  895. using (MySqlCommand cmd = dbcon.CreateCommand())
  896. {
  897. cmd.CommandText = "select * from land where RegionUUID = ?RegionUUID";
  898. cmd.Parameters.AddWithValue("RegionUUID", regionUUID.ToString());
  899. using (IDataReader reader = ExecuteReader(cmd))
  900. {
  901. while (reader.Read())
  902. {
  903. LandData newLand = BuildLandData(reader);
  904. landData.Add(newLand);
  905. }
  906. }
  907. }
  908. using (MySqlCommand cmd = dbcon.CreateCommand())
  909. {
  910. foreach (LandData land in landData)
  911. {
  912. cmd.Parameters.Clear();
  913. cmd.CommandText = "select * from landaccesslist where LandUUID = ?LandUUID";
  914. cmd.Parameters.AddWithValue("LandUUID", land.GlobalID.ToString());
  915. using (IDataReader reader = ExecuteReader(cmd))
  916. {
  917. while (reader.Read())
  918. {
  919. land.ParcelAccessList.Add(BuildLandAccessData(reader));
  920. }
  921. }
  922. }
  923. }
  924. }
  925. }
  926. return landData;
  927. }
  928. public void Shutdown()
  929. {
  930. }
  931. private SceneObjectPart BuildPrim(IDataReader row)
  932. {
  933. SceneObjectPart prim = new SceneObjectPart();
  934. // depending on the MySQL connector version, CHAR(36) may be already converted to Guid!
  935. prim.UUID = DBGuid.FromDB(row["UUID"]);
  936. prim.CreatorID = DBGuid.FromDB(row["CreatorID"]);
  937. prim.OwnerID = DBGuid.FromDB(row["OwnerID"]);
  938. prim.GroupID = DBGuid.FromDB(row["GroupID"]);
  939. prim.LastOwnerID = DBGuid.FromDB(row["LastOwnerID"]);
  940. // explicit conversion of integers is required, which sort
  941. // of sucks. No idea if there is a shortcut here or not.
  942. prim.CreationDate = (int)row["CreationDate"];
  943. if (row["Name"] != DBNull.Value)
  944. prim.Name = (string)row["Name"];
  945. else
  946. prim.Name = String.Empty;
  947. // Various text fields
  948. prim.Text = (string)row["Text"];
  949. prim.Color = Color.FromArgb((int)row["ColorA"],
  950. (int)row["ColorR"],
  951. (int)row["ColorG"],
  952. (int)row["ColorB"]);
  953. prim.Description = (string)row["Description"];
  954. prim.SitName = (string)row["SitName"];
  955. prim.TouchName = (string)row["TouchName"];
  956. // Permissions
  957. prim.Flags = (PrimFlags)(int)row["ObjectFlags"];
  958. prim.OwnerMask = (uint)(int)row["OwnerMask"];
  959. prim.NextOwnerMask = (uint)(int)row["NextOwnerMask"];
  960. prim.GroupMask = (uint)(int)row["GroupMask"];
  961. prim.EveryoneMask = (uint)(int)row["EveryoneMask"];
  962. prim.BaseMask = (uint)(int)row["BaseMask"];
  963. // Vectors
  964. prim.OffsetPosition = new Vector3(
  965. (float)(double)row["PositionX"],
  966. (float)(double)row["PositionY"],
  967. (float)(double)row["PositionZ"]
  968. );
  969. prim.GroupPosition = new Vector3(
  970. (float)(double)row["GroupPositionX"],
  971. (float)(double)row["GroupPositionY"],
  972. (float)(double)row["GroupPositionZ"]
  973. );
  974. prim.Velocity = new Vector3(
  975. (float)(double)row["VelocityX"],
  976. (float)(double)row["VelocityY"],
  977. (float)(double)row["VelocityZ"]
  978. );
  979. prim.AngularVelocity = new Vector3(
  980. (float)(double)row["AngularVelocityX"],
  981. (float)(double)row["AngularVelocityY"],
  982. (float)(double)row["AngularVelocityZ"]
  983. );
  984. prim.Acceleration = new Vector3(
  985. (float)(double)row["AccelerationX"],
  986. (float)(double)row["AccelerationY"],
  987. (float)(double)row["AccelerationZ"]
  988. );
  989. // quaternions
  990. prim.RotationOffset = new Quaternion(
  991. (float)(double)row["RotationX"],
  992. (float)(double)row["RotationY"],
  993. (float)(double)row["RotationZ"],
  994. (float)(double)row["RotationW"]
  995. );
  996. prim.SitTargetPositionLL = new Vector3(
  997. (float)(double)row["SitTargetOffsetX"],
  998. (float)(double)row["SitTargetOffsetY"],
  999. (float)(double)row["SitTargetOffsetZ"]
  1000. );
  1001. prim.SitTargetOrientationLL = new Quaternion(
  1002. (float)(double)row["SitTargetOrientX"],
  1003. (float)(double)row["SitTargetOrientY"],
  1004. (float)(double)row["SitTargetOrientZ"],
  1005. (float)(double)row["SitTargetOrientW"]
  1006. );
  1007. prim.PayPrice[0] = (int)row["PayPrice"];
  1008. prim.PayPrice[1] = (int)row["PayButton1"];
  1009. prim.PayPrice[2] = (int)row["PayButton2"];
  1010. prim.PayPrice[3] = (int)row["PayButton3"];
  1011. prim.PayPrice[4] = (int)row["PayButton4"];
  1012. prim.Sound = DBGuid.FromDB(row["LoopedSound"].ToString());
  1013. prim.SoundGain = (float)(double)row["LoopedSoundGain"];
  1014. prim.SoundFlags = 1; // If it's persisted at all, it's looped
  1015. if (!(row["TextureAnimation"] is DBNull))
  1016. prim.TextureAnimation = (byte[])row["TextureAnimation"];
  1017. if (!(row["ParticleSystem"] is DBNull))
  1018. prim.ParticleSystem = (byte[])row["ParticleSystem"];
  1019. prim.AngularVelocity = new Vector3(
  1020. (float)(double)row["OmegaX"],
  1021. (float)(double)row["OmegaY"],
  1022. (float)(double)row["OmegaZ"]
  1023. );
  1024. prim.SetCameraEyeOffset(new Vector3(
  1025. (float)(double)row["CameraEyeOffsetX"],
  1026. (float)(double)row["CameraEyeOffsetY"],
  1027. (float)(double)row["CameraEyeOffsetZ"]
  1028. ));
  1029. prim.SetCameraAtOffset(new Vector3(
  1030. (float)(double)row["CameraAtOffsetX"],
  1031. (float)(double)row["CameraAtOffsetY"],
  1032. (float)(double)row["CameraAtOffsetZ"]
  1033. ));
  1034. prim.SetForceMouselook((sbyte)row["ForceMouselook"] != 0);
  1035. prim.ScriptAccessPin = (int)row["ScriptAccessPin"];
  1036. prim.AllowedDrop = ((sbyte)row["AllowedDrop"] != 0);
  1037. prim.DIE_AT_EDGE = ((sbyte)row["DieAtEdge"] != 0);
  1038. prim.SalePrice = (int)row["SalePrice"];
  1039. prim.ObjectSaleType = unchecked((byte)(sbyte)row["SaleType"]);
  1040. prim.Material = unchecked((byte)(sbyte)row["Material"]);
  1041. if (!(row["ClickAction"] is DBNull))
  1042. prim.ClickAction = unchecked((byte)(sbyte)row["ClickAction"]);
  1043. prim.CollisionSound = DBGuid.FromDB(row["CollisionSound"]);
  1044. prim.CollisionSoundVolume = (float)(double)row["CollisionSoundVolume"];
  1045. prim.PassTouches = ((sbyte)row["PassTouches"] != 0);
  1046. prim.LinkNum = (int)row["LinkNumber"];
  1047. if (!(row["MediaURL"] is System.DBNull))
  1048. prim.MediaUrl = (string)row["MediaURL"];
  1049. return prim;
  1050. }
  1051. /// <summary>
  1052. /// Build a prim inventory item from the persisted data.
  1053. /// </summary>
  1054. /// <param name="row"></param>
  1055. /// <returns></returns>
  1056. private static TaskInventoryItem BuildItem(IDataReader row)
  1057. {
  1058. TaskInventoryItem taskItem = new TaskInventoryItem();
  1059. taskItem.ItemID = DBGuid.FromDB(row["itemID"]);
  1060. taskItem.ParentPartID = DBGuid.FromDB(row["primID"]);
  1061. taskItem.AssetID = DBGuid.FromDB(row["assetID"]);
  1062. taskItem.ParentID = DBGuid.FromDB(row["parentFolderID"]);
  1063. taskItem.InvType = Convert.ToInt32(row["invType"]);
  1064. taskItem.Type = Convert.ToInt32(row["assetType"]);
  1065. taskItem.Name = (String)row["name"];
  1066. taskItem.Description = (String)row["description"];
  1067. taskItem.CreationDate = Convert.ToUInt32(row["creationDate"]);
  1068. taskItem.CreatorID = DBGuid.FromDB(row["creatorID"]);
  1069. taskItem.OwnerID = DBGuid.FromDB(row["ownerID"]);
  1070. taskItem.LastOwnerID = DBGuid.FromDB(row["lastOwnerID"]);
  1071. taskItem.GroupID = DBGuid.FromDB(row["groupID"]);
  1072. taskItem.NextPermissions = Convert.ToUInt32(row["nextPermissions"]);
  1073. taskItem.CurrentPermissions = Convert.ToUInt32(row["currentPermissions"]);
  1074. taskItem.BasePermissions = Convert.ToUInt32(row["basePermissions"]);
  1075. taskItem.EveryonePermissions = Convert.ToUInt32(row["everyonePermissions"]);
  1076. taskItem.GroupPermissions = Convert.ToUInt32(row["groupPermissions"]);
  1077. taskItem.Flags = Convert.ToUInt32(row["flags"]);
  1078. return taskItem;
  1079. }
  1080. private static RegionSettings BuildRegionSettings(IDataReader row)
  1081. {
  1082. RegionSettings newSettings = new RegionSettings();
  1083. newSettings.RegionUUID = DBGuid.FromDB(row["regionUUID"]);
  1084. newSettings.BlockTerraform = Convert.ToBoolean(row["block_terraform"]);
  1085. newSettings.AllowDamage = Convert.ToBoolean(row["allow_damage"]);
  1086. newSettings.BlockFly = Convert.ToBoolean(row["block_fly"]);
  1087. newSettings.RestrictPushing = Convert.ToBoolean(row["restrict_pushing"]);
  1088. newSettings.AllowLandResell = Convert.ToBoolean(row["allow_land_resell"]);
  1089. newSettings.AllowLandJoinDivide = Convert.ToBoolean(row["allow_land_join_divide"]);
  1090. newSettings.BlockShowInSearch = Convert.ToBoolean(row["block_show_in_search"]);
  1091. newSettings.AgentLimit = Convert.ToInt32(row["agent_limit"]);
  1092. newSettings.ObjectBonus = Convert.ToDouble(row["object_bonus"]);
  1093. newSettings.Maturity = Convert.ToInt32(row["maturity"]);
  1094. newSettings.DisableScripts = Convert.ToBoolean(row["disable_scripts"]);
  1095. newSettings.DisableCollisions = Convert.ToBoolean(row["disable_collisions"]);
  1096. newSettings.DisablePhysics = Convert.ToBoolean(row["disable_physics"]);
  1097. newSettings.TerrainTexture1 = DBGuid.FromDB(row["terrain_texture_1"]);
  1098. newSettings.TerrainTexture2 = DBGuid.FromDB(row["terrain_texture_2"]);
  1099. newSettings.TerrainTexture3 = DBGuid.FromDB(row["terrain_texture_3"]);
  1100. newSettings.TerrainTexture4 = DBGuid.FromDB(row["terrain_texture_4"]);
  1101. newSettings.Elevation1NW = Convert.ToDouble(row["elevation_1_nw"]);
  1102. newSettings.Elevation2NW = Convert.ToDouble(row["elevation_2_nw"]);
  1103. newSettings.Elevation1NE = Convert.ToDouble(row["elevation_1_ne"]);
  1104. newSettings.Elevation2NE = Convert.ToDouble(row["elevation_2_ne"]);
  1105. newSettings.Elevation1SE = Convert.ToDouble(row["elevation_1_se"]);
  1106. newSettings.Elevation2SE = Convert.ToDouble(row["elevation_2_se"]);
  1107. newSettings.Elevation1SW = Convert.ToDouble(row["elevation_1_sw"]);
  1108. newSettings.Elevation2SW = Convert.ToDouble(row["elevation_2_sw"]);
  1109. newSettings.WaterHeight = Convert.ToDouble(row["water_height"]);
  1110. newSettings.TerrainRaiseLimit = Convert.ToDouble(row["terrain_raise_limit"]);
  1111. newSettings.TerrainLowerLimit = Convert.ToDouble(row["terrain_lower_limit"]);
  1112. newSettings.UseEstateSun = Convert.ToBoolean(row["use_estate_sun"]);
  1113. newSettings.Sandbox = Convert.ToBoolean(row["sandbox"]);
  1114. newSettings.SunVector = new Vector3 (
  1115. Convert.ToSingle(row["sunvectorx"]),
  1116. Convert.ToSingle(row["sunvectory"]),
  1117. Convert.ToSingle(row["sunvectorz"])
  1118. );
  1119. newSettings.FixedSun = Convert.ToBoolean(row["fixed_sun"]);
  1120. newSettings.SunPosition = Convert.ToDouble(row["sun_position"]);
  1121. newSettings.Covenant = DBGuid.FromDB(row["covenant"]);
  1122. newSettings.LoadedCreationDateTime = Convert.ToInt32(row["loaded_creation_datetime"]);
  1123. if (row["loaded_creation_id"] is DBNull)
  1124. newSettings.LoadedCreationID = "";
  1125. else
  1126. newSettings.LoadedCreationID = (String) row["loaded_creation_id"];
  1127. newSettings.TerrainImageID = DBGuid.FromDB(row["map_tile_ID"]);
  1128. return newSettings;
  1129. }
  1130. /// <summary>
  1131. ///
  1132. /// </summary>
  1133. /// <param name="row"></param>
  1134. /// <returns></returns>
  1135. private static LandData BuildLandData(IDataReader row)
  1136. {
  1137. LandData newData = new LandData();
  1138. newData.GlobalID = DBGuid.FromDB(row["UUID"]);
  1139. newData.LocalID = Convert.ToInt32(row["LocalLandID"]);
  1140. // Bitmap is a byte[512]
  1141. newData.Bitmap = (Byte[]) row["Bitmap"];
  1142. newData.Name = (String) row["Name"];
  1143. newData.Description = (String) row["Description"];
  1144. newData.OwnerID = DBGuid.FromDB(row["OwnerUUID"]);
  1145. newData.IsGroupOwned = Convert.ToBoolean(row["IsGroupOwned"]);
  1146. newData.Area = Convert.ToInt32(row["Area"]);
  1147. newData.AuctionID = Convert.ToUInt32(row["AuctionID"]); //Unimplemented
  1148. newData.Category = (ParcelCategory) Convert.ToInt32(row["Category"]);
  1149. //Enum libsecondlife.Parcel.ParcelCategory
  1150. newData.ClaimDate = Convert.ToInt32(row["ClaimDate"]);
  1151. newData.ClaimPrice = Convert.ToInt32(row["ClaimPrice"]);
  1152. newData.GroupID = DBGuid.FromDB(row["GroupUUID"]);
  1153. newData.SalePrice = Convert.ToInt32(row["SalePrice"]);
  1154. newData.Status = (ParcelStatus) Convert.ToInt32(row["LandStatus"]);
  1155. //Enum. libsecondlife.Parcel.ParcelStatus
  1156. newData.Flags = Convert.ToUInt32(row["LandFlags"]);
  1157. newData.LandingType = Convert.ToByte(row["LandingType"]);
  1158. newData.MediaAutoScale = Convert.ToByte(row["MediaAutoScale"]);
  1159. newData.MediaID = DBGuid.FromDB(row["MediaTextureUUID"]);
  1160. newData.MediaURL = (String) row["MediaURL"];
  1161. newData.MusicURL = (String) row["MusicURL"];
  1162. newData.PassHours = Convert.ToSingle(row["PassHours"]);
  1163. newData.PassPrice = Convert.ToInt32(row["PassPrice"]);
  1164. UUID authedbuyer = UUID.Zero;
  1165. UUID snapshotID = UUID.Zero;
  1166. UUID.TryParse((string)row["AuthBuyerID"], out authedbuyer);
  1167. UUID.TryParse((string)row["SnapshotUUID"], out snapshotID);
  1168. newData.OtherCleanTime = Convert.ToInt32(row["OtherCleanTime"]);
  1169. newData.Dwell = Convert.ToInt32(row["Dwell"]);
  1170. newData.AuthBuyerID = authedbuyer;
  1171. newData.SnapshotID = snapshotID;
  1172. try
  1173. {
  1174. newData.UserLocation =
  1175. new Vector3(Convert.ToSingle(row["UserLocationX"]), Convert.ToSingle(row["UserLocationY"]),
  1176. Convert.ToSingle(row["UserLocationZ"]));
  1177. newData.UserLookAt =
  1178. new Vector3(Convert.ToSingle(row["UserLookAtX"]), Convert.ToSingle(row["UserLookAtY"]),
  1179. Convert.ToSingle(row["UserLookAtZ"]));
  1180. }
  1181. catch (InvalidCastException)
  1182. {
  1183. newData.UserLocation = Vector3.Zero;
  1184. newData.UserLookAt = Vector3.Zero;
  1185. m_log.ErrorFormat("[PARCEL]: unable to get parcel telehub settings for {1}", newData.Name);
  1186. }
  1187. newData.ParcelAccessList = new List<ParcelManager.ParcelAccessEntry>();
  1188. return newData;
  1189. }
  1190. /// <summary>
  1191. ///
  1192. /// </summary>
  1193. /// <param name="row"></param>
  1194. /// <returns></returns>
  1195. private static ParcelManager.ParcelAccessEntry BuildLandAccessData(IDataReader row)
  1196. {
  1197. ParcelManager.ParcelAccessEntry entry = new ParcelManager.ParcelAccessEntry();
  1198. entry.AgentID = DBGuid.FromDB(row["AccessUUID"]);
  1199. entry.Flags = (AccessList) Convert.ToInt32(row["Flags"]);
  1200. entry.Time = new DateTime();
  1201. return entry;
  1202. }
  1203. /// <summary>
  1204. ///
  1205. /// </summary>
  1206. /// <param name="val"></param>
  1207. /// <returns></returns>
  1208. private static Array SerializeTerrain(double[,] val)
  1209. {
  1210. MemoryStream str = new MemoryStream(((int)Constants.RegionSize * (int)Constants.RegionSize) *sizeof (double));
  1211. BinaryWriter bw = new BinaryWriter(str);
  1212. // TODO: COMPATIBILITY - Add byte-order conversions
  1213. for (int x = 0; x < (int)Constants.RegionSize; x++)
  1214. for (int y = 0; y < (int)Constants.RegionSize; y++)
  1215. {
  1216. double height = val[x, y];
  1217. if (height == 0.0)
  1218. height = double.Epsilon;
  1219. bw.Write(height);
  1220. }
  1221. return str.ToArray();
  1222. }
  1223. /// <summary>
  1224. /// Fill the prim command with prim values
  1225. /// </summary>
  1226. /// <param name="row"></param>
  1227. /// <param name="prim"></param>
  1228. /// <param name="sceneGroupID"></param>
  1229. /// <param name="regionUUID"></param>
  1230. private void FillPrimCommand(MySqlCommand cmd, SceneObjectPart prim, UUID sceneGroupID, UUID regionUUID)
  1231. {
  1232. cmd.Parameters.AddWithValue("UUID", prim.UUID.ToString());
  1233. cmd.Parameters.AddWithValue("RegionUUID", regionUUID.ToString());
  1234. cmd.Parameters.AddWithValue("CreationDate", prim.CreationDate);
  1235. cmd.Parameters.AddWithValue("Name", prim.Name);
  1236. cmd.Parameters.AddWithValue("SceneGroupID", sceneGroupID.ToString());
  1237. // the UUID of the root part for this SceneObjectGroup
  1238. // various text fields
  1239. cmd.Parameters.AddWithValue("Text", prim.Text);
  1240. cmd.Parameters.AddWithValue("ColorR", prim.Color.R);
  1241. cmd.Parameters.AddWithValue("ColorG", prim.Color.G);
  1242. cmd.Parameters.AddWithValue("ColorB", prim.Color.B);
  1243. cmd.Parameters.AddWithValue("ColorA", prim.Color.A);
  1244. cmd.Parameters.AddWithValue("Description", prim.Description);
  1245. cmd.Parameters.AddWithValue("SitName", prim.SitName);
  1246. cmd.Parameters.AddWithValue("TouchName", prim.TouchName);
  1247. // permissions
  1248. cmd.Parameters.AddWithValue("ObjectFlags", (uint)prim.Flags);
  1249. cmd.Parameters.AddWithValue("CreatorID", prim.CreatorID.ToString());
  1250. cmd.Parameters.AddWithValue("OwnerID", prim.OwnerID.ToString());
  1251. cmd.Parameters.AddWithValue("GroupID", prim.GroupID.ToString());
  1252. cmd.Parameters.AddWithValue("LastOwnerID", prim.LastOwnerID.ToString());
  1253. cmd.Parameters.AddWithValue("OwnerMask", prim.OwnerMask);
  1254. cmd.Parameters.AddWithValue("NextOwnerMask", prim.NextOwnerMask);
  1255. cmd.Parameters.AddWithValue("GroupMask", prim.GroupMask);
  1256. cmd.Parameters.AddWithValue("EveryoneMask", prim.EveryoneMask);
  1257. cmd.Parameters.AddWithValue("BaseMask", prim.BaseMask);
  1258. // vectors
  1259. cmd.Parameters.AddWithValue("PositionX", (double)prim.OffsetPosition.X);
  1260. cmd.Parameters.AddWithValue("PositionY", (double)prim.OffsetPosition.Y);
  1261. cmd.Parameters.AddWithValue("PositionZ", (double)prim.OffsetPosition.Z);
  1262. cmd.Parameters.AddWithValue("GroupPositionX", (double)prim.GroupPosition.X);
  1263. cmd.Parameters.AddWithValue("GroupPositionY", (double)prim.GroupPosition.Y);
  1264. cmd.Parameters.AddWithValue("GroupPositionZ", (double)prim.GroupPosition.Z);
  1265. cmd.Parameters.AddWithValue("VelocityX", (double)prim.Velocity.X);
  1266. cmd.Parameters.AddWithValue("VelocityY", (double)prim.Velocity.Y);
  1267. cmd.Parameters.AddWithValue("VelocityZ", (double)prim.Velocity.Z);
  1268. cmd.Parameters.AddWithValue("AngularVelocityX", (double)prim.AngularVelocity.X);
  1269. cmd.Parameters.AddWithValue("AngularVelocityY", (double)prim.AngularVelocity.Y);
  1270. cmd.Parameters.AddWithValue("AngularVelocityZ", (double)prim.AngularVelocity.Z);
  1271. cmd.Parameters.AddWithValue("AccelerationX", (double)prim.Acceleration.X);
  1272. cmd.Parameters.AddWithValue("AccelerationY", (double)prim.Acceleration.Y);
  1273. cmd.Parameters.AddWithValue("AccelerationZ", (double)prim.Acceleration.Z);
  1274. // quaternions
  1275. cmd.Parameters.AddWithValue("RotationX", (double)prim.RotationOffset.X);
  1276. cmd.Parameters.AddWithValue("RotationY", (double)prim.RotationOffset.Y);
  1277. cmd.Parameters.AddWithValue("RotationZ", (double)prim.RotationOffset.Z);
  1278. cmd.Parameters.AddWithValue("RotationW", (double)prim.RotationOffset.W);
  1279. // Sit target
  1280. Vector3 sitTargetPos = prim.SitTargetPositionLL;
  1281. cmd.Parameters.AddWithValue("SitTargetOffsetX", (double)sitTargetPos.X);
  1282. cmd.Parameters.AddWithValue("SitTargetOffsetY", (double)sitTargetPos.Y);
  1283. cmd.Parameters.AddWithValue("SitTargetOffsetZ", (double)sitTargetPos.Z);
  1284. Quaternion sitTargetOrient = prim.SitTargetOrientationLL;
  1285. cmd.Parameters.AddWithValue("SitTargetOrientW", (double)sitTargetOrient.W);
  1286. cmd.Parameters.AddWithValue("SitTargetOrientX", (double)sitTargetOrient.X);
  1287. cmd.Parameters.AddWithValue("SitTargetOrientY", (double)sitTargetOrient.Y);
  1288. cmd.Parameters.AddWithValue("SitTargetOrientZ", (double)sitTargetOrient.Z);
  1289. cmd.Parameters.AddWithValue("PayPrice", prim.PayPrice[0]);
  1290. cmd.Parameters.AddWithValue("PayButton1", prim.PayPrice[1]);
  1291. cmd.Parameters.AddWithValue("PayButton2", prim.PayPrice[2]);
  1292. cmd.Parameters.AddWithValue("PayButton3", prim.PayPrice[3]);
  1293. cmd.Parameters.AddWithValue("PayButton4", prim.PayPrice[4]);
  1294. if ((prim.SoundFlags & 1) != 0) // Looped
  1295. {
  1296. cmd.Parameters.AddWithValue("LoopedSound", prim.Sound.ToString());
  1297. cmd.Parameters.AddWithValue("LoopedSoundGain", prim.SoundGain);
  1298. }
  1299. else
  1300. {
  1301. cmd.Parameters.AddWithValue("LoopedSound", UUID.Zero);
  1302. cmd.Parameters.AddWithValue("LoopedSoundGain", 0.0f);
  1303. }
  1304. cmd.Parameters.AddWithValue("TextureAnimation", prim.TextureAnimation);
  1305. cmd.Parameters.AddWithValue("ParticleSystem", prim.ParticleSystem);
  1306. cmd.Parameters.AddWithValue("OmegaX", (double)prim.AngularVelocity.X);
  1307. cmd.Parameters.AddWithValue("OmegaY", (double)prim.AngularVelocity.Y);
  1308. cmd.Parameters.AddWithValue("OmegaZ", (double)prim.AngularVelocity.Z);
  1309. cmd.Parameters.AddWithValue("CameraEyeOffsetX", (double)prim.GetCameraEyeOffset().X);
  1310. cmd.Parameters.AddWithValue("CameraEyeOffsetY", (double)prim.GetCameraEyeOffset().Y);
  1311. cmd.Parameters.AddWithValue("CameraEyeOffsetZ", (double)prim.GetCameraEyeOffset().Z);
  1312. cmd.Parameters.AddWithValue("CameraAtOffsetX", (double)prim.GetCameraAtOffset().X);
  1313. cmd.Parameters.AddWithValue("CameraAtOffsetY", (double)prim.GetCameraAtOffset().Y);
  1314. cmd.Parameters.AddWithValue("CameraAtOffsetZ", (double)prim.GetCameraAtOffset().Z);
  1315. if (prim.GetForceMouselook())
  1316. cmd.Parameters.AddWithValue("ForceMouselook", 1);
  1317. else
  1318. cmd.Parameters.AddWithValue("ForceMouselook", 0);
  1319. cmd.Parameters.AddWithValue("ScriptAccessPin", prim.ScriptAccessPin);
  1320. if (prim.AllowedDrop)
  1321. cmd.Parameters.AddWithValue("AllowedDrop", 1);
  1322. else
  1323. cmd.Parameters.AddWithValue("AllowedDrop", 0);
  1324. if (prim.DIE_AT_EDGE)
  1325. cmd.Parameters.AddWithValue("DieAtEdge", 1);
  1326. else
  1327. cmd.Parameters.AddWithValue("DieAtEdge", 0);
  1328. cmd.Parameters.AddWithValue("SalePrice", prim.SalePrice);
  1329. cmd.Parameters.AddWithValue("SaleType", unchecked((sbyte)(prim.ObjectSaleType)));
  1330. byte clickAction = prim.ClickAction;
  1331. cmd.Parameters.AddWithValue("ClickAction", unchecked((sbyte)(clickAction)));
  1332. cmd.Parameters.AddWithValue("Material", unchecked((sbyte)(prim.Material)));
  1333. cmd.Parameters.AddWithValue("CollisionSound", prim.CollisionSound.ToString());
  1334. cmd.Parameters.AddWithValue("CollisionSoundVolume", prim.CollisionSoundVolume);
  1335. if (prim.PassTouches)
  1336. cmd.Parameters.AddWithValue("PassTouches", 1);
  1337. else
  1338. cmd.Parameters.AddWithValue("PassTouches", 0);
  1339. cmd.Parameters.AddWithValue("LinkNumber", prim.LinkNum);
  1340. cmd.Parameters.AddWithValue("MediaURL", prim.MediaUrl);
  1341. }
  1342. /// <summary>
  1343. ///
  1344. /// </summary>
  1345. /// <param name="row"></param>
  1346. /// <param name="taskItem"></param>
  1347. private static void FillItemCommand(MySqlCommand cmd, TaskInventoryItem taskItem)
  1348. {
  1349. cmd.Parameters.AddWithValue("itemID", taskItem.ItemID);
  1350. cmd.Parameters.AddWithValue("primID", taskItem.ParentPartID);
  1351. cmd.Parameters.AddWithValue("assetID", taskItem.AssetID);
  1352. cmd.Parameters.AddWithValue("parentFolderID", taskItem.ParentID);
  1353. cmd.Parameters.AddWithValue("invType", taskItem.InvType);
  1354. cmd.Parameters.AddWithValue("assetType", taskItem.Type);
  1355. cmd.Parameters.AddWithValue("name", taskItem.Name);
  1356. cmd.Parameters.AddWithValue("description", taskItem.Description);
  1357. cmd.Parameters.AddWithValue("creationDate", taskItem.CreationDate);
  1358. cmd.Parameters.AddWithValue("creatorID", taskItem.CreatorID);
  1359. cmd.Parameters.AddWithValue("ownerID", taskItem.OwnerID);
  1360. cmd.Parameters.AddWithValue("lastOwnerID", taskItem.LastOwnerID);
  1361. cmd.Parameters.AddWithValue("groupID", taskItem.GroupID);
  1362. cmd.Parameters.AddWithValue("nextPermissions", taskItem.NextPermissions);
  1363. cmd.Parameters.AddWithValue("currentPermissions", taskItem.CurrentPermissions);
  1364. cmd.Parameters.AddWithValue("basePermissions", taskItem.BasePermissions);
  1365. cmd.Parameters.AddWithValue("everyonePermissions", taskItem.EveryonePermissions);
  1366. cmd.Parameters.AddWithValue("groupPermissions", taskItem.GroupPermissions);
  1367. cmd.Parameters.AddWithValue("flags", taskItem.Flags);
  1368. }
  1369. /// <summary>
  1370. ///
  1371. /// </summary>
  1372. private static void FillRegionSettingsCommand(MySqlCommand cmd, RegionSettings settings)
  1373. {
  1374. cmd.Parameters.AddWithValue("RegionUUID", settings.RegionUUID.ToString());
  1375. cmd.Parameters.AddWithValue("BlockTerraform", settings.BlockTerraform);
  1376. cmd.Parameters.AddWithValue("BlockFly", settings.BlockFly);
  1377. cmd.Parameters.AddWithValue("AllowDamage", settings.AllowDamage);
  1378. cmd.Parameters.AddWithValue("RestrictPushing", settings.RestrictPushing);
  1379. cmd.Parameters.AddWithValue("AllowLandResell", settings.AllowLandResell);
  1380. cmd.Parameters.AddWithValue("AllowLandJoinDivide", settings.AllowLandJoinDivide);
  1381. cmd.Parameters.AddWithValue("BlockShowInSearch", settings.BlockShowInSearch);
  1382. cmd.Parameters.AddWithValue("AgentLimit", settings.AgentLimit);
  1383. cmd.Parameters.AddWithValue("ObjectBonus", settings.ObjectBonus);
  1384. cmd.Parameters.AddWithValue("Maturity", settings.Maturity);
  1385. cmd.Parameters.AddWithValue("DisableScripts", settings.DisableScripts);
  1386. cmd.Parameters.AddWithValue("DisableCollisions", settings.DisableCollisions);
  1387. cmd.Parameters.AddWithValue("DisablePhysics", settings.DisablePhysics);
  1388. cmd.Parameters.AddWithValue("TerrainTexture1", settings.TerrainTexture1.ToString());
  1389. cmd.Parameters.AddWithValue("TerrainTexture2", settings.TerrainTexture2.ToString());
  1390. cmd.Parameters.AddWithValue("TerrainTexture3", settings.TerrainTexture3.ToString());
  1391. cmd.Parameters.AddWithValue("TerrainTexture4", settings.TerrainTexture4.ToString());
  1392. cmd.Parameters.AddWithValue("Elevation1NW", settings.Elevation1NW);
  1393. cmd.Parameters.AddWithValue("Elevation2NW", settings.Elevation2NW);
  1394. cmd.Parameters.AddWithValue("Elevation1NE", settings.Elevation1NE);
  1395. cmd.Parameters.AddWithValue("Elevation2NE", settings.Elevation2NE);
  1396. cmd.Parameters.AddWithValue("Elevation1SE", settings.Elevation1SE);
  1397. cmd.Parameters.AddWithValue("Elevation2SE", settings.Elevation2SE);
  1398. cmd.Parameters.AddWithValue("Elevation1SW", settings.Elevation1SW);
  1399. cmd.Parameters.AddWithValue("Elevation2SW", settings.Elevation2SW);
  1400. cmd.Parameters.AddWithValue("WaterHeight", settings.WaterHeight);
  1401. cmd.Parameters.AddWithValue("TerrainRaiseLimit", settings.TerrainRaiseLimit);
  1402. cmd.Parameters.AddWithValue("TerrainLowerLimit", settings.TerrainLowerLimit);
  1403. cmd.Parameters.AddWithValue("UseEstateSun", settings.UseEstateSun);
  1404. cmd.Parameters.AddWithValue("Sandbox", settings.Sandbox);
  1405. cmd.Parameters.AddWithValue("SunVectorX", settings.SunVector.X);
  1406. cmd.Parameters.AddWithValue("SunVectorY", settings.SunVector.Y);
  1407. cmd.Parameters.AddWithValue("SunVectorZ", settings.SunVector.Z);
  1408. cmd.Parameters.AddWithValue("FixedSun", settings.FixedSun);
  1409. cmd.Parameters.AddWithValue("SunPosition", settings.SunPosition);
  1410. cmd.Parameters.AddWithValue("Covenant", settings.Covenant.ToString());
  1411. cmd.Parameters.AddWithValue("LoadedCreationDateTime", settings.LoadedCreationDateTime);
  1412. cmd.Parameters.AddWithValue("LoadedCreationID", settings.LoadedCreationID);
  1413. cmd.Parameters.AddWithValue("TerrainImageID", settings.TerrainImageID);
  1414. }
  1415. /// <summary>
  1416. ///
  1417. /// </summary>
  1418. /// <param name="row"></param>
  1419. /// <param name="land"></param>
  1420. /// <param name="regionUUID"></param>
  1421. private static void FillLandCommand(MySqlCommand cmd, LandData land, UUID regionUUID)
  1422. {
  1423. cmd.Parameters.AddWithValue("UUID", land.GlobalID.ToString());
  1424. cmd.Parameters.AddWithValue("RegionUUID", regionUUID.ToString());
  1425. cmd.Parameters.AddWithValue("LocalLandID", land.LocalID);
  1426. // Bitmap is a byte[512]
  1427. cmd.Parameters.AddWithValue("Bitmap", land.Bitmap);
  1428. cmd.Parameters.AddWithValue("Name", land.Name);
  1429. cmd.Parameters.AddWithValue("Description", land.Description);
  1430. cmd.Parameters.AddWithValue("OwnerUUID", land.OwnerID.ToString());
  1431. cmd.Parameters.AddWithValue("IsGroupOwned", land.IsGroupOwned);
  1432. cmd.Parameters.AddWithValue("Area", land.Area);
  1433. cmd.Parameters.AddWithValue("AuctionID", land.AuctionID); //Unemplemented
  1434. cmd.Parameters.AddWithValue("Category", land.Category); //Enum libsecondlife.Parcel.ParcelCategory
  1435. cmd.Parameters.AddWithValue("ClaimDate", land.ClaimDate);
  1436. cmd.Parameters.AddWithValue("ClaimPrice", land.ClaimPrice);
  1437. cmd.Parameters.AddWithValue("GroupUUID", land.GroupID.ToString());
  1438. cmd.Parameters.AddWithValue("SalePrice", land.SalePrice);
  1439. cmd.Parameters.AddWithValue("LandStatus", land.Status); //Enum. libsecondlife.Parcel.ParcelStatus
  1440. cmd.Parameters.AddWithValue("LandFlags", land.Flags);
  1441. cmd.Parameters.AddWithValue("LandingType", land.LandingType);
  1442. cmd.Parameters.AddWithValue("MediaAutoScale", land.MediaAutoScale);
  1443. cmd.Parameters.AddWithValue("MediaTextureUUID", land.MediaID.ToString());
  1444. cmd.Parameters.AddWithValue("MediaURL", land.MediaURL);
  1445. cmd.Parameters.AddWithValue("MusicURL", land.MusicURL);
  1446. cmd.Parameters.AddWithValue("PassHours", land.PassHours);
  1447. cmd.Parameters.AddWithValue("PassPrice", land.PassPrice);
  1448. cmd.Parameters.AddWithValue("SnapshotUUID", land.SnapshotID.ToString());
  1449. cmd.Parameters.AddWithValue("UserLocationX", land.UserLocation.X);
  1450. cmd.Parameters.AddWithValue("UserLocationY", land.UserLocation.Y);
  1451. cmd.Parameters.AddWithValue("UserLocationZ", land.UserLocation.Z);
  1452. cmd.Parameters.AddWithValue("UserLookAtX", land.UserLookAt.X);
  1453. cmd.Parameters.AddWithValue("UserLookAtY", land.UserLookAt.Y);
  1454. cmd.Parameters.AddWithValue("UserLookAtZ", land.UserLookAt.Z);
  1455. cmd.Parameters.AddWithValue("AuthBuyerID", land.AuthBuyerID);
  1456. cmd.Parameters.AddWithValue("OtherCleanTime", land.OtherCleanTime);
  1457. cmd.Parameters.AddWithValue("Dwell", land.Dwell);
  1458. }
  1459. /// <summary>
  1460. ///
  1461. /// </summary>
  1462. /// <param name="row"></param>
  1463. /// <param name="entry"></param>
  1464. /// <param name="parcelID"></param>
  1465. private static void FillLandAccessCommand(MySqlCommand cmd, ParcelManager.ParcelAccessEntry entry, UUID parcelID)
  1466. {
  1467. cmd.Parameters.AddWithValue("LandUUID", parcelID.ToString());
  1468. cmd.Parameters.AddWithValue("AccessUUID", entry.AgentID.ToString());
  1469. cmd.Parameters.AddWithValue("Flags", entry.Flags);
  1470. }
  1471. /// <summary>
  1472. ///
  1473. /// </summary>
  1474. /// <param name="row"></param>
  1475. /// <returns></returns>
  1476. private PrimitiveBaseShape BuildShape(IDataReader row)
  1477. {
  1478. PrimitiveBaseShape s = new PrimitiveBaseShape();
  1479. s.Scale = new Vector3(
  1480. (float)(double)row["ScaleX"],
  1481. (float)(double)row["ScaleY"],
  1482. (float)(double)row["ScaleZ"]
  1483. );
  1484. // paths
  1485. s.PCode = (byte)(int)row["PCode"];
  1486. s.PathBegin = (ushort)(int)row["PathBegin"];
  1487. s.PathEnd = (ushort)(int)row["PathEnd"];
  1488. s.PathScaleX = (byte)(int)row["PathScaleX"];
  1489. s.PathScaleY = (byte)(int)row["PathScaleY"];
  1490. s.PathShearX = (byte)(int)row["PathShearX"];
  1491. s.PathShearY = (byte)(int)row["PathShearY"];
  1492. s.PathSkew = (sbyte)(int)row["PathSkew"];
  1493. s.PathCurve = (byte)(int)row["PathCurve"];
  1494. s.PathRadiusOffset = (sbyte)(int)row["PathRadiusOffset"];
  1495. s.PathRevolutions = (byte)(int)row["PathRevolutions"];
  1496. s.PathTaperX = (sbyte)(int)row["PathTaperX"];
  1497. s.PathTaperY = (sbyte)(int)row["PathTaperY"];
  1498. s.PathTwist = (sbyte)(int)row["PathTwist"];
  1499. s.PathTwistBegin = (sbyte)(int)row["PathTwistBegin"];
  1500. // profile
  1501. s.ProfileBegin = (ushort)(int)row["ProfileBegin"];
  1502. s.ProfileEnd = (ushort)(int)row["ProfileEnd"];
  1503. s.ProfileCurve = (byte)(int)row["ProfileCurve"];
  1504. s.ProfileHollow = (ushort)(int)row["ProfileHollow"];
  1505. s.TextureEntry = (byte[])row["Texture"];
  1506. s.ExtraParams = (byte[])row["ExtraParams"];
  1507. s.State = (byte)(int)row["State"];
  1508. if (!(row["Media"] is System.DBNull))
  1509. s.Media = PrimitiveBaseShape.MediaList.FromXml((string)row["Media"]);
  1510. return s;
  1511. }
  1512. /// <summary>
  1513. ///
  1514. /// </summary>
  1515. /// <param name="row"></param>
  1516. /// <param name="prim"></param>
  1517. private void FillShapeCommand(MySqlCommand cmd, SceneObjectPart prim)
  1518. {
  1519. PrimitiveBaseShape s = prim.Shape;
  1520. cmd.Parameters.AddWithValue("UUID", prim.UUID.ToString());
  1521. // shape is an enum
  1522. cmd.Parameters.AddWithValue("Shape", 0);
  1523. // vectors
  1524. cmd.Parameters.AddWithValue("ScaleX", (double)s.Scale.X);
  1525. cmd.Parameters.AddWithValue("ScaleY", (double)s.Scale.Y);
  1526. cmd.Parameters.AddWithValue("ScaleZ", (double)s.Scale.Z);
  1527. // paths
  1528. cmd.Parameters.AddWithValue("PCode", s.PCode);
  1529. cmd.Parameters.AddWithValue("PathBegin", s.PathBegin);
  1530. cmd.Parameters.AddWithValue("PathEnd", s.PathEnd);
  1531. cmd.Parameters.AddWithValue("PathScaleX", s.PathScaleX);
  1532. cmd.Parameters.AddWithValue("PathScaleY", s.PathScaleY);
  1533. cmd.Parameters.AddWithValue("PathShearX", s.PathShearX);
  1534. cmd.Parameters.AddWithValue("PathShearY", s.PathShearY);
  1535. cmd.Parameters.AddWithValue("PathSkew", s.PathSkew);
  1536. cmd.Parameters.AddWithValue("PathCurve", s.PathCurve);
  1537. cmd.Parameters.AddWithValue("PathRadiusOffset", s.PathRadiusOffset);
  1538. cmd.Parameters.AddWithValue("PathRevolutions", s.PathRevolutions);
  1539. cmd.Parameters.AddWithValue("PathTaperX", s.PathTaperX);
  1540. cmd.Parameters.AddWithValue("PathTaperY", s.PathTaperY);
  1541. cmd.Parameters.AddWithValue("PathTwist", s.PathTwist);
  1542. cmd.Parameters.AddWithValue("PathTwistBegin", s.PathTwistBegin);
  1543. // profile
  1544. cmd.Parameters.AddWithValue("ProfileBegin", s.ProfileBegin);
  1545. cmd.Parameters.AddWithValue("ProfileEnd", s.ProfileEnd);
  1546. cmd.Parameters.AddWithValue("ProfileCurve", s.ProfileCurve);
  1547. cmd.Parameters.AddWithValue("ProfileHollow", s.ProfileHollow);
  1548. cmd.Parameters.AddWithValue("Texture", s.TextureEntry);
  1549. cmd.Parameters.AddWithValue("ExtraParams", s.ExtraParams);
  1550. cmd.Parameters.AddWithValue("State", s.State);
  1551. cmd.Parameters.AddWithValue("Media", null == s.Media ? null : s.Media.ToXml());
  1552. }
  1553. public void StorePrimInventory(UUID primID, ICollection<TaskInventoryItem> items)
  1554. {
  1555. lock (m_dbLock)
  1556. {
  1557. RemoveItems(primID);
  1558. using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
  1559. {
  1560. dbcon.Open();
  1561. MySqlCommand cmd = dbcon.CreateCommand();
  1562. if (items.Count == 0)
  1563. return;
  1564. cmd.CommandText = "insert into primitems (" +
  1565. "invType, assetType, name, " +
  1566. "description, creationDate, nextPermissions, " +
  1567. "currentPermissions, basePermissions, " +
  1568. "everyonePermissions, groupPermissions, " +
  1569. "flags, itemID, primID, assetID, " +
  1570. "parentFolderID, creatorID, ownerID, " +
  1571. "groupID, lastOwnerID) values (?invType, " +
  1572. "?assetType, ?name, ?description, " +
  1573. "?creationDate, ?nextPermissions, " +
  1574. "?currentPermissions, ?basePermissions, " +
  1575. "?everyonePermissions, ?groupPermissions, " +
  1576. "?flags, ?itemID, ?primID, ?assetID, " +
  1577. "?parentFolderID, ?creatorID, ?ownerID, " +
  1578. "?groupID, ?lastOwnerID)";
  1579. foreach (TaskInventoryItem item in items)
  1580. {
  1581. cmd.Parameters.Clear();
  1582. FillItemCommand(cmd, item);
  1583. ExecuteNonQuery(cmd);
  1584. }
  1585. cmd.Dispose();
  1586. }
  1587. }
  1588. }
  1589. }
  1590. }