MSSQLUserData.cs 58 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194
  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 log4net;
  34. using OpenMetaverse;
  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((Guid)reader["ownerID"]);
  409. fli.Friend = new UUID((Guid)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. override public AvatarAppearance GetUserAppearance(UUID user)
  487. {
  488. try
  489. {
  490. AvatarAppearance appearance = new AvatarAppearance();
  491. using (AutoClosingSqlCommand command = database.Query("SELECT * FROM avatarappearance WHERE owner = @UUID"))
  492. {
  493. command.Parameters.Add(database.CreateParameter("@UUID", user));
  494. using (IDataReader reader = command.ExecuteReader())
  495. {
  496. if (reader.Read())
  497. appearance = readUserAppearance(reader);
  498. else
  499. {
  500. m_log.WarnFormat("[USER DB] No appearance found for user {0}", user.ToString());
  501. return null;
  502. }
  503. }
  504. }
  505. appearance.SetAttachments(GetUserAttachments(user));
  506. return appearance;
  507. }
  508. catch (Exception e)
  509. {
  510. m_log.Error("[USER DB] Error updating userfriend, error: " + e.Message);
  511. }
  512. return null;
  513. }
  514. /// <summary>
  515. /// Update a user appearence into database
  516. /// </summary>
  517. /// <param name="user">the used UUID</param>
  518. /// <param name="appearance">the appearence</param>
  519. override public void UpdateUserAppearance(UUID user, AvatarAppearance appearance)
  520. {
  521. string sql = String.Empty;
  522. sql += "DELETE FROM avatarappearance WHERE owner=@owner ";
  523. sql += "INSERT INTO avatarappearance ";
  524. sql += "(owner, serial, visual_params, texture, avatar_height, ";
  525. sql += "body_item, body_asset, skin_item, skin_asset, hair_item, hair_asset, eyes_item, eyes_asset, ";
  526. sql += "shirt_item, shirt_asset, pants_item, pants_asset, shoes_item, shoes_asset, socks_item, socks_asset, ";
  527. sql += "jacket_item, jacket_asset, gloves_item, gloves_asset, undershirt_item, undershirt_asset, underpants_item, underpants_asset, ";
  528. sql += "skirt_item, skirt_asset) values (";
  529. sql += "@owner, @serial, @visual_params, @texture, @avatar_height, ";
  530. sql += "@body_item, @body_asset, @skin_item, @skin_asset, @hair_item, @hair_asset, @eyes_item, @eyes_asset, ";
  531. sql += "@shirt_item, @shirt_asset, @pants_item, @pants_asset, @shoes_item, @shoes_asset, @socks_item, @socks_asset, ";
  532. sql += "@jacket_item, @jacket_asset, @gloves_item, @gloves_asset, @undershirt_item, @undershirt_asset, @underpants_item, @underpants_asset, ";
  533. sql += "@skirt_item, @skirt_asset)";
  534. using (AutoClosingSqlCommand cmd = database.Query(sql))
  535. {
  536. cmd.Parameters.Add(database.CreateParameter("@owner", appearance.Owner));
  537. cmd.Parameters.Add(database.CreateParameter("@serial", appearance.Serial));
  538. cmd.Parameters.Add(database.CreateParameter("@visual_params", appearance.VisualParams));
  539. cmd.Parameters.Add(database.CreateParameter("@texture", appearance.Texture.GetBytes()));
  540. cmd.Parameters.Add(database.CreateParameter("@avatar_height", appearance.AvatarHeight));
  541. cmd.Parameters.Add(database.CreateParameter("@body_item", appearance.BodyItem));
  542. cmd.Parameters.Add(database.CreateParameter("@body_asset", appearance.BodyAsset));
  543. cmd.Parameters.Add(database.CreateParameter("@skin_item", appearance.SkinItem));
  544. cmd.Parameters.Add(database.CreateParameter("@skin_asset", appearance.SkinAsset));
  545. cmd.Parameters.Add(database.CreateParameter("@hair_item", appearance.HairItem));
  546. cmd.Parameters.Add(database.CreateParameter("@hair_asset", appearance.HairAsset));
  547. cmd.Parameters.Add(database.CreateParameter("@eyes_item", appearance.EyesItem));
  548. cmd.Parameters.Add(database.CreateParameter("@eyes_asset", appearance.EyesAsset));
  549. cmd.Parameters.Add(database.CreateParameter("@shirt_item", appearance.ShirtItem));
  550. cmd.Parameters.Add(database.CreateParameter("@shirt_asset", appearance.ShirtAsset));
  551. cmd.Parameters.Add(database.CreateParameter("@pants_item", appearance.PantsItem));
  552. cmd.Parameters.Add(database.CreateParameter("@pants_asset", appearance.PantsAsset));
  553. cmd.Parameters.Add(database.CreateParameter("@shoes_item", appearance.ShoesItem));
  554. cmd.Parameters.Add(database.CreateParameter("@shoes_asset", appearance.ShoesAsset));
  555. cmd.Parameters.Add(database.CreateParameter("@socks_item", appearance.SocksItem));
  556. cmd.Parameters.Add(database.CreateParameter("@socks_asset", appearance.SocksAsset));
  557. cmd.Parameters.Add(database.CreateParameter("@jacket_item", appearance.JacketItem));
  558. cmd.Parameters.Add(database.CreateParameter("@jacket_asset", appearance.JacketAsset));
  559. cmd.Parameters.Add(database.CreateParameter("@gloves_item", appearance.GlovesItem));
  560. cmd.Parameters.Add(database.CreateParameter("@gloves_asset", appearance.GlovesAsset));
  561. cmd.Parameters.Add(database.CreateParameter("@undershirt_item", appearance.UnderShirtItem));
  562. cmd.Parameters.Add(database.CreateParameter("@undershirt_asset", appearance.UnderShirtAsset));
  563. cmd.Parameters.Add(database.CreateParameter("@underpants_item", appearance.UnderPantsItem));
  564. cmd.Parameters.Add(database.CreateParameter("@underpants_asset", appearance.UnderPantsAsset));
  565. cmd.Parameters.Add(database.CreateParameter("@skirt_item", appearance.SkirtItem));
  566. cmd.Parameters.Add(database.CreateParameter("@skirt_asset", appearance.SkirtAsset));
  567. try
  568. {
  569. cmd.ExecuteNonQuery();
  570. }
  571. catch (Exception e)
  572. {
  573. m_log.Error("[USER DB] Error updating user appearance, error: " + e.Message);
  574. }
  575. }
  576. UpdateUserAttachments(user, appearance.GetAttachments());
  577. }
  578. #endregion
  579. #region Attachment methods
  580. /// <summary>
  581. /// Gets all attachment of a agent.
  582. /// </summary>
  583. /// <param name="agentID">agent ID.</param>
  584. /// <returns></returns>
  585. public Hashtable GetUserAttachments(UUID agentID)
  586. {
  587. Hashtable returnTable = new Hashtable();
  588. using (AutoClosingSqlCommand command = database.Query("select attachpoint, item, asset from avatarattachments where UUID = @uuid", database.CreateParameter("@uuid", agentID)))
  589. {
  590. using (SqlDataReader reader = command.ExecuteReader())
  591. {
  592. while (reader.Read())
  593. {
  594. int attachpoint = Convert.ToInt32(reader["attachpoint"]);
  595. if (returnTable.ContainsKey(attachpoint))
  596. continue;
  597. Hashtable item = new Hashtable();
  598. item.Add("item", reader["item"].ToString());
  599. item.Add("asset", reader["asset"].ToString());
  600. returnTable.Add(attachpoint, item);
  601. }
  602. }
  603. }
  604. return returnTable;
  605. }
  606. /// <summary>
  607. /// Updates all attachments of the agent.
  608. /// </summary>
  609. /// <param name="agentID">agentID.</param>
  610. /// <param name="data">data with all items on attachmentpoints</param>
  611. public void UpdateUserAttachments(UUID agentID, Hashtable data)
  612. {
  613. string sql = "delete from avatarattachments where UUID = @uuid";
  614. using (AutoClosingSqlCommand command = database.Query(sql))
  615. {
  616. command.Parameters.Add(database.CreateParameter("uuid", agentID));
  617. command.ExecuteNonQuery();
  618. }
  619. if (data == null)
  620. return;
  621. sql = "insert into avatarattachments (UUID, attachpoint, item, asset) values (@uuid, @attachpoint, @item, @asset)";
  622. using (AutoClosingSqlCommand command = database.Query(sql))
  623. {
  624. bool firstTime = true;
  625. foreach (DictionaryEntry e in data)
  626. {
  627. int attachpoint = Convert.ToInt32(e.Key);
  628. Hashtable item = (Hashtable)e.Value;
  629. if (firstTime)
  630. {
  631. command.Parameters.Add(database.CreateParameter("@uuid", agentID));
  632. command.Parameters.Add(database.CreateParameter("@attachpoint", attachpoint));
  633. command.Parameters.Add(database.CreateParameter("@item", new UUID(item["item"].ToString())));
  634. command.Parameters.Add(database.CreateParameter("@asset", new UUID(item["asset"].ToString())));
  635. firstTime = false;
  636. }
  637. command.Parameters["@uuid"].Value = agentID.Guid; //.ToString();
  638. command.Parameters["@attachpoint"].Value = attachpoint;
  639. command.Parameters["@item"].Value = new Guid(item["item"].ToString());
  640. command.Parameters["@asset"].Value = new Guid(item["asset"].ToString());
  641. try
  642. {
  643. command.ExecuteNonQuery();
  644. }
  645. catch (Exception ex)
  646. {
  647. m_log.DebugFormat("[USER DB] : Error adding user attachment. {0}", ex.Message);
  648. }
  649. }
  650. }
  651. }
  652. /// <summary>
  653. /// Resets all attachments of a agent in the database.
  654. /// </summary>
  655. /// <param name="agentID">agentID.</param>
  656. override public void ResetAttachments(UUID agentID)
  657. {
  658. using (AutoClosingSqlCommand command = database.Query("update avatarattachments set asset = '00000000-0000-0000-0000-000000000000' where UUID = @uuid"))
  659. {
  660. command.Parameters.Add(database.CreateParameter("uuid", agentID));
  661. command.ExecuteNonQuery();
  662. }
  663. }
  664. override public void LogoutUsers(UUID regionID)
  665. {
  666. }
  667. #endregion
  668. #region Other public methods
  669. /// <summary>
  670. ///
  671. /// </summary>
  672. /// <param name="queryID"></param>
  673. /// <param name="query"></param>
  674. /// <returns></returns>
  675. override public List<AvatarPickerAvatar> GeneratePickerResults(UUID queryID, string query)
  676. {
  677. List<AvatarPickerAvatar> returnlist = new List<AvatarPickerAvatar>();
  678. string[] querysplit = query.Split(' ');
  679. if (querysplit.Length == 2)
  680. {
  681. try
  682. {
  683. using (AutoClosingSqlCommand command = database.Query("SELECT UUID,username,lastname FROM " + m_usersTableName + " WHERE username LIKE @first AND lastname LIKE @second"))
  684. {
  685. //Add wildcard to the search
  686. command.Parameters.Add(database.CreateParameter("first", querysplit[0] + "%"));
  687. command.Parameters.Add(database.CreateParameter("second", querysplit[1] + "%"));
  688. using (IDataReader reader = command.ExecuteReader())
  689. {
  690. while (reader.Read())
  691. {
  692. AvatarPickerAvatar user = new AvatarPickerAvatar();
  693. user.AvatarID = new UUID((Guid)reader["UUID"]);
  694. user.firstName = (string)reader["username"];
  695. user.lastName = (string)reader["lastname"];
  696. returnlist.Add(user);
  697. }
  698. }
  699. }
  700. }
  701. catch (Exception e)
  702. {
  703. m_log.Error(e.ToString());
  704. }
  705. }
  706. else if (querysplit.Length == 1)
  707. {
  708. try
  709. {
  710. using (AutoClosingSqlCommand command = database.Query("SELECT UUID,username,lastname FROM " + m_usersTableName + " WHERE username LIKE @first OR lastname LIKE @first"))
  711. {
  712. command.Parameters.Add(database.CreateParameter("first", querysplit[0] + "%"));
  713. using (IDataReader reader = command.ExecuteReader())
  714. {
  715. while (reader.Read())
  716. {
  717. AvatarPickerAvatar user = new AvatarPickerAvatar();
  718. user.AvatarID = new UUID((Guid)reader["UUID"]);
  719. user.firstName = (string)reader["username"];
  720. user.lastName = (string)reader["lastname"];
  721. returnlist.Add(user);
  722. }
  723. }
  724. }
  725. }
  726. catch (Exception e)
  727. {
  728. m_log.Error(e.ToString());
  729. }
  730. }
  731. return returnlist;
  732. }
  733. /// <summary>
  734. /// Store a weblogin key
  735. /// </summary>
  736. /// <param name="AgentID">The agent UUID</param>
  737. /// <param name="WebLoginKey">the WebLogin Key</param>
  738. /// <remarks>unused ?</remarks>
  739. override public void StoreWebLoginKey(UUID AgentID, UUID WebLoginKey)
  740. {
  741. UserProfileData user = GetUserByUUID(AgentID);
  742. user.WebLoginKey = WebLoginKey;
  743. UpdateUserProfile(user);
  744. }
  745. /// <summary>
  746. /// Database provider name
  747. /// </summary>
  748. /// <returns>Provider name</returns>
  749. override public string Name
  750. {
  751. get { return "MSSQL Userdata Interface"; }
  752. }
  753. /// <summary>
  754. /// Database provider version
  755. /// </summary>
  756. /// <returns>provider version</returns>
  757. override public string Version
  758. {
  759. get { return database.getVersion(); }
  760. }
  761. #endregion
  762. #region Private functions
  763. /// <summary>
  764. /// Reads a one item from an SQL result
  765. /// </summary>
  766. /// <param name="reader">The SQL Result</param>
  767. /// <returns>the item read</returns>
  768. private static AvatarAppearance readUserAppearance(IDataReader reader)
  769. {
  770. try
  771. {
  772. AvatarAppearance appearance = new AvatarAppearance();
  773. appearance.Owner = new UUID((Guid)reader["owner"]);
  774. appearance.Serial = Convert.ToInt32(reader["serial"]);
  775. appearance.VisualParams = (byte[])reader["visual_params"];
  776. appearance.Texture = new Primitive.TextureEntry((byte[])reader["texture"], 0, ((byte[])reader["texture"]).Length);
  777. appearance.AvatarHeight = (float)Convert.ToDouble(reader["avatar_height"]);
  778. appearance.BodyItem = new UUID((Guid)reader["body_item"]);
  779. appearance.BodyAsset = new UUID((Guid)reader["body_asset"]);
  780. appearance.SkinItem = new UUID((Guid)reader["skin_item"]);
  781. appearance.SkinAsset = new UUID((Guid)reader["skin_asset"]);
  782. appearance.HairItem = new UUID((Guid)reader["hair_item"]);
  783. appearance.HairAsset = new UUID((Guid)reader["hair_asset"]);
  784. appearance.EyesItem = new UUID((Guid)reader["eyes_item"]);
  785. appearance.EyesAsset = new UUID((Guid)reader["eyes_asset"]);
  786. appearance.ShirtItem = new UUID((Guid)reader["shirt_item"]);
  787. appearance.ShirtAsset = new UUID((Guid)reader["shirt_asset"]);
  788. appearance.PantsItem = new UUID((Guid)reader["pants_item"]);
  789. appearance.PantsAsset = new UUID((Guid)reader["pants_asset"]);
  790. appearance.ShoesItem = new UUID((Guid)reader["shoes_item"]);
  791. appearance.ShoesAsset = new UUID((Guid)reader["shoes_asset"]);
  792. appearance.SocksItem = new UUID((Guid)reader["socks_item"]);
  793. appearance.SocksAsset = new UUID((Guid)reader["socks_asset"]);
  794. appearance.JacketItem = new UUID((Guid)reader["jacket_item"]);
  795. appearance.JacketAsset = new UUID((Guid)reader["jacket_asset"]);
  796. appearance.GlovesItem = new UUID((Guid)reader["gloves_item"]);
  797. appearance.GlovesAsset = new UUID((Guid)reader["gloves_asset"]);
  798. appearance.UnderShirtItem = new UUID((Guid)reader["undershirt_item"]);
  799. appearance.UnderShirtAsset = new UUID((Guid)reader["undershirt_asset"]);
  800. appearance.UnderPantsItem = new UUID((Guid)reader["underpants_item"]);
  801. appearance.UnderPantsAsset = new UUID((Guid)reader["underpants_asset"]);
  802. appearance.SkirtItem = new UUID((Guid)reader["skirt_item"]);
  803. appearance.SkirtAsset = new UUID((Guid)reader["skirt_asset"]);
  804. return appearance;
  805. }
  806. catch (SqlException e)
  807. {
  808. m_log.Error(e.ToString());
  809. }
  810. return null;
  811. }
  812. /// <summary>
  813. /// Insert/Update a agent row in the DB.
  814. /// </summary>
  815. /// <param name="agentdata">agentdata.</param>
  816. private void InsertUpdateAgentRow(UserAgentData agentdata)
  817. {
  818. string sql = @"
  819. IF EXISTS (SELECT * FROM agents WHERE UUID = @UUID)
  820. BEGIN
  821. 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
  822. WHERE UUID = @UUID
  823. END
  824. ELSE
  825. BEGIN
  826. INSERT INTO
  827. agents (UUID, sessionID, secureSessionID, agentIP, agentPort, agentOnline, loginTime, logoutTime, currentRegion, currentHandle, currentPos) VALUES
  828. (@UUID, @sessionID, @secureSessionID, @agentIP, @agentPort, @agentOnline, @loginTime, @logoutTime, @currentRegion, @currentHandle, @currentPos)
  829. END
  830. ";
  831. using (AutoClosingSqlCommand command = database.Query(sql))
  832. {
  833. command.Parameters.Add(database.CreateParameter("@UUID", agentdata.ProfileID));
  834. command.Parameters.Add(database.CreateParameter("@sessionID", agentdata.SessionID));
  835. command.Parameters.Add(database.CreateParameter("@secureSessionID", agentdata.SecureSessionID));
  836. command.Parameters.Add(database.CreateParameter("@agentIP", agentdata.AgentIP));
  837. command.Parameters.Add(database.CreateParameter("@agentPort", agentdata.AgentPort));
  838. command.Parameters.Add(database.CreateParameter("@agentOnline", agentdata.AgentOnline));
  839. command.Parameters.Add(database.CreateParameter("@loginTime", agentdata.LoginTime));
  840. command.Parameters.Add(database.CreateParameter("@logoutTime", agentdata.LogoutTime));
  841. command.Parameters.Add(database.CreateParameter("@currentRegion", agentdata.Region));
  842. command.Parameters.Add(database.CreateParameter("@currentHandle", agentdata.Handle));
  843. command.Parameters.Add(database.CreateParameter("@currentPos", "<" + ((int)agentdata.Position.X) + "," + ((int)agentdata.Position.Y) + "," + ((int)agentdata.Position.Z) + ">"));
  844. command.Transaction = command.Connection.BeginTransaction(IsolationLevel.Serializable);
  845. try
  846. {
  847. if (command.ExecuteNonQuery() > 0)
  848. {
  849. command.Transaction.Commit();
  850. return;
  851. }
  852. command.Transaction.Rollback();
  853. return;
  854. }
  855. catch (Exception e)
  856. {
  857. command.Transaction.Rollback();
  858. m_log.Error(e.ToString());
  859. return;
  860. }
  861. }
  862. }
  863. /// <summary>
  864. /// Reads an agent row from a database reader
  865. /// </summary>
  866. /// <param name="reader">An active database reader</param>
  867. /// <returns>A user session agent</returns>
  868. private UserAgentData readAgentRow(IDataReader reader)
  869. {
  870. UserAgentData retval = new UserAgentData();
  871. if (reader.Read())
  872. {
  873. // Agent IDs
  874. retval.ProfileID = new UUID((Guid)reader["UUID"]);
  875. retval.SessionID = new UUID((Guid)reader["sessionID"]);
  876. retval.SecureSessionID = new UUID((Guid)reader["secureSessionID"]);
  877. // Agent Who?
  878. retval.AgentIP = (string)reader["agentIP"];
  879. retval.AgentPort = Convert.ToUInt32(reader["agentPort"].ToString());
  880. retval.AgentOnline = Convert.ToInt32(reader["agentOnline"].ToString()) != 0;
  881. // Login/Logout times (UNIX Epoch)
  882. retval.LoginTime = Convert.ToInt32(reader["loginTime"].ToString());
  883. retval.LogoutTime = Convert.ToInt32(reader["logoutTime"].ToString());
  884. // Current position
  885. retval.Region = new UUID((Guid)reader["currentRegion"]);
  886. retval.Handle = Convert.ToUInt64(reader["currentHandle"].ToString());
  887. Vector3 tmp_v;
  888. Vector3.TryParse((string)reader["currentPos"], out tmp_v);
  889. retval.Position = tmp_v;
  890. }
  891. else
  892. {
  893. return null;
  894. }
  895. return retval;
  896. }
  897. /// <summary>
  898. /// Creates a new user and inserts it into the database
  899. /// </summary>
  900. /// <param name="uuid">User ID</param>
  901. /// <param name="username">First part of the login</param>
  902. /// <param name="lastname">Second part of the login</param>
  903. /// <param name="email">Email of person</param>
  904. /// <param name="passwordHash">A salted hash of the users password</param>
  905. /// <param name="passwordSalt">The salt used for the password hash</param>
  906. /// <param name="homeRegion">A regionHandle of the users home region</param>
  907. /// <param name="homeLocX">Home region position vector</param>
  908. /// <param name="homeLocY">Home region position vector</param>
  909. /// <param name="homeLocZ">Home region position vector</param>
  910. /// <param name="homeLookAtX">Home region 'look at' vector</param>
  911. /// <param name="homeLookAtY">Home region 'look at' vector</param>
  912. /// <param name="homeLookAtZ">Home region 'look at' vector</param>
  913. /// <param name="created">Account created (unix timestamp)</param>
  914. /// <param name="lastlogin">Last login (unix timestamp)</param>
  915. /// <param name="inventoryURI">Users inventory URI</param>
  916. /// <param name="assetURI">Users asset URI</param>
  917. /// <param name="canDoMask">I can do mask</param>
  918. /// <param name="wantDoMask">I want to do mask</param>
  919. /// <param name="aboutText">Profile text</param>
  920. /// <param name="firstText">Firstlife text</param>
  921. /// <param name="profileImage">UUID for profile image</param>
  922. /// <param name="firstImage">UUID for firstlife image</param>
  923. /// <param name="webLoginKey">web login key</param>
  924. /// <param name="homeRegionID">homeregion UUID</param>
  925. /// <param name="godLevel">has the user godlevel</param>
  926. /// <param name="userFlags">unknown</param>
  927. /// <param name="customType">unknown</param>
  928. /// <param name="partnerID">UUID of partner</param>
  929. /// <returns>Success?</returns>
  930. private void InsertUserRow(UUID uuid, string username, string lastname, string email, string passwordHash,
  931. string passwordSalt, UInt64 homeRegion, float homeLocX, float homeLocY, float homeLocZ,
  932. float homeLookAtX, float homeLookAtY, float homeLookAtZ, int created, int lastlogin,
  933. string inventoryURI, string assetURI, uint canDoMask, uint wantDoMask,
  934. string aboutText, string firstText,
  935. UUID profileImage, UUID firstImage, UUID webLoginKey, UUID homeRegionID,
  936. int godLevel, int userFlags, string customType, UUID partnerID)
  937. {
  938. string sql = "INSERT INTO " + m_usersTableName;
  939. sql += " ([UUID], [username], [lastname], [email], [passwordHash], [passwordSalt], [homeRegion], ";
  940. sql += "[homeLocationX], [homeLocationY], [homeLocationZ], [homeLookAtX], [homeLookAtY], [homeLookAtZ], [created], ";
  941. sql += "[lastLogin], [userInventoryURI], [userAssetURI], [profileCanDoMask], [profileWantDoMask], [profileAboutText], ";
  942. sql += "[profileFirstText], [profileImage], [profileFirstImage], [webLoginKey], ";
  943. sql += "[homeRegionID], [userFlags], [godLevel], [customType], [partner]) VALUES ";
  944. sql += "(@UUID, @username, @lastname, @email, @passwordHash, @passwordSalt, @homeRegion, ";
  945. sql += "@homeLocationX, @homeLocationY, @homeLocationZ, @homeLookAtX, @homeLookAtY, @homeLookAtZ, @created, ";
  946. sql += "@lastLogin, @userInventoryURI, @userAssetURI, @profileCanDoMask, @profileWantDoMask, @profileAboutText, ";
  947. sql += "@profileFirstText, @profileImage, @profileFirstImage, @webLoginKey, ";
  948. sql += "@homeRegionID, @userFlags, @godLevel, @customType, @partner)";
  949. try
  950. {
  951. using (AutoClosingSqlCommand command = database.Query(sql))
  952. {
  953. command.Parameters.Add(database.CreateParameter("UUID", uuid));
  954. command.Parameters.Add(database.CreateParameter("username", username));
  955. command.Parameters.Add(database.CreateParameter("lastname", lastname));
  956. command.Parameters.Add(database.CreateParameter("email", email));
  957. command.Parameters.Add(database.CreateParameter("passwordHash", passwordHash));
  958. command.Parameters.Add(database.CreateParameter("passwordSalt", passwordSalt));
  959. command.Parameters.Add(database.CreateParameter("homeRegion", homeRegion));
  960. command.Parameters.Add(database.CreateParameter("homeLocationX", homeLocX));
  961. command.Parameters.Add(database.CreateParameter("homeLocationY", homeLocY));
  962. command.Parameters.Add(database.CreateParameter("homeLocationZ", homeLocZ));
  963. command.Parameters.Add(database.CreateParameter("homeLookAtX", homeLookAtX));
  964. command.Parameters.Add(database.CreateParameter("homeLookAtY", homeLookAtY));
  965. command.Parameters.Add(database.CreateParameter("homeLookAtZ", homeLookAtZ));
  966. command.Parameters.Add(database.CreateParameter("created", created));
  967. command.Parameters.Add(database.CreateParameter("lastLogin", lastlogin));
  968. command.Parameters.Add(database.CreateParameter("userInventoryURI", inventoryURI));
  969. command.Parameters.Add(database.CreateParameter("userAssetURI", assetURI));
  970. command.Parameters.Add(database.CreateParameter("profileCanDoMask", canDoMask));
  971. command.Parameters.Add(database.CreateParameter("profileWantDoMask", wantDoMask));
  972. command.Parameters.Add(database.CreateParameter("profileAboutText", aboutText));
  973. command.Parameters.Add(database.CreateParameter("profileFirstText", firstText));
  974. command.Parameters.Add(database.CreateParameter("profileImage", profileImage));
  975. command.Parameters.Add(database.CreateParameter("profileFirstImage", firstImage));
  976. command.Parameters.Add(database.CreateParameter("webLoginKey", webLoginKey));
  977. //
  978. command.Parameters.Add(database.CreateParameter("homeRegionID", homeRegionID));
  979. command.Parameters.Add(database.CreateParameter("userFlags", userFlags));
  980. command.Parameters.Add(database.CreateParameter("godLevel", godLevel));
  981. command.Parameters.Add(database.CreateParameter("customType", customType));
  982. command.Parameters.Add(database.CreateParameter("partner", partnerID));
  983. command.ExecuteNonQuery();
  984. return;
  985. }
  986. }
  987. catch (Exception e)
  988. {
  989. m_log.Error(e.ToString());
  990. return;
  991. }
  992. }
  993. /// <summary>
  994. /// Reads a user profile from an active data reader
  995. /// </summary>
  996. /// <param name="reader">An active database reader</param>
  997. /// <returns>A user profile</returns>
  998. private static UserProfileData ReadUserRow(IDataReader reader)
  999. {
  1000. UserProfileData retval = new UserProfileData();
  1001. if (reader.Read())
  1002. {
  1003. retval.ID = new UUID((Guid)reader["UUID"]);
  1004. retval.FirstName = (string)reader["username"];
  1005. retval.SurName = (string)reader["lastname"];
  1006. if (reader.IsDBNull(reader.GetOrdinal("email")))
  1007. retval.Email = "";
  1008. else
  1009. retval.Email = (string)reader["email"];
  1010. retval.PasswordHash = (string)reader["passwordHash"];
  1011. retval.PasswordSalt = (string)reader["passwordSalt"];
  1012. retval.HomeRegion = Convert.ToUInt64(reader["homeRegion"].ToString());
  1013. retval.HomeLocation = new Vector3(
  1014. Convert.ToSingle(reader["homeLocationX"].ToString()),
  1015. Convert.ToSingle(reader["homeLocationY"].ToString()),
  1016. Convert.ToSingle(reader["homeLocationZ"].ToString()));
  1017. retval.HomeLookAt = new Vector3(
  1018. Convert.ToSingle(reader["homeLookAtX"].ToString()),
  1019. Convert.ToSingle(reader["homeLookAtY"].ToString()),
  1020. Convert.ToSingle(reader["homeLookAtZ"].ToString()));
  1021. if (reader.IsDBNull(reader.GetOrdinal("homeRegionID")))
  1022. retval.HomeRegionID = UUID.Zero;
  1023. else
  1024. retval.HomeRegionID = new UUID((Guid)reader["homeRegionID"]);
  1025. retval.Created = Convert.ToInt32(reader["created"].ToString());
  1026. retval.LastLogin = Convert.ToInt32(reader["lastLogin"].ToString());
  1027. retval.UserInventoryURI = (string)reader["userInventoryURI"];
  1028. retval.UserAssetURI = (string)reader["userAssetURI"];
  1029. retval.CanDoMask = Convert.ToUInt32(reader["profileCanDoMask"].ToString());
  1030. retval.WantDoMask = Convert.ToUInt32(reader["profileWantDoMask"].ToString());
  1031. if (reader.IsDBNull(reader.GetOrdinal("profileAboutText")))
  1032. retval.AboutText = "";
  1033. else
  1034. retval.AboutText = (string)reader["profileAboutText"];
  1035. if (reader.IsDBNull(reader.GetOrdinal("profileFirstText")))
  1036. retval.FirstLifeAboutText = "";
  1037. else
  1038. retval.FirstLifeAboutText = (string)reader["profileFirstText"];
  1039. if (reader.IsDBNull(reader.GetOrdinal("profileImage")))
  1040. retval.Image = UUID.Zero;
  1041. else
  1042. retval.Image = new UUID((Guid)reader["profileImage"]);
  1043. if (reader.IsDBNull(reader.GetOrdinal("profileFirstImage")))
  1044. retval.Image = UUID.Zero;
  1045. else
  1046. retval.FirstLifeImage = new UUID((Guid)reader["profileFirstImage"]);
  1047. if (reader.IsDBNull(reader.GetOrdinal("webLoginKey")))
  1048. retval.WebLoginKey = UUID.Zero;
  1049. else
  1050. retval.WebLoginKey = new UUID((Guid)reader["webLoginKey"]);
  1051. retval.UserFlags = Convert.ToInt32(reader["userFlags"].ToString());
  1052. retval.GodLevel = Convert.ToInt32(reader["godLevel"].ToString());
  1053. if (reader.IsDBNull(reader.GetOrdinal("customType")))
  1054. retval.CustomType = "";
  1055. else
  1056. retval.CustomType = reader["customType"].ToString();
  1057. if (reader.IsDBNull(reader.GetOrdinal("partner")))
  1058. retval.Partner = UUID.Zero;
  1059. else
  1060. retval.Partner = new UUID((Guid)reader["partner"]);
  1061. }
  1062. else
  1063. {
  1064. return null;
  1065. }
  1066. return retval;
  1067. }
  1068. #endregion
  1069. }
  1070. }