SQLiteSimulationData.cs 133 KB

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