Merge branch 'master-core' into mantis5110

This commit is contained in:
Jonathan Freedman
2010-12-05 11:49:15 -08:00
79 changed files with 2421 additions and 1169 deletions

View File

@@ -302,31 +302,26 @@ namespace OpenSim.Framework
if (args["start_pos"] != null)
Vector3.TryParse(args["start_pos"].AsString(), out startpos);
// DEBUG ON
m_log.WarnFormat("[AGENTCIRCUITDATA] agentid={0}, child={1}, startpos={2}",AgentID,child,startpos.ToString());
// DEBUG OFF
m_log.InfoFormat("[AGENTCIRCUITDATA] agentid={0}, child={1}, startpos={2}",AgentID,child,startpos.ToString());
try {
// Unpack various appearance elements
Appearance = new AvatarAppearance(AgentID);
// Unpack various appearance elements
Appearance = new AvatarAppearance(AgentID);
// Eventually this code should be deprecated, use full appearance
// packing in packed_appearance
if (args["appearance_serial"] != null)
Appearance.Serial = args["appearance_serial"].AsInteger();
// Eventually this code should be deprecated, use full appearance
// packing in packed_appearance
if (args["appearance_serial"] != null)
Appearance.Serial = args["appearance_serial"].AsInteger();
if (args.ContainsKey("packed_appearance") && (args["packed_appearance"].Type == OSDType.Map))
{
Appearance.Unpack((OSDMap)args["packed_appearance"]);
// DEBUG ON
m_log.WarnFormat("[AGENTCIRCUITDATA] unpacked appearance");
// DEBUG OFF
if (args.ContainsKey("packed_appearance") && (args["packed_appearance"].Type == OSDType.Map))
{
Appearance.Unpack((OSDMap)args["packed_appearance"]);
m_log.InfoFormat("[AGENTCIRCUITDATA] unpacked appearance");
}
else
m_log.Warn("[AGENTCIRCUITDATA] failed to find a valid packed_appearance");
}
// DEBUG ON
else
m_log.Warn("[AGENTCIRCUITDATA] failed to find a valid packed_appearance");
// DEBUG OFF
} catch (Exception e)
catch (Exception e)
{
m_log.ErrorFormat("[AGENTCIRCUITDATA] failed to unpack appearance; {0}",e.Message);
}

View File

@@ -51,8 +51,16 @@ namespace OpenSim.Framework
string[] parts = temp.Split('\n');
int.TryParse(parts[0].Substring(17, 1), out Version);
UUID.TryParse(parts[1].Substring(10, 36), out RegionID);
// the vector is stored with spaces as separators, not with commas ("10.3 32.5 43" instead of "10.3, 32.5, 43")
Vector3.TryParse(parts[2].Substring(10, parts[2].Length - 10).Replace(" ", ","), out Position);
// The position is a vector with spaces as separators ("10.3 32.5 43").
// Parse each scalar separately to take into account the system's culture setting.
string[] scalars = parts[2].Substring(10, parts[2].Length - 10).Split(' ');
if (scalars.Length > 0)
System.Single.TryParse(scalars[0], out Position.X);
if (scalars.Length > 1)
System.Single.TryParse(scalars[1], out Position.Y);
if (scalars.Length > 2)
System.Single.TryParse(scalars[2], out Position.Z);
ulong.TryParse(parts[3].Substring(14, parts[3].Length - 14), out RegionHandle);
}
}

View File

