MySQLSimulationData.cs 108 KB

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