From e1f68145be8b0cfc48c7fe6920ae8db1bfa049f5 Mon Sep 17 00:00:00 2001 From: Jeff Ames Date: Sat, 7 Mar 2009 02:00:18 +0000 Subject: Update svn properties. --- .../Region/CoreModules/World/Tests/SOGSpamTest.cs | 20 +- .../Scripting/Minimodule/Heightmap.cs | 68 +-- .../OptionalModules/Scripting/Minimodule/Host.cs | 58 +- .../Scripting/Minimodule/IAvatar.cs | 28 +- .../Scripting/Minimodule/IHeightmap.cs | 28 +- .../OptionalModules/Scripting/Minimodule/IHost.cs | 26 +- .../Scripting/Minimodule/IObject.cs | 192 +++---- .../OptionalModules/Scripting/Minimodule/IWorld.cs | 24 +- .../Scripting/Minimodule/MRMBase.cs | 54 +- .../Scripting/Minimodule/MRMModule.cs | 470 +++++++-------- .../Scripting/Minimodule/SOPObject.cs | 634 ++++++++++----------- .../OptionalModules/Scripting/Minimodule/World.cs | 78 +-- .../Scripting/ObjectModules/IObjectModule.cs | 30 +- 13 files changed, 855 insertions(+), 855 deletions(-) (limited to 'OpenSim') diff --git a/OpenSim/Region/CoreModules/World/Tests/SOGSpamTest.cs b/OpenSim/Region/CoreModules/World/Tests/SOGSpamTest.cs index 836f559..9a2b157 100644 --- a/OpenSim/Region/CoreModules/World/Tests/SOGSpamTest.cs +++ b/OpenSim/Region/CoreModules/World/Tests/SOGSpamTest.cs @@ -1,10 +1,10 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace OpenSim.Region.CoreModules.World.Tests -{ - class SOGSpamTest - { - } -} +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenSim.Region.CoreModules.World.Tests +{ + class SOGSpamTest + { + } +} diff --git a/OpenSim/Region/OptionalModules/Scripting/Minimodule/Heightmap.cs b/OpenSim/Region/OptionalModules/Scripting/Minimodule/Heightmap.cs index c75c6e7..6fa6ebe 100644 --- a/OpenSim/Region/OptionalModules/Scripting/Minimodule/Heightmap.cs +++ b/OpenSim/Region/OptionalModules/Scripting/Minimodule/Heightmap.cs @@ -1,34 +1,34 @@ -using OpenSim.Region.Framework.Scenes; - -namespace OpenSim.Region.OptionalModules.Scripting.Minimodule -{ - public class Heightmap : IHeightmap - { - private Scene m_scene; - - public Heightmap(Scene scene) - { - m_scene = scene; - } - - public int Height - { - get { return m_scene.Heightmap.Height; } - } - - public int Width - { - get { return m_scene.Heightmap.Width; } - } - - public double Get(int x, int y) - { - return m_scene.Heightmap[x, y]; - } - - public void Set(int x, int y, double val) - { - m_scene.Heightmap[x, y] = val; - } - } -} +using OpenSim.Region.Framework.Scenes; + +namespace OpenSim.Region.OptionalModules.Scripting.Minimodule +{ + public class Heightmap : IHeightmap + { + private Scene m_scene; + + public Heightmap(Scene scene) + { + m_scene = scene; + } + + public int Height + { + get { return m_scene.Heightmap.Height; } + } + + public int Width + { + get { return m_scene.Heightmap.Width; } + } + + public double Get(int x, int y) + { + return m_scene.Heightmap[x, y]; + } + + public void Set(int x, int y, double val) + { + m_scene.Heightmap[x, y] = val; + } + } +} diff --git a/OpenSim/Region/OptionalModules/Scripting/Minimodule/Host.cs b/OpenSim/Region/OptionalModules/Scripting/Minimodule/Host.cs index dcb70b4..c8b51b6 100644 --- a/OpenSim/Region/OptionalModules/Scripting/Minimodule/Host.cs +++ b/OpenSim/Region/OptionalModules/Scripting/Minimodule/Host.cs @@ -1,29 +1,29 @@ -using System; -using System.Collections.Generic; -using System.Reflection; -using System.Text; -using log4net; - -namespace OpenSim.Region.OptionalModules.Scripting.Minimodule -{ - class Host : IHost - { - private readonly IObject m_obj; - private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); - - public Host(IObject m_obj) - { - this.m_obj = m_obj; - } - - public IObject Object - { - get { return m_obj; } - } - - public ILog Console - { - get { return m_log; } - } - } -} +using System; +using System.Collections.Generic; +using System.Reflection; +using System.Text; +using log4net; + +namespace OpenSim.Region.OptionalModules.Scripting.Minimodule +{ + class Host : IHost + { + private readonly IObject m_obj; + private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); + + public Host(IObject m_obj) + { + this.m_obj = m_obj; + } + + public IObject Object + { + get { return m_obj; } + } + + public ILog Console + { + get { return m_log; } + } + } +} diff --git a/OpenSim/Region/OptionalModules/Scripting/Minimodule/IAvatar.cs b/OpenSim/Region/OptionalModules/Scripting/Minimodule/IAvatar.cs index ba92c64..270ed89 100644 --- a/OpenSim/Region/OptionalModules/Scripting/Minimodule/IAvatar.cs +++ b/OpenSim/Region/OptionalModules/Scripting/Minimodule/IAvatar.cs @@ -1,14 +1,14 @@ -using System; -using System.Collections.Generic; -using System.Text; -using OpenMetaverse; - -namespace OpenSim.Region.OptionalModules.Scripting.Minimodule -{ - interface IAvatar - { - string Name { get; } - UUID GlobalID { get; } - Vector3 Position { get; } - } -} +using System; +using System.Collections.Generic; +using System.Text; +using OpenMetaverse; + +namespace OpenSim.Region.OptionalModules.Scripting.Minimodule +{ + interface IAvatar + { + string Name { get; } + UUID GlobalID { get; } + Vector3 Position { get; } + } +} diff --git a/OpenSim/Region/OptionalModules/Scripting/Minimodule/IHeightmap.cs b/OpenSim/Region/OptionalModules/Scripting/Minimodule/IHeightmap.cs index b4502a4..84d602a 100644 --- a/OpenSim/Region/OptionalModules/Scripting/Minimodule/IHeightmap.cs +++ b/OpenSim/Region/OptionalModules/Scripting/Minimodule/IHeightmap.cs @@ -1,14 +1,14 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace OpenSim.Region.OptionalModules.Scripting.Minimodule -{ - public interface IHeightmap - { - int Height { get; } - int Width { get; } - double Get(int x, int y); - void Set(int x, int y, double val); - } -} +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenSim.Region.OptionalModules.Scripting.Minimodule +{ + public interface IHeightmap + { + int Height { get; } + int Width { get; } + double Get(int x, int y); + void Set(int x, int y, double val); + } +} diff --git a/OpenSim/Region/OptionalModules/Scripting/Minimodule/IHost.cs b/OpenSim/Region/OptionalModules/Scripting/Minimodule/IHost.cs index 8f95ba7..123fa38 100644 --- a/OpenSim/Region/OptionalModules/Scripting/Minimodule/IHost.cs +++ b/OpenSim/Region/OptionalModules/Scripting/Minimodule/IHost.cs @@ -1,13 +1,13 @@ -using System; -using System.Collections.Generic; -using System.Text; -using log4net; - -namespace OpenSim.Region.OptionalModules.Scripting.Minimodule -{ - public interface IHost - { - IObject Object { get; } - ILog Console { get; } - } -} +using System; +using System.Collections.Generic; +using System.Text; +using log4net; + +namespace OpenSim.Region.OptionalModules.Scripting.Minimodule +{ + public interface IHost + { + IObject Object { get; } + ILog Console { get; } + } +} diff --git a/OpenSim/Region/OptionalModules/Scripting/Minimodule/IObject.cs b/OpenSim/Region/OptionalModules/Scripting/Minimodule/IObject.cs index ef442d4..0c7bfc0 100644 --- a/OpenSim/Region/OptionalModules/Scripting/Minimodule/IObject.cs +++ b/OpenSim/Region/OptionalModules/Scripting/Minimodule/IObject.cs @@ -1,96 +1,96 @@ -using System; -using System.Drawing; -using OpenMetaverse; - -namespace OpenSim.Region.OptionalModules.Scripting.Minimodule -{ - public interface IObject - { - bool Exists { get; } - uint LocalID { get; } - UUID GlobalID { get; } - - IObject[] Children { get; } - - /// - /// Equals 'this' if we have no parent. Ergo, Root.Children.Count will always return the total number of items in the linkset. - /// - IObject Root { get; } - - IObjectFace[] Faces { get; } - - Vector3 Scale { get; set; } - Quaternion Rotation { get; set; } - - Vector3 SitTarget { get; set; } - String SitTargetText { get; set; } - - String TouchText { get; set; } - - String Text { get; set; } - - bool IsPhysical { get; set; } // SetStatus(PHYSICS) - bool IsPhantom { get; set; } // SetStatus(PHANTOM) - bool IsRotationLockedX { get; set; } // SetStatus(!ROTATE_X) - bool IsRotationLockedY { get; set; } // SetStatus(!ROTATE_Y) - bool IsRotationLockedZ { get; set; } // SetStatus(!ROTATE_Z) - bool IsSandboxed { get; set; } // SetStatus(SANDBOX) - bool IsImmotile { get; set; } // SetStatus(BLOCK_GRAB) - bool IsAlwaysReturned { get; set; } // SetStatus(!DIE_AT_EDGE) - bool IsTemporary { get; set; } // TEMP_ON_REZ - - bool IsFlexible { get; set; } - - PrimType PrimShape { get; set; } - // TODO: - // PrimHole - // Repeats, Offsets, Cut/Dimple/ProfileCut - // Hollow, Twist, HoleSize, - // Taper[A+B], Shear[A+B], Revolutions, - // RadiusOffset, Skew - - Material Material { get; set; } - } - - public enum Material - { - Default, - Glass, - Metal, - Plastic, - Wood, - Rubber, - Stone, - Flesh - } - - public enum PrimType - { - NotPrimitive = 255, - Box = 0, - Cylinder = 1, - Prism = 2, - Sphere = 3, - Torus = 4, - Tube = 5, - Ring = 6, - Sculpt = 7 - } - - public enum TextureMapping - { - Default, - Planar - } - - public interface IObjectFace - { - Color Color { get; set; } - UUID Texture { get; set; } - TextureMapping Mapping { get; set; } // SetPrimParms(PRIM_TEXGEN) - bool Bright { get; set; } // SetPrimParms(FULLBRIGHT) - double Bloom { get; set; } // SetPrimParms(GLOW) - bool Shiny { get; set; } // SetPrimParms(SHINY) - bool BumpMap { get; set; } // SetPrimParms(BUMPMAP) [DEPRECIATE IN FAVOUR OF UUID?] - } -} +using System; +using System.Drawing; +using OpenMetaverse; + +namespace OpenSim.Region.OptionalModules.Scripting.Minimodule +{ + public interface IObject + { + bool Exists { get; } + uint LocalID { get; } + UUID GlobalID { get; } + + IObject[] Children { get; } + + /// + /// Equals 'this' if we have no parent. Ergo, Root.Children.Count will always return the total number of items in the linkset. + /// + IObject Root { get; } + + IObjectFace[] Faces { get; } + + Vector3 Scale { get; set; } + Quaternion Rotation { get; set; } + + Vector3 SitTarget { get; set; } + String SitTargetText { get; set; } + + String TouchText { get; set; } + + String Text { get; set; } + + bool IsPhysical { get; set; } // SetStatus(PHYSICS) + bool IsPhantom { get; set; } // SetStatus(PHANTOM) + bool IsRotationLockedX { get; set; } // SetStatus(!ROTATE_X) + bool IsRotationLockedY { get; set; } // SetStatus(!ROTATE_Y) + bool IsRotationLockedZ { get; set; } // SetStatus(!ROTATE_Z) + bool IsSandboxed { get; set; } // SetStatus(SANDBOX) + bool IsImmotile { get; set; } // SetStatus(BLOCK_GRAB) + bool IsAlwaysReturned { get; set; } // SetStatus(!DIE_AT_EDGE) + bool IsTemporary { get; set; } // TEMP_ON_REZ + + bool IsFlexible { get; set; } + + PrimType PrimShape { get; set; } + // TODO: + // PrimHole + // Repeats, Offsets, Cut/Dimple/ProfileCut + // Hollow, Twist, HoleSize, + // Taper[A+B], Shear[A+B], Revolutions, + // RadiusOffset, Skew + + Material Material { get; set; } + } + + public enum Material + { + Default, + Glass, + Metal, + Plastic, + Wood, + Rubber, + Stone, + Flesh + } + + public enum PrimType + { + NotPrimitive = 255, + Box = 0, + Cylinder = 1, + Prism = 2, + Sphere = 3, + Torus = 4, + Tube = 5, + Ring = 6, + Sculpt = 7 + } + + public enum TextureMapping + { + Default, + Planar + } + + public interface IObjectFace + { + Color Color { get; set; } + UUID Texture { get; set; } + TextureMapping Mapping { get; set; } // SetPrimParms(PRIM_TEXGEN) + bool Bright { get; set; } // SetPrimParms(FULLBRIGHT) + double Bloom { get; set; } // SetPrimParms(GLOW) + bool Shiny { get; set; } // SetPrimParms(SHINY) + bool BumpMap { get; set; } // SetPrimParms(BUMPMAP) [DEPRECIATE IN FAVOUR OF UUID?] + } +} diff --git a/OpenSim/Region/OptionalModules/Scripting/Minimodule/IWorld.cs b/OpenSim/Region/OptionalModules/Scripting/Minimodule/IWorld.cs index 2f1388e..ea74524 100644 --- a/OpenSim/Region/OptionalModules/Scripting/Minimodule/IWorld.cs +++ b/OpenSim/Region/OptionalModules/Scripting/Minimodule/IWorld.cs @@ -1,12 +1,12 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace OpenSim.Region.OptionalModules.Scripting.Minimodule -{ - public interface IWorld - { - IObject[] Objects { get; } - IHeightmap Terrain { get; } - } -} +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenSim.Region.OptionalModules.Scripting.Minimodule +{ + public interface IWorld + { + IObject[] Objects { get; } + IHeightmap Terrain { get; } + } +} diff --git a/OpenSim/Region/OptionalModules/Scripting/Minimodule/MRMBase.cs b/OpenSim/Region/OptionalModules/Scripting/Minimodule/MRMBase.cs index b2e6d2e..cbef1ca 100644 --- a/OpenSim/Region/OptionalModules/Scripting/Minimodule/MRMBase.cs +++ b/OpenSim/Region/OptionalModules/Scripting/Minimodule/MRMBase.cs @@ -1,27 +1,27 @@ -namespace OpenSim.Region.OptionalModules.Scripting.Minimodule -{ - public abstract class MRMBase - { - private IWorld m_world; - private IHost m_host; - - public void InitMiniModule(IWorld world, IHost host) - { - m_world = world; - m_host = host; - } - - protected IWorld World - { - get { return m_world; } - } - - protected IHost Host - { - get { return m_host; } - } - - public abstract void Start(); - public abstract void Stop(); - } -} +namespace OpenSim.Region.OptionalModules.Scripting.Minimodule +{ + public abstract class MRMBase + { + private IWorld m_world; + private IHost m_host; + + public void InitMiniModule(IWorld world, IHost host) + { + m_world = world; + m_host = host; + } + + protected IWorld World + { + get { return m_world; } + } + + protected IHost Host + { + get { return m_host; } + } + + public abstract void Start(); + public abstract void Stop(); + } +} diff --git a/OpenSim/Region/OptionalModules/Scripting/Minimodule/MRMModule.cs b/OpenSim/Region/OptionalModules/Scripting/Minimodule/MRMModule.cs index 86a3240..1536445 100644 --- a/OpenSim/Region/OptionalModules/Scripting/Minimodule/MRMModule.cs +++ b/OpenSim/Region/OptionalModules/Scripting/Minimodule/MRMModule.cs @@ -1,235 +1,235 @@ -using System; -using System.CodeDom.Compiler; -using System.Collections.Generic; -using System.IO; -using System.Reflection; -using System.Text; -using log4net; -using Microsoft.CSharp; -using Nini.Config; -using OpenMetaverse; -using OpenSim.Region.Framework.Interfaces; -using OpenSim.Region.Framework.Scenes; - -namespace OpenSim.Region.OptionalModules.Scripting.Minimodule -{ - public class MRMModule : IRegionModule - { - private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); - private Scene m_scene; - - private readonly Dictionary m_scripts = new Dictionary(); - - private static readonly CSharpCodeProvider CScodeProvider = new CSharpCodeProvider(); - - public void Initialise(Scene scene, IConfigSource source) - { - if (source.Configs["MRM"] != null) - { - if (source.Configs["MRM"].GetBoolean("Enabled", false)) - { - m_log.Info("[MRM] Enabling MRM Module"); - m_scene = scene; - scene.EventManager.OnRezScript += EventManager_OnRezScript; - } - else - { - m_log.Info("[MRM] Disabled MRM Module (Express)"); - } - } - else - { - m_log.Info("[MRM] Disabled MRM Module (Omission)"); - } - } - - void EventManager_OnRezScript(uint localID, UUID itemID, string script, int startParam, bool postOnRez, string engine, int stateSource) - { - if (script.StartsWith("//MiniMod:C#")) - { - m_log.Info("[MRM] Found C# MRM"); - IWorld m_world = new World(m_scene); - IHost m_host = new Host(new SOPObject(m_scene, localID)); - - MRMBase mmb = (MRMBase) AppDomain.CurrentDomain.CreateInstanceFromAndUnwrap( - CompileFromDotNetText(script, itemID.ToString()), - "OpenSim.MiniModule"); - m_log.Info("[MRM] Created MRM Instance"); - mmb.InitMiniModule(m_world, m_host); - m_scripts[itemID] = mmb; - - m_log.Info("[MRM] Starting MRM"); - mmb.Start(); - } - } - - public void PostInitialise() - { - - } - - public void Close() - { - foreach (KeyValuePair pair in m_scripts) - { - pair.Value.Stop(); - } - } - - public string Name - { - get { return "MiniRegionModule"; } - } - - public bool IsSharedModule - { - get { return false; } - } - - /// - /// Stolen from ScriptEngine Common - /// - /// - /// Unique ID for this module - /// - internal string CompileFromDotNetText(string Script, string uuid) - { - const string ext = ".cs"; - const string FilePrefix = "MiniModule"; - - // Output assembly name - string OutFile = Path.Combine("MiniModules", Path.Combine( - m_scene.RegionInfo.RegionID.ToString(), - FilePrefix + "_compiled_" + uuid + ".dll")); - - // Create Directories for Assemblies - if (!Directory.Exists("MiniModules")) - Directory.CreateDirectory("MiniModules"); - string tmp = Path.Combine("MiniModules", m_scene.RegionInfo.RegionID.ToString()); - if (!Directory.Exists(tmp)) - Directory.CreateDirectory(tmp); - - try - { - File.Delete(OutFile); - } - catch (IOException e) - { - throw new Exception("Unable to delete old existing " + - "script-file before writing new. Compile aborted: " + - e); - } - - // DEBUG - write source to disk - string srcFileName = FilePrefix + "_source_" + - Path.GetFileNameWithoutExtension(OutFile) + ext; - try - { - File.WriteAllText(Path.Combine(Path.Combine( - "MiniModules", - m_scene.RegionInfo.RegionID.ToString()), - srcFileName), Script); - } - catch (Exception ex) //NOTLEGIT - Should be just FileIOException - { - m_log.Error("[Compiler]: Exception while " + - "trying to write script source to file \"" + - srcFileName + "\": " + ex.ToString()); - } - - // Do actual compile - CompilerParameters parameters = new CompilerParameters(); - - parameters.IncludeDebugInformation = true; - - string rootPath = - Path.GetDirectoryName(AppDomain.CurrentDomain.BaseDirectory); - - - // TODO: Add Libraries - parameters.ReferencedAssemblies.Add(Path.Combine(rootPath, - "OpenSim.Region.OptionalModules.dll")); - parameters.ReferencedAssemblies.Add(Path.Combine(rootPath, - "log4net.dll")); - - parameters.GenerateExecutable = false; - parameters.OutputAssembly = OutFile; - parameters.IncludeDebugInformation = true; - parameters.TreatWarningsAsErrors = false; - - CompilerResults results = CScodeProvider.CompileAssemblyFromSource( - parameters, Script); - - int display = 5; - if (results.Errors.Count > 0) - { - string errtext = String.Empty; - foreach (CompilerError CompErr in results.Errors) - { - // Show 5 errors max - // - if (display <= 0) - break; - display--; - - string severity = "Error"; - if (CompErr.IsWarning) - { - severity = "Warning"; - } - - string text = CompErr.ErrorText; - - // The Second Life viewer's script editor begins - // countingn lines and columns at 0, so we subtract 1. - errtext += String.Format("Line ({0},{1}): {4} {2}: {3}\n", - CompErr.Line - 1, CompErr.Column - 1, - CompErr.ErrorNumber, text, severity); - } - - if (!File.Exists(OutFile)) - { - throw new Exception(errtext); - } - } - - if (!File.Exists(OutFile)) - { - string errtext = String.Empty; - errtext += "No compile error. But not able to locate compiled file."; - throw new Exception(errtext); - } - - FileInfo fi = new FileInfo(OutFile); - - Byte[] data = new Byte[fi.Length]; - - try - { - FileStream fs = File.Open(OutFile, FileMode.Open, FileAccess.Read); - fs.Read(data, 0, data.Length); - fs.Close(); - } - catch (IOException) - { - string errtext = String.Empty; - errtext += "No compile error. But not able to open file."; - throw new Exception(errtext); - } - - // Convert to base64 - // - string filetext = Convert.ToBase64String(data); - - ASCIIEncoding enc = new ASCIIEncoding(); - - Byte[] buf = enc.GetBytes(filetext); - - FileStream sfs = File.Create(OutFile + ".cil.b64"); - sfs.Write(buf, 0, buf.Length); - sfs.Close(); - - return OutFile; - } - } -} +using System; +using System.CodeDom.Compiler; +using System.Collections.Generic; +using System.IO; +using System.Reflection; +using System.Text; +using log4net; +using Microsoft.CSharp; +using Nini.Config; +using OpenMetaverse; +using OpenSim.Region.Framework.Interfaces; +using OpenSim.Region.Framework.Scenes; + +namespace OpenSim.Region.OptionalModules.Scripting.Minimodule +{ + public class MRMModule : IRegionModule + { + private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); + private Scene m_scene; + + private readonly Dictionary m_scripts = new Dictionary(); + + private static readonly CSharpCodeProvider CScodeProvider = new CSharpCodeProvider(); + + public void Initialise(Scene scene, IConfigSource source) + { + if (source.Configs["MRM"] != null) + { + if (source.Configs["MRM"].GetBoolean("Enabled", false)) + { + m_log.Info("[MRM] Enabling MRM Module"); + m_scene = scene; + scene.EventManager.OnRezScript += EventManager_OnRezScript; + } + else + { + m_log.Info("[MRM] Disabled MRM Module (Express)"); + } + } + else + { + m_log.Info("[MRM] Disabled MRM Module (Omission)"); + } + } + + void EventManager_OnRezScript(uint localID, UUID itemID, string script, int startParam, bool postOnRez, string engine, int stateSource) + { + if (script.StartsWith("//MiniMod:C#")) + { + m_log.Info("[MRM] Found C# MRM"); + IWorld m_world = new World(m_scene); + IHost m_host = new Host(new SOPObject(m_scene, localID)); + + MRMBase mmb = (MRMBase) AppDomain.CurrentDomain.CreateInstanceFromAndUnwrap( + CompileFromDotNetText(script, itemID.ToString()), + "OpenSim.MiniModule"); + m_log.Info("[MRM] Created MRM Instance"); + mmb.InitMiniModule(m_world, m_host); + m_scripts[itemID] = mmb; + + m_log.Info("[MRM] Starting MRM"); + mmb.Start(); + } + } + + public void PostInitialise() + { + + } + + public void Close() + { + foreach (KeyValuePair pair in m_scripts) + { + pair.Value.Stop(); + } + } + + public string Name + { + get { return "MiniRegionModule"; } + } + + public bool IsSharedModule + { + get { return false; } + } + + /// + /// Stolen from ScriptEngine Common + /// + /// + /// Unique ID for this module + /// + internal string CompileFromDotNetText(string Script, string uuid) + { + const string ext = ".cs"; + const string FilePrefix = "MiniModule"; + + // Output assembly name + string OutFile = Path.Combine("MiniModules", Path.Combine( + m_scene.RegionInfo.RegionID.ToString(), + FilePrefix + "_compiled_" + uuid + ".dll")); + + // Create Directories for Assemblies + if (!Directory.Exists("MiniModules")) + Directory.CreateDirectory("MiniModules"); + string tmp = Path.Combine("MiniModules", m_scene.RegionInfo.RegionID.ToString()); + if (!Directory.Exists(tmp)) + Directory.CreateDirectory(tmp); + + try + { + File.Delete(OutFile); + } + catch (IOException e) + { + throw new Exception("Unable to delete old existing " + + "script-file before writing new. Compile aborted: " + + e); + } + + // DEBUG - write source to disk + string srcFileName = FilePrefix + "_source_" + + Path.GetFileNameWithoutExtension(OutFile) + ext; + try + { + File.WriteAllText(Path.Combine(Path.Combine( + "MiniModules", + m_scene.RegionInfo.RegionID.ToString()), + srcFileName), Script); + } + catch (Exception ex) //NOTLEGIT - Should be just FileIOException + { + m_log.Error("[Compiler]: Exception while " + + "trying to write script source to file \"" + + srcFileName + "\": " + ex.ToString()); + } + + // Do actual compile + CompilerParameters parameters = new CompilerParameters(); + + parameters.IncludeDebugInformation = true; + + string rootPath = + Path.GetDirectoryName(AppDomain.CurrentDomain.BaseDirectory); + + + // TODO: Add Libraries + parameters.ReferencedAssemblies.Add(Path.Combine(rootPath, + "OpenSim.Region.OptionalModules.dll")); + parameters.ReferencedAssemblies.Add(Path.Combine(rootPath, + "log4net.dll")); + + parameters.GenerateExecutable = false; + parameters.OutputAssembly = OutFile; + parameters.IncludeDebugInformation = true; + parameters.TreatWarningsAsErrors = false; + + CompilerResults results = CScodeProvider.CompileAssemblyFromSource( + parameters, Script); + + int display = 5; + if (results.Errors.Count > 0) + { + string errtext = String.Empty; + foreach (CompilerError CompErr in results.Errors) + { + // Show 5 errors max + // + if (display <= 0) + break; + display--; + + string severity = "Error"; + if (CompErr.IsWarning) + { + severity = "Warning"; + } + + string text = CompErr.ErrorText; + + // The Second Life viewer's script editor begins + // countingn lines and columns at 0, so we subtract 1. + errtext += String.Format("Line ({0},{1}): {4} {2}: {3}\n", + CompErr.Line - 1, CompErr.Column - 1, + CompErr.ErrorNumber, text, severity); + } + + if (!File.Exists(OutFile)) + { + throw new Exception(errtext); + } + } + + if (!File.Exists(OutFile)) + { + string errtext = String.Empty; + errtext += "No compile error. But not able to locate compiled file."; + throw new Exception(errtext); + } + + FileInfo fi = new FileInfo(OutFile); + + Byte[] data = new Byte[fi.Length]; + + try + { + FileStream fs = File.Open(OutFile, FileMode.Open, FileAccess.Read); + fs.Read(data, 0, data.Length); + fs.Close(); + } + catch (IOException) + { + string errtext = String.Empty; + errtext += "No compile error. But not able to open file."; + throw new Exception(errtext); + } + + // Convert to base64 + // + string filetext = Convert.ToBase64String(data); + + ASCIIEncoding enc = new ASCIIEncoding(); + + Byte[] buf = enc.GetBytes(filetext); + + FileStream sfs = File.Create(OutFile + ".cil.b64"); + sfs.Write(buf, 0, buf.Length); + sfs.Close(); + + return OutFile; + } + } +} diff --git a/OpenSim/Region/OptionalModules/Scripting/Minimodule/SOPObject.cs b/OpenSim/Region/OptionalModules/Scripting/Minimodule/SOPObject.cs index d939e85..e154b79 100644 --- a/OpenSim/Region/OptionalModules/Scripting/Minimodule/SOPObject.cs +++ b/OpenSim/Region/OptionalModules/Scripting/Minimodule/SOPObject.cs @@ -1,317 +1,317 @@ -using System.Collections.Generic; -using OpenMetaverse; -using OpenSim.Framework; -using OpenSim.Region.Framework.Scenes; - -namespace OpenSim.Region.OptionalModules.Scripting.Minimodule -{ - class SOPObject : IObject - { - private readonly Scene m_rootScene; - private readonly uint m_localID; - - public SOPObject(Scene rootScene, uint localID) - { - m_rootScene = rootScene; - m_localID = localID; - } - - /// - /// This needs to run very, very quickly. - /// It is utilized in nearly every property and method. - /// - /// - private SceneObjectPart GetSOP() - { - if (m_rootScene.Entities.ContainsKey(m_localID)) - return ((SceneObjectGroup) m_rootScene.Entities[m_localID]).RootPart; - - return null; - } - - public bool Exists - { - get { return GetSOP() != null; } - } - - public uint LocalID - { - get { return m_localID; } - } - - public UUID GlobalID - { - get { return GetSOP().UUID; } - } - - public IObject[] Children - { - get - { - SceneObjectPart my = GetSOP(); - int total = my.ParentGroup.Children.Count; - - IObject[] rets = new IObject[total]; - - int i = 0; - foreach (KeyValuePair pair in my.ParentGroup.Children) - { - rets[i++] = new SOPObject(m_rootScene, pair.Value.LocalId); - } - - return rets; - } - } - - public IObject Root - { - get { return new SOPObject(m_rootScene, GetSOP().ParentGroup.RootPart.LocalId); } - } - - public IObjectFace[] Faces - { - get - { - SceneObjectPart sop = GetSOP(); - IObjectFace[] rets = new IObjectFace[getNumberOfSides(sop)]; - - for (int i = 0; i < rets.Length;i++ ) - { - //rets[i] = new ObjectFace - } - - return rets; - } - } - - public Vector3 Scale - { - get { return GetSOP().Scale; } - set { GetSOP().Scale = value; } - } - - public Quaternion Rotation - { - get { throw new System.NotImplementedException(); } - set { throw new System.NotImplementedException(); } - } - - public Vector3 SitTarget - { - get { throw new System.NotImplementedException(); } - set { throw new System.NotImplementedException(); } - } - - public string SitTargetText - { - get { throw new System.NotImplementedException(); } - set { throw new System.NotImplementedException(); } - } - - public string TouchText - { - get { throw new System.NotImplementedException(); } - set { throw new System.NotImplementedException(); } - } - - public string Text - { - get { throw new System.NotImplementedException(); } - set { throw new System.NotImplementedException(); } - } - - public bool IsPhysical - { - get { throw new System.NotImplementedException(); } - set { throw new System.NotImplementedException(); } - } - - public bool IsPhantom - { - get { throw new System.NotImplementedException(); } - set { throw new System.NotImplementedException(); } - } - - public bool IsRotationLockedX - { - get { throw new System.NotImplementedException(); } - set { throw new System.NotImplementedException(); } - } - - public bool IsRotationLockedY - { - get { throw new System.NotImplementedException(); } - set { throw new System.NotImplementedException(); } - } - - public bool IsRotationLockedZ - { - get { throw new System.NotImplementedException(); } - set { throw new System.NotImplementedException(); } - } - - public bool IsSandboxed - { - get { throw new System.NotImplementedException(); } - set { throw new System.NotImplementedException(); } - } - - public bool IsImmotile - { - get { throw new System.NotImplementedException(); } - set { throw new System.NotImplementedException(); } - } - - public bool IsAlwaysReturned - { - get { throw new System.NotImplementedException(); } - set { throw new System.NotImplementedException(); } - } - - public bool IsTemporary - { - get { throw new System.NotImplementedException(); } - set { throw new System.NotImplementedException(); } - } - - public bool IsFlexible - { - get { throw new System.NotImplementedException(); } - set { throw new System.NotImplementedException(); } - } - - public PrimType PrimShape - { - get { return (PrimType) getScriptPrimType(GetSOP().Shape); } - set { throw new System.NotImplementedException(); } - } - - public Material Material - { - get { throw new System.NotImplementedException(); } - set { throw new System.NotImplementedException(); } - } - - - #region Supporting Functions - - // Helper functions to understand if object has cut, hollow, dimple, and other affecting number of faces - private static void hasCutHollowDimpleProfileCut(int primType, PrimitiveBaseShape shape, out bool hasCut, out bool hasHollow, - out bool hasDimple, out bool hasProfileCut) - { - if (primType == (int)PrimType.Box - || - primType == (int)PrimType.Cylinder - || - primType == (int)PrimType.Prism) - - hasCut = (shape.ProfileBegin > 0) || (shape.ProfileEnd > 0); - else - hasCut = (shape.PathBegin > 0) || (shape.PathEnd > 0); - - hasHollow = shape.ProfileHollow > 0; - hasDimple = (shape.ProfileBegin > 0) || (shape.ProfileEnd > 0); // taken from llSetPrimitiveParms - hasProfileCut = hasDimple; // is it the same thing? - - } - - private static int getScriptPrimType(PrimitiveBaseShape primShape) - { - if (primShape.SculptEntry) - return (int) PrimType.Sculpt; - if ((primShape.ProfileCurve & 0x07) == (byte) ProfileShape.Square) - { - if (primShape.PathCurve == (byte) Extrusion.Straight) - return (int) PrimType.Box; - if (primShape.PathCurve == (byte) Extrusion.Curve1) - return (int) PrimType.Tube; - } - else if ((primShape.ProfileCurve & 0x07) == (byte) ProfileShape.Circle) - { - if (primShape.PathCurve == (byte) Extrusion.Straight) - return (int) PrimType.Cylinder; - if (primShape.PathCurve == (byte) Extrusion.Curve1) - return (int) PrimType.Torus; - } - else if ((primShape.ProfileCurve & 0x07) == (byte) ProfileShape.HalfCircle) - { - if (primShape.PathCurve == (byte) Extrusion.Curve1 || primShape.PathCurve == (byte) Extrusion.Curve2) - return (int) PrimType.Sphere; - } - else if ((primShape.ProfileCurve & 0x07) == (byte) ProfileShape.EquilateralTriangle) - { - if (primShape.PathCurve == (byte) Extrusion.Straight) - return (int) PrimType.Prism; - if (primShape.PathCurve == (byte) Extrusion.Curve1) - return (int) PrimType.Ring; - } - return (int) PrimType.NotPrimitive; - } - - private static int getNumberOfSides(SceneObjectPart part) - { - int ret; - bool hasCut; - bool hasHollow; - bool hasDimple; - bool hasProfileCut; - - int primType = getScriptPrimType(part.Shape); - hasCutHollowDimpleProfileCut(primType, part.Shape, out hasCut, out hasHollow, out hasDimple, out hasProfileCut); - - switch (primType) - { - default: - case (int) PrimType.Box: - ret = 6; - if (hasCut) ret += 2; - if (hasHollow) ret += 1; - break; - case (int) PrimType.Cylinder: - ret = 3; - if (hasCut) ret += 2; - if (hasHollow) ret += 1; - break; - case (int) PrimType.Prism: - ret = 5; - if (hasCut) ret += 2; - if (hasHollow) ret += 1; - break; - case (int) PrimType.Sphere: - ret = 1; - if (hasCut) ret += 2; - if (hasDimple) ret += 2; - if (hasHollow) - ret += 1; // GOTCHA: LSL shows 2 additional sides here. - // This has been fixed, but may cause porting issues. - break; - case (int) PrimType.Torus: - ret = 1; - if (hasCut) ret += 2; - if (hasProfileCut) ret += 2; - if (hasHollow) ret += 1; - break; - case (int) PrimType.Tube: - ret = 4; - if (hasCut) ret += 2; - if (hasProfileCut) ret += 2; - if (hasHollow) ret += 1; - break; - case (int) PrimType.Ring: - ret = 3; - if (hasCut) ret += 2; - if (hasProfileCut) ret += 2; - if (hasHollow) ret += 1; - break; - case (int) PrimType.Sculpt: - ret = 1; - break; - } - return ret; - } - - - #endregion - - } -} +using System.Collections.Generic; +using OpenMetaverse; +using OpenSim.Framework; +using OpenSim.Region.Framework.Scenes; + +namespace OpenSim.Region.OptionalModules.Scripting.Minimodule +{ + class SOPObject : IObject + { + private readonly Scene m_rootScene; + private readonly uint m_localID; + + public SOPObject(Scene rootScene, uint localID) + { + m_rootScene = rootScene; + m_localID = localID; + } + + /// + /// This needs to run very, very quickly. + /// It is utilized in nearly every property and method. + /// + /// + private SceneObjectPart GetSOP() + { + if (m_rootScene.Entities.ContainsKey(m_localID)) + return ((SceneObjectGroup) m_rootScene.Entities[m_localID]).RootPart; + + return null; + } + + public bool Exists + { + get { return GetSOP() != null; } + } + + public uint LocalID + { + get { return m_localID; } + } + + public UUID GlobalID + { + get { return GetSOP().UUID; } + } + + public IObject[] Children + { + get + { + SceneObjectPart my = GetSOP(); + int total = my.ParentGroup.Children.Count; + + IObject[] rets = new IObject[total]; + + int i = 0; + foreach (KeyValuePair pair in my.ParentGroup.Children) + { + rets[i++] = new SOPObject(m_rootScene, pair.Value.LocalId); + } + + return rets; + } + } + + public IObject Root + { + get { return new SOPObject(m_rootScene, GetSOP().ParentGroup.RootPart.LocalId); } + } + + public IObjectFace[] Faces + { + get + { + SceneObjectPart sop = GetSOP(); + IObjectFace[] rets = new IObjectFace[getNumberOfSides(sop)]; + + for (int i = 0; i < rets.Length;i++ ) + { + //rets[i] = new ObjectFace + } + + return rets; + } + } + + public Vector3 Scale + { + get { return GetSOP().Scale; } + set { GetSOP().Scale = value; } + } + + public Quaternion Rotation + { + get { throw new System.NotImplementedException(); } + set { throw new System.NotImplementedException(); } + } + + public Vector3 SitTarget + { + get { throw new System.NotImplementedException(); } + set { throw new System.NotImplementedException(); } + } + + public string SitTargetText + { + get { throw new System.NotImplementedException(); } + set { throw new System.NotImplementedException(); } + } + + public string TouchText + { + get { throw new System.NotImplementedException(); } + set { throw new System.NotImplementedException(); } + } + + public string Text + { + get { throw new System.NotImplementedException(); } + set { throw new System.NotImplementedException(); } + } + + public bool IsPhysical + { + get { throw new System.NotImplementedException(); } + set { throw new System.NotImplementedException(); } + } + + public bool IsPhantom + { + get { throw new System.NotImplementedException(); } + set { throw new System.NotImplementedException(); } + } + + public bool IsRotationLockedX + { + get { throw new System.NotImplementedException(); } + set { throw new System.NotImplementedException(); } + } + + public bool IsRotationLockedY + { + get { throw new System.NotImplementedException(); } + set { throw new System.NotImplementedException(); } + } + + public bool IsRotationLockedZ + { + get { throw new System.NotImplementedException(); } + set { throw new System.NotImplementedException(); } + } + + public bool IsSandboxed + { + get { throw new System.NotImplementedException(); } + set { throw new System.NotImplementedException(); } + } + + public bool IsImmotile + { + get { throw new System.NotImplementedException(); } + set { throw new System.NotImplementedException(); } + } + + public bool IsAlwaysReturned + { + get { throw new System.NotImplementedException(); } + set { throw new System.NotImplementedException(); } + } + + public bool IsTemporary + { + get { throw new System.NotImplementedException(); } + set { throw new System.NotImplementedException(); } + } + + public bool IsFlexible + { + get { throw new System.NotImplementedException(); } + set { throw new System.NotImplementedException(); } + } + + public PrimType PrimShape + { + get { return (PrimType) getScriptPrimType(GetSOP().Shape); } + set { throw new System.NotImplementedException(); } + } + + public Material Material + { + get { throw new System.NotImplementedException(); } + set { throw new System.NotImplementedException(); } + } + + + #region Supporting Functions + + // Helper functions to understand if object has cut, hollow, dimple, and other affecting number of faces + private static void hasCutHollowDimpleProfileCut(int primType, PrimitiveBaseShape shape, out bool hasCut, out bool hasHollow, + out bool hasDimple, out bool hasProfileCut) + { + if (primType == (int)PrimType.Box + || + primType == (int)PrimType.Cylinder + || + primType == (int)PrimType.Prism) + + hasCut = (shape.ProfileBegin > 0) || (shape.ProfileEnd > 0); + else + hasCut = (shape.PathBegin > 0) || (shape.PathEnd > 0); + + hasHollow = shape.ProfileHollow > 0; + hasDimple = (shape.ProfileBegin > 0) || (shape.ProfileEnd > 0); // taken from llSetPrimitiveParms + hasProfileCut = hasDimple; // is it the same thing? + + } + + private static int getScriptPrimType(PrimitiveBaseShape primShape) + { + if (primShape.SculptEntry) + return (int) PrimType.Sculpt; + if ((primShape.ProfileCurve & 0x07) == (byte) ProfileShape.Square) + { + if (primShape.PathCurve == (byte) Extrusion.Straight) + return (int) PrimType.Box; + if (primShape.PathCurve == (byte) Extrusion.Curve1) + return (int) PrimType.Tube; + } + else if ((primShape.ProfileCurve & 0x07) == (byte) ProfileShape.Circle) + { + if (primShape.PathCurve == (byte) Extrusion.Straight) + return (int) PrimType.Cylinder; + if (primShape.PathCurve == (byte) Extrusion.Curve1) + return (int) PrimType.Torus; + } + else if ((primShape.ProfileCurve & 0x07) == (byte) ProfileShape.HalfCircle) + { + if (primShape.PathCurve == (byte) Extrusion.Curve1 || primShape.PathCurve == (byte) Extrusion.Curve2) + return (int) PrimType.Sphere; + } + else if ((primShape.ProfileCurve & 0x07) == (byte) ProfileShape.EquilateralTriangle) + { + if (primShape.PathCurve == (byte) Extrusion.Straight) + return (int) PrimType.Prism; + if (primShape.PathCurve == (byte) Extrusion.Curve1) + return (int) PrimType.Ring; + } + return (int) PrimType.NotPrimitive; + } + + private static int getNumberOfSides(SceneObjectPart part) + { + int ret; + bool hasCut; + bool hasHollow; + bool hasDimple; + bool hasProfileCut; + + int primType = getScriptPrimType(part.Shape); + hasCutHollowDimpleProfileCut(primType, part.Shape, out hasCut, out hasHollow, out hasDimple, out hasProfileCut); + + switch (primType) + { + default: + case (int) PrimType.Box: + ret = 6; + if (hasCut) ret += 2; + if (hasHollow) ret += 1; + break; + case (int) PrimType.Cylinder: + ret = 3; + if (hasCut) ret += 2; + if (hasHollow) ret += 1; + break; + case (int) PrimType.Prism: + ret = 5; + if (hasCut) ret += 2; + if (hasHollow) ret += 1; + break; + case (int) PrimType.Sphere: + ret = 1; + if (hasCut) ret += 2; + if (hasDimple) ret += 2; + if (hasHollow) + ret += 1; // GOTCHA: LSL shows 2 additional sides here. + // This has been fixed, but may cause porting issues. + break; + case (int) PrimType.Torus: + ret = 1; + if (hasCut) ret += 2; + if (hasProfileCut) ret += 2; + if (hasHollow) ret += 1; + break; + case (int) PrimType.Tube: + ret = 4; + if (hasCut) ret += 2; + if (hasProfileCut) ret += 2; + if (hasHollow) ret += 1; + break; + case (int) PrimType.Ring: + ret = 3; + if (hasCut) ret += 2; + if (hasProfileCut) ret += 2; + if (hasHollow) ret += 1; + break; + case (int) PrimType.Sculpt: + ret = 1; + break; + } + return ret; + } + + + #endregion + + } +} diff --git a/OpenSim/Region/OptionalModules/Scripting/Minimodule/World.cs b/OpenSim/Region/OptionalModules/Scripting/Minimodule/World.cs index 6c7f854..b1a4394 100644 --- a/OpenSim/Region/OptionalModules/Scripting/Minimodule/World.cs +++ b/OpenSim/Region/OptionalModules/Scripting/Minimodule/World.cs @@ -1,39 +1,39 @@ -using System.Collections.Generic; -using OpenSim.Region.Framework.Scenes; - -namespace OpenSim.Region.OptionalModules.Scripting.Minimodule -{ - public class World : IWorld - { - private readonly Scene m_internalScene; - private readonly Heightmap m_heights; - - public World(Scene internalScene) - { - m_internalScene = internalScene; - m_heights = new Heightmap(m_internalScene); - } - - public IObject[] Objects - { - get - { - List ents = m_internalScene.Entities.GetAllByType(); - IObject[] rets = new IObject[ents.Count]; - - for (int i = 0; i < ents.Count; i++) - { - EntityBase ent = ents[i]; - rets[i] = new SOPObject(m_internalScene, ent.LocalId); - } - - return rets; - } - } - - public IHeightmap Terrain - { - get { return m_heights; } - } - } -} +using System.Collections.Generic; +using OpenSim.Region.Framework.Scenes; + +namespace OpenSim.Region.OptionalModules.Scripting.Minimodule +{ + public class World : IWorld + { + private readonly Scene m_internalScene; + private readonly Heightmap m_heights; + + public World(Scene internalScene) + { + m_internalScene = internalScene; + m_heights = new Heightmap(m_internalScene); + } + + public IObject[] Objects + { + get + { + List ents = m_internalScene.Entities.GetAllByType(); + IObject[] rets = new IObject[ents.Count]; + + for (int i = 0; i < ents.Count; i++) + { + EntityBase ent = ents[i]; + rets[i] = new SOPObject(m_internalScene, ent.LocalId); + } + + return rets; + } + } + + public IHeightmap Terrain + { + get { return m_heights; } + } + } +} diff --git a/OpenSim/Region/OptionalModules/Scripting/ObjectModules/IObjectModule.cs b/OpenSim/Region/OptionalModules/Scripting/ObjectModules/IObjectModule.cs index 923b053..6ced656 100644 --- a/OpenSim/Region/OptionalModules/Scripting/ObjectModules/IObjectModule.cs +++ b/OpenSim/Region/OptionalModules/Scripting/ObjectModules/IObjectModule.cs @@ -1,15 +1,15 @@ -using OpenSim.Region.Framework.Scenes; - -namespace OpenSim.Region.OptionalModules.Scripting.ObjectModules -{ - interface IObjectModule - { - void Add(EntityBase entity, Scene scene); - void Start(); - void Stop(); - void Tick(); - - string ClassName { get; } - bool IsShared { get; } - } -} +using OpenSim.Region.Framework.Scenes; + +namespace OpenSim.Region.OptionalModules.Scripting.ObjectModules +{ + interface IObjectModule + { + void Add(EntityBase entity, Scene scene); + void Start(); + void Stop(); + void Tick(); + + string ClassName { get; } + bool IsShared { get; } + } +} -- cgit v1.1