@@ -48,7 +48,7 @@ namespace OpenSim.Framework
public readonly static byte[] BAKE_INDICES = new byte[] { 8, 9, 10, 11, 19, 20 };
protected UUID m_owner;
protected int m_serial = 1;
protected int m_serial = 0;
protected byte[] m_visualparams;
protected Primitive.TextureEntry m_texture;
protected AvatarWearable[] m_wearables;
@@ -103,7 +103,7 @@ namespace OpenSim.Framework
{
// m_log.WarnFormat("[AVATAR APPEARANCE]: create empty appearance for {0}",owner);
m_serial = 1;
m_serial = 0;
m_owner = owner;
SetDefaultWearables();
@@ -127,7 +127,7 @@ namespace OpenSim.Framework
{
// m_log.WarnFormat("[AVATAR APPEARANCE] create initialized appearance for {0}",avatarID);
m_serial = 1;
m_serial = 0;
m_owner = avatarID;
if (wearables != null)
@@ -160,7 +160,7 @@ namespace OpenSim.Framework
if (appearance == null)
{
m_serial = 1;
m_serial = 0;
m_owner = UUID.Zero;
SetDefaultWearables();
@@ -229,6 +229,24 @@ namespace OpenSim.Framework
m_wearables = AvatarWearable.DefaultWearables;
}
/// <summary>
/// Invalidate all of the baked textures in the appearance, useful
/// if you know that none are valid
/// </summary>
public virtual void ResetAppearance()
{
m_serial = 0;
SetDefaultParams();
SetDefaultTexture();
//for (int i = 0; i < BAKE_INDICES.Length; i++)
// {
// int idx = BAKE_INDICES[i];
// m_texture.FaceTextures[idx].TextureID = UUID.Zero;
// }
}
protected virtual void SetDefaultParams()
{
m_visualparams = new byte[] { 33,61,85,23,58,127,63,85,63,42,0,85,63,36,85,95,153,63,34,0,63,109,88,132,63,136,81,85,103,136,127,0,150,150,150,127,0,0,0,0,0,127,0,0,255,127,114,127,99,63,127,140,127,127,0,0,0,191,0,104,0,0,0,0,0,0,0,0,0,145,216,133,0,127,0,127,170,0,0,127,127,109,85,127,127,63,85,42,150,150,150,150,150,150,150,25,150,150,150,0,127,0,0,144,85,127,132,127,85,0,127,127,127,127,127,127,59,127,85,127,127,106,47,79,127,127,204,2,141,66,0,0,127,127,0,0,0,0,127,0,159,0,0,178,127,36,85,131,127,127,127,153,95,0,140,75,27,127,127,0,150,150,198,0,0,63,30,127,165,209,198,127,127,153,204,51,51,255,255,255,204,0,255,150,150,150,150,150,150,150,150,150,150,0,150,150,150,150,150,0,127,127,150,150,150,150,150,150,150,150,0,0,150,51,132,150,150,150 };
@@ -240,9 +258,10 @@ namespace OpenSim.Framework
protected virtual void SetDefaultTexture()
{
m_texture = new Primitive.TextureEntry(new UUID("C228D1CF-4B5D-4BA8-84F4-899A0796AA97"));
for (uint i = 0; i < TEXTURE_COUNT; i++)
m_texture.CreateFace(i).TextureID = new UUID(AppearanceManager.DEFAULT_AVATAR_TEXTURE);
m_texture = new Primitive.TextureEntry(new UUID(AppearanceManager.DEFAULT_AVATAR_TEXTURE));
// for (uint i = 0; i < TEXTURE_COUNT; i++)
// m_texture.CreateFace(i).TextureID = new UUID(AppearanceManager.DEFAULT_AVATAR_TEXTURE);
}
/// <summary>
@@ -274,9 +293,6 @@ namespace OpenSim.Framework
}
changed = true;
// if (newface != null)
// m_log.WarnFormat("[AVATAR APPEARANCE]: index {0}, new texture id {1}",i,newface.TextureID);
}
m_texture = textureEntry;

View File

@@ -990,6 +990,7 @@ namespace OpenSim.Framework.Capabilities
public void BakedTextureUploaded(UUID assetID, byte[] data)
{
// m_log.WarnFormat("[CAPS]: Received baked texture {0}", assetID.ToString());
AssetBase asset;
asset = new AssetBase(assetID, "Baked Texture", (sbyte)AssetType.Texture, m_agentID.ToString());
asset.Data = data;
@@ -1331,6 +1332,7 @@ namespace OpenSim.Framework.Capabilities
newAssetID = UUID.Random();
uploaderPath = path;
httpListener = httpServer;
m_log.InfoFormat("[CAPS] baked texture upload starting for {0}",newAssetID);
}
/// <summary>
@@ -1358,6 +1360,8 @@ namespace OpenSim.Framework.Capabilities
handlerUpLoad(newAssetID, data);
}
m_log.InfoFormat("[CAPS] baked texture upload completed for {0}",newAssetID);
return res;
}
}

View File

