From 5df851761aa796cba70a3b6d8b36d119502c1de2 Mon Sep 17 00:00:00 2001 From: MW Date: Sat, 1 Dec 2007 18:49:17 +0000 Subject: Initial working Grid Inventory server. Only been tested on a very small grid, so likely to have problems on a larger grid with more people? To use , both the user server and Inventory server need to be running this latest revision. (older regions should be able to still be used, just the user won't have inventory on them). Also and HERE IS THE BIG BREAK ISSUE, currently, so that the initial inventory details for a user are added to the inventory db , you need to recreate the accounts using the user server "create user" feature. It should be quite easy to manual populate the inventory database instead but I someone else will need to look into that) Also I've only tested using SQLite as the database provider, there is a Mysql inventory provider but I don't know if it works (SQLite is set as default, so you will need to change it in the inventory server config.xml) --- .../Grid/InventoryServer/GridInventoryService.cs | 104 +++++++++++++++++++++ OpenSim/Grid/InventoryServer/Main.cs | 34 ++++++- OpenSim/Grid/UserServer/Main.cs | 19 +++- OpenSim/Grid/UserServer/UserLoginService.cs | 50 ++++++++++ 4 files changed, 202 insertions(+), 5 deletions(-) create mode 100644 OpenSim/Grid/InventoryServer/GridInventoryService.cs (limited to 'OpenSim/Grid') diff --git a/OpenSim/Grid/InventoryServer/GridInventoryService.cs b/OpenSim/Grid/InventoryServer/GridInventoryService.cs new file mode 100644 index 0000000..dda2f61 --- /dev/null +++ b/OpenSim/Grid/InventoryServer/GridInventoryService.cs @@ -0,0 +1,104 @@ +using System; +using System.Collections.Generic; +using System.Text; +using OpenSim.Framework; +using OpenSim.Framework.Communications; +using libsecondlife; + +namespace OpenSim.Grid.InventoryServer +{ + public class GridInventoryService : InventoryServiceBase + { + public override void RequestInventoryForUser(LLUUID userID, InventoryFolderInfo folderCallBack, + InventoryItemInfo itemCallBack) + { + + } + + private bool TryGetUsersInventory(LLUUID userID, out List folderList, out List itemsList) + { + List folders = RequestFirstLevelFolders(userID); + List allItems = new List(); + + if (folders != null) + { + foreach (InventoryFolderBase folder in folders) + { + if (folder.parentID != LLUUID.Zero) + { + List items = RequestFolderItems(folder.folderID); + if (items != null) + { + allItems.InsertRange(0, items); + } + } + } + } + + folderList = folders; + itemsList = allItems; + if (folderList != null) + { + return true; + } + else + { + return false; + } + } + + public InventoryCollection GetUserInventory(LLUUID userID) + { + InventoryCollection invCollection = new InventoryCollection(); + List folders; + List allItems; + if (TryGetUsersInventory(userID, out folders, out allItems)) + { + invCollection.AllItems = allItems; + invCollection.Folders = folders; + invCollection.UserID = userID; + } + return invCollection; + } + + public bool CreateUsersInventory(LLUUID user) + { + CreateNewUserInventory(user); + return true; + } + + + public override void AddNewInventoryFolder(LLUUID userID, InventoryFolderBase folder) + { + AddFolder(folder); + } + + public override void AddNewInventoryItem(LLUUID userID, InventoryItemBase item) + { + AddItem(item); + } + + public bool AddInventoryFolder( InventoryFolderBase folder) + { + AddNewInventoryFolder(folder.agentID, folder); + return true; + } + + public bool AddInventoryItem( InventoryItemBase item) + { + AddNewInventoryItem(item.avatarID, item); + return true; + } + + public override void DeleteInventoryItem(LLUUID userID, InventoryItemBase item) + { + DeleteItem(item); + } + + public bool DeleteInvItem( InventoryItemBase item) + { + DeleteInventoryItem(item.avatarID, item); + return true; + } + } +} diff --git a/OpenSim/Grid/InventoryServer/Main.cs b/OpenSim/Grid/InventoryServer/Main.cs index 1bc396b..8d232c2 100644 --- a/OpenSim/Grid/InventoryServer/Main.cs +++ b/OpenSim/Grid/InventoryServer/Main.cs @@ -47,6 +47,7 @@ namespace OpenSim.Grid.InventoryServer LogBase m_console; InventoryManager m_inventoryManager; InventoryConfig m_config; + GridInventoryService m_inventoryService; public const string LogName = "INVENTORY"; @@ -69,13 +70,35 @@ namespace OpenSim.Grid.InventoryServer { MainLog.Instance.Notice("Initialising inventory manager..."); m_config = new InventoryConfig(LogName, (Path.Combine(Util.configDir(), "InventoryServer_Config.xml"))); - - m_inventoryManager = new InventoryManager(); - m_inventoryManager.AddDatabasePlugin(m_config.DatabaseProvider); + + m_inventoryService = new GridInventoryService(); + // m_inventoryManager = new InventoryManager(); + m_inventoryService.AddPlugin(m_config.DatabaseProvider); + MainLog.Instance.Notice(LogName, "Starting HTTP server ..."); BaseHttpServer httpServer = new BaseHttpServer(m_config.HttpPort); + httpServer.AddStreamHandler( + new RestDeserialisehandler("POST", "/GetInventory/", + m_inventoryService.GetUserInventory)); + httpServer.AddStreamHandler( + new RestDeserialisehandler("POST", "/CreateInventory/", + m_inventoryService.CreateUsersInventory)); + httpServer.AddStreamHandler( + new RestDeserialisehandler("POST", "/NewFolder/", + m_inventoryService.AddInventoryFolder)); + + httpServer.AddStreamHandler( + new RestDeserialisehandler("POST", "/NewItem/", + m_inventoryService.AddInventoryItem)); + httpServer.AddStreamHandler( + new RestDeserialisehandler("POST", "/DeleteItem/", + m_inventoryService.DeleteInvItem)); - httpServer.AddStreamHandler(new InventoryManager.GetInventory(m_inventoryManager)); + httpServer.AddStreamHandler( + new RestDeserialisehandler>("POST", "/RootFolders/", + m_inventoryService.RequestFirstLevelFolders)); + + // httpServer.AddStreamHandler(new InventoryManager.GetInventory(m_inventoryManager)); httpServer.Start(); MainLog.Instance.Notice(LogName, "Started HTTP server"); @@ -96,6 +119,9 @@ namespace OpenSim.Grid.InventoryServer switch (cmd) { case "quit": + case "add-user": + m_inventoryService.CreateUsersInventory(LLUUID.Random()); + break; case "shutdown": m_console.Close(); Environment.Exit(0); diff --git a/OpenSim/Grid/UserServer/Main.cs b/OpenSim/Grid/UserServer/Main.cs index 779a72b..b00bb76 100644 --- a/OpenSim/Grid/UserServer/Main.cs +++ b/OpenSim/Grid/UserServer/Main.cs @@ -27,7 +27,9 @@ */ using System; +using System.Collections.Generic; using System.IO; +using libsecondlife; using OpenSim.Framework; using OpenSim.Framework.Console; using OpenSim.Framework.Servers; @@ -44,6 +46,7 @@ namespace OpenSim.Grid.UserServer public UserLoginService m_loginService; private LogBase m_console; + private LLUUID m_lastCreatedUser = LLUUID.Random(); [STAThread] public static void Main(string[] args) @@ -123,7 +126,9 @@ namespace OpenSim.Grid.UserServer tempMD5Passwd = Util.Md5Hash(Util.Md5Hash(tempMD5Passwd) + ":" + ""); - m_userManager.AddUserProfile(tempfirstname, templastname, tempMD5Passwd, regX, regY); + LLUUID userID = m_userManager.AddUserProfile(tempfirstname, templastname, tempMD5Passwd, regX, regY); + RestObjectPoster.BeginPostObject(m_userManager._config.InventoryUrl + "CreateInventory/", userID); + m_lastCreatedUser = userID; break; } } @@ -145,9 +150,21 @@ namespace OpenSim.Grid.UserServer m_console.Close(); Environment.Exit(0); break; + + case "test-inventory": + // RestObjectPosterResponse> requester = new RestObjectPosterResponse>(); + // requester.ReturnResponseVal = TestResponse; + // requester.BeginPostObject(m_userManager._config.InventoryUrl + "RootFolders/", m_lastCreatedUser); + List folders = SyncRestObjectPoster.BeginPostObject>(m_userManager._config.InventoryUrl + "RootFolders/", m_lastCreatedUser); + break; } } + public void TestResponse(List resp) + { + System.Console.WriteLine("response got"); + } + /*private void ConfigDB(IGenericConfig configData) { try diff --git a/OpenSim/Grid/UserServer/UserLoginService.cs b/OpenSim/Grid/UserServer/UserLoginService.cs index 0af5790..d3164ad 100644 --- a/OpenSim/Grid/UserServer/UserLoginService.cs +++ b/OpenSim/Grid/UserServer/UserLoginService.cs @@ -28,12 +28,16 @@ using System; using System.Collections; +using System.Collections.Generic; using System.Net; using Nwc.XmlRpc; +using libsecondlife; using OpenSim.Framework; using OpenSim.Framework.Console; +using OpenSim.Framework.Servers; using OpenSim.Framework.Data; using OpenSim.Framework.UserManagement; +using InventoryFolder = OpenSim.Framework.InventoryFolder; namespace OpenSim.Grid.UserServer { @@ -189,5 +193,51 @@ namespace OpenSim.Grid.UserServer } } + + protected override InventoryData CreateInventoryData(LLUUID userID) + { + List folders = SyncRestObjectPoster.BeginPostObject>(m_config.InventoryUrl + "RootFolders/", userID); + if (folders.Count > 0) + { + LLUUID rootID = LLUUID.Zero; + ArrayList AgentInventoryArray = new ArrayList(); + Hashtable TempHash; + foreach (InventoryFolderBase InvFolder in folders) + { + if (InvFolder.parentID == LLUUID.Zero) + { + rootID = InvFolder.folderID; + } + TempHash = new Hashtable(); + TempHash["name"] = InvFolder.name; + TempHash["parent_id"] = InvFolder.parentID.ToStringHyphenated(); + TempHash["version"] = (Int32)InvFolder.version; + TempHash["type_default"] = (Int32)InvFolder.type; + TempHash["folder_id"] = InvFolder.folderID.ToStringHyphenated(); + AgentInventoryArray.Add(TempHash); + } + return new InventoryData(AgentInventoryArray, rootID); + } + else + { + AgentInventory userInventory = new AgentInventory(); + userInventory.CreateRootFolder(userID, false); + + ArrayList AgentInventoryArray = new ArrayList(); + Hashtable TempHash; + foreach (InventoryFolder InvFolder in userInventory.InventoryFolders.Values) + { + TempHash = new Hashtable(); + TempHash["name"] = InvFolder.FolderName; + TempHash["parent_id"] = InvFolder.ParentID.ToStringHyphenated(); + TempHash["version"] = (Int32)InvFolder.Version; + TempHash["type_default"] = (Int32)InvFolder.DefaultType; + TempHash["folder_id"] = InvFolder.FolderID.ToStringHyphenated(); + AgentInventoryArray.Add(TempHash); + } + + return new InventoryData(AgentInventoryArray, userInventory.InventoryRoot.FolderID); + } + } } } \ No newline at end of file -- cgit v1.1