* More removing stuff. Tortoise SVN I hate you.

Sugilite
Adam Frisby 2007-06-28 08:35:41 +00:00
parent 9383fea40b
commit 17275f3ab7
4 changed files with 0 additions and 218 deletions

View File

@ -1,77 +0,0 @@
using System;
using System.Collections.Generic;
using System.Text;
// Compilation stuff
using System.CodeDom;
using System.CodeDom.Compiler;
using Microsoft.CSharp;
namespace OpenSim.Scripting
{
public class CSharpScriptEngine : IScriptCompiler
{
public string fileExt()
{
return ".cs";
}
private Dictionary<string,IScript> LoadDotNetScript(ICodeCompiler compiler, string filename)
{
CompilerParameters compilerParams = new CompilerParameters();
CompilerResults compilerResults;
compilerParams.GenerateExecutable = false;
compilerParams.GenerateInMemory = true;
compilerParams.IncludeDebugInformation = false;
compilerParams.ReferencedAssemblies.Add("OpenSim.Region.dll");
compilerParams.ReferencedAssemblies.Add("OpenSim.Framework.dll");
compilerParams.ReferencedAssemblies.Add("libsecondlife.dll");
compilerParams.ReferencedAssemblies.Add("System.dll");
compilerResults = compiler.CompileAssemblyFromFile(compilerParams, filename);
if (compilerResults.Errors.Count > 0)
{
OpenSim.Framework.Console.MainLog.Instance.Error("Compile errors");
foreach (CompilerError error in compilerResults.Errors)
{
OpenSim.Framework.Console.MainLog.Instance.Error(error.Line.ToString() + ": " + error.ErrorText.ToString());
}
}
else
{
Dictionary<string,IScript> scripts = new Dictionary<string,IScript>();
foreach (Type pluginType in compilerResults.CompiledAssembly.GetExportedTypes())
{
Type testInterface = pluginType.GetInterface("IScript", true);
if (testInterface != null)
{
IScript script = (IScript)compilerResults.CompiledAssembly.CreateInstance(pluginType.ToString());
string scriptName = "C#/" + script.getName();
Console.WriteLine("Script: " + scriptName + " loaded.");
if (!scripts.ContainsKey(scriptName))
{
scripts.Add(scriptName, script);
}
else
{
scripts[scriptName] = script;
}
}
}
return scripts;
}
return null;
}
public Dictionary<string,IScript> compile(string filename)
{
CSharpCodeProvider csharpProvider = new CSharpCodeProvider();
return LoadDotNetScript(csharpProvider.CreateCompiler(), filename);
}
}
}

View File

@ -1,44 +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);
string getName();
}
public class TestScript : IScript
{
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)
{
script.logger.Verbose("Hello " + presence.firstname.ToString() + "!");
}
void events_OnFrame()
{
//script.logger.Verbose("Hello World!");
}
}
}

View File

@ -1,31 +0,0 @@
using System;
using System.Collections.Generic;
using System.Text;
using OpenSim.Region.Scenes;
using OpenSim.Framework.Console;
namespace OpenSim.Scripting
{
/// <summary>
/// Class which provides access to the world
/// </summary>
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;
}
}
}

View File

@ -1,66 +0,0 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace OpenSim.Scripting
{
public class ScriptManager
{
List<IScript> scripts = new List<IScript>();
OpenSim.Region.Scenes.Scene scene;
Dictionary<string, IScriptCompiler> compilers = new Dictionary<string, IScriptCompiler>();
private void LoadFromCompiler(Dictionary<string, IScript> compiledscripts)
{
foreach (KeyValuePair<string, IScript> script in compiledscripts)
{
ScriptInfo scriptInfo = new ScriptInfo(scene); // Since each script could potentially corrupt their access with a stray assignment, making a new one for each script.
OpenSim.Framework.Console.MainLog.Instance.Verbose("Loading " + script.Key);
script.Value.Initialise(scriptInfo);
scripts.Add(script.Value);
}
OpenSim.Framework.Console.MainLog.Instance.Verbose("Finished loading " + compiledscripts.Count.ToString() + " script(s)");
}
public ScriptManager(OpenSim.Region.Scenes.Scene world)
{
scene = world;
// Defualt Engines
CSharpScriptEngine csharpCompiler = new CSharpScriptEngine();
compilers.Add(csharpCompiler.fileExt(),csharpCompiler);
}
public void Compile(string filename)
{
foreach (KeyValuePair<string, IScriptCompiler> compiler in compilers)
{
if (filename.EndsWith(compiler.Key))
{
LoadFromCompiler(compiler.Value.compile(filename));
break;
}
}
}
public void RunScriptCmd(string[] args)
{
switch (args[0])
{
case "load":
Compile(args[1]);
break;
default:
OpenSim.Framework.Console.MainLog.Instance.Error("Unknown script command");
break;
}
}
}
interface IScriptCompiler
{
Dictionary<string,IScript> compile(string filename);
string fileExt();
}
}