From 181a90967ee9084676f84e74b2393855218c5723 Mon Sep 17 00:00:00 2001 From: MW Date: Tue, 14 Aug 2007 17:29:15 +0000 Subject: Start of inventory items, when you upload a texture the data will now be stored in the inventory database and you will still have that texture in inventory on later logins (Again only in standalone mode with authentication.) Also there might be some problems if you upload textures in other regions to the start one (due to us not updating the CAPS url properly). --- .../Communications/Cache/AssetTransactions.cs | 4 +- .../Communications/Cache/CachedUserInfo.cs | 21 +++++- .../Communications/Cache/UserProfileCache.cs | 2 +- .../Framework/Communications/Capabilities/Caps.cs | 43 +++++++++++-- .../Framework/Communications/IInventoryServices.cs | 1 + .../Framework/Data.SQLite/SQLiteInventoryStore.cs | 75 ++++++++++++++++++++-- .../InventoryServiceBase/InventoryServiceBase.cs | 8 +++ 7 files changed, 139 insertions(+), 15 deletions(-) (limited to 'OpenSim/Framework') diff --git a/OpenSim/Framework/Communications/Cache/AssetTransactions.cs b/OpenSim/Framework/Communications/Cache/AssetTransactions.cs index c906b76..e12d234 100644 --- a/OpenSim/Framework/Communications/Cache/AssetTransactions.cs +++ b/OpenSim/Framework/Communications/Cache/AssetTransactions.cs @@ -128,7 +128,7 @@ namespace OpenSim.Framework.Communications.Caches } if (this.OnUpLoad != null) { - this.OnUpLoad(this.m_assetName, this.newAssetID, inventoryItemID, data); + this.OnUpLoad(this.m_assetName, "description", this.newAssetID, inventoryItemID, LLUUID.Zero, data); } return text; } @@ -266,7 +266,7 @@ namespace OpenSim.Framework.Communications.Caches } if (this.OnUpLoad != null) { - this.OnUpLoad(this.m_assetName, this.newAssetID, inventoryItemID, data); + this.OnUpLoad(this.m_assetName, "description", this.newAssetID, inventoryItemID, LLUUID.Zero, data); } return text; } diff --git a/OpenSim/Framework/Communications/Cache/CachedUserInfo.cs b/OpenSim/Framework/Communications/Cache/CachedUserInfo.cs index fc2f948..123e692 100644 --- a/OpenSim/Framework/Communications/Cache/CachedUserInfo.cs +++ b/OpenSim/Framework/Communications/Cache/CachedUserInfo.cs @@ -40,10 +40,16 @@ namespace OpenSim.Framework.Communications.Caches { public class CachedUserInfo { + private CommunicationsManager m_parentCommsManager; // Fields public InventoryFolder RootFolder = null; public UserProfileData UserProfile = null; + public CachedUserInfo(CommunicationsManager commsManager) + { + m_parentCommsManager = commsManager; + } + // Methods public void FolderReceive(LLUUID userID, InventoryFolder folderInfo) { @@ -73,6 +79,7 @@ namespace OpenSim.Framework.Communications.Caches public void ItemReceive(LLUUID userID, InventoryItemBase itemInfo) { + Console.WriteLine("received new inventory item " + itemInfo.inventoryID + " with asset id of " + itemInfo.assetID); if ((userID == this.UserProfile.UUID) && (this.RootFolder != null)) { if (itemInfo.parentFolderID == this.RootFolder.folderID) @@ -84,11 +91,23 @@ namespace OpenSim.Framework.Communications.Caches InventoryFolder folder = this.RootFolder.HasSubFolder(itemInfo.parentFolderID); if (folder != null) { - folder.Items.Add(itemInfo.inventoryID, itemInfo); + folder.Items.Add(itemInfo.inventoryID, itemInfo); } } } } + + public void AddItem(LLUUID userID, InventoryItemBase itemInfo) + { + if ((userID == this.UserProfile.UUID) && (this.RootFolder != null)) + { + this.ItemReceive(userID, itemInfo); + Console.WriteLine("now adding inventory item to database"); + this.m_parentCommsManager.InventoryServer.AddNewInventoryItem(userID, itemInfo); + } + } } + + } diff --git a/OpenSim/Framework/Communications/Cache/UserProfileCache.cs b/OpenSim/Framework/Communications/Cache/UserProfileCache.cs index e65b6b2..02c5f65 100644 --- a/OpenSim/Framework/Communications/Cache/UserProfileCache.cs +++ b/OpenSim/Framework/Communications/Cache/UserProfileCache.cs @@ -61,7 +61,7 @@ namespace OpenSim.Framework.Communications.Caches { if (!this.UserProfiles.ContainsKey(userID)) { - CachedUserInfo userInfo = new CachedUserInfo(); + CachedUserInfo userInfo = new CachedUserInfo(this.m_parent); userInfo.UserProfile = this.RequestUserProfileForUser(userID); if (userInfo.UserProfile != null) { diff --git a/OpenSim/Framework/Communications/Capabilities/Caps.cs b/OpenSim/Framework/Communications/Capabilities/Caps.cs index 82ef08d..eb88aa7 100644 --- a/OpenSim/Framework/Communications/Capabilities/Caps.cs +++ b/OpenSim/Framework/Communications/Capabilities/Caps.cs @@ -35,10 +35,12 @@ using OpenSim.Framework.Servers; using OpenSim.Framework.Types; using OpenSim.Framework.Utilities; using OpenSim.Framework.Communications.Caches; +using OpenSim.Framework.Data; namespace OpenSim.Region.Capabilities { - public delegate void UpLoadedTexture(string assetName, LLUUID assetID, LLUUID inventoryItem, byte[] data); + public delegate void UpLoadedTexture(string assetName, string description, LLUUID assetID, LLUUID inventoryItem, LLUUID parentFolder, byte[] data); + public delegate void NewInventoryItem(LLUUID userID, InventoryItemBase item); public class Caps { @@ -56,6 +58,7 @@ namespace OpenSim.Region.Capabilities private AssetCache assetCache; private int eventQueueCount = 1; private Queue CapsEventQueue = new Queue(); + public NewInventoryItem AddNewInventoryItem = null; public Caps(AssetCache assetCach, BaseHttpServer httpServer, string httpListen, int httpPort, string capsPath, LLUUID agent) { @@ -122,7 +125,7 @@ namespace OpenSim.Region.Capabilities string capsBaseUrl = "http://" + m_httpListenerHostName + ":" + m_httpListenPort.ToString() + "/CAPS/" + m_capsObjectPath; caps.MapLayer = capsBaseUrl + m_mapLayerPath; caps.NewFileAgentInventory = capsBaseUrl + m_newInventory; - caps.UpdateNotecardAgentInventory = capsBaseUrl + m_notecardUpdatePath; + // caps.UpdateNotecardAgentInventory = capsBaseUrl + m_notecardUpdatePath; return caps; } @@ -242,7 +245,7 @@ namespace OpenSim.Region.Capabilities LLUUID newInvItem = LLUUID.Random(); string uploaderPath = Util.RandomClass.Next(5000, 8000).ToString("0000"); - AssetUploader uploader = new AssetUploader(assetName, newAsset, newInvItem, capsBase + uploaderPath, this.httpListener); + AssetUploader uploader = new AssetUploader(assetName, "description", newAsset, newInvItem, LLUUID.Zero, "", "", capsBase + uploaderPath, this.httpListener); httpListener.AddStreamHandler(new BinaryStreamHandler("POST", capsBase + uploaderPath, uploader.uploaderCaps)); string uploaderURL = "http://" + m_httpListenerHostName + ":" + m_httpListenPort.ToString() + capsBase + uploaderPath; @@ -261,13 +264,16 @@ namespace OpenSim.Region.Capabilities public LLSDAssetUploadResponse NewAgentInventoryRequest(LLSDAssetUploadRequest llsdRequest) { // Console.WriteLine("asset upload request via CAPS"); + string assetName = llsdRequest.name; + string assetDes = llsdRequest.description; string capsBase = "/CAPS/" + m_capsObjectPath; LLUUID newAsset = LLUUID.Random(); LLUUID newInvItem = LLUUID.Random(); + LLUUID parentFolder = llsdRequest.folder_id; string uploaderPath = Util.RandomClass.Next(5000, 8000).ToString("0000"); - AssetUploader uploader = new AssetUploader(assetName, newAsset, newInvItem, capsBase + uploaderPath, this.httpListener); + AssetUploader uploader = new AssetUploader(assetName, assetDes, newAsset, newInvItem, parentFolder, "" , "", capsBase + uploaderPath, this.httpListener); httpListener.AddStreamHandler(new BinaryStreamHandler("POST", capsBase + uploaderPath, uploader.uploaderCaps)); string uploaderURL = "http://" + m_httpListenerHostName + ":" + m_httpListenPort.ToString() + capsBase + uploaderPath; @@ -284,7 +290,7 @@ namespace OpenSim.Region.Capabilities /// /// /// - public void UploadCompleteHandler(string assetName, LLUUID assetID, LLUUID inventoryItem, byte[] data) + public void UploadCompleteHandler(string assetName, string assetDescription, LLUUID assetID, LLUUID inventoryItem, LLUUID parentFolder, byte[] data) { AssetBase asset; asset = new AssetBase(); @@ -294,6 +300,25 @@ namespace OpenSim.Region.Capabilities asset.Name = assetName; asset.Data = data; this.assetCache.AddAsset(asset); + + InventoryItemBase item = new InventoryItemBase(); + item.avatarID = agentID; + item.creatorsID = agentID; + item.inventoryID = inventoryItem; + item.assetID = asset.FullID; + item.inventoryDescription = assetDescription; + item.inventoryName = assetName; + item.assetType = 0; + item.invType = 0; + item.parentFolderID = parentFolder; + item.inventoryCurrentPermissions = 2147483647; + item.inventoryNextPermissions = 2147483647; + + if (AddNewInventoryItem != null) + { + AddNewInventoryItem(agentID, item); + } + } public class AssetUploader @@ -303,9 +328,11 @@ namespace OpenSim.Region.Capabilities private string uploaderPath = ""; private LLUUID newAssetID; private LLUUID inventoryItemID; + private LLUUID parentFolder; private BaseHttpServer httpListener; private bool SaveAssets = false; private string m_assetName = ""; + private string m_assetDes = ""; /// /// @@ -314,13 +341,15 @@ namespace OpenSim.Region.Capabilities /// /// /// - public AssetUploader(string assetName, LLUUID assetID, LLUUID inventoryItem, string path, BaseHttpServer httpServer) + public AssetUploader(string assetName, string description, LLUUID assetID, LLUUID inventoryItem, LLUUID parentFolderID, string invType, string assetType, string path, BaseHttpServer httpServer) { m_assetName = assetName; + m_assetDes = description; newAssetID = assetID; inventoryItemID = inventoryItem; uploaderPath = path; httpListener = httpServer; + parentFolder = parentFolderID; } /// @@ -348,7 +377,7 @@ namespace OpenSim.Region.Capabilities if (OnUpLoad != null) { - OnUpLoad(m_assetName, newAssetID, inv, data); + OnUpLoad(m_assetName, m_assetDes, newAssetID, inv, parentFolder, data); } return res; diff --git a/OpenSim/Framework/Communications/IInventoryServices.cs b/OpenSim/Framework/Communications/IInventoryServices.cs index 777dbe2..6f01cf2 100644 --- a/OpenSim/Framework/Communications/IInventoryServices.cs +++ b/OpenSim/Framework/Communications/IInventoryServices.cs @@ -15,5 +15,6 @@ namespace OpenSim.Framework.Communications { void RequestInventoryForUser(LLUUID userID, InventoryFolderInfo folderCallBack, InventoryItemInfo itemCallBack); void AddNewInventoryFolder(LLUUID userID, InventoryFolder folder); + void AddNewInventoryItem(LLUUID userID, InventoryItemBase item); } } diff --git a/OpenSim/Framework/Data.SQLite/SQLiteInventoryStore.cs b/OpenSim/Framework/Data.SQLite/SQLiteInventoryStore.cs index 811a355..045fbee 100644 --- a/OpenSim/Framework/Data.SQLite/SQLiteInventoryStore.cs +++ b/OpenSim/Framework/Data.SQLite/SQLiteInventoryStore.cs @@ -91,7 +91,7 @@ namespace OpenSim.Framework.Data.SQLite data.Add("inventoryCurrentPermissions", DbType.Int32); data.Add("inventoryBasePermissions", DbType.Int32); data.Add("inventoryEveryOnePermissions", DbType.Int32); - + return data; } @@ -219,6 +219,44 @@ namespace OpenSim.Framework.Data.SQLite row["version"] = folder.version; } + public InventoryItemBase BuildItem(DataRow row) + { + InventoryItemBase item = new InventoryItemBase(); + item.inventoryID = new LLUUID((string)row["UUID"]); + item.assetID = new LLUUID((string)row["assetID"]); + item.assetType = Convert.ToInt32(row["assetType"]); + item.invType = Convert.ToInt32(row["invType"]); + item.parentFolderID = new LLUUID((string)row["parentFolderID"]); + item.avatarID = new LLUUID((string)row["avatarID"]); + item.creatorsID = new LLUUID((string)row["creatorsID"]); + item.inventoryName =(string) row["inventoryName"]; + item.inventoryDescription = (string) row["inventoryDescription"]; + + item.inventoryNextPermissions = Convert.ToUInt32(row["inventoryNextPermissions"]); + item.inventoryCurrentPermissions = Convert.ToUInt32(row["inventoryCurrentPermissions"]); + item.inventoryBasePermissions = Convert.ToUInt32(row["inventoryBasePermissions"]); + item.inventoryEveryOnePermissions = Convert.ToUInt32(row["inventoryEveryOnePermissions"]); + return item; + } + + private void fillItemRow(DataRow row, InventoryItemBase item) + { + row["UUID"] = item.inventoryID; + row["assetID"] = item.assetID; + row["assetType"] = item.assetType; + row["invType"] = item.invType; + row["parentFolderID"] = item.parentFolderID; + row["avatarID"] = item.avatarID; + row["creatorsID"] = item.creatorsID; + row["inventoryName"] = item.inventoryName; + row["inventoryDescription"] = item.inventoryDescription; + + row["inventoryNextPermissions"] = item.inventoryNextPermissions; + row["inventoryCurrentPermissions"] = item.inventoryCurrentPermissions; + row["inventoryBasePermissions"] = item.inventoryBasePermissions; + row["inventoryEveryOnePermissions"] = item.inventoryEveryOnePermissions; + } + private void addFolder(InventoryFolderBase folder) { DataTable inventoryFolderTable = ds.Tables["inventoryfolders"]; @@ -238,6 +276,24 @@ namespace OpenSim.Framework.Data.SQLite this.invFoldersDa.Update(ds, "inventoryfolders"); } + private void addItem(InventoryItemBase item) + { + DataTable inventoryItemTable = ds.Tables["inventoryitems"]; + + DataRow inventoryRow = inventoryItemTable.Rows.Find(item.inventoryID); + if (inventoryRow == null) + { + inventoryRow = inventoryItemTable.NewRow(); + fillItemRow(inventoryRow, item); + inventoryItemTable.Rows.Add(inventoryRow); + } + else + { + fillItemRow(inventoryRow, item); + } + this.invItemsDa.Update(ds, "inventoryitems"); + } + public void Shutdown() { // TODO: DataSet commit @@ -275,7 +331,16 @@ namespace OpenSim.Framework.Data.SQLite /// A List of InventoryItemBase items public List getInventoryInFolder(LLUUID folderID) { - return null; + List retval = new List(); + DataTable inventoryItemTable = ds.Tables["inventoryitems"]; + string selectExp = "parentFolderID = '" + folderID.ToString() + "'"; + DataRow[] rows = inventoryItemTable.Select(selectExp); + foreach (DataRow row in rows) + { + retval.Add(BuildItem(row)); + } + + return retval; } /// @@ -297,7 +362,7 @@ namespace OpenSim.Framework.Data.SQLite { List folders = new List(); DataTable inventoryFolderTable = ds.Tables["inventoryfolders"]; - string selectExp = "agentID = '"+ user.ToString()+"' AND parentID = '"+ LLUUID.Zero.ToString()+"'"; + string selectExp = "agentID = '" + user.ToString() + "' AND parentID = '" + LLUUID.Zero.ToString() + "'"; DataRow[] rows = inventoryFolderTable.Select(selectExp); foreach (DataRow row in rows) { @@ -339,7 +404,7 @@ namespace OpenSim.Framework.Data.SQLite { folders.Add(this.buildFolder(row)); } - // System.Console.WriteLine("found " + folders.Count + " inventory folders"); + // System.Console.WriteLine("found " + folders.Count + " inventory folders"); return folders; } @@ -369,6 +434,7 @@ namespace OpenSim.Framework.Data.SQLite /// The item to be created public void addInventoryItem(InventoryItemBase item) { + this.addItem(item); } /// @@ -377,6 +443,7 @@ namespace OpenSim.Framework.Data.SQLite /// The updated item public void updateInventoryItem(InventoryItemBase item) { + this.addItem(item); } /// diff --git a/OpenSim/Framework/InventoryServiceBase/InventoryServiceBase.cs b/OpenSim/Framework/InventoryServiceBase/InventoryServiceBase.cs index 10da633..bc55d05 100644 --- a/OpenSim/Framework/InventoryServiceBase/InventoryServiceBase.cs +++ b/OpenSim/Framework/InventoryServiceBase/InventoryServiceBase.cs @@ -116,6 +116,14 @@ namespace OpenSim.Framework.InventoryServiceBase } } + public void AddItem(InventoryItemBase item) + { + foreach (KeyValuePair plugin in m_plugins) + { + plugin.Value.addInventoryItem(item); + } + } + /// /// /// -- cgit v1.1