From fe9aea258ff4142e718b4916ccefeeedef229768 Mon Sep 17 00:00:00 2001 From: Homer Horwitz Date: Wed, 24 Sep 2008 21:12:21 +0000 Subject: [PATCH] Add persistence of active gestures. This needs an UGAIM update to work. Active gestures are sent as part of the login-response. Added fetchActiveGestures to SQLite and MySQL; added an empty one for MSSQL and NHibernate. Using the empty ones won't cause errors, but doesn't provide persistence either, of course. --- OpenSim/Data/MSSQL/MSSQLInventoryData.cs | 5 +++ OpenSim/Data/MySQL/MySQLInventoryData.cs | 36 +++++++++++++++++++ .../NHibernate/NHibernateInventoryData.cs | 5 +++ OpenSim/Data/SQLite/SQLiteInventoryStore.cs | 19 ++++++++++ .../IInterServiceInventoryServices.cs | 11 ++++++ .../Communications/InventoryServiceBase.cs | 9 +++++ .../Framework/Communications/LoginResponse.cs | 12 +++++-- OpenSim/Framework/IInventoryData.cs | 11 ++++++ .../OGS1/OGS1InterServiceInventoryService.cs | 16 +++++++++ .../InventoryServer/GridInventoryService.cs | 9 +++++ OpenSim/Grid/InventoryServer/Main.cs | 5 +++ OpenSim/Grid/UserServer/UserLoginService.cs | 34 ++++++++++++++++-- .../Communications/Local/LocalLoginService.cs | 30 ++++++++++++++++ 13 files changed, 198 insertions(+), 4 deletions(-) diff --git a/OpenSim/Data/MSSQL/MSSQLInventoryData.cs b/OpenSim/Data/MSSQL/MSSQLInventoryData.cs index 03600e23e6..2b9913cce8 100644 --- a/OpenSim/Data/MSSQL/MSSQLInventoryData.cs +++ b/OpenSim/Data/MSSQL/MSSQLInventoryData.cs @@ -798,6 +798,11 @@ namespace OpenSim.Data.MSSQL m_log.Error("[INVENTORY DB] Error deleting folder :" + e.Message); } } + + public List fetchActiveGestures (UUID avatarID) + { + return null; + } #endregion } } diff --git a/OpenSim/Data/MySQL/MySQLInventoryData.cs b/OpenSim/Data/MySQL/MySQLInventoryData.cs index 50d3cc74b8..68885e13ad 100644 --- a/OpenSim/Data/MySQL/MySQLInventoryData.cs +++ b/OpenSim/Data/MySQL/MySQLInventoryData.cs @@ -795,5 +795,41 @@ namespace OpenSim.Data.MySQL deleteOneFolder(folderID); deleteItemsInFolder(folderID); } + + public List fetchActiveGestures(UUID avatarID) + { + MySqlDataReader result = null; + MySqlCommand sqlCmd = null; + lock (database) + { + try + { + database.CheckConnection(); + sqlCmd = new MySqlCommand( + "SELECT * FROM inventoryitems WHERE avatarId = ?uuid AND assetType = ?type and flags = 1", + database.Connection); + sqlCmd.Parameters.AddWithValue("?uuid", avatarID.ToString()); + sqlCmd.Parameters.AddWithValue("?type", (int)AssetType.Gesture); + result = sqlCmd.ExecuteReader(); + + List list = new List(); + while (result.Read()) + list.Add(readInventoryItem(result)); + + return list; + } + catch (Exception e) + { + database.Reconnect(); + m_log.Error(e.ToString()); + return null; + } + finally + { + if(result != null) result.Close(); + if(sqlCmd != null) sqlCmd.Dispose(); + } + } + } } } diff --git a/OpenSim/Data/NHibernate/NHibernateInventoryData.cs b/OpenSim/Data/NHibernate/NHibernateInventoryData.cs index 20dad1aae4..bceb5d5ecf 100644 --- a/OpenSim/Data/NHibernate/NHibernateInventoryData.cs +++ b/OpenSim/Data/NHibernate/NHibernateInventoryData.cs @@ -389,5 +389,10 @@ namespace OpenSim.Data.NHibernate return folders; } + + public List fetchActiveGestures (UUID avatarID) + { + return null; + } } } diff --git a/OpenSim/Data/SQLite/SQLiteInventoryStore.cs b/OpenSim/Data/SQLite/SQLiteInventoryStore.cs index 40b61eed47..b9fda0439d 100644 --- a/OpenSim/Data/SQLite/SQLiteInventoryStore.cs +++ b/OpenSim/Data/SQLite/SQLiteInventoryStore.cs @@ -847,5 +847,24 @@ namespace OpenSim.Data.SQLite row["UUID"] = Util.ToRawUuidString(folder.ID); row["parentID"] = Util.ToRawUuidString(folder.ParentID); } + + public List fetchActiveGestures (UUID avatarID) + { + lock (ds) + { + List items = new List(); + + DataTable inventoryItemTable = ds.Tables["inventoryitems"]; + string selectExp = "avatarID = '" + Util.ToRawUuidString(avatarID) + "' AND assetType = " + + (int)AssetType.Gesture + " AND flags = 1"; + m_log.DebugFormat("[SQL]: sql = " + selectExp); + DataRow[] rows = inventoryItemTable.Select(selectExp); + foreach (DataRow row in rows) + { + items.Add(buildItem(row)); + } + return items; + } + } } } diff --git a/OpenSim/Framework/Communications/IInterServiceInventoryServices.cs b/OpenSim/Framework/Communications/IInterServiceInventoryServices.cs index 5900f4ed0a..661eb91d81 100644 --- a/OpenSim/Framework/Communications/IInterServiceInventoryServices.cs +++ b/OpenSim/Framework/Communications/IInterServiceInventoryServices.cs @@ -49,5 +49,16 @@ namespace OpenSim.Framework.Communications /// A flat list of the user's inventory folder tree, /// null if there is no inventory for this user List GetInventorySkeleton(UUID userId); + + /// + /// Returns a list of all the active gestures in a user's inventory. + /// + /// + /// The of the user + /// + /// + /// A flat list of the gesture items. + /// + List GetActiveGestures(UUID userId); } } diff --git a/OpenSim/Framework/Communications/InventoryServiceBase.cs b/OpenSim/Framework/Communications/InventoryServiceBase.cs index e9dc3c4866..d6392c48de 100644 --- a/OpenSim/Framework/Communications/InventoryServiceBase.cs +++ b/OpenSim/Framework/Communications/InventoryServiceBase.cs @@ -148,6 +148,15 @@ namespace OpenSim.Framework.Communications // See IInventoryServices public abstract void RequestInventoryForUser(UUID userID, InventoryReceiptCallback callback); + public List GetActiveGestures(UUID userId) + { + foreach (IInventoryDataPlugin plugin in m_plugins) + { + return plugin.fetchActiveGestures(userId); + } + return new List(); + } + #endregion #region Methods used by GridInventoryService diff --git a/OpenSim/Framework/Communications/LoginResponse.cs b/OpenSim/Framework/Communications/LoginResponse.cs index 435852d4b6..db504f9551 100644 --- a/OpenSim/Framework/Communications/LoginResponse.cs +++ b/OpenSim/Framework/Communications/LoginResponse.cs @@ -60,6 +60,7 @@ namespace OpenSim.Framework.Communications private ArrayList inventoryLibraryOwner; private ArrayList inventoryLibRoot; private ArrayList inventoryLibrary; + private ArrayList activeGestures; private UserInfo userProfile; @@ -124,6 +125,7 @@ namespace OpenSim.Framework.Communications agentInventory = new ArrayList(); inventoryLibrary = new ArrayList(); inventoryLibraryOwner = new ArrayList(); + activeGestures = new ArrayList(); xmlRpcResponse = new XmlRpcResponse(); // defaultXmlRpcResponse = new XmlRpcResponse(); @@ -355,7 +357,7 @@ namespace OpenSim.Framework.Communications responseData["inventory-skel-lib"] = inventoryLibrary; responseData["inventory-root"] = inventoryRoot; responseData["inventory-lib-root"] = inventoryLibRoot; - responseData["gestures"] = new ArrayList(); // todo + responseData["gestures"] = activeGestures; responseData["inventory-lib-owner"] = inventoryLibraryOwner; responseData["initial-outfit"] = initialOutfit; responseData["start_location"] = startLocation; @@ -452,7 +454,7 @@ namespace OpenSim.Framework.Communications #endregion Inventory - map["gestures"] = new LLSDArray(); // todo + map["gestures"] = ArrayListToLLSDArray(activeGestures); map["initial-outfit"] = ArrayListToLLSDArray(initialOutfit); map["start_location"] = LLSD.FromString(startLocation); @@ -699,6 +701,12 @@ namespace OpenSim.Framework.Communications set { inventoryLibRoot = value; } } + public ArrayList ActiveGestures + { + get { return activeGestures; } + set { activeGestures = value; } + } + public string Home { get { return home; } diff --git a/OpenSim/Framework/IInventoryData.cs b/OpenSim/Framework/IInventoryData.cs index d5fa25d564..e42e50d31d 100644 --- a/OpenSim/Framework/IInventoryData.cs +++ b/OpenSim/Framework/IInventoryData.cs @@ -131,6 +131,17 @@ namespace OpenSim.Framework /// /// The id of the folder void deleteInventoryFolder(UUID folder); + + /// + /// Returns all activated gesture-items in the inventory of the specified avatar. + /// + /// + /// The of the avatar + /// + /// + /// The list of gestures (s) + /// + List fetchActiveGestures(UUID avatarID); } public class InventoryDataInitialiser : PluginInitialiserBase diff --git a/OpenSim/Grid/Communications/OGS1/OGS1InterServiceInventoryService.cs b/OpenSim/Grid/Communications/OGS1/OGS1InterServiceInventoryService.cs index 5de5bb3d4b..ee76d7432b 100644 --- a/OpenSim/Grid/Communications/OGS1/OGS1InterServiceInventoryService.cs +++ b/OpenSim/Grid/Communications/OGS1/OGS1InterServiceInventoryService.cs @@ -67,5 +67,21 @@ namespace OpenSim.Grid.Communications.OGS1 return SynchronousRestObjectPoster.BeginPostObject>( "POST", m_inventoryServerUrl + "RootFolders/", userId.Guid); } + + /// + /// Returns a list of all the active gestures in a user's inventory. + /// + /// + /// The of the user + /// + /// + /// A flat list of the gesture items. + /// + public List GetActiveGestures(UUID userId) + { + return SynchronousRestObjectPoster.BeginPostObject>( + "POST", m_inventoryServerUrl + "ActiveGestures/", userId.Guid); + } + } } diff --git a/OpenSim/Grid/InventoryServer/GridInventoryService.cs b/OpenSim/Grid/InventoryServer/GridInventoryService.cs index 4d58775dc5..6f7672e951 100644 --- a/OpenSim/Grid/InventoryServer/GridInventoryService.cs +++ b/OpenSim/Grid/InventoryServer/GridInventoryService.cs @@ -233,5 +233,14 @@ namespace OpenSim.Grid.InventoryServer return CreateNewUserInventory(userID); } + + public List GetActiveGestures(Guid rawUserID) + { + UUID userID = new UUID(rawUserID); + + m_log.InfoFormat("[GRID AGENT INVENTORY]: fetching active gestures for user {0}", userID); + + return GetActiveGestures(userID); + } } } diff --git a/OpenSim/Grid/InventoryServer/Main.cs b/OpenSim/Grid/InventoryServer/Main.cs index 9f40d16e3d..3b990e70c5 100644 --- a/OpenSim/Grid/InventoryServer/Main.cs +++ b/OpenSim/Grid/InventoryServer/Main.cs @@ -123,6 +123,11 @@ namespace OpenSim.Grid.InventoryServer m_httpServer.AddStreamHandler( new RestDeserialiseTrustedHandler> ("POST", "/RootFolders/", m_inventoryService.GetInventorySkeleton, m_inventoryService.CheckTrustSource)); + + // for persistent active gestures + m_httpServer.AddStreamHandler( + new RestDeserialiseTrustedHandler> + ("POST", "/ActiveGestures/", m_inventoryService.GetActiveGestures, m_inventoryService.CheckTrustSource)); } private void Work() diff --git a/OpenSim/Grid/UserServer/UserLoginService.cs b/OpenSim/Grid/UserServer/UserLoginService.cs index 8ab9af137b..573e546f4c 100644 --- a/OpenSim/Grid/UserServer/UserLoginService.cs +++ b/OpenSim/Grid/UserServer/UserLoginService.cs @@ -131,6 +131,9 @@ namespace OpenSim.Grid.UserServer /// The requested start location public override bool CustomiseResponse(LoginResponse response, UserProfileData theUser, string startLocationRequest) { + // add active gestures to login-response + AddActiveGestures(response, theUser); + // HomeLocation RegionProfileData homeInfo = null; // use the homeRegionID if it is stored already. If not, use the regionHandle as before @@ -243,10 +246,37 @@ namespace OpenSim.Grid.UserServer // theUser.HomeLookAt.X, theUser.HomeLookAt.Y, theUser.HomeLookAt.Z); theUser.CurrentAgent.Position = new Vector3(128,128,0); response.StartLocation = "safe"; - + return PrepareLoginToRegion(regionInfo, theUser, response); } - + + /// + /// Add active gestures of the user to the login response. + /// + /// + /// A + /// + /// + /// A + /// + private void AddActiveGestures(LoginResponse response, UserProfileData theUser) + { + List gestures = m_inventoryService.GetActiveGestures(theUser.ID); + m_log.DebugFormat("[LOGIN]: AddActiveGestures, found {0}", gestures == null ? 0 : gestures.Count); + ArrayList list = new ArrayList(); + if (gestures != null) + { + foreach (InventoryItemBase gesture in gestures) + { + Hashtable item = new Hashtable(); + item["item_id"] = gesture.ID.ToString(); + item["asset_id"] = gesture.AssetID.ToString(); + list.Add(item); + } + } + response.ActiveGestures = list; + } + /// /// Prepare a login to the given region. This involves both telling the region to expect a connection /// and appropriately customising the response to the user. diff --git a/OpenSim/Region/Communications/Local/LocalLoginService.cs b/OpenSim/Region/Communications/Local/LocalLoginService.cs index ded2d5617f..3d09729b1f 100644 --- a/OpenSim/Region/Communications/Local/LocalLoginService.cs +++ b/OpenSim/Region/Communications/Local/LocalLoginService.cs @@ -142,6 +142,9 @@ namespace OpenSim.Region.Communications.Local /// The requested start location public override bool CustomiseResponse(LoginResponse response, UserProfileData theUser, string startLocationRequest) { + // add active gestures to login-response + AddActiveGestures(response, theUser); + // HomeLocation RegionInfo homeInfo = null; @@ -254,6 +257,33 @@ namespace OpenSim.Region.Communications.Local return PrepareLoginToRegion(regionInfo, theUser, response); } + /// + /// Add active gestures of the user to the login response. + /// + /// + /// A + /// + /// + /// A + /// + private void AddActiveGestures(LoginResponse response, UserProfileData theUser) + { + List gestures = m_interServiceInventoryService.GetActiveGestures(theUser.ID); + m_log.DebugFormat("[LOGIN]: AddActiveGestures, found {0}", gestures == null ? 0 : gestures.Count); + ArrayList list = new ArrayList(); + if (gestures != null) + { + foreach (InventoryItemBase gesture in gestures) + { + Hashtable item = new Hashtable(); + item["item_id"] = gesture.ID.ToString(); + item["asset_id"] = gesture.AssetID.ToString(); + list.Add(item); + } + } + response.ActiveGestures = list; + } + /// /// Prepare a login to the given region. This involves both telling the region to expect a connection /// and appropriately customising the response to the user.