* Rex merges, Inventory server

afrisby-3
Adam Frisby 2008-02-23 02:45:16 +00:00
parent 79cb89f406
commit f06b6e2274
3 changed files with 553 additions and 548 deletions

View File

@ -1,204 +1,206 @@
/*
* Copyright (c) Contributors, http://opensimulator.org/
* See CONTRIBUTORS.TXT for a full list of copyright holders.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the OpenSim Project nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
using System;
using System.Collections.Generic;
using libsecondlife;
using OpenSim.Framework;
using OpenSim.Framework.Communications;
using OpenSim.Framework.Console;
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<InventoryFolderBase> folderList,
out List<InventoryItemBase> itemsList)
{
List<InventoryFolderBase> rootFolders = RequestFirstLevelFolders(userID);
List<InventoryItemBase> allItems = new List<InventoryItemBase>();
List<InventoryFolderBase> allFolders = new List<InventoryFolderBase>();
if (rootFolders != null)
{
allFolders.InsertRange(0, rootFolders);
foreach (InventoryFolderBase subfolder in rootFolders)
{
List<InventoryFolderBase> subFolders = GetAllFolders(subfolder.folderID);
if (subFolders != null)
{
allFolders.InsertRange(0, subFolders);
}
}
}
foreach (InventoryFolderBase folder in allFolders)
{
List<InventoryItemBase> items = RequestFolderItems(folder.folderID);
if (items != null)
{
allItems.InsertRange(0, items);
}
}
folderList = allFolders;
itemsList = allItems;
if (folderList != null)
{
return true;
}
else
{
return false;
}
}
private List<InventoryFolderBase> GetAllFolders(LLUUID folder)
{
List<InventoryFolderBase> allFolders = new List<InventoryFolderBase>();
List<InventoryFolderBase> folders = RequestSubFolders(folder);
if (folders != null)
{
allFolders.InsertRange(0, folders);
foreach (InventoryFolderBase subfolder in folders)
{
List<InventoryFolderBase> subFolders = GetAllFolders(subfolder.folderID);
if (subFolders != null)
{
allFolders.InsertRange(0, subFolders);
}
}
}
return allFolders;
}
public InventoryCollection GetUserInventory(Guid rawUserID)
{
LLUUID userID = new LLUUID(rawUserID);
// We get enough verbose messages later on for diagnostics
//MainLog.Instance.Verbose("INVENTORY", "Request for inventory for " + userID.ToString());
InventoryCollection invCollection = new InventoryCollection();
List<InventoryFolderBase> folders;
List<InventoryItemBase> allItems;
if (TryGetUsersInventory(userID, out folders, out allItems))
{
invCollection.AllItems = allItems;
invCollection.Folders = folders;
invCollection.UserID = userID;
}
return invCollection;
}
public bool CreateUsersInventory(Guid rawUserID)
{
LLUUID userID = new LLUUID(rawUserID);
MainLog.Instance.Verbose(
"INVENTORY", "Creating new set of inventory folders for " + userID.ToString());
CreateNewUserInventory(userID);
return true;
}
public override void AddNewInventoryFolder(LLUUID userID, InventoryFolderBase folder)
{
AddFolder(folder);
}
public override void MoveExistingInventoryFolder(InventoryFolderBase folder)
{
MoveFolder(folder);
}
public override void AddNewInventoryItem(LLUUID userID, InventoryItemBase item)
{
AddItem(item);
}
public bool AddInventoryFolder(InventoryFolderBase folder)
{
// Right now, this actions act more like an update/insert combination than a simple create.
MainLog.Instance.Verbose(
"INVENTORY",
"Updating in " + folder.parentID.ToString()
+ ", folder " + folder.name);
AddNewInventoryFolder(folder.agentID, folder);
return true;
}
public bool MoveInventoryFolder(InventoryFolderBase folder)
{
MainLog.Instance.Verbose(
"INVENTORY",
"Moving folder " + folder.folderID
+ " to " + folder.parentID.ToString());
MoveExistingInventoryFolder(folder);
return true;
}
public bool AddInventoryItem(InventoryItemBase item)
{
// Right now, this actions act more like an update/insert combination than a simple create.
MainLog.Instance.Verbose(
"INVENTORY",
"Updating in " + item.parentFolderID.ToString()
+ ", item " + item.inventoryName);
AddNewInventoryItem(item.avatarID, item);
return true;
}
public override void DeleteInventoryItem(LLUUID userID, InventoryItemBase item)
{
// extra spaces to align with other inventory messages
MainLog.Instance.Verbose(
"INVENTORY",
"Deleting in " + item.parentFolderID.ToString()
+ ", item " + item.inventoryName);
DeleteItem(item);
}
public bool DeleteInvItem(InventoryItemBase item)
{
DeleteInventoryItem(item.avatarID, item);
return true;
}
}
}
/*
* Copyright (c) Contributors, http://opensimulator.org/
* See CONTRIBUTORS.TXT for a full list of copyright holders.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the OpenSim Project nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
using System;
using System.Collections.Generic;
using libsecondlife;
using OpenSim.Framework;
using OpenSim.Framework.Communications;
using OpenSim.Framework.Console;
namespace OpenSim.Grid.InventoryServer
{
public class GridInventoryService : InventoryServiceBase
{
private static readonly log4net.ILog m_log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
public override void RequestInventoryForUser(LLUUID userID, InventoryFolderInfo folderCallBack,
InventoryItemInfo itemCallBack)
{
}
private bool TryGetUsersInventory(LLUUID userID, out List<InventoryFolderBase> folderList,
out List<InventoryItemBase> itemsList)
{
List<InventoryFolderBase> rootFolders = RequestFirstLevelFolders(userID);
List<InventoryItemBase> allItems = new List<InventoryItemBase>();
List<InventoryFolderBase> allFolders = new List<InventoryFolderBase>();
if (rootFolders != null)
{
allFolders.InsertRange(0, rootFolders);
foreach (InventoryFolderBase subfolder in rootFolders)
{
List<InventoryFolderBase> subFolders = GetAllFolders(subfolder.folderID);
if (subFolders != null)
{
allFolders.InsertRange(0, subFolders);
}
}
}
foreach (InventoryFolderBase folder in allFolders)
{
List<InventoryItemBase> items = RequestFolderItems(folder.folderID);
if (items != null)
{
allItems.InsertRange(0, items);
}
}
folderList = allFolders;
itemsList = allItems;
if (folderList != null)
{
return true;
}
else
{
return false;
}
}
private List<InventoryFolderBase> GetAllFolders(LLUUID folder)
{
List<InventoryFolderBase> allFolders = new List<InventoryFolderBase>();
List<InventoryFolderBase> folders = RequestSubFolders(folder);
if (folders != null)
{
allFolders.InsertRange(0, folders);
foreach (InventoryFolderBase subfolder in folders)
{
List<InventoryFolderBase> subFolders = GetAllFolders(subfolder.folderID);
if (subFolders != null)
{
allFolders.InsertRange(0, subFolders);
}
}
}
return allFolders;
}
public InventoryCollection GetUserInventory(Guid rawUserID)
{
LLUUID userID = new LLUUID(rawUserID);
// We get enough verbose messages later on for diagnostics
//m_log.Info("[INVENTORY]: Request for inventory for " + userID.ToString());
InventoryCollection invCollection = new InventoryCollection();
List<InventoryFolderBase> folders;
List<InventoryItemBase> allItems;
if (TryGetUsersInventory(userID, out folders, out allItems))
{
invCollection.AllItems = allItems;
invCollection.Folders = folders;
invCollection.UserID = userID;
}
return invCollection;
}
public bool CreateUsersInventory(Guid rawUserID)
{
LLUUID userID = new LLUUID(rawUserID);
m_log.Info(
"[INVENTORY]: Creating new set of inventory folders for " + userID.ToString());
CreateNewUserInventory(userID);
return true;
}
public override void AddNewInventoryFolder(LLUUID userID, InventoryFolderBase folder)
{
AddFolder(folder);
}
public override void MoveExistingInventoryFolder(InventoryFolderBase folder)
{
MoveFolder(folder);
}
public override void AddNewInventoryItem(LLUUID userID, InventoryItemBase item)
{
AddItem(item);
}
public bool AddInventoryFolder(InventoryFolderBase folder)
{
// Right now, this actions act more like an update/insert combination than a simple create.
m_log.Info(
"[INVENTORY]: " +
"Updating in " + folder.parentID.ToString()
+ ", folder " + folder.name);
AddNewInventoryFolder(folder.agentID, folder);
return true;
}
public bool MoveInventoryFolder(InventoryFolderBase folder)
{
m_log.Info(
"[INVENTORY]: " +
"Moving folder " + folder.folderID
+ " to " + folder.parentID.ToString());
MoveExistingInventoryFolder(folder);
return true;
}
public bool AddInventoryItem(InventoryItemBase item)
{
// Right now, this actions act more like an update/insert combination than a simple create.
m_log.Info(
"[INVENTORY]: " +
"Updating in " + item.parentFolderID.ToString()
+ ", item " + item.inventoryName);
AddNewInventoryItem(item.avatarID, item);
return true;
}
public override void DeleteInventoryItem(LLUUID userID, InventoryItemBase item)
{
// extra spaces to align with other inventory messages
m_log.Info(
"[INVENTORY]: " +
"Deleting in " + item.parentFolderID.ToString()
+ ", item " + item.inventoryName);
DeleteItem(item);
}
public bool DeleteInvItem(InventoryItemBase item)
{
DeleteInventoryItem(item.avatarID, item);
return true;
}
}
}

View File

@ -1,210 +1,212 @@
/*
* Copyright (c) Contributors, http://opensimulator.org/
* See CONTRIBUTORS.TXT for a full list of copyright holders.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the OpenSim Project nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
using System;
using System.IO;
using System.Reflection;
using System.Text;
using System.Xml;
using System.Xml.Serialization;
using libsecondlife;
using OpenSim.Framework;
using OpenSim.Framework.Console;
using OpenSim.Framework.Servers;
namespace OpenSim.Grid.InventoryServer
{
public class InventoryManager
{
private IInventoryData _databasePlugin;
/// <summary>
/// Adds a new inventory server plugin - user servers will be requested in the order they were loaded.
/// </summary>
/// <param name="FileName">The filename to the inventory server plugin DLL</param>
public void AddDatabasePlugin(string FileName)
{
MainLog.Instance.Verbose(OpenInventory_Main.LogName, "Invenstorage: Attempting to load " + FileName);
Assembly pluginAssembly = Assembly.LoadFrom(FileName);
MainLog.Instance.Verbose(OpenInventory_Main.LogName,
"Invenstorage: Found " + pluginAssembly.GetTypes().Length + " interfaces.");
foreach (Type pluginType in pluginAssembly.GetTypes())
{
if (!pluginType.IsAbstract)
{
Type typeInterface = pluginType.GetInterface("IInventoryData", true);
if (typeInterface != null)
{
IInventoryData plug =
(IInventoryData) Activator.CreateInstance(pluginAssembly.GetType(pluginType.ToString()));
plug.Initialise();
_databasePlugin = plug;
MainLog.Instance.Verbose(OpenInventory_Main.LogName,
"Invenstorage: Added IInventoryData Interface");
break;
}
typeInterface = null;
}
}
pluginAssembly = null;
}
protected static SerializableInventory loadInventoryFromXmlFile(string fileName)
{
FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read);
XmlReader reader = new XmlTextReader(fs);
XmlSerializer x = new XmlSerializer(typeof (SerializableInventory));
SerializableInventory inventory = (SerializableInventory) x.Deserialize(reader);
fs.Close();
fs.Dispose();
return inventory;
}
protected static void saveInventoryToStream(SerializableInventory inventory, Stream s)
{
XmlTextWriter writer = new XmlTextWriter(s, Encoding.UTF8);
writer.Formatting = Formatting.Indented;
XmlSerializer x = new XmlSerializer(typeof (SerializableInventory));
x.Serialize(writer, inventory);
}
protected static bool fixupFolder(SerializableInventory.SerializableFolder f,
SerializableInventory.SerializableFolder parent)
{
bool modified = false;
// ensure we have a valid folder id
if (f.folderID == LLUUID.Zero)
{
f.folderID = LLUUID.Random();
modified = true;
}
// ensure we have valid agent id
if (f.agentID == LLUUID.Zero)
{
if (parent != null)
f.agentID = parent.agentID;
else
f.agentID = f.folderID;
modified = true;
}
if (f.parentID == LLUUID.Zero && parent != null)
{
f.parentID = parent.folderID;
modified = true;
}
foreach (SerializableInventory.SerializableFolder child in f.SubFolders)
{
modified |= fixupFolder(child, f);
}
return modified;
}
protected static bool fixupInventory(SerializableInventory inventory)
{
return fixupFolder(inventory.root, null);
}
public class GetInventory : BaseStreamHandler
{
private SerializableInventory _inventory;
private InventoryManager _manager;
public GetInventory(InventoryManager manager)
: base("GET", "/inventory")
{
_manager = manager;
_inventory = loadInventoryFromXmlFile("attic/inventory/Inventory_Library.xml");
if (fixupInventory(_inventory))
{
FileStream fs = new FileStream("attic/inventory/Inventory_Library.xml", FileMode.Truncate, FileAccess.Write);
saveInventoryToStream(_inventory, fs);
fs.Flush();
fs.Close();
MainLog.Instance.Debug(OpenInventory_Main.LogName, "Modified");
}
}
private void CreateDefaultInventory(LLUUID userID)
{
}
private byte[] GetUserInventory(LLUUID userID)
{
MainLog.Instance.Notice(OpenInventory_Main.LogName, "Getting Inventory for user {0}", userID.ToString());
byte[] result = new byte[] {};
InventoryFolderBase fb = _manager._databasePlugin.getUserRootFolder(userID);
if (fb == null)
{
MainLog.Instance.Notice(OpenInventory_Main.LogName, "Inventory not found for user {0}, creating new",
userID.ToString());
CreateDefaultInventory(userID);
}
return result;
}
public override byte[] Handle(string path, Stream request)
{
byte[] result = new byte[] {};
string[] parms = path.Split(new char[] {'/'}, StringSplitOptions.RemoveEmptyEntries);
if (parms.Length > 1)
{
if (string.Compare(parms[1], "library", true) == 0)
{
MemoryStream ms = new MemoryStream();
saveInventoryToStream(_inventory, ms);
result = ms.GetBuffer();
Array.Resize<byte>(ref result, (int) ms.Length);
}
else if (string.Compare(parms[1], "user", true) == 0)
{
if (parms.Length > 2)
{
result = GetUserInventory(new LLUUID(parms[2]));
}
}
}
return result;
}
}
}
}
/*
* Copyright (c) Contributors, http://opensimulator.org/
* See CONTRIBUTORS.TXT for a full list of copyright holders.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the OpenSim Project nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
using System;
using System.IO;
using System.Reflection;
using System.Text;
using System.Xml;
using System.Xml.Serialization;
using libsecondlife;
using OpenSim.Framework;
using OpenSim.Framework.Console;
using OpenSim.Framework.Servers;
namespace OpenSim.Grid.InventoryServer
{
public class InventoryManager
{
private static readonly log4net.ILog m_log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
private IInventoryData _databasePlugin;
/// <summary>
/// Adds a new inventory server plugin - user servers will be requested in the order they were loaded.
/// </summary>
/// <param name="FileName">The filename to the inventory server plugin DLL</param>
public void AddDatabasePlugin(string FileName)
{
m_log.Info("[" + OpenInventory_Main.LogName + "]: Invenstorage: Attempting to load " + FileName);
Assembly pluginAssembly = Assembly.LoadFrom(FileName);
m_log.Info("[" + OpenInventory_Main.LogName + "]: " +
"Invenstorage: Found " + pluginAssembly.GetTypes().Length + " interfaces.");
foreach (Type pluginType in pluginAssembly.GetTypes())
{
if (!pluginType.IsAbstract)
{
Type typeInterface = pluginType.GetInterface("IInventoryData", true);
if (typeInterface != null)
{
IInventoryData plug =
(IInventoryData) Activator.CreateInstance(pluginAssembly.GetType(pluginType.ToString()));
plug.Initialise();
_databasePlugin = plug;
m_log.Info("[" + OpenInventory_Main.LogName + "]: " +
"Invenstorage: Added IInventoryData Interface");
break;
}
typeInterface = null;
}
}
pluginAssembly = null;
}
protected static SerializableInventory loadInventoryFromXmlFile(string fileName)
{
FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read);
XmlReader reader = new XmlTextReader(fs);
XmlSerializer x = new XmlSerializer(typeof (SerializableInventory));
SerializableInventory inventory = (SerializableInventory) x.Deserialize(reader);
fs.Close();
fs.Dispose();
return inventory;
}
protected static void saveInventoryToStream(SerializableInventory inventory, Stream s)
{
XmlTextWriter writer = new XmlTextWriter(s, Encoding.UTF8);
writer.Formatting = Formatting.Indented;
XmlSerializer x = new XmlSerializer(typeof (SerializableInventory));
x.Serialize(writer, inventory);
}
protected static bool fixupFolder(SerializableInventory.SerializableFolder f,
SerializableInventory.SerializableFolder parent)
{
bool modified = false;
// ensure we have a valid folder id
if (f.folderID == LLUUID.Zero)
{
f.folderID = LLUUID.Random();
modified = true;
}
// ensure we have valid agent id
if (f.agentID == LLUUID.Zero)
{
if (parent != null)
f.agentID = parent.agentID;
else
f.agentID = f.folderID;
modified = true;
}
if (f.parentID == LLUUID.Zero && parent != null)
{
f.parentID = parent.folderID;
modified = true;
}
foreach (SerializableInventory.SerializableFolder child in f.SubFolders)
{
modified |= fixupFolder(child, f);
}
return modified;
}
protected static bool fixupInventory(SerializableInventory inventory)
{
return fixupFolder(inventory.root, null);
}
public class GetInventory : BaseStreamHandler
{
private SerializableInventory _inventory;
private InventoryManager _manager;
public GetInventory(InventoryManager manager)
: base("GET", "/inventory")
{
_manager = manager;
_inventory = loadInventoryFromXmlFile("attic/inventory/Inventory_Library.xml");
if (fixupInventory(_inventory))
{
FileStream fs = new FileStream("attic/inventory/Inventory_Library.xml", FileMode.Truncate, FileAccess.Write);
saveInventoryToStream(_inventory, fs);
fs.Flush();
fs.Close();
m_log.Debug("[" + OpenInventory_Main.LogName + "]: Modified");
}
}
private void CreateDefaultInventory(LLUUID userID)
{
}
private byte[] GetUserInventory(LLUUID userID)
{
m_log.InfoFormat("[" + OpenInventory_Main.LogName + "]: Getting Inventory for user {0}", userID.ToString());
byte[] result = new byte[] {};
InventoryFolderBase fb = _manager._databasePlugin.getUserRootFolder(userID);
if (fb == null)
{
m_log.InfoFormat("[" + OpenInventory_Main.LogName + "]: Inventory not found for user {0}, creating new",
userID.ToString());
CreateDefaultInventory(userID);
}
return result;
}
public override byte[] Handle(string path, Stream request)
{
byte[] result = new byte[] {};
string[] parms = path.Split(new char[] {'/'}, StringSplitOptions.RemoveEmptyEntries);
if (parms.Length > 1)
{
if (string.Compare(parms[1], "library", true) == 0)
{
MemoryStream ms = new MemoryStream();
saveInventoryToStream(_inventory, ms);
result = ms.GetBuffer();
Array.Resize<byte>(ref result, (int) ms.Length);
}
else if (string.Compare(parms[1], "user", true) == 0)
{
if (parms.Length > 2)
{
result = GetUserInventory(new LLUUID(parms[2]));
}
}
}
return result;
}
}
}
}

View File

@ -1,134 +1,135 @@
/*
* Copyright (c) Contributors, http://opensimulator.org/
* See CONTRIBUTORS.TXT for a full list of copyright holders.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the OpenSim Project nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
using System;
using System.Collections.Generic;
using System.IO;
using libsecondlife;
using OpenSim.Framework;
using OpenSim.Framework.Console;
using OpenSim.Framework.Servers;
namespace OpenSim.Grid.InventoryServer
{
public class OpenInventory_Main : conscmd_callback
{
private LogBase m_console;
private InventoryManager m_inventoryManager;
private InventoryConfig m_config;
private GridInventoryService m_inventoryService;
public const string LogName = "INVENTORY";
[STAThread]
public static void Main(string[] args)
{
OpenInventory_Main theServer = new OpenInventory_Main();
theServer.Startup();
theServer.Work();
}
public OpenInventory_Main()
{
m_console = new LogBase("opengrid-inventory-console.log", LogName, this, true);
MainLog.Instance = m_console;
}
public void Startup()
{
MainLog.Instance.Notice("Initialising inventory manager...");
m_config = new InventoryConfig(LogName, (Path.Combine(Util.configDir(), "InventoryServer_Config.xml")));
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<Guid, InventoryCollection>("POST", "/GetInventory/",
m_inventoryService.GetUserInventory));
httpServer.AddStreamHandler(
new RestDeserialisehandler<Guid, bool>("POST", "/CreateInventory/",
m_inventoryService.CreateUsersInventory));
httpServer.AddStreamHandler(
new RestDeserialisehandler<InventoryFolderBase, bool>("POST", "/NewFolder/",
m_inventoryService.AddInventoryFolder));
httpServer.AddStreamHandler(
new RestDeserialisehandler<InventoryFolderBase, bool>("POST", "/MoveFolder/",
m_inventoryService.MoveInventoryFolder));
httpServer.AddStreamHandler(
new RestDeserialisehandler<InventoryItemBase, bool>("POST", "/NewItem/",
m_inventoryService.AddInventoryItem));
httpServer.AddStreamHandler(
new RestDeserialisehandler<InventoryItemBase, bool>("POST", "/DeleteItem/",
m_inventoryService.DeleteInvItem));
httpServer.AddStreamHandler(
new RestDeserialisehandler<Guid, List<InventoryFolderBase>>("POST", "/RootFolders/",
m_inventoryService.RequestFirstLevelFolders));
// httpServer.AddStreamHandler(new InventoryManager.GetInventory(m_inventoryManager));
httpServer.Start();
MainLog.Instance.Notice(LogName, "Started HTTP server");
}
private void Work()
{
m_console.Notice("Enter help for a list of commands\n");
while (true)
{
m_console.MainLogPrompt();
}
}
public void RunCmd(string cmd, string[] cmdparams)
{
switch (cmd)
{
case "quit":
case "add-user":
m_inventoryService.CreateUsersInventory(LLUUID.Random().UUID);
break;
case "shutdown":
m_console.Close();
Environment.Exit(0);
break;
}
}
public void Show(string ShowWhat)
{
}
}
}
/*
* Copyright (c) Contributors, http://opensimulator.org/
* See CONTRIBUTORS.TXT for a full list of copyright holders.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the OpenSim Project nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
using System;
using System.Collections.Generic;
using System.IO;
using libsecondlife;
using OpenSim.Framework;
using OpenSim.Framework.Console;
using OpenSim.Framework.Servers;
namespace OpenSim.Grid.InventoryServer
{
public class OpenInventory_Main : BaseOpenSimServer, conscmd_callback
{
private static readonly log4net.ILog m_log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
private InventoryManager m_inventoryManager;
private InventoryConfig m_config;
private GridInventoryService m_inventoryService;
public const string LogName = "INVENTORY";
[STAThread]
public static void Main(string[] args)
{
log4net.Config.XmlConfigurator.Configure();
OpenInventory_Main theServer = new OpenInventory_Main();
theServer.Startup();
theServer.Work();
}
public OpenInventory_Main()
{
m_console = new ConsoleBase(LogName, this);
MainConsole.Instance = m_console;
}
public void Startup()
{
m_log.Info("Initialising inventory manager...");
m_config = new InventoryConfig(LogName, (Path.Combine(Util.configDir(), "InventoryServer_Config.xml")));
m_inventoryService = new GridInventoryService();
// m_inventoryManager = new InventoryManager();
m_inventoryService.AddPlugin(m_config.DatabaseProvider);
m_log.Info("[" + LogName + "]: Starting HTTP server ...");
BaseHttpServer httpServer = new BaseHttpServer(m_config.HttpPort);
httpServer.AddStreamHandler(
new RestDeserialisehandler<Guid, InventoryCollection>("POST", "/GetInventory/",
m_inventoryService.GetUserInventory));
httpServer.AddStreamHandler(
new RestDeserialisehandler<Guid, bool>("POST", "/CreateInventory/",
m_inventoryService.CreateUsersInventory));
httpServer.AddStreamHandler(
new RestDeserialisehandler<InventoryFolderBase, bool>("POST", "/NewFolder/",
m_inventoryService.AddInventoryFolder));
httpServer.AddStreamHandler(
new RestDeserialisehandler<InventoryFolderBase, bool>("POST", "/MoveFolder/",
m_inventoryService.MoveInventoryFolder));
httpServer.AddStreamHandler(
new RestDeserialisehandler<InventoryItemBase, bool>("POST", "/NewItem/",
m_inventoryService.AddInventoryItem));
httpServer.AddStreamHandler(
new RestDeserialisehandler<InventoryItemBase, bool>("POST", "/DeleteItem/",
m_inventoryService.DeleteInvItem));
httpServer.AddStreamHandler(
new RestDeserialisehandler<Guid, List<InventoryFolderBase>>("POST", "/RootFolders/",
m_inventoryService.RequestFirstLevelFolders));
// httpServer.AddStreamHandler(new InventoryManager.GetInventory(m_inventoryManager));
httpServer.Start();
m_log.Info("[" + LogName + "]: Started HTTP server");
}
private void Work()
{
m_console.Notice("Enter help for a list of commands\n");
while (true)
{
m_console.Prompt();
}
}
public override void RunCmd(string cmd, string[] cmdparams)
{
base.RunCmd(cmd, cmdparams);
switch (cmd)
{
case "quit":
case "add-user":
m_inventoryService.CreateUsersInventory(LLUUID.Random().UUID);
break;
case "shutdown":
m_console.Close();
Environment.Exit(0);
break;
}
}
}
}