* Provide relief for mantis 1263, 1202, 679

* If a caller attempts to set PrimitiveBaseShape.ProfileCurve with a HollowShape or ProfileShape component which is not a valid enum, a warning is spat out and a default shape 
subtituted
* This does not solve any underlying problem if we're missing some enum values (though it's not obvious what these are), but it should allow save-xml2/load-xml2 to be used 
without causing invalid enum value related exceptions.  The checks will also guard against badly behaved clients.
* This change alters the order of shape values in the xml, since it appears properties are serialized after fields (at least this is the case in mono).  .net native 
deserialization can cope with this it appears, though people manipulating xml manually may need to adapt (if there are any).
* This may be a good argument against relying on .net [de]serialization for our xml format.
0.6.0-stable
Justin Clarke Casey 2008-05-21 22:17:28 +00:00
parent c8857daf52
commit 42ac35ba7d
1 changed files with 49 additions and 23 deletions

View File

@ -26,8 +26,10 @@
*/ */
using System; using System;
using System.Reflection;
using System.Xml.Serialization; using System.Xml.Serialization;
using libsecondlife; using libsecondlife;
using log4net;
namespace OpenSim.Framework namespace OpenSim.Framework
{ {
@ -70,6 +72,8 @@ namespace OpenSim.Framework
[Serializable] [Serializable]
public class PrimitiveBaseShape public class PrimitiveBaseShape
{ {
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
private static readonly LLObject.TextureEntry m_defaultTexture; private static readonly LLObject.TextureEntry m_defaultTexture;
private byte[] m_textureEntry; private byte[] m_textureEntry;
@ -91,12 +95,51 @@ namespace OpenSim.Framework
public byte PCode; public byte PCode;
public ushort ProfileBegin; public ushort ProfileBegin;
public byte ProfileCurve; public byte ProfileCurve
{
get { return (byte)((byte)HollowShape | (byte)ProfileShape); }
set
{
// Handle hollow shape component
byte hollowShapeByte = (byte)(value & 0xf0);
if (!Enum.IsDefined(typeof(HollowShape), hollowShapeByte))
{
m_log.WarnFormat(
"[SHAPE]: Attempt to set a ProfileCurve with a hollow shape value of {0}, which isn't a valid enum. Replacing with default shape.",
hollowShapeByte);
this.HollowShape = HollowShape.Same;
}
else
{
this.HollowShape = (HollowShape)hollowShapeByte;
}
// Handle profile shape component
byte profileShapeByte = (byte)(value & 0xf);
if (!Enum.IsDefined(typeof(ProfileShape), profileShapeByte))
{
m_log.WarnFormat(
"[SHAPE]: Attempt to set a ProfileCurve with a profile shape value of {0}, which isn't a valid enum. Replacing with square.",
profileShapeByte);
this.ProfileShape = ProfileShape.Square;
}
else
{
this.ProfileShape = (ProfileShape)profileShapeByte;
}
}
}
public ushort ProfileEnd; public ushort ProfileEnd;
public ushort ProfileHollow; public ushort ProfileHollow;
public LLVector3 Scale; public LLVector3 Scale;
public byte State; public byte State;
// Sculpted // Sculpted
[XmlIgnore] public LLUUID SculptTexture = LLUUID.Zero; [XmlIgnore] public LLUUID SculptTexture = LLUUID.Zero;
[XmlIgnore] public byte SculptType = (byte)0; [XmlIgnore] public byte SculptType = (byte)0;
@ -154,25 +197,9 @@ namespace OpenSim.Framework
set { m_textureEntry = value; } set { m_textureEntry = value; }
} }
public ProfileShape ProfileShape public ProfileShape ProfileShape;
{
get { return (ProfileShape) (ProfileCurve & 0xf); }
set
{
byte oldValueMasked = (byte) (ProfileCurve & 0xf0);
ProfileCurve = (byte) (oldValueMasked | (byte) value);
}
}
public HollowShape HollowShape public HollowShape HollowShape;
{
get { return (HollowShape) (ProfileCurve & 0xf0); }
set
{
byte oldValueMasked = (byte) (ProfileCurve & 0x0f);
ProfileCurve = (byte) (oldValueMasked | (byte) value);
}
}
public static PrimitiveBaseShape Default public static PrimitiveBaseShape Default
{ {
@ -186,7 +213,6 @@ namespace OpenSim.Framework
} }
} }
public static PrimitiveBaseShape Create() public static PrimitiveBaseShape Create()
{ {
PrimitiveBaseShape shape = new PrimitiveBaseShape(); PrimitiveBaseShape shape = new PrimitiveBaseShape();