From 0c1a6c85cc678effc882dd5897d3357416807ba9 Mon Sep 17 00:00:00 2001 From: Adam Frisby Date: Thu, 28 Jun 2007 08:09:05 +0000 Subject: * 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) --- OpenSim/OpenSim.Region/OpenSim.Region.csproj | 25 ++-- OpenSim/OpenSim.Region/Scenes/Entity.cs | 3 +- OpenSim/OpenSim.Region/Scenes/Scene.cs | 22 +--- OpenSim/OpenSim.Region/Scenes/SceneBase.cs | 1 - .../Scenes/scripting/CSharpScriptEngine.cs | 77 +++++++++++++ .../Scenes/scripting/IScriptContext.cs | 40 ------- .../Scenes/scripting/IScriptEntity.cs | 46 -------- .../Scenes/scripting/IScriptHandler.cs | 126 --------------------- OpenSim/OpenSim.Region/Scenes/scripting/Script.cs | 71 +++++------- .../Scenes/scripting/ScriptFactory.cs | 35 ------ .../OpenSim.Region/Scenes/scripting/ScriptInfo.cs | 31 +++++ .../Scenes/scripting/ScriptManager.cs | 66 +++++++++++ .../Scenes/scripting/Scripts/FollowRandomAvatar.cs | 64 ----------- OpenSim/OpenSim.Scripting/OpenSim.Scripting.csproj | 66 ----------- .../OpenSim.Scripting/Properties/AssemblyInfo.cs | 35 ------ OpenSim/OpenSim.Scripting/Script.cs | 32 ------ OpenSim/OpenSim.Scripting/ScriptAccess.cs | 31 ----- OpenSim/OpenSim/OpenSimMain.cs | 7 ++ 18 files changed, 224 insertions(+), 554 deletions(-) create mode 100644 OpenSim/OpenSim.Region/Scenes/scripting/CSharpScriptEngine.cs delete mode 100644 OpenSim/OpenSim.Region/Scenes/scripting/IScriptContext.cs delete mode 100644 OpenSim/OpenSim.Region/Scenes/scripting/IScriptEntity.cs delete mode 100644 OpenSim/OpenSim.Region/Scenes/scripting/IScriptHandler.cs delete mode 100644 OpenSim/OpenSim.Region/Scenes/scripting/ScriptFactory.cs create mode 100644 OpenSim/OpenSim.Region/Scenes/scripting/ScriptInfo.cs create mode 100644 OpenSim/OpenSim.Region/Scenes/scripting/ScriptManager.cs delete mode 100644 OpenSim/OpenSim.Region/Scenes/scripting/Scripts/FollowRandomAvatar.cs delete mode 100644 OpenSim/OpenSim.Scripting/OpenSim.Scripting.csproj delete mode 100644 OpenSim/OpenSim.Scripting/Properties/AssemblyInfo.cs delete mode 100644 OpenSim/OpenSim.Scripting/Script.cs delete mode 100644 OpenSim/OpenSim.Scripting/ScriptAccess.cs (limited to 'OpenSim') 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 @@ Code - - Code - - - Code - - - Code - - - Code - - - Code - - - Code - + + + + + + + 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; using Axiom.MathLib; using OpenSim.Physics.Manager; using libsecondlife; -using OpenSim.Region.Scripting; namespace OpenSim.Region.Scenes { - public abstract class Entity : IScriptReadonlyEntity + public abstract class Entity { public libsecondlife.LLUUID uuid; 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; using OpenSim.Framework.Types; using OpenSim.Framework.Inventory; using OpenSim.Framework; -using OpenSim.Region.Scripting; using OpenSim.Terrain; using OpenGrid.Framework.Communications; using OpenSim.Caches; using OpenSim.Region; using OpenSim.Servers; +using OpenSim.Scripting; namespace OpenSim.Region.Scenes { @@ -60,8 +60,6 @@ namespace OpenSim.Region.Scenes private Random Rand = new Random(); private uint _primCount = 702000; private int storageCount; - private Dictionary m_scriptHandlers; - private Dictionary m_scripts; private Mutex updateLock; protected AuthenticateSessionsBase authenticateHandler; @@ -74,6 +72,7 @@ namespace OpenSim.Region.Scenes public ParcelManager parcelManager; public EstateManager estateManager; public EventManager eventManager; + public ScriptManager scriptManager; #region Properties /// @@ -117,12 +116,9 @@ namespace OpenSim.Region.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(); - m_scripts = new Dictionary(); - OpenSim.Framework.Console.MainLog.Instance.Verbose( "World.cs - creating new entitities instance"); Entities = new Dictionary(); Avatars = new Dictionary(); @@ -195,19 +191,9 @@ namespace OpenSim.Region.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 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; using OpenSim.Framework.Interfaces; using OpenSim.Framework.Types; using OpenSim.Framework.Inventory; -using OpenSim.Region.Scripting; using OpenSim.Terrain; using OpenSim.Caches; 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 @@ +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 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 scripts = new Dictionary(); + + 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 compile(string filename) + { + CSharpCodeProvider csharpProvider = new CSharpCodeProvider(); + return LoadDotNetScript(csharpProvider.CreateCompiler(), filename); + } + } +} 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 @@ -/* -* 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.Scripting -{ - public interface IScriptContext - { - IScriptEntity Entity { get; } - bool TryGetRandomAvatar(out IScriptReadonlyEntity avatar); - } -} 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 @@ -/* -* 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.Scripting -{ - public interface IScriptReadonlyEntity - { - LLVector3 Pos { get; } - string Name { get; } - } - - public interface IScriptEntity - { - LLVector3 Pos { get; set; } - string Name { get; } - } -} 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 @@ -/* -* 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; -using OpenSim.Region.Scenes; -using Avatar=OpenSim.Region.Scenes.ScenePresence; -using Primitive = OpenSim.Region.Scenes.Primitive; - -namespace OpenSim.Region.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 - } - -} 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 @@ -/* -* 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.Scripting +using OpenSim.Framework.Console; +using OpenSim.Framework; +using OpenSim.Region; +using OpenSim.Region.Scenes; + +namespace OpenSim.Scripting { - public class Script + public interface IScript + { + void Initialise(ScriptInfo scriptInfo); + string getName(); + } + + public class TestScript : IScript { - private LLUUID m_scriptId; - public virtual LLUUID ScriptId + ScriptInfo script; + + public string getName() + { + return "TestScript 0.1"; + } + + public void Initialise(ScriptInfo scriptInfo) + { + script = scriptInfo; + script.events.OnFrame += new OpenSim.Region.Scenes.EventManager.OnFrameDelegate(events_OnFrame); + script.events.OnNewPresence += new EventManager.OnNewPresenceDelegate(events_OnNewPresence); + } + + void events_OnNewPresence(ScenePresence presence) { - get - { - return m_scriptId; - } + script.logger.Verbose("Hello " + presence.firstname.ToString() + "!"); } - public Script( LLUUID scriptId ) + void events_OnFrame() { - m_scriptId = scriptId; + //script.logger.Verbose("Hello World!"); } - - public ScriptEventHandler OnFrame; } } 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 @@ -/* -* 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.Scripting -{ - public delegate Script ScriptFactory(); -} diff --git a/OpenSim/OpenSim.Region/Scenes/scripting/ScriptInfo.cs b/OpenSim/OpenSim.Region/Scenes/scripting/ScriptInfo.cs new file mode 100644 index 0000000..a9fede5 --- /dev/null +++ b/OpenSim/OpenSim.Region/Scenes/scripting/ScriptInfo.cs @@ -0,0 +1,31 @@ +using System; +using System.Collections.Generic; +using System.Text; + +using OpenSim.Region.Scenes; +using OpenSim.Framework.Console; + +namespace OpenSim.Scripting +{ + /// + /// Class which provides access to the world + /// + public class ScriptInfo + { + // Reference to world.eventsManager provided for convenience + public EventManager events; + + // The main world + public Scene world; + + // The console + public LogBase logger; + + public ScriptInfo(Scene scene) + { + world = scene; + events = world.eventManager; + logger = OpenSim.Framework.Console.MainLog.Instance; + } + } +} 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 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenSim.Scripting +{ + public class ScriptManager + { + List scripts = new List(); + OpenSim.Region.Scenes.Scene scene; + Dictionary compilers = new Dictionary(); + + private void LoadFromCompiler(Dictionary compiledscripts) + { + foreach (KeyValuePair 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.Scenes.Scene world) + { + scene = world; + + // Defualt Engines + CSharpScriptEngine csharpCompiler = new CSharpScriptEngine(); + compilers.Add(csharpCompiler.fileExt(),csharpCompiler); + } + + public void Compile(string filename) + { + foreach (KeyValuePair 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 compile(string filename); + string fileExt(); + } +} 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 @@ -/* -* 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.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; - } - } - } - - -} 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 @@ - - - Debug - AnyCPU - 8.0.50727 - 2.0 - {3C3A8BD5-F53C-42D0-8ADE-E2492790788A} - Library - Properties - OpenSim.Scripting - OpenSim.Scripting - - - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - - - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - - - - False - ..\..\bin\libsecondlife.dll - - - - - - - - - - - - - {A7CD0630-0000-0000-0000-000000000000} - OpenSim.Framework.Console - - - {8ACA2445-0000-0000-0000-000000000000} - OpenSim.Framework - - - {196916AF-0000-0000-0000-000000000000} - OpenSim.Region - - - - - \ 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 @@ -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. -[assembly: AssemblyTitle("OpenSim.Scripting")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("OpenSim.Scripting")] -[assembly: AssemblyCopyright("Copyright © 2007")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -// Setting ComVisible to false makes the types in this assembly not visible -// to COM components. If you need to access a type in this assembly from -// COM, set the ComVisible attribute to true on that type. -[assembly: ComVisible(false)] - -// The following GUID is for the ID of the typelib if this project is exposed to COM -[assembly: Guid("61eae1ad-82aa-4c77-8bc5-b5a8c9522b18")] - -// Version information for an assembly consists of the following four values: -// -// Major Version -// Minor Version -// Build Number -// Revision -// -// You can specify all the values or you can default the Revision and Build Numbers -// by using the '*' as shown below: -[assembly: AssemblyVersion("1.0.0.0")] -[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 @@ -using System; -using System.Collections.Generic; -using System.Text; - -using OpenSim.Framework.Console; -using OpenSim.Framework; -using OpenSim.Region; -using OpenSim.Region.Scenes; - -namespace OpenSim.Scripting -{ - public interface IScript - { - void Initialise(ScriptInfo scriptInfo); - } - - public class TestScript : IScript - { - ScriptInfo script; - - public void Initialise(ScriptInfo scriptInfo) - { - script = scriptInfo; - script.events.OnFrame += new OpenSim.Region.Scenes.EventManager.OnFrameDelegate(events_OnFrame); - } - - void events_OnFrame() - { - script.logger.Verbose("Hello World!"); - } - } -} diff --git a/OpenSim/OpenSim.Scripting/ScriptAccess.cs b/OpenSim/OpenSim.Scripting/ScriptAccess.cs deleted file mode 100644 index a9fede5..0000000 --- a/OpenSim/OpenSim.Scripting/ScriptAccess.cs +++ /dev/null @@ -1,31 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; - -using OpenSim.Region.Scenes; -using OpenSim.Framework.Console; - -namespace OpenSim.Scripting -{ - /// - /// Class which provides access to the world - /// - public class ScriptInfo - { - // Reference to world.eventsManager provided for convenience - public EventManager events; - - // The main world - public Scene world; - - // The console - public LogBase logger; - - public ScriptInfo(Scene scene) - { - world = scene; - events = world.eventManager; - logger = OpenSim.Framework.Console.MainLog.Instance; - } - } -} 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 } break; + case "script": + for (int i = 0; i < m_localWorld.Count; i++) + { + ((Scene)m_localWorld[i]).scriptManager.RunScriptCmd(cmdparams); + } + break; + case "shutdown": Shutdown(); break; -- cgit v1.1