SQLiteSimulationData.cs 130 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981
  1. /*
  2. * Copyright (c) Contributors, http://opensimulator.org/
  3. * See CONTRIBUTORS.TXT for a full list of copyright holders.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are met:
  7. * * Redistributions of source code must retain the above copyright
  8. * notice, this list of conditions and the following disclaimer.
  9. * * Redistributions in binary form must reproduce the above copyright
  10. * notice, this list of conditions and the following disclaimer in the
  11. * documentation and/or other materials provided with the distribution.
  12. * * Neither the name of the OpenSimulator Project nor the
  13. * names of its contributors may be used to endorse or promote products
  14. * derived from this software without specific prior written permission.
  15. *
  16. * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
  17. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  18. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  19. * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
  20. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  21. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  22. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  23. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  24. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  25. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. */
  27. using System;
  28. using System.Collections.Generic;
  29. using System.Data;
  30. using System.Drawing;
  31. using System.IO;
  32. using System.Reflection;
  33. using log4net;
  34. #if CSharpSqlite
  35. using Community.CsharpSqlite.Sqlite;
  36. #else
  37. using Mono.Data.Sqlite;
  38. #endif
  39. using OpenMetaverse;
  40. using OpenMetaverse.StructuredData;
  41. using OpenSim.Framework;
  42. using OpenSim.Region.Framework.Interfaces;
  43. using OpenSim.Region.Framework.Scenes;
  44. namespace OpenSim.Data.SQLite
  45. {
  46. /// <summary>
  47. /// A RegionData Interface to the SQLite database
  48. /// </summary>
  49. public class SQLiteSimulationData : ISimulationDataStore
  50. {
  51. private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  52. private const string primSelect = "select * from prims";
  53. private const string shapeSelect = "select * from primshapes";
  54. private const string itemsSelect = "select * from primitems";
  55. private const string terrainSelect = "select * from terrain limit 1";
  56. private const string landSelect = "select * from land";
  57. private const string landAccessListSelect = "select distinct * from landaccesslist";
  58. private const string regionbanListSelect = "select * from regionban";
  59. private const string regionSettingsSelect = "select * from regionsettings";
  60. private const string regionWindlightSelect = "select * from regionwindlight";
  61. private const string regionEnvironmentSelect = "select * from regionenvironment";
  62. private const string regionSpawnPointsSelect = "select * from spawn_points";
  63. private DataSet ds;
  64. private SqliteDataAdapter primDa;
  65. private SqliteDataAdapter shapeDa;
  66. private SqliteDataAdapter itemsDa;
  67. private SqliteDataAdapter terrainDa;
  68. private SqliteDataAdapter landDa;
  69. private SqliteDataAdapter landAccessListDa;
  70. private SqliteDataAdapter regionSettingsDa;
  71. private SqliteDataAdapter regionWindlightDa;
  72. private SqliteDataAdapter regionEnvironmentDa;
  73. private SqliteDataAdapter regionSpawnPointsDa;
  74. private SqliteConnection m_conn;
  75. private String m_connectionString;
  76. protected virtual Assembly Assembly
  77. {
  78. get { return GetType().Assembly; }
  79. }
  80. public SQLiteSimulationData()
  81. {
  82. }
  83. public SQLiteSimulationData(string connectionString)
  84. {
  85. Initialise(connectionString);
  86. }
  87. // Temporary attribute while this is experimental
  88. /***********************************************************************
  89. *
  90. * Public Interface Functions
  91. *
  92. **********************************************************************/
  93. /// <summary>
  94. /// <list type="bullet">
  95. /// <item>Initialises RegionData Interface</item>
  96. /// <item>Loads and initialises a new SQLite connection and maintains it.</item>
  97. /// </list>
  98. /// </summary>
  99. /// <param name="connectionString">the connection string</param>
  100. public void Initialise(string connectionString)
  101. {
  102. try
  103. {
  104. if (Util.IsWindows())
  105. Util.LoadArchSpecificWindowsDll("sqlite3.dll");
  106. m_connectionString = connectionString;
  107. ds = new DataSet("Region");
  108. m_log.Info("[SQLITE REGION DB]: Sqlite - connecting: " + connectionString);
  109. m_conn = new SqliteConnection(m_connectionString);
  110. m_conn.Open();
  111. SqliteCommand primSelectCmd = new SqliteCommand(primSelect, m_conn);
  112. primDa = new SqliteDataAdapter(primSelectCmd);
  113. SqliteCommand shapeSelectCmd = new SqliteCommand(shapeSelect, m_conn);
  114. shapeDa = new SqliteDataAdapter(shapeSelectCmd);
  115. // SqliteCommandBuilder shapeCb = new SqliteCommandBuilder(shapeDa);
  116. SqliteCommand itemsSelectCmd = new SqliteCommand(itemsSelect, m_conn);
  117. itemsDa = new SqliteDataAdapter(itemsSelectCmd);
  118. SqliteCommand terrainSelectCmd = new SqliteCommand(terrainSelect, m_conn);
  119. terrainDa = new SqliteDataAdapter(terrainSelectCmd);
  120. SqliteCommand landSelectCmd = new SqliteCommand(landSelect, m_conn);
  121. landDa = new SqliteDataAdapter(landSelectCmd);
  122. SqliteCommand landAccessListSelectCmd = new SqliteCommand(landAccessListSelect, m_conn);
  123. landAccessListDa = new SqliteDataAdapter(landAccessListSelectCmd);
  124. SqliteCommand regionSettingsSelectCmd = new SqliteCommand(regionSettingsSelect, m_conn);
  125. regionSettingsDa = new SqliteDataAdapter(regionSettingsSelectCmd);
  126. SqliteCommand regionWindlightSelectCmd = new SqliteCommand(regionWindlightSelect, m_conn);
  127. regionWindlightDa = new SqliteDataAdapter(regionWindlightSelectCmd);
  128. SqliteCommand regionEnvironmentSelectCmd = new SqliteCommand(regionEnvironmentSelect, m_conn);
  129. regionEnvironmentDa = new SqliteDataAdapter(regionEnvironmentSelectCmd);
  130. SqliteCommand regionSpawnPointsSelectCmd = new SqliteCommand(regionSpawnPointsSelect, m_conn);
  131. regionSpawnPointsDa = new SqliteDataAdapter(regionSpawnPointsSelectCmd);
  132. // This actually does the roll forward assembly stuff
  133. Migration m = new Migration(m_conn, Assembly, "RegionStore");
  134. m.Update();
  135. lock (ds)
  136. {
  137. ds.Tables.Add(createPrimTable());
  138. setupPrimCommands(primDa, m_conn);
  139. ds.Tables.Add(createShapeTable());
  140. setupShapeCommands(shapeDa, m_conn);
  141. ds.Tables.Add(createItemsTable());
  142. setupItemsCommands(itemsDa, m_conn);
  143. ds.Tables.Add(createTerrainTable());
  144. setupTerrainCommands(terrainDa, m_conn);
  145. ds.Tables.Add(createLandTable());
  146. setupLandCommands(landDa, m_conn);
  147. ds.Tables.Add(createLandAccessListTable());
  148. setupLandAccessCommands(landAccessListDa, m_conn);
  149. ds.Tables.Add(createRegionSettingsTable());
  150. setupRegionSettingsCommands(regionSettingsDa, m_conn);
  151. ds.Tables.Add(createRegionWindlightTable());
  152. setupRegionWindlightCommands(regionWindlightDa, m_conn);
  153. ds.Tables.Add(createRegionEnvironmentTable());
  154. setupRegionEnvironmentCommands(regionEnvironmentDa, m_conn);
  155. ds.Tables.Add(createRegionSpawnPointsTable());
  156. setupRegionSpawnPointsCommands(regionSpawnPointsDa, m_conn);
  157. // WORKAROUND: This is a work around for sqlite on
  158. // windows, which gets really unhappy with blob columns
  159. // that have no sample data in them. At some point we
  160. // need to actually find a proper way to handle this.
  161. try
  162. {
  163. primDa.Fill(ds.Tables["prims"]);
  164. }
  165. catch (Exception e)
  166. {
  167. m_log.ErrorFormat("[SQLITE REGION DB]: Caught fill error on prims table :{0}", e.Message);
  168. }
  169. try
  170. {
  171. shapeDa.Fill(ds.Tables["primshapes"]);
  172. }
  173. catch (Exception e)
  174. {
  175. m_log.ErrorFormat("[SQLITE REGION DB]: Caught fill error on primshapes table :{0}", e.Message);
  176. }
  177. try
  178. {
  179. itemsDa.Fill(ds.Tables["primitems"]);
  180. }
  181. catch (Exception e)
  182. {
  183. m_log.ErrorFormat("[SQLITE REGION DB]: Caught fill error on primitems table :{0}", e.Message);
  184. }
  185. try
  186. {
  187. terrainDa.Fill(ds.Tables["terrain"]);
  188. }
  189. catch (Exception e)
  190. {
  191. m_log.ErrorFormat("[SQLITE REGION DB]: Caught fill error on terrain table :{0}", e.Message);
  192. }
  193. try
  194. {
  195. landDa.Fill(ds.Tables["land"]);
  196. }
  197. catch (Exception e)
  198. {
  199. m_log.ErrorFormat("[SQLITE REGION DB]: Caught fill error on land table :{0}", e.Message);
  200. }
  201. try
  202. {
  203. landAccessListDa.Fill(ds.Tables["landaccesslist"]);
  204. }
  205. catch (Exception e)
  206. {
  207. m_log.ErrorFormat("[SQLITE REGION DB]: Caught fill error on landaccesslist table :{0}", e.Message);
  208. }
  209. try
  210. {
  211. regionSettingsDa.Fill(ds.Tables["regionsettings"]);
  212. }
  213. catch (Exception e)
  214. {
  215. m_log.ErrorFormat("[SQLITE REGION DB]: Caught fill error on regionsettings table :{0}", e.Message);
  216. }
  217. try
  218. {
  219. regionWindlightDa.Fill(ds.Tables["regionwindlight"]);
  220. }
  221. catch (Exception e)
  222. {
  223. m_log.ErrorFormat("[SQLITE REGION DB]: Caught fill error on regionwindlight table :{0}", e.Message);
  224. }
  225. try
  226. {
  227. regionEnvironmentDa.Fill(ds.Tables["regionenvironment"]);
  228. }
  229. catch (Exception e)
  230. {
  231. m_log.ErrorFormat("[SQLITE REGION DB]: Caught fill error on regionenvironment table :{0}", e.Message);
  232. }
  233. try
  234. {
  235. regionSpawnPointsDa.Fill(ds.Tables["spawn_points"]);
  236. }
  237. catch (Exception e)
  238. {
  239. m_log.ErrorFormat("[SQLITE REGION DB]: Caught fill error on spawn_points table :{0}", e.Message);
  240. }
  241. // We have to create a data set mapping for every table, otherwise the IDataAdaptor.Update() will not populate rows with values!
  242. // Not sure exactly why this is - this kind of thing was not necessary before - justincc 20100409
  243. // Possibly because we manually set up our own DataTables before connecting to the database
  244. CreateDataSetMapping(primDa, "prims");
  245. CreateDataSetMapping(shapeDa, "primshapes");
  246. CreateDataSetMapping(itemsDa, "primitems");
  247. CreateDataSetMapping(terrainDa, "terrain");
  248. CreateDataSetMapping(landDa, "land");
  249. CreateDataSetMapping(landAccessListDa, "landaccesslist");
  250. CreateDataSetMapping(regionSettingsDa, "regionsettings");
  251. CreateDataSetMapping(regionWindlightDa, "regionwindlight");
  252. CreateDataSetMapping(regionEnvironmentDa, "regionenvironment");
  253. CreateDataSetMapping(regionSpawnPointsDa, "spawn_points");
  254. }
  255. }
  256. catch (Exception e)
  257. {
  258. m_log.ErrorFormat("[SQLITE REGION DB]: {0} - {1}", e.Message, e.StackTrace);
  259. Environment.Exit(23);
  260. }
  261. return;
  262. }
  263. public void Dispose()
  264. {
  265. if (m_conn != null)
  266. {
  267. m_conn.Close();
  268. m_conn = null;
  269. }
  270. if (ds != null)
  271. {
  272. ds.Dispose();
  273. ds = null;
  274. }
  275. if (primDa != null)
  276. {
  277. primDa.Dispose();
  278. primDa = null;
  279. }
  280. if (shapeDa != null)
  281. {
  282. shapeDa.Dispose();
  283. shapeDa = null;
  284. }
  285. if (itemsDa != null)
  286. {
  287. itemsDa.Dispose();
  288. itemsDa = null;
  289. }
  290. if (terrainDa != null)
  291. {
  292. terrainDa.Dispose();
  293. terrainDa = null;
  294. }
  295. if (landDa != null)
  296. {
  297. landDa.Dispose();
  298. landDa = null;
  299. }
  300. if (landAccessListDa != null)
  301. {
  302. landAccessListDa.Dispose();
  303. landAccessListDa = null;
  304. }
  305. if (regionSettingsDa != null)
  306. {
  307. regionSettingsDa.Dispose();
  308. regionSettingsDa = null;
  309. }
  310. if (regionWindlightDa != null)
  311. {
  312. regionWindlightDa.Dispose();
  313. regionWindlightDa = null;
  314. }
  315. if (regionEnvironmentDa != null)
  316. {
  317. regionEnvironmentDa.Dispose();
  318. regionEnvironmentDa = null;
  319. }
  320. if (regionSpawnPointsDa != null)
  321. {
  322. regionSpawnPointsDa.Dispose();
  323. regionWindlightDa = null;
  324. }
  325. }
  326. public void StoreRegionSettings(RegionSettings rs)
  327. {
  328. lock (ds)
  329. {
  330. DataTable regionsettings = ds.Tables["regionsettings"];
  331. DataRow settingsRow = regionsettings.Rows.Find(rs.RegionUUID.ToString());
  332. if (settingsRow == null)
  333. {
  334. settingsRow = regionsettings.NewRow();
  335. fillRegionSettingsRow(settingsRow, rs);
  336. regionsettings.Rows.Add(settingsRow);
  337. }
  338. else
  339. {
  340. fillRegionSettingsRow(settingsRow, rs);
  341. }
  342. StoreSpawnPoints(rs);
  343. Commit();
  344. }
  345. }
  346. public void StoreSpawnPoints(RegionSettings rs)
  347. {
  348. lock (ds)
  349. {
  350. // DataTable spawnpoints = ds.Tables["spawn_points"];
  351. // remove region's spawnpoints
  352. using (
  353. SqliteCommand cmd =
  354. new SqliteCommand("delete from spawn_points where RegionID=:RegionID",
  355. m_conn))
  356. {
  357. cmd.Parameters.Add(new SqliteParameter(":RegionID", rs.RegionUUID.ToString()));
  358. cmd.ExecuteNonQuery();
  359. }
  360. }
  361. foreach (SpawnPoint sp in rs.SpawnPoints())
  362. {
  363. using (SqliteCommand cmd = new SqliteCommand("insert into spawn_points(RegionID, Yaw, Pitch, Distance)" +
  364. "values ( :RegionID, :Yaw, :Pitch, :Distance)", m_conn))
  365. {
  366. cmd.Parameters.Add(new SqliteParameter(":RegionID", rs.RegionUUID.ToString()));
  367. cmd.Parameters.Add(new SqliteParameter(":Yaw", sp.Yaw));
  368. cmd.Parameters.Add(new SqliteParameter(":Pitch", sp.Pitch));
  369. cmd.Parameters.Add(new SqliteParameter(":Distance", sp.Distance));
  370. cmd.ExecuteNonQuery();
  371. }
  372. }
  373. }
  374. /// <summary>
  375. /// Load windlight settings from region storage
  376. /// </summary>
  377. /// <param name="regionUUID">RegionID</param>
  378. public RegionLightShareData LoadRegionWindlightSettings(UUID regionUUID)
  379. {
  380. RegionLightShareData wl = null;
  381. lock (ds)
  382. {
  383. DataTable windlightTable = ds.Tables["regionwindlight"];
  384. DataRow windlightRow = windlightTable.Rows.Find(regionUUID.ToString());
  385. if (windlightRow == null)
  386. {
  387. wl = new RegionLightShareData();
  388. wl.regionID = regionUUID;
  389. StoreRegionWindlightSettings(wl);
  390. return wl;
  391. }
  392. wl = buildRegionWindlight(windlightRow);
  393. return wl;
  394. }
  395. }
  396. /// <summary>
  397. /// Remove windlight settings from region storage
  398. /// </summary>
  399. /// <param name="regionID">RegionID</param>
  400. public void RemoveRegionWindlightSettings(UUID regionID)
  401. {
  402. lock (ds)
  403. {
  404. DataTable windlightTable = ds.Tables["regionwindlight"];
  405. DataRow windlightRow = windlightTable.Rows.Find(regionID.ToString());
  406. if (windlightRow != null)
  407. {
  408. windlightRow.Delete();
  409. }
  410. }
  411. Commit();
  412. }
  413. /// <summary>
  414. /// Adds an windlight into region storage
  415. /// </summary>
  416. /// <param name="wl">RegionLightShareData</param>
  417. public void StoreRegionWindlightSettings(RegionLightShareData wl)
  418. {
  419. lock (ds)
  420. {
  421. DataTable windlightTable = ds.Tables["regionwindlight"];
  422. DataRow windlightRow = windlightTable.Rows.Find(wl.regionID.ToString());
  423. if (windlightRow == null)
  424. {
  425. windlightRow = windlightTable.NewRow();
  426. fillRegionWindlightRow(windlightRow, wl);
  427. windlightTable.Rows.Add(windlightRow);
  428. }
  429. else
  430. {
  431. fillRegionWindlightRow(windlightRow, wl);
  432. }
  433. Commit();
  434. }
  435. }
  436. #region Region Environment Settings
  437. public string LoadRegionEnvironmentSettings(UUID regionUUID)
  438. {
  439. lock (ds)
  440. {
  441. DataTable environmentTable = ds.Tables["regionenvironment"];
  442. DataRow row = environmentTable.Rows.Find(regionUUID.ToString());
  443. if (row == null)
  444. {
  445. return String.Empty;
  446. }
  447. return (String)row["llsd_settings"];
  448. }
  449. }
  450. public void StoreRegionEnvironmentSettings(UUID regionUUID, string settings)
  451. {
  452. lock (ds)
  453. {
  454. DataTable environmentTable = ds.Tables["regionenvironment"];
  455. DataRow row = environmentTable.Rows.Find(regionUUID.ToString());
  456. if (row == null)
  457. {
  458. row = environmentTable.NewRow();
  459. row["region_id"] = regionUUID.ToString();
  460. row["llsd_settings"] = settings;
  461. environmentTable.Rows.Add(row);
  462. }
  463. else
  464. {
  465. row["llsd_settings"] = settings;
  466. }
  467. regionEnvironmentDa.Update(ds, "regionenvironment");
  468. }
  469. }
  470. public void RemoveRegionEnvironmentSettings(UUID regionUUID)
  471. {
  472. lock (ds)
  473. {
  474. DataTable environmentTable = ds.Tables["regionenvironment"];
  475. DataRow row = environmentTable.Rows.Find(regionUUID.ToString());
  476. if (row != null)
  477. {
  478. row.Delete();
  479. }
  480. regionEnvironmentDa.Update(ds, "regionenvironment");
  481. }
  482. }
  483. #endregion
  484. public RegionSettings LoadRegionSettings(UUID regionUUID)
  485. {
  486. lock (ds)
  487. {
  488. DataTable regionsettings = ds.Tables["regionsettings"];
  489. string searchExp = "regionUUID = '" + regionUUID.ToString() + "'";
  490. DataRow[] rawsettings = regionsettings.Select(searchExp);
  491. if (rawsettings.Length == 0)
  492. {
  493. RegionSettings rs = new RegionSettings();
  494. rs.RegionUUID = regionUUID;
  495. rs.OnSave += StoreRegionSettings;
  496. StoreRegionSettings(rs);
  497. return rs;
  498. }
  499. DataRow row = rawsettings[0];
  500. RegionSettings newSettings = buildRegionSettings(row);
  501. newSettings.OnSave += StoreRegionSettings;
  502. LoadSpawnPoints(newSettings);
  503. return newSettings;
  504. }
  505. }
  506. private void LoadSpawnPoints(RegionSettings rs)
  507. {
  508. rs.ClearSpawnPoints();
  509. DataTable spawnpoints = ds.Tables["spawn_points"];
  510. string byRegion = "RegionID = '" + rs.RegionUUID + "'";
  511. DataRow[] spForRegion = spawnpoints.Select(byRegion);
  512. foreach (DataRow spRow in spForRegion)
  513. {
  514. SpawnPoint sp = new SpawnPoint();
  515. sp.Pitch = (float)spRow["Pitch"];
  516. sp.Yaw = (float)spRow["Yaw"];
  517. sp.Distance = (float)spRow["Distance"];
  518. rs.AddSpawnPoint(sp);
  519. }
  520. }
  521. /// <summary>
  522. /// Adds an object into region storage
  523. /// </summary>
  524. /// <param name="obj">the object</param>
  525. /// <param name="regionUUID">the region UUID</param>
  526. public void StoreObject(SceneObjectGroup obj, UUID regionUUID)
  527. {
  528. uint flags = obj.RootPart.GetEffectiveObjectFlags();
  529. // Eligibility check
  530. //
  531. if ((flags & (uint)PrimFlags.Temporary) != 0)
  532. return;
  533. if ((flags & (uint)PrimFlags.TemporaryOnRez) != 0)
  534. return;
  535. lock (ds)
  536. {
  537. foreach (SceneObjectPart prim in obj.Parts)
  538. {
  539. // m_log.Info("[REGION DB]: Adding obj: " + obj.UUID + " to region: " + regionUUID);
  540. addPrim(prim, obj.UUID, regionUUID);
  541. }
  542. }
  543. Commit();
  544. // m_log.Info("[Dump of prims]: " + ds.GetXml());
  545. }
  546. /// <summary>
  547. /// Removes an object from region storage
  548. /// </summary>
  549. /// <param name="obj">the object</param>
  550. /// <param name="regionUUID">the region UUID</param>
  551. public void RemoveObject(UUID obj, UUID regionUUID)
  552. {
  553. // m_log.InfoFormat("[REGION DB]: Removing obj: {0} from region: {1}", obj.Guid, regionUUID);
  554. DataTable prims = ds.Tables["prims"];
  555. DataTable shapes = ds.Tables["primshapes"];
  556. string selectExp = "SceneGroupID = '" + obj + "' and RegionUUID = '" + regionUUID + "'";
  557. lock (ds)
  558. {
  559. DataRow[] primRows = prims.Select(selectExp);
  560. foreach (DataRow row in primRows)
  561. {
  562. // Remove shape rows
  563. UUID uuid = new UUID((string)row["UUID"]);
  564. DataRow shapeRow = shapes.Rows.Find(uuid.ToString());
  565. if (shapeRow != null)
  566. {
  567. shapeRow.Delete();
  568. }
  569. RemoveItems(uuid);
  570. // Remove prim row
  571. row.Delete();
  572. }
  573. }
  574. Commit();
  575. }
  576. /// <summary>
  577. /// Remove all persisted items of the given prim.
  578. /// The caller must acquire the necessrary synchronization locks and commit or rollback changes.
  579. /// </summary>
  580. /// <param name="uuid">The item UUID</param>
  581. private void RemoveItems(UUID uuid)
  582. {
  583. DataTable items = ds.Tables["primitems"];
  584. String sql = String.Format("primID = '{0}'", uuid);
  585. DataRow[] itemRows = items.Select(sql);
  586. foreach (DataRow itemRow in itemRows)
  587. {
  588. itemRow.Delete();
  589. }
  590. }
  591. /// <summary>
  592. /// Load persisted objects from region storage.
  593. /// </summary>
  594. /// <param name="regionUUID">The region UUID</param>
  595. /// <returns>List of loaded groups</returns>
  596. public List<SceneObjectGroup> LoadObjects(UUID regionUUID)
  597. {
  598. Dictionary<UUID, SceneObjectGroup> createdObjects = new Dictionary<UUID, SceneObjectGroup>();
  599. List<SceneObjectGroup> retvals = new List<SceneObjectGroup>();
  600. DataTable prims = ds.Tables["prims"];
  601. DataTable shapes = ds.Tables["primshapes"];
  602. string byRegion = "RegionUUID = '" + regionUUID + "'";
  603. lock (ds)
  604. {
  605. DataRow[] primsForRegion = prims.Select(byRegion);
  606. // m_log.Info("[SQLITE REGION DB]: Loaded " + primsForRegion.Length + " prims for region: " + regionUUID);
  607. // First, create all groups
  608. foreach (DataRow primRow in primsForRegion)
  609. {
  610. try
  611. {
  612. SceneObjectPart prim = null;
  613. string uuid = (string)primRow["UUID"];
  614. string objID = (string)primRow["SceneGroupID"];
  615. if (uuid == objID) //is new SceneObjectGroup ?
  616. {
  617. prim = buildPrim(primRow);
  618. DataRow shapeRow = shapes.Rows.Find(prim.UUID.ToString());
  619. if (shapeRow != null)
  620. {
  621. prim.Shape = buildShape(shapeRow);
  622. }
  623. else
  624. {
  625. m_log.Warn(
  626. "[SQLITE REGION DB]: No shape found for prim in storage, so setting default box shape");
  627. prim.Shape = PrimitiveBaseShape.Default;
  628. }
  629. SceneObjectGroup group = new SceneObjectGroup(prim);
  630. createdObjects.Add(group.UUID, group);
  631. retvals.Add(group);
  632. LoadItems(prim);
  633. }
  634. }
  635. catch (Exception e)
  636. {
  637. m_log.Error("[SQLITE REGION DB]: Failed create prim object in new group, exception and data follows");
  638. m_log.Error("[SQLITE REGION DB]: ", e);
  639. foreach (DataColumn col in prims.Columns)
  640. {
  641. m_log.Error("[SQLITE REGION DB]: Col: " + col.ColumnName + " => " + primRow[col]);
  642. }
  643. }
  644. }
  645. // Now fill the groups with part data
  646. foreach (DataRow primRow in primsForRegion)
  647. {
  648. try
  649. {
  650. SceneObjectPart prim = null;
  651. string uuid = (string)primRow["UUID"];
  652. string objID = (string)primRow["SceneGroupID"];
  653. if (uuid != objID) //is new SceneObjectGroup ?
  654. {
  655. prim = buildPrim(primRow);
  656. DataRow shapeRow = shapes.Rows.Find(prim.UUID.ToString());
  657. if (shapeRow != null)
  658. {
  659. prim.Shape = buildShape(shapeRow);
  660. }
  661. else
  662. {
  663. m_log.Warn(
  664. "[SQLITE REGION DB]: No shape found for prim in storage, so setting default box shape");
  665. prim.Shape = PrimitiveBaseShape.Default;
  666. }
  667. createdObjects[new UUID(objID)].AddPart(prim);
  668. LoadItems(prim);
  669. }
  670. }
  671. catch (Exception e)
  672. {
  673. m_log.Error("[SQLITE REGION DB]: Failed create prim object in group, exception and data follows");
  674. m_log.Error("[SQLITE REGION DB]: ", e);
  675. foreach (DataColumn col in prims.Columns)
  676. {
  677. m_log.Error("[SQLITE REGION DB]: Col: " + col.ColumnName + " => " + primRow[col]);
  678. }
  679. }
  680. }
  681. }
  682. return retvals;
  683. }
  684. /// <summary>
  685. /// Load in a prim's persisted inventory.
  686. /// </summary>
  687. /// <param name="prim">the prim</param>
  688. private void LoadItems(SceneObjectPart prim)
  689. {
  690. // m_log.DebugFormat("[SQLITE REGION DB]: Loading inventory for {0} {1}", prim.Name, prim.UUID);
  691. DataTable dbItems = ds.Tables["primitems"];
  692. String sql = String.Format("primID = '{0}'", prim.UUID.ToString());
  693. DataRow[] dbItemRows = dbItems.Select(sql);
  694. IList<TaskInventoryItem> inventory = new List<TaskInventoryItem>();
  695. // m_log.DebugFormat("[SQLITE REGION DB]: Found {0} items for {1} {2}", dbItemRows.Length, prim.Name, prim.UUID);
  696. foreach (DataRow row in dbItemRows)
  697. {
  698. TaskInventoryItem item = buildItem(row);
  699. inventory.Add(item);
  700. // m_log.DebugFormat("[SQLITE REGION DB]: Restored item {0} {1}", item.Name, item.ItemID);
  701. }
  702. prim.Inventory.RestoreInventoryItems(inventory);
  703. }
  704. /// <summary>
  705. /// Store a terrain revision in region storage
  706. /// </summary>
  707. /// <param name="ter">terrain heightfield</param>
  708. /// <param name="regionID">region UUID</param>
  709. public void StoreTerrain(double[,] ter, UUID regionID)
  710. {
  711. lock (ds)
  712. {
  713. int revision = Util.UnixTimeSinceEpoch();
  714. // This is added to get rid of the infinitely growing
  715. // terrain databases which negatively impact on SQLite
  716. // over time. Before reenabling this feature there
  717. // needs to be a limitter put on the number of
  718. // revisions in the database, as this old
  719. // implementation is a DOS attack waiting to happen.
  720. using (
  721. SqliteCommand cmd =
  722. new SqliteCommand("delete from terrain where RegionUUID=:RegionUUID and Revision <= :Revision",
  723. m_conn))
  724. {
  725. cmd.Parameters.Add(new SqliteParameter(":RegionUUID", regionID.ToString()));
  726. cmd.Parameters.Add(new SqliteParameter(":Revision", revision));
  727. cmd.ExecuteNonQuery();
  728. }
  729. // the following is an work around for .NET. The perf
  730. // issues associated with it aren't as bad as you think.
  731. m_log.Debug("[SQLITE REGION DB]: Storing terrain revision r" + revision.ToString());
  732. String sql = "insert into terrain(RegionUUID, Revision, Heightfield)" +
  733. " values(:RegionUUID, :Revision, :Heightfield)";
  734. using (SqliteCommand cmd = new SqliteCommand(sql, m_conn))
  735. {
  736. cmd.Parameters.Add(new SqliteParameter(":RegionUUID", regionID.ToString()));
  737. cmd.Parameters.Add(new SqliteParameter(":Revision", revision));
  738. cmd.Parameters.Add(new SqliteParameter(":Heightfield", serializeTerrain(ter)));
  739. cmd.ExecuteNonQuery();
  740. }
  741. }
  742. }
  743. /// <summary>
  744. /// Load the latest terrain revision from region storage
  745. /// </summary>
  746. /// <param name="regionID">the region UUID</param>
  747. /// <returns>Heightfield data</returns>
  748. public double[,] LoadTerrain(UUID regionID)
  749. {
  750. lock (ds)
  751. {
  752. double[,] terret = new double[(int)Constants.RegionSize, (int)Constants.RegionSize];
  753. terret.Initialize();
  754. String sql = "select RegionUUID, Revision, Heightfield from terrain" +
  755. " where RegionUUID=:RegionUUID order by Revision desc";
  756. using (SqliteCommand cmd = new SqliteCommand(sql, m_conn))
  757. {
  758. cmd.Parameters.Add(new SqliteParameter(":RegionUUID", regionID.ToString()));
  759. using (IDataReader row = cmd.ExecuteReader())
  760. {
  761. int rev = 0;
  762. if (row.Read())
  763. {
  764. // TODO: put this into a function
  765. using (MemoryStream str = new MemoryStream((byte[])row["Heightfield"]))
  766. {
  767. using (BinaryReader br = new BinaryReader(str))
  768. {
  769. for (int x = 0; x < (int)Constants.RegionSize; x++)
  770. {
  771. for (int y = 0; y < (int)Constants.RegionSize; y++)
  772. {
  773. terret[x, y] = br.ReadDouble();
  774. }
  775. }
  776. }
  777. }
  778. rev = Convert.ToInt32(row["Revision"]);
  779. }
  780. else
  781. {
  782. m_log.Warn("[SQLITE REGION DB]: No terrain found for region");
  783. return null;
  784. }
  785. m_log.Debug("[SQLITE REGION DB]: Loaded terrain revision r" + rev.ToString());
  786. }
  787. }
  788. return terret;
  789. }
  790. }
  791. public void RemoveLandObject(UUID globalID)
  792. {
  793. lock (ds)
  794. {
  795. // Can't use blanket SQL statements when using SqlAdapters unless you re-read the data into the adapter
  796. // after you're done.
  797. // replaced below code with the SqliteAdapter version.
  798. //using (SqliteCommand cmd = new SqliteCommand("delete from land where UUID=:UUID", m_conn))
  799. //{
  800. // cmd.Parameters.Add(new SqliteParameter(":UUID", globalID.ToString()));
  801. // cmd.ExecuteNonQuery();
  802. //}
  803. //using (SqliteCommand cmd = new SqliteCommand("delete from landaccesslist where LandUUID=:UUID", m_conn))
  804. //{
  805. // cmd.Parameters.Add(new SqliteParameter(":UUID", globalID.ToString()));
  806. // cmd.ExecuteNonQuery();
  807. //}
  808. DataTable land = ds.Tables["land"];
  809. DataTable landaccesslist = ds.Tables["landaccesslist"];
  810. DataRow landRow = land.Rows.Find(globalID.ToString());
  811. if (landRow != null)
  812. {
  813. landRow.Delete();
  814. }
  815. List<DataRow> rowsToDelete = new List<DataRow>();
  816. foreach (DataRow rowToCheck in landaccesslist.Rows)
  817. {
  818. if (rowToCheck["LandUUID"].ToString() == globalID.ToString())
  819. rowsToDelete.Add(rowToCheck);
  820. }
  821. for (int iter = 0; iter < rowsToDelete.Count; iter++)
  822. {
  823. rowsToDelete[iter].Delete();
  824. }
  825. }
  826. Commit();
  827. }
  828. /// <summary>
  829. ///
  830. /// </summary>
  831. /// <param name="parcel"></param>
  832. public void StoreLandObject(ILandObject parcel)
  833. {
  834. lock (ds)
  835. {
  836. DataTable land = ds.Tables["land"];
  837. DataTable landaccesslist = ds.Tables["landaccesslist"];
  838. DataRow landRow = land.Rows.Find(parcel.LandData.GlobalID.ToString());
  839. if (landRow == null)
  840. {
  841. landRow = land.NewRow();
  842. fillLandRow(landRow, parcel.LandData, parcel.RegionUUID);
  843. land.Rows.Add(landRow);
  844. }
  845. else
  846. {
  847. fillLandRow(landRow, parcel.LandData, parcel.RegionUUID);
  848. }
  849. // I know this caused someone issues before, but OpenSim is unusable if we leave this stuff around
  850. //using (SqliteCommand cmd = new SqliteCommand("delete from landaccesslist where LandUUID=:LandUUID", m_conn))
  851. //{
  852. // cmd.Parameters.Add(new SqliteParameter(":LandUUID", parcel.LandData.GlobalID.ToString()));
  853. // cmd.ExecuteNonQuery();
  854. // }
  855. // This is the slower.. but more appropriate thing to do
  856. // We can't modify the table with direct queries before calling Commit() and re-filling them.
  857. List<DataRow> rowsToDelete = new List<DataRow>();
  858. foreach (DataRow rowToCheck in landaccesslist.Rows)
  859. {
  860. if (rowToCheck["LandUUID"].ToString() == parcel.LandData.GlobalID.ToString())
  861. rowsToDelete.Add(rowToCheck);
  862. }
  863. for (int iter = 0; iter < rowsToDelete.Count; iter++)
  864. {
  865. rowsToDelete[iter].Delete();
  866. landaccesslist.Rows.Remove(rowsToDelete[iter]);
  867. }
  868. rowsToDelete.Clear();
  869. foreach (LandAccessEntry entry in parcel.LandData.ParcelAccessList)
  870. {
  871. DataRow newAccessRow = landaccesslist.NewRow();
  872. fillLandAccessRow(newAccessRow, entry, parcel.LandData.GlobalID);
  873. landaccesslist.Rows.Add(newAccessRow);
  874. }
  875. }
  876. Commit();
  877. }
  878. /// <summary>
  879. ///
  880. /// </summary>
  881. /// <param name="regionUUID"></param>
  882. /// <returns></returns>
  883. public List<LandData> LoadLandObjects(UUID regionUUID)
  884. {
  885. List<LandData> landDataForRegion = new List<LandData>();
  886. lock (ds)
  887. {
  888. DataTable land = ds.Tables["land"];
  889. DataTable landaccesslist = ds.Tables["landaccesslist"];
  890. string searchExp = "RegionUUID = '" + regionUUID + "'";
  891. DataRow[] rawDataForRegion = land.Select(searchExp);
  892. foreach (DataRow rawDataLand in rawDataForRegion)
  893. {
  894. LandData newLand = buildLandData(rawDataLand);
  895. string accessListSearchExp = "LandUUID = '" + newLand.GlobalID + "'";
  896. DataRow[] rawDataForLandAccessList = landaccesslist.Select(accessListSearchExp);
  897. foreach (DataRow rawDataLandAccess in rawDataForLandAccessList)
  898. {
  899. newLand.ParcelAccessList.Add(buildLandAccessData(rawDataLandAccess));
  900. }
  901. landDataForRegion.Add(newLand);
  902. }
  903. }
  904. return landDataForRegion;
  905. }
  906. /// <summary>
  907. ///
  908. /// </summary>
  909. public void Commit()
  910. {
  911. // m_log.Debug("[SQLITE]: Starting commit");
  912. lock (ds)
  913. {
  914. primDa.Update(ds, "prims");
  915. shapeDa.Update(ds, "primshapes");
  916. itemsDa.Update(ds, "primitems");
  917. terrainDa.Update(ds, "terrain");
  918. landDa.Update(ds, "land");
  919. landAccessListDa.Update(ds, "landaccesslist");
  920. try
  921. {
  922. regionSettingsDa.Update(ds, "regionsettings");
  923. regionWindlightDa.Update(ds, "regionwindlight");
  924. }
  925. catch (SqliteException SqlEx)
  926. {
  927. throw new Exception(
  928. "There was a SQL error or connection string configuration error when saving the region settings. This could be a bug, it could also happen if ConnectionString is defined in the [DatabaseService] section of StandaloneCommon.ini in the config_include folder. This could also happen if the config_include folder doesn't exist or if the OpenSim.ini [Architecture] section isn't set. If this is your first time running OpenSimulator, please restart the simulator and bug a developer to fix this!",
  929. SqlEx);
  930. }
  931. ds.AcceptChanges();
  932. }
  933. }
  934. /// <summary>
  935. /// See <see cref="Commit"/>
  936. /// </summary>
  937. public void Shutdown()
  938. {
  939. Commit();
  940. }
  941. /***********************************************************************
  942. *
  943. * Database Definition Functions
  944. *
  945. * This should be db agnostic as we define them in ADO.NET terms
  946. *
  947. **********************************************************************/
  948. protected void CreateDataSetMapping(IDataAdapter da, string tableName)
  949. {
  950. ITableMapping dbMapping = da.TableMappings.Add(tableName, tableName);
  951. foreach (DataColumn col in ds.Tables[tableName].Columns)
  952. {
  953. dbMapping.ColumnMappings.Add(col.ColumnName, col.ColumnName);
  954. }
  955. }
  956. /// <summary>
  957. ///
  958. /// </summary>
  959. /// <param name="dt"></param>
  960. /// <param name="name"></param>
  961. /// <param name="type"></param>
  962. private static void createCol(DataTable dt, string name, Type type)
  963. {
  964. DataColumn col = new DataColumn(name, type);
  965. dt.Columns.Add(col);
  966. }
  967. /// <summary>
  968. /// Creates the "terrain" table
  969. /// </summary>
  970. /// <returns>terrain table DataTable</returns>
  971. private static DataTable createTerrainTable()
  972. {
  973. DataTable terrain = new DataTable("terrain");
  974. createCol(terrain, "RegionUUID", typeof(String));
  975. createCol(terrain, "Revision", typeof(Int32));
  976. createCol(terrain, "Heightfield", typeof(Byte[]));
  977. return terrain;
  978. }
  979. /// <summary>
  980. /// Creates the "prims" table
  981. /// </summary>
  982. /// <returns>prim table DataTable</returns>
  983. private static DataTable createPrimTable()
  984. {
  985. DataTable prims = new DataTable("prims");
  986. createCol(prims, "UUID", typeof(String));
  987. createCol(prims, "RegionUUID", typeof(String));
  988. createCol(prims, "CreationDate", typeof(Int32));
  989. createCol(prims, "Name", typeof(String));
  990. createCol(prims, "SceneGroupID", typeof(String));
  991. // various text fields
  992. createCol(prims, "Text", typeof(String));
  993. createCol(prims, "ColorR", typeof(Int32));
  994. createCol(prims, "ColorG", typeof(Int32));
  995. createCol(prims, "ColorB", typeof(Int32));
  996. createCol(prims, "ColorA", typeof(Int32));
  997. createCol(prims, "Description", typeof(String));
  998. createCol(prims, "SitName", typeof(String));
  999. createCol(prims, "TouchName", typeof(String));
  1000. // permissions
  1001. createCol(prims, "ObjectFlags", typeof(Int32));
  1002. createCol(prims, "CreatorID", typeof(String));
  1003. createCol(prims, "OwnerID", typeof(String));
  1004. createCol(prims, "GroupID", typeof(String));
  1005. createCol(prims, "LastOwnerID", typeof(String));
  1006. createCol(prims, "OwnerMask", typeof(Int32));
  1007. createCol(prims, "NextOwnerMask", typeof(Int32));
  1008. createCol(prims, "GroupMask", typeof(Int32));
  1009. createCol(prims, "EveryoneMask", typeof(Int32));
  1010. createCol(prims, "BaseMask", typeof(Int32));
  1011. // vectors
  1012. createCol(prims, "PositionX", typeof(Double));
  1013. createCol(prims, "PositionY", typeof(Double));
  1014. createCol(prims, "PositionZ", typeof(Double));
  1015. createCol(prims, "GroupPositionX", typeof(Double));
  1016. createCol(prims, "GroupPositionY", typeof(Double));
  1017. createCol(prims, "GroupPositionZ", typeof(Double));
  1018. createCol(prims, "VelocityX", typeof(Double));
  1019. createCol(prims, "VelocityY", typeof(Double));
  1020. createCol(prims, "VelocityZ", typeof(Double));
  1021. createCol(prims, "AngularVelocityX", typeof(Double));
  1022. createCol(prims, "AngularVelocityY", typeof(Double));
  1023. createCol(prims, "AngularVelocityZ", typeof(Double));
  1024. createCol(prims, "AccelerationX", typeof(Double));
  1025. createCol(prims, "AccelerationY", typeof(Double));
  1026. createCol(prims, "AccelerationZ", typeof(Double));
  1027. // quaternions
  1028. createCol(prims, "RotationX", typeof(Double));
  1029. createCol(prims, "RotationY", typeof(Double));
  1030. createCol(prims, "RotationZ", typeof(Double));
  1031. createCol(prims, "RotationW", typeof(Double));
  1032. // sit target
  1033. createCol(prims, "SitTargetOffsetX", typeof(Double));
  1034. createCol(prims, "SitTargetOffsetY", typeof(Double));
  1035. createCol(prims, "SitTargetOffsetZ", typeof(Double));
  1036. createCol(prims, "SitTargetOrientW", typeof(Double));
  1037. createCol(prims, "SitTargetOrientX", typeof(Double));
  1038. createCol(prims, "SitTargetOrientY", typeof(Double));
  1039. createCol(prims, "SitTargetOrientZ", typeof(Double));
  1040. createCol(prims, "PayPrice", typeof(Int32));
  1041. createCol(prims, "PayButton1", typeof(Int32));
  1042. createCol(prims, "PayButton2", typeof(Int32));
  1043. createCol(prims, "PayButton3", typeof(Int32));
  1044. createCol(prims, "PayButton4", typeof(Int32));
  1045. createCol(prims, "LoopedSound", typeof(String));
  1046. createCol(prims, "LoopedSoundGain", typeof(Double));
  1047. createCol(prims, "TextureAnimation", typeof(String));
  1048. createCol(prims, "ParticleSystem", typeof(String));
  1049. createCol(prims, "OmegaX", typeof(Double));
  1050. createCol(prims, "OmegaY", typeof(Double));
  1051. createCol(prims, "OmegaZ", typeof(Double));
  1052. createCol(prims, "CameraEyeOffsetX", typeof(Double));
  1053. createCol(prims, "CameraEyeOffsetY", typeof(Double));
  1054. createCol(prims, "CameraEyeOffsetZ", typeof(Double));
  1055. createCol(prims, "CameraAtOffsetX", typeof(Double));
  1056. createCol(prims, "CameraAtOffsetY", typeof(Double));
  1057. createCol(prims, "CameraAtOffsetZ", typeof(Double));
  1058. createCol(prims, "ForceMouselook", typeof(Int16));
  1059. createCol(prims, "ScriptAccessPin", typeof(Int32));
  1060. createCol(prims, "AllowedDrop", typeof(Int16));
  1061. createCol(prims, "DieAtEdge", typeof(Int16));
  1062. createCol(prims, "SalePrice", typeof(Int32));
  1063. createCol(prims, "SaleType", typeof(Int16));
  1064. // click action
  1065. createCol(prims, "ClickAction", typeof(Byte));
  1066. createCol(prims, "Material", typeof(Byte));
  1067. createCol(prims, "CollisionSound", typeof(String));
  1068. createCol(prims, "CollisionSoundVolume", typeof(Double));
  1069. createCol(prims, "VolumeDetect", typeof(Int16));
  1070. createCol(prims, "MediaURL", typeof(String));
  1071. createCol(prims, "DynAttrs", typeof(String));
  1072. createCol(prims, "PhysicsShapeType", typeof(Byte));
  1073. createCol(prims, "Density", typeof(Double));
  1074. createCol(prims, "GravityModifier", typeof(Double));
  1075. createCol(prims, "Friction", typeof(Double));
  1076. createCol(prims, "Restitution", typeof(Double));
  1077. createCol(prims, "KeyframeMotion", typeof(Byte[]));
  1078. // Add in contraints
  1079. prims.PrimaryKey = new DataColumn[] { prims.Columns["UUID"] };
  1080. return prims;
  1081. }
  1082. /// <summary>
  1083. /// Creates "primshapes" table
  1084. /// </summary>
  1085. /// <returns>shape table DataTable</returns>
  1086. private static DataTable createShapeTable()
  1087. {
  1088. DataTable shapes = new DataTable("primshapes");
  1089. createCol(shapes, "UUID", typeof(String));
  1090. // shape is an enum
  1091. createCol(shapes, "Shape", typeof(Int32));
  1092. // vectors
  1093. createCol(shapes, "ScaleX", typeof(Double));
  1094. createCol(shapes, "ScaleY", typeof(Double));
  1095. createCol(shapes, "ScaleZ", typeof(Double));
  1096. // paths
  1097. createCol(shapes, "PCode", typeof(Int32));
  1098. createCol(shapes, "PathBegin", typeof(Int32));
  1099. createCol(shapes, "PathEnd", typeof(Int32));
  1100. createCol(shapes, "PathScaleX", typeof(Int32));
  1101. createCol(shapes, "PathScaleY", typeof(Int32));
  1102. createCol(shapes, "PathShearX", typeof(Int32));
  1103. createCol(shapes, "PathShearY", typeof(Int32));
  1104. createCol(shapes, "PathSkew", typeof(Int32));
  1105. createCol(shapes, "PathCurve", typeof(Int32));
  1106. createCol(shapes, "PathRadiusOffset", typeof(Int32));
  1107. createCol(shapes, "PathRevolutions", typeof(Int32));
  1108. createCol(shapes, "PathTaperX", typeof(Int32));
  1109. createCol(shapes, "PathTaperY", typeof(Int32));
  1110. createCol(shapes, "PathTwist", typeof(Int32));
  1111. createCol(shapes, "PathTwistBegin", typeof(Int32));
  1112. // profile
  1113. createCol(shapes, "ProfileBegin", typeof(Int32));
  1114. createCol(shapes, "ProfileEnd", typeof(Int32));
  1115. createCol(shapes, "ProfileCurve", typeof(Int32));
  1116. createCol(shapes, "ProfileHollow", typeof(Int32));
  1117. createCol(shapes, "State", typeof(Int32));
  1118. // text TODO: this isn't right, but I'm not sure the right
  1119. // way to specify this as a blob atm
  1120. createCol(shapes, "Texture", typeof(Byte[]));
  1121. createCol(shapes, "ExtraParams", typeof(Byte[]));
  1122. createCol(shapes, "Media", typeof(String));
  1123. shapes.PrimaryKey = new DataColumn[] { shapes.Columns["UUID"] };
  1124. return shapes;
  1125. }
  1126. /// <summary>
  1127. /// creates "primitems" table
  1128. /// </summary>
  1129. /// <returns>item table DataTable</returns>
  1130. private static DataTable createItemsTable()
  1131. {
  1132. DataTable items = new DataTable("primitems");
  1133. createCol(items, "itemID", typeof(String));
  1134. createCol(items, "primID", typeof(String));
  1135. createCol(items, "assetID", typeof(String));
  1136. createCol(items, "parentFolderID", typeof(String));
  1137. createCol(items, "invType", typeof(Int32));
  1138. createCol(items, "assetType", typeof(Int32));
  1139. createCol(items, "name", typeof(String));
  1140. createCol(items, "description", typeof(String));
  1141. createCol(items, "creationDate", typeof(Int64));
  1142. createCol(items, "creatorID", typeof(String));
  1143. createCol(items, "ownerID", typeof(String));
  1144. createCol(items, "lastOwnerID", typeof(String));
  1145. createCol(items, "groupID", typeof(String));
  1146. createCol(items, "nextPermissions", typeof(UInt32));
  1147. createCol(items, "currentPermissions", typeof(UInt32));
  1148. createCol(items, "basePermissions", typeof(UInt32));
  1149. createCol(items, "everyonePermissions", typeof(UInt32));
  1150. createCol(items, "groupPermissions", typeof(UInt32));
  1151. createCol(items, "flags", typeof(UInt32));
  1152. items.PrimaryKey = new DataColumn[] { items.Columns["itemID"] };
  1153. return items;
  1154. }
  1155. /// <summary>
  1156. /// Creates "land" table
  1157. /// </summary>
  1158. /// <returns>land table DataTable</returns>
  1159. private static DataTable createLandTable()
  1160. {
  1161. DataTable land = new DataTable("land");
  1162. createCol(land, "UUID", typeof(String));
  1163. createCol(land, "RegionUUID", typeof(String));
  1164. createCol(land, "LocalLandID", typeof(UInt32));
  1165. // Bitmap is a byte[512]
  1166. createCol(land, "Bitmap", typeof(Byte[]));
  1167. createCol(land, "Name", typeof(String));
  1168. createCol(land, "Desc", typeof(String));
  1169. createCol(land, "OwnerUUID", typeof(String));
  1170. createCol(land, "IsGroupOwned", typeof(Boolean));
  1171. createCol(land, "Area", typeof(Int32));
  1172. createCol(land, "AuctionID", typeof(Int32)); //Unemplemented
  1173. createCol(land, "Category", typeof(Int32)); //Enum OpenMetaverse.Parcel.ParcelCategory
  1174. createCol(land, "ClaimDate", typeof(Int32));
  1175. createCol(land, "ClaimPrice", typeof(Int32));
  1176. createCol(land, "GroupUUID", typeof(string));
  1177. createCol(land, "SalePrice", typeof(Int32));
  1178. createCol(land, "LandStatus", typeof(Int32)); //Enum. OpenMetaverse.Parcel.ParcelStatus
  1179. createCol(land, "LandFlags", typeof(UInt32));
  1180. createCol(land, "LandingType", typeof(Byte));
  1181. createCol(land, "MediaAutoScale", typeof(Byte));
  1182. createCol(land, "MediaTextureUUID", typeof(String));
  1183. createCol(land, "MediaURL", typeof(String));
  1184. createCol(land, "MusicURL", typeof(String));
  1185. createCol(land, "PassHours", typeof(Double));
  1186. createCol(land, "PassPrice", typeof(UInt32));
  1187. createCol(land, "SnapshotUUID", typeof(String));
  1188. createCol(land, "UserLocationX", typeof(Double));
  1189. createCol(land, "UserLocationY", typeof(Double));
  1190. createCol(land, "UserLocationZ", typeof(Double));
  1191. createCol(land, "UserLookAtX", typeof(Double));
  1192. createCol(land, "UserLookAtY", typeof(Double));
  1193. createCol(land, "UserLookAtZ", typeof(Double));
  1194. createCol(land, "AuthbuyerID", typeof(String));
  1195. createCol(land, "OtherCleanTime", typeof(Int32));
  1196. createCol(land, "Dwell", typeof(Int32));
  1197. createCol(land, "MediaType", typeof(String));
  1198. createCol(land, "MediaDescription", typeof(String));
  1199. createCol(land, "MediaSize", typeof(String));
  1200. createCol(land, "MediaLoop", typeof(Boolean));
  1201. createCol(land, "ObscureMedia", typeof(Boolean));
  1202. createCol(land, "ObscureMusic", typeof(Boolean));
  1203. land.PrimaryKey = new DataColumn[] { land.Columns["UUID"] };
  1204. return land;
  1205. }
  1206. /// <summary>
  1207. /// create "landaccesslist" table
  1208. /// </summary>
  1209. /// <returns>Landacceslist DataTable</returns>
  1210. private static DataTable createLandAccessListTable()
  1211. {
  1212. DataTable landaccess = new DataTable("landaccesslist");
  1213. createCol(landaccess, "LandUUID", typeof(String));
  1214. createCol(landaccess, "AccessUUID", typeof(String));
  1215. createCol(landaccess, "Flags", typeof(UInt32));
  1216. return landaccess;
  1217. }
  1218. private static DataTable createRegionSettingsTable()
  1219. {
  1220. DataTable regionsettings = new DataTable("regionsettings");
  1221. createCol(regionsettings, "regionUUID", typeof(String));
  1222. createCol(regionsettings, "block_terraform", typeof(Int32));
  1223. createCol(regionsettings, "block_fly", typeof(Int32));
  1224. createCol(regionsettings, "allow_damage", typeof(Int32));
  1225. createCol(regionsettings, "restrict_pushing", typeof(Int32));
  1226. createCol(regionsettings, "allow_land_resell", typeof(Int32));
  1227. createCol(regionsettings, "allow_land_join_divide", typeof(Int32));
  1228. createCol(regionsettings, "block_show_in_search", typeof(Int32));
  1229. createCol(regionsettings, "agent_limit", typeof(Int32));
  1230. createCol(regionsettings, "object_bonus", typeof(Double));
  1231. createCol(regionsettings, "maturity", typeof(Int32));
  1232. createCol(regionsettings, "disable_scripts", typeof(Int32));
  1233. createCol(regionsettings, "disable_collisions", typeof(Int32));
  1234. createCol(regionsettings, "disable_physics", typeof(Int32));
  1235. createCol(regionsettings, "terrain_texture_1", typeof(String));
  1236. createCol(regionsettings, "terrain_texture_2", typeof(String));
  1237. createCol(regionsettings, "terrain_texture_3", typeof(String));
  1238. createCol(regionsettings, "terrain_texture_4", typeof(String));
  1239. createCol(regionsettings, "elevation_1_nw", typeof(Double));
  1240. createCol(regionsettings, "elevation_2_nw", typeof(Double));
  1241. createCol(regionsettings, "elevation_1_ne", typeof(Double));
  1242. createCol(regionsettings, "elevation_2_ne", typeof(Double));
  1243. createCol(regionsettings, "elevation_1_se", typeof(Double));
  1244. createCol(regionsettings, "elevation_2_se", typeof(Double));
  1245. createCol(regionsettings, "elevation_1_sw", typeof(Double));
  1246. createCol(regionsettings, "elevation_2_sw", typeof(Double));
  1247. createCol(regionsettings, "water_height", typeof(Double));
  1248. createCol(regionsettings, "terrain_raise_limit", typeof(Double));
  1249. createCol(regionsettings, "terrain_lower_limit", typeof(Double));
  1250. createCol(regionsettings, "use_estate_sun", typeof(Int32));
  1251. createCol(regionsettings, "sandbox", typeof(Int32));
  1252. createCol(regionsettings, "sunvectorx", typeof(Double));
  1253. createCol(regionsettings, "sunvectory", typeof(Double));
  1254. createCol(regionsettings, "sunvectorz", typeof(Double));
  1255. createCol(regionsettings, "fixed_sun", typeof(Int32));
  1256. createCol(regionsettings, "sun_position", typeof(Double));
  1257. createCol(regionsettings, "covenant", typeof(String));
  1258. createCol(regionsettings, "covenant_datetime", typeof(Int32));
  1259. createCol(regionsettings, "map_tile_ID", typeof(String));
  1260. createCol(regionsettings, "TelehubObject", typeof(String));
  1261. createCol(regionsettings, "parcel_tile_ID", typeof(String));
  1262. regionsettings.PrimaryKey = new DataColumn[] { regionsettings.Columns["regionUUID"] };
  1263. return regionsettings;
  1264. }
  1265. /// <summary>
  1266. /// create "regionwindlight" table
  1267. /// </summary>
  1268. /// <returns>RegionWindlight DataTable</returns>
  1269. private static DataTable createRegionWindlightTable()
  1270. {
  1271. DataTable regionwindlight = new DataTable("regionwindlight");
  1272. createCol(regionwindlight, "region_id", typeof(String));
  1273. createCol(regionwindlight, "water_color_r", typeof(Double));
  1274. createCol(regionwindlight, "water_color_g", typeof(Double));
  1275. createCol(regionwindlight, "water_color_b", typeof(Double));
  1276. createCol(regionwindlight, "water_color_i", typeof(Double));
  1277. createCol(regionwindlight, "water_fog_density_exponent", typeof(Double));
  1278. createCol(regionwindlight, "underwater_fog_modifier", typeof(Double));
  1279. createCol(regionwindlight, "reflection_wavelet_scale_1", typeof(Double));
  1280. createCol(regionwindlight, "reflection_wavelet_scale_2", typeof(Double));
  1281. createCol(regionwindlight, "reflection_wavelet_scale_3", typeof(Double));
  1282. createCol(regionwindlight, "fresnel_scale", typeof(Double));
  1283. createCol(regionwindlight, "fresnel_offset", typeof(Double));
  1284. createCol(regionwindlight, "refract_scale_above", typeof(Double));
  1285. createCol(regionwindlight, "refract_scale_below", typeof(Double));
  1286. createCol(regionwindlight, "blur_multiplier", typeof(Double));
  1287. createCol(regionwindlight, "big_wave_direction_x", typeof(Double));
  1288. createCol(regionwindlight, "big_wave_direction_y", typeof(Double));
  1289. createCol(regionwindlight, "little_wave_direction_x", typeof(Double));
  1290. createCol(regionwindlight, "little_wave_direction_y", typeof(Double));
  1291. createCol(regionwindlight, "normal_map_texture", typeof(String));
  1292. createCol(regionwindlight, "horizon_r", typeof(Double));
  1293. createCol(regionwindlight, "horizon_g", typeof(Double));
  1294. createCol(regionwindlight, "horizon_b", typeof(Double));
  1295. createCol(regionwindlight, "horizon_i", typeof(Double));
  1296. createCol(regionwindlight, "haze_horizon", typeof(Double));
  1297. createCol(regionwindlight, "blue_density_r", typeof(Double));
  1298. createCol(regionwindlight, "blue_density_g", typeof(Double));
  1299. createCol(regionwindlight, "blue_density_b", typeof(Double));
  1300. createCol(regionwindlight, "blue_density_i", typeof(Double));
  1301. createCol(regionwindlight, "haze_density", typeof(Double));
  1302. createCol(regionwindlight, "density_multiplier", typeof(Double));
  1303. createCol(regionwindlight, "distance_multiplier", typeof(Double));
  1304. createCol(regionwindlight, "max_altitude", typeof(Int32));
  1305. createCol(regionwindlight, "sun_moon_color_r", typeof(Double));
  1306. createCol(regionwindlight, "sun_moon_color_g", typeof(Double));
  1307. createCol(regionwindlight, "sun_moon_color_b", typeof(Double));
  1308. createCol(regionwindlight, "sun_moon_color_i", typeof(Double));
  1309. createCol(regionwindlight, "sun_moon_position", typeof(Double));
  1310. createCol(regionwindlight, "ambient_r", typeof(Double));
  1311. createCol(regionwindlight, "ambient_g", typeof(Double));
  1312. createCol(regionwindlight, "ambient_b", typeof(Double));
  1313. createCol(regionwindlight, "ambient_i", typeof(Double));
  1314. createCol(regionwindlight, "east_angle", typeof(Double));
  1315. createCol(regionwindlight, "sun_glow_focus", typeof(Double));
  1316. createCol(regionwindlight, "sun_glow_size", typeof(Double));
  1317. createCol(regionwindlight, "scene_gamma", typeof(Double));
  1318. createCol(regionwindlight, "star_brightness", typeof(Double));
  1319. createCol(regionwindlight, "cloud_color_r", typeof(Double));
  1320. createCol(regionwindlight, "cloud_color_g", typeof(Double));
  1321. createCol(regionwindlight, "cloud_color_b", typeof(Double));
  1322. createCol(regionwindlight, "cloud_color_i", typeof(Double));
  1323. createCol(regionwindlight, "cloud_x", typeof(Double));
  1324. createCol(regionwindlight, "cloud_y", typeof(Double));
  1325. createCol(regionwindlight, "cloud_density", typeof(Double));
  1326. createCol(regionwindlight, "cloud_coverage", typeof(Double));
  1327. createCol(regionwindlight, "cloud_scale", typeof(Double));
  1328. createCol(regionwindlight, "cloud_detail_x", typeof(Double));
  1329. createCol(regionwindlight, "cloud_detail_y", typeof(Double));
  1330. createCol(regionwindlight, "cloud_detail_density", typeof(Double));
  1331. createCol(regionwindlight, "cloud_scroll_x", typeof(Double));
  1332. createCol(regionwindlight, "cloud_scroll_x_lock", typeof(Int32));
  1333. createCol(regionwindlight, "cloud_scroll_y", typeof(Double));
  1334. createCol(regionwindlight, "cloud_scroll_y_lock", typeof(Int32));
  1335. createCol(regionwindlight, "draw_classic_clouds", typeof(Int32));
  1336. regionwindlight.PrimaryKey = new DataColumn[] { regionwindlight.Columns["region_id"] };
  1337. return regionwindlight;
  1338. }
  1339. private static DataTable createRegionEnvironmentTable()
  1340. {
  1341. DataTable regionEnvironment = new DataTable("regionenvironment");
  1342. createCol(regionEnvironment, "region_id", typeof(String));
  1343. createCol(regionEnvironment, "llsd_settings", typeof(String));
  1344. regionEnvironment.PrimaryKey = new DataColumn[] { regionEnvironment.Columns["region_id"] };
  1345. return regionEnvironment;
  1346. }
  1347. private static DataTable createRegionSpawnPointsTable()
  1348. {
  1349. DataTable spawn_points = new DataTable("spawn_points");
  1350. createCol(spawn_points, "regionID", typeof(String));
  1351. createCol(spawn_points, "Yaw", typeof(float));
  1352. createCol(spawn_points, "Pitch", typeof(float));
  1353. createCol(spawn_points, "Distance", typeof(float));
  1354. return spawn_points;
  1355. }
  1356. /***********************************************************************
  1357. *
  1358. * Convert between ADO.NET <=> OpenSim Objects
  1359. *
  1360. * These should be database independant
  1361. *
  1362. **********************************************************************/
  1363. /// <summary>
  1364. ///
  1365. /// </summary>
  1366. /// <param name="row"></param>
  1367. /// <returns></returns>
  1368. private SceneObjectPart buildPrim(DataRow row)
  1369. {
  1370. // Code commented. Uncomment to test the unit test inline.
  1371. // The unit test mentions this commented code for the purposes
  1372. // of debugging a unit test failure
  1373. // SceneObjectGroup sog = new SceneObjectGroup();
  1374. // SceneObjectPart sop = new SceneObjectPart();
  1375. // sop.LocalId = 1;
  1376. // sop.Name = "object1";
  1377. // sop.Description = "object1";
  1378. // sop.Text = "";
  1379. // sop.SitName = "";
  1380. // sop.TouchName = "";
  1381. // sop.UUID = UUID.Random();
  1382. // sop.Shape = PrimitiveBaseShape.Default;
  1383. // sog.SetRootPart(sop);
  1384. // Add breakpoint in above line. Check sop fields.
  1385. // TODO: this doesn't work yet because something more
  1386. // interesting has to be done to actually get these values
  1387. // back out. Not enough time to figure it out yet.
  1388. SceneObjectPart prim = new SceneObjectPart();
  1389. prim.UUID = new UUID((String)row["UUID"]);
  1390. // explicit conversion of integers is required, which sort
  1391. // of sucks. No idea if there is a shortcut here or not.
  1392. prim.CreationDate = Convert.ToInt32(row["CreationDate"]);
  1393. prim.Name = row["Name"] == DBNull.Value ? string.Empty : (string)row["Name"];
  1394. // various text fields
  1395. prim.Text = (String)row["Text"];
  1396. prim.Color = Color.FromArgb(Convert.ToInt32(row["ColorA"]),
  1397. Convert.ToInt32(row["ColorR"]),
  1398. Convert.ToInt32(row["ColorG"]),
  1399. Convert.ToInt32(row["ColorB"]));
  1400. prim.Description = (String)row["Description"];
  1401. prim.SitName = (String)row["SitName"];
  1402. prim.TouchName = (String)row["TouchName"];
  1403. // permissions
  1404. prim.ObjectFlags = Convert.ToUInt32(row["ObjectFlags"]);
  1405. prim.CreatorIdentification = (String)row["CreatorID"];
  1406. prim.OwnerID = new UUID((String)row["OwnerID"]);
  1407. prim.GroupID = new UUID((String)row["GroupID"]);
  1408. prim.LastOwnerID = new UUID((String)row["LastOwnerID"]);
  1409. prim.OwnerMask = Convert.ToUInt32(row["OwnerMask"]);
  1410. prim.NextOwnerMask = Convert.ToUInt32(row["NextOwnerMask"]);
  1411. prim.GroupMask = Convert.ToUInt32(row["GroupMask"]);
  1412. prim.EveryoneMask = Convert.ToUInt32(row["EveryoneMask"]);
  1413. prim.BaseMask = Convert.ToUInt32(row["BaseMask"]);
  1414. // vectors
  1415. prim.OffsetPosition = new Vector3(
  1416. Convert.ToSingle(row["PositionX"]),
  1417. Convert.ToSingle(row["PositionY"]),
  1418. Convert.ToSingle(row["PositionZ"])
  1419. );
  1420. prim.GroupPosition = new Vector3(
  1421. Convert.ToSingle(row["GroupPositionX"]),
  1422. Convert.ToSingle(row["GroupPositionY"]),
  1423. Convert.ToSingle(row["GroupPositionZ"])
  1424. );
  1425. prim.Velocity = new Vector3(
  1426. Convert.ToSingle(row["VelocityX"]),
  1427. Convert.ToSingle(row["VelocityY"]),
  1428. Convert.ToSingle(row["VelocityZ"])
  1429. );
  1430. prim.AngularVelocity = new Vector3(
  1431. Convert.ToSingle(row["AngularVelocityX"]),
  1432. Convert.ToSingle(row["AngularVelocityY"]),
  1433. Convert.ToSingle(row["AngularVelocityZ"])
  1434. );
  1435. prim.Acceleration = new Vector3(
  1436. Convert.ToSingle(row["AccelerationX"]),
  1437. Convert.ToSingle(row["AccelerationY"]),
  1438. Convert.ToSingle(row["AccelerationZ"])
  1439. );
  1440. // quaternions
  1441. prim.RotationOffset = new Quaternion(
  1442. Convert.ToSingle(row["RotationX"]),
  1443. Convert.ToSingle(row["RotationY"]),
  1444. Convert.ToSingle(row["RotationZ"]),
  1445. Convert.ToSingle(row["RotationW"])
  1446. );
  1447. prim.SitTargetPositionLL = new Vector3(
  1448. Convert.ToSingle(row["SitTargetOffsetX"]),
  1449. Convert.ToSingle(row["SitTargetOffsetY"]),
  1450. Convert.ToSingle(row["SitTargetOffsetZ"]));
  1451. prim.SitTargetOrientationLL = new Quaternion(
  1452. Convert.ToSingle(
  1453. row["SitTargetOrientX"]),
  1454. Convert.ToSingle(
  1455. row["SitTargetOrientY"]),
  1456. Convert.ToSingle(
  1457. row["SitTargetOrientZ"]),
  1458. Convert.ToSingle(
  1459. row["SitTargetOrientW"]));
  1460. prim.ClickAction = Convert.ToByte(row["ClickAction"]);
  1461. prim.PayPrice[0] = Convert.ToInt32(row["PayPrice"]);
  1462. prim.PayPrice[1] = Convert.ToInt32(row["PayButton1"]);
  1463. prim.PayPrice[2] = Convert.ToInt32(row["PayButton2"]);
  1464. prim.PayPrice[3] = Convert.ToInt32(row["PayButton3"]);
  1465. prim.PayPrice[4] = Convert.ToInt32(row["PayButton4"]);
  1466. prim.Sound = new UUID(row["LoopedSound"].ToString());
  1467. prim.SoundGain = Convert.ToSingle(row["LoopedSoundGain"]);
  1468. prim.SoundFlags = 1; // If it's persisted at all, it's looped
  1469. if (!row.IsNull("TextureAnimation"))
  1470. prim.TextureAnimation = Convert.FromBase64String(row["TextureAnimation"].ToString());
  1471. if (!row.IsNull("ParticleSystem"))
  1472. prim.ParticleSystem = Convert.FromBase64String(row["ParticleSystem"].ToString());
  1473. prim.AngularVelocity = new Vector3(
  1474. Convert.ToSingle(row["OmegaX"]),
  1475. Convert.ToSingle(row["OmegaY"]),
  1476. Convert.ToSingle(row["OmegaZ"])
  1477. );
  1478. prim.SetCameraEyeOffset(new Vector3(
  1479. Convert.ToSingle(row["CameraEyeOffsetX"]),
  1480. Convert.ToSingle(row["CameraEyeOffsetY"]),
  1481. Convert.ToSingle(row["CameraEyeOffsetZ"])
  1482. ));
  1483. prim.SetCameraAtOffset(new Vector3(
  1484. Convert.ToSingle(row["CameraAtOffsetX"]),
  1485. Convert.ToSingle(row["CameraAtOffsetY"]),
  1486. Convert.ToSingle(row["CameraAtOffsetZ"])
  1487. ));
  1488. if (Convert.ToInt16(row["ForceMouselook"]) != 0)
  1489. prim.SetForceMouselook(true);
  1490. prim.ScriptAccessPin = Convert.ToInt32(row["ScriptAccessPin"]);
  1491. if (Convert.ToInt16(row["AllowedDrop"]) != 0)
  1492. prim.AllowedDrop = true;
  1493. if (Convert.ToInt16(row["DieAtEdge"]) != 0)
  1494. prim.DIE_AT_EDGE = true;
  1495. prim.SalePrice = Convert.ToInt32(row["SalePrice"]);
  1496. prim.ObjectSaleType = Convert.ToByte(row["SaleType"]);
  1497. prim.Material = Convert.ToByte(row["Material"]);
  1498. prim.CollisionSound = new UUID(row["CollisionSound"].ToString());
  1499. prim.CollisionSoundVolume = Convert.ToSingle(row["CollisionSoundVolume"]);
  1500. if (Convert.ToInt16(row["VolumeDetect"]) != 0)
  1501. prim.VolumeDetectActive = true;
  1502. if (!(row["MediaURL"] is System.DBNull))
  1503. {
  1504. // m_log.DebugFormat("[SQLITE]: MediaUrl type [{0}]", row["MediaURL"].GetType());
  1505. prim.MediaUrl = (string)row["MediaURL"];
  1506. }
  1507. if (!(row["DynAttrs"] is System.DBNull))
  1508. {
  1509. //m_log.DebugFormat("[SQLITE]: DynAttrs type [{0}]", row["DynAttrs"].GetType());
  1510. prim.DynAttrs = DAMap.FromXml((string)row["DynAttrs"]);
  1511. }
  1512. else
  1513. {
  1514. prim.DynAttrs = new DAMap();
  1515. }
  1516. prim.PhysicsShapeType = Convert.ToByte(row["PhysicsShapeType"]);
  1517. prim.Density = Convert.ToSingle(row["Density"]);
  1518. prim.GravityModifier = Convert.ToSingle(row["GravityModifier"]);
  1519. prim.Friction = Convert.ToSingle(row["Friction"]);
  1520. prim.Restitution = Convert.ToSingle(row["Restitution"]);
  1521. if (!(row["KeyframeMotion"] is DBNull))
  1522. {
  1523. Byte[] data = (byte[])row["KeyframeMotion"];
  1524. if (data.Length > 0)
  1525. prim.KeyframeMotion = KeyframeMotion.FromData(null, data);
  1526. else
  1527. prim.KeyframeMotion = null;
  1528. }
  1529. else
  1530. {
  1531. prim.KeyframeMotion = null;
  1532. }
  1533. return prim;
  1534. }
  1535. /// <summary>
  1536. /// Build a prim inventory item from the persisted data.
  1537. /// </summary>
  1538. /// <param name="row"></param>
  1539. /// <returns></returns>
  1540. private static TaskInventoryItem buildItem(DataRow row)
  1541. {
  1542. TaskInventoryItem taskItem = new TaskInventoryItem();
  1543. taskItem.ItemID = new UUID((String)row["itemID"]);
  1544. taskItem.ParentPartID = new UUID((String)row["primID"]);
  1545. taskItem.AssetID = new UUID((String)row["assetID"]);
  1546. taskItem.ParentID = new UUID((String)row["parentFolderID"]);
  1547. taskItem.InvType = Convert.ToInt32(row["invType"]);
  1548. taskItem.Type = Convert.ToInt32(row["assetType"]);
  1549. taskItem.Name = (String)row["name"];
  1550. taskItem.Description = (String)row["description"];
  1551. taskItem.CreationDate = Convert.ToUInt32(row["creationDate"]);
  1552. taskItem.CreatorIdentification = (String)row["creatorID"];
  1553. taskItem.OwnerID = new UUID((String)row["ownerID"]);
  1554. taskItem.LastOwnerID = new UUID((String)row["lastOwnerID"]);
  1555. taskItem.GroupID = new UUID((String)row["groupID"]);
  1556. taskItem.NextPermissions = Convert.ToUInt32(row["nextPermissions"]);
  1557. taskItem.CurrentPermissions = Convert.ToUInt32(row["currentPermissions"]);
  1558. taskItem.BasePermissions = Convert.ToUInt32(row["basePermissions"]);
  1559. taskItem.EveryonePermissions = Convert.ToUInt32(row["everyonePermissions"]);
  1560. taskItem.GroupPermissions = Convert.ToUInt32(row["groupPermissions"]);
  1561. taskItem.Flags = Convert.ToUInt32(row["flags"]);
  1562. return taskItem;
  1563. }
  1564. /// <summary>
  1565. /// Build a Land Data from the persisted data.
  1566. /// </summary>
  1567. /// <param name="row"></param>
  1568. /// <returns></returns>
  1569. private LandData buildLandData(DataRow row)
  1570. {
  1571. LandData newData = new LandData();
  1572. newData.GlobalID = new UUID((String)row["UUID"]);
  1573. newData.LocalID = Convert.ToInt32(row["LocalLandID"]);
  1574. // Bitmap is a byte[512]
  1575. newData.Bitmap = (Byte[])row["Bitmap"];
  1576. newData.Name = (String)row["Name"];
  1577. newData.Description = (String)row["Desc"];
  1578. newData.OwnerID = (UUID)(String)row["OwnerUUID"];
  1579. newData.IsGroupOwned = (Boolean)row["IsGroupOwned"];
  1580. newData.Area = Convert.ToInt32(row["Area"]);
  1581. newData.AuctionID = Convert.ToUInt32(row["AuctionID"]); //Unemplemented
  1582. newData.Category = (ParcelCategory)Convert.ToInt32(row["Category"]);
  1583. //Enum OpenMetaverse.Parcel.ParcelCategory
  1584. newData.ClaimDate = Convert.ToInt32(row["ClaimDate"]);
  1585. newData.ClaimPrice = Convert.ToInt32(row["ClaimPrice"]);
  1586. newData.GroupID = new UUID((String)row["GroupUUID"]);
  1587. newData.SalePrice = Convert.ToInt32(row["SalePrice"]);
  1588. newData.Status = (ParcelStatus)Convert.ToInt32(row["LandStatus"]);
  1589. //Enum. OpenMetaverse.Parcel.ParcelStatus
  1590. newData.Flags = Convert.ToUInt32(row["LandFlags"]);
  1591. newData.LandingType = (Byte)row["LandingType"];
  1592. newData.MediaAutoScale = (Byte)row["MediaAutoScale"];
  1593. newData.MediaID = new UUID((String)row["MediaTextureUUID"]);
  1594. newData.MediaURL = (String)row["MediaURL"];
  1595. newData.MusicURL = (String)row["MusicURL"];
  1596. newData.PassHours = Convert.ToSingle(row["PassHours"]);
  1597. newData.PassPrice = Convert.ToInt32(row["PassPrice"]);
  1598. newData.SnapshotID = (UUID)(String)row["SnapshotUUID"];
  1599. newData.Dwell = Convert.ToInt32(row["Dwell"]);
  1600. newData.MediaType = (String)row["MediaType"];
  1601. newData.MediaDescription = (String)row["MediaDescription"];
  1602. newData.MediaWidth = Convert.ToInt32((((string)row["MediaSize"]).Split(','))[0]);
  1603. newData.MediaHeight = Convert.ToInt32((((string)row["MediaSize"]).Split(','))[1]);
  1604. newData.MediaLoop = Convert.ToBoolean(row["MediaLoop"]);
  1605. newData.ObscureMedia = Convert.ToBoolean(row["ObscureMedia"]);
  1606. newData.ObscureMusic = Convert.ToBoolean(row["ObscureMusic"]);
  1607. try
  1608. {
  1609. newData.UserLocation =
  1610. new Vector3(Convert.ToSingle(row["UserLocationX"]), Convert.ToSingle(row["UserLocationY"]),
  1611. Convert.ToSingle(row["UserLocationZ"]));
  1612. newData.UserLookAt =
  1613. new Vector3(Convert.ToSingle(row["UserLookAtX"]), Convert.ToSingle(row["UserLookAtY"]),
  1614. Convert.ToSingle(row["UserLookAtZ"]));
  1615. }
  1616. catch (InvalidCastException)
  1617. {
  1618. m_log.ErrorFormat("[SQLITE REGION DB]: unable to get parcel telehub settings for {1}", newData.Name);
  1619. newData.UserLocation = Vector3.Zero;
  1620. newData.UserLookAt = Vector3.Zero;
  1621. }
  1622. newData.ParcelAccessList = new List<LandAccessEntry>();
  1623. UUID authBuyerID = UUID.Zero;
  1624. UUID.TryParse((string)row["AuthbuyerID"], out authBuyerID);
  1625. newData.OtherCleanTime = Convert.ToInt32(row["OtherCleanTime"]);
  1626. return newData;
  1627. }
  1628. private RegionSettings buildRegionSettings(DataRow row)
  1629. {
  1630. RegionSettings newSettings = new RegionSettings();
  1631. newSettings.RegionUUID = new UUID((string)row["regionUUID"]);
  1632. newSettings.BlockTerraform = Convert.ToBoolean(row["block_terraform"]);
  1633. newSettings.AllowDamage = Convert.ToBoolean(row["allow_damage"]);
  1634. newSettings.BlockFly = Convert.ToBoolean(row["block_fly"]);
  1635. newSettings.RestrictPushing = Convert.ToBoolean(row["restrict_pushing"]);
  1636. newSettings.AllowLandResell = Convert.ToBoolean(row["allow_land_resell"]);
  1637. newSettings.AllowLandJoinDivide = Convert.ToBoolean(row["allow_land_join_divide"]);
  1638. newSettings.BlockShowInSearch = Convert.ToBoolean(row["block_show_in_search"]);
  1639. newSettings.AgentLimit = Convert.ToInt32(row["agent_limit"]);
  1640. newSettings.ObjectBonus = Convert.ToDouble(row["object_bonus"]);
  1641. newSettings.Maturity = Convert.ToInt32(row["maturity"]);
  1642. newSettings.DisableScripts = Convert.ToBoolean(row["disable_scripts"]);
  1643. newSettings.DisableCollisions = Convert.ToBoolean(row["disable_collisions"]);
  1644. newSettings.DisablePhysics = Convert.ToBoolean(row["disable_physics"]);
  1645. newSettings.TerrainTexture1 = new UUID((String)row["terrain_texture_1"]);
  1646. newSettings.TerrainTexture2 = new UUID((String)row["terrain_texture_2"]);
  1647. newSettings.TerrainTexture3 = new UUID((String)row["terrain_texture_3"]);
  1648. newSettings.TerrainTexture4 = new UUID((String)row["terrain_texture_4"]);
  1649. newSettings.Elevation1NW = Convert.ToDouble(row["elevation_1_nw"]);
  1650. newSettings.Elevation2NW = Convert.ToDouble(row["elevation_2_nw"]);
  1651. newSettings.Elevation1NE = Convert.ToDouble(row["elevation_1_ne"]);
  1652. newSettings.Elevation2NE = Convert.ToDouble(row["elevation_2_ne"]);
  1653. newSettings.Elevation1SE = Convert.ToDouble(row["elevation_1_se"]);
  1654. newSettings.Elevation2SE = Convert.ToDouble(row["elevation_2_se"]);
  1655. newSettings.Elevation1SW = Convert.ToDouble(row["elevation_1_sw"]);
  1656. newSettings.Elevation2SW = Convert.ToDouble(row["elevation_2_sw"]);
  1657. newSettings.WaterHeight = Convert.ToDouble(row["water_height"]);
  1658. newSettings.TerrainRaiseLimit = Convert.ToDouble(row["terrain_raise_limit"]);
  1659. newSettings.TerrainLowerLimit = Convert.ToDouble(row["terrain_lower_limit"]);
  1660. newSettings.UseEstateSun = Convert.ToBoolean(row["use_estate_sun"]);
  1661. newSettings.Sandbox = Convert.ToBoolean(row["sandbox"]);
  1662. newSettings.SunVector = new Vector3(
  1663. Convert.ToSingle(row["sunvectorx"]),
  1664. Convert.ToSingle(row["sunvectory"]),
  1665. Convert.ToSingle(row["sunvectorz"])
  1666. );
  1667. newSettings.FixedSun = Convert.ToBoolean(row["fixed_sun"]);
  1668. newSettings.SunPosition = Convert.ToDouble(row["sun_position"]);
  1669. newSettings.Covenant = new UUID((String)row["covenant"]);
  1670. newSettings.CovenantChangedDateTime = Convert.ToInt32(row["covenant_datetime"]);
  1671. newSettings.TerrainImageID = new UUID((String)row["map_tile_ID"]);
  1672. newSettings.TelehubObject = new UUID((String)row["TelehubObject"]);
  1673. newSettings.ParcelImageID = new UUID((String)row["parcel_tile_ID"]);
  1674. return newSettings;
  1675. }
  1676. /// <summary>
  1677. /// Build a windlight entry from the persisted data.
  1678. /// </summary>
  1679. /// <param name="row"></param>
  1680. /// <returns>RegionLightShareData</returns>
  1681. private RegionLightShareData buildRegionWindlight(DataRow row)
  1682. {
  1683. RegionLightShareData windlight = new RegionLightShareData();
  1684. windlight.regionID = new UUID((string)row["region_id"]);
  1685. windlight.waterColor.X = Convert.ToSingle(row["water_color_r"]);
  1686. windlight.waterColor.Y = Convert.ToSingle(row["water_color_g"]);
  1687. windlight.waterColor.Z = Convert.ToSingle(row["water_color_b"]);
  1688. //windlight.waterColor.W = Convert.ToSingle(row["water_color_i"]); //not implemented
  1689. windlight.waterFogDensityExponent = Convert.ToSingle(row["water_fog_density_exponent"]);
  1690. windlight.underwaterFogModifier = Convert.ToSingle(row["underwater_fog_modifier"]);
  1691. windlight.reflectionWaveletScale.X = Convert.ToSingle(row["reflection_wavelet_scale_1"]);
  1692. windlight.reflectionWaveletScale.Y = Convert.ToSingle(row["reflection_wavelet_scale_2"]);
  1693. windlight.reflectionWaveletScale.Z = Convert.ToSingle(row["reflection_wavelet_scale_3"]);
  1694. windlight.fresnelScale = Convert.ToSingle(row["fresnel_scale"]);
  1695. windlight.fresnelOffset = Convert.ToSingle(row["fresnel_offset"]);
  1696. windlight.refractScaleAbove = Convert.ToSingle(row["refract_scale_above"]);
  1697. windlight.refractScaleBelow = Convert.ToSingle(row["refract_scale_below"]);
  1698. windlight.blurMultiplier = Convert.ToSingle(row["blur_multiplier"]);
  1699. windlight.bigWaveDirection.X = Convert.ToSingle(row["big_wave_direction_x"]);
  1700. windlight.bigWaveDirection.Y = Convert.ToSingle(row["big_wave_direction_y"]);
  1701. windlight.littleWaveDirection.X = Convert.ToSingle(row["little_wave_direction_x"]);
  1702. windlight.littleWaveDirection.Y = Convert.ToSingle(row["little_wave_direction_y"]);
  1703. windlight.normalMapTexture = new UUID((string)row["normal_map_texture"]);
  1704. windlight.horizon.X = Convert.ToSingle(row["horizon_r"]);
  1705. windlight.horizon.Y = Convert.ToSingle(row["horizon_g"]);
  1706. windlight.horizon.Z = Convert.ToSingle(row["horizon_b"]);
  1707. windlight.horizon.W = Convert.ToSingle(row["horizon_i"]);
  1708. windlight.hazeHorizon = Convert.ToSingle(row["haze_horizon"]);
  1709. windlight.blueDensity.X = Convert.ToSingle(row["blue_density_r"]);
  1710. windlight.blueDensity.Y = Convert.ToSingle(row["blue_density_g"]);
  1711. windlight.blueDensity.Z = Convert.ToSingle(row["blue_density_b"]);
  1712. windlight.blueDensity.W = Convert.ToSingle(row["blue_density_i"]);
  1713. windlight.hazeDensity = Convert.ToSingle(row["haze_density"]);
  1714. windlight.densityMultiplier = Convert.ToSingle(row["density_multiplier"]);
  1715. windlight.distanceMultiplier = Convert.ToSingle(row["distance_multiplier"]);
  1716. windlight.maxAltitude = Convert.ToUInt16(row["max_altitude"]);
  1717. windlight.sunMoonColor.X = Convert.ToSingle(row["sun_moon_color_r"]);
  1718. windlight.sunMoonColor.Y = Convert.ToSingle(row["sun_moon_color_g"]);
  1719. windlight.sunMoonColor.Z = Convert.ToSingle(row["sun_moon_color_b"]);
  1720. windlight.sunMoonColor.W = Convert.ToSingle(row["sun_moon_color_i"]);
  1721. windlight.sunMoonPosition = Convert.ToSingle(row["sun_moon_position"]);
  1722. windlight.ambient.X = Convert.ToSingle(row["ambient_r"]);
  1723. windlight.ambient.Y = Convert.ToSingle(row["ambient_g"]);
  1724. windlight.ambient.Z = Convert.ToSingle(row["ambient_b"]);
  1725. windlight.ambient.W = Convert.ToSingle(row["ambient_i"]);
  1726. windlight.eastAngle = Convert.ToSingle(row["east_angle"]);
  1727. windlight.sunGlowFocus = Convert.ToSingle(row["sun_glow_focus"]);
  1728. windlight.sunGlowSize = Convert.ToSingle(row["sun_glow_size"]);
  1729. windlight.sceneGamma = Convert.ToSingle(row["scene_gamma"]);
  1730. windlight.starBrightness = Convert.ToSingle(row["star_brightness"]);
  1731. windlight.cloudColor.X = Convert.ToSingle(row["cloud_color_r"]);
  1732. windlight.cloudColor.Y = Convert.ToSingle(row["cloud_color_g"]);
  1733. windlight.cloudColor.Z = Convert.ToSingle(row["cloud_color_b"]);
  1734. windlight.cloudColor.W = Convert.ToSingle(row["cloud_color_i"]);
  1735. windlight.cloudXYDensity.X = Convert.ToSingle(row["cloud_x"]);
  1736. windlight.cloudXYDensity.Y = Convert.ToSingle(row["cloud_y"]);
  1737. windlight.cloudXYDensity.Z = Convert.ToSingle(row["cloud_density"]);
  1738. windlight.cloudCoverage = Convert.ToSingle(row["cloud_coverage"]);
  1739. windlight.cloudScale = Convert.ToSingle(row["cloud_scale"]);
  1740. windlight.cloudDetailXYDensity.X = Convert.ToSingle(row["cloud_detail_x"]);
  1741. windlight.cloudDetailXYDensity.Y = Convert.ToSingle(row["cloud_detail_y"]);
  1742. windlight.cloudDetailXYDensity.Z = Convert.ToSingle(row["cloud_detail_density"]);
  1743. windlight.cloudScrollX = Convert.ToSingle(row["cloud_scroll_x"]);
  1744. windlight.cloudScrollXLock = Convert.ToBoolean(row["cloud_scroll_x_lock"]);
  1745. windlight.cloudScrollY = Convert.ToSingle(row["cloud_scroll_y"]);
  1746. windlight.cloudScrollYLock = Convert.ToBoolean(row["cloud_scroll_y_lock"]);
  1747. windlight.drawClassicClouds = Convert.ToBoolean(row["draw_classic_clouds"]);
  1748. return windlight;
  1749. }
  1750. /// <summary>
  1751. /// Build a land access entry from the persisted data.
  1752. /// </summary>
  1753. /// <param name="row"></param>
  1754. /// <returns></returns>
  1755. private static LandAccessEntry buildLandAccessData(DataRow row)
  1756. {
  1757. LandAccessEntry entry = new LandAccessEntry();
  1758. entry.AgentID = new UUID((string)row["AccessUUID"]);
  1759. entry.Flags = (AccessList)row["Flags"];
  1760. entry.Expires = 0;
  1761. return entry;
  1762. }
  1763. /// <summary>
  1764. ///
  1765. /// </summary>
  1766. /// <param name="val"></param>
  1767. /// <returns></returns>
  1768. private static Array serializeTerrain(double[,] val)
  1769. {
  1770. MemoryStream str = new MemoryStream(((int)Constants.RegionSize * (int)Constants.RegionSize) * sizeof(double));
  1771. BinaryWriter bw = new BinaryWriter(str);
  1772. // TODO: COMPATIBILITY - Add byte-order conversions
  1773. for (int x = 0; x < (int)Constants.RegionSize; x++)
  1774. for (int y = 0; y < (int)Constants.RegionSize; y++)
  1775. bw.Write(val[x, y]);
  1776. return str.ToArray();
  1777. }
  1778. // private void fillTerrainRow(DataRow row, UUID regionUUID, int rev, double[,] val)
  1779. // {
  1780. // row["RegionUUID"] = regionUUID;
  1781. // row["Revision"] = rev;
  1782. // MemoryStream str = new MemoryStream(((int)Constants.RegionSize * (int)Constants.RegionSize)*sizeof (double));
  1783. // BinaryWriter bw = new BinaryWriter(str);
  1784. // // TODO: COMPATIBILITY - Add byte-order conversions
  1785. // for (int x = 0; x < (int)Constants.RegionSize; x++)
  1786. // for (int y = 0; y < (int)Constants.RegionSize; y++)
  1787. // bw.Write(val[x, y]);
  1788. // row["Heightfield"] = str.ToArray();
  1789. // }
  1790. /// <summary>
  1791. ///
  1792. /// </summary>
  1793. /// <param name="row"></param>
  1794. /// <param name="prim"></param>
  1795. /// <param name="sceneGroupID"></param>
  1796. /// <param name="regionUUID"></param>
  1797. private static void fillPrimRow(DataRow row, SceneObjectPart prim, UUID sceneGroupID, UUID regionUUID)
  1798. {
  1799. row["UUID"] = prim.UUID.ToString();
  1800. row["RegionUUID"] = regionUUID.ToString();
  1801. row["CreationDate"] = prim.CreationDate;
  1802. row["Name"] = prim.Name;
  1803. row["SceneGroupID"] = sceneGroupID.ToString();
  1804. // the UUID of the root part for this SceneObjectGroup
  1805. // various text fields
  1806. row["Text"] = prim.Text;
  1807. row["Description"] = prim.Description;
  1808. row["SitName"] = prim.SitName;
  1809. row["TouchName"] = prim.TouchName;
  1810. // permissions
  1811. row["ObjectFlags"] = prim.ObjectFlags;
  1812. row["CreatorID"] = prim.CreatorIdentification.ToString();
  1813. row["OwnerID"] = prim.OwnerID.ToString();
  1814. row["GroupID"] = prim.GroupID.ToString();
  1815. row["LastOwnerID"] = prim.LastOwnerID.ToString();
  1816. row["OwnerMask"] = prim.OwnerMask;
  1817. row["NextOwnerMask"] = prim.NextOwnerMask;
  1818. row["GroupMask"] = prim.GroupMask;
  1819. row["EveryoneMask"] = prim.EveryoneMask;
  1820. row["BaseMask"] = prim.BaseMask;
  1821. // vectors
  1822. row["PositionX"] = prim.OffsetPosition.X;
  1823. row["PositionY"] = prim.OffsetPosition.Y;
  1824. row["PositionZ"] = prim.OffsetPosition.Z;
  1825. row["GroupPositionX"] = prim.GroupPosition.X;
  1826. row["GroupPositionY"] = prim.GroupPosition.Y;
  1827. row["GroupPositionZ"] = prim.GroupPosition.Z;
  1828. row["VelocityX"] = prim.Velocity.X;
  1829. row["VelocityY"] = prim.Velocity.Y;
  1830. row["VelocityZ"] = prim.Velocity.Z;
  1831. row["AngularVelocityX"] = prim.AngularVelocity.X;
  1832. row["AngularVelocityY"] = prim.AngularVelocity.Y;
  1833. row["AngularVelocityZ"] = prim.AngularVelocity.Z;
  1834. row["AccelerationX"] = prim.Acceleration.X;
  1835. row["AccelerationY"] = prim.Acceleration.Y;
  1836. row["AccelerationZ"] = prim.Acceleration.Z;
  1837. // quaternions
  1838. row["RotationX"] = prim.RotationOffset.X;
  1839. row["RotationY"] = prim.RotationOffset.Y;
  1840. row["RotationZ"] = prim.RotationOffset.Z;
  1841. row["RotationW"] = prim.RotationOffset.W;
  1842. // Sit target
  1843. Vector3 sitTargetPos = prim.SitTargetPositionLL;
  1844. row["SitTargetOffsetX"] = sitTargetPos.X;
  1845. row["SitTargetOffsetY"] = sitTargetPos.Y;
  1846. row["SitTargetOffsetZ"] = sitTargetPos.Z;
  1847. Quaternion sitTargetOrient = prim.SitTargetOrientationLL;
  1848. row["SitTargetOrientW"] = sitTargetOrient.W;
  1849. row["SitTargetOrientX"] = sitTargetOrient.X;
  1850. row["SitTargetOrientY"] = sitTargetOrient.Y;
  1851. row["SitTargetOrientZ"] = sitTargetOrient.Z;
  1852. row["ColorR"] = Convert.ToInt32(prim.Color.R);
  1853. row["ColorG"] = Convert.ToInt32(prim.Color.G);
  1854. row["ColorB"] = Convert.ToInt32(prim.Color.B);
  1855. row["ColorA"] = Convert.ToInt32(prim.Color.A);
  1856. row["PayPrice"] = prim.PayPrice[0];
  1857. row["PayButton1"] = prim.PayPrice[1];
  1858. row["PayButton2"] = prim.PayPrice[2];
  1859. row["PayButton3"] = prim.PayPrice[3];
  1860. row["PayButton4"] = prim.PayPrice[4];
  1861. row["TextureAnimation"] = Convert.ToBase64String(prim.TextureAnimation);
  1862. row["ParticleSystem"] = Convert.ToBase64String(prim.ParticleSystem);
  1863. row["OmegaX"] = prim.AngularVelocity.X;
  1864. row["OmegaY"] = prim.AngularVelocity.Y;
  1865. row["OmegaZ"] = prim.AngularVelocity.Z;
  1866. row["CameraEyeOffsetX"] = prim.GetCameraEyeOffset().X;
  1867. row["CameraEyeOffsetY"] = prim.GetCameraEyeOffset().Y;
  1868. row["CameraEyeOffsetZ"] = prim.GetCameraEyeOffset().Z;
  1869. row["CameraAtOffsetX"] = prim.GetCameraAtOffset().X;
  1870. row["CameraAtOffsetY"] = prim.GetCameraAtOffset().Y;
  1871. row["CameraAtOffsetZ"] = prim.GetCameraAtOffset().Z;
  1872. if ((prim.SoundFlags & 1) != 0) // Looped
  1873. {
  1874. row["LoopedSound"] = prim.Sound.ToString();
  1875. row["LoopedSoundGain"] = prim.SoundGain;
  1876. }
  1877. else
  1878. {
  1879. row["LoopedSound"] = UUID.Zero.ToString();
  1880. row["LoopedSoundGain"] = 0.0f;
  1881. }
  1882. if (prim.GetForceMouselook())
  1883. row["ForceMouselook"] = 1;
  1884. else
  1885. row["ForceMouselook"] = 0;
  1886. row["ScriptAccessPin"] = prim.ScriptAccessPin;
  1887. if (prim.AllowedDrop)
  1888. row["AllowedDrop"] = 1;
  1889. else
  1890. row["AllowedDrop"] = 0;
  1891. if (prim.DIE_AT_EDGE)
  1892. row["DieAtEdge"] = 1;
  1893. else
  1894. row["DieAtEdge"] = 0;
  1895. row["SalePrice"] = prim.SalePrice;
  1896. row["SaleType"] = Convert.ToInt16(prim.ObjectSaleType);
  1897. // click action
  1898. row["ClickAction"] = prim.ClickAction;
  1899. row["SalePrice"] = prim.SalePrice;
  1900. row["Material"] = prim.Material;
  1901. row["CollisionSound"] = prim.CollisionSound.ToString();
  1902. row["CollisionSoundVolume"] = prim.CollisionSoundVolume;
  1903. if (prim.VolumeDetectActive)
  1904. row["VolumeDetect"] = 1;
  1905. else
  1906. row["VolumeDetect"] = 0;
  1907. row["MediaURL"] = prim.MediaUrl;
  1908. if (prim.DynAttrs.CountNamespaces > 0)
  1909. row["DynAttrs"] = prim.DynAttrs.ToXml();
  1910. else
  1911. row["DynAttrs"] = null;
  1912. row["PhysicsShapeType"] = prim.PhysicsShapeType;
  1913. row["Density"] = (double)prim.Density;
  1914. row["GravityModifier"] = (double)prim.GravityModifier;
  1915. row["Friction"] = (double)prim.Friction;
  1916. row["Restitution"] = (double)prim.Restitution;
  1917. if (prim.KeyframeMotion != null)
  1918. row["KeyframeMotion"] = prim.KeyframeMotion.Serialize();
  1919. else
  1920. row["KeyframeMotion"] = new Byte[0];
  1921. }
  1922. /// <summary>
  1923. ///
  1924. /// </summary>
  1925. /// <param name="row"></param>
  1926. /// <param name="taskItem"></param>
  1927. private static void fillItemRow(DataRow row, TaskInventoryItem taskItem)
  1928. {
  1929. row["itemID"] = taskItem.ItemID.ToString();
  1930. row["primID"] = taskItem.ParentPartID.ToString();
  1931. row["assetID"] = taskItem.AssetID.ToString();
  1932. row["parentFolderID"] = taskItem.ParentID.ToString();
  1933. row["invType"] = taskItem.InvType;
  1934. row["assetType"] = taskItem.Type;
  1935. row["name"] = taskItem.Name;
  1936. row["description"] = taskItem.Description;
  1937. row["creationDate"] = taskItem.CreationDate;
  1938. row["creatorID"] = taskItem.CreatorIdentification.ToString();
  1939. row["ownerID"] = taskItem.OwnerID.ToString();
  1940. row["lastOwnerID"] = taskItem.LastOwnerID.ToString();
  1941. row["groupID"] = taskItem.GroupID.ToString();
  1942. row["nextPermissions"] = taskItem.NextPermissions;
  1943. row["currentPermissions"] = taskItem.CurrentPermissions;
  1944. row["basePermissions"] = taskItem.BasePermissions;
  1945. row["everyonePermissions"] = taskItem.EveryonePermissions;
  1946. row["groupPermissions"] = taskItem.GroupPermissions;
  1947. row["flags"] = taskItem.Flags;
  1948. }
  1949. /// <summary>
  1950. ///
  1951. /// </summary>
  1952. /// <param name="row"></param>
  1953. /// <param name="land"></param>
  1954. /// <param name="regionUUID"></param>
  1955. private static void fillLandRow(DataRow row, LandData land, UUID regionUUID)
  1956. {
  1957. row["UUID"] = land.GlobalID.ToString();
  1958. row["RegionUUID"] = regionUUID.ToString();
  1959. row["LocalLandID"] = land.LocalID;
  1960. // Bitmap is a byte[512]
  1961. row["Bitmap"] = land.Bitmap;
  1962. row["Name"] = land.Name;
  1963. row["Desc"] = land.Description;
  1964. row["OwnerUUID"] = land.OwnerID.ToString();
  1965. row["IsGroupOwned"] = land.IsGroupOwned;
  1966. row["Area"] = land.Area;
  1967. row["AuctionID"] = land.AuctionID; //Unemplemented
  1968. row["Category"] = land.Category; //Enum OpenMetaverse.Parcel.ParcelCategory
  1969. row["ClaimDate"] = land.ClaimDate;
  1970. row["ClaimPrice"] = land.ClaimPrice;
  1971. row["GroupUUID"] = land.GroupID.ToString();
  1972. row["SalePrice"] = land.SalePrice;
  1973. row["LandStatus"] = land.Status; //Enum. OpenMetaverse.Parcel.ParcelStatus
  1974. row["LandFlags"] = land.Flags;
  1975. row["LandingType"] = land.LandingType;
  1976. row["MediaAutoScale"] = land.MediaAutoScale;
  1977. row["MediaTextureUUID"] = land.MediaID.ToString();
  1978. row["MediaURL"] = land.MediaURL;
  1979. row["MusicURL"] = land.MusicURL;
  1980. row["PassHours"] = land.PassHours;
  1981. row["PassPrice"] = land.PassPrice;
  1982. row["SnapshotUUID"] = land.SnapshotID.ToString();
  1983. row["UserLocationX"] = land.UserLocation.X;
  1984. row["UserLocationY"] = land.UserLocation.Y;
  1985. row["UserLocationZ"] = land.UserLocation.Z;
  1986. row["UserLookAtX"] = land.UserLookAt.X;
  1987. row["UserLookAtY"] = land.UserLookAt.Y;
  1988. row["UserLookAtZ"] = land.UserLookAt.Z;
  1989. row["AuthbuyerID"] = land.AuthBuyerID.ToString();
  1990. row["OtherCleanTime"] = land.OtherCleanTime;
  1991. row["Dwell"] = land.Dwell;
  1992. row["MediaType"] = land.MediaType;
  1993. row["MediaDescription"] = land.MediaDescription;
  1994. row["MediaSize"] = String.Format("{0},{1}", land.MediaWidth, land.MediaHeight);
  1995. row["MediaLoop"] = land.MediaLoop;
  1996. row["ObscureMusic"] = land.ObscureMusic;
  1997. row["ObscureMedia"] = land.ObscureMedia;
  1998. }
  1999. /// <summary>
  2000. ///
  2001. /// </summary>
  2002. /// <param name="row"></param>
  2003. /// <param name="entry"></param>
  2004. /// <param name="parcelID"></param>
  2005. private static void fillLandAccessRow(DataRow row, LandAccessEntry entry, UUID parcelID)
  2006. {
  2007. row["LandUUID"] = parcelID.ToString();
  2008. row["AccessUUID"] = entry.AgentID.ToString();
  2009. row["Flags"] = entry.Flags;
  2010. }
  2011. private static void fillRegionSettingsRow(DataRow row, RegionSettings settings)
  2012. {
  2013. row["regionUUID"] = settings.RegionUUID.ToString();
  2014. row["block_terraform"] = settings.BlockTerraform;
  2015. row["block_fly"] = settings.BlockFly;
  2016. row["allow_damage"] = settings.AllowDamage;
  2017. row["restrict_pushing"] = settings.RestrictPushing;
  2018. row["allow_land_resell"] = settings.AllowLandResell;
  2019. row["allow_land_join_divide"] = settings.AllowLandJoinDivide;
  2020. row["block_show_in_search"] = settings.BlockShowInSearch;
  2021. row["agent_limit"] = settings.AgentLimit;
  2022. row["object_bonus"] = settings.ObjectBonus;
  2023. row["maturity"] = settings.Maturity;
  2024. row["disable_scripts"] = settings.DisableScripts;
  2025. row["disable_collisions"] = settings.DisableCollisions;
  2026. row["disable_physics"] = settings.DisablePhysics;
  2027. row["terrain_texture_1"] = settings.TerrainTexture1.ToString();
  2028. row["terrain_texture_2"] = settings.TerrainTexture2.ToString();
  2029. row["terrain_texture_3"] = settings.TerrainTexture3.ToString();
  2030. row["terrain_texture_4"] = settings.TerrainTexture4.ToString();
  2031. row["elevation_1_nw"] = settings.Elevation1NW;
  2032. row["elevation_2_nw"] = settings.Elevation2NW;
  2033. row["elevation_1_ne"] = settings.Elevation1NE;
  2034. row["elevation_2_ne"] = settings.Elevation2NE;
  2035. row["elevation_1_se"] = settings.Elevation1SE;
  2036. row["elevation_2_se"] = settings.Elevation2SE;
  2037. row["elevation_1_sw"] = settings.Elevation1SW;
  2038. row["elevation_2_sw"] = settings.Elevation2SW;
  2039. row["water_height"] = settings.WaterHeight;
  2040. row["terrain_raise_limit"] = settings.TerrainRaiseLimit;
  2041. row["terrain_lower_limit"] = settings.TerrainLowerLimit;
  2042. row["use_estate_sun"] = settings.UseEstateSun;
  2043. row["sandbox"] = settings.Sandbox; // unlike other database modules, sqlite uses a lower case s for sandbox!
  2044. row["sunvectorx"] = settings.SunVector.X;
  2045. row["sunvectory"] = settings.SunVector.Y;
  2046. row["sunvectorz"] = settings.SunVector.Z;
  2047. row["fixed_sun"] = settings.FixedSun;
  2048. row["sun_position"] = settings.SunPosition;
  2049. row["covenant"] = settings.Covenant.ToString();
  2050. row["covenant_datetime"] = settings.CovenantChangedDateTime;
  2051. row["map_tile_ID"] = settings.TerrainImageID.ToString();
  2052. row["TelehubObject"] = settings.TelehubObject.ToString();
  2053. row["parcel_tile_ID"] = settings.ParcelImageID.ToString();
  2054. }
  2055. /// <summary>
  2056. ///
  2057. /// </summary>
  2058. /// <param name="row"></param>
  2059. /// <param name="windlight"></param>
  2060. private static void fillRegionWindlightRow(DataRow row, RegionLightShareData windlight)
  2061. {
  2062. row["region_id"] = windlight.regionID.ToString();
  2063. row["water_color_r"] = windlight.waterColor.X;
  2064. row["water_color_g"] = windlight.waterColor.Y;
  2065. row["water_color_b"] = windlight.waterColor.Z;
  2066. row["water_color_i"] = 1; //windlight.waterColor.W; //not implemented
  2067. row["water_fog_density_exponent"] = windlight.waterFogDensityExponent;
  2068. row["underwater_fog_modifier"] = windlight.underwaterFogModifier;
  2069. row["reflection_wavelet_scale_1"] = windlight.reflectionWaveletScale.X;
  2070. row["reflection_wavelet_scale_2"] = windlight.reflectionWaveletScale.Y;
  2071. row["reflection_wavelet_scale_3"] = windlight.reflectionWaveletScale.Z;
  2072. row["fresnel_scale"] = windlight.fresnelScale;
  2073. row["fresnel_offset"] = windlight.fresnelOffset;
  2074. row["refract_scale_above"] = windlight.refractScaleAbove;
  2075. row["refract_scale_below"] = windlight.refractScaleBelow;
  2076. row["blur_multiplier"] = windlight.blurMultiplier;
  2077. row["big_wave_direction_x"] = windlight.bigWaveDirection.X;
  2078. row["big_wave_direction_y"] = windlight.bigWaveDirection.Y;
  2079. row["little_wave_direction_x"] = windlight.littleWaveDirection.X;
  2080. row["little_wave_direction_y"] = windlight.littleWaveDirection.Y;
  2081. row["normal_map_texture"] = windlight.normalMapTexture.ToString();
  2082. row["horizon_r"] = windlight.horizon.X;
  2083. row["horizon_g"] = windlight.horizon.Y;
  2084. row["horizon_b"] = windlight.horizon.Z;
  2085. row["horizon_i"] = windlight.horizon.W;
  2086. row["haze_horizon"] = windlight.hazeHorizon;
  2087. row["blue_density_r"] = windlight.blueDensity.X;
  2088. row["blue_density_g"] = windlight.blueDensity.Y;
  2089. row["blue_density_b"] = windlight.blueDensity.Z;
  2090. row["blue_density_i"] = windlight.blueDensity.W;
  2091. row["haze_density"] = windlight.hazeDensity;
  2092. row["density_multiplier"] = windlight.densityMultiplier;
  2093. row["distance_multiplier"] = windlight.distanceMultiplier;
  2094. row["max_altitude"] = windlight.maxAltitude;
  2095. row["sun_moon_color_r"] = windlight.sunMoonColor.X;
  2096. row["sun_moon_color_g"] = windlight.sunMoonColor.Y;
  2097. row["sun_moon_color_b"] = windlight.sunMoonColor.Z;
  2098. row["sun_moon_color_i"] = windlight.sunMoonColor.W;
  2099. row["sun_moon_position"] = windlight.sunMoonPosition;
  2100. row["ambient_r"] = windlight.ambient.X;
  2101. row["ambient_g"] = windlight.ambient.Y;
  2102. row["ambient_b"] = windlight.ambient.Z;
  2103. row["ambient_i"] = windlight.ambient.W;
  2104. row["east_angle"] = windlight.eastAngle;
  2105. row["sun_glow_focus"] = windlight.sunGlowFocus;
  2106. row["sun_glow_size"] = windlight.sunGlowSize;
  2107. row["scene_gamma"] = windlight.sceneGamma;
  2108. row["star_brightness"] = windlight.starBrightness;
  2109. row["cloud_color_r"] = windlight.cloudColor.X;
  2110. row["cloud_color_g"] = windlight.cloudColor.Y;
  2111. row["cloud_color_b"] = windlight.cloudColor.Z;
  2112. row["cloud_color_i"] = windlight.cloudColor.W;
  2113. row["cloud_x"] = windlight.cloudXYDensity.X;
  2114. row["cloud_y"] = windlight.cloudXYDensity.Y;
  2115. row["cloud_density"] = windlight.cloudXYDensity.Z;
  2116. row["cloud_coverage"] = windlight.cloudCoverage;
  2117. row["cloud_scale"] = windlight.cloudScale;
  2118. row["cloud_detail_x"] = windlight.cloudDetailXYDensity.X;
  2119. row["cloud_detail_y"] = windlight.cloudDetailXYDensity.Y;
  2120. row["cloud_detail_density"] = windlight.cloudDetailXYDensity.Z;
  2121. row["cloud_scroll_x"] = windlight.cloudScrollX;
  2122. row["cloud_scroll_x_lock"] = windlight.cloudScrollXLock;
  2123. row["cloud_scroll_y"] = windlight.cloudScrollY;
  2124. row["cloud_scroll_y_lock"] = windlight.cloudScrollYLock;
  2125. row["draw_classic_clouds"] = windlight.drawClassicClouds;
  2126. }
  2127. /// <summary>
  2128. ///
  2129. /// </summary>
  2130. /// <param name="row"></param>
  2131. /// <returns></returns>
  2132. private PrimitiveBaseShape buildShape(DataRow row)
  2133. {
  2134. PrimitiveBaseShape s = new PrimitiveBaseShape();
  2135. s.Scale = new Vector3(
  2136. Convert.ToSingle(row["ScaleX"]),
  2137. Convert.ToSingle(row["ScaleY"]),
  2138. Convert.ToSingle(row["ScaleZ"])
  2139. );
  2140. // paths
  2141. s.PCode = Convert.ToByte(row["PCode"]);
  2142. s.PathBegin = Convert.ToUInt16(row["PathBegin"]);
  2143. s.PathEnd = Convert.ToUInt16(row["PathEnd"]);
  2144. s.PathScaleX = Convert.ToByte(row["PathScaleX"]);
  2145. s.PathScaleY = Convert.ToByte(row["PathScaleY"]);
  2146. s.PathShearX = Convert.ToByte(row["PathShearX"]);
  2147. s.PathShearY = Convert.ToByte(row["PathShearY"]);
  2148. s.PathSkew = Convert.ToSByte(row["PathSkew"]);
  2149. s.PathCurve = Convert.ToByte(row["PathCurve"]);
  2150. s.PathRadiusOffset = Convert.ToSByte(row["PathRadiusOffset"]);
  2151. s.PathRevolutions = Convert.ToByte(row["PathRevolutions"]);
  2152. s.PathTaperX = Convert.ToSByte(row["PathTaperX"]);
  2153. s.PathTaperY = Convert.ToSByte(row["PathTaperY"]);
  2154. s.PathTwist = Convert.ToSByte(row["PathTwist"]);
  2155. s.PathTwistBegin = Convert.ToSByte(row["PathTwistBegin"]);
  2156. // profile
  2157. s.ProfileBegin = Convert.ToUInt16(row["ProfileBegin"]);
  2158. s.ProfileEnd = Convert.ToUInt16(row["ProfileEnd"]);
  2159. s.ProfileCurve = Convert.ToByte(row["ProfileCurve"]);
  2160. s.ProfileHollow = Convert.ToUInt16(row["ProfileHollow"]);
  2161. s.State = Convert.ToByte(row["State"]);
  2162. byte[] textureEntry = (byte[])row["Texture"];
  2163. s.TextureEntry = textureEntry;
  2164. s.ExtraParams = (byte[])row["ExtraParams"];
  2165. if (!(row["Media"] is System.DBNull))
  2166. s.Media = PrimitiveBaseShape.MediaList.FromXml((string)row["Media"]);
  2167. return s;
  2168. }
  2169. /// <summary>
  2170. ///
  2171. /// </summary>
  2172. /// <param name="row"></param>
  2173. /// <param name="prim"></param>
  2174. private static void fillShapeRow(DataRow row, SceneObjectPart prim)
  2175. {
  2176. PrimitiveBaseShape s = prim.Shape;
  2177. row["UUID"] = prim.UUID.ToString();
  2178. // shape is an enum
  2179. row["Shape"] = 0;
  2180. // vectors
  2181. row["ScaleX"] = s.Scale.X;
  2182. row["ScaleY"] = s.Scale.Y;
  2183. row["ScaleZ"] = s.Scale.Z;
  2184. // paths
  2185. row["PCode"] = s.PCode;
  2186. row["PathBegin"] = s.PathBegin;
  2187. row["PathEnd"] = s.PathEnd;
  2188. row["PathScaleX"] = s.PathScaleX;
  2189. row["PathScaleY"] = s.PathScaleY;
  2190. row["PathShearX"] = s.PathShearX;
  2191. row["PathShearY"] = s.PathShearY;
  2192. row["PathSkew"] = s.PathSkew;
  2193. row["PathCurve"] = s.PathCurve;
  2194. row["PathRadiusOffset"] = s.PathRadiusOffset;
  2195. row["PathRevolutions"] = s.PathRevolutions;
  2196. row["PathTaperX"] = s.PathTaperX;
  2197. row["PathTaperY"] = s.PathTaperY;
  2198. row["PathTwist"] = s.PathTwist;
  2199. row["PathTwistBegin"] = s.PathTwistBegin;
  2200. // profile
  2201. row["ProfileBegin"] = s.ProfileBegin;
  2202. row["ProfileEnd"] = s.ProfileEnd;
  2203. row["ProfileCurve"] = s.ProfileCurve;
  2204. row["ProfileHollow"] = s.ProfileHollow;
  2205. row["State"] = s.State;
  2206. row["Texture"] = s.TextureEntry;
  2207. row["ExtraParams"] = s.ExtraParams;
  2208. if (s.Media != null)
  2209. row["Media"] = s.Media.ToXml();
  2210. }
  2211. /// <summary>
  2212. /// Persistently store a prim.
  2213. /// </summary>
  2214. /// <param name="prim"></param>
  2215. /// <param name="sceneGroupID"></param>
  2216. /// <param name="regionUUID"></param>
  2217. private void addPrim(SceneObjectPart prim, UUID sceneGroupID, UUID regionUUID)
  2218. {
  2219. DataTable prims = ds.Tables["prims"];
  2220. DataTable shapes = ds.Tables["primshapes"];
  2221. DataRow primRow = prims.Rows.Find(prim.UUID.ToString());
  2222. if (primRow == null)
  2223. {
  2224. primRow = prims.NewRow();
  2225. fillPrimRow(primRow, prim, sceneGroupID, regionUUID);
  2226. prims.Rows.Add(primRow);
  2227. }
  2228. else
  2229. {
  2230. fillPrimRow(primRow, prim, sceneGroupID, regionUUID);
  2231. }
  2232. DataRow shapeRow = shapes.Rows.Find(prim.UUID.ToString());
  2233. if (shapeRow == null)
  2234. {
  2235. shapeRow = shapes.NewRow();
  2236. fillShapeRow(shapeRow, prim);
  2237. shapes.Rows.Add(shapeRow);
  2238. }
  2239. else
  2240. {
  2241. fillShapeRow(shapeRow, prim);
  2242. }
  2243. }
  2244. /// <summary>
  2245. /// </summary>
  2246. /// <param name="primID"></param>
  2247. /// <param name="items"></param>
  2248. public void StorePrimInventory(UUID primID, ICollection<TaskInventoryItem> items)
  2249. {
  2250. // m_log.DebugFormat("[SQLITE REGION DB]: Entered StorePrimInventory with prim ID {0}", primID);
  2251. DataTable dbItems = ds.Tables["primitems"];
  2252. // For now, we're just going to crudely remove all the previous inventory items
  2253. // no matter whether they have changed or not, and replace them with the current set.
  2254. lock (ds)
  2255. {
  2256. RemoveItems(primID);
  2257. // repalce with current inventory details
  2258. foreach (TaskInventoryItem newItem in items)
  2259. {
  2260. // m_log.InfoFormat(
  2261. // "[DATASTORE]: ",
  2262. // "Adding item {0}, {1} to prim ID {2}",
  2263. // newItem.Name, newItem.ItemID, newItem.ParentPartID);
  2264. DataRow newItemRow = dbItems.NewRow();
  2265. fillItemRow(newItemRow, newItem);
  2266. dbItems.Rows.Add(newItemRow);
  2267. }
  2268. }
  2269. Commit();
  2270. }
  2271. /***********************************************************************
  2272. *
  2273. * SQL Statement Creation Functions
  2274. *
  2275. * These functions create SQL statements for update, insert, and create.
  2276. * They can probably be factored later to have a db independant
  2277. * portion and a db specific portion
  2278. *
  2279. **********************************************************************/
  2280. /// <summary>
  2281. /// Create an insert command
  2282. /// </summary>
  2283. /// <param name="table">table name</param>
  2284. /// <param name="dt">data table</param>
  2285. /// <returns>the created command</returns>
  2286. /// <remarks>
  2287. /// This is subtle enough to deserve some commentary.
  2288. /// Instead of doing *lots* and *lots of hardcoded strings
  2289. /// for database definitions we'll use the fact that
  2290. /// realistically all insert statements look like "insert
  2291. /// into A(b, c) values(:b, :c) on the parameterized query
  2292. /// front. If we just have a list of b, c, etc... we can
  2293. /// generate these strings instead of typing them out.
  2294. /// </remarks>
  2295. private static SqliteCommand createInsertCommand(string table, DataTable dt)
  2296. {
  2297. string[] cols = new string[dt.Columns.Count];
  2298. for (int i = 0; i < dt.Columns.Count; i++)
  2299. {
  2300. DataColumn col = dt.Columns[i];
  2301. cols[i] = col.ColumnName;
  2302. }
  2303. string sql = "insert into " + table + "(";
  2304. sql += String.Join(", ", cols);
  2305. // important, the first ':' needs to be here, the rest get added in the join
  2306. sql += ") values (:";
  2307. sql += String.Join(", :", cols);
  2308. sql += ")";
  2309. // m_log.DebugFormat("[SQLITE]: Created insert command {0}", sql);
  2310. SqliteCommand cmd = new SqliteCommand(sql);
  2311. // this provides the binding for all our parameters, so
  2312. // much less code than it used to be
  2313. foreach (DataColumn col in dt.Columns)
  2314. {
  2315. cmd.Parameters.Add(createSqliteParameter(col.ColumnName, col.DataType));
  2316. }
  2317. return cmd;
  2318. }
  2319. /// <summary>
  2320. /// create an update command
  2321. /// </summary>
  2322. /// <param name="table">table name</param>
  2323. /// <param name="pk"></param>
  2324. /// <param name="dt"></param>
  2325. /// <returns>the created command</returns>
  2326. private static SqliteCommand createUpdateCommand(string table, string pk, DataTable dt)
  2327. {
  2328. string sql = "update " + table + " set ";
  2329. string subsql = String.Empty;
  2330. foreach (DataColumn col in dt.Columns)
  2331. {
  2332. if (subsql.Length > 0)
  2333. {
  2334. // a map function would rock so much here
  2335. subsql += ", ";
  2336. }
  2337. subsql += col.ColumnName + "= :" + col.ColumnName;
  2338. }
  2339. sql += subsql;
  2340. sql += " where " + pk;
  2341. SqliteCommand cmd = new SqliteCommand(sql);
  2342. // this provides the binding for all our parameters, so
  2343. // much less code than it used to be
  2344. foreach (DataColumn col in dt.Columns)
  2345. {
  2346. cmd.Parameters.Add(createSqliteParameter(col.ColumnName, col.DataType));
  2347. }
  2348. return cmd;
  2349. }
  2350. /// <summary>
  2351. /// create an update command
  2352. /// </summary>
  2353. /// <param name="table">table name</param>
  2354. /// <param name="pk"></param>
  2355. /// <param name="dt"></param>
  2356. /// <returns>the created command</returns>
  2357. private static SqliteCommand createUpdateCommand(string table, string pk1, string pk2, DataTable dt)
  2358. {
  2359. string sql = "update " + table + " set ";
  2360. string subsql = String.Empty;
  2361. foreach (DataColumn col in dt.Columns)
  2362. {
  2363. if (subsql.Length > 0)
  2364. {
  2365. // a map function would rock so much here
  2366. subsql += ", ";
  2367. }
  2368. subsql += col.ColumnName + "= :" + col.ColumnName;
  2369. }
  2370. sql += subsql;
  2371. sql += " where " + pk1 + " and " + pk2;
  2372. SqliteCommand cmd = new SqliteCommand(sql);
  2373. // this provides the binding for all our parameters, so
  2374. // much less code than it used to be
  2375. foreach (DataColumn col in dt.Columns)
  2376. {
  2377. cmd.Parameters.Add(createSqliteParameter(col.ColumnName, col.DataType));
  2378. }
  2379. return cmd;
  2380. }
  2381. /// <summary>
  2382. ///
  2383. /// </summary>
  2384. /// <param name="dt">Data Table</param>
  2385. /// <returns></returns>
  2386. // private static string defineTable(DataTable dt)
  2387. // {
  2388. // string sql = "create table " + dt.TableName + "(";
  2389. // string subsql = String.Empty;
  2390. // foreach (DataColumn col in dt.Columns)
  2391. // {
  2392. // if (subsql.Length > 0)
  2393. // {
  2394. // // a map function would rock so much here
  2395. // subsql += ",\n";
  2396. // }
  2397. // subsql += col.ColumnName + " " + sqliteType(col.DataType);
  2398. // if (dt.PrimaryKey.Length > 0 && col == dt.PrimaryKey[0])
  2399. // {
  2400. // subsql += " primary key";
  2401. // }
  2402. // }
  2403. // sql += subsql;
  2404. // sql += ")";
  2405. // return sql;
  2406. // }
  2407. /***********************************************************************
  2408. *
  2409. * Database Binding functions
  2410. *
  2411. * These will be db specific due to typing, and minor differences
  2412. * in databases.
  2413. *
  2414. **********************************************************************/
  2415. ///<summary>
  2416. /// This is a convenience function that collapses 5 repetitive
  2417. /// lines for defining SqliteParameters to 2 parameters:
  2418. /// column name and database type.
  2419. ///
  2420. /// It assumes certain conventions like :param as the param
  2421. /// name to replace in parametrized queries, and that source
  2422. /// version is always current version, both of which are fine
  2423. /// for us.
  2424. ///</summary>
  2425. ///<returns>a built sqlite parameter</returns>
  2426. private static SqliteParameter createSqliteParameter(string name, Type type)
  2427. {
  2428. SqliteParameter param = new SqliteParameter();
  2429. param.ParameterName = ":" + name;
  2430. param.DbType = dbtypeFromType(type);
  2431. param.SourceColumn = name;
  2432. param.SourceVersion = DataRowVersion.Current;
  2433. return param;
  2434. }
  2435. /// <summary>
  2436. ///
  2437. /// </summary>
  2438. /// <param name="da"></param>
  2439. /// <param name="conn"></param>
  2440. private void setupPrimCommands(SqliteDataAdapter da, SqliteConnection conn)
  2441. {
  2442. da.InsertCommand = createInsertCommand("prims", ds.Tables["prims"]);
  2443. da.InsertCommand.Connection = conn;
  2444. da.UpdateCommand = createUpdateCommand("prims", "UUID=:UUID", ds.Tables["prims"]);
  2445. da.UpdateCommand.Connection = conn;
  2446. SqliteCommand delete = new SqliteCommand("delete from prims where UUID = :UUID");
  2447. delete.Parameters.Add(createSqliteParameter("UUID", typeof(String)));
  2448. delete.Connection = conn;
  2449. da.DeleteCommand = delete;
  2450. }
  2451. /// <summary>
  2452. ///
  2453. /// </summary>
  2454. /// <param name="da"></param>
  2455. /// <param name="conn"></param>
  2456. private void setupItemsCommands(SqliteDataAdapter da, SqliteConnection conn)
  2457. {
  2458. da.InsertCommand = createInsertCommand("primitems", ds.Tables["primitems"]);
  2459. da.InsertCommand.Connection = conn;
  2460. da.UpdateCommand = createUpdateCommand("primitems", "itemID = :itemID", ds.Tables["primitems"]);
  2461. da.UpdateCommand.Connection = conn;
  2462. SqliteCommand delete = new SqliteCommand("delete from primitems where itemID = :itemID");
  2463. delete.Parameters.Add(createSqliteParameter("itemID", typeof(String)));
  2464. delete.Connection = conn;
  2465. da.DeleteCommand = delete;
  2466. }
  2467. /// <summary>
  2468. ///
  2469. /// </summary>
  2470. /// <param name="da"></param>
  2471. /// <param name="conn"></param>
  2472. private void setupTerrainCommands(SqliteDataAdapter da, SqliteConnection conn)
  2473. {
  2474. da.InsertCommand = createInsertCommand("terrain", ds.Tables["terrain"]);
  2475. da.InsertCommand.Connection = conn;
  2476. }
  2477. /// <summary>
  2478. ///
  2479. /// </summary>
  2480. /// <param name="da"></param>
  2481. /// <param name="conn"></param>
  2482. private void setupLandCommands(SqliteDataAdapter da, SqliteConnection conn)
  2483. {
  2484. da.InsertCommand = createInsertCommand("land", ds.Tables["land"]);
  2485. da.InsertCommand.Connection = conn;
  2486. da.UpdateCommand = createUpdateCommand("land", "UUID=:UUID", ds.Tables["land"]);
  2487. da.UpdateCommand.Connection = conn;
  2488. SqliteCommand delete = new SqliteCommand("delete from land where UUID=:UUID");
  2489. delete.Parameters.Add(createSqliteParameter("UUID", typeof(String)));
  2490. da.DeleteCommand = delete;
  2491. da.DeleteCommand.Connection = conn;
  2492. }
  2493. /// <summary>
  2494. ///
  2495. /// </summary>
  2496. /// <param name="da"></param>
  2497. /// <param name="conn"></param>
  2498. private void setupLandAccessCommands(SqliteDataAdapter da, SqliteConnection conn)
  2499. {
  2500. da.InsertCommand = createInsertCommand("landaccesslist", ds.Tables["landaccesslist"]);
  2501. da.InsertCommand.Connection = conn;
  2502. da.UpdateCommand = createUpdateCommand("landaccesslist", "LandUUID=:landUUID", "AccessUUID=:AccessUUID", ds.Tables["landaccesslist"]);
  2503. da.UpdateCommand.Connection = conn;
  2504. SqliteCommand delete = new SqliteCommand("delete from landaccesslist where LandUUID= :LandUUID and AccessUUID= :AccessUUID");
  2505. delete.Parameters.Add(createSqliteParameter("LandUUID", typeof(String)));
  2506. delete.Parameters.Add(createSqliteParameter("AccessUUID", typeof(String)));
  2507. da.DeleteCommand = delete;
  2508. da.DeleteCommand.Connection = conn;
  2509. }
  2510. private void setupRegionSettingsCommands(SqliteDataAdapter da, SqliteConnection conn)
  2511. {
  2512. da.InsertCommand = createInsertCommand("regionsettings", ds.Tables["regionsettings"]);
  2513. da.InsertCommand.Connection = conn;
  2514. da.UpdateCommand = createUpdateCommand("regionsettings", "regionUUID=:regionUUID", ds.Tables["regionsettings"]);
  2515. da.UpdateCommand.Connection = conn;
  2516. }
  2517. /// <summary>
  2518. ///
  2519. /// </summary>
  2520. /// <param name="da"></param>
  2521. /// <param name="conn"></param>
  2522. private void setupRegionWindlightCommands(SqliteDataAdapter da, SqliteConnection conn)
  2523. {
  2524. da.InsertCommand = createInsertCommand("regionwindlight", ds.Tables["regionwindlight"]);
  2525. da.InsertCommand.Connection = conn;
  2526. da.UpdateCommand = createUpdateCommand("regionwindlight", "region_id=:region_id", ds.Tables["regionwindlight"]);
  2527. da.UpdateCommand.Connection = conn;
  2528. }
  2529. private void setupRegionEnvironmentCommands(SqliteDataAdapter da, SqliteConnection conn)
  2530. {
  2531. da.InsertCommand = createInsertCommand("regionenvironment", ds.Tables["regionenvironment"]);
  2532. da.InsertCommand.Connection = conn;
  2533. da.UpdateCommand = createUpdateCommand("regionenvironment", "region_id=:region_id", ds.Tables["regionenvironment"]);
  2534. da.UpdateCommand.Connection = conn;
  2535. }
  2536. private void setupRegionSpawnPointsCommands(SqliteDataAdapter da, SqliteConnection conn)
  2537. {
  2538. da.InsertCommand = createInsertCommand("spawn_points", ds.Tables["spawn_points"]);
  2539. da.InsertCommand.Connection = conn;
  2540. da.UpdateCommand = createUpdateCommand("spawn_points", "RegionID=:RegionID", ds.Tables["spawn_points"]);
  2541. da.UpdateCommand.Connection = conn;
  2542. }
  2543. /// <summary>
  2544. ///
  2545. /// </summary>
  2546. /// <param name="da"></param>
  2547. /// <param name="conn"></param>
  2548. private void setupShapeCommands(SqliteDataAdapter da, SqliteConnection conn)
  2549. {
  2550. da.InsertCommand = createInsertCommand("primshapes", ds.Tables["primshapes"]);
  2551. da.InsertCommand.Connection = conn;
  2552. da.UpdateCommand = createUpdateCommand("primshapes", "UUID=:UUID", ds.Tables["primshapes"]);
  2553. da.UpdateCommand.Connection = conn;
  2554. SqliteCommand delete = new SqliteCommand("delete from primshapes where UUID = :UUID");
  2555. delete.Parameters.Add(createSqliteParameter("UUID", typeof(String)));
  2556. delete.Connection = conn;
  2557. da.DeleteCommand = delete;
  2558. }
  2559. /***********************************************************************
  2560. *
  2561. * Type conversion functions
  2562. *
  2563. **********************************************************************/
  2564. /// <summary>
  2565. /// Type conversion function
  2566. /// </summary>
  2567. /// <param name="type"></param>
  2568. /// <returns></returns>
  2569. private static DbType dbtypeFromType(Type type)
  2570. {
  2571. if (type == typeof(String))
  2572. {
  2573. return DbType.String;
  2574. }
  2575. else if (type == typeof(Int32))
  2576. {
  2577. return DbType.Int32;
  2578. }
  2579. else if (type == typeof(Double))
  2580. {
  2581. return DbType.Double;
  2582. }
  2583. else if (type == typeof(Byte))
  2584. {
  2585. return DbType.Byte;
  2586. }
  2587. else if (type == typeof(Double))
  2588. {
  2589. return DbType.Double;
  2590. }
  2591. else if (type == typeof(Byte[]))
  2592. {
  2593. return DbType.Binary;
  2594. }
  2595. else
  2596. {
  2597. return DbType.String;
  2598. }
  2599. }
  2600. static void PrintDataSet(DataSet ds)
  2601. {
  2602. // Print out any name and extended properties.
  2603. Console.WriteLine("DataSet is named: {0}", ds.DataSetName);
  2604. foreach (System.Collections.DictionaryEntry de in ds.ExtendedProperties)
  2605. {
  2606. Console.WriteLine("Key = {0}, Value = {1}", de.Key, de.Value);
  2607. }
  2608. Console.WriteLine();
  2609. foreach (DataTable dt in ds.Tables)
  2610. {
  2611. Console.WriteLine("=> {0} Table:", dt.TableName);
  2612. // Print out the column names.
  2613. for (int curCol = 0; curCol < dt.Columns.Count; curCol++)
  2614. {
  2615. Console.Write(dt.Columns[curCol].ColumnName + "\t");
  2616. }
  2617. Console.WriteLine("\n----------------------------------");
  2618. // Print the DataTable.
  2619. for (int curRow = 0; curRow < dt.Rows.Count; curRow++)
  2620. {
  2621. for (int curCol = 0; curCol < dt.Columns.Count; curCol++)
  2622. {
  2623. Console.Write(dt.Rows[curRow][curCol].ToString() + "\t");
  2624. }
  2625. Console.WriteLine();
  2626. }
  2627. }
  2628. }
  2629. public void SaveExtra(UUID regionID, string name, string value)
  2630. {
  2631. }
  2632. public void RemoveExtra(UUID regionID, string name)
  2633. {
  2634. }
  2635. public Dictionary<string, string> GetExtra(UUID regionID)
  2636. {
  2637. return null;
  2638. }
  2639. }
  2640. }