MySQLSimulationData.cs 104 KB

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