MSSQLUserData.cs 56 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151
  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;
  29. using System.Collections.Generic;
  30. using System.Data;
  31. using System.Data.SqlClient;
  32. using System.Reflection;
  33. using OpenMetaverse;
  34. using log4net;
  35. using OpenSim.Framework;
  36. namespace OpenSim.Data.MSSQL
  37. {
  38. /// <summary>
  39. /// A database interface class to a user profile storage system
  40. /// </summary>
  41. public class MSSQLUserData : UserDataBase
  42. {
  43. private const string _migrationStore = "UserStore";
  44. private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  45. /// <summary>
  46. /// Database manager for MSSQL
  47. /// </summary>
  48. public MSSQLManager database;
  49. private const string m_agentsTableName = "agents";
  50. private const string m_usersTableName = "users";
  51. private const string m_userFriendsTableName = "userfriends";
  52. // [Obsolete("Cannot be default-initialized!")]
  53. override public void Initialise()
  54. {
  55. m_log.Info("[MSSQLUserData]: " + Name + " cannot be default-initialized!");
  56. throw new PluginNotInitialisedException(Name);
  57. }
  58. /// <summary>
  59. /// Loads and initialises the MSSQL storage plugin
  60. /// </summary>
  61. /// <param name="connect">connectionstring</param>
  62. /// <remarks>use mssql_connection.ini</remarks>
  63. override public void Initialise(string connect)
  64. {
  65. if (!string.IsNullOrEmpty(connect))
  66. {
  67. database = new MSSQLManager(connect);
  68. }
  69. else
  70. {
  71. IniFile iniFile = new IniFile("mssql_connection.ini");
  72. string settingDataSource = iniFile.ParseFileReadValue("data_source");
  73. string settingInitialCatalog = iniFile.ParseFileReadValue("initial_catalog");
  74. string settingPersistSecurityInfo = iniFile.ParseFileReadValue("persist_security_info");
  75. string settingUserId = iniFile.ParseFileReadValue("user_id");
  76. string settingPassword = iniFile.ParseFileReadValue("password");
  77. database = new MSSQLManager(settingDataSource, settingInitialCatalog, settingPersistSecurityInfo, settingUserId, settingPassword);
  78. }
  79. //Check migration on DB
  80. database.CheckMigration(_migrationStore);
  81. }
  82. /// <summary>
  83. /// Releases unmanaged and - optionally - managed resources
  84. /// </summary>
  85. override public void Dispose() { }
  86. #region User table methods
  87. /// <summary>
  88. /// Searches the database for a specified user profile by name components
  89. /// </summary>
  90. /// <param name="user">The first part of the account name</param>
  91. /// <param name="last">The second part of the account name</param>
  92. /// <returns>A user profile</returns>
  93. override public UserProfileData GetUserByName(string user, string last)
  94. {
  95. using (AutoClosingSqlCommand command = database.Query("SELECT * FROM " + m_usersTableName + " WHERE username = @first AND lastname = @second"))
  96. {
  97. command.Parameters.Add(database.CreateParameter("first", user));
  98. command.Parameters.Add(database.CreateParameter("second", last));
  99. try
  100. {
  101. using (SqlDataReader reader = command.ExecuteReader())
  102. {
  103. return ReadUserRow(reader);
  104. }
  105. }
  106. catch (Exception e)
  107. {
  108. m_log.Error("[USER DB] Error getting user profile, error: " + e.Message);
  109. return null;
  110. }
  111. }
  112. }
  113. /// <summary>
  114. /// See IUserDataPlugin
  115. /// </summary>
  116. /// <param name="uuid"></param>
  117. /// <returns></returns>
  118. override public UserProfileData GetUserByUUID(UUID uuid)
  119. {
  120. using (AutoClosingSqlCommand command = database.Query("SELECT * FROM " + m_usersTableName + " WHERE UUID = @uuid"))
  121. {
  122. command.Parameters.Add(database.CreateParameter("uuid", uuid));
  123. try
  124. {
  125. using (IDataReader reader = command.ExecuteReader())
  126. {
  127. return ReadUserRow(reader);
  128. }
  129. }
  130. catch (Exception e)
  131. {
  132. m_log.Error("[USER DB] Error getting user profile by UUID, error: " + e.Message);
  133. return null;
  134. }
  135. }
  136. }
  137. /// <summary>
  138. /// Creates a new users profile
  139. /// </summary>
  140. /// <param name="user">The user profile to create</param>
  141. override public void AddNewUserProfile(UserProfileData user)
  142. {
  143. try
  144. {
  145. InsertUserRow(user.ID, user.FirstName, user.SurName, user.Email, user.PasswordHash, user.PasswordSalt,
  146. user.HomeRegion, user.HomeLocation.X, user.HomeLocation.Y,
  147. user.HomeLocation.Z,
  148. user.HomeLookAt.X, user.HomeLookAt.Y, user.HomeLookAt.Z, user.Created,
  149. user.LastLogin, user.UserInventoryURI, user.UserAssetURI,
  150. user.CanDoMask, user.WantDoMask,
  151. user.AboutText, user.FirstLifeAboutText, user.Image,
  152. user.FirstLifeImage, user.WebLoginKey, user.HomeRegionID,
  153. user.GodLevel, user.UserFlags, user.CustomType, user.Partner);
  154. }
  155. catch (Exception e)
  156. {
  157. m_log.Error("[USER DB] Error adding new profile, error: " + e.Message);
  158. }
  159. }
  160. /// <summary>
  161. /// update a user profile
  162. /// </summary>
  163. /// <param name="user">the profile to update</param>
  164. /// <returns></returns>
  165. override public bool UpdateUserProfile(UserProfileData user)
  166. {
  167. using (AutoClosingSqlCommand command = database.Query("UPDATE " + m_usersTableName + " set UUID = @uuid, " +
  168. "username = @username, " +
  169. "lastname = @lastname," +
  170. "email = @email," +
  171. "passwordHash = @passwordHash," +
  172. "passwordSalt = @passwordSalt," +
  173. "homeRegion = @homeRegion," +
  174. "homeLocationX = @homeLocationX," +
  175. "homeLocationY = @homeLocationY," +
  176. "homeLocationZ = @homeLocationZ," +
  177. "homeLookAtX = @homeLookAtX," +
  178. "homeLookAtY = @homeLookAtY," +
  179. "homeLookAtZ = @homeLookAtZ," +
  180. "created = @created," +
  181. "lastLogin = @lastLogin," +
  182. "userInventoryURI = @userInventoryURI," +
  183. "userAssetURI = @userAssetURI," +
  184. "profileCanDoMask = @profileCanDoMask," +
  185. "profileWantDoMask = @profileWantDoMask," +
  186. "profileAboutText = @profileAboutText," +
  187. "profileFirstText = @profileFirstText," +
  188. "profileImage = @profileImage," +
  189. "profileFirstImage = @profileFirstImage, " +
  190. "webLoginKey = @webLoginKey, " +
  191. "homeRegionID = @homeRegionID, " +
  192. "userFlags = @userFlags, " +
  193. "godLevel = @godLevel, " +
  194. "customType = @customType, " +
  195. "partner = @partner where " +
  196. "UUID = @keyUUUID;"))
  197. {
  198. command.Parameters.Add(database.CreateParameter("uuid", user.ID));
  199. command.Parameters.Add(database.CreateParameter("username", user.FirstName));
  200. command.Parameters.Add(database.CreateParameter("lastname", user.SurName));
  201. command.Parameters.Add(database.CreateParameter("email", user.Email));
  202. command.Parameters.Add(database.CreateParameter("passwordHash", user.PasswordHash));
  203. command.Parameters.Add(database.CreateParameter("passwordSalt", user.PasswordSalt));
  204. command.Parameters.Add(database.CreateParameter("homeRegion", user.HomeRegion));
  205. command.Parameters.Add(database.CreateParameter("homeLocationX", user.HomeLocation.X));
  206. command.Parameters.Add(database.CreateParameter("homeLocationY", user.HomeLocation.Y));
  207. command.Parameters.Add(database.CreateParameter("homeLocationZ", user.HomeLocation.Z));
  208. command.Parameters.Add(database.CreateParameter("homeLookAtX", user.HomeLookAt.X));
  209. command.Parameters.Add(database.CreateParameter("homeLookAtY", user.HomeLookAt.Y));
  210. command.Parameters.Add(database.CreateParameter("homeLookAtZ", user.HomeLookAt.Z));
  211. command.Parameters.Add(database.CreateParameter("created", user.Created));
  212. command.Parameters.Add(database.CreateParameter("lastLogin", user.LastLogin));
  213. command.Parameters.Add(database.CreateParameter("userInventoryURI", user.UserInventoryURI));
  214. command.Parameters.Add(database.CreateParameter("userAssetURI", user.UserAssetURI));
  215. command.Parameters.Add(database.CreateParameter("profileCanDoMask", user.CanDoMask));
  216. command.Parameters.Add(database.CreateParameter("profileWantDoMask", user.WantDoMask));
  217. command.Parameters.Add(database.CreateParameter("profileAboutText", user.AboutText));
  218. command.Parameters.Add(database.CreateParameter("profileFirstText", user.FirstLifeAboutText));
  219. command.Parameters.Add(database.CreateParameter("profileImage", user.Image));
  220. command.Parameters.Add(database.CreateParameter("profileFirstImage", user.FirstLifeImage));
  221. command.Parameters.Add(database.CreateParameter("webLoginKey", user.WebLoginKey));
  222. //
  223. command.Parameters.Add(database.CreateParameter("homeRegionID", user.HomeRegionID));
  224. command.Parameters.Add(database.CreateParameter("userFlags", user.UserFlags));
  225. command.Parameters.Add(database.CreateParameter("godLevel", user.GodLevel));
  226. command.Parameters.Add(database.CreateParameter("customType", user.CustomType));
  227. command.Parameters.Add(database.CreateParameter("partner", user.Partner));
  228. command.Parameters.Add(database.CreateParameter("keyUUUID", user.ID));
  229. try
  230. {
  231. int affected = command.ExecuteNonQuery();
  232. return (affected != 0);
  233. }
  234. catch (Exception e)
  235. {
  236. m_log.Error("[USER DB] Error updating profile, error: " + e.Message);
  237. }
  238. }
  239. return false;
  240. }
  241. #endregion
  242. #region Agent table methods
  243. /// <summary>
  244. /// Returns a user session searching by name
  245. /// </summary>
  246. /// <param name="name">The account name</param>
  247. /// <returns>The users session</returns>
  248. override public UserAgentData GetAgentByName(string name)
  249. {
  250. return GetAgentByName(name.Split(' ')[0], name.Split(' ')[1]);
  251. }
  252. /// <summary>
  253. /// Returns a user session by account name
  254. /// </summary>
  255. /// <param name="user">First part of the users account name</param>
  256. /// <param name="last">Second part of the users account name</param>
  257. /// <returns>The users session</returns>
  258. override public UserAgentData GetAgentByName(string user, string last)
  259. {
  260. UserProfileData profile = GetUserByName(user, last);
  261. return GetAgentByUUID(profile.ID);
  262. }
  263. /// <summary>
  264. /// Returns an agent session by account UUID
  265. /// </summary>
  266. /// <param name="uuid">The accounts UUID</param>
  267. /// <returns>The users session</returns>
  268. override public UserAgentData GetAgentByUUID(UUID uuid)
  269. {
  270. using (AutoClosingSqlCommand command = database.Query("SELECT * FROM " + m_agentsTableName + " WHERE UUID = @uuid"))
  271. {
  272. command.Parameters.Add(database.CreateParameter("uuid", uuid));
  273. try
  274. {
  275. using (SqlDataReader reader = command.ExecuteReader())
  276. {
  277. return readAgentRow(reader);
  278. }
  279. }
  280. catch (Exception e)
  281. {
  282. m_log.Error("[USER DB] Error updating agentdata by UUID, error: " + e.Message);
  283. return null;
  284. }
  285. }
  286. }
  287. /// <summary>
  288. /// Creates a new agent
  289. /// </summary>
  290. /// <param name="agent">The agent to create</param>
  291. override public void AddNewUserAgent(UserAgentData agent)
  292. {
  293. try
  294. {
  295. InsertUpdateAgentRow(agent);
  296. }
  297. catch (Exception e)
  298. {
  299. m_log.Error("[USER DB] Error adding new agentdata, error: " + e.Message);
  300. }
  301. }
  302. #endregion
  303. #region User Friends List Data
  304. /// <summary>
  305. /// Add a new friend in the friendlist
  306. /// </summary>
  307. /// <param name="friendlistowner">UUID of the friendlist owner</param>
  308. /// <param name="friend">Friend's UUID</param>
  309. /// <param name="perms">Permission flag</param>
  310. override public void AddNewUserFriend(UUID friendlistowner, UUID friend, uint perms)
  311. {
  312. int dtvalue = Util.UnixTimeSinceEpoch();
  313. using (AutoClosingSqlCommand command = database.Query(
  314. "INSERT INTO " + m_userFriendsTableName + " " +
  315. "(ownerID,friendID,friendPerms,datetimestamp) " +
  316. "VALUES " +
  317. "(@ownerID,@friendID,@friendPerms,@datetimestamp)"))
  318. {
  319. command.Parameters.Add(database.CreateParameter("ownerID", friendlistowner));
  320. command.Parameters.Add(database.CreateParameter("friendID", friend));
  321. command.Parameters.Add(database.CreateParameter("friendPerms", perms));
  322. command.Parameters.Add(database.CreateParameter("datetimestamp", dtvalue));
  323. command.ExecuteNonQuery();
  324. try
  325. {
  326. command.CommandText = string.Format("INSERT INTO {0} (ownerID,friendID,friendPerms,datetimestamp) VALUES (@friendID,@ownerID,@friendPerms,@datetimestamp)",
  327. m_userFriendsTableName);
  328. command.ExecuteNonQuery();
  329. }
  330. catch (Exception e)
  331. {
  332. m_log.Error("[USER DB] Error adding new userfriend, error: " + e.Message);
  333. return;
  334. }
  335. }
  336. }
  337. /// <summary>
  338. /// Remove an friend from the friendlist
  339. /// </summary>
  340. /// <param name="friendlistowner">UUID of the friendlist owner</param>
  341. /// <param name="friend">UUID of the not-so-friendly user to remove from the list</param>
  342. override public void RemoveUserFriend(UUID friendlistowner, UUID friend)
  343. {
  344. using (AutoClosingSqlCommand command = database.Query("delete from " + m_userFriendsTableName + " where ownerID = @ownerID and friendID = @friendID"))
  345. {
  346. command.Parameters.Add(database.CreateParameter("@ownerID", friendlistowner));
  347. command.Parameters.Add(database.CreateParameter("@friendID", friend));
  348. command.ExecuteNonQuery();
  349. command.CommandText = "delete from " + m_userFriendsTableName +
  350. " where ownerID = @friendID and friendID = @ownerID";
  351. try
  352. {
  353. command.ExecuteNonQuery();
  354. }
  355. catch (Exception e)
  356. {
  357. m_log.Error("[USER DB] Error removing userfriend, error: " + e.Message);
  358. }
  359. }
  360. }
  361. /// <summary>
  362. /// Update friendlist permission flag for a friend
  363. /// </summary>
  364. /// <param name="friendlistowner">UUID of the friendlist owner</param>
  365. /// <param name="friend">UUID of the friend</param>
  366. /// <param name="perms">new permission flag</param>
  367. override public void UpdateUserFriendPerms(UUID friendlistowner, UUID friend, uint perms)
  368. {
  369. using (AutoClosingSqlCommand command = database.Query(
  370. "update " + m_userFriendsTableName +
  371. " SET friendPerms = @friendPerms " +
  372. "where ownerID = @ownerID and friendID = @friendID"))
  373. {
  374. command.Parameters.Add(database.CreateParameter("@ownerID", friendlistowner));
  375. command.Parameters.Add(database.CreateParameter("@friendID", friend));
  376. command.Parameters.Add(database.CreateParameter("@friendPerms", perms));
  377. try
  378. {
  379. command.ExecuteNonQuery();
  380. }
  381. catch (Exception e)
  382. {
  383. m_log.Error("[USER DB] Error updating userfriend, error: " + e.Message);
  384. }
  385. }
  386. }
  387. /// <summary>
  388. /// Get (fetch?) the user's friendlist
  389. /// </summary>
  390. /// <param name="friendlistowner">UUID of the friendlist owner</param>
  391. /// <returns>Friendlist list</returns>
  392. override public List<FriendListItem> GetUserFriendList(UUID friendlistowner)
  393. {
  394. List<FriendListItem> friendList = new List<FriendListItem>();
  395. //Left Join userfriends to itself
  396. using (AutoClosingSqlCommand command = database.Query(
  397. "select a.ownerID,a.friendID,a.friendPerms,b.friendPerms as ownerperms from " + m_userFriendsTableName + " as a, " + m_userFriendsTableName + " as b" +
  398. " where a.ownerID = @ownerID and b.ownerID = a.friendID and b.friendID = a.ownerID"))
  399. {
  400. command.Parameters.Add(database.CreateParameter("@ownerID", friendlistowner));
  401. try
  402. {
  403. using (IDataReader reader = command.ExecuteReader())
  404. {
  405. while (reader.Read())
  406. {
  407. FriendListItem fli = new FriendListItem();
  408. fli.FriendListOwner = new UUID((string)reader["ownerID"]);
  409. fli.Friend = new UUID((string)reader["friendID"]);
  410. fli.FriendPerms = (uint)Convert.ToInt32(reader["friendPerms"]);
  411. // This is not a real column in the database table, it's a joined column from the opposite record
  412. fli.FriendListOwnerPerms = (uint)Convert.ToInt32(reader["ownerperms"]);
  413. friendList.Add(fli);
  414. }
  415. }
  416. }
  417. catch (Exception e)
  418. {
  419. m_log.Error("[USER DB] Error updating userfriend, error: " + e.Message);
  420. }
  421. }
  422. return friendList;
  423. }
  424. override public Dictionary<UUID, FriendRegionInfo> GetFriendRegionInfos (List<UUID> uuids)
  425. {
  426. Dictionary<UUID, FriendRegionInfo> infos = new Dictionary<UUID,FriendRegionInfo>();
  427. try
  428. {
  429. foreach (UUID uuid in uuids)
  430. {
  431. using (AutoClosingSqlCommand command = database.Query(
  432. "select agentOnline,currentHandle from " + m_agentsTableName + " where UUID = @uuid"))
  433. {
  434. command.Parameters.Add(database.CreateParameter("@uuid", uuid));
  435. using (IDataReader reader = command.ExecuteReader())
  436. {
  437. while (reader.Read())
  438. {
  439. FriendRegionInfo fri = new FriendRegionInfo();
  440. fri.isOnline = (byte)reader["agentOnline"] != 0;
  441. fri.regionHandle = Convert.ToUInt64(reader["currentHandle"].ToString());
  442. infos[uuid] = fri;
  443. }
  444. }
  445. }
  446. }
  447. }
  448. catch (Exception e)
  449. {
  450. m_log.Warn("[MSSQL]: Got exception on trying to find friends regions:", e);
  451. }
  452. return infos;
  453. }
  454. #endregion
  455. #region Money functions (not used)
  456. /// <summary>
  457. /// Performs a money transfer request between two accounts
  458. /// </summary>
  459. /// <param name="from">The senders account ID</param>
  460. /// <param name="to">The receivers account ID</param>
  461. /// <param name="amount">The amount to transfer</param>
  462. /// <returns>false</returns>
  463. override public bool MoneyTransferRequest(UUID from, UUID to, uint amount)
  464. {
  465. return false;
  466. }
  467. /// <summary>
  468. /// Performs an inventory transfer request between two accounts
  469. /// </summary>
  470. /// <remarks>TODO: Move to inventory server</remarks>
  471. /// <param name="from">The senders account ID</param>
  472. /// <param name="to">The receivers account ID</param>
  473. /// <param name="item">The item to transfer</param>
  474. /// <returns>false</returns>
  475. override public bool InventoryTransferRequest(UUID from, UUID to, UUID item)
  476. {
  477. return false;
  478. }
  479. #endregion
  480. #region Appearance methods
  481. /// <summary>
  482. /// Gets the user appearance.
  483. /// </summary>
  484. /// <param name="user">The user.</param>
  485. /// <returns></returns>
  486. /// TODO: stubs for now to get us to a compiling state gently
  487. override public AvatarAppearance GetUserAppearance(UUID user)
  488. {
  489. try
  490. {
  491. AvatarAppearance appearance = new AvatarAppearance();
  492. using (AutoClosingSqlCommand command = database.Query("SELECT * FROM avatarappearance WHERE owner = @UUID"))
  493. {
  494. command.Parameters.Add(database.CreateParameter("@UUID", user));
  495. using (IDataReader reader = command.ExecuteReader())
  496. {
  497. if (reader.Read())
  498. appearance = readUserAppearance(reader);
  499. }
  500. }
  501. appearance.SetAttachments(GetUserAttachments(user));
  502. return appearance;
  503. }
  504. catch (Exception e)
  505. {
  506. m_log.Error("[USER DB] Error updating userfriend, error: " + e.Message);
  507. }
  508. return null;
  509. }
  510. /// <summary>
  511. /// Update a user appearence into database
  512. /// </summary>
  513. /// <param name="user">the used UUID</param>
  514. /// <param name="appearance">the appearence</param>
  515. override public void UpdateUserAppearance(UUID user, AvatarAppearance appearance)
  516. {
  517. m_log.Error("[USER DB] updating user appearance for user ID " + user.Guid);
  518. string sql = String.Empty;
  519. sql += "DELETE FROM avatarappearance WHERE owner=@owner ";
  520. sql += "INSERT INTO avatarappearance ";
  521. sql += "(owner, serial, visual_params, texture, avatar_height, ";
  522. sql += "body_item, body_asset, skin_item, skin_asset, hair_item, hair_asset, eyes_item, eyes_asset, ";
  523. sql += "shirt_item, shirt_asset, pants_item, pants_asset, shoes_item, shoes_asset, socks_item, socks_asset, ";
  524. sql += "jacket_item, jacket_asset, gloves_item, gloves_asset, undershirt_item, undershirt_asset, underpants_item, underpants_asset, ";
  525. sql += "skirt_item, skirt_asset) values (";
  526. sql += "@owner, @serial, @visual_params, @texture, @avatar_height, ";
  527. sql += "@body_item, @body_asset, @skin_item, @skin_asset, @hair_item, @hair_asset, @eyes_item, @eyes_asset, ";
  528. sql += "@shirt_item, @shirt_asset, @pants_item, @pants_asset, @shoes_item, @shoes_asset, @socks_item, @socks_asset, ";
  529. sql += "@jacket_item, @jacket_asset, @gloves_item, @gloves_asset, @undershirt_item, @undershirt_asset, @underpants_item, @underpants_asset, ";
  530. sql += "@skirt_item, @skirt_asset)";
  531. using (AutoClosingSqlCommand cmd = database.Query(sql))
  532. {
  533. cmd.Parameters.Add(database.CreateParameter("@owner", appearance.Owner));
  534. cmd.Parameters.Add(database.CreateParameter("@serial", appearance.Serial));
  535. cmd.Parameters.Add(database.CreateParameter("@visual_params", appearance.VisualParams));
  536. cmd.Parameters.Add(database.CreateParameter("@texture", appearance.Texture.ToBytes()));
  537. cmd.Parameters.Add(database.CreateParameter("@avatar_height", appearance.AvatarHeight));
  538. cmd.Parameters.Add(database.CreateParameter("@body_item", appearance.BodyItem));
  539. cmd.Parameters.Add(database.CreateParameter("@body_asset", appearance.BodyAsset));
  540. cmd.Parameters.Add(database.CreateParameter("@skin_item", appearance.SkinItem));
  541. cmd.Parameters.Add(database.CreateParameter("@skin_asset", appearance.SkinAsset));
  542. cmd.Parameters.Add(database.CreateParameter("@hair_item", appearance.HairItem));
  543. cmd.Parameters.Add(database.CreateParameter("@hair_asset", appearance.HairAsset));
  544. cmd.Parameters.Add(database.CreateParameter("@eyes_item", appearance.EyesItem));
  545. cmd.Parameters.Add(database.CreateParameter("@eyes_asset", appearance.EyesAsset));
  546. cmd.Parameters.Add(database.CreateParameter("@shirt_item", appearance.ShirtItem));
  547. cmd.Parameters.Add(database.CreateParameter("@shirt_asset", appearance.ShirtAsset));
  548. cmd.Parameters.Add(database.CreateParameter("@pants_item", appearance.PantsItem));
  549. cmd.Parameters.Add(database.CreateParameter("@pants_asset", appearance.PantsAsset));
  550. cmd.Parameters.Add(database.CreateParameter("@shoes_item", appearance.ShoesItem));
  551. cmd.Parameters.Add(database.CreateParameter("@shoes_asset", appearance.ShoesAsset));
  552. cmd.Parameters.Add(database.CreateParameter("@socks_item", appearance.SocksItem));
  553. cmd.Parameters.Add(database.CreateParameter("@socks_asset", appearance.SocksAsset));
  554. cmd.Parameters.Add(database.CreateParameter("@jacket_item", appearance.JacketItem));
  555. cmd.Parameters.Add(database.CreateParameter("@jacket_asset", appearance.JacketAsset));
  556. cmd.Parameters.Add(database.CreateParameter("@gloves_item", appearance.GlovesItem));
  557. cmd.Parameters.Add(database.CreateParameter("@gloves_asset", appearance.GlovesAsset));
  558. cmd.Parameters.Add(database.CreateParameter("@undershirt_item", appearance.UnderShirtItem));
  559. cmd.Parameters.Add(database.CreateParameter("@undershirt_asset", appearance.UnderShirtAsset));
  560. cmd.Parameters.Add(database.CreateParameter("@underpants_item", appearance.UnderPantsItem));
  561. cmd.Parameters.Add(database.CreateParameter("@underpants_asset", appearance.UnderPantsAsset));
  562. cmd.Parameters.Add(database.CreateParameter("@skirt_item", appearance.SkirtItem));
  563. cmd.Parameters.Add(database.CreateParameter("@skirt_asset", appearance.SkirtAsset));
  564. try
  565. {
  566. cmd.ExecuteNonQuery();
  567. }
  568. catch (Exception e)
  569. {
  570. m_log.Error("[USER DB] Error updating user appearance, error: " + e.Message);
  571. }
  572. }
  573. UpdateUserAttachments(user, appearance.GetAttachments());
  574. }
  575. #endregion
  576. #region Attachment methods
  577. /// <summary>
  578. /// Gets all attachment of a agent.
  579. /// </summary>
  580. /// <param name="agentID">agent ID.</param>
  581. /// <returns></returns>
  582. public Hashtable GetUserAttachments(UUID agentID)
  583. {
  584. Hashtable returnTable = new Hashtable();
  585. using (AutoClosingSqlCommand command = database.Query("select attachpoint, item, asset from avatarattachments where UUID = @uuid", database.CreateParameter("@uuid", agentID)))
  586. {
  587. using (SqlDataReader reader = command.ExecuteReader())
  588. {
  589. while (reader.Read())
  590. {
  591. int attachpoint = Convert.ToInt32(reader["attachpoint"]);
  592. if (returnTable.ContainsKey(attachpoint))
  593. continue;
  594. Hashtable item = new Hashtable();
  595. item.Add("item", reader["item"].ToString());
  596. item.Add("asset", reader["asset"].ToString());
  597. returnTable.Add(attachpoint, item);
  598. }
  599. }
  600. }
  601. return returnTable;
  602. }
  603. /// <summary>
  604. /// Updates all attachments of the agent.
  605. /// </summary>
  606. /// <param name="agentID">agentID.</param>
  607. /// <param name="data">data with all items on attachmentpoints</param>
  608. public void UpdateUserAttachments(UUID agentID, Hashtable data)
  609. {
  610. string sql = "delete from avatarattachments where UUID = @uuid";
  611. using (AutoClosingSqlCommand command = database.Query(sql))
  612. {
  613. command.Parameters.Add(database.CreateParameter("uuid", agentID));
  614. command.ExecuteNonQuery();
  615. }
  616. if (data == null)
  617. return;
  618. sql = "insert into avatarattachments (UUID, attachpoint, item, asset) values (@uuid, @attachpoint, @item, @asset)";
  619. using (AutoClosingSqlCommand command = database.Query(sql))
  620. {
  621. bool firstTime = true;
  622. foreach (DictionaryEntry e in data)
  623. {
  624. int attachpoint = Convert.ToInt32(e.Key);
  625. Hashtable item = (Hashtable)e.Value;
  626. if (firstTime)
  627. {
  628. command.Parameters.Add(database.CreateParameter("@uuid", agentID));
  629. command.Parameters.Add(database.CreateParameter("@attachpoint", attachpoint));
  630. command.Parameters.Add(database.CreateParameter("@item", item["item"].ToString()));
  631. command.Parameters.Add(database.CreateParameter("@asset", item["asset"].ToString()));
  632. firstTime = false;
  633. }
  634. command.Parameters["@uuid"].Value = agentID.ToString();
  635. command.Parameters["@attachpoint"].Value = attachpoint;
  636. command.Parameters["@item"].Value = item["item"].ToString();
  637. command.Parameters["@asset"].Value = item["asset"].ToString();
  638. try
  639. {
  640. command.ExecuteNonQuery();
  641. }
  642. catch (Exception ex)
  643. {
  644. m_log.DebugFormat("[USER DB] : Error adding user attachment. {0}", ex.Message);
  645. }
  646. }
  647. }
  648. }
  649. /// <summary>
  650. /// Resets all attachments of a agent in the database.
  651. /// </summary>
  652. /// <param name="agentID">agentID.</param>
  653. override public void ResetAttachments(UUID agentID)
  654. {
  655. using (AutoClosingSqlCommand command = database.Query("update avatarattachments set asset = '00000000-0000-0000-0000-000000000000' where UUID = @uuid"))
  656. {
  657. command.Parameters.Add(database.CreateParameter("uuid", agentID));
  658. command.ExecuteNonQuery();
  659. }
  660. }
  661. override public void LogoutUsers(UUID regionID)
  662. {
  663. }
  664. #endregion
  665. #region Other public methods
  666. /// <summary>
  667. ///
  668. /// </summary>
  669. /// <param name="queryID"></param>
  670. /// <param name="query"></param>
  671. /// <returns></returns>
  672. override public List<AvatarPickerAvatar> GeneratePickerResults(UUID queryID, string query)
  673. {
  674. List<AvatarPickerAvatar> returnlist = new List<AvatarPickerAvatar>();
  675. string[] querysplit = query.Split(' ');
  676. if (querysplit.Length == 2)
  677. {
  678. try
  679. {
  680. using (AutoClosingSqlCommand command = database.Query("SELECT UUID,username,lastname FROM " + m_usersTableName + " WHERE username LIKE @first AND lastname LIKE @second"))
  681. {
  682. //Add wildcard to the search
  683. command.Parameters.Add(database.CreateParameter("first", querysplit[0] + "%"));
  684. command.Parameters.Add(database.CreateParameter("second", querysplit[1] + "%"));
  685. using (IDataReader reader = command.ExecuteReader())
  686. {
  687. while (reader.Read())
  688. {
  689. AvatarPickerAvatar user = new AvatarPickerAvatar();
  690. user.AvatarID = new UUID((string)reader["UUID"]);
  691. user.firstName = (string)reader["username"];
  692. user.lastName = (string)reader["lastname"];
  693. returnlist.Add(user);
  694. }
  695. }
  696. }
  697. }
  698. catch (Exception e)
  699. {
  700. m_log.Error(e.ToString());
  701. }
  702. }
  703. else if (querysplit.Length == 1)
  704. {
  705. try
  706. {
  707. using (AutoClosingSqlCommand command = database.Query("SELECT UUID,username,lastname FROM " + m_usersTableName + " WHERE username LIKE @first OR lastname LIKE @first"))
  708. {
  709. command.Parameters.Add(database.CreateParameter("first", querysplit[0] + "%"));
  710. using (IDataReader reader = command.ExecuteReader())
  711. {
  712. while (reader.Read())
  713. {
  714. AvatarPickerAvatar user = new AvatarPickerAvatar();
  715. user.AvatarID = new UUID((string)reader["UUID"]);
  716. user.firstName = (string)reader["username"];
  717. user.lastName = (string)reader["lastname"];
  718. returnlist.Add(user);
  719. }
  720. }
  721. }
  722. }
  723. catch (Exception e)
  724. {
  725. m_log.Error(e.ToString());
  726. }
  727. }
  728. return returnlist;
  729. }
  730. /// <summary>
  731. /// Store a weblogin key
  732. /// </summary>
  733. /// <param name="AgentID">The agent UUID</param>
  734. /// <param name="WebLoginKey">the WebLogin Key</param>
  735. /// <remarks>unused ?</remarks>
  736. override public void StoreWebLoginKey(UUID AgentID, UUID WebLoginKey)
  737. {
  738. UserProfileData user = GetUserByUUID(AgentID);
  739. user.WebLoginKey = WebLoginKey;
  740. UpdateUserProfile(user);
  741. }
  742. /// <summary>
  743. /// Database provider name
  744. /// </summary>
  745. /// <returns>Provider name</returns>
  746. override public string Name
  747. {
  748. get { return "MSSQL Userdata Interface"; }
  749. }
  750. /// <summary>
  751. /// Database provider version
  752. /// </summary>
  753. /// <returns>provider version</returns>
  754. override public string Version
  755. {
  756. get { return database.getVersion(); }
  757. }
  758. #endregion
  759. #region Private functions
  760. /// <summary>
  761. /// Reads a one item from an SQL result
  762. /// </summary>
  763. /// <param name="reader">The SQL Result</param>
  764. /// <returns>the item read</returns>
  765. private static AvatarAppearance readUserAppearance(IDataReader reader)
  766. {
  767. try
  768. {
  769. AvatarAppearance appearance = new AvatarAppearance();
  770. appearance.Owner = new UUID((string)reader["owner"]);
  771. appearance.Serial = Convert.ToInt32(reader["serial"]);
  772. appearance.VisualParams = (byte[])reader["visual_params"];
  773. appearance.Texture = new Primitive.TextureEntry((byte[])reader["texture"], 0, ((byte[])reader["texture"]).Length);
  774. appearance.AvatarHeight = (float)Convert.ToDouble(reader["avatar_height"]);
  775. appearance.BodyItem = new UUID((string)reader["body_item"]);
  776. appearance.BodyAsset = new UUID((string)reader["body_asset"]);
  777. appearance.SkinItem = new UUID((string)reader["skin_item"]);
  778. appearance.SkinAsset = new UUID((string)reader["skin_asset"]);
  779. appearance.HairItem = new UUID((string)reader["hair_item"]);
  780. appearance.HairAsset = new UUID((string)reader["hair_asset"]);
  781. appearance.EyesItem = new UUID((string)reader["eyes_item"]);
  782. appearance.EyesAsset = new UUID((string)reader["eyes_asset"]);
  783. appearance.ShirtItem = new UUID((string)reader["shirt_item"]);
  784. appearance.ShirtAsset = new UUID((string)reader["shirt_asset"]);
  785. appearance.PantsItem = new UUID((string)reader["pants_item"]);
  786. appearance.PantsAsset = new UUID((string)reader["pants_asset"]);
  787. appearance.ShoesItem = new UUID((string)reader["shoes_item"]);
  788. appearance.ShoesAsset = new UUID((string)reader["shoes_asset"]);
  789. appearance.SocksItem = new UUID((string)reader["socks_item"]);
  790. appearance.SocksAsset = new UUID((string)reader["socks_asset"]);
  791. appearance.JacketItem = new UUID((string)reader["jacket_item"]);
  792. appearance.JacketAsset = new UUID((string)reader["jacket_asset"]);
  793. appearance.GlovesItem = new UUID((string)reader["gloves_item"]);
  794. appearance.GlovesAsset = new UUID((string)reader["gloves_asset"]);
  795. appearance.UnderShirtItem = new UUID((string)reader["undershirt_item"]);
  796. appearance.UnderShirtAsset = new UUID((string)reader["undershirt_asset"]);
  797. appearance.UnderPantsItem = new UUID((string)reader["underpants_item"]);
  798. appearance.UnderPantsAsset = new UUID((string)reader["underpants_asset"]);
  799. appearance.SkirtItem = new UUID((string)reader["skirt_item"]);
  800. appearance.SkirtAsset = new UUID((string)reader["skirt_asset"]);
  801. return appearance;
  802. }
  803. catch (SqlException e)
  804. {
  805. m_log.Error(e.ToString());
  806. }
  807. return null;
  808. }
  809. /// <summary>
  810. /// Insert/Update a agent row in the DB.
  811. /// </summary>
  812. /// <param name="agentdata">agentdata.</param>
  813. private void InsertUpdateAgentRow(UserAgentData agentdata)
  814. {
  815. string sql = @"
  816. IF EXISTS (SELECT * FROM agents WHERE UUID = @UUID)
  817. BEGIN
  818. UPDATE agents SET UUID = @UUID, sessionID = @sessionID, secureSessionID = @secureSessionID, agentIP = @agentIP, agentPort = @agentPort, agentOnline = @agentOnline, loginTime = @loginTime, logoutTime = @logoutTime, currentRegion = @currentRegion, currentHandle = @currentHandle, currentPos = @currentPos
  819. WHERE UUID = @UUID
  820. END
  821. ELSE
  822. BEGIN
  823. INSERT INTO
  824. agents (UUID, sessionID, secureSessionID, agentIP, agentPort, agentOnline, loginTime, logoutTime, currentRegion, currentHandle, currentPos) VALUES
  825. (@UUID, @sessionID, @secureSessionID, @agentIP, @agentPort, @agentOnline, @loginTime, @logoutTime, @currentRegion, @currentHandle, @currentPos)
  826. END
  827. ";
  828. using (AutoClosingSqlCommand command = database.Query(sql))
  829. {
  830. command.Parameters.Add(database.CreateParameter("@UUID", agentdata.ProfileID));
  831. command.Parameters.Add(database.CreateParameter("@sessionID", agentdata.SessionID));
  832. command.Parameters.Add(database.CreateParameter("@secureSessionID", agentdata.SecureSessionID));
  833. command.Parameters.Add(database.CreateParameter("@agentIP", agentdata.AgentIP));
  834. command.Parameters.Add(database.CreateParameter("@agentPort", agentdata.AgentPort));
  835. command.Parameters.Add(database.CreateParameter("@agentOnline", agentdata.AgentOnline));
  836. command.Parameters.Add(database.CreateParameter("@loginTime", agentdata.LoginTime));
  837. command.Parameters.Add(database.CreateParameter("@logoutTime", agentdata.LogoutTime));
  838. command.Parameters.Add(database.CreateParameter("@currentRegion", agentdata.Region));
  839. command.Parameters.Add(database.CreateParameter("@currentHandle", agentdata.Handle));
  840. command.Parameters.Add(database.CreateParameter("@currentPos", "<" + ((int)agentdata.Position.X) + "," + ((int)agentdata.Position.Y) + "," + ((int)agentdata.Position.Z) + ">"));
  841. command.Transaction = command.Connection.BeginTransaction(IsolationLevel.Serializable);
  842. try
  843. {
  844. if (command.ExecuteNonQuery() > 0)
  845. {
  846. command.Transaction.Commit();
  847. return;
  848. }
  849. command.Transaction.Rollback();
  850. return;
  851. }
  852. catch (Exception e)
  853. {
  854. command.Transaction.Rollback();
  855. m_log.Error(e.ToString());
  856. return;
  857. }
  858. }
  859. }
  860. /// <summary>
  861. /// Reads an agent row from a database reader
  862. /// </summary>
  863. /// <param name="reader">An active database reader</param>
  864. /// <returns>A user session agent</returns>
  865. private UserAgentData readAgentRow(IDataReader reader)
  866. {
  867. UserAgentData retval = new UserAgentData();
  868. if (reader.Read())
  869. {
  870. // Agent IDs
  871. retval.ProfileID = new UUID((string)reader["UUID"]);
  872. retval.SessionID = new UUID((string)reader["sessionID"]);
  873. retval.SecureSessionID = new UUID((string)reader["secureSessionID"]);
  874. // Agent Who?
  875. retval.AgentIP = (string)reader["agentIP"];
  876. retval.AgentPort = Convert.ToUInt32(reader["agentPort"].ToString());
  877. retval.AgentOnline = Convert.ToInt32(reader["agentOnline"].ToString()) != 0;
  878. // Login/Logout times (UNIX Epoch)
  879. retval.LoginTime = Convert.ToInt32(reader["loginTime"].ToString());
  880. retval.LogoutTime = Convert.ToInt32(reader["logoutTime"].ToString());
  881. // Current position
  882. retval.Region = (UUID)(string)reader["currentRegion"];
  883. retval.Handle = Convert.ToUInt64(reader["currentHandle"].ToString());
  884. Vector3 tmp_v;
  885. Vector3.TryParse((string)reader["currentPos"], out tmp_v);
  886. retval.Position = tmp_v;
  887. }
  888. else
  889. {
  890. return null;
  891. }
  892. return retval;
  893. }
  894. /// <summary>
  895. /// Creates a new user and inserts it into the database
  896. /// </summary>
  897. /// <param name="uuid">User ID</param>
  898. /// <param name="username">First part of the login</param>
  899. /// <param name="lastname">Second part of the login</param>
  900. /// <param name="email">Email of person</param>
  901. /// <param name="passwordHash">A salted hash of the users password</param>
  902. /// <param name="passwordSalt">The salt used for the password hash</param>
  903. /// <param name="homeRegion">A regionHandle of the users home region</param>
  904. /// <param name="homeLocX">Home region position vector</param>
  905. /// <param name="homeLocY">Home region position vector</param>
  906. /// <param name="homeLocZ">Home region position vector</param>
  907. /// <param name="homeLookAtX">Home region 'look at' vector</param>
  908. /// <param name="homeLookAtY">Home region 'look at' vector</param>
  909. /// <param name="homeLookAtZ">Home region 'look at' vector</param>
  910. /// <param name="created">Account created (unix timestamp)</param>
  911. /// <param name="lastlogin">Last login (unix timestamp)</param>
  912. /// <param name="inventoryURI">Users inventory URI</param>
  913. /// <param name="assetURI">Users asset URI</param>
  914. /// <param name="canDoMask">I can do mask</param>
  915. /// <param name="wantDoMask">I want to do mask</param>
  916. /// <param name="aboutText">Profile text</param>
  917. /// <param name="firstText">Firstlife text</param>
  918. /// <param name="profileImage">UUID for profile image</param>
  919. /// <param name="firstImage">UUID for firstlife image</param>
  920. /// <param name="webLoginKey">web login key</param>
  921. /// <param name="homeRegionID">homeregion UUID</param>
  922. /// <param name="godLevel">has the user godlevel</param>
  923. /// <param name="userFlags">unknown</param>
  924. /// <param name="customType">unknown</param>
  925. /// <param name="partnerID">UUID of partner</param>
  926. /// <returns>Success?</returns>
  927. private void InsertUserRow(UUID uuid, string username, string lastname, string email, string passwordHash,
  928. string passwordSalt, UInt64 homeRegion, float homeLocX, float homeLocY, float homeLocZ,
  929. float homeLookAtX, float homeLookAtY, float homeLookAtZ, int created, int lastlogin,
  930. string inventoryURI, string assetURI, uint canDoMask, uint wantDoMask,
  931. string aboutText, string firstText,
  932. UUID profileImage, UUID firstImage, UUID webLoginKey, UUID homeRegionID,
  933. int godLevel, int userFlags, string customType, UUID partnerID)
  934. {
  935. string sql = "INSERT INTO " + m_usersTableName;
  936. sql += " ([UUID], [username], [lastname], [email], [passwordHash], [passwordSalt], [homeRegion], ";
  937. sql += "[homeLocationX], [homeLocationY], [homeLocationZ], [homeLookAtX], [homeLookAtY], [homeLookAtZ], [created], ";
  938. sql += "[lastLogin], [userInventoryURI], [userAssetURI], [profileCanDoMask], [profileWantDoMask], [profileAboutText], ";
  939. sql += "[profileFirstText], [profileImage], [profileFirstImage], [webLoginKey], ";
  940. sql += "[homeRegionID], [userFlags], [godLevel], [customType], [partner]) VALUES ";
  941. sql += "(@UUID, @username, @lastname, @email, @passwordHash, @passwordSalt, @homeRegion, ";
  942. sql += "@homeLocationX, @homeLocationY, @homeLocationZ, @homeLookAtX, @homeLookAtY, @homeLookAtZ, @created, ";
  943. sql += "@lastLogin, @userInventoryURI, @userAssetURI, @profileCanDoMask, @profileWantDoMask, @profileAboutText, ";
  944. sql += "@profileFirstText, @profileImage, @profileFirstImage, @webLoginKey, ";
  945. sql += "@homeRegionID, @userFlags, @godLevel, @customType, @partner)";
  946. try
  947. {
  948. using (AutoClosingSqlCommand command = database.Query(sql))
  949. {
  950. command.Parameters.Add(database.CreateParameter("UUID", uuid));
  951. command.Parameters.Add(database.CreateParameter("username", username));
  952. command.Parameters.Add(database.CreateParameter("lastname", lastname));
  953. command.Parameters.Add(database.CreateParameter("email", email));
  954. command.Parameters.Add(database.CreateParameter("passwordHash", passwordHash));
  955. command.Parameters.Add(database.CreateParameter("passwordSalt", passwordSalt));
  956. command.Parameters.Add(database.CreateParameter("homeRegion", homeRegion));
  957. command.Parameters.Add(database.CreateParameter("homeLocationX", homeLocX));
  958. command.Parameters.Add(database.CreateParameter("homeLocationY", homeLocY));
  959. command.Parameters.Add(database.CreateParameter("homeLocationZ", homeLocZ));
  960. command.Parameters.Add(database.CreateParameter("homeLookAtX", homeLookAtX));
  961. command.Parameters.Add(database.CreateParameter("homeLookAtY", homeLookAtY));
  962. command.Parameters.Add(database.CreateParameter("homeLookAtZ", homeLookAtZ));
  963. command.Parameters.Add(database.CreateParameter("created", created));
  964. command.Parameters.Add(database.CreateParameter("lastLogin", lastlogin));
  965. command.Parameters.Add(database.CreateParameter("userInventoryURI", inventoryURI));
  966. command.Parameters.Add(database.CreateParameter("userAssetURI", assetURI));
  967. command.Parameters.Add(database.CreateParameter("profileCanDoMask", canDoMask));
  968. command.Parameters.Add(database.CreateParameter("profileWantDoMask", wantDoMask));
  969. command.Parameters.Add(database.CreateParameter("profileAboutText", aboutText));
  970. command.Parameters.Add(database.CreateParameter("profileFirstText", firstText));
  971. command.Parameters.Add(database.CreateParameter("profileImage", profileImage));
  972. command.Parameters.Add(database.CreateParameter("profileFirstImage", firstImage));
  973. command.Parameters.Add(database.CreateParameter("webLoginKey", webLoginKey));
  974. //
  975. command.Parameters.Add(database.CreateParameter("homeRegionID", homeRegionID));
  976. command.Parameters.Add(database.CreateParameter("userFlags", userFlags));
  977. command.Parameters.Add(database.CreateParameter("godLevel", godLevel));
  978. command.Parameters.Add(database.CreateParameter("customType", customType));
  979. command.Parameters.Add(database.CreateParameter("partner", partnerID));
  980. command.ExecuteNonQuery();
  981. return;
  982. }
  983. }
  984. catch (Exception e)
  985. {
  986. m_log.Error(e.ToString());
  987. return;
  988. }
  989. }
  990. /// <summary>
  991. /// Reads a user profile from an active data reader
  992. /// </summary>
  993. /// <param name="reader">An active database reader</param>
  994. /// <returns>A user profile</returns>
  995. private static UserProfileData ReadUserRow(IDataReader reader)
  996. {
  997. UserProfileData retval = new UserProfileData();
  998. if (reader.Read())
  999. {
  1000. retval.ID = new UUID((string)reader["UUID"]);
  1001. retval.FirstName = (string)reader["username"];
  1002. retval.SurName = (string)reader["lastname"];
  1003. retval.PasswordHash = (string)reader["passwordHash"];
  1004. retval.PasswordSalt = (string)reader["passwordSalt"];
  1005. retval.HomeRegion = Convert.ToUInt64(reader["homeRegion"].ToString());
  1006. retval.HomeLocation = new Vector3(
  1007. Convert.ToSingle(reader["homeLocationX"].ToString()),
  1008. Convert.ToSingle(reader["homeLocationY"].ToString()),
  1009. Convert.ToSingle(reader["homeLocationZ"].ToString()));
  1010. retval.HomeLookAt = new Vector3(
  1011. Convert.ToSingle(reader["homeLookAtX"].ToString()),
  1012. Convert.ToSingle(reader["homeLookAtY"].ToString()),
  1013. Convert.ToSingle(reader["homeLookAtZ"].ToString()));
  1014. retval.Created = Convert.ToInt32(reader["created"].ToString());
  1015. retval.LastLogin = Convert.ToInt32(reader["lastLogin"].ToString());
  1016. retval.UserInventoryURI = (string)reader["userInventoryURI"];
  1017. retval.UserAssetURI = (string)reader["userAssetURI"];
  1018. retval.CanDoMask = Convert.ToUInt32(reader["profileCanDoMask"].ToString());
  1019. retval.WantDoMask = Convert.ToUInt32(reader["profileWantDoMask"].ToString());
  1020. retval.AboutText = (string)reader["profileAboutText"];
  1021. retval.FirstLifeAboutText = (string)reader["profileFirstText"];
  1022. retval.Image = new UUID((string)reader["profileImage"]);
  1023. retval.FirstLifeImage = new UUID((string)reader["profileFirstImage"]);
  1024. retval.WebLoginKey = new UUID((string)reader["webLoginKey"]);
  1025. }
  1026. else
  1027. {
  1028. return null;
  1029. }
  1030. return retval;
  1031. }
  1032. #endregion
  1033. }
  1034. }