MySQLLegacyRegionData.cs 71 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594
  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. Dictionary<UUID, SceneObjectGroup> objects = new Dictionary<UUID, SceneObjectGroup>();
  362. Dictionary<UUID, SceneObjectPart> prims = new Dictionary<UUID, 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[prim.UUID] = prim;
  385. UUID groupID = new UUID(reader["SceneGroupID"].ToString());
  386. if (groupID != lastGroupID) // New SOG
  387. {
  388. if (grp != null)
  389. objects[grp.UUID] = 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[grp.UUID] = grp;
  422. cmd.Dispose();
  423. }
  424. // Instead of attempting to LoadItems on every prim,
  425. // most of which probably have no items... get a
  426. // list from DB of all prims which have items and
  427. // LoadItems only on those
  428. List<SceneObjectPart> primsWithInventory = new List<SceneObjectPart>();
  429. lock (m_Connection)
  430. {
  431. MySqlCommand itemCmd = m_Connection.CreateCommand();
  432. itemCmd.CommandText = "select distinct primID from primitems";
  433. IDataReader itemReader = ExecuteReader(itemCmd);
  434. try
  435. {
  436. while (itemReader.Read())
  437. {
  438. if (!(itemReader["primID"] is DBNull))
  439. {
  440. UUID primID = new UUID(itemReader["primID"].ToString());
  441. if (prims.ContainsKey(primID))
  442. {
  443. primsWithInventory.Add(prims[primID]);
  444. }
  445. }
  446. }
  447. }
  448. finally
  449. {
  450. itemReader.Close();
  451. }
  452. itemCmd.Dispose();
  453. }
  454. foreach (SceneObjectPart prim in primsWithInventory)
  455. {
  456. LoadItems(prim);
  457. }
  458. m_log.DebugFormat("[REGION DB]: Loaded {0} objects using {1} prims", objects.Count, prims.Count);
  459. return new List<SceneObjectGroup>(objects.Values);
  460. }
  461. /// <summary>
  462. /// Load in a prim's persisted inventory.
  463. /// </summary>
  464. /// <param name="prim">The prim</param>
  465. private void LoadItems(SceneObjectPart prim)
  466. {
  467. lock (m_Connection)
  468. {
  469. MySqlCommand cmd = m_Connection.CreateCommand();
  470. cmd.CommandText = "select * from primitems where "+
  471. "PrimID = ?PrimID";
  472. cmd.Parameters.AddWithValue("PrimID", prim.UUID.ToString());
  473. IDataReader reader = ExecuteReader(cmd);
  474. List<TaskInventoryItem> inventory =
  475. new List<TaskInventoryItem>();
  476. try
  477. {
  478. while (reader.Read())
  479. {
  480. TaskInventoryItem item = BuildItem(reader);
  481. item.ParentID = prim.UUID; // Values in database are
  482. // often wrong
  483. inventory.Add(item);
  484. }
  485. }
  486. finally
  487. {
  488. reader.Close();
  489. }
  490. cmd.Dispose();
  491. prim.Inventory.RestoreInventoryItems(inventory);
  492. }
  493. }
  494. public void StoreTerrain(double[,] ter, UUID regionID)
  495. {
  496. m_log.Info("[REGION DB]: Storing terrain");
  497. lock (m_Connection)
  498. {
  499. MySqlCommand cmd = m_Connection.CreateCommand();
  500. cmd.CommandText = "delete from terrain where " +
  501. "RegionUUID = ?RegionUUID";
  502. cmd.Parameters.AddWithValue("RegionUUID", regionID.ToString());
  503. ExecuteNonQuery(cmd);
  504. cmd.CommandText = "insert into terrain (RegionUUID, " +
  505. "Revision, Heightfield) values (?RegionUUID, " +
  506. "1, ?Heightfield)";
  507. cmd.Parameters.AddWithValue("Heightfield",
  508. SerializeTerrain(ter));
  509. ExecuteNonQuery(cmd);
  510. cmd.Dispose();
  511. }
  512. }
  513. public double[,] LoadTerrain(UUID regionID)
  514. {
  515. double[,] terrain = null;
  516. lock (m_Connection)
  517. {
  518. MySqlCommand cmd = m_Connection.CreateCommand();
  519. cmd.CommandText = "select RegionUUID, Revision, Heightfield " +
  520. "from terrain where RegionUUID = ?RegionUUID "+
  521. "order by Revision desc limit 1";
  522. cmd.Parameters.AddWithValue("RegionUUID", regionID.ToString());
  523. IDataReader reader = ExecuteReader(cmd);
  524. try
  525. {
  526. while (reader.Read())
  527. {
  528. terrain = new double[(int)Constants.RegionSize, (int)Constants.RegionSize];
  529. terrain.Initialize();
  530. MemoryStream mstr = new MemoryStream((byte[]) reader["Heightfield"]);
  531. int rev = 0;
  532. BinaryReader br = new BinaryReader(mstr);
  533. for (int x = 0; x < (int)Constants.RegionSize; x++)
  534. {
  535. for (int y = 0; y < (int)Constants.RegionSize; y++)
  536. {
  537. terrain[x, y] = br.ReadDouble();
  538. }
  539. rev = Convert.ToInt32(reader["Revision"]);
  540. }
  541. m_log.InfoFormat("[REGION DB]: Loaded terrain " +
  542. "revision r{0}", rev);
  543. }
  544. }
  545. finally
  546. {
  547. reader.Close();
  548. }
  549. cmd.Dispose();
  550. }
  551. return terrain;
  552. }
  553. public void RemoveLandObject(UUID globalID)
  554. {
  555. lock (m_Connection)
  556. {
  557. MySqlCommand cmd = m_Connection.CreateCommand();
  558. cmd.CommandText = "delete from land where UUID = ?UUID";
  559. cmd.Parameters.AddWithValue("UUID", globalID.ToString());
  560. ExecuteNonQuery(cmd);
  561. cmd.Dispose();
  562. }
  563. }
  564. public void StoreLandObject(ILandObject parcel)
  565. {
  566. lock (m_Connection)
  567. {
  568. MySqlCommand cmd = m_Connection.CreateCommand();
  569. cmd.CommandText = "replace into land (UUID, RegionUUID, " +
  570. "LocalLandID, Bitmap, Name, Description, " +
  571. "OwnerUUID, IsGroupOwned, Area, AuctionID, " +
  572. "Category, ClaimDate, ClaimPrice, GroupUUID, " +
  573. "SalePrice, LandStatus, LandFlags, LandingType, " +
  574. "MediaAutoScale, MediaTextureUUID, MediaURL, " +
  575. "MusicURL, PassHours, PassPrice, SnapshotUUID, " +
  576. "UserLocationX, UserLocationY, UserLocationZ, " +
  577. "UserLookAtX, UserLookAtY, UserLookAtZ, " +
  578. "AuthbuyerID, OtherCleanTime, Dwell) values (" +
  579. "?UUID, ?RegionUUID, " +
  580. "?LocalLandID, ?Bitmap, ?Name, ?Description, " +
  581. "?OwnerUUID, ?IsGroupOwned, ?Area, ?AuctionID, " +
  582. "?Category, ?ClaimDate, ?ClaimPrice, ?GroupUUID, " +
  583. "?SalePrice, ?LandStatus, ?LandFlags, ?LandingType, " +
  584. "?MediaAutoScale, ?MediaTextureUUID, ?MediaURL, " +
  585. "?MusicURL, ?PassHours, ?PassPrice, ?SnapshotUUID, " +
  586. "?UserLocationX, ?UserLocationY, ?UserLocationZ, " +
  587. "?UserLookAtX, ?UserLookAtY, ?UserLookAtZ, " +
  588. "?AuthbuyerID, ?OtherCleanTime, ?Dwell)";
  589. FillLandCommand(cmd, parcel.landData, parcel.regionUUID);
  590. ExecuteNonQuery(cmd);
  591. cmd.CommandText = "delete from landaccesslist where " +
  592. "LandUUID = ?UUID";
  593. ExecuteNonQuery(cmd);
  594. cmd.Parameters.Clear();
  595. cmd.CommandText = "insert into landaccesslist (LandUUID, " +
  596. "AccessUUID, Flags) values (?LandUUID, ?AccessUUID, " +
  597. "?Flags)";
  598. foreach (ParcelManager.ParcelAccessEntry entry in
  599. parcel.landData.ParcelAccessList)
  600. {
  601. FillLandAccessCommand(cmd, entry, parcel.landData.GlobalID);
  602. ExecuteNonQuery(cmd);
  603. cmd.Parameters.Clear();
  604. }
  605. cmd.Dispose();
  606. }
  607. }
  608. public RegionSettings LoadRegionSettings(UUID regionUUID)
  609. {
  610. RegionSettings rs = null;
  611. lock (m_Connection)
  612. {
  613. MySqlCommand cmd = m_Connection.CreateCommand();
  614. cmd.CommandText = "select * from regionsettings where " +
  615. "regionUUID = ?RegionUUID";
  616. cmd.Parameters.AddWithValue("regionUUID", regionUUID);
  617. IDataReader reader = ExecuteReader(cmd);
  618. try
  619. {
  620. if (reader.Read())
  621. {
  622. rs = BuildRegionSettings(reader);
  623. rs.OnSave += StoreRegionSettings;
  624. }
  625. else
  626. {
  627. rs = new RegionSettings();
  628. rs.RegionUUID = regionUUID;
  629. rs.OnSave += StoreRegionSettings;
  630. StoreRegionSettings(rs);
  631. }
  632. }
  633. finally
  634. {
  635. reader.Close();
  636. }
  637. cmd.Dispose();
  638. }
  639. return rs;
  640. }
  641. public void StoreRegionSettings(RegionSettings rs)
  642. {
  643. lock (m_Connection)
  644. {
  645. MySqlCommand cmd = m_Connection.CreateCommand();
  646. cmd.CommandText = "replace into regionsettings (regionUUID, " +
  647. "block_terraform, block_fly, allow_damage, " +
  648. "restrict_pushing, allow_land_resell, " +
  649. "allow_land_join_divide, block_show_in_search, " +
  650. "agent_limit, object_bonus, maturity, " +
  651. "disable_scripts, disable_collisions, " +
  652. "disable_physics, terrain_texture_1, " +
  653. "terrain_texture_2, terrain_texture_3, " +
  654. "terrain_texture_4, elevation_1_nw, " +
  655. "elevation_2_nw, elevation_1_ne, " +
  656. "elevation_2_ne, elevation_1_se, "+
  657. "elevation_2_se, elevation_1_sw, "+
  658. "elevation_2_sw, water_height, " +
  659. "terrain_raise_limit, terrain_lower_limit, " +
  660. "use_estate_sun, fixed_sun, sun_position, " +
  661. "covenant, Sandbox, sunvectorx, sunvectory, " +
  662. "sunvectorz, loaded_creation_datetime, " +
  663. "loaded_creation_id) values ( ?RegionUUID, ?BlockTerraform, " +
  664. "?BlockFly, ?AllowDamage, ?RestrictPushing, " +
  665. "?AllowLandResell, ?AllowLandJoinDivide, " +
  666. "?BlockShowInSearch, ?AgentLimit, ?ObjectBonus, " +
  667. "?Maturity, ?DisableScripts, ?DisableCollisions, " +
  668. "?DisablePhysics, ?TerrainTexture1, " +
  669. "?TerrainTexture2, ?TerrainTexture3, " +
  670. "?TerrainTexture4, ?Elevation1NW, ?Elevation2NW, " +
  671. "?Elevation1NE, ?Elevation2NE, ?Elevation1SE, " +
  672. "?Elevation2SE, ?Elevation1SW, ?Elevation2SW, " +
  673. "?WaterHeight, ?TerrainRaiseLimit, " +
  674. "?TerrainLowerLimit, ?UseEstateSun, ?FixedSun, " +
  675. "?SunPosition, ?Covenant, ?Sandbox, " +
  676. "?SunVectorX, ?SunVectorY, ?SunVectorZ, " +
  677. "?LoadedCreationDateTime, ?LoadedCreationID)";
  678. FillRegionSettingsCommand(cmd, rs);
  679. ExecuteNonQuery(cmd);
  680. cmd.Dispose();
  681. }
  682. }
  683. public List<LandData> LoadLandObjects(UUID regionUUID)
  684. {
  685. List<LandData> landData = new List<LandData>();
  686. lock (m_Connection)
  687. {
  688. MySqlCommand cmd = m_Connection.CreateCommand();
  689. cmd.CommandText = "select * from land where " +
  690. "RegionUUID = ?RegionUUID";
  691. cmd.Parameters.AddWithValue("RegionUUID", regionUUID.ToString());
  692. IDataReader reader = ExecuteReader(cmd);
  693. try
  694. {
  695. while (reader.Read())
  696. {
  697. LandData newLand = BuildLandData(reader);
  698. landData.Add(newLand);
  699. }
  700. }
  701. finally
  702. {
  703. reader.Close();
  704. }
  705. foreach (LandData land in landData)
  706. {
  707. cmd.Parameters.Clear();
  708. cmd.CommandText = "select * from landaccesslist " +
  709. "where LandUUID = ?LandUUID";
  710. cmd.Parameters.AddWithValue("LandUUID", land.GlobalID.ToString());
  711. reader = ExecuteReader(cmd);
  712. try
  713. {
  714. while (reader.Read())
  715. {
  716. land.ParcelAccessList.Add(BuildLandAccessData(reader));
  717. }
  718. }
  719. finally
  720. {
  721. reader.Close();
  722. }
  723. }
  724. cmd.Dispose();
  725. }
  726. return landData;
  727. }
  728. public void Shutdown()
  729. {
  730. }
  731. private SceneObjectPart BuildPrim(IDataReader row)
  732. {
  733. SceneObjectPart prim = new SceneObjectPart();
  734. prim.UUID = new UUID((String) row["UUID"]);
  735. // explicit conversion of integers is required, which sort
  736. // of sucks. No idea if there is a shortcut here or not.
  737. prim.CreationDate = Convert.ToInt32(row["CreationDate"]);
  738. if (row["Name"] != DBNull.Value)
  739. prim.Name = (String)row["Name"];
  740. else
  741. prim.Name = string.Empty;
  742. // various text fields
  743. prim.Text = (String) row["Text"];
  744. prim.Color = Color.FromArgb(Convert.ToInt32(row["ColorA"]),
  745. Convert.ToInt32(row["ColorR"]),
  746. Convert.ToInt32(row["ColorG"]),
  747. Convert.ToInt32(row["ColorB"]));
  748. prim.Description = (String) row["Description"];
  749. prim.SitName = (String) row["SitName"];
  750. prim.TouchName = (String) row["TouchName"];
  751. // permissions
  752. prim.ObjectFlags = Convert.ToUInt32(row["ObjectFlags"]);
  753. prim.CreatorID = new UUID((String) row["CreatorID"]);
  754. prim.OwnerID = new UUID((String) row["OwnerID"]);
  755. prim.GroupID = new UUID((String) row["GroupID"]);
  756. prim.LastOwnerID = new UUID((String) row["LastOwnerID"]);
  757. prim.OwnerMask = Convert.ToUInt32(row["OwnerMask"]);
  758. prim.NextOwnerMask = Convert.ToUInt32(row["NextOwnerMask"]);
  759. prim.GroupMask = Convert.ToUInt32(row["GroupMask"]);
  760. prim.EveryoneMask = Convert.ToUInt32(row["EveryoneMask"]);
  761. prim.BaseMask = Convert.ToUInt32(row["BaseMask"]);
  762. // vectors
  763. prim.OffsetPosition = new Vector3(
  764. Convert.ToSingle(row["PositionX"]),
  765. Convert.ToSingle(row["PositionY"]),
  766. Convert.ToSingle(row["PositionZ"])
  767. );
  768. prim.GroupPosition = new Vector3(
  769. Convert.ToSingle(row["GroupPositionX"]),
  770. Convert.ToSingle(row["GroupPositionY"]),
  771. Convert.ToSingle(row["GroupPositionZ"])
  772. );
  773. prim.Velocity = new Vector3(
  774. Convert.ToSingle(row["VelocityX"]),
  775. Convert.ToSingle(row["VelocityY"]),
  776. Convert.ToSingle(row["VelocityZ"])
  777. );
  778. prim.AngularVelocity = new Vector3(
  779. Convert.ToSingle(row["AngularVelocityX"]),
  780. Convert.ToSingle(row["AngularVelocityY"]),
  781. Convert.ToSingle(row["AngularVelocityZ"])
  782. );
  783. prim.Acceleration = new Vector3(
  784. Convert.ToSingle(row["AccelerationX"]),
  785. Convert.ToSingle(row["AccelerationY"]),
  786. Convert.ToSingle(row["AccelerationZ"])
  787. );
  788. // quaternions
  789. prim.RotationOffset = new Quaternion(
  790. Convert.ToSingle(row["RotationX"]),
  791. Convert.ToSingle(row["RotationY"]),
  792. Convert.ToSingle(row["RotationZ"]),
  793. Convert.ToSingle(row["RotationW"])
  794. );
  795. prim.SitTargetPositionLL = new Vector3(
  796. Convert.ToSingle(row["SitTargetOffsetX"]),
  797. Convert.ToSingle(row["SitTargetOffsetY"]),
  798. Convert.ToSingle(row["SitTargetOffsetZ"])
  799. );
  800. prim.SitTargetOrientationLL = new Quaternion(
  801. Convert.ToSingle(row["SitTargetOrientX"]),
  802. Convert.ToSingle(row["SitTargetOrientY"]),
  803. Convert.ToSingle(row["SitTargetOrientZ"]),
  804. Convert.ToSingle(row["SitTargetOrientW"])
  805. );
  806. prim.PayPrice[0] = Convert.ToInt32(row["PayPrice"]);
  807. prim.PayPrice[1] = Convert.ToInt32(row["PayButton1"]);
  808. prim.PayPrice[2] = Convert.ToInt32(row["PayButton2"]);
  809. prim.PayPrice[3] = Convert.ToInt32(row["PayButton3"]);
  810. prim.PayPrice[4] = Convert.ToInt32(row["PayButton4"]);
  811. prim.Sound = new UUID(row["LoopedSound"].ToString());
  812. prim.SoundGain = Convert.ToSingle(row["LoopedSoundGain"]);
  813. prim.SoundFlags = 1; // If it's persisted at all, it's looped
  814. if (!(row["TextureAnimation"] is DBNull))
  815. prim.TextureAnimation = (Byte[])row["TextureAnimation"];
  816. if (!(row["ParticleSystem"] is DBNull))
  817. prim.ParticleSystem = (Byte[])row["ParticleSystem"];
  818. prim.RotationalVelocity = new Vector3(
  819. Convert.ToSingle(row["OmegaX"]),
  820. Convert.ToSingle(row["OmegaY"]),
  821. Convert.ToSingle(row["OmegaZ"])
  822. );
  823. prim.SetCameraEyeOffset(new Vector3(
  824. Convert.ToSingle(row["CameraEyeOffsetX"]),
  825. Convert.ToSingle(row["CameraEyeOffsetY"]),
  826. Convert.ToSingle(row["CameraEyeOffsetZ"])
  827. ));
  828. prim.SetCameraAtOffset(new Vector3(
  829. Convert.ToSingle(row["CameraAtOffsetX"]),
  830. Convert.ToSingle(row["CameraAtOffsetY"]),
  831. Convert.ToSingle(row["CameraAtOffsetZ"])
  832. ));
  833. if (Convert.ToInt16(row["ForceMouselook"]) != 0)
  834. prim.SetForceMouselook(true);
  835. prim.ScriptAccessPin = Convert.ToInt32(row["ScriptAccessPin"]);
  836. if (Convert.ToInt16(row["AllowedDrop"]) != 0)
  837. prim.AllowedDrop = true;
  838. if (Convert.ToInt16(row["DieAtEdge"]) != 0)
  839. prim.DIE_AT_EDGE = true;
  840. prim.SalePrice = Convert.ToInt32(row["SalePrice"]);
  841. prim.ObjectSaleType = unchecked((byte)Convert.ToSByte(row["SaleType"]));
  842. prim.Material = unchecked((byte)Convert.ToSByte(row["Material"]));
  843. if (!(row["ClickAction"] is DBNull))
  844. prim.ClickAction = unchecked((byte)Convert.ToSByte(row["ClickAction"]));
  845. prim.CollisionSound = new UUID(row["CollisionSound"].ToString());
  846. prim.CollisionSoundVolume = Convert.ToSingle(row["CollisionSoundVolume"]);
  847. if (Convert.ToInt16(row["PassTouches"]) != 0)
  848. prim.PassTouches = true;
  849. prim.LinkNum = Convert.ToInt32(row["LinkNumber"]);
  850. return prim;
  851. }
  852. /// <summary>
  853. /// Build a prim inventory item from the persisted data.
  854. /// </summary>
  855. /// <param name="row"></param>
  856. /// <returns></returns>
  857. private static TaskInventoryItem BuildItem(IDataReader row)
  858. {
  859. TaskInventoryItem taskItem = new TaskInventoryItem();
  860. taskItem.ItemID = new UUID((String)row["itemID"]);
  861. taskItem.ParentPartID = new UUID((String)row["primID"]);
  862. taskItem.AssetID = new UUID((String)row["assetID"]);
  863. taskItem.ParentID = new UUID((String)row["parentFolderID"]);
  864. taskItem.InvType = Convert.ToInt32(row["invType"]);
  865. taskItem.Type = Convert.ToInt32(row["assetType"]);
  866. taskItem.Name = (String)row["name"];
  867. taskItem.Description = (String)row["description"];
  868. taskItem.CreationDate = Convert.ToUInt32(row["creationDate"]);
  869. taskItem.CreatorID = new UUID((String)row["creatorID"]);
  870. taskItem.OwnerID = new UUID((String)row["ownerID"]);
  871. taskItem.LastOwnerID = new UUID((String)row["lastOwnerID"]);
  872. taskItem.GroupID = new UUID((String)row["groupID"]);
  873. taskItem.NextPermissions = Convert.ToUInt32(row["nextPermissions"]);
  874. taskItem.CurrentPermissions = Convert.ToUInt32(row["currentPermissions"]);
  875. taskItem.BasePermissions = Convert.ToUInt32(row["basePermissions"]);
  876. taskItem.EveryonePermissions = Convert.ToUInt32(row["everyonePermissions"]);
  877. taskItem.GroupPermissions = Convert.ToUInt32(row["groupPermissions"]);
  878. taskItem.Flags = Convert.ToUInt32(row["flags"]);
  879. return taskItem;
  880. }
  881. private static RegionSettings BuildRegionSettings(IDataReader row)
  882. {
  883. RegionSettings newSettings = new RegionSettings();
  884. newSettings.RegionUUID = new UUID((string) row["regionUUID"]);
  885. newSettings.BlockTerraform = Convert.ToBoolean(row["block_terraform"]);
  886. newSettings.AllowDamage = Convert.ToBoolean(row["allow_damage"]);
  887. newSettings.BlockFly = Convert.ToBoolean(row["block_fly"]);
  888. newSettings.RestrictPushing = Convert.ToBoolean(row["restrict_pushing"]);
  889. newSettings.AllowLandResell = Convert.ToBoolean(row["allow_land_resell"]);
  890. newSettings.AllowLandJoinDivide = Convert.ToBoolean(row["allow_land_join_divide"]);
  891. newSettings.BlockShowInSearch = Convert.ToBoolean(row["block_show_in_search"]);
  892. newSettings.AgentLimit = Convert.ToInt32(row["agent_limit"]);
  893. newSettings.ObjectBonus = Convert.ToDouble(row["object_bonus"]);
  894. newSettings.Maturity = Convert.ToInt32(row["maturity"]);
  895. newSettings.DisableScripts = Convert.ToBoolean(row["disable_scripts"]);
  896. newSettings.DisableCollisions = Convert.ToBoolean(row["disable_collisions"]);
  897. newSettings.DisablePhysics = Convert.ToBoolean(row["disable_physics"]);
  898. newSettings.TerrainTexture1 = new UUID((String) row["terrain_texture_1"]);
  899. newSettings.TerrainTexture2 = new UUID((String) row["terrain_texture_2"]);
  900. newSettings.TerrainTexture3 = new UUID((String) row["terrain_texture_3"]);
  901. newSettings.TerrainTexture4 = new UUID((String) row["terrain_texture_4"]);
  902. newSettings.Elevation1NW = Convert.ToDouble(row["elevation_1_nw"]);
  903. newSettings.Elevation2NW = Convert.ToDouble(row["elevation_2_nw"]);
  904. newSettings.Elevation1NE = Convert.ToDouble(row["elevation_1_ne"]);
  905. newSettings.Elevation2NE = Convert.ToDouble(row["elevation_2_ne"]);
  906. newSettings.Elevation1SE = Convert.ToDouble(row["elevation_1_se"]);
  907. newSettings.Elevation2SE = Convert.ToDouble(row["elevation_2_se"]);
  908. newSettings.Elevation1SW = Convert.ToDouble(row["elevation_1_sw"]);
  909. newSettings.Elevation2SW = Convert.ToDouble(row["elevation_2_sw"]);
  910. newSettings.WaterHeight = Convert.ToDouble(row["water_height"]);
  911. newSettings.TerrainRaiseLimit = Convert.ToDouble(row["terrain_raise_limit"]);
  912. newSettings.TerrainLowerLimit = Convert.ToDouble(row["terrain_lower_limit"]);
  913. newSettings.UseEstateSun = Convert.ToBoolean(row["use_estate_sun"]);
  914. newSettings.Sandbox = Convert.ToBoolean(row["sandbox"]);
  915. newSettings.SunVector = new Vector3 (
  916. Convert.ToSingle(row["sunvectorx"]),
  917. Convert.ToSingle(row["sunvectory"]),
  918. Convert.ToSingle(row["sunvectorz"])
  919. );
  920. newSettings.FixedSun = Convert.ToBoolean(row["fixed_sun"]);
  921. newSettings.SunPosition = Convert.ToDouble(row["sun_position"]);
  922. newSettings.Covenant = new UUID((String) row["covenant"]);
  923. newSettings.LoadedCreationDateTime = Convert.ToInt32(row["loaded_creation_datetime"]);
  924. if (row["loaded_creation_id"] is DBNull)
  925. newSettings.LoadedCreationID = "";
  926. else
  927. newSettings.LoadedCreationID = (String) row["loaded_creation_id"];
  928. return newSettings;
  929. }
  930. /// <summary>
  931. ///
  932. /// </summary>
  933. /// <param name="row"></param>
  934. /// <returns></returns>
  935. private static LandData BuildLandData(IDataReader row)
  936. {
  937. LandData newData = new LandData();
  938. newData.GlobalID = new UUID((String) row["UUID"]);
  939. newData.LocalID = Convert.ToInt32(row["LocalLandID"]);
  940. // Bitmap is a byte[512]
  941. newData.Bitmap = (Byte[]) row["Bitmap"];
  942. newData.Name = (String) row["Name"];
  943. newData.Description = (String) row["Description"];
  944. newData.OwnerID = new UUID((String)row["OwnerUUID"]);
  945. newData.IsGroupOwned = Convert.ToBoolean(row["IsGroupOwned"]);
  946. newData.Area = Convert.ToInt32(row["Area"]);
  947. newData.AuctionID = Convert.ToUInt32(row["AuctionID"]); //Unimplemented
  948. newData.Category = (ParcelCategory) Convert.ToInt32(row["Category"]);
  949. //Enum libsecondlife.Parcel.ParcelCategory
  950. newData.ClaimDate = Convert.ToInt32(row["ClaimDate"]);
  951. newData.ClaimPrice = Convert.ToInt32(row["ClaimPrice"]);
  952. newData.GroupID = new UUID((String) row["GroupUUID"]);
  953. newData.SalePrice = Convert.ToInt32(row["SalePrice"]);
  954. newData.Status = (ParcelStatus) Convert.ToInt32(row["LandStatus"]);
  955. //Enum. libsecondlife.Parcel.ParcelStatus
  956. newData.Flags = Convert.ToUInt32(row["LandFlags"]);
  957. newData.LandingType = Convert.ToByte(row["LandingType"]);
  958. newData.MediaAutoScale = Convert.ToByte(row["MediaAutoScale"]);
  959. newData.MediaID = new UUID((String) row["MediaTextureUUID"]);
  960. newData.MediaURL = (String) row["MediaURL"];
  961. newData.MusicURL = (String) row["MusicURL"];
  962. newData.PassHours = Convert.ToSingle(row["PassHours"]);
  963. newData.PassPrice = Convert.ToInt32(row["PassPrice"]);
  964. UUID authedbuyer = UUID.Zero;
  965. UUID snapshotID = UUID.Zero;
  966. UUID.TryParse((string)row["AuthBuyerID"], out authedbuyer);
  967. UUID.TryParse((string)row["SnapshotUUID"], out snapshotID);
  968. newData.OtherCleanTime = Convert.ToInt32(row["OtherCleanTime"]);
  969. newData.Dwell = Convert.ToInt32(row["Dwell"]);
  970. newData.AuthBuyerID = authedbuyer;
  971. newData.SnapshotID = snapshotID;
  972. try
  973. {
  974. newData.UserLocation =
  975. new Vector3(Convert.ToSingle(row["UserLocationX"]), Convert.ToSingle(row["UserLocationY"]),
  976. Convert.ToSingle(row["UserLocationZ"]));
  977. newData.UserLookAt =
  978. new Vector3(Convert.ToSingle(row["UserLookAtX"]), Convert.ToSingle(row["UserLookAtY"]),
  979. Convert.ToSingle(row["UserLookAtZ"]));
  980. }
  981. catch (InvalidCastException)
  982. {
  983. newData.UserLocation = Vector3.Zero;
  984. newData.UserLookAt = Vector3.Zero;
  985. m_log.ErrorFormat("[PARCEL]: unable to get parcel telehub settings for {1}", newData.Name);
  986. }
  987. newData.ParcelAccessList = new List<ParcelManager.ParcelAccessEntry>();
  988. return newData;
  989. }
  990. /// <summary>
  991. ///
  992. /// </summary>
  993. /// <param name="row"></param>
  994. /// <returns></returns>
  995. private static ParcelManager.ParcelAccessEntry BuildLandAccessData(IDataReader row)
  996. {
  997. ParcelManager.ParcelAccessEntry entry = new ParcelManager.ParcelAccessEntry();
  998. entry.AgentID = new UUID((string) row["AccessUUID"]);
  999. entry.Flags = (AccessList) Convert.ToInt32(row["Flags"]);
  1000. entry.Time = new DateTime();
  1001. return entry;
  1002. }
  1003. /// <summary>
  1004. ///
  1005. /// </summary>
  1006. /// <param name="val"></param>
  1007. /// <returns></returns>
  1008. private static Array SerializeTerrain(double[,] val)
  1009. {
  1010. MemoryStream str = new MemoryStream(((int)Constants.RegionSize * (int)Constants.RegionSize) *sizeof (double));
  1011. BinaryWriter bw = new BinaryWriter(str);
  1012. // TODO: COMPATIBILITY - Add byte-order conversions
  1013. for (int x = 0; x < (int)Constants.RegionSize; x++)
  1014. for (int y = 0; y < (int)Constants.RegionSize; y++)
  1015. {
  1016. double height = val[x, y];
  1017. if (height == 0.0)
  1018. height = double.Epsilon;
  1019. bw.Write(height);
  1020. }
  1021. return str.ToArray();
  1022. }
  1023. /// <summary>
  1024. /// Fill the prim command with prim values
  1025. /// </summary>
  1026. /// <param name="row"></param>
  1027. /// <param name="prim"></param>
  1028. /// <param name="sceneGroupID"></param>
  1029. /// <param name="regionUUID"></param>
  1030. private void FillPrimCommand(MySqlCommand cmd, SceneObjectPart prim, UUID sceneGroupID, UUID regionUUID)
  1031. {
  1032. cmd.Parameters.AddWithValue("UUID", prim.UUID.ToString());
  1033. cmd.Parameters.AddWithValue("RegionUUID", regionUUID.ToString());
  1034. cmd.Parameters.AddWithValue("CreationDate", prim.CreationDate);
  1035. cmd.Parameters.AddWithValue("Name", prim.Name);
  1036. cmd.Parameters.AddWithValue("SceneGroupID", sceneGroupID.ToString());
  1037. // the UUID of the root part for this SceneObjectGroup
  1038. // various text fields
  1039. cmd.Parameters.AddWithValue("Text", prim.Text);
  1040. cmd.Parameters.AddWithValue("ColorR", prim.Color.R);
  1041. cmd.Parameters.AddWithValue("ColorG", prim.Color.G);
  1042. cmd.Parameters.AddWithValue("ColorB", prim.Color.B);
  1043. cmd.Parameters.AddWithValue("ColorA", prim.Color.A);
  1044. cmd.Parameters.AddWithValue("Description", prim.Description);
  1045. cmd.Parameters.AddWithValue("SitName", prim.SitName);
  1046. cmd.Parameters.AddWithValue("TouchName", prim.TouchName);
  1047. // permissions
  1048. cmd.Parameters.AddWithValue("ObjectFlags", prim.ObjectFlags);
  1049. cmd.Parameters.AddWithValue("CreatorID", prim.CreatorID.ToString());
  1050. cmd.Parameters.AddWithValue("OwnerID", prim.OwnerID.ToString());
  1051. cmd.Parameters.AddWithValue("GroupID", prim.GroupID.ToString());
  1052. cmd.Parameters.AddWithValue("LastOwnerID", prim.LastOwnerID.ToString());
  1053. cmd.Parameters.AddWithValue("OwnerMask", prim.OwnerMask);
  1054. cmd.Parameters.AddWithValue("NextOwnerMask", prim.NextOwnerMask);
  1055. cmd.Parameters.AddWithValue("GroupMask", prim.GroupMask);
  1056. cmd.Parameters.AddWithValue("EveryoneMask", prim.EveryoneMask);
  1057. cmd.Parameters.AddWithValue("BaseMask", prim.BaseMask);
  1058. // vectors
  1059. cmd.Parameters.AddWithValue("PositionX", (double)prim.OffsetPosition.X);
  1060. cmd.Parameters.AddWithValue("PositionY", (double)prim.OffsetPosition.Y);
  1061. cmd.Parameters.AddWithValue("PositionZ", (double)prim.OffsetPosition.Z);
  1062. cmd.Parameters.AddWithValue("GroupPositionX", (double)prim.GroupPosition.X);
  1063. cmd.Parameters.AddWithValue("GroupPositionY", (double)prim.GroupPosition.Y);
  1064. cmd.Parameters.AddWithValue("GroupPositionZ", (double)prim.GroupPosition.Z);
  1065. cmd.Parameters.AddWithValue("VelocityX", (double)prim.Velocity.X);
  1066. cmd.Parameters.AddWithValue("VelocityY", (double)prim.Velocity.Y);
  1067. cmd.Parameters.AddWithValue("VelocityZ", (double)prim.Velocity.Z);
  1068. cmd.Parameters.AddWithValue("AngularVelocityX", (double)prim.AngularVelocity.X);
  1069. cmd.Parameters.AddWithValue("AngularVelocityY", (double)prim.AngularVelocity.Y);
  1070. cmd.Parameters.AddWithValue("AngularVelocityZ", (double)prim.AngularVelocity.Z);
  1071. cmd.Parameters.AddWithValue("AccelerationX", (double)prim.Acceleration.X);
  1072. cmd.Parameters.AddWithValue("AccelerationY", (double)prim.Acceleration.Y);
  1073. cmd.Parameters.AddWithValue("AccelerationZ", (double)prim.Acceleration.Z);
  1074. // quaternions
  1075. cmd.Parameters.AddWithValue("RotationX", (double)prim.RotationOffset.X);
  1076. cmd.Parameters.AddWithValue("RotationY", (double)prim.RotationOffset.Y);
  1077. cmd.Parameters.AddWithValue("RotationZ", (double)prim.RotationOffset.Z);
  1078. cmd.Parameters.AddWithValue("RotationW", (double)prim.RotationOffset.W);
  1079. // Sit target
  1080. Vector3 sitTargetPos = prim.SitTargetPositionLL;
  1081. cmd.Parameters.AddWithValue("SitTargetOffsetX", (double)sitTargetPos.X);
  1082. cmd.Parameters.AddWithValue("SitTargetOffsetY", (double)sitTargetPos.Y);
  1083. cmd.Parameters.AddWithValue("SitTargetOffsetZ", (double)sitTargetPos.Z);
  1084. Quaternion sitTargetOrient = prim.SitTargetOrientationLL;
  1085. cmd.Parameters.AddWithValue("SitTargetOrientW", (double)sitTargetOrient.W);
  1086. cmd.Parameters.AddWithValue("SitTargetOrientX", (double)sitTargetOrient.X);
  1087. cmd.Parameters.AddWithValue("SitTargetOrientY", (double)sitTargetOrient.Y);
  1088. cmd.Parameters.AddWithValue("SitTargetOrientZ", (double)sitTargetOrient.Z);
  1089. cmd.Parameters.AddWithValue("PayPrice", prim.PayPrice[0]);
  1090. cmd.Parameters.AddWithValue("PayButton1", prim.PayPrice[1]);
  1091. cmd.Parameters.AddWithValue("PayButton2", prim.PayPrice[2]);
  1092. cmd.Parameters.AddWithValue("PayButton3", prim.PayPrice[3]);
  1093. cmd.Parameters.AddWithValue("PayButton4", prim.PayPrice[4]);
  1094. if ((prim.SoundFlags & 1) != 0) // Looped
  1095. {
  1096. cmd.Parameters.AddWithValue("LoopedSound", prim.Sound.ToString());
  1097. cmd.Parameters.AddWithValue("LoopedSoundGain", prim.SoundGain);
  1098. }
  1099. else
  1100. {
  1101. cmd.Parameters.AddWithValue("LoopedSound", UUID.Zero);
  1102. cmd.Parameters.AddWithValue("LoopedSoundGain", 0.0f);
  1103. }
  1104. cmd.Parameters.AddWithValue("TextureAnimation", prim.TextureAnimation);
  1105. cmd.Parameters.AddWithValue("ParticleSystem", prim.ParticleSystem);
  1106. cmd.Parameters.AddWithValue("OmegaX", (double)prim.RotationalVelocity.X);
  1107. cmd.Parameters.AddWithValue("OmegaY", (double)prim.RotationalVelocity.Y);
  1108. cmd.Parameters.AddWithValue("OmegaZ", (double)prim.RotationalVelocity.Z);
  1109. cmd.Parameters.AddWithValue("CameraEyeOffsetX", (double)prim.GetCameraEyeOffset().X);
  1110. cmd.Parameters.AddWithValue("CameraEyeOffsetY", (double)prim.GetCameraEyeOffset().Y);
  1111. cmd.Parameters.AddWithValue("CameraEyeOffsetZ", (double)prim.GetCameraEyeOffset().Z);
  1112. cmd.Parameters.AddWithValue("CameraAtOffsetX", (double)prim.GetCameraAtOffset().X);
  1113. cmd.Parameters.AddWithValue("CameraAtOffsetY", (double)prim.GetCameraAtOffset().Y);
  1114. cmd.Parameters.AddWithValue("CameraAtOffsetZ", (double)prim.GetCameraAtOffset().Z);
  1115. if (prim.GetForceMouselook())
  1116. cmd.Parameters.AddWithValue("ForceMouselook", 1);
  1117. else
  1118. cmd.Parameters.AddWithValue("ForceMouselook", 0);
  1119. cmd.Parameters.AddWithValue("ScriptAccessPin", prim.ScriptAccessPin);
  1120. if (prim.AllowedDrop)
  1121. cmd.Parameters.AddWithValue("AllowedDrop", 1);
  1122. else
  1123. cmd.Parameters.AddWithValue("AllowedDrop", 0);
  1124. if (prim.DIE_AT_EDGE)
  1125. cmd.Parameters.AddWithValue("DieAtEdge", 1);
  1126. else
  1127. cmd.Parameters.AddWithValue("DieAtEdge", 0);
  1128. cmd.Parameters.AddWithValue("SalePrice", prim.SalePrice);
  1129. cmd.Parameters.AddWithValue("SaleType", unchecked((sbyte)(prim.ObjectSaleType)));
  1130. byte clickAction = prim.ClickAction;
  1131. cmd.Parameters.AddWithValue("ClickAction", unchecked((sbyte)(clickAction)));
  1132. cmd.Parameters.AddWithValue("Material", unchecked((sbyte)(prim.Material)));
  1133. cmd.Parameters.AddWithValue("CollisionSound", prim.CollisionSound.ToString());
  1134. cmd.Parameters.AddWithValue("CollisionSoundVolume", prim.CollisionSoundVolume);
  1135. if (prim.PassTouches)
  1136. cmd.Parameters.AddWithValue("PassTouches", 1);
  1137. else
  1138. cmd.Parameters.AddWithValue("PassTouches", 0);
  1139. cmd.Parameters.AddWithValue("LinkNumber", prim.LinkNum);
  1140. }
  1141. /// <summary>
  1142. ///
  1143. /// </summary>
  1144. /// <param name="row"></param>
  1145. /// <param name="taskItem"></param>
  1146. private static void FillItemCommand(MySqlCommand cmd, TaskInventoryItem taskItem)
  1147. {
  1148. cmd.Parameters.AddWithValue("itemID", taskItem.ItemID);
  1149. cmd.Parameters.AddWithValue("primID", taskItem.ParentPartID);
  1150. cmd.Parameters.AddWithValue("assetID", taskItem.AssetID);
  1151. cmd.Parameters.AddWithValue("parentFolderID", taskItem.ParentID);
  1152. cmd.Parameters.AddWithValue("invType", taskItem.InvType);
  1153. cmd.Parameters.AddWithValue("assetType", taskItem.Type);
  1154. cmd.Parameters.AddWithValue("name", taskItem.Name);
  1155. cmd.Parameters.AddWithValue("description", taskItem.Description);
  1156. cmd.Parameters.AddWithValue("creationDate", taskItem.CreationDate);
  1157. cmd.Parameters.AddWithValue("creatorID", taskItem.CreatorID);
  1158. cmd.Parameters.AddWithValue("ownerID", taskItem.OwnerID);
  1159. cmd.Parameters.AddWithValue("lastOwnerID", taskItem.LastOwnerID);
  1160. cmd.Parameters.AddWithValue("groupID", taskItem.GroupID);
  1161. cmd.Parameters.AddWithValue("nextPermissions", taskItem.NextPermissions);
  1162. cmd.Parameters.AddWithValue("currentPermissions", taskItem.CurrentPermissions);
  1163. cmd.Parameters.AddWithValue("basePermissions", taskItem.BasePermissions);
  1164. cmd.Parameters.AddWithValue("everyonePermissions", taskItem.EveryonePermissions);
  1165. cmd.Parameters.AddWithValue("groupPermissions", taskItem.GroupPermissions);
  1166. cmd.Parameters.AddWithValue("flags", taskItem.Flags);
  1167. }
  1168. /// <summary>
  1169. ///
  1170. /// </summary>
  1171. private static void FillRegionSettingsCommand(MySqlCommand cmd, RegionSettings settings)
  1172. {
  1173. cmd.Parameters.AddWithValue("RegionUUID", settings.RegionUUID.ToString());
  1174. cmd.Parameters.AddWithValue("BlockTerraform", settings.BlockTerraform);
  1175. cmd.Parameters.AddWithValue("BlockFly", settings.BlockFly);
  1176. cmd.Parameters.AddWithValue("AllowDamage", settings.AllowDamage);
  1177. cmd.Parameters.AddWithValue("RestrictPushing", settings.RestrictPushing);
  1178. cmd.Parameters.AddWithValue("AllowLandResell", settings.AllowLandResell);
  1179. cmd.Parameters.AddWithValue("AllowLandJoinDivide", settings.AllowLandJoinDivide);
  1180. cmd.Parameters.AddWithValue("BlockShowInSearch", settings.BlockShowInSearch);
  1181. cmd.Parameters.AddWithValue("AgentLimit", settings.AgentLimit);
  1182. cmd.Parameters.AddWithValue("ObjectBonus", settings.ObjectBonus);
  1183. cmd.Parameters.AddWithValue("Maturity", settings.Maturity);
  1184. cmd.Parameters.AddWithValue("DisableScripts", settings.DisableScripts);
  1185. cmd.Parameters.AddWithValue("DisableCollisions", settings.DisableCollisions);
  1186. cmd.Parameters.AddWithValue("DisablePhysics", settings.DisablePhysics);
  1187. cmd.Parameters.AddWithValue("TerrainTexture1", settings.TerrainTexture1.ToString());
  1188. cmd.Parameters.AddWithValue("TerrainTexture2", settings.TerrainTexture2.ToString());
  1189. cmd.Parameters.AddWithValue("TerrainTexture3", settings.TerrainTexture3.ToString());
  1190. cmd.Parameters.AddWithValue("TerrainTexture4", settings.TerrainTexture4.ToString());
  1191. cmd.Parameters.AddWithValue("Elevation1NW", settings.Elevation1NW);
  1192. cmd.Parameters.AddWithValue("Elevation2NW", settings.Elevation2NW);
  1193. cmd.Parameters.AddWithValue("Elevation1NE", settings.Elevation1NE);
  1194. cmd.Parameters.AddWithValue("Elevation2NE", settings.Elevation2NE);
  1195. cmd.Parameters.AddWithValue("Elevation1SE", settings.Elevation1SE);
  1196. cmd.Parameters.AddWithValue("Elevation2SE", settings.Elevation2SE);
  1197. cmd.Parameters.AddWithValue("Elevation1SW", settings.Elevation1SW);
  1198. cmd.Parameters.AddWithValue("Elevation2SW", settings.Elevation2SW);
  1199. cmd.Parameters.AddWithValue("WaterHeight", settings.WaterHeight);
  1200. cmd.Parameters.AddWithValue("TerrainRaiseLimit", settings.TerrainRaiseLimit);
  1201. cmd.Parameters.AddWithValue("TerrainLowerLimit", settings.TerrainLowerLimit);
  1202. cmd.Parameters.AddWithValue("UseEstateSun", settings.UseEstateSun);
  1203. cmd.Parameters.AddWithValue("Sandbox", settings.Sandbox);
  1204. cmd.Parameters.AddWithValue("SunVectorX", settings.SunVector.X);
  1205. cmd.Parameters.AddWithValue("SunVectorY", settings.SunVector.Y);
  1206. cmd.Parameters.AddWithValue("SunVectorZ", settings.SunVector.Z);
  1207. cmd.Parameters.AddWithValue("FixedSun", settings.FixedSun);
  1208. cmd.Parameters.AddWithValue("SunPosition", settings.SunPosition);
  1209. cmd.Parameters.AddWithValue("Covenant", settings.Covenant.ToString());
  1210. cmd.Parameters.AddWithValue("LoadedCreationDateTime", settings.LoadedCreationDateTime);
  1211. cmd.Parameters.AddWithValue("LoadedCreationID", settings.LoadedCreationID);
  1212. }
  1213. /// <summary>
  1214. ///
  1215. /// </summary>
  1216. /// <param name="row"></param>
  1217. /// <param name="land"></param>
  1218. /// <param name="regionUUID"></param>
  1219. private static void FillLandCommand(MySqlCommand cmd, LandData land, UUID regionUUID)
  1220. {
  1221. cmd.Parameters.AddWithValue("UUID", land.GlobalID.ToString());
  1222. cmd.Parameters.AddWithValue("RegionUUID", regionUUID.ToString());
  1223. cmd.Parameters.AddWithValue("LocalLandID", land.LocalID);
  1224. // Bitmap is a byte[512]
  1225. cmd.Parameters.AddWithValue("Bitmap", land.Bitmap);
  1226. cmd.Parameters.AddWithValue("Name", land.Name);
  1227. cmd.Parameters.AddWithValue("Description", land.Description);
  1228. cmd.Parameters.AddWithValue("OwnerUUID", land.OwnerID.ToString());
  1229. cmd.Parameters.AddWithValue("IsGroupOwned", land.IsGroupOwned);
  1230. cmd.Parameters.AddWithValue("Area", land.Area);
  1231. cmd.Parameters.AddWithValue("AuctionID", land.AuctionID); //Unemplemented
  1232. cmd.Parameters.AddWithValue("Category", land.Category); //Enum libsecondlife.Parcel.ParcelCategory
  1233. cmd.Parameters.AddWithValue("ClaimDate", land.ClaimDate);
  1234. cmd.Parameters.AddWithValue("ClaimPrice", land.ClaimPrice);
  1235. cmd.Parameters.AddWithValue("GroupUUID", land.GroupID.ToString());
  1236. cmd.Parameters.AddWithValue("SalePrice", land.SalePrice);
  1237. cmd.Parameters.AddWithValue("LandStatus", land.Status); //Enum. libsecondlife.Parcel.ParcelStatus
  1238. cmd.Parameters.AddWithValue("LandFlags", land.Flags);
  1239. cmd.Parameters.AddWithValue("LandingType", land.LandingType);
  1240. cmd.Parameters.AddWithValue("MediaAutoScale", land.MediaAutoScale);
  1241. cmd.Parameters.AddWithValue("MediaTextureUUID", land.MediaID.ToString());
  1242. cmd.Parameters.AddWithValue("MediaURL", land.MediaURL);
  1243. cmd.Parameters.AddWithValue("MusicURL", land.MusicURL);
  1244. cmd.Parameters.AddWithValue("PassHours", land.PassHours);
  1245. cmd.Parameters.AddWithValue("PassPrice", land.PassPrice);
  1246. cmd.Parameters.AddWithValue("SnapshotUUID", land.SnapshotID.ToString());
  1247. cmd.Parameters.AddWithValue("UserLocationX", land.UserLocation.X);
  1248. cmd.Parameters.AddWithValue("UserLocationY", land.UserLocation.Y);
  1249. cmd.Parameters.AddWithValue("UserLocationZ", land.UserLocation.Z);
  1250. cmd.Parameters.AddWithValue("UserLookAtX", land.UserLookAt.X);
  1251. cmd.Parameters.AddWithValue("UserLookAtY", land.UserLookAt.Y);
  1252. cmd.Parameters.AddWithValue("UserLookAtZ", land.UserLookAt.Z);
  1253. cmd.Parameters.AddWithValue("AuthBuyerID", land.AuthBuyerID);
  1254. cmd.Parameters.AddWithValue("OtherCleanTime", land.OtherCleanTime);
  1255. cmd.Parameters.AddWithValue("Dwell", land.Dwell);
  1256. }
  1257. /// <summary>
  1258. ///
  1259. /// </summary>
  1260. /// <param name="row"></param>
  1261. /// <param name="entry"></param>
  1262. /// <param name="parcelID"></param>
  1263. private static void FillLandAccessCommand(MySqlCommand cmd, ParcelManager.ParcelAccessEntry entry, UUID parcelID)
  1264. {
  1265. cmd.Parameters.AddWithValue("LandUUID", parcelID.ToString());
  1266. cmd.Parameters.AddWithValue("AccessUUID", entry.AgentID.ToString());
  1267. cmd.Parameters.AddWithValue("Flags", entry.Flags);
  1268. }
  1269. /// <summary>
  1270. ///
  1271. /// </summary>
  1272. /// <param name="row"></param>
  1273. /// <returns></returns>
  1274. private PrimitiveBaseShape BuildShape(IDataReader row)
  1275. {
  1276. PrimitiveBaseShape s = new PrimitiveBaseShape();
  1277. s.Scale = new Vector3(
  1278. Convert.ToSingle(row["ScaleX"]),
  1279. Convert.ToSingle(row["ScaleY"]),
  1280. Convert.ToSingle(row["ScaleZ"])
  1281. );
  1282. // paths
  1283. s.PCode = Convert.ToByte(row["PCode"]);
  1284. s.PathBegin = Convert.ToUInt16(row["PathBegin"]);
  1285. s.PathEnd = Convert.ToUInt16(row["PathEnd"]);
  1286. s.PathScaleX = Convert.ToByte(row["PathScaleX"]);
  1287. s.PathScaleY = Convert.ToByte(row["PathScaleY"]);
  1288. s.PathShearX = Convert.ToByte(row["PathShearX"]);
  1289. s.PathShearY = Convert.ToByte(row["PathShearY"]);
  1290. s.PathSkew = Convert.ToSByte(row["PathSkew"]);
  1291. s.PathCurve = Convert.ToByte(row["PathCurve"]);
  1292. s.PathRadiusOffset = Convert.ToSByte(row["PathRadiusOffset"]);
  1293. s.PathRevolutions = Convert.ToByte(row["PathRevolutions"]);
  1294. s.PathTaperX = Convert.ToSByte(row["PathTaperX"]);
  1295. s.PathTaperY = Convert.ToSByte(row["PathTaperY"]);
  1296. s.PathTwist = Convert.ToSByte(row["PathTwist"]);
  1297. s.PathTwistBegin = Convert.ToSByte(row["PathTwistBegin"]);
  1298. // profile
  1299. s.ProfileBegin = Convert.ToUInt16(row["ProfileBegin"]);
  1300. s.ProfileEnd = Convert.ToUInt16(row["ProfileEnd"]);
  1301. s.ProfileCurve = Convert.ToByte(row["ProfileCurve"]);
  1302. s.ProfileHollow = Convert.ToUInt16(row["ProfileHollow"]);
  1303. byte[] textureEntry = (byte[]) row["Texture"];
  1304. s.TextureEntry = textureEntry;
  1305. s.ExtraParams = (byte[]) row["ExtraParams"];
  1306. s.State = Convert.ToByte(row["State"]);
  1307. return s;
  1308. }
  1309. /// <summary>
  1310. ///
  1311. /// </summary>
  1312. /// <param name="row"></param>
  1313. /// <param name="prim"></param>
  1314. private void FillShapeCommand(MySqlCommand cmd, SceneObjectPart prim)
  1315. {
  1316. PrimitiveBaseShape s = prim.Shape;
  1317. cmd.Parameters.AddWithValue("UUID", prim.UUID.ToString());
  1318. // shape is an enum
  1319. cmd.Parameters.AddWithValue("Shape", 0);
  1320. // vectors
  1321. cmd.Parameters.AddWithValue("ScaleX", (double)s.Scale.X);
  1322. cmd.Parameters.AddWithValue("ScaleY", (double)s.Scale.Y);
  1323. cmd.Parameters.AddWithValue("ScaleZ", (double)s.Scale.Z);
  1324. // paths
  1325. cmd.Parameters.AddWithValue("PCode", s.PCode);
  1326. cmd.Parameters.AddWithValue("PathBegin", s.PathBegin);
  1327. cmd.Parameters.AddWithValue("PathEnd", s.PathEnd);
  1328. cmd.Parameters.AddWithValue("PathScaleX", s.PathScaleX);
  1329. cmd.Parameters.AddWithValue("PathScaleY", s.PathScaleY);
  1330. cmd.Parameters.AddWithValue("PathShearX", s.PathShearX);
  1331. cmd.Parameters.AddWithValue("PathShearY", s.PathShearY);
  1332. cmd.Parameters.AddWithValue("PathSkew", s.PathSkew);
  1333. cmd.Parameters.AddWithValue("PathCurve", s.PathCurve);
  1334. cmd.Parameters.AddWithValue("PathRadiusOffset", s.PathRadiusOffset);
  1335. cmd.Parameters.AddWithValue("PathRevolutions", s.PathRevolutions);
  1336. cmd.Parameters.AddWithValue("PathTaperX", s.PathTaperX);
  1337. cmd.Parameters.AddWithValue("PathTaperY", s.PathTaperY);
  1338. cmd.Parameters.AddWithValue("PathTwist", s.PathTwist);
  1339. cmd.Parameters.AddWithValue("PathTwistBegin", s.PathTwistBegin);
  1340. // profile
  1341. cmd.Parameters.AddWithValue("ProfileBegin", s.ProfileBegin);
  1342. cmd.Parameters.AddWithValue("ProfileEnd", s.ProfileEnd);
  1343. cmd.Parameters.AddWithValue("ProfileCurve", s.ProfileCurve);
  1344. cmd.Parameters.AddWithValue("ProfileHollow", s.ProfileHollow);
  1345. cmd.Parameters.AddWithValue("Texture", s.TextureEntry);
  1346. cmd.Parameters.AddWithValue("ExtraParams", s.ExtraParams);
  1347. cmd.Parameters.AddWithValue("State", s.State);
  1348. }
  1349. public void StorePrimInventory(UUID primID, ICollection<TaskInventoryItem> items)
  1350. {
  1351. lock (m_Connection)
  1352. {
  1353. RemoveItems(primID);
  1354. MySqlCommand cmd = m_Connection.CreateCommand();
  1355. if (items.Count == 0)
  1356. return;
  1357. cmd.CommandText = "insert into primitems ("+
  1358. "invType, assetType, name, "+
  1359. "description, creationDate, nextPermissions, "+
  1360. "currentPermissions, basePermissions, "+
  1361. "everyonePermissions, groupPermissions, "+
  1362. "flags, itemID, primID, assetID, "+
  1363. "parentFolderID, creatorID, ownerID, "+
  1364. "groupID, lastOwnerID) values (?invType, "+
  1365. "?assetType, ?name, ?description, "+
  1366. "?creationDate, ?nextPermissions, "+
  1367. "?currentPermissions, ?basePermissions, "+
  1368. "?everyonePermissions, ?groupPermissions, "+
  1369. "?flags, ?itemID, ?primID, ?assetID, "+
  1370. "?parentFolderID, ?creatorID, ?ownerID, "+
  1371. "?groupID, ?lastOwnerID)";
  1372. foreach (TaskInventoryItem item in items)
  1373. {
  1374. cmd.Parameters.Clear();
  1375. FillItemCommand(cmd, item);
  1376. ExecuteNonQuery(cmd);
  1377. }
  1378. cmd.Dispose();
  1379. }
  1380. }
  1381. }
  1382. }