29 using System.Reflection;
30 using System.Collections;
31 using System.Collections.Generic;
32 using System.Runtime.Remoting.Lifetime;
33 using System.Threading;
38 using OpenSim.Framework;
39 using OpenSim.Region.Framework.Interfaces;
40 using OpenSim.Region.Framework.Scenes;
41 using OpenSim.Region.ScriptEngine.Shared;
42 using OpenSim.Region.ScriptEngine.Shared.Api.Plugins;
43 using OpenSim.Region.ScriptEngine.Shared.ScriptBase;
44 using OpenSim.Region.ScriptEngine.Interfaces;
45 using OpenSim.Region.ScriptEngine.Shared.Api.Interfaces;
65 internal bool m_MODFunctionsEnabled =
false;
71 m_ScriptEngine = scriptEngine;
75 if (m_ScriptEngine.Config.GetBoolean(
"AllowMODFunctions",
false))
76 m_MODFunctionsEnabled =
true;
80 m_MODFunctionsEnabled =
false;
85 ILease lease = (ILease)base.InitializeLifetimeService();
87 if (lease.CurrentState == LeaseState.Initial)
89 lease.InitialLeaseTime = TimeSpan.FromMinutes(0);
98 get {
return m_ScriptEngine.World; }
101 internal void MODError(
string msg)
110 internal void MODShoutError(
string message)
112 if (message.Length > 1023)
113 message = message.Substring(0, 1023);
116 Utils.StringToBytes(message),
118 m_host.ParentGroup.RootPart.AbsolutePosition, m_host.Name, m_host.UUID,
false);
121 wComm.DeliverMessage(ChatTypeEnum.Shout, ScriptBaseClass.DEBUG_CHANNEL, m_host.Name, m_host.UUID, message);
138 Type returntype = m_comms.LookupReturnType(fname);
139 if (returntype != typeof(
void))
140 MODError(
String.Format(
"return type mismatch for {0}",fname));
142 modInvoke(fname,parms);
153 Type returntype = m_comms.LookupReturnType(fname);
154 if (returntype != typeof(
string))
155 MODError(
String.Format(
"return type mismatch for {0}",fname));
157 string result = (string)modInvoke(fname,parms);
169 Type returntype = m_comms.LookupReturnType(fname);
170 if (returntype != typeof(
int))
171 MODError(
String.Format(
"return type mismatch for {0}",fname));
173 int result = (int)modInvoke(fname,parms);
185 Type returntype = m_comms.LookupReturnType(fname);
186 if (returntype != typeof(
float))
187 MODError(
String.Format(
"return type mismatch for {0}",fname));
189 float result = (float)modInvoke(fname,parms);
201 Type returntype = m_comms.LookupReturnType(fname);
202 if (returntype != typeof(
UUID))
203 MODError(
String.Format(
"return type mismatch for {0}",fname));
205 UUID result = (
UUID)modInvoke(fname,parms);
206 return new LSL_Key(result.ToString());
217 Type returntype = m_comms.LookupReturnType(fname);
218 if (returntype != typeof(OpenMetaverse.Vector3))
219 MODError(
String.Format(
"return type mismatch for {0}",fname));
221 OpenMetaverse.Vector3 result = (OpenMetaverse.Vector3)modInvoke(fname,parms);
222 return new LSL_Vector(result.X,result.Y,result.Z);
233 Type returntype = m_comms.LookupReturnType(fname);
234 if (returntype != typeof(OpenMetaverse.Quaternion))
235 MODError(
String.Format(
"return type mismatch for {0}",fname));
237 OpenMetaverse.Quaternion result = (OpenMetaverse.Quaternion)modInvoke(fname,parms);
238 return new LSL_Rotation(result.X,result.Y,result.Z,result.W);
249 Type returntype = m_comms.LookupReturnType(fname);
250 if (returntype != typeof(
object[]))
251 MODError(
String.Format(
"return type mismatch for {0}",fname));
253 object[] result = (
object[])modInvoke(fname,parms);
254 object[] llist =
new object[result.Length];
255 for (
int i = 0; i < result.Length; i++)
257 if (result[i] is
string)
261 else if (result[i] is
int)
265 else if (result[i] is
float)
267 llist[i] =
new LSL_Float((
float)result[i]);
269 else if (result[i] is
double)
271 llist[i] =
new LSL_Float((
double)result[i]);
273 else if (result[i] is
UUID)
275 llist[i] =
new LSL_Key(result[i].ToString());
277 else if (result[i] is OpenMetaverse.Vector3)
279 OpenMetaverse.Vector3 vresult = (OpenMetaverse.Vector3)result[i];
280 llist[i] =
new LSL_Vector(vresult.X, vresult.Y, vresult.Z);
282 else if (result[i] is OpenMetaverse.Quaternion)
284 OpenMetaverse.Quaternion qresult = (OpenMetaverse.Quaternion)result[i];
285 llist[i] =
new LSL_Rotation(qresult.X, qresult.Y, qresult.Z, qresult.W);
289 MODError(
String.Format(
"unknown list element {1} returned by {0}", fname, result[i].GetType().Name));
302 protected object modInvoke(
string fname, params
object[] parms)
304 if (!m_MODFunctionsEnabled)
306 MODShoutError(
"Module command functions not enabled");
316 Type[] signature = m_comms.LookupTypeSignature(fname);
317 if (signature.Length != parms.Length)
318 MODError(
String.Format(
"wrong number of parameters to function {0}",fname));
320 object[] convertedParms =
new object[parms.Length];
321 for (
int i = 0; i < parms.Length; i++)
322 convertedParms[i] = ConvertFromLSL(parms[i], signature[i], fname);
328 object result = m_comms.InvokeOperation(m_host.UUID, m_item.ItemID, fname, convertedParms);
332 Type returntype = m_comms.LookupReturnType(fname);
333 if (returntype == typeof(
void))
336 MODError(
String.Format(
"Invocation of {0} failed; null return value",fname));
340 MODError(
String.Format(
"Invocation of {0} failed; {1}",fname,e.Message));
351 if (!m_MODFunctionsEnabled)
353 MODShoutError(
"Module command functions not enabled");
354 return UUID.Zero.ToString();;
357 UUID req = UUID.Random();
359 m_comms.RaiseEvent(m_item.ItemID, req.ToString(), module, command, k);
361 return req.ToString();
371 if (type == typeof(
string))
375 if (type == typeof(
UUID))
382 if (type == typeof(
int) || type == typeof(
float))
389 if (type == typeof(
float))
396 if (type == typeof(
UUID))
397 return new UUID((LSL_Key)lslparm);
403 if (type == typeof(OpenMetaverse.Quaternion))
405 return (OpenMetaverse.Quaternion)((
LSL_Rotation)lslparm);
412 if (type == typeof(OpenMetaverse.Vector3))
414 return (OpenMetaverse.Vector3)((
LSL_Vector)lslparm);
421 if (type == typeof(
object[]))
423 object[] plist = ((
LSL_List)lslparm).Data;
424 object[] result =
new object[plist.Length];
425 for (
int i = 0; i < plist.Length; i++)
427 if (plist[i] is LSL_String)
428 result[i] = (string)(LSL_String)plist[i];
429 else if (plist[i] is LSL_Integer)
430 result[i] = (int)(LSL_Integer)plist[i];
433 else if (plist[i] is
int)
434 result[i] = plist[i];
435 else if (plist[i] is LSL_Float)
436 result[i] = (float)(LSL_Float)plist[i];
437 else if (plist[i] is LSL_Key)
438 result[i] =
new UUID((LSL_Key)plist[i]);
439 else if (plist[i] is LSL_Rotation)
440 result[i] = (Quaternion)((LSL_Rotation)plist[i]);
441 else if (plist[i] is LSL_Vector)
442 result[i] = (Vector3)((LSL_Vector)plist[i]);
444 MODError(
String.Format(
"{0}: unknown LSL list element type", fname));
451 MODError(
String.Format(
"{0}: parameter type mismatch; expecting {1}, type(parm)={2}", fname, type.Name, lslparm.GetType()));
LSL_Key modInvokeK(string fname, params object[] parms)
LSL_List modInvokeL(string fname, params object[] parms)
void Initialize(IScriptEngine scriptEngine, SceneObjectPart host, TaskInventoryItem item)
Initialize the API
OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLFloat LSL_Float
OpenSim.Region.ScriptEngine.Shared.LSL_Types.list LSL_List
OpenSim.Region.ScriptEngine.Shared.LSL_Types.list LSL_List
OpenSim.Region.ScriptEngine.Shared.LSL_Types.Vector3 LSL_Vector
LSL_Integer modInvokeI(string fname, params object[] parms)
OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLString LSL_Key
LSL_String modInvokeS(string fname, params object[] parms)
LSL_Vector modInvokeV(string fname, params object[] parms)
Represents an item in a task inventory
OpenSim.Region.ScriptEngine.Shared.LSL_Types.Vector3 LSL_Vector
LSL_Float modInvokeF(string fname, params object[] parms)
An interface for a script API module to communicate with the engine it's running under ...
OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLFloat LSL_Float
object ConvertFromLSL(object lslparm, Type type, string fname)
LSL_Rotation modInvokeR(string fname, params object[] parms)
string modSendCommand(string module, string command, string k)
Send a command to functions registered on an event
OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLString LSL_Key
OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLInteger LSL_Integer
Interface for communication between OpenSim modules and in-world scripts
OpenSim.Region.ScriptEngine.Shared.LSL_Types.Quaternion LSL_Rotation
void modInvokeN(string fname, params object[] parms)
OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLInteger LSL_Integer
override Object InitializeLifetimeService()
OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLString LSL_String
Interactive OpenSim region server
OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLInteger LSLInteger
object modInvoke(string fname, params object[] parms)
Invokes a preregistered function through the ScriptModuleComms class
OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLString LSL_String
OpenSim.Region.ScriptEngine.Shared.LSL_Types.Quaternion LSL_Rotation