1
0

MySQLSimulationData.cs 104 KB

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