* 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.Reflection;
using System.Xml.Serialization;
using libsecondlife;
using log4net;
namespace OpenSim.Framework
{
@ -70,6 +72,8 @@ namespace OpenSim.Framework
[Serializable]
public class PrimitiveBaseShape
{
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
private static readonly LLObject.TextureEntry m_defaultTexture;
private byte[] m_textureEntry;
@ -89,14 +93,53 @@ namespace OpenSim.Framework
public sbyte PathTwist;
public sbyte PathTwistBegin;
public byte PCode;
public ushort ProfileBegin;
public byte ProfileCurve;
public ushort ProfileBegin;
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 ProfileHollow;
public LLVector3 Scale;
public byte State;
// Sculpted
[XmlIgnore] public LLUUID SculptTexture = LLUUID.Zero;
[XmlIgnore] public byte SculptType = (byte)0;
@ -154,25 +197,9 @@ namespace OpenSim.Framework
set { m_textureEntry = value; }
}
public ProfileShape ProfileShape
{
get { return (ProfileShape) (ProfileCurve & 0xf); }
set
{
byte oldValueMasked = (byte) (ProfileCurve & 0xf0);
ProfileCurve = (byte) (oldValueMasked | (byte) value);
}
}
public HollowShape HollowShape
{
get { return (HollowShape) (ProfileCurve & 0xf0); }
set
{
byte oldValueMasked = (byte) (ProfileCurve & 0x0f);
ProfileCurve = (byte) (oldValueMasked | (byte) value);
}
}
public ProfileShape ProfileShape;
public HollowShape HollowShape;
public static PrimitiveBaseShape Default
{
@ -186,7 +213,6 @@ namespace OpenSim.Framework
}
}
public static PrimitiveBaseShape Create()
{
PrimitiveBaseShape shape = new PrimitiveBaseShape();