SQLiteSimulationData.cs 129 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960
  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 SQLLITE]";
  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 revision 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 revision r {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. /// Load the latest terrain revision from region storage
  744. /// </summary>
  745. /// <param name="regionID">the region UUID</param>
  746. /// <returns>Heightfield data</returns>
  747. public double[,] LoadTerrain(UUID regionID)
  748. {
  749. double[,] ret = null;
  750. TerrainData terrData = LoadTerrain(regionID, (int)Constants.RegionSize, (int)Constants.RegionSize, (int)Constants.RegionHeight);
  751. if (terrData != null)
  752. ret = terrData.GetDoubles();
  753. return ret;
  754. }
  755. // Returns 'null' if region not found
  756. public TerrainData LoadTerrain(UUID regionID, int pSizeX, int pSizeY, int pSizeZ)
  757. {
  758. TerrainData terrData = null;
  759. lock (ds)
  760. {
  761. String sql = "select RegionUUID, Revision, Heightfield from terrain" +
  762. " where RegionUUID=:RegionUUID order by Revision desc";
  763. using (SqliteCommand cmd = new SqliteCommand(sql, m_conn))
  764. {
  765. cmd.Parameters.Add(new SqliteParameter(":RegionUUID", regionID.ToString()));
  766. using (IDataReader row = cmd.ExecuteReader())
  767. {
  768. int rev = 0;
  769. if (row.Read())
  770. {
  771. rev = Convert.ToInt32(row["Revision"]);
  772. byte[] blob = (byte[])row["Heightfield"];
  773. terrData = TerrainData.CreateFromDatabaseBlobFactory(pSizeX, pSizeY, pSizeZ, rev, blob);
  774. }
  775. else
  776. {
  777. m_log.Warn("[SQLITE REGION DB]: No terrain found for region");
  778. return null;
  779. }
  780. m_log.Debug("[SQLITE REGION DB]: Loaded terrain revision r" + rev.ToString());
  781. }
  782. }
  783. }
  784. return terrData;
  785. }
  786. public void RemoveLandObject(UUID globalID)
  787. {
  788. lock (ds)
  789. {
  790. // Can't use blanket SQL statements when using SqlAdapters unless you re-read the data into the adapter
  791. // after you're done.
  792. // replaced below code with the SqliteAdapter version.
  793. //using (SqliteCommand cmd = new SqliteCommand("delete from land where UUID=:UUID", m_conn))
  794. //{
  795. // cmd.Parameters.Add(new SqliteParameter(":UUID", globalID.ToString()));
  796. // cmd.ExecuteNonQuery();
  797. //}
  798. //using (SqliteCommand cmd = new SqliteCommand("delete from landaccesslist where LandUUID=:UUID", m_conn))
  799. //{
  800. // cmd.Parameters.Add(new SqliteParameter(":UUID", globalID.ToString()));
  801. // cmd.ExecuteNonQuery();
  802. //}
  803. DataTable land = ds.Tables["land"];
  804. DataTable landaccesslist = ds.Tables["landaccesslist"];
  805. DataRow landRow = land.Rows.Find(globalID.ToString());
  806. if (landRow != null)
  807. {
  808. landRow.Delete();
  809. }
  810. List<DataRow> rowsToDelete = new List<DataRow>();
  811. foreach (DataRow rowToCheck in landaccesslist.Rows)
  812. {
  813. if (rowToCheck["LandUUID"].ToString() == globalID.ToString())
  814. rowsToDelete.Add(rowToCheck);
  815. }
  816. for (int iter = 0; iter < rowsToDelete.Count; iter++)
  817. {
  818. rowsToDelete[iter].Delete();
  819. }
  820. }
  821. Commit();
  822. }
  823. /// <summary>
  824. ///
  825. /// </summary>
  826. /// <param name="parcel"></param>
  827. public void StoreLandObject(ILandObject parcel)
  828. {
  829. lock (ds)
  830. {
  831. DataTable land = ds.Tables["land"];
  832. DataTable landaccesslist = ds.Tables["landaccesslist"];
  833. DataRow landRow = land.Rows.Find(parcel.LandData.GlobalID.ToString());
  834. if (landRow == null)
  835. {
  836. landRow = land.NewRow();
  837. fillLandRow(landRow, parcel.LandData, parcel.RegionUUID);
  838. land.Rows.Add(landRow);
  839. }
  840. else
  841. {
  842. fillLandRow(landRow, parcel.LandData, parcel.RegionUUID);
  843. }
  844. // I know this caused someone issues before, but OpenSim is unusable if we leave this stuff around
  845. //using (SqliteCommand cmd = new SqliteCommand("delete from landaccesslist where LandUUID=:LandUUID", m_conn))
  846. //{
  847. // cmd.Parameters.Add(new SqliteParameter(":LandUUID", parcel.LandData.GlobalID.ToString()));
  848. // cmd.ExecuteNonQuery();
  849. // }
  850. // This is the slower.. but more appropriate thing to do
  851. // We can't modify the table with direct queries before calling Commit() and re-filling them.
  852. List<DataRow> rowsToDelete = new List<DataRow>();
  853. foreach (DataRow rowToCheck in landaccesslist.Rows)
  854. {
  855. if (rowToCheck["LandUUID"].ToString() == parcel.LandData.GlobalID.ToString())
  856. rowsToDelete.Add(rowToCheck);
  857. }
  858. for (int iter = 0; iter < rowsToDelete.Count; iter++)
  859. {
  860. rowsToDelete[iter].Delete();
  861. landaccesslist.Rows.Remove(rowsToDelete[iter]);
  862. }
  863. rowsToDelete.Clear();
  864. foreach (LandAccessEntry entry in parcel.LandData.ParcelAccessList)
  865. {
  866. DataRow newAccessRow = landaccesslist.NewRow();
  867. fillLandAccessRow(newAccessRow, entry, parcel.LandData.GlobalID);
  868. landaccesslist.Rows.Add(newAccessRow);
  869. }
  870. }
  871. Commit();
  872. }
  873. /// <summary>
  874. ///
  875. /// </summary>
  876. /// <param name="regionUUID"></param>
  877. /// <returns></returns>
  878. public List<LandData> LoadLandObjects(UUID regionUUID)
  879. {
  880. List<LandData> landDataForRegion = new List<LandData>();
  881. lock (ds)
  882. {
  883. DataTable land = ds.Tables["land"];
  884. DataTable landaccesslist = ds.Tables["landaccesslist"];
  885. string searchExp = "RegionUUID = '" + regionUUID + "'";
  886. DataRow[] rawDataForRegion = land.Select(searchExp);
  887. foreach (DataRow rawDataLand in rawDataForRegion)
  888. {
  889. LandData newLand = buildLandData(rawDataLand);
  890. string accessListSearchExp = "LandUUID = '" + newLand.GlobalID + "'";
  891. DataRow[] rawDataForLandAccessList = landaccesslist.Select(accessListSearchExp);
  892. foreach (DataRow rawDataLandAccess in rawDataForLandAccessList)
  893. {
  894. newLand.ParcelAccessList.Add(buildLandAccessData(rawDataLandAccess));
  895. }
  896. landDataForRegion.Add(newLand);
  897. }
  898. }
  899. return landDataForRegion;
  900. }
  901. /// <summary>
  902. ///
  903. /// </summary>
  904. public void Commit()
  905. {
  906. // m_log.Debug("[SQLITE]: Starting commit");
  907. lock (ds)
  908. {
  909. primDa.Update(ds, "prims");
  910. shapeDa.Update(ds, "primshapes");
  911. itemsDa.Update(ds, "primitems");
  912. terrainDa.Update(ds, "terrain");
  913. landDa.Update(ds, "land");
  914. landAccessListDa.Update(ds, "landaccesslist");
  915. try
  916. {
  917. regionSettingsDa.Update(ds, "regionsettings");
  918. regionWindlightDa.Update(ds, "regionwindlight");
  919. }
  920. catch (SqliteException SqlEx)
  921. {
  922. throw new Exception(
  923. "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!",
  924. SqlEx);
  925. }
  926. ds.AcceptChanges();
  927. }
  928. }
  929. /// <summary>
  930. /// See <see cref="Commit"/>
  931. /// </summary>
  932. public void Shutdown()
  933. {
  934. Commit();
  935. }
  936. /***********************************************************************
  937. *
  938. * Database Definition Functions
  939. *
  940. * This should be db agnostic as we define them in ADO.NET terms
  941. *
  942. **********************************************************************/
  943. protected void CreateDataSetMapping(IDataAdapter da, string tableName)
  944. {
  945. ITableMapping dbMapping = da.TableMappings.Add(tableName, tableName);
  946. foreach (DataColumn col in ds.Tables[tableName].Columns)
  947. {
  948. dbMapping.ColumnMappings.Add(col.ColumnName, col.ColumnName);
  949. }
  950. }
  951. /// <summary>
  952. ///
  953. /// </summary>
  954. /// <param name="dt"></param>
  955. /// <param name="name"></param>
  956. /// <param name="type"></param>
  957. private static void createCol(DataTable dt, string name, Type type)
  958. {
  959. DataColumn col = new DataColumn(name, type);
  960. dt.Columns.Add(col);
  961. }
  962. /// <summary>
  963. /// Creates the "terrain" table
  964. /// </summary>
  965. /// <returns>terrain table DataTable</returns>
  966. private static DataTable createTerrainTable()
  967. {
  968. DataTable terrain = new DataTable("terrain");
  969. createCol(terrain, "RegionUUID", typeof(String));
  970. createCol(terrain, "Revision", typeof(Int32));
  971. createCol(terrain, "Heightfield", typeof(Byte[]));
  972. return terrain;
  973. }
  974. /// <summary>
  975. /// Creates the "prims" table
  976. /// </summary>
  977. /// <returns>prim table DataTable</returns>
  978. private static DataTable createPrimTable()
  979. {
  980. DataTable prims = new DataTable("prims");
  981. createCol(prims, "UUID", typeof(String));
  982. createCol(prims, "RegionUUID", typeof(String));
  983. createCol(prims, "CreationDate", typeof(Int32));
  984. createCol(prims, "Name", typeof(String));
  985. createCol(prims, "SceneGroupID", typeof(String));
  986. // various text fields
  987. createCol(prims, "Text", typeof(String));
  988. createCol(prims, "ColorR", typeof(Int32));
  989. createCol(prims, "ColorG", typeof(Int32));
  990. createCol(prims, "ColorB", typeof(Int32));
  991. createCol(prims, "ColorA", typeof(Int32));
  992. createCol(prims, "Description", typeof(String));
  993. createCol(prims, "SitName", typeof(String));
  994. createCol(prims, "TouchName", typeof(String));
  995. // permissions
  996. createCol(prims, "ObjectFlags", typeof(Int32));
  997. createCol(prims, "CreatorID", typeof(String));
  998. createCol(prims, "OwnerID", typeof(String));
  999. createCol(prims, "GroupID", typeof(String));
  1000. createCol(prims, "LastOwnerID", typeof(String));
  1001. createCol(prims, "OwnerMask", typeof(Int32));
  1002. createCol(prims, "NextOwnerMask", typeof(Int32));
  1003. createCol(prims, "GroupMask", typeof(Int32));
  1004. createCol(prims, "EveryoneMask", typeof(Int32));
  1005. createCol(prims, "BaseMask", typeof(Int32));
  1006. // vectors
  1007. createCol(prims, "PositionX", typeof(Double));
  1008. createCol(prims, "PositionY", typeof(Double));
  1009. createCol(prims, "PositionZ", typeof(Double));
  1010. createCol(prims, "GroupPositionX", typeof(Double));
  1011. createCol(prims, "GroupPositionY", typeof(Double));
  1012. createCol(prims, "GroupPositionZ", typeof(Double));
  1013. createCol(prims, "VelocityX", typeof(Double));
  1014. createCol(prims, "VelocityY", typeof(Double));
  1015. createCol(prims, "VelocityZ", typeof(Double));
  1016. createCol(prims, "AngularVelocityX", typeof(Double));
  1017. createCol(prims, "AngularVelocityY", typeof(Double));
  1018. createCol(prims, "AngularVelocityZ", typeof(Double));
  1019. createCol(prims, "AccelerationX", typeof(Double));
  1020. createCol(prims, "AccelerationY", typeof(Double));
  1021. createCol(prims, "AccelerationZ", typeof(Double));
  1022. // quaternions
  1023. createCol(prims, "RotationX", typeof(Double));
  1024. createCol(prims, "RotationY", typeof(Double));
  1025. createCol(prims, "RotationZ", typeof(Double));
  1026. createCol(prims, "RotationW", typeof(Double));
  1027. // sit target
  1028. createCol(prims, "SitTargetOffsetX", typeof(Double));
  1029. createCol(prims, "SitTargetOffsetY", typeof(Double));
  1030. createCol(prims, "SitTargetOffsetZ", typeof(Double));
  1031. createCol(prims, "SitTargetOrientW", typeof(Double));
  1032. createCol(prims, "SitTargetOrientX", typeof(Double));
  1033. createCol(prims, "SitTargetOrientY", typeof(Double));
  1034. createCol(prims, "SitTargetOrientZ", typeof(Double));
  1035. createCol(prims, "PayPrice", typeof(Int32));
  1036. createCol(prims, "PayButton1", typeof(Int32));
  1037. createCol(prims, "PayButton2", typeof(Int32));
  1038. createCol(prims, "PayButton3", typeof(Int32));
  1039. createCol(prims, "PayButton4", typeof(Int32));
  1040. createCol(prims, "LoopedSound", typeof(String));
  1041. createCol(prims, "LoopedSoundGain", typeof(Double));
  1042. createCol(prims, "TextureAnimation", typeof(String));
  1043. createCol(prims, "ParticleSystem", typeof(String));
  1044. createCol(prims, "OmegaX", typeof(Double));
  1045. createCol(prims, "OmegaY", typeof(Double));
  1046. createCol(prims, "OmegaZ", typeof(Double));
  1047. createCol(prims, "CameraEyeOffsetX", typeof(Double));
  1048. createCol(prims, "CameraEyeOffsetY", typeof(Double));
  1049. createCol(prims, "CameraEyeOffsetZ", typeof(Double));
  1050. createCol(prims, "CameraAtOffsetX", typeof(Double));
  1051. createCol(prims, "CameraAtOffsetY", typeof(Double));
  1052. createCol(prims, "CameraAtOffsetZ", typeof(Double));
  1053. createCol(prims, "ForceMouselook", typeof(Int16));
  1054. createCol(prims, "ScriptAccessPin", typeof(Int32));
  1055. createCol(prims, "AllowedDrop", typeof(Int16));
  1056. createCol(prims, "DieAtEdge", typeof(Int16));
  1057. createCol(prims, "SalePrice", typeof(Int32));
  1058. createCol(prims, "SaleType", typeof(Int16));
  1059. // click action
  1060. createCol(prims, "ClickAction", typeof(Byte));
  1061. createCol(prims, "Material", typeof(Byte));
  1062. createCol(prims, "CollisionSound", typeof(String));
  1063. createCol(prims, "CollisionSoundVolume", typeof(Double));
  1064. createCol(prims, "VolumeDetect", typeof(Int16));
  1065. createCol(prims, "MediaURL", typeof(String));
  1066. createCol(prims, "AttachedPosX", typeof(Double));
  1067. createCol(prims, "AttachedPosY", typeof(Double));
  1068. createCol(prims, "AttachedPosZ", typeof(Double));
  1069. createCol(prims, "DynAttrs", typeof(String));
  1070. createCol(prims, "PhysicsShapeType", typeof(Byte));
  1071. createCol(prims, "Density", typeof(Double));
  1072. createCol(prims, "GravityModifier", typeof(Double));
  1073. createCol(prims, "Friction", typeof(Double));
  1074. createCol(prims, "Restitution", typeof(Double));
  1075. createCol(prims, "KeyframeMotion", typeof(Byte[]));
  1076. // Add in contraints
  1077. prims.PrimaryKey = new DataColumn[] { prims.Columns["UUID"] };
  1078. return prims;
  1079. }
  1080. /// <summary>
  1081. /// Creates "primshapes" table
  1082. /// </summary>
  1083. /// <returns>shape table DataTable</returns>
  1084. private static DataTable createShapeTable()
  1085. {
  1086. DataTable shapes = new DataTable("primshapes");
  1087. createCol(shapes, "UUID", typeof(String));
  1088. // shape is an enum
  1089. createCol(shapes, "Shape", typeof(Int32));
  1090. // vectors
  1091. createCol(shapes, "ScaleX", typeof(Double));
  1092. createCol(shapes, "ScaleY", typeof(Double));
  1093. createCol(shapes, "ScaleZ", typeof(Double));
  1094. // paths
  1095. createCol(shapes, "PCode", typeof(Int32));
  1096. createCol(shapes, "PathBegin", typeof(Int32));
  1097. createCol(shapes, "PathEnd", typeof(Int32));
  1098. createCol(shapes, "PathScaleX", typeof(Int32));
  1099. createCol(shapes, "PathScaleY", typeof(Int32));
  1100. createCol(shapes, "PathShearX", typeof(Int32));
  1101. createCol(shapes, "PathShearY", typeof(Int32));
  1102. createCol(shapes, "PathSkew", typeof(Int32));
  1103. createCol(shapes, "PathCurve", typeof(Int32));
  1104. createCol(shapes, "PathRadiusOffset", typeof(Int32));
  1105. createCol(shapes, "PathRevolutions", typeof(Int32));
  1106. createCol(shapes, "PathTaperX", typeof(Int32));
  1107. createCol(shapes, "PathTaperY", typeof(Int32));
  1108. createCol(shapes, "PathTwist", typeof(Int32));
  1109. createCol(shapes, "PathTwistBegin", typeof(Int32));
  1110. // profile
  1111. createCol(shapes, "ProfileBegin", typeof(Int32));
  1112. createCol(shapes, "ProfileEnd", typeof(Int32));
  1113. createCol(shapes, "ProfileCurve", typeof(Int32));
  1114. createCol(shapes, "ProfileHollow", typeof(Int32));
  1115. createCol(shapes, "State", typeof(Int32));
  1116. // text TODO: this isn't right, but I'm not sure the right
  1117. // way to specify this as a blob atm
  1118. createCol(shapes, "Texture", typeof(Byte[]));
  1119. createCol(shapes, "ExtraParams", typeof(Byte[]));
  1120. createCol(shapes, "Media", typeof(String));
  1121. shapes.PrimaryKey = new DataColumn[] { shapes.Columns["UUID"] };
  1122. return shapes;
  1123. }
  1124. /// <summary>
  1125. /// creates "primitems" table
  1126. /// </summary>
  1127. /// <returns>item table DataTable</returns>
  1128. private static DataTable createItemsTable()
  1129. {
  1130. DataTable items = new DataTable("primitems");
  1131. createCol(items, "itemID", typeof(String));
  1132. createCol(items, "primID", typeof(String));
  1133. createCol(items, "assetID", typeof(String));
  1134. createCol(items, "parentFolderID", typeof(String));
  1135. createCol(items, "invType", typeof(Int32));
  1136. createCol(items, "assetType", typeof(Int32));
  1137. createCol(items, "name", typeof(String));
  1138. createCol(items, "description", typeof(String));
  1139. createCol(items, "creationDate", typeof(Int64));
  1140. createCol(items, "creatorID", typeof(String));
  1141. createCol(items, "ownerID", typeof(String));
  1142. createCol(items, "lastOwnerID", typeof(String));
  1143. createCol(items, "groupID", typeof(String));
  1144. createCol(items, "nextPermissions", typeof(UInt32));
  1145. createCol(items, "currentPermissions", typeof(UInt32));
  1146. createCol(items, "basePermissions", typeof(UInt32));
  1147. createCol(items, "everyonePermissions", typeof(UInt32));
  1148. createCol(items, "groupPermissions", typeof(UInt32));
  1149. createCol(items, "flags", typeof(UInt32));
  1150. items.PrimaryKey = new DataColumn[] { items.Columns["itemID"] };
  1151. return items;
  1152. }
  1153. /// <summary>
  1154. /// Creates "land" table
  1155. /// </summary>
  1156. /// <returns>land table DataTable</returns>
  1157. private static DataTable createLandTable()
  1158. {
  1159. DataTable land = new DataTable("land");
  1160. createCol(land, "UUID", typeof(String));
  1161. createCol(land, "RegionUUID", typeof(String));
  1162. createCol(land, "LocalLandID", typeof(UInt32));
  1163. // Bitmap is a byte[512]
  1164. createCol(land, "Bitmap", typeof(Byte[]));
  1165. createCol(land, "Name", typeof(String));
  1166. createCol(land, "Desc", typeof(String));
  1167. createCol(land, "OwnerUUID", typeof(String));
  1168. createCol(land, "IsGroupOwned", typeof(Boolean));
  1169. createCol(land, "Area", typeof(Int32));
  1170. createCol(land, "AuctionID", typeof(Int32)); //Unemplemented
  1171. createCol(land, "Category", typeof(Int32)); //Enum OpenMetaverse.Parcel.ParcelCategory
  1172. createCol(land, "ClaimDate", typeof(Int32));
  1173. createCol(land, "ClaimPrice", typeof(Int32));
  1174. createCol(land, "GroupUUID", typeof(string));
  1175. createCol(land, "SalePrice", typeof(Int32));
  1176. createCol(land, "LandStatus", typeof(Int32)); //Enum. OpenMetaverse.Parcel.ParcelStatus
  1177. createCol(land, "LandFlags", typeof(UInt32));
  1178. createCol(land, "LandingType", typeof(Byte));
  1179. createCol(land, "MediaAutoScale", typeof(Byte));
  1180. createCol(land, "MediaTextureUUID", typeof(String));
  1181. createCol(land, "MediaURL", typeof(String));
  1182. createCol(land, "MusicURL", typeof(String));
  1183. createCol(land, "PassHours", typeof(Double));
  1184. createCol(land, "PassPrice", typeof(UInt32));
  1185. createCol(land, "SnapshotUUID", typeof(String));
  1186. createCol(land, "UserLocationX", typeof(Double));
  1187. createCol(land, "UserLocationY", typeof(Double));
  1188. createCol(land, "UserLocationZ", typeof(Double));
  1189. createCol(land, "UserLookAtX", typeof(Double));
  1190. createCol(land, "UserLookAtY", typeof(Double));
  1191. createCol(land, "UserLookAtZ", typeof(Double));
  1192. createCol(land, "AuthbuyerID", typeof(String));
  1193. createCol(land, "OtherCleanTime", typeof(Int32));
  1194. createCol(land, "Dwell", typeof(Int32));
  1195. createCol(land, "MediaType", typeof(String));
  1196. createCol(land, "MediaDescription", typeof(String));
  1197. createCol(land, "MediaSize", typeof(String));
  1198. createCol(land, "MediaLoop", typeof(Boolean));
  1199. createCol(land, "ObscureMedia", typeof(Boolean));
  1200. createCol(land, "ObscureMusic", typeof(Boolean));
  1201. land.PrimaryKey = new DataColumn[] { land.Columns["UUID"] };
  1202. return land;
  1203. }
  1204. /// <summary>
  1205. /// create "landaccesslist" table
  1206. /// </summary>
  1207. /// <returns>Landacceslist DataTable</returns>
  1208. private static DataTable createLandAccessListTable()
  1209. {
  1210. DataTable landaccess = new DataTable("landaccesslist");
  1211. createCol(landaccess, "LandUUID", typeof(String));
  1212. createCol(landaccess, "AccessUUID", typeof(String));
  1213. createCol(landaccess, "Flags", typeof(UInt32));
  1214. return landaccess;
  1215. }
  1216. private static DataTable createRegionSettingsTable()
  1217. {
  1218. DataTable regionsettings = new DataTable("regionsettings");
  1219. createCol(regionsettings, "regionUUID", typeof(String));
  1220. createCol(regionsettings, "block_terraform", typeof(Int32));
  1221. createCol(regionsettings, "block_fly", typeof(Int32));
  1222. createCol(regionsettings, "allow_damage", typeof(Int32));
  1223. createCol(regionsettings, "restrict_pushing", typeof(Int32));
  1224. createCol(regionsettings, "allow_land_resell", typeof(Int32));
  1225. createCol(regionsettings, "allow_land_join_divide", typeof(Int32));
  1226. createCol(regionsettings, "block_show_in_search", typeof(Int32));
  1227. createCol(regionsettings, "agent_limit", typeof(Int32));
  1228. createCol(regionsettings, "object_bonus", typeof(Double));
  1229. createCol(regionsettings, "maturity", typeof(Int32));
  1230. createCol(regionsettings, "disable_scripts", typeof(Int32));
  1231. createCol(regionsettings, "disable_collisions", typeof(Int32));
  1232. createCol(regionsettings, "disable_physics", typeof(Int32));
  1233. createCol(regionsettings, "terrain_texture_1", typeof(String));
  1234. createCol(regionsettings, "terrain_texture_2", typeof(String));
  1235. createCol(regionsettings, "terrain_texture_3", typeof(String));
  1236. createCol(regionsettings, "terrain_texture_4", typeof(String));
  1237. createCol(regionsettings, "elevation_1_nw", typeof(Double));
  1238. createCol(regionsettings, "elevation_2_nw", typeof(Double));
  1239. createCol(regionsettings, "elevation_1_ne", typeof(Double));
  1240. createCol(regionsettings, "elevation_2_ne", typeof(Double));
  1241. createCol(regionsettings, "elevation_1_se", typeof(Double));
  1242. createCol(regionsettings, "elevation_2_se", typeof(Double));
  1243. createCol(regionsettings, "elevation_1_sw", typeof(Double));
  1244. createCol(regionsettings, "elevation_2_sw", typeof(Double));
  1245. createCol(regionsettings, "water_height", typeof(Double));
  1246. createCol(regionsettings, "terrain_raise_limit", typeof(Double));
  1247. createCol(regionsettings, "terrain_lower_limit", typeof(Double));
  1248. createCol(regionsettings, "use_estate_sun", typeof(Int32));
  1249. createCol(regionsettings, "sandbox", typeof(Int32));
  1250. createCol(regionsettings, "sunvectorx", typeof(Double));
  1251. createCol(regionsettings, "sunvectory", typeof(Double));
  1252. createCol(regionsettings, "sunvectorz", typeof(Double));
  1253. createCol(regionsettings, "fixed_sun", typeof(Int32));
  1254. createCol(regionsettings, "sun_position", typeof(Double));
  1255. createCol(regionsettings, "covenant", typeof(String));
  1256. createCol(regionsettings, "covenant_datetime", typeof(Int32));
  1257. createCol(regionsettings, "map_tile_ID", typeof(String));
  1258. createCol(regionsettings, "TelehubObject", typeof(String));
  1259. createCol(regionsettings, "parcel_tile_ID", typeof(String));
  1260. regionsettings.PrimaryKey = new DataColumn[] { regionsettings.Columns["regionUUID"] };
  1261. return regionsettings;
  1262. }
  1263. /// <summary>
  1264. /// create "regionwindlight" table
  1265. /// </summary>
  1266. /// <returns>RegionWindlight DataTable</returns>
  1267. private static DataTable createRegionWindlightTable()
  1268. {
  1269. DataTable regionwindlight = new DataTable("regionwindlight");
  1270. createCol(regionwindlight, "region_id", typeof(String));
  1271. createCol(regionwindlight, "water_color_r", typeof(Double));
  1272. createCol(regionwindlight, "water_color_g", typeof(Double));
  1273. createCol(regionwindlight, "water_color_b", typeof(Double));
  1274. createCol(regionwindlight, "water_color_i", typeof(Double));
  1275. createCol(regionwindlight, "water_fog_density_exponent", typeof(Double));
  1276. createCol(regionwindlight, "underwater_fog_modifier", typeof(Double));
  1277. createCol(regionwindlight, "reflection_wavelet_scale_1", typeof(Double));
  1278. createCol(regionwindlight, "reflection_wavelet_scale_2", typeof(Double));
  1279. createCol(regionwindlight, "reflection_wavelet_scale_3", typeof(Double));
  1280. createCol(regionwindlight, "fresnel_scale", typeof(Double));
  1281. createCol(regionwindlight, "fresnel_offset", typeof(Double));
  1282. createCol(regionwindlight, "refract_scale_above", typeof(Double));
  1283. createCol(regionwindlight, "refract_scale_below", typeof(Double));
  1284. createCol(regionwindlight, "blur_multiplier", typeof(Double));
  1285. createCol(regionwindlight, "big_wave_direction_x", typeof(Double));
  1286. createCol(regionwindlight, "big_wave_direction_y", typeof(Double));
  1287. createCol(regionwindlight, "little_wave_direction_x", typeof(Double));
  1288. createCol(regionwindlight, "little_wave_direction_y", typeof(Double));
  1289. createCol(regionwindlight, "normal_map_texture", typeof(String));
  1290. createCol(regionwindlight, "horizon_r", typeof(Double));
  1291. createCol(regionwindlight, "horizon_g", typeof(Double));
  1292. createCol(regionwindlight, "horizon_b", typeof(Double));
  1293. createCol(regionwindlight, "horizon_i", typeof(Double));
  1294. createCol(regionwindlight, "haze_horizon", typeof(Double));
  1295. createCol(regionwindlight, "blue_density_r", typeof(Double));
  1296. createCol(regionwindlight, "blue_density_g", typeof(Double));
  1297. createCol(regionwindlight, "blue_density_b", typeof(Double));
  1298. createCol(regionwindlight, "blue_density_i", typeof(Double));
  1299. createCol(regionwindlight, "haze_density", typeof(Double));
  1300. createCol(regionwindlight, "density_multiplier", typeof(Double));
  1301. createCol(regionwindlight, "distance_multiplier", typeof(Double));
  1302. createCol(regionwindlight, "max_altitude", typeof(Int32));
  1303. createCol(regionwindlight, "sun_moon_color_r", typeof(Double));
  1304. createCol(regionwindlight, "sun_moon_color_g", typeof(Double));
  1305. createCol(regionwindlight, "sun_moon_color_b", typeof(Double));
  1306. createCol(regionwindlight, "sun_moon_color_i", typeof(Double));
  1307. createCol(regionwindlight, "sun_moon_position", typeof(Double));
  1308. createCol(regionwindlight, "ambient_r", typeof(Double));
  1309. createCol(regionwindlight, "ambient_g", typeof(Double));
  1310. createCol(regionwindlight, "ambient_b", typeof(Double));
  1311. createCol(regionwindlight, "ambient_i", typeof(Double));
  1312. createCol(regionwindlight, "east_angle", typeof(Double));
  1313. createCol(regionwindlight, "sun_glow_focus", typeof(Double));
  1314. createCol(regionwindlight, "sun_glow_size", typeof(Double));
  1315. createCol(regionwindlight, "scene_gamma", typeof(Double));
  1316. createCol(regionwindlight, "star_brightness", typeof(Double));
  1317. createCol(regionwindlight, "cloud_color_r", typeof(Double));
  1318. createCol(regionwindlight, "cloud_color_g", typeof(Double));
  1319. createCol(regionwindlight, "cloud_color_b", typeof(Double));
  1320. createCol(regionwindlight, "cloud_color_i", typeof(Double));
  1321. createCol(regionwindlight, "cloud_x", typeof(Double));
  1322. createCol(regionwindlight, "cloud_y", typeof(Double));
  1323. createCol(regionwindlight, "cloud_density", typeof(Double));
  1324. createCol(regionwindlight, "cloud_coverage", typeof(Double));
  1325. createCol(regionwindlight, "cloud_scale", typeof(Double));
  1326. createCol(regionwindlight, "cloud_detail_x", typeof(Double));
  1327. createCol(regionwindlight, "cloud_detail_y", typeof(Double));
  1328. createCol(regionwindlight, "cloud_detail_density", typeof(Double));
  1329. createCol(regionwindlight, "cloud_scroll_x", typeof(Double));
  1330. createCol(regionwindlight, "cloud_scroll_x_lock", typeof(Int32));
  1331. createCol(regionwindlight, "cloud_scroll_y", typeof(Double));
  1332. createCol(regionwindlight, "cloud_scroll_y_lock", typeof(Int32));
  1333. createCol(regionwindlight, "draw_classic_clouds", typeof(Int32));
  1334. regionwindlight.PrimaryKey = new DataColumn[] { regionwindlight.Columns["region_id"] };
  1335. return regionwindlight;
  1336. }
  1337. private static DataTable createRegionEnvironmentTable()
  1338. {
  1339. DataTable regionEnvironment = new DataTable("regionenvironment");
  1340. createCol(regionEnvironment, "region_id", typeof(String));
  1341. createCol(regionEnvironment, "llsd_settings", typeof(String));
  1342. regionEnvironment.PrimaryKey = new DataColumn[] { regionEnvironment.Columns["region_id"] };
  1343. return regionEnvironment;
  1344. }
  1345. private static DataTable createRegionSpawnPointsTable()
  1346. {
  1347. DataTable spawn_points = new DataTable("spawn_points");
  1348. createCol(spawn_points, "regionID", typeof(String));
  1349. createCol(spawn_points, "Yaw", typeof(float));
  1350. createCol(spawn_points, "Pitch", typeof(float));
  1351. createCol(spawn_points, "Distance", typeof(float));
  1352. return spawn_points;
  1353. }
  1354. /***********************************************************************
  1355. *
  1356. * Convert between ADO.NET <=> OpenSim Objects
  1357. *
  1358. * These should be database independant
  1359. *
  1360. **********************************************************************/
  1361. /// <summary>
  1362. ///
  1363. /// </summary>
  1364. /// <param name="row"></param>
  1365. /// <returns></returns>
  1366. private SceneObjectPart buildPrim(DataRow row)
  1367. {
  1368. // Code commented. Uncomment to test the unit test inline.
  1369. // The unit test mentions this commented code for the purposes
  1370. // of debugging a unit test failure
  1371. // SceneObjectGroup sog = new SceneObjectGroup();
  1372. // SceneObjectPart sop = new SceneObjectPart();
  1373. // sop.LocalId = 1;
  1374. // sop.Name = "object1";
  1375. // sop.Description = "object1";
  1376. // sop.Text = "";
  1377. // sop.SitName = "";
  1378. // sop.TouchName = "";
  1379. // sop.UUID = UUID.Random();
  1380. // sop.Shape = PrimitiveBaseShape.Default;
  1381. // sog.SetRootPart(sop);
  1382. // Add breakpoint in above line. Check sop fields.
  1383. // TODO: this doesn't work yet because something more
  1384. // interesting has to be done to actually get these values
  1385. // back out. Not enough time to figure it out yet.
  1386. SceneObjectPart prim = new SceneObjectPart();
  1387. prim.UUID = new UUID((String)row["UUID"]);
  1388. // explicit conversion of integers is required, which sort
  1389. // of sucks. No idea if there is a shortcut here or not.
  1390. prim.CreationDate = Convert.ToInt32(row["CreationDate"]);
  1391. prim.Name = row["Name"] == DBNull.Value ? string.Empty : (string)row["Name"];
  1392. // various text fields
  1393. prim.Text = (String)row["Text"];
  1394. prim.Color = Color.FromArgb(Convert.ToInt32(row["ColorA"]),
  1395. Convert.ToInt32(row["ColorR"]),
  1396. Convert.ToInt32(row["ColorG"]),
  1397. Convert.ToInt32(row["ColorB"]));
  1398. prim.Description = (String)row["Description"];
  1399. prim.SitName = (String)row["SitName"];
  1400. prim.TouchName = (String)row["TouchName"];
  1401. // permissions
  1402. prim.Flags = (PrimFlags)Convert.ToUInt32(row["ObjectFlags"]);
  1403. prim.CreatorIdentification = (String)row["CreatorID"];
  1404. prim.OwnerID = new UUID((String)row["OwnerID"]);
  1405. prim.GroupID = new UUID((String)row["GroupID"]);
  1406. prim.LastOwnerID = new UUID((String)row["LastOwnerID"]);
  1407. prim.OwnerMask = Convert.ToUInt32(row["OwnerMask"]);
  1408. prim.NextOwnerMask = Convert.ToUInt32(row["NextOwnerMask"]);
  1409. prim.GroupMask = Convert.ToUInt32(row["GroupMask"]);
  1410. prim.EveryoneMask = Convert.ToUInt32(row["EveryoneMask"]);
  1411. prim.BaseMask = Convert.ToUInt32(row["BaseMask"]);
  1412. // vectors
  1413. prim.OffsetPosition = new Vector3(
  1414. Convert.ToSingle(row["PositionX"]),
  1415. Convert.ToSingle(row["PositionY"]),
  1416. Convert.ToSingle(row["PositionZ"])
  1417. );
  1418. prim.GroupPosition = new Vector3(
  1419. Convert.ToSingle(row["GroupPositionX"]),
  1420. Convert.ToSingle(row["GroupPositionY"]),
  1421. Convert.ToSingle(row["GroupPositionZ"])
  1422. );
  1423. prim.Velocity = new Vector3(
  1424. Convert.ToSingle(row["VelocityX"]),
  1425. Convert.ToSingle(row["VelocityY"]),
  1426. Convert.ToSingle(row["VelocityZ"])
  1427. );
  1428. prim.AngularVelocity = new Vector3(
  1429. Convert.ToSingle(row["AngularVelocityX"]),
  1430. Convert.ToSingle(row["AngularVelocityY"]),
  1431. Convert.ToSingle(row["AngularVelocityZ"])
  1432. );
  1433. prim.Acceleration = new Vector3(
  1434. Convert.ToSingle(row["AccelerationX"]),
  1435. Convert.ToSingle(row["AccelerationY"]),
  1436. Convert.ToSingle(row["AccelerationZ"])
  1437. );
  1438. // quaternions
  1439. prim.RotationOffset = new Quaternion(
  1440. Convert.ToSingle(row["RotationX"]),
  1441. Convert.ToSingle(row["RotationY"]),
  1442. Convert.ToSingle(row["RotationZ"]),
  1443. Convert.ToSingle(row["RotationW"])
  1444. );
  1445. prim.SitTargetPositionLL = new Vector3(
  1446. Convert.ToSingle(row["SitTargetOffsetX"]),
  1447. Convert.ToSingle(row["SitTargetOffsetY"]),
  1448. Convert.ToSingle(row["SitTargetOffsetZ"]));
  1449. prim.SitTargetOrientationLL = new Quaternion(
  1450. Convert.ToSingle(
  1451. row["SitTargetOrientX"]),
  1452. Convert.ToSingle(
  1453. row["SitTargetOrientY"]),
  1454. Convert.ToSingle(
  1455. row["SitTargetOrientZ"]),
  1456. Convert.ToSingle(
  1457. row["SitTargetOrientW"]));
  1458. prim.ClickAction = Convert.ToByte(row["ClickAction"]);
  1459. prim.PayPrice[0] = Convert.ToInt32(row["PayPrice"]);
  1460. prim.PayPrice[1] = Convert.ToInt32(row["PayButton1"]);
  1461. prim.PayPrice[2] = Convert.ToInt32(row["PayButton2"]);
  1462. prim.PayPrice[3] = Convert.ToInt32(row["PayButton3"]);
  1463. prim.PayPrice[4] = Convert.ToInt32(row["PayButton4"]);
  1464. prim.Sound = new UUID(row["LoopedSound"].ToString());
  1465. prim.SoundGain = Convert.ToSingle(row["LoopedSoundGain"]);
  1466. prim.SoundFlags = 1; // If it's persisted at all, it's looped
  1467. if (!row.IsNull("TextureAnimation"))
  1468. prim.TextureAnimation = Convert.FromBase64String(row["TextureAnimation"].ToString());
  1469. if (!row.IsNull("ParticleSystem"))
  1470. prim.ParticleSystem = Convert.FromBase64String(row["ParticleSystem"].ToString());
  1471. prim.AngularVelocity = new Vector3(
  1472. Convert.ToSingle(row["OmegaX"]),
  1473. Convert.ToSingle(row["OmegaY"]),
  1474. Convert.ToSingle(row["OmegaZ"])
  1475. );
  1476. prim.SetCameraEyeOffset(new Vector3(
  1477. Convert.ToSingle(row["CameraEyeOffsetX"]),
  1478. Convert.ToSingle(row["CameraEyeOffsetY"]),
  1479. Convert.ToSingle(row["CameraEyeOffsetZ"])
  1480. ));
  1481. prim.SetCameraAtOffset(new Vector3(
  1482. Convert.ToSingle(row["CameraAtOffsetX"]),
  1483. Convert.ToSingle(row["CameraAtOffsetY"]),
  1484. Convert.ToSingle(row["CameraAtOffsetZ"])
  1485. ));
  1486. if (Convert.ToInt16(row["ForceMouselook"]) != 0)
  1487. prim.SetForceMouselook(true);
  1488. prim.ScriptAccessPin = Convert.ToInt32(row["ScriptAccessPin"]);
  1489. if (Convert.ToInt16(row["AllowedDrop"]) != 0)
  1490. prim.AllowedDrop = true;
  1491. if (Convert.ToInt16(row["DieAtEdge"]) != 0)
  1492. prim.DIE_AT_EDGE = true;
  1493. prim.SalePrice = Convert.ToInt32(row["SalePrice"]);
  1494. prim.ObjectSaleType = Convert.ToByte(row["SaleType"]);
  1495. prim.Material = Convert.ToByte(row["Material"]);
  1496. prim.CollisionSound = new UUID(row["CollisionSound"].ToString());
  1497. prim.CollisionSoundVolume = Convert.ToSingle(row["CollisionSoundVolume"]);
  1498. if (Convert.ToInt16(row["VolumeDetect"]) != 0)
  1499. prim.VolumeDetectActive = true;
  1500. if (!(row["MediaURL"] is System.DBNull))
  1501. {
  1502. // m_log.DebugFormat("[SQLITE]: MediaUrl type [{0}]", row["MediaURL"].GetType());
  1503. prim.MediaUrl = (string)row["MediaURL"];
  1504. }
  1505. prim.AttachedPos = new Vector3(
  1506. Convert.ToSingle(row["AttachedPosX"]),
  1507. Convert.ToSingle(row["AttachedPosY"]),
  1508. Convert.ToSingle(row["AttachedPosZ"])
  1509. );
  1510. if (!(row["DynAttrs"] is System.DBNull))
  1511. {
  1512. //m_log.DebugFormat("[SQLITE]: DynAttrs type [{0}]", row["DynAttrs"].GetType());
  1513. prim.DynAttrs = DAMap.FromXml((string)row["DynAttrs"]);
  1514. }
  1515. else
  1516. {
  1517. prim.DynAttrs = new DAMap();
  1518. }
  1519. prim.PhysicsShapeType = Convert.ToByte(row["PhysicsShapeType"]);
  1520. prim.Density = Convert.ToSingle(row["Density"]);
  1521. prim.GravityModifier = Convert.ToSingle(row["GravityModifier"]);
  1522. prim.Friction = Convert.ToSingle(row["Friction"]);
  1523. prim.Restitution = Convert.ToSingle(row["Restitution"]);
  1524. if (!(row["KeyframeMotion"] is DBNull))
  1525. {
  1526. Byte[] data = (byte[])row["KeyframeMotion"];
  1527. if (data.Length > 0)
  1528. prim.KeyframeMotion = KeyframeMotion.FromData(null, data);
  1529. else
  1530. prim.KeyframeMotion = null;
  1531. }
  1532. else
  1533. {
  1534. prim.KeyframeMotion = null;
  1535. }
  1536. return prim;
  1537. }
  1538. /// <summary>
  1539. /// Build a prim inventory item from the persisted data.
  1540. /// </summary>
  1541. /// <param name="row"></param>
  1542. /// <returns></returns>
  1543. private static TaskInventoryItem buildItem(DataRow row)
  1544. {
  1545. TaskInventoryItem taskItem = new TaskInventoryItem();
  1546. taskItem.ItemID = new UUID((String)row["itemID"]);
  1547. taskItem.ParentPartID = new UUID((String)row["primID"]);
  1548. taskItem.AssetID = new UUID((String)row["assetID"]);
  1549. taskItem.ParentID = new UUID((String)row["parentFolderID"]);
  1550. taskItem.InvType = Convert.ToInt32(row["invType"]);
  1551. taskItem.Type = Convert.ToInt32(row["assetType"]);
  1552. taskItem.Name = (String)row["name"];
  1553. taskItem.Description = (String)row["description"];
  1554. taskItem.CreationDate = Convert.ToUInt32(row["creationDate"]);
  1555. taskItem.CreatorIdentification = (String)row["creatorID"];
  1556. taskItem.OwnerID = new UUID((String)row["ownerID"]);
  1557. taskItem.LastOwnerID = new UUID((String)row["lastOwnerID"]);
  1558. taskItem.GroupID = new UUID((String)row["groupID"]);
  1559. taskItem.NextPermissions = Convert.ToUInt32(row["nextPermissions"]);
  1560. taskItem.CurrentPermissions = Convert.ToUInt32(row["currentPermissions"]);
  1561. taskItem.BasePermissions = Convert.ToUInt32(row["basePermissions"]);
  1562. taskItem.EveryonePermissions = Convert.ToUInt32(row["everyonePermissions"]);
  1563. taskItem.GroupPermissions = Convert.ToUInt32(row["groupPermissions"]);
  1564. taskItem.Flags = Convert.ToUInt32(row["flags"]);
  1565. return taskItem;
  1566. }
  1567. /// <summary>
  1568. /// Build a Land Data from the persisted data.
  1569. /// </summary>
  1570. /// <param name="row"></param>
  1571. /// <returns></returns>
  1572. private LandData buildLandData(DataRow row)
  1573. {
  1574. LandData newData = new LandData();
  1575. newData.GlobalID = new UUID((String)row["UUID"]);
  1576. newData.LocalID = Convert.ToInt32(row["LocalLandID"]);
  1577. // Bitmap is a byte[512]
  1578. newData.Bitmap = (Byte[])row["Bitmap"];
  1579. newData.Name = (String)row["Name"];
  1580. newData.Description = (String)row["Desc"];
  1581. newData.OwnerID = (UUID)(String)row["OwnerUUID"];
  1582. newData.IsGroupOwned = (Boolean)row["IsGroupOwned"];
  1583. newData.Area = Convert.ToInt32(row["Area"]);
  1584. newData.AuctionID = Convert.ToUInt32(row["AuctionID"]); //Unemplemented
  1585. newData.Category = (ParcelCategory)Convert.ToInt32(row["Category"]);
  1586. //Enum OpenMetaverse.Parcel.ParcelCategory
  1587. newData.ClaimDate = Convert.ToInt32(row["ClaimDate"]);
  1588. newData.ClaimPrice = Convert.ToInt32(row["ClaimPrice"]);
  1589. newData.GroupID = new UUID((String)row["GroupUUID"]);
  1590. newData.SalePrice = Convert.ToInt32(row["SalePrice"]);
  1591. newData.Status = (ParcelStatus)Convert.ToInt32(row["LandStatus"]);
  1592. //Enum. OpenMetaverse.Parcel.ParcelStatus
  1593. newData.Flags = Convert.ToUInt32(row["LandFlags"]);
  1594. newData.LandingType = (Byte)row["LandingType"];
  1595. newData.MediaAutoScale = (Byte)row["MediaAutoScale"];
  1596. newData.MediaID = new UUID((String)row["MediaTextureUUID"]);
  1597. newData.MediaURL = (String)row["MediaURL"];
  1598. newData.MusicURL = (String)row["MusicURL"];
  1599. newData.PassHours = Convert.ToSingle(row["PassHours"]);
  1600. newData.PassPrice = Convert.ToInt32(row["PassPrice"]);
  1601. newData.SnapshotID = (UUID)(String)row["SnapshotUUID"];
  1602. newData.Dwell = Convert.ToInt32(row["Dwell"]);
  1603. newData.MediaType = (String)row["MediaType"];
  1604. newData.MediaDescription = (String)row["MediaDescription"];
  1605. newData.MediaWidth = Convert.ToInt32((((string)row["MediaSize"]).Split(','))[0]);
  1606. newData.MediaHeight = Convert.ToInt32((((string)row["MediaSize"]).Split(','))[1]);
  1607. newData.MediaLoop = Convert.ToBoolean(row["MediaLoop"]);
  1608. newData.ObscureMedia = Convert.ToBoolean(row["ObscureMedia"]);
  1609. newData.ObscureMusic = Convert.ToBoolean(row["ObscureMusic"]);
  1610. try
  1611. {
  1612. newData.UserLocation =
  1613. new Vector3(Convert.ToSingle(row["UserLocationX"]), Convert.ToSingle(row["UserLocationY"]),
  1614. Convert.ToSingle(row["UserLocationZ"]));
  1615. newData.UserLookAt =
  1616. new Vector3(Convert.ToSingle(row["UserLookAtX"]), Convert.ToSingle(row["UserLookAtY"]),
  1617. Convert.ToSingle(row["UserLookAtZ"]));
  1618. }
  1619. catch (InvalidCastException)
  1620. {
  1621. m_log.ErrorFormat("[SQLITE REGION DB]: unable to get parcel telehub settings for {1}", newData.Name);
  1622. newData.UserLocation = Vector3.Zero;
  1623. newData.UserLookAt = Vector3.Zero;
  1624. }
  1625. newData.ParcelAccessList = new List<LandAccessEntry>();
  1626. UUID authBuyerID = UUID.Zero;
  1627. UUID.TryParse((string)row["AuthbuyerID"], out authBuyerID);
  1628. newData.OtherCleanTime = Convert.ToInt32(row["OtherCleanTime"]);
  1629. return newData;
  1630. }
  1631. private RegionSettings buildRegionSettings(DataRow row)
  1632. {
  1633. RegionSettings newSettings = new RegionSettings();
  1634. newSettings.RegionUUID = new UUID((string)row["regionUUID"]);
  1635. newSettings.BlockTerraform = Convert.ToBoolean(row["block_terraform"]);
  1636. newSettings.AllowDamage = Convert.ToBoolean(row["allow_damage"]);
  1637. newSettings.BlockFly = Convert.ToBoolean(row["block_fly"]);
  1638. newSettings.RestrictPushing = Convert.ToBoolean(row["restrict_pushing"]);
  1639. newSettings.AllowLandResell = Convert.ToBoolean(row["allow_land_resell"]);
  1640. newSettings.AllowLandJoinDivide = Convert.ToBoolean(row["allow_land_join_divide"]);
  1641. newSettings.BlockShowInSearch = Convert.ToBoolean(row["block_show_in_search"]);
  1642. newSettings.AgentLimit = Convert.ToInt32(row["agent_limit"]);
  1643. newSettings.ObjectBonus = Convert.ToDouble(row["object_bonus"]);
  1644. newSettings.Maturity = Convert.ToInt32(row["maturity"]);
  1645. newSettings.DisableScripts = Convert.ToBoolean(row["disable_scripts"]);
  1646. newSettings.DisableCollisions = Convert.ToBoolean(row["disable_collisions"]);
  1647. newSettings.DisablePhysics = Convert.ToBoolean(row["disable_physics"]);
  1648. newSettings.TerrainTexture1 = new UUID((String)row["terrain_texture_1"]);
  1649. newSettings.TerrainTexture2 = new UUID((String)row["terrain_texture_2"]);
  1650. newSettings.TerrainTexture3 = new UUID((String)row["terrain_texture_3"]);
  1651. newSettings.TerrainTexture4 = new UUID((String)row["terrain_texture_4"]);
  1652. newSettings.Elevation1NW = Convert.ToDouble(row["elevation_1_nw"]);
  1653. newSettings.Elevation2NW = Convert.ToDouble(row["elevation_2_nw"]);
  1654. newSettings.Elevation1NE = Convert.ToDouble(row["elevation_1_ne"]);
  1655. newSettings.Elevation2NE = Convert.ToDouble(row["elevation_2_ne"]);
  1656. newSettings.Elevation1SE = Convert.ToDouble(row["elevation_1_se"]);
  1657. newSettings.Elevation2SE = Convert.ToDouble(row["elevation_2_se"]);
  1658. newSettings.Elevation1SW = Convert.ToDouble(row["elevation_1_sw"]);
  1659. newSettings.Elevation2SW = Convert.ToDouble(row["elevation_2_sw"]);
  1660. newSettings.WaterHeight = Convert.ToDouble(row["water_height"]);
  1661. newSettings.TerrainRaiseLimit = Convert.ToDouble(row["terrain_raise_limit"]);
  1662. newSettings.TerrainLowerLimit = Convert.ToDouble(row["terrain_lower_limit"]);
  1663. newSettings.UseEstateSun = Convert.ToBoolean(row["use_estate_sun"]);
  1664. newSettings.Sandbox = Convert.ToBoolean(row["sandbox"]);
  1665. newSettings.SunVector = new Vector3(
  1666. Convert.ToSingle(row["sunvectorx"]),
  1667. Convert.ToSingle(row["sunvectory"]),
  1668. Convert.ToSingle(row["sunvectorz"])
  1669. );
  1670. newSettings.FixedSun = Convert.ToBoolean(row["fixed_sun"]);
  1671. newSettings.SunPosition = Convert.ToDouble(row["sun_position"]);
  1672. newSettings.Covenant = new UUID((String)row["covenant"]);
  1673. newSettings.CovenantChangedDateTime = Convert.ToInt32(row["covenant_datetime"]);
  1674. newSettings.TerrainImageID = new UUID((String)row["map_tile_ID"]);
  1675. newSettings.TelehubObject = new UUID((String)row["TelehubObject"]);
  1676. newSettings.ParcelImageID = new UUID((String)row["parcel_tile_ID"]);
  1677. return newSettings;
  1678. }
  1679. /// <summary>
  1680. /// Build a windlight entry from the persisted data.
  1681. /// </summary>
  1682. /// <param name="row"></param>
  1683. /// <returns>RegionLightShareData</returns>
  1684. private RegionLightShareData buildRegionWindlight(DataRow row)
  1685. {
  1686. RegionLightShareData windlight = new RegionLightShareData();
  1687. windlight.regionID = new UUID((string)row["region_id"]);
  1688. windlight.waterColor.X = Convert.ToSingle(row["water_color_r"]);
  1689. windlight.waterColor.Y = Convert.ToSingle(row["water_color_g"]);
  1690. windlight.waterColor.Z = Convert.ToSingle(row["water_color_b"]);
  1691. //windlight.waterColor.W = Convert.ToSingle(row["water_color_i"]); //not implemented
  1692. windlight.waterFogDensityExponent = Convert.ToSingle(row["water_fog_density_exponent"]);
  1693. windlight.underwaterFogModifier = Convert.ToSingle(row["underwater_fog_modifier"]);
  1694. windlight.reflectionWaveletScale.X = Convert.ToSingle(row["reflection_wavelet_scale_1"]);
  1695. windlight.reflectionWaveletScale.Y = Convert.ToSingle(row["reflection_wavelet_scale_2"]);
  1696. windlight.reflectionWaveletScale.Z = Convert.ToSingle(row["reflection_wavelet_scale_3"]);
  1697. windlight.fresnelScale = Convert.ToSingle(row["fresnel_scale"]);
  1698. windlight.fresnelOffset = Convert.ToSingle(row["fresnel_offset"]);
  1699. windlight.refractScaleAbove = Convert.ToSingle(row["refract_scale_above"]);
  1700. windlight.refractScaleBelow = Convert.ToSingle(row["refract_scale_below"]);
  1701. windlight.blurMultiplier = Convert.ToSingle(row["blur_multiplier"]);
  1702. windlight.bigWaveDirection.X = Convert.ToSingle(row["big_wave_direction_x"]);
  1703. windlight.bigWaveDirection.Y = Convert.ToSingle(row["big_wave_direction_y"]);
  1704. windlight.littleWaveDirection.X = Convert.ToSingle(row["little_wave_direction_x"]);
  1705. windlight.littleWaveDirection.Y = Convert.ToSingle(row["little_wave_direction_y"]);
  1706. windlight.normalMapTexture = new UUID((string)row["normal_map_texture"]);
  1707. windlight.horizon.X = Convert.ToSingle(row["horizon_r"]);
  1708. windlight.horizon.Y = Convert.ToSingle(row["horizon_g"]);
  1709. windlight.horizon.Z = Convert.ToSingle(row["horizon_b"]);
  1710. windlight.horizon.W = Convert.ToSingle(row["horizon_i"]);
  1711. windlight.hazeHorizon = Convert.ToSingle(row["haze_horizon"]);
  1712. windlight.blueDensity.X = Convert.ToSingle(row["blue_density_r"]);
  1713. windlight.blueDensity.Y = Convert.ToSingle(row["blue_density_g"]);
  1714. windlight.blueDensity.Z = Convert.ToSingle(row["blue_density_b"]);
  1715. windlight.blueDensity.W = Convert.ToSingle(row["blue_density_i"]);
  1716. windlight.hazeDensity = Convert.ToSingle(row["haze_density"]);
  1717. windlight.densityMultiplier = Convert.ToSingle(row["density_multiplier"]);
  1718. windlight.distanceMultiplier = Convert.ToSingle(row["distance_multiplier"]);
  1719. windlight.maxAltitude = Convert.ToUInt16(row["max_altitude"]);
  1720. windlight.sunMoonColor.X = Convert.ToSingle(row["sun_moon_color_r"]);
  1721. windlight.sunMoonColor.Y = Convert.ToSingle(row["sun_moon_color_g"]);
  1722. windlight.sunMoonColor.Z = Convert.ToSingle(row["sun_moon_color_b"]);
  1723. windlight.sunMoonColor.W = Convert.ToSingle(row["sun_moon_color_i"]);
  1724. windlight.sunMoonPosition = Convert.ToSingle(row["sun_moon_position"]);
  1725. windlight.ambient.X = Convert.ToSingle(row["ambient_r"]);
  1726. windlight.ambient.Y = Convert.ToSingle(row["ambient_g"]);
  1727. windlight.ambient.Z = Convert.ToSingle(row["ambient_b"]);
  1728. windlight.ambient.W = Convert.ToSingle(row["ambient_i"]);
  1729. windlight.eastAngle = Convert.ToSingle(row["east_angle"]);
  1730. windlight.sunGlowFocus = Convert.ToSingle(row["sun_glow_focus"]);
  1731. windlight.sunGlowSize = Convert.ToSingle(row["sun_glow_size"]);
  1732. windlight.sceneGamma = Convert.ToSingle(row["scene_gamma"]);
  1733. windlight.starBrightness = Convert.ToSingle(row["star_brightness"]);
  1734. windlight.cloudColor.X = Convert.ToSingle(row["cloud_color_r"]);
  1735. windlight.cloudColor.Y = Convert.ToSingle(row["cloud_color_g"]);
  1736. windlight.cloudColor.Z = Convert.ToSingle(row["cloud_color_b"]);
  1737. windlight.cloudColor.W = Convert.ToSingle(row["cloud_color_i"]);
  1738. windlight.cloudXYDensity.X = Convert.ToSingle(row["cloud_x"]);
  1739. windlight.cloudXYDensity.Y = Convert.ToSingle(row["cloud_y"]);
  1740. windlight.cloudXYDensity.Z = Convert.ToSingle(row["cloud_density"]);
  1741. windlight.cloudCoverage = Convert.ToSingle(row["cloud_coverage"]);
  1742. windlight.cloudScale = Convert.ToSingle(row["cloud_scale"]);
  1743. windlight.cloudDetailXYDensity.X = Convert.ToSingle(row["cloud_detail_x"]);
  1744. windlight.cloudDetailXYDensity.Y = Convert.ToSingle(row["cloud_detail_y"]);
  1745. windlight.cloudDetailXYDensity.Z = Convert.ToSingle(row["cloud_detail_density"]);
  1746. windlight.cloudScrollX = Convert.ToSingle(row["cloud_scroll_x"]);
  1747. windlight.cloudScrollXLock = Convert.ToBoolean(row["cloud_scroll_x_lock"]);
  1748. windlight.cloudScrollY = Convert.ToSingle(row["cloud_scroll_y"]);
  1749. windlight.cloudScrollYLock = Convert.ToBoolean(row["cloud_scroll_y_lock"]);
  1750. windlight.drawClassicClouds = Convert.ToBoolean(row["draw_classic_clouds"]);
  1751. return windlight;
  1752. }
  1753. /// <summary>
  1754. /// Build a land access entry from the persisted data.
  1755. /// </summary>
  1756. /// <param name="row"></param>
  1757. /// <returns></returns>
  1758. private static LandAccessEntry buildLandAccessData(DataRow row)
  1759. {
  1760. LandAccessEntry entry = new LandAccessEntry();
  1761. entry.AgentID = new UUID((string)row["AccessUUID"]);
  1762. entry.Flags = (AccessList)row["Flags"];
  1763. entry.Expires = 0;
  1764. return entry;
  1765. }
  1766. /// <summary>
  1767. ///
  1768. /// </summary>
  1769. /// <param name="row"></param>
  1770. /// <param name="prim"></param>
  1771. /// <param name="sceneGroupID"></param>
  1772. /// <param name="regionUUID"></param>
  1773. private static void fillPrimRow(DataRow row, SceneObjectPart prim, UUID sceneGroupID, UUID regionUUID)
  1774. {
  1775. row["UUID"] = prim.UUID.ToString();
  1776. row["RegionUUID"] = regionUUID.ToString();
  1777. row["CreationDate"] = prim.CreationDate;
  1778. row["Name"] = prim.Name;
  1779. row["SceneGroupID"] = sceneGroupID.ToString();
  1780. // the UUID of the root part for this SceneObjectGroup
  1781. // various text fields
  1782. row["Text"] = prim.Text;
  1783. row["Description"] = prim.Description;
  1784. row["SitName"] = prim.SitName;
  1785. row["TouchName"] = prim.TouchName;
  1786. // permissions
  1787. row["ObjectFlags"] = (uint)prim.Flags;
  1788. row["CreatorID"] = prim.CreatorIdentification.ToString();
  1789. row["OwnerID"] = prim.OwnerID.ToString();
  1790. row["GroupID"] = prim.GroupID.ToString();
  1791. row["LastOwnerID"] = prim.LastOwnerID.ToString();
  1792. row["OwnerMask"] = prim.OwnerMask;
  1793. row["NextOwnerMask"] = prim.NextOwnerMask;
  1794. row["GroupMask"] = prim.GroupMask;
  1795. row["EveryoneMask"] = prim.EveryoneMask;
  1796. row["BaseMask"] = prim.BaseMask;
  1797. // vectors
  1798. row["PositionX"] = prim.OffsetPosition.X;
  1799. row["PositionY"] = prim.OffsetPosition.Y;
  1800. row["PositionZ"] = prim.OffsetPosition.Z;
  1801. row["GroupPositionX"] = prim.GroupPosition.X;
  1802. row["GroupPositionY"] = prim.GroupPosition.Y;
  1803. row["GroupPositionZ"] = prim.GroupPosition.Z;
  1804. row["VelocityX"] = prim.Velocity.X;
  1805. row["VelocityY"] = prim.Velocity.Y;
  1806. row["VelocityZ"] = prim.Velocity.Z;
  1807. row["AngularVelocityX"] = prim.AngularVelocity.X;
  1808. row["AngularVelocityY"] = prim.AngularVelocity.Y;
  1809. row["AngularVelocityZ"] = prim.AngularVelocity.Z;
  1810. row["AccelerationX"] = prim.Acceleration.X;
  1811. row["AccelerationY"] = prim.Acceleration.Y;
  1812. row["AccelerationZ"] = prim.Acceleration.Z;
  1813. // quaternions
  1814. row["RotationX"] = prim.RotationOffset.X;
  1815. row["RotationY"] = prim.RotationOffset.Y;
  1816. row["RotationZ"] = prim.RotationOffset.Z;
  1817. row["RotationW"] = prim.RotationOffset.W;
  1818. // Sit target
  1819. Vector3 sitTargetPos = prim.SitTargetPositionLL;
  1820. row["SitTargetOffsetX"] = sitTargetPos.X;
  1821. row["SitTargetOffsetY"] = sitTargetPos.Y;
  1822. row["SitTargetOffsetZ"] = sitTargetPos.Z;
  1823. Quaternion sitTargetOrient = prim.SitTargetOrientationLL;
  1824. row["SitTargetOrientW"] = sitTargetOrient.W;
  1825. row["SitTargetOrientX"] = sitTargetOrient.X;
  1826. row["SitTargetOrientY"] = sitTargetOrient.Y;
  1827. row["SitTargetOrientZ"] = sitTargetOrient.Z;
  1828. row["ColorR"] = Convert.ToInt32(prim.Color.R);
  1829. row["ColorG"] = Convert.ToInt32(prim.Color.G);
  1830. row["ColorB"] = Convert.ToInt32(prim.Color.B);
  1831. row["ColorA"] = Convert.ToInt32(prim.Color.A);
  1832. row["PayPrice"] = prim.PayPrice[0];
  1833. row["PayButton1"] = prim.PayPrice[1];
  1834. row["PayButton2"] = prim.PayPrice[2];
  1835. row["PayButton3"] = prim.PayPrice[3];
  1836. row["PayButton4"] = prim.PayPrice[4];
  1837. row["TextureAnimation"] = Convert.ToBase64String(prim.TextureAnimation);
  1838. row["ParticleSystem"] = Convert.ToBase64String(prim.ParticleSystem);
  1839. row["OmegaX"] = prim.AngularVelocity.X;
  1840. row["OmegaY"] = prim.AngularVelocity.Y;
  1841. row["OmegaZ"] = prim.AngularVelocity.Z;
  1842. row["CameraEyeOffsetX"] = prim.GetCameraEyeOffset().X;
  1843. row["CameraEyeOffsetY"] = prim.GetCameraEyeOffset().Y;
  1844. row["CameraEyeOffsetZ"] = prim.GetCameraEyeOffset().Z;
  1845. row["CameraAtOffsetX"] = prim.GetCameraAtOffset().X;
  1846. row["CameraAtOffsetY"] = prim.GetCameraAtOffset().Y;
  1847. row["CameraAtOffsetZ"] = prim.GetCameraAtOffset().Z;
  1848. if ((prim.SoundFlags & 1) != 0) // Looped
  1849. {
  1850. row["LoopedSound"] = prim.Sound.ToString();
  1851. row["LoopedSoundGain"] = prim.SoundGain;
  1852. }
  1853. else
  1854. {
  1855. row["LoopedSound"] = UUID.Zero.ToString();
  1856. row["LoopedSoundGain"] = 0.0f;
  1857. }
  1858. if (prim.GetForceMouselook())
  1859. row["ForceMouselook"] = 1;
  1860. else
  1861. row["ForceMouselook"] = 0;
  1862. row["ScriptAccessPin"] = prim.ScriptAccessPin;
  1863. if (prim.AllowedDrop)
  1864. row["AllowedDrop"] = 1;
  1865. else
  1866. row["AllowedDrop"] = 0;
  1867. if (prim.DIE_AT_EDGE)
  1868. row["DieAtEdge"] = 1;
  1869. else
  1870. row["DieAtEdge"] = 0;
  1871. row["SalePrice"] = prim.SalePrice;
  1872. row["SaleType"] = Convert.ToInt16(prim.ObjectSaleType);
  1873. // click action
  1874. row["ClickAction"] = prim.ClickAction;
  1875. row["SalePrice"] = prim.SalePrice;
  1876. row["Material"] = prim.Material;
  1877. row["CollisionSound"] = prim.CollisionSound.ToString();
  1878. row["CollisionSoundVolume"] = prim.CollisionSoundVolume;
  1879. if (prim.VolumeDetectActive)
  1880. row["VolumeDetect"] = 1;
  1881. else
  1882. row["VolumeDetect"] = 0;
  1883. row["MediaURL"] = prim.MediaUrl;
  1884. row["AttachedPosX"] = prim.AttachedPos.X;
  1885. row["AttachedPosY"] = prim.AttachedPos.Y;
  1886. row["AttachedPosZ"] = prim.AttachedPos.Z;
  1887. if (prim.DynAttrs.CountNamespaces > 0)
  1888. row["DynAttrs"] = prim.DynAttrs.ToXml();
  1889. else
  1890. row["DynAttrs"] = null;
  1891. row["PhysicsShapeType"] = prim.PhysicsShapeType;
  1892. row["Density"] = (double)prim.Density;
  1893. row["GravityModifier"] = (double)prim.GravityModifier;
  1894. row["Friction"] = (double)prim.Friction;
  1895. row["Restitution"] = (double)prim.Restitution;
  1896. if (prim.KeyframeMotion != null)
  1897. row["KeyframeMotion"] = prim.KeyframeMotion.Serialize();
  1898. else
  1899. row["KeyframeMotion"] = new Byte[0];
  1900. }
  1901. /// <summary>
  1902. ///
  1903. /// </summary>
  1904. /// <param name="row"></param>
  1905. /// <param name="taskItem"></param>
  1906. private static void fillItemRow(DataRow row, TaskInventoryItem taskItem)
  1907. {
  1908. row["itemID"] = taskItem.ItemID.ToString();
  1909. row["primID"] = taskItem.ParentPartID.ToString();
  1910. row["assetID"] = taskItem.AssetID.ToString();
  1911. row["parentFolderID"] = taskItem.ParentID.ToString();
  1912. row["invType"] = taskItem.InvType;
  1913. row["assetType"] = taskItem.Type;
  1914. row["name"] = taskItem.Name;
  1915. row["description"] = taskItem.Description;
  1916. row["creationDate"] = taskItem.CreationDate;
  1917. row["creatorID"] = taskItem.CreatorIdentification.ToString();
  1918. row["ownerID"] = taskItem.OwnerID.ToString();
  1919. row["lastOwnerID"] = taskItem.LastOwnerID.ToString();
  1920. row["groupID"] = taskItem.GroupID.ToString();
  1921. row["nextPermissions"] = taskItem.NextPermissions;
  1922. row["currentPermissions"] = taskItem.CurrentPermissions;
  1923. row["basePermissions"] = taskItem.BasePermissions;
  1924. row["everyonePermissions"] = taskItem.EveryonePermissions;
  1925. row["groupPermissions"] = taskItem.GroupPermissions;
  1926. row["flags"] = taskItem.Flags;
  1927. }
  1928. /// <summary>
  1929. ///
  1930. /// </summary>
  1931. /// <param name="row"></param>
  1932. /// <param name="land"></param>
  1933. /// <param name="regionUUID"></param>
  1934. private static void fillLandRow(DataRow row, LandData land, UUID regionUUID)
  1935. {
  1936. row["UUID"] = land.GlobalID.ToString();
  1937. row["RegionUUID"] = regionUUID.ToString();
  1938. row["LocalLandID"] = land.LocalID;
  1939. // Bitmap is a byte[512]
  1940. row["Bitmap"] = land.Bitmap;
  1941. row["Name"] = land.Name;
  1942. row["Desc"] = land.Description;
  1943. row["OwnerUUID"] = land.OwnerID.ToString();
  1944. row["IsGroupOwned"] = land.IsGroupOwned;
  1945. row["Area"] = land.Area;
  1946. row["AuctionID"] = land.AuctionID; //Unemplemented
  1947. row["Category"] = land.Category; //Enum OpenMetaverse.Parcel.ParcelCategory
  1948. row["ClaimDate"] = land.ClaimDate;
  1949. row["ClaimPrice"] = land.ClaimPrice;
  1950. row["GroupUUID"] = land.GroupID.ToString();
  1951. row["SalePrice"] = land.SalePrice;
  1952. row["LandStatus"] = land.Status; //Enum. OpenMetaverse.Parcel.ParcelStatus
  1953. row["LandFlags"] = land.Flags;
  1954. row["LandingType"] = land.LandingType;
  1955. row["MediaAutoScale"] = land.MediaAutoScale;
  1956. row["MediaTextureUUID"] = land.MediaID.ToString();
  1957. row["MediaURL"] = land.MediaURL;
  1958. row["MusicURL"] = land.MusicURL;
  1959. row["PassHours"] = land.PassHours;
  1960. row["PassPrice"] = land.PassPrice;
  1961. row["SnapshotUUID"] = land.SnapshotID.ToString();
  1962. row["UserLocationX"] = land.UserLocation.X;
  1963. row["UserLocationY"] = land.UserLocation.Y;
  1964. row["UserLocationZ"] = land.UserLocation.Z;
  1965. row["UserLookAtX"] = land.UserLookAt.X;
  1966. row["UserLookAtY"] = land.UserLookAt.Y;
  1967. row["UserLookAtZ"] = land.UserLookAt.Z;
  1968. row["AuthbuyerID"] = land.AuthBuyerID.ToString();
  1969. row["OtherCleanTime"] = land.OtherCleanTime;
  1970. row["Dwell"] = land.Dwell;
  1971. row["MediaType"] = land.MediaType;
  1972. row["MediaDescription"] = land.MediaDescription;
  1973. row["MediaSize"] = String.Format("{0},{1}", land.MediaWidth, land.MediaHeight);
  1974. row["MediaLoop"] = land.MediaLoop;
  1975. row["ObscureMusic"] = land.ObscureMusic;
  1976. row["ObscureMedia"] = land.ObscureMedia;
  1977. }
  1978. /// <summary>
  1979. ///
  1980. /// </summary>
  1981. /// <param name="row"></param>
  1982. /// <param name="entry"></param>
  1983. /// <param name="parcelID"></param>
  1984. private static void fillLandAccessRow(DataRow row, LandAccessEntry entry, UUID parcelID)
  1985. {
  1986. row["LandUUID"] = parcelID.ToString();
  1987. row["AccessUUID"] = entry.AgentID.ToString();
  1988. row["Flags"] = entry.Flags;
  1989. }
  1990. private static void fillRegionSettingsRow(DataRow row, RegionSettings settings)
  1991. {
  1992. row["regionUUID"] = settings.RegionUUID.ToString();
  1993. row["block_terraform"] = settings.BlockTerraform;
  1994. row["block_fly"] = settings.BlockFly;
  1995. row["allow_damage"] = settings.AllowDamage;
  1996. row["restrict_pushing"] = settings.RestrictPushing;
  1997. row["allow_land_resell"] = settings.AllowLandResell;
  1998. row["allow_land_join_divide"] = settings.AllowLandJoinDivide;
  1999. row["block_show_in_search"] = settings.BlockShowInSearch;
  2000. row["agent_limit"] = settings.AgentLimit;
  2001. row["object_bonus"] = settings.ObjectBonus;
  2002. row["maturity"] = settings.Maturity;
  2003. row["disable_scripts"] = settings.DisableScripts;
  2004. row["disable_collisions"] = settings.DisableCollisions;
  2005. row["disable_physics"] = settings.DisablePhysics;
  2006. row["terrain_texture_1"] = settings.TerrainTexture1.ToString();
  2007. row["terrain_texture_2"] = settings.TerrainTexture2.ToString();
  2008. row["terrain_texture_3"] = settings.TerrainTexture3.ToString();
  2009. row["terrain_texture_4"] = settings.TerrainTexture4.ToString();
  2010. row["elevation_1_nw"] = settings.Elevation1NW;
  2011. row["elevation_2_nw"] = settings.Elevation2NW;
  2012. row["elevation_1_ne"] = settings.Elevation1NE;
  2013. row["elevation_2_ne"] = settings.Elevation2NE;
  2014. row["elevation_1_se"] = settings.Elevation1SE;
  2015. row["elevation_2_se"] = settings.Elevation2SE;
  2016. row["elevation_1_sw"] = settings.Elevation1SW;
  2017. row["elevation_2_sw"] = settings.Elevation2SW;
  2018. row["water_height"] = settings.WaterHeight;
  2019. row["terrain_raise_limit"] = settings.TerrainRaiseLimit;
  2020. row["terrain_lower_limit"] = settings.TerrainLowerLimit;
  2021. row["use_estate_sun"] = settings.UseEstateSun;
  2022. row["sandbox"] = settings.Sandbox; // unlike other database modules, sqlite uses a lower case s for sandbox!
  2023. row["sunvectorx"] = settings.SunVector.X;
  2024. row["sunvectory"] = settings.SunVector.Y;
  2025. row["sunvectorz"] = settings.SunVector.Z;
  2026. row["fixed_sun"] = settings.FixedSun;
  2027. row["sun_position"] = settings.SunPosition;
  2028. row["covenant"] = settings.Covenant.ToString();
  2029. row["covenant_datetime"] = settings.CovenantChangedDateTime;
  2030. row["map_tile_ID"] = settings.TerrainImageID.ToString();
  2031. row["TelehubObject"] = settings.TelehubObject.ToString();
  2032. row["parcel_tile_ID"] = settings.ParcelImageID.ToString();
  2033. }
  2034. /// <summary>
  2035. ///
  2036. /// </summary>
  2037. /// <param name="row"></param>
  2038. /// <param name="windlight"></param>
  2039. private static void fillRegionWindlightRow(DataRow row, RegionLightShareData windlight)
  2040. {
  2041. row["region_id"] = windlight.regionID.ToString();
  2042. row["water_color_r"] = windlight.waterColor.X;
  2043. row["water_color_g"] = windlight.waterColor.Y;
  2044. row["water_color_b"] = windlight.waterColor.Z;
  2045. row["water_color_i"] = 1; //windlight.waterColor.W; //not implemented
  2046. row["water_fog_density_exponent"] = windlight.waterFogDensityExponent;
  2047. row["underwater_fog_modifier"] = windlight.underwaterFogModifier;
  2048. row["reflection_wavelet_scale_1"] = windlight.reflectionWaveletScale.X;
  2049. row["reflection_wavelet_scale_2"] = windlight.reflectionWaveletScale.Y;
  2050. row["reflection_wavelet_scale_3"] = windlight.reflectionWaveletScale.Z;
  2051. row["fresnel_scale"] = windlight.fresnelScale;
  2052. row["fresnel_offset"] = windlight.fresnelOffset;
  2053. row["refract_scale_above"] = windlight.refractScaleAbove;
  2054. row["refract_scale_below"] = windlight.refractScaleBelow;
  2055. row["blur_multiplier"] = windlight.blurMultiplier;
  2056. row["big_wave_direction_x"] = windlight.bigWaveDirection.X;
  2057. row["big_wave_direction_y"] = windlight.bigWaveDirection.Y;
  2058. row["little_wave_direction_x"] = windlight.littleWaveDirection.X;
  2059. row["little_wave_direction_y"] = windlight.littleWaveDirection.Y;
  2060. row["normal_map_texture"] = windlight.normalMapTexture.ToString();
  2061. row["horizon_r"] = windlight.horizon.X;
  2062. row["horizon_g"] = windlight.horizon.Y;
  2063. row["horizon_b"] = windlight.horizon.Z;
  2064. row["horizon_i"] = windlight.horizon.W;
  2065. row["haze_horizon"] = windlight.hazeHorizon;
  2066. row["blue_density_r"] = windlight.blueDensity.X;
  2067. row["blue_density_g"] = windlight.blueDensity.Y;
  2068. row["blue_density_b"] = windlight.blueDensity.Z;
  2069. row["blue_density_i"] = windlight.blueDensity.W;
  2070. row["haze_density"] = windlight.hazeDensity;
  2071. row["density_multiplier"] = windlight.densityMultiplier;
  2072. row["distance_multiplier"] = windlight.distanceMultiplier;
  2073. row["max_altitude"] = windlight.maxAltitude;
  2074. row["sun_moon_color_r"] = windlight.sunMoonColor.X;
  2075. row["sun_moon_color_g"] = windlight.sunMoonColor.Y;
  2076. row["sun_moon_color_b"] = windlight.sunMoonColor.Z;
  2077. row["sun_moon_color_i"] = windlight.sunMoonColor.W;
  2078. row["sun_moon_position"] = windlight.sunMoonPosition;
  2079. row["ambient_r"] = windlight.ambient.X;
  2080. row["ambient_g"] = windlight.ambient.Y;
  2081. row["ambient_b"] = windlight.ambient.Z;
  2082. row["ambient_i"] = windlight.ambient.W;
  2083. row["east_angle"] = windlight.eastAngle;
  2084. row["sun_glow_focus"] = windlight.sunGlowFocus;
  2085. row["sun_glow_size"] = windlight.sunGlowSize;
  2086. row["scene_gamma"] = windlight.sceneGamma;
  2087. row["star_brightness"] = windlight.starBrightness;
  2088. row["cloud_color_r"] = windlight.cloudColor.X;
  2089. row["cloud_color_g"] = windlight.cloudColor.Y;
  2090. row["cloud_color_b"] = windlight.cloudColor.Z;
  2091. row["cloud_color_i"] = windlight.cloudColor.W;
  2092. row["cloud_x"] = windlight.cloudXYDensity.X;
  2093. row["cloud_y"] = windlight.cloudXYDensity.Y;
  2094. row["cloud_density"] = windlight.cloudXYDensity.Z;
  2095. row["cloud_coverage"] = windlight.cloudCoverage;
  2096. row["cloud_scale"] = windlight.cloudScale;
  2097. row["cloud_detail_x"] = windlight.cloudDetailXYDensity.X;
  2098. row["cloud_detail_y"] = windlight.cloudDetailXYDensity.Y;
  2099. row["cloud_detail_density"] = windlight.cloudDetailXYDensity.Z;
  2100. row["cloud_scroll_x"] = windlight.cloudScrollX;
  2101. row["cloud_scroll_x_lock"] = windlight.cloudScrollXLock;
  2102. row["cloud_scroll_y"] = windlight.cloudScrollY;
  2103. row["cloud_scroll_y_lock"] = windlight.cloudScrollYLock;
  2104. row["draw_classic_clouds"] = windlight.drawClassicClouds;
  2105. }
  2106. /// <summary>
  2107. ///
  2108. /// </summary>
  2109. /// <param name="row"></param>
  2110. /// <returns></returns>
  2111. private PrimitiveBaseShape buildShape(DataRow row)
  2112. {
  2113. PrimitiveBaseShape s = new PrimitiveBaseShape();
  2114. s.Scale = new Vector3(
  2115. Convert.ToSingle(row["ScaleX"]),
  2116. Convert.ToSingle(row["ScaleY"]),
  2117. Convert.ToSingle(row["ScaleZ"])
  2118. );
  2119. // paths
  2120. s.PCode = Convert.ToByte(row["PCode"]);
  2121. s.PathBegin = Convert.ToUInt16(row["PathBegin"]);
  2122. s.PathEnd = Convert.ToUInt16(row["PathEnd"]);
  2123. s.PathScaleX = Convert.ToByte(row["PathScaleX"]);
  2124. s.PathScaleY = Convert.ToByte(row["PathScaleY"]);
  2125. s.PathShearX = Convert.ToByte(row["PathShearX"]);
  2126. s.PathShearY = Convert.ToByte(row["PathShearY"]);
  2127. s.PathSkew = Convert.ToSByte(row["PathSkew"]);
  2128. s.PathCurve = Convert.ToByte(row["PathCurve"]);
  2129. s.PathRadiusOffset = Convert.ToSByte(row["PathRadiusOffset"]);
  2130. s.PathRevolutions = Convert.ToByte(row["PathRevolutions"]);
  2131. s.PathTaperX = Convert.ToSByte(row["PathTaperX"]);
  2132. s.PathTaperY = Convert.ToSByte(row["PathTaperY"]);
  2133. s.PathTwist = Convert.ToSByte(row["PathTwist"]);
  2134. s.PathTwistBegin = Convert.ToSByte(row["PathTwistBegin"]);
  2135. // profile
  2136. s.ProfileBegin = Convert.ToUInt16(row["ProfileBegin"]);
  2137. s.ProfileEnd = Convert.ToUInt16(row["ProfileEnd"]);
  2138. s.ProfileCurve = Convert.ToByte(row["ProfileCurve"]);
  2139. s.ProfileHollow = Convert.ToUInt16(row["ProfileHollow"]);
  2140. s.State = Convert.ToByte(row["State"]);
  2141. s.LastAttachPoint = Convert.ToByte(row["LastAttachPoint"]);
  2142. byte[] textureEntry = (byte[])row["Texture"];
  2143. s.TextureEntry = textureEntry;
  2144. s.ExtraParams = (byte[])row["ExtraParams"];
  2145. if (!(row["Media"] is System.DBNull))
  2146. s.Media = PrimitiveBaseShape.MediaList.FromXml((string)row["Media"]);
  2147. return s;
  2148. }
  2149. /// <summary>
  2150. ///
  2151. /// </summary>
  2152. /// <param name="row"></param>
  2153. /// <param name="prim"></param>
  2154. private static void fillShapeRow(DataRow row, SceneObjectPart prim)
  2155. {
  2156. PrimitiveBaseShape s = prim.Shape;
  2157. row["UUID"] = prim.UUID.ToString();
  2158. // shape is an enum
  2159. row["Shape"] = 0;
  2160. // vectors
  2161. row["ScaleX"] = s.Scale.X;
  2162. row["ScaleY"] = s.Scale.Y;
  2163. row["ScaleZ"] = s.Scale.Z;
  2164. // paths
  2165. row["PCode"] = s.PCode;
  2166. row["PathBegin"] = s.PathBegin;
  2167. row["PathEnd"] = s.PathEnd;
  2168. row["PathScaleX"] = s.PathScaleX;
  2169. row["PathScaleY"] = s.PathScaleY;
  2170. row["PathShearX"] = s.PathShearX;
  2171. row["PathShearY"] = s.PathShearY;
  2172. row["PathSkew"] = s.PathSkew;
  2173. row["PathCurve"] = s.PathCurve;
  2174. row["PathRadiusOffset"] = s.PathRadiusOffset;
  2175. row["PathRevolutions"] = s.PathRevolutions;
  2176. row["PathTaperX"] = s.PathTaperX;
  2177. row["PathTaperY"] = s.PathTaperY;
  2178. row["PathTwist"] = s.PathTwist;
  2179. row["PathTwistBegin"] = s.PathTwistBegin;
  2180. // profile
  2181. row["ProfileBegin"] = s.ProfileBegin;
  2182. row["ProfileEnd"] = s.ProfileEnd;
  2183. row["ProfileCurve"] = s.ProfileCurve;
  2184. row["ProfileHollow"] = s.ProfileHollow;
  2185. row["State"] = s.State;
  2186. row["LastAttachPoint"] = s.LastAttachPoint;
  2187. row["Texture"] = s.TextureEntry;
  2188. row["ExtraParams"] = s.ExtraParams;
  2189. if (s.Media != null)
  2190. row["Media"] = s.Media.ToXml();
  2191. }
  2192. /// <summary>
  2193. /// Persistently store a prim.
  2194. /// </summary>
  2195. /// <param name="prim"></param>
  2196. /// <param name="sceneGroupID"></param>
  2197. /// <param name="regionUUID"></param>
  2198. private void addPrim(SceneObjectPart prim, UUID sceneGroupID, UUID regionUUID)
  2199. {
  2200. DataTable prims = ds.Tables["prims"];
  2201. DataTable shapes = ds.Tables["primshapes"];
  2202. DataRow primRow = prims.Rows.Find(prim.UUID.ToString());
  2203. if (primRow == null)
  2204. {
  2205. primRow = prims.NewRow();
  2206. fillPrimRow(primRow, prim, sceneGroupID, regionUUID);
  2207. prims.Rows.Add(primRow);
  2208. }
  2209. else
  2210. {
  2211. fillPrimRow(primRow, prim, sceneGroupID, regionUUID);
  2212. }
  2213. DataRow shapeRow = shapes.Rows.Find(prim.UUID.ToString());
  2214. if (shapeRow == null)
  2215. {
  2216. shapeRow = shapes.NewRow();
  2217. fillShapeRow(shapeRow, prim);
  2218. shapes.Rows.Add(shapeRow);
  2219. }
  2220. else
  2221. {
  2222. fillShapeRow(shapeRow, prim);
  2223. }
  2224. }
  2225. /// <summary>
  2226. /// </summary>
  2227. /// <param name="primID"></param>
  2228. /// <param name="items"></param>
  2229. public void StorePrimInventory(UUID primID, ICollection<TaskInventoryItem> items)
  2230. {
  2231. // m_log.DebugFormat("[SQLITE REGION DB]: Entered StorePrimInventory with prim ID {0}", primID);
  2232. DataTable dbItems = ds.Tables["primitems"];
  2233. // For now, we're just going to crudely remove all the previous inventory items
  2234. // no matter whether they have changed or not, and replace them with the current set.
  2235. lock (ds)
  2236. {
  2237. RemoveItems(primID);
  2238. // repalce with current inventory details
  2239. foreach (TaskInventoryItem newItem in items)
  2240. {
  2241. // m_log.InfoFormat(
  2242. // "[DATASTORE]: ",
  2243. // "Adding item {0}, {1} to prim ID {2}",
  2244. // newItem.Name, newItem.ItemID, newItem.ParentPartID);
  2245. DataRow newItemRow = dbItems.NewRow();
  2246. fillItemRow(newItemRow, newItem);
  2247. dbItems.Rows.Add(newItemRow);
  2248. }
  2249. }
  2250. Commit();
  2251. }
  2252. /***********************************************************************
  2253. *
  2254. * SQL Statement Creation Functions
  2255. *
  2256. * These functions create SQL statements for update, insert, and create.
  2257. * They can probably be factored later to have a db independant
  2258. * portion and a db specific portion
  2259. *
  2260. **********************************************************************/
  2261. /// <summary>
  2262. /// Create an insert command
  2263. /// </summary>
  2264. /// <param name="table">table name</param>
  2265. /// <param name="dt">data table</param>
  2266. /// <returns>the created command</returns>
  2267. /// <remarks>
  2268. /// This is subtle enough to deserve some commentary.
  2269. /// Instead of doing *lots* and *lots of hardcoded strings
  2270. /// for database definitions we'll use the fact that
  2271. /// realistically all insert statements look like "insert
  2272. /// into A(b, c) values(:b, :c) on the parameterized query
  2273. /// front. If we just have a list of b, c, etc... we can
  2274. /// generate these strings instead of typing them out.
  2275. /// </remarks>
  2276. private static SqliteCommand createInsertCommand(string table, DataTable dt)
  2277. {
  2278. string[] cols = new string[dt.Columns.Count];
  2279. for (int i = 0; i < dt.Columns.Count; i++)
  2280. {
  2281. DataColumn col = dt.Columns[i];
  2282. cols[i] = col.ColumnName;
  2283. }
  2284. string sql = "insert into " + table + "(";
  2285. sql += String.Join(", ", cols);
  2286. // important, the first ':' needs to be here, the rest get added in the join
  2287. sql += ") values (:";
  2288. sql += String.Join(", :", cols);
  2289. sql += ")";
  2290. // m_log.DebugFormat("[SQLITE]: Created insert command {0}", sql);
  2291. SqliteCommand cmd = new SqliteCommand(sql);
  2292. // this provides the binding for all our parameters, so
  2293. // much less code than it used to be
  2294. foreach (DataColumn col in dt.Columns)
  2295. {
  2296. cmd.Parameters.Add(createSqliteParameter(col.ColumnName, col.DataType));
  2297. }
  2298. return cmd;
  2299. }
  2300. /// <summary>
  2301. /// create an update command
  2302. /// </summary>
  2303. /// <param name="table">table name</param>
  2304. /// <param name="pk"></param>
  2305. /// <param name="dt"></param>
  2306. /// <returns>the created command</returns>
  2307. private static SqliteCommand createUpdateCommand(string table, string pk, DataTable dt)
  2308. {
  2309. string sql = "update " + table + " set ";
  2310. string subsql = String.Empty;
  2311. foreach (DataColumn col in dt.Columns)
  2312. {
  2313. if (subsql.Length > 0)
  2314. {
  2315. // a map function would rock so much here
  2316. subsql += ", ";
  2317. }
  2318. subsql += col.ColumnName + "= :" + col.ColumnName;
  2319. }
  2320. sql += subsql;
  2321. sql += " where " + pk;
  2322. SqliteCommand cmd = new SqliteCommand(sql);
  2323. // this provides the binding for all our parameters, so
  2324. // much less code than it used to be
  2325. foreach (DataColumn col in dt.Columns)
  2326. {
  2327. cmd.Parameters.Add(createSqliteParameter(col.ColumnName, col.DataType));
  2328. }
  2329. return cmd;
  2330. }
  2331. /// <summary>
  2332. /// create an update command
  2333. /// </summary>
  2334. /// <param name="table">table name</param>
  2335. /// <param name="pk"></param>
  2336. /// <param name="dt"></param>
  2337. /// <returns>the created command</returns>
  2338. private static SqliteCommand createUpdateCommand(string table, string pk1, string pk2, DataTable dt)
  2339. {
  2340. string sql = "update " + table + " set ";
  2341. string subsql = String.Empty;
  2342. foreach (DataColumn col in dt.Columns)
  2343. {
  2344. if (subsql.Length > 0)
  2345. {
  2346. // a map function would rock so much here
  2347. subsql += ", ";
  2348. }
  2349. subsql += col.ColumnName + "= :" + col.ColumnName;
  2350. }
  2351. sql += subsql;
  2352. sql += " where " + pk1 + " and " + pk2;
  2353. SqliteCommand cmd = new SqliteCommand(sql);
  2354. // this provides the binding for all our parameters, so
  2355. // much less code than it used to be
  2356. foreach (DataColumn col in dt.Columns)
  2357. {
  2358. cmd.Parameters.Add(createSqliteParameter(col.ColumnName, col.DataType));
  2359. }
  2360. return cmd;
  2361. }
  2362. /// <summary>
  2363. ///
  2364. /// </summary>
  2365. /// <param name="dt">Data Table</param>
  2366. /// <returns></returns>
  2367. // private static string defineTable(DataTable dt)
  2368. // {
  2369. // string sql = "create table " + dt.TableName + "(";
  2370. // string subsql = String.Empty;
  2371. // foreach (DataColumn col in dt.Columns)
  2372. // {
  2373. // if (subsql.Length > 0)
  2374. // {
  2375. // // a map function would rock so much here
  2376. // subsql += ",\n";
  2377. // }
  2378. // subsql += col.ColumnName + " " + sqliteType(col.DataType);
  2379. // if (dt.PrimaryKey.Length > 0 && col == dt.PrimaryKey[0])
  2380. // {
  2381. // subsql += " primary key";
  2382. // }
  2383. // }
  2384. // sql += subsql;
  2385. // sql += ")";
  2386. // return sql;
  2387. // }
  2388. /***********************************************************************
  2389. *
  2390. * Database Binding functions
  2391. *
  2392. * These will be db specific due to typing, and minor differences
  2393. * in databases.
  2394. *
  2395. **********************************************************************/
  2396. ///<summary>
  2397. /// This is a convenience function that collapses 5 repetitive
  2398. /// lines for defining SqliteParameters to 2 parameters:
  2399. /// column name and database type.
  2400. ///
  2401. /// It assumes certain conventions like :param as the param
  2402. /// name to replace in parametrized queries, and that source
  2403. /// version is always current version, both of which are fine
  2404. /// for us.
  2405. ///</summary>
  2406. ///<returns>a built sqlite parameter</returns>
  2407. private static SqliteParameter createSqliteParameter(string name, Type type)
  2408. {
  2409. SqliteParameter param = new SqliteParameter();
  2410. param.ParameterName = ":" + name;
  2411. param.DbType = dbtypeFromType(type);
  2412. param.SourceColumn = name;
  2413. param.SourceVersion = DataRowVersion.Current;
  2414. return param;
  2415. }
  2416. /// <summary>
  2417. ///
  2418. /// </summary>
  2419. /// <param name="da"></param>
  2420. /// <param name="conn"></param>
  2421. private void setupPrimCommands(SqliteDataAdapter da, SqliteConnection conn)
  2422. {
  2423. da.InsertCommand = createInsertCommand("prims", ds.Tables["prims"]);
  2424. da.InsertCommand.Connection = conn;
  2425. da.UpdateCommand = createUpdateCommand("prims", "UUID=:UUID", ds.Tables["prims"]);
  2426. da.UpdateCommand.Connection = conn;
  2427. SqliteCommand delete = new SqliteCommand("delete from prims where UUID = :UUID");
  2428. delete.Parameters.Add(createSqliteParameter("UUID", typeof(String)));
  2429. delete.Connection = conn;
  2430. da.DeleteCommand = delete;
  2431. }
  2432. /// <summary>
  2433. ///
  2434. /// </summary>
  2435. /// <param name="da"></param>
  2436. /// <param name="conn"></param>
  2437. private void setupItemsCommands(SqliteDataAdapter da, SqliteConnection conn)
  2438. {
  2439. da.InsertCommand = createInsertCommand("primitems", ds.Tables["primitems"]);
  2440. da.InsertCommand.Connection = conn;
  2441. da.UpdateCommand = createUpdateCommand("primitems", "itemID = :itemID", ds.Tables["primitems"]);
  2442. da.UpdateCommand.Connection = conn;
  2443. SqliteCommand delete = new SqliteCommand("delete from primitems where itemID = :itemID");
  2444. delete.Parameters.Add(createSqliteParameter("itemID", typeof(String)));
  2445. delete.Connection = conn;
  2446. da.DeleteCommand = delete;
  2447. }
  2448. /// <summary>
  2449. ///
  2450. /// </summary>
  2451. /// <param name="da"></param>
  2452. /// <param name="conn"></param>
  2453. private void setupTerrainCommands(SqliteDataAdapter da, SqliteConnection conn)
  2454. {
  2455. da.InsertCommand = createInsertCommand("terrain", ds.Tables["terrain"]);
  2456. da.InsertCommand.Connection = conn;
  2457. }
  2458. /// <summary>
  2459. ///
  2460. /// </summary>
  2461. /// <param name="da"></param>
  2462. /// <param name="conn"></param>
  2463. private void setupLandCommands(SqliteDataAdapter da, SqliteConnection conn)
  2464. {
  2465. da.InsertCommand = createInsertCommand("land", ds.Tables["land"]);
  2466. da.InsertCommand.Connection = conn;
  2467. da.UpdateCommand = createUpdateCommand("land", "UUID=:UUID", ds.Tables["land"]);
  2468. da.UpdateCommand.Connection = conn;
  2469. SqliteCommand delete = new SqliteCommand("delete from land where UUID=:UUID");
  2470. delete.Parameters.Add(createSqliteParameter("UUID", typeof(String)));
  2471. da.DeleteCommand = delete;
  2472. da.DeleteCommand.Connection = conn;
  2473. }
  2474. /// <summary>
  2475. ///
  2476. /// </summary>
  2477. /// <param name="da"></param>
  2478. /// <param name="conn"></param>
  2479. private void setupLandAccessCommands(SqliteDataAdapter da, SqliteConnection conn)
  2480. {
  2481. da.InsertCommand = createInsertCommand("landaccesslist", ds.Tables["landaccesslist"]);
  2482. da.InsertCommand.Connection = conn;
  2483. da.UpdateCommand = createUpdateCommand("landaccesslist", "LandUUID=:landUUID", "AccessUUID=:AccessUUID", ds.Tables["landaccesslist"]);
  2484. da.UpdateCommand.Connection = conn;
  2485. SqliteCommand delete = new SqliteCommand("delete from landaccesslist where LandUUID= :LandUUID and AccessUUID= :AccessUUID");
  2486. delete.Parameters.Add(createSqliteParameter("LandUUID", typeof(String)));
  2487. delete.Parameters.Add(createSqliteParameter("AccessUUID", typeof(String)));
  2488. da.DeleteCommand = delete;
  2489. da.DeleteCommand.Connection = conn;
  2490. }
  2491. private void setupRegionSettingsCommands(SqliteDataAdapter da, SqliteConnection conn)
  2492. {
  2493. da.InsertCommand = createInsertCommand("regionsettings", ds.Tables["regionsettings"]);
  2494. da.InsertCommand.Connection = conn;
  2495. da.UpdateCommand = createUpdateCommand("regionsettings", "regionUUID=:regionUUID", ds.Tables["regionsettings"]);
  2496. da.UpdateCommand.Connection = conn;
  2497. }
  2498. /// <summary>
  2499. ///
  2500. /// </summary>
  2501. /// <param name="da"></param>
  2502. /// <param name="conn"></param>
  2503. private void setupRegionWindlightCommands(SqliteDataAdapter da, SqliteConnection conn)
  2504. {
  2505. da.InsertCommand = createInsertCommand("regionwindlight", ds.Tables["regionwindlight"]);
  2506. da.InsertCommand.Connection = conn;
  2507. da.UpdateCommand = createUpdateCommand("regionwindlight", "region_id=:region_id", ds.Tables["regionwindlight"]);
  2508. da.UpdateCommand.Connection = conn;
  2509. }
  2510. private void setupRegionEnvironmentCommands(SqliteDataAdapter da, SqliteConnection conn)
  2511. {
  2512. da.InsertCommand = createInsertCommand("regionenvironment", ds.Tables["regionenvironment"]);
  2513. da.InsertCommand.Connection = conn;
  2514. da.UpdateCommand = createUpdateCommand("regionenvironment", "region_id=:region_id", ds.Tables["regionenvironment"]);
  2515. da.UpdateCommand.Connection = conn;
  2516. }
  2517. private void setupRegionSpawnPointsCommands(SqliteDataAdapter da, SqliteConnection conn)
  2518. {
  2519. da.InsertCommand = createInsertCommand("spawn_points", ds.Tables["spawn_points"]);
  2520. da.InsertCommand.Connection = conn;
  2521. da.UpdateCommand = createUpdateCommand("spawn_points", "RegionID=:RegionID", ds.Tables["spawn_points"]);
  2522. da.UpdateCommand.Connection = conn;
  2523. }
  2524. /// <summary>
  2525. ///
  2526. /// </summary>
  2527. /// <param name="da"></param>
  2528. /// <param name="conn"></param>
  2529. private void setupShapeCommands(SqliteDataAdapter da, SqliteConnection conn)
  2530. {
  2531. da.InsertCommand = createInsertCommand("primshapes", ds.Tables["primshapes"]);
  2532. da.InsertCommand.Connection = conn;
  2533. da.UpdateCommand = createUpdateCommand("primshapes", "UUID=:UUID", ds.Tables["primshapes"]);
  2534. da.UpdateCommand.Connection = conn;
  2535. SqliteCommand delete = new SqliteCommand("delete from primshapes where UUID = :UUID");
  2536. delete.Parameters.Add(createSqliteParameter("UUID", typeof(String)));
  2537. delete.Connection = conn;
  2538. da.DeleteCommand = delete;
  2539. }
  2540. /***********************************************************************
  2541. *
  2542. * Type conversion functions
  2543. *
  2544. **********************************************************************/
  2545. /// <summary>
  2546. /// Type conversion function
  2547. /// </summary>
  2548. /// <param name="type"></param>
  2549. /// <returns></returns>
  2550. private static DbType dbtypeFromType(Type type)
  2551. {
  2552. if (type == typeof(String))
  2553. {
  2554. return DbType.String;
  2555. }
  2556. else if (type == typeof(Int32))
  2557. {
  2558. return DbType.Int32;
  2559. }
  2560. else if (type == typeof(Double))
  2561. {
  2562. return DbType.Double;
  2563. }
  2564. else if (type == typeof(Byte))
  2565. {
  2566. return DbType.Byte;
  2567. }
  2568. else if (type == typeof(Double))
  2569. {
  2570. return DbType.Double;
  2571. }
  2572. else if (type == typeof(Byte[]))
  2573. {
  2574. return DbType.Binary;
  2575. }
  2576. else
  2577. {
  2578. return DbType.String;
  2579. }
  2580. }
  2581. static void PrintDataSet(DataSet ds)
  2582. {
  2583. // Print out any name and extended properties.
  2584. Console.WriteLine("DataSet is named: {0}", ds.DataSetName);
  2585. foreach (System.Collections.DictionaryEntry de in ds.ExtendedProperties)
  2586. {
  2587. Console.WriteLine("Key = {0}, Value = {1}", de.Key, de.Value);
  2588. }
  2589. Console.WriteLine();
  2590. foreach (DataTable dt in ds.Tables)
  2591. {
  2592. Console.WriteLine("=> {0} Table:", dt.TableName);
  2593. // Print out the column names.
  2594. for (int curCol = 0; curCol < dt.Columns.Count; curCol++)
  2595. {
  2596. Console.Write(dt.Columns[curCol].ColumnName + "\t");
  2597. }
  2598. Console.WriteLine("\n----------------------------------");
  2599. // Print the DataTable.
  2600. for (int curRow = 0; curRow < dt.Rows.Count; curRow++)
  2601. {
  2602. for (int curCol = 0; curCol < dt.Columns.Count; curCol++)
  2603. {
  2604. Console.Write(dt.Rows[curRow][curCol].ToString() + "\t");
  2605. }
  2606. Console.WriteLine();
  2607. }
  2608. }
  2609. }
  2610. public void SaveExtra(UUID regionID, string name, string value)
  2611. {
  2612. }
  2613. public void RemoveExtra(UUID regionID, string name)
  2614. {
  2615. }
  2616. public Dictionary<string, string> GetExtra(UUID regionID)
  2617. {
  2618. return null;
  2619. }
  2620. }
  2621. }