1
0

MySQLUserData.cs 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813
  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 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. using System;
  28. using System.Collections.Generic;
  29. using System.Data;
  30. using System.Reflection;
  31. using System.Text.RegularExpressions;
  32. using libsecondlife;
  33. using log4net;
  34. using OpenSim.Framework;
  35. using OpenSim.Data.Base;
  36. namespace OpenSim.Data.MySQL
  37. {
  38. /// <summary>
  39. /// A database interface class to a user profile storage system
  40. /// </summary>
  41. internal class MySQLUserData : UserDataBase
  42. {
  43. private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  44. /// <summary>
  45. /// Database manager for MySQL
  46. /// </summary>
  47. public MySQLManager database;
  48. private string m_agentsTableName;
  49. private string m_usersTableName;
  50. private string m_userFriendsTableName;
  51. private string m_appearanceTableName = "avatarappearance";
  52. private string m_connectString;
  53. /// <summary>
  54. /// Initialise User Interface
  55. /// Loads and initialises the MySQL storage plugin
  56. /// Warns and uses the obsolete mysql_connection.ini if connect string is empty.
  57. /// Checks for migration
  58. /// </summary>
  59. /// <param name="connect">connect string.</param>
  60. override public void Initialise(string connect)
  61. {
  62. if (connect == String.Empty) {
  63. // TODO: actually do something with our connect string
  64. // instead of loading the second config
  65. m_log.Warn("Using obsoletely mysql_connection.ini, try using user_source connect string instead");
  66. IniFile iniFile = new IniFile("mysql_connection.ini");
  67. string settingHostname = iniFile.ParseFileReadValue("hostname");
  68. string settingDatabase = iniFile.ParseFileReadValue("database");
  69. string settingUsername = iniFile.ParseFileReadValue("username");
  70. string settingPassword = iniFile.ParseFileReadValue("password");
  71. string settingPooling = iniFile.ParseFileReadValue("pooling");
  72. string settingPort = iniFile.ParseFileReadValue("port");
  73. m_usersTableName = iniFile.ParseFileReadValue("userstablename");
  74. if (m_usersTableName == null)
  75. {
  76. m_usersTableName = "users";
  77. }
  78. m_userFriendsTableName = iniFile.ParseFileReadValue("userfriendstablename");
  79. if (m_userFriendsTableName == null)
  80. {
  81. m_userFriendsTableName = "userfriends";
  82. }
  83. m_agentsTableName = iniFile.ParseFileReadValue("agentstablename");
  84. if (m_agentsTableName == null)
  85. {
  86. m_agentsTableName = "agents";
  87. }
  88. m_connectString = "Server=" + settingHostname + ";Port=" + settingPort + ";Database=" + settingDatabase + ";User ID=" +
  89. settingUsername + ";Password=" + settingPassword + ";Pooling=" + settingPooling + ";";
  90. database = new MySQLManager(m_connectString);
  91. }
  92. else
  93. {
  94. m_connectString = connect;
  95. m_agentsTableName = "agents";
  96. m_usersTableName = "users";
  97. m_userFriendsTableName = "userfriends";
  98. database = new MySQLManager(m_connectString);
  99. }
  100. // This actually does the roll forward assembly stuff
  101. Assembly assem = GetType().Assembly;
  102. Migration m = new Migration(database.Connection, assem, "UserStore");
  103. // TODO: After rev 6000, remove this. People should have
  104. // been rolled onto the new migration code by then.
  105. TestTables(m);
  106. m.Update();
  107. }
  108. #region Test and initialization code
  109. /// <summary>
  110. /// Ensure that the user related tables exists and are at the latest version
  111. /// </summary>
  112. private void TestTables(Migration m)
  113. {
  114. Dictionary<string, string> tableList = new Dictionary<string, string>();
  115. tableList[m_agentsTableName] = null;
  116. tableList[m_usersTableName] = null;
  117. tableList[m_userFriendsTableName] = null;
  118. tableList[m_appearanceTableName] = null;
  119. database.GetTableVersion(tableList);
  120. // if we've already started using migrations, get out of
  121. // here, we've got this under control
  122. if (m.Version > 0)
  123. return;
  124. // if there are no tables, get out of here and let
  125. // migrations do their job
  126. if (
  127. tableList[m_agentsTableName] == null &&
  128. tableList[m_usersTableName] == null &&
  129. tableList[m_userFriendsTableName] == null &&
  130. tableList[m_appearanceTableName] == null
  131. )
  132. return;
  133. // otherwise, let the upgrade on legacy proceed...
  134. UpgradeAgentsTable(tableList[m_agentsTableName]);
  135. UpgradeUsersTable(tableList[m_usersTableName]);
  136. UpgradeFriendsTable(tableList[m_userFriendsTableName]);
  137. UpgradeAppearanceTable(tableList[m_appearanceTableName]);
  138. // ... and set the version
  139. if (m.Version == 0)
  140. m.Version = 1;
  141. }
  142. /// <summary>
  143. /// Create or upgrade the table if necessary
  144. /// </summary>
  145. /// <param name="oldVersion">A null indicates that the table does not
  146. /// currently exist</param>
  147. private void UpgradeAgentsTable(string oldVersion)
  148. {
  149. // null as the version, indicates that the table didn't exist
  150. if (oldVersion == null)
  151. {
  152. database.ExecuteResourceSql("CreateAgentsTable.sql");
  153. return;
  154. }
  155. }
  156. /// <summary>
  157. /// Create or upgrade the table if necessary
  158. /// </summary>
  159. /// <param name="oldVersion">A null indicates that the table does not
  160. /// currently exist</param>
  161. private void UpgradeUsersTable(string oldVersion)
  162. {
  163. // null as the version, indicates that the table didn't exist
  164. if (oldVersion == null)
  165. {
  166. database.ExecuteResourceSql("CreateUsersTable.sql");
  167. return;
  168. }
  169. else if (oldVersion.Contains("Rev. 1"))
  170. {
  171. database.ExecuteResourceSql("UpgradeUsersTableToVersion2.sql");
  172. return;
  173. }
  174. //m_log.Info("[DB]: DBVers:" + oldVersion);
  175. }
  176. /// <summary>
  177. /// Create or upgrade the table if necessary
  178. /// </summary>
  179. /// <param name="oldVersion">A null indicates that the table does not
  180. /// currently exist</param>
  181. private void UpgradeFriendsTable(string oldVersion)
  182. {
  183. // null as the version, indicates that the table didn't exist
  184. if (oldVersion == null)
  185. {
  186. database.ExecuteResourceSql("CreateUserFriendsTable.sql");
  187. return;
  188. }
  189. }
  190. /// <summary>
  191. /// Create or upgrade the table if necessary
  192. /// </summary>
  193. /// <param name="oldVersion">A null indicates that the table does not
  194. /// currently exist</param>
  195. private void UpgradeAppearanceTable(string oldVersion)
  196. {
  197. // null as the version, indicates that the table didn't exist
  198. if (oldVersion == null)
  199. {
  200. database.ExecuteResourceSql("CreateAvatarAppearance.sql");
  201. return;
  202. }
  203. else if (oldVersion.Contains("Rev.1"))
  204. {
  205. database.ExecuteSql("drop table avatarappearance");
  206. database.ExecuteResourceSql("CreateAvatarAppearance.sql");
  207. return;
  208. }
  209. }
  210. #endregion
  211. // see IUserData
  212. override public UserProfileData GetUserByName(string user, string last)
  213. {
  214. try
  215. {
  216. lock (database)
  217. {
  218. Dictionary<string, string> param = new Dictionary<string, string>();
  219. param["?first"] = user;
  220. param["?second"] = last;
  221. IDbCommand result =
  222. database.Query("SELECT * FROM " + m_usersTableName + " WHERE username = ?first AND lastname = ?second", param);
  223. IDataReader reader = result.ExecuteReader();
  224. UserProfileData row = database.readUserRow(reader);
  225. reader.Close();
  226. result.Dispose();
  227. return row;
  228. }
  229. }
  230. catch (Exception e)
  231. {
  232. database.Reconnect();
  233. m_log.Error(e.ToString());
  234. return null;
  235. }
  236. }
  237. #region User Friends List Data
  238. override public void AddNewUserFriend(LLUUID friendlistowner, LLUUID friend, uint perms)
  239. {
  240. int dtvalue = Util.UnixTimeSinceEpoch();
  241. Dictionary<string, string> param = new Dictionary<string, string>();
  242. param["?ownerID"] = friendlistowner.UUID.ToString();
  243. param["?friendID"] = friend.UUID.ToString();
  244. param["?friendPerms"] = perms.ToString();
  245. param["?datetimestamp"] = dtvalue.ToString();
  246. try
  247. {
  248. lock (database)
  249. {
  250. IDbCommand adder =
  251. database.Query(
  252. "INSERT INTO `" + m_userFriendsTableName + "` " +
  253. "(`ownerID`,`friendID`,`friendPerms`,`datetimestamp`) " +
  254. "VALUES " +
  255. "(?ownerID,?friendID,?friendPerms,?datetimestamp)",
  256. param);
  257. adder.ExecuteNonQuery();
  258. adder =
  259. database.Query(
  260. "INSERT INTO `" + m_userFriendsTableName + "` " +
  261. "(`ownerID`,`friendID`,`friendPerms`,`datetimestamp`) " +
  262. "VALUES " +
  263. "(?friendID,?ownerID,?friendPerms,?datetimestamp)",
  264. param);
  265. adder.ExecuteNonQuery();
  266. }
  267. }
  268. catch (Exception e)
  269. {
  270. database.Reconnect();
  271. m_log.Error(e.ToString());
  272. return;
  273. }
  274. }
  275. override public void RemoveUserFriend(LLUUID friendlistowner, LLUUID friend)
  276. {
  277. Dictionary<string, string> param = new Dictionary<string, string>();
  278. param["?ownerID"] = friendlistowner.UUID.ToString();
  279. param["?friendID"] = friend.UUID.ToString();
  280. try
  281. {
  282. lock (database)
  283. {
  284. IDbCommand updater =
  285. database.Query(
  286. "delete from " + m_userFriendsTableName + " where ownerID = ?ownerID and friendID = ?friendID",
  287. param);
  288. updater.ExecuteNonQuery();
  289. updater =
  290. database.Query(
  291. "delete from " + m_userFriendsTableName + " where ownerID = ?friendID and friendID = ?ownerID",
  292. param);
  293. updater.ExecuteNonQuery();
  294. }
  295. }
  296. catch (Exception e)
  297. {
  298. database.Reconnect();
  299. m_log.Error(e.ToString());
  300. return;
  301. }
  302. }
  303. override public void UpdateUserFriendPerms(LLUUID friendlistowner, LLUUID friend, uint perms)
  304. {
  305. Dictionary<string, string> param = new Dictionary<string, string>();
  306. param["?ownerID"] = friendlistowner.UUID.ToString();
  307. param["?friendID"] = friend.UUID.ToString();
  308. param["?friendPerms"] = perms.ToString();
  309. try
  310. {
  311. lock (database)
  312. {
  313. IDbCommand updater =
  314. database.Query(
  315. "update " + m_userFriendsTableName +
  316. " SET friendPerms = ?friendPerms " +
  317. "where ownerID = ?ownerID and friendID = ?friendID",
  318. param);
  319. updater.ExecuteNonQuery();
  320. }
  321. }
  322. catch (Exception e)
  323. {
  324. database.Reconnect();
  325. m_log.Error(e.ToString());
  326. return;
  327. }
  328. }
  329. override public List<FriendListItem> GetUserFriendList(LLUUID friendlistowner)
  330. {
  331. List<FriendListItem> Lfli = new List<FriendListItem>();
  332. Dictionary<string, string> param = new Dictionary<string, string>();
  333. param["?ownerID"] = friendlistowner.UUID.ToString();
  334. try
  335. {
  336. lock (database)
  337. {
  338. //Left Join userfriends to itself
  339. IDbCommand result =
  340. database.Query(
  341. "select a.ownerID,a.friendID,a.friendPerms,b.friendPerms as ownerperms from " + m_userFriendsTableName + " as a, " + m_userFriendsTableName + " as b" +
  342. " where a.ownerID = ?ownerID and b.ownerID = a.friendID and b.friendID = a.ownerID",
  343. param);
  344. IDataReader reader = result.ExecuteReader();
  345. while (reader.Read())
  346. {
  347. FriendListItem fli = new FriendListItem();
  348. fli.FriendListOwner = new LLUUID((string)reader["ownerID"]);
  349. fli.Friend = new LLUUID((string)reader["friendID"]);
  350. fli.FriendPerms = (uint)Convert.ToInt32(reader["friendPerms"]);
  351. // This is not a real column in the database table, it's a joined column from the opposite record
  352. fli.FriendListOwnerPerms = (uint)Convert.ToInt32(reader["ownerperms"]);
  353. Lfli.Add(fli);
  354. }
  355. reader.Close();
  356. result.Dispose();
  357. }
  358. }
  359. catch (Exception e)
  360. {
  361. database.Reconnect();
  362. m_log.Error(e.ToString());
  363. return Lfli;
  364. }
  365. return Lfli;
  366. }
  367. #endregion
  368. override public void UpdateUserCurrentRegion(LLUUID avatarid, LLUUID regionuuid, ulong regionhandle)
  369. {
  370. //m_log.Info("[USER DB]: Stub UpdateUserCUrrentRegion called");
  371. }
  372. override public List<AvatarPickerAvatar> GeneratePickerResults(LLUUID queryID, string query)
  373. {
  374. List<AvatarPickerAvatar> returnlist = new List<AvatarPickerAvatar>();
  375. Regex objAlphaNumericPattern = new Regex("[^a-zA-Z0-9]");
  376. string[] querysplit;
  377. querysplit = query.Split(' ');
  378. if (querysplit.Length == 2)
  379. {
  380. Dictionary<string, string> param = new Dictionary<string, string>();
  381. param["?first"] = objAlphaNumericPattern.Replace(querysplit[0], String.Empty) + "%";
  382. param["?second"] = objAlphaNumericPattern.Replace(querysplit[1], String.Empty) + "%";
  383. try
  384. {
  385. lock (database)
  386. {
  387. IDbCommand result =
  388. database.Query(
  389. "SELECT UUID,username,lastname FROM " + m_usersTableName + " WHERE username like ?first AND lastname like ?second LIMIT 100",
  390. param);
  391. IDataReader reader = result.ExecuteReader();
  392. while (reader.Read())
  393. {
  394. AvatarPickerAvatar user = new AvatarPickerAvatar();
  395. user.AvatarID = new LLUUID((string) reader["UUID"]);
  396. user.firstName = (string) reader["username"];
  397. user.lastName = (string) reader["lastname"];
  398. returnlist.Add(user);
  399. }
  400. reader.Close();
  401. result.Dispose();
  402. }
  403. }
  404. catch (Exception e)
  405. {
  406. database.Reconnect();
  407. m_log.Error(e.ToString());
  408. return returnlist;
  409. }
  410. }
  411. else if (querysplit.Length == 1)
  412. {
  413. try
  414. {
  415. lock (database)
  416. {
  417. Dictionary<string, string> param = new Dictionary<string, string>();
  418. param["?first"] = objAlphaNumericPattern.Replace(querysplit[0], String.Empty) + "%";
  419. IDbCommand result =
  420. database.Query(
  421. "SELECT UUID,username,lastname FROM " + m_usersTableName + " WHERE username like ?first OR lastname like ?first LIMIT 100",
  422. param);
  423. IDataReader reader = result.ExecuteReader();
  424. while (reader.Read())
  425. {
  426. AvatarPickerAvatar user = new AvatarPickerAvatar();
  427. user.AvatarID = new LLUUID((string) reader["UUID"]);
  428. user.firstName = (string) reader["username"];
  429. user.lastName = (string) reader["lastname"];
  430. returnlist.Add(user);
  431. }
  432. reader.Close();
  433. result.Dispose();
  434. }
  435. }
  436. catch (Exception e)
  437. {
  438. database.Reconnect();
  439. m_log.Error(e.ToString());
  440. return returnlist;
  441. }
  442. }
  443. return returnlist;
  444. }
  445. /// <summary>
  446. /// See IUserData
  447. /// </summary>
  448. /// <param name="uuid">User UUID</param>
  449. /// <returns>User profile data</returns>
  450. override public UserProfileData GetUserByUUID(LLUUID uuid)
  451. {
  452. try
  453. {
  454. lock (database)
  455. {
  456. Dictionary<string, string> param = new Dictionary<string, string>();
  457. param["?uuid"] = uuid.ToString();
  458. IDbCommand result = database.Query("SELECT * FROM " + m_usersTableName + " WHERE UUID = ?uuid", param);
  459. IDataReader reader = result.ExecuteReader();
  460. UserProfileData row = database.readUserRow(reader);
  461. reader.Close();
  462. result.Dispose();
  463. return row;
  464. }
  465. }
  466. catch (Exception e)
  467. {
  468. database.Reconnect();
  469. m_log.Error(e.ToString());
  470. return null;
  471. }
  472. }
  473. /// <summary>
  474. /// Returns a user session searching by name
  475. /// </summary>
  476. /// <param name="name">The account name : "Username Lastname"</param>
  477. /// <returns>The users session</returns>
  478. override public UserAgentData GetAgentByName(string name)
  479. {
  480. return GetAgentByName(name.Split(' ')[0], name.Split(' ')[1]);
  481. }
  482. /// <summary>
  483. /// Returns a user session by account name
  484. /// </summary>
  485. /// <param name="user">First part of the users account name</param>
  486. /// <param name="last">Second part of the users account name</param>
  487. /// <returns>The users session</returns>
  488. override public UserAgentData GetAgentByName(string user, string last)
  489. {
  490. UserProfileData profile = GetUserByName(user, last);
  491. return GetAgentByUUID(profile.ID);
  492. }
  493. /// <summary>
  494. /// </summary>
  495. /// <param name="AgentID"></param>
  496. /// <param name="WebLoginKey"></param>
  497. /// <remarks>is it still used ?</remarks>
  498. override public void StoreWebLoginKey(LLUUID AgentID, LLUUID WebLoginKey)
  499. {
  500. Dictionary<string, string> param = new Dictionary<string, string>();
  501. param["?UUID"] = AgentID.UUID.ToString();
  502. param["?webLoginKey"] = WebLoginKey.UUID.ToString();
  503. try
  504. {
  505. lock (database)
  506. {
  507. IDbCommand updater =
  508. database.Query(
  509. "update " + m_usersTableName + " SET webLoginKey = ?webLoginKey " +
  510. "where UUID = ?UUID",
  511. param);
  512. updater.ExecuteNonQuery();
  513. }
  514. }
  515. catch (Exception e)
  516. {
  517. database.Reconnect();
  518. m_log.Error(e.ToString());
  519. return;
  520. }
  521. }
  522. /// <summary>
  523. /// Returns an agent session by account UUID
  524. /// </summary>
  525. /// <param name="uuid">The accounts UUID</param>
  526. /// <returns>The users session</returns>
  527. override public UserAgentData GetAgentByUUID(LLUUID uuid)
  528. {
  529. try
  530. {
  531. lock (database)
  532. {
  533. Dictionary<string, string> param = new Dictionary<string, string>();
  534. param["?uuid"] = uuid.ToString();
  535. IDbCommand result = database.Query("SELECT * FROM " + m_agentsTableName + " WHERE UUID = ?uuid", param);
  536. IDataReader reader = result.ExecuteReader();
  537. UserAgentData row = database.readAgentRow(reader);
  538. reader.Close();
  539. result.Dispose();
  540. return row;
  541. }
  542. }
  543. catch (Exception e)
  544. {
  545. database.Reconnect();
  546. m_log.Error(e.ToString());
  547. return null;
  548. }
  549. }
  550. /// <summary>
  551. /// Creates a new users profile
  552. /// </summary>
  553. /// <param name="user">The user profile to create</param>
  554. override public void AddNewUserProfile(UserProfileData user)
  555. {
  556. try
  557. {
  558. lock (database)
  559. {
  560. database.insertUserRow(user.ID, user.FirstName, user.SurName, user.PasswordHash, user.PasswordSalt,
  561. user.HomeRegion, user.HomeLocation.X, user.HomeLocation.Y,
  562. user.HomeLocation.Z,
  563. user.HomeLookAt.X, user.HomeLookAt.Y, user.HomeLookAt.Z, user.Created,
  564. user.LastLogin, user.UserInventoryURI, user.UserAssetURI,
  565. user.CanDoMask, user.WantDoMask,
  566. user.AboutText, user.FirstLifeAboutText, user.Image,
  567. user.FirstLifeImage, user.WebLoginKey);
  568. }
  569. }
  570. catch (Exception e)
  571. {
  572. database.Reconnect();
  573. m_log.Error(e.ToString());
  574. }
  575. }
  576. /// <summary>
  577. /// Creates a new agent
  578. /// </summary>
  579. /// <param name="agent">The agent to create</param>
  580. override public void AddNewUserAgent(UserAgentData agent)
  581. {
  582. try
  583. {
  584. lock (database)
  585. {
  586. database.insertAgentRow(agent);
  587. }
  588. }
  589. catch (Exception e)
  590. {
  591. database.Reconnect();
  592. m_log.Error(e.ToString());
  593. }
  594. }
  595. /// <summary>
  596. /// Updates a user profile stored in the DB
  597. /// </summary>
  598. /// <param name="user">The profile data to use to update the DB</param>
  599. override public bool UpdateUserProfile(UserProfileData user)
  600. {
  601. lock (database)
  602. {
  603. database.updateUserRow(user.ID, user.FirstName, user.SurName, user.PasswordHash, user.PasswordSalt,
  604. user.HomeRegion, user.HomeLocation.X, user.HomeLocation.Y, user.HomeLocation.Z, user.HomeLookAt.X,
  605. user.HomeLookAt.Y, user.HomeLookAt.Z, user.Created, user.LastLogin, user.UserInventoryURI,
  606. user.UserAssetURI, user.CanDoMask, user.WantDoMask, user.AboutText,
  607. user.FirstLifeAboutText, user.Image, user.FirstLifeImage, user.WebLoginKey);
  608. }
  609. return true;
  610. }
  611. /// <summary>
  612. /// Performs a money transfer request between two accounts
  613. /// </summary>
  614. /// <param name="from">The senders account ID</param>
  615. /// <param name="to">The receivers account ID</param>
  616. /// <param name="amount">The amount to transfer</param>
  617. /// <returns>Success?</returns>
  618. override public bool MoneyTransferRequest(LLUUID from, LLUUID to, uint amount)
  619. {
  620. return false;
  621. }
  622. /// <summary>
  623. /// Performs an inventory transfer request between two accounts
  624. /// </summary>
  625. /// <remarks>TODO: Move to inventory server</remarks>
  626. /// <param name="from">The senders account ID</param>
  627. /// <param name="to">The receivers account ID</param>
  628. /// <param name="item">The item to transfer</param>
  629. /// <returns>Success?</returns>
  630. override public bool InventoryTransferRequest(LLUUID from, LLUUID to, LLUUID item)
  631. {
  632. return false;
  633. }
  634. /// <summary>
  635. /// Appearance
  636. /// TODO: stubs for now to get us to a compiling state gently
  637. /// override
  638. /// </summary>
  639. override public AvatarAppearance GetUserAppearance(LLUUID user)
  640. {
  641. try {
  642. lock (database)
  643. {
  644. Dictionary<string, string> param = new Dictionary<string, string>();
  645. param["?owner"] = user.ToString();
  646. IDbCommand result = database.Query("SELECT * FROM " + m_appearanceTableName + " WHERE owner = ?owner", param);
  647. IDataReader reader = result.ExecuteReader();
  648. AvatarAppearance appearance = database.readAppearanceRow(reader);
  649. reader.Close();
  650. result.Dispose();
  651. return appearance;
  652. }
  653. }
  654. catch (Exception e)
  655. {
  656. database.Reconnect();
  657. m_log.Error(e.ToString());
  658. return null;
  659. }
  660. }
  661. /// <summary>
  662. /// Updates an avatar appearence
  663. /// </summary>
  664. /// <param name="user">The user UUID</param>
  665. /// <param name="appearance">The avatar appearance</param>
  666. // override
  667. override public void UpdateUserAppearance(LLUUID user, AvatarAppearance appearance)
  668. {
  669. try
  670. {
  671. lock (database)
  672. {
  673. appearance.Owner = user;
  674. database.insertAppearanceRow(appearance);
  675. }
  676. }
  677. catch (Exception e)
  678. {
  679. database.Reconnect();
  680. m_log.Error(e.ToString());
  681. }
  682. }
  683. /// <summary>
  684. /// Adds an attachment item to a user
  685. /// </summary>
  686. /// <param name="user">the user UUID</param>
  687. /// <param name="item">the item UUID</param>
  688. override public void AddAttachment(LLUUID user, LLUUID item)
  689. {
  690. return;
  691. }
  692. /// <summary>
  693. /// Removes an attachment from a user
  694. /// </summary>
  695. /// <param name="user">the user UUID</param>
  696. /// <param name="item">the item UUID</param>
  697. override public void RemoveAttachment(LLUUID user, LLUUID item)
  698. {
  699. return;
  700. }
  701. /// <summary>
  702. /// Get the list of item attached to a user
  703. /// </summary>
  704. /// <param name="user">the user UUID</param>
  705. /// <returns>UUID list of attached item</returns>
  706. override public List<LLUUID> GetAttachments(LLUUID user)
  707. {
  708. return new List<LLUUID>();
  709. }
  710. /// <summary>
  711. /// Database provider name
  712. /// </summary>
  713. /// <returns>Provider name</returns>
  714. override public string Name
  715. {
  716. get {return "MySQL Userdata Interface";}
  717. }
  718. /// <summary>
  719. /// Database provider version
  720. /// </summary>
  721. /// <returns>provider version</returns>
  722. override public string Version
  723. {
  724. get {return "0.1";}
  725. }
  726. }
  727. }