Merge branch 'master' of ssh://3dhosting.de/var/git/careminster
commit
95d533ce8a
|
@ -143,6 +143,8 @@ namespace OpenSim.Framework
|
|||
public string RemotingAddress;
|
||||
public UUID ScopeID = UUID.Zero;
|
||||
|
||||
private Dictionary<String, String> m_otherSettings = new Dictionary<string, string>();
|
||||
|
||||
|
||||
// Apparently, we're applying the same estatesettings regardless of whether it's local or remote.
|
||||
|
||||
|
@ -445,6 +447,18 @@ namespace OpenSim.Framework
|
|||
m_internalEndPoint = tmpEPE;
|
||||
}
|
||||
|
||||
public string GetOtherSetting(string key)
|
||||
{
|
||||
string val;
|
||||
m_otherSettings.TryGetValue(key, out val);
|
||||
return val;
|
||||
}
|
||||
|
||||
public void SetOtherSetting(string key, string value)
|
||||
{
|
||||
m_otherSettings[key] = value;
|
||||
}
|
||||
|
||||
private void ReadNiniConfig(IConfigSource source, string name)
|
||||
{
|
||||
// bool creatingNew = false;
|
||||
|
@ -473,30 +487,39 @@ namespace OpenSim.Framework
|
|||
if (source.Configs[name] == null)
|
||||
{
|
||||
source.AddConfig(name);
|
||||
|
||||
// creatingNew = true;
|
||||
}
|
||||
|
||||
RegionName = name;
|
||||
IConfig config = source.Configs[name];
|
||||
|
||||
// UUID
|
||||
//
|
||||
string regionUUID = config.GetString("RegionUUID", string.Empty);
|
||||
// Track all of the keys in this config and remove as they are processed
|
||||
// The remaining keys will be added to generic key-value storage for
|
||||
// whoever might need it
|
||||
HashSet<String> allKeys = new HashSet<String>();
|
||||
foreach (string s in config.GetKeys())
|
||||
{
|
||||
allKeys.Add(s.ToLower());
|
||||
}
|
||||
|
||||
// RegionUUID
|
||||
//
|
||||
allKeys.Remove(("RegionUUID").ToLower());
|
||||
string regionUUID = config.GetString("RegionUUID", string.Empty);
|
||||
if (regionUUID == String.Empty)
|
||||
{
|
||||
UUID newID = UUID.Random();
|
||||
|
||||
regionUUID = MainConsole.Instance.CmdPrompt("Region UUID", newID.ToString());
|
||||
regionUUID = MainConsole.Instance.CmdPrompt("RegionUUID", newID.ToString());
|
||||
config.Set("RegionUUID", regionUUID);
|
||||
}
|
||||
|
||||
RegionID = new UUID(regionUUID);
|
||||
originRegionID = RegionID; // What IS this?!
|
||||
originRegionID = RegionID; // What IS this?! (Needed for RegionCombinerModule?)
|
||||
|
||||
RegionName = name;
|
||||
// Location
|
||||
//
|
||||
allKeys.Remove(("Location").ToLower());
|
||||
string location = config.GetString("Location", String.Empty);
|
||||
|
||||
if (location == String.Empty)
|
||||
{
|
||||
location = MainConsole.Instance.CmdPrompt("Region Location", "1000,1000");
|
||||
|
@ -508,13 +531,10 @@ namespace OpenSim.Framework
|
|||
m_regionLocX = Convert.ToUInt32(locationElements[0]);
|
||||
m_regionLocY = Convert.ToUInt32(locationElements[1]);
|
||||
|
||||
|
||||
// Datastore (is this implemented? Omitted from example!)
|
||||
DataStore = config.GetString("Datastore", String.Empty);
|
||||
|
||||
// Internal IP
|
||||
// InternalAddress
|
||||
//
|
||||
IPAddress address;
|
||||
|
||||
allKeys.Remove(("InternalAddress").ToLower());
|
||||
if (config.Contains("InternalAddress"))
|
||||
{
|
||||
address = IPAddress.Parse(config.GetString("InternalAddress", String.Empty));
|
||||
|
@ -525,8 +545,10 @@ namespace OpenSim.Framework
|
|||
config.Set("InternalAddress", address.ToString());
|
||||
}
|
||||
|
||||
// InternalPort
|
||||
//
|
||||
int port;
|
||||
|
||||
allKeys.Remove(("InternalPort").ToLower());
|
||||
if (config.Contains("InternalPort"))
|
||||
{
|
||||
port = config.GetInt("InternalPort", 9000);
|
||||
|
@ -536,9 +558,11 @@ namespace OpenSim.Framework
|
|||
port = Convert.ToInt32(MainConsole.Instance.CmdPrompt("Internal port", "9000"));
|
||||
config.Set("InternalPort", port);
|
||||
}
|
||||
|
||||
m_internalEndPoint = new IPEndPoint(address, port);
|
||||
|
||||
// AllowAlternatePorts
|
||||
//
|
||||
allKeys.Remove(("AllowAlternatePorts").ToLower());
|
||||
if (config.Contains("AllowAlternatePorts"))
|
||||
{
|
||||
m_allow_alternate_ports = config.GetBoolean("AllowAlternatePorts", true);
|
||||
|
@ -550,10 +574,10 @@ namespace OpenSim.Framework
|
|||
config.Set("AllowAlternatePorts", m_allow_alternate_ports.ToString());
|
||||
}
|
||||
|
||||
// External IP
|
||||
// ExternalHostName
|
||||
//
|
||||
allKeys.Remove(("ExternalHostName").ToLower());
|
||||
string externalName;
|
||||
|
||||
if (config.Contains("ExternalHostName"))
|
||||
{
|
||||
externalName = config.GetString("ExternalHostName", "SYSTEMIP");
|
||||
|
@ -563,7 +587,6 @@ namespace OpenSim.Framework
|
|||
externalName = MainConsole.Instance.CmdPrompt("External host name", "SYSTEMIP");
|
||||
config.Set("ExternalHostName", externalName);
|
||||
}
|
||||
|
||||
if (externalName == "SYSTEMIP")
|
||||
{
|
||||
m_externalHostName = Util.GetLocalHost().ToString();
|
||||
|
@ -576,24 +599,32 @@ namespace OpenSim.Framework
|
|||
m_externalHostName = externalName;
|
||||
}
|
||||
|
||||
// RegionType
|
||||
m_regionType = config.GetString("RegionType", String.Empty);
|
||||
allKeys.Remove(("RegionType").ToLower());
|
||||
|
||||
// Prim stuff
|
||||
//
|
||||
m_nonphysPrimMax = config.GetInt("NonphysicalPrimMax", 256);
|
||||
|
||||
allKeys.Remove(("NonphysicalPrimMax").ToLower());
|
||||
m_physPrimMax = config.GetInt("PhysicalPrimMax", 10);
|
||||
|
||||
allKeys.Remove(("PhysicalPrimMax").ToLower());
|
||||
m_clampPrimSize = config.GetBoolean("ClampPrimSize", false);
|
||||
|
||||
allKeys.Remove(("ClampPrimSize").ToLower());
|
||||
m_objectCapacity = config.GetInt("MaxPrims", 15000);
|
||||
|
||||
allKeys.Remove(("MaxPrims").ToLower());
|
||||
m_agentCapacity = config.GetInt("MaxAgents", 100);
|
||||
|
||||
allKeys.Remove(("MaxAgents").ToLower());
|
||||
|
||||
// Multi-tenancy
|
||||
//
|
||||
ScopeID = new UUID(config.GetString("ScopeID", UUID.Zero.ToString()));
|
||||
allKeys.Remove(("ScopeID").ToLower());
|
||||
|
||||
foreach (String s in allKeys)
|
||||
{
|
||||
m_otherSettings.Add(s, config.GetString(s));
|
||||
}
|
||||
}
|
||||
|
||||
private void WriteNiniConfig(IConfigSource source)
|
||||
|
|
|
@ -5417,7 +5417,7 @@ namespace OpenSim.Region.Framework.Scenes
|
|||
presence.AbsolutePosition = presence.MoveToPositionTarget;
|
||||
presence.ResetMoveToTarget();
|
||||
|
||||
if (presence.PhysicsActor.Flying)
|
||||
if (presence.Flying)
|
||||
{
|
||||
// A horrible hack to stop the avatar dead in its tracks rather than having them overshoot
|
||||
// the target if flying.
|
||||
|
@ -5425,16 +5425,16 @@ namespace OpenSim.Region.Framework.Scenes
|
|||
// least be able to set collision status once, rather than 5 times to give it enough
|
||||
// weighting so that that PhysicsActor thinks it really is colliding.
|
||||
for (int i = 0; i < 5; i++)
|
||||
presence.PhysicsActor.IsColliding = true;
|
||||
presence.IsColliding = true;
|
||||
|
||||
if (presence.LandAtTarget)
|
||||
presence.PhysicsActor.Flying = false;
|
||||
presence.Flying = false;
|
||||
|
||||
// Vector3 targetPos = presence.MoveToPositionTarget;
|
||||
// float terrainHeight = (float)presence.Scene.Heightmap[(int)targetPos.X, (int)targetPos.Y];
|
||||
// if (targetPos.Z - terrainHeight < 0.2)
|
||||
// {
|
||||
// presence.PhysicsActor.Flying = false;
|
||||
// presence.Flying = false;
|
||||
// }
|
||||
}
|
||||
|
||||
|
|
|
@ -142,12 +142,27 @@ namespace OpenSim.Region.Framework.Scenes
|
|||
{
|
||||
get { return m_userFlags; }
|
||||
}
|
||||
private bool m_flyingOld; // add for fly velocity control
|
||||
|
||||
// Flying
|
||||
public bool Flying
|
||||
{
|
||||
get { return PhysicsActor != null && PhysicsActor.Flying; }
|
||||
set { PhysicsActor.Flying = value; }
|
||||
}
|
||||
|
||||
// add for fly velocity control
|
||||
private bool FlyingOld {get; set;}
|
||||
public bool WasFlying
|
||||
{
|
||||
get { return m_wasFlying; }
|
||||
get; private set;
|
||||
}
|
||||
|
||||
public bool IsColliding
|
||||
{
|
||||
get { return PhysicsActor != null && PhysicsActor.IsColliding; }
|
||||
// We would expect setting IsColliding to be private but it's used by a hack in Scene
|
||||
set { PhysicsActor.IsColliding = value; }
|
||||
}
|
||||
private bool m_wasFlying; // add for fly velocity control
|
||||
|
||||
// private int m_lastColCount = -1; //KF: Look for Collision chnages
|
||||
// private int m_updateCount = 0; //KF: Update Anims for a while
|
||||
|
@ -697,9 +712,9 @@ namespace OpenSim.Region.Framework.Scenes
|
|||
set {
|
||||
if(value)
|
||||
{
|
||||
if ((PhysicsActor != null) && PhysicsActor.Flying)
|
||||
if (Flying)
|
||||
m_AgentControlFlags |= AgentManager.ControlFlags.AGENT_CONTROL_FLY;
|
||||
else if ((m_AgentControlFlags & AgentManager.ControlFlags.AGENT_CONTROL_FLY) != 0)
|
||||
else
|
||||
m_AgentControlFlags &= ~AgentManager.ControlFlags.AGENT_CONTROL_FLY;
|
||||
}
|
||||
m_inTransit = value;
|
||||
|
@ -925,11 +940,11 @@ namespace OpenSim.Region.Framework.Scenes
|
|||
|
||||
if (ForceFly)
|
||||
{
|
||||
PhysicsActor.Flying = true;
|
||||
Flying = true;
|
||||
}
|
||||
else if (FlyDisabled)
|
||||
{
|
||||
PhysicsActor.Flying = false;
|
||||
Flying = false;
|
||||
}
|
||||
|
||||
// Don't send an animation pack here, since on a region crossing this will sometimes cause a flying
|
||||
|
@ -1054,11 +1069,7 @@ namespace OpenSim.Region.Framework.Scenes
|
|||
/// <param name="pos"></param>
|
||||
public void Teleport(Vector3 pos)
|
||||
{
|
||||
bool isFlying = false;
|
||||
if (PhysicsActor != null)
|
||||
isFlying = PhysicsActor.Flying;
|
||||
|
||||
m_log.DebugFormat("[SCENE PRESENCCE]: Local teleport, flying = {0}", isFlying);
|
||||
bool isFlying = Flying;
|
||||
RemoveFromPhysicalScene();
|
||||
Velocity = Vector3.Zero;
|
||||
CheckLandingPoint(ref pos);
|
||||
|
@ -1070,10 +1081,7 @@ namespace OpenSim.Region.Framework.Scenes
|
|||
|
||||
public void TeleportWithMomentum(Vector3 pos)
|
||||
{
|
||||
bool isFlying = false;
|
||||
if (PhysicsActor != null)
|
||||
isFlying = PhysicsActor.Flying;
|
||||
|
||||
bool isFlying = Flying;
|
||||
RemoveFromPhysicalScene();
|
||||
CheckLandingPoint(ref pos);
|
||||
AbsolutePosition = pos;
|
||||
|
@ -1208,8 +1216,8 @@ namespace OpenSim.Region.Framework.Scenes
|
|||
AbsolutePosition = pos;
|
||||
}
|
||||
|
||||
bool m_flying = ((m_AgentControlFlags & AgentManager.ControlFlags.AGENT_CONTROL_FLY) != 0);
|
||||
MakeRootAgent(AbsolutePosition, m_flying);
|
||||
bool flying = ((m_AgentControlFlags & AgentManager.ControlFlags.AGENT_CONTROL_FLY) != 0);
|
||||
MakeRootAgent(AbsolutePosition, flying);
|
||||
|
||||
if ((m_callbackURI != null) && !m_callbackURI.Equals(""))
|
||||
{
|
||||
|
@ -1434,7 +1442,7 @@ namespace OpenSim.Region.Framework.Scenes
|
|||
bool DCFlagKeyPressed = false;
|
||||
Vector3 agent_control_v3 = Vector3.Zero;
|
||||
|
||||
bool oldflying = PhysicsActor.Flying;
|
||||
bool oldflying = Flying;
|
||||
|
||||
if (ForceFly)
|
||||
actor.Flying = true;
|
||||
|
@ -1454,7 +1462,7 @@ namespace OpenSim.Region.Framework.Scenes
|
|||
|
||||
// use camera up angle when in mouselook and not flying or when holding the left mouse button down and not flying
|
||||
// this prevents 'jumping' in inappropriate situations.
|
||||
if ((m_mouseLook && !PhysicsActor.Flying) || (m_leftButtonDown && !PhysicsActor.Flying))
|
||||
if (!Flying && (m_mouseLook || m_leftButtonDown))
|
||||
dirVectors = GetWalkDirectionVectors();
|
||||
else
|
||||
dirVectors = Dir_Vectors;
|
||||
|
@ -1541,7 +1549,7 @@ namespace OpenSim.Region.Framework.Scenes
|
|||
// with something with the down arrow pressed.
|
||||
|
||||
// Only do this if we're flying
|
||||
if (PhysicsActor != null && PhysicsActor.Flying && !ForceFly)
|
||||
if (Flying && !ForceFly)
|
||||
{
|
||||
// Landing detection code
|
||||
|
||||
|
@ -1549,7 +1557,7 @@ namespace OpenSim.Region.Framework.Scenes
|
|||
bool controlland = (((flags & AgentManager.ControlFlags.AGENT_CONTROL_UP_NEG) != 0) ||
|
||||
((flags & AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_UP_NEG) != 0));
|
||||
|
||||
if (PhysicsActor.Flying && PhysicsActor.IsColliding && controlland)
|
||||
if (Flying && IsColliding && controlland)
|
||||
{
|
||||
// nesting this check because LengthSquared() is expensive and we don't
|
||||
// want to do it every step when flying.
|
||||
|
@ -1762,9 +1770,9 @@ namespace OpenSim.Region.Framework.Scenes
|
|||
Name, pos, terrainHeight, m_scene.RegionInfo.RegionName);
|
||||
|
||||
if (noFly)
|
||||
PhysicsActor.Flying = false;
|
||||
Flying = false;
|
||||
else if (pos.Z > terrainHeight)
|
||||
PhysicsActor.Flying = true;
|
||||
Flying = true;
|
||||
|
||||
LandAtTarget = landAtTarget;
|
||||
MovingToTarget = true;
|
||||
|
@ -2330,42 +2338,42 @@ namespace OpenSim.Region.Framework.Scenes
|
|||
Vector3 direc = vec * Rotation;
|
||||
direc.Normalize();
|
||||
|
||||
if (PhysicsActor.Flying != m_flyingOld) // add for fly velocity control
|
||||
if (Flying != FlyingOld) // add for fly velocity control
|
||||
{
|
||||
m_flyingOld = PhysicsActor.Flying; // add for fly velocity control
|
||||
if (!PhysicsActor.Flying)
|
||||
m_wasFlying = true; // add for fly velocity control
|
||||
FlyingOld = Flying; // add for fly velocity control
|
||||
if (!Flying)
|
||||
WasFlying = true; // add for fly velocity control
|
||||
}
|
||||
|
||||
if (PhysicsActor.IsColliding == true)
|
||||
m_wasFlying = false; // add for fly velocity control
|
||||
if (IsColliding)
|
||||
WasFlying = false; // add for fly velocity control
|
||||
|
||||
if ((vec.Z == 0f) && !PhysicsActor.Flying)
|
||||
if ((vec.Z == 0f) && !Flying)
|
||||
direc.Z = 0f; // Prevent camera WASD up.
|
||||
|
||||
direc *= 0.03f * 128f * SpeedModifier;
|
||||
|
||||
if (PhysicsActor != null)
|
||||
{
|
||||
if (PhysicsActor.Flying)
|
||||
if (Flying)
|
||||
{
|
||||
direc *= 4.0f;
|
||||
//bool controlland = (((m_AgentControlFlags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_UP_NEG) != 0) || ((m_AgentControlFlags & (uint)AgentManager.ControlFlags.AGENT_CONTROL_NUDGE_UP_NEG) != 0));
|
||||
//if (controlland)
|
||||
// m_log.Info("[AGENT]: landCommand");
|
||||
//if (PhysicsActor.IsColliding)
|
||||
//if (IsColliding)
|
||||
// m_log.Info("[AGENT]: colliding");
|
||||
//if (PhysicsActor.Flying && PhysicsActor.IsColliding && controlland)
|
||||
//if (Flying && IsColliding && controlland)
|
||||
//{
|
||||
// StopFlying();
|
||||
// m_log.Info("[AGENT]: Stop Flying");
|
||||
//}
|
||||
}
|
||||
if (Animator.Falling && m_wasFlying) // if falling from flying, disable motion add
|
||||
if (Animator.Falling && WasFlying) // if falling from flying, disable motion add
|
||||
{
|
||||
direc *= 0.0f;
|
||||
}
|
||||
else if (!PhysicsActor.Flying && PhysicsActor.IsColliding)
|
||||
else if (!Flying && IsColliding)
|
||||
{
|
||||
if (direc.Z > 2.0f)
|
||||
{
|
||||
|
@ -2835,7 +2843,7 @@ namespace OpenSim.Region.Framework.Scenes
|
|||
{
|
||||
if (m_requestedSitTargetUUID == UUID.Zero)
|
||||
{
|
||||
bool isFlying = PhysicsActor.Flying;
|
||||
bool isFlying = Flying;
|
||||
RemoveFromPhysicalScene();
|
||||
|
||||
Vector3 pos = AbsolutePosition;
|
||||
|
@ -2862,7 +2870,7 @@ namespace OpenSim.Region.Framework.Scenes
|
|||
{
|
||||
if (m_requestedSitTargetUUID == UUID.Zero)
|
||||
{
|
||||
bool isFlying = PhysicsActor.Flying;
|
||||
bool isFlying = Flying;
|
||||
RemoveFromPhysicalScene();
|
||||
|
||||
Vector3 pos = AbsolutePosition;
|
||||
|
@ -2912,7 +2920,7 @@ namespace OpenSim.Region.Framework.Scenes
|
|||
{
|
||||
try
|
||||
{
|
||||
return m_scene.CrossAgentToNewRegion(this, PhysicsActor.Flying);
|
||||
return m_scene.CrossAgentToNewRegion(this, Flying);
|
||||
}
|
||||
catch
|
||||
{
|
||||
|
@ -3188,7 +3196,7 @@ namespace OpenSim.Region.Framework.Scenes
|
|||
Appearance = new AvatarAppearance(cAgent.Appearance);
|
||||
if (PhysicsActor != null)
|
||||
{
|
||||
bool isFlying = PhysicsActor.Flying;
|
||||
bool isFlying = Flying;
|
||||
RemoveFromPhysicalScene();
|
||||
AddToPhysicalScene(isFlying);
|
||||
}
|
||||
|
@ -3291,7 +3299,7 @@ namespace OpenSim.Region.Framework.Scenes
|
|||
|
||||
private void OutOfBoundsCall(Vector3 pos)
|
||||
{
|
||||
//bool flying = PhysicsActor.Flying;
|
||||
//bool flying = Flying;
|
||||
//RemoveFromPhysicalScene();
|
||||
|
||||
//AddToPhysicalScene(flying);
|
||||
|
|
|
@ -61,7 +61,7 @@ namespace OpenSim.Region.Framework.Scenes.Tests
|
|||
|
||||
TestScene scene = SceneHelpers.SetupScene();
|
||||
ScenePresence sp = SceneHelpers.AddScenePresence(scene, TestHelpers.ParseTail(0x1));
|
||||
sp.PhysicsActor.Flying = true;
|
||||
sp.Flying = true;
|
||||
sp.PhysicsCollisionUpdate(new CollisionEventUpdate());
|
||||
|
||||
Assert.That(sp.Animator.CurrentMovementAnimation, Is.EqualTo("HOVER"));
|
||||
|
|
|
@ -79,7 +79,7 @@ namespace OpenSim.Region.Framework.Scenes.Tests
|
|||
// Vector3 startPos = new Vector3(128, 128, 30);
|
||||
|
||||
// For now, we'll make the scene presence fly to simplify this test, but this needs to change.
|
||||
sp.PhysicsActor.Flying = true;
|
||||
sp.Flying = true;
|
||||
|
||||
m_scene.Update();
|
||||
Assert.That(sp.AbsolutePosition, Is.EqualTo(startPos));
|
||||
|
|
|
@ -175,7 +175,7 @@ namespace OpenSim.Region.OptionalModules.World.NPC.Tests
|
|||
Assert.That(npc.AbsolutePosition, Is.EqualTo(startPos));
|
||||
|
||||
// For now, we'll make the scene presence fly to simplify this test, but this needs to change.
|
||||
npc.PhysicsActor.Flying = true;
|
||||
npc.Flying = true;
|
||||
|
||||
scene.Update();
|
||||
Assert.That(npc.AbsolutePosition, Is.EqualTo(startPos));
|
||||
|
|
|
@ -5984,9 +5984,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
|
|||
// note: this may need some tweaking when walking downhill. you "fall down" for a brief instant
|
||||
// and don't collide when walking downhill, which instantly registers as in-air, briefly. should
|
||||
// there be some minimum non-collision threshold time before claiming the avatar is in-air?
|
||||
if ((flags & ScriptBaseClass.AGENT_WALKING) == 0 &&
|
||||
agent.PhysicsActor != null &&
|
||||
!agent.PhysicsActor.IsColliding)
|
||||
if ((flags & ScriptBaseClass.AGENT_WALKING) == 0 && !agent.IsColliding )
|
||||
{
|
||||
flags |= ScriptBaseClass.AGENT_IN_AIR;
|
||||
}
|
||||
|
|
|
@ -1559,209 +1559,83 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
|
|||
return m_ScriptEngine.World.GetSimulatorVersion();
|
||||
}
|
||||
|
||||
private Hashtable osdToHashtable(OSDMap map)
|
||||
{
|
||||
Hashtable result = new Hashtable();
|
||||
foreach (KeyValuePair<string, OSD> item in map) {
|
||||
result.Add(item.Key, osdToObject(item.Value));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private ArrayList osdToArray(OSDArray list)
|
||||
{
|
||||
ArrayList result = new ArrayList();
|
||||
foreach ( OSD item in list ) {
|
||||
result.Add(osdToObject(item));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private Object osdToObject(OSD decoded)
|
||||
{
|
||||
if ( decoded is OSDString ) {
|
||||
return (string) decoded.AsString();
|
||||
} else if ( decoded is OSDInteger ) {
|
||||
return (int) decoded.AsInteger();
|
||||
} else if ( decoded is OSDReal ) {
|
||||
return (float) decoded.AsReal();
|
||||
} else if ( decoded is OSDBoolean ) {
|
||||
return (bool) decoded.AsBoolean();
|
||||
} else if ( decoded is OSDMap ) {
|
||||
return osdToHashtable((OSDMap) decoded);
|
||||
} else if ( decoded is OSDArray ) {
|
||||
return osdToArray((OSDArray) decoded);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public Object osParseJSONNew(string JSON)
|
||||
{
|
||||
CheckThreatLevel(ThreatLevel.None, "osParseJSON");
|
||||
|
||||
m_host.AddScriptLPS(1);
|
||||
|
||||
try
|
||||
{
|
||||
OSD decoded = OSDParser.DeserializeJson(JSON);
|
||||
return osdToObject(decoded);
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
OSSLError("osParseJSONNew: Problems decoding JSON string " + JSON + " : " + e.Message) ;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public Hashtable osParseJSON(string JSON)
|
||||
{
|
||||
CheckThreatLevel(ThreatLevel.None, "osParseJSON");
|
||||
|
||||
m_host.AddScriptLPS(1);
|
||||
|
||||
// see http://www.json.org/ for more details on JSON
|
||||
|
||||
string currentKey = null;
|
||||
Stack objectStack = new Stack(); // objects in JSON can be nested so we need to keep a track of this
|
||||
Hashtable jsondata = new Hashtable(); // the hashtable to be returned
|
||||
int i = 0;
|
||||
try
|
||||
{
|
||||
|
||||
// iterate through the serialised stream of tokens and store at the right depth in the hashtable
|
||||
// the top level hashtable may contain more nested hashtables within it each containing an objects representation
|
||||
for (i = 0; i < JSON.Length; i++)
|
||||
{
|
||||
|
||||
// m_log.Debug(""+JSON[i]);
|
||||
switch (JSON[i])
|
||||
{
|
||||
case '{':
|
||||
// create hashtable and add it to the stack or array if we are populating one, we can have a lot of nested objects in JSON
|
||||
|
||||
Hashtable currentObject = new Hashtable();
|
||||
if (objectStack.Count == 0) // the stack should only be empty for the first outer object
|
||||
{
|
||||
|
||||
objectStack.Push(jsondata);
|
||||
}
|
||||
else if (objectStack.Peek().ToString() == "System.Collections.ArrayList")
|
||||
{
|
||||
// add it to the parent array
|
||||
((ArrayList)objectStack.Peek()).Add(currentObject);
|
||||
objectStack.Push(currentObject);
|
||||
}
|
||||
else
|
||||
{
|
||||
// add it to the parent hashtable
|
||||
((Hashtable)objectStack.Peek()).Add(currentKey,currentObject);
|
||||
objectStack.Push(currentObject);
|
||||
}
|
||||
|
||||
// clear the key
|
||||
currentKey = null;
|
||||
break;
|
||||
|
||||
case '}':
|
||||
// pop the hashtable off the stack
|
||||
objectStack.Pop();
|
||||
break;
|
||||
|
||||
case '"':// string boundary
|
||||
|
||||
string tokenValue = "";
|
||||
i++; // move to next char
|
||||
|
||||
// just loop through until the next quote mark storing the string, ignore quotes with pre-ceding \
|
||||
while (JSON[i] != '"')
|
||||
{
|
||||
tokenValue += JSON[i];
|
||||
|
||||
// handle escaped double quotes \"
|
||||
if (JSON[i] == '\\' && JSON[i+1] == '"')
|
||||
{
|
||||
tokenValue += JSON[i+1];
|
||||
i++;
|
||||
}
|
||||
i++;
|
||||
|
||||
}
|
||||
|
||||
// ok we've got a string, if we've got an array on the top of the stack then we store it
|
||||
if (objectStack.Peek().ToString() == "System.Collections.ArrayList")
|
||||
{
|
||||
((ArrayList)objectStack.Peek()).Add(tokenValue);
|
||||
}
|
||||
else if (currentKey == null) // no key stored and its not an array this must be a key so store it
|
||||
{
|
||||
currentKey = tokenValue;
|
||||
}
|
||||
else
|
||||
{
|
||||
// we have a key so lets store this value
|
||||
((Hashtable)objectStack.Peek()).Add(currentKey,tokenValue);
|
||||
// now lets clear the key, we're done with it and moving on
|
||||
currentKey = null;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case ':':// key : value separator
|
||||
// just ignore
|
||||
break;
|
||||
|
||||
case ' ':// spaces
|
||||
// just ignore
|
||||
break;
|
||||
|
||||
case '[': // array start
|
||||
ArrayList currentArray = new ArrayList();
|
||||
|
||||
if (objectStack.Peek().ToString() == "System.Collections.ArrayList")
|
||||
{
|
||||
((ArrayList)objectStack.Peek()).Add(currentArray);
|
||||
}
|
||||
else
|
||||
{
|
||||
((Hashtable)objectStack.Peek()).Add(currentKey,currentArray);
|
||||
// clear the key
|
||||
currentKey = null;
|
||||
}
|
||||
objectStack.Push(currentArray);
|
||||
|
||||
break;
|
||||
|
||||
case ',':// seperator
|
||||
// just ignore
|
||||
break;
|
||||
|
||||
case ']'://Array end
|
||||
// pop the array off the stack
|
||||
objectStack.Pop();
|
||||
break;
|
||||
|
||||
case 't': // we've found a character start not in quotes, it must be a boolean true
|
||||
|
||||
if (objectStack.Peek().ToString() == "System.Collections.ArrayList")
|
||||
{
|
||||
((ArrayList)objectStack.Peek()).Add(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
((Hashtable)objectStack.Peek()).Add(currentKey,true);
|
||||
currentKey = null;
|
||||
}
|
||||
|
||||
//advance the counter to the letter 'e'
|
||||
i = i + 3;
|
||||
break;
|
||||
|
||||
case 'f': // we've found a character start not in quotes, it must be a boolean false
|
||||
|
||||
if (objectStack.Peek().ToString() == "System.Collections.ArrayList")
|
||||
{
|
||||
((ArrayList)objectStack.Peek()).Add(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
((Hashtable)objectStack.Peek()).Add(currentKey,false);
|
||||
currentKey = null;
|
||||
}
|
||||
//advance the counter to the letter 'e'
|
||||
i = i + 4;
|
||||
break;
|
||||
|
||||
case '\n':// carriage return
|
||||
// just ignore
|
||||
break;
|
||||
|
||||
case '\r':// carriage return
|
||||
// just ignore
|
||||
break;
|
||||
|
||||
default:
|
||||
// ok here we're catching all numeric types int,double,long we might want to spit these up mr accurately
|
||||
// but for now we'll just do them as strings
|
||||
|
||||
string numberValue = "";
|
||||
|
||||
// just loop through until the next known marker quote mark storing the string
|
||||
while (JSON[i] != '"' && JSON[i] != ',' && JSON[i] != ']' && JSON[i] != '}' && JSON[i] != ' ')
|
||||
{
|
||||
numberValue += "" + JSON[i++];
|
||||
}
|
||||
|
||||
i--; // we want to process this caracter that marked the end of this string in the main loop
|
||||
|
||||
// ok we've got a string, if we've got an array on the top of the stack then we store it
|
||||
if (objectStack.Peek().ToString() == "System.Collections.ArrayList")
|
||||
{
|
||||
((ArrayList)objectStack.Peek()).Add(numberValue);
|
||||
}
|
||||
else
|
||||
{
|
||||
// we have a key so lets store this value
|
||||
((Hashtable)objectStack.Peek()).Add(currentKey,numberValue);
|
||||
// now lets clear the key, we're done with it and moving on
|
||||
currentKey = null;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
Object decoded = osParseJSONNew(JSON);
|
||||
|
||||
if ( decoded is Hashtable ) {
|
||||
return (Hashtable) decoded;
|
||||
} else if ( decoded is ArrayList ) {
|
||||
ArrayList decoded_list = (ArrayList) decoded;
|
||||
Hashtable fakearray = new Hashtable();
|
||||
int i = 0;
|
||||
for ( i = 0; i < decoded_list.Count ; i++ ) {
|
||||
fakearray.Add(i, decoded_list[i]);
|
||||
}
|
||||
return fakearray;
|
||||
} else {
|
||||
OSSLError("osParseJSON: unable to parse JSON string " + JSON);
|
||||
return null;
|
||||
}
|
||||
catch(Exception)
|
||||
{
|
||||
OSSLError("osParseJSON: The JSON string is not valid " + JSON) ;
|
||||
}
|
||||
|
||||
return jsondata;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using OpenSim.Region.ScriptEngine.Interfaces;
|
||||
|
||||
|
@ -140,6 +141,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Interfaces
|
|||
|
||||
string osGetScriptEngineName();
|
||||
string osGetSimulatorVersion();
|
||||
Object osParseJSONNew(string JSON);
|
||||
Hashtable osParseJSON(string JSON);
|
||||
|
||||
void osMessageObject(key objectUUID,string message);
|
||||
|
|
|
@ -396,6 +396,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
|
|||
{
|
||||
return m_OSSL_Functions.osParseJSON(JSON);
|
||||
}
|
||||
|
||||
public Object osParseJSONNew(string JSON)
|
||||
{
|
||||
return m_OSSL_Functions.osParseJSONNew(JSON);
|
||||
}
|
||||
|
||||
public void osMessageObject(key objectUUID,string message)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue