diff options
Diffstat (limited to 'OpenSim/Region/OptionalModules/Scripting')
-rw-r--r-- | OpenSim/Region/OptionalModules/Scripting/RegionReadyModule/RegionReadyModule.cs | 15 | ||||
-rw-r--r-- | OpenSim/Region/OptionalModules/Scripting/ScriptModuleComms/ScriptModuleCommsModule.cs | 95 |
2 files changed, 90 insertions, 20 deletions
diff --git a/OpenSim/Region/OptionalModules/Scripting/RegionReadyModule/RegionReadyModule.cs b/OpenSim/Region/OptionalModules/Scripting/RegionReadyModule/RegionReadyModule.cs index d0142a4..0b9f875 100644 --- a/OpenSim/Region/OptionalModules/Scripting/RegionReadyModule/RegionReadyModule.cs +++ b/OpenSim/Region/OptionalModules/Scripting/RegionReadyModule/RegionReadyModule.cs | |||
@@ -70,8 +70,6 @@ namespace OpenSim.Region.OptionalModules.Scripting.RegionReady | |||
70 | 70 | ||
71 | public void Initialise(IConfigSource config) | 71 | public void Initialise(IConfigSource config) |
72 | { | 72 | { |
73 | //m_log.Info("[RegionReady] Initialising"); | ||
74 | |||
75 | m_config = config.Configs["RegionReady"]; | 73 | m_config = config.Configs["RegionReady"]; |
76 | if (m_config != null) | 74 | if (m_config != null) |
77 | { | 75 | { |
@@ -84,9 +82,6 @@ namespace OpenSim.Region.OptionalModules.Scripting.RegionReady | |||
84 | m_uri = m_config.GetString("alert_uri",string.Empty); | 82 | m_uri = m_config.GetString("alert_uri",string.Empty); |
85 | } | 83 | } |
86 | } | 84 | } |
87 | |||
88 | // if (!m_enabled) | ||
89 | // m_log.Info("[RegionReady] disabled."); | ||
90 | } | 85 | } |
91 | 86 | ||
92 | public void AddRegion(Scene scene) | 87 | public void AddRegion(Scene scene) |
@@ -113,7 +108,7 @@ namespace OpenSim.Region.OptionalModules.Scripting.RegionReady | |||
113 | { | 108 | { |
114 | scene.LoginLock = true; | 109 | scene.LoginLock = true; |
115 | scene.LoginsDisabled = true; | 110 | scene.LoginsDisabled = true; |
116 | m_log.InfoFormat("[RegionReady]: Logins disabled for {0}",m_scene.RegionInfo.RegionName); | 111 | m_log.InfoFormat("[RegionReady]: Region {0} - logins disabled during initialization.",m_scene.RegionInfo.RegionName); |
117 | 112 | ||
118 | if(m_uri != string.Empty) | 113 | if(m_uri != string.Empty) |
119 | { | 114 | { |
@@ -167,7 +162,7 @@ namespace OpenSim.Region.OptionalModules.Scripting.RegionReady | |||
167 | 162 | ||
168 | void OnEmptyScriptCompileQueue(int numScriptsFailed, string message) | 163 | void OnEmptyScriptCompileQueue(int numScriptsFailed, string message) |
169 | { | 164 | { |
170 | m_log.InfoFormat("[RegionReady]: Script compile queue empty!"); | 165 | m_log.DebugFormat("[RegionReady]: Script compile queue empty!"); |
171 | 166 | ||
172 | if (m_firstEmptyCompileQueue || m_oarFileLoading) | 167 | if (m_firstEmptyCompileQueue || m_oarFileLoading) |
173 | { | 168 | { |
@@ -194,7 +189,7 @@ namespace OpenSim.Region.OptionalModules.Scripting.RegionReady | |||
194 | c.SenderUUID = UUID.Zero; | 189 | c.SenderUUID = UUID.Zero; |
195 | c.Scene = m_scene; | 190 | c.Scene = m_scene; |
196 | 191 | ||
197 | m_log.InfoFormat("[RegionReady]: Region \"{0}\" is ready: \"{1}\" on channel {2}", | 192 | m_log.DebugFormat("[RegionReady]: Region \"{0}\" is ready: \"{1}\" on channel {2}", |
198 | m_scene.RegionInfo.RegionName, c.Message, m_channelNotify); | 193 | m_scene.RegionInfo.RegionName, c.Message, m_channelNotify); |
199 | 194 | ||
200 | m_scene.EventManager.TriggerOnChatBroadcast(this, c); | 195 | m_scene.EventManager.TriggerOnChatBroadcast(this, c); |
@@ -210,7 +205,7 @@ namespace OpenSim.Region.OptionalModules.Scripting.RegionReady | |||
210 | { | 205 | { |
211 | m_lastOarLoadedOk = true; | 206 | m_lastOarLoadedOk = true; |
212 | } else { | 207 | } else { |
213 | m_log.InfoFormat("[RegionReady]: Oar file load errors: {0}", message); | 208 | m_log.WarnFormat("[RegionReady]: Oar file load errors: {0}", message); |
214 | m_lastOarLoadedOk = false; | 209 | m_lastOarLoadedOk = false; |
215 | } | 210 | } |
216 | } | 211 | } |
@@ -233,7 +228,7 @@ namespace OpenSim.Region.OptionalModules.Scripting.RegionReady | |||
233 | // m_log.InfoFormat("[RegionReady]: Logins enabled for {0}, Oar {1}", | 228 | // m_log.InfoFormat("[RegionReady]: Logins enabled for {0}, Oar {1}", |
234 | // m_scene.RegionInfo.RegionName, m_oarFileLoading.ToString()); | 229 | // m_scene.RegionInfo.RegionName, m_oarFileLoading.ToString()); |
235 | 230 | ||
236 | m_log.InfoFormat("[RegionReady]: Logins enabled for {0}", m_scene.RegionInfo.RegionName); | 231 | m_log.InfoFormat("[RegionReady]: Initialization complete - logins enabled for {0}", m_scene.RegionInfo.RegionName); |
237 | 232 | ||
238 | if ( m_uri != string.Empty ) | 233 | if ( m_uri != string.Empty ) |
239 | { | 234 | { |
diff --git a/OpenSim/Region/OptionalModules/Scripting/ScriptModuleComms/ScriptModuleCommsModule.cs b/OpenSim/Region/OptionalModules/Scripting/ScriptModuleComms/ScriptModuleCommsModule.cs index a90362e..cab30de 100644 --- a/OpenSim/Region/OptionalModules/Scripting/ScriptModuleComms/ScriptModuleCommsModule.cs +++ b/OpenSim/Region/OptionalModules/Scripting/ScriptModuleComms/ScriptModuleCommsModule.cs | |||
@@ -35,6 +35,8 @@ using OpenSim.Region.Framework.Interfaces; | |||
35 | using OpenSim.Region.Framework.Scenes; | 35 | using OpenSim.Region.Framework.Scenes; |
36 | using Mono.Addins; | 36 | using Mono.Addins; |
37 | using OpenMetaverse; | 37 | using OpenMetaverse; |
38 | using System.Linq; | ||
39 | using System.Linq.Expressions; | ||
38 | 40 | ||
39 | namespace OpenSim.Region.CoreModules.Scripting.ScriptModuleComms | 41 | namespace OpenSim.Region.CoreModules.Scripting.ScriptModuleComms |
40 | { | 42 | { |
@@ -47,15 +49,15 @@ namespace OpenSim.Region.CoreModules.Scripting.ScriptModuleComms | |||
47 | #region ScriptInvocation | 49 | #region ScriptInvocation |
48 | protected class ScriptInvocationData | 50 | protected class ScriptInvocationData |
49 | { | 51 | { |
50 | public ScriptInvocation ScriptInvocationFn { get; private set; } | 52 | public Delegate ScriptInvocationDelegate { get; private set; } |
51 | public string FunctionName { get; private set; } | 53 | public string FunctionName { get; private set; } |
52 | public Type[] TypeSignature { get; private set; } | 54 | public Type[] TypeSignature { get; private set; } |
53 | public Type ReturnType { get; private set; } | 55 | public Type ReturnType { get; private set; } |
54 | 56 | ||
55 | public ScriptInvocationData(string fname, ScriptInvocation fn, Type[] callsig, Type returnsig) | 57 | public ScriptInvocationData(string fname, Delegate fn, Type[] callsig, Type returnsig) |
56 | { | 58 | { |
57 | FunctionName = fname; | 59 | FunctionName = fname; |
58 | ScriptInvocationFn = fn; | 60 | ScriptInvocationDelegate = fn; |
59 | TypeSignature = callsig; | 61 | TypeSignature = callsig; |
60 | ReturnType = returnsig; | 62 | ReturnType = returnsig; |
61 | } | 63 | } |
@@ -126,14 +128,72 @@ namespace OpenSim.Region.CoreModules.Scripting.ScriptModuleComms | |||
126 | m_scriptModule.PostScriptEvent(script, "link_message", args); | 128 | m_scriptModule.PostScriptEvent(script, "link_message", args); |
127 | } | 129 | } |
128 | 130 | ||
129 | public void RegisterScriptInvocation(string fname, ScriptInvocation fcall, Type[] csig, Type rsig) | 131 | public void RegisterScriptInvocation(object target, string meth) |
130 | { | 132 | { |
133 | MethodInfo mi = target.GetType().GetMethod(meth, | ||
134 | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance); | ||
135 | if (mi == null) | ||
136 | { | ||
137 | m_log.WarnFormat("[MODULE COMMANDS] Failed to register method {0}",meth); | ||
138 | return; | ||
139 | } | ||
140 | |||
141 | RegisterScriptInvocation(target, mi); | ||
142 | } | ||
143 | |||
144 | public void RegisterScriptInvocation(object target, string[] meth) | ||
145 | { | ||
146 | foreach (string m in meth) | ||
147 | RegisterScriptInvocation(target, m); | ||
148 | } | ||
149 | |||
150 | public void RegisterScriptInvocation(object target, MethodInfo mi) | ||
151 | { | ||
152 | m_log.DebugFormat("[MODULE COMMANDS] Register method {0} from type {1}", mi.Name, target.GetType().Name); | ||
153 | |||
154 | Type delegateType; | ||
155 | var typeArgs = mi.GetParameters() | ||
156 | .Select(p => p.ParameterType) | ||
157 | .ToList(); | ||
158 | |||
159 | if (mi.ReturnType == typeof(void)) | ||
160 | { | ||
161 | delegateType = Expression.GetActionType(typeArgs.ToArray()); | ||
162 | } | ||
163 | else | ||
164 | { | ||
165 | typeArgs.Add(mi.ReturnType); | ||
166 | delegateType = Expression.GetFuncType(typeArgs.ToArray()); | ||
167 | } | ||
168 | |||
169 | Delegate fcall = Delegate.CreateDelegate(delegateType, target, mi); | ||
170 | |||
131 | lock (m_scriptInvocation) | 171 | lock (m_scriptInvocation) |
132 | { | 172 | { |
133 | m_scriptInvocation[fname] = new ScriptInvocationData(fname,fcall,csig,rsig); | 173 | ParameterInfo[] parameters = fcall.Method.GetParameters (); |
174 | if (parameters.Length < 2) // Must have two UUID params | ||
175 | return; | ||
176 | |||
177 | // Hide the first two parameters | ||
178 | Type[] parmTypes = new Type[parameters.Length - 2]; | ||
179 | for (int i = 2 ; i < parameters.Length ; i++) | ||
180 | parmTypes[i - 2] = parameters[i].ParameterType; | ||
181 | m_scriptInvocation[fcall.Method.Name] = new ScriptInvocationData(fcall.Method.Name, fcall, parmTypes, fcall.Method.ReturnType); | ||
134 | } | 182 | } |
135 | } | 183 | } |
136 | 184 | ||
185 | public Delegate[] GetScriptInvocationList() | ||
186 | { | ||
187 | List<Delegate> ret = new List<Delegate>(); | ||
188 | |||
189 | lock (m_scriptInvocation) | ||
190 | { | ||
191 | foreach (ScriptInvocationData d in m_scriptInvocation.Values) | ||
192 | ret.Add(d.ScriptInvocationDelegate); | ||
193 | } | ||
194 | return ret.ToArray(); | ||
195 | } | ||
196 | |||
137 | public string LookupModInvocation(string fname) | 197 | public string LookupModInvocation(string fname) |
138 | { | 198 | { |
139 | lock (m_scriptInvocation) | 199 | lock (m_scriptInvocation) |
@@ -147,19 +207,29 @@ namespace OpenSim.Region.CoreModules.Scripting.ScriptModuleComms | |||
147 | return "modInvokeI"; | 207 | return "modInvokeI"; |
148 | else if (sid.ReturnType == typeof(float)) | 208 | else if (sid.ReturnType == typeof(float)) |
149 | return "modInvokeF"; | 209 | return "modInvokeF"; |
210 | else if (sid.ReturnType == typeof(UUID)) | ||
211 | return "modInvokeK"; | ||
212 | else if (sid.ReturnType == typeof(OpenMetaverse.Vector3)) | ||
213 | return "modInvokeV"; | ||
214 | else if (sid.ReturnType == typeof(OpenMetaverse.Quaternion)) | ||
215 | return "modInvokeR"; | ||
216 | else if (sid.ReturnType == typeof(object[])) | ||
217 | return "modInvokeL"; | ||
218 | |||
219 | m_log.WarnFormat("[MODULE COMMANDS] failed to find match for {0} with return type {1}",fname,sid.ReturnType.Name); | ||
150 | } | 220 | } |
151 | } | 221 | } |
152 | 222 | ||
153 | return null; | 223 | return null; |
154 | } | 224 | } |
155 | 225 | ||
156 | public ScriptInvocation LookupScriptInvocation(string fname) | 226 | public Delegate LookupScriptInvocation(string fname) |
157 | { | 227 | { |
158 | lock (m_scriptInvocation) | 228 | lock (m_scriptInvocation) |
159 | { | 229 | { |
160 | ScriptInvocationData sid; | 230 | ScriptInvocationData sid; |
161 | if (m_scriptInvocation.TryGetValue(fname,out sid)) | 231 | if (m_scriptInvocation.TryGetValue(fname,out sid)) |
162 | return sid.ScriptInvocationFn; | 232 | return sid.ScriptInvocationDelegate; |
163 | } | 233 | } |
164 | 234 | ||
165 | return null; | 235 | return null; |
@@ -189,10 +259,15 @@ namespace OpenSim.Region.CoreModules.Scripting.ScriptModuleComms | |||
189 | return null; | 259 | return null; |
190 | } | 260 | } |
191 | 261 | ||
192 | public object InvokeOperation(UUID scriptid, string fname, params object[] parms) | 262 | public object InvokeOperation(UUID hostid, UUID scriptid, string fname, params object[] parms) |
193 | { | 263 | { |
194 | ScriptInvocation fn = LookupScriptInvocation(fname); | 264 | List<object> olist = new List<object>(); |
195 | return fn(scriptid,parms); | 265 | olist.Add(hostid); |
266 | olist.Add(scriptid); | ||
267 | foreach (object o in parms) | ||
268 | olist.Add(o); | ||
269 | Delegate fn = LookupScriptInvocation(fname); | ||
270 | return fn.DynamicInvoke(olist.ToArray()); | ||
196 | } | 271 | } |
197 | #endregion | 272 | #endregion |
198 | 273 | ||