MySQLSimulationData.cs 104 KB

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