mirror of
https://github.com/opensim/opensim.git
synced 2026-08-01 06:06:06 +08:00
Add an extension to allow registering multiple interfaces of a type with
Scene. Make the script engines check that the engine name in the //Engine:language comment is a valid engine and treat it as a normal comment if it's not. //DotNetEngine: needs to be written as //ScriptEngine.DotNetEngine: now, since that is it's real internal name. //XEngine: still works
This commit is contained in:
@@ -215,6 +215,12 @@ namespace OpenSim.Region.ScriptEngine.Common.ScriptEngineBase
|
||||
|
||||
public void OnRezScript(uint localID, UUID itemID, string script, int startParam, bool postOnRez, string engine)
|
||||
{
|
||||
List<IScriptModule> engines = new List<IScriptModule>(myScriptEngine.World.RequestModuleInterfaces<IScriptModule>());
|
||||
|
||||
List<string> names = new List<string>();
|
||||
foreach (IScriptModule m in engines)
|
||||
names.Add(m.ScriptEngineName);
|
||||
|
||||
int lineEnd = script.IndexOf('\n');
|
||||
|
||||
if (lineEnd != 1)
|
||||
@@ -224,8 +230,13 @@ namespace OpenSim.Region.ScriptEngine.Common.ScriptEngineBase
|
||||
int colon = firstline.IndexOf(':');
|
||||
if (firstline.Length > 2 && firstline.Substring(0, 2) == "//" && colon != -1)
|
||||
{
|
||||
engine = firstline.Substring(2, colon-2);
|
||||
script = "//" + script.Substring(script.IndexOf(':')+1);
|
||||
string engineName = firstline.Substring(2, colon-2);
|
||||
|
||||
if (names.Contains(engineName))
|
||||
{
|
||||
engine = engineName;
|
||||
script = "//" + script.Substring(script.IndexOf(':')+1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -282,7 +282,7 @@ namespace OpenSim.Region.ScriptEngine.Common.ScriptEngineBase
|
||||
// QIS.functionName);
|
||||
#endif
|
||||
// Only pipe event if land supports it.
|
||||
if (m_ScriptEngine.World.pipeEventsForScript(QIS.localID))
|
||||
if (m_ScriptEngine.World.PipeEventsForScript(QIS.localID))
|
||||
{
|
||||
LastExecutionStarted = DateTime.Now.Ticks;
|
||||
KillCurrentScript = false;
|
||||
|
||||
@@ -30,6 +30,7 @@ using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
using log4net;
|
||||
using Nini.Config;
|
||||
using OpenSim.Region.Interfaces;
|
||||
using OpenSim.Region.Environment.Interfaces;
|
||||
using OpenSim.Region.Environment.Scenes;
|
||||
using OpenSim.Region.ScriptEngine.Interfaces;
|
||||
@@ -43,7 +44,7 @@ namespace OpenSim.Region.ScriptEngine.Common.ScriptEngineBase
|
||||
/// </summary>
|
||||
///
|
||||
[Serializable]
|
||||
public abstract class ScriptEngine : IRegionModule, ScriptServerInterfaces.ScriptEngine, iScriptEngineFunctionModule, IEventReceiver
|
||||
public abstract class ScriptEngine : IRegionModule, IScriptModule, ScriptServerInterfaces.ScriptEngine, iScriptEngineFunctionModule, IEventReceiver
|
||||
{
|
||||
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
|
||||
|
||||
@@ -126,8 +127,7 @@ namespace OpenSim.Region.ScriptEngine.Common.ScriptEngineBase
|
||||
m_log.Info("[" + ScriptEngineName + "]: Reading configuration from config section \"" + ScriptEngineName + "\"");
|
||||
ReadConfig();
|
||||
|
||||
// Should we iterate the region for scripts that needs starting?
|
||||
// Or can we assume we are loaded before anything else so we can use proper events?
|
||||
m_Scene.StackModuleInterface<IScriptModule>(this);
|
||||
}
|
||||
|
||||
public void PostInitialise()
|
||||
|
||||
@@ -5114,7 +5114,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
|
||||
public LSL_Integer llScriptDanger(LSL_Vector pos)
|
||||
{
|
||||
m_host.AddScriptLPS(1);
|
||||
bool result = World.scriptDanger(m_host.LocalId, new Vector3((float)pos.x, (float)pos.y, (float)pos.z));
|
||||
bool result = World.ScriptDanger(m_host.LocalId, new Vector3((float)pos.x, (float)pos.y, (float)pos.z));
|
||||
if (result)
|
||||
{
|
||||
return 1;
|
||||
|
||||
@@ -567,85 +567,89 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
|
||||
}
|
||||
else
|
||||
{
|
||||
SceneObjectPart part = m_Engine.World.GetSceneObjectPart(
|
||||
m_LocalID);
|
||||
// m_Engine.Log.DebugFormat("[Script] Delivered event {2} in state {3} to {0}.{1}",
|
||||
// m_PrimName, m_ScriptName, data.EventName, m_State);
|
||||
|
||||
try
|
||||
if (m_Engine.World.PipeEventsForScript(m_LocalID) ||
|
||||
data.EventName == "control") // Don't freeze avies!
|
||||
{
|
||||
m_CurrentEvent = data.EventName;
|
||||
m_EventStart = DateTime.Now;
|
||||
m_InEvent = true;
|
||||
SceneObjectPart part = m_Engine.World.GetSceneObjectPart(
|
||||
m_LocalID);
|
||||
// m_Engine.Log.DebugFormat("[Script] Delivered event {2} in state {3} to {0}.{1}",
|
||||
// m_PrimName, m_ScriptName, data.EventName, m_State);
|
||||
|
||||
m_Script.ExecuteEvent(State, data.EventName, data.Params);
|
||||
|
||||
m_InEvent = false;
|
||||
m_CurrentEvent = String.Empty;
|
||||
|
||||
if (m_SaveState)
|
||||
try
|
||||
{
|
||||
// This will be the very first event we deliver
|
||||
// (state_entry) in defualt state
|
||||
//
|
||||
m_CurrentEvent = data.EventName;
|
||||
m_EventStart = DateTime.Now;
|
||||
m_InEvent = true;
|
||||
|
||||
SaveState(m_Assembly);
|
||||
m_Script.ExecuteEvent(State, data.EventName, data.Params);
|
||||
|
||||
m_SaveState = false;
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
m_InEvent = false;
|
||||
m_CurrentEvent = String.Empty;
|
||||
m_InEvent = false;
|
||||
m_CurrentEvent = String.Empty;
|
||||
|
||||
if (!(e is TargetInvocationException) || (!(e.InnerException is EventAbortException) && (!(e.InnerException is SelfDeleteException))))
|
||||
{
|
||||
if (e is System.Threading.ThreadAbortException)
|
||||
if (m_SaveState)
|
||||
{
|
||||
lock (m_EventQueue)
|
||||
// This will be the very first event we deliver
|
||||
// (state_entry) in defualt state
|
||||
//
|
||||
|
||||
SaveState(m_Assembly);
|
||||
|
||||
m_SaveState = false;
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
m_InEvent = false;
|
||||
m_CurrentEvent = String.Empty;
|
||||
|
||||
if (!(e is TargetInvocationException) || (!(e.InnerException is EventAbortException) && (!(e.InnerException is SelfDeleteException))))
|
||||
{
|
||||
if (e is System.Threading.ThreadAbortException)
|
||||
{
|
||||
if ((m_EventQueue.Count > 0) && m_RunEvents && (!m_ShuttingDown))
|
||||
lock (m_EventQueue)
|
||||
{
|
||||
m_CurrentResult=m_Engine.QueueEventHandler(this);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_CurrentResult = null;
|
||||
if ((m_EventQueue.Count > 0) && m_RunEvents && (!m_ShuttingDown))
|
||||
{
|
||||
m_CurrentResult=m_Engine.QueueEventHandler(this);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_CurrentResult = null;
|
||||
}
|
||||
}
|
||||
|
||||
m_DetectParams = null;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
m_DetectParams = null;
|
||||
|
||||
return 0;
|
||||
try
|
||||
{
|
||||
// DISPLAY ERROR INWORLD
|
||||
string text = "Runtime error:\n" + e.InnerException.ToString();
|
||||
if (text.Length > 1000)
|
||||
text = text.Substring(0, 1000);
|
||||
m_Engine.World.SimChat(Utils.StringToBytes(text),
|
||||
ChatTypeEnum.DebugChannel, 2147483647,
|
||||
part.AbsolutePosition,
|
||||
part.Name, part.UUID, false);
|
||||
}
|
||||
catch (Exception e2) // LEGIT: User Scripting
|
||||
{
|
||||
m_Engine.Log.Error("[Script]: "+
|
||||
"Error displaying error in-world: " +
|
||||
e2.ToString());
|
||||
m_Engine.Log.Error("[Script]: " +
|
||||
"Errormessage: Error compiling script:\r\n" +
|
||||
e.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
try
|
||||
else if ((e is TargetInvocationException) && (e.InnerException is SelfDeleteException))
|
||||
{
|
||||
// DISPLAY ERROR INWORLD
|
||||
string text = "Runtime error:\n" + e.InnerException.ToString();
|
||||
if (text.Length > 1000)
|
||||
text = text.Substring(0, 1000);
|
||||
m_Engine.World.SimChat(Utils.StringToBytes(text),
|
||||
ChatTypeEnum.DebugChannel, 2147483647,
|
||||
part.AbsolutePosition,
|
||||
part.Name, part.UUID, false);
|
||||
m_InSelfDelete = true;
|
||||
if (part != null && part.ParentGroup != null)
|
||||
m_Engine.World.DeleteSceneObject(part.ParentGroup);
|
||||
}
|
||||
catch (Exception e2) // LEGIT: User Scripting
|
||||
{
|
||||
m_Engine.Log.Error("[Script]: "+
|
||||
"Error displaying error in-world: " +
|
||||
e2.ToString());
|
||||
m_Engine.Log.Error("[Script]: " +
|
||||
"Errormessage: Error compiling script:\r\n" +
|
||||
e.ToString());
|
||||
}
|
||||
}
|
||||
else if ((e is TargetInvocationException) && (e.InnerException is SelfDeleteException))
|
||||
{
|
||||
m_InSelfDelete = true;
|
||||
if (part != null && part.ParentGroup != null)
|
||||
m_Engine.World.DeleteSceneObject(part.ParentGroup);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,6 +39,7 @@ using log4net;
|
||||
using Nini.Config;
|
||||
using Amib.Threading;
|
||||
using OpenSim.Framework;
|
||||
using OpenSim.Region.Interfaces;
|
||||
using OpenSim.Region.Environment;
|
||||
using OpenSim.Region.Environment.Scenes;
|
||||
using OpenSim.Region.Environment.Interfaces;
|
||||
@@ -50,7 +51,7 @@ using OpenSim.Region.ScriptEngine.Interfaces;
|
||||
|
||||
namespace OpenSim.Region.ScriptEngine.XEngine
|
||||
{
|
||||
public class XEngine : IRegionModule, IScriptEngine
|
||||
public class XEngine : IRegionModule, IScriptModule, IScriptEngine
|
||||
{
|
||||
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
|
||||
|
||||
@@ -213,6 +214,8 @@ namespace OpenSim.Region.ScriptEngine.XEngine
|
||||
//
|
||||
SetupEngine(m_MinThreads, m_MaxThreads, m_IdleTimeout, m_Prio,
|
||||
m_MaxScriptQueue, m_StackSize);
|
||||
|
||||
m_Scene.StackModuleInterface<IScriptModule>(this);
|
||||
}
|
||||
|
||||
public void PostInitialise()
|
||||
@@ -331,6 +334,12 @@ namespace OpenSim.Region.ScriptEngine.XEngine
|
||||
|
||||
public void OnRezScript(uint localID, UUID itemID, string script, int startParam, bool postOnRez, string engine)
|
||||
{
|
||||
List<IScriptModule> engines = new List<IScriptModule>(m_Scene.RequestModuleInterfaces<IScriptModule>());
|
||||
|
||||
List<string> names = new List<string>();
|
||||
foreach (IScriptModule m in engines)
|
||||
names.Add(m.ScriptEngineName);
|
||||
|
||||
int lineEnd = script.IndexOf('\n');
|
||||
|
||||
if (lineEnd != 1)
|
||||
@@ -340,8 +349,13 @@ namespace OpenSim.Region.ScriptEngine.XEngine
|
||||
int colon = firstline.IndexOf(':');
|
||||
if (firstline.Length > 2 && firstline.Substring(0, 2) == "//" && colon != -1)
|
||||
{
|
||||
engine = firstline.Substring(2, colon-2);
|
||||
script = "//" + script.Substring(script.IndexOf(':')+1);
|
||||
string engineName = firstline.Substring(2, colon-2);
|
||||
|
||||
if (names.Contains(engineName))
|
||||
{
|
||||
engine = engineName;
|
||||
script = "//" + script.Substring(script.IndexOf(':')+1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -454,14 +468,20 @@ namespace OpenSim.Region.ScriptEngine.XEngine
|
||||
// m_log.DebugFormat("[XEngine] Compiling script {0} ({1})",
|
||||
// item.Name, itemID.ToString());
|
||||
|
||||
ScenePresence presence = m_Scene.GetScenePresence(item.OwnerID);
|
||||
|
||||
string assembly = "";
|
||||
try
|
||||
{
|
||||
assembly = m_Compiler.PerformScriptCompile(script,
|
||||
assetID.ToString());
|
||||
if (presence != null)
|
||||
presence.ControllingClient.SendAgentAlertMessage("Compile successful", false);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
if (presence != null)
|
||||
presence.ControllingClient.SendAgentAlertMessage("Script saved with errors, check debug window!", false);
|
||||
try
|
||||
{
|
||||
// DISPLAY ERROR INWORLD
|
||||
|
||||
Reference in New Issue
Block a user