1
0

MySQLSimulationData.cs 114 KB

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