MySQLSimulationData.cs 103 KB

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