MySQLSimulationData.cs 103 KB

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