MySQLUserProfilesData.cs 44 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048
  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.Data;
  29. using System.Reflection;
  30. using OpenSim.Data;
  31. using OpenSim.Framework;
  32. using MySql.Data.MySqlClient;
  33. using OpenMetaverse;
  34. using OpenMetaverse.StructuredData;
  35. using log4net;
  36. namespace OpenSim.Data.MySQL
  37. {
  38. public class UserProfilesData: IProfilesData
  39. {
  40. static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  41. #region Properites
  42. string ConnectionString
  43. {
  44. get; set;
  45. }
  46. protected virtual Assembly Assembly
  47. {
  48. get { return GetType().Assembly; }
  49. }
  50. #endregion Properties
  51. #region class Member Functions
  52. public UserProfilesData(string connectionString)
  53. {
  54. ConnectionString = connectionString;
  55. Init();
  56. }
  57. void Init()
  58. {
  59. using (MySqlConnection dbcon = new MySqlConnection(ConnectionString))
  60. {
  61. dbcon.Open();
  62. Migration m = new Migration(dbcon, Assembly, "UserProfiles");
  63. m.Update();
  64. dbcon.Close();
  65. }
  66. }
  67. #endregion Member Functions
  68. #region Classifieds Queries
  69. /// <summary>
  70. /// Gets the classified records.
  71. /// </summary>
  72. /// <returns>
  73. /// Array of classified records
  74. /// </returns>
  75. /// <param name='creatorId'>
  76. /// Creator identifier.
  77. /// </param>
  78. public OSDArray GetClassifiedRecords(UUID creatorId)
  79. {
  80. OSDArray data = new OSDArray();
  81. using (MySqlConnection dbcon = new MySqlConnection(ConnectionString))
  82. {
  83. const string query = "SELECT classifieduuid, name FROM classifieds WHERE creatoruuid = ?Id";
  84. dbcon.Open();
  85. using (MySqlCommand cmd = new MySqlCommand(query, dbcon))
  86. {
  87. cmd.Parameters.AddWithValue("?Id", creatorId);
  88. using( MySqlDataReader reader = cmd.ExecuteReader(CommandBehavior.Default))
  89. {
  90. if(reader.HasRows)
  91. {
  92. while (reader.Read())
  93. {
  94. OSDMap n = new OSDMap();
  95. UUID Id = UUID.Zero;
  96. string Name = null;
  97. try
  98. {
  99. UUID.TryParse(Convert.ToString( reader["classifieduuid"]), out Id);
  100. Name = Convert.ToString(reader["name"]);
  101. }
  102. catch (Exception e)
  103. {
  104. m_log.ErrorFormat("[PROFILES_DATA]" +
  105. ": UserAccount exception {0}", e.Message);
  106. }
  107. n.Add("classifieduuid", OSD.FromUUID(Id));
  108. n.Add("name", OSD.FromString(Name));
  109. data.Add(n);
  110. }
  111. }
  112. }
  113. }
  114. dbcon.Close();
  115. }
  116. return data;
  117. }
  118. public bool UpdateClassifiedRecord(UserClassifiedAdd ad, ref string result)
  119. {
  120. const string query =
  121. "INSERT INTO classifieds ("
  122. + "`classifieduuid`,"
  123. + "`creatoruuid`,"
  124. + "`creationdate`,"
  125. + "`expirationdate`,"
  126. + "`category`,"
  127. + "`name`,"
  128. + "`description`,"
  129. + "`parceluuid`,"
  130. + "`parentestate`,"
  131. + "`snapshotuuid`,"
  132. + "`simname`,"
  133. + "`posglobal`,"
  134. + "`parcelname`,"
  135. + "`classifiedflags`,"
  136. + "`priceforlisting`) "
  137. + "VALUES ("
  138. + "?ClassifiedId,"
  139. + "?CreatorId,"
  140. + "?CreatedDate,"
  141. + "?ExpirationDate,"
  142. + "?Category,"
  143. + "?Name,"
  144. + "?Description,"
  145. + "?ParcelId,"
  146. + "?ParentEstate,"
  147. + "?SnapshotId,"
  148. + "?SimName,"
  149. + "?GlobalPos,"
  150. + "?ParcelName,"
  151. + "?Flags,"
  152. + "?ListingPrice ) "
  153. + "ON DUPLICATE KEY UPDATE "
  154. + "category=?Category, "
  155. + "expirationdate=?ExpirationDate, "
  156. + "name=?Name, "
  157. + "description=?Description, "
  158. + "parentestate=?ParentEstate, "
  159. + "posglobal=?GlobalPos, "
  160. + "parcelname=?ParcelName, "
  161. + "classifiedflags=?Flags, "
  162. + "priceforlisting=?ListingPrice, "
  163. + "snapshotuuid=?SnapshotId"
  164. ;
  165. if(string.IsNullOrEmpty(ad.ParcelName))
  166. ad.ParcelName = "Unknown";
  167. if(ad.ParcelId == null)
  168. ad.ParcelId = UUID.Zero;
  169. if(string.IsNullOrEmpty(ad.Description))
  170. ad.Description = "No Description";
  171. DateTime epoch = new DateTime(1970, 1, 1);
  172. DateTime now = DateTime.Now;
  173. TimeSpan epochnow = now - epoch;
  174. TimeSpan duration;
  175. DateTime expiration;
  176. TimeSpan epochexp;
  177. if(ad.Flags == 2)
  178. {
  179. duration = new TimeSpan(7,0,0,0);
  180. expiration = now.Add(duration);
  181. epochexp = expiration - epoch;
  182. }
  183. else
  184. {
  185. duration = new TimeSpan(365,0,0,0);
  186. expiration = now.Add(duration);
  187. epochexp = expiration - epoch;
  188. }
  189. ad.CreationDate = (int)epochnow.TotalSeconds;
  190. ad.ExpirationDate = (int)epochexp.TotalSeconds;
  191. try
  192. {
  193. using (MySqlConnection dbcon = new MySqlConnection(ConnectionString))
  194. {
  195. dbcon.Open();
  196. using (MySqlCommand cmd = new MySqlCommand(query, dbcon))
  197. {
  198. cmd.Parameters.AddWithValue("?ClassifiedId", ad.ClassifiedId.ToString());
  199. cmd.Parameters.AddWithValue("?CreatorId", ad.CreatorId.ToString());
  200. cmd.Parameters.AddWithValue("?CreatedDate", ad.CreationDate.ToString());
  201. cmd.Parameters.AddWithValue("?ExpirationDate", ad.ExpirationDate.ToString());
  202. cmd.Parameters.AddWithValue("?Category", ad.Category.ToString());
  203. cmd.Parameters.AddWithValue("?Name", ad.Name.ToString());
  204. cmd.Parameters.AddWithValue("?Description", ad.Description.ToString());
  205. cmd.Parameters.AddWithValue("?ParcelId", ad.ParcelId.ToString());
  206. cmd.Parameters.AddWithValue("?ParentEstate", ad.ParentEstate.ToString());
  207. cmd.Parameters.AddWithValue("?SnapshotId", ad.SnapshotId.ToString ());
  208. cmd.Parameters.AddWithValue("?SimName", ad.SimName.ToString());
  209. cmd.Parameters.AddWithValue("?GlobalPos", ad.GlobalPos.ToString());
  210. cmd.Parameters.AddWithValue("?ParcelName", ad.ParcelName.ToString());
  211. cmd.Parameters.AddWithValue("?Flags", ad.Flags.ToString());
  212. cmd.Parameters.AddWithValue("?ListingPrice", ad.Price.ToString ());
  213. cmd.ExecuteNonQuery();
  214. }
  215. dbcon.Close();
  216. }
  217. }
  218. catch (Exception e)
  219. {
  220. m_log.ErrorFormat("[PROFILES_DATA]" +
  221. ": ClassifiedesUpdate exception {0}", e.Message);
  222. result = e.Message;
  223. return false;
  224. }
  225. return true;
  226. }
  227. public bool DeleteClassifiedRecord(UUID recordId)
  228. {
  229. const string query = "DELETE FROM classifieds WHERE classifieduuid = ?recordId";
  230. try
  231. {
  232. using (MySqlConnection dbcon = new MySqlConnection(ConnectionString))
  233. {
  234. dbcon.Open();
  235. using (MySqlCommand cmd = new MySqlCommand(query, dbcon))
  236. {
  237. cmd.Parameters.AddWithValue("?recordId", recordId.ToString());
  238. cmd.ExecuteNonQuery();
  239. }
  240. dbcon.Close();
  241. }
  242. }
  243. catch (Exception e)
  244. {
  245. m_log.ErrorFormat("[PROFILES_DATA]" +
  246. ": DeleteClassifiedRecord exception {0}", e.Message);
  247. return false;
  248. }
  249. return true;
  250. }
  251. public bool GetClassifiedInfo(ref UserClassifiedAdd ad, ref string result)
  252. {
  253. const string query = "SELECT * FROM classifieds WHERE classifieduuid = ?AdId";
  254. try
  255. {
  256. using (MySqlConnection dbcon = new MySqlConnection(ConnectionString))
  257. {
  258. dbcon.Open();
  259. using (MySqlCommand cmd = new MySqlCommand(query, dbcon))
  260. {
  261. cmd.Parameters.AddWithValue("?AdId", ad.ClassifiedId.ToString());
  262. using (MySqlDataReader reader = cmd.ExecuteReader())
  263. {
  264. if(reader.Read ())
  265. {
  266. ad.CreatorId = new UUID(reader.GetGuid("creatoruuid"));
  267. ad.ParcelId = new UUID(reader.GetGuid("parceluuid"));
  268. ad.SnapshotId = new UUID(reader.GetGuid("snapshotuuid"));
  269. ad.CreationDate = Convert.ToInt32(reader["creationdate"]);
  270. ad.ExpirationDate = Convert.ToInt32(reader["expirationdate"]);
  271. ad.ParentEstate = Convert.ToInt32(reader["parentestate"]);
  272. ad.Flags = (byte)reader.GetUInt32("classifiedflags");
  273. ad.Category = reader.GetInt32("category");
  274. ad.Price = reader.GetInt16("priceforlisting");
  275. ad.Name = reader.GetString("name");
  276. ad.Description = reader.GetString("description");
  277. ad.SimName = reader.GetString("simname");
  278. ad.GlobalPos = reader.GetString("posglobal");
  279. ad.ParcelName = reader.GetString("parcelname");
  280. }
  281. }
  282. }
  283. dbcon.Close();
  284. }
  285. }
  286. catch (Exception e)
  287. {
  288. m_log.ErrorFormat("[PROFILES_DATA]" +
  289. ": GetPickInfo exception {0}", e.Message);
  290. }
  291. return true;
  292. }
  293. #endregion Classifieds Queries
  294. #region Picks Queries
  295. public OSDArray GetAvatarPicks(UUID avatarId)
  296. {
  297. const string query = "SELECT `pickuuid`,`name` FROM userpicks WHERE creatoruuid = ?Id";
  298. OSDArray data = new OSDArray();
  299. try
  300. {
  301. using (MySqlConnection dbcon = new MySqlConnection(ConnectionString))
  302. {
  303. dbcon.Open();
  304. using (MySqlCommand cmd = new MySqlCommand(query, dbcon))
  305. {
  306. cmd.Parameters.AddWithValue("?Id", avatarId.ToString());
  307. using (MySqlDataReader reader = cmd.ExecuteReader())
  308. {
  309. if(reader.HasRows)
  310. {
  311. while (reader.Read())
  312. {
  313. OSDMap record = new OSDMap();
  314. record.Add("pickuuid",OSD.FromString((string)reader["pickuuid"]));
  315. record.Add("name",OSD.FromString((string)reader["name"]));
  316. data.Add(record);
  317. }
  318. }
  319. }
  320. }
  321. dbcon.Close();
  322. }
  323. }
  324. catch (Exception e)
  325. {
  326. m_log.ErrorFormat("[PROFILES_DATA]" +
  327. ": GetAvatarPicks exception {0}", e.Message);
  328. }
  329. return data;
  330. }
  331. public UserProfilePick GetPickInfo(UUID avatarId, UUID pickId)
  332. {
  333. UserProfilePick pick = new UserProfilePick();
  334. const string query = "SELECT * FROM userpicks WHERE creatoruuid = ?CreatorId AND pickuuid = ?PickId";
  335. try
  336. {
  337. using (MySqlConnection dbcon = new MySqlConnection(ConnectionString))
  338. {
  339. dbcon.Open();
  340. using (MySqlCommand cmd = new MySqlCommand(query, dbcon))
  341. {
  342. cmd.Parameters.AddWithValue("?CreatorId", avatarId.ToString());
  343. cmd.Parameters.AddWithValue("?PickId", pickId.ToString());
  344. using (MySqlDataReader reader = cmd.ExecuteReader())
  345. {
  346. if(reader.HasRows)
  347. {
  348. reader.Read();
  349. string description = (string)reader["description"];
  350. if (string.IsNullOrEmpty(description))
  351. description = "No description given.";
  352. UUID.TryParse((string)reader["pickuuid"], out pick.PickId);
  353. UUID.TryParse((string)reader["creatoruuid"], out pick.CreatorId);
  354. UUID.TryParse((string)reader["parceluuid"], out pick.ParcelId);
  355. UUID.TryParse((string)reader["snapshotuuid"], out pick.SnapshotId);
  356. pick.GlobalPos = (string)reader["posglobal"];
  357. pick.Gatekeeper = (string)reader["gatekeeper"];
  358. bool.TryParse((string)reader["toppick"], out pick.TopPick);
  359. bool.TryParse((string)reader["enabled"], out pick.Enabled);
  360. pick.Name = (string)reader["name"];
  361. pick.Desc = description;
  362. pick.ParcelName = (string)reader["user"];
  363. pick.OriginalName = (string)reader["originalname"];
  364. pick.SimName = (string)reader["simname"];
  365. pick.SortOrder = (int)reader["sortorder"];
  366. }
  367. }
  368. }
  369. dbcon.Close();
  370. }
  371. }
  372. catch (Exception e)
  373. {
  374. m_log.ErrorFormat("[PROFILES_DATA]" +
  375. ": GetPickInfo exception {0}", e.Message);
  376. }
  377. return pick;
  378. }
  379. public bool UpdatePicksRecord(UserProfilePick pick)
  380. {
  381. const string query =
  382. "INSERT INTO userpicks VALUES ("
  383. + "?PickId,"
  384. + "?CreatorId,"
  385. + "?TopPick,"
  386. + "?ParcelId,"
  387. + "?Name,"
  388. + "?Desc,"
  389. + "?SnapshotId,"
  390. + "?User,"
  391. + "?Original,"
  392. + "?SimName,"
  393. + "?GlobalPos,"
  394. + "?SortOrder,"
  395. + "?Enabled,"
  396. + "?Gatekeeper)"
  397. + "ON DUPLICATE KEY UPDATE "
  398. + "parceluuid=?ParcelId,"
  399. + "name=?Name,"
  400. + "description=?Desc,"
  401. + "user=?User,"
  402. + "simname=?SimName,"
  403. + "snapshotuuid=?SnapshotId,"
  404. + "pickuuid=?PickId,"
  405. + "posglobal=?GlobalPos,"
  406. + "gatekeeper=?Gatekeeper"
  407. ;
  408. try
  409. {
  410. using (MySqlConnection dbcon = new MySqlConnection(ConnectionString))
  411. {
  412. dbcon.Open();
  413. using (MySqlCommand cmd = new MySqlCommand(query, dbcon))
  414. {
  415. cmd.Parameters.AddWithValue("?PickId", pick.PickId.ToString());
  416. cmd.Parameters.AddWithValue("?CreatorId", pick.CreatorId.ToString());
  417. cmd.Parameters.AddWithValue("?TopPick", pick.TopPick.ToString());
  418. cmd.Parameters.AddWithValue("?ParcelId", pick.ParcelId.ToString());
  419. cmd.Parameters.AddWithValue("?Name", pick.Name.ToString());
  420. cmd.Parameters.AddWithValue("?Desc", pick.Desc.ToString());
  421. cmd.Parameters.AddWithValue("?SnapshotId", pick.SnapshotId.ToString());
  422. cmd.Parameters.AddWithValue("?User", pick.ParcelName.ToString());
  423. cmd.Parameters.AddWithValue("?Original", pick.OriginalName.ToString());
  424. cmd.Parameters.AddWithValue("?SimName",pick.SimName.ToString());
  425. cmd.Parameters.AddWithValue("?GlobalPos", pick.GlobalPos);
  426. cmd.Parameters.AddWithValue("?Gatekeeper",pick.Gatekeeper);
  427. cmd.Parameters.AddWithValue("?SortOrder", pick.SortOrder.ToString ());
  428. cmd.Parameters.AddWithValue("?Enabled", pick.Enabled.ToString());
  429. cmd.ExecuteNonQuery();
  430. }
  431. dbcon.Close();
  432. }
  433. }
  434. catch (Exception e)
  435. {
  436. m_log.ErrorFormat("[PROFILES_DATA]" +
  437. ": UpdateAvatarNotes exception {0}", e.Message);
  438. return false;
  439. }
  440. return true;
  441. }
  442. public bool DeletePicksRecord(UUID pickId)
  443. {
  444. string query = "DELETE FROM userpicks WHERE pickuuid = ?PickId";
  445. try
  446. {
  447. using (MySqlConnection dbcon = new MySqlConnection(ConnectionString))
  448. {
  449. dbcon.Open();
  450. using (MySqlCommand cmd = new MySqlCommand(query, dbcon))
  451. {
  452. cmd.Parameters.AddWithValue("?PickId", pickId.ToString());
  453. cmd.ExecuteNonQuery();
  454. }
  455. dbcon.Close();
  456. }
  457. }
  458. catch (Exception e)
  459. {
  460. m_log.ErrorFormat("[PROFILES_DATA]" +
  461. ": DeleteUserPickRecord exception {0}", e.Message);
  462. return false;
  463. }
  464. return true;
  465. }
  466. #endregion Picks Queries
  467. #region Avatar Notes Queries
  468. public bool GetAvatarNotes(ref UserProfileNotes notes)
  469. { // WIP
  470. const string query = "SELECT `notes` FROM usernotes WHERE useruuid = ?Id AND targetuuid = ?TargetId";
  471. try
  472. {
  473. using (MySqlConnection dbcon = new MySqlConnection(ConnectionString))
  474. {
  475. dbcon.Open();
  476. using (MySqlCommand cmd = new MySqlCommand(query, dbcon))
  477. {
  478. cmd.Parameters.AddWithValue("?Id", notes.UserId.ToString());
  479. cmd.Parameters.AddWithValue("?TargetId", notes.TargetId.ToString());
  480. using (MySqlDataReader reader = cmd.ExecuteReader(CommandBehavior.SingleRow))
  481. {
  482. if(reader.HasRows)
  483. {
  484. reader.Read();
  485. notes.Notes = OSD.FromString((string)reader["notes"]);
  486. }
  487. else
  488. {
  489. notes.Notes = OSD.FromString("");
  490. }
  491. }
  492. }
  493. dbcon.Close();
  494. }
  495. }
  496. catch (Exception e)
  497. {
  498. m_log.ErrorFormat("[PROFILES_DATA]" +
  499. ": GetAvatarNotes exception {0}", e.Message);
  500. }
  501. return true;
  502. }
  503. public bool UpdateAvatarNotes(ref UserProfileNotes note, ref string result)
  504. {
  505. string query;
  506. bool remove;
  507. if(string.IsNullOrEmpty(note.Notes))
  508. {
  509. remove = true;
  510. query = "DELETE FROM usernotes WHERE useruuid=?UserId AND targetuuid=?TargetId";
  511. }
  512. else
  513. {
  514. remove = false;
  515. query = "INSERT INTO usernotes VALUES ("
  516. + "?UserId,"
  517. + "?TargetId,"
  518. + "?Notes )"
  519. + "ON DUPLICATE KEY "
  520. + "UPDATE "
  521. + "notes=?Notes"
  522. ;
  523. }
  524. try
  525. {
  526. using (MySqlConnection dbcon = new MySqlConnection(ConnectionString))
  527. {
  528. dbcon.Open();
  529. using (MySqlCommand cmd = new MySqlCommand(query, dbcon))
  530. {
  531. if(!remove)
  532. cmd.Parameters.AddWithValue("?Notes", note.Notes);
  533. cmd.Parameters.AddWithValue("?TargetId", note.TargetId.ToString ());
  534. cmd.Parameters.AddWithValue("?UserId", note.UserId.ToString());
  535. cmd.ExecuteNonQuery();
  536. }
  537. dbcon.Close();
  538. }
  539. }
  540. catch (Exception e)
  541. {
  542. m_log.ErrorFormat("[PROFILES_DATA]" +
  543. ": UpdateAvatarNotes exception {0}", e.Message);
  544. return false;
  545. }
  546. return true;
  547. }
  548. #endregion Avatar Notes Queries
  549. #region Avatar Properties
  550. public bool GetAvatarProperties(ref UserProfileProperties props, ref string result)
  551. {
  552. string query = "SELECT * FROM userprofile WHERE useruuid = ?Id";
  553. try
  554. {
  555. using (MySqlConnection dbcon = new MySqlConnection(ConnectionString))
  556. {
  557. dbcon.Open();
  558. using (MySqlCommand cmd = new MySqlCommand(query, dbcon))
  559. {
  560. cmd.Parameters.AddWithValue("?Id", props.UserId.ToString());
  561. using (MySqlDataReader reader = cmd.ExecuteReader(CommandBehavior.SingleRow))
  562. {
  563. if(reader.HasRows)
  564. {
  565. m_log.DebugFormat("[PROFILES_DATA]" +
  566. ": Getting data for {0}.", props.UserId);
  567. reader.Read();
  568. props.WebUrl = (string)reader["profileURL"];
  569. UUID.TryParse((string)reader["profileImage"], out props.ImageId);
  570. props.AboutText = (string)reader["profileAboutText"];
  571. UUID.TryParse((string)reader["profileFirstImage"], out props.FirstLifeImageId);
  572. props.FirstLifeText = (string)reader["profileFirstText"];
  573. UUID.TryParse((string)reader["profilePartner"], out props.PartnerId);
  574. props.WantToMask = (int)reader["profileWantToMask"];
  575. props.WantToText = (string)reader["profileWantToText"];
  576. props.SkillsMask = (int)reader["profileSkillsMask"];
  577. props.SkillsText = (string)reader["profileSkillsText"];
  578. props.Language = (string)reader["profileLanguages"];
  579. }
  580. else
  581. {
  582. m_log.DebugFormat("[PROFILES_DATA]" +
  583. ": No data for {0}", props.UserId);
  584. props.WebUrl = string.Empty;
  585. props.ImageId = UUID.Zero;
  586. props.AboutText = string.Empty;
  587. props.FirstLifeImageId = UUID.Zero;
  588. props.FirstLifeText = string.Empty;
  589. props.PartnerId = UUID.Zero;
  590. props.WantToMask = 0;
  591. props.WantToText = string.Empty;
  592. props.SkillsMask = 0;
  593. props.SkillsText = string.Empty;
  594. props.Language = string.Empty;
  595. props.PublishProfile = false;
  596. props.PublishMature = false;
  597. query = "INSERT INTO userprofile ("
  598. + "useruuid, "
  599. + "profilePartner, "
  600. + "profileAllowPublish, "
  601. + "profileMaturePublish, "
  602. + "profileURL, "
  603. + "profileWantToMask, "
  604. + "profileWantToText, "
  605. + "profileSkillsMask, "
  606. + "profileSkillsText, "
  607. + "profileLanguages, "
  608. + "profileImage, "
  609. + "profileAboutText, "
  610. + "profileFirstImage, "
  611. + "profileFirstText) VALUES ("
  612. + "?userId, "
  613. + "?profilePartner, "
  614. + "?profileAllowPublish, "
  615. + "?profileMaturePublish, "
  616. + "?profileURL, "
  617. + "?profileWantToMask, "
  618. + "?profileWantToText, "
  619. + "?profileSkillsMask, "
  620. + "?profileSkillsText, "
  621. + "?profileLanguages, "
  622. + "?profileImage, "
  623. + "?profileAboutText, "
  624. + "?profileFirstImage, "
  625. + "?profileFirstText)"
  626. ;
  627. dbcon.Close();
  628. dbcon.Open();
  629. using (MySqlCommand put = new MySqlCommand(query, dbcon))
  630. {
  631. put.Parameters.AddWithValue("?userId", props.UserId.ToString());
  632. put.Parameters.AddWithValue("?profilePartner", props.PartnerId.ToString());
  633. put.Parameters.AddWithValue("?profileAllowPublish", props.PublishProfile);
  634. put.Parameters.AddWithValue("?profileMaturePublish", props.PublishMature);
  635. put.Parameters.AddWithValue("?profileURL", props.WebUrl);
  636. put.Parameters.AddWithValue("?profileWantToMask", props.WantToMask);
  637. put.Parameters.AddWithValue("?profileWantToText", props.WantToText);
  638. put.Parameters.AddWithValue("?profileSkillsMask", props.SkillsMask);
  639. put.Parameters.AddWithValue("?profileSkillsText", props.SkillsText);
  640. put.Parameters.AddWithValue("?profileLanguages", props.Language);
  641. put.Parameters.AddWithValue("?profileImage", props.ImageId.ToString());
  642. put.Parameters.AddWithValue("?profileAboutText", props.AboutText);
  643. put.Parameters.AddWithValue("?profileFirstImage", props.FirstLifeImageId.ToString());
  644. put.Parameters.AddWithValue("?profileFirstText", props.FirstLifeText);
  645. put.ExecuteNonQuery();
  646. }
  647. }
  648. }
  649. }
  650. dbcon.Close();
  651. }
  652. }
  653. catch (Exception e)
  654. {
  655. m_log.ErrorFormat("[PROFILES_DATA]" +
  656. ": Requst properties exception {0}", e.Message);
  657. result = e.Message;
  658. return false;
  659. }
  660. return true;
  661. }
  662. public bool UpdateAvatarProperties(ref UserProfileProperties props, ref string result)
  663. {
  664. const string query = "UPDATE userprofile SET profileURL=?profileURL,"
  665. + "profileImage=?image, profileAboutText=?abouttext,"
  666. + "profileFirstImage=?firstlifeimage, profileFirstText=?firstlifetext "
  667. + "WHERE useruuid=?uuid";
  668. try
  669. {
  670. using (MySqlConnection dbcon = new MySqlConnection(ConnectionString))
  671. {
  672. dbcon.Open();
  673. using (MySqlCommand cmd = new MySqlCommand(query, dbcon))
  674. {
  675. cmd.Parameters.AddWithValue("?profileURL", props.WebUrl);
  676. cmd.Parameters.AddWithValue("?image", props.ImageId.ToString());
  677. cmd.Parameters.AddWithValue("?abouttext", props.AboutText);
  678. cmd.Parameters.AddWithValue("?firstlifeimage", props.FirstLifeImageId.ToString());
  679. cmd.Parameters.AddWithValue("?firstlifetext", props.FirstLifeText);
  680. cmd.Parameters.AddWithValue("?uuid", props.UserId.ToString());
  681. cmd.ExecuteNonQuery();
  682. }
  683. dbcon.Close();
  684. }
  685. }
  686. catch (Exception e)
  687. {
  688. m_log.ErrorFormat("[PROFILES_DATA]" +
  689. ": AgentPropertiesUpdate exception {0}", e.Message);
  690. return false;
  691. }
  692. return true;
  693. }
  694. #endregion Avatar Properties
  695. #region Avatar Interests
  696. public bool UpdateAvatarInterests(UserProfileProperties up, ref string result)
  697. {
  698. const string query = "UPDATE userprofile SET "
  699. + "profileWantToMask=?WantMask, "
  700. + "profileWantToText=?WantText,"
  701. + "profileSkillsMask=?SkillsMask,"
  702. + "profileSkillsText=?SkillsText, "
  703. + "profileLanguages=?Languages "
  704. + "WHERE useruuid=?uuid";
  705. try
  706. {
  707. using (MySqlConnection dbcon = new MySqlConnection(ConnectionString))
  708. {
  709. dbcon.Open();
  710. using (MySqlCommand cmd = new MySqlCommand(query, dbcon))
  711. {
  712. cmd.Parameters.AddWithValue("?WantMask", up.WantToMask);
  713. cmd.Parameters.AddWithValue("?WantText", up.WantToText);
  714. cmd.Parameters.AddWithValue("?SkillsMask", up.SkillsMask);
  715. cmd.Parameters.AddWithValue("?SkillsText", up.SkillsText);
  716. cmd.Parameters.AddWithValue("?Languages", up.Language);
  717. cmd.Parameters.AddWithValue("?uuid", up.UserId.ToString());
  718. cmd.ExecuteNonQuery();
  719. }
  720. }
  721. }
  722. catch (Exception e)
  723. {
  724. m_log.ErrorFormat("[PROFILES_DATA]" +
  725. ": AgentInterestsUpdate exception {0}", e.Message);
  726. result = e.Message;
  727. return false;
  728. }
  729. return true;
  730. }
  731. #endregion Avatar Interests
  732. public OSDArray GetUserImageAssets(UUID avatarId)
  733. {
  734. OSDArray data = new OSDArray();
  735. const string queryA = "SELECT `snapshotuuid` FROM {0} WHERE `creatoruuid` = ?Id";
  736. // Get classified image assets
  737. try
  738. {
  739. using (MySqlConnection dbcon = new MySqlConnection(ConnectionString))
  740. {
  741. dbcon.Open();
  742. using (MySqlCommand cmd = new MySqlCommand(string.Format (queryA,"`classifieds`"), dbcon))
  743. {
  744. cmd.Parameters.AddWithValue("?Id", avatarId.ToString());
  745. using (MySqlDataReader reader = cmd.ExecuteReader(CommandBehavior.SingleRow))
  746. {
  747. if(reader.HasRows)
  748. {
  749. while (reader.Read())
  750. {
  751. data.Add(new OSDString((string)reader["snapshotuuid"].ToString ()));
  752. }
  753. }
  754. }
  755. }
  756. dbcon.Close();
  757. dbcon.Open();
  758. using (MySqlCommand cmd = new MySqlCommand(string.Format (queryA,"`userpicks`"), dbcon))
  759. {
  760. cmd.Parameters.AddWithValue("?Id", avatarId.ToString());
  761. using (MySqlDataReader reader = cmd.ExecuteReader(CommandBehavior.SingleRow))
  762. {
  763. if(reader.HasRows)
  764. {
  765. while (reader.Read())
  766. {
  767. data.Add(new OSDString((string)reader["snapshotuuid"].ToString ()));
  768. }
  769. }
  770. }
  771. }
  772. dbcon.Close();
  773. dbcon.Open();
  774. const string queryB = "SELECT `profileImage`, `profileFirstImage` FROM `userprofile` WHERE `useruuid` = ?Id";
  775. using (MySqlCommand cmd = new MySqlCommand(string.Format (queryB,"`userpicks`"), dbcon))
  776. {
  777. cmd.Parameters.AddWithValue("?Id", avatarId.ToString());
  778. using (MySqlDataReader reader = cmd.ExecuteReader(CommandBehavior.SingleRow))
  779. {
  780. if(reader.HasRows)
  781. {
  782. while (reader.Read())
  783. {
  784. data.Add(new OSDString((string)reader["profileImage"].ToString ()));
  785. data.Add(new OSDString((string)reader["profileFirstImage"].ToString ()));
  786. }
  787. }
  788. }
  789. }
  790. dbcon.Close();
  791. }
  792. }
  793. catch (Exception e)
  794. {
  795. m_log.ErrorFormat("[PROFILES_DATA]" +
  796. ": GetAvatarNotes exception {0}", e.Message);
  797. }
  798. return data;
  799. }
  800. #region User Preferences
  801. public bool GetUserPreferences(ref UserPreferences pref, ref string result)
  802. {
  803. const string query = "SELECT imviaemail,visible,email FROM usersettings WHERE useruuid = ?Id";
  804. try
  805. {
  806. using (MySqlConnection dbcon = new MySqlConnection(ConnectionString))
  807. {
  808. dbcon.Open();
  809. using (MySqlCommand cmd = new MySqlCommand(query, dbcon))
  810. {
  811. cmd.Parameters.AddWithValue("?Id", pref.UserId.ToString());
  812. using (MySqlDataReader reader = cmd.ExecuteReader())
  813. {
  814. if (reader.HasRows)
  815. {
  816. reader.Read();
  817. bool.TryParse((string)reader["imviaemail"], out pref.IMViaEmail);
  818. bool.TryParse((string)reader["visible"], out pref.Visible);
  819. pref.EMail = (string)reader["email"];
  820. }
  821. else
  822. {
  823. dbcon.Close();
  824. dbcon.Open();
  825. const string queryB = "INSERT INTO usersettings VALUES (?uuid,'false','false', ?Email)";
  826. using (MySqlCommand put = new MySqlCommand(queryB, dbcon))
  827. {
  828. put.Parameters.AddWithValue("?Email", pref.EMail);
  829. put.Parameters.AddWithValue("?uuid", pref.UserId.ToString());
  830. put.ExecuteNonQuery();
  831. }
  832. }
  833. }
  834. }
  835. dbcon.Close();
  836. }
  837. }
  838. catch (Exception e)
  839. {
  840. m_log.ErrorFormat("[PROFILES_DATA]" +
  841. ": Get preferences exception {0}", e.Message);
  842. result = e.Message;
  843. return false;
  844. }
  845. return true;
  846. }
  847. public bool UpdateUserPreferences(ref UserPreferences pref, ref string result)
  848. {
  849. const string query = "UPDATE usersettings SET imviaemail=?ImViaEmail,"
  850. + "visible=?Visible, email=?EMail "
  851. + "WHERE useruuid=?uuid";
  852. try
  853. {
  854. using (MySqlConnection dbcon = new MySqlConnection(ConnectionString))
  855. {
  856. dbcon.Open();
  857. using (MySqlCommand cmd = new MySqlCommand(query, dbcon))
  858. {
  859. cmd.Parameters.AddWithValue("?ImViaEmail", pref.IMViaEmail.ToString().ToLower());
  860. cmd.Parameters.AddWithValue("?Visible", pref.Visible.ToString().ToLower());
  861. cmd.Parameters.AddWithValue("?uuid", pref.UserId.ToString());
  862. cmd.Parameters.AddWithValue("?EMail", pref.EMail.ToString().ToLower());
  863. cmd.ExecuteNonQuery();
  864. }
  865. dbcon.Close();
  866. }
  867. }
  868. catch (Exception e)
  869. {
  870. m_log.ErrorFormat("[PROFILES_DATA]" +
  871. ": UserPreferencesUpdate exception {0} {1}", e.Message, e.InnerException);
  872. result = e.Message;
  873. return false;
  874. }
  875. return true;
  876. }
  877. #endregion User Preferences
  878. #region Integration
  879. public bool GetUserAppData(ref UserAppData props, ref string result)
  880. {
  881. const string query = "SELECT * FROM `userdata` WHERE UserId = ?Id AND TagId = ?TagId";
  882. try
  883. {
  884. using (MySqlConnection dbcon = new MySqlConnection(ConnectionString))
  885. {
  886. dbcon.Open();
  887. using (MySqlCommand cmd = new MySqlCommand(query, dbcon))
  888. {
  889. cmd.Parameters.AddWithValue("?Id", props.UserId.ToString());
  890. cmd.Parameters.AddWithValue ("?TagId", props.TagId.ToString());
  891. using (MySqlDataReader reader = cmd.ExecuteReader(CommandBehavior.SingleRow))
  892. {
  893. if(reader.HasRows)
  894. {
  895. reader.Read();
  896. props.DataKey = (string)reader["DataKey"];
  897. props.DataVal = (string)reader["DataVal"];
  898. }
  899. else
  900. {
  901. const string queryB = "INSERT INTO userdata VALUES (?UserId, ?TagId, ?DataKey, ?DataVal)";
  902. using (MySqlCommand put = new MySqlCommand(queryB, dbcon))
  903. {
  904. put.Parameters.AddWithValue("?UserId", props.UserId.ToString());
  905. put.Parameters.AddWithValue("?TagId", props.TagId.ToString());
  906. put.Parameters.AddWithValue("?DataKey", props.DataKey.ToString());
  907. put.Parameters.AddWithValue("?DataVal", props.DataVal.ToString());
  908. put.ExecuteNonQuery();
  909. }
  910. }
  911. }
  912. }
  913. dbcon.Close();
  914. }
  915. }
  916. catch (Exception e)
  917. {
  918. m_log.ErrorFormat("[PROFILES_DATA]" +
  919. ": Requst application data exception {0}", e.Message);
  920. result = e.Message;
  921. return false;
  922. }
  923. return true;
  924. }
  925. public bool SetUserAppData(UserAppData props, ref string result)
  926. {
  927. const string query = "UPDATE userdata SET TagId = ?TagId, DataKey = ?DataKey, DataVal = ?DataVal WHERE UserId = ?UserId AND TagId = ?TagId";
  928. try
  929. {
  930. using (MySqlConnection dbcon = new MySqlConnection(ConnectionString))
  931. {
  932. dbcon.Open();
  933. using (MySqlCommand cmd = new MySqlCommand(query, dbcon))
  934. {
  935. cmd.Parameters.AddWithValue("?UserId", props.UserId.ToString());
  936. cmd.Parameters.AddWithValue("?TagId", props.TagId.ToString());
  937. cmd.Parameters.AddWithValue("?DataKey", props.DataKey.ToString());
  938. cmd.Parameters.AddWithValue("?DataVal", props.DataKey.ToString());
  939. cmd.ExecuteNonQuery();
  940. }
  941. dbcon.Close();
  942. }
  943. }
  944. catch (Exception e)
  945. {
  946. m_log.ErrorFormat("[PROFILES_DATA]" +
  947. ": SetUserData exception {0}", e.Message);
  948. return false;
  949. }
  950. return true;
  951. }
  952. #endregion Integration
  953. }
  954. }