1
0

MySQLSimulationData.cs 97 KB

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