diff options
Diffstat (limited to 'OpenSim/Region/ScriptEngine/LSOEngine/ScriptManager.cs')
-rw-r--r-- | OpenSim/Region/ScriptEngine/LSOEngine/ScriptManager.cs | 314 |
1 files changed, 157 insertions, 157 deletions
diff --git a/OpenSim/Region/ScriptEngine/LSOEngine/ScriptManager.cs b/OpenSim/Region/ScriptEngine/LSOEngine/ScriptManager.cs index 0143027..56c422f 100644 --- a/OpenSim/Region/ScriptEngine/LSOEngine/ScriptManager.cs +++ b/OpenSim/Region/ScriptEngine/LSOEngine/ScriptManager.cs | |||
@@ -1,158 +1,158 @@ | |||
1 | /* | 1 | /* |
2 | * Copyright (c) Contributors, http://opensimulator.org/ | 2 | * Copyright (c) Contributors, http://opensimulator.org/ |
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | 3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. |
4 | * | 4 | * |
5 | * Redistribution and use in source and binary forms, with or without | 5 | * Redistribution and use in source and binary forms, with or without |
6 | * modification, are permitted provided that the following conditions are met: | 6 | * modification, are permitted provided that the following conditions are met: |
7 | * * Redistributions of source code must retain the above copyright | 7 | * * Redistributions of source code must retain the above copyright |
8 | * notice, this list of conditions and the following disclaimer. | 8 | * notice, this list of conditions and the following disclaimer. |
9 | * * Redistributions in binary form must reproduce the above copyright | 9 | * * Redistributions in binary form must reproduce the above copyright |
10 | * notice, this list of conditions and the following disclaimer in the | 10 | * notice, this list of conditions and the following disclaimer in the |
11 | * documentation and/or other materials provided with the distribution. | 11 | * documentation and/or other materials provided with the distribution. |
12 | * * Neither the name of the OpenSim Project nor the | 12 | * * Neither the name of the OpenSim Project nor the |
13 | * names of its contributors may be used to endorse or promote products | 13 | * names of its contributors may be used to endorse or promote products |
14 | * derived from this software without specific prior written permission. | 14 | * derived from this software without specific prior written permission. |
15 | * | 15 | * |
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS AS IS AND ANY | 16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS AS IS AND ANY |
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | 17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | 18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | 19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY |
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | 20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | 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 | 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 | 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 | 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. | 25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
26 | * | 26 | * |
27 | */ | 27 | */ |
28 | 28 | ||
29 | using System; | 29 | using System; |
30 | using System.Collections.Generic; | 30 | using System.Collections.Generic; |
31 | using System.IO; | 31 | using System.IO; |
32 | using System.Reflection; | 32 | using System.Reflection; |
33 | using System.Runtime.Serialization.Formatters.Binary; | 33 | using System.Runtime.Serialization.Formatters.Binary; |
34 | using System.Threading; | 34 | using System.Threading; |
35 | using libsecondlife; | 35 | using libsecondlife; |
36 | using OpenSim.Framework; | 36 | using OpenSim.Framework; |
37 | using OpenSim.Region.Environment.Scenes; | 37 | using OpenSim.Region.Environment.Scenes; |
38 | using OpenSim.Region.ScriptEngine.Common; | 38 | using OpenSim.Region.ScriptEngine.Common; |
39 | 39 | ||
40 | namespace OpenSim.Region.ScriptEngine.LSOEngine | 40 | namespace OpenSim.Region.ScriptEngine.LSOEngine |
41 | { | 41 | { |
42 | public class ScriptManager : OpenSim.Region.ScriptEngine.Common.ScriptEngineBase.ScriptManager | 42 | public class ScriptManager : OpenSim.Region.ScriptEngine.Common.ScriptEngineBase.ScriptManager |
43 | { | 43 | { |
44 | public ScriptManager(Common.ScriptEngineBase.ScriptEngine scriptEngine) | 44 | public ScriptManager(Common.ScriptEngineBase.ScriptEngine scriptEngine) |
45 | : base(scriptEngine) | 45 | : base(scriptEngine) |
46 | { | 46 | { |
47 | base.m_scriptEngine = scriptEngine; | 47 | base.m_scriptEngine = scriptEngine; |
48 | 48 | ||
49 | } | 49 | } |
50 | 50 | ||
51 | // KEEP TRACK OF SCRIPTS <int id, whatever script> | 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>>(); | 52 | //internal Dictionary<uint, Dictionary<LLUUID, LSL_BaseClass>> Scripts = new Dictionary<uint, Dictionary<LLUUID, LSL_BaseClass>>(); |
53 | // LOAD SCRIPT | 53 | // LOAD SCRIPT |
54 | // UNLOAD SCRIPT | 54 | // UNLOAD SCRIPT |
55 | // PROVIDE SCRIPT WITH ITS INTERFACE TO OpenSim | 55 | // PROVIDE SCRIPT WITH ITS INTERFACE TO OpenSim |
56 | 56 | ||
57 | public override void _StartScript(uint localID, LLUUID itemID, string Script) | 57 | public override void _StartScript(uint localID, LLUUID itemID, string Script) |
58 | { | 58 | { |
59 | //IScriptHost root = host.GetRoot(); | 59 | //IScriptHost root = host.GetRoot(); |
60 | Console.WriteLine("ScriptManager StartScript: localID: " + localID + ", itemID: " + itemID); | 60 | Console.WriteLine("ScriptManager StartScript: localID: " + localID + ", itemID: " + itemID); |
61 | 61 | ||
62 | // We will initialize and start the script. | 62 | // We will initialize and start the script. |
63 | // It will be up to the script itself to hook up the correct events. | 63 | // It will be up to the script itself to hook up the correct events. |
64 | string ScriptSource = ""; | 64 | string ScriptSource = ""; |
65 | 65 | ||
66 | SceneObjectPart m_host = World.GetSceneObjectPart(localID); | 66 | SceneObjectPart m_host = World.GetSceneObjectPart(localID); |
67 | 67 | ||
68 | try | 68 | try |
69 | { | 69 | { |
70 | // Compile (We assume LSL) | 70 | // Compile (We assume LSL) |
71 | //ScriptSource = LSLCompiler.CompileFromLSLText(Script); | 71 | //ScriptSource = LSLCompiler.CompileFromLSLText(Script); |
72 | 72 | ||
73 | #if DEBUG | 73 | #if DEBUG |
74 | long before; | 74 | long before; |
75 | before = GC.GetTotalMemory(true); | 75 | before = GC.GetTotalMemory(true); |
76 | #endif | 76 | #endif |
77 | 77 | ||
78 | IScript CompiledScript; | 78 | IScript CompiledScript; |
79 | CompiledScript = m_scriptEngine.m_AppDomainManager.LoadScript(ScriptSource); | 79 | CompiledScript = m_scriptEngine.m_AppDomainManager.LoadScript(ScriptSource); |
80 | 80 | ||
81 | #if DEBUG | 81 | #if DEBUG |
82 | Console.WriteLine("Script " + itemID + " occupies {0} bytes", GC.GetTotalMemory(true) - before); | 82 | Console.WriteLine("Script " + itemID + " occupies {0} bytes", GC.GetTotalMemory(true) - before); |
83 | #endif | 83 | #endif |
84 | 84 | ||
85 | CompiledScript.Source = ScriptSource; | 85 | CompiledScript.Source = ScriptSource; |
86 | // Add it to our script memstruct | 86 | // Add it to our script memstruct |
87 | SetScript(localID, itemID, CompiledScript); | 87 | SetScript(localID, itemID, CompiledScript); |
88 | 88 | ||
89 | // We need to give (untrusted) assembly a private instance of BuiltIns | 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. | 90 | // this private copy will contain Read-Only FullitemID so that it can bring that on to the server whenever needed. |
91 | 91 | ||
92 | 92 | ||
93 | LSL_BuiltIn_Commands LSLB = new LSL_BuiltIn_Commands(m_scriptEngine, m_host, localID, itemID); | 93 | LSL_BuiltIn_Commands LSLB = new LSL_BuiltIn_Commands(m_scriptEngine, m_host, localID, itemID); |
94 | 94 | ||
95 | // Start the script - giving it BuiltIns | 95 | // Start the script - giving it BuiltIns |
96 | CompiledScript.Start(LSLB); | 96 | CompiledScript.Start(LSLB); |
97 | 97 | ||
98 | // Fire the first start-event | 98 | // Fire the first start-event |
99 | m_scriptEngine.m_EventQueueManager.AddToScriptQueue(localID, itemID, "state_entry", new object[] { }); | 99 | m_scriptEngine.m_EventQueueManager.AddToScriptQueue(localID, itemID, "state_entry", new object[] { }); |
100 | } | 100 | } |
101 | catch (Exception e) | 101 | catch (Exception e) |
102 | { | 102 | { |
103 | //m_scriptEngine.Log.Error("ScriptEngine", "Error compiling script: " + e.ToString()); | 103 | //m_scriptEngine.Log.Error("ScriptEngine", "Error compiling script: " + e.ToString()); |
104 | try | 104 | try |
105 | { | 105 | { |
106 | // DISPLAY ERROR INWORLD | 106 | // DISPLAY ERROR INWORLD |
107 | string text = "Error compiling script:\r\n" + e.Message.ToString(); | 107 | string text = "Error compiling script:\r\n" + e.Message.ToString(); |
108 | if (text.Length > 1500) | 108 | if (text.Length > 1500) |
109 | text = text.Substring(0, 1500); | 109 | text = text.Substring(0, 1500); |
110 | World.SimChat(Helpers.StringToField(text), ChatTypeEnum.Say, 0, m_host.AbsolutePosition, | 110 | World.SimChat(Helpers.StringToField(text), ChatTypeEnum.Say, 0, m_host.AbsolutePosition, |
111 | m_host.Name, m_host.UUID); | 111 | m_host.Name, m_host.UUID); |
112 | } | 112 | } |
113 | catch (Exception e2) | 113 | catch (Exception e2) |
114 | { | 114 | { |
115 | m_scriptEngine.Log.Error("ScriptEngine", "Error displaying error in-world: " + e2.ToString()); | 115 | m_scriptEngine.Log.Error("ScriptEngine", "Error displaying error in-world: " + e2.ToString()); |
116 | m_scriptEngine.Log.Error("ScriptEngine", | 116 | m_scriptEngine.Log.Error("ScriptEngine", |
117 | "Errormessage: Error compiling script:\r\n" + e.Message.ToString()); | 117 | "Errormessage: Error compiling script:\r\n" + e.Message.ToString()); |
118 | } | 118 | } |
119 | } | 119 | } |
120 | } | 120 | } |
121 | 121 | ||
122 | public override void _StopScript(uint localID, LLUUID itemID) | 122 | public override void _StopScript(uint localID, LLUUID itemID) |
123 | { | 123 | { |
124 | // Stop script | 124 | // Stop script |
125 | Console.WriteLine("Stop script localID: " + localID + " LLUID: " + itemID.ToString()); | 125 | Console.WriteLine("Stop script localID: " + localID + " LLUID: " + itemID.ToString()); |
126 | 126 | ||
127 | 127 | ||
128 | // Stop long command on script | 128 | // Stop long command on script |
129 | m_scriptEngine.m_LSLLongCmdHandler.RemoveScript(localID, itemID); | 129 | m_scriptEngine.m_LSLLongCmdHandler.RemoveScript(localID, itemID); |
130 | 130 | ||
131 | IScript LSLBC = GetScript(localID, itemID); | 131 | IScript LSLBC = GetScript(localID, itemID); |
132 | if (LSLBC == null) | 132 | if (LSLBC == null) |
133 | return; | 133 | return; |
134 | 134 | ||
135 | // TEMP: First serialize it | 135 | // TEMP: First serialize it |
136 | //GetSerializedScript(localID, itemID); | 136 | //GetSerializedScript(localID, itemID); |
137 | 137 | ||
138 | 138 | ||
139 | try | 139 | try |
140 | { | 140 | { |
141 | // Get AppDomain | 141 | // Get AppDomain |
142 | AppDomain ad = LSLBC.Exec.GetAppDomain(); | 142 | AppDomain ad = LSLBC.Exec.GetAppDomain(); |
143 | // Tell script not to accept new requests | 143 | // Tell script not to accept new requests |
144 | GetScript(localID, itemID).Exec.StopScript(); | 144 | GetScript(localID, itemID).Exec.StopScript(); |
145 | // Remove from internal structure | 145 | // Remove from internal structure |
146 | RemoveScript(localID, itemID); | 146 | RemoveScript(localID, itemID); |
147 | // Tell AppDomain that we have stopped script | 147 | // Tell AppDomain that we have stopped script |
148 | m_scriptEngine.m_AppDomainManager.StopScript(ad); | 148 | m_scriptEngine.m_AppDomainManager.StopScript(ad); |
149 | } | 149 | } |
150 | catch (Exception e) | 150 | catch (Exception e) |
151 | { | 151 | { |
152 | Console.WriteLine("Exception stopping script localID: " + localID + " LLUID: " + itemID.ToString() + | 152 | Console.WriteLine("Exception stopping script localID: " + localID + " LLUID: " + itemID.ToString() + |
153 | ": " + e.ToString()); | 153 | ": " + e.ToString()); |
154 | } | 154 | } |
155 | } | 155 | } |
156 | 156 | ||
157 | } | 157 | } |
158 | } \ No newline at end of file | 158 | } \ No newline at end of file |