mirror of
https://github.com/opensim/opensim.git
synced 2026-08-07 17:55:48 +08:00
Imported the scripting changes, so now should be up to date with sugilite.
This commit is contained in:
@@ -70,6 +70,10 @@
|
||||
<HintPath>..\..\..\bin\libsecondlife.dll</HintPath>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.JScript" >
|
||||
<HintPath>Microsoft.JScript.dll</HintPath>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="System" >
|
||||
<HintPath>System.dll</HintPath>
|
||||
<Private>False</Private>
|
||||
@@ -78,6 +82,10 @@
|
||||
<HintPath>System.Xml.dll</HintPath>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="VJSharpCodeProvider" >
|
||||
<HintPath>VJSharpCodeProvider.dll</HintPath>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="XMLRPC.dll" >
|
||||
<HintPath>..\..\..\bin\XMLRPC.dll</HintPath>
|
||||
<Private>False</Private>
|
||||
@@ -152,55 +160,55 @@
|
||||
<Compile Include="Scenes\Entity.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="Scenes\Scene.Scripting.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="Scenes\ScenePresence.Body.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="Scenes\SceneEvents.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="Scenes\ScenePresence.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="Scenes\ScenePresence.Animations.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="Scenes\Scene.PacketHandlers.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="Scenes\SceneObject.cs">
|
||||
<Compile Include="Scenes\IScenePresenceBody.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="Scenes\Primitive.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="Scenes\IScenePresenceBody.cs">
|
||||
<Compile Include="Scenes\Scene.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="Scenes\Scene.PacketHandlers.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="Scenes\Scene.Scripting.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="Scenes\SceneBase.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="Scenes\Scene.cs">
|
||||
<Compile Include="Scenes\SceneEvents.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="Scenes\scripting\IScriptHandler.cs">
|
||||
<Compile Include="Scenes\SceneObject.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="Scenes\scripting\ScriptFactory.cs">
|
||||
<Compile Include="Scenes\ScenePresence.Animations.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="Scenes\scripting\IScriptContext.cs">
|
||||
<Compile Include="Scenes\ScenePresence.Body.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="Scenes\ScenePresence.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="Scenes\scripting\Script.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="Scenes\scripting\IScriptEntity.cs">
|
||||
<Compile Include="Scenes\scripting\ScriptInfo.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="Scenes\scripting\Scripts\FollowRandomAvatar.cs">
|
||||
<Compile Include="Scenes\scripting\ScriptManager.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="Scenes\scripting\Engines\CSharpScriptEngine.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="Scenes\scripting\Engines\JScriptEngine.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="Scenes\scripting\Engines\JSharpScriptEngine.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
</ItemGroup>
|
||||
|
||||
@@ -0,0 +1,75 @@
|
||||
<?xml version="1.0" ?>
|
||||
<project name="OpenSim.Region.Environment" default="build">
|
||||
<target name="build">
|
||||
<echo message="Build Directory is ${project::get-base-directory()}/${build.dir}" />
|
||||
<mkdir dir="${project::get-base-directory()}/${build.dir}" />
|
||||
<copy todir="${project::get-base-directory()}/${build.dir}">
|
||||
<fileset basedir="${project::get-base-directory()}">
|
||||
</fileset>
|
||||
</copy>
|
||||
<csc target="library" debug="${build.debug}" unsafe="False" define="TRACE;DEBUG" output="${project::get-base-directory()}/${build.dir}/${project::get-name()}.dll">
|
||||
<resources prefix="OpenSim.Region.Environment" dynamicprefix="true" >
|
||||
</resources>
|
||||
<sources failonempty="true">
|
||||
<include name="EstateManager.cs" />
|
||||
<include name="ParcelManager.cs" />
|
||||
<include name="RegionManager.cs" />
|
||||
<include name="Scenes/Entity.cs" />
|
||||
<include name="Scenes/IScenePresenceBody.cs" />
|
||||
<include name="Scenes/Primitive.cs" />
|
||||
<include name="Scenes/Scene.cs" />
|
||||
<include name="Scenes/Scene.PacketHandlers.cs" />
|
||||
<include name="Scenes/Scene.Scripting.cs" />
|
||||
<include name="Scenes/SceneBase.cs" />
|
||||
<include name="Scenes/SceneEvents.cs" />
|
||||
<include name="Scenes/SceneObject.cs" />
|
||||
<include name="Scenes/ScenePresence.Animations.cs" />
|
||||
<include name="Scenes/ScenePresence.Body.cs" />
|
||||
<include name="Scenes/ScenePresence.cs" />
|
||||
<include name="Scenes/scripting/Script.cs" />
|
||||
<include name="Scenes/scripting/ScriptInfo.cs" />
|
||||
<include name="Scenes/scripting/ScriptManager.cs" />
|
||||
<include name="Scenes/scripting/Engines/CSharpScriptEngine.cs" />
|
||||
<include name="Scenes/scripting/Engines/JScriptEngine.cs" />
|
||||
<include name="Scenes/scripting/Engines/JSharpScriptEngine.cs" />
|
||||
</sources>
|
||||
<references basedir="${project::get-base-directory()}">
|
||||
<lib>
|
||||
<include name="${project::get-base-directory()}" />
|
||||
<include name="${project::get-base-directory()}/${build.dir}" />
|
||||
</lib>
|
||||
<include name="../../../bin/Axiom.MathLib.dll" />
|
||||
<include name="../../../bin/Db4objects.Db4o.dll" />
|
||||
<include name="../../../bin/libsecondlife.dll" />
|
||||
<include name="Microsoft.JScript.dll" />
|
||||
<include name="../../../bin/OpenSim.Framework.dll" />
|
||||
<include name="../../../bin/OpenSim.Framework.Communications.dll" />
|
||||
<include name="../../../bin/OpenSim.Framework.Console.dll" />
|
||||
<include name="../../../bin/OpenSim.Framework.GenericConfig.Xml.dll" />
|
||||
<include name="../../../bin/OpenSim.Framework.Servers.dll" />
|
||||
<include name="../../../bin/OpenSim.Region.Caches.dll" />
|
||||
<include name="../../../bin/OpenSim.Region.Capabilities.dll" />
|
||||
<include name="../../../bin/OpenSim.Region.Physics.Manager.dll" />
|
||||
<include name="../../../bin/OpenSim.Region.Terrain.BasicTerrain.dll" />
|
||||
<include name="System.dll" />
|
||||
<include name="System.Xml.dll" />
|
||||
<include name="VJSharpCodeProvider.dll" />
|
||||
<include name="../../../bin/XMLRPC.dll" />
|
||||
</references>
|
||||
</csc>
|
||||
<echo message="Copying from [${project::get-base-directory()}/${build.dir}/] to [${project::get-base-directory()}/../../../bin/" />
|
||||
<mkdir dir="${project::get-base-directory()}/../../../bin/"/>
|
||||
<copy todir="${project::get-base-directory()}/../../../bin/">
|
||||
<fileset basedir="${project::get-base-directory()}/${build.dir}/" >
|
||||
<include name="*.dll"/>
|
||||
<include name="*.exe"/>
|
||||
</fileset>
|
||||
</copy>
|
||||
</target>
|
||||
<target name="clean">
|
||||
<delete dir="${bin.dir}" failonerror="false" />
|
||||
<delete dir="${obj.dir}" failonerror="false" />
|
||||
</target>
|
||||
<target name="doc" description="Creates documentation.">
|
||||
</target>
|
||||
</project>
|
||||
@@ -31,11 +31,10 @@ using System.Text;
|
||||
using Axiom.MathLib;
|
||||
using OpenSim.Physics.Manager;
|
||||
using libsecondlife;
|
||||
using OpenSim.Region.Environment.Scripting;
|
||||
|
||||
namespace OpenSim.Region.Environment.Scenes
|
||||
{
|
||||
public abstract class Entity : IScriptReadonlyEntity
|
||||
public abstract class Entity
|
||||
{
|
||||
public libsecondlife.LLUUID uuid;
|
||||
public Quaternion rotation;
|
||||
|
||||
@@ -39,12 +39,14 @@ using OpenSim.Framework.Interfaces;
|
||||
using OpenSim.Framework.Types;
|
||||
using OpenSim.Framework.Inventory;
|
||||
using OpenSim.Framework;
|
||||
using OpenSim.Region.Environment.Scripting;
|
||||
using OpenSim.Region.Terrain;
|
||||
using OpenSim.Framework.Communications;
|
||||
using OpenSim.Region.Caches;
|
||||
using OpenSim.Region.Environment;
|
||||
using OpenSim.Framework.Servers;
|
||||
using OpenSim.Scripting;
|
||||
using OpenSim.Region.Capabilities;
|
||||
using Caps = OpenSim.Region.Capabilities.Caps;
|
||||
|
||||
namespace OpenSim.Region.Environment.Scenes
|
||||
{
|
||||
@@ -60,20 +62,19 @@ namespace OpenSim.Region.Environment.Scenes
|
||||
private Random Rand = new Random();
|
||||
private uint _primCount = 702000;
|
||||
private int storageCount;
|
||||
private Dictionary<LLUUID, ScriptHandler> m_scriptHandlers;
|
||||
private Dictionary<string, ScriptFactory> m_scripts;
|
||||
private Mutex updateLock;
|
||||
|
||||
protected AuthenticateSessionsBase authenticateHandler;
|
||||
protected RegionCommsListener regionCommsHost;
|
||||
protected CommunicationsManager commsManager;
|
||||
|
||||
protected Dictionary<LLUUID, Capabilities.Caps> capsHandlers = new Dictionary<LLUUID, Capabilities.Caps>();
|
||||
protected Dictionary<LLUUID,Caps> capsHandlers = new Dictionary<LLUUID, Caps>();
|
||||
protected BaseHttpServer httpListener;
|
||||
|
||||
public ParcelManager parcelManager;
|
||||
public EstateManager estateManager;
|
||||
public EventManager eventManager;
|
||||
public ScriptManager scriptManager;
|
||||
|
||||
#region Properties
|
||||
/// <summary>
|
||||
@@ -117,12 +118,9 @@ namespace OpenSim.Region.Environment.Scenes
|
||||
|
||||
parcelManager = new ParcelManager(this, this.m_regInfo);
|
||||
estateManager = new EstateManager(this, this.m_regInfo);
|
||||
|
||||
scriptManager = new ScriptManager(this);
|
||||
eventManager = new EventManager();
|
||||
|
||||
m_scriptHandlers = new Dictionary<LLUUID, ScriptHandler>();
|
||||
m_scripts = new Dictionary<string, ScriptFactory>();
|
||||
|
||||
OpenSim.Framework.Console.MainLog.Instance.Verbose( "World.cs - creating new entitities instance");
|
||||
Entities = new Dictionary<libsecondlife.LLUUID, Entity>();
|
||||
Avatars = new Dictionary<LLUUID, ScenePresence>();
|
||||
@@ -195,19 +193,9 @@ namespace OpenSim.Region.Environment.Scenes
|
||||
Entities[UUID].update();
|
||||
}
|
||||
|
||||
// New
|
||||
// General purpose event manager
|
||||
eventManager.TriggerOnFrame();
|
||||
|
||||
// TODO: Obsolete - Phase out
|
||||
foreach (ScriptHandler scriptHandler in m_scriptHandlers.Values)
|
||||
{
|
||||
scriptHandler.OnFrame();
|
||||
}
|
||||
foreach (IScriptEngine scripteng in this.scriptEngines.Values)
|
||||
{
|
||||
scripteng.OnFrame();
|
||||
}
|
||||
|
||||
//backup world data
|
||||
this.storageCount++;
|
||||
if (storageCount > 1200) //set to how often you want to backup
|
||||
@@ -256,7 +244,7 @@ namespace OpenSim.Region.Environment.Scenes
|
||||
//Parcel backup routines
|
||||
ParcelData[] parcels = new ParcelData[parcelManager.parcelList.Count];
|
||||
int i = 0;
|
||||
foreach (OpenSim.Region.Environment.Parcel parcel in parcelManager.parcelList.Values)
|
||||
foreach (OpenSim.Region.Parcel parcel in parcelManager.parcelList.Values)
|
||||
{
|
||||
parcels[i] = parcel.parcelData;
|
||||
i++;
|
||||
@@ -672,7 +660,7 @@ namespace OpenSim.Region.Environment.Scenes
|
||||
if (agent.CapsPath != "")
|
||||
{
|
||||
//Console.WriteLine("new user, so creating caps handler for it");
|
||||
Capabilities.Caps cap = new Capabilities.Caps(this.assetCache, httpListener, this.m_regInfo.CommsIPListenAddr, 9000, agent.CapsPath, agent.AgentID);
|
||||
Caps cap = new Caps(this.assetCache, httpListener, this.m_regInfo.CommsIPListenAddr, 9000, agent.CapsPath, agent.AgentID);
|
||||
cap.RegisterHandlers();
|
||||
this.capsHandlers.Add(agent.AgentID, cap);
|
||||
}
|
||||
|
||||
@@ -37,7 +37,6 @@ using OpenSim.Physics.Manager;
|
||||
using OpenSim.Framework.Interfaces;
|
||||
using OpenSim.Framework.Types;
|
||||
using OpenSim.Framework.Inventory;
|
||||
using OpenSim.Region.Environment.Scripting;
|
||||
using OpenSim.Region.Terrain;
|
||||
using OpenSim.Region.Caches;
|
||||
|
||||
|
||||
@@ -0,0 +1,104 @@
|
||||
/*
|
||||
* Copyright (c) Contributors, http://www.openmetaverse.org/
|
||||
* See CONTRIBUTORS.TXT for a full list of copyright holders.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * Neither the name of the OpenSim Project nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
// Compilation stuff
|
||||
using System.CodeDom;
|
||||
using System.CodeDom.Compiler;
|
||||
using Microsoft.CSharp;
|
||||
|
||||
namespace OpenSim.Scripting
|
||||
{
|
||||
public class CSharpScriptEngine : IScriptCompiler
|
||||
{
|
||||
public string FileExt()
|
||||
{
|
||||
return ".cs";
|
||||
}
|
||||
|
||||
private Dictionary<string,IScript> LoadDotNetScript(ICodeCompiler compiler, string filename)
|
||||
{
|
||||
CompilerParameters compilerParams = new CompilerParameters();
|
||||
CompilerResults compilerResults;
|
||||
compilerParams.GenerateExecutable = false;
|
||||
compilerParams.GenerateInMemory = true;
|
||||
compilerParams.IncludeDebugInformation = false;
|
||||
compilerParams.ReferencedAssemblies.Add("OpenSim.Region.dll");
|
||||
compilerParams.ReferencedAssemblies.Add("OpenSim.Framework.dll");
|
||||
compilerParams.ReferencedAssemblies.Add("libsecondlife.dll");
|
||||
compilerParams.ReferencedAssemblies.Add("System.dll");
|
||||
|
||||
compilerResults = compiler.CompileAssemblyFromFile(compilerParams, filename);
|
||||
|
||||
if (compilerResults.Errors.Count > 0)
|
||||
{
|
||||
OpenSim.Framework.Console.MainLog.Instance.Error("Compile errors");
|
||||
foreach (CompilerError error in compilerResults.Errors)
|
||||
{
|
||||
OpenSim.Framework.Console.MainLog.Instance.Error(error.Line.ToString() + ": " + error.ErrorText.ToString());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Dictionary<string,IScript> scripts = new Dictionary<string,IScript>();
|
||||
|
||||
foreach (Type pluginType in compilerResults.CompiledAssembly.GetExportedTypes())
|
||||
{
|
||||
Type testInterface = pluginType.GetInterface("IScript", true);
|
||||
|
||||
if (testInterface != null)
|
||||
{
|
||||
IScript script = (IScript)compilerResults.CompiledAssembly.CreateInstance(pluginType.ToString());
|
||||
|
||||
string scriptName = "C#/" + script.getName();
|
||||
Console.WriteLine("Script: " + scriptName + " loaded.");
|
||||
|
||||
if (!scripts.ContainsKey(scriptName))
|
||||
{
|
||||
scripts.Add(scriptName, script);
|
||||
}
|
||||
else
|
||||
{
|
||||
scripts[scriptName] = script;
|
||||
}
|
||||
}
|
||||
}
|
||||
return scripts;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public Dictionary<string,IScript> compile(string filename)
|
||||
{
|
||||
CSharpCodeProvider csharpProvider = new CSharpCodeProvider();
|
||||
return LoadDotNetScript(csharpProvider.CreateCompiler(), filename);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,104 @@
|
||||
/*
|
||||
* Copyright (c) Contributors, http://www.openmetaverse.org/
|
||||
* See CONTRIBUTORS.TXT for a full list of copyright holders.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * Neither the name of the OpenSim Project nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
// Compilation stuff
|
||||
using System.CodeDom;
|
||||
using System.CodeDom.Compiler;
|
||||
using Microsoft.JScript;
|
||||
|
||||
namespace OpenSim.Scripting
|
||||
{
|
||||
public class JScriptEngine : IScriptCompiler
|
||||
{
|
||||
public string FileExt()
|
||||
{
|
||||
return ".js";
|
||||
}
|
||||
|
||||
private Dictionary<string, IScript> LoadDotNetScript(ICodeCompiler compiler, string filename)
|
||||
{
|
||||
CompilerParameters compilerParams = new CompilerParameters();
|
||||
CompilerResults compilerResults;
|
||||
compilerParams.GenerateExecutable = false;
|
||||
compilerParams.GenerateInMemory = true;
|
||||
compilerParams.IncludeDebugInformation = false;
|
||||
compilerParams.ReferencedAssemblies.Add("OpenSim.Region.dll");
|
||||
compilerParams.ReferencedAssemblies.Add("OpenSim.Framework.dll");
|
||||
compilerParams.ReferencedAssemblies.Add("libsecondlife.dll");
|
||||
compilerParams.ReferencedAssemblies.Add("System.dll");
|
||||
|
||||
compilerResults = compiler.CompileAssemblyFromFile(compilerParams, filename);
|
||||
|
||||
if (compilerResults.Errors.Count > 0)
|
||||
{
|
||||
OpenSim.Framework.Console.MainLog.Instance.Error("Compile errors");
|
||||
foreach (CompilerError error in compilerResults.Errors)
|
||||
{
|
||||
OpenSim.Framework.Console.MainLog.Instance.Error(error.Line.ToString() + ": " + error.ErrorText.ToString());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Dictionary<string, IScript> scripts = new Dictionary<string, IScript>();
|
||||
|
||||
foreach (Type pluginType in compilerResults.CompiledAssembly.GetExportedTypes())
|
||||
{
|
||||
Type testInterface = pluginType.GetInterface("IScript", true);
|
||||
|
||||
if (testInterface != null)
|
||||
{
|
||||
IScript script = (IScript)compilerResults.CompiledAssembly.CreateInstance(pluginType.ToString());
|
||||
|
||||
string scriptName = "JS.NET/" + script.getName();
|
||||
Console.WriteLine("Script: " + scriptName + " loaded.");
|
||||
|
||||
if (!scripts.ContainsKey(scriptName))
|
||||
{
|
||||
scripts.Add(scriptName, script);
|
||||
}
|
||||
else
|
||||
{
|
||||
scripts[scriptName] = script;
|
||||
}
|
||||
}
|
||||
}
|
||||
return scripts;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public Dictionary<string, IScript> compile(string filename)
|
||||
{
|
||||
JScriptCodeProvider jscriptProvider = new JScriptCodeProvider();
|
||||
return LoadDotNetScript(jscriptProvider.CreateCompiler(), filename);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,104 @@
|
||||
/*
|
||||
* Copyright (c) Contributors, http://www.openmetaverse.org/
|
||||
* See CONTRIBUTORS.TXT for a full list of copyright holders.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * Neither the name of the OpenSim Project nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
// Compilation stuff
|
||||
using System.CodeDom;
|
||||
using System.CodeDom.Compiler;
|
||||
using Microsoft.VJSharp;
|
||||
|
||||
namespace OpenSim.Scripting
|
||||
{
|
||||
public class JSharpScriptEngine : IScriptCompiler
|
||||
{
|
||||
public string FileExt()
|
||||
{
|
||||
return ".jsl";
|
||||
}
|
||||
|
||||
private Dictionary<string, IScript> LoadDotNetScript(ICodeCompiler compiler, string filename)
|
||||
{
|
||||
CompilerParameters compilerParams = new CompilerParameters();
|
||||
CompilerResults compilerResults;
|
||||
compilerParams.GenerateExecutable = false;
|
||||
compilerParams.GenerateInMemory = true;
|
||||
compilerParams.IncludeDebugInformation = false;
|
||||
compilerParams.ReferencedAssemblies.Add("OpenSim.Region.dll");
|
||||
compilerParams.ReferencedAssemblies.Add("OpenSim.Framework.dll");
|
||||
compilerParams.ReferencedAssemblies.Add("libsecondlife.dll");
|
||||
compilerParams.ReferencedAssemblies.Add("System.dll");
|
||||
|
||||
compilerResults = compiler.CompileAssemblyFromFile(compilerParams, filename);
|
||||
|
||||
if (compilerResults.Errors.Count > 0)
|
||||
{
|
||||
OpenSim.Framework.Console.MainLog.Instance.Error("Compile errors");
|
||||
foreach (CompilerError error in compilerResults.Errors)
|
||||
{
|
||||
OpenSim.Framework.Console.MainLog.Instance.Error(error.Line.ToString() + ": " + error.ErrorText.ToString());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Dictionary<string, IScript> scripts = new Dictionary<string, IScript>();
|
||||
|
||||
foreach (Type pluginType in compilerResults.CompiledAssembly.GetExportedTypes())
|
||||
{
|
||||
Type testInterface = pluginType.GetInterface("IScript", true);
|
||||
|
||||
if (testInterface != null)
|
||||
{
|
||||
IScript script = (IScript)compilerResults.CompiledAssembly.CreateInstance(pluginType.ToString());
|
||||
|
||||
string scriptName = "J#/" + script.getName();
|
||||
Console.WriteLine("Script: " + scriptName + " loaded.");
|
||||
|
||||
if (!scripts.ContainsKey(scriptName))
|
||||
{
|
||||
scripts.Add(scriptName, script);
|
||||
}
|
||||
else
|
||||
{
|
||||
scripts[scriptName] = script;
|
||||
}
|
||||
}
|
||||
}
|
||||
return scripts;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public Dictionary<string, IScript> compile(string filename)
|
||||
{
|
||||
VJSharpCodeProvider jsharpProvider = new VJSharpCodeProvider();
|
||||
return LoadDotNetScript(jsharpProvider.CreateCompiler(), filename);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,40 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Contributors, http://www.openmetaverse.org/
|
||||
* See CONTRIBUTORS.TXT for a full list of copyright holders.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * Neither the name of the OpenSim Project nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using libsecondlife;
|
||||
|
||||
namespace OpenSim.Region.Environment.Scripting
|
||||
{
|
||||
public interface IScriptContext
|
||||
{
|
||||
IScriptEntity Entity { get; }
|
||||
bool TryGetRandomAvatar(out IScriptReadonlyEntity avatar);
|
||||
}
|
||||
}
|
||||
@@ -1,46 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Contributors, http://www.openmetaverse.org/
|
||||
* See CONTRIBUTORS.TXT for a full list of copyright holders.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * Neither the name of the OpenSim Project nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using libsecondlife;
|
||||
|
||||
namespace OpenSim.Region.Environment.Scripting
|
||||
{
|
||||
public interface IScriptReadonlyEntity
|
||||
{
|
||||
LLVector3 Pos { get; }
|
||||
string Name { get; }
|
||||
}
|
||||
|
||||
public interface IScriptEntity
|
||||
{
|
||||
LLVector3 Pos { get; set; }
|
||||
string Name { get; }
|
||||
}
|
||||
}
|
||||
@@ -1,126 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Contributors, http://www.openmetaverse.org/
|
||||
* See CONTRIBUTORS.TXT for a full list of copyright holders.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * Neither the name of the OpenSim Project nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using libsecondlife;
|
||||
using OpenSim.Physics.Manager;
|
||||
using OpenSim.Region.Environment;
|
||||
using OpenSim.Region.Environment.Scenes;
|
||||
using Avatar=OpenSim.Region.Environment.Scenes.ScenePresence;
|
||||
using Primitive = OpenSim.Region.Environment.Scenes.Primitive;
|
||||
|
||||
namespace OpenSim.Region.Environment.Scripting
|
||||
{
|
||||
public delegate void ScriptEventHandler(IScriptContext context);
|
||||
|
||||
public class ScriptHandler : IScriptContext, IScriptEntity, IScriptReadonlyEntity
|
||||
{
|
||||
private Scene m_world;
|
||||
private Script m_script;
|
||||
private Entity m_entity;
|
||||
|
||||
public LLUUID ScriptId
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_script.ScriptId;
|
||||
}
|
||||
}
|
||||
|
||||
public void OnFrame()
|
||||
{
|
||||
m_script.OnFrame(this);
|
||||
}
|
||||
|
||||
public ScriptHandler(Script script, Entity entity, Scene world)
|
||||
{
|
||||
m_script = script;
|
||||
m_entity = entity;
|
||||
m_world = world;
|
||||
}
|
||||
|
||||
#region IScriptContext Members
|
||||
|
||||
IScriptEntity IScriptContext.Entity
|
||||
{
|
||||
get
|
||||
{
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
bool IScriptContext.TryGetRandomAvatar(out IScriptReadonlyEntity avatar)
|
||||
{
|
||||
foreach (Entity entity in m_world.Entities.Values )
|
||||
{
|
||||
if( entity is Avatar )
|
||||
{
|
||||
avatar = entity;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
avatar = null;
|
||||
return false;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IScriptEntity and IScriptReadonlyEntity Members
|
||||
|
||||
public string Name
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_entity.Name;
|
||||
}
|
||||
}
|
||||
|
||||
public LLVector3 Pos
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_entity.Pos;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (m_entity is Primitive)
|
||||
{
|
||||
Primitive prim = m_entity as Primitive;
|
||||
// Of course, we really should have asked the physEngine if this is possible, and if not, returned false.
|
||||
// prim.UpdatePosition( value );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Contributors, http://www.openmetaverse.org/
|
||||
* See CONTRIBUTORS.TXT for a full list of copyright holders.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * Neither the name of the OpenSim Project nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace OpenSim.Region.Environment.Scripting
|
||||
{
|
||||
public delegate Script ScriptFactory();
|
||||
}
|
||||
@@ -28,26 +28,31 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using libsecondlife;
|
||||
|
||||
namespace OpenSim.Region.Environment.Scripting
|
||||
using OpenSim.Region.Environment.Scenes;
|
||||
using OpenSim.Framework.Console;
|
||||
|
||||
namespace OpenSim.Scripting
|
||||
{
|
||||
public class Script
|
||||
/// <summary>
|
||||
/// Class which provides access to the world
|
||||
/// </summary>
|
||||
public class ScriptInfo
|
||||
{
|
||||
private LLUUID m_scriptId;
|
||||
public virtual LLUUID ScriptId
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_scriptId;
|
||||
}
|
||||
}
|
||||
// Reference to world.eventsManager provided for convenience
|
||||
public EventManager events;
|
||||
|
||||
public Script( LLUUID scriptId )
|
||||
// The main world
|
||||
public Scene world;
|
||||
|
||||
// The console
|
||||
public LogBase logger;
|
||||
|
||||
public ScriptInfo(Scene scene)
|
||||
{
|
||||
m_scriptId = scriptId;
|
||||
world = scene;
|
||||
events = world.eventManager;
|
||||
logger = OpenSim.Framework.Console.MainLog.Instance;
|
||||
}
|
||||
|
||||
public ScriptEventHandler OnFrame;
|
||||
}
|
||||
}
|
||||
99
OpenSim/Region/Environment/Scenes/scripting/ScriptManager.cs
Normal file
99
OpenSim/Region/Environment/Scenes/scripting/ScriptManager.cs
Normal file
@@ -0,0 +1,99 @@
|
||||
/*
|
||||
* Copyright (c) Contributors, http://www.openmetaverse.org/
|
||||
* See CONTRIBUTORS.TXT for a full list of copyright holders.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * Neither the name of the OpenSim Project nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace OpenSim.Scripting
|
||||
{
|
||||
public class ScriptManager
|
||||
{
|
||||
List<IScript> scripts = new List<IScript>();
|
||||
OpenSim.Region.Environment.Scenes.Scene scene;
|
||||
Dictionary<string, IScriptCompiler> compilers = new Dictionary<string, IScriptCompiler>();
|
||||
|
||||
private void LoadFromCompiler(Dictionary<string, IScript> compiledscripts)
|
||||
{
|
||||
foreach (KeyValuePair<string, IScript> script in compiledscripts)
|
||||
{
|
||||
ScriptInfo scriptInfo = new ScriptInfo(scene); // Since each script could potentially corrupt their access with a stray assignment, making a new one for each script.
|
||||
OpenSim.Framework.Console.MainLog.Instance.Verbose("Loading " + script.Key);
|
||||
script.Value.Initialise(scriptInfo);
|
||||
scripts.Add(script.Value);
|
||||
}
|
||||
OpenSim.Framework.Console.MainLog.Instance.Verbose("Finished loading " + compiledscripts.Count.ToString() + " script(s)");
|
||||
}
|
||||
|
||||
public ScriptManager(OpenSim.Region.Environment.Scenes.Scene world)
|
||||
{
|
||||
scene = world;
|
||||
|
||||
// Default Engines
|
||||
CSharpScriptEngine csharpCompiler = new CSharpScriptEngine();
|
||||
compilers.Add(csharpCompiler.FileExt(),csharpCompiler);
|
||||
|
||||
JScriptEngine jscriptCompiler = new JScriptEngine();
|
||||
compilers.Add(jscriptCompiler.FileExt(), jscriptCompiler);
|
||||
|
||||
JSharpScriptEngine jsharpCompiler = new JSharpScriptEngine();
|
||||
compilers.Add(jsharpCompiler.FileExt(), jsharpCompiler);
|
||||
}
|
||||
|
||||
public void Compile(string filename)
|
||||
{
|
||||
foreach (KeyValuePair<string, IScriptCompiler> compiler in compilers)
|
||||
{
|
||||
if (filename.EndsWith(compiler.Key))
|
||||
{
|
||||
LoadFromCompiler(compiler.Value.compile(filename));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void RunScriptCmd(string[] args)
|
||||
{
|
||||
switch (args[0])
|
||||
{
|
||||
case "load":
|
||||
Compile(args[1]);
|
||||
break;
|
||||
|
||||
default:
|
||||
OpenSim.Framework.Console.MainLog.Instance.Error("Unknown script command");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
interface IScriptCompiler
|
||||
{
|
||||
Dictionary<string,IScript> compile(string filename);
|
||||
string FileExt();
|
||||
}
|
||||
}
|
||||
@@ -1,64 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) Contributors, http://www.openmetaverse.org/
|
||||
* See CONTRIBUTORS.TXT for a full list of copyright holders.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* * Neither the name of the OpenSim Project nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using libsecondlife;
|
||||
|
||||
namespace OpenSim.Region.Environment.Scripting
|
||||
{
|
||||
public class FollowRandomAvatar : Script
|
||||
{
|
||||
public FollowRandomAvatar()
|
||||
: base(LLUUID.Random())
|
||||
{
|
||||
OnFrame += MyOnFrame;
|
||||
}
|
||||
|
||||
private void MyOnFrame(IScriptContext context)
|
||||
{
|
||||
LLVector3 pos = context.Entity.Pos;
|
||||
|
||||
IScriptReadonlyEntity avatar;
|
||||
|
||||
if (context.TryGetRandomAvatar(out avatar))
|
||||
{
|
||||
LLVector3 avatarPos = avatar.Pos;
|
||||
|
||||
float x = pos.X + ((float)avatarPos.X.CompareTo(pos.X)) / 2;
|
||||
float y = pos.Y + ((float)avatarPos.Y.CompareTo(pos.Y)) / 2;
|
||||
|
||||
LLVector3 newPos = new LLVector3(x, y, pos.Z);
|
||||
|
||||
context.Entity.Pos = newPos;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user