MySQLSimulationData.cs 92 KB

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