aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/ScriptEngine/LSOEngine/ScriptManager.cs
diff options
context:
space:
mode:
authorTedd Hansen2008-01-12 15:49:41 +0000
committerTedd Hansen2008-01-12 15:49:41 +0000
commit27859faf7abdee7874819539dc518ea9e44437a5 (patch)
treea612281fe31a9c2d99e2756410f97395961b03b0 /OpenSim/Region/ScriptEngine/LSOEngine/ScriptManager.cs
parentSet eol (diff)
downloadopensim-SC-27859faf7abdee7874819539dc518ea9e44437a5.zip
opensim-SC-27859faf7abdee7874819539dc518ea9e44437a5.tar.gz
opensim-SC-27859faf7abdee7874819539dc518ea9e44437a5.tar.bz2
opensim-SC-27859faf7abdee7874819539dc518ea9e44437a5.tar.xz
Welcome back LSO.
Added old LSO code, will use it as base to create new LSO VM.
Diffstat (limited to 'OpenSim/Region/ScriptEngine/LSOEngine/ScriptManager.cs')
-rw-r--r--OpenSim/Region/ScriptEngine/LSOEngine/ScriptManager.cs158
1 files changed, 158 insertions, 0 deletions
diff --git a/OpenSim/Region/ScriptEngine/LSOEngine/ScriptManager.cs b/OpenSim/Region/ScriptEngine/LSOEngine/ScriptManager.cs
new file mode 100644
index 0000000..0143027
--- /dev/null
+++ b/OpenSim/Region/ScriptEngine/LSOEngine/ScriptManager.cs
@@ -0,0 +1,158 @@
1/*
2* Copyright (c) Contributors, http://opensimulator.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*/
28
29using System;
30using System.Collections.Generic;
31using System.IO;
32using System.Reflection;
33using System.Runtime.Serialization.Formatters.Binary;
34using System.Threading;
35using libsecondlife;
36using OpenSim.Framework;
37using OpenSim.Region.Environment.Scenes;
38using OpenSim.Region.ScriptEngine.Common;
39
40namespace OpenSim.Region.ScriptEngine.LSOEngine
41{
42 public class ScriptManager : OpenSim.Region.ScriptEngine.Common.ScriptEngineBase.ScriptManager
43 {
44 public ScriptManager(Common.ScriptEngineBase.ScriptEngine scriptEngine)
45 : base(scriptEngine)
46 {
47 base.m_scriptEngine = scriptEngine;
48
49 }
50
51 // KEEP TRACK OF SCRIPTS <int id, whatever script>
52 //internal Dictionary<uint, Dictionary<LLUUID, LSL_BaseClass>> Scripts = new Dictionary<uint, Dictionary<LLUUID, LSL_BaseClass>>();
53 // LOAD SCRIPT
54 // UNLOAD SCRIPT
55 // PROVIDE SCRIPT WITH ITS INTERFACE TO OpenSim
56
57 public override void _StartScript(uint localID, LLUUID itemID, string Script)
58 {
59 //IScriptHost root = host.GetRoot();
60 Console.WriteLine("ScriptManager StartScript: localID: " + localID + ", itemID: " + itemID);
61
62 // We will initialize and start the script.
63 // It will be up to the script itself to hook up the correct events.
64 string ScriptSource = "";
65
66 SceneObjectPart m_host = World.GetSceneObjectPart(localID);
67
68 try
69 {
70 // Compile (We assume LSL)
71 //ScriptSource = LSLCompiler.CompileFromLSLText(Script);
72
73#if DEBUG
74 long before;
75 before = GC.GetTotalMemory(true);
76#endif
77
78 IScript CompiledScript;
79 CompiledScript = m_scriptEngine.m_AppDomainManager.LoadScript(ScriptSource);
80
81#if DEBUG
82 Console.WriteLine("Script " + itemID + " occupies {0} bytes", GC.GetTotalMemory(true) - before);
83#endif
84
85 CompiledScript.Source = ScriptSource;
86 // Add it to our script memstruct
87 SetScript(localID, itemID, CompiledScript);
88
89 // We need to give (untrusted) assembly a private instance of BuiltIns
90 // this private copy will contain Read-Only FullitemID so that it can bring that on to the server whenever needed.
91
92
93 LSL_BuiltIn_Commands LSLB = new LSL_BuiltIn_Commands(m_scriptEngine, m_host, localID, itemID);
94
95 // Start the script - giving it BuiltIns
96 CompiledScript.Start(LSLB);
97
98 // Fire the first start-event
99 m_scriptEngine.m_EventQueueManager.AddToScriptQueue(localID, itemID, "state_entry", new object[] { });
100 }
101 catch (Exception e)
102 {
103 //m_scriptEngine.Log.Error("ScriptEngine", "Error compiling script: " + e.ToString());
104 try
105 {
106 // DISPLAY ERROR INWORLD
107 string text = "Error compiling script:\r\n" + e.Message.ToString();
108 if (text.Length > 1500)
109 text = text.Substring(0, 1500);
110 World.SimChat(Helpers.StringToField(text), ChatTypeEnum.Say, 0, m_host.AbsolutePosition,
111 m_host.Name, m_host.UUID);
112 }
113 catch (Exception e2)
114 {
115 m_scriptEngine.Log.Error("ScriptEngine", "Error displaying error in-world: " + e2.ToString());
116 m_scriptEngine.Log.Error("ScriptEngine",
117 "Errormessage: Error compiling script:\r\n" + e.Message.ToString());
118 }
119 }
120 }
121
122 public override void _StopScript(uint localID, LLUUID itemID)
123 {
124 // Stop script
125 Console.WriteLine("Stop script localID: " + localID + " LLUID: " + itemID.ToString());
126
127
128 // Stop long command on script
129 m_scriptEngine.m_LSLLongCmdHandler.RemoveScript(localID, itemID);
130
131 IScript LSLBC = GetScript(localID, itemID);
132 if (LSLBC == null)
133 return;
134
135 // TEMP: First serialize it
136 //GetSerializedScript(localID, itemID);
137
138
139 try
140 {
141 // Get AppDomain
142 AppDomain ad = LSLBC.Exec.GetAppDomain();
143 // Tell script not to accept new requests
144 GetScript(localID, itemID).Exec.StopScript();
145 // Remove from internal structure
146 RemoveScript(localID, itemID);
147 // Tell AppDomain that we have stopped script
148 m_scriptEngine.m_AppDomainManager.StopScript(ad);
149 }
150 catch (Exception e)
151 {
152 Console.WriteLine("Exception stopping script localID: " + localID + " LLUID: " + itemID.ToString() +
153 ": " + e.ToString());
154 }
155 }
156
157 }
158} \ No newline at end of file