aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/ScriptEngine/Shared/Api/Implementation
diff options
context:
space:
mode:
authorMelanie2011-12-12 11:42:22 +0000
committerMelanie2011-12-12 11:42:22 +0000
commit52a4dbccbec7f3c3139f49c29fdc20b8332f50f0 (patch)
treec1c76545b90c9a9df67886eb01d10e8388785c00 /OpenSim/Region/ScriptEngine/Shared/Api/Implementation
parentFix a regression that causes data from the attachments module to fail loading (diff)
parentCleaned up ScenePresence parameters for Flying, WasFlying, FlyingOld and IsCo... (diff)
downloadopensim-SC-52a4dbccbec7f3c3139f49c29fdc20b8332f50f0.zip
opensim-SC-52a4dbccbec7f3c3139f49c29fdc20b8332f50f0.tar.gz
opensim-SC-52a4dbccbec7f3c3139f49c29fdc20b8332f50f0.tar.bz2
opensim-SC-52a4dbccbec7f3c3139f49c29fdc20b8332f50f0.tar.xz
Merge branch 'master' into careminster
Conflicts: OpenSim/Framework/RegionInfo.cs OpenSim/Region/Framework/Scenes/ScenePresence.cs
Diffstat (limited to 'OpenSim/Region/ScriptEngine/Shared/Api/Implementation')
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs4
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs256
2 files changed, 66 insertions, 194 deletions
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs
index fcb1278..5f5d3cb 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs
@@ -5984,9 +5984,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
5984 // note: this may need some tweaking when walking downhill. you "fall down" for a brief instant 5984 // note: this may need some tweaking when walking downhill. you "fall down" for a brief instant
5985 // and don't collide when walking downhill, which instantly registers as in-air, briefly. should 5985 // and don't collide when walking downhill, which instantly registers as in-air, briefly. should
5986 // there be some minimum non-collision threshold time before claiming the avatar is in-air? 5986 // there be some minimum non-collision threshold time before claiming the avatar is in-air?
5987 if ((flags & ScriptBaseClass.AGENT_WALKING) == 0 && 5987 if ((flags & ScriptBaseClass.AGENT_WALKING) == 0 && !agent.IsColliding )
5988 agent.PhysicsActor != null &&
5989 !agent.PhysicsActor.IsColliding)
5990 { 5988 {
5991 flags |= ScriptBaseClass.AGENT_IN_AIR; 5989 flags |= ScriptBaseClass.AGENT_IN_AIR;
5992 } 5990 }
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs
index c0d2f38..c57684b 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs
@@ -1559,209 +1559,83 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1559 return m_ScriptEngine.World.GetSimulatorVersion(); 1559 return m_ScriptEngine.World.GetSimulatorVersion();
1560 } 1560 }
1561 1561
1562 public Hashtable osParseJSON(string JSON) 1562 private Hashtable osdToHashtable(OSDMap map)
1563 {
1564 Hashtable result = new Hashtable();
1565 foreach (KeyValuePair<string, OSD> item in map) {
1566 result.Add(item.Key, osdToObject(item.Value));
1567 }
1568 return result;
1569 }
1570
1571 private ArrayList osdToArray(OSDArray list)
1572 {
1573 ArrayList result = new ArrayList();
1574 foreach ( OSD item in list ) {
1575 result.Add(osdToObject(item));
1576 }
1577 return result;
1578 }
1579
1580 private Object osdToObject(OSD decoded)
1581 {
1582 if ( decoded is OSDString ) {
1583 return (string) decoded.AsString();
1584 } else if ( decoded is OSDInteger ) {
1585 return (int) decoded.AsInteger();
1586 } else if ( decoded is OSDReal ) {
1587 return (float) decoded.AsReal();
1588 } else if ( decoded is OSDBoolean ) {
1589 return (bool) decoded.AsBoolean();
1590 } else if ( decoded is OSDMap ) {
1591 return osdToHashtable((OSDMap) decoded);
1592 } else if ( decoded is OSDArray ) {
1593 return osdToArray((OSDArray) decoded);
1594 } else {
1595 return null;
1596 }
1597 }
1598
1599 public Object osParseJSONNew(string JSON)
1563 { 1600 {
1564 CheckThreatLevel(ThreatLevel.None, "osParseJSON"); 1601 CheckThreatLevel(ThreatLevel.None, "osParseJSON");
1565 1602
1566 m_host.AddScriptLPS(1); 1603 m_host.AddScriptLPS(1);
1567 1604
1568 // see http://www.json.org/ for more details on JSON
1569
1570 string currentKey = null;
1571 Stack objectStack = new Stack(); // objects in JSON can be nested so we need to keep a track of this
1572 Hashtable jsondata = new Hashtable(); // the hashtable to be returned
1573 int i = 0;
1574 try 1605 try
1575 { 1606 {
1607 OSD decoded = OSDParser.DeserializeJson(JSON);
1608 return osdToObject(decoded);
1609 }
1610 catch(Exception e)
1611 {
1612 OSSLError("osParseJSONNew: Problems decoding JSON string " + JSON + " : " + e.Message) ;
1613 return null;
1614 }
1615 }
1576 1616
1577 // iterate through the serialised stream of tokens and store at the right depth in the hashtable 1617 public Hashtable osParseJSON(string JSON)
1578 // the top level hashtable may contain more nested hashtables within it each containing an objects representation 1618 {
1579 for (i = 0; i < JSON.Length; i++) 1619 CheckThreatLevel(ThreatLevel.None, "osParseJSON");
1580 {
1581
1582 // m_log.Debug(""+JSON[i]);
1583 switch (JSON[i])
1584 {
1585 case '{':
1586 // 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
1587
1588 Hashtable currentObject = new Hashtable();
1589 if (objectStack.Count == 0) // the stack should only be empty for the first outer object
1590 {
1591
1592 objectStack.Push(jsondata);
1593 }
1594 else if (objectStack.Peek().ToString() == "System.Collections.ArrayList")
1595 {
1596 // add it to the parent array
1597 ((ArrayList)objectStack.Peek()).Add(currentObject);
1598 objectStack.Push(currentObject);
1599 }
1600 else
1601 {
1602 // add it to the parent hashtable
1603 ((Hashtable)objectStack.Peek()).Add(currentKey,currentObject);
1604 objectStack.Push(currentObject);
1605 }
1606
1607 // clear the key
1608 currentKey = null;
1609 break;
1610
1611 case '}':
1612 // pop the hashtable off the stack
1613 objectStack.Pop();
1614 break;
1615
1616 case '"':// string boundary
1617
1618 string tokenValue = "";
1619 i++; // move to next char
1620
1621 // just loop through until the next quote mark storing the string, ignore quotes with pre-ceding \
1622 while (JSON[i] != '"')
1623 {
1624 tokenValue += JSON[i];
1625
1626 // handle escaped double quotes \"
1627 if (JSON[i] == '\\' && JSON[i+1] == '"')
1628 {
1629 tokenValue += JSON[i+1];
1630 i++;
1631 }
1632 i++;
1633
1634 }
1635
1636 // ok we've got a string, if we've got an array on the top of the stack then we store it
1637 if (objectStack.Peek().ToString() == "System.Collections.ArrayList")
1638 {
1639 ((ArrayList)objectStack.Peek()).Add(tokenValue);
1640 }
1641 else if (currentKey == null) // no key stored and its not an array this must be a key so store it
1642 {
1643 currentKey = tokenValue;
1644 }
1645 else
1646 {
1647 // we have a key so lets store this value
1648 ((Hashtable)objectStack.Peek()).Add(currentKey,tokenValue);
1649 // now lets clear the key, we're done with it and moving on
1650 currentKey = null;
1651 }
1652
1653 break;
1654
1655 case ':':// key : value separator
1656 // just ignore
1657 break;
1658
1659 case ' ':// spaces
1660 // just ignore
1661 break;
1662
1663 case '[': // array start
1664 ArrayList currentArray = new ArrayList();
1665
1666 if (objectStack.Peek().ToString() == "System.Collections.ArrayList")
1667 {
1668 ((ArrayList)objectStack.Peek()).Add(currentArray);
1669 }
1670 else
1671 {
1672 ((Hashtable)objectStack.Peek()).Add(currentKey,currentArray);
1673 // clear the key
1674 currentKey = null;
1675 }
1676 objectStack.Push(currentArray);
1677
1678 break;
1679
1680 case ',':// seperator
1681 // just ignore
1682 break;
1683
1684 case ']'://Array end
1685 // pop the array off the stack
1686 objectStack.Pop();
1687 break;
1688
1689 case 't': // we've found a character start not in quotes, it must be a boolean true
1690
1691 if (objectStack.Peek().ToString() == "System.Collections.ArrayList")
1692 {
1693 ((ArrayList)objectStack.Peek()).Add(true);
1694 }
1695 else
1696 {
1697 ((Hashtable)objectStack.Peek()).Add(currentKey,true);
1698 currentKey = null;
1699 }
1700
1701 //advance the counter to the letter 'e'
1702 i = i + 3;
1703 break;
1704
1705 case 'f': // we've found a character start not in quotes, it must be a boolean false
1706
1707 if (objectStack.Peek().ToString() == "System.Collections.ArrayList")
1708 {
1709 ((ArrayList)objectStack.Peek()).Add(false);
1710 }
1711 else
1712 {
1713 ((Hashtable)objectStack.Peek()).Add(currentKey,false);
1714 currentKey = null;
1715 }
1716 //advance the counter to the letter 'e'
1717 i = i + 4;
1718 break;
1719
1720 case '\n':// carriage return
1721 // just ignore
1722 break;
1723
1724 case '\r':// carriage return
1725 // just ignore
1726 break;
1727
1728 default:
1729 // ok here we're catching all numeric types int,double,long we might want to spit these up mr accurately
1730 // but for now we'll just do them as strings
1731
1732 string numberValue = "";
1733
1734 // just loop through until the next known marker quote mark storing the string
1735 while (JSON[i] != '"' && JSON[i] != ',' && JSON[i] != ']' && JSON[i] != '}' && JSON[i] != ' ')
1736 {
1737 numberValue += "" + JSON[i++];
1738 }
1739
1740 i--; // we want to process this caracter that marked the end of this string in the main loop
1741 1620
1742 // ok we've got a string, if we've got an array on the top of the stack then we store it 1621 m_host.AddScriptLPS(1);
1743 if (objectStack.Peek().ToString() == "System.Collections.ArrayList")
1744 {
1745 ((ArrayList)objectStack.Peek()).Add(numberValue);
1746 }
1747 else
1748 {
1749 // we have a key so lets store this value
1750 ((Hashtable)objectStack.Peek()).Add(currentKey,numberValue);
1751 // now lets clear the key, we're done with it and moving on
1752 currentKey = null;
1753 }
1754 1622
1755 break; 1623 Object decoded = osParseJSONNew(JSON);
1756 } 1624
1625 if ( decoded is Hashtable ) {
1626 return (Hashtable) decoded;
1627 } else if ( decoded is ArrayList ) {
1628 ArrayList decoded_list = (ArrayList) decoded;
1629 Hashtable fakearray = new Hashtable();
1630 int i = 0;
1631 for ( i = 0; i < decoded_list.Count ; i++ ) {
1632 fakearray.Add(i, decoded_list[i]);
1757 } 1633 }
1634 return fakearray;
1635 } else {
1636 OSSLError("osParseJSON: unable to parse JSON string " + JSON);
1637 return null;
1758 } 1638 }
1759 catch(Exception)
1760 {
1761 OSSLError("osParseJSON: The JSON string is not valid " + JSON) ;
1762 }
1763
1764 return jsondata;
1765 } 1639 }
1766 1640
1767 /// <summary> 1641 /// <summary>