MySQLRegionData.cs 69 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560
  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. namespace OpenSim.Data.MySQL
  41. {
  42. /// <summary>
  43. /// A MySQL Interface for the Region Server
  44. /// </summary>
  45. public class MySQLDataStore : IRegionDataStore
  46. {
  47. private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  48. private string m_ConnectionString;
  49. private MySqlConnection m_Connection = null;
  50. public void Initialise(string connectionString)
  51. {
  52. m_ConnectionString = connectionString;
  53. m_Connection = new MySqlConnection(m_ConnectionString);
  54. m_Connection.Open();
  55. // Apply new Migrations
  56. //
  57. Assembly assem = GetType().Assembly;
  58. Migration m = new Migration(m_Connection, assem, "RegionStore");
  59. m.Update();
  60. // Clean dropped attachments
  61. //
  62. MySqlCommand cmd = m_Connection.CreateCommand();
  63. cmd.CommandText = "delete from prims, primshapes using prims " +
  64. "left join primshapes on prims.uuid = primshapes.uuid " +
  65. "where PCode = 9 and State <> 0";
  66. ExecuteNonQuery(cmd);
  67. cmd.Dispose();
  68. }
  69. private IDataReader ExecuteReader(MySqlCommand c)
  70. {
  71. IDataReader r = null;
  72. bool errorSeen = false;
  73. while (true)
  74. {
  75. try
  76. {
  77. r = c.ExecuteReader();
  78. }
  79. catch (Exception)
  80. {
  81. Thread.Sleep(500);
  82. m_Connection.Close();
  83. m_Connection = (MySqlConnection) ((ICloneable)m_Connection).Clone();
  84. m_Connection.Open();
  85. c.Connection = m_Connection;
  86. if (!errorSeen)
  87. {
  88. errorSeen = true;
  89. continue;
  90. }
  91. throw;
  92. }
  93. break;
  94. }
  95. return r;
  96. }
  97. private void ExecuteNonQuery(MySqlCommand c)
  98. {
  99. bool errorSeen = false;
  100. while (true)
  101. {
  102. try
  103. {
  104. c.ExecuteNonQuery();
  105. }
  106. catch (Exception)
  107. {
  108. Thread.Sleep(500);
  109. m_Connection.Close();
  110. m_Connection = (MySqlConnection) ((ICloneable)m_Connection).Clone();
  111. m_Connection.Open();
  112. c.Connection = m_Connection;
  113. if (!errorSeen)
  114. {
  115. errorSeen = true;
  116. continue;
  117. }
  118. throw;
  119. }
  120. break;
  121. }
  122. }
  123. public void Dispose() {}
  124. public void StoreObject(SceneObjectGroup obj, UUID regionUUID)
  125. {
  126. uint flags = obj.RootPart.GetEffectiveObjectFlags();
  127. // Eligibility check
  128. //
  129. if ((flags & (uint)PrimFlags.Temporary) != 0)
  130. return;
  131. if ((flags & (uint)PrimFlags.TemporaryOnRez) != 0)
  132. return;
  133. lock (m_Connection)
  134. {
  135. MySqlCommand cmd = m_Connection.CreateCommand();
  136. foreach (SceneObjectPart prim in obj.Children.Values)
  137. {
  138. cmd.Parameters.Clear();
  139. cmd.CommandText = "replace into prims ("+
  140. "UUID, CreationDate, "+
  141. "Name, Text, Description, "+
  142. "SitName, TouchName, ObjectFlags, "+
  143. "OwnerMask, NextOwnerMask, GroupMask, "+
  144. "EveryoneMask, BaseMask, PositionX, "+
  145. "PositionY, PositionZ, GroupPositionX, "+
  146. "GroupPositionY, GroupPositionZ, VelocityX, "+
  147. "VelocityY, VelocityZ, AngularVelocityX, "+
  148. "AngularVelocityY, AngularVelocityZ, "+
  149. "AccelerationX, AccelerationY, "+
  150. "AccelerationZ, RotationX, "+
  151. "RotationY, RotationZ, "+
  152. "RotationW, SitTargetOffsetX, "+
  153. "SitTargetOffsetY, SitTargetOffsetZ, "+
  154. "SitTargetOrientW, SitTargetOrientX, "+
  155. "SitTargetOrientY, SitTargetOrientZ, "+
  156. "RegionUUID, CreatorID, "+
  157. "OwnerID, GroupID, "+
  158. "LastOwnerID, SceneGroupID, "+
  159. "PayPrice, PayButton1, "+
  160. "PayButton2, PayButton3, "+
  161. "PayButton4, LoopedSound, "+
  162. "LoopedSoundGain, TextureAnimation, "+
  163. "OmegaX, OmegaY, OmegaZ, "+
  164. "CameraEyeOffsetX, CameraEyeOffsetY, "+
  165. "CameraEyeOffsetZ, CameraAtOffsetX, "+
  166. "CameraAtOffsetY, CameraAtOffsetZ, "+
  167. "ForceMouselook, ScriptAccessPin, "+
  168. "AllowedDrop, DieAtEdge, "+
  169. "SalePrice, SaleType, "+
  170. "ColorR, ColorG, ColorB, ColorA, "+
  171. "ParticleSystem, ClickAction, Material, "+
  172. "CollisionSound, CollisionSoundVolume, "+
  173. "PassTouches, "+
  174. "LinkNumber) values (" + "?UUID, "+
  175. "?CreationDate, ?Name, ?Text, "+
  176. "?Description, ?SitName, ?TouchName, "+
  177. "?ObjectFlags, ?OwnerMask, ?NextOwnerMask, "+
  178. "?GroupMask, ?EveryoneMask, ?BaseMask, "+
  179. "?PositionX, ?PositionY, ?PositionZ, "+
  180. "?GroupPositionX, ?GroupPositionY, "+
  181. "?GroupPositionZ, ?VelocityX, "+
  182. "?VelocityY, ?VelocityZ, ?AngularVelocityX, "+
  183. "?AngularVelocityY, ?AngularVelocityZ, "+
  184. "?AccelerationX, ?AccelerationY, "+
  185. "?AccelerationZ, ?RotationX, "+
  186. "?RotationY, ?RotationZ, "+
  187. "?RotationW, ?SitTargetOffsetX, "+
  188. "?SitTargetOffsetY, ?SitTargetOffsetZ, "+
  189. "?SitTargetOrientW, ?SitTargetOrientX, "+
  190. "?SitTargetOrientY, ?SitTargetOrientZ, "+
  191. "?RegionUUID, ?CreatorID, ?OwnerID, "+
  192. "?GroupID, ?LastOwnerID, ?SceneGroupID, "+
  193. "?PayPrice, ?PayButton1, ?PayButton2, "+
  194. "?PayButton3, ?PayButton4, ?LoopedSound, "+
  195. "?LoopedSoundGain, ?TextureAnimation, "+
  196. "?OmegaX, ?OmegaY, ?OmegaZ, "+
  197. "?CameraEyeOffsetX, ?CameraEyeOffsetY, "+
  198. "?CameraEyeOffsetZ, ?CameraAtOffsetX, "+
  199. "?CameraAtOffsetY, ?CameraAtOffsetZ, "+
  200. "?ForceMouselook, ?ScriptAccessPin, "+
  201. "?AllowedDrop, ?DieAtEdge, ?SalePrice, "+
  202. "?SaleType, ?ColorR, ?ColorG, "+
  203. "?ColorB, ?ColorA, ?ParticleSystem, "+
  204. "?ClickAction, ?Material, ?CollisionSound, "+
  205. "?CollisionSoundVolume, ?PassTouches, ?LinkNumber)";
  206. FillPrimCommand(cmd, prim, obj.UUID, regionUUID);
  207. ExecuteNonQuery(cmd);
  208. cmd.Parameters.Clear();
  209. cmd.CommandText = "replace into primshapes ("+
  210. "UUID, Shape, ScaleX, ScaleY, "+
  211. "ScaleZ, PCode, PathBegin, PathEnd, "+
  212. "PathScaleX, PathScaleY, PathShearX, "+
  213. "PathShearY, PathSkew, PathCurve, "+
  214. "PathRadiusOffset, PathRevolutions, "+
  215. "PathTaperX, PathTaperY, PathTwist, "+
  216. "PathTwistBegin, ProfileBegin, ProfileEnd, "+
  217. "ProfileCurve, ProfileHollow, Texture, "+
  218. "ExtraParams, State) values (?UUID, "+
  219. "?Shape, ?ScaleX, ?ScaleY, ?ScaleZ, "+
  220. "?PCode, ?PathBegin, ?PathEnd, "+
  221. "?PathScaleX, ?PathScaleY, "+
  222. "?PathShearX, ?PathShearY, "+
  223. "?PathSkew, ?PathCurve, ?PathRadiusOffset, "+
  224. "?PathRevolutions, ?PathTaperX, "+
  225. "?PathTaperY, ?PathTwist, "+
  226. "?PathTwistBegin, ?ProfileBegin, "+
  227. "?ProfileEnd, ?ProfileCurve, "+
  228. "?ProfileHollow, ?Texture, ?ExtraParams, "+
  229. "?State)";
  230. FillShapeCommand(cmd, prim);
  231. ExecuteNonQuery(cmd);
  232. }
  233. cmd.Dispose();
  234. }
  235. }
  236. public void RemoveObject(UUID obj, UUID regionUUID)
  237. {
  238. // Formerly, this used to check the region UUID.
  239. // That makes no sense, as we remove the contents of a prim
  240. // unconditionally, but the prim dependent on the region ID.
  241. // So, we would destroy an object and cause hard to detect
  242. // issues if we delete the contents only. Deleting it all may
  243. // cause the loss of a prim, but is cleaner.
  244. // It's also faster because it uses the primary key.
  245. //
  246. lock (m_Connection)
  247. {
  248. MySqlCommand cmd = m_Connection.CreateCommand();
  249. cmd.CommandText = "select UUID from prims where "+
  250. "SceneGroupID= ?UUID";
  251. cmd.Parameters.AddWithValue("UUID", obj.ToString());
  252. List<UUID> uuids = new List<UUID>();
  253. IDataReader reader = ExecuteReader(cmd);
  254. try
  255. {
  256. while (reader.Read())
  257. {
  258. uuids.Add(new UUID(reader["UUID"].ToString()));
  259. }
  260. }
  261. finally
  262. {
  263. reader.Close();
  264. }
  265. // delete the main prims
  266. cmd.CommandText = "delete from prims where SceneGroupID= ?UUID";
  267. ExecuteNonQuery(cmd);
  268. cmd.Dispose();
  269. // there is no way this should be < 1 unless there is
  270. // a very corrupt database, but in that case be extra
  271. // safe anyway.
  272. if (uuids.Count > 0)
  273. {
  274. RemoveShapes(uuids);
  275. RemoveItems(uuids);
  276. }
  277. }
  278. }
  279. /// <summary>
  280. /// Remove all persisted items of the given prim.
  281. /// The caller must acquire the necessrary synchronization locks
  282. /// </summary>
  283. /// <param name="uuid">the Item UUID</param>
  284. private void RemoveItems(UUID uuid)
  285. {
  286. lock (m_Connection)
  287. {
  288. MySqlCommand cmd = m_Connection.CreateCommand();
  289. cmd.CommandText = "delete from primitems where " +
  290. "PrimID = ?PrimID";
  291. cmd.Parameters.AddWithValue("PrimID", uuid.ToString());
  292. ExecuteNonQuery(cmd);
  293. cmd.Dispose();
  294. }
  295. }
  296. /// <summary>
  297. /// Remove all persisted shapes for a list of prims
  298. /// The caller must acquire the necessrary synchronization locks
  299. /// </summary>
  300. /// <param name="uuids">the list of UUIDs</param>
  301. private void RemoveShapes(List<UUID> uuids)
  302. {
  303. lock (m_Connection)
  304. {
  305. string sql = "delete from primshapes where ";
  306. MySqlCommand cmd = m_Connection.CreateCommand();
  307. for (int i = 0; i < uuids.Count; i++)
  308. {
  309. if ((i + 1) == uuids.Count)
  310. {// end of the list
  311. sql += "(UUID = ?UUID" + i + ")";
  312. }
  313. else
  314. {
  315. sql += "(UUID = ?UUID" + i + ") or ";
  316. }
  317. }
  318. cmd.CommandText = sql;
  319. for (int i = 0; i < uuids.Count; i++)
  320. {
  321. cmd.Parameters.AddWithValue("UUID" + i, uuids[i].ToString());
  322. }
  323. ExecuteNonQuery(cmd);
  324. cmd.Dispose();
  325. }
  326. }
  327. /// <summary>
  328. /// Remove all persisted items for a list of prims
  329. /// The caller must acquire the necessrary synchronization locks
  330. /// </summary>
  331. /// <param name="uuids">the list of UUIDs</param>
  332. private void RemoveItems(List<UUID> uuids)
  333. {
  334. lock (m_Connection)
  335. {
  336. string sql = "delete from primitems where ";
  337. MySqlCommand cmd = m_Connection.CreateCommand();
  338. for (int i = 0; i < uuids.Count; i++)
  339. {
  340. if ((i + 1) == uuids.Count)
  341. {// end of the list
  342. sql += "(PrimID = ?PrimID" + i + ")";
  343. }
  344. else
  345. {
  346. sql += "(PrimID = ?PrimID" + i + ") or ";
  347. }
  348. }
  349. cmd.CommandText = sql;
  350. for (int i = 0; i < uuids.Count; i++)
  351. {
  352. cmd.Parameters.AddWithValue("PrimID" + i, uuids[i].ToString());
  353. }
  354. ExecuteNonQuery(cmd);
  355. cmd.Dispose();
  356. }
  357. }
  358. public List<SceneObjectGroup> LoadObjects(UUID regionUUID)
  359. {
  360. UUID lastGroupID = UUID.Zero;
  361. List<SceneObjectGroup> objects = new List<SceneObjectGroup>();
  362. List<SceneObjectPart> prims = new List<SceneObjectPart>();
  363. SceneObjectGroup grp = null;
  364. lock (m_Connection)
  365. {
  366. MySqlCommand cmd = m_Connection.CreateCommand();
  367. cmd.CommandText = "select *, " +
  368. "case when prims.UUID = SceneGroupID " +
  369. "then 0 else 1 end as sort from prims " +
  370. "left join primshapes on prims.UUID = primshapes.UUID "+
  371. "where RegionUUID = ?RegionUUID " +
  372. "order by SceneGroupID asc, sort asc, LinkNumber asc";
  373. cmd.Parameters.AddWithValue("RegionUUID", regionUUID.ToString());
  374. IDataReader reader = ExecuteReader(cmd);
  375. try
  376. {
  377. while (reader.Read())
  378. {
  379. SceneObjectPart prim = BuildPrim(reader);
  380. if (reader["Shape"] is DBNull)
  381. prim.Shape = PrimitiveBaseShape.Default;
  382. else
  383. prim.Shape = BuildShape(reader);
  384. prims.Add(prim);
  385. UUID groupID = new UUID(reader["SceneGroupID"].ToString());
  386. if (groupID != lastGroupID) // New SOG
  387. {
  388. if (grp != null)
  389. objects.Add(grp);
  390. lastGroupID = groupID;
  391. // There sometimes exist OpenSim bugs that 'orphan groups' so that none of the prims are
  392. // recorded as the root prim (for which the UUID must equal the persisted group UUID). In
  393. // this case, force the UUID to be the same as the group UUID so that at least these can be
  394. // deleted (we need to change the UUID so that any other prims in the linkset can also be
  395. // deleted).
  396. if (prim.UUID != groupID && groupID != UUID.Zero)
  397. {
  398. m_log.WarnFormat(
  399. "[REGION DB]: Found root prim {0} {1} at {2} where group was actually {3}. Forcing UUID to group UUID",
  400. prim.Name, prim.UUID, prim.GroupPosition, groupID);
  401. prim.UUID = groupID;
  402. }
  403. grp = new SceneObjectGroup(prim);
  404. }
  405. else
  406. {
  407. // Black magic to preserve link numbers
  408. //
  409. int link = prim.LinkNum;
  410. grp.AddPart(prim);
  411. if (link != 0)
  412. prim.LinkNum = link;
  413. }
  414. }
  415. }
  416. finally
  417. {
  418. reader.Close();
  419. }
  420. if (grp != null)
  421. objects.Add(grp);
  422. cmd.Dispose();
  423. }
  424. foreach (SceneObjectPart part in prims)
  425. LoadItems(part);
  426. m_log.DebugFormat("[REGION DB]: Loaded {0} objects using {1} prims", objects.Count, prims.Count);
  427. return objects;
  428. }
  429. /// <summary>
  430. /// Load in a prim's persisted inventory.
  431. /// </summary>
  432. /// <param name="prim">The prim</param>
  433. private void LoadItems(SceneObjectPart prim)
  434. {
  435. lock (m_Connection)
  436. {
  437. MySqlCommand cmd = m_Connection.CreateCommand();
  438. cmd.CommandText = "select * from primitems where "+
  439. "PrimID = ?PrimID";
  440. cmd.Parameters.AddWithValue("PrimID", prim.UUID.ToString());
  441. IDataReader reader = ExecuteReader(cmd);
  442. List<TaskInventoryItem> inventory =
  443. new List<TaskInventoryItem>();
  444. try
  445. {
  446. while (reader.Read())
  447. {
  448. TaskInventoryItem item = BuildItem(reader);
  449. item.ParentID = prim.UUID; // Values in database are
  450. // often wrong
  451. inventory.Add(item);
  452. }
  453. }
  454. finally
  455. {
  456. reader.Close();
  457. }
  458. cmd.Dispose();
  459. prim.Inventory.RestoreInventoryItems(inventory);
  460. }
  461. }
  462. public void StoreTerrain(double[,] ter, UUID regionID)
  463. {
  464. m_log.Info("[REGION DB]: Storing terrain");
  465. lock (m_Connection)
  466. {
  467. MySqlCommand cmd = m_Connection.CreateCommand();
  468. cmd.CommandText = "delete from terrain where " +
  469. "RegionUUID = ?RegionUUID";
  470. cmd.Parameters.AddWithValue("RegionUUID", regionID.ToString());
  471. ExecuteNonQuery(cmd);
  472. cmd.CommandText = "insert into terrain (RegionUUID, " +
  473. "Revision, Heightfield) values (?RegionUUID, " +
  474. "1, ?Heightfield)";
  475. cmd.Parameters.AddWithValue("Heightfield",
  476. SerializeTerrain(ter));
  477. ExecuteNonQuery(cmd);
  478. cmd.Dispose();
  479. }
  480. }
  481. public double[,] LoadTerrain(UUID regionID)
  482. {
  483. double[,] terrain = null;
  484. lock (m_Connection)
  485. {
  486. MySqlCommand cmd = m_Connection.CreateCommand();
  487. cmd.CommandText = "select RegionUUID, Revision, Heightfield " +
  488. "from terrain where RegionUUID = ?RegionUUID "+
  489. "order by Revision desc limit 1";
  490. cmd.Parameters.AddWithValue("RegionUUID", regionID.ToString());
  491. IDataReader reader = ExecuteReader(cmd);
  492. try
  493. {
  494. while (reader.Read())
  495. {
  496. terrain = new double[256,256];
  497. terrain.Initialize();
  498. MemoryStream mstr = new MemoryStream((byte[]) reader["Heightfield"]);
  499. int rev = 0;
  500. BinaryReader br = new BinaryReader(mstr);
  501. for (int x = 0; x < 256; x++)
  502. {
  503. for (int y = 0; y < 256; y++)
  504. {
  505. terrain[x, y] = br.ReadDouble();
  506. }
  507. rev = Convert.ToInt32(reader["Revision"]);
  508. }
  509. m_log.InfoFormat("[REGION DB]: Loaded terrain " +
  510. "revision r{0}", rev);
  511. }
  512. }
  513. finally
  514. {
  515. reader.Close();
  516. }
  517. cmd.Dispose();
  518. }
  519. return terrain;
  520. }
  521. public void RemoveLandObject(UUID globalID)
  522. {
  523. lock (m_Connection)
  524. {
  525. MySqlCommand cmd = m_Connection.CreateCommand();
  526. cmd.CommandText = "delete from land where UUID = ?UUID";
  527. cmd.Parameters.AddWithValue("UUID", globalID.ToString());
  528. ExecuteNonQuery(cmd);
  529. cmd.Dispose();
  530. }
  531. }
  532. public void StoreLandObject(ILandObject parcel)
  533. {
  534. lock (m_Connection)
  535. {
  536. MySqlCommand cmd = m_Connection.CreateCommand();
  537. cmd.CommandText = "replace into land (UUID, RegionUUID, " +
  538. "LocalLandID, Bitmap, Name, Description, " +
  539. "OwnerUUID, IsGroupOwned, Area, AuctionID, " +
  540. "Category, ClaimDate, ClaimPrice, GroupUUID, " +
  541. "SalePrice, LandStatus, LandFlags, LandingType, " +
  542. "MediaAutoScale, MediaTextureUUID, MediaURL, " +
  543. "MusicURL, PassHours, PassPrice, SnapshotUUID, " +
  544. "UserLocationX, UserLocationY, UserLocationZ, " +
  545. "UserLookAtX, UserLookAtY, UserLookAtZ, " +
  546. "AuthbuyerID, OtherCleanTime, Dwell) values (" +
  547. "?UUID, ?RegionUUID, " +
  548. "?LocalLandID, ?Bitmap, ?Name, ?Description, " +
  549. "?OwnerUUID, ?IsGroupOwned, ?Area, ?AuctionID, " +
  550. "?Category, ?ClaimDate, ?ClaimPrice, ?GroupUUID, " +
  551. "?SalePrice, ?LandStatus, ?LandFlags, ?LandingType, " +
  552. "?MediaAutoScale, ?MediaTextureUUID, ?MediaURL, " +
  553. "?MusicURL, ?PassHours, ?PassPrice, ?SnapshotUUID, " +
  554. "?UserLocationX, ?UserLocationY, ?UserLocationZ, " +
  555. "?UserLookAtX, ?UserLookAtY, ?UserLookAtZ, " +
  556. "?AuthbuyerID, ?OtherCleanTime, ?Dwell)";
  557. FillLandCommand(cmd, parcel.landData, parcel.regionUUID);
  558. ExecuteNonQuery(cmd);
  559. cmd.CommandText = "delete from landaccesslist where " +
  560. "LandUUID = ?UUID";
  561. ExecuteNonQuery(cmd);
  562. cmd.Parameters.Clear();
  563. cmd.CommandText = "insert into landaccesslist (LandUUID, " +
  564. "AccessUUID, Flags) values (?LandUUID, ?AccessUUID, " +
  565. "?Flags)";
  566. foreach (ParcelManager.ParcelAccessEntry entry in
  567. parcel.landData.ParcelAccessList)
  568. {
  569. FillLandAccessCommand(cmd, entry, parcel.landData.GlobalID);
  570. ExecuteNonQuery(cmd);
  571. cmd.Parameters.Clear();
  572. }
  573. cmd.Dispose();
  574. }
  575. }
  576. public RegionSettings LoadRegionSettings(UUID regionUUID)
  577. {
  578. RegionSettings rs = null;
  579. lock (m_Connection)
  580. {
  581. MySqlCommand cmd = m_Connection.CreateCommand();
  582. cmd.CommandText = "select * from regionsettings where " +
  583. "regionUUID = ?RegionUUID";
  584. cmd.Parameters.AddWithValue("regionUUID", regionUUID);
  585. IDataReader reader = ExecuteReader(cmd);
  586. try
  587. {
  588. if (reader.Read())
  589. {
  590. rs = BuildRegionSettings(reader);
  591. rs.OnSave += StoreRegionSettings;
  592. }
  593. else
  594. {
  595. rs = new RegionSettings();
  596. rs.RegionUUID = regionUUID;
  597. rs.OnSave += StoreRegionSettings;
  598. StoreRegionSettings(rs);
  599. }
  600. }
  601. finally
  602. {
  603. reader.Close();
  604. }
  605. cmd.Dispose();
  606. }
  607. return rs;
  608. }
  609. public void StoreRegionSettings(RegionSettings rs)
  610. {
  611. lock (m_Connection)
  612. {
  613. MySqlCommand cmd = m_Connection.CreateCommand();
  614. cmd.CommandText = "replace into regionsettings (regionUUID, " +
  615. "block_terraform, block_fly, allow_damage, " +
  616. "restrict_pushing, allow_land_resell, " +
  617. "allow_land_join_divide, block_show_in_search, " +
  618. "agent_limit, object_bonus, maturity, " +
  619. "disable_scripts, disable_collisions, " +
  620. "disable_physics, terrain_texture_1, " +
  621. "terrain_texture_2, terrain_texture_3, " +
  622. "terrain_texture_4, elevation_1_nw, " +
  623. "elevation_2_nw, elevation_1_ne, " +
  624. "elevation_2_ne, elevation_1_se, "+
  625. "elevation_2_se, elevation_1_sw, "+
  626. "elevation_2_sw, water_height, " +
  627. "terrain_raise_limit, terrain_lower_limit, " +
  628. "use_estate_sun, fixed_sun, sun_position, " +
  629. "covenant, Sandbox, sunvectorx, sunvectory, " +
  630. "sunvectorz, loaded_creation_datetime, " +
  631. "loaded_creation_id) values ( ?RegionUUID, ?BlockTerraform, " +
  632. "?BlockFly, ?AllowDamage, ?RestrictPushing, " +
  633. "?AllowLandResell, ?AllowLandJoinDivide, " +
  634. "?BlockShowInSearch, ?AgentLimit, ?ObjectBonus, " +
  635. "?Maturity, ?DisableScripts, ?DisableCollisions, " +
  636. "?DisablePhysics, ?TerrainTexture1, " +
  637. "?TerrainTexture2, ?TerrainTexture3, " +
  638. "?TerrainTexture4, ?Elevation1NW, ?Elevation2NW, " +
  639. "?Elevation1NE, ?Elevation2NE, ?Elevation1SE, " +
  640. "?Elevation2SE, ?Elevation1SW, ?Elevation2SW, " +
  641. "?WaterHeight, ?TerrainRaiseLimit, " +
  642. "?TerrainLowerLimit, ?UseEstateSun, ?FixedSun, " +
  643. "?SunPosition, ?Covenant, ?Sandbox, " +
  644. "?SunVectorX, ?SunVectorY, ?SunVectorZ, " +
  645. "?LoadedCreationDateTime, ?LoadedCreationID)";
  646. FillRegionSettingsCommand(cmd, rs);
  647. ExecuteNonQuery(cmd);
  648. cmd.Dispose();
  649. }
  650. }
  651. public List<LandData> LoadLandObjects(UUID regionUUID)
  652. {
  653. List<LandData> landData = new List<LandData>();
  654. lock (m_Connection)
  655. {
  656. MySqlCommand cmd = m_Connection.CreateCommand();
  657. cmd.CommandText = "select * from land where " +
  658. "RegionUUID = ?RegionUUID";
  659. cmd.Parameters.AddWithValue("RegionUUID", regionUUID.ToString());
  660. IDataReader reader = ExecuteReader(cmd);
  661. try
  662. {
  663. while (reader.Read())
  664. {
  665. LandData newLand = BuildLandData(reader);
  666. landData.Add(newLand);
  667. }
  668. }
  669. finally
  670. {
  671. reader.Close();
  672. }
  673. foreach (LandData land in landData)
  674. {
  675. cmd.Parameters.Clear();
  676. cmd.CommandText = "select * from landaccesslist " +
  677. "where LandUUID = ?LandUUID";
  678. cmd.Parameters.AddWithValue("LandUUID", land.GlobalID.ToString());
  679. reader = ExecuteReader(cmd);
  680. try
  681. {
  682. while (reader.Read())
  683. {
  684. land.ParcelAccessList.Add(BuildLandAccessData(reader));
  685. }
  686. }
  687. finally
  688. {
  689. reader.Close();
  690. }
  691. }
  692. cmd.Dispose();
  693. }
  694. return landData;
  695. }
  696. public void Shutdown()
  697. {
  698. }
  699. private SceneObjectPart BuildPrim(IDataReader row)
  700. {
  701. SceneObjectPart prim = new SceneObjectPart();
  702. prim.UUID = new UUID((String) row["UUID"]);
  703. // explicit conversion of integers is required, which sort
  704. // of sucks. No idea if there is a shortcut here or not.
  705. prim.CreationDate = Convert.ToInt32(row["CreationDate"]);
  706. prim.Name = (String) row["Name"];
  707. // various text fields
  708. prim.Text = (String) row["Text"];
  709. prim.Color = Color.FromArgb(Convert.ToInt32(row["ColorA"]),
  710. Convert.ToInt32(row["ColorR"]),
  711. Convert.ToInt32(row["ColorG"]),
  712. Convert.ToInt32(row["ColorB"]));
  713. prim.Description = (String) row["Description"];
  714. prim.SitName = (String) row["SitName"];
  715. prim.TouchName = (String) row["TouchName"];
  716. // permissions
  717. prim.ObjectFlags = Convert.ToUInt32(row["ObjectFlags"]);
  718. prim.CreatorID = new UUID((String) row["CreatorID"]);
  719. prim.OwnerID = new UUID((String) row["OwnerID"]);
  720. prim.GroupID = new UUID((String) row["GroupID"]);
  721. prim.LastOwnerID = new UUID((String) row["LastOwnerID"]);
  722. prim.OwnerMask = Convert.ToUInt32(row["OwnerMask"]);
  723. prim.NextOwnerMask = Convert.ToUInt32(row["NextOwnerMask"]);
  724. prim.GroupMask = Convert.ToUInt32(row["GroupMask"]);
  725. prim.EveryoneMask = Convert.ToUInt32(row["EveryoneMask"]);
  726. prim.BaseMask = Convert.ToUInt32(row["BaseMask"]);
  727. // vectors
  728. prim.OffsetPosition = new Vector3(
  729. Convert.ToSingle(row["PositionX"]),
  730. Convert.ToSingle(row["PositionY"]),
  731. Convert.ToSingle(row["PositionZ"])
  732. );
  733. prim.GroupPosition = new Vector3(
  734. Convert.ToSingle(row["GroupPositionX"]),
  735. Convert.ToSingle(row["GroupPositionY"]),
  736. Convert.ToSingle(row["GroupPositionZ"])
  737. );
  738. prim.Velocity = new Vector3(
  739. Convert.ToSingle(row["VelocityX"]),
  740. Convert.ToSingle(row["VelocityY"]),
  741. Convert.ToSingle(row["VelocityZ"])
  742. );
  743. prim.AngularVelocity = new Vector3(
  744. Convert.ToSingle(row["AngularVelocityX"]),
  745. Convert.ToSingle(row["AngularVelocityY"]),
  746. Convert.ToSingle(row["AngularVelocityZ"])
  747. );
  748. prim.Acceleration = new Vector3(
  749. Convert.ToSingle(row["AccelerationX"]),
  750. Convert.ToSingle(row["AccelerationY"]),
  751. Convert.ToSingle(row["AccelerationZ"])
  752. );
  753. // quaternions
  754. prim.RotationOffset = new Quaternion(
  755. Convert.ToSingle(row["RotationX"]),
  756. Convert.ToSingle(row["RotationY"]),
  757. Convert.ToSingle(row["RotationZ"]),
  758. Convert.ToSingle(row["RotationW"])
  759. );
  760. prim.SitTargetPositionLL = new Vector3(
  761. Convert.ToSingle(row["SitTargetOffsetX"]),
  762. Convert.ToSingle(row["SitTargetOffsetY"]),
  763. Convert.ToSingle(row["SitTargetOffsetZ"])
  764. );
  765. prim.SitTargetOrientationLL = new Quaternion(
  766. Convert.ToSingle(row["SitTargetOrientX"]),
  767. Convert.ToSingle(row["SitTargetOrientY"]),
  768. Convert.ToSingle(row["SitTargetOrientZ"]),
  769. Convert.ToSingle(row["SitTargetOrientW"])
  770. );
  771. prim.PayPrice[0] = Convert.ToInt32(row["PayPrice"]);
  772. prim.PayPrice[1] = Convert.ToInt32(row["PayButton1"]);
  773. prim.PayPrice[2] = Convert.ToInt32(row["PayButton2"]);
  774. prim.PayPrice[3] = Convert.ToInt32(row["PayButton3"]);
  775. prim.PayPrice[4] = Convert.ToInt32(row["PayButton4"]);
  776. prim.Sound = new UUID(row["LoopedSound"].ToString());
  777. prim.SoundGain = Convert.ToSingle(row["LoopedSoundGain"]);
  778. prim.SoundFlags = 1; // If it's persisted at all, it's looped
  779. if (!(row["TextureAnimation"] is DBNull))
  780. prim.TextureAnimation = (Byte[])row["TextureAnimation"];
  781. if (!(row["ParticleSystem"] is DBNull))
  782. prim.ParticleSystem = (Byte[])row["ParticleSystem"];
  783. prim.RotationalVelocity = new Vector3(
  784. Convert.ToSingle(row["OmegaX"]),
  785. Convert.ToSingle(row["OmegaY"]),
  786. Convert.ToSingle(row["OmegaZ"])
  787. );
  788. prim.SetCameraEyeOffset(new Vector3(
  789. Convert.ToSingle(row["CameraEyeOffsetX"]),
  790. Convert.ToSingle(row["CameraEyeOffsetY"]),
  791. Convert.ToSingle(row["CameraEyeOffsetZ"])
  792. ));
  793. prim.SetCameraAtOffset(new Vector3(
  794. Convert.ToSingle(row["CameraAtOffsetX"]),
  795. Convert.ToSingle(row["CameraAtOffsetY"]),
  796. Convert.ToSingle(row["CameraAtOffsetZ"])
  797. ));
  798. if (Convert.ToInt16(row["ForceMouselook"]) != 0)
  799. prim.SetForceMouselook(true);
  800. prim.ScriptAccessPin = Convert.ToInt32(row["ScriptAccessPin"]);
  801. if (Convert.ToInt16(row["AllowedDrop"]) != 0)
  802. prim.AllowedDrop = true;
  803. if (Convert.ToInt16(row["DieAtEdge"]) != 0)
  804. prim.DIE_AT_EDGE = true;
  805. prim.SalePrice = Convert.ToInt32(row["SalePrice"]);
  806. prim.ObjectSaleType = Convert.ToByte(row["SaleType"]);
  807. prim.Material = Convert.ToByte(row["Material"]);
  808. if (!(row["ClickAction"] is DBNull))
  809. prim.ClickAction = (byte)Convert.ToByte(row["ClickAction"]);
  810. prim.CollisionSound = new UUID(row["CollisionSound"].ToString());
  811. prim.CollisionSoundVolume = Convert.ToSingle(row["CollisionSoundVolume"]);
  812. if (Convert.ToInt16(row["PassTouches"]) != 0)
  813. prim.PassTouches = true;
  814. prim.LinkNum = Convert.ToInt32(row["LinkNumber"]);
  815. return prim;
  816. }
  817. /// <summary>
  818. /// Build a prim inventory item from the persisted data.
  819. /// </summary>
  820. /// <param name="row"></param>
  821. /// <returns></returns>
  822. private static TaskInventoryItem BuildItem(IDataReader row)
  823. {
  824. TaskInventoryItem taskItem = new TaskInventoryItem();
  825. taskItem.ItemID = new UUID((String)row["itemID"]);
  826. taskItem.ParentPartID = new UUID((String)row["primID"]);
  827. taskItem.AssetID = new UUID((String)row["assetID"]);
  828. taskItem.ParentID = new UUID((String)row["parentFolderID"]);
  829. taskItem.InvType = Convert.ToInt32(row["invType"]);
  830. taskItem.Type = Convert.ToInt32(row["assetType"]);
  831. taskItem.Name = (String)row["name"];
  832. taskItem.Description = (String)row["description"];
  833. taskItem.CreationDate = Convert.ToUInt32(row["creationDate"]);
  834. taskItem.CreatorID = new UUID((String)row["creatorID"]);
  835. taskItem.OwnerID = new UUID((String)row["ownerID"]);
  836. taskItem.LastOwnerID = new UUID((String)row["lastOwnerID"]);
  837. taskItem.GroupID = new UUID((String)row["groupID"]);
  838. taskItem.NextPermissions = Convert.ToUInt32(row["nextPermissions"]);
  839. taskItem.CurrentPermissions = Convert.ToUInt32(row["currentPermissions"]);
  840. taskItem.BasePermissions = Convert.ToUInt32(row["basePermissions"]);
  841. taskItem.EveryonePermissions = Convert.ToUInt32(row["everyonePermissions"]);
  842. taskItem.GroupPermissions = Convert.ToUInt32(row["groupPermissions"]);
  843. taskItem.Flags = Convert.ToUInt32(row["flags"]);
  844. return taskItem;
  845. }
  846. private static RegionSettings BuildRegionSettings(IDataReader row)
  847. {
  848. RegionSettings newSettings = new RegionSettings();
  849. newSettings.RegionUUID = new UUID((string) row["regionUUID"]);
  850. newSettings.BlockTerraform = Convert.ToBoolean(row["block_terraform"]);
  851. newSettings.AllowDamage = Convert.ToBoolean(row["allow_damage"]);
  852. newSettings.BlockFly = Convert.ToBoolean(row["block_fly"]);
  853. newSettings.RestrictPushing = Convert.ToBoolean(row["restrict_pushing"]);
  854. newSettings.AllowLandResell = Convert.ToBoolean(row["allow_land_resell"]);
  855. newSettings.AllowLandJoinDivide = Convert.ToBoolean(row["allow_land_join_divide"]);
  856. newSettings.BlockShowInSearch = Convert.ToBoolean(row["block_show_in_search"]);
  857. newSettings.AgentLimit = Convert.ToInt32(row["agent_limit"]);
  858. newSettings.ObjectBonus = Convert.ToDouble(row["object_bonus"]);
  859. newSettings.Maturity = Convert.ToInt32(row["maturity"]);
  860. newSettings.DisableScripts = Convert.ToBoolean(row["disable_scripts"]);
  861. newSettings.DisableCollisions = Convert.ToBoolean(row["disable_collisions"]);
  862. newSettings.DisablePhysics = Convert.ToBoolean(row["disable_physics"]);
  863. newSettings.TerrainTexture1 = new UUID((String) row["terrain_texture_1"]);
  864. newSettings.TerrainTexture2 = new UUID((String) row["terrain_texture_2"]);
  865. newSettings.TerrainTexture3 = new UUID((String) row["terrain_texture_3"]);
  866. newSettings.TerrainTexture4 = new UUID((String) row["terrain_texture_4"]);
  867. newSettings.Elevation1NW = Convert.ToDouble(row["elevation_1_nw"]);
  868. newSettings.Elevation2NW = Convert.ToDouble(row["elevation_2_nw"]);
  869. newSettings.Elevation1NE = Convert.ToDouble(row["elevation_1_ne"]);
  870. newSettings.Elevation2NE = Convert.ToDouble(row["elevation_2_ne"]);
  871. newSettings.Elevation1SE = Convert.ToDouble(row["elevation_1_se"]);
  872. newSettings.Elevation2SE = Convert.ToDouble(row["elevation_2_se"]);
  873. newSettings.Elevation1SW = Convert.ToDouble(row["elevation_1_sw"]);
  874. newSettings.Elevation2SW = Convert.ToDouble(row["elevation_2_sw"]);
  875. newSettings.WaterHeight = Convert.ToDouble(row["water_height"]);
  876. newSettings.TerrainRaiseLimit = Convert.ToDouble(row["terrain_raise_limit"]);
  877. newSettings.TerrainLowerLimit = Convert.ToDouble(row["terrain_lower_limit"]);
  878. newSettings.UseEstateSun = Convert.ToBoolean(row["use_estate_sun"]);
  879. newSettings.Sandbox = Convert.ToBoolean(row["sandbox"]);
  880. newSettings.SunVector = new Vector3 (
  881. Convert.ToSingle(row["sunvectorx"]),
  882. Convert.ToSingle(row["sunvectory"]),
  883. Convert.ToSingle(row["sunvectorz"])
  884. );
  885. newSettings.FixedSun = Convert.ToBoolean(row["fixed_sun"]);
  886. newSettings.SunPosition = Convert.ToDouble(row["sun_position"]);
  887. newSettings.Covenant = new UUID((String) row["covenant"]);
  888. newSettings.LoadedCreationDateTime = Convert.ToInt32(row["loaded_creation_datetime"]);
  889. if (row["loaded_creation_id"] is DBNull)
  890. newSettings.LoadedCreationID = "";
  891. else
  892. newSettings.LoadedCreationID = (String) row["loaded_creation_id"];
  893. return newSettings;
  894. }
  895. /// <summary>
  896. ///
  897. /// </summary>
  898. /// <param name="row"></param>
  899. /// <returns></returns>
  900. private static LandData BuildLandData(IDataReader row)
  901. {
  902. LandData newData = new LandData();
  903. newData.GlobalID = new UUID((String) row["UUID"]);
  904. newData.LocalID = Convert.ToInt32(row["LocalLandID"]);
  905. // Bitmap is a byte[512]
  906. newData.Bitmap = (Byte[]) row["Bitmap"];
  907. newData.Name = (String) row["Name"];
  908. newData.Description = (String) row["Description"];
  909. newData.OwnerID = new UUID((String)row["OwnerUUID"]);
  910. newData.IsGroupOwned = Convert.ToBoolean(row["IsGroupOwned"]);
  911. newData.Area = Convert.ToInt32(row["Area"]);
  912. newData.AuctionID = Convert.ToUInt32(row["AuctionID"]); //Unimplemented
  913. newData.Category = (ParcelCategory) Convert.ToInt32(row["Category"]);
  914. //Enum libsecondlife.Parcel.ParcelCategory
  915. newData.ClaimDate = Convert.ToInt32(row["ClaimDate"]);
  916. newData.ClaimPrice = Convert.ToInt32(row["ClaimPrice"]);
  917. newData.GroupID = new UUID((String) row["GroupUUID"]);
  918. newData.SalePrice = Convert.ToInt32(row["SalePrice"]);
  919. newData.Status = (ParcelStatus) Convert.ToInt32(row["LandStatus"]);
  920. //Enum. libsecondlife.Parcel.ParcelStatus
  921. newData.Flags = Convert.ToUInt32(row["LandFlags"]);
  922. newData.LandingType = Convert.ToByte(row["LandingType"]);
  923. newData.MediaAutoScale = Convert.ToByte(row["MediaAutoScale"]);
  924. newData.MediaID = new UUID((String) row["MediaTextureUUID"]);
  925. newData.MediaURL = (String) row["MediaURL"];
  926. newData.MusicURL = (String) row["MusicURL"];
  927. newData.PassHours = Convert.ToSingle(row["PassHours"]);
  928. newData.PassPrice = Convert.ToInt32(row["PassPrice"]);
  929. UUID authedbuyer = UUID.Zero;
  930. UUID snapshotID = UUID.Zero;
  931. UUID.TryParse((string)row["AuthBuyerID"], out authedbuyer);
  932. UUID.TryParse((string)row["SnapshotUUID"], out snapshotID);
  933. newData.OtherCleanTime = Convert.ToInt32(row["OtherCleanTime"]);
  934. newData.Dwell = Convert.ToInt32(row["Dwell"]);
  935. newData.AuthBuyerID = authedbuyer;
  936. newData.SnapshotID = snapshotID;
  937. try
  938. {
  939. newData.UserLocation =
  940. new Vector3(Convert.ToSingle(row["UserLocationX"]), Convert.ToSingle(row["UserLocationY"]),
  941. Convert.ToSingle(row["UserLocationZ"]));
  942. newData.UserLookAt =
  943. new Vector3(Convert.ToSingle(row["UserLookAtX"]), Convert.ToSingle(row["UserLookAtY"]),
  944. Convert.ToSingle(row["UserLookAtZ"]));
  945. }
  946. catch (InvalidCastException)
  947. {
  948. newData.UserLocation = Vector3.Zero;
  949. newData.UserLookAt = Vector3.Zero;
  950. m_log.ErrorFormat("[PARCEL]: unable to get parcel telehub settings for {1}", newData.Name);
  951. }
  952. newData.ParcelAccessList = new List<ParcelManager.ParcelAccessEntry>();
  953. return newData;
  954. }
  955. /// <summary>
  956. ///
  957. /// </summary>
  958. /// <param name="row"></param>
  959. /// <returns></returns>
  960. private static ParcelManager.ParcelAccessEntry BuildLandAccessData(IDataReader row)
  961. {
  962. ParcelManager.ParcelAccessEntry entry = new ParcelManager.ParcelAccessEntry();
  963. entry.AgentID = new UUID((string) row["AccessUUID"]);
  964. entry.Flags = (AccessList) Convert.ToInt32(row["Flags"]);
  965. entry.Time = new DateTime();
  966. return entry;
  967. }
  968. /// <summary>
  969. ///
  970. /// </summary>
  971. /// <param name="val"></param>
  972. /// <returns></returns>
  973. private static Array SerializeTerrain(double[,] val)
  974. {
  975. MemoryStream str = new MemoryStream(65536*sizeof (double));
  976. BinaryWriter bw = new BinaryWriter(str);
  977. // TODO: COMPATIBILITY - Add byte-order conversions
  978. for (int x = 0; x < 256; x++)
  979. for (int y = 0; y < 256; y++)
  980. {
  981. double height = val[x, y];
  982. if (height == 0.0)
  983. height = double.Epsilon;
  984. bw.Write(height);
  985. }
  986. return str.ToArray();
  987. }
  988. /// <summary>
  989. /// Fill the prim command with prim values
  990. /// </summary>
  991. /// <param name="row"></param>
  992. /// <param name="prim"></param>
  993. /// <param name="sceneGroupID"></param>
  994. /// <param name="regionUUID"></param>
  995. private void FillPrimCommand(MySqlCommand cmd, SceneObjectPart prim, UUID sceneGroupID, UUID regionUUID)
  996. {
  997. cmd.Parameters.AddWithValue("UUID", prim.UUID.ToString());
  998. cmd.Parameters.AddWithValue("RegionUUID", regionUUID.ToString());
  999. cmd.Parameters.AddWithValue("CreationDate", prim.CreationDate);
  1000. cmd.Parameters.AddWithValue("Name", prim.Name);
  1001. cmd.Parameters.AddWithValue("SceneGroupID", sceneGroupID.ToString());
  1002. // the UUID of the root part for this SceneObjectGroup
  1003. // various text fields
  1004. cmd.Parameters.AddWithValue("Text", prim.Text);
  1005. cmd.Parameters.AddWithValue("ColorR", prim.Color.R);
  1006. cmd.Parameters.AddWithValue("ColorG", prim.Color.G);
  1007. cmd.Parameters.AddWithValue("ColorB", prim.Color.B);
  1008. cmd.Parameters.AddWithValue("ColorA", prim.Color.A);
  1009. cmd.Parameters.AddWithValue("Description", prim.Description);
  1010. cmd.Parameters.AddWithValue("SitName", prim.SitName);
  1011. cmd.Parameters.AddWithValue("TouchName", prim.TouchName);
  1012. // permissions
  1013. cmd.Parameters.AddWithValue("ObjectFlags", prim.ObjectFlags);
  1014. cmd.Parameters.AddWithValue("CreatorID", prim.CreatorID.ToString());
  1015. cmd.Parameters.AddWithValue("OwnerID", prim.OwnerID.ToString());
  1016. cmd.Parameters.AddWithValue("GroupID", prim.GroupID.ToString());
  1017. cmd.Parameters.AddWithValue("LastOwnerID", prim.LastOwnerID.ToString());
  1018. cmd.Parameters.AddWithValue("OwnerMask", prim.OwnerMask);
  1019. cmd.Parameters.AddWithValue("NextOwnerMask", prim.NextOwnerMask);
  1020. cmd.Parameters.AddWithValue("GroupMask", prim.GroupMask);
  1021. cmd.Parameters.AddWithValue("EveryoneMask", prim.EveryoneMask);
  1022. cmd.Parameters.AddWithValue("BaseMask", prim.BaseMask);
  1023. // vectors
  1024. cmd.Parameters.AddWithValue("PositionX", (double)prim.OffsetPosition.X);
  1025. cmd.Parameters.AddWithValue("PositionY", (double)prim.OffsetPosition.Y);
  1026. cmd.Parameters.AddWithValue("PositionZ", (double)prim.OffsetPosition.Z);
  1027. cmd.Parameters.AddWithValue("GroupPositionX", (double)prim.GroupPosition.X);
  1028. cmd.Parameters.AddWithValue("GroupPositionY", (double)prim.GroupPosition.Y);
  1029. cmd.Parameters.AddWithValue("GroupPositionZ", (double)prim.GroupPosition.Z);
  1030. cmd.Parameters.AddWithValue("VelocityX", (double)prim.Velocity.X);
  1031. cmd.Parameters.AddWithValue("VelocityY", (double)prim.Velocity.Y);
  1032. cmd.Parameters.AddWithValue("VelocityZ", (double)prim.Velocity.Z);
  1033. cmd.Parameters.AddWithValue("AngularVelocityX", (double)prim.AngularVelocity.X);
  1034. cmd.Parameters.AddWithValue("AngularVelocityY", (double)prim.AngularVelocity.Y);
  1035. cmd.Parameters.AddWithValue("AngularVelocityZ", (double)prim.AngularVelocity.Z);
  1036. cmd.Parameters.AddWithValue("AccelerationX", (double)prim.Acceleration.X);
  1037. cmd.Parameters.AddWithValue("AccelerationY", (double)prim.Acceleration.Y);
  1038. cmd.Parameters.AddWithValue("AccelerationZ", (double)prim.Acceleration.Z);
  1039. // quaternions
  1040. cmd.Parameters.AddWithValue("RotationX", (double)prim.RotationOffset.X);
  1041. cmd.Parameters.AddWithValue("RotationY", (double)prim.RotationOffset.Y);
  1042. cmd.Parameters.AddWithValue("RotationZ", (double)prim.RotationOffset.Z);
  1043. cmd.Parameters.AddWithValue("RotationW", (double)prim.RotationOffset.W);
  1044. // Sit target
  1045. Vector3 sitTargetPos = prim.SitTargetPositionLL;
  1046. cmd.Parameters.AddWithValue("SitTargetOffsetX", (double)sitTargetPos.X);
  1047. cmd.Parameters.AddWithValue("SitTargetOffsetY", (double)sitTargetPos.Y);
  1048. cmd.Parameters.AddWithValue("SitTargetOffsetZ", (double)sitTargetPos.Z);
  1049. Quaternion sitTargetOrient = prim.SitTargetOrientationLL;
  1050. cmd.Parameters.AddWithValue("SitTargetOrientW", (double)sitTargetOrient.W);
  1051. cmd.Parameters.AddWithValue("SitTargetOrientX", (double)sitTargetOrient.X);
  1052. cmd.Parameters.AddWithValue("SitTargetOrientY", (double)sitTargetOrient.Y);
  1053. cmd.Parameters.AddWithValue("SitTargetOrientZ", (double)sitTargetOrient.Z);
  1054. cmd.Parameters.AddWithValue("PayPrice", prim.PayPrice[0]);
  1055. cmd.Parameters.AddWithValue("PayButton1", prim.PayPrice[1]);
  1056. cmd.Parameters.AddWithValue("PayButton2", prim.PayPrice[2]);
  1057. cmd.Parameters.AddWithValue("PayButton3", prim.PayPrice[3]);
  1058. cmd.Parameters.AddWithValue("PayButton4", prim.PayPrice[4]);
  1059. if ((prim.SoundFlags & 1) != 0) // Looped
  1060. {
  1061. cmd.Parameters.AddWithValue("LoopedSound", prim.Sound.ToString());
  1062. cmd.Parameters.AddWithValue("LoopedSoundGain", prim.SoundGain);
  1063. }
  1064. else
  1065. {
  1066. cmd.Parameters.AddWithValue("LoopedSound", UUID.Zero);
  1067. cmd.Parameters.AddWithValue("LoopedSoundGain", 0.0f);
  1068. }
  1069. cmd.Parameters.AddWithValue("TextureAnimation", prim.TextureAnimation);
  1070. cmd.Parameters.AddWithValue("ParticleSystem", prim.ParticleSystem);
  1071. cmd.Parameters.AddWithValue("OmegaX", (double)prim.RotationalVelocity.X);
  1072. cmd.Parameters.AddWithValue("OmegaY", (double)prim.RotationalVelocity.Y);
  1073. cmd.Parameters.AddWithValue("OmegaZ", (double)prim.RotationalVelocity.Z);
  1074. cmd.Parameters.AddWithValue("CameraEyeOffsetX", (double)prim.GetCameraEyeOffset().X);
  1075. cmd.Parameters.AddWithValue("CameraEyeOffsetY", (double)prim.GetCameraEyeOffset().Y);
  1076. cmd.Parameters.AddWithValue("CameraEyeOffsetZ", (double)prim.GetCameraEyeOffset().Z);
  1077. cmd.Parameters.AddWithValue("CameraAtOffsetX", (double)prim.GetCameraAtOffset().X);
  1078. cmd.Parameters.AddWithValue("CameraAtOffsetY", (double)prim.GetCameraAtOffset().Y);
  1079. cmd.Parameters.AddWithValue("CameraAtOffsetZ", (double)prim.GetCameraAtOffset().Z);
  1080. if (prim.GetForceMouselook())
  1081. cmd.Parameters.AddWithValue("ForceMouselook", 1);
  1082. else
  1083. cmd.Parameters.AddWithValue("ForceMouselook", 0);
  1084. cmd.Parameters.AddWithValue("ScriptAccessPin", prim.ScriptAccessPin);
  1085. if (prim.AllowedDrop)
  1086. cmd.Parameters.AddWithValue("AllowedDrop", 1);
  1087. else
  1088. cmd.Parameters.AddWithValue("AllowedDrop", 0);
  1089. if (prim.DIE_AT_EDGE)
  1090. cmd.Parameters.AddWithValue("DieAtEdge", 1);
  1091. else
  1092. cmd.Parameters.AddWithValue("DieAtEdge", 0);
  1093. cmd.Parameters.AddWithValue("SalePrice", prim.SalePrice);
  1094. cmd.Parameters.AddWithValue("SaleType", Convert.ToInt16(prim.ObjectSaleType));
  1095. byte clickAction = prim.ClickAction;
  1096. cmd.Parameters.AddWithValue("ClickAction", clickAction);
  1097. cmd.Parameters.AddWithValue("Material", prim.Material);
  1098. cmd.Parameters.AddWithValue("CollisionSound", prim.CollisionSound.ToString());
  1099. cmd.Parameters.AddWithValue("CollisionSoundVolume", prim.CollisionSoundVolume);
  1100. if (prim.PassTouches)
  1101. cmd.Parameters.AddWithValue("PassTouches", 1);
  1102. else
  1103. cmd.Parameters.AddWithValue("PassTouches", 0);
  1104. cmd.Parameters.AddWithValue("LinkNumber", prim.LinkNum);
  1105. }
  1106. /// <summary>
  1107. ///
  1108. /// </summary>
  1109. /// <param name="row"></param>
  1110. /// <param name="taskItem"></param>
  1111. private static void FillItemCommand(MySqlCommand cmd, TaskInventoryItem taskItem)
  1112. {
  1113. cmd.Parameters.AddWithValue("itemID", taskItem.ItemID);
  1114. cmd.Parameters.AddWithValue("primID", taskItem.ParentPartID);
  1115. cmd.Parameters.AddWithValue("assetID", taskItem.AssetID);
  1116. cmd.Parameters.AddWithValue("parentFolderID", taskItem.ParentID);
  1117. cmd.Parameters.AddWithValue("invType", taskItem.InvType);
  1118. cmd.Parameters.AddWithValue("assetType", taskItem.Type);
  1119. cmd.Parameters.AddWithValue("name", taskItem.Name);
  1120. cmd.Parameters.AddWithValue("description", taskItem.Description);
  1121. cmd.Parameters.AddWithValue("creationDate", taskItem.CreationDate);
  1122. cmd.Parameters.AddWithValue("creatorID", taskItem.CreatorID);
  1123. cmd.Parameters.AddWithValue("ownerID", taskItem.OwnerID);
  1124. cmd.Parameters.AddWithValue("lastOwnerID", taskItem.LastOwnerID);
  1125. cmd.Parameters.AddWithValue("groupID", taskItem.GroupID);
  1126. cmd.Parameters.AddWithValue("nextPermissions", taskItem.NextPermissions);
  1127. cmd.Parameters.AddWithValue("currentPermissions", taskItem.CurrentPermissions);
  1128. cmd.Parameters.AddWithValue("basePermissions", taskItem.BasePermissions);
  1129. cmd.Parameters.AddWithValue("everyonePermissions", taskItem.EveryonePermissions);
  1130. cmd.Parameters.AddWithValue("groupPermissions", taskItem.GroupPermissions);
  1131. cmd.Parameters.AddWithValue("flags", taskItem.Flags);
  1132. }
  1133. /// <summary>
  1134. ///
  1135. /// </summary>
  1136. private static void FillRegionSettingsCommand(MySqlCommand cmd, RegionSettings settings)
  1137. {
  1138. cmd.Parameters.AddWithValue("RegionUUID", settings.RegionUUID.ToString());
  1139. cmd.Parameters.AddWithValue("BlockTerraform", settings.BlockTerraform);
  1140. cmd.Parameters.AddWithValue("BlockFly", settings.BlockFly);
  1141. cmd.Parameters.AddWithValue("AllowDamage", settings.AllowDamage);
  1142. cmd.Parameters.AddWithValue("RestrictPushing", settings.RestrictPushing);
  1143. cmd.Parameters.AddWithValue("AllowLandResell", settings.AllowLandResell);
  1144. cmd.Parameters.AddWithValue("AllowLandJoinDivide", settings.AllowLandJoinDivide);
  1145. cmd.Parameters.AddWithValue("BlockShowInSearch", settings.BlockShowInSearch);
  1146. cmd.Parameters.AddWithValue("AgentLimit", settings.AgentLimit);
  1147. cmd.Parameters.AddWithValue("ObjectBonus", settings.ObjectBonus);
  1148. cmd.Parameters.AddWithValue("Maturity", settings.Maturity);
  1149. cmd.Parameters.AddWithValue("DisableScripts", settings.DisableScripts);
  1150. cmd.Parameters.AddWithValue("DisableCollisions", settings.DisableCollisions);
  1151. cmd.Parameters.AddWithValue("DisablePhysics", settings.DisablePhysics);
  1152. cmd.Parameters.AddWithValue("TerrainTexture1", settings.TerrainTexture1.ToString());
  1153. cmd.Parameters.AddWithValue("TerrainTexture2", settings.TerrainTexture2.ToString());
  1154. cmd.Parameters.AddWithValue("TerrainTexture3", settings.TerrainTexture3.ToString());
  1155. cmd.Parameters.AddWithValue("TerrainTexture4", settings.TerrainTexture4.ToString());
  1156. cmd.Parameters.AddWithValue("Elevation1NW", settings.Elevation1NW);
  1157. cmd.Parameters.AddWithValue("Elevation2NW", settings.Elevation2NW);
  1158. cmd.Parameters.AddWithValue("Elevation1NE", settings.Elevation1NE);
  1159. cmd.Parameters.AddWithValue("Elevation2NE", settings.Elevation2NE);
  1160. cmd.Parameters.AddWithValue("Elevation1SE", settings.Elevation1SE);
  1161. cmd.Parameters.AddWithValue("Elevation2SE", settings.Elevation2SE);
  1162. cmd.Parameters.AddWithValue("Elevation1SW", settings.Elevation1SW);
  1163. cmd.Parameters.AddWithValue("Elevation2SW", settings.Elevation2SW);
  1164. cmd.Parameters.AddWithValue("WaterHeight", settings.WaterHeight);
  1165. cmd.Parameters.AddWithValue("TerrainRaiseLimit", settings.TerrainRaiseLimit);
  1166. cmd.Parameters.AddWithValue("TerrainLowerLimit", settings.TerrainLowerLimit);
  1167. cmd.Parameters.AddWithValue("UseEstateSun", settings.UseEstateSun);
  1168. cmd.Parameters.AddWithValue("Sandbox", settings.Sandbox);
  1169. cmd.Parameters.AddWithValue("SunVectorX", settings.SunVector.X);
  1170. cmd.Parameters.AddWithValue("SunVectorY", settings.SunVector.Y);
  1171. cmd.Parameters.AddWithValue("SunVectorZ", settings.SunVector.Z);
  1172. cmd.Parameters.AddWithValue("FixedSun", settings.FixedSun);
  1173. cmd.Parameters.AddWithValue("SunPosition", settings.SunPosition);
  1174. cmd.Parameters.AddWithValue("Covenant", settings.Covenant.ToString());
  1175. cmd.Parameters.AddWithValue("LoadedCreationDateTime", settings.LoadedCreationDateTime);
  1176. cmd.Parameters.AddWithValue("LoadedCreationID", settings.LoadedCreationID);
  1177. }
  1178. /// <summary>
  1179. ///
  1180. /// </summary>
  1181. /// <param name="row"></param>
  1182. /// <param name="land"></param>
  1183. /// <param name="regionUUID"></param>
  1184. private static void FillLandCommand(MySqlCommand cmd, LandData land, UUID regionUUID)
  1185. {
  1186. cmd.Parameters.AddWithValue("UUID", land.GlobalID.ToString());
  1187. cmd.Parameters.AddWithValue("RegionUUID", regionUUID.ToString());
  1188. cmd.Parameters.AddWithValue("LocalLandID", land.LocalID);
  1189. // Bitmap is a byte[512]
  1190. cmd.Parameters.AddWithValue("Bitmap", land.Bitmap);
  1191. cmd.Parameters.AddWithValue("Name", land.Name);
  1192. cmd.Parameters.AddWithValue("Description", land.Description);
  1193. cmd.Parameters.AddWithValue("OwnerUUID", land.OwnerID.ToString());
  1194. cmd.Parameters.AddWithValue("IsGroupOwned", land.IsGroupOwned);
  1195. cmd.Parameters.AddWithValue("Area", land.Area);
  1196. cmd.Parameters.AddWithValue("AuctionID", land.AuctionID); //Unemplemented
  1197. cmd.Parameters.AddWithValue("Category", land.Category); //Enum libsecondlife.Parcel.ParcelCategory
  1198. cmd.Parameters.AddWithValue("ClaimDate", land.ClaimDate);
  1199. cmd.Parameters.AddWithValue("ClaimPrice", land.ClaimPrice);
  1200. cmd.Parameters.AddWithValue("GroupUUID", land.GroupID.ToString());
  1201. cmd.Parameters.AddWithValue("SalePrice", land.SalePrice);
  1202. cmd.Parameters.AddWithValue("LandStatus", land.Status); //Enum. libsecondlife.Parcel.ParcelStatus
  1203. cmd.Parameters.AddWithValue("LandFlags", land.Flags);
  1204. cmd.Parameters.AddWithValue("LandingType", land.LandingType);
  1205. cmd.Parameters.AddWithValue("MediaAutoScale", land.MediaAutoScale);
  1206. cmd.Parameters.AddWithValue("MediaTextureUUID", land.MediaID.ToString());
  1207. cmd.Parameters.AddWithValue("MediaURL", land.MediaURL);
  1208. cmd.Parameters.AddWithValue("MusicURL", land.MusicURL);
  1209. cmd.Parameters.AddWithValue("PassHours", land.PassHours);
  1210. cmd.Parameters.AddWithValue("PassPrice", land.PassPrice);
  1211. cmd.Parameters.AddWithValue("SnapshotUUID", land.SnapshotID.ToString());
  1212. cmd.Parameters.AddWithValue("UserLocationX", land.UserLocation.X);
  1213. cmd.Parameters.AddWithValue("UserLocationY", land.UserLocation.Y);
  1214. cmd.Parameters.AddWithValue("UserLocationZ", land.UserLocation.Z);
  1215. cmd.Parameters.AddWithValue("UserLookAtX", land.UserLookAt.X);
  1216. cmd.Parameters.AddWithValue("UserLookAtY", land.UserLookAt.Y);
  1217. cmd.Parameters.AddWithValue("UserLookAtZ", land.UserLookAt.Z);
  1218. cmd.Parameters.AddWithValue("AuthBuyerID", land.AuthBuyerID);
  1219. cmd.Parameters.AddWithValue("OtherCleanTime", land.OtherCleanTime);
  1220. cmd.Parameters.AddWithValue("Dwell", land.Dwell);
  1221. }
  1222. /// <summary>
  1223. ///
  1224. /// </summary>
  1225. /// <param name="row"></param>
  1226. /// <param name="entry"></param>
  1227. /// <param name="parcelID"></param>
  1228. private static void FillLandAccessCommand(MySqlCommand cmd, ParcelManager.ParcelAccessEntry entry, UUID parcelID)
  1229. {
  1230. cmd.Parameters.AddWithValue("LandUUID", parcelID.ToString());
  1231. cmd.Parameters.AddWithValue("AccessUUID", entry.AgentID.ToString());
  1232. cmd.Parameters.AddWithValue("Flags", entry.Flags);
  1233. }
  1234. /// <summary>
  1235. ///
  1236. /// </summary>
  1237. /// <param name="row"></param>
  1238. /// <returns></returns>
  1239. private PrimitiveBaseShape BuildShape(IDataReader row)
  1240. {
  1241. PrimitiveBaseShape s = new PrimitiveBaseShape();
  1242. s.Scale = new Vector3(
  1243. Convert.ToSingle(row["ScaleX"]),
  1244. Convert.ToSingle(row["ScaleY"]),
  1245. Convert.ToSingle(row["ScaleZ"])
  1246. );
  1247. // paths
  1248. s.PCode = Convert.ToByte(row["PCode"]);
  1249. s.PathBegin = Convert.ToUInt16(row["PathBegin"]);
  1250. s.PathEnd = Convert.ToUInt16(row["PathEnd"]);
  1251. s.PathScaleX = Convert.ToByte(row["PathScaleX"]);
  1252. s.PathScaleY = Convert.ToByte(row["PathScaleY"]);
  1253. s.PathShearX = Convert.ToByte(row["PathShearX"]);
  1254. s.PathShearY = Convert.ToByte(row["PathShearY"]);
  1255. s.PathSkew = Convert.ToSByte(row["PathSkew"]);
  1256. s.PathCurve = Convert.ToByte(row["PathCurve"]);
  1257. s.PathRadiusOffset = Convert.ToSByte(row["PathRadiusOffset"]);
  1258. s.PathRevolutions = Convert.ToByte(row["PathRevolutions"]);
  1259. s.PathTaperX = Convert.ToSByte(row["PathTaperX"]);
  1260. s.PathTaperY = Convert.ToSByte(row["PathTaperY"]);
  1261. s.PathTwist = Convert.ToSByte(row["PathTwist"]);
  1262. s.PathTwistBegin = Convert.ToSByte(row["PathTwistBegin"]);
  1263. // profile
  1264. s.ProfileBegin = Convert.ToUInt16(row["ProfileBegin"]);
  1265. s.ProfileEnd = Convert.ToUInt16(row["ProfileEnd"]);
  1266. s.ProfileCurve = Convert.ToByte(row["ProfileCurve"]);
  1267. s.ProfileHollow = Convert.ToUInt16(row["ProfileHollow"]);
  1268. byte[] textureEntry = (byte[]) row["Texture"];
  1269. s.TextureEntry = textureEntry;
  1270. s.ExtraParams = (byte[]) row["ExtraParams"];
  1271. s.State = Convert.ToByte(row["State"]);
  1272. return s;
  1273. }
  1274. /// <summary>
  1275. ///
  1276. /// </summary>
  1277. /// <param name="row"></param>
  1278. /// <param name="prim"></param>
  1279. private void FillShapeCommand(MySqlCommand cmd, SceneObjectPart prim)
  1280. {
  1281. PrimitiveBaseShape s = prim.Shape;
  1282. cmd.Parameters.AddWithValue("UUID", prim.UUID.ToString());
  1283. // shape is an enum
  1284. cmd.Parameters.AddWithValue("Shape", 0);
  1285. // vectors
  1286. cmd.Parameters.AddWithValue("ScaleX", (double)s.Scale.X);
  1287. cmd.Parameters.AddWithValue("ScaleY", (double)s.Scale.Y);
  1288. cmd.Parameters.AddWithValue("ScaleZ", (double)s.Scale.Z);
  1289. // paths
  1290. cmd.Parameters.AddWithValue("PCode", s.PCode);
  1291. cmd.Parameters.AddWithValue("PathBegin", s.PathBegin);
  1292. cmd.Parameters.AddWithValue("PathEnd", s.PathEnd);
  1293. cmd.Parameters.AddWithValue("PathScaleX", s.PathScaleX);
  1294. cmd.Parameters.AddWithValue("PathScaleY", s.PathScaleY);
  1295. cmd.Parameters.AddWithValue("PathShearX", s.PathShearX);
  1296. cmd.Parameters.AddWithValue("PathShearY", s.PathShearY);
  1297. cmd.Parameters.AddWithValue("PathSkew", s.PathSkew);
  1298. cmd.Parameters.AddWithValue("PathCurve", s.PathCurve);
  1299. cmd.Parameters.AddWithValue("PathRadiusOffset", s.PathRadiusOffset);
  1300. cmd.Parameters.AddWithValue("PathRevolutions", s.PathRevolutions);
  1301. cmd.Parameters.AddWithValue("PathTaperX", s.PathTaperX);
  1302. cmd.Parameters.AddWithValue("PathTaperY", s.PathTaperY);
  1303. cmd.Parameters.AddWithValue("PathTwist", s.PathTwist);
  1304. cmd.Parameters.AddWithValue("PathTwistBegin", s.PathTwistBegin);
  1305. // profile
  1306. cmd.Parameters.AddWithValue("ProfileBegin", s.ProfileBegin);
  1307. cmd.Parameters.AddWithValue("ProfileEnd", s.ProfileEnd);
  1308. cmd.Parameters.AddWithValue("ProfileCurve", s.ProfileCurve);
  1309. cmd.Parameters.AddWithValue("ProfileHollow", s.ProfileHollow);
  1310. cmd.Parameters.AddWithValue("Texture", s.TextureEntry);
  1311. cmd.Parameters.AddWithValue("ExtraParams", s.ExtraParams);
  1312. cmd.Parameters.AddWithValue("State", s.State);
  1313. }
  1314. public void StorePrimInventory(UUID primID, ICollection<TaskInventoryItem> items)
  1315. {
  1316. lock (m_Connection)
  1317. {
  1318. RemoveItems(primID);
  1319. MySqlCommand cmd = m_Connection.CreateCommand();
  1320. if (items.Count == 0)
  1321. return;
  1322. cmd.CommandText = "insert into primitems ("+
  1323. "invType, assetType, name, "+
  1324. "description, creationDate, nextPermissions, "+
  1325. "currentPermissions, basePermissions, "+
  1326. "everyonePermissions, groupPermissions, "+
  1327. "flags, itemID, primID, assetID, "+
  1328. "parentFolderID, creatorID, ownerID, "+
  1329. "groupID, lastOwnerID) values (?invType, "+
  1330. "?assetType, ?name, ?description, "+
  1331. "?creationDate, ?nextPermissions, "+
  1332. "?currentPermissions, ?basePermissions, "+
  1333. "?everyonePermissions, ?groupPermissions, "+
  1334. "?flags, ?itemID, ?primID, ?assetID, "+
  1335. "?parentFolderID, ?creatorID, ?ownerID, "+
  1336. "?groupID, ?lastOwnerID)";
  1337. foreach (TaskInventoryItem item in items)
  1338. {
  1339. cmd.Parameters.Clear();
  1340. FillItemCommand(cmd, item);
  1341. ExecuteNonQuery(cmd);
  1342. }
  1343. cmd.Dispose();
  1344. }
  1345. }
  1346. }
  1347. }