MySQLSimulationData.cs 101 KB

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