MySQLSimulationData.cs 91 KB

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