SQLiteSimulationData.cs 125 KB

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