1
0

MySQLSimulationData.cs 98 KB

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