MySQLManager.cs 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692
  1. /*
  2. * Copyright (c) Contributors, http://www.openmetaverse.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 OpenSim 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. */
  28. using System;
  29. using System.Collections.Generic;
  30. using System.Data;
  31. using libsecondlife;
  32. using MySql.Data.MySqlClient;
  33. namespace OpenSim.Framework.Data.MySQL
  34. {
  35. /// <summary>
  36. /// A MySQL Database manager
  37. /// </summary>
  38. class MySQLManager
  39. {
  40. /// <summary>
  41. /// The database connection object
  42. /// </summary>
  43. IDbConnection dbcon;
  44. /// <summary>
  45. /// Connection string for ADO.net
  46. /// </summary>
  47. string connectionString;
  48. /// <summary>
  49. /// Initialises and creates a new MySQL connection and maintains it.
  50. /// </summary>
  51. /// <param name="hostname">The MySQL server being connected to</param>
  52. /// <param name="database">The name of the MySQL database being used</param>
  53. /// <param name="username">The username logging into the database</param>
  54. /// <param name="password">The password for the user logging in</param>
  55. /// <param name="cpooling">Whether to use connection pooling or not, can be one of the following: 'yes', 'true', 'no' or 'false', if unsure use 'false'.</param>
  56. public MySQLManager(string hostname, string database, string username, string password, string cpooling, string port)
  57. {
  58. try
  59. {
  60. connectionString = "Server=" + hostname + ";Port=" + port + ";Database=" + database + ";User ID=" + username + ";Password=" + password + ";Pooling=" + cpooling + ";";
  61. dbcon = new MySqlConnection(connectionString);
  62. dbcon.Open();
  63. Console.WriteLine("MySQL connection established");
  64. }
  65. catch (Exception e)
  66. {
  67. throw new Exception("Error initialising MySql Database: " + e.ToString());
  68. }
  69. }
  70. /// <summary>
  71. /// Shuts down the database connection
  72. /// </summary>
  73. public void Close()
  74. {
  75. dbcon.Close();
  76. dbcon = null;
  77. }
  78. /// <summary>
  79. /// Reconnects to the database
  80. /// </summary>
  81. public void Reconnect()
  82. {
  83. lock (dbcon)
  84. {
  85. try
  86. {
  87. // Close the DB connection
  88. dbcon.Close();
  89. // Try reopen it
  90. dbcon = new MySqlConnection(connectionString);
  91. dbcon.Open();
  92. }
  93. catch (Exception e)
  94. {
  95. Console.WriteLine("Unable to reconnect to database " + e.ToString());
  96. }
  97. }
  98. }
  99. /// <summary>
  100. /// Runs a query with protection against SQL Injection by using parameterised input.
  101. /// </summary>
  102. /// <param name="sql">The SQL string - replace any variables such as WHERE x = "y" with WHERE x = @y</param>
  103. /// <param name="parameters">The parameters - index so that @y is indexed as 'y'</param>
  104. /// <returns>A MySQL DB Command</returns>
  105. public IDbCommand Query(string sql, Dictionary<string, string> parameters)
  106. {
  107. try
  108. {
  109. MySqlCommand dbcommand = (MySqlCommand)dbcon.CreateCommand();
  110. dbcommand.CommandText = sql;
  111. foreach (KeyValuePair<string, string> param in parameters)
  112. {
  113. dbcommand.Parameters.Add(param.Key, param.Value);
  114. }
  115. return (IDbCommand)dbcommand;
  116. }
  117. catch
  118. {
  119. lock (dbcon)
  120. {
  121. // Close the DB connection
  122. try
  123. {
  124. dbcon.Close();
  125. }
  126. catch { }
  127. // Try reopen it
  128. try
  129. {
  130. dbcon = new MySqlConnection(connectionString);
  131. dbcon.Open();
  132. }
  133. catch (Exception e)
  134. {
  135. Console.WriteLine("Unable to reconnect to database " + e.ToString());
  136. }
  137. // Run the query again
  138. try
  139. {
  140. MySqlCommand dbcommand = (MySqlCommand)dbcon.CreateCommand();
  141. dbcommand.CommandText = sql;
  142. foreach (KeyValuePair<string, string> param in parameters)
  143. {
  144. dbcommand.Parameters.Add(param.Key, param.Value);
  145. }
  146. return (IDbCommand)dbcommand;
  147. }
  148. catch (Exception e)
  149. {
  150. // Return null if it fails.
  151. Console.WriteLine("Failed during Query generation: " + e.ToString());
  152. return null;
  153. }
  154. }
  155. }
  156. }
  157. /// <summary>
  158. /// Reads a region row from a database reader
  159. /// </summary>
  160. /// <param name="reader">An active database reader</param>
  161. /// <returns>A region profile</returns>
  162. public SimProfileData readSimRow(IDataReader reader)
  163. {
  164. SimProfileData retval = new SimProfileData();
  165. if (reader.Read())
  166. {
  167. // Region Main
  168. retval.regionHandle = Convert.ToUInt64(reader["regionHandle"].ToString());
  169. retval.regionName = (string)reader["regionName"];
  170. retval.UUID = new LLUUID((string)reader["uuid"]);
  171. // Secrets
  172. retval.regionRecvKey = (string)reader["regionRecvKey"];
  173. retval.regionSecret = (string)reader["regionSecret"];
  174. retval.regionSendKey = (string)reader["regionSendKey"];
  175. // Region Server
  176. retval.regionDataURI = (string)reader["regionDataURI"];
  177. retval.regionOnline = false; // Needs to be pinged before this can be set.
  178. retval.serverIP = (string)reader["serverIP"];
  179. retval.serverPort = (uint)reader["serverPort"];
  180. retval.serverURI = (string)reader["serverURI"];
  181. retval.httpPort = Convert.ToUInt32(reader["serverHttpPort"].ToString());
  182. retval.remotingPort = Convert.ToUInt32(reader["serverRemotingPort"].ToString());
  183. // Location
  184. retval.regionLocX = Convert.ToUInt32(reader["locX"].ToString());
  185. retval.regionLocY = Convert.ToUInt32(reader["locY"].ToString());
  186. retval.regionLocZ = Convert.ToUInt32(reader["locZ"].ToString());
  187. // Neighbours - 0 = No Override
  188. retval.regionEastOverrideHandle = Convert.ToUInt64(reader["eastOverrideHandle"].ToString());
  189. retval.regionWestOverrideHandle = Convert.ToUInt64(reader["westOverrideHandle"].ToString());
  190. retval.regionSouthOverrideHandle = Convert.ToUInt64(reader["southOverrideHandle"].ToString());
  191. retval.regionNorthOverrideHandle = Convert.ToUInt64(reader["northOverrideHandle"].ToString());
  192. // Assets
  193. retval.regionAssetURI = (string)reader["regionAssetURI"];
  194. retval.regionAssetRecvKey = (string)reader["regionAssetRecvKey"];
  195. retval.regionAssetSendKey = (string)reader["regionAssetSendKey"];
  196. // Userserver
  197. retval.regionUserURI = (string)reader["regionUserURI"];
  198. retval.regionUserRecvKey = (string)reader["regionUserRecvKey"];
  199. retval.regionUserSendKey = (string)reader["regionUserSendKey"];
  200. // World Map Addition
  201. string tempRegionMap = reader["regionMapTexture"].ToString();
  202. if (tempRegionMap != "")
  203. {
  204. retval.regionMapTextureID = new LLUUID(tempRegionMap);
  205. }
  206. else
  207. {
  208. retval.regionMapTextureID = new LLUUID();
  209. }
  210. }
  211. else
  212. {
  213. return null;
  214. }
  215. return retval;
  216. }
  217. /// <summary>
  218. /// Reads a reservation row from a database reader
  219. /// </summary>
  220. /// <param name="reader">An active database reader</param>
  221. /// <returns>A reservation data object</returns>
  222. public ReservationData readReservationRow(IDataReader reader)
  223. {
  224. ReservationData retval = new ReservationData();
  225. if (reader.Read())
  226. {
  227. retval.gridRecvKey = (string)reader["gridRecvKey"];
  228. retval.gridSendKey = (string)reader["gridSendKey"];
  229. retval.reservationCompany = (string)reader["resCompany"];
  230. retval.reservationMaxX = Convert.ToInt32(reader["resXMax"].ToString());
  231. retval.reservationMaxY = Convert.ToInt32(reader["resYMax"].ToString());
  232. retval.reservationMinX = Convert.ToInt32(reader["resXMin"].ToString());
  233. retval.reservationMinY = Convert.ToInt32(reader["resYMin"].ToString());
  234. retval.reservationName = (string)reader["resName"];
  235. retval.status = Convert.ToInt32(reader["status"].ToString()) == 1;
  236. retval.userUUID = new LLUUID((string)reader["userUUID"]);
  237. }
  238. else
  239. {
  240. return null;
  241. }
  242. return retval;
  243. }
  244. /// <summary>
  245. /// Reads an agent row from a database reader
  246. /// </summary>
  247. /// <param name="reader">An active database reader</param>
  248. /// <returns>A user session agent</returns>
  249. public UserAgentData readAgentRow(IDataReader reader)
  250. {
  251. UserAgentData retval = new UserAgentData();
  252. if (reader.Read())
  253. {
  254. // Agent IDs
  255. retval.UUID = new LLUUID((string)reader["UUID"]);
  256. retval.sessionID = new LLUUID((string)reader["sessionID"]);
  257. retval.secureSessionID = new LLUUID((string)reader["secureSessionID"]);
  258. // Agent Who?
  259. retval.agentIP = (string)reader["agentIP"];
  260. retval.agentPort = Convert.ToUInt32(reader["agentPort"].ToString());
  261. retval.agentOnline = Convert.ToBoolean(reader["agentOnline"].ToString());
  262. // Login/Logout times (UNIX Epoch)
  263. retval.loginTime = Convert.ToInt32(reader["loginTime"].ToString());
  264. retval.logoutTime = Convert.ToInt32(reader["logoutTime"].ToString());
  265. // Current position
  266. retval.currentRegion = (string)reader["currentRegion"];
  267. retval.currentHandle = Convert.ToUInt64(reader["currentHandle"].ToString());
  268. LLVector3.TryParse((string)reader["currentPos"], out retval.currentPos);
  269. }
  270. else
  271. {
  272. return null;
  273. }
  274. return retval;
  275. }
  276. /// <summary>
  277. /// Reads a user profile from an active data reader
  278. /// </summary>
  279. /// <param name="reader">An active database reader</param>
  280. /// <returns>A user profile</returns>
  281. public UserProfileData readUserRow(IDataReader reader)
  282. {
  283. UserProfileData retval = new UserProfileData();
  284. if (reader.Read())
  285. {
  286. retval.UUID = new LLUUID((string)reader["UUID"]);
  287. retval.username = (string)reader["username"];
  288. retval.surname = (string)reader["lastname"];
  289. retval.passwordHash = (string)reader["passwordHash"];
  290. retval.passwordSalt = (string)reader["passwordSalt"];
  291. retval.homeRegion = Convert.ToUInt64(reader["homeRegion"].ToString());
  292. retval.homeLocation = new LLVector3(
  293. Convert.ToSingle(reader["homeLocationX"].ToString()),
  294. Convert.ToSingle(reader["homeLocationY"].ToString()),
  295. Convert.ToSingle(reader["homeLocationZ"].ToString()));
  296. retval.homeLookAt = new LLVector3(
  297. Convert.ToSingle(reader["homeLookAtX"].ToString()),
  298. Convert.ToSingle(reader["homeLookAtY"].ToString()),
  299. Convert.ToSingle(reader["homeLookAtZ"].ToString()));
  300. retval.created = Convert.ToInt32(reader["created"].ToString());
  301. retval.lastLogin = Convert.ToInt32(reader["lastLogin"].ToString());
  302. retval.userInventoryURI = (string)reader["userInventoryURI"];
  303. retval.userAssetURI = (string)reader["userAssetURI"];
  304. retval.profileCanDoMask = Convert.ToUInt32(reader["profileCanDoMask"].ToString());
  305. retval.profileWantDoMask = Convert.ToUInt32(reader["profileWantDoMask"].ToString());
  306. retval.profileAboutText = (string)reader["profileAboutText"];
  307. retval.profileFirstText = (string)reader["profileFirstText"];
  308. retval.profileImage = new LLUUID((string)reader["profileImage"]);
  309. retval.profileFirstImage = new LLUUID((string)reader["profileFirstImage"]);
  310. }
  311. else
  312. {
  313. return null;
  314. }
  315. return retval;
  316. }
  317. /// <summary>
  318. /// Reads a list of inventory folders returned by a query.
  319. /// </summary>
  320. /// <param name="reader">A MySQL Data Reader</param>
  321. /// <returns>A List containing inventory folders</returns>
  322. public List<InventoryFolderBase> readInventoryFolders(IDataReader reader)
  323. {
  324. List<InventoryFolderBase> rows = new List<InventoryFolderBase>();
  325. while(reader.Read())
  326. {
  327. try
  328. {
  329. InventoryFolderBase folder = new InventoryFolderBase();
  330. folder.agentID = new LLUUID((string)reader["agentID"]);
  331. folder.parentID = new LLUUID((string)reader["parentFolderID"]);
  332. folder.folderID = new LLUUID((string)reader["folderID"]);
  333. folder.name = (string)reader["folderName"];
  334. rows.Add(folder);
  335. }
  336. catch (Exception e)
  337. {
  338. Console.WriteLine(e.ToString());
  339. }
  340. }
  341. return rows;
  342. }
  343. /// <summary>
  344. /// Reads a collection of items from an SQL result
  345. /// </summary>
  346. /// <param name="reader">The SQL Result</param>
  347. /// <returns>A List containing Inventory Items</returns>
  348. public List<InventoryItemBase> readInventoryItems(IDataReader reader)
  349. {
  350. List<InventoryItemBase> rows = new List<InventoryItemBase>();
  351. while (reader.Read())
  352. {
  353. try
  354. {
  355. InventoryItemBase item = new InventoryItemBase();
  356. item.assetID = new LLUUID((string)reader["assetID"]);
  357. item.avatarID = new LLUUID((string)reader["avatarID"]);
  358. item.inventoryCurrentPermissions = Convert.ToUInt32(reader["inventoryCurrentPermissions"].ToString());
  359. item.inventoryDescription = (string)reader["inventoryDescription"];
  360. item.inventoryID = new LLUUID((string)reader["inventoryID"]);
  361. item.inventoryName = (string)reader["inventoryName"];
  362. item.inventoryNextPermissions = Convert.ToUInt32(reader["inventoryNextPermissions"].ToString());
  363. item.parentFolderID = new LLUUID((string)reader["parentFolderID"]);
  364. item.assetType = Convert.ToInt32(reader["type"].ToString());
  365. rows.Add(item);
  366. }
  367. catch (Exception e)
  368. {
  369. Console.WriteLine(e.ToString());
  370. }
  371. }
  372. return rows;
  373. }
  374. /// <summary>
  375. /// Inserts a new row into the log database
  376. /// </summary>
  377. /// <param name="serverDaemon">The daemon which triggered this event</param>
  378. /// <param name="target">Who were we operating on when this occured (region UUID, user UUID, etc)</param>
  379. /// <param name="methodCall">The method call where the problem occured</param>
  380. /// <param name="arguments">The arguments passed to the method</param>
  381. /// <param name="priority">How critical is this?</param>
  382. /// <param name="logMessage">Extra message info</param>
  383. /// <returns>Saved successfully?</returns>
  384. public bool insertLogRow(string serverDaemon, string target, string methodCall, string arguments, int priority, string logMessage)
  385. {
  386. string sql = "INSERT INTO logs (`target`, `server`, `method`, `arguments`, `priority`, `message`) VALUES ";
  387. sql += "(?target, ?server, ?method, ?arguments, ?priority, ?message)";
  388. Dictionary<string, string> parameters = new Dictionary<string, string>();
  389. parameters["?server"] = serverDaemon;
  390. parameters["?target"] = target;
  391. parameters["?method"] = methodCall;
  392. parameters["?arguments"] = arguments;
  393. parameters["?priority"] = priority.ToString();
  394. parameters["?message"] = logMessage;
  395. bool returnval = false;
  396. try
  397. {
  398. IDbCommand result = Query(sql, parameters);
  399. if (result.ExecuteNonQuery() == 1)
  400. returnval = true;
  401. result.Dispose();
  402. }
  403. catch (Exception e)
  404. {
  405. Console.WriteLine(e.ToString());
  406. return false;
  407. }
  408. return returnval;
  409. }
  410. /// <summary>
  411. /// Inserts a new item into the database
  412. /// </summary>
  413. /// <param name="item">The item</param>
  414. /// <returns>Success?</returns>
  415. public bool insertItem(InventoryItemBase item)
  416. {
  417. string sql = "REPLACE INTO inventoryitems (inventoryID, assetID, type, parentFolderID, avatarID, inventoryName, inventoryDescription, inventoryNextPermissions, inventoryCurrentPermissions) VALUES ";
  418. sql += "(?inventoryID, ?assetID, ?type, ?parentFolderID, ?avatarID, ?inventoryName, ?inventoryDescription, ?inventoryNextPermissions, ?inventoryCurrentPermissions)";
  419. Dictionary<string, string> parameters = new Dictionary<string, string>();
  420. parameters["?inventoryID"] = item.inventoryID.ToStringHyphenated();
  421. parameters["?assetID"] = item.assetID.ToStringHyphenated();
  422. parameters["?type"] = item.assetType.ToString();
  423. parameters["?parentFolderID"] = item.parentFolderID.ToStringHyphenated();
  424. parameters["?avatarID"] = item.avatarID.ToStringHyphenated();
  425. parameters["?inventoryName"] = item.inventoryName;
  426. parameters["?inventoryDescription"] = item.inventoryDescription;
  427. parameters["?inventoryNextPermissions"] = item.inventoryNextPermissions.ToString();
  428. parameters["?inventoryCurrentPermissions"] = item.inventoryCurrentPermissions.ToString();
  429. bool returnval = false;
  430. try
  431. {
  432. IDbCommand result = Query(sql, parameters);
  433. if (result.ExecuteNonQuery() == 1)
  434. returnval = true;
  435. result.Dispose();
  436. }
  437. catch (Exception e)
  438. {
  439. Console.WriteLine(e.ToString());
  440. return false;
  441. }
  442. return returnval;
  443. }
  444. /// <summary>
  445. /// Inserts a new folder into the database
  446. /// </summary>
  447. /// <param name="folder">The folder</param>
  448. /// <returns>Success?</returns>
  449. public bool insertFolder(InventoryFolderBase folder)
  450. {
  451. string sql = "REPLACE INTO inventoryfolders (folderID, agentID, parentFolderID, folderName) VALUES ";
  452. sql += "(?folderID, ?agentID, ?parentFolderID, ?folderName)";
  453. Dictionary<string, string> parameters = new Dictionary<string, string>();
  454. parameters["?folderID"] = folder.folderID.ToStringHyphenated();
  455. parameters["?agentID"] = folder.agentID.ToStringHyphenated();
  456. parameters["?parentFolderID"] = folder.parentID.ToStringHyphenated();
  457. parameters["?folderName"] = folder.name;
  458. bool returnval = false;
  459. try
  460. {
  461. IDbCommand result = Query(sql, parameters);
  462. if (result.ExecuteNonQuery() == 1)
  463. returnval = true;
  464. result.Dispose();
  465. }
  466. catch (Exception e)
  467. {
  468. Console.WriteLine(e.ToString());
  469. return false;
  470. }
  471. return returnval;
  472. }
  473. /// <summary>
  474. /// Creates a new user and inserts it into the database
  475. /// </summary>
  476. /// <param name="uuid">User ID</param>
  477. /// <param name="username">First part of the login</param>
  478. /// <param name="lastname">Second part of the login</param>
  479. /// <param name="passwordHash">A salted hash of the users password</param>
  480. /// <param name="passwordSalt">The salt used for the password hash</param>
  481. /// <param name="homeRegion">A regionHandle of the users home region</param>
  482. /// <param name="homeLocX">Home region position vector</param>
  483. /// <param name="homeLocY">Home region position vector</param>
  484. /// <param name="homeLocZ">Home region position vector</param>
  485. /// <param name="homeLookAtX">Home region 'look at' vector</param>
  486. /// <param name="homeLookAtY">Home region 'look at' vector</param>
  487. /// <param name="homeLookAtZ">Home region 'look at' vector</param>
  488. /// <param name="created">Account created (unix timestamp)</param>
  489. /// <param name="lastlogin">Last login (unix timestamp)</param>
  490. /// <param name="inventoryURI">Users inventory URI</param>
  491. /// <param name="assetURI">Users asset URI</param>
  492. /// <param name="canDoMask">I can do mask</param>
  493. /// <param name="wantDoMask">I want to do mask</param>
  494. /// <param name="aboutText">Profile text</param>
  495. /// <param name="firstText">Firstlife text</param>
  496. /// <param name="profileImage">UUID for profile image</param>
  497. /// <param name="firstImage">UUID for firstlife image</param>
  498. /// <returns>Success?</returns>
  499. public bool insertUserRow(libsecondlife.LLUUID uuid, string username, string lastname, string passwordHash, string passwordSalt, UInt64 homeRegion, float homeLocX, float homeLocY, float homeLocZ,
  500. float homeLookAtX, float homeLookAtY, float homeLookAtZ, int created, int lastlogin, string inventoryURI, string assetURI, uint canDoMask, uint wantDoMask, string aboutText, string firstText,
  501. libsecondlife.LLUUID profileImage, libsecondlife.LLUUID firstImage)
  502. {
  503. string sql = "INSERT INTO users (`UUID`, `username`, `lastname`, `passwordHash`, `passwordSalt`, `homeRegion`, ";
  504. sql += "`homeLocationX`, `homeLocationY`, `homeLocationZ`, `homeLookAtX`, `homeLookAtY`, `homeLookAtZ`, `created`, ";
  505. sql += "`lastLogin`, `userInventoryURI`, `userAssetURI`, `profileCanDoMask`, `profileWantDoMask`, `profileAboutText`, ";
  506. sql += "`profileFirstText`, `profileImage`, `profileFirstImage`) VALUES ";
  507. sql += "(?UUID, ?username, ?lastname, ?passwordHash, ?passwordSalt, ?homeRegion, ";
  508. sql += "?homeLocationX, ?homeLocationY, ?homeLocationZ, ?homeLookAtX, ?homeLookAtY, ?homeLookAtZ, ?created, ";
  509. sql += "?lastLogin, ?userInventoryURI, ?userAssetURI, ?profileCanDoMask, ?profileWantDoMask, ?profileAboutText, ";
  510. sql += "?profileFirstText, ?profileImage, ?profileFirstImage)";
  511. Dictionary<string, string> parameters = new Dictionary<string, string>();
  512. parameters["?UUID"] = uuid.ToStringHyphenated();
  513. parameters["?username"] = username.ToString();
  514. parameters["?lastname"] = lastname.ToString();
  515. parameters["?passwordHash"] = passwordHash.ToString();
  516. parameters["?passwordSalt"] = passwordSalt.ToString();
  517. parameters["?homeRegion"] = homeRegion.ToString();
  518. parameters["?homeLocationX"] = homeLocX.ToString();
  519. parameters["?homeLocationY"] = homeLocY.ToString();
  520. parameters["?homeLocationZ"] = homeLocZ.ToString();
  521. parameters["?homeLookAtX"] = homeLookAtX.ToString();
  522. parameters["?homeLookAtY"] = homeLookAtY.ToString();
  523. parameters["?homeLookAtZ"] = homeLookAtZ.ToString();
  524. parameters["?created"] = created.ToString();
  525. parameters["?lastLogin"] = lastlogin.ToString();
  526. parameters["?userInventoryURI"] = "";
  527. parameters["?userAssetURI"] = "";
  528. parameters["?profileCanDoMask"] = "0";
  529. parameters["?profileWantDoMask"] = "0";
  530. parameters["?profileAboutText"] = "";
  531. parameters["?profileFirstText"] = "";
  532. parameters["?profileImage"] = libsecondlife.LLUUID.Zero.ToStringHyphenated();
  533. parameters["?profileFirstImage"] = libsecondlife.LLUUID.Zero.ToStringHyphenated();
  534. bool returnval = false;
  535. try
  536. {
  537. IDbCommand result = Query(sql, parameters);
  538. if (result.ExecuteNonQuery() == 1)
  539. returnval = true;
  540. result.Dispose();
  541. }
  542. catch (Exception e)
  543. {
  544. Console.WriteLine(e.ToString());
  545. return false;
  546. }
  547. return returnval;
  548. }
  549. /// <summary>
  550. /// Inserts a new region into the database
  551. /// </summary>
  552. /// <param name="profile">The region to insert</param>
  553. /// <returns>Success?</returns>
  554. public bool insertRegion(SimProfileData regiondata)
  555. {
  556. string sql = "REPLACE INTO regions (regionHandle, regionName, uuid, regionRecvKey, regionSecret, regionSendKey, regionDataURI, ";
  557. sql += "serverIP, serverPort, serverURI, locX, locY, locZ, eastOverrideHandle, westOverrideHandle, southOverrideHandle, northOverrideHandle, regionAssetURI, regionAssetRecvKey, ";
  558. sql += "regionAssetSendKey, regionUserURI, regionUserRecvKey, regionUserSendKey, regionMapTexture, serverHttpPort, serverRemotingPort) VALUES ";
  559. sql += "(?regionHandle, ?regionName, ?uuid, ?regionRecvKey, ?regionSecret, ?regionSendKey, ?regionDataURI, ";
  560. sql += "?serverIP, ?serverPort, ?serverURI, ?locX, ?locY, ?locZ, ?eastOverrideHandle, ?westOverrideHandle, ?southOverrideHandle, ?northOverrideHandle, ?regionAssetURI, ?regionAssetRecvKey, ";
  561. sql += "?regionAssetSendKey, ?regionUserURI, ?regionUserRecvKey, ?regionUserSendKey, ?regionMapTexture, ?serverHttpPort, ?serverRemotingPort);";
  562. Dictionary<string, string> parameters = new Dictionary<string, string>();
  563. parameters["?regionHandle"] = regiondata.regionHandle.ToString();
  564. parameters["?regionName"] = regiondata.regionName.ToString();
  565. parameters["?uuid"] = regiondata.UUID.ToStringHyphenated();
  566. parameters["?regionRecvKey"] = regiondata.regionRecvKey.ToString();
  567. parameters["?regionSecret"] = regiondata.regionSecret.ToString();
  568. parameters["?regionSendKey"] = regiondata.regionSendKey.ToString();
  569. parameters["?regionDataURI"] = regiondata.regionDataURI.ToString();
  570. parameters["?serverIP"] = regiondata.serverIP.ToString();
  571. parameters["?serverPort"] = regiondata.serverPort.ToString();
  572. parameters["?serverURI"] = regiondata.serverURI.ToString();
  573. parameters["?locX"] = regiondata.regionLocX.ToString();
  574. parameters["?locY"] = regiondata.regionLocY.ToString();
  575. parameters["?locZ"] = regiondata.regionLocZ.ToString();
  576. parameters["?eastOverrideHandle"] = regiondata.regionEastOverrideHandle.ToString();
  577. parameters["?westOverrideHandle"] = regiondata.regionWestOverrideHandle.ToString();
  578. parameters["?northOverrideHandle"] = regiondata.regionNorthOverrideHandle.ToString();
  579. parameters["?southOverrideHandle"] = regiondata.regionSouthOverrideHandle.ToString();
  580. parameters["?regionAssetURI"] = regiondata.regionAssetURI.ToString();
  581. parameters["?regionAssetRecvKey"] = regiondata.regionAssetRecvKey.ToString();
  582. parameters["?regionAssetSendKey"] = regiondata.regionAssetSendKey.ToString();
  583. parameters["?regionUserURI"] = regiondata.regionUserURI.ToString();
  584. parameters["?regionUserRecvKey"] = regiondata.regionUserRecvKey.ToString();
  585. parameters["?regionUserSendKey"] = regiondata.regionUserSendKey.ToString();
  586. parameters["?regionMapTexture"] = regiondata.regionMapTextureID.ToStringHyphenated();
  587. parameters["?serverHttpPort"] = regiondata.httpPort.ToString();
  588. parameters["?serverRemotingPort"] = regiondata.remotingPort.ToString();
  589. bool returnval = false;
  590. try
  591. {
  592. IDbCommand result = Query(sql, parameters);
  593. //Console.WriteLine(result.CommandText);
  594. int x;
  595. if ((x = result.ExecuteNonQuery()) > 0)
  596. {
  597. returnval = true;
  598. }
  599. result.Dispose();
  600. }
  601. catch (Exception e)
  602. {
  603. Console.WriteLine(e.ToString());
  604. return false;
  605. }
  606. return returnval;
  607. }
  608. }
  609. }