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