aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region
diff options
context:
space:
mode:
authorDiva Canto2012-03-15 16:03:33 -0700
committerDiva Canto2012-03-15 16:03:33 -0700
commit0548eeb571cc503384724688f8b11143efb9b620 (patch)
tree25efe4b40a3bcde2f67023174c583e2187df424a /OpenSim/Region
parentMore on SLURLs and V3. This is hacky, but it works. Basically, we have to red... (diff)
parentProtect the scriptmodulecomms interface. (diff)
downloadopensim-SC_OLD-0548eeb571cc503384724688f8b11143efb9b620.zip
opensim-SC_OLD-0548eeb571cc503384724688f8b11143efb9b620.tar.gz
opensim-SC_OLD-0548eeb571cc503384724688f8b11143efb9b620.tar.bz2
opensim-SC_OLD-0548eeb571cc503384724688f8b11143efb9b620.tar.xz
Merge branch 'master' of ssh://opensimulator.org/var/git/opensim
Diffstat (limited to 'OpenSim/Region')
-rw-r--r--OpenSim/Region/Framework/Interfaces/IScriptModuleComms.cs10
-rw-r--r--OpenSim/Region/OptionalModules/Scripting/ScriptModuleComms/ScriptModuleCommsModule.cs99
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Implementation/MOD_Api.cs109
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Interface/IMOD_Api.cs9
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Runtime/MOD_Stub.cs15
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/CodeTools/CSCodeGenerator.cs31
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/CodeTools/Compiler.cs5
7 files changed, 273 insertions, 5 deletions
diff --git a/OpenSim/Region/Framework/Interfaces/IScriptModuleComms.cs b/OpenSim/Region/Framework/Interfaces/IScriptModuleComms.cs
index d7fa316..bb4c788 100644
--- a/OpenSim/Region/Framework/Interfaces/IScriptModuleComms.cs
+++ b/OpenSim/Region/Framework/Interfaces/IScriptModuleComms.cs
@@ -31,6 +31,7 @@ using OpenMetaverse;
31namespace OpenSim.Region.Framework.Interfaces 31namespace OpenSim.Region.Framework.Interfaces
32{ 32{
33 public delegate void ScriptCommand(UUID script, string id, string module, string command, string k); 33 public delegate void ScriptCommand(UUID script, string id, string module, string command, string k);
34 public delegate object ScriptInvocation(UUID script, object[] parms);
34 35
35 /// <summary> 36 /// <summary>
36 /// Interface for communication between OpenSim modules and in-world scripts 37 /// Interface for communication between OpenSim modules and in-world scripts
@@ -45,6 +46,15 @@ namespace OpenSim.Region.Framework.Interfaces
45 /// </summary> 46 /// </summary>
46 event ScriptCommand OnScriptCommand; 47 event ScriptCommand OnScriptCommand;
47 48
49 void RegisterScriptInvocation(string name, ScriptInvocation fn, Type[] csig, Type rsig);
50
51 ScriptInvocation LookupScriptInvocation(string fname);
52 string LookupModInvocation(string fname);
53 Type[] LookupTypeSignature(string fname);
54 Type LookupReturnType(string fname);
55
56 object InvokeOperation(UUID scriptId, string fname, params object[] parms);
57
48 /// <summary> 58 /// <summary>
49 /// Send a link_message event to an in-world script 59 /// Send a link_message event to an in-world script
50 /// </summary> 60 /// </summary>
diff --git a/OpenSim/Region/OptionalModules/Scripting/ScriptModuleComms/ScriptModuleCommsModule.cs b/OpenSim/Region/OptionalModules/Scripting/ScriptModuleComms/ScriptModuleCommsModule.cs
index 44c9ada..a90362e 100644
--- a/OpenSim/Region/OptionalModules/Scripting/ScriptModuleComms/ScriptModuleCommsModule.cs
+++ b/OpenSim/Region/OptionalModules/Scripting/ScriptModuleComms/ScriptModuleCommsModule.cs
@@ -27,6 +27,7 @@
27 27
28using System; 28using System;
29using System.Reflection; 29using System.Reflection;
30using System.Collections.Generic;
30using Nini.Config; 31using Nini.Config;
31using log4net; 32using log4net;
32using OpenSim.Framework; 33using OpenSim.Framework;
@@ -35,7 +36,7 @@ using OpenSim.Region.Framework.Scenes;
35using Mono.Addins; 36using Mono.Addins;
36using OpenMetaverse; 37using OpenMetaverse;
37 38
38namespace OpenSim.Region.OptionalModules.Scripting.ScriptModuleComms 39namespace OpenSim.Region.CoreModules.Scripting.ScriptModuleComms
39{ 40{
40 [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "ScriptModuleCommsModule")] 41 [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "ScriptModuleCommsModule")]
41 class ScriptModuleCommsModule : INonSharedRegionModule, IScriptModuleComms 42 class ScriptModuleCommsModule : INonSharedRegionModule, IScriptModuleComms
@@ -43,10 +44,30 @@ namespace OpenSim.Region.OptionalModules.Scripting.ScriptModuleComms
43 private static readonly ILog m_log = 44 private static readonly ILog m_log =
44 LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 45 LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
45 46
46 private IScriptModule m_scriptModule = null; 47#region ScriptInvocation
48 protected class ScriptInvocationData
49 {
50 public ScriptInvocation ScriptInvocationFn { get; private set; }
51 public string FunctionName { get; private set; }
52 public Type[] TypeSignature { get; private set; }
53 public Type ReturnType { get; private set; }
54
55 public ScriptInvocationData(string fname, ScriptInvocation fn, Type[] callsig, Type returnsig)
56 {
57 FunctionName = fname;
58 ScriptInvocationFn = fn;
59 TypeSignature = callsig;
60 ReturnType = returnsig;
61 }
62 }
47 63
64 private Dictionary<string,ScriptInvocationData> m_scriptInvocation = new Dictionary<string,ScriptInvocationData>();
65#endregion
66
67 private IScriptModule m_scriptModule = null;
48 public event ScriptCommand OnScriptCommand; 68 public event ScriptCommand OnScriptCommand;
49 69
70#region RegionModuleInterface
50 public void Initialise(IConfigSource config) 71 public void Initialise(IConfigSource config)
51 { 72 {
52 } 73 }
@@ -81,6 +102,9 @@ namespace OpenSim.Region.OptionalModules.Scripting.ScriptModuleComms
81 public void Close() 102 public void Close()
82 { 103 {
83 } 104 }
105#endregion
106
107#region ScriptModuleComms
84 108
85 public void RaiseEvent(UUID script, string id, string module, string command, string k) 109 public void RaiseEvent(UUID script, string id, string module, string command, string k)
86 { 110 {
@@ -101,5 +125,76 @@ namespace OpenSim.Region.OptionalModules.Scripting.ScriptModuleComms
101 125
102 m_scriptModule.PostScriptEvent(script, "link_message", args); 126 m_scriptModule.PostScriptEvent(script, "link_message", args);
103 } 127 }
128
129 public void RegisterScriptInvocation(string fname, ScriptInvocation fcall, Type[] csig, Type rsig)
130 {
131 lock (m_scriptInvocation)
132 {
133 m_scriptInvocation[fname] = new ScriptInvocationData(fname,fcall,csig,rsig);
134 }
135 }
136
137 public string LookupModInvocation(string fname)
138 {
139 lock (m_scriptInvocation)
140 {
141 ScriptInvocationData sid;
142 if (m_scriptInvocation.TryGetValue(fname,out sid))
143 {
144 if (sid.ReturnType == typeof(string))
145 return "modInvokeS";
146 else if (sid.ReturnType == typeof(int))
147 return "modInvokeI";
148 else if (sid.ReturnType == typeof(float))
149 return "modInvokeF";
150 }
151 }
152
153 return null;
154 }
155
156 public ScriptInvocation LookupScriptInvocation(string fname)
157 {
158 lock (m_scriptInvocation)
159 {
160 ScriptInvocationData sid;
161 if (m_scriptInvocation.TryGetValue(fname,out sid))
162 return sid.ScriptInvocationFn;
163 }
164
165 return null;
166 }
167
168 public Type[] LookupTypeSignature(string fname)
169 {
170 lock (m_scriptInvocation)
171 {
172 ScriptInvocationData sid;
173 if (m_scriptInvocation.TryGetValue(fname,out sid))
174 return sid.TypeSignature;
175 }
176
177 return null;
178 }
179
180 public Type LookupReturnType(string fname)
181 {
182 lock (m_scriptInvocation)
183 {
184 ScriptInvocationData sid;
185 if (m_scriptInvocation.TryGetValue(fname,out sid))
186 return sid.ReturnType;
187 }
188
189 return null;
190 }
191
192 public object InvokeOperation(UUID scriptid, string fname, params object[] parms)
193 {
194 ScriptInvocation fn = LookupScriptInvocation(fname);
195 return fn(scriptid,parms);
196 }
197#endregion
198
104 } 199 }
105} 200}
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/MOD_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/MOD_Api.cs
index d4facdd..2942104 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/MOD_Api.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/MOD_Api.cs
@@ -116,6 +116,115 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
116 wComm.DeliverMessage(ChatTypeEnum.Shout, ScriptBaseClass.DEBUG_CHANNEL, m_host.Name, m_host.UUID, message); 116 wComm.DeliverMessage(ChatTypeEnum.Shout, ScriptBaseClass.DEBUG_CHANNEL, m_host.Name, m_host.UUID, message);
117 } 117 }
118 118
119 /// <summary>
120 ///
121 /// </summary>
122 /// <param name="fname">The name of the function to invoke</param>
123 /// <param name="fname">List of parameters</param>
124 /// <returns>string result of the invocation</returns>
125 public string modInvokeS(string fname, params object[] parms)
126 {
127 Type returntype = m_comms.LookupReturnType(fname);
128 if (returntype != typeof(string))
129 MODError(String.Format("return type mismatch for {0}",fname));
130
131 return (string)modInvoke(fname,parms);
132 }
133
134 public int modInvokeI(string fname, params object[] parms)
135 {
136 Type returntype = m_comms.LookupReturnType(fname);
137 if (returntype != typeof(int))
138 MODError(String.Format("return type mismatch for {0}",fname));
139
140 return (int)modInvoke(fname,parms);
141 }
142
143 public float modInvokeF(string fname, params object[] parms)
144 {
145 Type returntype = m_comms.LookupReturnType(fname);
146 if (returntype != typeof(float))
147 MODError(String.Format("return type mismatch for {0}",fname));
148
149 return (float)modInvoke(fname,parms);
150 }
151
152 /// <summary>
153 /// Invokes a preregistered function through the ScriptModuleComms class
154 /// </summary>
155 /// <param name="fname">The name of the function to invoke</param>
156 /// <param name="fname">List of parameters</param>
157 /// <returns>string result of the invocation</returns>
158 protected object modInvoke(string fname, params object[] parms)
159 {
160 if (!m_MODFunctionsEnabled)
161 {
162 MODShoutError("Module command functions not enabled");
163 return "";
164 }
165
166 Type[] signature = m_comms.LookupTypeSignature(fname);
167 if (signature.Length != parms.Length)
168 MODError(String.Format("wrong number of parameters to function {0}",fname));
169
170 object[] convertedParms = new object[parms.Length];
171
172 for (int i = 0; i < parms.Length; i++)
173 {
174 if (parms[i] is LSL_String)
175 {
176 if (signature[i] != typeof(string))
177 MODError(String.Format("parameter type mismatch in {0}; expecting {1}",fname,signature[i].Name));
178
179 convertedParms[i] = (string)(LSL_String)parms[i];
180 }
181 else if (parms[i] is LSL_Integer)
182 {
183 if (signature[i] != typeof(int))
184 MODError(String.Format("parameter type mismatch in {0}; expecting {1}",fname,signature[i].Name));
185
186 convertedParms[i] = (int)(LSL_Integer)parms[i];
187 }
188 else if (parms[i] is LSL_Float)
189 {
190 if (signature[i] != typeof(float))
191 MODError(String.Format("parameter type mismatch in {0}; expecting {1}",fname,signature[i].Name));
192
193 convertedParms[i] = (float)(LSL_Float)parms[i];
194 }
195 else if (parms[i] is LSL_Key)
196 {
197 if (signature[i] != typeof(string))
198 MODError(String.Format("parameter type mismatch in {0}; expecting {1}",fname,signature[i].Name));
199
200 convertedParms[i] = (string)(LSL_Key)parms[i];
201 }
202 else if (parms[i] is LSL_Rotation)
203 {
204 if (signature[i] != typeof(string))
205 MODError(String.Format("parameter type mismatch in {0}; expecting {1}",fname,signature[i].Name));
206
207 convertedParms[i] = (string)(LSL_Rotation)parms[i];
208 }
209 else if (parms[i] is LSL_Vector)
210 {
211 if (signature[i] != typeof(string))
212 MODError(String.Format("parameter type mismatch in {0}; expecting {1}",fname,signature[i].Name));
213
214 convertedParms[i] = (string)(LSL_Vector)parms[i];
215 }
216 else
217 {
218 if (signature[i] != parms[i].GetType())
219 MODError(String.Format("parameter type mismatch in {0}; expecting {1}",fname,signature[i].Name));
220
221 convertedParms[i] = parms[i];
222 }
223 }
224
225 return m_comms.InvokeOperation(m_itemID,fname,convertedParms);
226 }
227
119 public string modSendCommand(string module, string command, string k) 228 public string modSendCommand(string module, string command, string k)
120 { 229 {
121 if (!m_MODFunctionsEnabled) 230 if (!m_MODFunctionsEnabled)
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IMOD_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IMOD_Api.cs
index e08eca5..756a59f 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IMOD_Api.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IMOD_Api.cs
@@ -40,6 +40,15 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Interfaces
40{ 40{
41 public interface IMOD_Api 41 public interface IMOD_Api
42 { 42 {
43 // Invocation functions
44 string modInvokeS(string fname, params object[] parms);
45 int modInvokeI(string fname, params object[] parms);
46 float modInvokeF(string fname, params object[] parms);
47 // vector modInvokeV(string fname, params object[] parms);
48 // rotation modInvokeV(string fname, params object[] parms);
49 // key modInvokeK(string fname, params object[] parms);
50 // list modInvokeL(string fname, params object[] parms);
51
43 //Module functions 52 //Module functions
44 string modSendCommand(string modules, string command, string k); 53 string modSendCommand(string modules, string command, string k);
45 } 54 }
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/MOD_Stub.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/MOD_Stub.cs
index 6525c76..04b7f14 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/MOD_Stub.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/MOD_Stub.cs
@@ -58,6 +58,21 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
58 m_MOD_Functions = (IMOD_Api)api; 58 m_MOD_Functions = (IMOD_Api)api;
59 } 59 }
60 60
61 public string modInvokeS(string fname, params object[] parms)
62 {
63 return m_MOD_Functions.modInvokeS(fname, parms);
64 }
65
66 public int modInvokeI(string fname, params object[] parms)
67 {
68 return m_MOD_Functions.modInvokeI(fname, parms);
69 }
70
71 public float modInvokeF(string fname, params object[] parms)
72 {
73 return m_MOD_Functions.modInvokeF(fname, parms);
74 }
75
61 public string modSendCommand(string module, string command, string k) 76 public string modSendCommand(string module, string command, string k)
62 { 77 {
63 return m_MOD_Functions.modSendCommand(module, command, k); 78 return m_MOD_Functions.modSendCommand(module, command, k);
diff --git a/OpenSim/Region/ScriptEngine/Shared/CodeTools/CSCodeGenerator.cs b/OpenSim/Region/ScriptEngine/Shared/CodeTools/CSCodeGenerator.cs
index 65d3b9b..b24f016 100644
--- a/OpenSim/Region/ScriptEngine/Shared/CodeTools/CSCodeGenerator.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/CodeTools/CSCodeGenerator.cs
@@ -32,6 +32,8 @@ using System.Reflection;
32using log4net; 32using log4net;
33using Tools; 33using Tools;
34 34
35using OpenSim.Region.Framework.Interfaces;
36
35namespace OpenSim.Region.ScriptEngine.Shared.CodeTools 37namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
36{ 38{
37 public class CSCodeGenerator : ICodeConverter 39 public class CSCodeGenerator : ICodeConverter
@@ -45,12 +47,20 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
45 private int m_CSharpLine; // the current line of generated C# code 47 private int m_CSharpLine; // the current line of generated C# code
46 private int m_CSharpCol; // the current column of generated C# code 48 private int m_CSharpCol; // the current column of generated C# code
47 private List<string> m_warnings = new List<string>(); 49 private List<string> m_warnings = new List<string>();
50 private IScriptModuleComms m_comms = null;
48 51
49 /// <summary> 52 /// <summary>
50 /// Creates an 'empty' CSCodeGenerator instance. 53 /// Creates an 'empty' CSCodeGenerator instance.
51 /// </summary> 54 /// </summary>
52 public CSCodeGenerator() 55 public CSCodeGenerator()
53 { 56 {
57 m_comms = null;
58 ResetCounters();
59 }
60
61 public CSCodeGenerator(IScriptModuleComms comms)
62 {
63 m_comms = comms;
54 ResetCounters(); 64 ResetCounters();
55 } 65 }
56 66
@@ -866,8 +876,25 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
866 { 876 {
867 string retstr = String.Empty; 877 string retstr = String.Empty;
868 878
869 retstr += Generate(String.Format("{0}(", CheckName(fc.Id)), fc); 879 string modinvoke = null;
870 880 if (m_comms != null)
881 modinvoke = m_comms.LookupModInvocation(fc.Id);
882
883 if (modinvoke != null)
884 {
885 if (fc.kids[0] is ArgumentList)
886 {
887 if ((fc.kids[0] as ArgumentList).kids.Count == 0)
888 retstr += Generate(String.Format("{0}(\"{1}\"",modinvoke,fc.Id), fc);
889 else
890 retstr += Generate(String.Format("{0}(\"{1}\",",modinvoke,fc.Id), fc);
891 }
892 }
893 else
894 {
895 retstr += Generate(String.Format("{0}(", CheckName(fc.Id)), fc);
896 }
897
871 foreach (SYMBOL kid in fc.kids) 898 foreach (SYMBOL kid in fc.kids)
872 retstr += GenerateNode(kid); 899 retstr += GenerateNode(kid);
873 900
diff --git a/OpenSim/Region/ScriptEngine/Shared/CodeTools/Compiler.cs b/OpenSim/Region/ScriptEngine/Shared/CodeTools/Compiler.cs
index c10143b..8f2ec49 100644
--- a/OpenSim/Region/ScriptEngine/Shared/CodeTools/Compiler.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/CodeTools/Compiler.cs
@@ -35,6 +35,7 @@ using Microsoft.CSharp;
35//using Microsoft.JScript; 35//using Microsoft.JScript;
36using Microsoft.VisualBasic; 36using Microsoft.VisualBasic;
37using log4net; 37using log4net;
38
38using OpenSim.Region.Framework.Interfaces; 39using OpenSim.Region.Framework.Interfaces;
39using OpenSim.Region.ScriptEngine.Interfaces; 40using OpenSim.Region.ScriptEngine.Interfaces;
40using OpenMetaverse; 41using OpenMetaverse;
@@ -293,6 +294,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
293 { 294 {
294// m_log.DebugFormat("[Compiler]: Compiling script\n{0}", Script); 295// m_log.DebugFormat("[Compiler]: Compiling script\n{0}", Script);
295 296
297 IScriptModuleComms comms = m_scriptEngine.World.RequestModuleInterface<IScriptModuleComms>();
298
296 linemap = null; 299 linemap = null;
297 m_warnings.Clear(); 300 m_warnings.Clear();
298 301
@@ -382,7 +385,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
382 if (language == enumCompileType.lsl) 385 if (language == enumCompileType.lsl)
383 { 386 {
384 // Its LSL, convert it to C# 387 // Its LSL, convert it to C#
385 LSL_Converter = (ICodeConverter)new CSCodeGenerator(); 388 LSL_Converter = (ICodeConverter)new CSCodeGenerator(comms);
386 compileScript = LSL_Converter.Convert(Script); 389 compileScript = LSL_Converter.Convert(Script);
387 390
388 // copy converter warnings into our warnings. 391 // copy converter warnings into our warnings.