aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Environment
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/Environment')
-rw-r--r--OpenSim/Region/Environment/OpenSim.Region.Environment.csproj42
-rw-r--r--OpenSim/Region/Environment/OpenSim.Region.Environment.dll.build75
-rw-r--r--OpenSim/Region/Environment/Scenes/Entity.cs3
-rw-r--r--OpenSim/Region/Environment/Scenes/Scene.cs30
-rw-r--r--OpenSim/Region/Environment/Scenes/SceneBase.cs1
-rw-r--r--OpenSim/Region/Environment/Scenes/scripting/Engines/CSharpScriptEngine.cs104
-rw-r--r--OpenSim/Region/Environment/Scenes/scripting/Engines/JScriptEngine.cs104
-rw-r--r--OpenSim/Region/Environment/Scenes/scripting/Engines/JSharpScriptEngine.cs104
-rw-r--r--OpenSim/Region/Environment/Scenes/scripting/IScriptContext.cs40
-rw-r--r--OpenSim/Region/Environment/Scenes/scripting/IScriptEntity.cs46
-rw-r--r--OpenSim/Region/Environment/Scenes/scripting/IScriptHandler.cs126
-rw-r--r--OpenSim/Region/Environment/Scenes/scripting/ScriptFactory.cs35
-rw-r--r--OpenSim/Region/Environment/Scenes/scripting/ScriptInfo.cs (renamed from OpenSim/Region/Environment/Scenes/scripting/Script.cs)35
-rw-r--r--OpenSim/Region/Environment/Scenes/scripting/ScriptManager.cs99
-rw-r--r--OpenSim/Region/Environment/Scenes/scripting/Scripts/FollowRandomAvatar.cs64
15 files changed, 541 insertions, 367 deletions
diff --git a/OpenSim/Region/Environment/OpenSim.Region.Environment.csproj b/OpenSim/Region/Environment/OpenSim.Region.Environment.csproj
index 6f07969..efde96c 100644
--- a/OpenSim/Region/Environment/OpenSim.Region.Environment.csproj
+++ b/OpenSim/Region/Environment/OpenSim.Region.Environment.csproj
@@ -70,6 +70,10 @@
70 <HintPath>..\..\..\bin\libsecondlife.dll</HintPath> 70 <HintPath>..\..\..\bin\libsecondlife.dll</HintPath>
71 <Private>False</Private> 71 <Private>False</Private>
72 </Reference> 72 </Reference>
73 <Reference Include="Microsoft.JScript" >
74 <HintPath>Microsoft.JScript.dll</HintPath>
75 <Private>False</Private>
76 </Reference>
73 <Reference Include="System" > 77 <Reference Include="System" >
74 <HintPath>System.dll</HintPath> 78 <HintPath>System.dll</HintPath>
75 <Private>False</Private> 79 <Private>False</Private>
@@ -78,6 +82,10 @@
78 <HintPath>System.Xml.dll</HintPath> 82 <HintPath>System.Xml.dll</HintPath>
79 <Private>False</Private> 83 <Private>False</Private>
80 </Reference> 84 </Reference>
85 <Reference Include="VJSharpCodeProvider" >
86 <HintPath>VJSharpCodeProvider.dll</HintPath>
87 <Private>False</Private>
88 </Reference>
81 <Reference Include="XMLRPC.dll" > 89 <Reference Include="XMLRPC.dll" >
82 <HintPath>..\..\..\bin\XMLRPC.dll</HintPath> 90 <HintPath>..\..\..\bin\XMLRPC.dll</HintPath>
83 <Private>False</Private> 91 <Private>False</Private>
@@ -152,55 +160,55 @@
152 <Compile Include="Scenes\Entity.cs"> 160 <Compile Include="Scenes\Entity.cs">
153 <SubType>Code</SubType> 161 <SubType>Code</SubType>
154 </Compile> 162 </Compile>
155 <Compile Include="Scenes\Scene.Scripting.cs"> 163 <Compile Include="Scenes\IScenePresenceBody.cs">
156 <SubType>Code</SubType> 164 <SubType>Code</SubType>
157 </Compile> 165 </Compile>
158 <Compile Include="Scenes\ScenePresence.Body.cs"> 166 <Compile Include="Scenes\Primitive.cs">
159 <SubType>Code</SubType> 167 <SubType>Code</SubType>
160 </Compile> 168 </Compile>
161 <Compile Include="Scenes\SceneEvents.cs"> 169 <Compile Include="Scenes\Scene.cs">
162 <SubType>Code</SubType> 170 <SubType>Code</SubType>
163 </Compile> 171 </Compile>
164 <Compile Include="Scenes\ScenePresence.cs"> 172 <Compile Include="Scenes\Scene.PacketHandlers.cs">
165 <SubType>Code</SubType> 173 <SubType>Code</SubType>
166 </Compile> 174 </Compile>
167 <Compile Include="Scenes\ScenePresence.Animations.cs"> 175 <Compile Include="Scenes\Scene.Scripting.cs">
168 <SubType>Code</SubType> 176 <SubType>Code</SubType>
169 </Compile> 177 </Compile>
170 <Compile Include="Scenes\Scene.PacketHandlers.cs"> 178 <Compile Include="Scenes\SceneBase.cs">
171 <SubType>Code</SubType> 179 <SubType>Code</SubType>
172 </Compile> 180 </Compile>
173 <Compile Include="Scenes\SceneObject.cs"> 181 <Compile Include="Scenes\SceneEvents.cs">
174 <SubType>Code</SubType> 182 <SubType>Code</SubType>
175 </Compile> 183 </Compile>
176 <Compile Include="Scenes\Primitive.cs"> 184 <Compile Include="Scenes\SceneObject.cs">
177 <SubType>Code</SubType> 185 <SubType>Code</SubType>
178 </Compile> 186 </Compile>
179 <Compile Include="Scenes\IScenePresenceBody.cs"> 187 <Compile Include="Scenes\ScenePresence.Animations.cs">
180 <SubType>Code</SubType> 188 <SubType>Code</SubType>
181 </Compile> 189 </Compile>
182 <Compile Include="Scenes\SceneBase.cs"> 190 <Compile Include="Scenes\ScenePresence.Body.cs">
183 <SubType>Code</SubType> 191 <SubType>Code</SubType>
184 </Compile> 192 </Compile>
185 <Compile Include="Scenes\Scene.cs"> 193 <Compile Include="Scenes\ScenePresence.cs">
186 <SubType>Code</SubType> 194 <SubType>Code</SubType>
187 </Compile> 195 </Compile>
188 <Compile Include="Scenes\scripting\IScriptHandler.cs"> 196 <Compile Include="Scenes\scripting\Script.cs">
189 <SubType>Code</SubType> 197 <SubType>Code</SubType>
190 </Compile> 198 </Compile>
191 <Compile Include="Scenes\scripting\ScriptFactory.cs"> 199 <Compile Include="Scenes\scripting\ScriptInfo.cs">
192 <SubType>Code</SubType> 200 <SubType>Code</SubType>
193 </Compile> 201 </Compile>
194 <Compile Include="Scenes\scripting\IScriptContext.cs"> 202 <Compile Include="Scenes\scripting\ScriptManager.cs">
195 <SubType>Code</SubType> 203 <SubType>Code</SubType>
196 </Compile> 204 </Compile>
197 <Compile Include="Scenes\scripting\Script.cs"> 205 <Compile Include="Scenes\scripting\Engines\CSharpScriptEngine.cs">
198 <SubType>Code</SubType> 206 <SubType>Code</SubType>
199 </Compile> 207 </Compile>
200 <Compile Include="Scenes\scripting\IScriptEntity.cs"> 208 <Compile Include="Scenes\scripting\Engines\JScriptEngine.cs">
201 <SubType>Code</SubType> 209 <SubType>Code</SubType>
202 </Compile> 210 </Compile>
203 <Compile Include="Scenes\scripting\Scripts\FollowRandomAvatar.cs"> 211 <Compile Include="Scenes\scripting\Engines\JSharpScriptEngine.cs">
204 <SubType>Code</SubType> 212 <SubType>Code</SubType>
205 </Compile> 213 </Compile>
206 </ItemGroup> 214 </ItemGroup>
diff --git a/OpenSim/Region/Environment/OpenSim.Region.Environment.dll.build b/OpenSim/Region/Environment/OpenSim.Region.Environment.dll.build
new file mode 100644
index 0000000..da73c8c
--- /dev/null
+++ b/OpenSim/Region/Environment/OpenSim.Region.Environment.dll.build
@@ -0,0 +1,75 @@
1<?xml version="1.0" ?>
2<project name="OpenSim.Region.Environment" default="build">
3 <target name="build">
4 <echo message="Build Directory is ${project::get-base-directory()}/${build.dir}" />
5 <mkdir dir="${project::get-base-directory()}/${build.dir}" />
6 <copy todir="${project::get-base-directory()}/${build.dir}">
7 <fileset basedir="${project::get-base-directory()}">
8 </fileset>
9 </copy>
10 <csc target="library" debug="${build.debug}" unsafe="False" define="TRACE;DEBUG" output="${project::get-base-directory()}/${build.dir}/${project::get-name()}.dll">
11 <resources prefix="OpenSim.Region.Environment" dynamicprefix="true" >
12 </resources>
13 <sources failonempty="true">
14 <include name="EstateManager.cs" />
15 <include name="ParcelManager.cs" />
16 <include name="RegionManager.cs" />
17 <include name="Scenes/Entity.cs" />
18 <include name="Scenes/IScenePresenceBody.cs" />
19 <include name="Scenes/Primitive.cs" />
20 <include name="Scenes/Scene.cs" />
21 <include name="Scenes/Scene.PacketHandlers.cs" />
22 <include name="Scenes/Scene.Scripting.cs" />
23 <include name="Scenes/SceneBase.cs" />
24 <include name="Scenes/SceneEvents.cs" />
25 <include name="Scenes/SceneObject.cs" />
26 <include name="Scenes/ScenePresence.Animations.cs" />
27 <include name="Scenes/ScenePresence.Body.cs" />
28 <include name="Scenes/ScenePresence.cs" />
29 <include name="Scenes/scripting/Script.cs" />
30 <include name="Scenes/scripting/ScriptInfo.cs" />
31 <include name="Scenes/scripting/ScriptManager.cs" />
32 <include name="Scenes/scripting/Engines/CSharpScriptEngine.cs" />
33 <include name="Scenes/scripting/Engines/JScriptEngine.cs" />
34 <include name="Scenes/scripting/Engines/JSharpScriptEngine.cs" />
35 </sources>
36 <references basedir="${project::get-base-directory()}">
37 <lib>
38 <include name="${project::get-base-directory()}" />
39 <include name="${project::get-base-directory()}/${build.dir}" />
40 </lib>
41 <include name="../../../bin/Axiom.MathLib.dll" />
42 <include name="../../../bin/Db4objects.Db4o.dll" />
43 <include name="../../../bin/libsecondlife.dll" />
44 <include name="Microsoft.JScript.dll" />
45 <include name="../../../bin/OpenSim.Framework.dll" />
46 <include name="../../../bin/OpenSim.Framework.Communications.dll" />
47 <include name="../../../bin/OpenSim.Framework.Console.dll" />
48 <include name="../../../bin/OpenSim.Framework.GenericConfig.Xml.dll" />
49 <include name="../../../bin/OpenSim.Framework.Servers.dll" />
50 <include name="../../../bin/OpenSim.Region.Caches.dll" />
51 <include name="../../../bin/OpenSim.Region.Capabilities.dll" />
52 <include name="../../../bin/OpenSim.Region.Physics.Manager.dll" />
53 <include name="../../../bin/OpenSim.Region.Terrain.BasicTerrain.dll" />
54 <include name="System.dll" />
55 <include name="System.Xml.dll" />
56 <include name="VJSharpCodeProvider.dll" />
57 <include name="../../../bin/XMLRPC.dll" />
58 </references>
59 </csc>
60 <echo message="Copying from [${project::get-base-directory()}/${build.dir}/] to [${project::get-base-directory()}/../../../bin/" />
61 <mkdir dir="${project::get-base-directory()}/../../../bin/"/>
62 <copy todir="${project::get-base-directory()}/../../../bin/">
63 <fileset basedir="${project::get-base-directory()}/${build.dir}/" >
64 <include name="*.dll"/>
65 <include name="*.exe"/>
66 </fileset>
67 </copy>
68 </target>
69 <target name="clean">
70 <delete dir="${bin.dir}" failonerror="false" />
71 <delete dir="${obj.dir}" failonerror="false" />
72 </target>
73 <target name="doc" description="Creates documentation.">
74 </target>
75</project>
diff --git a/OpenSim/Region/Environment/Scenes/Entity.cs b/OpenSim/Region/Environment/Scenes/Entity.cs
index bbba34d..db5070d 100644
--- a/OpenSim/Region/Environment/Scenes/Entity.cs
+++ b/OpenSim/Region/Environment/Scenes/Entity.cs
@@ -31,11 +31,10 @@ using System.Text;
31using Axiom.MathLib; 31using Axiom.MathLib;
32using OpenSim.Physics.Manager; 32using OpenSim.Physics.Manager;
33using libsecondlife; 33using libsecondlife;
34using OpenSim.Region.Environment.Scripting;
35 34
36namespace OpenSim.Region.Environment.Scenes 35namespace OpenSim.Region.Environment.Scenes
37{ 36{
38 public abstract class Entity : IScriptReadonlyEntity 37 public abstract class Entity
39 { 38 {
40 public libsecondlife.LLUUID uuid; 39 public libsecondlife.LLUUID uuid;
41 public Quaternion rotation; 40 public Quaternion rotation;
diff --git a/OpenSim/Region/Environment/Scenes/Scene.cs b/OpenSim/Region/Environment/Scenes/Scene.cs
index ff54efa..b345c0c 100644
--- a/OpenSim/Region/Environment/Scenes/Scene.cs
+++ b/OpenSim/Region/Environment/Scenes/Scene.cs
@@ -39,12 +39,14 @@ using OpenSim.Framework.Interfaces;
39using OpenSim.Framework.Types; 39using OpenSim.Framework.Types;
40using OpenSim.Framework.Inventory; 40using OpenSim.Framework.Inventory;
41using OpenSim.Framework; 41using OpenSim.Framework;
42using OpenSim.Region.Environment.Scripting;
43using OpenSim.Region.Terrain; 42using OpenSim.Region.Terrain;
44using OpenSim.Framework.Communications; 43using OpenSim.Framework.Communications;
45using OpenSim.Region.Caches; 44using OpenSim.Region.Caches;
46using OpenSim.Region.Environment; 45using OpenSim.Region.Environment;
47using OpenSim.Framework.Servers; 46using OpenSim.Framework.Servers;
47using OpenSim.Scripting;
48using OpenSim.Region.Capabilities;
49using Caps = OpenSim.Region.Capabilities.Caps;
48 50
49namespace OpenSim.Region.Environment.Scenes 51namespace OpenSim.Region.Environment.Scenes
50{ 52{
@@ -60,20 +62,19 @@ namespace OpenSim.Region.Environment.Scenes
60 private Random Rand = new Random(); 62 private Random Rand = new Random();
61 private uint _primCount = 702000; 63 private uint _primCount = 702000;
62 private int storageCount; 64 private int storageCount;
63 private Dictionary<LLUUID, ScriptHandler> m_scriptHandlers;
64 private Dictionary<string, ScriptFactory> m_scripts;
65 private Mutex updateLock; 65 private Mutex updateLock;
66 66
67 protected AuthenticateSessionsBase authenticateHandler; 67 protected AuthenticateSessionsBase authenticateHandler;
68 protected RegionCommsListener regionCommsHost; 68 protected RegionCommsListener regionCommsHost;
69 protected CommunicationsManager commsManager; 69 protected CommunicationsManager commsManager;
70 70
71 protected Dictionary<LLUUID, Capabilities.Caps> capsHandlers = new Dictionary<LLUUID, Capabilities.Caps>(); 71 protected Dictionary<LLUUID,Caps> capsHandlers = new Dictionary<LLUUID, Caps>();
72 protected BaseHttpServer httpListener; 72 protected BaseHttpServer httpListener;
73 73
74 public ParcelManager parcelManager; 74 public ParcelManager parcelManager;
75 public EstateManager estateManager; 75 public EstateManager estateManager;
76 public EventManager eventManager; 76 public EventManager eventManager;
77 public ScriptManager scriptManager;
77 78
78 #region Properties 79 #region Properties
79 /// <summary> 80 /// <summary>
@@ -117,12 +118,9 @@ namespace OpenSim.Region.Environment.Scenes
117 118
118 parcelManager = new ParcelManager(this, this.m_regInfo); 119 parcelManager = new ParcelManager(this, this.m_regInfo);
119 estateManager = new EstateManager(this, this.m_regInfo); 120 estateManager = new EstateManager(this, this.m_regInfo);
120 121 scriptManager = new ScriptManager(this);
121 eventManager = new EventManager(); 122 eventManager = new EventManager();
122 123
123 m_scriptHandlers = new Dictionary<LLUUID, ScriptHandler>();
124 m_scripts = new Dictionary<string, ScriptFactory>();
125
126 OpenSim.Framework.Console.MainLog.Instance.Verbose( "World.cs - creating new entitities instance"); 124 OpenSim.Framework.Console.MainLog.Instance.Verbose( "World.cs - creating new entitities instance");
127 Entities = new Dictionary<libsecondlife.LLUUID, Entity>(); 125 Entities = new Dictionary<libsecondlife.LLUUID, Entity>();
128 Avatars = new Dictionary<LLUUID, ScenePresence>(); 126 Avatars = new Dictionary<LLUUID, ScenePresence>();
@@ -195,19 +193,9 @@ namespace OpenSim.Region.Environment.Scenes
195 Entities[UUID].update(); 193 Entities[UUID].update();
196 } 194 }
197 195
198 // New 196 // General purpose event manager
199 eventManager.TriggerOnFrame(); 197 eventManager.TriggerOnFrame();
200 198
201 // TODO: Obsolete - Phase out
202 foreach (ScriptHandler scriptHandler in m_scriptHandlers.Values)
203 {
204 scriptHandler.OnFrame();
205 }
206 foreach (IScriptEngine scripteng in this.scriptEngines.Values)
207 {
208 scripteng.OnFrame();
209 }
210
211 //backup world data 199 //backup world data
212 this.storageCount++; 200 this.storageCount++;
213 if (storageCount > 1200) //set to how often you want to backup 201 if (storageCount > 1200) //set to how often you want to backup
@@ -256,7 +244,7 @@ namespace OpenSim.Region.Environment.Scenes
256 //Parcel backup routines 244 //Parcel backup routines
257 ParcelData[] parcels = new ParcelData[parcelManager.parcelList.Count]; 245 ParcelData[] parcels = new ParcelData[parcelManager.parcelList.Count];
258 int i = 0; 246 int i = 0;
259 foreach (OpenSim.Region.Environment.Parcel parcel in parcelManager.parcelList.Values) 247 foreach (OpenSim.Region.Parcel parcel in parcelManager.parcelList.Values)
260 { 248 {
261 parcels[i] = parcel.parcelData; 249 parcels[i] = parcel.parcelData;
262 i++; 250 i++;
@@ -672,7 +660,7 @@ namespace OpenSim.Region.Environment.Scenes
672 if (agent.CapsPath != "") 660 if (agent.CapsPath != "")
673 { 661 {
674 //Console.WriteLine("new user, so creating caps handler for it"); 662 //Console.WriteLine("new user, so creating caps handler for it");
675 Capabilities.Caps cap = new Capabilities.Caps(this.assetCache, httpListener, this.m_regInfo.CommsIPListenAddr, 9000, agent.CapsPath, agent.AgentID); 663 Caps cap = new Caps(this.assetCache, httpListener, this.m_regInfo.CommsIPListenAddr, 9000, agent.CapsPath, agent.AgentID);
676 cap.RegisterHandlers(); 664 cap.RegisterHandlers();
677 this.capsHandlers.Add(agent.AgentID, cap); 665 this.capsHandlers.Add(agent.AgentID, cap);
678 } 666 }
diff --git a/OpenSim/Region/Environment/Scenes/SceneBase.cs b/OpenSim/Region/Environment/Scenes/SceneBase.cs
index 3d8f522..50d3b82 100644
--- a/OpenSim/Region/Environment/Scenes/SceneBase.cs
+++ b/OpenSim/Region/Environment/Scenes/SceneBase.cs
@@ -37,7 +37,6 @@ using OpenSim.Physics.Manager;
37using OpenSim.Framework.Interfaces; 37using OpenSim.Framework.Interfaces;
38using OpenSim.Framework.Types; 38using OpenSim.Framework.Types;
39using OpenSim.Framework.Inventory; 39using OpenSim.Framework.Inventory;
40using OpenSim.Region.Environment.Scripting;
41using OpenSim.Region.Terrain; 40using OpenSim.Region.Terrain;
42using OpenSim.Region.Caches; 41using OpenSim.Region.Caches;
43 42
diff --git a/OpenSim/Region/Environment/Scenes/scripting/Engines/CSharpScriptEngine.cs b/OpenSim/Region/Environment/Scenes/scripting/Engines/CSharpScriptEngine.cs
new file mode 100644
index 0000000..870303f
--- /dev/null
+++ b/OpenSim/Region/Environment/Scenes/scripting/Engines/CSharpScriptEngine.cs
@@ -0,0 +1,104 @@
1/*
2* Copyright (c) Contributors, http://www.openmetaverse.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 OpenSim 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.Collections.Generic;
30using System.Text;
31
32// Compilation stuff
33using System.CodeDom;
34using System.CodeDom.Compiler;
35using Microsoft.CSharp;
36
37namespace OpenSim.Scripting
38{
39 public class CSharpScriptEngine : IScriptCompiler
40 {
41 public string FileExt()
42 {
43 return ".cs";
44 }
45
46 private Dictionary<string,IScript> LoadDotNetScript(ICodeCompiler compiler, string filename)
47 {
48 CompilerParameters compilerParams = new CompilerParameters();
49 CompilerResults compilerResults;
50 compilerParams.GenerateExecutable = false;
51 compilerParams.GenerateInMemory = true;
52 compilerParams.IncludeDebugInformation = false;
53 compilerParams.ReferencedAssemblies.Add("OpenSim.Region.dll");
54 compilerParams.ReferencedAssemblies.Add("OpenSim.Framework.dll");
55 compilerParams.ReferencedAssemblies.Add("libsecondlife.dll");
56 compilerParams.ReferencedAssemblies.Add("System.dll");
57
58 compilerResults = compiler.CompileAssemblyFromFile(compilerParams, filename);
59
60 if (compilerResults.Errors.Count > 0)
61 {
62 OpenSim.Framework.Console.MainLog.Instance.Error("Compile errors");
63 foreach (CompilerError error in compilerResults.Errors)
64 {
65 OpenSim.Framework.Console.MainLog.Instance.Error(error.Line.ToString() + ": " + error.ErrorText.ToString());
66 }
67 }
68 else
69 {
70 Dictionary<string,IScript> scripts = new Dictionary<string,IScript>();
71
72 foreach (Type pluginType in compilerResults.CompiledAssembly.GetExportedTypes())
73 {
74 Type testInterface = pluginType.GetInterface("IScript", true);
75
76 if (testInterface != null)
77 {
78 IScript script = (IScript)compilerResults.CompiledAssembly.CreateInstance(pluginType.ToString());
79
80 string scriptName = "C#/" + script.getName();
81 Console.WriteLine("Script: " + scriptName + " loaded.");
82
83 if (!scripts.ContainsKey(scriptName))
84 {
85 scripts.Add(scriptName, script);
86 }
87 else
88 {
89 scripts[scriptName] = script;
90 }
91 }
92 }
93 return scripts;
94 }
95 return null;
96 }
97
98 public Dictionary<string,IScript> compile(string filename)
99 {
100 CSharpCodeProvider csharpProvider = new CSharpCodeProvider();
101 return LoadDotNetScript(csharpProvider.CreateCompiler(), filename);
102 }
103 }
104}
diff --git a/OpenSim/Region/Environment/Scenes/scripting/Engines/JScriptEngine.cs b/OpenSim/Region/Environment/Scenes/scripting/Engines/JScriptEngine.cs
new file mode 100644
index 0000000..ffae1d7
--- /dev/null
+++ b/OpenSim/Region/Environment/Scenes/scripting/Engines/JScriptEngine.cs
@@ -0,0 +1,104 @@
1/*
2* Copyright (c) Contributors, http://www.openmetaverse.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 OpenSim 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.Collections.Generic;
30using System.Text;
31
32// Compilation stuff
33using System.CodeDom;
34using System.CodeDom.Compiler;
35using Microsoft.JScript;
36
37namespace OpenSim.Scripting
38{
39 public class JScriptEngine : IScriptCompiler
40 {
41 public string FileExt()
42 {
43 return ".js";
44 }
45
46 private Dictionary<string, IScript> LoadDotNetScript(ICodeCompiler compiler, string filename)
47 {
48 CompilerParameters compilerParams = new CompilerParameters();
49 CompilerResults compilerResults;
50 compilerParams.GenerateExecutable = false;
51 compilerParams.GenerateInMemory = true;
52 compilerParams.IncludeDebugInformation = false;
53 compilerParams.ReferencedAssemblies.Add("OpenSim.Region.dll");
54 compilerParams.ReferencedAssemblies.Add("OpenSim.Framework.dll");
55 compilerParams.ReferencedAssemblies.Add("libsecondlife.dll");
56 compilerParams.ReferencedAssemblies.Add("System.dll");
57
58 compilerResults = compiler.CompileAssemblyFromFile(compilerParams, filename);
59
60 if (compilerResults.Errors.Count > 0)
61 {
62 OpenSim.Framework.Console.MainLog.Instance.Error("Compile errors");
63 foreach (CompilerError error in compilerResults.Errors)
64 {
65 OpenSim.Framework.Console.MainLog.Instance.Error(error.Line.ToString() + ": " + error.ErrorText.ToString());
66 }
67 }
68 else
69 {
70 Dictionary<string, IScript> scripts = new Dictionary<string, IScript>();
71
72 foreach (Type pluginType in compilerResults.CompiledAssembly.GetExportedTypes())
73 {
74 Type testInterface = pluginType.GetInterface("IScript", true);
75
76 if (testInterface != null)
77 {
78 IScript script = (IScript)compilerResults.CompiledAssembly.CreateInstance(pluginType.ToString());
79
80 string scriptName = "JS.NET/" + script.getName();
81 Console.WriteLine("Script: " + scriptName + " loaded.");
82
83 if (!scripts.ContainsKey(scriptName))
84 {
85 scripts.Add(scriptName, script);
86 }
87 else
88 {
89 scripts[scriptName] = script;
90 }
91 }
92 }
93 return scripts;
94 }
95 return null;
96 }
97
98 public Dictionary<string, IScript> compile(string filename)
99 {
100 JScriptCodeProvider jscriptProvider = new JScriptCodeProvider();
101 return LoadDotNetScript(jscriptProvider.CreateCompiler(), filename);
102 }
103 }
104}
diff --git a/OpenSim/Region/Environment/Scenes/scripting/Engines/JSharpScriptEngine.cs b/OpenSim/Region/Environment/Scenes/scripting/Engines/JSharpScriptEngine.cs
new file mode 100644
index 0000000..b33b55d
--- /dev/null
+++ b/OpenSim/Region/Environment/Scenes/scripting/Engines/JSharpScriptEngine.cs
@@ -0,0 +1,104 @@
1/*
2* Copyright (c) Contributors, http://www.openmetaverse.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 OpenSim 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.Collections.Generic;
30using System.Text;
31
32// Compilation stuff
33using System.CodeDom;
34using System.CodeDom.Compiler;
35using Microsoft.VJSharp;
36
37namespace OpenSim.Scripting
38{
39 public class JSharpScriptEngine : IScriptCompiler
40 {
41 public string FileExt()
42 {
43 return ".jsl";
44 }
45
46 private Dictionary<string, IScript> LoadDotNetScript(ICodeCompiler compiler, string filename)
47 {
48 CompilerParameters compilerParams = new CompilerParameters();
49 CompilerResults compilerResults;
50 compilerParams.GenerateExecutable = false;
51 compilerParams.GenerateInMemory = true;
52 compilerParams.IncludeDebugInformation = false;
53 compilerParams.ReferencedAssemblies.Add("OpenSim.Region.dll");
54 compilerParams.ReferencedAssemblies.Add("OpenSim.Framework.dll");
55 compilerParams.ReferencedAssemblies.Add("libsecondlife.dll");
56 compilerParams.ReferencedAssemblies.Add("System.dll");
57
58 compilerResults = compiler.CompileAssemblyFromFile(compilerParams, filename);
59
60 if (compilerResults.Errors.Count > 0)
61 {
62 OpenSim.Framework.Console.MainLog.Instance.Error("Compile errors");
63 foreach (CompilerError error in compilerResults.Errors)
64 {
65 OpenSim.Framework.Console.MainLog.Instance.Error(error.Line.ToString() + ": " + error.ErrorText.ToString());
66 }
67 }
68 else
69 {
70 Dictionary<string, IScript> scripts = new Dictionary<string, IScript>();
71
72 foreach (Type pluginType in compilerResults.CompiledAssembly.GetExportedTypes())
73 {
74 Type testInterface = pluginType.GetInterface("IScript", true);
75
76 if (testInterface != null)
77 {
78 IScript script = (IScript)compilerResults.CompiledAssembly.CreateInstance(pluginType.ToString());
79
80 string scriptName = "J#/" + script.getName();
81 Console.WriteLine("Script: " + scriptName + " loaded.");
82
83 if (!scripts.ContainsKey(scriptName))
84 {
85 scripts.Add(scriptName, script);
86 }
87 else
88 {
89 scripts[scriptName] = script;
90 }
91 }
92 }
93 return scripts;
94 }
95 return null;
96 }
97
98 public Dictionary<string, IScript> compile(string filename)
99 {
100 VJSharpCodeProvider jsharpProvider = new VJSharpCodeProvider();
101 return LoadDotNetScript(jsharpProvider.CreateCompiler(), filename);
102 }
103 }
104}
diff --git a/OpenSim/Region/Environment/Scenes/scripting/IScriptContext.cs b/OpenSim/Region/Environment/Scenes/scripting/IScriptContext.cs
deleted file mode 100644
index eb8a117..0000000
--- a/OpenSim/Region/Environment/Scenes/scripting/IScriptContext.cs
+++ /dev/null
@@ -1,40 +0,0 @@
1/*
2* Copyright (c) Contributors, http://www.openmetaverse.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 OpenSim 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.Collections.Generic;
30using System.Text;
31using libsecondlife;
32
33namespace OpenSim.Region.Environment.Scripting
34{
35 public interface IScriptContext
36 {
37 IScriptEntity Entity { get; }
38 bool TryGetRandomAvatar(out IScriptReadonlyEntity avatar);
39 }
40}
diff --git a/OpenSim/Region/Environment/Scenes/scripting/IScriptEntity.cs b/OpenSim/Region/Environment/Scenes/scripting/IScriptEntity.cs
deleted file mode 100644
index e813626..0000000
--- a/OpenSim/Region/Environment/Scenes/scripting/IScriptEntity.cs
+++ /dev/null
@@ -1,46 +0,0 @@
1/*
2* Copyright (c) Contributors, http://www.openmetaverse.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 OpenSim 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.Collections.Generic;
30using System.Text;
31using libsecondlife;
32
33namespace OpenSim.Region.Environment.Scripting
34{
35 public interface IScriptReadonlyEntity
36 {
37 LLVector3 Pos { get; }
38 string Name { get; }
39 }
40
41 public interface IScriptEntity
42 {
43 LLVector3 Pos { get; set; }
44 string Name { get; }
45 }
46}
diff --git a/OpenSim/Region/Environment/Scenes/scripting/IScriptHandler.cs b/OpenSim/Region/Environment/Scenes/scripting/IScriptHandler.cs
deleted file mode 100644
index 115b4f4..0000000
--- a/OpenSim/Region/Environment/Scenes/scripting/IScriptHandler.cs
+++ /dev/null
@@ -1,126 +0,0 @@
1/*
2* Copyright (c) Contributors, http://www.openmetaverse.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 OpenSim 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.Collections.Generic;
30using System.Text;
31using libsecondlife;
32using OpenSim.Physics.Manager;
33using OpenSim.Region.Environment;
34using OpenSim.Region.Environment.Scenes;
35using Avatar=OpenSim.Region.Environment.Scenes.ScenePresence;
36using Primitive = OpenSim.Region.Environment.Scenes.Primitive;
37
38namespace OpenSim.Region.Environment.Scripting
39{
40 public delegate void ScriptEventHandler(IScriptContext context);
41
42 public class ScriptHandler : IScriptContext, IScriptEntity, IScriptReadonlyEntity
43 {
44 private Scene m_world;
45 private Script m_script;
46 private Entity m_entity;
47
48 public LLUUID ScriptId
49 {
50 get
51 {
52 return m_script.ScriptId;
53 }
54 }
55
56 public void OnFrame()
57 {
58 m_script.OnFrame(this);
59 }
60
61 public ScriptHandler(Script script, Entity entity, Scene world)
62 {
63 m_script = script;
64 m_entity = entity;
65 m_world = world;
66 }
67
68 #region IScriptContext Members
69
70 IScriptEntity IScriptContext.Entity
71 {
72 get
73 {
74 return this;
75 }
76 }
77
78 bool IScriptContext.TryGetRandomAvatar(out IScriptReadonlyEntity avatar)
79 {
80 foreach (Entity entity in m_world.Entities.Values )
81 {
82 if( entity is Avatar )
83 {
84 avatar = entity;
85 return true;
86 }
87 }
88
89 avatar = null;
90 return false;
91 }
92
93 #endregion
94
95 #region IScriptEntity and IScriptReadonlyEntity Members
96
97 public string Name
98 {
99 get
100 {
101 return m_entity.Name;
102 }
103 }
104
105 public LLVector3 Pos
106 {
107 get
108 {
109 return m_entity.Pos;
110 }
111
112 set
113 {
114 if (m_entity is Primitive)
115 {
116 Primitive prim = m_entity as Primitive;
117 // Of course, we really should have asked the physEngine if this is possible, and if not, returned false.
118 // prim.UpdatePosition( value );
119 }
120 }
121 }
122
123 #endregion
124 }
125
126}
diff --git a/OpenSim/Region/Environment/Scenes/scripting/ScriptFactory.cs b/OpenSim/Region/Environment/Scenes/scripting/ScriptFactory.cs
deleted file mode 100644
index 0ce65ea..0000000
--- a/OpenSim/Region/Environment/Scenes/scripting/ScriptFactory.cs
+++ /dev/null
@@ -1,35 +0,0 @@
1/*
2* Copyright (c) Contributors, http://www.openmetaverse.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 OpenSim 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.Collections.Generic;
30using System.Text;
31
32namespace OpenSim.Region.Environment.Scripting
33{
34 public delegate Script ScriptFactory();
35}
diff --git a/OpenSim/Region/Environment/Scenes/scripting/Script.cs b/OpenSim/Region/Environment/Scenes/scripting/ScriptInfo.cs
index 5d398b0..57df4c4 100644
--- a/OpenSim/Region/Environment/Scenes/scripting/Script.cs
+++ b/OpenSim/Region/Environment/Scenes/scripting/ScriptInfo.cs
@@ -28,26 +28,31 @@
28using System; 28using System;
29using System.Collections.Generic; 29using System.Collections.Generic;
30using System.Text; 30using System.Text;
31using libsecondlife;
32 31
33namespace OpenSim.Region.Environment.Scripting 32using OpenSim.Region.Environment.Scenes;
33using OpenSim.Framework.Console;
34
35namespace OpenSim.Scripting
34{ 36{
35 public class Script 37 /// <summary>
38 /// Class which provides access to the world
39 /// </summary>
40 public class ScriptInfo
36 { 41 {
37 private LLUUID m_scriptId; 42 // Reference to world.eventsManager provided for convenience
38 public virtual LLUUID ScriptId 43 public EventManager events;
39 { 44
40 get 45 // The main world
41 { 46 public Scene world;
42 return m_scriptId; 47
43 } 48 // The console
44 } 49 public LogBase logger;
45 50
46 public Script( LLUUID scriptId ) 51 public ScriptInfo(Scene scene)
47 { 52 {
48 m_scriptId = scriptId; 53 world = scene;
54 events = world.eventManager;
55 logger = OpenSim.Framework.Console.MainLog.Instance;
49 } 56 }
50
51 public ScriptEventHandler OnFrame;
52 } 57 }
53} 58}
diff --git a/OpenSim/Region/Environment/Scenes/scripting/ScriptManager.cs b/OpenSim/Region/Environment/Scenes/scripting/ScriptManager.cs
new file mode 100644
index 0000000..5d1d188
--- /dev/null
+++ b/OpenSim/Region/Environment/Scenes/scripting/ScriptManager.cs
@@ -0,0 +1,99 @@
1/*
2* Copyright (c) Contributors, http://www.openmetaverse.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 OpenSim 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.Collections.Generic;
30using System.Text;
31
32namespace OpenSim.Scripting
33{
34 public class ScriptManager
35 {
36 List<IScript> scripts = new List<IScript>();
37 OpenSim.Region.Environment.Scenes.Scene scene;
38 Dictionary<string, IScriptCompiler> compilers = new Dictionary<string, IScriptCompiler>();
39
40 private void LoadFromCompiler(Dictionary<string, IScript> compiledscripts)
41 {
42 foreach (KeyValuePair<string, IScript> script in compiledscripts)
43 {
44 ScriptInfo scriptInfo = new ScriptInfo(scene); // Since each script could potentially corrupt their access with a stray assignment, making a new one for each script.
45 OpenSim.Framework.Console.MainLog.Instance.Verbose("Loading " + script.Key);
46 script.Value.Initialise(scriptInfo);
47 scripts.Add(script.Value);
48 }
49 OpenSim.Framework.Console.MainLog.Instance.Verbose("Finished loading " + compiledscripts.Count.ToString() + " script(s)");
50 }
51
52 public ScriptManager(OpenSim.Region.Environment.Scenes.Scene world)
53 {
54 scene = world;
55
56 // Default Engines
57 CSharpScriptEngine csharpCompiler = new CSharpScriptEngine();
58 compilers.Add(csharpCompiler.FileExt(),csharpCompiler);
59
60 JScriptEngine jscriptCompiler = new JScriptEngine();
61 compilers.Add(jscriptCompiler.FileExt(), jscriptCompiler);
62
63 JSharpScriptEngine jsharpCompiler = new JSharpScriptEngine();
64 compilers.Add(jsharpCompiler.FileExt(), jsharpCompiler);
65 }
66
67 public void Compile(string filename)
68 {
69 foreach (KeyValuePair<string, IScriptCompiler> compiler in compilers)
70 {
71 if (filename.EndsWith(compiler.Key))
72 {
73 LoadFromCompiler(compiler.Value.compile(filename));
74 break;
75 }
76 }
77 }
78
79 public void RunScriptCmd(string[] args)
80 {
81 switch (args[0])
82 {
83 case "load":
84 Compile(args[1]);
85 break;
86
87 default:
88 OpenSim.Framework.Console.MainLog.Instance.Error("Unknown script command");
89 break;
90 }
91 }
92 }
93
94 interface IScriptCompiler
95 {
96 Dictionary<string,IScript> compile(string filename);
97 string FileExt();
98 }
99}
diff --git a/OpenSim/Region/Environment/Scenes/scripting/Scripts/FollowRandomAvatar.cs b/OpenSim/Region/Environment/Scenes/scripting/Scripts/FollowRandomAvatar.cs
deleted file mode 100644
index 90c79e3..0000000
--- a/OpenSim/Region/Environment/Scenes/scripting/Scripts/FollowRandomAvatar.cs
+++ /dev/null
@@ -1,64 +0,0 @@
1/*
2* Copyright (c) Contributors, http://www.openmetaverse.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 OpenSim 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.Collections.Generic;
30using System.Text;
31using libsecondlife;
32
33namespace OpenSim.Region.Environment.Scripting
34{
35 public class FollowRandomAvatar : Script
36 {
37 public FollowRandomAvatar()
38 : base(LLUUID.Random())
39 {
40 OnFrame += MyOnFrame;
41 }
42
43 private void MyOnFrame(IScriptContext context)
44 {
45 LLVector3 pos = context.Entity.Pos;
46
47 IScriptReadonlyEntity avatar;
48
49 if (context.TryGetRandomAvatar(out avatar))
50 {
51 LLVector3 avatarPos = avatar.Pos;
52
53 float x = pos.X + ((float)avatarPos.X.CompareTo(pos.X)) / 2;
54 float y = pos.Y + ((float)avatarPos.Y.CompareTo(pos.Y)) / 2;
55
56 LLVector3 newPos = new LLVector3(x, y, pos.Z);
57
58 context.Entity.Pos = newPos;
59 }
60 }
61 }
62
63
64}