MySQLUserProfilesData.cs 46 KB

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