MySQLSimulationData.cs 104 KB

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