1
0

SQLiteSimulationData.cs 131 KB

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