MSSQLUserData.cs 56 KB

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