SQLiteSimulationData.cs 128 KB

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