aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim
diff options
context:
space:
mode:
authorAdam Frisby2007-06-28 08:09:05 +0000
committerAdam Frisby2007-06-28 08:09:05 +0000
commit0c1a6c85cc678effc882dd5897d3357416807ba9 (patch)
tree6149f74c6a5a4d75bbeea3711a687dc6dcc66a6f /OpenSim
parentSome very Preliminary work on .net remoting for interregion comms. (diff)
downloadopensim-SC_OLD-0c1a6c85cc678effc882dd5897d3357416807ba9.zip
opensim-SC_OLD-0c1a6c85cc678effc882dd5897d3357416807ba9.tar.gz
opensim-SC_OLD-0c1a6c85cc678effc882dd5897d3357416807ba9.tar.bz2
opensim-SC_OLD-0c1a6c85cc678effc882dd5897d3357416807ba9.tar.xz
* Brand spankin' new scripting engine.
* Use "script load somefile.cs" for C# scripting. Will commit additional languages shortly. Scripts should implement the IScript interfaces to work correctly. * Someone port this over to NameSpaceChanges (built in Sugilite since sugilite is working)
Diffstat (limited to 'OpenSim')
-rw-r--r--OpenSim/OpenSim.Region/OpenSim.Region.csproj25
-rw-r--r--OpenSim/OpenSim.Region/Scenes/Entity.cs3
-rw-r--r--OpenSim/OpenSim.Region/Scenes/Scene.cs22
-rw-r--r--OpenSim/OpenSim.Region/Scenes/SceneBase.cs1
-rw-r--r--OpenSim/OpenSim.Region/Scenes/scripting/CSharpScriptEngine.cs77
-rw-r--r--OpenSim/OpenSim.Region/Scenes/scripting/IScriptContext.cs40
-rw-r--r--OpenSim/OpenSim.Region/Scenes/scripting/IScriptEntity.cs46
-rw-r--r--OpenSim/OpenSim.Region/Scenes/scripting/IScriptHandler.cs126
-rw-r--r--OpenSim/OpenSim.Region/Scenes/scripting/Script.cs71
-rw-r--r--OpenSim/OpenSim.Region/Scenes/scripting/ScriptFactory.cs35
-rw-r--r--OpenSim/OpenSim.Region/Scenes/scripting/ScriptInfo.cs (renamed from OpenSim/OpenSim.Scripting/ScriptAccess.cs)0
-rw-r--r--OpenSim/OpenSim.Region/Scenes/scripting/ScriptManager.cs66
-rw-r--r--OpenSim/OpenSim.Region/Scenes/scripting/Scripts/FollowRandomAvatar.cs64
-rw-r--r--OpenSim/OpenSim.Scripting/OpenSim.Scripting.csproj66
-rw-r--r--OpenSim/OpenSim.Scripting/Properties/AssemblyInfo.cs35
-rw-r--r--OpenSim/OpenSim.Scripting/Script.cs32
-rw-r--r--OpenSim/OpenSim/OpenSimMain.cs7
17 files changed, 193 insertions, 523 deletions
diff --git a/OpenSim/OpenSim.Region/OpenSim.Region.csproj b/OpenSim/OpenSim.Region/OpenSim.Region.csproj
index 0868c68..0d9e9b0 100644
--- a/OpenSim/OpenSim.Region/OpenSim.Region.csproj
+++ b/OpenSim/OpenSim.Region/OpenSim.Region.csproj
@@ -190,24 +190,13 @@
190 <Compile Include="Scenes\ScenePresence.cs"> 190 <Compile Include="Scenes\ScenePresence.cs">
191 <SubType>Code</SubType> 191 <SubType>Code</SubType>
192 </Compile> 192 </Compile>
193 <Compile Include="Scenes\scripting\IScriptContext.cs"> 193 <Compile Include="Scenes\scripting\CSharpScriptEngine.cs" />
194 <SubType>Code</SubType> 194 <Compile Include="Scenes\scripting\Script.cs" />
195 </Compile> 195 <Compile Include="Scenes\scripting\ScriptInfo.cs" />
196 <Compile Include="Scenes\scripting\IScriptEntity.cs"> 196 <Compile Include="Scenes\scripting\ScriptManager.cs" />
197 <SubType>Code</SubType> 197 </ItemGroup>
198 </Compile> 198 <ItemGroup>
199 <Compile Include="Scenes\scripting\IScriptHandler.cs"> 199 <Folder Include="Scenes\scripting\CSharpScripts\" />
200 <SubType>Code</SubType>
201 </Compile>
202 <Compile Include="Scenes\scripting\Script.cs">
203 <SubType>Code</SubType>
204 </Compile>
205 <Compile Include="Scenes\scripting\ScriptFactory.cs">
206 <SubType>Code</SubType>
207 </Compile>
208 <Compile Include="Scenes\scripting\Scripts\FollowRandomAvatar.cs">
209 <SubType>Code</SubType>
210 </Compile>
211 </ItemGroup> 200 </ItemGroup>
212 <Import Project="$(MSBuildBinPath)\Microsoft.CSHARP.Targets" /> 201 <Import Project="$(MSBuildBinPath)\Microsoft.CSHARP.Targets" />
213 <PropertyGroup> 202 <PropertyGroup>
diff --git a/OpenSim/OpenSim.Region/Scenes/Entity.cs b/OpenSim/OpenSim.Region/Scenes/Entity.cs
index f8754f5..77f8854 100644
--- a/OpenSim/OpenSim.Region/Scenes/Entity.cs
+++ b/OpenSim/OpenSim.Region/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.Scripting;
35 34
36namespace OpenSim.Region.Scenes 35namespace OpenSim.Region.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/OpenSim.Region/Scenes/Scene.cs b/OpenSim/OpenSim.Region/Scenes/Scene.cs
index bf2244e..f7d90fa 100644
--- a/OpenSim/OpenSim.Region/Scenes/Scene.cs
+++ b/OpenSim/OpenSim.Region/Scenes/Scene.cs
@@ -39,12 +39,12 @@ 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.Scripting;
43using OpenSim.Terrain; 42using OpenSim.Terrain;
44using OpenGrid.Framework.Communications; 43using OpenGrid.Framework.Communications;
45using OpenSim.Caches; 44using OpenSim.Caches;
46using OpenSim.Region; 45using OpenSim.Region;
47using OpenSim.Servers; 46using OpenSim.Servers;
47using OpenSim.Scripting;
48 48
49namespace OpenSim.Region.Scenes 49namespace OpenSim.Region.Scenes
50{ 50{
@@ -60,8 +60,6 @@ namespace OpenSim.Region.Scenes
60 private Random Rand = new Random(); 60 private Random Rand = new Random();
61 private uint _primCount = 702000; 61 private uint _primCount = 702000;
62 private int storageCount; 62 private int storageCount;
63 private Dictionary<LLUUID, ScriptHandler> m_scriptHandlers;
64 private Dictionary<string, ScriptFactory> m_scripts;
65 private Mutex updateLock; 63 private Mutex updateLock;
66 64
67 protected AuthenticateSessionsBase authenticateHandler; 65 protected AuthenticateSessionsBase authenticateHandler;
@@ -74,6 +72,7 @@ namespace OpenSim.Region.Scenes
74 public ParcelManager parcelManager; 72 public ParcelManager parcelManager;
75 public EstateManager estateManager; 73 public EstateManager estateManager;
76 public EventManager eventManager; 74 public EventManager eventManager;
75 public ScriptManager scriptManager;
77 76
78 #region Properties 77 #region Properties
79 /// <summary> 78 /// <summary>
@@ -117,12 +116,9 @@ namespace OpenSim.Region.Scenes
117 116
118 parcelManager = new ParcelManager(this, this.m_regInfo); 117 parcelManager = new ParcelManager(this, this.m_regInfo);
119 estateManager = new EstateManager(this, this.m_regInfo); 118 estateManager = new EstateManager(this, this.m_regInfo);
120 119 scriptManager = new ScriptManager(this);
121 eventManager = new EventManager(); 120 eventManager = new EventManager();
122 121
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"); 122 OpenSim.Framework.Console.MainLog.Instance.Verbose( "World.cs - creating new entitities instance");
127 Entities = new Dictionary<libsecondlife.LLUUID, Entity>(); 123 Entities = new Dictionary<libsecondlife.LLUUID, Entity>();
128 Avatars = new Dictionary<LLUUID, ScenePresence>(); 124 Avatars = new Dictionary<LLUUID, ScenePresence>();
@@ -195,19 +191,9 @@ namespace OpenSim.Region.Scenes
195 Entities[UUID].update(); 191 Entities[UUID].update();
196 } 192 }
197 193
198 // New 194 // General purpose event manager
199 eventManager.TriggerOnFrame(); 195 eventManager.TriggerOnFrame();
200 196
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 197 //backup world data
212 this.storageCount++; 198 this.storageCount++;
213 if (storageCount > 1200) //set to how often you want to backup 199 if (storageCount > 1200) //set to how often you want to backup
diff --git a/OpenSim/OpenSim.Region/Scenes/SceneBase.cs b/OpenSim/OpenSim.Region/Scenes/SceneBase.cs
index 4dbd374..5275fcf 100644
--- a/OpenSim/OpenSim.Region/Scenes/SceneBase.cs
+++ b/OpenSim/OpenSim.Region/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.Scripting;
41using OpenSim.Terrain; 40using OpenSim.Terrain;
42using OpenSim.Caches; 41using OpenSim.Caches;
43 42
diff --git a/OpenSim/OpenSim.Region/Scenes/scripting/CSharpScriptEngine.cs b/OpenSim/OpenSim.Region/Scenes/scripting/CSharpScriptEngine.cs
new file mode 100644
index 0000000..d5622b8
--- /dev/null
+++ b/OpenSim/OpenSim.Region/Scenes/scripting/CSharpScriptEngine.cs
@@ -0,0 +1,77 @@
1using System;
2using System.Collections.Generic;
3using System.Text;
4
5// Compilation stuff
6using System.CodeDom;
7using System.CodeDom.Compiler;
8using Microsoft.CSharp;
9
10namespace OpenSim.Scripting
11{
12 public class CSharpScriptEngine : IScriptCompiler
13 {
14 public string fileExt()
15 {
16 return ".cs";
17 }
18
19 private Dictionary<string,IScript> LoadDotNetScript(ICodeCompiler compiler, string filename)
20 {
21 CompilerParameters compilerParams = new CompilerParameters();
22 CompilerResults compilerResults;
23 compilerParams.GenerateExecutable = false;
24 compilerParams.GenerateInMemory = true;
25 compilerParams.IncludeDebugInformation = false;
26 compilerParams.ReferencedAssemblies.Add("OpenSim.Region.dll");
27 compilerParams.ReferencedAssemblies.Add("OpenSim.Framework.dll");
28 compilerParams.ReferencedAssemblies.Add("libsecondlife.dll");
29 compilerParams.ReferencedAssemblies.Add("System.dll");
30
31 compilerResults = compiler.CompileAssemblyFromFile(compilerParams, filename);
32
33 if (compilerResults.Errors.Count > 0)
34 {
35 OpenSim.Framework.Console.MainLog.Instance.Error("Compile errors");
36 foreach (CompilerError error in compilerResults.Errors)
37 {
38 OpenSim.Framework.Console.MainLog.Instance.Error(error.Line.ToString() + ": " + error.ErrorText.ToString());
39 }
40 }
41 else
42 {
43 Dictionary<string,IScript> scripts = new Dictionary<string,IScript>();
44
45 foreach (Type pluginType in compilerResults.CompiledAssembly.GetExportedTypes())
46 {
47 Type testInterface = pluginType.GetInterface("IScript", true);
48
49 if (testInterface != null)
50 {
51 IScript script = (IScript)compilerResults.CompiledAssembly.CreateInstance(pluginType.ToString());
52
53 string scriptName = "C#/" + script.getName();
54 Console.WriteLine("Script: " + scriptName + " loaded.");
55
56 if (!scripts.ContainsKey(scriptName))
57 {
58 scripts.Add(scriptName, script);
59 }
60 else
61 {
62 scripts[scriptName] = script;
63 }
64 }
65 }
66 return scripts;
67 }
68 return null;
69 }
70
71 public Dictionary<string,IScript> compile(string filename)
72 {
73 CSharpCodeProvider csharpProvider = new CSharpCodeProvider();
74 return LoadDotNetScript(csharpProvider.CreateCompiler(), filename);
75 }
76 }
77}
diff --git a/OpenSim/OpenSim.Region/Scenes/scripting/IScriptContext.cs b/OpenSim/OpenSim.Region/Scenes/scripting/IScriptContext.cs
deleted file mode 100644
index daa1b92..0000000
--- a/OpenSim/OpenSim.Region/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.Scripting
34{
35 public interface IScriptContext
36 {
37 IScriptEntity Entity { get; }
38 bool TryGetRandomAvatar(out IScriptReadonlyEntity avatar);
39 }
40}
diff --git a/OpenSim/OpenSim.Region/Scenes/scripting/IScriptEntity.cs b/OpenSim/OpenSim.Region/Scenes/scripting/IScriptEntity.cs
deleted file mode 100644
index 44b886f..0000000
--- a/OpenSim/OpenSim.Region/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.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/OpenSim.Region/Scenes/scripting/IScriptHandler.cs b/OpenSim/OpenSim.Region/Scenes/scripting/IScriptHandler.cs
deleted file mode 100644
index 797998d..0000000
--- a/OpenSim/OpenSim.Region/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;
34using OpenSim.Region.Scenes;
35using Avatar=OpenSim.Region.Scenes.ScenePresence;
36using Primitive = OpenSim.Region.Scenes.Primitive;
37
38namespace OpenSim.Region.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/OpenSim.Region/Scenes/scripting/Script.cs b/OpenSim/OpenSim.Region/Scenes/scripting/Script.cs
index 1d01f3c..57390bc 100644
--- a/OpenSim/OpenSim.Region/Scenes/scripting/Script.cs
+++ b/OpenSim/OpenSim.Region/Scenes/scripting/Script.cs
@@ -1,53 +1,44 @@
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; 1using System;
29using System.Collections.Generic; 2using System.Collections.Generic;
30using System.Text; 3using System.Text;
31using libsecondlife;
32 4
33namespace OpenSim.Region.Scripting 5using OpenSim.Framework.Console;
6using OpenSim.Framework;
7using OpenSim.Region;
8using OpenSim.Region.Scenes;
9
10namespace OpenSim.Scripting
34{ 11{
35 public class Script 12 public interface IScript
13 {
14 void Initialise(ScriptInfo scriptInfo);
15 string getName();
16 }
17
18 public class TestScript : IScript
36 { 19 {
37 private LLUUID m_scriptId; 20 ScriptInfo script;
38 public virtual LLUUID ScriptId 21
22 public string getName()
23 {
24 return "TestScript 0.1";
25 }
26
27 public void Initialise(ScriptInfo scriptInfo)
28 {
29 script = scriptInfo;
30 script.events.OnFrame += new OpenSim.Region.Scenes.EventManager.OnFrameDelegate(events_OnFrame);
31 script.events.OnNewPresence += new EventManager.OnNewPresenceDelegate(events_OnNewPresence);
32 }
33
34 void events_OnNewPresence(ScenePresence presence)
39 { 35 {
40 get 36 script.logger.Verbose("Hello " + presence.firstname.ToString() + "!");
41 {
42 return m_scriptId;
43 }
44 } 37 }
45 38
46 public Script( LLUUID scriptId ) 39 void events_OnFrame()
47 { 40 {
48 m_scriptId = scriptId; 41 //script.logger.Verbose("Hello World!");
49 } 42 }
50
51 public ScriptEventHandler OnFrame;
52 } 43 }
53} 44}
diff --git a/OpenSim/OpenSim.Region/Scenes/scripting/ScriptFactory.cs b/OpenSim/OpenSim.Region/Scenes/scripting/ScriptFactory.cs
deleted file mode 100644
index 32ef046..0000000
--- a/OpenSim/OpenSim.Region/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.Scripting
33{
34 public delegate Script ScriptFactory();
35}
diff --git a/OpenSim/OpenSim.Scripting/ScriptAccess.cs b/OpenSim/OpenSim.Region/Scenes/scripting/ScriptInfo.cs
index a9fede5..a9fede5 100644
--- a/OpenSim/OpenSim.Scripting/ScriptAccess.cs
+++ b/OpenSim/OpenSim.Region/Scenes/scripting/ScriptInfo.cs
diff --git a/OpenSim/OpenSim.Region/Scenes/scripting/ScriptManager.cs b/OpenSim/OpenSim.Region/Scenes/scripting/ScriptManager.cs
new file mode 100644
index 0000000..ff5c115
--- /dev/null
+++ b/OpenSim/OpenSim.Region/Scenes/scripting/ScriptManager.cs
@@ -0,0 +1,66 @@
1using System;
2using System.Collections.Generic;
3using System.Text;
4
5namespace OpenSim.Scripting
6{
7 public class ScriptManager
8 {
9 List<IScript> scripts = new List<IScript>();
10 OpenSim.Region.Scenes.Scene scene;
11 Dictionary<string, IScriptCompiler> compilers = new Dictionary<string, IScriptCompiler>();
12
13 private void LoadFromCompiler(Dictionary<string, IScript> compiledscripts)
14 {
15 foreach (KeyValuePair<string, IScript> script in compiledscripts)
16 {
17 ScriptInfo scriptInfo = new ScriptInfo(scene); // Since each script could potentially corrupt their access with a stray assignment, making a new one for each script.
18 OpenSim.Framework.Console.MainLog.Instance.Verbose("Loading " + script.Key);
19 script.Value.Initialise(scriptInfo);
20 scripts.Add(script.Value);
21 }
22 OpenSim.Framework.Console.MainLog.Instance.Verbose("Finished loading " + compiledscripts.Count.ToString() + " script(s)");
23 }
24
25 public ScriptManager(OpenSim.Region.Scenes.Scene world)
26 {
27 scene = world;
28
29 // Defualt Engines
30 CSharpScriptEngine csharpCompiler = new CSharpScriptEngine();
31 compilers.Add(csharpCompiler.fileExt(),csharpCompiler);
32 }
33
34 public void Compile(string filename)
35 {
36 foreach (KeyValuePair<string, IScriptCompiler> compiler in compilers)
37 {
38 if (filename.EndsWith(compiler.Key))
39 {
40 LoadFromCompiler(compiler.Value.compile(filename));
41 break;
42 }
43 }
44 }
45
46 public void RunScriptCmd(string[] args)
47 {
48 switch (args[0])
49 {
50 case "load":
51 Compile(args[1]);
52 break;
53
54 default:
55 OpenSim.Framework.Console.MainLog.Instance.Error("Unknown script command");
56 break;
57 }
58 }
59 }
60
61 interface IScriptCompiler
62 {
63 Dictionary<string,IScript> compile(string filename);
64 string fileExt();
65 }
66}
diff --git a/OpenSim/OpenSim.Region/Scenes/scripting/Scripts/FollowRandomAvatar.cs b/OpenSim/OpenSim.Region/Scenes/scripting/Scripts/FollowRandomAvatar.cs
deleted file mode 100644
index 21f07a8..0000000
--- a/OpenSim/OpenSim.Region/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.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}
diff --git a/OpenSim/OpenSim.Scripting/OpenSim.Scripting.csproj b/OpenSim/OpenSim.Scripting/OpenSim.Scripting.csproj
deleted file mode 100644
index 41b852d..0000000
--- a/OpenSim/OpenSim.Scripting/OpenSim.Scripting.csproj
+++ /dev/null
@@ -1,66 +0,0 @@
1<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
2 <PropertyGroup>
3 <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
4 <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
5 <ProductVersion>8.0.50727</ProductVersion>
6 <SchemaVersion>2.0</SchemaVersion>
7 <ProjectGuid>{3C3A8BD5-F53C-42D0-8ADE-E2492790788A}</ProjectGuid>
8 <OutputType>Library</OutputType>
9 <AppDesignerFolder>Properties</AppDesignerFolder>
10 <RootNamespace>OpenSim.Scripting</RootNamespace>
11 <AssemblyName>OpenSim.Scripting</AssemblyName>
12 </PropertyGroup>
13 <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
14 <DebugSymbols>true</DebugSymbols>
15 <DebugType>full</DebugType>
16 <Optimize>false</Optimize>
17 <OutputPath>bin\Debug\</OutputPath>
18 <DefineConstants>DEBUG;TRACE</DefineConstants>
19 <ErrorReport>prompt</ErrorReport>
20 <WarningLevel>4</WarningLevel>
21 </PropertyGroup>
22 <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
23 <DebugType>pdbonly</DebugType>
24 <Optimize>true</Optimize>
25 <OutputPath>bin\Release\</OutputPath>
26 <DefineConstants>TRACE</DefineConstants>
27 <ErrorReport>prompt</ErrorReport>
28 <WarningLevel>4</WarningLevel>
29 </PropertyGroup>
30 <ItemGroup>
31 <Reference Include="libsecondlife, Version=0.9.0.0, Culture=neutral, processorArchitecture=MSIL">
32 <SpecificVersion>False</SpecificVersion>
33 <HintPath>..\..\bin\libsecondlife.dll</HintPath>
34 </Reference>
35 <Reference Include="System" />
36 <Reference Include="System.Data" />
37 <Reference Include="System.Xml" />
38 </ItemGroup>
39 <ItemGroup>
40 <Compile Include="Properties\AssemblyInfo.cs" />
41 <Compile Include="Script.cs" />
42 <Compile Include="ScriptAccess.cs" />
43 </ItemGroup>
44 <ItemGroup>
45 <ProjectReference Include="..\..\Common\OpenSim.Framework.Console\OpenSim.Framework.Console.csproj">
46 <Project>{A7CD0630-0000-0000-0000-000000000000}</Project>
47 <Name>OpenSim.Framework.Console</Name>
48 </ProjectReference>
49 <ProjectReference Include="..\..\Common\OpenSim.Framework\OpenSim.Framework.csproj">
50 <Project>{8ACA2445-0000-0000-0000-000000000000}</Project>
51 <Name>OpenSim.Framework</Name>
52 </ProjectReference>
53 <ProjectReference Include="..\OpenSim.Region\OpenSim.Region.csproj">
54 <Project>{196916AF-0000-0000-0000-000000000000}</Project>
55 <Name>OpenSim.Region</Name>
56 </ProjectReference>
57 </ItemGroup>
58 <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
59 <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
60 Other similar extension points exist, see Microsoft.Common.targets.
61 <Target Name="BeforeBuild">
62 </Target>
63 <Target Name="AfterBuild">
64 </Target>
65 -->
66</Project> \ No newline at end of file
diff --git a/OpenSim/OpenSim.Scripting/Properties/AssemblyInfo.cs b/OpenSim/OpenSim.Scripting/Properties/AssemblyInfo.cs
deleted file mode 100644
index f5da4c0..0000000
--- a/OpenSim/OpenSim.Scripting/Properties/AssemblyInfo.cs
+++ /dev/null
@@ -1,35 +0,0 @@
1using System.Reflection;
2using System.Runtime.CompilerServices;
3using System.Runtime.InteropServices;
4
5// General Information about an assembly is controlled through the following
6// set of attributes. Change these attribute values to modify the information
7// associated with an assembly.
8[assembly: AssemblyTitle("OpenSim.Scripting")]
9[assembly: AssemblyDescription("")]
10[assembly: AssemblyConfiguration("")]
11[assembly: AssemblyCompany("")]
12[assembly: AssemblyProduct("OpenSim.Scripting")]
13[assembly: AssemblyCopyright("Copyright © 2007")]
14[assembly: AssemblyTrademark("")]
15[assembly: AssemblyCulture("")]
16
17// Setting ComVisible to false makes the types in this assembly not visible
18// to COM components. If you need to access a type in this assembly from
19// COM, set the ComVisible attribute to true on that type.
20[assembly: ComVisible(false)]
21
22// The following GUID is for the ID of the typelib if this project is exposed to COM
23[assembly: Guid("61eae1ad-82aa-4c77-8bc5-b5a8c9522b18")]
24
25// Version information for an assembly consists of the following four values:
26//
27// Major Version
28// Minor Version
29// Build Number
30// Revision
31//
32// You can specify all the values or you can default the Revision and Build Numbers
33// by using the '*' as shown below:
34[assembly: AssemblyVersion("1.0.0.0")]
35[assembly: AssemblyFileVersion("1.0.0.0")]
diff --git a/OpenSim/OpenSim.Scripting/Script.cs b/OpenSim/OpenSim.Scripting/Script.cs
deleted file mode 100644
index 0f4af00..0000000
--- a/OpenSim/OpenSim.Scripting/Script.cs
+++ /dev/null
@@ -1,32 +0,0 @@
1using System;
2using System.Collections.Generic;
3using System.Text;
4
5using OpenSim.Framework.Console;
6using OpenSim.Framework;
7using OpenSim.Region;
8using OpenSim.Region.Scenes;
9
10namespace OpenSim.Scripting
11{
12 public interface IScript
13 {
14 void Initialise(ScriptInfo scriptInfo);
15 }
16
17 public class TestScript : IScript
18 {
19 ScriptInfo script;
20
21 public void Initialise(ScriptInfo scriptInfo)
22 {
23 script = scriptInfo;
24 script.events.OnFrame += new OpenSim.Region.Scenes.EventManager.OnFrameDelegate(events_OnFrame);
25 }
26
27 void events_OnFrame()
28 {
29 script.logger.Verbose("Hello World!");
30 }
31 }
32}
diff --git a/OpenSim/OpenSim/OpenSimMain.cs b/OpenSim/OpenSim/OpenSimMain.cs
index 7da2263..b7ec9e6 100644
--- a/OpenSim/OpenSim/OpenSimMain.cs
+++ b/OpenSim/OpenSim/OpenSimMain.cs
@@ -433,6 +433,13 @@ namespace OpenSim
433 } 433 }
434 break; 434 break;
435 435
436 case "script":
437 for (int i = 0; i < m_localWorld.Count; i++)
438 {
439 ((Scene)m_localWorld[i]).scriptManager.RunScriptCmd(cmdparams);
440 }
441 break;
442
436 case "shutdown": 443 case "shutdown":
437 Shutdown(); 444 Shutdown();
438 break; 445 break;