From fe49c96ee0db0974a91b9b175ac1b00aef035797 Mon Sep 17 00:00:00 2001
From: Teravus Ovares
Date: Mon, 3 Mar 2008 08:30:36 +0000
Subject: * Applying Ahzz's profile patch. Thanks Ahzz! * Fixed a few bugs in
the patch that are sim crashers. * There's still a bug in mySQL mode/ grid
mode where the main userprofile text doesn't save.
---
.../Communications/CommunicationsManager.cs | 6 ++
.../Framework/Communications/UserManagerBase.cs | 31 +++++-
OpenSim/Framework/Data.MSSQL/MSSQLUserData.cs | 14 +--
OpenSim/Framework/Data.MySQL/MySQLManager.cs | 113 ++++++++++++++++++++-
OpenSim/Framework/Data.MySQL/MySQLUserData.cs | 8 +-
OpenSim/Framework/Data.SQLite/SQLiteUserData.cs | 8 +-
OpenSim/Framework/IClientAPI.cs | 3 +
OpenSim/Framework/IUserService.cs | 7 ++
OpenSim/Framework/Util.cs | 22 +++-
9 files changed, 187 insertions(+), 25 deletions(-)
(limited to 'OpenSim/Framework')
diff --git a/OpenSim/Framework/Communications/CommunicationsManager.cs b/OpenSim/Framework/Communications/CommunicationsManager.cs
index 4ad808a..655abd7 100644
--- a/OpenSim/Framework/Communications/CommunicationsManager.cs
+++ b/OpenSim/Framework/Communications/CommunicationsManager.cs
@@ -229,6 +229,12 @@ namespace OpenSim.Framework.Communications
#region Packet Handlers
+ public void UpdateAvatarPropertiesRequest(IClientAPI remote_client, UserProfileData UserProfile)
+ {
+ m_userService.UpdateUserProfileProperties(UserProfile);
+ return;
+ }
+
public void HandleUUIDNameRequest(LLUUID uuid, IClientAPI remote_client)
{
if (uuid == m_userProfileCacheService.libraryRoot.agentID)
diff --git a/OpenSim/Framework/Communications/UserManagerBase.cs b/OpenSim/Framework/Communications/UserManagerBase.cs
index 733d62b..3380e90 100644
--- a/OpenSim/Framework/Communications/UserManagerBase.cs
+++ b/OpenSim/Framework/Communications/UserManagerBase.cs
@@ -139,11 +139,10 @@ namespace OpenSim.Framework.UserManagement
}
///
- /// Set's user profile from object
+ /// Set's user profile from data object
///
- /// First name
- /// Last name
- /// A user profile
+ ///
+ ///
public bool setUserProfile(UserProfileData data)
{
foreach (KeyValuePair plugin in _plugins)
@@ -158,7 +157,6 @@ namespace OpenSim.Framework.UserManagement
m_log.Info("[USERSTORAGE]: Unable to set user via " + plugin.Key + "(" + e.ToString() + ")");
}
}
-
return false;
}
@@ -534,6 +532,29 @@ namespace OpenSim.Framework.UserManagement
return user.UUID;
}
+ public bool UpdateUserProfileProperties(UserProfileData UserProfile)
+ {
+ if (null == GetUserProfile(UserProfile.UUID))
+ {
+ m_log.Info("[USERSTORAGE]: Failed to find User by UUID " + UserProfile.UUID.ToString());
+ return false;
+ }
+ foreach (KeyValuePair plugin in _plugins)
+ {
+ try
+ {
+ plugin.Value.UpdateUserProfile(UserProfile);
+ }
+ catch (Exception e)
+ {
+ m_log.Info("[USERSTORAGE]: Unable to update user " + UserProfile.UUID.ToString()
+ + " via " + plugin.Key + "(" + e.ToString() + ")");
+ return false;
+ }
+ }
+ return true;
+ }
+
public abstract UserProfileData SetupMasterUser(string firstName, string lastName);
public abstract UserProfileData SetupMasterUser(string firstName, string lastName, string password);
public abstract UserProfileData SetupMasterUser(LLUUID uuid);
diff --git a/OpenSim/Framework/Data.MSSQL/MSSQLUserData.cs b/OpenSim/Framework/Data.MSSQL/MSSQLUserData.cs
index 402a88f..2244f4b 100644
--- a/OpenSim/Framework/Data.MSSQL/MSSQLUserData.cs
+++ b/OpenSim/Framework/Data.MSSQL/MSSQLUserData.cs
@@ -588,10 +588,10 @@ namespace OpenSim.Framework.Data.MSSQL
parameters["userAssetURI"] = String.Empty;
parameters["profileCanDoMask"] = "0";
parameters["profileWantDoMask"] = "0";
- parameters["profileAboutText"] = String.Empty;
- parameters["profileFirstText"] = String.Empty;
- parameters["profileImage"] = LLUUID.Zero.ToString();
- parameters["profileFirstImage"] = LLUUID.Zero.ToString();
+ parameters["profileAboutText"] = aboutText;
+ parameters["profileFirstText"] = firstText;
+ parameters["profileImage"] = profileImage.ToString();
+ parameters["profileFirstImage"] = firstImage.ToString();
parameters["webLoginKey"] = LLUUID.Random().ToString();
bool returnval = false;
@@ -670,8 +670,8 @@ namespace OpenSim.Framework.Data.MSSQL
SqlParameter param18 = new SqlParameter("@profileWantDoMask", Convert.ToInt32(user.profileWantDoMask));
SqlParameter param19 = new SqlParameter("@profileAboutText", user.profileAboutText);
SqlParameter param20 = new SqlParameter("@profileFirstText", user.profileFirstText);
- SqlParameter param21 = new SqlParameter("@profileImage", LLUUID.Zero.ToString());
- SqlParameter param22 = new SqlParameter("@profileFirstImage", LLUUID.Zero.ToString());
+ SqlParameter param21 = new SqlParameter("@profileImage", user.profileImage.ToString());
+ SqlParameter param22 = new SqlParameter("@profileFirstImage", user.profileFirstImage.ToString());
SqlParameter param23 = new SqlParameter("@keyUUUID", user.UUID.ToString());
SqlParameter param24 = new SqlParameter("@webLoginKey", user.webLoginKey.UUID.ToString());
command.Parameters.Add(param1);
@@ -768,4 +768,4 @@ namespace OpenSim.Framework.Data.MSSQL
{
}
}
-}
\ No newline at end of file
+}
diff --git a/OpenSim/Framework/Data.MySQL/MySQLManager.cs b/OpenSim/Framework/Data.MySQL/MySQLManager.cs
index 1a90eea..ea11aa0 100644
--- a/OpenSim/Framework/Data.MySQL/MySQLManager.cs
+++ b/OpenSim/Framework/Data.MySQL/MySQLManager.cs
@@ -452,11 +452,25 @@ namespace OpenSim.Framework.Data.MySQL
retval.profileCanDoMask = Convert.ToUInt32(reader["profileCanDoMask"].ToString());
retval.profileWantDoMask = Convert.ToUInt32(reader["profileWantDoMask"].ToString());
- retval.profileAboutText = (string) reader["profileAboutText"];
- retval.profileFirstText = (string) reader["profileFirstText"];
+ if (reader.IsDBNull(reader.GetOrdinal("profileAboutText")))
+ retval.profileAboutText = "";
+ else
+ retval.profileAboutText = (string) reader["profileAboutText"];
- LLUUID.TryParse((string)reader["profileImage"], out retval.profileImage);
- LLUUID.TryParse((string)reader["profileFirstImage"], out retval.profileFirstImage);
+ if (reader.IsDBNull( reader.GetOrdinal( "profileFirstText" ) ) )
+ retval.profileFirstText = "";
+ else
+ retval.profileFirstText = (string)reader["profileFirstText"];
+
+ if (reader.IsDBNull( reader.GetOrdinal( "profileImage" ) ) )
+ retval.profileImage = LLUUID.Zero;
+ else
+ LLUUID.TryParse((string)reader["profileImage"], out retval.profileImage);
+
+ if (reader.IsDBNull( reader.GetOrdinal( "profileFirstImage" ) ) )
+ retval.profileFirstImage = LLUUID.Zero;
+ else
+ LLUUID.TryParse((string)reader["profileFirstImage"], out retval.profileFirstImage);
if( reader.IsDBNull( reader.GetOrdinal( "webLoginKey" ) ) )
{
@@ -553,6 +567,7 @@ namespace OpenSim.Framework.Data.MySQL
string aboutText, string firstText,
LLUUID profileImage, LLUUID firstImage, LLUUID webLoginKey)
{
+ m_log.Debug("[MySQLManager]: Fetching profile for " + uuid.ToString());
string sql =
"INSERT INTO users (`UUID`, `username`, `lastname`, `passwordHash`, `passwordSalt`, `homeRegion`, ";
sql +=
@@ -610,9 +625,99 @@ namespace OpenSim.Framework.Data.MySQL
return false;
}
+ m_log.Debug("[MySQLManager]: Fetch user retval == " + returnval.ToString());
return returnval;
}
+ ///
+ /// Creates a new user and inserts it into the database
+ ///
+ /// User ID
+ /// First part of the login
+ /// Second part of the login
+ /// A salted hash of the users password
+ /// The salt used for the password hash
+ /// A regionHandle of the users home region
+ /// Home region position vector
+ /// Home region position vector
+ /// Home region position vector
+ /// Home region 'look at' vector
+ /// Home region 'look at' vector
+ /// Home region 'look at' vector
+ /// Account created (unix timestamp)
+ /// Last login (unix timestamp)
+ /// Users inventory URI
+ /// Users asset URI
+ /// I can do mask
+ /// I want to do mask
+ /// Profile text
+ /// Firstlife text
+ /// UUID for profile image
+ /// UUID for firstlife image
+ /// Success?
+ public bool updateUserRow(LLUUID uuid, string username, string lastname, string passwordHash,
+ string passwordSalt, UInt64 homeRegion, float homeLocX, float homeLocY, float homeLocZ,
+ float homeLookAtX, float homeLookAtY, float homeLookAtZ, int created, int lastlogin,
+ string inventoryURI, string assetURI, uint canDoMask, uint wantDoMask,
+ string aboutText, string firstText,
+ LLUUID profileImage, LLUUID firstImage, LLUUID webLoginKey)
+ {
+ string sql = "UPDATE users SET `username` = ?username , `lastname` = ?lastname ";
+ sql += ", `passwordHash` = ?passwordHash , `passwordSalt` = ?passwordSalt , ";
+ sql += "`homeRegion` = ?homeRegion , `homeLocationX` = ?homeLocationX , ";
+ sql += "`homeLocationY` = ?homeLocationY , `homeLocationZ` = ?homeLocationZ , ";
+ sql += "`homeLookAtX` = ?homeLookAtX , `homeLookAtY` = ?homeLookAtY , ";
+ sql += "`homeLookAtZ` = ?homeLookAtZ , `created` = ?created , `lastLogin` = ?lastLogin , ";
+ sql += "`userInventoryURI` = ?userInventoryURI , `userAssetURI` = ?userAssetURI , ";
+ sql += "`profileCanDoMask` = ?profileCanDoMask , `profileWantDoMask` = ?profileWantDoMask , ";
+ sql += "`profileAboutText` = ?profileAboutText , `profileFirstText` = ?profileFirstText, ";
+ sql += "`profileImage` = ?profileImage , `profileFirstImage` = ?profileFirstImage , ";
+ sql += "`webLoginKey` = ?webLoginKey WHERE UUID = ?UUID";
+
+ Dictionary parameters = new Dictionary();
+ parameters["?UUID"] = uuid.ToString();
+ parameters["?username"] = username.ToString();
+ parameters["?lastname"] = lastname.ToString();
+ parameters["?passwordHash"] = passwordHash.ToString();
+ parameters["?passwordSalt"] = passwordSalt.ToString();
+ parameters["?homeRegion"] = homeRegion.ToString();
+ parameters["?homeLocationX"] = homeLocX.ToString();
+ parameters["?homeLocationY"] = homeLocY.ToString();
+ parameters["?homeLocationZ"] = homeLocZ.ToString();
+ parameters["?homeLookAtX"] = homeLookAtX.ToString();
+ parameters["?homeLookAtY"] = homeLookAtY.ToString();
+ parameters["?homeLookAtZ"] = homeLookAtZ.ToString();
+ parameters["?created"] = created.ToString();
+ parameters["?lastLogin"] = lastlogin.ToString();
+ parameters["?userInventoryURI"] = inventoryURI;
+ parameters["?userAssetURI"] = assetURI;
+ parameters["?profileCanDoMask"] = "0";
+ parameters["?profileWantDoMask"] = "0";
+ parameters["?profileAboutText"] = aboutText;
+ parameters["?profileFirstText"] = firstText;
+ parameters["?profileImage"] = profileImage.ToString();
+ parameters["?profileFirstImage"] = firstImage.ToString();
+ parameters["?webLoginKey"] = webLoginKey.ToString();
+
+ bool returnval = false;
+ try
+ {
+ IDbCommand result = Query(sql, parameters);
+
+ if (result.ExecuteNonQuery() == 1)
+ returnval = true;
+
+ result.Dispose();
+ }
+ catch (Exception e)
+ {
+ m_log.Error(e.ToString());
+ return false;
+ }
+
+ m_log.Debug("[MySQLManager]: update user retval == " + returnval.ToString());
+ return returnval;
+ }
///
/// Inserts a new region into the database
diff --git a/OpenSim/Framework/Data.MySQL/MySQLUserData.cs b/OpenSim/Framework/Data.MySQL/MySQLUserData.cs
index bc18376..2bba6ce 100644
--- a/OpenSim/Framework/Data.MySQL/MySQLUserData.cs
+++ b/OpenSim/Framework/Data.MySQL/MySQLUserData.cs
@@ -594,7 +594,11 @@ namespace OpenSim.Framework.Data.MySQL
/// The profile data to use to update the DB
public bool UpdateUserProfile(UserProfileData user)
{
- // TODO: implement
+ database.updateUserRow(user.UUID, user.username, user.surname, user.passwordHash, user.passwordSalt
+ , user.homeRegion, user.homeLocation.X, user.homeLocation.Y, user.homeLocation.Z, user.homeLookAt.X
+ , user.homeLookAt.Y, user.homeLookAt.Z, user.created, user.lastLogin, user.userInventoryURI
+ , user.userAssetURI, user.profileCanDoMask, user.profileWantDoMask, user.profileAboutText
+ , user.profileFirstText, user.profileImage, user.profileFirstImage, user.webLoginKey);
return true;
}
@@ -641,4 +645,4 @@ namespace OpenSim.Framework.Data.MySQL
return "0.1";
}
}
-}
\ No newline at end of file
+}
diff --git a/OpenSim/Framework/Data.SQLite/SQLiteUserData.cs b/OpenSim/Framework/Data.SQLite/SQLiteUserData.cs
index 2316de8..22f0053 100644
--- a/OpenSim/Framework/Data.SQLite/SQLiteUserData.cs
+++ b/OpenSim/Framework/Data.SQLite/SQLiteUserData.cs
@@ -590,7 +590,7 @@ namespace OpenSim.Framework.Data.SQLite
// interesting has to be done to actually get these values
// back out. Not enough time to figure it out yet.
UserProfileData user = new UserProfileData();
- user.UUID = new LLUUID((String) row["UUID"]);
+ LLUUID.TryParse((String)row["UUID"], out user.UUID);
user.username = (String) row["username"];
user.surname = (String) row["surname"];
user.passwordHash = (String) row["passwordHash"];
@@ -617,8 +617,8 @@ namespace OpenSim.Framework.Data.SQLite
user.profileWantDoMask = Convert.ToUInt32(row["profileWantDoMask"]);
user.profileAboutText = (String) row["profileAboutText"];
user.profileFirstText = (String) row["profileFirstText"];
- user.profileImage = new LLUUID((String) row["profileImage"]);
- user.profileFirstImage = new LLUUID((String) row["profileFirstImage"]);
+ LLUUID.TryParse((String)row["profileImage"], out user.profileImage);
+ LLUUID.TryParse((String)row["profileFirstImage"], out user.profileFirstImage);
user.webLoginKey = new LLUUID((String) row["webLoginKey"]);
return user;
@@ -832,4 +832,4 @@ namespace OpenSim.Framework.Data.SQLite
return true;
}
}
-}
\ No newline at end of file
+}
diff --git a/OpenSim/Framework/IClientAPI.cs b/OpenSim/Framework/IClientAPI.cs
index 511bbad..5001f00 100644
--- a/OpenSim/Framework/IClientAPI.cs
+++ b/OpenSim/Framework/IClientAPI.cs
@@ -264,6 +264,8 @@ namespace OpenSim.Framework
public delegate void RequestAvatarProperties(IClientAPI remoteClient, LLUUID avatarID);
+ public delegate void UpdateAvatarProperties(IClientAPI remoteClient, UserProfileData ProfileData);
+
public delegate void SetAlwaysRun(IClientAPI remoteClient, bool SetAlwaysRun);
public delegate void GenericCall2();
@@ -530,6 +532,7 @@ namespace OpenSim.Framework
event MoneyTransferRequest OnMoneyTransferRequest;
event MoneyBalanceRequest OnMoneyBalanceRequest;
+ event UpdateAvatarProperties OnUpdateAvatarProperties;
LLVector3 StartPos { get; set; }
diff --git a/OpenSim/Framework/IUserService.cs b/OpenSim/Framework/IUserService.cs
index 3b84486..0faf12e 100644
--- a/OpenSim/Framework/IUserService.cs
+++ b/OpenSim/Framework/IUserService.cs
@@ -87,6 +87,13 @@ namespace OpenSim.Framework
void UpdateUserFriendPerms(LLUUID friendlistowner, LLUUID friend, uint perms);
///
+ /// Updates a user profile
+ ///
+ /// Profile to update
+ ///
+ bool UpdateUserProfileProperties(UserProfileData UserProfile);
+
+ ///
/// Logs off a user on the user server
///
/// UUID of the user
diff --git a/OpenSim/Framework/Util.cs b/OpenSim/Framework/Util.cs
index 856cac3..35e795b 100644
--- a/OpenSim/Framework/Util.cs
+++ b/OpenSim/Framework/Util.cs
@@ -181,9 +181,25 @@ namespace OpenSim.Framework
public static int UnixTimeSinceEpoch()
{
- TimeSpan t = (DateTime.UtcNow - new DateTime(1970, 1, 1));
- int timestamp = (int) t.TotalSeconds;
- return timestamp;
+ return ToUnixTime(DateTime.UtcNow);
+ }
+
+ public static int ToUnixTime(DateTime stamp)
+ {
+ TimeSpan t = (stamp.ToUniversalTime() - Convert.ToDateTime("1/1/1970 8:00:00 AM"));
+ return (int)t.TotalSeconds;
+ }
+
+ public static DateTime ToDateTime(ulong seconds)
+ {
+ DateTime epoch = Convert.ToDateTime("1/1/1970 8:00:00 AM");
+ return epoch.AddSeconds(seconds);
+ }
+
+ public static DateTime ToDateTime(int seconds)
+ {
+ DateTime epoch = Convert.ToDateTime("1/1/1970 8:00:00 AM");
+ return epoch.AddSeconds(seconds);
}
public static string Md5Hash(string pass)
--
cgit v1.1