@@ -331,9 +331,7 @@ namespace OpenSim.Framework
public virtual OSDMap Pack()
{
// DEBUG ON
m_log.WarnFormat("[CHILDAGENTDATAUPDATE] Pack data");
// DEBUG OFF
m_log.InfoFormat("[CHILDAGENTDATAUPDATE] Pack data");
OSDMap args = new OSDMap();
args["message_type"] = OSD.FromString("AgentData");
@@ -454,9 +452,7 @@ namespace OpenSim.Framework
/// <param name="hash"></param>
public virtual void Unpack(OSDMap args)
{
// DEBUG ON
m_log.WarnFormat("[CHILDAGENTDATAUPDATE] Unpack data");
// DEBUG OFF
m_log.InfoFormat("[CHILDAGENTDATAUPDATE] Unpack data");
if (args.ContainsKey("region_id"))
UUID.TryParse(args["region_id"].AsString(), out RegionID);
@@ -613,10 +609,8 @@ namespace OpenSim.Framework
if (args.ContainsKey("packed_appearance") && (args["packed_appearance"]).Type == OSDType.Map)
Appearance = new AvatarAppearance(AgentID,(OSDMap)args["packed_appearance"]);
// DEBUG ON
else
m_log.WarnFormat("[CHILDAGENTDATAUPDATE] No packed appearance");
// DEBUG OFF
if ((args["controllers"] != null) && (args["controllers"]).Type == OSDType.Array)
{

View File

@@ -1,104 +0,0 @@
/*
* 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 OpenSimulator 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.Collections.Generic;
using OpenSim.Data;
using OpenMetaverse;
using OpenSim.Services.Interfaces;
namespace OpenSim.Framework.Communications.Osp
{
/// <summary>
/// Wrap other inventory data plugins so that we can perform OSP related post processing for items
/// </summary>
public class OspInventoryWrapperPlugin : IInventoryDataPlugin
{
protected IInventoryDataPlugin m_wrappedPlugin;
//protected CommunicationsManager m_commsManager;
protected IUserAccountService m_userAccountService;
public OspInventoryWrapperPlugin(IInventoryDataPlugin wrappedPlugin, IUserAccountService userService)
{
m_wrappedPlugin = wrappedPlugin;
m_userAccountService = userService;
}
public string Name { get { return "OspInventoryWrapperPlugin"; } }
public string Version { get { return "0.1"; } }
public void Initialise() {}
public void Initialise(string connect) {}
public void Dispose() {}
public InventoryItemBase getInventoryItem(UUID item)
{
return PostProcessItem(m_wrappedPlugin.getInventoryItem(item));
}
// XXX: Why on earth does this exist as it appears to duplicate getInventoryItem?
public InventoryItemBase queryInventoryItem(UUID item)
{
return PostProcessItem(m_wrappedPlugin.queryInventoryItem(item));
}
public List<InventoryItemBase> getInventoryInFolder(UUID folderID)
{
List<InventoryItemBase> items = m_wrappedPlugin.getInventoryInFolder(folderID);
foreach (InventoryItemBase item in items)
PostProcessItem(item);
return items;
}
public List<InventoryItemBase> fetchActiveGestures(UUID avatarID)
{
return m_wrappedPlugin.fetchActiveGestures(avatarID);
// Presuming that no post processing is needed here as gestures don't refer to creator information (?)
}
protected InventoryItemBase PostProcessItem(InventoryItemBase item)
{
item.CreatorIdAsUuid = OspResolver.ResolveOspa(item.CreatorId, m_userAccountService);
return item;
}
public List<InventoryFolderBase> getFolderHierarchy(UUID parentID) { return m_wrappedPlugin.getFolderHierarchy(parentID); }
public List<InventoryFolderBase> getUserRootFolders(UUID user) { return m_wrappedPlugin.getUserRootFolders(user); }
public InventoryFolderBase getUserRootFolder(UUID user) { return m_wrappedPlugin.getUserRootFolder(user); }
public List<InventoryFolderBase> getInventoryFolders(UUID parentID) { return m_wrappedPlugin.getInventoryFolders(parentID); }
public InventoryFolderBase getInventoryFolder(UUID folder) { return m_wrappedPlugin.getInventoryFolder(folder); }
public void addInventoryItem(InventoryItemBase item) { m_wrappedPlugin.addInventoryItem(item); }
public void updateInventoryItem(InventoryItemBase item) { m_wrappedPlugin.updateInventoryItem(item); }
public void deleteInventoryItem(UUID item) { m_wrappedPlugin.deleteInventoryItem(item); }
public InventoryFolderBase queryInventoryFolder(UUID folder) { return m_wrappedPlugin.queryInventoryFolder(folder); }
public void addInventoryFolder(InventoryFolderBase folder) { m_wrappedPlugin.addInventoryFolder(folder); }
public void updateInventoryFolder(InventoryFolderBase folder) { m_wrappedPlugin.updateInventoryFolder(folder); }
public void moveInventoryFolder(InventoryFolderBase folder) { m_wrappedPlugin.moveInventoryFolder(folder); }
public void deleteInventoryFolder(UUID folder) { m_wrappedPlugin.deleteInventoryFolder(folder); }
}
}

View File

@@ -73,7 +73,7 @@ namespace OpenSim.Framework
void AddNewClient(IClientAPI client);
void RemoveClient(UUID agentID);
void Restart(int seconds);
void Restart();
//RegionInfo OtherRegionUp(RegionInfo thisRegion);
string GetSimulatorVersion();

View File

@@ -0,0 +1,99 @@
/*
* 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 OpenSimulator 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 System.Xml;
using OpenMetaverse;
using OpenSim.Services.Interfaces;
namespace OpenSim.Framework.Serialization.External
{
/// <summary>
/// Utilities for manipulating external representations of data structures in OpenSim
/// </summary>
public class ExternalRepresentationUtils
{
/// <summary>
/// Takes a XML representation of a SceneObjectPart and returns another XML representation
/// with creator data added to it.
/// </summary>
/// <param name="xml">The SceneObjectPart represented in XML2</param>
/// <param name="profileURL">The URL of the profile service for the creator</param>
/// <param name="userService">The service for retrieving user account information</param>
/// <param name="scopeID">The scope of the user account information (Grid ID)</param>
/// <returns>The SceneObjectPart represented in XML2</returns>
public static string RewriteSOP(string xml, string profileURL, IUserAccountService userService, UUID scopeID)
{
if (xml == string.Empty || profileURL == string.Empty || userService == null)
return xml;
XmlDocument doc = new XmlDocument();
doc.LoadXml(xml);
XmlNodeList sops = doc.GetElementsByTagName("SceneObjectPart");
foreach (XmlNode sop in sops)
{
UserAccount creator = null;
bool hasCreatorData = false;
XmlNodeList nodes = sop.ChildNodes;
foreach (XmlNode node in nodes)
{
if (node.Name == "CreatorID")
{
UUID uuid = UUID.Zero;
UUID.TryParse(node.InnerText, out uuid);
creator = userService.GetUserAccount(scopeID, uuid);
}
if (node.Name == "CreatorData" && node.InnerText != null && node.InnerText != string.Empty)
hasCreatorData = true;
//if (node.Name == "OwnerID")
//{
// UserAccount owner = GetUser(node.InnerText);
// if (owner != null)
// node.InnerText = m_ProfileServiceURL + "/" + node.InnerText + "/" + owner.FirstName + " " + owner.LastName;
//}
}
if (!hasCreatorData && creator != null)
{
XmlElement creatorData = doc.CreateElement("CreatorData");
creatorData.InnerText = profileURL + "/" + creator.PrincipalID + ";" + creator.FirstName + " " + creator.LastName;
sop.AppendChild(creatorData);
}
}
using (StringWriter wr = new StringWriter())
{
doc.Save(wr);
return wr.ToString();
}
}
}
}

View File

@@ -32,7 +32,7 @@ using OpenMetaverse;
using OpenSim.Framework;
using OpenSim.Services.Interfaces;
namespace OpenSim.Framework.Communications.Osp
namespace OpenSim.Framework.Serialization
{
/// <summary>
/// Resolves OpenSim Profile Anchors (OSPA). An OSPA is a string used to provide information for
@@ -57,6 +57,12 @@ namespace OpenSim.Framework.Communications.Osp
/// <returns>The OSPA. Null if a user with the given UUID could not be found.</returns>
public static string MakeOspa(UUID userId, IUserAccountService userService)
{
if (userService == null)
{
m_log.Warn("[OSP RESOLVER]: UserService is null");
return userId.ToString();
}
UserAccount account = userService.GetUserAccount(UUID.Zero, userId);
if (account != null)
return MakeOspa(account.FirstName, account.LastName);

View File

@@ -26,11 +26,16 @@
*/
using System;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using System.Text;
using System.Xml;
using log4net;
using OpenMetaverse;
using OpenSim.Framework;
using OpenSim.Services.Interfaces;
namespace OpenSim.Framework.Serialization.External
{
@@ -40,6 +45,141 @@ namespace OpenSim.Framework.Serialization.External
/// XXX: Please do not use yet.
public class UserInventoryItemSerializer
{
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
private delegate void InventoryItemXmlProcessor(InventoryItemBase item, XmlTextReader reader);
private static Dictionary<string, InventoryItemXmlProcessor> m_InventoryItemXmlProcessors = new Dictionary<string, InventoryItemXmlProcessor>();
#region InventoryItemBase Processor initialization
static UserInventoryItemSerializer()
{
m_InventoryItemXmlProcessors.Add("Name", ProcessName);
m_InventoryItemXmlProcessors.Add("ID", ProcessID);
m_InventoryItemXmlProcessors.Add("InvType", ProcessInvType);
m_InventoryItemXmlProcessors.Add("CreatorUUID", ProcessCreatorUUID);
m_InventoryItemXmlProcessors.Add("CreatorID", ProcessCreatorID);
m_InventoryItemXmlProcessors.Add("CreatorData", ProcessCreatorData);
m_InventoryItemXmlProcessors.Add("CreationDate", ProcessCreationDate);
m_InventoryItemXmlProcessors.Add("Owner", ProcessOwner);
m_InventoryItemXmlProcessors.Add("Description", ProcessDescription);
m_InventoryItemXmlProcessors.Add("AssetType", ProcessAssetType);
m_InventoryItemXmlProcessors.Add("AssetID", ProcessAssetID);
m_InventoryItemXmlProcessors.Add("SaleType", ProcessSaleType);
m_InventoryItemXmlProcessors.Add("SalePrice", ProcessSalePrice);
m_InventoryItemXmlProcessors.Add("BasePermissions", ProcessBasePermissions);
m_InventoryItemXmlProcessors.Add("CurrentPermissions", ProcessCurrentPermissions);
m_InventoryItemXmlProcessors.Add("EveryOnePermissions", ProcessEveryOnePermissions);
m_InventoryItemXmlProcessors.Add("NextPermissions", ProcessNextPermissions);
m_InventoryItemXmlProcessors.Add("Flags", ProcessFlags);
m_InventoryItemXmlProcessors.Add("GroupID", ProcessGroupID);
m_InventoryItemXmlProcessors.Add("GroupOwned", ProcessGroupOwned);
}
#endregion
#region InventoryItemBase Processors
private static void ProcessName(InventoryItemBase item, XmlTextReader reader)
{
item.Name = reader.ReadElementContentAsString("Name", String.Empty);
}
private static void ProcessID(InventoryItemBase item, XmlTextReader reader)
{
item.ID = Util.ReadUUID(reader, "ID");
}
private static void ProcessInvType(InventoryItemBase item, XmlTextReader reader)
{
item.InvType = reader.ReadElementContentAsInt("InvType", String.Empty);
}
private static void ProcessCreatorUUID(InventoryItemBase item, XmlTextReader reader)
{
item.CreatorId = reader.ReadElementContentAsString("CreatorUUID", String.Empty);
}
private static void ProcessCreatorID(InventoryItemBase item, XmlTextReader reader)
{
// when it exists, this overrides the previous
item.CreatorId = reader.ReadElementContentAsString("CreatorID", String.Empty);
}
private static void ProcessCreationDate(InventoryItemBase item, XmlTextReader reader)
{
item.CreationDate = reader.ReadElementContentAsInt("CreationDate", String.Empty);
}
private static void ProcessOwner(InventoryItemBase item, XmlTextReader reader)
{
item.Owner = Util.ReadUUID(reader, "Owner");
}
private static void ProcessDescription(InventoryItemBase item, XmlTextReader reader)
{
item.Description = reader.ReadElementContentAsString("Description", String.Empty);
}
private static void ProcessAssetType(InventoryItemBase item, XmlTextReader reader)
{
item.AssetType = reader.ReadElementContentAsInt("AssetType", String.Empty);
}
private static void ProcessAssetID(InventoryItemBase item, XmlTextReader reader)
{
item.AssetID = Util.ReadUUID(reader, "AssetID");
}
private static void ProcessSaleType(InventoryItemBase item, XmlTextReader reader)
{
item.SaleType = (byte)reader.ReadElementContentAsInt("SaleType", String.Empty);
}
private static void ProcessSalePrice(InventoryItemBase item, XmlTextReader reader)
{
item.SalePrice = reader.ReadElementContentAsInt("SalePrice", String.Empty);
}
private static void ProcessBasePermissions(InventoryItemBase item, XmlTextReader reader)
{
item.BasePermissions = (uint)reader.ReadElementContentAsInt("BasePermissions", String.Empty);
}
private static void ProcessCurrentPermissions(InventoryItemBase item, XmlTextReader reader)
{
item.CurrentPermissions = (uint)reader.ReadElementContentAsInt("CurrentPermissions", String.Empty);
}
private static void ProcessEveryOnePermissions(InventoryItemBase item, XmlTextReader reader)
{
item.EveryOnePermissions = (uint)reader.ReadElementContentAsInt("EveryOnePermissions", String.Empty);
}
private static void ProcessNextPermissions(InventoryItemBase item, XmlTextReader reader)
{
item.NextPermissions = (uint)reader.ReadElementContentAsInt("NextPermissions", String.Empty);
}
private static void ProcessFlags(InventoryItemBase item, XmlTextReader reader)
{
item.Flags = (uint)reader.ReadElementContentAsInt("Flags", String.Empty);
}
private static void ProcessGroupID(InventoryItemBase item, XmlTextReader reader)
{
item.GroupID = Util.ReadUUID(reader, "GroupID");
}
private static void ProcessGroupOwned(InventoryItemBase item, XmlTextReader reader)
{
item.GroupOwned = Util.ReadBoolean(reader);
}
private static void ProcessCreatorData(InventoryItemBase item, XmlTextReader reader)
{
item.CreatorData = reader.ReadElementContentAsString("CreatorData", String.Empty);
}
#endregion
/// <summary>
/// Deserialize item
/// </summary>
@@ -60,40 +200,47 @@ namespace OpenSim.Framework.Serialization.External
public static InventoryItemBase Deserialize(string serialization)
{
InventoryItemBase item = new InventoryItemBase();
StringReader sr = new StringReader(serialization);
XmlTextReader xtr = new XmlTextReader(sr);
xtr.ReadStartElement("InventoryItem");
item.Name = xtr.ReadElementString("Name");
item.ID = UUID.Parse( xtr.ReadElementString("ID"));
item.InvType = Convert.ToInt32( xtr.ReadElementString("InvType"));
item.CreatorId = xtr.ReadElementString("CreatorUUID");
item.CreationDate = Convert.ToInt32( xtr.ReadElementString("CreationDate"));
item.Owner = UUID.Parse( xtr.ReadElementString("Owner"));
item.Description = xtr.ReadElementString("Description");
item.AssetType = Convert.ToInt32( xtr.ReadElementString("AssetType"));
item.AssetID = UUID.Parse( xtr.ReadElementString("AssetID"));
item.SaleType = Convert.ToByte( xtr.ReadElementString("SaleType"));
item.SalePrice = Convert.ToInt32( xtr.ReadElementString("SalePrice"));
item.BasePermissions = Convert.ToUInt32( xtr.ReadElementString("BasePermissions"));
item.CurrentPermissions = Convert.ToUInt32( xtr.ReadElementString("CurrentPermissions"));
item.EveryOnePermissions = Convert.ToUInt32( xtr.ReadElementString("EveryOnePermissions"));
item.NextPermissions = Convert.ToUInt32( xtr.ReadElementString("NextPermissions"));
item.Flags = Convert.ToUInt32( xtr.ReadElementString("Flags"));
item.GroupID = UUID.Parse( xtr.ReadElementString("GroupID"));
item.GroupOwned = Convert.ToBoolean(xtr.ReadElementString("GroupOwned"));
xtr.ReadEndElement();
xtr.Close();
sr.Close();
using (XmlTextReader reader = new XmlTextReader(new StringReader(serialization)))
{
reader.ReadStartElement("InventoryItem");
string nodeName = string.Empty;
while (reader.NodeType != XmlNodeType.EndElement)
{
nodeName = reader.Name;
InventoryItemXmlProcessor p = null;
if (m_InventoryItemXmlProcessors.TryGetValue(reader.Name, out p))
{
//m_log.DebugFormat("[XXX] Processing: {0}", reader.Name);
try
{
p(item, reader);
}
catch (Exception e)
{
m_log.DebugFormat("[InventoryItemSerializer]: exception while parsing {0}: {1}", nodeName, e);
if (reader.NodeType == XmlNodeType.EndElement)
reader.Read();
}
}
else
{
// m_log.DebugFormat("[InventoryItemSerializer]: caught unknown element {0}", nodeName);
reader.ReadOuterXml(); // ignore
}
}
reader.ReadEndElement(); // InventoryItem
}
//m_log.DebugFormat("[XXX]: parsed InventoryItemBase {0} - {1}", obj.Name, obj.UUID);
return item;
}
public static string Serialize(InventoryItemBase inventoryItem)
public static string Serialize(InventoryItemBase inventoryItem, Dictionary<string, object> options, IUserAccountService userAccountService)
{
StringWriter sw = new StringWriter();
XmlTextWriter writer = new XmlTextWriter(sw);
@@ -112,7 +259,7 @@ namespace OpenSim.Framework.Serialization.External
writer.WriteString(inventoryItem.InvType.ToString());
writer.WriteEndElement();
writer.WriteStartElement("CreatorUUID");
writer.WriteString(inventoryItem.CreatorId);
writer.WriteString(OspResolver.MakeOspa(inventoryItem.CreatorIdAsUuid, userAccountService));
writer.WriteEndElement();
writer.WriteStartElement("CreationDate");
writer.WriteString(inventoryItem.CreationDate.ToString());
@@ -156,6 +303,20 @@ namespace OpenSim.Framework.Serialization.External
writer.WriteStartElement("GroupOwned");
writer.WriteString(inventoryItem.GroupOwned.ToString());
writer.WriteEndElement();
if (inventoryItem.CreatorData != null && inventoryItem.CreatorData != string.Empty)
writer.WriteElementString("CreatorData", inventoryItem.CreatorData);
else if (options.ContainsKey("profile"))
{
if (userAccountService != null)
{
UserAccount account = userAccountService.GetUserAccount(UUID.Zero, inventoryItem.CreatorIdAsUuid);
if (account != null)
{
writer.WriteElementString("CreatorData", (string)options["profile"] + "/" + inventoryItem.CreatorIdAsUuid + ";" + account.FirstName + " " + account.LastName);
}
writer.WriteElementString("CreatorID", inventoryItem.CreatorId);
}
}
writer.WriteEndElement();

View File

@@ -1558,5 +1558,86 @@ namespace OpenSim.Framework
return string.Empty;
}
#region Xml Serialization Utilities
public static bool ReadBoolean(XmlTextReader reader)
{
reader.ReadStartElement();
bool result = Boolean.Parse(reader.ReadContentAsString().ToLower());
reader.ReadEndElement();
return result;
}
public static UUID ReadUUID(XmlTextReader reader, string name)
{
UUID id;
string idStr;
reader.ReadStartElement(name);
if (reader.Name == "Guid")
idStr = reader.ReadElementString("Guid");
else if (reader.Name == "UUID")
idStr = reader.ReadElementString("UUID");
else // no leading tag
idStr = reader.ReadContentAsString();
UUID.TryParse(idStr, out id);
reader.ReadEndElement();
return id;
}
public static Vector3 ReadVector(XmlTextReader reader, string name)
{
Vector3 vec;
reader.ReadStartElement(name);
vec.X = reader.ReadElementContentAsFloat(reader.Name, String.Empty); // X or x
vec.Y = reader.ReadElementContentAsFloat(reader.Name, String.Empty); // Y or y
vec.Z = reader.ReadElementContentAsFloat(reader.Name, String.Empty); // Z or z
reader.ReadEndElement();
return vec;
}
public static Quaternion ReadQuaternion(XmlTextReader reader, string name)
{
Quaternion quat = new Quaternion();
reader.ReadStartElement(name);
while (reader.NodeType != XmlNodeType.EndElement)
{
switch (reader.Name.ToLower())
{
case "x":
quat.X = reader.ReadElementContentAsFloat(reader.Name, String.Empty);
break;
case "y":
quat.Y = reader.ReadElementContentAsFloat(reader.Name, String.Empty);
break;
case "z":
quat.Z = reader.ReadElementContentAsFloat(reader.Name, String.Empty);
break;
case "w":
quat.W = reader.ReadElementContentAsFloat(reader.Name, String.Empty);
break;
}
}
reader.ReadEndElement();
return quat;
}
public static T ReadEnum<T>(XmlTextReader reader, string name)
{
string value = reader.ReadElementContentAsString(name, String.Empty);
// !!!!! to deal with flags without commas
if (value.Contains(" ") && !value.Contains(","))
value = value.Replace(" ", ", ");
return (T)Enum.Parse(typeof(T), value); ;
}
#endregion
}
}