1
0

SQLiteSimulationData.cs 127 KB

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