MySQLSimulationData.cs 95 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102
  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. 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 != UUID.Zero)
  950. prim.SoundFlags = 1; // If it's persisted at all, it's looped
  951. else
  952. prim.SoundFlags = 0;
  953. if (!(row["TextureAnimation"] is DBNull))
  954. prim.TextureAnimation = (byte[])row["TextureAnimation"];
  955. if (!(row["ParticleSystem"] is 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 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 System.DBNull))
  982. prim.MediaUrl = (string)row["MediaURL"];
  983. if (!(row["AttachedPosX"] is 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 System.DBNull))
  992. prim.DynAttrs = DAMap.FromXml((string)row["DynAttrs"]);
  993. else
  994. prim.DynAttrs = null;
  995. if (!(row["KeyframeMotion"] is 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. SOPVehicle vehicle = null;
  1014. if (row["Vehicle"].ToString() != String.Empty)
  1015. {
  1016. vehicle = SOPVehicle.FromXml2(row["Vehicle"].ToString());
  1017. if (vehicle != null)
  1018. prim.VehicleParams = vehicle;
  1019. }
  1020. PhysicsInertiaData pdata = null;
  1021. if (row["PhysInertia"].ToString() != String.Empty)
  1022. pdata = PhysicsInertiaData.FromXml2(row["PhysInertia"].ToString());
  1023. prim.PhysicsInertia = pdata;
  1024. if (!(row["sopanims"] is DBNull))
  1025. {
  1026. Byte[] data = (byte[])row["sopanims"];
  1027. if (data.Length > 0)
  1028. prim.DeSerializeAnimations(data);
  1029. else
  1030. prim.Animations = null;
  1031. }
  1032. else
  1033. {
  1034. prim.Animations = null;
  1035. }
  1036. prim.SitActiveRange = (float)row["sitactrange"];
  1037. int pseudocrc = (int)row["pseudocrc"];
  1038. if(pseudocrc != 0)
  1039. prim.PseudoCRC = pseudocrc;
  1040. return prim;
  1041. }
  1042. /// <summary>
  1043. /// Build a prim inventory item from the persisted data.
  1044. /// </summary>
  1045. /// <param name="row"></param>
  1046. /// <returns></returns>
  1047. private static TaskInventoryItem BuildItem(IDataReader row)
  1048. {
  1049. try
  1050. {
  1051. TaskInventoryItem taskItem = new TaskInventoryItem();
  1052. taskItem.ItemID = DBGuid.FromDB(row["itemID"]);
  1053. taskItem.ParentPartID = DBGuid.FromDB(row["primID"]);
  1054. taskItem.AssetID = DBGuid.FromDB(row["assetID"]);
  1055. taskItem.ParentID = DBGuid.FromDB(row["parentFolderID"]);
  1056. taskItem.InvType = Convert.ToInt32(row["invType"]);
  1057. taskItem.Type = Convert.ToInt32(row["assetType"]);
  1058. taskItem.Name = (String)row["name"];
  1059. taskItem.Description = (String)row["description"];
  1060. taskItem.CreationDate = Convert.ToUInt32(row["creationDate"]);
  1061. taskItem.CreatorIdentification = (String)row["creatorID"];
  1062. taskItem.OwnerID = DBGuid.FromDB(row["ownerID"]);
  1063. taskItem.LastOwnerID = DBGuid.FromDB(row["lastOwnerID"]);
  1064. taskItem.GroupID = DBGuid.FromDB(row["groupID"]);
  1065. taskItem.NextPermissions = Convert.ToUInt32(row["nextPermissions"]);
  1066. taskItem.CurrentPermissions = Convert.ToUInt32(row["currentPermissions"]);
  1067. taskItem.BasePermissions = Convert.ToUInt32(row["basePermissions"]);
  1068. taskItem.EveryonePermissions = Convert.ToUInt32(row["everyonePermissions"]);
  1069. taskItem.GroupPermissions = Convert.ToUInt32(row["groupPermissions"]);
  1070. taskItem.Flags = Convert.ToUInt32(row["flags"]);
  1071. return taskItem;
  1072. }
  1073. catch
  1074. {
  1075. m_log.ErrorFormat("[MYSQL DB]: Error reading task inventory: itemID was {0}, primID was {1}", row["itemID"].ToString(), row["primID"].ToString());
  1076. throw;
  1077. }
  1078. }
  1079. private static RegionSettings BuildRegionSettings(IDataReader row)
  1080. {
  1081. RegionSettings newSettings = new RegionSettings();
  1082. newSettings.RegionUUID = DBGuid.FromDB(row["regionUUID"]);
  1083. newSettings.BlockTerraform = Convert.ToBoolean(row["block_terraform"]);
  1084. newSettings.AllowDamage = Convert.ToBoolean(row["allow_damage"]);
  1085. newSettings.BlockFly = Convert.ToBoolean(row["block_fly"]);
  1086. newSettings.RestrictPushing = Convert.ToBoolean(row["restrict_pushing"]);
  1087. newSettings.AllowLandResell = Convert.ToBoolean(row["allow_land_resell"]);
  1088. newSettings.AllowLandJoinDivide = Convert.ToBoolean(row["allow_land_join_divide"]);
  1089. newSettings.BlockShowInSearch = Convert.ToBoolean(row["block_show_in_search"]);
  1090. newSettings.AgentLimit = Convert.ToInt32(row["agent_limit"]);
  1091. newSettings.ObjectBonus = Convert.ToDouble(row["object_bonus"]);
  1092. newSettings.Maturity = Convert.ToInt32(row["maturity"]);
  1093. newSettings.DisableScripts = Convert.ToBoolean(row["disable_scripts"]);
  1094. newSettings.DisableCollisions = Convert.ToBoolean(row["disable_collisions"]);
  1095. newSettings.DisablePhysics = Convert.ToBoolean(row["disable_physics"]);
  1096. newSettings.TerrainTexture1 = DBGuid.FromDB(row["terrain_texture_1"]);
  1097. newSettings.TerrainTexture2 = DBGuid.FromDB(row["terrain_texture_2"]);
  1098. newSettings.TerrainTexture3 = DBGuid.FromDB(row["terrain_texture_3"]);
  1099. newSettings.TerrainTexture4 = DBGuid.FromDB(row["terrain_texture_4"]);
  1100. newSettings.Elevation1NW = Convert.ToDouble(row["elevation_1_nw"]);
  1101. newSettings.Elevation2NW = Convert.ToDouble(row["elevation_2_nw"]);
  1102. newSettings.Elevation1NE = Convert.ToDouble(row["elevation_1_ne"]);
  1103. newSettings.Elevation2NE = Convert.ToDouble(row["elevation_2_ne"]);
  1104. newSettings.Elevation1SE = Convert.ToDouble(row["elevation_1_se"]);
  1105. newSettings.Elevation2SE = Convert.ToDouble(row["elevation_2_se"]);
  1106. newSettings.Elevation1SW = Convert.ToDouble(row["elevation_1_sw"]);
  1107. newSettings.Elevation2SW = Convert.ToDouble(row["elevation_2_sw"]);
  1108. newSettings.WaterHeight = Convert.ToDouble(row["water_height"]);
  1109. newSettings.TerrainRaiseLimit = Convert.ToDouble(row["terrain_raise_limit"]);
  1110. newSettings.TerrainLowerLimit = Convert.ToDouble(row["terrain_lower_limit"]);
  1111. newSettings.UseEstateSun = Convert.ToBoolean(row["use_estate_sun"]);
  1112. newSettings.Sandbox = Convert.ToBoolean(row["Sandbox"]);
  1113. newSettings.SunVector = new Vector3 (
  1114. Convert.ToSingle(row["sunvectorx"]),
  1115. Convert.ToSingle(row["sunvectory"]),
  1116. Convert.ToSingle(row["sunvectorz"])
  1117. );
  1118. newSettings.FixedSun = Convert.ToBoolean(row["fixed_sun"]);
  1119. newSettings.SunPosition = Convert.ToDouble(row["sun_position"]);
  1120. newSettings.Covenant = DBGuid.FromDB(row["covenant"]);
  1121. newSettings.CovenantChangedDateTime = Convert.ToInt32(row["covenant_datetime"]);
  1122. newSettings.LoadedCreationDateTime = Convert.ToInt32(row["loaded_creation_datetime"]);
  1123. if (row["loaded_creation_id"] is DBNull)
  1124. newSettings.LoadedCreationID = "";
  1125. else
  1126. newSettings.LoadedCreationID = (String) row["loaded_creation_id"];
  1127. newSettings.TerrainImageID = DBGuid.FromDB(row["map_tile_ID"]);
  1128. newSettings.ParcelImageID = DBGuid.FromDB(row["parcel_tile_ID"]);
  1129. newSettings.TelehubObject = DBGuid.FromDB(row["TelehubObject"]);
  1130. newSettings.GodBlockSearch = Convert.ToBoolean(row["block_search"]);
  1131. newSettings.Casino = Convert.ToBoolean(row["casino"]);
  1132. if (!(row["cacheID"] is DBNull))
  1133. newSettings.CacheID = DBGuid.FromDB(row["cacheID"]);
  1134. return newSettings;
  1135. }
  1136. /// <summary>
  1137. ///
  1138. /// </summary>
  1139. /// <param name="row"></param>
  1140. /// <returns></returns>
  1141. private static LandData BuildLandData(IDataReader row)
  1142. {
  1143. LandData newData = new LandData();
  1144. newData.GlobalID = DBGuid.FromDB(row["UUID"]);
  1145. newData.LocalID = Convert.ToInt32(row["LocalLandID"]);
  1146. // Bitmap is a byte[512]
  1147. newData.Bitmap = (Byte[]) row["Bitmap"];
  1148. newData.Name = (String) row["Name"];
  1149. newData.Description = (String) row["Description"];
  1150. newData.OwnerID = DBGuid.FromDB(row["OwnerUUID"]);
  1151. newData.IsGroupOwned = Convert.ToBoolean(row["IsGroupOwned"]);
  1152. newData.Area = Convert.ToInt32(row["Area"]);
  1153. newData.AuctionID = Convert.ToUInt32(row["AuctionID"]); //Unimplemented
  1154. newData.Category = (ParcelCategory) Convert.ToInt32(row["Category"]);
  1155. //Enum libsecondlife.Parcel.ParcelCategory
  1156. newData.ClaimDate = Convert.ToInt32(row["ClaimDate"]);
  1157. newData.ClaimPrice = Convert.ToInt32(row["ClaimPrice"]);
  1158. newData.GroupID = DBGuid.FromDB(row["GroupUUID"]);
  1159. newData.SalePrice = Convert.ToInt32(row["SalePrice"]);
  1160. newData.Status = (ParcelStatus) Convert.ToInt32(row["LandStatus"]);
  1161. //Enum. libsecondlife.Parcel.ParcelStatus
  1162. newData.Flags = Convert.ToUInt32(row["LandFlags"]);
  1163. newData.LandingType = Convert.ToByte(row["LandingType"]);
  1164. newData.MediaAutoScale = Convert.ToByte(row["MediaAutoScale"]);
  1165. newData.MediaID = DBGuid.FromDB(row["MediaTextureUUID"]);
  1166. newData.MediaURL = (String) row["MediaURL"];
  1167. newData.MusicURL = (String) row["MusicURL"];
  1168. newData.PassHours = Convert.ToSingle(row["PassHours"]);
  1169. newData.PassPrice = Convert.ToInt32(row["PassPrice"]);
  1170. UUID authedbuyer = UUID.Zero;
  1171. UUID snapshotID = UUID.Zero;
  1172. UUID.TryParse((string)row["AuthBuyerID"], out authedbuyer);
  1173. UUID.TryParse((string)row["SnapshotUUID"], out snapshotID);
  1174. newData.OtherCleanTime = Convert.ToInt32(row["OtherCleanTime"]);
  1175. newData.Dwell = Convert.ToSingle(row["Dwell"]);
  1176. newData.AuthBuyerID = authedbuyer;
  1177. newData.SnapshotID = snapshotID;
  1178. try
  1179. {
  1180. newData.UserLocation =
  1181. new Vector3(Convert.ToSingle(row["UserLocationX"]), Convert.ToSingle(row["UserLocationY"]),
  1182. Convert.ToSingle(row["UserLocationZ"]));
  1183. newData.UserLookAt =
  1184. new Vector3(Convert.ToSingle(row["UserLookAtX"]), Convert.ToSingle(row["UserLookAtY"]),
  1185. Convert.ToSingle(row["UserLookAtZ"]));
  1186. }
  1187. catch (InvalidCastException)
  1188. {
  1189. newData.UserLocation = Vector3.Zero;
  1190. newData.UserLookAt = Vector3.Zero;
  1191. m_log.ErrorFormat("[PARCEL]: unable to get parcel telehub settings for {1}", newData.Name);
  1192. }
  1193. newData.MediaDescription = (string) row["MediaDescription"];
  1194. newData.MediaType = (string) row["MediaType"];
  1195. newData.MediaWidth = Convert.ToInt32((((string) row["MediaSize"]).Split(','))[0]);
  1196. newData.MediaHeight = Convert.ToInt32((((string) row["MediaSize"]).Split(','))[1]);
  1197. newData.MediaLoop = Convert.ToBoolean(row["MediaLoop"]);
  1198. newData.ObscureMusic = Convert.ToBoolean(row["ObscureMusic"]);
  1199. newData.ObscureMedia = Convert.ToBoolean(row["ObscureMedia"]);
  1200. newData.ParcelAccessList = new List<LandAccessEntry>();
  1201. if (!(row["SeeAVs"] is System.DBNull))
  1202. newData.SeeAVs = Convert.ToInt32(row["SeeAVs"]) != 0 ? true : false;
  1203. if (!(row["AnyAVSounds"] is System.DBNull))
  1204. newData.AnyAVSounds = Convert.ToInt32(row["AnyAVSounds"]) != 0 ? true : false;
  1205. if (!(row["GroupAVSounds"] is System.DBNull))
  1206. newData.GroupAVSounds = Convert.ToInt32(row["GroupAVSounds"]) != 0 ? true : false;
  1207. if (row["environment"] is DBNull)
  1208. {
  1209. newData.Environment = null;
  1210. newData.EnvironmentVersion = -1;
  1211. }
  1212. else
  1213. {
  1214. string env = (string)row["environment"];
  1215. if(string.IsNullOrEmpty(env))
  1216. {
  1217. newData.Environment = null;
  1218. newData.EnvironmentVersion = -1;
  1219. }
  1220. else
  1221. {
  1222. try
  1223. {
  1224. ViewerEnvironment VEnv = ViewerEnvironment.FromOSDString(env);
  1225. newData.Environment = VEnv;
  1226. newData.EnvironmentVersion = VEnv.version;
  1227. }
  1228. catch
  1229. {
  1230. newData.Environment = null;
  1231. newData.EnvironmentVersion = -1;
  1232. }
  1233. }
  1234. }
  1235. return newData;
  1236. }
  1237. /// <summary>
  1238. ///
  1239. /// </summary>
  1240. /// <param name="row"></param>
  1241. /// <returns></returns>
  1242. private static LandAccessEntry BuildLandAccessData(IDataReader row)
  1243. {
  1244. LandAccessEntry entry = new LandAccessEntry();
  1245. entry.AgentID = DBGuid.FromDB(row["AccessUUID"]);
  1246. entry.Flags = (AccessList) Convert.ToInt32(row["Flags"]);
  1247. entry.Expires = Convert.ToInt32(row["Expires"]);
  1248. return entry;
  1249. }
  1250. /// <summary>
  1251. /// Fill the prim command with prim values
  1252. /// </summary>
  1253. /// <param name="row"></param>
  1254. /// <param name="prim"></param>
  1255. /// <param name="sceneGroupID"></param>
  1256. /// <param name="regionUUID"></param>
  1257. private void FillPrimCommand(MySqlCommand cmd, SceneObjectPart prim, UUID sceneGroupID, UUID regionUUID)
  1258. {
  1259. cmd.Parameters.AddWithValue("UUID", prim.UUID.ToString());
  1260. cmd.Parameters.AddWithValue("RegionUUID", regionUUID.ToString());
  1261. cmd.Parameters.AddWithValue("CreationDate", prim.CreationDate);
  1262. cmd.Parameters.AddWithValue("Name", prim.Name);
  1263. cmd.Parameters.AddWithValue("SceneGroupID", sceneGroupID.ToString());
  1264. // the UUID of the root part for this SceneObjectGroup
  1265. // various text fields
  1266. cmd.Parameters.AddWithValue("Text", prim.Text);
  1267. cmd.Parameters.AddWithValue("ColorR", prim.Color.R);
  1268. cmd.Parameters.AddWithValue("ColorG", prim.Color.G);
  1269. cmd.Parameters.AddWithValue("ColorB", prim.Color.B);
  1270. cmd.Parameters.AddWithValue("ColorA", prim.Color.A);
  1271. cmd.Parameters.AddWithValue("Description", prim.Description);
  1272. cmd.Parameters.AddWithValue("SitName", prim.SitName);
  1273. cmd.Parameters.AddWithValue("TouchName", prim.TouchName);
  1274. // permissions
  1275. cmd.Parameters.AddWithValue("ObjectFlags", (uint)prim.Flags);
  1276. cmd.Parameters.AddWithValue("CreatorID", prim.CreatorIdentification.ToString());
  1277. cmd.Parameters.AddWithValue("OwnerID", prim.OwnerID.ToString());
  1278. cmd.Parameters.AddWithValue("GroupID", prim.GroupID.ToString());
  1279. cmd.Parameters.AddWithValue("LastOwnerID", prim.LastOwnerID.ToString());
  1280. cmd.Parameters.AddWithValue("RezzerID", prim.RezzerID.ToString());
  1281. cmd.Parameters.AddWithValue("OwnerMask", prim.OwnerMask);
  1282. cmd.Parameters.AddWithValue("NextOwnerMask", prim.NextOwnerMask);
  1283. cmd.Parameters.AddWithValue("GroupMask", prim.GroupMask);
  1284. cmd.Parameters.AddWithValue("EveryoneMask", prim.EveryoneMask);
  1285. cmd.Parameters.AddWithValue("BaseMask", prim.BaseMask);
  1286. // vectors
  1287. cmd.Parameters.AddWithValue("PositionX", prim.OffsetPosition.X);
  1288. cmd.Parameters.AddWithValue("PositionY", prim.OffsetPosition.Y);
  1289. cmd.Parameters.AddWithValue("PositionZ", prim.OffsetPosition.Z);
  1290. cmd.Parameters.AddWithValue("GroupPositionX", prim.GroupPosition.X);
  1291. cmd.Parameters.AddWithValue("GroupPositionY", prim.GroupPosition.Y);
  1292. cmd.Parameters.AddWithValue("GroupPositionZ", prim.GroupPosition.Z);
  1293. cmd.Parameters.AddWithValue("VelocityX", prim.Velocity.X);
  1294. cmd.Parameters.AddWithValue("VelocityY", prim.Velocity.Y);
  1295. cmd.Parameters.AddWithValue("VelocityZ", prim.Velocity.Z);
  1296. cmd.Parameters.AddWithValue("AngularVelocityX", prim.AngularVelocity.X);
  1297. cmd.Parameters.AddWithValue("AngularVelocityY", prim.AngularVelocity.Y);
  1298. cmd.Parameters.AddWithValue("AngularVelocityZ", prim.AngularVelocity.Z);
  1299. cmd.Parameters.AddWithValue("AccelerationX", prim.Acceleration.X);
  1300. cmd.Parameters.AddWithValue("AccelerationY", prim.Acceleration.Y);
  1301. cmd.Parameters.AddWithValue("AccelerationZ", prim.Acceleration.Z);
  1302. cmd.Parameters.AddWithValue("standtargetx", prim.StandOffset.X);
  1303. cmd.Parameters.AddWithValue("standtargety", prim.StandOffset.Y);
  1304. cmd.Parameters.AddWithValue("standtargetz", prim.StandOffset.Z);
  1305. // quaternions
  1306. cmd.Parameters.AddWithValue("RotationX", prim.RotationOffset.X);
  1307. cmd.Parameters.AddWithValue("RotationY", prim.RotationOffset.Y);
  1308. cmd.Parameters.AddWithValue("RotationZ", prim.RotationOffset.Z);
  1309. cmd.Parameters.AddWithValue("RotationW", prim.RotationOffset.W);
  1310. // Sit target
  1311. Vector3 sitTargetPos = prim.SitTargetPositionLL;
  1312. cmd.Parameters.AddWithValue("SitTargetOffsetX", sitTargetPos.X);
  1313. cmd.Parameters.AddWithValue("SitTargetOffsetY", sitTargetPos.Y);
  1314. cmd.Parameters.AddWithValue("SitTargetOffsetZ", sitTargetPos.Z);
  1315. Quaternion sitTargetOrient = prim.SitTargetOrientationLL;
  1316. cmd.Parameters.AddWithValue("SitTargetOrientW", sitTargetOrient.W);
  1317. cmd.Parameters.AddWithValue("SitTargetOrientX", sitTargetOrient.X);
  1318. cmd.Parameters.AddWithValue("SitTargetOrientY", sitTargetOrient.Y);
  1319. cmd.Parameters.AddWithValue("SitTargetOrientZ", sitTargetOrient.Z);
  1320. cmd.Parameters.AddWithValue("PayPrice", prim.PayPrice[0]);
  1321. cmd.Parameters.AddWithValue("PayButton1", prim.PayPrice[1]);
  1322. cmd.Parameters.AddWithValue("PayButton2", prim.PayPrice[2]);
  1323. cmd.Parameters.AddWithValue("PayButton3", prim.PayPrice[3]);
  1324. cmd.Parameters.AddWithValue("PayButton4", prim.PayPrice[4]);
  1325. if ((prim.SoundFlags & 1) != 0) // Looped
  1326. {
  1327. cmd.Parameters.AddWithValue("LoopedSound", prim.Sound.ToString());
  1328. cmd.Parameters.AddWithValue("LoopedSoundGain", (float)prim.SoundGain);
  1329. }
  1330. else
  1331. {
  1332. cmd.Parameters.AddWithValue("LoopedSound", UUID.Zero);
  1333. cmd.Parameters.AddWithValue("LoopedSoundGain", 0.0f);
  1334. }
  1335. cmd.Parameters.AddWithValue("TextureAnimation", prim.TextureAnimation);
  1336. cmd.Parameters.AddWithValue("ParticleSystem", prim.ParticleSystem);
  1337. cmd.Parameters.AddWithValue("CameraEyeOffsetX", prim.GetCameraEyeOffset().X);
  1338. cmd.Parameters.AddWithValue("CameraEyeOffsetY", prim.GetCameraEyeOffset().Y);
  1339. cmd.Parameters.AddWithValue("CameraEyeOffsetZ", prim.GetCameraEyeOffset().Z);
  1340. cmd.Parameters.AddWithValue("CameraAtOffsetX", prim.GetCameraAtOffset().X);
  1341. cmd.Parameters.AddWithValue("CameraAtOffsetY", prim.GetCameraAtOffset().Y);
  1342. cmd.Parameters.AddWithValue("CameraAtOffsetZ", prim.GetCameraAtOffset().Z);
  1343. if (prim.GetForceMouselook())
  1344. cmd.Parameters.AddWithValue("ForceMouselook", 1);
  1345. else
  1346. cmd.Parameters.AddWithValue("ForceMouselook", 0);
  1347. cmd.Parameters.AddWithValue("ScriptAccessPin", prim.ScriptAccessPin);
  1348. if (prim.AllowedDrop)
  1349. cmd.Parameters.AddWithValue("AllowedDrop", 1);
  1350. else
  1351. cmd.Parameters.AddWithValue("AllowedDrop", 0);
  1352. if (prim.DIE_AT_EDGE)
  1353. cmd.Parameters.AddWithValue("DieAtEdge", 1);
  1354. else
  1355. cmd.Parameters.AddWithValue("DieAtEdge", 0);
  1356. cmd.Parameters.AddWithValue("SalePrice", prim.SalePrice);
  1357. cmd.Parameters.AddWithValue("SaleType", unchecked((sbyte)(prim.ObjectSaleType)));
  1358. byte clickAction = prim.ClickAction;
  1359. cmd.Parameters.AddWithValue("ClickAction", unchecked((sbyte)(clickAction)));
  1360. cmd.Parameters.AddWithValue("Material", unchecked((sbyte)(prim.Material)));
  1361. cmd.Parameters.AddWithValue("CollisionSound", prim.CollisionSound.ToString());
  1362. cmd.Parameters.AddWithValue("CollisionSoundVolume", prim.CollisionSoundVolume);
  1363. if (prim.PassTouches)
  1364. cmd.Parameters.AddWithValue("PassTouches", 1);
  1365. else
  1366. cmd.Parameters.AddWithValue("PassTouches", 0);
  1367. if (prim.PassCollisions)
  1368. cmd.Parameters.AddWithValue("PassCollisions", 1);
  1369. else
  1370. cmd.Parameters.AddWithValue("PassCollisions", 0);
  1371. cmd.Parameters.AddWithValue("LinkNumber", prim.LinkNum);
  1372. cmd.Parameters.AddWithValue("MediaURL", prim.MediaUrl);
  1373. if (prim.AttachedPos != null)
  1374. {
  1375. cmd.Parameters.AddWithValue("AttachedPosX", prim.AttachedPos.X);
  1376. cmd.Parameters.AddWithValue("AttachedPosY", prim.AttachedPos.Y);
  1377. cmd.Parameters.AddWithValue("AttachedPosZ", prim.AttachedPos.Z);
  1378. }
  1379. if (prim.KeyframeMotion != null)
  1380. cmd.Parameters.AddWithValue("KeyframeMotion", prim.KeyframeMotion.Serialize());
  1381. else
  1382. cmd.Parameters.AddWithValue("KeyframeMotion", new Byte[0]);
  1383. if (prim.PhysicsInertia != null)
  1384. cmd.Parameters.AddWithValue("PhysInertia", prim.PhysicsInertia.ToXml2());
  1385. else
  1386. cmd.Parameters.AddWithValue("PhysInertia", String.Empty);
  1387. if (prim.VehicleParams != null)
  1388. cmd.Parameters.AddWithValue("Vehicle", prim.VehicleParams.ToXml2());
  1389. else
  1390. cmd.Parameters.AddWithValue("Vehicle", String.Empty);
  1391. if (prim.DynAttrs != null && prim.DynAttrs.CountNamespaces > 0)
  1392. cmd.Parameters.AddWithValue("DynAttrs", prim.DynAttrs.ToXml());
  1393. else
  1394. cmd.Parameters.AddWithValue("DynAttrs", null);
  1395. cmd.Parameters.AddWithValue("PhysicsShapeType", prim.PhysicsShapeType);
  1396. cmd.Parameters.AddWithValue("Density", prim.Density);
  1397. cmd.Parameters.AddWithValue("GravityModifier", prim.GravityModifier);
  1398. cmd.Parameters.AddWithValue("Friction", prim.Friction);
  1399. cmd.Parameters.AddWithValue("Restitution", prim.Restitution);
  1400. cmd.Parameters.AddWithValue("RotationAxisLocks", prim.RotationAxisLocks);
  1401. if (prim.Animations!= null)
  1402. cmd.Parameters.AddWithValue("sopanims", prim.SerializeAnimations());
  1403. else
  1404. cmd.Parameters.AddWithValue("sopanims", null);
  1405. cmd.Parameters.AddWithValue("sitactrange", prim.SitActiveRange);
  1406. cmd.Parameters.AddWithValue("pseudocrc", prim.PseudoCRC);
  1407. }
  1408. /// <summary>
  1409. ///
  1410. /// </summary>
  1411. /// <param name="row"></param>
  1412. /// <param name="taskItem"></param>
  1413. private static void FillItemCommand(MySqlCommand cmd, TaskInventoryItem taskItem)
  1414. {
  1415. cmd.Parameters.AddWithValue("itemID", taskItem.ItemID);
  1416. cmd.Parameters.AddWithValue("primID", taskItem.ParentPartID);
  1417. cmd.Parameters.AddWithValue("assetID", taskItem.AssetID);
  1418. cmd.Parameters.AddWithValue("parentFolderID", taskItem.ParentID);
  1419. cmd.Parameters.AddWithValue("invType", taskItem.InvType);
  1420. cmd.Parameters.AddWithValue("assetType", taskItem.Type);
  1421. cmd.Parameters.AddWithValue("name", taskItem.Name);
  1422. cmd.Parameters.AddWithValue("description", taskItem.Description);
  1423. cmd.Parameters.AddWithValue("creationDate", taskItem.CreationDate);
  1424. cmd.Parameters.AddWithValue("creatorID", taskItem.CreatorIdentification);
  1425. cmd.Parameters.AddWithValue("ownerID", taskItem.OwnerID);
  1426. cmd.Parameters.AddWithValue("lastOwnerID", taskItem.LastOwnerID);
  1427. cmd.Parameters.AddWithValue("groupID", taskItem.GroupID);
  1428. cmd.Parameters.AddWithValue("nextPermissions", taskItem.NextPermissions);
  1429. cmd.Parameters.AddWithValue("currentPermissions", taskItem.CurrentPermissions);
  1430. cmd.Parameters.AddWithValue("basePermissions", taskItem.BasePermissions);
  1431. cmd.Parameters.AddWithValue("everyonePermissions", taskItem.EveryonePermissions);
  1432. cmd.Parameters.AddWithValue("groupPermissions", taskItem.GroupPermissions);
  1433. cmd.Parameters.AddWithValue("flags", taskItem.Flags);
  1434. }
  1435. /// <summary>
  1436. ///
  1437. /// </summary>
  1438. private static void FillRegionSettingsCommand(MySqlCommand cmd, RegionSettings settings)
  1439. {
  1440. cmd.Parameters.AddWithValue("RegionUUID", settings.RegionUUID.ToString());
  1441. cmd.Parameters.AddWithValue("BlockTerraform", settings.BlockTerraform);
  1442. cmd.Parameters.AddWithValue("BlockFly", settings.BlockFly);
  1443. cmd.Parameters.AddWithValue("AllowDamage", settings.AllowDamage);
  1444. cmd.Parameters.AddWithValue("RestrictPushing", settings.RestrictPushing);
  1445. cmd.Parameters.AddWithValue("AllowLandResell", settings.AllowLandResell);
  1446. cmd.Parameters.AddWithValue("AllowLandJoinDivide", settings.AllowLandJoinDivide);
  1447. cmd.Parameters.AddWithValue("BlockShowInSearch", settings.BlockShowInSearch);
  1448. cmd.Parameters.AddWithValue("AgentLimit", settings.AgentLimit);
  1449. cmd.Parameters.AddWithValue("ObjectBonus", settings.ObjectBonus);
  1450. cmd.Parameters.AddWithValue("Maturity", settings.Maturity);
  1451. cmd.Parameters.AddWithValue("DisableScripts", settings.DisableScripts);
  1452. cmd.Parameters.AddWithValue("DisableCollisions", settings.DisableCollisions);
  1453. cmd.Parameters.AddWithValue("DisablePhysics", settings.DisablePhysics);
  1454. cmd.Parameters.AddWithValue("TerrainTexture1", settings.TerrainTexture1.ToString());
  1455. cmd.Parameters.AddWithValue("TerrainTexture2", settings.TerrainTexture2.ToString());
  1456. cmd.Parameters.AddWithValue("TerrainTexture3", settings.TerrainTexture3.ToString());
  1457. cmd.Parameters.AddWithValue("TerrainTexture4", settings.TerrainTexture4.ToString());
  1458. cmd.Parameters.AddWithValue("Elevation1NW", settings.Elevation1NW);
  1459. cmd.Parameters.AddWithValue("Elevation2NW", settings.Elevation2NW);
  1460. cmd.Parameters.AddWithValue("Elevation1NE", settings.Elevation1NE);
  1461. cmd.Parameters.AddWithValue("Elevation2NE", settings.Elevation2NE);
  1462. cmd.Parameters.AddWithValue("Elevation1SE", settings.Elevation1SE);
  1463. cmd.Parameters.AddWithValue("Elevation2SE", settings.Elevation2SE);
  1464. cmd.Parameters.AddWithValue("Elevation1SW", settings.Elevation1SW);
  1465. cmd.Parameters.AddWithValue("Elevation2SW", settings.Elevation2SW);
  1466. cmd.Parameters.AddWithValue("WaterHeight", settings.WaterHeight);
  1467. cmd.Parameters.AddWithValue("TerrainRaiseLimit", settings.TerrainRaiseLimit);
  1468. cmd.Parameters.AddWithValue("TerrainLowerLimit", settings.TerrainLowerLimit);
  1469. cmd.Parameters.AddWithValue("UseEstateSun", settings.UseEstateSun);
  1470. cmd.Parameters.AddWithValue("Sandbox", settings.Sandbox);
  1471. cmd.Parameters.AddWithValue("SunVectorX", settings.SunVector.X);
  1472. cmd.Parameters.AddWithValue("SunVectorY", settings.SunVector.Y);
  1473. cmd.Parameters.AddWithValue("SunVectorZ", settings.SunVector.Z);
  1474. cmd.Parameters.AddWithValue("FixedSun", settings.FixedSun);
  1475. cmd.Parameters.AddWithValue("SunPosition", settings.SunPosition);
  1476. cmd.Parameters.AddWithValue("Covenant", settings.Covenant.ToString());
  1477. cmd.Parameters.AddWithValue("CovenantChangedDateTime", settings.CovenantChangedDateTime);
  1478. cmd.Parameters.AddWithValue("LoadedCreationDateTime", settings.LoadedCreationDateTime);
  1479. cmd.Parameters.AddWithValue("LoadedCreationID", settings.LoadedCreationID);
  1480. cmd.Parameters.AddWithValue("TerrainImageID", settings.TerrainImageID);
  1481. cmd.Parameters.AddWithValue("block_search", settings.GodBlockSearch);
  1482. cmd.Parameters.AddWithValue("casino", settings.Casino);
  1483. cmd.Parameters.AddWithValue("ParcelImageID", settings.ParcelImageID);
  1484. cmd.Parameters.AddWithValue("TelehubObject", settings.TelehubObject);
  1485. cmd.Parameters.AddWithValue("cacheID", settings.CacheID);
  1486. }
  1487. /// <summary>
  1488. ///
  1489. /// </summary>
  1490. /// <param name="row"></param>
  1491. /// <param name="land"></param>
  1492. /// <param name="regionUUID"></param>
  1493. private static void FillLandCommand(MySqlCommand cmd, LandData land, UUID regionUUID)
  1494. {
  1495. cmd.Parameters.AddWithValue("UUID", land.GlobalID.ToString());
  1496. cmd.Parameters.AddWithValue("RegionUUID", regionUUID.ToString());
  1497. cmd.Parameters.AddWithValue("LocalLandID", land.LocalID);
  1498. // Bitmap is a byte[512]
  1499. cmd.Parameters.AddWithValue("Bitmap", land.Bitmap);
  1500. cmd.Parameters.AddWithValue("Name", land.Name);
  1501. cmd.Parameters.AddWithValue("Description", land.Description);
  1502. cmd.Parameters.AddWithValue("OwnerUUID", land.OwnerID.ToString());
  1503. cmd.Parameters.AddWithValue("IsGroupOwned", land.IsGroupOwned);
  1504. cmd.Parameters.AddWithValue("Area", land.Area);
  1505. cmd.Parameters.AddWithValue("AuctionID", land.AuctionID); //Unemplemented
  1506. cmd.Parameters.AddWithValue("Category", land.Category); //Enum libsecondlife.Parcel.ParcelCategory
  1507. cmd.Parameters.AddWithValue("ClaimDate", land.ClaimDate);
  1508. cmd.Parameters.AddWithValue("ClaimPrice", land.ClaimPrice);
  1509. cmd.Parameters.AddWithValue("GroupUUID", land.GroupID.ToString());
  1510. cmd.Parameters.AddWithValue("SalePrice", land.SalePrice);
  1511. cmd.Parameters.AddWithValue("LandStatus", land.Status); //Enum. libsecondlife.Parcel.ParcelStatus
  1512. cmd.Parameters.AddWithValue("LandFlags", land.Flags);
  1513. cmd.Parameters.AddWithValue("LandingType", land.LandingType);
  1514. cmd.Parameters.AddWithValue("MediaAutoScale", land.MediaAutoScale);
  1515. cmd.Parameters.AddWithValue("MediaTextureUUID", land.MediaID.ToString());
  1516. cmd.Parameters.AddWithValue("MediaURL", land.MediaURL);
  1517. cmd.Parameters.AddWithValue("MusicURL", land.MusicURL);
  1518. cmd.Parameters.AddWithValue("PassHours", land.PassHours);
  1519. cmd.Parameters.AddWithValue("PassPrice", land.PassPrice);
  1520. cmd.Parameters.AddWithValue("SnapshotUUID", land.SnapshotID.ToString());
  1521. cmd.Parameters.AddWithValue("UserLocationX", land.UserLocation.X);
  1522. cmd.Parameters.AddWithValue("UserLocationY", land.UserLocation.Y);
  1523. cmd.Parameters.AddWithValue("UserLocationZ", land.UserLocation.Z);
  1524. cmd.Parameters.AddWithValue("UserLookAtX", land.UserLookAt.X);
  1525. cmd.Parameters.AddWithValue("UserLookAtY", land.UserLookAt.Y);
  1526. cmd.Parameters.AddWithValue("UserLookAtZ", land.UserLookAt.Z);
  1527. cmd.Parameters.AddWithValue("AuthBuyerID", land.AuthBuyerID);
  1528. cmd.Parameters.AddWithValue("OtherCleanTime", land.OtherCleanTime);
  1529. cmd.Parameters.AddWithValue("Dwell", land.Dwell);
  1530. cmd.Parameters.AddWithValue("MediaDescription", land.MediaDescription);
  1531. cmd.Parameters.AddWithValue("MediaType", land.MediaType);
  1532. cmd.Parameters.AddWithValue("MediaWidth", land.MediaWidth);
  1533. cmd.Parameters.AddWithValue("MediaHeight", land.MediaHeight);
  1534. cmd.Parameters.AddWithValue("MediaLoop", land.MediaLoop);
  1535. cmd.Parameters.AddWithValue("ObscureMusic", land.ObscureMusic);
  1536. cmd.Parameters.AddWithValue("ObscureMedia", land.ObscureMedia);
  1537. cmd.Parameters.AddWithValue("SeeAVs", land.SeeAVs ? 1 : 0);
  1538. cmd.Parameters.AddWithValue("AnyAVSounds", land.AnyAVSounds ? 1 : 0);
  1539. cmd.Parameters.AddWithValue("GroupAVSounds", land.GroupAVSounds ? 1 : 0);
  1540. if (land.Environment == null)
  1541. cmd.Parameters.AddWithValue("environment", "");
  1542. else
  1543. {
  1544. try
  1545. {
  1546. cmd.Parameters.AddWithValue("environment", ViewerEnvironment.ToOSDString(land.Environment));
  1547. }
  1548. catch
  1549. {
  1550. cmd.Parameters.AddWithValue("environment", "");
  1551. }
  1552. }
  1553. }
  1554. /// <summary>
  1555. ///
  1556. /// </summary>
  1557. /// <param name="row"></param>
  1558. /// <param name="entry"></param>
  1559. /// <param name="parcelID"></param>
  1560. private static void FillLandAccessCommand(MySqlCommand cmd, LandAccessEntry entry, UUID parcelID)
  1561. {
  1562. cmd.Parameters.AddWithValue("LandUUID", parcelID.ToString());
  1563. cmd.Parameters.AddWithValue("AccessUUID", entry.AgentID.ToString());
  1564. cmd.Parameters.AddWithValue("Flags", entry.Flags);
  1565. cmd.Parameters.AddWithValue("Expires", entry.Expires.ToString());
  1566. }
  1567. /// <summary>
  1568. ///
  1569. /// </summary>
  1570. /// <param name="row"></param>
  1571. /// <returns></returns>
  1572. private PrimitiveBaseShape BuildShape(IDataReader row)
  1573. {
  1574. PrimitiveBaseShape s = new PrimitiveBaseShape();
  1575. s.Scale = new Vector3(
  1576. (float)(double)row["ScaleX"],
  1577. (float)(double)row["ScaleY"],
  1578. (float)(double)row["ScaleZ"]
  1579. );
  1580. // paths
  1581. s.PCode = (byte)(int)row["PCode"];
  1582. s.PathBegin = (ushort)(int)row["PathBegin"];
  1583. s.PathEnd = (ushort)(int)row["PathEnd"];
  1584. s.PathScaleX = (byte)(int)row["PathScaleX"];
  1585. s.PathScaleY = (byte)(int)row["PathScaleY"];
  1586. s.PathShearX = (byte)(int)row["PathShearX"];
  1587. s.PathShearY = (byte)(int)row["PathShearY"];
  1588. s.PathSkew = (sbyte)(int)row["PathSkew"];
  1589. s.PathCurve = (byte)(int)row["PathCurve"];
  1590. s.PathRadiusOffset = (sbyte)(int)row["PathRadiusOffset"];
  1591. s.PathRevolutions = (byte)(int)row["PathRevolutions"];
  1592. s.PathTaperX = (sbyte)(int)row["PathTaperX"];
  1593. s.PathTaperY = (sbyte)(int)row["PathTaperY"];
  1594. s.PathTwist = (sbyte)(int)row["PathTwist"];
  1595. s.PathTwistBegin = (sbyte)(int)row["PathTwistBegin"];
  1596. // profile
  1597. s.ProfileBegin = (ushort)(int)row["ProfileBegin"];
  1598. s.ProfileEnd = (ushort)(int)row["ProfileEnd"];
  1599. s.ProfileCurve = (byte)(int)row["ProfileCurve"];
  1600. s.ProfileHollow = (ushort)(int)row["ProfileHollow"];
  1601. s.TextureEntry = (byte[])row["Texture"];
  1602. s.ExtraParams = (byte[])row["ExtraParams"];
  1603. s.State = (byte)(int)row["State"];
  1604. s.LastAttachPoint = (byte)(int)row["LastAttachPoint"];
  1605. if (!(row["Media"] is System.DBNull))
  1606. s.Media = PrimitiveBaseShape.MediaList.FromXml((string)row["Media"]);
  1607. return s;
  1608. }
  1609. /// <summary>
  1610. ///
  1611. /// </summary>
  1612. /// <param name="row"></param>
  1613. /// <param name="prim"></param>
  1614. private void FillShapeCommand(MySqlCommand cmd, SceneObjectPart prim)
  1615. {
  1616. PrimitiveBaseShape s = prim.Shape;
  1617. cmd.Parameters.AddWithValue("UUID", prim.UUID.ToString());
  1618. // shape is an enum
  1619. cmd.Parameters.AddWithValue("Shape", 0);
  1620. // vectors
  1621. cmd.Parameters.AddWithValue("ScaleX", (double)s.Scale.X);
  1622. cmd.Parameters.AddWithValue("ScaleY", (double)s.Scale.Y);
  1623. cmd.Parameters.AddWithValue("ScaleZ", (double)s.Scale.Z);
  1624. // paths
  1625. cmd.Parameters.AddWithValue("PCode", s.PCode);
  1626. cmd.Parameters.AddWithValue("PathBegin", s.PathBegin);
  1627. cmd.Parameters.AddWithValue("PathEnd", s.PathEnd);
  1628. cmd.Parameters.AddWithValue("PathScaleX", s.PathScaleX);
  1629. cmd.Parameters.AddWithValue("PathScaleY", s.PathScaleY);
  1630. cmd.Parameters.AddWithValue("PathShearX", s.PathShearX);
  1631. cmd.Parameters.AddWithValue("PathShearY", s.PathShearY);
  1632. cmd.Parameters.AddWithValue("PathSkew", s.PathSkew);
  1633. cmd.Parameters.AddWithValue("PathCurve", s.PathCurve);
  1634. cmd.Parameters.AddWithValue("PathRadiusOffset", s.PathRadiusOffset);
  1635. cmd.Parameters.AddWithValue("PathRevolutions", s.PathRevolutions);
  1636. cmd.Parameters.AddWithValue("PathTaperX", s.PathTaperX);
  1637. cmd.Parameters.AddWithValue("PathTaperY", s.PathTaperY);
  1638. cmd.Parameters.AddWithValue("PathTwist", s.PathTwist);
  1639. cmd.Parameters.AddWithValue("PathTwistBegin", s.PathTwistBegin);
  1640. // profile
  1641. cmd.Parameters.AddWithValue("ProfileBegin", s.ProfileBegin);
  1642. cmd.Parameters.AddWithValue("ProfileEnd", s.ProfileEnd);
  1643. cmd.Parameters.AddWithValue("ProfileCurve", s.ProfileCurve);
  1644. cmd.Parameters.AddWithValue("ProfileHollow", s.ProfileHollow);
  1645. cmd.Parameters.AddWithValue("Texture", s.TextureEntry);
  1646. cmd.Parameters.AddWithValue("ExtraParams", s.ExtraParams);
  1647. cmd.Parameters.AddWithValue("State", s.State);
  1648. cmd.Parameters.AddWithValue("LastAttachPoint", s.LastAttachPoint);
  1649. cmd.Parameters.AddWithValue("Media", null == s.Media ? null : s.Media.ToXml());
  1650. }
  1651. public virtual void StorePrimInventory(UUID primID, ICollection<TaskInventoryItem> items)
  1652. {
  1653. lock (m_dbLock)
  1654. {
  1655. using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
  1656. {
  1657. dbcon.Open();
  1658. using (MySqlCommand cmd = dbcon.CreateCommand())
  1659. {
  1660. cmd.CommandText = "delete from primitems where primID = ?PrimID";
  1661. cmd.Parameters.AddWithValue("primID", primID.ToString());
  1662. ExecuteNonQuery(cmd);
  1663. if (items.Count == 0)
  1664. {
  1665. dbcon.Close();
  1666. return;
  1667. }
  1668. cmd.Parameters.Clear();
  1669. cmd.CommandText = "insert into primitems (" +
  1670. "invType, assetType, name, " +
  1671. "description, creationDate, nextPermissions, " +
  1672. "currentPermissions, basePermissions, " +
  1673. "everyonePermissions, groupPermissions, " +
  1674. "flags, itemID, primID, assetID, " +
  1675. "parentFolderID, creatorID, ownerID, " +
  1676. "groupID, lastOwnerID) values (?invType, " +
  1677. "?assetType, ?name, ?description, " +
  1678. "?creationDate, ?nextPermissions, " +
  1679. "?currentPermissions, ?basePermissions, " +
  1680. "?everyonePermissions, ?groupPermissions, " +
  1681. "?flags, ?itemID, ?primID, ?assetID, " +
  1682. "?parentFolderID, ?creatorID, ?ownerID, " +
  1683. "?groupID, ?lastOwnerID)";
  1684. foreach (TaskInventoryItem item in items)
  1685. {
  1686. cmd.Parameters.Clear();
  1687. FillItemCommand(cmd, item);
  1688. ExecuteNonQuery(cmd);
  1689. }
  1690. }
  1691. dbcon.Close();
  1692. }
  1693. }
  1694. }
  1695. public UUID[] GetObjectIDs(UUID regionID)
  1696. {
  1697. List<UUID> uuids = new List<UUID>();
  1698. lock (m_dbLock)
  1699. {
  1700. using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
  1701. {
  1702. dbcon.Open();
  1703. using (MySqlCommand cmd = dbcon.CreateCommand())
  1704. {
  1705. cmd.CommandText = "select UUID from prims where RegionUUID = ?RegionUUID and SceneGroupID = UUID";
  1706. cmd.Parameters.AddWithValue("RegionUUID", regionID.ToString());
  1707. using (IDataReader reader = ExecuteReader(cmd))
  1708. {
  1709. while (reader.Read())
  1710. {
  1711. UUID id = new UUID(reader["UUID"].ToString());
  1712. uuids.Add(id);
  1713. }
  1714. }
  1715. }
  1716. dbcon.Close();
  1717. }
  1718. }
  1719. return uuids.ToArray();
  1720. }
  1721. private void LoadSpawnPoints(RegionSettings rs)
  1722. {
  1723. rs.ClearSpawnPoints();
  1724. lock (m_dbLock)
  1725. {
  1726. using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
  1727. {
  1728. dbcon.Open();
  1729. using (MySqlCommand cmd = dbcon.CreateCommand())
  1730. {
  1731. cmd.CommandText = "select Yaw, Pitch, Distance from spawn_points where RegionID = ?RegionID";
  1732. cmd.Parameters.AddWithValue("?RegionID", rs.RegionUUID.ToString());
  1733. using (IDataReader r = cmd.ExecuteReader())
  1734. {
  1735. while (r.Read())
  1736. {
  1737. SpawnPoint sp = new SpawnPoint();
  1738. sp.Yaw = (float)r["Yaw"];
  1739. sp.Pitch = (float)r["Pitch"];
  1740. sp.Distance = (float)r["Distance"];
  1741. rs.AddSpawnPoint(sp);
  1742. }
  1743. }
  1744. }
  1745. dbcon.Close();
  1746. }
  1747. }
  1748. }
  1749. private void SaveSpawnPoints(RegionSettings rs)
  1750. {
  1751. lock (m_dbLock)
  1752. {
  1753. using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
  1754. {
  1755. dbcon.Open();
  1756. using (MySqlCommand cmd = dbcon.CreateCommand())
  1757. {
  1758. cmd.CommandText = "delete from spawn_points where RegionID = ?RegionID";
  1759. cmd.Parameters.AddWithValue("?RegionID", rs.RegionUUID.ToString());
  1760. cmd.ExecuteNonQuery();
  1761. cmd.Parameters.Clear();
  1762. cmd.CommandText = "insert into spawn_points (RegionID, Yaw, Pitch, Distance) values ( ?RegionID, ?Yaw, ?Pitch, ?Distance)";
  1763. foreach (SpawnPoint p in rs.SpawnPoints())
  1764. {
  1765. cmd.Parameters.AddWithValue("?RegionID", rs.RegionUUID.ToString());
  1766. cmd.Parameters.AddWithValue("?Yaw", p.Yaw);
  1767. cmd.Parameters.AddWithValue("?Pitch", p.Pitch);
  1768. cmd.Parameters.AddWithValue("?Distance", p.Distance);
  1769. cmd.ExecuteNonQuery();
  1770. cmd.Parameters.Clear();
  1771. }
  1772. }
  1773. dbcon.Close();
  1774. }
  1775. }
  1776. }
  1777. public void SaveExtra(UUID regionID, string name, string val)
  1778. {
  1779. using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
  1780. {
  1781. dbcon.Open();
  1782. using (MySqlCommand cmd = dbcon.CreateCommand())
  1783. {
  1784. cmd.CommandText = "replace into regionextra values (?RegionID, ?Name, ?value)";
  1785. cmd.Parameters.AddWithValue("?RegionID", regionID.ToString());
  1786. cmd.Parameters.AddWithValue("?Name", name);
  1787. cmd.Parameters.AddWithValue("?value", val);
  1788. cmd.ExecuteNonQuery();
  1789. }
  1790. dbcon.Close();
  1791. }
  1792. }
  1793. public void RemoveExtra(UUID regionID, string name)
  1794. {
  1795. using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
  1796. {
  1797. dbcon.Open();
  1798. using (MySqlCommand cmd = dbcon.CreateCommand())
  1799. {
  1800. cmd.CommandText = "delete from regionextra where RegionID=?RegionID and Name=?Name";
  1801. cmd.Parameters.AddWithValue("?RegionID", regionID.ToString());
  1802. cmd.Parameters.AddWithValue("?Name", name);
  1803. cmd.ExecuteNonQuery();
  1804. }
  1805. dbcon.Close();
  1806. }
  1807. }
  1808. public Dictionary<string, string> GetExtra(UUID regionID)
  1809. {
  1810. Dictionary<string, string> ret = new Dictionary<string, string>();
  1811. using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
  1812. {
  1813. dbcon.Open();
  1814. using (MySqlCommand cmd = dbcon.CreateCommand())
  1815. {
  1816. cmd.CommandText = "select * from regionextra where RegionID=?RegionID";
  1817. cmd.Parameters.AddWithValue("?RegionID", regionID.ToString());
  1818. using (IDataReader r = cmd.ExecuteReader())
  1819. {
  1820. while (r.Read())
  1821. {
  1822. ret[r["Name"].ToString()] = r["value"].ToString();
  1823. }
  1824. }
  1825. }
  1826. dbcon.Close();
  1827. }
  1828. return ret;
  1829. }
  1830. }
  1831. }