MySQLSimulationData.cs 72 KB

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