From 2ceff87a02d9862497d1d8fa965851ae2d9c9b1b Mon Sep 17 00:00:00 2001 From: MW Date: Wed, 11 Jul 2007 17:47:25 +0000 Subject: More work on UserProfile and inventory cache (still currently not enabled). Asset uploading over CAPS now works, and although inventory isn't really working yet, this should now at least enables texturing of prims. --- .../Communications/CommunicationsManager.cs | 4 + .../Framework/Communications/IInventoryServices.cs | 17 ++++ .../Communications/caches/CachedUserInfo.cs | 77 +++++++++++++++ .../Communications/caches/InventoryFolder.cs | 51 ++++++++++ .../Communications/caches/UserProfileCache.cs | 107 +++++++++++++++++++++ OpenSim/Framework/Data/InventoryData.cs | 6 +- OpenSim/Framework/General/Interfaces/IClientAPI.cs | 4 + OpenSim/Framework/Servers/BinaryStreamHandler.cs | 44 +++++++++ OpenSim/Framework/Servers/RestMethod.cs | 1 + 9 files changed, 308 insertions(+), 3 deletions(-) create mode 100644 OpenSim/Framework/Communications/IInventoryServices.cs create mode 100644 OpenSim/Framework/Communications/caches/CachedUserInfo.cs create mode 100644 OpenSim/Framework/Communications/caches/InventoryFolder.cs create mode 100644 OpenSim/Framework/Communications/caches/UserProfileCache.cs create mode 100644 OpenSim/Framework/Servers/BinaryStreamHandler.cs (limited to 'OpenSim/Framework') diff --git a/OpenSim/Framework/Communications/CommunicationsManager.cs b/OpenSim/Framework/Communications/CommunicationsManager.cs index 109d027..ebc9632 100644 --- a/OpenSim/Framework/Communications/CommunicationsManager.cs +++ b/OpenSim/Framework/Communications/CommunicationsManager.cs @@ -32,6 +32,7 @@ using OpenSim.Framework.Data; using OpenSim.Framework.Interfaces; using OpenSim.Framework.Types; using OpenSim.Framework.Servers; +using OpenSim.Framework.Communications.Caches; namespace OpenSim.Framework.Communications { @@ -40,12 +41,15 @@ namespace OpenSim.Framework.Communications { public IUserServices UserServer; public IGridServices GridServer; + public IInventoryServices InventoryServer; public IInterRegionCommunications InterRegion; + public UserProfileCache UserProfilesCache; public NetworkServersInfo ServersInfo; public CommunicationsManager(NetworkServersInfo serversInfo, BaseHttpServer httpServer) { ServersInfo = serversInfo; + UserProfilesCache = new UserProfileCache(this); } #region Packet Handlers diff --git a/OpenSim/Framework/Communications/IInventoryServices.cs b/OpenSim/Framework/Communications/IInventoryServices.cs new file mode 100644 index 0000000..0b05834 --- /dev/null +++ b/OpenSim/Framework/Communications/IInventoryServices.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Text; +using OpenSim.Framework.Data; +using libsecondlife; +using OpenSim.Framework.Communications.Caches; + +namespace OpenSim.Framework.Communications +{ + public delegate void InventoryFolderInfo(LLUUID userID, InventoryFolder folderInfo); + public delegate void InventoryItemInfo(LLUUID userID, InventoryItemBase itemInfo); + + public interface IInventoryServices + { + void RequestInventoryForUser(LLUUID userID, InventoryFolderInfo folderCallBack, InventoryItemInfo itemCallBack); + } +} diff --git a/OpenSim/Framework/Communications/caches/CachedUserInfo.cs b/OpenSim/Framework/Communications/caches/CachedUserInfo.cs new file mode 100644 index 0000000..1c779e9 --- /dev/null +++ b/OpenSim/Framework/Communications/caches/CachedUserInfo.cs @@ -0,0 +1,77 @@ +using System; +using System.Collections.Generic; +using System.Text; +using OpenSim.Framework.Data; +using libsecondlife; + +namespace OpenSim.Framework.Communications.Caches +{ + public class CachedUserInfo + { + public UserProfileData UserProfile; + //public Dictionary Folders = new Dictionary(); + public InventoryFolder RootFolder; + + public CachedUserInfo() + { + + } + + /// + /// + /// + /// + /// + public void FolderReceive(LLUUID userID, InventoryFolder folderInfo) + { + if (userID == UserProfile.UUID) + { + if (this.RootFolder == null) + { + if (folderInfo.parentID == LLUUID.Zero) + { + this.RootFolder = folderInfo; + } + } + else + { + if (this.RootFolder.folderID == folderInfo.parentID) + { + this.RootFolder.SubFolders.Add(folderInfo.folderID, folderInfo); + } + else + { + InventoryFolder pFolder = this.RootFolder.HasSubFolder(folderInfo.parentID); + if (pFolder != null) + { + pFolder.SubFolders.Add(folderInfo.folderID, folderInfo); + } + } + } + } + } + + public void ItemReceive(LLUUID userID, InventoryItemBase itemInfo) + { + if (userID == UserProfile.UUID) + { + if (this.RootFolder != null) + { + if (itemInfo.parentFolderID == this.RootFolder.folderID) + { + this.RootFolder.Items.Add(itemInfo.inventoryID, itemInfo); + } + else + { + InventoryFolder pFolder = this.RootFolder.HasSubFolder(itemInfo.parentFolderID); + if (pFolder != null) + { + pFolder.Items.Add(itemInfo.inventoryID, itemInfo); + } + } + } + + } + } + } +} diff --git a/OpenSim/Framework/Communications/caches/InventoryFolder.cs b/OpenSim/Framework/Communications/caches/InventoryFolder.cs new file mode 100644 index 0000000..eaddf19 --- /dev/null +++ b/OpenSim/Framework/Communications/caches/InventoryFolder.cs @@ -0,0 +1,51 @@ +using System; +using System.Collections.Generic; +using System.Text; +using libsecondlife; +using OpenSim.Framework.Data; + +namespace OpenSim.Framework.Communications.Caches +{ + public class InventoryFolder : InventoryFolderBase + { + public Dictionary SubFolders = new Dictionary(); + public Dictionary Items = new Dictionary(); + + public InventoryFolder() + { + } + + public InventoryFolder HasSubFolder(LLUUID folderID) + { + InventoryFolder returnFolder = null; + if (this.SubFolders.ContainsKey(folderID)) + { + returnFolder = this.SubFolders[folderID]; + } + else + { + foreach (InventoryFolder folder in this.SubFolders.Values) + { + returnFolder = folder.HasSubFolder(folderID); + if (returnFolder != null) + { + break; + } + } + } + return returnFolder; + } + + public InventoryFolder CreateNewSubFolder(LLUUID folderID, string folderName, ushort type) + { + InventoryFolder subFold = new InventoryFolder(); + subFold.name = folderName; + subFold.folderID = folderID; + subFold.type = type; + subFold.parentID = this.folderID; + subFold.agentID = this.agentID; + this.SubFolders.Add(subFold.folderID, subFold); + return subFold; + } + } +} diff --git a/OpenSim/Framework/Communications/caches/UserProfileCache.cs b/OpenSim/Framework/Communications/caches/UserProfileCache.cs new file mode 100644 index 0000000..0ee63ba --- /dev/null +++ b/OpenSim/Framework/Communications/caches/UserProfileCache.cs @@ -0,0 +1,107 @@ +using System; +using System.Collections.Generic; +using System.Text; +using libsecondlife; +using OpenSim.Framework.Data; +using OpenSim.Framework.Communications; + +namespace OpenSim.Framework.Communications.Caches +{ + public class UserProfileCache + { + public Dictionary UserProfiles = new Dictionary(); + + private CommunicationsManager m_parent; + + public UserProfileCache(CommunicationsManager parent) + { + m_parent = parent; + } + + /// + /// A new user has moved into a region in this instance + /// so get info from servers + /// + /// + public void AddNewUser(LLUUID userID) + { + if (!this.UserProfiles.ContainsKey(userID)) + { + CachedUserInfo userInfo = new CachedUserInfo(); + userInfo.UserProfile = this.RequestUserProfileForUser(userID); + this.m_parent.InventoryServer.RequestInventoryForUser(userID, userInfo.FolderReceive, userInfo.ItemReceive); + if (userInfo.UserProfile != null) + { + this.UserProfiles.Add(userID, userInfo); + } + else + { + //no profile for this user, what do we do now? + } + } + else + { + //already have a cached profile for this user + //we should make sure its upto date with the user server version + } + } + + /// + /// A new user has moved into a region in this instance + /// so get info from servers + /// + /// + /// + public void AddNewUser(string firstName, string lastName) + { + + } + + /// + /// A user has left this instance + /// so make sure servers have been updated + /// Then remove cached info + /// + /// + public void UserLogOut(LLUUID userID) + { + + } + + /// + /// Request the user profile from User server + /// + /// + private UserProfileData RequestUserProfileForUser(LLUUID userID) + { + return this.m_parent.UserServer.GetUserProfile(userID); + } + + /// + /// Request Iventory Info from Inventory server + /// + /// + private void RequestInventoryForUser(LLUUID userID) + { + + } + + /// + /// Make sure UserProfile is updated on user server + /// + /// + private void UpdateUserProfileToServer(LLUUID userID) + { + + } + + /// + /// Update Inventory data to Inventory server + /// + /// + private void UpdateInventoryToServer(LLUUID userID) + { + + } + } +} diff --git a/OpenSim/Framework/Data/InventoryData.cs b/OpenSim/Framework/Data/InventoryData.cs index fe2e25c..7253cc7 100644 --- a/OpenSim/Framework/Data/InventoryData.cs +++ b/OpenSim/Framework/Data/InventoryData.cs @@ -48,7 +48,7 @@ namespace OpenSim.Framework.Data /// public int type; /// - /// The folder this item is contained in (NULL_KEY = Inventory Root) + /// The folder this item is contained in /// public LLUUID parentFolderID; /// @@ -56,7 +56,7 @@ namespace OpenSim.Framework.Data /// public LLUUID avatarID; /// - /// The creator of this folder + /// The creator of this item /// public LLUUID creatorsID; /// @@ -91,7 +91,7 @@ namespace OpenSim.Framework.Data /// public LLUUID agentID; /// - /// The folder this folder is contained in (NULL_KEY for root) + /// The folder this folder is contained in /// public LLUUID parentID; /// diff --git a/OpenSim/Framework/General/Interfaces/IClientAPI.cs b/OpenSim/Framework/General/Interfaces/IClientAPI.cs index 1b0c682..fe1e9dc 100644 --- a/OpenSim/Framework/General/Interfaces/IClientAPI.cs +++ b/OpenSim/Framework/General/Interfaces/IClientAPI.cs @@ -30,6 +30,7 @@ using System.Net; using libsecondlife; using libsecondlife.Packets; using OpenSim.Framework.Types; +using OpenSim.Framework.Data; namespace OpenSim.Framework.Interfaces { @@ -176,5 +177,8 @@ namespace OpenSim.Framework.Interfaces void SendPrimitiveToClient(ulong regionHandle, ushort timeDilation, uint localID, PrimitiveBaseShape primShape, LLVector3 pos, LLQuaternion rotation, LLUUID textureID, uint flags, LLUUID objectID, LLUUID ownerID, string text, uint parentID); void SendPrimitiveToClient(ulong regionHandle, ushort timeDilation, uint localID, PrimitiveBaseShape primShape, LLVector3 pos, LLUUID textureID, uint flags, LLUUID objectID, LLUUID ownerID, string text, uint parentID); void SendPrimTerseUpdate(ulong regionHandle, ushort timeDilation, uint localID, LLVector3 position, LLQuaternion rotation); + + void SendInventoryFolderDetails(LLUUID ownerID, LLUUID folderID, List items); + void SendInventoryItemDetails(LLUUID ownerID, LLUUID folderID, InventoryItemBase item); } } diff --git a/OpenSim/Framework/Servers/BinaryStreamHandler.cs b/OpenSim/Framework/Servers/BinaryStreamHandler.cs new file mode 100644 index 0000000..302dbff --- /dev/null +++ b/OpenSim/Framework/Servers/BinaryStreamHandler.cs @@ -0,0 +1,44 @@ +using System; +using System.Collections.Generic; +using System.Text; +using System.IO; + +namespace OpenSim.Framework.Servers +{ + + public class BinaryStreamHandler : BaseStreamHandler + { + BinaryMethod m_restMethod; + + override public byte[] Handle(string path, Stream request) + { + byte[] data = ReadFully(request); + string param = GetParam(path); + string responseString = m_restMethod(data, path, param); + + return Encoding.UTF8.GetBytes(responseString); + } + + public BinaryStreamHandler(string httpMethod, string path, BinaryMethod restMethod) + : base(httpMethod, path) + { + m_restMethod = restMethod; + } + + public byte[] ReadFully(Stream stream) + { + byte[] buffer = new byte[32768]; + using (MemoryStream ms = new MemoryStream()) + { + while (true) + { + int read = stream.Read(buffer, 0, buffer.Length); + if (read <= 0) + return ms.ToArray(); + ms.Write(buffer, 0, read); + } + } + } + } + +} diff --git a/OpenSim/Framework/Servers/RestMethod.cs b/OpenSim/Framework/Servers/RestMethod.cs index c6cb230..2a92fc1 100644 --- a/OpenSim/Framework/Servers/RestMethod.cs +++ b/OpenSim/Framework/Servers/RestMethod.cs @@ -28,4 +28,5 @@ namespace OpenSim.Framework.Servers { public delegate string RestMethod( string request, string path, string param ); + public delegate string BinaryMethod(byte[] data, string path, string param); } -- cgit v1.1