aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/ScriptEngine/Shared/Api
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/ScriptEngine/Shared/Api')
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs239
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Implementation/Plugins/Timer.cs6
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Interface/ILSL_Api.cs5
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Constants.cs10
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Stub.cs25
5 files changed, 282 insertions, 3 deletions
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs
index 7d5c750..b5ba4a0 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs
@@ -37,6 +37,7 @@ using System.Timers;
37using Nini.Config; 37using Nini.Config;
38using log4net; 38using log4net;
39using OpenMetaverse; 39using OpenMetaverse;
40using OpenMetaverse.StructuredData;
40using OpenMetaverse.Packets; 41using OpenMetaverse.Packets;
41using OpenSim; 42using OpenSim;
42using OpenSim.Framework; 43using OpenSim.Framework;
@@ -13658,6 +13659,244 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
13658 13659
13659 return String.Empty; 13660 return String.Empty;
13660 } 13661 }
13662
13663 public LSL_String llJsonGetValue(LSL_String json, LSL_List specifiers)
13664 {
13665 OSD o = OSDParser.DeserializeJson(json);
13666 OSD specVal = JsonGetSpecific(o, specifiers, 0);
13667
13668 return specVal.AsString();
13669 }
13670
13671 public LSL_List llJson2List(LSL_String json)
13672 {
13673 try
13674 {
13675 OSD o = OSDParser.DeserializeJson(json);
13676 return (LSL_List)ParseJsonNode(o);
13677 }
13678 catch (Exception)
13679 {
13680 return new LSL_List(ScriptBaseClass.JSON_INVALID);
13681 }
13682 }
13683
13684 private object ParseJsonNode(OSD node)
13685 {
13686 if (node.Type == OSDType.Integer)
13687 return new LSL_Integer(node.AsInteger());
13688 if (node.Type == OSDType.Boolean)
13689 return new LSL_Integer(node.AsBoolean() ? 1 : 0);
13690 if (node.Type == OSDType.Real)
13691 return new LSL_Float(node.AsReal());
13692 if (node.Type == OSDType.UUID || node.Type == OSDType.String)
13693 return new LSL_String(node.AsString());
13694 if (node.Type == OSDType.Array)
13695 {
13696 LSL_List resp = new LSL_List();
13697 OSDArray ar = node as OSDArray;
13698 foreach (OSD o in ar)
13699 resp.Add(ParseJsonNode(o));
13700 return resp;
13701 }
13702 if (node.Type == OSDType.Map)
13703 {
13704 LSL_List resp = new LSL_List();
13705 OSDMap ar = node as OSDMap;
13706 foreach (KeyValuePair<string, OSD> o in ar)
13707 {
13708 resp.Add(new LSL_String(o.Key));
13709 resp.Add(ParseJsonNode(o.Value));
13710 }
13711 return resp;
13712 }
13713 throw new Exception(ScriptBaseClass.JSON_INVALID);
13714 }
13715
13716 public LSL_String llList2Json(LSL_String type, LSL_List values)
13717 {
13718 try
13719 {
13720 if (type == ScriptBaseClass.JSON_ARRAY)
13721 {
13722 OSDArray array = new OSDArray();
13723 foreach (object o in values.Data)
13724 {
13725 array.Add(ListToJson(o));
13726 }
13727 return OSDParser.SerializeJsonString(array);
13728 }
13729 else if (type == ScriptBaseClass.JSON_OBJECT)
13730 {
13731 OSDMap map = new OSDMap();
13732 for (int i = 0; i < values.Data.Length; i += 2)
13733 {
13734 if (!(values.Data[i] is LSL_String))
13735 return ScriptBaseClass.JSON_INVALID;
13736 map.Add(((LSL_String)values.Data[i]).m_string, ListToJson(values.Data[i + 1]));
13737 }
13738 return OSDParser.SerializeJsonString(map);
13739 }
13740 return ScriptBaseClass.JSON_INVALID;
13741 }
13742 catch (Exception ex)
13743 {
13744 return ex.Message;
13745 }
13746 }
13747
13748 private OSD ListToJson(object o)
13749 {
13750 if (o is LSL_Float)
13751 return OSD.FromReal(((LSL_Float)o).value);
13752 if (o is LSL_Integer)
13753 {
13754 int i = ((LSL_Integer)o).value;
13755 if (i == 0)
13756 return OSD.FromBoolean(false);
13757 else if (i == 1)
13758 return OSD.FromBoolean(true);
13759 return OSD.FromInteger(i);
13760 }
13761 if (o is LSL_Rotation)
13762 return OSD.FromString(((LSL_Rotation)o).ToString());
13763 if (o is LSL_Vector)
13764 return OSD.FromString(((LSL_Vector)o).ToString());
13765 if (o is LSL_String)
13766 {
13767 string str = ((LSL_String)o).m_string;
13768 if (str == ScriptBaseClass.JSON_NULL)
13769 return new OSD();
13770 return OSD.FromString(str);
13771 }
13772 throw new Exception(ScriptBaseClass.JSON_INVALID);
13773 }
13774
13775 private OSD JsonGetSpecific(OSD o, LSL_List specifiers, int i)
13776 {
13777 object spec = specifiers.Data[i];
13778 OSD nextVal = null;
13779 if (o is OSDArray)
13780 {
13781 if (spec is LSL_Integer)
13782 nextVal = ((OSDArray)o)[((LSL_Integer)spec).value];
13783 }
13784 if (o is OSDMap)
13785 {
13786 if (spec is LSL_String)
13787 nextVal = ((OSDMap)o)[((LSL_String)spec).m_string];
13788 }
13789 if (nextVal != null)
13790 {
13791 if (specifiers.Data.Length - 1 > i)
13792 return JsonGetSpecific(nextVal, specifiers, i + 1);
13793 }
13794 return nextVal;
13795 }
13796
13797 public LSL_String llJsonSetValue(LSL_String json, LSL_List specifiers, LSL_String value)
13798 {
13799 try
13800 {
13801 OSD o = OSDParser.DeserializeJson(json);
13802 JsonSetSpecific(o, specifiers, 0, value);
13803 return OSDParser.SerializeJsonString(o);
13804 }
13805 catch (Exception)
13806 {
13807 }
13808 return ScriptBaseClass.JSON_INVALID;
13809 }
13810
13811 private void JsonSetSpecific(OSD o, LSL_List specifiers, int i, LSL_String val)
13812 {
13813 object spec = specifiers.Data[i];
13814 // 20131224 not used object specNext = i+1 == specifiers.Data.Length ? null : specifiers.Data[i+1];
13815 OSD nextVal = null;
13816 if (o is OSDArray)
13817 {
13818 OSDArray array = ((OSDArray)o);
13819 if (spec is LSL_Integer)
13820 {
13821 int v = ((LSL_Integer)spec).value;
13822 if (v >= array.Count)
13823 array.Add(JsonBuildRestOfSpec(specifiers, i + 1, val));
13824 else
13825 nextVal = ((OSDArray)o)[v];
13826 }
13827 else if (spec is LSL_String && ((LSL_String)spec) == ScriptBaseClass.JSON_APPEND)
13828 array.Add(JsonBuildRestOfSpec(specifiers, i + 1, val));
13829 }
13830 if (o is OSDMap)
13831 {
13832 if (spec is LSL_String)
13833 {
13834 OSDMap map = ((OSDMap)o);
13835 if (map.ContainsKey(((LSL_String)spec).m_string))
13836 nextVal = map[((LSL_String)spec).m_string];
13837 else
13838 map.Add(((LSL_String)spec).m_string, JsonBuildRestOfSpec(specifiers, i + 1, val));
13839 }
13840 }
13841 if (nextVal != null)
13842 {
13843 if (specifiers.Data.Length - 1 > i)
13844 {
13845 JsonSetSpecific(nextVal, specifiers, i + 1, val);
13846 return;
13847 }
13848 }
13849 }
13850
13851 private OSD JsonBuildRestOfSpec(LSL_List specifiers, int i, LSL_String val)
13852 {
13853 object spec = i >= specifiers.Data.Length ? null : specifiers.Data[i];
13854 // 20131224 not used object specNext = i+1 >= specifiers.Data.Length ? null : specifiers.Data[i+1];
13855
13856 if (spec == null)
13857 return OSD.FromString(val);
13858
13859 if (spec is LSL_Integer ||
13860 (spec is LSL_String && ((LSL_String)spec) == ScriptBaseClass.JSON_APPEND))
13861 {
13862 OSDArray array = new OSDArray();
13863 array.Add(JsonBuildRestOfSpec(specifiers, i + 1, val));
13864 return array;
13865 }
13866 else if (spec is LSL_String)
13867 {
13868 OSDMap map = new OSDMap();
13869 map.Add((LSL_String)spec, JsonBuildRestOfSpec(specifiers, i + 1, val));
13870 return map;
13871 }
13872 return new OSD();
13873 }
13874
13875 public LSL_String llJsonValueType(LSL_String json, LSL_List specifiers)
13876 {
13877 OSD o = OSDParser.DeserializeJson(json);
13878 OSD specVal = JsonGetSpecific(o, specifiers, 0);
13879 if (specVal == null)
13880 return ScriptBaseClass.JSON_INVALID;
13881 switch (specVal.Type)
13882 {
13883 case OSDType.Array:
13884 return ScriptBaseClass.JSON_ARRAY;
13885 case OSDType.Boolean:
13886 return specVal.AsBoolean() ? ScriptBaseClass.JSON_TRUE : ScriptBaseClass.JSON_FALSE;
13887 case OSDType.Integer:
13888 case OSDType.Real:
13889 return ScriptBaseClass.JSON_NUMBER;
13890 case OSDType.Map:
13891 return ScriptBaseClass.JSON_OBJECT;
13892 case OSDType.String:
13893 case OSDType.UUID:
13894 return ScriptBaseClass.JSON_STRING;
13895 case OSDType.Unknown:
13896 return ScriptBaseClass.JSON_NULL;
13897 }
13898 return ScriptBaseClass.JSON_INVALID;
13899 }
13661 } 13900 }
13662 13901
13663 public class NotecardCache 13902 public class NotecardCache
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/Plugins/Timer.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/Plugins/Timer.cs
index 68aacd2..5b1fdc0 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/Plugins/Timer.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/Plugins/Timer.cs
@@ -123,14 +123,14 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Plugins
123 if (Timers.Count == 0) 123 if (Timers.Count == 0)
124 return; 124 return;
125 125
126 Dictionary<string, TimerInfo>.ValueCollection tvals; 126 Dictionary<string, TimerInfo> tvals;
127 lock (TimerListLock) 127 lock (TimerListLock)
128 { 128 {
129 // Go through all timers 129 // Go through all timers
130 tvals = Timers.Values; 130 tvals = new Dictionary<string, TimerInfo>(Timers);
131 } 131 }
132 132
133 foreach (TimerInfo ts in tvals) 133 foreach (TimerInfo ts in tvals.Values)
134 { 134 {
135 // Time has passed? 135 // Time has passed?
136 if (ts.next < DateTime.Now.Ticks) 136 if (ts.next < DateTime.Now.Ticks)
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Interface/ILSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Interface/ILSL_Api.cs
index 8c51564..b642a9c 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Interface/ILSL_Api.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Interface/ILSL_Api.cs
@@ -437,5 +437,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Interfaces
437 void llSetAnimationOverride(LSL_String animState, LSL_String anim); 437 void llSetAnimationOverride(LSL_String animState, LSL_String anim);
438 void llResetAnimationOverride(LSL_String anim_state); 438 void llResetAnimationOverride(LSL_String anim_state);
439 LSL_String llGetAnimationOverride(LSL_String anim_state); 439 LSL_String llGetAnimationOverride(LSL_String anim_state);
440 LSL_String llJsonGetValue(LSL_String json, LSL_List specifiers);
441 LSL_List llJson2List(LSL_String json);
442 LSL_String llList2Json(LSL_String type, LSL_List values);
443 LSL_String llJsonSetValue(LSL_String json, LSL_List specifiers, LSL_String value);
444 LSL_String llJsonValueType(LSL_String json, LSL_List specifiers);
440 } 445 }
441} 446}
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Constants.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Constants.cs
index e6ab6ec..0e22ff3 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Constants.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Constants.cs
@@ -788,6 +788,16 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
788 public const int KFM_CMD_STOP = 1; 788 public const int KFM_CMD_STOP = 1;
789 public const int KFM_CMD_PAUSE = 2; 789 public const int KFM_CMD_PAUSE = 2;
790 790
791 public const string JSON_ARRAY = "JSON_ARRAY";
792 public const string JSON_OBJECT = "JSON_OBJECT";
793 public const string JSON_INVALID = "JSON_INVALID";
794 public const string JSON_NUMBER = "JSON_NUMBER";
795 public const string JSON_STRING = "JSON_STRING";
796 public const string JSON_TRUE = "JSON_TRUE";
797 public const string JSON_FALSE = "JSON_FALSE";
798 public const string JSON_NULL = "JSON_NULL";
799 public const string JSON_APPEND = "JSON_APPEND";
800
791 /// <summary> 801 /// <summary>
792 /// process name parameter as regex 802 /// process name parameter as regex
793 /// </summary> 803 /// </summary>
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Stub.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Stub.cs
index 78c41a7..5047162 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Stub.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Stub.cs
@@ -2029,5 +2029,30 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
2029 { 2029 {
2030 return m_LSL_Functions.llGetAnimationOverride(anim_state); 2030 return m_LSL_Functions.llGetAnimationOverride(anim_state);
2031 } 2031 }
2032
2033 public LSL_String llJsonGetValue(LSL_String json, LSL_List specifiers)
2034 {
2035 return m_LSL_Functions.llJsonGetValue(json, specifiers);
2036 }
2037
2038 public LSL_List llJson2List(LSL_String json)
2039 {
2040 return m_LSL_Functions.llJson2List(json);
2041 }
2042
2043 public LSL_String llList2Json(LSL_String type, LSL_List values)
2044 {
2045 return m_LSL_Functions.llList2Json(type, values);
2046 }
2047
2048 public LSL_String llJsonSetValue(LSL_String json, LSL_List specifiers, LSL_String value)
2049 {
2050 return m_LSL_Functions.llJsonSetValue(json, specifiers, value);
2051 }
2052
2053 public LSL_String llJsonValueType(LSL_String json, LSL_List specifiers)
2054 {
2055 return m_LSL_Functions.llJsonValueType(json, specifiers);
2056 }
2032 } 2057 }
2033} 2058}