MySQLRegionData.cs 70 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563
  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[(int)Constants.RegionSize, (int)Constants.RegionSize];
  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 < (int)Constants.RegionSize; x++)
  502. {
  503. for (int y = 0; y < (int)Constants.RegionSize; 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. if (row["Name"] != DBNull.Value)
  707. prim.Name = (String)row["Name"];
  708. else
  709. prim.Name = string.Empty;
  710. // various text fields
  711. prim.Text = (String) row["Text"];
  712. prim.Color = Color.FromArgb(Convert.ToInt32(row["ColorA"]),
  713. Convert.ToInt32(row["ColorR"]),
  714. Convert.ToInt32(row["ColorG"]),
  715. Convert.ToInt32(row["ColorB"]));
  716. prim.Description = (String) row["Description"];
  717. prim.SitName = (String) row["SitName"];
  718. prim.TouchName = (String) row["TouchName"];
  719. // permissions
  720. prim.ObjectFlags = Convert.ToUInt32(row["ObjectFlags"]);
  721. prim.CreatorID = new UUID((String) row["CreatorID"]);
  722. prim.OwnerID = new UUID((String) row["OwnerID"]);
  723. prim.GroupID = new UUID((String) row["GroupID"]);
  724. prim.LastOwnerID = new UUID((String) row["LastOwnerID"]);
  725. prim.OwnerMask = Convert.ToUInt32(row["OwnerMask"]);
  726. prim.NextOwnerMask = Convert.ToUInt32(row["NextOwnerMask"]);
  727. prim.GroupMask = Convert.ToUInt32(row["GroupMask"]);
  728. prim.EveryoneMask = Convert.ToUInt32(row["EveryoneMask"]);
  729. prim.BaseMask = Convert.ToUInt32(row["BaseMask"]);
  730. // vectors
  731. prim.OffsetPosition = new Vector3(
  732. Convert.ToSingle(row["PositionX"]),
  733. Convert.ToSingle(row["PositionY"]),
  734. Convert.ToSingle(row["PositionZ"])
  735. );
  736. prim.GroupPosition = new Vector3(
  737. Convert.ToSingle(row["GroupPositionX"]),
  738. Convert.ToSingle(row["GroupPositionY"]),
  739. Convert.ToSingle(row["GroupPositionZ"])
  740. );
  741. prim.Velocity = new Vector3(
  742. Convert.ToSingle(row["VelocityX"]),
  743. Convert.ToSingle(row["VelocityY"]),
  744. Convert.ToSingle(row["VelocityZ"])
  745. );
  746. prim.AngularVelocity = new Vector3(
  747. Convert.ToSingle(row["AngularVelocityX"]),
  748. Convert.ToSingle(row["AngularVelocityY"]),
  749. Convert.ToSingle(row["AngularVelocityZ"])
  750. );
  751. prim.Acceleration = new Vector3(
  752. Convert.ToSingle(row["AccelerationX"]),
  753. Convert.ToSingle(row["AccelerationY"]),
  754. Convert.ToSingle(row["AccelerationZ"])
  755. );
  756. // quaternions
  757. prim.RotationOffset = new Quaternion(
  758. Convert.ToSingle(row["RotationX"]),
  759. Convert.ToSingle(row["RotationY"]),
  760. Convert.ToSingle(row["RotationZ"]),
  761. Convert.ToSingle(row["RotationW"])
  762. );
  763. prim.SitTargetPositionLL = new Vector3(
  764. Convert.ToSingle(row["SitTargetOffsetX"]),
  765. Convert.ToSingle(row["SitTargetOffsetY"]),
  766. Convert.ToSingle(row["SitTargetOffsetZ"])
  767. );
  768. prim.SitTargetOrientationLL = new Quaternion(
  769. Convert.ToSingle(row["SitTargetOrientX"]),
  770. Convert.ToSingle(row["SitTargetOrientY"]),
  771. Convert.ToSingle(row["SitTargetOrientZ"]),
  772. Convert.ToSingle(row["SitTargetOrientW"])
  773. );
  774. prim.PayPrice[0] = Convert.ToInt32(row["PayPrice"]);
  775. prim.PayPrice[1] = Convert.ToInt32(row["PayButton1"]);
  776. prim.PayPrice[2] = Convert.ToInt32(row["PayButton2"]);
  777. prim.PayPrice[3] = Convert.ToInt32(row["PayButton3"]);
  778. prim.PayPrice[4] = Convert.ToInt32(row["PayButton4"]);
  779. prim.Sound = new UUID(row["LoopedSound"].ToString());
  780. prim.SoundGain = Convert.ToSingle(row["LoopedSoundGain"]);
  781. prim.SoundFlags = 1; // If it's persisted at all, it's looped
  782. if (!(row["TextureAnimation"] is DBNull))
  783. prim.TextureAnimation = (Byte[])row["TextureAnimation"];
  784. if (!(row["ParticleSystem"] is DBNull))
  785. prim.ParticleSystem = (Byte[])row["ParticleSystem"];
  786. prim.RotationalVelocity = new Vector3(
  787. Convert.ToSingle(row["OmegaX"]),
  788. Convert.ToSingle(row["OmegaY"]),
  789. Convert.ToSingle(row["OmegaZ"])
  790. );
  791. prim.SetCameraEyeOffset(new Vector3(
  792. Convert.ToSingle(row["CameraEyeOffsetX"]),
  793. Convert.ToSingle(row["CameraEyeOffsetY"]),
  794. Convert.ToSingle(row["CameraEyeOffsetZ"])
  795. ));
  796. prim.SetCameraAtOffset(new Vector3(
  797. Convert.ToSingle(row["CameraAtOffsetX"]),
  798. Convert.ToSingle(row["CameraAtOffsetY"]),
  799. Convert.ToSingle(row["CameraAtOffsetZ"])
  800. ));
  801. if (Convert.ToInt16(row["ForceMouselook"]) != 0)
  802. prim.SetForceMouselook(true);
  803. prim.ScriptAccessPin = Convert.ToInt32(row["ScriptAccessPin"]);
  804. if (Convert.ToInt16(row["AllowedDrop"]) != 0)
  805. prim.AllowedDrop = true;
  806. if (Convert.ToInt16(row["DieAtEdge"]) != 0)
  807. prim.DIE_AT_EDGE = true;
  808. prim.SalePrice = Convert.ToInt32(row["SalePrice"]);
  809. prim.ObjectSaleType = unchecked((byte)Convert.ToSByte(row["SaleType"]));
  810. prim.Material = unchecked((byte)Convert.ToSByte(row["Material"]));
  811. if (!(row["ClickAction"] is DBNull))
  812. prim.ClickAction = unchecked((byte)Convert.ToSByte(row["ClickAction"]));
  813. prim.CollisionSound = new UUID(row["CollisionSound"].ToString());
  814. prim.CollisionSoundVolume = Convert.ToSingle(row["CollisionSoundVolume"]);
  815. if (Convert.ToInt16(row["PassTouches"]) != 0)
  816. prim.PassTouches = true;
  817. prim.LinkNum = Convert.ToInt32(row["LinkNumber"]);
  818. return prim;
  819. }
  820. /// <summary>
  821. /// Build a prim inventory item from the persisted data.
  822. /// </summary>
  823. /// <param name="row"></param>
  824. /// <returns></returns>
  825. private static TaskInventoryItem BuildItem(IDataReader row)
  826. {
  827. TaskInventoryItem taskItem = new TaskInventoryItem();
  828. taskItem.ItemID = new UUID((String)row["itemID"]);
  829. taskItem.ParentPartID = new UUID((String)row["primID"]);
  830. taskItem.AssetID = new UUID((String)row["assetID"]);
  831. taskItem.ParentID = new UUID((String)row["parentFolderID"]);
  832. taskItem.InvType = Convert.ToInt32(row["invType"]);
  833. taskItem.Type = Convert.ToInt32(row["assetType"]);
  834. taskItem.Name = (String)row["name"];
  835. taskItem.Description = (String)row["description"];
  836. taskItem.CreationDate = Convert.ToUInt32(row["creationDate"]);
  837. taskItem.CreatorID = new UUID((String)row["creatorID"]);
  838. taskItem.OwnerID = new UUID((String)row["ownerID"]);
  839. taskItem.LastOwnerID = new UUID((String)row["lastOwnerID"]);
  840. taskItem.GroupID = new UUID((String)row["groupID"]);
  841. taskItem.NextPermissions = Convert.ToUInt32(row["nextPermissions"]);
  842. taskItem.CurrentPermissions = Convert.ToUInt32(row["currentPermissions"]);
  843. taskItem.BasePermissions = Convert.ToUInt32(row["basePermissions"]);
  844. taskItem.EveryonePermissions = Convert.ToUInt32(row["everyonePermissions"]);
  845. taskItem.GroupPermissions = Convert.ToUInt32(row["groupPermissions"]);
  846. taskItem.Flags = Convert.ToUInt32(row["flags"]);
  847. return taskItem;
  848. }
  849. private static RegionSettings BuildRegionSettings(IDataReader row)
  850. {
  851. RegionSettings newSettings = new RegionSettings();
  852. newSettings.RegionUUID = new UUID((string) row["regionUUID"]);
  853. newSettings.BlockTerraform = Convert.ToBoolean(row["block_terraform"]);
  854. newSettings.AllowDamage = Convert.ToBoolean(row["allow_damage"]);
  855. newSettings.BlockFly = Convert.ToBoolean(row["block_fly"]);
  856. newSettings.RestrictPushing = Convert.ToBoolean(row["restrict_pushing"]);
  857. newSettings.AllowLandResell = Convert.ToBoolean(row["allow_land_resell"]);
  858. newSettings.AllowLandJoinDivide = Convert.ToBoolean(row["allow_land_join_divide"]);
  859. newSettings.BlockShowInSearch = Convert.ToBoolean(row["block_show_in_search"]);
  860. newSettings.AgentLimit = Convert.ToInt32(row["agent_limit"]);
  861. newSettings.ObjectBonus = Convert.ToDouble(row["object_bonus"]);
  862. newSettings.Maturity = Convert.ToInt32(row["maturity"]);
  863. newSettings.DisableScripts = Convert.ToBoolean(row["disable_scripts"]);
  864. newSettings.DisableCollisions = Convert.ToBoolean(row["disable_collisions"]);
  865. newSettings.DisablePhysics = Convert.ToBoolean(row["disable_physics"]);
  866. newSettings.TerrainTexture1 = new UUID((String) row["terrain_texture_1"]);
  867. newSettings.TerrainTexture2 = new UUID((String) row["terrain_texture_2"]);
  868. newSettings.TerrainTexture3 = new UUID((String) row["terrain_texture_3"]);
  869. newSettings.TerrainTexture4 = new UUID((String) row["terrain_texture_4"]);
  870. newSettings.Elevation1NW = Convert.ToDouble(row["elevation_1_nw"]);
  871. newSettings.Elevation2NW = Convert.ToDouble(row["elevation_2_nw"]);
  872. newSettings.Elevation1NE = Convert.ToDouble(row["elevation_1_ne"]);
  873. newSettings.Elevation2NE = Convert.ToDouble(row["elevation_2_ne"]);
  874. newSettings.Elevation1SE = Convert.ToDouble(row["elevation_1_se"]);
  875. newSettings.Elevation2SE = Convert.ToDouble(row["elevation_2_se"]);
  876. newSettings.Elevation1SW = Convert.ToDouble(row["elevation_1_sw"]);
  877. newSettings.Elevation2SW = Convert.ToDouble(row["elevation_2_sw"]);
  878. newSettings.WaterHeight = Convert.ToDouble(row["water_height"]);
  879. newSettings.TerrainRaiseLimit = Convert.ToDouble(row["terrain_raise_limit"]);
  880. newSettings.TerrainLowerLimit = Convert.ToDouble(row["terrain_lower_limit"]);
  881. newSettings.UseEstateSun = Convert.ToBoolean(row["use_estate_sun"]);
  882. newSettings.Sandbox = Convert.ToBoolean(row["sandbox"]);
  883. newSettings.SunVector = new Vector3 (
  884. Convert.ToSingle(row["sunvectorx"]),
  885. Convert.ToSingle(row["sunvectory"]),
  886. Convert.ToSingle(row["sunvectorz"])
  887. );
  888. newSettings.FixedSun = Convert.ToBoolean(row["fixed_sun"]);
  889. newSettings.SunPosition = Convert.ToDouble(row["sun_position"]);
  890. newSettings.Covenant = new UUID((String) row["covenant"]);
  891. newSettings.LoadedCreationDateTime = Convert.ToInt32(row["loaded_creation_datetime"]);
  892. if (row["loaded_creation_id"] is DBNull)
  893. newSettings.LoadedCreationID = "";
  894. else
  895. newSettings.LoadedCreationID = (String) row["loaded_creation_id"];
  896. return newSettings;
  897. }
  898. /// <summary>
  899. ///
  900. /// </summary>
  901. /// <param name="row"></param>
  902. /// <returns></returns>
  903. private static LandData BuildLandData(IDataReader row)
  904. {
  905. LandData newData = new LandData();
  906. newData.GlobalID = new UUID((String) row["UUID"]);
  907. newData.LocalID = Convert.ToInt32(row["LocalLandID"]);
  908. // Bitmap is a byte[512]
  909. newData.Bitmap = (Byte[]) row["Bitmap"];
  910. newData.Name = (String) row["Name"];
  911. newData.Description = (String) row["Description"];
  912. newData.OwnerID = new UUID((String)row["OwnerUUID"]);
  913. newData.IsGroupOwned = Convert.ToBoolean(row["IsGroupOwned"]);
  914. newData.Area = Convert.ToInt32(row["Area"]);
  915. newData.AuctionID = Convert.ToUInt32(row["AuctionID"]); //Unimplemented
  916. newData.Category = (ParcelCategory) Convert.ToInt32(row["Category"]);
  917. //Enum libsecondlife.Parcel.ParcelCategory
  918. newData.ClaimDate = Convert.ToInt32(row["ClaimDate"]);
  919. newData.ClaimPrice = Convert.ToInt32(row["ClaimPrice"]);
  920. newData.GroupID = new UUID((String) row["GroupUUID"]);
  921. newData.SalePrice = Convert.ToInt32(row["SalePrice"]);
  922. newData.Status = (ParcelStatus) Convert.ToInt32(row["LandStatus"]);
  923. //Enum. libsecondlife.Parcel.ParcelStatus
  924. newData.Flags = Convert.ToUInt32(row["LandFlags"]);
  925. newData.LandingType = Convert.ToByte(row["LandingType"]);
  926. newData.MediaAutoScale = Convert.ToByte(row["MediaAutoScale"]);
  927. newData.MediaID = new UUID((String) row["MediaTextureUUID"]);
  928. newData.MediaURL = (String) row["MediaURL"];
  929. newData.MusicURL = (String) row["MusicURL"];
  930. newData.PassHours = Convert.ToSingle(row["PassHours"]);
  931. newData.PassPrice = Convert.ToInt32(row["PassPrice"]);
  932. UUID authedbuyer = UUID.Zero;
  933. UUID snapshotID = UUID.Zero;
  934. UUID.TryParse((string)row["AuthBuyerID"], out authedbuyer);
  935. UUID.TryParse((string)row["SnapshotUUID"], out snapshotID);
  936. newData.OtherCleanTime = Convert.ToInt32(row["OtherCleanTime"]);
  937. newData.Dwell = Convert.ToInt32(row["Dwell"]);
  938. newData.AuthBuyerID = authedbuyer;
  939. newData.SnapshotID = snapshotID;
  940. try
  941. {
  942. newData.UserLocation =
  943. new Vector3(Convert.ToSingle(row["UserLocationX"]), Convert.ToSingle(row["UserLocationY"]),
  944. Convert.ToSingle(row["UserLocationZ"]));
  945. newData.UserLookAt =
  946. new Vector3(Convert.ToSingle(row["UserLookAtX"]), Convert.ToSingle(row["UserLookAtY"]),
  947. Convert.ToSingle(row["UserLookAtZ"]));
  948. }
  949. catch (InvalidCastException)
  950. {
  951. newData.UserLocation = Vector3.Zero;
  952. newData.UserLookAt = Vector3.Zero;
  953. m_log.ErrorFormat("[PARCEL]: unable to get parcel telehub settings for {1}", newData.Name);
  954. }
  955. newData.ParcelAccessList = new List<ParcelManager.ParcelAccessEntry>();
  956. return newData;
  957. }
  958. /// <summary>
  959. ///
  960. /// </summary>
  961. /// <param name="row"></param>
  962. /// <returns></returns>
  963. private static ParcelManager.ParcelAccessEntry BuildLandAccessData(IDataReader row)
  964. {
  965. ParcelManager.ParcelAccessEntry entry = new ParcelManager.ParcelAccessEntry();
  966. entry.AgentID = new UUID((string) row["AccessUUID"]);
  967. entry.Flags = (AccessList) Convert.ToInt32(row["Flags"]);
  968. entry.Time = new DateTime();
  969. return entry;
  970. }
  971. /// <summary>
  972. ///
  973. /// </summary>
  974. /// <param name="val"></param>
  975. /// <returns></returns>
  976. private static Array SerializeTerrain(double[,] val)
  977. {
  978. MemoryStream str = new MemoryStream(((int)Constants.RegionSize * (int)Constants.RegionSize) *sizeof (double));
  979. BinaryWriter bw = new BinaryWriter(str);
  980. // TODO: COMPATIBILITY - Add byte-order conversions
  981. for (int x = 0; x < (int)Constants.RegionSize; x++)
  982. for (int y = 0; y < (int)Constants.RegionSize; y++)
  983. {
  984. double height = val[x, y];
  985. if (height == 0.0)
  986. height = double.Epsilon;
  987. bw.Write(height);
  988. }
  989. return str.ToArray();
  990. }
  991. /// <summary>
  992. /// Fill the prim command with prim values
  993. /// </summary>
  994. /// <param name="row"></param>
  995. /// <param name="prim"></param>
  996. /// <param name="sceneGroupID"></param>
  997. /// <param name="regionUUID"></param>
  998. private void FillPrimCommand(MySqlCommand cmd, SceneObjectPart prim, UUID sceneGroupID, UUID regionUUID)
  999. {
  1000. cmd.Parameters.AddWithValue("UUID", prim.UUID.ToString());
  1001. cmd.Parameters.AddWithValue("RegionUUID", regionUUID.ToString());
  1002. cmd.Parameters.AddWithValue("CreationDate", prim.CreationDate);
  1003. cmd.Parameters.AddWithValue("Name", prim.Name);
  1004. cmd.Parameters.AddWithValue("SceneGroupID", sceneGroupID.ToString());
  1005. // the UUID of the root part for this SceneObjectGroup
  1006. // various text fields
  1007. cmd.Parameters.AddWithValue("Text", prim.Text);
  1008. cmd.Parameters.AddWithValue("ColorR", prim.Color.R);
  1009. cmd.Parameters.AddWithValue("ColorG", prim.Color.G);
  1010. cmd.Parameters.AddWithValue("ColorB", prim.Color.B);
  1011. cmd.Parameters.AddWithValue("ColorA", prim.Color.A);
  1012. cmd.Parameters.AddWithValue("Description", prim.Description);
  1013. cmd.Parameters.AddWithValue("SitName", prim.SitName);
  1014. cmd.Parameters.AddWithValue("TouchName", prim.TouchName);
  1015. // permissions
  1016. cmd.Parameters.AddWithValue("ObjectFlags", prim.ObjectFlags);
  1017. cmd.Parameters.AddWithValue("CreatorID", prim.CreatorID.ToString());
  1018. cmd.Parameters.AddWithValue("OwnerID", prim.OwnerID.ToString());
  1019. cmd.Parameters.AddWithValue("GroupID", prim.GroupID.ToString());
  1020. cmd.Parameters.AddWithValue("LastOwnerID", prim.LastOwnerID.ToString());
  1021. cmd.Parameters.AddWithValue("OwnerMask", prim.OwnerMask);
  1022. cmd.Parameters.AddWithValue("NextOwnerMask", prim.NextOwnerMask);
  1023. cmd.Parameters.AddWithValue("GroupMask", prim.GroupMask);
  1024. cmd.Parameters.AddWithValue("EveryoneMask", prim.EveryoneMask);
  1025. cmd.Parameters.AddWithValue("BaseMask", prim.BaseMask);
  1026. // vectors
  1027. cmd.Parameters.AddWithValue("PositionX", (double)prim.OffsetPosition.X);
  1028. cmd.Parameters.AddWithValue("PositionY", (double)prim.OffsetPosition.Y);
  1029. cmd.Parameters.AddWithValue("PositionZ", (double)prim.OffsetPosition.Z);
  1030. cmd.Parameters.AddWithValue("GroupPositionX", (double)prim.GroupPosition.X);
  1031. cmd.Parameters.AddWithValue("GroupPositionY", (double)prim.GroupPosition.Y);
  1032. cmd.Parameters.AddWithValue("GroupPositionZ", (double)prim.GroupPosition.Z);
  1033. cmd.Parameters.AddWithValue("VelocityX", (double)prim.Velocity.X);
  1034. cmd.Parameters.AddWithValue("VelocityY", (double)prim.Velocity.Y);
  1035. cmd.Parameters.AddWithValue("VelocityZ", (double)prim.Velocity.Z);
  1036. cmd.Parameters.AddWithValue("AngularVelocityX", (double)prim.AngularVelocity.X);
  1037. cmd.Parameters.AddWithValue("AngularVelocityY", (double)prim.AngularVelocity.Y);
  1038. cmd.Parameters.AddWithValue("AngularVelocityZ", (double)prim.AngularVelocity.Z);
  1039. cmd.Parameters.AddWithValue("AccelerationX", (double)prim.Acceleration.X);
  1040. cmd.Parameters.AddWithValue("AccelerationY", (double)prim.Acceleration.Y);
  1041. cmd.Parameters.AddWithValue("AccelerationZ", (double)prim.Acceleration.Z);
  1042. // quaternions
  1043. cmd.Parameters.AddWithValue("RotationX", (double)prim.RotationOffset.X);
  1044. cmd.Parameters.AddWithValue("RotationY", (double)prim.RotationOffset.Y);
  1045. cmd.Parameters.AddWithValue("RotationZ", (double)prim.RotationOffset.Z);
  1046. cmd.Parameters.AddWithValue("RotationW", (double)prim.RotationOffset.W);
  1047. // Sit target
  1048. Vector3 sitTargetPos = prim.SitTargetPositionLL;
  1049. cmd.Parameters.AddWithValue("SitTargetOffsetX", (double)sitTargetPos.X);
  1050. cmd.Parameters.AddWithValue("SitTargetOffsetY", (double)sitTargetPos.Y);
  1051. cmd.Parameters.AddWithValue("SitTargetOffsetZ", (double)sitTargetPos.Z);
  1052. Quaternion sitTargetOrient = prim.SitTargetOrientationLL;
  1053. cmd.Parameters.AddWithValue("SitTargetOrientW", (double)sitTargetOrient.W);
  1054. cmd.Parameters.AddWithValue("SitTargetOrientX", (double)sitTargetOrient.X);
  1055. cmd.Parameters.AddWithValue("SitTargetOrientY", (double)sitTargetOrient.Y);
  1056. cmd.Parameters.AddWithValue("SitTargetOrientZ", (double)sitTargetOrient.Z);
  1057. cmd.Parameters.AddWithValue("PayPrice", prim.PayPrice[0]);
  1058. cmd.Parameters.AddWithValue("PayButton1", prim.PayPrice[1]);
  1059. cmd.Parameters.AddWithValue("PayButton2", prim.PayPrice[2]);
  1060. cmd.Parameters.AddWithValue("PayButton3", prim.PayPrice[3]);
  1061. cmd.Parameters.AddWithValue("PayButton4", prim.PayPrice[4]);
  1062. if ((prim.SoundFlags & 1) != 0) // Looped
  1063. {
  1064. cmd.Parameters.AddWithValue("LoopedSound", prim.Sound.ToString());
  1065. cmd.Parameters.AddWithValue("LoopedSoundGain", prim.SoundGain);
  1066. }
  1067. else
  1068. {
  1069. cmd.Parameters.AddWithValue("LoopedSound", UUID.Zero);
  1070. cmd.Parameters.AddWithValue("LoopedSoundGain", 0.0f);
  1071. }
  1072. cmd.Parameters.AddWithValue("TextureAnimation", prim.TextureAnimation);
  1073. cmd.Parameters.AddWithValue("ParticleSystem", prim.ParticleSystem);
  1074. cmd.Parameters.AddWithValue("OmegaX", (double)prim.RotationalVelocity.X);
  1075. cmd.Parameters.AddWithValue("OmegaY", (double)prim.RotationalVelocity.Y);
  1076. cmd.Parameters.AddWithValue("OmegaZ", (double)prim.RotationalVelocity.Z);
  1077. cmd.Parameters.AddWithValue("CameraEyeOffsetX", (double)prim.GetCameraEyeOffset().X);
  1078. cmd.Parameters.AddWithValue("CameraEyeOffsetY", (double)prim.GetCameraEyeOffset().Y);
  1079. cmd.Parameters.AddWithValue("CameraEyeOffsetZ", (double)prim.GetCameraEyeOffset().Z);
  1080. cmd.Parameters.AddWithValue("CameraAtOffsetX", (double)prim.GetCameraAtOffset().X);
  1081. cmd.Parameters.AddWithValue("CameraAtOffsetY", (double)prim.GetCameraAtOffset().Y);
  1082. cmd.Parameters.AddWithValue("CameraAtOffsetZ", (double)prim.GetCameraAtOffset().Z);
  1083. if (prim.GetForceMouselook())
  1084. cmd.Parameters.AddWithValue("ForceMouselook", 1);
  1085. else
  1086. cmd.Parameters.AddWithValue("ForceMouselook", 0);
  1087. cmd.Parameters.AddWithValue("ScriptAccessPin", prim.ScriptAccessPin);
  1088. if (prim.AllowedDrop)
  1089. cmd.Parameters.AddWithValue("AllowedDrop", 1);
  1090. else
  1091. cmd.Parameters.AddWithValue("AllowedDrop", 0);
  1092. if (prim.DIE_AT_EDGE)
  1093. cmd.Parameters.AddWithValue("DieAtEdge", 1);
  1094. else
  1095. cmd.Parameters.AddWithValue("DieAtEdge", 0);
  1096. cmd.Parameters.AddWithValue("SalePrice", prim.SalePrice);
  1097. cmd.Parameters.AddWithValue("SaleType", unchecked((sbyte)(prim.ObjectSaleType)));
  1098. byte clickAction = prim.ClickAction;
  1099. cmd.Parameters.AddWithValue("ClickAction", unchecked((sbyte)(clickAction)));
  1100. cmd.Parameters.AddWithValue("Material", unchecked((sbyte)(prim.Material)));
  1101. cmd.Parameters.AddWithValue("CollisionSound", prim.CollisionSound.ToString());
  1102. cmd.Parameters.AddWithValue("CollisionSoundVolume", prim.CollisionSoundVolume);
  1103. if (prim.PassTouches)
  1104. cmd.Parameters.AddWithValue("PassTouches", 1);
  1105. else
  1106. cmd.Parameters.AddWithValue("PassTouches", 0);
  1107. cmd.Parameters.AddWithValue("LinkNumber", prim.LinkNum);
  1108. }
  1109. /// <summary>
  1110. ///
  1111. /// </summary>
  1112. /// <param name="row"></param>
  1113. /// <param name="taskItem"></param>
  1114. private static void FillItemCommand(MySqlCommand cmd, TaskInventoryItem taskItem)
  1115. {
  1116. cmd.Parameters.AddWithValue("itemID", taskItem.ItemID);
  1117. cmd.Parameters.AddWithValue("primID", taskItem.ParentPartID);
  1118. cmd.Parameters.AddWithValue("assetID", taskItem.AssetID);
  1119. cmd.Parameters.AddWithValue("parentFolderID", taskItem.ParentID);
  1120. cmd.Parameters.AddWithValue("invType", taskItem.InvType);
  1121. cmd.Parameters.AddWithValue("assetType", taskItem.Type);
  1122. cmd.Parameters.AddWithValue("name", taskItem.Name);
  1123. cmd.Parameters.AddWithValue("description", taskItem.Description);
  1124. cmd.Parameters.AddWithValue("creationDate", taskItem.CreationDate);
  1125. cmd.Parameters.AddWithValue("creatorID", taskItem.CreatorID);
  1126. cmd.Parameters.AddWithValue("ownerID", taskItem.OwnerID);
  1127. cmd.Parameters.AddWithValue("lastOwnerID", taskItem.LastOwnerID);
  1128. cmd.Parameters.AddWithValue("groupID", taskItem.GroupID);
  1129. cmd.Parameters.AddWithValue("nextPermissions", taskItem.NextPermissions);
  1130. cmd.Parameters.AddWithValue("currentPermissions", taskItem.CurrentPermissions);
  1131. cmd.Parameters.AddWithValue("basePermissions", taskItem.BasePermissions);
  1132. cmd.Parameters.AddWithValue("everyonePermissions", taskItem.EveryonePermissions);
  1133. cmd.Parameters.AddWithValue("groupPermissions", taskItem.GroupPermissions);
  1134. cmd.Parameters.AddWithValue("flags", taskItem.Flags);
  1135. }
  1136. /// <summary>
  1137. ///
  1138. /// </summary>
  1139. private static void FillRegionSettingsCommand(MySqlCommand cmd, RegionSettings settings)
  1140. {
  1141. cmd.Parameters.AddWithValue("RegionUUID", settings.RegionUUID.ToString());
  1142. cmd.Parameters.AddWithValue("BlockTerraform", settings.BlockTerraform);
  1143. cmd.Parameters.AddWithValue("BlockFly", settings.BlockFly);
  1144. cmd.Parameters.AddWithValue("AllowDamage", settings.AllowDamage);
  1145. cmd.Parameters.AddWithValue("RestrictPushing", settings.RestrictPushing);
  1146. cmd.Parameters.AddWithValue("AllowLandResell", settings.AllowLandResell);
  1147. cmd.Parameters.AddWithValue("AllowLandJoinDivide", settings.AllowLandJoinDivide);
  1148. cmd.Parameters.AddWithValue("BlockShowInSearch", settings.BlockShowInSearch);
  1149. cmd.Parameters.AddWithValue("AgentLimit", settings.AgentLimit);
  1150. cmd.Parameters.AddWithValue("ObjectBonus", settings.ObjectBonus);
  1151. cmd.Parameters.AddWithValue("Maturity", settings.Maturity);
  1152. cmd.Parameters.AddWithValue("DisableScripts", settings.DisableScripts);
  1153. cmd.Parameters.AddWithValue("DisableCollisions", settings.DisableCollisions);
  1154. cmd.Parameters.AddWithValue("DisablePhysics", settings.DisablePhysics);
  1155. cmd.Parameters.AddWithValue("TerrainTexture1", settings.TerrainTexture1.ToString());
  1156. cmd.Parameters.AddWithValue("TerrainTexture2", settings.TerrainTexture2.ToString());
  1157. cmd.Parameters.AddWithValue("TerrainTexture3", settings.TerrainTexture3.ToString());
  1158. cmd.Parameters.AddWithValue("TerrainTexture4", settings.TerrainTexture4.ToString());
  1159. cmd.Parameters.AddWithValue("Elevation1NW", settings.Elevation1NW);
  1160. cmd.Parameters.AddWithValue("Elevation2NW", settings.Elevation2NW);
  1161. cmd.Parameters.AddWithValue("Elevation1NE", settings.Elevation1NE);
  1162. cmd.Parameters.AddWithValue("Elevation2NE", settings.Elevation2NE);
  1163. cmd.Parameters.AddWithValue("Elevation1SE", settings.Elevation1SE);
  1164. cmd.Parameters.AddWithValue("Elevation2SE", settings.Elevation2SE);
  1165. cmd.Parameters.AddWithValue("Elevation1SW", settings.Elevation1SW);
  1166. cmd.Parameters.AddWithValue("Elevation2SW", settings.Elevation2SW);
  1167. cmd.Parameters.AddWithValue("WaterHeight", settings.WaterHeight);
  1168. cmd.Parameters.AddWithValue("TerrainRaiseLimit", settings.TerrainRaiseLimit);
  1169. cmd.Parameters.AddWithValue("TerrainLowerLimit", settings.TerrainLowerLimit);
  1170. cmd.Parameters.AddWithValue("UseEstateSun", settings.UseEstateSun);
  1171. cmd.Parameters.AddWithValue("Sandbox", settings.Sandbox);
  1172. cmd.Parameters.AddWithValue("SunVectorX", settings.SunVector.X);
  1173. cmd.Parameters.AddWithValue("SunVectorY", settings.SunVector.Y);
  1174. cmd.Parameters.AddWithValue("SunVectorZ", settings.SunVector.Z);
  1175. cmd.Parameters.AddWithValue("FixedSun", settings.FixedSun);
  1176. cmd.Parameters.AddWithValue("SunPosition", settings.SunPosition);
  1177. cmd.Parameters.AddWithValue("Covenant", settings.Covenant.ToString());
  1178. cmd.Parameters.AddWithValue("LoadedCreationDateTime", settings.LoadedCreationDateTime);
  1179. cmd.Parameters.AddWithValue("LoadedCreationID", settings.LoadedCreationID);
  1180. }
  1181. /// <summary>
  1182. ///
  1183. /// </summary>
  1184. /// <param name="row"></param>
  1185. /// <param name="land"></param>
  1186. /// <param name="regionUUID"></param>
  1187. private static void FillLandCommand(MySqlCommand cmd, LandData land, UUID regionUUID)
  1188. {
  1189. cmd.Parameters.AddWithValue("UUID", land.GlobalID.ToString());
  1190. cmd.Parameters.AddWithValue("RegionUUID", regionUUID.ToString());
  1191. cmd.Parameters.AddWithValue("LocalLandID", land.LocalID);
  1192. // Bitmap is a byte[512]
  1193. cmd.Parameters.AddWithValue("Bitmap", land.Bitmap);
  1194. cmd.Parameters.AddWithValue("Name", land.Name);
  1195. cmd.Parameters.AddWithValue("Description", land.Description);
  1196. cmd.Parameters.AddWithValue("OwnerUUID", land.OwnerID.ToString());
  1197. cmd.Parameters.AddWithValue("IsGroupOwned", land.IsGroupOwned);
  1198. cmd.Parameters.AddWithValue("Area", land.Area);
  1199. cmd.Parameters.AddWithValue("AuctionID", land.AuctionID); //Unemplemented
  1200. cmd.Parameters.AddWithValue("Category", land.Category); //Enum libsecondlife.Parcel.ParcelCategory
  1201. cmd.Parameters.AddWithValue("ClaimDate", land.ClaimDate);
  1202. cmd.Parameters.AddWithValue("ClaimPrice", land.ClaimPrice);
  1203. cmd.Parameters.AddWithValue("GroupUUID", land.GroupID.ToString());
  1204. cmd.Parameters.AddWithValue("SalePrice", land.SalePrice);
  1205. cmd.Parameters.AddWithValue("LandStatus", land.Status); //Enum. libsecondlife.Parcel.ParcelStatus
  1206. cmd.Parameters.AddWithValue("LandFlags", land.Flags);
  1207. cmd.Parameters.AddWithValue("LandingType", land.LandingType);
  1208. cmd.Parameters.AddWithValue("MediaAutoScale", land.MediaAutoScale);
  1209. cmd.Parameters.AddWithValue("MediaTextureUUID", land.MediaID.ToString());
  1210. cmd.Parameters.AddWithValue("MediaURL", land.MediaURL);
  1211. cmd.Parameters.AddWithValue("MusicURL", land.MusicURL);
  1212. cmd.Parameters.AddWithValue("PassHours", land.PassHours);
  1213. cmd.Parameters.AddWithValue("PassPrice", land.PassPrice);
  1214. cmd.Parameters.AddWithValue("SnapshotUUID", land.SnapshotID.ToString());
  1215. cmd.Parameters.AddWithValue("UserLocationX", land.UserLocation.X);
  1216. cmd.Parameters.AddWithValue("UserLocationY", land.UserLocation.Y);
  1217. cmd.Parameters.AddWithValue("UserLocationZ", land.UserLocation.Z);
  1218. cmd.Parameters.AddWithValue("UserLookAtX", land.UserLookAt.X);
  1219. cmd.Parameters.AddWithValue("UserLookAtY", land.UserLookAt.Y);
  1220. cmd.Parameters.AddWithValue("UserLookAtZ", land.UserLookAt.Z);
  1221. cmd.Parameters.AddWithValue("AuthBuyerID", land.AuthBuyerID);
  1222. cmd.Parameters.AddWithValue("OtherCleanTime", land.OtherCleanTime);
  1223. cmd.Parameters.AddWithValue("Dwell", land.Dwell);
  1224. }
  1225. /// <summary>
  1226. ///
  1227. /// </summary>
  1228. /// <param name="row"></param>
  1229. /// <param name="entry"></param>
  1230. /// <param name="parcelID"></param>
  1231. private static void FillLandAccessCommand(MySqlCommand cmd, ParcelManager.ParcelAccessEntry entry, UUID parcelID)
  1232. {
  1233. cmd.Parameters.AddWithValue("LandUUID", parcelID.ToString());
  1234. cmd.Parameters.AddWithValue("AccessUUID", entry.AgentID.ToString());
  1235. cmd.Parameters.AddWithValue("Flags", entry.Flags);
  1236. }
  1237. /// <summary>
  1238. ///
  1239. /// </summary>
  1240. /// <param name="row"></param>
  1241. /// <returns></returns>
  1242. private PrimitiveBaseShape BuildShape(IDataReader row)
  1243. {
  1244. PrimitiveBaseShape s = new PrimitiveBaseShape();
  1245. s.Scale = new Vector3(
  1246. Convert.ToSingle(row["ScaleX"]),
  1247. Convert.ToSingle(row["ScaleY"]),
  1248. Convert.ToSingle(row["ScaleZ"])
  1249. );
  1250. // paths
  1251. s.PCode = Convert.ToByte(row["PCode"]);
  1252. s.PathBegin = Convert.ToUInt16(row["PathBegin"]);
  1253. s.PathEnd = Convert.ToUInt16(row["PathEnd"]);
  1254. s.PathScaleX = Convert.ToByte(row["PathScaleX"]);
  1255. s.PathScaleY = Convert.ToByte(row["PathScaleY"]);
  1256. s.PathShearX = Convert.ToByte(row["PathShearX"]);
  1257. s.PathShearY = Convert.ToByte(row["PathShearY"]);
  1258. s.PathSkew = Convert.ToSByte(row["PathSkew"]);
  1259. s.PathCurve = Convert.ToByte(row["PathCurve"]);
  1260. s.PathRadiusOffset = Convert.ToSByte(row["PathRadiusOffset"]);
  1261. s.PathRevolutions = Convert.ToByte(row["PathRevolutions"]);
  1262. s.PathTaperX = Convert.ToSByte(row["PathTaperX"]);
  1263. s.PathTaperY = Convert.ToSByte(row["PathTaperY"]);
  1264. s.PathTwist = Convert.ToSByte(row["PathTwist"]);
  1265. s.PathTwistBegin = Convert.ToSByte(row["PathTwistBegin"]);
  1266. // profile
  1267. s.ProfileBegin = Convert.ToUInt16(row["ProfileBegin"]);
  1268. s.ProfileEnd = Convert.ToUInt16(row["ProfileEnd"]);
  1269. s.ProfileCurve = Convert.ToByte(row["ProfileCurve"]);
  1270. s.ProfileHollow = Convert.ToUInt16(row["ProfileHollow"]);
  1271. byte[] textureEntry = (byte[]) row["Texture"];
  1272. s.TextureEntry = textureEntry;
  1273. s.ExtraParams = (byte[]) row["ExtraParams"];
  1274. s.State = Convert.ToByte(row["State"]);
  1275. return s;
  1276. }
  1277. /// <summary>
  1278. ///
  1279. /// </summary>
  1280. /// <param name="row"></param>
  1281. /// <param name="prim"></param>
  1282. private void FillShapeCommand(MySqlCommand cmd, SceneObjectPart prim)
  1283. {
  1284. PrimitiveBaseShape s = prim.Shape;
  1285. cmd.Parameters.AddWithValue("UUID", prim.UUID.ToString());
  1286. // shape is an enum
  1287. cmd.Parameters.AddWithValue("Shape", 0);
  1288. // vectors
  1289. cmd.Parameters.AddWithValue("ScaleX", (double)s.Scale.X);
  1290. cmd.Parameters.AddWithValue("ScaleY", (double)s.Scale.Y);
  1291. cmd.Parameters.AddWithValue("ScaleZ", (double)s.Scale.Z);
  1292. // paths
  1293. cmd.Parameters.AddWithValue("PCode", s.PCode);
  1294. cmd.Parameters.AddWithValue("PathBegin", s.PathBegin);
  1295. cmd.Parameters.AddWithValue("PathEnd", s.PathEnd);
  1296. cmd.Parameters.AddWithValue("PathScaleX", s.PathScaleX);
  1297. cmd.Parameters.AddWithValue("PathScaleY", s.PathScaleY);
  1298. cmd.Parameters.AddWithValue("PathShearX", s.PathShearX);
  1299. cmd.Parameters.AddWithValue("PathShearY", s.PathShearY);
  1300. cmd.Parameters.AddWithValue("PathSkew", s.PathSkew);
  1301. cmd.Parameters.AddWithValue("PathCurve", s.PathCurve);
  1302. cmd.Parameters.AddWithValue("PathRadiusOffset", s.PathRadiusOffset);
  1303. cmd.Parameters.AddWithValue("PathRevolutions", s.PathRevolutions);
  1304. cmd.Parameters.AddWithValue("PathTaperX", s.PathTaperX);
  1305. cmd.Parameters.AddWithValue("PathTaperY", s.PathTaperY);
  1306. cmd.Parameters.AddWithValue("PathTwist", s.PathTwist);
  1307. cmd.Parameters.AddWithValue("PathTwistBegin", s.PathTwistBegin);
  1308. // profile
  1309. cmd.Parameters.AddWithValue("ProfileBegin", s.ProfileBegin);
  1310. cmd.Parameters.AddWithValue("ProfileEnd", s.ProfileEnd);
  1311. cmd.Parameters.AddWithValue("ProfileCurve", s.ProfileCurve);
  1312. cmd.Parameters.AddWithValue("ProfileHollow", s.ProfileHollow);
  1313. cmd.Parameters.AddWithValue("Texture", s.TextureEntry);
  1314. cmd.Parameters.AddWithValue("ExtraParams", s.ExtraParams);
  1315. cmd.Parameters.AddWithValue("State", s.State);
  1316. }
  1317. public void StorePrimInventory(UUID primID, ICollection<TaskInventoryItem> items)
  1318. {
  1319. lock (m_Connection)
  1320. {
  1321. RemoveItems(primID);
  1322. MySqlCommand cmd = m_Connection.CreateCommand();
  1323. if (items.Count == 0)
  1324. return;
  1325. cmd.CommandText = "insert into primitems ("+
  1326. "invType, assetType, name, "+
  1327. "description, creationDate, nextPermissions, "+
  1328. "currentPermissions, basePermissions, "+
  1329. "everyonePermissions, groupPermissions, "+
  1330. "flags, itemID, primID, assetID, "+
  1331. "parentFolderID, creatorID, ownerID, "+
  1332. "groupID, lastOwnerID) values (?invType, "+
  1333. "?assetType, ?name, ?description, "+
  1334. "?creationDate, ?nextPermissions, "+
  1335. "?currentPermissions, ?basePermissions, "+
  1336. "?everyonePermissions, ?groupPermissions, "+
  1337. "?flags, ?itemID, ?primID, ?assetID, "+
  1338. "?parentFolderID, ?creatorID, ?ownerID, "+
  1339. "?groupID, ?lastOwnerID)";
  1340. foreach (TaskInventoryItem item in items)
  1341. {
  1342. cmd.Parameters.Clear();
  1343. FillItemCommand(cmd, item);
  1344. ExecuteNonQuery(cmd);
  1345. }
  1346. cmd.Dispose();
  1347. }
  1348. }
  1349. }
  1350. }