aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/OptionalModules/Scripting
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/OptionalModules/Scripting')
-rw-r--r--OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStoreModule.cs14
-rw-r--r--OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStoreScriptModule.cs2
-rw-r--r--OpenSim/Region/OptionalModules/Scripting/RegionReadyModule/RegionReadyModule.cs2
-rw-r--r--OpenSim/Region/OptionalModules/Scripting/ScriptModuleComms/ScriptModuleCommsModule.cs308
4 files changed, 9 insertions, 317 deletions
diff --git a/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStoreModule.cs b/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStoreModule.cs
index 311531c..732c28f 100644
--- a/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStoreModule.cs
+++ b/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStoreModule.cs
@@ -175,14 +175,15 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
175 /// 175 ///
176 /// </summary> 176 /// </summary>
177 // ----------------------------------------------------------------- 177 // -----------------------------------------------------------------
178 public bool CreateStore(string value, out UUID result) 178 public bool CreateStore(string value, ref UUID result)
179 { 179 {
180 result = UUID.Zero; 180 if (result == UUID.Zero)
181 result = UUID.Random();
182
183 JsonStore map = null;
181 184
182 if (! m_enabled) return false; 185 if (! m_enabled) return false;
183 186
184 UUID uuid = UUID.Random();
185 JsonStore map = null;
186 187
187 try 188 try
188 { 189 {
@@ -195,9 +196,8 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
195 } 196 }
196 197
197 lock (m_JsonValueStore) 198 lock (m_JsonValueStore)
198 m_JsonValueStore.Add(uuid,map); 199 m_JsonValueStore.Add(result,map);
199 200
200 result = uuid;
201 return true; 201 return true;
202 } 202 }
203 203
@@ -231,7 +231,7 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
231 if (! m_JsonValueStore.TryGetValue(storeID,out map)) 231 if (! m_JsonValueStore.TryGetValue(storeID,out map))
232 { 232 {
233 m_log.InfoFormat("[JsonStore] Missing store {0}",storeID); 233 m_log.InfoFormat("[JsonStore] Missing store {0}",storeID);
234 return true; 234 return false;
235 } 235 }
236 } 236 }
237 237
diff --git a/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStoreScriptModule.cs b/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStoreScriptModule.cs
index eaba816..6910d14 100644
--- a/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStoreScriptModule.cs
+++ b/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStoreScriptModule.cs
@@ -227,7 +227,7 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
227 protected UUID JsonCreateStore(UUID hostID, UUID scriptID, string value) 227 protected UUID JsonCreateStore(UUID hostID, UUID scriptID, string value)
228 { 228 {
229 UUID uuid = UUID.Zero; 229 UUID uuid = UUID.Zero;
230 if (! m_store.CreateStore(value, out uuid)) 230 if (! m_store.CreateStore(value, ref uuid))
231 GenerateRuntimeError("Failed to create Json store"); 231 GenerateRuntimeError("Failed to create Json store");
232 232
233 return uuid; 233 return uuid;
diff --git a/OpenSim/Region/OptionalModules/Scripting/RegionReadyModule/RegionReadyModule.cs b/OpenSim/Region/OptionalModules/Scripting/RegionReadyModule/RegionReadyModule.cs
index fff3a32..bad75f7 100644
--- a/OpenSim/Region/OptionalModules/Scripting/RegionReadyModule/RegionReadyModule.cs
+++ b/OpenSim/Region/OptionalModules/Scripting/RegionReadyModule/RegionReadyModule.cs
@@ -181,7 +181,7 @@ namespace OpenSim.Region.OptionalModules.Scripting.RegionReady
181 } 181 }
182 } 182 }
183 183
184 void OnOarFileLoaded(Guid requestId, string message) 184 void OnOarFileLoaded(Guid requestId, List<UUID> loadedScenes, string message)
185 { 185 {
186 m_oarFileLoading = true; 186 m_oarFileLoading = true;
187 187
diff --git a/OpenSim/Region/OptionalModules/Scripting/ScriptModuleComms/ScriptModuleCommsModule.cs b/OpenSim/Region/OptionalModules/Scripting/ScriptModuleComms/ScriptModuleCommsModule.cs
deleted file mode 100644
index 705a847..0000000
--- a/OpenSim/Region/OptionalModules/Scripting/ScriptModuleComms/ScriptModuleCommsModule.cs
+++ /dev/null
@@ -1,308 +0,0 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSimulator Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using System;
29using System.Reflection;
30using System.Collections.Generic;
31using Nini.Config;
32using log4net;
33using OpenSim.Framework;
34using OpenSim.Region.Framework.Interfaces;
35using OpenSim.Region.Framework.Scenes;
36using Mono.Addins;
37using OpenMetaverse;
38using System.Linq;
39using System.Linq.Expressions;
40
41namespace OpenSim.Region.OptionalModules.Scripting.ScriptModuleComms
42{
43 [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "ScriptModuleCommsModule")]
44 class ScriptModuleCommsModule : INonSharedRegionModule, IScriptModuleComms
45 {
46 private static readonly ILog m_log =
47 LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
48
49 private Dictionary<string,object> m_constants = new Dictionary<string,object>();
50
51#region ScriptInvocation
52 protected class ScriptInvocationData
53 {
54 public Delegate ScriptInvocationDelegate { get; private set; }
55 public string FunctionName { get; private set; }
56 public Type[] TypeSignature { get; private set; }
57 public Type ReturnType { get; private set; }
58
59 public ScriptInvocationData(string fname, Delegate fn, Type[] callsig, Type returnsig)
60 {
61 FunctionName = fname;
62 ScriptInvocationDelegate = fn;
63 TypeSignature = callsig;
64 ReturnType = returnsig;
65 }
66 }
67
68 private Dictionary<string,ScriptInvocationData> m_scriptInvocation = new Dictionary<string,ScriptInvocationData>();
69#endregion
70
71 private IScriptModule m_scriptModule = null;
72 public event ScriptCommand OnScriptCommand;
73
74#region RegionModuleInterface
75 public void Initialise(IConfigSource config)
76 {
77 }
78
79 public void AddRegion(Scene scene)
80 {
81 scene.RegisterModuleInterface<IScriptModuleComms>(this);
82 }
83
84 public void RemoveRegion(Scene scene)
85 {
86 }
87
88 public void RegionLoaded(Scene scene)
89 {
90 m_scriptModule = scene.RequestModuleInterface<IScriptModule>();
91
92 if (m_scriptModule != null)
93 m_log.Info("[MODULE COMMANDS]: Script engine found, module active");
94 }
95
96 public string Name
97 {
98 get { return "ScriptModuleCommsModule"; }
99 }
100
101 public Type ReplaceableInterface
102 {
103 get { return null; }
104 }
105
106 public void Close()
107 {
108 }
109#endregion
110
111#region ScriptModuleComms
112
113 public void RaiseEvent(UUID script, string id, string module, string command, string k)
114 {
115 ScriptCommand c = OnScriptCommand;
116
117 if (c == null)
118 return;
119
120 c(script, id, module, command, k);
121 }
122
123 public void DispatchReply(UUID script, int code, string text, string k)
124 {
125 if (m_scriptModule == null)
126 return;
127
128 Object[] args = new Object[] {-1, code, text, k};
129
130 m_scriptModule.PostScriptEvent(script, "link_message", args);
131 }
132
133 public void RegisterScriptInvocation(object target, string meth)
134 {
135 MethodInfo mi = target.GetType().GetMethod(meth,
136 BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance);
137 if (mi == null)
138 {
139 m_log.WarnFormat("[MODULE COMMANDS] Failed to register method {0}",meth);
140 return;
141 }
142
143 RegisterScriptInvocation(target, mi);
144 }
145
146 public void RegisterScriptInvocation(object target, string[] meth)
147 {
148 foreach (string m in meth)
149 RegisterScriptInvocation(target, m);
150 }
151
152 public void RegisterScriptInvocation(object target, MethodInfo mi)
153 {
154 m_log.DebugFormat("[MODULE COMMANDS] Register method {0} from type {1}", mi.Name, target.GetType().Name);
155
156 Type delegateType;
157 var typeArgs = mi.GetParameters()
158 .Select(p => p.ParameterType)
159 .ToList();
160
161 if (mi.ReturnType == typeof(void))
162 {
163 delegateType = Expression.GetActionType(typeArgs.ToArray());
164 }
165 else
166 {
167 typeArgs.Add(mi.ReturnType);
168 delegateType = Expression.GetFuncType(typeArgs.ToArray());
169 }
170
171 Delegate fcall = Delegate.CreateDelegate(delegateType, target, mi);
172
173 lock (m_scriptInvocation)
174 {
175 ParameterInfo[] parameters = fcall.Method.GetParameters ();
176 if (parameters.Length < 2) // Must have two UUID params
177 return;
178
179 // Hide the first two parameters
180 Type[] parmTypes = new Type[parameters.Length - 2];
181 for (int i = 2 ; i < parameters.Length ; i++)
182 parmTypes[i - 2] = parameters[i].ParameterType;
183 m_scriptInvocation[fcall.Method.Name] = new ScriptInvocationData(fcall.Method.Name, fcall, parmTypes, fcall.Method.ReturnType);
184 }
185 }
186
187 public Delegate[] GetScriptInvocationList()
188 {
189 List<Delegate> ret = new List<Delegate>();
190
191 lock (m_scriptInvocation)
192 {
193 foreach (ScriptInvocationData d in m_scriptInvocation.Values)
194 ret.Add(d.ScriptInvocationDelegate);
195 }
196 return ret.ToArray();
197 }
198
199 public string LookupModInvocation(string fname)
200 {
201 lock (m_scriptInvocation)
202 {
203 ScriptInvocationData sid;
204 if (m_scriptInvocation.TryGetValue(fname,out sid))
205 {
206 if (sid.ReturnType == typeof(string))
207 return "modInvokeS";
208 else if (sid.ReturnType == typeof(int))
209 return "modInvokeI";
210 else if (sid.ReturnType == typeof(float))
211 return "modInvokeF";
212 else if (sid.ReturnType == typeof(UUID))
213 return "modInvokeK";
214 else if (sid.ReturnType == typeof(OpenMetaverse.Vector3))
215 return "modInvokeV";
216 else if (sid.ReturnType == typeof(OpenMetaverse.Quaternion))
217 return "modInvokeR";
218 else if (sid.ReturnType == typeof(object[]))
219 return "modInvokeL";
220
221 m_log.WarnFormat("[MODULE COMMANDS] failed to find match for {0} with return type {1}",fname,sid.ReturnType.Name);
222 }
223 }
224
225 return null;
226 }
227
228 public Delegate LookupScriptInvocation(string fname)
229 {
230 lock (m_scriptInvocation)
231 {
232 ScriptInvocationData sid;
233 if (m_scriptInvocation.TryGetValue(fname,out sid))
234 return sid.ScriptInvocationDelegate;
235 }
236
237 return null;
238 }
239
240 public Type[] LookupTypeSignature(string fname)
241 {
242 lock (m_scriptInvocation)
243 {
244 ScriptInvocationData sid;
245 if (m_scriptInvocation.TryGetValue(fname,out sid))
246 return sid.TypeSignature;
247 }
248
249 return null;
250 }
251
252 public Type LookupReturnType(string fname)
253 {
254 lock (m_scriptInvocation)
255 {
256 ScriptInvocationData sid;
257 if (m_scriptInvocation.TryGetValue(fname,out sid))
258 return sid.ReturnType;
259 }
260
261 return null;
262 }
263
264 public object InvokeOperation(UUID hostid, UUID scriptid, string fname, params object[] parms)
265 {
266 List<object> olist = new List<object>();
267 olist.Add(hostid);
268 olist.Add(scriptid);
269 foreach (object o in parms)
270 olist.Add(o);
271 Delegate fn = LookupScriptInvocation(fname);
272 return fn.DynamicInvoke(olist.ToArray());
273 }
274
275 /// <summary>
276 /// Operation to for a region module to register a constant to be used
277 /// by the script engine
278 /// </summary>
279 public void RegisterConstant(string cname, object value)
280 {
281 m_log.DebugFormat("[MODULE COMMANDS] register constant <{0}> with value {1}",cname,value.ToString());
282 lock (m_constants)
283 {
284 m_constants.Add(cname,value);
285 }
286 }
287
288 /// <summary>
289 /// Operation to check for a registered constant
290 /// </summary>
291 public object LookupModConstant(string cname)
292 {
293 // m_log.DebugFormat("[MODULE COMMANDS] lookup constant <{0}>",cname);
294
295 lock (m_constants)
296 {
297 object value = null;
298 if (m_constants.TryGetValue(cname,out value))
299 return value;
300 }
301
302 return null;
303 }
304
305#endregion
306
307 }
308}