diff options
author | John Hurliman | 2009-10-27 13:31:04 -0700 |
---|---|---|
committer | John Hurliman | 2009-10-27 13:31:04 -0700 |
commit | 2525810e2a1b23f9c5b17b3d075e02c0c6255e2c (patch) | |
tree | f4312229b82d5edf8477920a97e7e79c40379473 | |
parent | Lowering the position tolerance of terse updates for ScenePresences to mitiga... (diff) | |
download | opensim-SC_OLD-2525810e2a1b23f9c5b17b3d075e02c0c6255e2c.zip opensim-SC_OLD-2525810e2a1b23f9c5b17b3d075e02c0c6255e2c.tar.gz opensim-SC_OLD-2525810e2a1b23f9c5b17b3d075e02c0c6255e2c.tar.bz2 opensim-SC_OLD-2525810e2a1b23f9c5b17b3d075e02c0c6255e2c.tar.xz |
Removed the DotNetEngine scripting engine. You will need to create a fresh checkout or clean out all *DotNet*.dll assemblies from the bin/ directory to run OpenSim moving forward
37 files changed, 1 insertions, 5907 deletions
diff --git a/OpenSim/Region/ScriptEngine/DotNetEngine/AppDomainManager.cs b/OpenSim/Region/ScriptEngine/DotNetEngine/AppDomainManager.cs deleted file mode 100644 index 7116512..0000000 --- a/OpenSim/Region/ScriptEngine/DotNetEngine/AppDomainManager.cs +++ /dev/null | |||
@@ -1,234 +0,0 @@ | |||
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 OpenSimulator 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 | using System; | ||
29 | using System.Collections; | ||
30 | using System.Collections.Generic; | ||
31 | using System.Reflection; | ||
32 | using System.Security; | ||
33 | using System.Security.Policy; | ||
34 | using System.Security.Permissions; | ||
35 | using OpenSim.Region.ScriptEngine.Interfaces; | ||
36 | using OpenSim.Region.ScriptEngine.Shared.ScriptBase; | ||
37 | using log4net; | ||
38 | |||
39 | namespace OpenSim.Region.ScriptEngine.DotNetEngine | ||
40 | { | ||
41 | public class AppDomainManager | ||
42 | { | ||
43 | // | ||
44 | // This class does AppDomain handling and loading/unloading of | ||
45 | // scripts in it. It is instanced in "ScriptEngine" and controlled | ||
46 | // from "ScriptManager" | ||
47 | // | ||
48 | // 1. Create a new AppDomain if old one is full (or doesn't exist) | ||
49 | // 2. Load scripts into AppDomain | ||
50 | // 3. Unload scripts from AppDomain (stopping them and marking | ||
51 | // them as inactive) | ||
52 | // 4. Unload AppDomain completely when all scripts in it has stopped | ||
53 | // | ||
54 | |||
55 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
56 | |||
57 | private int maxScriptsPerAppDomain = 1; | ||
58 | |||
59 | // Internal list of all AppDomains | ||
60 | private List<AppDomainStructure> appDomains = | ||
61 | new List<AppDomainStructure>(); | ||
62 | |||
63 | // Structure to keep track of data around AppDomain | ||
64 | private class AppDomainStructure | ||
65 | { | ||
66 | // The AppDomain itself | ||
67 | public AppDomain CurrentAppDomain; | ||
68 | |||
69 | // Number of scripts loaded into AppDomain | ||
70 | public int ScriptsLoaded; | ||
71 | |||
72 | // Number of dead scripts | ||
73 | public int ScriptsWaitingUnload; | ||
74 | } | ||
75 | |||
76 | // Current AppDomain | ||
77 | private AppDomainStructure currentAD; | ||
78 | |||
79 | private object getLock = new object(); // Mutex | ||
80 | private object freeLock = new object(); // Mutex | ||
81 | |||
82 | private ScriptEngine m_scriptEngine; | ||
83 | //public AppDomainManager(ScriptEngine scriptEngine) | ||
84 | public AppDomainManager(ScriptEngine scriptEngine) | ||
85 | { | ||
86 | m_scriptEngine = scriptEngine; | ||
87 | ReadConfig(); | ||
88 | } | ||
89 | |||
90 | public void ReadConfig() | ||
91 | { | ||
92 | maxScriptsPerAppDomain = m_scriptEngine.ScriptConfigSource.GetInt( | ||
93 | "ScriptsPerAppDomain", 1); | ||
94 | } | ||
95 | |||
96 | // Find a free AppDomain, creating one if necessary | ||
97 | private AppDomainStructure GetFreeAppDomain() | ||
98 | { | ||
99 | lock (getLock) | ||
100 | { | ||
101 | // Current full? | ||
102 | if (currentAD != null && | ||
103 | currentAD.ScriptsLoaded >= maxScriptsPerAppDomain) | ||
104 | { | ||
105 | // Add it to AppDomains list and empty current | ||
106 | appDomains.Add(currentAD); | ||
107 | currentAD = null; | ||
108 | } | ||
109 | // No current | ||
110 | if (currentAD == null) | ||
111 | { | ||
112 | // Create a new current AppDomain | ||
113 | currentAD = new AppDomainStructure(); | ||
114 | currentAD.CurrentAppDomain = PrepareNewAppDomain(); | ||
115 | } | ||
116 | |||
117 | return currentAD; | ||
118 | } | ||
119 | } | ||
120 | |||
121 | private int AppDomainNameCount; | ||
122 | |||
123 | // Create and prepare a new AppDomain for scripts | ||
124 | private AppDomain PrepareNewAppDomain() | ||
125 | { | ||
126 | // Create and prepare a new AppDomain | ||
127 | AppDomainNameCount++; | ||
128 | |||
129 | // TODO: Currently security match current appdomain | ||
130 | |||
131 | // Construct and initialize settings for a second AppDomain. | ||
132 | AppDomainSetup ads = new AppDomainSetup(); | ||
133 | ads.ApplicationBase = AppDomain.CurrentDomain.BaseDirectory; | ||
134 | ads.DisallowBindingRedirects = true; | ||
135 | ads.DisallowCodeDownload = true; | ||
136 | ads.LoaderOptimization = LoaderOptimization.MultiDomainHost; | ||
137 | ads.ShadowCopyFiles = "false"; // Disable shadowing | ||
138 | ads.ConfigurationFile = | ||
139 | AppDomain.CurrentDomain.SetupInformation.ConfigurationFile; | ||
140 | |||
141 | AppDomain AD = AppDomain.CreateDomain("ScriptAppDomain_" + | ||
142 | AppDomainNameCount, null, ads); | ||
143 | |||
144 | m_log.Info("[" + m_scriptEngine.ScriptEngineName + | ||
145 | "]: AppDomain Loading: " + | ||
146 | AssemblyName.GetAssemblyName( | ||
147 | "OpenSim.Region.ScriptEngine.Shared.dll").ToString()); | ||
148 | AD.Load(AssemblyName.GetAssemblyName( | ||
149 | "OpenSim.Region.ScriptEngine.Shared.dll")); | ||
150 | |||
151 | // Return the new AppDomain | ||
152 | return AD; | ||
153 | } | ||
154 | |||
155 | // Unload appdomains that are full and have only dead scripts | ||
156 | private void UnloadAppDomains() | ||
157 | { | ||
158 | lock (freeLock) | ||
159 | { | ||
160 | // Go through all | ||
161 | foreach (AppDomainStructure ads in new ArrayList(appDomains)) | ||
162 | { | ||
163 | // Don't process current AppDomain | ||
164 | if (ads.CurrentAppDomain != currentAD.CurrentAppDomain) | ||
165 | { | ||
166 | // Not current AppDomain | ||
167 | // Is number of unloaded bigger or equal to number of loaded? | ||
168 | if (ads.ScriptsLoaded <= ads.ScriptsWaitingUnload) | ||
169 | { | ||
170 | // Remove from internal list | ||
171 | appDomains.Remove(ads); | ||
172 | |||
173 | // Unload | ||
174 | AppDomain.Unload(ads.CurrentAppDomain); | ||
175 | } | ||
176 | } | ||
177 | } | ||
178 | } | ||
179 | } | ||
180 | |||
181 | public IScript LoadScript(string FileName, out AppDomain ad) | ||
182 | { | ||
183 | // Find next available AppDomain to put it in | ||
184 | AppDomainStructure FreeAppDomain = GetFreeAppDomain(); | ||
185 | |||
186 | IScript mbrt = (IScript) | ||
187 | FreeAppDomain.CurrentAppDomain.CreateInstanceFromAndUnwrap( | ||
188 | FileName, "SecondLife.Script"); | ||
189 | |||
190 | FreeAppDomain.ScriptsLoaded++; | ||
191 | ad = FreeAppDomain.CurrentAppDomain; | ||
192 | |||
193 | return mbrt; | ||
194 | } | ||
195 | |||
196 | |||
197 | // Increase "dead script" counter for an AppDomain | ||
198 | public void StopScript(AppDomain ad) | ||
199 | { | ||
200 | lock (freeLock) | ||
201 | { | ||
202 | // Check if it is current AppDomain | ||
203 | if (currentAD.CurrentAppDomain == ad) | ||
204 | { | ||
205 | // Yes - increase | ||
206 | currentAD.ScriptsWaitingUnload++; | ||
207 | return; | ||
208 | } | ||
209 | |||
210 | // Lopp through all AppDomains | ||
211 | foreach (AppDomainStructure ads in new ArrayList(appDomains)) | ||
212 | { | ||
213 | if (ads.CurrentAppDomain == ad) | ||
214 | { | ||
215 | // Found it | ||
216 | ads.ScriptsWaitingUnload++; | ||
217 | break; | ||
218 | } | ||
219 | } | ||
220 | } | ||
221 | |||
222 | UnloadAppDomains(); // Outsite lock, has its own GetLock | ||
223 | } | ||
224 | |||
225 | // If set to true then threads and stuff should try | ||
226 | // to make a graceful exit | ||
227 | public bool PleaseShutdown | ||
228 | { | ||
229 | get { return _PleaseShutdown; } | ||
230 | set { _PleaseShutdown = value; } | ||
231 | } | ||
232 | private bool _PleaseShutdown = false; | ||
233 | } | ||
234 | } | ||
diff --git a/OpenSim/Region/ScriptEngine/DotNetEngine/Common.cs b/OpenSim/Region/ScriptEngine/DotNetEngine/Common.cs deleted file mode 100644 index 1cd60e3..0000000 --- a/OpenSim/Region/ScriptEngine/DotNetEngine/Common.cs +++ /dev/null | |||
@@ -1,51 +0,0 @@ | |||
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 OpenSimulator 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 | using System.Reflection; | ||
29 | using log4net; | ||
30 | |||
31 | namespace OpenSim.Region.ScriptEngine.DotNetEngine | ||
32 | { | ||
33 | public static class Common | ||
34 | { | ||
35 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
36 | |||
37 | public static ScriptEngine mySE; | ||
38 | |||
39 | // This class just contains some static log stuff used for debugging. | ||
40 | |||
41 | public static void SendToDebug(string message) | ||
42 | { | ||
43 | m_log.Info("[" + mySE.ScriptEngineName + "]: Debug: " + message); | ||
44 | } | ||
45 | |||
46 | public static void SendToLog(string message) | ||
47 | { | ||
48 | m_log.Info("[" + mySE.ScriptEngineName + "]: LOG: " + message); | ||
49 | } | ||
50 | } | ||
51 | } | ||
diff --git a/OpenSim/Region/ScriptEngine/DotNetEngine/EventManager.cs b/OpenSim/Region/ScriptEngine/DotNetEngine/EventManager.cs deleted file mode 100644 index 4e13fb3..0000000 --- a/OpenSim/Region/ScriptEngine/DotNetEngine/EventManager.cs +++ /dev/null | |||
@@ -1,544 +0,0 @@ | |||
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 OpenSimulator 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 | using System; | ||
29 | using System.Collections.Generic; | ||
30 | using System.Reflection; | ||
31 | using OpenMetaverse; | ||
32 | using OpenSim.Framework; | ||
33 | using OpenSim.Region.CoreModules; | ||
34 | using OpenSim.Region; | ||
35 | using OpenSim.Region.Framework.Scenes; | ||
36 | using OpenSim.Region.Framework.Interfaces; | ||
37 | using OpenSim.Region.ScriptEngine.Shared; | ||
38 | using log4net; | ||
39 | |||
40 | namespace OpenSim.Region.ScriptEngine.DotNetEngine | ||
41 | { | ||
42 | /// <summary> | ||
43 | /// Prepares events so they can be directly executed upon a script by EventQueueManager, then queues it. | ||
44 | /// </summary> | ||
45 | [Serializable] | ||
46 | public class EventManager | ||
47 | { | ||
48 | // | ||
49 | // Class is instanced in "ScriptEngine" and Uses "EventQueueManager" | ||
50 | // that is also instanced in "ScriptEngine". | ||
51 | // This class needs a bit of explaining: | ||
52 | // | ||
53 | // This class it the link between an event inside OpenSim and | ||
54 | // the corresponding event in a user script being executed. | ||
55 | // | ||
56 | // For example when an user touches an object then the | ||
57 | // "myScriptEngine.World.EventManager.OnObjectGrab" event is fired | ||
58 | // inside OpenSim. | ||
59 | // We hook up to this event and queue a touch_start in | ||
60 | // EventQueueManager with the proper LSL parameters. | ||
61 | // It will then be delivered to the script by EventQueueManager. | ||
62 | // | ||
63 | // You can check debug C# dump of an LSL script if you need to | ||
64 | // verify what exact parameters are needed. | ||
65 | // | ||
66 | |||
67 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
68 | |||
69 | private ScriptEngine myScriptEngine; | ||
70 | |||
71 | public EventManager(ScriptEngine _ScriptEngine, bool performHookUp) | ||
72 | { | ||
73 | myScriptEngine = _ScriptEngine; | ||
74 | ReadConfig(); | ||
75 | |||
76 | if (performHookUp) | ||
77 | { | ||
78 | myScriptEngine.World.EventManager.OnRezScript += OnRezScript; | ||
79 | } | ||
80 | } | ||
81 | |||
82 | public void HookUpEvents() | ||
83 | { | ||
84 | m_log.Info("[" + myScriptEngine.ScriptEngineName + | ||
85 | "]: Hooking up to server events"); | ||
86 | |||
87 | myScriptEngine.World.EventManager.OnObjectGrab += | ||
88 | touch_start; | ||
89 | myScriptEngine.World.EventManager.OnObjectDeGrab += | ||
90 | touch_end; | ||
91 | myScriptEngine.World.EventManager.OnRemoveScript += | ||
92 | OnRemoveScript; | ||
93 | myScriptEngine.World.EventManager.OnScriptChangedEvent += | ||
94 | changed; | ||
95 | myScriptEngine.World.EventManager.OnScriptAtTargetEvent += | ||
96 | at_target; | ||
97 | myScriptEngine.World.EventManager.OnScriptNotAtTargetEvent += | ||
98 | not_at_target; | ||
99 | myScriptEngine.World.EventManager.OnScriptControlEvent += | ||
100 | control; | ||
101 | myScriptEngine.World.EventManager.OnScriptColliderStart += | ||
102 | collision_start; | ||
103 | myScriptEngine.World.EventManager.OnScriptColliding += | ||
104 | collision; | ||
105 | myScriptEngine.World.EventManager.OnScriptCollidingEnd += | ||
106 | collision_end; | ||
107 | |||
108 | IMoneyModule money = | ||
109 | myScriptEngine.World.RequestModuleInterface<IMoneyModule>(); | ||
110 | if (money != null) | ||
111 | money.OnObjectPaid+=HandleObjectPaid; | ||
112 | } | ||
113 | |||
114 | public void ReadConfig() | ||
115 | { | ||
116 | } | ||
117 | |||
118 | private void HandleObjectPaid(UUID objectID, UUID agentID, int amount) | ||
119 | { | ||
120 | SceneObjectPart part = | ||
121 | myScriptEngine.World.GetSceneObjectPart(objectID); | ||
122 | |||
123 | if (part != null) | ||
124 | { | ||
125 | money(part.LocalId, agentID, amount); | ||
126 | } | ||
127 | } | ||
128 | |||
129 | public void changed(uint localID, uint change) | ||
130 | { | ||
131 | // Add to queue for all scripts in localID, Object pass change. | ||
132 | myScriptEngine.PostObjectEvent(localID, new EventParams( | ||
133 | "changed",new object[] { new LSL_Types.LSLInteger(change) }, | ||
134 | new DetectParams[0])); | ||
135 | } | ||
136 | |||
137 | public void state_entry(uint localID) | ||
138 | { | ||
139 | // Add to queue for all scripts in ObjectID object | ||
140 | myScriptEngine.PostObjectEvent(localID, new EventParams( | ||
141 | "state_entry",new object[] { }, | ||
142 | new DetectParams[0])); | ||
143 | } | ||
144 | |||
145 | public void touch_start(uint localID, uint originalID, | ||
146 | Vector3 offsetPos, IClientAPI remoteClient, SurfaceTouchEventArgs surfaceArgs) | ||
147 | { | ||
148 | // Add to queue for all scripts in ObjectID object | ||
149 | DetectParams[] det = new DetectParams[1]; | ||
150 | det[0] = new DetectParams(); | ||
151 | det[0].Key = remoteClient.AgentId; | ||
152 | det[0].Populate(myScriptEngine.World); | ||
153 | |||
154 | if (originalID == 0) | ||
155 | { | ||
156 | SceneObjectPart part = | ||
157 | myScriptEngine.World.GetSceneObjectPart(localID); | ||
158 | |||
159 | if (part == null) | ||
160 | return; | ||
161 | |||
162 | det[0].LinkNum = part.LinkNum; | ||
163 | } | ||
164 | else | ||
165 | { | ||
166 | SceneObjectPart originalPart = | ||
167 | myScriptEngine.World.GetSceneObjectPart(originalID); | ||
168 | det[0].LinkNum = originalPart.LinkNum; | ||
169 | } | ||
170 | if (surfaceArgs != null) | ||
171 | { | ||
172 | det[0].SurfaceTouchArgs = surfaceArgs; | ||
173 | } | ||
174 | |||
175 | myScriptEngine.PostObjectEvent(localID, new EventParams( | ||
176 | "touch_start", new Object[] { new LSL_Types.LSLInteger(1) }, | ||
177 | det)); | ||
178 | } | ||
179 | |||
180 | public void touch(uint localID, uint originalID, Vector3 offsetPos, | ||
181 | IClientAPI remoteClient) | ||
182 | { | ||
183 | // Add to queue for all scripts in ObjectID object | ||
184 | DetectParams[] det = new DetectParams[1]; | ||
185 | det[0] = new DetectParams(); | ||
186 | det[0].Key = remoteClient.AgentId; | ||
187 | det[0].Populate(myScriptEngine.World); | ||
188 | det[0].OffsetPos = new LSL_Types.Vector3(offsetPos.X, | ||
189 | offsetPos.Y, | ||
190 | offsetPos.Z); | ||
191 | |||
192 | if (originalID == 0) | ||
193 | { | ||
194 | SceneObjectPart part = myScriptEngine.World.GetSceneObjectPart(localID); | ||
195 | if (part == null) | ||
196 | return; | ||
197 | |||
198 | det[0].LinkNum = part.LinkNum; | ||
199 | } | ||
200 | else | ||
201 | { | ||
202 | SceneObjectPart originalPart = myScriptEngine.World.GetSceneObjectPart(originalID); | ||
203 | det[0].LinkNum = originalPart.LinkNum; | ||
204 | } | ||
205 | |||
206 | myScriptEngine.PostObjectEvent(localID, new EventParams( | ||
207 | "touch", new Object[] { new LSL_Types.LSLInteger(1) }, | ||
208 | det)); | ||
209 | } | ||
210 | |||
211 | public void touch_end(uint localID, uint originalID, IClientAPI remoteClient, | ||
212 | SurfaceTouchEventArgs surfaceArgs) | ||
213 | { | ||
214 | // Add to queue for all scripts in ObjectID object | ||
215 | DetectParams[] det = new DetectParams[1]; | ||
216 | det[0] = new DetectParams(); | ||
217 | det[0].Key = remoteClient.AgentId; | ||
218 | det[0].Populate(myScriptEngine.World); | ||
219 | |||
220 | if (originalID == 0) | ||
221 | { | ||
222 | SceneObjectPart part = | ||
223 | myScriptEngine.World.GetSceneObjectPart(localID); | ||
224 | if (part == null) | ||
225 | return; | ||
226 | |||
227 | det[0].LinkNum = part.LinkNum; | ||
228 | } | ||
229 | else | ||
230 | { | ||
231 | SceneObjectPart originalPart = | ||
232 | myScriptEngine.World.GetSceneObjectPart(originalID); | ||
233 | det[0].LinkNum = originalPart.LinkNum; | ||
234 | } | ||
235 | |||
236 | if (surfaceArgs != null) | ||
237 | { | ||
238 | det[0].SurfaceTouchArgs = surfaceArgs; | ||
239 | } | ||
240 | |||
241 | myScriptEngine.PostObjectEvent(localID, new EventParams( | ||
242 | "touch_end", new Object[] { new LSL_Types.LSLInteger(1) }, | ||
243 | det)); | ||
244 | } | ||
245 | |||
246 | public void OnRezScript(uint localID, UUID itemID, string script, | ||
247 | int startParam, bool postOnRez, string engine, int stateSource) | ||
248 | { | ||
249 | if (script.StartsWith("//MRM:")) | ||
250 | return; | ||
251 | |||
252 | List<IScriptModule> engines = | ||
253 | new List<IScriptModule>( | ||
254 | myScriptEngine.World.RequestModuleInterfaces<IScriptModule>()); | ||
255 | |||
256 | List<string> names = new List<string>(); | ||
257 | foreach (IScriptModule m in engines) | ||
258 | names.Add(m.ScriptEngineName); | ||
259 | |||
260 | int lineEnd = script.IndexOf('\n'); | ||
261 | |||
262 | if (lineEnd > 1) | ||
263 | { | ||
264 | string firstline = script.Substring(0, lineEnd).Trim(); | ||
265 | |||
266 | int colon = firstline.IndexOf(':'); | ||
267 | if (firstline.Length > 2 && | ||
268 | firstline.Substring(0, 2) == "//" && colon != -1) | ||
269 | { | ||
270 | string engineName = firstline.Substring(2, colon-2); | ||
271 | |||
272 | if (names.Contains(engineName)) | ||
273 | { | ||
274 | engine = engineName; | ||
275 | script = "//" + script.Substring(script.IndexOf(':')+1); | ||
276 | } | ||
277 | else | ||
278 | { | ||
279 | if (engine == myScriptEngine.ScriptEngineName) | ||
280 | { | ||
281 | SceneObjectPart part = | ||
282 | myScriptEngine.World.GetSceneObjectPart( | ||
283 | localID); | ||
284 | |||
285 | TaskInventoryItem item = | ||
286 | part.Inventory.GetInventoryItem(itemID); | ||
287 | |||
288 | ScenePresence presence = | ||
289 | myScriptEngine.World.GetScenePresence( | ||
290 | item.OwnerID); | ||
291 | |||
292 | if (presence != null) | ||
293 | { | ||
294 | presence.ControllingClient.SendAgentAlertMessage( | ||
295 | "Selected engine unavailable. "+ | ||
296 | "Running script on "+ | ||
297 | myScriptEngine.ScriptEngineName, | ||
298 | false); | ||
299 | } | ||
300 | } | ||
301 | } | ||
302 | } | ||
303 | } | ||
304 | |||
305 | if (engine != myScriptEngine.ScriptEngineName) | ||
306 | return; | ||
307 | |||
308 | // m_log.Debug("OnRezScript localID: " + localID + | ||
309 | // " LLUID: " + itemID.ToString() + " Size: " + | ||
310 | // script.Length); | ||
311 | |||
312 | myScriptEngine.m_ScriptManager.StartScript(localID, itemID, script, | ||
313 | startParam, postOnRez); | ||
314 | } | ||
315 | |||
316 | public void OnRemoveScript(uint localID, UUID itemID) | ||
317 | { | ||
318 | // m_log.Debug("OnRemoveScript localID: " + localID + " LLUID: " + itemID.ToString()); | ||
319 | myScriptEngine.m_ScriptManager.StopScript( | ||
320 | localID, | ||
321 | itemID | ||
322 | ); | ||
323 | } | ||
324 | |||
325 | public void money(uint localID, UUID agentID, int amount) | ||
326 | { | ||
327 | myScriptEngine.PostObjectEvent(localID, new EventParams( | ||
328 | "money", new object[] { | ||
329 | new LSL_Types.LSLString(agentID.ToString()), | ||
330 | new LSL_Types.LSLInteger(amount) }, | ||
331 | new DetectParams[0])); | ||
332 | } | ||
333 | |||
334 | // TODO: Replace placeholders below | ||
335 | // NOTE! THE PARAMETERS FOR THESE FUNCTIONS ARE NOT CORRECT! | ||
336 | // These needs to be hooked up to OpenSim during init of this class | ||
337 | // then queued in EventQueueManager. | ||
338 | // When queued in EventQueueManager they need to be LSL compatible (name and params) | ||
339 | |||
340 | public void state_exit(uint localID) | ||
341 | { | ||
342 | myScriptEngine.PostObjectEvent(localID, new EventParams( | ||
343 | "state_exit", new object[] { }, | ||
344 | new DetectParams[0])); | ||
345 | } | ||
346 | |||
347 | public void collision_start(uint localID, ColliderArgs col) | ||
348 | { | ||
349 | // Add to queue for all scripts in ObjectID object | ||
350 | List<DetectParams> det = new List<DetectParams>(); | ||
351 | |||
352 | foreach (DetectedObject detobj in col.Colliders) | ||
353 | { | ||
354 | DetectParams d = new DetectParams(); | ||
355 | d.Key =detobj.keyUUID; | ||
356 | d.Populate(myScriptEngine.World); | ||
357 | det.Add(d); | ||
358 | } | ||
359 | |||
360 | if (det.Count > 0) | ||
361 | myScriptEngine.PostObjectEvent(localID, new EventParams( | ||
362 | "collision_start", | ||
363 | new Object[] { new LSL_Types.LSLInteger(det.Count) }, | ||
364 | det.ToArray())); | ||
365 | } | ||
366 | |||
367 | public void collision(uint localID, ColliderArgs col) | ||
368 | { | ||
369 | // Add to queue for all scripts in ObjectID object | ||
370 | List<DetectParams> det = new List<DetectParams>(); | ||
371 | |||
372 | foreach (DetectedObject detobj in col.Colliders) | ||
373 | { | ||
374 | DetectParams d = new DetectParams(); | ||
375 | d.Key =detobj.keyUUID; | ||
376 | d.Populate(myScriptEngine.World); | ||
377 | det.Add(d); | ||
378 | } | ||
379 | |||
380 | if (det.Count > 0) | ||
381 | myScriptEngine.PostObjectEvent(localID, new EventParams( | ||
382 | "collision", new Object[] { new LSL_Types.LSLInteger(det.Count) }, | ||
383 | det.ToArray())); | ||
384 | } | ||
385 | |||
386 | public void collision_end(uint localID, ColliderArgs col) | ||
387 | { | ||
388 | // Add to queue for all scripts in ObjectID object | ||
389 | List<DetectParams> det = new List<DetectParams>(); | ||
390 | |||
391 | foreach (DetectedObject detobj in col.Colliders) | ||
392 | { | ||
393 | DetectParams d = new DetectParams(); | ||
394 | d.Key =detobj.keyUUID; | ||
395 | d.Populate(myScriptEngine.World); | ||
396 | det.Add(d); | ||
397 | } | ||
398 | |||
399 | if (det.Count > 0) | ||
400 | myScriptEngine.PostObjectEvent(localID, new EventParams( | ||
401 | "collision_end", | ||
402 | new Object[] { new LSL_Types.LSLInteger(det.Count) }, | ||
403 | det.ToArray())); | ||
404 | } | ||
405 | |||
406 | public void land_collision_start(uint localID, UUID itemID) | ||
407 | { | ||
408 | myScriptEngine.PostObjectEvent(localID, new EventParams( | ||
409 | "land_collision_start", | ||
410 | new object[0], | ||
411 | new DetectParams[0])); | ||
412 | } | ||
413 | |||
414 | public void land_collision(uint localID, UUID itemID) | ||
415 | { | ||
416 | myScriptEngine.PostObjectEvent(localID, new EventParams( | ||
417 | "land_collision", | ||
418 | new object[0], | ||
419 | new DetectParams[0])); | ||
420 | } | ||
421 | |||
422 | public void land_collision_end(uint localID, UUID itemID) | ||
423 | { | ||
424 | myScriptEngine.PostObjectEvent(localID, new EventParams( | ||
425 | "land_collision_end", | ||
426 | new object[0], | ||
427 | new DetectParams[0])); | ||
428 | } | ||
429 | |||
430 | // Handled by long commands | ||
431 | public void timer(uint localID, UUID itemID) | ||
432 | { | ||
433 | } | ||
434 | |||
435 | public void listen(uint localID, UUID itemID) | ||
436 | { | ||
437 | } | ||
438 | |||
439 | public void control(uint localID, UUID itemID, UUID agentID, uint held, uint change) | ||
440 | { | ||
441 | if ((change == 0) && (myScriptEngine.m_EventQueueManager.CheckEeventQueueForEvent(localID,"control"))) return; | ||
442 | myScriptEngine.PostObjectEvent(localID, new EventParams( | ||
443 | "control",new object[] { | ||
444 | new LSL_Types.LSLString(agentID.ToString()), | ||
445 | new LSL_Types.LSLInteger(held), | ||
446 | new LSL_Types.LSLInteger(change)}, | ||
447 | new DetectParams[0])); | ||
448 | } | ||
449 | |||
450 | public void email(uint localID, UUID itemID, string timeSent, | ||
451 | string address, string subject, string message, int numLeft) | ||
452 | { | ||
453 | myScriptEngine.PostObjectEvent(localID, new EventParams( | ||
454 | "email",new object[] { | ||
455 | new LSL_Types.LSLString(timeSent), | ||
456 | new LSL_Types.LSLString(address), | ||
457 | new LSL_Types.LSLString(subject), | ||
458 | new LSL_Types.LSLString(message), | ||
459 | new LSL_Types.LSLInteger(numLeft)}, | ||
460 | new DetectParams[0])); | ||
461 | } | ||
462 | |||
463 | public void at_target(uint localID, uint handle, Vector3 targetpos, | ||
464 | Vector3 atpos) | ||
465 | { | ||
466 | myScriptEngine.PostObjectEvent(localID, new EventParams( | ||
467 | "at_target", new object[] { | ||
468 | new LSL_Types.LSLInteger(handle), | ||
469 | new LSL_Types.Vector3(targetpos.X,targetpos.Y,targetpos.Z), | ||
470 | new LSL_Types.Vector3(atpos.X,atpos.Y,atpos.Z) }, | ||
471 | new DetectParams[0])); | ||
472 | } | ||
473 | |||
474 | public void not_at_target(uint localID) | ||
475 | { | ||
476 | myScriptEngine.PostObjectEvent(localID, new EventParams( | ||
477 | "not_at_target",new object[0], | ||
478 | new DetectParams[0])); | ||
479 | } | ||
480 | |||
481 | public void at_rot_target(uint localID, UUID itemID) | ||
482 | { | ||
483 | myScriptEngine.PostObjectEvent(localID, new EventParams( | ||
484 | "at_rot_target",new object[0], | ||
485 | new DetectParams[0])); | ||
486 | } | ||
487 | |||
488 | public void not_at_rot_target(uint localID, UUID itemID) | ||
489 | { | ||
490 | myScriptEngine.PostObjectEvent(localID, new EventParams( | ||
491 | "not_at_rot_target",new object[0], | ||
492 | new DetectParams[0])); | ||
493 | } | ||
494 | |||
495 | public void attach(uint localID, UUID itemID) | ||
496 | { | ||
497 | } | ||
498 | |||
499 | public void dataserver(uint localID, UUID itemID) | ||
500 | { | ||
501 | } | ||
502 | |||
503 | public void link_message(uint localID, UUID itemID) | ||
504 | { | ||
505 | } | ||
506 | |||
507 | public void moving_start(uint localID, UUID itemID) | ||
508 | { | ||
509 | myScriptEngine.PostObjectEvent(localID, new EventParams( | ||
510 | "moving_start",new object[0], | ||
511 | new DetectParams[0])); | ||
512 | } | ||
513 | |||
514 | public void moving_end(uint localID, UUID itemID) | ||
515 | { | ||
516 | myScriptEngine.PostObjectEvent(localID, new EventParams( | ||
517 | "moving_end",new object[0], | ||
518 | new DetectParams[0])); | ||
519 | } | ||
520 | |||
521 | public void object_rez(uint localID, UUID itemID) | ||
522 | { | ||
523 | } | ||
524 | |||
525 | public void remote_data(uint localID, UUID itemID) | ||
526 | { | ||
527 | } | ||
528 | |||
529 | // Handled by long commands | ||
530 | public void http_response(uint localID, UUID itemID) | ||
531 | { | ||
532 | } | ||
533 | |||
534 | /// <summary> | ||
535 | /// If set to true then threads and stuff should try to make a graceful exit | ||
536 | /// </summary> | ||
537 | public bool PleaseShutdown | ||
538 | { | ||
539 | get { return _PleaseShutdown; } | ||
540 | set { _PleaseShutdown = value; } | ||
541 | } | ||
542 | private bool _PleaseShutdown = false; | ||
543 | } | ||
544 | } | ||
diff --git a/OpenSim/Region/ScriptEngine/DotNetEngine/EventQueueManager.cs b/OpenSim/Region/ScriptEngine/DotNetEngine/EventQueueManager.cs deleted file mode 100644 index 5865452..0000000 --- a/OpenSim/Region/ScriptEngine/DotNetEngine/EventQueueManager.cs +++ /dev/null | |||
@@ -1,460 +0,0 @@ | |||
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 OpenSimulator 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 | using System; | ||
29 | using System.Collections; | ||
30 | using System.Collections.Generic; | ||
31 | using System.Reflection; | ||
32 | using OpenMetaverse; | ||
33 | using OpenSim.Region.ScriptEngine.Shared; | ||
34 | using log4net; | ||
35 | |||
36 | namespace OpenSim.Region.ScriptEngine.DotNetEngine | ||
37 | { | ||
38 | /// <summary> | ||
39 | /// EventQueueManager handles event queues | ||
40 | /// Events are queued and executed in separate thread | ||
41 | /// </summary> | ||
42 | [Serializable] | ||
43 | public class EventQueueManager | ||
44 | { | ||
45 | // | ||
46 | // Class is instanced in "ScriptEngine" and used by "EventManager" which is also instanced in "ScriptEngine". | ||
47 | // | ||
48 | // Class purpose is to queue and execute functions that are received by "EventManager": | ||
49 | // - allowing "EventManager" to release its event thread immediately, thus not interrupting server execution. | ||
50 | // - allowing us to prioritize and control execution of script functions. | ||
51 | // Class can use multiple threads for simultaneous execution. Mutexes are used for thread safety. | ||
52 | // | ||
53 | // 1. Hold an execution queue for scripts | ||
54 | // 2. Use threads to process queue, each thread executes one script function on each pass. | ||
55 | // 3. Catch any script error and process it | ||
56 | // | ||
57 | // | ||
58 | // Notes: | ||
59 | // * Current execution load balancing is optimized for 1 thread, and can cause unfair execute balancing between scripts. | ||
60 | // Not noticeable unless server is under high load. | ||
61 | // | ||
62 | |||
63 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
64 | |||
65 | public ScriptEngine m_ScriptEngine; | ||
66 | |||
67 | /// <summary> | ||
68 | /// List of threads (classes) processing event queue | ||
69 | /// Note that this may or may not be a reference to a static object depending on PrivateRegionThreads config setting. | ||
70 | /// </summary> | ||
71 | internal static List<EventQueueThreadClass> eventQueueThreads = new List<EventQueueThreadClass>(); // Thread pool that we work on | ||
72 | /// <summary> | ||
73 | /// Locking access to eventQueueThreads AND staticGlobalEventQueueThreads. | ||
74 | /// </summary> | ||
75 | // private object eventQueueThreadsLock = new object(); | ||
76 | // Static objects for referencing the objects above if we don't have private threads: | ||
77 | //internal static List<EventQueueThreadClass> staticEventQueueThreads; // A static reference used if we don't use private threads | ||
78 | // internal static object staticEventQueueThreadsLock; // Statick lock object reference for same reason | ||
79 | |||
80 | /// <summary> | ||
81 | /// Global static list of all threads (classes) processing event queue -- used by max enforcment thread | ||
82 | /// </summary> | ||
83 | //private List<EventQueueThreadClass> staticGlobalEventQueueThreads = new List<EventQueueThreadClass>(); | ||
84 | |||
85 | /// <summary> | ||
86 | /// Used internally to specify how many threads should exit gracefully | ||
87 | /// </summary> | ||
88 | public static int ThreadsToExit; | ||
89 | public static object ThreadsToExitLock = new object(); | ||
90 | |||
91 | |||
92 | //public object queueLock = new object(); // Mutex lock object | ||
93 | |||
94 | /// <summary> | ||
95 | /// How many threads to process queue with | ||
96 | /// </summary> | ||
97 | internal static int numberOfThreads; | ||
98 | |||
99 | internal static int EventExecutionMaxQueueSize; | ||
100 | |||
101 | /// <summary> | ||
102 | /// Maximum time one function can use for execution before we perform a thread kill. | ||
103 | /// </summary> | ||
104 | private static int maxFunctionExecutionTimems | ||
105 | { | ||
106 | get { return (int)(maxFunctionExecutionTimens / 10000); } | ||
107 | set { maxFunctionExecutionTimens = value * 10000; } | ||
108 | } | ||
109 | |||
110 | /// <summary> | ||
111 | /// Contains nanoseconds version of maxFunctionExecutionTimems so that it matches time calculations better (performance reasons). | ||
112 | /// WARNING! ONLY UPDATE maxFunctionExecutionTimems, NEVER THIS DIRECTLY. | ||
113 | /// </summary> | ||
114 | public static long maxFunctionExecutionTimens; | ||
115 | |||
116 | /// <summary> | ||
117 | /// Enforce max execution time | ||
118 | /// </summary> | ||
119 | public static bool EnforceMaxExecutionTime; | ||
120 | |||
121 | /// <summary> | ||
122 | /// Kill script (unload) when it exceeds execution time | ||
123 | /// </summary> | ||
124 | private static bool KillScriptOnMaxFunctionExecutionTime; | ||
125 | |||
126 | /// <summary> | ||
127 | /// List of localID locks for mutex processing of script events | ||
128 | /// </summary> | ||
129 | private List<uint> objectLocks = new List<uint>(); | ||
130 | private object tryLockLock = new object(); // Mutex lock object | ||
131 | |||
132 | /// <summary> | ||
133 | /// Queue containing events waiting to be executed | ||
134 | /// </summary> | ||
135 | public Queue<QueueItemStruct> eventQueue = new Queue<QueueItemStruct>(); | ||
136 | |||
137 | #region " Queue structures " | ||
138 | /// <summary> | ||
139 | /// Queue item structure | ||
140 | /// </summary> | ||
141 | public struct QueueItemStruct | ||
142 | { | ||
143 | public uint localID; | ||
144 | public UUID itemID; | ||
145 | public string functionName; | ||
146 | public DetectParams[] llDetectParams; | ||
147 | public object[] param; | ||
148 | public Dictionary<KeyValuePair<int,int>,KeyValuePair<int,int>> | ||
149 | LineMap; | ||
150 | } | ||
151 | |||
152 | #endregion | ||
153 | |||
154 | #region " Initialization / Startup " | ||
155 | public EventQueueManager(ScriptEngine _ScriptEngine) | ||
156 | { | ||
157 | m_ScriptEngine = _ScriptEngine; | ||
158 | |||
159 | ReadConfig(); | ||
160 | AdjustNumberOfScriptThreads(); | ||
161 | } | ||
162 | |||
163 | public void ReadConfig() | ||
164 | { | ||
165 | // Refresh config | ||
166 | numberOfThreads = m_ScriptEngine.ScriptConfigSource.GetInt("NumberOfScriptThreads", 2); | ||
167 | maxFunctionExecutionTimems = m_ScriptEngine.ScriptConfigSource.GetInt("MaxEventExecutionTimeMs", 5000); | ||
168 | EnforceMaxExecutionTime = m_ScriptEngine.ScriptConfigSource.GetBoolean("EnforceMaxEventExecutionTime", true); | ||
169 | KillScriptOnMaxFunctionExecutionTime = m_ScriptEngine.ScriptConfigSource.GetBoolean("DeactivateScriptOnTimeout", false); | ||
170 | EventExecutionMaxQueueSize = m_ScriptEngine.ScriptConfigSource.GetInt("EventExecutionMaxQueueSize", 300); | ||
171 | |||
172 | // Now refresh config in all threads | ||
173 | lock (eventQueueThreads) | ||
174 | { | ||
175 | foreach (EventQueueThreadClass EventQueueThread in eventQueueThreads) | ||
176 | { | ||
177 | EventQueueThread.ReadConfig(); | ||
178 | } | ||
179 | } | ||
180 | } | ||
181 | |||
182 | #endregion | ||
183 | |||
184 | #region " Shutdown all threads " | ||
185 | ~EventQueueManager() | ||
186 | { | ||
187 | Stop(); | ||
188 | } | ||
189 | |||
190 | private void Stop() | ||
191 | { | ||
192 | if (eventQueueThreads != null) | ||
193 | { | ||
194 | // Kill worker threads | ||
195 | lock (eventQueueThreads) | ||
196 | { | ||
197 | foreach (EventQueueThreadClass EventQueueThread in new ArrayList(eventQueueThreads)) | ||
198 | { | ||
199 | AbortThreadClass(EventQueueThread); | ||
200 | } | ||
201 | //eventQueueThreads.Clear(); | ||
202 | //staticGlobalEventQueueThreads.Clear(); | ||
203 | } | ||
204 | } | ||
205 | |||
206 | // Remove all entries from our event queue | ||
207 | lock (eventQueue) | ||
208 | { | ||
209 | eventQueue.Clear(); | ||
210 | } | ||
211 | } | ||
212 | |||
213 | #endregion | ||
214 | |||
215 | #region " Start / stop script execution threads (ThreadClasses) " | ||
216 | private void StartNewThreadClass() | ||
217 | { | ||
218 | EventQueueThreadClass eqtc = new EventQueueThreadClass(); | ||
219 | eventQueueThreads.Add(eqtc); | ||
220 | //m_log.Debug("[" + m_ScriptEngine.ScriptEngineName + "]: Started new script execution thread. Current thread count: " + eventQueueThreads.Count); | ||
221 | } | ||
222 | |||
223 | private void AbortThreadClass(EventQueueThreadClass threadClass) | ||
224 | { | ||
225 | if (eventQueueThreads.Contains(threadClass)) | ||
226 | eventQueueThreads.Remove(threadClass); | ||
227 | |||
228 | try | ||
229 | { | ||
230 | threadClass.Stop(); | ||
231 | } | ||
232 | catch (Exception) | ||
233 | { | ||
234 | //m_log.Error("[" + m_ScriptEngine.ScriptEngineName + ":EventQueueManager]: If you see this, could you please report it to Tedd:"); | ||
235 | //m_log.Error("[" + m_ScriptEngine.ScriptEngineName + ":EventQueueManager]: Script thread execution timeout kill ended in exception: " + ex.ToString()); | ||
236 | } | ||
237 | //m_log.Debug("[" + m_ScriptEngine.ScriptEngineName + "]: Killed script execution thread. Remaining thread count: " + eventQueueThreads.Count); | ||
238 | } | ||
239 | #endregion | ||
240 | |||
241 | #region " Mutex locks for queue access " | ||
242 | /// <summary> | ||
243 | /// Try to get a mutex lock on localID | ||
244 | /// </summary> | ||
245 | /// <param name="localID"></param> | ||
246 | /// <returns></returns> | ||
247 | public bool TryLock(uint localID) | ||
248 | { | ||
249 | lock (tryLockLock) | ||
250 | { | ||
251 | if (objectLocks.Contains(localID) == true) | ||
252 | { | ||
253 | return false; | ||
254 | } | ||
255 | else | ||
256 | { | ||
257 | objectLocks.Add(localID); | ||
258 | return true; | ||
259 | } | ||
260 | } | ||
261 | } | ||
262 | |||
263 | /// <summary> | ||
264 | /// Release mutex lock on localID | ||
265 | /// </summary> | ||
266 | /// <param name="localID"></param> | ||
267 | public void ReleaseLock(uint localID) | ||
268 | { | ||
269 | lock (tryLockLock) | ||
270 | { | ||
271 | if (objectLocks.Contains(localID) == true) | ||
272 | { | ||
273 | objectLocks.Remove(localID); | ||
274 | } | ||
275 | } | ||
276 | } | ||
277 | #endregion | ||
278 | |||
279 | #region " Check execution queue for a specified Event" | ||
280 | /// <summary> | ||
281 | /// checks to see if a specified event type is already in the queue | ||
282 | /// </summary> | ||
283 | /// <param name="localID">Region object ID</param> | ||
284 | /// <param name="FunctionName">Name of the function, will be state + "_event_" + FunctionName</param> | ||
285 | /// <returns>true if event is found , false if not found</returns> | ||
286 | /// | ||
287 | public bool CheckEeventQueueForEvent(uint localID, string FunctionName) | ||
288 | { | ||
289 | if (eventQueue.Count > 0) | ||
290 | { | ||
291 | lock (eventQueue) | ||
292 | { | ||
293 | foreach (EventQueueManager.QueueItemStruct QIS in eventQueue) | ||
294 | { | ||
295 | if ((QIS.functionName == FunctionName) && (QIS.localID == localID)) | ||
296 | return true; | ||
297 | } | ||
298 | } | ||
299 | } | ||
300 | return false; | ||
301 | } | ||
302 | #endregion | ||
303 | |||
304 | #region " Add events to execution queue " | ||
305 | /// <summary> | ||
306 | /// Add event to event execution queue | ||
307 | /// </summary> | ||
308 | /// <param name="localID">Region object ID</param> | ||
309 | /// <param name="FunctionName">Name of the function, will be state + "_event_" + FunctionName</param> | ||
310 | /// <param name="param">Array of parameters to match event mask</param> | ||
311 | public bool AddToObjectQueue(uint localID, string FunctionName, DetectParams[] qParams, params object[] param) | ||
312 | { | ||
313 | // Determine all scripts in Object and add to their queue | ||
314 | //myScriptEngine.log.Info("[" + ScriptEngineName + "]: EventQueueManager Adding localID: " + localID + ", FunctionName: " + FunctionName); | ||
315 | |||
316 | // Do we have any scripts in this object at all? If not, return | ||
317 | if (m_ScriptEngine.m_ScriptManager.Scripts.ContainsKey(localID) == false) | ||
318 | { | ||
319 | //m_log.Debug("Event \String.Empty + FunctionName + "\" for localID: " + localID + ". No scripts found on this localID."); | ||
320 | return false; | ||
321 | } | ||
322 | |||
323 | List<UUID> scriptKeys = | ||
324 | m_ScriptEngine.m_ScriptManager.GetScriptKeys(localID); | ||
325 | |||
326 | foreach (UUID itemID in scriptKeys) | ||
327 | { | ||
328 | // Add to each script in that object | ||
329 | // TODO: Some scripts may not subscribe to this event. Should we NOT add it? Does it matter? | ||
330 | AddToScriptQueue(localID, itemID, FunctionName, qParams, param); | ||
331 | } | ||
332 | return true; | ||
333 | } | ||
334 | |||
335 | /// <summary> | ||
336 | /// Add event to event execution queue | ||
337 | /// </summary> | ||
338 | /// <param name="localID">Region object ID</param> | ||
339 | /// <param name="itemID">Region script ID</param> | ||
340 | /// <param name="FunctionName">Name of the function, will be state + "_event_" + FunctionName</param> | ||
341 | /// <param name="param">Array of parameters to match event mask</param> | ||
342 | public bool AddToScriptQueue(uint localID, UUID itemID, string FunctionName, DetectParams[] qParams, params object[] param) | ||
343 | { | ||
344 | List<UUID> keylist = m_ScriptEngine.m_ScriptManager.GetScriptKeys(localID); | ||
345 | |||
346 | if (!keylist.Contains(itemID)) // We don't manage that script | ||
347 | { | ||
348 | return false; | ||
349 | } | ||
350 | |||
351 | lock (eventQueue) | ||
352 | { | ||
353 | if (eventQueue.Count >= EventExecutionMaxQueueSize) | ||
354 | { | ||
355 | m_log.Error("[" + m_ScriptEngine.ScriptEngineName + "]: ERROR: Event execution queue item count is at " + eventQueue.Count + ". Config variable \"EventExecutionMaxQueueSize\" is set to " + EventExecutionMaxQueueSize + ", so ignoring new event."); | ||
356 | m_log.Error("[" + m_ScriptEngine.ScriptEngineName + "]: Event ignored: localID: " + localID + ", itemID: " + itemID + ", FunctionName: " + FunctionName); | ||
357 | return false; | ||
358 | } | ||
359 | |||
360 | InstanceData id = m_ScriptEngine.m_ScriptManager.GetScript( | ||
361 | localID, itemID); | ||
362 | |||
363 | // Create a structure and add data | ||
364 | QueueItemStruct QIS = new QueueItemStruct(); | ||
365 | QIS.localID = localID; | ||
366 | QIS.itemID = itemID; | ||
367 | QIS.functionName = FunctionName; | ||
368 | QIS.llDetectParams = qParams; | ||
369 | QIS.param = param; | ||
370 | if (id != null) | ||
371 | QIS.LineMap = id.LineMap; | ||
372 | |||
373 | // Add it to queue | ||
374 | eventQueue.Enqueue(QIS); | ||
375 | } | ||
376 | return true; | ||
377 | } | ||
378 | #endregion | ||
379 | |||
380 | #region " Maintenance thread " | ||
381 | |||
382 | /// <summary> | ||
383 | /// Adjust number of script thread classes. It can start new, but if it needs to stop it will just set number of threads in "ThreadsToExit" and threads will have to exit themselves. | ||
384 | /// Called from MaintenanceThread | ||
385 | /// </summary> | ||
386 | public void AdjustNumberOfScriptThreads() | ||
387 | { | ||
388 | // Is there anything here for us to do? | ||
389 | if (eventQueueThreads.Count == numberOfThreads) | ||
390 | return; | ||
391 | |||
392 | lock (eventQueueThreads) | ||
393 | { | ||
394 | int diff = numberOfThreads - eventQueueThreads.Count; | ||
395 | // Positive number: Start | ||
396 | // Negative number: too many are running | ||
397 | if (diff > 0) | ||
398 | { | ||
399 | // We need to add more threads | ||
400 | for (int ThreadCount = eventQueueThreads.Count; ThreadCount < numberOfThreads; ThreadCount++) | ||
401 | { | ||
402 | StartNewThreadClass(); | ||
403 | } | ||
404 | } | ||
405 | if (diff < 0) | ||
406 | { | ||
407 | // We need to kill some threads | ||
408 | lock (ThreadsToExitLock) | ||
409 | { | ||
410 | ThreadsToExit = Math.Abs(diff); | ||
411 | } | ||
412 | } | ||
413 | } | ||
414 | } | ||
415 | |||
416 | /// <summary> | ||
417 | /// Check if any thread class has been executing an event too long | ||
418 | /// </summary> | ||
419 | public void CheckScriptMaxExecTime() | ||
420 | { | ||
421 | // Iterate through all ScriptThreadClasses and check how long their current function has been executing | ||
422 | lock (eventQueueThreads) | ||
423 | { | ||
424 | foreach (EventQueueThreadClass EventQueueThread in eventQueueThreads) | ||
425 | { | ||
426 | // Is thread currently executing anything? | ||
427 | if (EventQueueThread.InExecution) | ||
428 | { | ||
429 | // Has execution time expired? | ||
430 | if (DateTime.Now.Ticks - EventQueueThread.LastExecutionStarted > | ||
431 | maxFunctionExecutionTimens) | ||
432 | { | ||
433 | // Yes! We need to kill this thread! | ||
434 | |||
435 | // Set flag if script should be removed or not | ||
436 | EventQueueThread.KillCurrentScript = KillScriptOnMaxFunctionExecutionTime; | ||
437 | |||
438 | // Abort this thread | ||
439 | AbortThreadClass(EventQueueThread); | ||
440 | |||
441 | // We do not need to start another, MaintenenceThread will do that for us | ||
442 | //StartNewThreadClass(); | ||
443 | } | ||
444 | } | ||
445 | } | ||
446 | } | ||
447 | } | ||
448 | #endregion | ||
449 | |||
450 | ///// <summary> | ||
451 | ///// If set to true then threads and stuff should try to make a graceful exit | ||
452 | ///// </summary> | ||
453 | //public bool PleaseShutdown | ||
454 | //{ | ||
455 | // get { return _PleaseShutdown; } | ||
456 | // set { _PleaseShutdown = value; } | ||
457 | //} | ||
458 | //private bool _PleaseShutdown = false; | ||
459 | } | ||
460 | } | ||
diff --git a/OpenSim/Region/ScriptEngine/DotNetEngine/EventQueueThreadClass.cs b/OpenSim/Region/ScriptEngine/DotNetEngine/EventQueueThreadClass.cs deleted file mode 100644 index 51fd41a..0000000 --- a/OpenSim/Region/ScriptEngine/DotNetEngine/EventQueueThreadClass.cs +++ /dev/null | |||
@@ -1,428 +0,0 @@ | |||
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 OpenSimulator 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 | using System; | ||
29 | using System.Collections; | ||
30 | using System.Collections.Generic; | ||
31 | using System.Reflection; | ||
32 | using System.Text.RegularExpressions; | ||
33 | using System.Threading; | ||
34 | using System.Globalization; | ||
35 | using OpenMetaverse; | ||
36 | using log4net; | ||
37 | using OpenSim.Framework; | ||
38 | using OpenSim.Region.Framework.Scenes; | ||
39 | using OpenSim.Region.Framework.Scenes.Scripting; | ||
40 | using OpenSim.Region.ScriptEngine.Shared; | ||
41 | using OpenSim.Region.ScriptEngine.Shared.CodeTools; | ||
42 | |||
43 | namespace OpenSim.Region.ScriptEngine.DotNetEngine | ||
44 | { | ||
45 | // Because every thread needs some data set for it | ||
46 | // (time started to execute current function), it will do its work | ||
47 | // within a class | ||
48 | public class EventQueueThreadClass | ||
49 | { | ||
50 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
51 | |||
52 | // How many ms to sleep if queue is empty | ||
53 | private static int nothingToDoSleepms;// = 50; | ||
54 | private static ThreadPriority MyThreadPriority; | ||
55 | |||
56 | public long LastExecutionStarted; | ||
57 | public bool InExecution = false; | ||
58 | public bool KillCurrentScript = false; | ||
59 | |||
60 | //private EventQueueManager eventQueueManager; | ||
61 | public Thread EventQueueThread; | ||
62 | private static int ThreadCount = 0; | ||
63 | |||
64 | private string ScriptEngineName = "ScriptEngine.Common"; | ||
65 | |||
66 | public EventQueueThreadClass()//EventQueueManager eqm | ||
67 | { | ||
68 | CultureInfo USCulture = new CultureInfo("en-US"); | ||
69 | Thread.CurrentThread.CurrentCulture = USCulture; | ||
70 | |||
71 | //eventQueueManager = eqm; | ||
72 | ReadConfig(); | ||
73 | Start(); | ||
74 | } | ||
75 | |||
76 | ~EventQueueThreadClass() | ||
77 | { | ||
78 | Stop(); | ||
79 | } | ||
80 | |||
81 | public void ReadConfig() | ||
82 | { | ||
83 | lock (ScriptEngine.ScriptEngines) | ||
84 | { | ||
85 | foreach (ScriptEngine m_ScriptEngine in | ||
86 | ScriptEngine.ScriptEngines) | ||
87 | { | ||
88 | ScriptEngineName = m_ScriptEngine.ScriptEngineName; | ||
89 | nothingToDoSleepms = | ||
90 | m_ScriptEngine.ScriptConfigSource.GetInt( | ||
91 | "SleepTimeIfNoScriptExecutionMs", 50); | ||
92 | |||
93 | string pri = m_ScriptEngine.ScriptConfigSource.GetString( | ||
94 | "ScriptThreadPriority", "BelowNormal"); | ||
95 | |||
96 | switch (pri.ToLower()) | ||
97 | { | ||
98 | case "lowest": | ||
99 | MyThreadPriority = ThreadPriority.Lowest; | ||
100 | break; | ||
101 | case "belownormal": | ||
102 | MyThreadPriority = ThreadPriority.BelowNormal; | ||
103 | break; | ||
104 | case "normal": | ||
105 | MyThreadPriority = ThreadPriority.Normal; | ||
106 | break; | ||
107 | case "abovenormal": | ||
108 | MyThreadPriority = ThreadPriority.AboveNormal; | ||
109 | break; | ||
110 | case "highest": | ||
111 | MyThreadPriority = ThreadPriority.Highest; | ||
112 | break; | ||
113 | default: | ||
114 | MyThreadPriority = ThreadPriority.BelowNormal; | ||
115 | m_log.Error( | ||
116 | "[ScriptEngine.DotNetEngine]: Unknown "+ | ||
117 | "priority type \"" + pri + | ||
118 | "\" in config file. Defaulting to "+ | ||
119 | "\"BelowNormal\"."); | ||
120 | break; | ||
121 | } | ||
122 | } | ||
123 | } | ||
124 | // Now set that priority | ||
125 | if (EventQueueThread != null) | ||
126 | if (EventQueueThread.IsAlive) | ||
127 | EventQueueThread.Priority = MyThreadPriority; | ||
128 | } | ||
129 | |||
130 | /// <summary> | ||
131 | /// Start thread | ||
132 | /// </summary> | ||
133 | private void Start() | ||
134 | { | ||
135 | EventQueueThread = Watchdog.StartThread(EventQueueThreadLoop, "EventQueueManagerThread_" + ThreadCount, MyThreadPriority, true); | ||
136 | |||
137 | // Look at this... Don't you wish everyone did that solid | ||
138 | // coding everywhere? :P | ||
139 | |||
140 | if (ThreadCount == int.MaxValue) | ||
141 | ThreadCount = 0; | ||
142 | |||
143 | ThreadCount++; | ||
144 | } | ||
145 | |||
146 | public void Stop() | ||
147 | { | ||
148 | if (EventQueueThread != null && EventQueueThread.IsAlive == true) | ||
149 | { | ||
150 | try | ||
151 | { | ||
152 | EventQueueThread.Abort(); // Send abort | ||
153 | } | ||
154 | catch (Exception) | ||
155 | { | ||
156 | } | ||
157 | } | ||
158 | } | ||
159 | |||
160 | private EventQueueManager.QueueItemStruct BlankQIS = | ||
161 | new EventQueueManager.QueueItemStruct(); | ||
162 | |||
163 | private ScriptEngine lastScriptEngine; | ||
164 | private uint lastLocalID; | ||
165 | private UUID lastItemID; | ||
166 | |||
167 | // Queue processing thread loop | ||
168 | private void EventQueueThreadLoop() | ||
169 | { | ||
170 | CultureInfo USCulture = new CultureInfo("en-US"); | ||
171 | Thread.CurrentThread.CurrentCulture = USCulture; | ||
172 | |||
173 | try | ||
174 | { | ||
175 | while (true) | ||
176 | { | ||
177 | try | ||
178 | { | ||
179 | while (true) | ||
180 | { | ||
181 | DoProcessQueue(); | ||
182 | Watchdog.UpdateThread(); | ||
183 | } | ||
184 | } | ||
185 | catch (ThreadAbortException) | ||
186 | { | ||
187 | m_log.Info("[" + ScriptEngineName + | ||
188 | "]: ThreadAbortException while executing "+ | ||
189 | "function."); | ||
190 | } | ||
191 | catch (SelfDeleteException) // Must delete SOG | ||
192 | { | ||
193 | SceneObjectPart part = | ||
194 | lastScriptEngine.World.GetSceneObjectPart( | ||
195 | lastLocalID); | ||
196 | if (part != null && part.ParentGroup != null) | ||
197 | lastScriptEngine.World.DeleteSceneObject( | ||
198 | part.ParentGroup, false); | ||
199 | } | ||
200 | catch (ScriptDeleteException) // Must delete item | ||
201 | { | ||
202 | SceneObjectPart part = | ||
203 | lastScriptEngine.World.GetSceneObjectPart( | ||
204 | lastLocalID); | ||
205 | if (part != null && part.ParentGroup != null) | ||
206 | part.Inventory.RemoveInventoryItem(lastItemID); | ||
207 | } | ||
208 | catch (Exception e) | ||
209 | { | ||
210 | m_log.ErrorFormat("[{0}]: Exception {1} thrown", ScriptEngineName, e.GetType().ToString()); | ||
211 | throw e; | ||
212 | } | ||
213 | |||
214 | Watchdog.UpdateThread(); | ||
215 | } | ||
216 | } | ||
217 | catch (ThreadAbortException) | ||
218 | { | ||
219 | } | ||
220 | catch (Exception e) | ||
221 | { | ||
222 | // TODO: Let users in the sim and those entering it and possibly an external watchdog know what has happened | ||
223 | m_log.ErrorFormat( | ||
224 | "[{0}]: Event queue thread terminating with exception. PLEASE REBOOT YOUR SIM - SCRIPT EVENTS WILL NOT WORK UNTIL YOU DO. Exception is {1}", | ||
225 | ScriptEngineName, e); | ||
226 | } | ||
227 | |||
228 | Watchdog.RemoveThread(); | ||
229 | } | ||
230 | |||
231 | public void DoProcessQueue() | ||
232 | { | ||
233 | foreach (ScriptEngine m_ScriptEngine in | ||
234 | new ArrayList(ScriptEngine.ScriptEngines)) | ||
235 | { | ||
236 | lastScriptEngine = m_ScriptEngine; | ||
237 | |||
238 | EventQueueManager.QueueItemStruct QIS = BlankQIS; | ||
239 | bool GotItem = false; | ||
240 | |||
241 | //if (PleaseShutdown) | ||
242 | // return; | ||
243 | |||
244 | if (m_ScriptEngine.m_EventQueueManager == null || | ||
245 | m_ScriptEngine.m_EventQueueManager.eventQueue == null) | ||
246 | continue; | ||
247 | |||
248 | if (m_ScriptEngine.m_EventQueueManager.eventQueue.Count == 0) | ||
249 | { | ||
250 | // Nothing to do? Sleep a bit waiting for something to do | ||
251 | Thread.Sleep(nothingToDoSleepms); | ||
252 | } | ||
253 | else | ||
254 | { | ||
255 | // Something in queue, process | ||
256 | |||
257 | // OBJECT BASED LOCK - TWO THREADS WORKING ON SAME | ||
258 | // OBJECT IS NOT GOOD | ||
259 | lock (m_ScriptEngine.m_EventQueueManager.eventQueue) | ||
260 | { | ||
261 | GotItem = false; | ||
262 | for (int qc = 0; qc < m_ScriptEngine.m_EventQueueManager.eventQueue.Count; qc++) | ||
263 | { | ||
264 | // Get queue item | ||
265 | QIS = m_ScriptEngine.m_EventQueueManager.eventQueue.Dequeue(); | ||
266 | |||
267 | // Check if object is being processed by | ||
268 | // someone else | ||
269 | if (m_ScriptEngine.m_EventQueueManager.TryLock( | ||
270 | QIS.localID) == false) | ||
271 | { | ||
272 | // Object is already being processed, requeue it | ||
273 | m_ScriptEngine.m_EventQueueManager. | ||
274 | eventQueue.Enqueue(QIS); | ||
275 | } | ||
276 | else | ||
277 | { | ||
278 | // We have lock on an object and can process it | ||
279 | GotItem = true; | ||
280 | break; | ||
281 | } | ||
282 | } | ||
283 | } | ||
284 | |||
285 | if (GotItem == true) | ||
286 | { | ||
287 | // Execute function | ||
288 | try | ||
289 | { | ||
290 | // Only pipe event if land supports it. | ||
291 | if (m_ScriptEngine.World.PipeEventsForScript( | ||
292 | QIS.localID)) | ||
293 | { | ||
294 | lastLocalID = QIS.localID; | ||
295 | lastItemID = QIS.itemID; | ||
296 | LastExecutionStarted = DateTime.Now.Ticks; | ||
297 | KillCurrentScript = false; | ||
298 | InExecution = true; | ||
299 | m_ScriptEngine.m_ScriptManager.ExecuteEvent( | ||
300 | QIS.localID, | ||
301 | QIS.itemID, | ||
302 | QIS.functionName, | ||
303 | QIS.llDetectParams, | ||
304 | QIS.param); | ||
305 | |||
306 | InExecution = false; | ||
307 | } | ||
308 | } | ||
309 | catch (TargetInvocationException tie) | ||
310 | { | ||
311 | Exception e = tie.InnerException; | ||
312 | |||
313 | if (e is SelfDeleteException) // Forward it | ||
314 | throw e; | ||
315 | |||
316 | InExecution = false; | ||
317 | string text = FormatException(tie, QIS.LineMap); | ||
318 | |||
319 | // DISPLAY ERROR INWORLD | ||
320 | |||
321 | // if (e.InnerException != null) | ||
322 | // { | ||
323 | // // Send inner exception | ||
324 | // string line = " (unknown line)"; | ||
325 | // Regex rx = new Regex(@"SecondLife\.Script\..+[\s:](?<line>\d+)\.?\r?$", RegexOptions.Compiled); | ||
326 | // if (rx.Match(e.InnerException.ToString()).Success) | ||
327 | // line = " (line " + rx.Match(e.InnerException.ToString()).Result("${line}") + ")"; | ||
328 | // text += e.InnerException.Message.ToString() + line; | ||
329 | // } | ||
330 | // else | ||
331 | // { | ||
332 | // text += "\r\n"; | ||
333 | // // Send normal | ||
334 | // text += e.Message.ToString(); | ||
335 | // } | ||
336 | // if (KillCurrentScript) | ||
337 | // text += "\r\nScript will be deactivated!"; | ||
338 | |||
339 | try | ||
340 | { | ||
341 | if (text.Length >= 1100) | ||
342 | text = text.Substring(0, 1099); | ||
343 | IScriptHost m_host = | ||
344 | m_ScriptEngine.World.GetSceneObjectPart(QIS.localID); | ||
345 | m_ScriptEngine.World.SimChat( | ||
346 | Utils.StringToBytes(text), | ||
347 | ChatTypeEnum.DebugChannel, 2147483647, | ||
348 | m_host.AbsolutePosition, | ||
349 | m_host.Name, m_host.UUID, false); | ||
350 | } | ||
351 | catch (Exception) | ||
352 | { | ||
353 | m_log.Error("[" + | ||
354 | ScriptEngineName + "]: " + | ||
355 | "Unable to send text in-world:\r\n" + | ||
356 | text); | ||
357 | } | ||
358 | finally | ||
359 | { | ||
360 | // So we are done sending message in-world | ||
361 | if (KillCurrentScript) | ||
362 | { | ||
363 | m_ScriptEngine.m_EventQueueManager. | ||
364 | m_ScriptEngine.m_ScriptManager. | ||
365 | StopScript( | ||
366 | QIS.localID, QIS.itemID); | ||
367 | } | ||
368 | } | ||
369 | } | ||
370 | catch (Exception) | ||
371 | { | ||
372 | throw; | ||
373 | } | ||
374 | finally | ||
375 | { | ||
376 | InExecution = false; | ||
377 | m_ScriptEngine.m_EventQueueManager.ReleaseLock( | ||
378 | QIS.localID); | ||
379 | } | ||
380 | } | ||
381 | } | ||
382 | } | ||
383 | } | ||
384 | |||
385 | string FormatException(Exception e, Dictionary<KeyValuePair<int,int>, | ||
386 | KeyValuePair<int,int>> LineMap) | ||
387 | { | ||
388 | if (e.InnerException == null) | ||
389 | return e.ToString(); | ||
390 | |||
391 | string message = "Runtime error:\n" + e.InnerException.StackTrace; | ||
392 | string[] lines = message.Split(new char[] {'\n'}); | ||
393 | |||
394 | foreach (string line in lines) | ||
395 | { | ||
396 | if (line.Contains("SecondLife.Script")) | ||
397 | { | ||
398 | int idx = line.IndexOf(':'); | ||
399 | if (idx != -1) | ||
400 | { | ||
401 | string val = line.Substring(idx+1); | ||
402 | int lineNum = 0; | ||
403 | if (int.TryParse(val, out lineNum)) | ||
404 | { | ||
405 | KeyValuePair<int, int> pos = | ||
406 | Compiler.FindErrorPosition( | ||
407 | lineNum, 0, LineMap); | ||
408 | |||
409 | int scriptLine = pos.Key; | ||
410 | int col = pos.Value; | ||
411 | if (scriptLine == 0) | ||
412 | scriptLine++; | ||
413 | if (col == 0) | ||
414 | col++; | ||
415 | message = string.Format("Runtime error:\n" + | ||
416 | "Line ({0}): {1}", scriptLine - 1, | ||
417 | e.InnerException.Message); | ||
418 | |||
419 | return message; | ||
420 | } | ||
421 | } | ||
422 | } | ||
423 | } | ||
424 | |||
425 | return message; | ||
426 | } | ||
427 | } | ||
428 | } | ||
diff --git a/OpenSim/Region/ScriptEngine/DotNetEngine/MaintenanceThread.cs b/OpenSim/Region/ScriptEngine/DotNetEngine/MaintenanceThread.cs deleted file mode 100644 index 87fdf1f..0000000 --- a/OpenSim/Region/ScriptEngine/DotNetEngine/MaintenanceThread.cs +++ /dev/null | |||
@@ -1,238 +0,0 @@ | |||
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 OpenSimulator 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 | using System; | ||
29 | using System.Collections; | ||
30 | using System.Reflection; | ||
31 | using System.Threading; | ||
32 | using log4net; | ||
33 | using OpenSim.Framework; | ||
34 | |||
35 | namespace OpenSim.Region.ScriptEngine.DotNetEngine | ||
36 | { | ||
37 | /// <summary> | ||
38 | /// This class does maintenance on script engine. | ||
39 | /// </summary> | ||
40 | public class MaintenanceThread | ||
41 | { | ||
42 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
43 | |||
44 | //public ScriptEngine m_ScriptEngine; | ||
45 | private int MaintenanceLoopms; | ||
46 | private int MaintenanceLoopTicks_ScriptLoadUnload; | ||
47 | private int MaintenanceLoopTicks_Other; | ||
48 | |||
49 | |||
50 | public MaintenanceThread() | ||
51 | { | ||
52 | //m_ScriptEngine = _ScriptEngine; | ||
53 | |||
54 | ReadConfig(); | ||
55 | |||
56 | // Start maintenance thread | ||
57 | StartMaintenanceThread(); | ||
58 | } | ||
59 | |||
60 | ~MaintenanceThread() | ||
61 | { | ||
62 | StopMaintenanceThread(); | ||
63 | } | ||
64 | |||
65 | public void ReadConfig() | ||
66 | { | ||
67 | // Bad hack, but we need a m_ScriptEngine :) | ||
68 | lock (ScriptEngine.ScriptEngines) | ||
69 | { | ||
70 | foreach (ScriptEngine m_ScriptEngine in ScriptEngine.ScriptEngines) | ||
71 | { | ||
72 | MaintenanceLoopms = m_ScriptEngine.ScriptConfigSource.GetInt("MaintenanceLoopms", 50); | ||
73 | MaintenanceLoopTicks_ScriptLoadUnload = | ||
74 | m_ScriptEngine.ScriptConfigSource.GetInt("MaintenanceLoopTicks_ScriptLoadUnload", 1); | ||
75 | MaintenanceLoopTicks_Other = | ||
76 | m_ScriptEngine.ScriptConfigSource.GetInt("MaintenanceLoopTicks_Other", 10); | ||
77 | |||
78 | return; | ||
79 | } | ||
80 | } | ||
81 | } | ||
82 | |||
83 | #region " Maintenance thread " | ||
84 | /// <summary> | ||
85 | /// Maintenance thread. Enforcing max execution time for example. | ||
86 | /// </summary> | ||
87 | public Thread MaintenanceThreadThread; | ||
88 | |||
89 | /// <summary> | ||
90 | /// Starts maintenance thread | ||
91 | /// </summary> | ||
92 | private void StartMaintenanceThread() | ||
93 | { | ||
94 | if (MaintenanceThreadThread == null) | ||
95 | { | ||
96 | MaintenanceThreadThread = Watchdog.StartThread(MaintenanceLoop, "ScriptMaintenanceThread", ThreadPriority.Normal, true); | ||
97 | } | ||
98 | } | ||
99 | |||
100 | /// <summary> | ||
101 | /// Stops maintenance thread | ||
102 | /// </summary> | ||
103 | private void StopMaintenanceThread() | ||
104 | { | ||
105 | #if DEBUG | ||
106 | //m_log.Debug("[" + m_ScriptEngine.ScriptEngineName + "]: StopMaintenanceThread() called"); | ||
107 | #endif | ||
108 | //PleaseShutdown = true; | ||
109 | Thread.Sleep(100); | ||
110 | try | ||
111 | { | ||
112 | if (MaintenanceThreadThread != null && MaintenanceThreadThread.IsAlive) | ||
113 | { | ||
114 | MaintenanceThreadThread.Abort(); | ||
115 | } | ||
116 | } | ||
117 | catch (Exception) | ||
118 | { | ||
119 | //m_log.Error("[" + m_ScriptEngine.ScriptEngineName + "]: Exception stopping maintenence thread: " + ex.ToString()); | ||
120 | } | ||
121 | } | ||
122 | |||
123 | // private ScriptEngine lastScriptEngine; // Keep track of what ScriptEngine instance we are at so we can give exception | ||
124 | /// <summary> | ||
125 | /// A thread should run in this loop and check all running scripts | ||
126 | /// </summary> | ||
127 | public void MaintenanceLoop() | ||
128 | { | ||
129 | //if (m_ScriptEngine.m_EventQueueManager.maxFunctionExecutionTimens < MaintenanceLoopms) | ||
130 | // m_log.Warn("[" + m_ScriptEngine.ScriptEngineName + "]: " + | ||
131 | // "Configuration error: MaxEventExecutionTimeMs is less than MaintenanceLoopms. The Maintenance Loop will only check scripts once per run."); | ||
132 | |||
133 | long Last_maxFunctionExecutionTimens = 0; // DateTime.Now.Ticks; | ||
134 | long Last_ReReadConfigFilens = DateTime.Now.Ticks; | ||
135 | int MaintenanceLoopTicks_ScriptLoadUnload_Count = 0; | ||
136 | int MaintenanceLoopTicks_Other_Count = 0; | ||
137 | bool MaintenanceLoopTicks_ScriptLoadUnload_ResetCount = false; | ||
138 | bool MaintenanceLoopTicks_Other_ResetCount = false; | ||
139 | |||
140 | while (true) | ||
141 | { | ||
142 | try | ||
143 | { | ||
144 | while (true) | ||
145 | { | ||
146 | Thread.Sleep(MaintenanceLoopms); // Sleep before next pass | ||
147 | |||
148 | // Reset counters? | ||
149 | if (MaintenanceLoopTicks_ScriptLoadUnload_ResetCount) | ||
150 | { | ||
151 | MaintenanceLoopTicks_ScriptLoadUnload_ResetCount = false; | ||
152 | MaintenanceLoopTicks_ScriptLoadUnload_Count = 0; | ||
153 | } | ||
154 | if (MaintenanceLoopTicks_Other_ResetCount) | ||
155 | { | ||
156 | MaintenanceLoopTicks_Other_ResetCount = false; | ||
157 | MaintenanceLoopTicks_Other_Count = 0; | ||
158 | } | ||
159 | |||
160 | // Increase our counters | ||
161 | MaintenanceLoopTicks_ScriptLoadUnload_Count++; | ||
162 | MaintenanceLoopTicks_Other_Count++; | ||
163 | |||
164 | foreach (ScriptEngine m_ScriptEngine in new ArrayList(ScriptEngine.ScriptEngines)) | ||
165 | { | ||
166 | // lastScriptEngine = m_ScriptEngine; | ||
167 | // Re-reading config every x seconds | ||
168 | if (MaintenanceLoopTicks_Other_Count >= MaintenanceLoopTicks_Other) | ||
169 | { | ||
170 | MaintenanceLoopTicks_Other_ResetCount = true; | ||
171 | if (m_ScriptEngine.RefreshConfigFilens > 0) | ||
172 | { | ||
173 | // Check if its time to re-read config | ||
174 | if (DateTime.Now.Ticks - Last_ReReadConfigFilens > | ||
175 | m_ScriptEngine.RefreshConfigFilens) | ||
176 | { | ||
177 | //m_log.Debug("Time passed: " + (DateTime.Now.Ticks - Last_ReReadConfigFilens) + ">" + m_ScriptEngine.RefreshConfigFilens); | ||
178 | // Its time to re-read config file | ||
179 | m_ScriptEngine.ReadConfig(); | ||
180 | Last_ReReadConfigFilens = DateTime.Now.Ticks; // Reset time | ||
181 | } | ||
182 | |||
183 | |||
184 | // Adjust number of running script threads if not correct | ||
185 | if (m_ScriptEngine.m_EventQueueManager != null) | ||
186 | m_ScriptEngine.m_EventQueueManager.AdjustNumberOfScriptThreads(); | ||
187 | |||
188 | // Check if any script has exceeded its max execution time | ||
189 | if (EventQueueManager.EnforceMaxExecutionTime) | ||
190 | { | ||
191 | // We are enforcing execution time | ||
192 | if (DateTime.Now.Ticks - Last_maxFunctionExecutionTimens > | ||
193 | EventQueueManager.maxFunctionExecutionTimens) | ||
194 | { | ||
195 | // Its time to check again | ||
196 | m_ScriptEngine.m_EventQueueManager.CheckScriptMaxExecTime(); // Do check | ||
197 | Last_maxFunctionExecutionTimens = DateTime.Now.Ticks; // Reset time | ||
198 | } | ||
199 | } | ||
200 | } | ||
201 | } | ||
202 | if (MaintenanceLoopTicks_ScriptLoadUnload_Count >= MaintenanceLoopTicks_ScriptLoadUnload) | ||
203 | { | ||
204 | MaintenanceLoopTicks_ScriptLoadUnload_ResetCount = true; | ||
205 | // LOAD / UNLOAD SCRIPTS | ||
206 | if (m_ScriptEngine.m_ScriptManager != null) | ||
207 | m_ScriptEngine.m_ScriptManager.DoScriptLoadUnload(); | ||
208 | } | ||
209 | } | ||
210 | |||
211 | Watchdog.UpdateThread(); | ||
212 | } | ||
213 | } | ||
214 | catch(ThreadAbortException) | ||
215 | { | ||
216 | m_log.Error("Thread aborted in MaintenanceLoopThread. If this is during shutdown, please ignore"); | ||
217 | } | ||
218 | catch (Exception ex) | ||
219 | { | ||
220 | m_log.ErrorFormat("Exception in MaintenanceLoopThread. Thread will recover after 5 sec throttle. Exception: {0}", ex.ToString()); | ||
221 | } | ||
222 | } | ||
223 | |||
224 | Watchdog.RemoveThread(); | ||
225 | } | ||
226 | #endregion | ||
227 | |||
228 | ///// <summary> | ||
229 | ///// If set to true then threads and stuff should try to make a graceful exit | ||
230 | ///// </summary> | ||
231 | //public bool PleaseShutdown | ||
232 | //{ | ||
233 | // get { return _PleaseShutdown; } | ||
234 | // set { _PleaseShutdown = value; } | ||
235 | //} | ||
236 | //private bool _PleaseShutdown = false; | ||
237 | } | ||
238 | } | ||
diff --git a/OpenSim/Region/ScriptEngine/DotNetEngine/Properties/AssemblyInfo.cs b/OpenSim/Region/ScriptEngine/DotNetEngine/Properties/AssemblyInfo.cs deleted file mode 100644 index 4c4c5e7..0000000 --- a/OpenSim/Region/ScriptEngine/DotNetEngine/Properties/AssemblyInfo.cs +++ /dev/null | |||
@@ -1,65 +0,0 @@ | |||
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 OpenSimulator 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 | using System.Reflection; | ||
29 | using System.Runtime.InteropServices; | ||
30 | |||
31 | // General information about an assembly is controlled through the following | ||
32 | // set of attributes. Change these attribute values to modify the information | ||
33 | // associated with an assembly. | ||
34 | |||
35 | [assembly : AssemblyTitle("OpenSim.Region.ScriptEngine.DotNetEngine")] | ||
36 | [assembly : AssemblyDescription("")] | ||
37 | [assembly : AssemblyConfiguration("")] | ||
38 | [assembly : AssemblyCompany("http://opensimulator.org")] | ||
39 | [assembly : AssemblyProduct("OpenSim.Region.ScriptEngine.DotNetEngine")] | ||
40 | [assembly : AssemblyCopyright("Copyright (c) OpenSimulator.org Developers 2007-2009")] | ||
41 | [assembly : AssemblyTrademark("")] | ||
42 | [assembly : AssemblyCulture("")] | ||
43 | |||
44 | // Setting ComVisible to false makes the types in this assembly not visible | ||
45 | // to COM components. If you need to access a type in this assembly from | ||
46 | // COM, set the ComVisible attribute to true on that type. | ||
47 | |||
48 | [assembly : ComVisible(false)] | ||
49 | |||
50 | // The following GUID is for the ID of the typelib if this project is exposed to COM | ||
51 | |||
52 | [assembly : Guid("2842257e-6fde-4460-9368-4cde57fa9cc4")] | ||
53 | |||
54 | // Version information for an assembly consists of the following four values: | ||
55 | // | ||
56 | // Major Version | ||
57 | // Minor Version | ||
58 | // Build Number | ||
59 | // Revision | ||
60 | // | ||
61 | // You can specify all the values or you can default the Revision and Build Numbers | ||
62 | // by using the '*' as shown below: | ||
63 | |||
64 | [assembly : AssemblyVersion("0.6.5.*")] | ||
65 | [assembly : AssemblyFileVersion("0.6.5.0")] | ||
diff --git a/OpenSim/Region/ScriptEngine/DotNetEngine/Resources/DotNetEngine.addin.xml b/OpenSim/Region/ScriptEngine/DotNetEngine/Resources/DotNetEngine.addin.xml deleted file mode 100644 index 78a8dca..0000000 --- a/OpenSim/Region/ScriptEngine/DotNetEngine/Resources/DotNetEngine.addin.xml +++ /dev/null | |||
@@ -1,13 +0,0 @@ | |||
1 | <Addin id="OpenSim.Region.ScriptEngine.DotNetEngine" version="0.2"> | ||
2 | <Runtime> | ||
3 | <Import assembly="OpenSim.Region.ScriptEngine.DotNetEngine.dll"/> | ||
4 | </Runtime> | ||
5 | |||
6 | <Dependencies> | ||
7 | <Addin id="OpenSim" version="0.5" /> | ||
8 | </Dependencies> | ||
9 | |||
10 | <Extension path = "/OpenSim/RegionModules"> | ||
11 | <RegionModule id="DotNetEngine" type="OpenSim.Region.ScriptEngine.DotNetEngine.ScriptEngine" /> | ||
12 | </Extension> | ||
13 | </Addin> | ||
diff --git a/OpenSim/Region/ScriptEngine/DotNetEngine/ScriptEngine.cs b/OpenSim/Region/ScriptEngine/DotNetEngine/ScriptEngine.cs deleted file mode 100644 index 9806218..0000000 --- a/OpenSim/Region/ScriptEngine/DotNetEngine/ScriptEngine.cs +++ /dev/null | |||
@@ -1,485 +0,0 @@ | |||
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 OpenSimulator 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 | using System; | ||
29 | using System.Collections.Generic; | ||
30 | using System.Reflection; | ||
31 | using log4net; | ||
32 | using Nini.Config; | ||
33 | using OpenSim.Framework; | ||
34 | using OpenSim.Region.CoreModules.Framework.EventQueue; | ||
35 | using OpenSim.Region.Framework.Interfaces; | ||
36 | using OpenSim.Region.Framework.Scenes; | ||
37 | using OpenSim.Region.ScriptEngine.Interfaces; | ||
38 | using OpenMetaverse; | ||
39 | using OpenMetaverse.StructuredData; | ||
40 | using OpenSim.Region.ScriptEngine.Shared; | ||
41 | using OpenSim.Region.ScriptEngine.Shared.ScriptBase; | ||
42 | |||
43 | namespace OpenSim.Region.ScriptEngine.DotNetEngine | ||
44 | { | ||
45 | [Serializable] | ||
46 | public class ScriptEngine : INonSharedRegionModule, IScriptEngine, IScriptModule | ||
47 | { | ||
48 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
49 | |||
50 | public static List<ScriptEngine> ScriptEngines = | ||
51 | new List<ScriptEngine>(); | ||
52 | |||
53 | private Scene m_Scene; | ||
54 | public Scene World | ||
55 | { | ||
56 | get { return m_Scene; } | ||
57 | } | ||
58 | |||
59 | // Handles and queues incoming events from OpenSim | ||
60 | public EventManager m_EventManager; | ||
61 | |||
62 | // Executes events, handles script threads | ||
63 | public EventQueueManager m_EventQueueManager; | ||
64 | |||
65 | // Load, unload and execute scripts | ||
66 | public ScriptManager m_ScriptManager; | ||
67 | |||
68 | // Handles loading/unloading of scripts into AppDomains | ||
69 | public AppDomainManager m_AppDomainManager; | ||
70 | |||
71 | // Thread that does different kinds of maintenance, | ||
72 | // for example refreshing config and killing scripts | ||
73 | // that has been running too long | ||
74 | public static MaintenanceThread m_MaintenanceThread; | ||
75 | |||
76 | private IConfigSource m_ConfigSource; | ||
77 | public IConfig ScriptConfigSource; | ||
78 | private bool m_enabled = false; | ||
79 | |||
80 | public IConfig Config | ||
81 | { | ||
82 | get { return ScriptConfigSource; } | ||
83 | } | ||
84 | |||
85 | public IConfigSource ConfigSource | ||
86 | { | ||
87 | get { return m_ConfigSource; } | ||
88 | } | ||
89 | |||
90 | // How many seconds between re-reading config-file. | ||
91 | // 0 = never. ScriptEngine will try to adjust to new config changes. | ||
92 | public int RefreshConfigFileSeconds { | ||
93 | get { return (int)(RefreshConfigFilens / 10000000); } | ||
94 | set { RefreshConfigFilens = value * 10000000; } | ||
95 | } | ||
96 | |||
97 | public long RefreshConfigFilens; | ||
98 | |||
99 | public string ScriptEngineName | ||
100 | { | ||
101 | get { return "ScriptEngine.DotNetEngine"; } | ||
102 | } | ||
103 | |||
104 | public IScriptModule ScriptModule | ||
105 | { | ||
106 | get { return this; } | ||
107 | } | ||
108 | |||
109 | public event ScriptRemoved OnScriptRemoved; | ||
110 | public event ObjectRemoved OnObjectRemoved; | ||
111 | |||
112 | public ScriptEngine() | ||
113 | { | ||
114 | // For logging, just need any instance, doesn't matter | ||
115 | Common.mySE = this; | ||
116 | |||
117 | lock (ScriptEngines) | ||
118 | { | ||
119 | // Keep a list of ScriptEngines for shared threads | ||
120 | // to process all instances | ||
121 | ScriptEngines.Add(this); | ||
122 | } | ||
123 | } | ||
124 | |||
125 | public void Initialise(IConfigSource config) | ||
126 | { | ||
127 | m_ConfigSource = config; | ||
128 | } | ||
129 | |||
130 | public void AddRegion(Scene Sceneworld) | ||
131 | { | ||
132 | // Make sure we have config | ||
133 | if (ConfigSource.Configs[ScriptEngineName] == null) | ||
134 | ConfigSource.AddConfig(ScriptEngineName); | ||
135 | |||
136 | ScriptConfigSource = ConfigSource.Configs[ScriptEngineName]; | ||
137 | |||
138 | m_enabled = ScriptConfigSource.GetBoolean("Enabled", true); | ||
139 | if (!m_enabled) | ||
140 | return; | ||
141 | |||
142 | m_log.Info("[" + ScriptEngineName + "]: ScriptEngine initializing"); | ||
143 | |||
144 | m_Scene = Sceneworld; | ||
145 | |||
146 | // Create all objects we'll be using | ||
147 | m_EventQueueManager = new EventQueueManager(this); | ||
148 | m_EventManager = new EventManager(this, true); | ||
149 | |||
150 | // We need to start it | ||
151 | m_ScriptManager = new ScriptManager(this); | ||
152 | m_ScriptManager.Setup(); | ||
153 | m_AppDomainManager = new AppDomainManager(this); | ||
154 | if (m_MaintenanceThread == null) | ||
155 | m_MaintenanceThread = new MaintenanceThread(); | ||
156 | |||
157 | m_log.Info("[" + ScriptEngineName + "]: Reading configuration "+ | ||
158 | "from config section \"" + ScriptEngineName + "\""); | ||
159 | |||
160 | ReadConfig(); | ||
161 | |||
162 | m_Scene.StackModuleInterface<IScriptModule>(this); | ||
163 | } | ||
164 | |||
165 | public void RemoveRegion(Scene scene) | ||
166 | { | ||
167 | } | ||
168 | |||
169 | public void RegionLoaded(Scene scene) | ||
170 | { | ||
171 | if (!m_enabled) | ||
172 | return; | ||
173 | |||
174 | m_EventManager.HookUpEvents(); | ||
175 | |||
176 | m_Scene.EventManager.OnScriptReset += OnScriptReset; | ||
177 | m_Scene.EventManager.OnGetScriptRunning += OnGetScriptRunning; | ||
178 | m_Scene.EventManager.OnStartScript += OnStartScript; | ||
179 | m_Scene.EventManager.OnStopScript += OnStopScript; | ||
180 | |||
181 | m_ScriptManager.Start(); | ||
182 | } | ||
183 | |||
184 | public void Shutdown() | ||
185 | { | ||
186 | // We are shutting down | ||
187 | lock (ScriptEngines) | ||
188 | { | ||
189 | ScriptEngines.Remove(this); | ||
190 | } | ||
191 | } | ||
192 | |||
193 | public void ReadConfig() | ||
194 | { | ||
195 | RefreshConfigFileSeconds = ScriptConfigSource.GetInt("RefreshConfig", 0); | ||
196 | |||
197 | if (m_EventQueueManager != null) m_EventQueueManager.ReadConfig(); | ||
198 | if (m_EventManager != null) m_EventManager.ReadConfig(); | ||
199 | if (m_ScriptManager != null) m_ScriptManager.ReadConfig(); | ||
200 | if (m_AppDomainManager != null) m_AppDomainManager.ReadConfig(); | ||
201 | if (m_MaintenanceThread != null) m_MaintenanceThread.ReadConfig(); | ||
202 | } | ||
203 | |||
204 | #region IRegionModule | ||
205 | |||
206 | public void Close() | ||
207 | { | ||
208 | } | ||
209 | |||
210 | public Type ReplaceableInterface | ||
211 | { | ||
212 | get { return null; } | ||
213 | } | ||
214 | |||
215 | public string Name | ||
216 | { | ||
217 | get { return "Common." + ScriptEngineName; } | ||
218 | } | ||
219 | |||
220 | public bool IsSharedModule | ||
221 | { | ||
222 | get { return false; } | ||
223 | } | ||
224 | |||
225 | public bool PostObjectEvent(uint localID, EventParams p) | ||
226 | { | ||
227 | return m_EventQueueManager.AddToObjectQueue(localID, p.EventName, | ||
228 | p.DetectParams, p.Params); | ||
229 | } | ||
230 | |||
231 | public bool PostScriptEvent(UUID itemID, EventParams p) | ||
232 | { | ||
233 | uint localID = m_ScriptManager.GetLocalID(itemID); | ||
234 | return m_EventQueueManager.AddToScriptQueue(localID, itemID, | ||
235 | p.EventName, p.DetectParams, p.Params); | ||
236 | } | ||
237 | |||
238 | public bool PostScriptEvent(UUID itemID, string name, Object[] p) | ||
239 | { | ||
240 | Object[] lsl_p = new Object[p.Length]; | ||
241 | for (int i = 0; i < p.Length ; i++) | ||
242 | { | ||
243 | if (p[i] is int) | ||
244 | lsl_p[i] = new LSL_Types.LSLInteger((int)p[i]); | ||
245 | else if (p[i] is string) | ||
246 | lsl_p[i] = new LSL_Types.LSLString((string)p[i]); | ||
247 | else if (p[i] is Vector3) | ||
248 | lsl_p[i] = new LSL_Types.Vector3(((Vector3)p[i]).X, ((Vector3)p[i]).Y, ((Vector3)p[i]).Z); | ||
249 | else if (p[i] is Quaternion) | ||
250 | lsl_p[i] = new LSL_Types.Quaternion(((Quaternion)p[i]).X, ((Quaternion)p[i]).Y, ((Quaternion)p[i]).Z, ((Quaternion)p[i]).W); | ||
251 | else if (p[i] is float) | ||
252 | lsl_p[i] = new LSL_Types.LSLFloat((float)p[i]); | ||
253 | else | ||
254 | lsl_p[i] = p[i]; | ||
255 | } | ||
256 | |||
257 | return PostScriptEvent(itemID, new EventParams(name, lsl_p, new DetectParams[0])); | ||
258 | } | ||
259 | |||
260 | public bool PostObjectEvent(UUID itemID, string name, Object[] p) | ||
261 | { | ||
262 | SceneObjectPart part = m_Scene.GetSceneObjectPart(itemID); | ||
263 | if (part == null) | ||
264 | return false; | ||
265 | |||
266 | Object[] lsl_p = new Object[p.Length]; | ||
267 | for (int i = 0; i < p.Length ; i++) | ||
268 | { | ||
269 | if (p[i] is int) | ||
270 | lsl_p[i] = new LSL_Types.LSLInteger((int)p[i]); | ||
271 | else if (p[i] is string) | ||
272 | lsl_p[i] = new LSL_Types.LSLString((string)p[i]); | ||
273 | else if (p[i] is Vector3) | ||
274 | lsl_p[i] = new LSL_Types.Vector3(((Vector3)p[i]).X, ((Vector3)p[i]).Y, ((Vector3)p[i]).Z); | ||
275 | else if (p[i] is Quaternion) | ||
276 | lsl_p[i] = new LSL_Types.Quaternion(((Quaternion)p[i]).X, ((Quaternion)p[i]).Y, ((Quaternion)p[i]).Z, ((Quaternion)p[i]).W); | ||
277 | else if (p[i] is float) | ||
278 | lsl_p[i] = new LSL_Types.LSLFloat((float)p[i]); | ||
279 | else | ||
280 | lsl_p[i] = p[i]; | ||
281 | } | ||
282 | |||
283 | return PostObjectEvent(part.LocalId, new EventParams(name, lsl_p, new DetectParams[0])); | ||
284 | } | ||
285 | |||
286 | public DetectParams GetDetectParams(UUID itemID, int number) | ||
287 | { | ||
288 | uint localID = m_ScriptManager.GetLocalID(itemID); | ||
289 | if (localID == 0) | ||
290 | return null; | ||
291 | |||
292 | InstanceData id = m_ScriptManager.GetScript(localID, itemID); | ||
293 | |||
294 | if (id == null) | ||
295 | return null; | ||
296 | |||
297 | DetectParams[] det = m_ScriptManager.GetDetectParams(id); | ||
298 | |||
299 | if (number < 0 || number >= det.Length) | ||
300 | return null; | ||
301 | |||
302 | return det[number]; | ||
303 | } | ||
304 | |||
305 | public int GetStartParameter(UUID itemID) | ||
306 | { | ||
307 | return m_ScriptManager.GetStartParameter(itemID); | ||
308 | } | ||
309 | |||
310 | public void SetMinEventDelay(UUID itemID, double delay) | ||
311 | { | ||
312 | // TODO in DotNet, done in XEngine | ||
313 | throw new NotImplementedException(); | ||
314 | } | ||
315 | |||
316 | #endregion | ||
317 | |||
318 | public void SetState(UUID itemID, string state) | ||
319 | { | ||
320 | uint localID = m_ScriptManager.GetLocalID(itemID); | ||
321 | if (localID == 0) | ||
322 | return; | ||
323 | |||
324 | InstanceData id = m_ScriptManager.GetScript(localID, itemID); | ||
325 | |||
326 | if (id == null) | ||
327 | return; | ||
328 | |||
329 | string currentState = id.State; | ||
330 | |||
331 | if (currentState != state) | ||
332 | { | ||
333 | try | ||
334 | { | ||
335 | m_EventManager.state_exit(localID); | ||
336 | |||
337 | } | ||
338 | catch (AppDomainUnloadedException) | ||
339 | { | ||
340 | m_log.Error("[SCRIPT]: state change called when "+ | ||
341 | "script was unloaded. Nothing to worry about, "+ | ||
342 | "but noting the occurance"); | ||
343 | } | ||
344 | |||
345 | id.State = state; | ||
346 | |||
347 | try | ||
348 | { | ||
349 | int eventFlags = m_ScriptManager.GetStateEventFlags(localID, | ||
350 | itemID); | ||
351 | |||
352 | SceneObjectPart part = m_Scene.GetSceneObjectPart(localID); | ||
353 | if (part != null) | ||
354 | part.SetScriptEvents(itemID, eventFlags); | ||
355 | |||
356 | m_EventManager.state_entry(localID); | ||
357 | } | ||
358 | catch (AppDomainUnloadedException) | ||
359 | { | ||
360 | m_log.Error("[SCRIPT]: state change called when "+ | ||
361 | "script was unloaded. Nothing to worry about, but "+ | ||
362 | "noting the occurance"); | ||
363 | } | ||
364 | } | ||
365 | } | ||
366 | |||
367 | public bool GetScriptState(UUID itemID) | ||
368 | { | ||
369 | uint localID = m_ScriptManager.GetLocalID(itemID); | ||
370 | if (localID == 0) | ||
371 | return false; | ||
372 | |||
373 | InstanceData id = m_ScriptManager.GetScript(localID, itemID); | ||
374 | if (id == null) | ||
375 | return false; | ||
376 | |||
377 | return id.Running; | ||
378 | } | ||
379 | |||
380 | public void SetScriptState(UUID itemID, bool state) | ||
381 | { | ||
382 | uint localID = m_ScriptManager.GetLocalID(itemID); | ||
383 | if (localID == 0) | ||
384 | return; | ||
385 | |||
386 | InstanceData id = m_ScriptManager.GetScript(localID, itemID); | ||
387 | if (id == null) | ||
388 | return; | ||
389 | |||
390 | if (!id.Disabled) | ||
391 | id.Running = state; | ||
392 | } | ||
393 | |||
394 | public void ApiResetScript(UUID itemID) | ||
395 | { | ||
396 | uint localID = m_ScriptManager.GetLocalID(itemID); | ||
397 | if (localID == 0) | ||
398 | return; | ||
399 | |||
400 | m_ScriptManager.ResetScript(localID, itemID); | ||
401 | } | ||
402 | |||
403 | public void ResetScript(UUID itemID) | ||
404 | { | ||
405 | uint localID = m_ScriptManager.GetLocalID(itemID); | ||
406 | if (localID == 0) | ||
407 | return; | ||
408 | |||
409 | m_ScriptManager.ResetScript(localID, itemID); | ||
410 | } | ||
411 | |||
412 | public void OnScriptReset(uint localID, UUID itemID) | ||
413 | { | ||
414 | ResetScript(itemID); | ||
415 | } | ||
416 | |||
417 | public void OnStartScript(uint localID, UUID itemID) | ||
418 | { | ||
419 | InstanceData id = m_ScriptManager.GetScript(localID, itemID); | ||
420 | if (id == null) | ||
421 | return; | ||
422 | |||
423 | if (!id.Disabled) | ||
424 | id.Running = true; | ||
425 | } | ||
426 | |||
427 | public void OnStopScript(uint localID, UUID itemID) | ||
428 | { | ||
429 | InstanceData id = m_ScriptManager.GetScript(localID, itemID); | ||
430 | if (id == null) | ||
431 | return; | ||
432 | |||
433 | id.Running = false; | ||
434 | } | ||
435 | |||
436 | public void OnGetScriptRunning(IClientAPI controllingClient, | ||
437 | UUID objectID, UUID itemID) | ||
438 | { | ||
439 | uint localID = m_ScriptManager.GetLocalID(itemID); | ||
440 | if (localID == 0) | ||
441 | return; | ||
442 | |||
443 | InstanceData id = m_ScriptManager.GetScript(localID, itemID); | ||
444 | if (id == null) | ||
445 | return; | ||
446 | |||
447 | IEventQueue eq = World.RequestModuleInterface<IEventQueue>(); | ||
448 | if (eq == null) | ||
449 | { | ||
450 | controllingClient.SendScriptRunningReply(objectID, itemID, | ||
451 | id.Running); | ||
452 | } | ||
453 | else | ||
454 | { | ||
455 | eq.Enqueue(EventQueueHelper.ScriptRunningReplyEvent(objectID, itemID, id.Running, true), | ||
456 | controllingClient.AgentId); | ||
457 | } | ||
458 | } | ||
459 | |||
460 | public IScriptApi GetApi(UUID itemID, string name) | ||
461 | { | ||
462 | return m_ScriptManager.GetApi(itemID, name); | ||
463 | } | ||
464 | |||
465 | public IScriptWorkItem QueueEventHandler(Object o) | ||
466 | { | ||
467 | return null; | ||
468 | } | ||
469 | |||
470 | public string GetAssemblyName(UUID itemID) | ||
471 | { | ||
472 | return ""; | ||
473 | } | ||
474 | |||
475 | public string GetXMLState(UUID itemID) | ||
476 | { | ||
477 | return ""; | ||
478 | } | ||
479 | |||
480 | public bool CanBeDeleted(UUID itemID) | ||
481 | { | ||
482 | return true; | ||
483 | } | ||
484 | } | ||
485 | } | ||
diff --git a/OpenSim/Region/ScriptEngine/DotNetEngine/ScriptManager.cs b/OpenSim/Region/ScriptEngine/DotNetEngine/ScriptManager.cs deleted file mode 100644 index 6ac209e..0000000 --- a/OpenSim/Region/ScriptEngine/DotNetEngine/ScriptManager.cs +++ /dev/null | |||
@@ -1,703 +0,0 @@ | |||
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 OpenSimulator 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 | using System; | ||
29 | using System.Reflection; | ||
30 | using System.Globalization; | ||
31 | using System.Runtime.Remoting; | ||
32 | using System.Runtime.Remoting.Lifetime; | ||
33 | using log4net; | ||
34 | using OpenMetaverse; | ||
35 | using OpenSim.Framework; | ||
36 | using OpenSim.Region.Framework.Scenes; | ||
37 | using OpenSim.Region.ScriptEngine.Interfaces; | ||
38 | using OpenSim.Region.ScriptEngine.Shared; | ||
39 | using OpenSim.Region.ScriptEngine.Shared.Api; | ||
40 | using System.Collections.Generic; | ||
41 | using System.IO; | ||
42 | using System.Runtime.Serialization.Formatters.Binary; | ||
43 | using System.Threading; | ||
44 | using OpenSim.Region.ScriptEngine.Shared.Api.Runtime; | ||
45 | using OpenSim.Region.ScriptEngine.Shared.ScriptBase; | ||
46 | using OpenSim.Region.ScriptEngine.Shared.CodeTools; | ||
47 | |||
48 | namespace OpenSim.Region.ScriptEngine.DotNetEngine | ||
49 | { | ||
50 | public class InstanceData | ||
51 | { | ||
52 | public IScript Script; | ||
53 | public string State; | ||
54 | public bool Running; | ||
55 | public bool Disabled; | ||
56 | public string Source; | ||
57 | public int StartParam; | ||
58 | public AppDomain AppDomain; | ||
59 | public Dictionary<string, IScriptApi> Apis; | ||
60 | public Dictionary<KeyValuePair<int,int>, KeyValuePair<int,int>> | ||
61 | LineMap; | ||
62 | // public ISponsor ScriptSponsor; | ||
63 | } | ||
64 | |||
65 | public class ScriptManager | ||
66 | { | ||
67 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
68 | |||
69 | #region Declares | ||
70 | |||
71 | private Thread scriptLoadUnloadThread; | ||
72 | private static Thread staticScriptLoadUnloadThread = null; | ||
73 | private Queue<LUStruct> LUQueue = new Queue<LUStruct>(); | ||
74 | private static bool PrivateThread; | ||
75 | private int LoadUnloadMaxQueueSize; | ||
76 | private Object scriptLock = new Object(); | ||
77 | private bool m_started = false; | ||
78 | private Dictionary<InstanceData, DetectParams[]> detparms = | ||
79 | new Dictionary<InstanceData, DetectParams[]>(); | ||
80 | |||
81 | // Load/Unload structure | ||
82 | private struct LUStruct | ||
83 | { | ||
84 | public uint localID; | ||
85 | public UUID itemID; | ||
86 | public string script; | ||
87 | public LUType Action; | ||
88 | public int startParam; | ||
89 | public bool postOnRez; | ||
90 | } | ||
91 | |||
92 | private enum LUType | ||
93 | { | ||
94 | Unknown = 0, | ||
95 | Load = 1, | ||
96 | Unload = 2 | ||
97 | } | ||
98 | |||
99 | public Dictionary<uint, Dictionary<UUID, InstanceData>> Scripts = | ||
100 | new Dictionary<uint, Dictionary<UUID, InstanceData>>(); | ||
101 | |||
102 | private Compiler LSLCompiler; | ||
103 | |||
104 | public Scene World | ||
105 | { | ||
106 | get { return m_scriptEngine.World; } | ||
107 | } | ||
108 | |||
109 | #endregion | ||
110 | |||
111 | public void Initialize() | ||
112 | { | ||
113 | // Create our compiler | ||
114 | LSLCompiler = new Compiler(m_scriptEngine); | ||
115 | } | ||
116 | |||
117 | public void _StartScript(uint localID, UUID itemID, string Script, | ||
118 | int startParam, bool postOnRez) | ||
119 | { | ||
120 | m_log.DebugFormat( | ||
121 | "[{0}]: ScriptManager StartScript: localID: {1}, itemID: {2}", | ||
122 | m_scriptEngine.ScriptEngineName, localID, itemID); | ||
123 | |||
124 | // We will initialize and start the script. | ||
125 | // It will be up to the script itself to hook up the correct events. | ||
126 | string CompiledScriptFile = String.Empty; | ||
127 | |||
128 | SceneObjectPart m_host = World.GetSceneObjectPart(localID); | ||
129 | |||
130 | if (null == m_host) | ||
131 | { | ||
132 | m_log.ErrorFormat( | ||
133 | "[{0}]: Could not find scene object part corresponding "+ | ||
134 | "to localID {1} to start script", | ||
135 | m_scriptEngine.ScriptEngineName, localID); | ||
136 | |||
137 | return; | ||
138 | } | ||
139 | |||
140 | UUID assetID = UUID.Zero; | ||
141 | TaskInventoryItem taskInventoryItem = new TaskInventoryItem(); | ||
142 | if (m_host.TaskInventory.TryGetValue(itemID, out taskInventoryItem)) | ||
143 | assetID = taskInventoryItem.AssetID; | ||
144 | |||
145 | ScenePresence presence = | ||
146 | World.GetScenePresence(taskInventoryItem.OwnerID); | ||
147 | |||
148 | CultureInfo USCulture = new CultureInfo("en-US"); | ||
149 | Thread.CurrentThread.CurrentCulture = USCulture; | ||
150 | |||
151 | try | ||
152 | { | ||
153 | // Compile (We assume LSL) | ||
154 | CompiledScriptFile = | ||
155 | (string)LSLCompiler.PerformScriptCompile(Script, | ||
156 | assetID.ToString(), taskInventoryItem.OwnerID); | ||
157 | |||
158 | if (presence != null && (!postOnRez)) | ||
159 | presence.ControllingClient.SendAgentAlertMessage( | ||
160 | "Compile successful", false); | ||
161 | |||
162 | m_log.InfoFormat("[SCRIPT]: Compiled assetID {0}: {1}", | ||
163 | assetID, CompiledScriptFile); | ||
164 | |||
165 | InstanceData id = new InstanceData(); | ||
166 | |||
167 | IScript CompiledScript; | ||
168 | CompiledScript = | ||
169 | m_scriptEngine.m_AppDomainManager.LoadScript( | ||
170 | CompiledScriptFile, out id.AppDomain); | ||
171 | //Register the sponsor | ||
172 | // ISponsor scriptSponsor = new ScriptSponsor(); | ||
173 | // ILease lease = (ILease)RemotingServices.GetLifetimeService(CompiledScript as MarshalByRefObject); | ||
174 | // lease.Register(scriptSponsor); | ||
175 | // id.ScriptSponsor = scriptSponsor; | ||
176 | |||
177 | id.LineMap = LSLCompiler.LineMap(); | ||
178 | id.Script = CompiledScript; | ||
179 | id.Source = Script; | ||
180 | id.StartParam = startParam; | ||
181 | id.State = "default"; | ||
182 | id.Running = true; | ||
183 | id.Disabled = false; | ||
184 | |||
185 | // Add it to our script memstruct | ||
186 | m_scriptEngine.m_ScriptManager.SetScript(localID, itemID, id); | ||
187 | |||
188 | id.Apis = new Dictionary<string, IScriptApi>(); | ||
189 | |||
190 | ApiManager am = new ApiManager(); | ||
191 | |||
192 | foreach (string api in am.GetApis()) | ||
193 | { | ||
194 | id.Apis[api] = am.CreateApi(api); | ||
195 | id.Apis[api].Initialize(m_scriptEngine, m_host, | ||
196 | localID, itemID); | ||
197 | } | ||
198 | |||
199 | foreach (KeyValuePair<string,IScriptApi> kv in id.Apis) | ||
200 | { | ||
201 | CompiledScript.InitApi(kv.Key, kv.Value); | ||
202 | } | ||
203 | |||
204 | // Fire the first start-event | ||
205 | int eventFlags = | ||
206 | m_scriptEngine.m_ScriptManager.GetStateEventFlags( | ||
207 | localID, itemID); | ||
208 | |||
209 | m_host.SetScriptEvents(itemID, eventFlags); | ||
210 | |||
211 | m_scriptEngine.m_EventQueueManager.AddToScriptQueue( | ||
212 | localID, itemID, "state_entry", new DetectParams[0], | ||
213 | new object[] { }); | ||
214 | |||
215 | if (postOnRez) | ||
216 | { | ||
217 | m_scriptEngine.m_EventQueueManager.AddToScriptQueue( | ||
218 | localID, itemID, "on_rez", new DetectParams[0], | ||
219 | new object[] { new LSL_Types.LSLInteger(startParam) }); | ||
220 | } | ||
221 | |||
222 | string[] warnings = LSLCompiler.GetWarnings(); | ||
223 | |||
224 | if (warnings != null && warnings.Length != 0) | ||
225 | { | ||
226 | if (presence != null && (!postOnRez)) | ||
227 | presence.ControllingClient.SendAgentAlertMessage( | ||
228 | "Script saved with warnings, check debug window!", | ||
229 | false); | ||
230 | |||
231 | foreach (string warning in warnings) | ||
232 | { | ||
233 | try | ||
234 | { | ||
235 | // DISPLAY WARNING INWORLD | ||
236 | string text = "Warning:\n" + warning; | ||
237 | if (text.Length > 1100) | ||
238 | text = text.Substring(0, 1099); | ||
239 | |||
240 | World.SimChat(Utils.StringToBytes(text), | ||
241 | ChatTypeEnum.DebugChannel, 2147483647, | ||
242 | m_host.AbsolutePosition, m_host.Name, m_host.UUID, | ||
243 | false); | ||
244 | } | ||
245 | catch (Exception e2) // LEGIT: User Scripting | ||
246 | { | ||
247 | m_log.Error("[" + | ||
248 | m_scriptEngine.ScriptEngineName + | ||
249 | "]: Error displaying warning in-world: " + | ||
250 | e2.ToString()); | ||
251 | m_log.Error("[" + | ||
252 | m_scriptEngine.ScriptEngineName + "]: " + | ||
253 | "Warning:\r\n" + | ||
254 | warning); | ||
255 | } | ||
256 | } | ||
257 | } | ||
258 | } | ||
259 | catch (Exception e) // LEGIT: User Scripting | ||
260 | { | ||
261 | if (presence != null && (!postOnRez)) | ||
262 | presence.ControllingClient.SendAgentAlertMessage( | ||
263 | "Script saved with errors, check debug window!", | ||
264 | false); | ||
265 | try | ||
266 | { | ||
267 | // DISPLAY ERROR INWORLD | ||
268 | string text = "Error compiling script:\n" + | ||
269 | e.Message.ToString(); | ||
270 | if (text.Length > 1100) | ||
271 | text = text.Substring(0, 1099); | ||
272 | |||
273 | World.SimChat(Utils.StringToBytes(text), | ||
274 | ChatTypeEnum.DebugChannel, 2147483647, | ||
275 | m_host.AbsolutePosition, m_host.Name, m_host.UUID, | ||
276 | false); | ||
277 | } | ||
278 | catch (Exception e2) // LEGIT: User Scripting | ||
279 | { | ||
280 | m_log.Error("[" + | ||
281 | m_scriptEngine.ScriptEngineName + | ||
282 | "]: Error displaying error in-world: " + | ||
283 | e2.ToString()); | ||
284 | m_log.Error("[" + | ||
285 | m_scriptEngine.ScriptEngineName + "]: " + | ||
286 | "Errormessage: Error compiling script:\r\n" + | ||
287 | e2.Message.ToString()); | ||
288 | } | ||
289 | } | ||
290 | } | ||
291 | |||
292 | public void _StopScript(uint localID, UUID itemID) | ||
293 | { | ||
294 | InstanceData id = GetScript(localID, itemID); | ||
295 | if (id == null) | ||
296 | return; | ||
297 | |||
298 | m_log.DebugFormat("[{0}]: Unloading script", | ||
299 | m_scriptEngine.ScriptEngineName); | ||
300 | |||
301 | // Stop long command on script | ||
302 | AsyncCommandManager.RemoveScript(m_scriptEngine, localID, itemID); | ||
303 | |||
304 | try | ||
305 | { | ||
306 | // Get AppDomain | ||
307 | // Tell script not to accept new requests | ||
308 | id.Running = false; | ||
309 | id.Disabled = true; | ||
310 | AppDomain ad = id.AppDomain; | ||
311 | |||
312 | // Remove from internal structure | ||
313 | RemoveScript(localID, itemID); | ||
314 | |||
315 | // Tell AppDomain that we have stopped script | ||
316 | m_scriptEngine.m_AppDomainManager.StopScript(ad); | ||
317 | } | ||
318 | catch (Exception e) // LEGIT: User Scripting | ||
319 | { | ||
320 | m_log.Error("[" + | ||
321 | m_scriptEngine.ScriptEngineName + | ||
322 | "]: Exception stopping script localID: " + | ||
323 | localID + " LLUID: " + itemID.ToString() + | ||
324 | ": " + e.ToString()); | ||
325 | } | ||
326 | } | ||
327 | |||
328 | public void ReadConfig() | ||
329 | { | ||
330 | // TODO: Requires sharing of all ScriptManagers to single thread | ||
331 | PrivateThread = true; | ||
332 | LoadUnloadMaxQueueSize = m_scriptEngine.ScriptConfigSource.GetInt( | ||
333 | "LoadUnloadMaxQueueSize", 100); | ||
334 | } | ||
335 | |||
336 | #region Object init/shutdown | ||
337 | |||
338 | public ScriptEngine m_scriptEngine; | ||
339 | |||
340 | public ScriptManager(ScriptEngine scriptEngine) | ||
341 | { | ||
342 | m_scriptEngine = scriptEngine; | ||
343 | } | ||
344 | |||
345 | public void Setup() | ||
346 | { | ||
347 | ReadConfig(); | ||
348 | Initialize(); | ||
349 | } | ||
350 | |||
351 | public void Start() | ||
352 | { | ||
353 | m_started = true; | ||
354 | |||
355 | |||
356 | AppDomain.CurrentDomain.AssemblyResolve += | ||
357 | new ResolveEventHandler(CurrentDomain_AssemblyResolve); | ||
358 | |||
359 | // | ||
360 | // CREATE THREAD | ||
361 | // Private or shared | ||
362 | // | ||
363 | if (PrivateThread) | ||
364 | { | ||
365 | // Assign one thread per region | ||
366 | //scriptLoadUnloadThread = StartScriptLoadUnloadThread(); | ||
367 | } | ||
368 | else | ||
369 | { | ||
370 | // Shared thread - make sure one exist, then assign it to the private | ||
371 | if (staticScriptLoadUnloadThread == null) | ||
372 | { | ||
373 | //staticScriptLoadUnloadThread = | ||
374 | // StartScriptLoadUnloadThread(); | ||
375 | } | ||
376 | scriptLoadUnloadThread = staticScriptLoadUnloadThread; | ||
377 | } | ||
378 | } | ||
379 | |||
380 | ~ScriptManager() | ||
381 | { | ||
382 | // Abort load/unload thread | ||
383 | try | ||
384 | { | ||
385 | if (scriptLoadUnloadThread != null && | ||
386 | scriptLoadUnloadThread.IsAlive == true) | ||
387 | { | ||
388 | scriptLoadUnloadThread.Abort(); | ||
389 | //scriptLoadUnloadThread.Join(); | ||
390 | } | ||
391 | } | ||
392 | catch | ||
393 | { | ||
394 | } | ||
395 | } | ||
396 | |||
397 | #endregion | ||
398 | |||
399 | #region Load / Unload scripts (Thread loop) | ||
400 | |||
401 | public void DoScriptLoadUnload() | ||
402 | { | ||
403 | if (!m_started) | ||
404 | return; | ||
405 | |||
406 | lock (LUQueue) | ||
407 | { | ||
408 | if (LUQueue.Count > 0) | ||
409 | { | ||
410 | LUStruct item = LUQueue.Dequeue(); | ||
411 | |||
412 | if (item.Action == LUType.Unload) | ||
413 | { | ||
414 | _StopScript(item.localID, item.itemID); | ||
415 | RemoveScript(item.localID, item.itemID); | ||
416 | } | ||
417 | else if (item.Action == LUType.Load) | ||
418 | { | ||
419 | m_log.DebugFormat("[{0}]: Loading script", | ||
420 | m_scriptEngine.ScriptEngineName); | ||
421 | _StartScript(item.localID, item.itemID, item.script, | ||
422 | item.startParam, item.postOnRez); | ||
423 | } | ||
424 | } | ||
425 | } | ||
426 | } | ||
427 | |||
428 | #endregion | ||
429 | |||
430 | #region Helper functions | ||
431 | |||
432 | private static Assembly CurrentDomain_AssemblyResolve( | ||
433 | object sender, ResolveEventArgs args) | ||
434 | { | ||
435 | return Assembly.GetExecutingAssembly().FullName == args.Name ? | ||
436 | Assembly.GetExecutingAssembly() : null; | ||
437 | } | ||
438 | |||
439 | #endregion | ||
440 | |||
441 | #region Start/Stop/Reset script | ||
442 | |||
443 | /// <summary> | ||
444 | /// Fetches, loads and hooks up a script to an objects events | ||
445 | /// </summary> | ||
446 | /// <param name="itemID"></param> | ||
447 | /// <param name="localID"></param> | ||
448 | public void StartScript(uint localID, UUID itemID, string Script, int startParam, bool postOnRez) | ||
449 | { | ||
450 | lock (LUQueue) | ||
451 | { | ||
452 | if ((LUQueue.Count >= LoadUnloadMaxQueueSize) && m_started) | ||
453 | { | ||
454 | m_log.Error("[" + | ||
455 | m_scriptEngine.ScriptEngineName + | ||
456 | "]: ERROR: Load/unload queue item count is at " + | ||
457 | LUQueue.Count + | ||
458 | ". Config variable \"LoadUnloadMaxQueueSize\" "+ | ||
459 | "is set to " + LoadUnloadMaxQueueSize + | ||
460 | ", so ignoring new script."); | ||
461 | |||
462 | return; | ||
463 | } | ||
464 | |||
465 | LUStruct ls = new LUStruct(); | ||
466 | ls.localID = localID; | ||
467 | ls.itemID = itemID; | ||
468 | ls.script = Script; | ||
469 | ls.Action = LUType.Load; | ||
470 | ls.startParam = startParam; | ||
471 | ls.postOnRez = postOnRez; | ||
472 | LUQueue.Enqueue(ls); | ||
473 | } | ||
474 | } | ||
475 | |||
476 | /// <summary> | ||
477 | /// Disables and unloads a script | ||
478 | /// </summary> | ||
479 | /// <param name="localID"></param> | ||
480 | /// <param name="itemID"></param> | ||
481 | public void StopScript(uint localID, UUID itemID) | ||
482 | { | ||
483 | LUStruct ls = new LUStruct(); | ||
484 | ls.localID = localID; | ||
485 | ls.itemID = itemID; | ||
486 | ls.Action = LUType.Unload; | ||
487 | ls.startParam = 0; | ||
488 | ls.postOnRez = false; | ||
489 | lock (LUQueue) | ||
490 | { | ||
491 | LUQueue.Enqueue(ls); | ||
492 | } | ||
493 | } | ||
494 | |||
495 | #endregion | ||
496 | |||
497 | #region Perform event execution in script | ||
498 | |||
499 | // Execute a LL-event-function in Script | ||
500 | internal void ExecuteEvent(uint localID, UUID itemID, | ||
501 | string FunctionName, DetectParams[] qParams, object[] args) | ||
502 | { | ||
503 | int ExeStage=0; // ;^) Ewe Loon, for debuging | ||
504 | InstanceData id=null; | ||
505 | try // ;^) Ewe Loon,fix | ||
506 | { // ;^) Ewe Loon,fix | ||
507 | ExeStage = 1; // ;^) Ewe Loon, for debuging | ||
508 | id = GetScript(localID, itemID); | ||
509 | if (id == null) | ||
510 | return; | ||
511 | ExeStage = 2; // ;^) Ewe Loon, for debuging | ||
512 | if (qParams.Length>0) // ;^) Ewe Loon,fix | ||
513 | detparms[id] = qParams; | ||
514 | ExeStage = 3; // ;^) Ewe Loon, for debuging | ||
515 | if (id.Running) | ||
516 | id.Script.ExecuteEvent(id.State, FunctionName, args); | ||
517 | ExeStage = 4; // ;^) Ewe Loon, for debuging | ||
518 | if (qParams.Length>0) // ;^) Ewe Loon,fix | ||
519 | detparms.Remove(id); | ||
520 | ExeStage = 5; // ;^) Ewe Loon, for debuging | ||
521 | } | ||
522 | catch (Exception e) // ;^) Ewe Loon, From here down tis fix | ||
523 | { | ||
524 | if ((ExeStage == 3)&&(qParams.Length>0)) | ||
525 | detparms.Remove(id); | ||
526 | SceneObjectPart ob = m_scriptEngine.World.GetSceneObjectPart(localID); | ||
527 | m_log.InfoFormat("[Script Error] ,{0},{1},@{2},{3},{4},{5}", ob.Name , FunctionName, ExeStage, e.Message, qParams.Length, detparms.Count); | ||
528 | if (ExeStage != 2) throw e; | ||
529 | } | ||
530 | } | ||
531 | |||
532 | public uint GetLocalID(UUID itemID) | ||
533 | { | ||
534 | foreach (KeyValuePair<uint, Dictionary<UUID, InstanceData> > k | ||
535 | in Scripts) | ||
536 | { | ||
537 | if (k.Value.ContainsKey(itemID)) | ||
538 | return k.Key; | ||
539 | } | ||
540 | return 0; | ||
541 | } | ||
542 | |||
543 | public int GetStateEventFlags(uint localID, UUID itemID) | ||
544 | { | ||
545 | try | ||
546 | { | ||
547 | InstanceData id = GetScript(localID, itemID); | ||
548 | if (id == null) | ||
549 | { | ||
550 | return 0; | ||
551 | } | ||
552 | int evflags = id.Script.GetStateEventFlags(id.State); | ||
553 | |||
554 | return (int)evflags; | ||
555 | } | ||
556 | catch (Exception) | ||
557 | { | ||
558 | } | ||
559 | |||
560 | return 0; | ||
561 | } | ||
562 | |||
563 | #endregion | ||
564 | |||
565 | #region Internal functions to keep track of script | ||
566 | |||
567 | public List<UUID> GetScriptKeys(uint localID) | ||
568 | { | ||
569 | if (Scripts.ContainsKey(localID) == false) | ||
570 | return new List<UUID>(); | ||
571 | |||
572 | Dictionary<UUID, InstanceData> Obj; | ||
573 | Scripts.TryGetValue(localID, out Obj); | ||
574 | |||
575 | return new List<UUID>(Obj.Keys); | ||
576 | } | ||
577 | |||
578 | public InstanceData GetScript(uint localID, UUID itemID) | ||
579 | { | ||
580 | lock (scriptLock) | ||
581 | { | ||
582 | InstanceData id = null; | ||
583 | |||
584 | if (Scripts.ContainsKey(localID) == false) | ||
585 | return null; | ||
586 | |||
587 | Dictionary<UUID, InstanceData> Obj; | ||
588 | Scripts.TryGetValue(localID, out Obj); | ||
589 | if (Obj==null) return null; | ||
590 | if (Obj.ContainsKey(itemID) == false) | ||
591 | return null; | ||
592 | |||
593 | // Get script | ||
594 | Obj.TryGetValue(itemID, out id); | ||
595 | return id; | ||
596 | } | ||
597 | } | ||
598 | |||
599 | public void SetScript(uint localID, UUID itemID, InstanceData id) | ||
600 | { | ||
601 | lock (scriptLock) | ||
602 | { | ||
603 | // Create object if it doesn't exist | ||
604 | if (Scripts.ContainsKey(localID) == false) | ||
605 | { | ||
606 | Scripts.Add(localID, new Dictionary<UUID, InstanceData>()); | ||
607 | } | ||
608 | |||
609 | // Delete script if it exists | ||
610 | Dictionary<UUID, InstanceData> Obj; | ||
611 | Scripts.TryGetValue(localID, out Obj); | ||
612 | if (Obj.ContainsKey(itemID) == true) | ||
613 | Obj.Remove(itemID); | ||
614 | |||
615 | // Add to object | ||
616 | Obj.Add(itemID, id); | ||
617 | } | ||
618 | } | ||
619 | |||
620 | public void RemoveScript(uint localID, UUID itemID) | ||
621 | { | ||
622 | if (localID == 0) | ||
623 | localID = GetLocalID(itemID); | ||
624 | |||
625 | // Don't have that object? | ||
626 | if (Scripts.ContainsKey(localID) == false) | ||
627 | return; | ||
628 | |||
629 | // Delete script if it exists | ||
630 | Dictionary<UUID, InstanceData> Obj; | ||
631 | Scripts.TryGetValue(localID, out Obj); | ||
632 | if (Obj.ContainsKey(itemID) == true) | ||
633 | Obj.Remove(itemID); | ||
634 | } | ||
635 | |||
636 | #endregion | ||
637 | |||
638 | public void ResetScript(uint localID, UUID itemID) | ||
639 | { | ||
640 | InstanceData id = GetScript(localID, itemID); | ||
641 | string script = id.Source; | ||
642 | StopScript(localID, itemID); | ||
643 | SceneObjectPart part = World.GetSceneObjectPart(localID); | ||
644 | part.Inventory.GetInventoryItem(itemID).PermsMask = 0; | ||
645 | part.Inventory.GetInventoryItem(itemID).PermsGranter = UUID.Zero; | ||
646 | StartScript(localID, itemID, script, id.StartParam, false); | ||
647 | } | ||
648 | |||
649 | #region Script serialization/deserialization | ||
650 | |||
651 | public void GetSerializedScript(uint localID, UUID itemID) | ||
652 | { | ||
653 | // Serialize the script and return it | ||
654 | // Should not be a problem | ||
655 | FileStream fs = File.Create("SERIALIZED_SCRIPT_" + itemID); | ||
656 | BinaryFormatter b = new BinaryFormatter(); | ||
657 | b.Serialize(fs, GetScript(localID, itemID)); | ||
658 | fs.Close(); | ||
659 | } | ||
660 | |||
661 | public void PutSerializedScript(uint localID, UUID itemID) | ||
662 | { | ||
663 | // Deserialize the script and inject it into an AppDomain | ||
664 | |||
665 | // How to inject into an AppDomain? | ||
666 | } | ||
667 | |||
668 | #endregion | ||
669 | |||
670 | public DetectParams[] GetDetectParams(InstanceData id) | ||
671 | { | ||
672 | if (detparms.ContainsKey(id)) | ||
673 | return detparms[id]; | ||
674 | |||
675 | return null; | ||
676 | } | ||
677 | |||
678 | public int GetStartParameter(UUID itemID) | ||
679 | { | ||
680 | uint localID = GetLocalID(itemID); | ||
681 | InstanceData id = GetScript(localID, itemID); | ||
682 | |||
683 | if (id == null) | ||
684 | return 0; | ||
685 | |||
686 | return id.StartParam; | ||
687 | } | ||
688 | |||
689 | public IScriptApi GetApi(UUID itemID, string name) | ||
690 | { | ||
691 | uint localID = GetLocalID(itemID); | ||
692 | |||
693 | InstanceData id = GetScript(localID, itemID); | ||
694 | if (id == null) | ||
695 | return null; | ||
696 | |||
697 | if (id.Apis.ContainsKey(name)) | ||
698 | return id.Apis[name]; | ||
699 | |||
700 | return null; | ||
701 | } | ||
702 | } | ||
703 | } | ||
diff --git a/OpenSim/ScriptEngine/Components/DotNetEngine/Commands_LSL/Commands_LSL.cs b/OpenSim/ScriptEngine/Components/DotNetEngine/Commands_LSL/Commands_LSL.cs deleted file mode 100644 index 0b7c894..0000000 --- a/OpenSim/ScriptEngine/Components/DotNetEngine/Commands_LSL/Commands_LSL.cs +++ /dev/null | |||
@@ -1,40 +0,0 @@ | |||
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 OpenSimulator 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 | using System; | ||
29 | using System.Collections.Generic; | ||
30 | using System.Text; | ||
31 | using OpenSim.ScriptEngine.Shared; | ||
32 | |||
33 | namespace OpenSim.ScriptEngine.Components.DotNetEngine.Commands_LSL | ||
34 | { | ||
35 | public class Commands_LSL : IScriptEngineComponent | ||
36 | { | ||
37 | |||
38 | |||
39 | } | ||
40 | } | ||
diff --git a/OpenSim/ScriptEngine/Components/DotNetEngine/Commands_LSL/LSL_BaseClass.cs b/OpenSim/ScriptEngine/Components/DotNetEngine/Commands_LSL/LSL_BaseClass.cs deleted file mode 100644 index fdbc699..0000000 --- a/OpenSim/ScriptEngine/Components/DotNetEngine/Commands_LSL/LSL_BaseClass.cs +++ /dev/null | |||
@@ -1,56 +0,0 @@ | |||
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 OpenSimulator 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 | using System; | ||
29 | using System.Collections.Generic; | ||
30 | using System.Reflection; | ||
31 | using System.Text; | ||
32 | using log4net; | ||
33 | using OpenSim.ScriptEngine.Shared; | ||
34 | |||
35 | namespace OpenSim.ScriptEngine.Components.DotNetEngine.Commands_LSL | ||
36 | { | ||
37 | public class Script : IScriptCommandProvider | ||
38 | { | ||
39 | internal static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
40 | |||
41 | public void llSay(int channelID, string text) | ||
42 | { | ||
43 | m_log.InfoFormat("[{0}] llSay({1}, \"{2}\")", "(Commands_LSL)OpenSim.ScriptEngine.Components.DotNetEngine.Commands_LSL.Script", channelID, text); | ||
44 | } | ||
45 | |||
46 | public void ExecuteCommand(string functionName, params object[] args) | ||
47 | { | ||
48 | |||
49 | } | ||
50 | |||
51 | public string Name | ||
52 | { | ||
53 | get { return "SECS.DotNetEngine.Commands_LSL.Script"; } | ||
54 | } | ||
55 | } | ||
56 | } \ No newline at end of file | ||
diff --git a/OpenSim/ScriptEngine/Components/DotNetEngine/Commands_LSL/Properties/AssemblyInfo.cs b/OpenSim/ScriptEngine/Components/DotNetEngine/Commands_LSL/Properties/AssemblyInfo.cs deleted file mode 100644 index fc67ec1..0000000 --- a/OpenSim/ScriptEngine/Components/DotNetEngine/Commands_LSL/Properties/AssemblyInfo.cs +++ /dev/null | |||
@@ -1,63 +0,0 @@ | |||
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 OpenSimulator 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 | using System.Reflection; | ||
29 | using System.Runtime.CompilerServices; | ||
30 | using System.Runtime.InteropServices; | ||
31 | |||
32 | // General Information about an assembly is controlled through the following | ||
33 | // set of attributes. Change these attribute values to modify the information | ||
34 | // associated with an assembly. | ||
35 | [assembly: AssemblyTitle("OpenSim.ScriptEngine.Components.DotNetEngine.Commands_LSL")] | ||
36 | [assembly: AssemblyDescription("")] | ||
37 | [assembly: AssemblyConfiguration("")] | ||
38 | [assembly: AssemblyCompany("http://opensimulator.org")] | ||
39 | [assembly: AssemblyProduct("OpenSim.ScriptEngine.Components.DotNetEngine.Commands_LSL")] | ||
40 | [assembly: AssemblyCopyright("Copyright © Microsoft 2008")] | ||
41 | [assembly: AssemblyTrademark("")] | ||
42 | [assembly: AssemblyCulture("")] | ||
43 | |||
44 | // Setting ComVisible to false makes the types in this assembly not visible | ||
45 | // to COM components. If you need to access a type in this assembly from | ||
46 | // COM, set the ComVisible attribute to true on that type. | ||
47 | [assembly: ComVisible(false)] | ||
48 | |||
49 | // The following GUID is for the ID of the typelib if this project is exposed to COM | ||
50 | [assembly: Guid("ea77002b-c967-4368-ace9-6533f8147d4b")] | ||
51 | |||
52 | // Version information for an assembly consists of the following four values: | ||
53 | // | ||
54 | // Major Version | ||
55 | // Minor Version | ||
56 | // Build Number | ||
57 | // Revision | ||
58 | // | ||
59 | // You can specify all the values or you can default the Build and Revision Numbers | ||
60 | // by using the '*' as shown below: | ||
61 | // [assembly: AssemblyVersion("0.6.5.*")] | ||
62 | [assembly: AssemblyVersion("0.6.5.*")] | ||
63 | [assembly: AssemblyFileVersion("0.6.5.0")] | ||
diff --git a/OpenSim/ScriptEngine/Components/DotNetEngine/Commands_OSSL/Commands_OSSL.cs b/OpenSim/ScriptEngine/Components/DotNetEngine/Commands_OSSL/Commands_OSSL.cs deleted file mode 100644 index 86eab09..0000000 --- a/OpenSim/ScriptEngine/Components/DotNetEngine/Commands_OSSL/Commands_OSSL.cs +++ /dev/null | |||
@@ -1,44 +0,0 @@ | |||
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 OpenSimulator 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 | using System; | ||
29 | using System.Collections.Generic; | ||
30 | using System.Text; | ||
31 | using OpenSim.ScriptEngine.Shared; | ||
32 | |||
33 | namespace OpenSim.ScriptEngine.Components.DotNetEngine.Commands_OSSL | ||
34 | { | ||
35 | public class Commands_OSSL : IScriptEngineComponent | ||
36 | { | ||
37 | //private RegionInfoStructure CurrentRegion; | ||
38 | public void Initialize(RegionInfoStructure currentRegion) | ||
39 | { | ||
40 | //CurrentRegion = currentRegion; | ||
41 | } | ||
42 | |||
43 | } | ||
44 | } | ||
diff --git a/OpenSim/ScriptEngine/Components/DotNetEngine/Commands_OSSL/Properties/AssemblyInfo.cs b/OpenSim/ScriptEngine/Components/DotNetEngine/Commands_OSSL/Properties/AssemblyInfo.cs deleted file mode 100644 index c6b15cf..0000000 --- a/OpenSim/ScriptEngine/Components/DotNetEngine/Commands_OSSL/Properties/AssemblyInfo.cs +++ /dev/null | |||
@@ -1,63 +0,0 @@ | |||
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 OpenSimulator 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 | using System.Reflection; | ||
29 | using System.Runtime.CompilerServices; | ||
30 | using System.Runtime.InteropServices; | ||
31 | |||
32 | // General Information about an assembly is controlled through the following | ||
33 | // set of attributes. Change these attribute values to modify the information | ||
34 | // associated with an assembly. | ||
35 | [assembly: AssemblyTitle("OpenSim.ScriptEngine.Components.DotNetEngine.Commands_OSSL")] | ||
36 | [assembly: AssemblyDescription("")] | ||
37 | [assembly: AssemblyConfiguration("")] | ||
38 | [assembly: AssemblyCompany("http://opensimulator.org")] | ||
39 | [assembly: AssemblyProduct("OpenSim.ScriptEngine.Components.DotNetEngine.Commands_OSSL")] | ||
40 | [assembly: AssemblyCopyright("Copyright © Microsoft 2008")] | ||
41 | [assembly: AssemblyTrademark("")] | ||
42 | [assembly: AssemblyCulture("")] | ||
43 | |||
44 | // Setting ComVisible to false makes the types in this assembly not visible | ||
45 | // to COM components. If you need to access a type in this assembly from | ||
46 | // COM, set the ComVisible attribute to true on that type. | ||
47 | [assembly: ComVisible(false)] | ||
48 | |||
49 | // The following GUID is for the ID of the typelib if this project is exposed to COM | ||
50 | [assembly: Guid("ea77002b-c967-4368-ace9-6533f8147d4b")] | ||
51 | |||
52 | // Version information for an assembly consists of the following four values: | ||
53 | // | ||
54 | // Major Version | ||
55 | // Minor Version | ||
56 | // Build Number | ||
57 | // Revision | ||
58 | // | ||
59 | // You can specify all the values or you can default the Build and Revision Numbers | ||
60 | // by using the '*' as shown below: | ||
61 | // [assembly: AssemblyVersion("0.6.5.*")] | ||
62 | [assembly: AssemblyVersion("0.6.5.*")] | ||
63 | [assembly: AssemblyFileVersion("0.6.5.0")] | ||
diff --git a/OpenSim/ScriptEngine/Components/DotNetEngine/Compilers/CILCompiler.cs b/OpenSim/ScriptEngine/Components/DotNetEngine/Compilers/CILCompiler.cs deleted file mode 100644 index 3d2d9d2..0000000 --- a/OpenSim/ScriptEngine/Components/DotNetEngine/Compilers/CILCompiler.cs +++ /dev/null | |||
@@ -1,187 +0,0 @@ | |||
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 OpenSimulator 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 | using System; | ||
28 | using System.CodeDom.Compiler; | ||
29 | using System.Collections.Generic; | ||
30 | using System.IO; | ||
31 | using System.Reflection; | ||
32 | using System.Text.RegularExpressions; | ||
33 | using log4net; | ||
34 | using OpenSim.ScriptEngine.Shared; | ||
35 | using ScriptAssemblies; | ||
36 | |||
37 | namespace OpenSim.ScriptEngine.Components.DotNetEngine.Compilers | ||
38 | { | ||
39 | public abstract class CILCompiler | ||
40 | { | ||
41 | internal static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
42 | private string ScriptEnginesPath = "ScriptEngines"; | ||
43 | private string Name { get { return "SECS.DotNetEngine.CILCompiler"; } } | ||
44 | private string m_scriptAssemblyName; | ||
45 | internal string ScriptAssemblyName { get { return m_scriptAssemblyName; } set { m_scriptAssemblyName = value; } } | ||
46 | |||
47 | // Default inherit | ||
48 | protected string ScriptInheritFrom = typeof(ScriptAssemblies.ScriptBase).Name; | ||
49 | private readonly System.Security.Cryptography.MD5CryptoServiceProvider MD5Sum = new System.Security.Cryptography.MD5CryptoServiceProvider(); | ||
50 | protected CodeDomProvider CompileProvider; | ||
51 | |||
52 | //private string[] AppDomainAssemblies = new string[] { "OpenSim.Region.ScriptEngine.Shared.dll", "OpenSim.Region.ScriptEngine.Shared.Script.dll", "OpenSim.Region.ScriptEngine.Shared.Api.Runtime.dll" }; | ||
53 | private readonly string[] AppDomainAssemblies = new string[] { | ||
54 | Assembly.GetAssembly(typeof(Int32)).Location, | ||
55 | "OpenSim.ScriptEngine.Shared.dll", | ||
56 | "OpenSim.ScriptEngine.Shared.Script.dll", | ||
57 | Path.Combine("ScriptEngines", "OpenSim.Region.ScriptEngine.Shared.dll") | ||
58 | }; | ||
59 | |||
60 | public abstract string PreProcessScript(ref string script); | ||
61 | |||
62 | public CILCompiler() | ||
63 | { | ||
64 | } | ||
65 | |||
66 | private static readonly Regex FileNameFixer = new Regex(@"[^a-zA-Z0-9\.\-]", RegexOptions.Compiled | RegexOptions.Singleline); | ||
67 | public string Compile(ScriptMetaData data, ref string _script) | ||
68 | { | ||
69 | // Add "using", "inherit", default constructor, etc around script. | ||
70 | string script = PreProcessScript(ref _script); | ||
71 | |||
72 | // Get filename based on content | ||
73 | string md5Sum = System.Convert.ToBase64String( | ||
74 | MD5Sum.ComputeHash( | ||
75 | System.Text.Encoding.ASCII.GetBytes(script) | ||
76 | )); | ||
77 | // Unique name for this assembly | ||
78 | ScriptAssemblyName = "SECS_Script_" + FileNameFixer.Replace(md5Sum, "_"); | ||
79 | |||
80 | string OutFile = Path.Combine(ScriptEnginesPath, ScriptAssemblyName + ".dll"); | ||
81 | |||
82 | // Make sure target dir exist | ||
83 | if (!Directory.Exists(ScriptEnginesPath)) | ||
84 | try { Directory.CreateDirectory(ScriptEnginesPath); } | ||
85 | catch { } | ||
86 | |||
87 | // Already exist? No point in recompiling | ||
88 | if (File.Exists(OutFile)) | ||
89 | return OutFile; | ||
90 | |||
91 | // | ||
92 | // Dump source code | ||
93 | // | ||
94 | string dumpFile = OutFile + ".txt"; | ||
95 | try | ||
96 | { | ||
97 | if (File.Exists(dumpFile)) | ||
98 | File.Delete(dumpFile); | ||
99 | File.WriteAllText(dumpFile, script); | ||
100 | } | ||
101 | catch (Exception e) | ||
102 | { | ||
103 | m_log.DebugFormat("[{0}] Exception trying to dump script source code to file \"{1}\": {2}", Name, dumpFile, e.ToString()); | ||
104 | } | ||
105 | |||
106 | // | ||
107 | // COMPILE | ||
108 | // | ||
109 | |||
110 | CompilerParameters parameters = new CompilerParameters(); | ||
111 | parameters.IncludeDebugInformation = true; | ||
112 | //string rootPath = Path.GetDirectoryName(AppDomain.CurrentDomain.BaseDirectory); | ||
113 | |||
114 | foreach (string file in AppDomainAssemblies) | ||
115 | { | ||
116 | parameters.ReferencedAssemblies.Add(file); | ||
117 | m_log.DebugFormat("[{0}] Adding reference for compile: \"{1}\".", Name, file); | ||
118 | } | ||
119 | //lock (commandProvider) | ||
120 | //{ | ||
121 | // foreach (string key in commandProvider.Keys) | ||
122 | // { | ||
123 | // IScriptCommandProvider cp = commandProvider[key]; | ||
124 | // string | ||
125 | // file = cp.GetType().Assembly.Location; | ||
126 | // parameters.ReferencedAssemblies.Add(file); | ||
127 | // m_log.DebugFormat("[{0}] Loading command provider assembly \"{1}\" into AppDomain: \"{2}\".", Name, | ||
128 | // key, file); | ||
129 | // } | ||
130 | //} | ||
131 | |||
132 | parameters.GenerateExecutable = false; | ||
133 | parameters.OutputAssembly = OutFile; | ||
134 | parameters.IncludeDebugInformation = true; | ||
135 | //parameters.WarningLevel = 1; // Should be 4? | ||
136 | parameters.TreatWarningsAsErrors = false; | ||
137 | |||
138 | // Do compile | ||
139 | CompilerResults results = CompileProvider.CompileAssemblyFromSource(parameters, script); | ||
140 | |||
141 | |||
142 | // | ||
143 | // WARNINGS AND ERRORS | ||
144 | // | ||
145 | //TODO | ||
146 | int display = 5; | ||
147 | if (results.Errors.Count > 0) | ||
148 | { | ||
149 | string errtext = String.Empty; | ||
150 | foreach (CompilerError CompErr in results.Errors) | ||
151 | { | ||
152 | // Show 5 errors max | ||
153 | // | ||
154 | if (display <= 0) | ||
155 | break; | ||
156 | display--; | ||
157 | |||
158 | string severity = "Error"; | ||
159 | if (CompErr.IsWarning) | ||
160 | severity = "Warning"; | ||
161 | |||
162 | //TODO: Implement | ||
163 | KeyValuePair<int, int> lslPos = new KeyValuePair<int, int>(); | ||
164 | |||
165 | //lslPos = "NOT IMPLEMENTED";// FindErrorPosition(CompErr.Line, CompErr.Column); | ||
166 | |||
167 | string text = CompErr.ErrorText; | ||
168 | |||
169 | // The Second Life viewer's script editor begins | ||
170 | // countingn lines and columns at 0, so we subtract 1. | ||
171 | errtext += String.Format("Line ({0},{1}): {4} {2}: {3}\n", | ||
172 | lslPos.Key - 1, lslPos.Value - 1, | ||
173 | CompErr.ErrorNumber, text, severity); | ||
174 | } | ||
175 | |||
176 | if (!File.Exists(OutFile)) | ||
177 | { | ||
178 | throw new Exception(errtext); | ||
179 | } | ||
180 | } | ||
181 | |||
182 | // TODO: Process errors | ||
183 | return OutFile; | ||
184 | } | ||
185 | |||
186 | } | ||
187 | } | ||
diff --git a/OpenSim/ScriptEngine/Components/DotNetEngine/Compilers/Compiler_CS.cs b/OpenSim/ScriptEngine/Components/DotNetEngine/Compilers/Compiler_CS.cs deleted file mode 100644 index a8599bf..0000000 --- a/OpenSim/ScriptEngine/Components/DotNetEngine/Compilers/Compiler_CS.cs +++ /dev/null | |||
@@ -1,70 +0,0 @@ | |||
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 OpenSimulator 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 | using System; | ||
28 | using System.CodeDom.Compiler; | ||
29 | using System.Collections.Generic; | ||
30 | using System.Text; | ||
31 | using Microsoft.CSharp; | ||
32 | using OpenSim.ScriptEngine.Shared; | ||
33 | |||
34 | namespace OpenSim.ScriptEngine.Components.DotNetEngine.Compilers | ||
35 | { | ||
36 | public class Compiler_CS : CILCompiler, IScriptCompiler | ||
37 | { | ||
38 | private string[] ScriptUsing = new string[] | ||
39 | { | ||
40 | "System", | ||
41 | "OpenSim.ScriptEngine.Shared", | ||
42 | "OpenSim.Region.ScriptEngine.Shared", | ||
43 | "System.Collections.Generic" | ||
44 | }; | ||
45 | |||
46 | public Compiler_CS() | ||
47 | { | ||
48 | CompileProvider = new CSharpCodeProvider(); | ||
49 | } | ||
50 | |||
51 | public override string PreProcessScript(ref string script) | ||
52 | { | ||
53 | string s = ""; | ||
54 | foreach (string u in ScriptUsing) | ||
55 | { | ||
56 | s += "using " + u + ";"; | ||
57 | } | ||
58 | |||
59 | s += "\r\n" | ||
60 | + String.Empty + "namespace ScriptAssemblies { " | ||
61 | + String.Empty + "public class UserScript" + " : " + ScriptInheritFrom + " { \r\n" + | ||
62 | @"public Script() { } " + | ||
63 | script + | ||
64 | "} }\r\n"; | ||
65 | |||
66 | return s; | ||
67 | } | ||
68 | |||
69 | } | ||
70 | } | ||
diff --git a/OpenSim/ScriptEngine/Components/DotNetEngine/Compilers/Compiler_JS.cs b/OpenSim/ScriptEngine/Components/DotNetEngine/Compilers/Compiler_JS.cs deleted file mode 100644 index 4361ae2..0000000 --- a/OpenSim/ScriptEngine/Components/DotNetEngine/Compilers/Compiler_JS.cs +++ /dev/null | |||
@@ -1,56 +0,0 @@ | |||
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 OpenSimulator 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 | using System; | ||
28 | using System.CodeDom.Compiler; | ||
29 | using System.Collections.Generic; | ||
30 | using System.Text; | ||
31 | using Microsoft.JScript; | ||
32 | using OpenSim.ScriptEngine.Shared; | ||
33 | |||
34 | namespace OpenSim.ScriptEngine.Components.DotNetEngine.Compilers | ||
35 | { | ||
36 | public class Compiler_JS : CILCompiler, IScriptCompiler | ||
37 | { | ||
38 | |||
39 | public Compiler_JS() | ||
40 | { | ||
41 | CompileProvider = new JScriptCodeProvider() as CodeDomProvider; | ||
42 | } | ||
43 | |||
44 | public override string PreProcessScript(ref string script) | ||
45 | { | ||
46 | return | ||
47 | "import OpenSim.Region.ScriptEngine.Shared; import System.Collections.Generic;\r\n" + | ||
48 | "package SecondLife {\r\n" + | ||
49 | "class Script extends OpenSim.Region.ScriptEngine.Shared.ScriptBase.ScriptBaseClass { \r\n" + | ||
50 | script + | ||
51 | "} }\r\n"; | ||
52 | |||
53 | } | ||
54 | |||
55 | } | ||
56 | } | ||
diff --git a/OpenSim/ScriptEngine/Components/DotNetEngine/Compilers/Compiler_LSL.cs b/OpenSim/ScriptEngine/Components/DotNetEngine/Compilers/Compiler_LSL.cs deleted file mode 100644 index 496afc9..0000000 --- a/OpenSim/ScriptEngine/Components/DotNetEngine/Compilers/Compiler_LSL.cs +++ /dev/null | |||
@@ -1,57 +0,0 @@ | |||
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 OpenSimulator 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 | using System; | ||
28 | using System.Collections.Generic; | ||
29 | using System.Reflection; | ||
30 | using System.Text; | ||
31 | using OpenSim.ScriptEngine.Components.DotNetEngine.Compilers.LSL; | ||
32 | using OpenSim.ScriptEngine.Shared; | ||
33 | |||
34 | namespace OpenSim.ScriptEngine.Components.DotNetEngine.Compilers | ||
35 | { | ||
36 | public class Compiler_LSL : IScriptCompiler | ||
37 | { | ||
38 | |||
39 | |||
40 | private readonly Compiler_CS m_Compiler_CS = new Compiler_CS(); | ||
41 | private readonly LSL2CS m_LSL2CS = new LSL2CS(); | ||
42 | |||
43 | public string Compile(ScriptMetaData scriptMetaData, ref string script) | ||
44 | { | ||
45 | // Convert script to CS | ||
46 | string scriptCS = m_LSL2CS.Convert(ref script); | ||
47 | // Use CS compiler to compile it | ||
48 | return m_Compiler_CS.Compile(scriptMetaData, ref scriptCS); | ||
49 | } | ||
50 | |||
51 | public string PreProcessScript(ref string script) | ||
52 | { | ||
53 | // This is handled by our converter | ||
54 | return script; | ||
55 | } | ||
56 | } | ||
57 | } | ||
diff --git a/OpenSim/ScriptEngine/Components/DotNetEngine/Compilers/Compiler_VB.cs b/OpenSim/ScriptEngine/Components/DotNetEngine/Compilers/Compiler_VB.cs deleted file mode 100644 index 04597ba..0000000 --- a/OpenSim/ScriptEngine/Components/DotNetEngine/Compilers/Compiler_VB.cs +++ /dev/null | |||
@@ -1,56 +0,0 @@ | |||
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 OpenSimulator 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 | using System; | ||
28 | using System.CodeDom.Compiler; | ||
29 | using System.Collections.Generic; | ||
30 | using System.Text; | ||
31 | using Microsoft.VisualBasic; | ||
32 | using OpenSim.ScriptEngine.Shared; | ||
33 | |||
34 | namespace OpenSim.ScriptEngine.Components.DotNetEngine.Compilers | ||
35 | { | ||
36 | public class Compiler_VB : CILCompiler, IScriptCompiler | ||
37 | { | ||
38 | |||
39 | public Compiler_VB() | ||
40 | { | ||
41 | CompileProvider = new VBCodeProvider() as CodeDomProvider; | ||
42 | } | ||
43 | |||
44 | public override string PreProcessScript(ref string script) | ||
45 | { | ||
46 | return | ||
47 | "Imports OpenSim.Region.ScriptEngine.Shared: Imports System.Collections.Generic: " + | ||
48 | String.Empty + "NameSpace SecondLife:" + | ||
49 | String.Empty + "Public Class Script: Inherits OpenSim.Region.ScriptEngine.Shared.ScriptBase.ScriptBaseClass: " + | ||
50 | "\r\nPublic Sub New()\r\nEnd Sub: " + | ||
51 | script + | ||
52 | ":End Class :End Namespace\r\n"; | ||
53 | } | ||
54 | } | ||
55 | } | ||
56 | |||
diff --git a/OpenSim/ScriptEngine/Components/DotNetEngine/Compilers/Compiler_YP.cs b/OpenSim/ScriptEngine/Components/DotNetEngine/Compilers/Compiler_YP.cs deleted file mode 100644 index dce17ad..0000000 --- a/OpenSim/ScriptEngine/Components/DotNetEngine/Compilers/Compiler_YP.cs +++ /dev/null | |||
@@ -1,55 +0,0 @@ | |||
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 OpenSimulator 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 | using System; | ||
28 | using System.Collections.Generic; | ||
29 | using System.Reflection; | ||
30 | using System.Text; | ||
31 | using OpenSim.ScriptEngine.Components.DotNetEngine.Compilers.YP; | ||
32 | using OpenSim.ScriptEngine.Shared; | ||
33 | |||
34 | namespace OpenSim.ScriptEngine.Components.DotNetEngine.Compilers | ||
35 | { | ||
36 | public class Compiler_YP: IScriptCompiler | ||
37 | { | ||
38 | |||
39 | private readonly Compiler_CS m_Compiler_CS = new Compiler_CS(); | ||
40 | |||
41 | public string Compile(ScriptMetaData scriptMetaData, ref string script) | ||
42 | { | ||
43 | // Convert script to CS | ||
44 | string scriptCS = YP2CS.Convert(ref script); | ||
45 | // Use CS compiler to compile it | ||
46 | return m_Compiler_CS.Compile(scriptMetaData, ref scriptCS); | ||
47 | } | ||
48 | |||
49 | public string PreProcessScript(ref string script) | ||
50 | { | ||
51 | // This is handled by our converter | ||
52 | return script; | ||
53 | } | ||
54 | } | ||
55 | } | ||
diff --git a/OpenSim/ScriptEngine/Components/DotNetEngine/Compilers/LSL/LSL2CS.cs b/OpenSim/ScriptEngine/Components/DotNetEngine/Compilers/LSL/LSL2CS.cs deleted file mode 100644 index d4af1c7..0000000 --- a/OpenSim/ScriptEngine/Components/DotNetEngine/Compilers/LSL/LSL2CS.cs +++ /dev/null | |||
@@ -1,44 +0,0 @@ | |||
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 OpenSimulator 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 | using System; | ||
28 | using System.Collections.Generic; | ||
29 | using System.Text; | ||
30 | using OpenSim.Region.ScriptEngine.Shared.CodeTools; | ||
31 | |||
32 | namespace OpenSim.ScriptEngine.Components.DotNetEngine.Compilers.LSL | ||
33 | { | ||
34 | public class LSL2CS | ||
35 | { | ||
36 | private ICodeConverter Converter = new CSCodeGenerator(); | ||
37 | |||
38 | public string Convert(ref string script) | ||
39 | { | ||
40 | //m_positionMap = ((CSCodeGenerator) LSL_Converter).PositionMap; | ||
41 | return Converter.Convert(script); | ||
42 | } | ||
43 | } | ||
44 | } | ||
diff --git a/OpenSim/ScriptEngine/Components/DotNetEngine/Compilers/Properties/AssemblyInfo.cs b/OpenSim/ScriptEngine/Components/DotNetEngine/Compilers/Properties/AssemblyInfo.cs deleted file mode 100644 index dedc48e..0000000 --- a/OpenSim/ScriptEngine/Components/DotNetEngine/Compilers/Properties/AssemblyInfo.cs +++ /dev/null | |||
@@ -1,63 +0,0 @@ | |||
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 OpenSimulator 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 | using System.Reflection; | ||
29 | using System.Runtime.CompilerServices; | ||
30 | using System.Runtime.InteropServices; | ||
31 | |||
32 | // General Information about an assembly is controlled through the following | ||
33 | // set of attributes. Change these attribute values to modify the information | ||
34 | // associated with an assembly. | ||
35 | [assembly: AssemblyTitle("OpenSim.ScriptEngine.Components.DotNetEngine.Compilers")] | ||
36 | [assembly: AssemblyDescription("")] | ||
37 | [assembly: AssemblyConfiguration("")] | ||
38 | [assembly: AssemblyCompany("http://opensimulator.org")] | ||
39 | [assembly: AssemblyProduct("OpenSim.ScriptEngine.Components.DotNetEngine.Compilers")] | ||
40 | [assembly: AssemblyCopyright("Copyright © Microsoft 2008")] | ||
41 | [assembly: AssemblyTrademark("")] | ||
42 | [assembly: AssemblyCulture("")] | ||
43 | |||
44 | // Setting ComVisible to false makes the types in this assembly not visible | ||
45 | // to COM components. If you need to access a type in this assembly from | ||
46 | // COM, set the ComVisible attribute to true on that type. | ||
47 | [assembly: ComVisible(false)] | ||
48 | |||
49 | // The following GUID is for the ID of the typelib if this project is exposed to COM | ||
50 | [assembly: Guid("ea77002b-c967-4368-ace9-6533f8147d4b")] | ||
51 | |||
52 | // Version information for an assembly consists of the following four values: | ||
53 | // | ||
54 | // Major Version | ||
55 | // Minor Version | ||
56 | // Build Number | ||
57 | // Revision | ||
58 | // | ||
59 | // You can specify all the values or you can default the Build and Revision Numbers | ||
60 | // by using the '*' as shown below: | ||
61 | // [assembly: AssemblyVersion("0.6.5.*")] | ||
62 | [assembly: AssemblyVersion("0.6.5.*")] | ||
63 | [assembly: AssemblyFileVersion("0.6.5.0")] | ||
diff --git a/OpenSim/ScriptEngine/Components/DotNetEngine/Compilers/YP/YP2CS.cs b/OpenSim/ScriptEngine/Components/DotNetEngine/Compilers/YP/YP2CS.cs deleted file mode 100644 index 10b5715..0000000 --- a/OpenSim/ScriptEngine/Components/DotNetEngine/Compilers/YP/YP2CS.cs +++ /dev/null | |||
@@ -1,54 +0,0 @@ | |||
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 OpenSimulator 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 | using System; | ||
28 | using System.Collections.Generic; | ||
29 | using System.Text; | ||
30 | |||
31 | namespace OpenSim.ScriptEngine.Components.DotNetEngine.Compilers.YP | ||
32 | { | ||
33 | public class YP2CS | ||
34 | { | ||
35 | public static string Convert(ref string script) | ||
36 | { | ||
37 | return script; | ||
38 | } | ||
39 | |||
40 | public string PreProcessScript(ref string script) | ||
41 | { | ||
42 | return | ||
43 | "using OpenSim.Region.ScriptEngine.Shared.YieldProlog; " + | ||
44 | "using OpenSim.Region.ScriptEngine.Shared; using System.Collections.Generic;\r\n" + | ||
45 | String.Empty + "namespace SecondLife { " + | ||
46 | String.Empty + "public class Script : OpenSim.Region.ScriptEngine.Shared.ScriptBase.ScriptBaseClass { \r\n" + | ||
47 | //@"public Script() { } " + | ||
48 | @"static OpenSim.Region.ScriptEngine.Shared.YieldProlog.YP YP=null; " + | ||
49 | @"public Script() { YP= new OpenSim.Region.ScriptEngine.Shared.YieldProlog.YP(); } " + | ||
50 | script + | ||
51 | "} }\r\n"; | ||
52 | } | ||
53 | } | ||
54 | } | ||
diff --git a/OpenSim/ScriptEngine/Components/DotNetEngine/Events/LSLEventProvider.cs b/OpenSim/ScriptEngine/Components/DotNetEngine/Events/LSLEventProvider.cs deleted file mode 100644 index 81dc62d..0000000 --- a/OpenSim/ScriptEngine/Components/DotNetEngine/Events/LSLEventProvider.cs +++ /dev/null | |||
@@ -1,121 +0,0 @@ | |||
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 OpenSimulator 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 | using System; | ||
28 | using System.Collections.Generic; | ||
29 | using System.Text; | ||
30 | using OpenMetaverse; | ||
31 | using OpenSim.Framework; | ||
32 | using OpenSim.Region.Framework.Scenes; | ||
33 | using OpenSim.Region.ScriptEngine.Shared; | ||
34 | using OpenSim.ScriptEngine.Shared; | ||
35 | using EventParams = OpenSim.ScriptEngine.Shared.EventParams; | ||
36 | |||
37 | namespace OpenSim.ScriptEngine.Components.DotNetEngine.Events | ||
38 | { | ||
39 | public class LSLEventProvider : IScriptEventProvider | ||
40 | { | ||
41 | public delegate void RezScriptDelegate(uint localID, UUID itemID, string script, int startParam, bool postOnRez, | ||
42 | string engine); | ||
43 | public event RezScriptDelegate RezScript; | ||
44 | public delegate void RemoveScriptDelegate(uint localID, UUID itemID); | ||
45 | public event RemoveScriptDelegate RemoveScript; | ||
46 | public delegate void ScriptChangedDelegate(uint localID, uint change); | ||
47 | public event ScriptChangedDelegate ScriptChanged; | ||
48 | |||
49 | private RegionInfoStructure CurrentRegion; | ||
50 | public void Initialize(RegionInfoStructure currentRegion) | ||
51 | { | ||
52 | CurrentRegion = currentRegion; | ||
53 | HookupEvents(); | ||
54 | } | ||
55 | |||
56 | private void HookupEvents() | ||
57 | { | ||
58 | CurrentRegion.Scene.EventManager.OnObjectGrab += OnObjectGrab; | ||
59 | CurrentRegion.Scene.EventManager.OnRezScript += OnRezScript; | ||
60 | CurrentRegion.Scene.EventManager.OnRemoveScript += OnRemoveScript; | ||
61 | CurrentRegion.Scene.EventManager.OnScriptChangedEvent += OnScriptChangedEvent; | ||
62 | |||
63 | |||
64 | } | ||
65 | |||
66 | private void OnScriptChangedEvent(uint localID, uint change) | ||
67 | { | ||
68 | // Script is being changed, fire event | ||
69 | if (ScriptChanged != null) | ||
70 | ScriptChanged(localID, change); | ||
71 | } | ||
72 | |||
73 | private void OnRemoveScript(uint localID, UUID itemID) | ||
74 | { | ||
75 | // Script is being removed, fire event | ||
76 | if (RemoveScript != null) | ||
77 | RemoveScript(localID, itemID); | ||
78 | } | ||
79 | |||
80 | private void OnRezScript(uint localID, UUID itemID, string script, int startParam, bool postOnRez, string engine, int stateSource) | ||
81 | { | ||
82 | // New script being created, fire event | ||
83 | if (RezScript != null) | ||
84 | RezScript(localID, itemID, script, startParam, postOnRez, engine); | ||
85 | } | ||
86 | |||
87 | private void OnObjectGrab(uint localID, uint originalID, Vector3 offsetPos, IClientAPI remoteClient, SurfaceTouchEventArgs surfaceArgs) | ||
88 | { | ||
89 | // Add to queue for all scripts in ObjectID object | ||
90 | DetectParams[] det = new DetectParams[1]; | ||
91 | det[0] = new DetectParams(); | ||
92 | det[0].Key = remoteClient.AgentId; | ||
93 | //det[0].Populate(World); | ||
94 | |||
95 | if (originalID == 0) | ||
96 | { | ||
97 | SceneObjectPart part = | ||
98 | CurrentRegion.Scene.GetSceneObjectPart(localID); | ||
99 | |||
100 | if (part == null) | ||
101 | return; | ||
102 | |||
103 | det[0].LinkNum = part.LinkNum; | ||
104 | } | ||
105 | else | ||
106 | { | ||
107 | SceneObjectPart originalPart = | ||
108 | CurrentRegion.Scene.GetSceneObjectPart(originalID); | ||
109 | det[0].LinkNum = originalPart.LinkNum; | ||
110 | } | ||
111 | if (surfaceArgs != null) | ||
112 | { | ||
113 | det[0].SurfaceTouchArgs = surfaceArgs; | ||
114 | } | ||
115 | Shared.EventParams ep = | ||
116 | new Shared.EventParams(localID, "touch_start", new Object[] {new LSL_Types.LSLInteger(1)}, det); | ||
117 | CurrentRegion.Executors_Execute(ep); | ||
118 | |||
119 | } | ||
120 | } | ||
121 | } | ||
diff --git a/OpenSim/ScriptEngine/Components/DotNetEngine/Events/Properties/AssemblyInfo.cs b/OpenSim/ScriptEngine/Components/DotNetEngine/Events/Properties/AssemblyInfo.cs deleted file mode 100644 index 299304a..0000000 --- a/OpenSim/ScriptEngine/Components/DotNetEngine/Events/Properties/AssemblyInfo.cs +++ /dev/null | |||
@@ -1,63 +0,0 @@ | |||
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 OpenSimulator 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 | using System.Reflection; | ||
29 | using System.Runtime.CompilerServices; | ||
30 | using System.Runtime.InteropServices; | ||
31 | |||
32 | // General Information about an assembly is controlled through the following | ||
33 | // set of attributes. Change these attribute values to modify the information | ||
34 | // associated with an assembly. | ||
35 | [assembly: AssemblyTitle("OpenSim.ScriptEngine.Components.DotNetEngine.Scheduler")] | ||
36 | [assembly: AssemblyDescription("")] | ||
37 | [assembly: AssemblyConfiguration("")] | ||
38 | [assembly: AssemblyCompany("http://opensimulator.org")] | ||
39 | [assembly: AssemblyProduct("OpenSim.ScriptEngine.Components.DotNetEngine.Scheduler")] | ||
40 | [assembly: AssemblyCopyright("Copyright © Microsoft 2008")] | ||
41 | [assembly: AssemblyTrademark("")] | ||
42 | [assembly: AssemblyCulture("")] | ||
43 | |||
44 | // Setting ComVisible to false makes the types in this assembly not visible | ||
45 | // to COM components. If you need to access a type in this assembly from | ||
46 | // COM, set the ComVisible attribute to true on that type. | ||
47 | [assembly: ComVisible(false)] | ||
48 | |||
49 | // The following GUID is for the ID of the typelib if this project is exposed to COM | ||
50 | [assembly: Guid("ea77002b-c967-4368-ace9-6533f8147d4b")] | ||
51 | |||
52 | // Version information for an assembly consists of the following four values: | ||
53 | // | ||
54 | // Major Version | ||
55 | // Minor Version | ||
56 | // Build Number | ||
57 | // Revision | ||
58 | // | ||
59 | // You can specify all the values or you can default the Build and Revision Numbers | ||
60 | // by using the '*' as shown below: | ||
61 | // [assembly: AssemblyVersion("0.6.5.*")] | ||
62 | [assembly: AssemblyVersion("0.6.5.*")] | ||
63 | [assembly: AssemblyFileVersion("0.6.5.0")] | ||
diff --git a/OpenSim/ScriptEngine/Components/DotNetEngine/Scheduler/BaseClassFactory.cs b/OpenSim/ScriptEngine/Components/DotNetEngine/Scheduler/BaseClassFactory.cs deleted file mode 100644 index afa2300..0000000 --- a/OpenSim/ScriptEngine/Components/DotNetEngine/Scheduler/BaseClassFactory.cs +++ /dev/null | |||
@@ -1,240 +0,0 @@ | |||
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 OpenSimulator 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 | using System; | ||
29 | using System.Collections.Generic; | ||
30 | using System.IO; | ||
31 | using System.Reflection; | ||
32 | using System.Reflection.Emit; | ||
33 | using System.Text; | ||
34 | using OpenSim.ScriptEngine.Shared; | ||
35 | |||
36 | namespace OpenSim.ScriptEngine.Components.DotNetEngine.Scheduler | ||
37 | { | ||
38 | public class BaseClassFactory | ||
39 | { | ||
40 | |||
41 | |||
42 | public static void MakeBaseClass(ScriptStructure script) | ||
43 | { | ||
44 | string asmName = "ScriptAssemblies"; | ||
45 | string ModuleID = asmName; | ||
46 | string ClassID = "Script"; | ||
47 | string moveToDir = "ScriptEngines"; | ||
48 | string asmFileName = ModuleID + "_" + ClassID + ".dll"; | ||
49 | if (!Directory.Exists(moveToDir)) | ||
50 | Directory.CreateDirectory(moveToDir); | ||
51 | |||
52 | ILGenerator ilgen; | ||
53 | AssemblyBuilder asmBuilder = AppDomain.CurrentDomain.DefineDynamicAssembly( | ||
54 | new AssemblyName(asmName), AssemblyBuilderAccess.RunAndSave); | ||
55 | |||
56 | // The module builder | ||
57 | ModuleBuilder modBuilder = asmBuilder.DefineDynamicModule(ModuleID, asmFileName); | ||
58 | |||
59 | // The class builder | ||
60 | TypeBuilder classBuilder = modBuilder.DefineType(ClassID, TypeAttributes.Class | TypeAttributes.Public); | ||
61 | |||
62 | // The default constructor | ||
63 | //ConstructorBuilder ctorBuilder = classBuilder.DefineDefaultConstructor(MethodAttributes.Public); | ||
64 | |||
65 | |||
66 | Type[] paramsTypeArray = new Type[] {typeof (System.ParamArrayAttribute)}; | ||
67 | Type[] executeFunctionTypeArray = new Type[] {typeof (string), typeof (System.ParamArrayAttribute)}; | ||
68 | foreach (IScriptCommandProvider cp in script.RegionInfo.CommandProviders.Values) | ||
69 | { | ||
70 | Type t = cp.GetType(); | ||
71 | foreach (MethodInfo mi in t.GetMethods()) | ||
72 | { | ||
73 | MethodBuilder methodBuilder = classBuilder.DefineMethod(mi.Name, mi.Attributes, mi.GetType(), Type.EmptyTypes); | ||
74 | methodBuilder.SetParameters(paramsTypeArray); | ||
75 | //ParameterBuilder paramBuilder = methodBuilder.DefineParameter(1, ParameterAttributes.None, "args"); | ||
76 | |||
77 | ilgen = methodBuilder.GetILGenerator(); | ||
78 | //ilgen.Emit(OpCodes.Nop); | ||
79 | //ilgen.Emit(OpCodes.Ldarg_0); | ||
80 | //ilgen.Emit(OpCodes.Ldc_I4_0); | ||
81 | //ilgen.Emit(OpCodes.Ldelem_Ref); | ||
82 | //ilgen.MarkSequencePoint(doc, 6, 1, 6, 100); | ||
83 | |||
84 | //MethodInfo ExecuteFunction = typeof(ScriptAssemblies.IScript).GetMethod( | ||
85 | // "ExecuteFunction", | ||
86 | // executeFunctionTypeArray); | ||
87 | |||
88 | ilgen.DeclareLocal(typeof(string)); | ||
89 | ilgen.Emit(OpCodes.Nop); | ||
90 | ilgen.Emit(OpCodes.Ldstr, mi.Name); | ||
91 | ilgen.Emit(OpCodes.Stloc_0); | ||
92 | ilgen.Emit(OpCodes.Ldarg_0); | ||
93 | ilgen.Emit(OpCodes.Ldloc_0); | ||
94 | ilgen.Emit(OpCodes.Ldarg_1); | ||
95 | |||
96 | // FieldInfo testInfo = classBuilder. | ||
97 | //BindingFlags.NonPublic | BindingFlags.Instance); | ||
98 | |||
99 | //ilgen.Emit(OpCodes.Ldfld, testInfo); | ||
100 | |||
101 | //ilgen.EmitCall(OpCodes.Call, ExecuteFunction, executeFunctionTypeArray); | ||
102 | ilgen.EmitCall(OpCodes.Call, typeof(System.Console).GetMethod("WriteLine"), executeFunctionTypeArray); | ||
103 | |||
104 | // // string.Format("Hello, {0} World!", toWhom) | ||
105 | // // | ||
106 | // ilgen.Emit(OpCodes.Ldstr, "Hello, {0} World!"); | ||
107 | // ilgen.Emit(OpCodes.Ldarg_1); | ||
108 | // ilgen.Emit(OpCodes.Call, typeof(string).GetMethod | ||
109 | //("Format", new Type[] { typeof(string), typeof(object) })); | ||
110 | |||
111 | // // m_log.Debug("Hello, World!"); | ||
112 | // // | ||
113 | // ilgen.Emit(OpCodes.Call, typeof(Console).GetMethod | ||
114 | // ("WriteLine", new Type[] { typeof(string) })); | ||
115 | ilgen.Emit(OpCodes.Ret); | ||
116 | |||
117 | |||
118 | |||
119 | //Label eom = ilgen.DefineLabel(); | ||
120 | //ilgen.Emit(OpCodes.Br_S, eom); | ||
121 | //ilgen.MarkLabel(eom); | ||
122 | //ilgen.Emit(OpCodes.Ret); | ||
123 | //Type test = methodBuilder.SetParameters(); | ||
124 | |||
125 | |||
126 | //methodBuilder.SetParameters(typeof (object[])); | ||
127 | |||
128 | |||
129 | } | ||
130 | } | ||
131 | |||
132 | |||
133 | //// Two fields: m_firstname, m_lastname | ||
134 | //FieldBuilder fBuilderFirstName = classBuilder.DefineField("m_firstname", typeof(string), FieldAttributes.Private); | ||
135 | //FieldBuilder fBuilderLastName = classBuilder.DefineField("m_lastname", typeof(string), FieldAttributes.Private); | ||
136 | |||
137 | //// Two properties for this object: FirstName, LastName | ||
138 | //PropertyBuilder pBuilderFirstName = classBuilder.DefineProperty("FirstName", System.Reflection.PropertyAttributes.HasDefault, typeof(string), null); | ||
139 | //PropertyBuilder pBuilderLastName = classBuilder.DefineProperty("LastName", System.Reflection.PropertyAttributes.HasDefault, typeof(string), null); | ||
140 | |||
141 | //// Custom attributes for get, set accessors | ||
142 | //MethodAttributes getSetAttr = MethodAttributes.Public | MethodAttributes.HideBySig | MethodAttributes.SpecialName; | ||
143 | |||
144 | //// get,set accessors for FirstName | ||
145 | //MethodBuilder mGetFirstNameBuilder = classBuilder.DefineMethod("get_FirstName", getSetAttr, typeof(string), Type.EmptyTypes); | ||
146 | |||
147 | //// Code generation | ||
148 | //ilgen = mGetFirstNameBuilder.GetILGenerator(); | ||
149 | //ilgen.Emit(OpCodes.Ldarg_0); | ||
150 | //ilgen.Emit(OpCodes.Ldfld, fBuilderFirstName); // returning the firstname field | ||
151 | //ilgen.Emit(OpCodes.Ret); | ||
152 | |||
153 | //MethodBuilder mSetFirstNameBuilder = classBuilder.DefineMethod("set_FirstName", getSetAttr, null, new Type[] { typeof(string) }); | ||
154 | |||
155 | //// Code generation | ||
156 | //ilgen = mSetFirstNameBuilder.GetILGenerator(); | ||
157 | //ilgen.Emit(OpCodes.Ldarg_0); | ||
158 | //ilgen.Emit(OpCodes.Ldarg_1); | ||
159 | //ilgen.Emit(OpCodes.Stfld, fBuilderFirstName); // setting the firstname field from the first argument (1) | ||
160 | //ilgen.Emit(OpCodes.Ret); | ||
161 | |||
162 | //// get,set accessors for LastName | ||
163 | //MethodBuilder mGetLastNameBuilder = classBuilder.DefineMethod("get_LastName", getSetAttr, typeof(string), Type.EmptyTypes); | ||
164 | |||
165 | //// Code generation | ||
166 | //ilgen = mGetLastNameBuilder.GetILGenerator(); | ||
167 | //ilgen.Emit(OpCodes.Ldarg_0); | ||
168 | //ilgen.Emit(OpCodes.Ldfld, fBuilderLastName); // returning the firstname field | ||
169 | //ilgen.Emit(OpCodes.Ret); | ||
170 | |||
171 | //MethodBuilder mSetLastNameBuilder = classBuilder.DefineMethod("set_LastName", getSetAttr, null, new Type[] { typeof(string) }); | ||
172 | |||
173 | //// Code generation | ||
174 | //ilgen = mSetLastNameBuilder.GetILGenerator(); | ||
175 | //ilgen.Emit(OpCodes.Ldarg_0); | ||
176 | //ilgen.Emit(OpCodes.Ldarg_1); | ||
177 | //ilgen.Emit(OpCodes.Stfld, fBuilderLastName); // setting the firstname field from the first argument (1) | ||
178 | //ilgen.Emit(OpCodes.Ret); | ||
179 | |||
180 | //// Assigning get/set accessors | ||
181 | //pBuilderFirstName.SetGetMethod(mGetFirstNameBuilder); | ||
182 | //pBuilderFirstName.SetSetMethod(mSetFirstNameBuilder); | ||
183 | |||
184 | //pBuilderLastName.SetGetMethod(mGetLastNameBuilder); | ||
185 | //pBuilderLastName.SetSetMethod(mSetLastNameBuilder); | ||
186 | |||
187 | //// Now, a custom method named GetFullName that concatenates FirstName and LastName properties | ||
188 | //MethodBuilder mGetFullNameBuilder = classBuilder.DefineMethod("GetFullName", MethodAttributes.Public, typeof(string), Type.EmptyTypes); | ||
189 | |||
190 | //// Code generation | ||
191 | //ilgen = mGetFullNameBuilder.GetILGenerator(); | ||
192 | //ilgen.Emit(OpCodes.Ldarg_0); | ||
193 | //ilgen.Emit(OpCodes.Call, mGetFirstNameBuilder); // getting the firstname | ||
194 | //ilgen.Emit(OpCodes.Ldstr, " "); // an space | ||
195 | //ilgen.Emit(OpCodes.Ldarg_0); | ||
196 | //ilgen.Emit(OpCodes.Call, mGetLastNameBuilder); // getting the lastname | ||
197 | |||
198 | //// We need the 'Concat' method from string type | ||
199 | //MethodInfo concatMethod = typeof(String).GetMethod("Concat", new Type[] { typeof(string), typeof(string), typeof(string) }); | ||
200 | |||
201 | //ilgen.Emit(OpCodes.Call, concatMethod); // calling concat and returning the result | ||
202 | //ilgen.Emit(OpCodes.Ret); | ||
203 | |||
204 | //// Another constructor that initializes firstname and lastname | ||
205 | //ConstructorBuilder ctorBuilder2 = classBuilder.DefineConstructor(MethodAttributes.Public, CallingConventions.Standard, new Type[] { typeof(string), typeof(string) }); | ||
206 | //ctorBuilder2.DefineParameter(1, ParameterAttributes.In, "firstname"); | ||
207 | //ctorBuilder2.DefineParameter(2, ParameterAttributes.In, "lastname"); | ||
208 | |||
209 | //// Code generation | ||
210 | //ilgen = ctorBuilder2.GetILGenerator(); | ||
211 | |||
212 | //// First of all, we need to call the base constructor, | ||
213 | //// the Object's constructor in this sample | ||
214 | //Type objType = Type.GetType("System.Object"); | ||
215 | //ConstructorInfo objCtor = objType.GetConstructor(Type.EmptyTypes); | ||
216 | |||
217 | //ilgen.Emit(OpCodes.Ldarg_0); | ||
218 | //ilgen.Emit(OpCodes.Call, objCtor); // calling the Object's constructor | ||
219 | |||
220 | //ilgen.Emit(OpCodes.Ldarg_0); | ||
221 | //ilgen.Emit(OpCodes.Ldarg_1); | ||
222 | //ilgen.Emit(OpCodes.Call, mSetFirstNameBuilder); // setting the firstname field from the first argument (1) | ||
223 | //ilgen.Emit(OpCodes.Ldarg_0); | ||
224 | //ilgen.Emit(OpCodes.Ldarg_2); | ||
225 | //ilgen.Emit(OpCodes.Call, mSetLastNameBuilder); // setting the lastname field from the second argument (2) | ||
226 | //ilgen.Emit(OpCodes.Ret); | ||
227 | |||
228 | // Finally, create the type and save the assembly | ||
229 | classBuilder.CreateType(); | ||
230 | |||
231 | asmBuilder.Save(asmFileName); | ||
232 | string toFile = Path.Combine(moveToDir, asmFileName); | ||
233 | if (File.Exists(toFile)) | ||
234 | File.Delete(toFile); | ||
235 | File.Move(asmFileName, toFile); | ||
236 | |||
237 | //string a = ""; | ||
238 | } | ||
239 | } | ||
240 | } | ||
diff --git a/OpenSim/ScriptEngine/Components/DotNetEngine/Scheduler/LoadUnloadStructure.cs b/OpenSim/ScriptEngine/Components/DotNetEngine/Scheduler/LoadUnloadStructure.cs deleted file mode 100644 index 9468c18..0000000 --- a/OpenSim/ScriptEngine/Components/DotNetEngine/Scheduler/LoadUnloadStructure.cs +++ /dev/null | |||
@@ -1,49 +0,0 @@ | |||
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 OpenSimulator 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 | using System; | ||
29 | using System.Collections.Generic; | ||
30 | using System.Text; | ||
31 | using OpenSim.ScriptEngine.Shared; | ||
32 | |||
33 | namespace OpenSim.ScriptEngine.Components.DotNetEngine.Scheduler | ||
34 | { | ||
35 | public struct LoadUnloadStructure | ||
36 | { | ||
37 | public ScriptStructure Script; | ||
38 | public LUType Action; | ||
39 | public bool PostOnRez; | ||
40 | public int StartParam; | ||
41 | |||
42 | public enum LUType | ||
43 | { | ||
44 | Unknown = 0, | ||
45 | Load = 1, | ||
46 | Unload = 2 | ||
47 | } | ||
48 | } | ||
49 | } | ||
diff --git a/OpenSim/ScriptEngine/Components/DotNetEngine/Scheduler/Properties/AssemblyInfo.cs b/OpenSim/ScriptEngine/Components/DotNetEngine/Scheduler/Properties/AssemblyInfo.cs deleted file mode 100644 index 1831e50..0000000 --- a/OpenSim/ScriptEngine/Components/DotNetEngine/Scheduler/Properties/AssemblyInfo.cs +++ /dev/null | |||
@@ -1,63 +0,0 @@ | |||
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 OpenSimulator 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 | using System.Reflection; | ||
29 | using System.Runtime.CompilerServices; | ||
30 | using System.Runtime.InteropServices; | ||
31 | |||
32 | // General Information about an assembly is controlled through the following | ||
33 | // set of attributes. Change these attribute values to modify the information | ||
34 | // associated with an assembly. | ||
35 | [assembly: AssemblyTitle("OpenSim.Grid.ScriptEngine.Components.DefaultScheduler")] | ||
36 | [assembly: AssemblyDescription("")] | ||
37 | [assembly: AssemblyConfiguration("")] | ||
38 | [assembly: AssemblyCompany("http://opensimulator.org")] | ||
39 | [assembly: AssemblyProduct("OpenSim.Grid.ScriptEngine.Components.DefaultScheduler")] | ||
40 | [assembly: AssemblyCopyright("Copyright © Microsoft 2008")] | ||
41 | [assembly: AssemblyTrademark("")] | ||
42 | [assembly: AssemblyCulture("")] | ||
43 | |||
44 | // Setting ComVisible to false makes the types in this assembly not visible | ||
45 | // to COM components. If you need to access a type in this assembly from | ||
46 | // COM, set the ComVisible attribute to true on that type. | ||
47 | [assembly: ComVisible(false)] | ||
48 | |||
49 | // The following GUID is for the ID of the typelib if this project is exposed to COM | ||
50 | [assembly: Guid("ea77002b-c967-4368-ace9-6533f8147d4b")] | ||
51 | |||
52 | // Version information for an assembly consists of the following four values: | ||
53 | // | ||
54 | // Major Version | ||
55 | // Minor Version | ||
56 | // Build Number | ||
57 | // Revision | ||
58 | // | ||
59 | // You can specify all the values or you can default the Build and Revision Numbers | ||
60 | // by using the '*' as shown below: | ||
61 | // [assembly: AssemblyVersion("0.6.5.*")] | ||
62 | [assembly: AssemblyVersion("0.6.5.*")] | ||
63 | [assembly: AssemblyFileVersion("0.6.5.0")] | ||
diff --git a/OpenSim/ScriptEngine/Components/DotNetEngine/Scheduler/Scheduler.cs b/OpenSim/ScriptEngine/Components/DotNetEngine/Scheduler/Scheduler.cs deleted file mode 100644 index 8c36764..0000000 --- a/OpenSim/ScriptEngine/Components/DotNetEngine/Scheduler/Scheduler.cs +++ /dev/null | |||
@@ -1,55 +0,0 @@ | |||
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 OpenSimulator 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 | using System; | ||
28 | using System.Collections.Generic; | ||
29 | using System.Text; | ||
30 | using OpenMetaverse; | ||
31 | using OpenSim.ScriptEngine.Shared; | ||
32 | |||
33 | namespace OpenSim.ScriptEngine.Components.DotNetEngine.Scheduler | ||
34 | { | ||
35 | public class Scheduler : IScriptScheduler | ||
36 | { | ||
37 | |||
38 | private ScriptManager m_ScriptManager = new ScriptManager(); | ||
39 | public void AddScript(ScriptStructure scriptStructure) | ||
40 | { | ||
41 | m_ScriptManager.AddScript(scriptStructure); | ||
42 | } | ||
43 | |||
44 | public void Removecript(uint id, UUID itemID) | ||
45 | { | ||
46 | m_ScriptManager.RemoveScript(id, itemID); | ||
47 | } | ||
48 | |||
49 | public void Close() | ||
50 | { | ||
51 | m_ScriptManager.Close(); | ||
52 | } | ||
53 | |||
54 | } | ||
55 | } | ||
diff --git a/OpenSim/ScriptEngine/Components/DotNetEngine/Scheduler/ScriptLoader.cs b/OpenSim/ScriptEngine/Components/DotNetEngine/Scheduler/ScriptLoader.cs deleted file mode 100644 index 3c20f20..0000000 --- a/OpenSim/ScriptEngine/Components/DotNetEngine/Scheduler/ScriptLoader.cs +++ /dev/null | |||
@@ -1,216 +0,0 @@ | |||
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 OpenSimulator 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 | using System; | ||
28 | using System.Collections; | ||
29 | using System.Collections.Generic; | ||
30 | using System.Reflection; | ||
31 | using System.Text; | ||
32 | using log4net; | ||
33 | using OpenSim.ScriptEngine.Shared; | ||
34 | using IScript=OpenSim.Region.ScriptEngine.Shared.ScriptBase.IScript; | ||
35 | |||
36 | namespace OpenSim.ScriptEngine.Components.DotNetEngine.Scheduler | ||
37 | { | ||
38 | public class ScriptLoader : IScriptLoader | ||
39 | { | ||
40 | // | ||
41 | // This class does AppDomain handling and loading/unloading of | ||
42 | // scripts in it. It is instanced in "ScriptEngine" and controlled | ||
43 | // from "ScriptManager" | ||
44 | // | ||
45 | // 1. Create a new AppDomain if old one is full (or doesn't exist) | ||
46 | // 2. Load scripts into AppDomain | ||
47 | // 3. Unload scripts from AppDomain (stopping them and marking | ||
48 | // them as inactive) | ||
49 | // 4. Unload AppDomain completely when all scripts in it has stopped | ||
50 | // | ||
51 | |||
52 | public string Name { get { return "SECS.DotNetEngine.Scheduler.ScriptLoader"; } } | ||
53 | private int maxScriptsPerAppDomain = 10; | ||
54 | |||
55 | // Internal list of all AppDomains | ||
56 | private List<AppDomainStructure> appDomains = | ||
57 | new List<AppDomainStructure>(); | ||
58 | private Dictionary<string, AppDomainStructure> AppDomainFiles = new Dictionary<string, AppDomainStructure>(); | ||
59 | public readonly string[] AssembliesInAppDomain = new string[] { "OpenSim.ScriptEngine.Shared.Script.dll", "OpenSim.Region.ScriptEngine.Shared.dll" }; | ||
60 | |||
61 | internal static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
62 | |||
63 | // Structure to keep track of data around AppDomain | ||
64 | private class AppDomainStructure | ||
65 | { | ||
66 | public AppDomain CurrentAppDomain; // The AppDomain itself | ||
67 | public int ScriptsLoaded; // Number of scripts loaded into AppDomain | ||
68 | public int ScriptsWaitingUnload; // Number of dead scripts | ||
69 | } | ||
70 | |||
71 | // Current AppDomain | ||
72 | private AppDomainStructure currentAD; | ||
73 | |||
74 | private object getLock = new object(); // Mutex | ||
75 | private object freeLock = new object(); // Mutex | ||
76 | |||
77 | // Find a free AppDomain, creating one if necessary | ||
78 | private AppDomainStructure GetFreeAppDomain() | ||
79 | { | ||
80 | lock (getLock) | ||
81 | { | ||
82 | // Current full? | ||
83 | if (currentAD != null && | ||
84 | currentAD.ScriptsLoaded >= maxScriptsPerAppDomain) | ||
85 | { | ||
86 | // Add it to AppDomains list and empty current | ||
87 | appDomains.Add(currentAD); | ||
88 | currentAD = null; | ||
89 | } | ||
90 | // No current | ||
91 | if (currentAD == null) | ||
92 | { | ||
93 | // Create a new current AppDomain | ||
94 | currentAD = new AppDomainStructure(); | ||
95 | currentAD.CurrentAppDomain = PrepareNewAppDomain(); | ||
96 | } | ||
97 | |||
98 | return currentAD; | ||
99 | } | ||
100 | } | ||
101 | |||
102 | private int AppDomainNameCount; | ||
103 | public ScriptAssemblies.IScript LoadScript(ScriptStructure script) | ||
104 | { | ||
105 | // Find next available AppDomain to put it in | ||
106 | AppDomainStructure FreeAppDomain; | ||
107 | |||
108 | // If we already have loaded file, then reuse that AppDomains | ||
109 | if (AppDomainFiles.ContainsKey(script.AssemblyFileName)) | ||
110 | FreeAppDomain = AppDomainFiles[script.AssemblyFileName]; | ||
111 | else | ||
112 | FreeAppDomain = GetFreeAppDomain(); | ||
113 | |||
114 | // Set script object AppDomain | ||
115 | script.AppDomain = FreeAppDomain.CurrentAppDomain; | ||
116 | |||
117 | // Create instance of script | ||
118 | ScriptAssemblies.IScript mbrt = (ScriptAssemblies.IScript) | ||
119 | FreeAppDomain.CurrentAppDomain.CreateInstanceFromAndUnwrap( | ||
120 | script.AssemblyFileName, "ScriptAssemblies.Script"); | ||
121 | //, true, BindingFlags.CreateInstance, null); | ||
122 | FreeAppDomain.ScriptsLoaded++; | ||
123 | |||
124 | return mbrt; | ||
125 | } | ||
126 | |||
127 | // Create and prepare a new AppDomain for scripts | ||
128 | private AppDomain PrepareNewAppDomain() | ||
129 | { | ||
130 | // Create and prepare a new AppDomain | ||
131 | AppDomainNameCount++; | ||
132 | |||
133 | // TODO: Currently security match current appdomain | ||
134 | |||
135 | // Construct and initialize settings for a second AppDomain. | ||
136 | AppDomainSetup ads = new AppDomainSetup(); | ||
137 | ads.ApplicationBase = AppDomain.CurrentDomain.BaseDirectory; | ||
138 | ads.DisallowBindingRedirects = true; | ||
139 | ads.DisallowCodeDownload = true; | ||
140 | ads.LoaderOptimization = LoaderOptimization.MultiDomainHost; | ||
141 | ads.ShadowCopyFiles = "false"; // Disable shadowing | ||
142 | ads.ConfigurationFile = | ||
143 | AppDomain.CurrentDomain.SetupInformation.ConfigurationFile; | ||
144 | |||
145 | AppDomain AD = AppDomain.CreateDomain("ScriptAppDomain_" + | ||
146 | AppDomainNameCount, null, ads); | ||
147 | |||
148 | foreach (string file in AssembliesInAppDomain) | ||
149 | { | ||
150 | m_log.InfoFormat("[{0}] AppDomain Loading: \"{1}\"->\"{2}\".", Name, file, | ||
151 | AssemblyName.GetAssemblyName(file).ToString()); | ||
152 | AD.Load(AssemblyName.GetAssemblyName(file)); | ||
153 | } | ||
154 | |||
155 | // Return the new AppDomain | ||
156 | return AD; | ||
157 | } | ||
158 | |||
159 | // Unload appdomains that are full and have only dead scripts | ||
160 | private void UnloadAppDomains() | ||
161 | { | ||
162 | lock (freeLock) | ||
163 | { | ||
164 | // Go through all | ||
165 | foreach (AppDomainStructure ads in new ArrayList(appDomains)) | ||
166 | { | ||
167 | // Don't process current AppDomain | ||
168 | if (ads.CurrentAppDomain != currentAD.CurrentAppDomain) | ||
169 | { | ||
170 | // Not current AppDomain | ||
171 | // Is number of unloaded bigger or equal to number of loaded? | ||
172 | if (ads.ScriptsLoaded <= ads.ScriptsWaitingUnload) | ||
173 | { | ||
174 | // Remove from internal list | ||
175 | appDomains.Remove(ads); | ||
176 | |||
177 | // Unload | ||
178 | AppDomain.Unload(ads.CurrentAppDomain); | ||
179 | } | ||
180 | } | ||
181 | } | ||
182 | } | ||
183 | } | ||
184 | |||
185 | // Increase "dead script" counter for an AppDomain | ||
186 | public void StopScript(AppDomain ad) | ||
187 | { | ||
188 | lock (freeLock) | ||
189 | { | ||
190 | // Check if it is current AppDomain | ||
191 | if (currentAD.CurrentAppDomain == ad) | ||
192 | { | ||
193 | // Yes - increase | ||
194 | currentAD.ScriptsWaitingUnload++; | ||
195 | return; | ||
196 | } | ||
197 | |||
198 | // Lopp through all AppDomains | ||
199 | foreach (AppDomainStructure ads in new ArrayList(appDomains)) | ||
200 | { | ||
201 | if (ads.CurrentAppDomain == ad) | ||
202 | { | ||
203 | // Found it | ||
204 | ads.ScriptsWaitingUnload++; | ||
205 | break; | ||
206 | } | ||
207 | } | ||
208 | } | ||
209 | |||
210 | UnloadAppDomains(); // Outsite lock, has its own GetLock | ||
211 | } | ||
212 | |||
213 | |||
214 | |||
215 | } | ||
216 | } \ No newline at end of file | ||
diff --git a/OpenSim/ScriptEngine/Components/DotNetEngine/Scheduler/ScriptManager.cs b/OpenSim/ScriptEngine/Components/DotNetEngine/Scheduler/ScriptManager.cs deleted file mode 100644 index 3dad902..0000000 --- a/OpenSim/ScriptEngine/Components/DotNetEngine/Scheduler/ScriptManager.cs +++ /dev/null | |||
@@ -1,203 +0,0 @@ | |||
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 OpenSimulator 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 | using System; | ||
29 | using System.Collections.Generic; | ||
30 | using System.Diagnostics; | ||
31 | using System.Reflection; | ||
32 | using System.Text; | ||
33 | using System.Threading; | ||
34 | using log4net; | ||
35 | using OpenMetaverse; | ||
36 | using OpenSim.Region.ScriptEngine.Shared; | ||
37 | using OpenSim.ScriptEngine.Shared; | ||
38 | using EventParams=OpenSim.ScriptEngine.Shared.EventParams; | ||
39 | |||
40 | namespace OpenSim.ScriptEngine.Components.DotNetEngine.Scheduler | ||
41 | { | ||
42 | public partial class ScriptManager: IScriptExecutor | ||
43 | { | ||
44 | private const int NoWorkSleepMs = 50; | ||
45 | private const int NoWorkSleepMsInc = 1; // How much time to increase wait with on every iteration | ||
46 | private const int NoWorkSleepMsIncMax = 300; // Max time to wait | ||
47 | |||
48 | internal static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
49 | public string Name { get { return "SECS.DotNetEngine.ScriptManager"; } } | ||
50 | private static Thread ScriptLoadUnloadThread; | ||
51 | public Dictionary<uint, Dictionary<UUID, ScriptStructure>> Scripts = new Dictionary<uint, Dictionary<UUID, ScriptStructure>>(); | ||
52 | |||
53 | private RegionInfoStructure CurrentRegion; | ||
54 | public void Initialize(RegionInfoStructure currentRegion) | ||
55 | { | ||
56 | CurrentRegion = currentRegion; | ||
57 | } | ||
58 | |||
59 | public ScriptManager() | ||
60 | { | ||
61 | ScriptLoadUnloadThread = new Thread(LoadUnloadLoop); | ||
62 | ScriptLoadUnloadThread.Name = "ScriptLoadUnloadThread"; | ||
63 | ScriptLoadUnloadThread.IsBackground = true; | ||
64 | ScriptLoadUnloadThread.Start(); | ||
65 | } | ||
66 | public void Close() { } | ||
67 | |||
68 | private void LoadUnloadLoop () | ||
69 | { | ||
70 | int _NoWorkSleepMsInc = 0; | ||
71 | while (true) | ||
72 | { | ||
73 | if (DoScriptLoadUnload()) | ||
74 | { | ||
75 | // We found work, reset counter | ||
76 | _NoWorkSleepMsInc = NoWorkSleepMs; | ||
77 | } else | ||
78 | { | ||
79 | // We didn't find work | ||
80 | // Sleep | ||
81 | Thread.Sleep(NoWorkSleepMs + NoWorkSleepMsInc); | ||
82 | // Increase sleep delay | ||
83 | _NoWorkSleepMsInc += NoWorkSleepMsInc; | ||
84 | // Make sure we don't exceed max | ||
85 | if (_NoWorkSleepMsInc > NoWorkSleepMsIncMax) | ||
86 | _NoWorkSleepMsInc = NoWorkSleepMsIncMax; | ||
87 | } | ||
88 | } | ||
89 | } | ||
90 | |||
91 | #region Add/Remove/Find script functions for our Script memory structure | ||
92 | private void MemAddScript(ScriptStructure script) | ||
93 | { | ||
94 | lock (scriptLock) | ||
95 | { | ||
96 | // Create object if it doesn't exist | ||
97 | if (!Scripts.ContainsKey(script.LocalID)) | ||
98 | Scripts.Add(script.LocalID, new Dictionary<UUID, ScriptStructure>()); | ||
99 | |||
100 | // Delete script if it exists | ||
101 | Dictionary<UUID, ScriptStructure> Obj; | ||
102 | if (Scripts.TryGetValue(script.LocalID, out Obj)) | ||
103 | if (Obj.ContainsKey(script.ItemID) == true) | ||
104 | Obj.Remove(script.ItemID); | ||
105 | |||
106 | // Add to object | ||
107 | Obj.Add(script.ItemID, script); | ||
108 | } | ||
109 | } | ||
110 | private void MemRemoveScript(uint LocalID, UUID ItemID) | ||
111 | { | ||
112 | // TODO: Also clean up command queue and async commands for object | ||
113 | lock (scriptLock) | ||
114 | { | ||
115 | // Create object if it doesn't exist | ||
116 | if (!Scripts.ContainsKey(LocalID)) | ||
117 | return; | ||
118 | |||
119 | // Delete script if it exists | ||
120 | Dictionary<UUID, ScriptStructure> Obj; | ||
121 | if (Scripts.TryGetValue(LocalID, out Obj)) | ||
122 | if (Obj.ContainsKey(ItemID) == true) | ||
123 | Obj.Remove(ItemID); | ||
124 | |||
125 | // Empty? | ||
126 | if (Obj.Count == 0) | ||
127 | Scripts.Remove(LocalID); | ||
128 | |||
129 | } | ||
130 | } | ||
131 | public bool TryGetScript(uint localID, UUID itemID, ref ScriptStructure script) | ||
132 | { | ||
133 | lock (scriptLock) | ||
134 | { | ||
135 | |||
136 | if (Scripts.ContainsKey(localID) == false) | ||
137 | return false; | ||
138 | |||
139 | Dictionary<UUID, ScriptStructure> Obj; | ||
140 | if (Scripts.TryGetValue(localID, out Obj)) | ||
141 | if (Obj.ContainsKey(itemID) == false) | ||
142 | return false; | ||
143 | |||
144 | // Get script | ||
145 | return Obj.TryGetValue(itemID, out script); | ||
146 | } | ||
147 | } | ||
148 | public ScriptStructure GetScript(uint localID, UUID itemID) | ||
149 | { | ||
150 | lock (scriptLock) | ||
151 | { | ||
152 | |||
153 | if (Scripts.ContainsKey(localID) == false) | ||
154 | throw new Exception("No script with LocalID " + localID + " was found."); | ||
155 | |||
156 | Dictionary<UUID, ScriptStructure> Obj; | ||
157 | if (Scripts.TryGetValue(localID, out Obj)) | ||
158 | if (Obj.ContainsKey(itemID) == false) | ||
159 | throw new Exception("No script with ItemID " + itemID + " was found."); | ||
160 | |||
161 | // Get script | ||
162 | return Obj[itemID]; | ||
163 | } | ||
164 | } | ||
165 | public bool TryGetScripts(uint localID, ref Dictionary<UUID, ScriptStructure> returnList) | ||
166 | { | ||
167 | Dictionary<UUID, ScriptStructure> getList = GetScripts(localID); | ||
168 | if (getList != null) | ||
169 | { | ||
170 | returnList = getList; | ||
171 | return true; | ||
172 | } | ||
173 | return false; | ||
174 | } | ||
175 | public Dictionary<UUID, ScriptStructure> GetScripts(uint localID) | ||
176 | { | ||
177 | lock (scriptLock) | ||
178 | { | ||
179 | |||
180 | if (Scripts.ContainsKey(localID) == false) | ||
181 | return null; | ||
182 | return Scripts[localID]; | ||
183 | } | ||
184 | } | ||
185 | #endregion | ||
186 | |||
187 | public void ExecuteCommand(EventParams p) | ||
188 | { | ||
189 | ScriptStructure ss = new ScriptStructure(); | ||
190 | if (TryGetScript(p.LocalID, p.ItemID, ref ss)) | ||
191 | ExecuteCommand(ref ss, p); | ||
192 | } | ||
193 | |||
194 | public void ExecuteCommand(ref ScriptStructure scriptContainer, EventParams p) | ||
195 | { | ||
196 | m_log.DebugFormat("[{0}] ######################################################", Name); | ||
197 | m_log.DebugFormat("[{0}] Command execution ItemID {1}: \"{2}\".", Name, scriptContainer.ItemID, p.EventName); | ||
198 | scriptContainer.ExecuteEvent(p); | ||
199 | m_log.DebugFormat("[{0}] ######################################################", Name); | ||
200 | } | ||
201 | |||
202 | } | ||
203 | } | ||
diff --git a/OpenSim/ScriptEngine/Components/DotNetEngine/Scheduler/ScriptManager_ScriptLoadUnload.cs b/OpenSim/ScriptEngine/Components/DotNetEngine/Scheduler/ScriptManager_ScriptLoadUnload.cs deleted file mode 100644 index dd72dbf..0000000 --- a/OpenSim/ScriptEngine/Components/DotNetEngine/Scheduler/ScriptManager_ScriptLoadUnload.cs +++ /dev/null | |||
@@ -1,287 +0,0 @@ | |||
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 OpenSimulator 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 | using System; | ||
29 | using System.Collections.Generic; | ||
30 | using System.Globalization; | ||
31 | using System.Reflection; | ||
32 | using System.Text; | ||
33 | using System.Threading; | ||
34 | using log4net; | ||
35 | using OpenMetaverse; | ||
36 | using OpenSim.Framework; | ||
37 | using OpenSim.Region.Framework.Scenes; | ||
38 | using OpenSim.Region.ScriptEngine.Interfaces; | ||
39 | using OpenSim.Region.ScriptEngine.Shared.ScriptBase; | ||
40 | using OpenSim.ScriptEngine.Shared; | ||
41 | |||
42 | namespace OpenSim.ScriptEngine.Components.DotNetEngine.Scheduler | ||
43 | { | ||
44 | public partial class ScriptManager | ||
45 | { | ||
46 | private Queue<LoadUnloadStructure> LUQueue = new Queue<LoadUnloadStructure>(); | ||
47 | private int LoadUnloadMaxQueueSize = 500; | ||
48 | private Object scriptLock = new Object(); | ||
49 | //private Dictionary<InstanceData, DetectParams[]> detparms = new Dictionary<InstanceData, DetectParams[]>(); | ||
50 | |||
51 | // Load/Unload structure | ||
52 | |||
53 | |||
54 | public void AddScript(ScriptStructure script) | ||
55 | { | ||
56 | lock (LUQueue) | ||
57 | { | ||
58 | if ((LUQueue.Count >= LoadUnloadMaxQueueSize)) | ||
59 | { | ||
60 | m_log.ErrorFormat("[{0}] ERROR: Load queue count is at {1} of max {2}. Ignoring load request for script LocalID: {3}, ItemID: {4}.", | ||
61 | Name, LUQueue.Count, LoadUnloadMaxQueueSize, script.LocalID, script.ItemID); | ||
62 | return; | ||
63 | } | ||
64 | |||
65 | LoadUnloadStructure ls = new LoadUnloadStructure(); | ||
66 | ls.Script = script; | ||
67 | ls.Action = LoadUnloadStructure.LUType.Load; | ||
68 | LUQueue.Enqueue(ls); | ||
69 | } | ||
70 | |||
71 | } | ||
72 | public void RemoveScript(uint localID, UUID itemID) | ||
73 | { | ||
74 | LoadUnloadStructure ls = new LoadUnloadStructure(); | ||
75 | |||
76 | // See if we can find script | ||
77 | if (!TryGetScript(localID, itemID, ref ls.Script)) | ||
78 | { | ||
79 | // Set manually | ||
80 | ls.Script.LocalID = localID; | ||
81 | ls.Script.ItemID = itemID; | ||
82 | } | ||
83 | ls.Script.StartParam = 0; | ||
84 | |||
85 | ls.Action = LoadUnloadStructure.LUType.Unload; | ||
86 | ls.PostOnRez = false; | ||
87 | |||
88 | lock (LUQueue) | ||
89 | { | ||
90 | LUQueue.Enqueue(ls); | ||
91 | } | ||
92 | } | ||
93 | |||
94 | internal bool DoScriptLoadUnload() | ||
95 | { | ||
96 | bool ret = false; | ||
97 | // if (!m_started) | ||
98 | // return; | ||
99 | |||
100 | lock (LUQueue) | ||
101 | { | ||
102 | if (LUQueue.Count > 0) | ||
103 | { | ||
104 | LoadUnloadStructure item = LUQueue.Dequeue(); | ||
105 | ret = true; | ||
106 | |||
107 | if (item.Action == LoadUnloadStructure.LUType.Unload) | ||
108 | { | ||
109 | _StopScript(item.Script.LocalID, item.Script.ItemID); | ||
110 | RemoveScript(item.Script.LocalID, item.Script.ItemID); | ||
111 | } | ||
112 | else if (item.Action == LoadUnloadStructure.LUType.Load) | ||
113 | { | ||
114 | m_log.DebugFormat("[{0}] Loading script", Name); | ||
115 | _StartScript(item); | ||
116 | } | ||
117 | } | ||
118 | } | ||
119 | return ret; | ||
120 | } | ||
121 | |||
122 | //public void _StartScript(uint localID, UUID itemID, string Script, int startParam, bool postOnRez) | ||
123 | private void _StartScript(LoadUnloadStructure ScriptObject) | ||
124 | { | ||
125 | m_log.DebugFormat( | ||
126 | "[{0}]: ScriptManager StartScript: localID: {1}, itemID: {2}", | ||
127 | Name, ScriptObject.Script.LocalID, ScriptObject.Script.ItemID); | ||
128 | |||
129 | // We will initialize and start the script. | ||
130 | // It will be up to the script itself to hook up the correct events. | ||
131 | |||
132 | SceneObjectPart m_host = ScriptObject.Script.RegionInfo.Scene.GetSceneObjectPart(ScriptObject.Script.LocalID); | ||
133 | |||
134 | if (null == m_host) | ||
135 | { | ||
136 | m_log.ErrorFormat( | ||
137 | "[{0}]: Could not find scene object part corresponding " + | ||
138 | "to localID {1} to start script", | ||
139 | Name, ScriptObject.Script.LocalID); | ||
140 | |||
141 | return; | ||
142 | } | ||
143 | |||
144 | //UUID assetID = UUID.Zero; | ||
145 | TaskInventoryItem taskInventoryItem = new TaskInventoryItem(); | ||
146 | //if (m_host.TaskInventory.TryGetValue(ScriptObject.Script.ItemID, out taskInventoryItem)) | ||
147 | // assetID = taskInventoryItem.AssetID; | ||
148 | |||
149 | ScenePresence presence = | ||
150 | ScriptObject.Script.RegionInfo.Scene.GetScenePresence(taskInventoryItem.OwnerID); | ||
151 | |||
152 | CultureInfo USCulture = new CultureInfo("en-US"); | ||
153 | Thread.CurrentThread.CurrentCulture = USCulture; | ||
154 | |||
155 | try | ||
156 | { | ||
157 | // | ||
158 | // Compile script to an assembly | ||
159 | // | ||
160 | //TODO: DEBUG | ||
161 | BaseClassFactory.MakeBaseClass(ScriptObject.Script); | ||
162 | |||
163 | m_log.DebugFormat("[{0}] Compiling script {1}", Name, ScriptObject.Script.Name); | ||
164 | |||
165 | string fileName = ""; | ||
166 | try | ||
167 | { | ||
168 | IScriptCompiler compiler = | ||
169 | ScriptObject.Script.RegionInfo.FindCompiler(ScriptObject.Script.ScriptMetaData); | ||
170 | //RegionInfoStructure currentRegionInfo = ScriptObject.Script.RegionInfo; | ||
171 | fileName = compiler.Compile(ScriptObject.Script.ScriptMetaData, | ||
172 | ref ScriptObject.Script.Source); | ||
173 | ScriptObject.Script.AssemblyFileName = fileName; | ||
174 | } | ||
175 | catch (Exception e) | ||
176 | { | ||
177 | m_log.ErrorFormat("[{0}] Internal error while compiling \"{1}\": {2}", Name, ScriptObject.Script.Name, e.ToString()); | ||
178 | } | ||
179 | m_log.DebugFormat("[{0}] Compiled \"{1}\" to assembly: \"{2}\".", Name, ScriptObject.Script.Name, fileName); | ||
180 | |||
181 | // Add it to our script memstruct | ||
182 | MemAddScript(ScriptObject.Script); | ||
183 | |||
184 | ScriptAssemblies.IScript CompiledScript; | ||
185 | CompiledScript = CurrentRegion.ScriptLoader.LoadScript(ScriptObject.Script); | ||
186 | ScriptObject.Script.State = "default"; | ||
187 | ScriptObject.Script.ScriptObject = CompiledScript; | ||
188 | ScriptObject.Script.Disabled = false; | ||
189 | ScriptObject.Script.Running = true; | ||
190 | //id.LineMap = LSLCompiler.LineMap(); | ||
191 | //id.Script = CompiledScript; | ||
192 | //id.Source = item.Script.Script; | ||
193 | //item.StartParam = startParam; | ||
194 | |||
195 | |||
196 | |||
197 | // TODO: Fire the first start-event | ||
198 | //int eventFlags = | ||
199 | // m_scriptEngine.m_ScriptManager.GetStateEventFlags( | ||
200 | // localID, itemID); | ||
201 | |||
202 | //m_host.SetScriptEvents(itemID, eventFlags); | ||
203 | ScriptObject.Script.RegionInfo.Executors_Execute(ScriptObject.Script, | ||
204 | new EventParams(ScriptObject.Script.LocalID, ScriptObject.Script.ItemID, "state_entry", new object[] { }, new Region.ScriptEngine.Shared.DetectParams[0]) | ||
205 | ); | ||
206 | |||
207 | if (ScriptObject.PostOnRez) | ||
208 | { | ||
209 | ScriptObject.Script.RegionInfo.Executors_Execute(ScriptObject.Script, | ||
210 | new EventParams(ScriptObject.Script.LocalID, "on_rez", new object[] | ||
211 | {new Region.ScriptEngine.Shared.LSL_Types.LSLInteger(ScriptObject.StartParam) | ||
212 | }, new Region.ScriptEngine.Shared.DetectParams[0])); | ||
213 | } | ||
214 | } | ||
215 | catch (Exception e) // LEGIT: User Scripting | ||
216 | { | ||
217 | if (presence != null && (!ScriptObject.PostOnRez)) | ||
218 | presence.ControllingClient.SendAgentAlertMessage( | ||
219 | "Script saved with errors, check debug window!", | ||
220 | false); | ||
221 | try | ||
222 | { | ||
223 | // DISPLAY ERROR INWORLD | ||
224 | string text = "Error compiling script:\n" + | ||
225 | e.Message.ToString(); | ||
226 | if (text.Length > 1100) | ||
227 | text = text.Substring(0, 1099); | ||
228 | |||
229 | ScriptObject.Script.RegionInfo.Scene.SimChat(Utils.StringToBytes(text), | ||
230 | ChatTypeEnum.DebugChannel, 2147483647, | ||
231 | m_host.AbsolutePosition, m_host.Name, m_host.UUID, | ||
232 | false); | ||
233 | } | ||
234 | catch (Exception e2) // LEGIT: User Scripting | ||
235 | { | ||
236 | m_log.Error("[" + | ||
237 | Name + | ||
238 | "]: Error displaying error in-world: " + | ||
239 | e2.ToString()); | ||
240 | m_log.Error("[" + | ||
241 | Name + "]: " + | ||
242 | "Errormessage: Error compiling script:\r\n" + | ||
243 | e2.Message.ToString()); | ||
244 | } | ||
245 | } | ||
246 | } | ||
247 | |||
248 | |||
249 | |||
250 | public void _StopScript(uint localID, UUID itemID) | ||
251 | { | ||
252 | ScriptStructure ss = new ScriptStructure(); | ||
253 | if (!TryGetScript(localID, itemID, ref ss)) | ||
254 | return; | ||
255 | |||
256 | m_log.DebugFormat("[{0}] Unloading script", Name); | ||
257 | |||
258 | // Stop long command on script | ||
259 | //AsyncCommandManager.RemoveScript(ss); | ||
260 | |||
261 | try | ||
262 | { | ||
263 | // Get AppDomain | ||
264 | // Tell script not to accept new requests | ||
265 | ss.Running = false; | ||
266 | ss.Disabled = true; | ||
267 | //AppDomain ad = ss.AppDomain; | ||
268 | |||
269 | // Remove from internal structure | ||
270 | MemRemoveScript(localID, itemID); | ||
271 | |||
272 | // TODO: Tell AppDomain that we have stopped script | ||
273 | |||
274 | } | ||
275 | catch (Exception e) // LEGIT: User Scripting | ||
276 | { | ||
277 | m_log.Error("[" + | ||
278 | Name + | ||
279 | "]: Exception stopping script localID: " + | ||
280 | localID + " LLUID: " + itemID.ToString() + | ||
281 | ": " + e.ToString()); | ||
282 | } | ||
283 | } | ||
284 | |||
285 | |||
286 | } | ||
287 | } | ||
diff --git a/OpenSim/ScriptEngine/Engines/DotNetEngine/DotNetEngine.cs b/OpenSim/ScriptEngine/Engines/DotNetEngine/DotNetEngine.cs deleted file mode 100644 index 3b8a0ae..0000000 --- a/OpenSim/ScriptEngine/Engines/DotNetEngine/DotNetEngine.cs +++ /dev/null | |||
@@ -1,196 +0,0 @@ | |||
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 OpenSimulator 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 | using System; | ||
28 | using System.Collections.Generic; | ||
29 | using System.Reflection; | ||
30 | using System.Text; | ||
31 | using System.Text.RegularExpressions; | ||
32 | using log4net; | ||
33 | using Nini.Config; | ||
34 | using OpenMetaverse; | ||
35 | using OpenSim.ApplicationPlugins.ScriptEngine; | ||
36 | using OpenSim.Region.Framework.Interfaces; | ||
37 | using OpenSim.Region.Framework.Scenes; | ||
38 | using OpenSim.ScriptEngine.Components.DotNetEngine.Events; | ||
39 | using OpenSim.ScriptEngine.Components.DotNetEngine.Scheduler; | ||
40 | using OpenSim.ScriptEngine.Shared; | ||
41 | using ComponentFactory = OpenSim.ApplicationPlugins.ScriptEngine.ComponentFactory; | ||
42 | |||
43 | namespace OpenSim.ScriptEngine.Engines.DotNetEngine | ||
44 | { | ||
45 | // This is a sample engine | ||
46 | public partial class DotNetEngine : IScriptEngine | ||
47 | { | ||
48 | |||
49 | //private string[] _ComponentNames = new string[] { | ||
50 | // "Commands_LSL", | ||
51 | // "Commands_OSSL", | ||
52 | // "Compiler_CS", | ||
53 | // "Compiler_JS", | ||
54 | // "Compiler_LSL", | ||
55 | // "Compiler_VB", | ||
56 | // "LSLEventProvider", | ||
57 | // "Scheduler" | ||
58 | // }; | ||
59 | internal static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
60 | |||
61 | public string Name { get { return "SECS.DotNetEngine"; } } | ||
62 | //public bool IsSharedModule { get { return true; } } | ||
63 | internal RegionInfoStructure RegionInfo; | ||
64 | |||
65 | private string[] commandNames = new string[] | ||
66 | { | ||
67 | "Commands_LSL" | ||
68 | }; | ||
69 | |||
70 | private string[] compilerNames = new string[] | ||
71 | { | ||
72 | "Compiler_CS", | ||
73 | "Compiler_JS", | ||
74 | "Compiler_LSL", | ||
75 | "Compiler_YP", | ||
76 | "Compiler_VB" | ||
77 | }; | ||
78 | private string[] schedulerNames = new string[] | ||
79 | { | ||
80 | "Scheduler" | ||
81 | }; | ||
82 | |||
83 | //internal IScriptLoader m_ScriptLoader; | ||
84 | internal LSLEventProvider m_LSLEventProvider; | ||
85 | //internal IScriptExecutor m_Executor; | ||
86 | //internal Dictionary<string, IScriptCompiler> Compilers = new Dictionary<string, IScriptCompiler>(); | ||
87 | internal Dictionary<string, IScriptScheduler> Schedulers = new Dictionary<string, IScriptScheduler>(); | ||
88 | public static Dictionary<string, IScriptCompiler> Compilers = new Dictionary<string, IScriptCompiler>(); | ||
89 | // private static bool haveInitialized = false; | ||
90 | |||
91 | public DotNetEngine() | ||
92 | { | ||
93 | RegionInfo = new RegionInfoStructure(); | ||
94 | RegionInfo.Compilers = Compilers; | ||
95 | RegionInfo.Schedulers = Schedulers; | ||
96 | RegionInfo.Executors = new Dictionary<string, IScriptExecutor>(); | ||
97 | RegionInfo.CommandProviders = new Dictionary<string, IScriptCommandProvider>(); | ||
98 | RegionInfo.EventProviders = new Dictionary<string, IScriptEventProvider>(); | ||
99 | } | ||
100 | |||
101 | public void Initialise(Scene scene, IConfigSource source) | ||
102 | { | ||
103 | RegionInfo.Scene = scene; | ||
104 | RegionInfo.ConfigSource = source; | ||
105 | |||
106 | m_log.DebugFormat("[{0}] Initializing components", Name); | ||
107 | InitializeComponents(); | ||
108 | } | ||
109 | |||
110 | public void PostInitialise() { } | ||
111 | |||
112 | /// <summary> | ||
113 | /// Called on region close | ||
114 | /// </summary> | ||
115 | public void Close() | ||
116 | { | ||
117 | ComponentClose(); | ||
118 | } | ||
119 | #region Initialize the Script Engine Components we need | ||
120 | public void InitializeComponents() | ||
121 | { | ||
122 | string cname = ""; | ||
123 | m_log.DebugFormat("[{0}] Component initialization", Name); | ||
124 | // Initialize an instance of all module we want | ||
125 | try | ||
126 | { | ||
127 | cname = "ScriptManager"; | ||
128 | m_log.DebugFormat("[{0}] Executor: {1}", Name, cname); | ||
129 | RegionInfo.Executors.Add(cname, | ||
130 | ComponentFactory.GetComponentInstance(RegionInfo, cname) as IScriptExecutor); | ||
131 | |||
132 | cname = "ScriptLoader"; | ||
133 | m_log.DebugFormat("[{0}] ScriptLoader: {1}", Name, cname); | ||
134 | RegionInfo.ScriptLoader = | ||
135 | ComponentFactory.GetComponentInstance(RegionInfo, cname) as IScriptExecutor as ScriptLoader; | ||
136 | |||
137 | // CommandProviders | ||
138 | foreach (string cn in commandNames) | ||
139 | { | ||
140 | cname = cn; | ||
141 | m_log.DebugFormat("[{0}] CommandProvider: {1}", Name, cname); | ||
142 | RegionInfo.CommandProviders.Add(cname, | ||
143 | ComponentFactory.GetComponentInstance(RegionInfo, cname) as | ||
144 | IScriptCommandProvider); | ||
145 | } | ||
146 | |||
147 | // Compilers | ||
148 | foreach (string cn in compilerNames) | ||
149 | { | ||
150 | cname = cn; | ||
151 | m_log.DebugFormat("[{0}] Compiler: {1}", Name, cname); | ||
152 | RegionInfo.Compilers.Add(cname, | ||
153 | ComponentFactory.GetComponentInstance(RegionInfo, cname) as | ||
154 | IScriptCompiler); | ||
155 | } | ||
156 | |||
157 | // Schedulers | ||
158 | foreach (string cn in schedulerNames) | ||
159 | { | ||
160 | cname = cn; | ||
161 | m_log.DebugFormat("[{0}] Scheduler: {1}", Name, cname); | ||
162 | RegionInfo.Schedulers.Add(cname, | ||
163 | ComponentFactory.GetComponentInstance(RegionInfo, cname) as | ||
164 | IScriptScheduler); | ||
165 | } | ||
166 | |||
167 | // Event provider | ||
168 | cname = "LSLEventProvider"; | ||
169 | m_log.DebugFormat("[{0}] EventProvider: {1}", Name, cname); | ||
170 | IScriptEventProvider sep = ComponentFactory.GetComponentInstance(RegionInfo, cname) as IScriptEventProvider; | ||
171 | RegionInfo.EventProviders.Add(cname, sep); | ||
172 | m_LSLEventProvider = sep as LSLEventProvider; | ||
173 | |||
174 | // Hook up events | ||
175 | m_LSLEventProvider.RezScript += Events_RezScript; | ||
176 | m_LSLEventProvider.RemoveScript += Events_RemoveScript; | ||
177 | } | ||
178 | catch (Exception e) | ||
179 | { | ||
180 | m_log.ErrorFormat("[{0}] Exception while loading \"{1}\": {2}", Name, cname, e.ToString()); | ||
181 | } | ||
182 | } | ||
183 | |||
184 | private void ComponentClose() | ||
185 | { | ||
186 | // Close schedulers | ||
187 | foreach (IScriptScheduler scheduler in RegionInfo.Schedulers.Values) | ||
188 | { | ||
189 | scheduler.Close(); | ||
190 | } | ||
191 | } | ||
192 | |||
193 | #endregion | ||
194 | |||
195 | } | ||
196 | } | ||
diff --git a/OpenSim/ScriptEngine/Engines/DotNetEngine/DotNetEngine_ScriptLoadUnload.cs b/OpenSim/ScriptEngine/Engines/DotNetEngine/DotNetEngine_ScriptLoadUnload.cs deleted file mode 100644 index a113c1e..0000000 --- a/OpenSim/ScriptEngine/Engines/DotNetEngine/DotNetEngine_ScriptLoadUnload.cs +++ /dev/null | |||
@@ -1,95 +0,0 @@ | |||
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 OpenSimulator 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 | using System; | ||
29 | using System.Collections.Generic; | ||
30 | using System.Text; | ||
31 | using OpenMetaverse; | ||
32 | using OpenSim.ScriptEngine.Components.DotNetEngine.Events; | ||
33 | using OpenSim.ScriptEngine.Shared; | ||
34 | |||
35 | namespace OpenSim.ScriptEngine.Engines.DotNetEngine | ||
36 | { | ||
37 | public partial class DotNetEngine | ||
38 | { | ||
39 | |||
40 | //internal Dictionary<int, IScriptScheduler> ScriptMapping = new Dictionary<int, IScriptScheduler>(); | ||
41 | |||
42 | |||
43 | // | ||
44 | // HANDLE EVENTS FROM SCRIPTS | ||
45 | // We will handle script add, change and remove events outside of command pipeline | ||
46 | // | ||
47 | #region Script Add/Change/Remove | ||
48 | void Events_RezScript(uint localID, UUID itemID, string script, int startParam, bool postOnRez, string engine) | ||
49 | { | ||
50 | // ### | ||
51 | // # New script created | ||
52 | // ### | ||
53 | m_log.DebugFormat( | ||
54 | "[{0}] NEW SCRIPT: localID: {1}, itemID: {2}, startParam: {3}, postOnRez: {4}, engine: {5}", | ||
55 | Name, localID, itemID, startParam, postOnRez, engine); | ||
56 | |||
57 | // Make a script object | ||
58 | ScriptStructure scriptObject = new ScriptStructure(); | ||
59 | scriptObject.RegionInfo = RegionInfo; | ||
60 | scriptObject.LocalID = localID; | ||
61 | scriptObject.ItemID = itemID; | ||
62 | scriptObject.Source = script; | ||
63 | |||
64 | // | ||
65 | // Get MetaData from script header | ||
66 | // | ||
67 | ScriptMetaData scriptMetaData = ScriptMetaData.Extract(ref script); | ||
68 | scriptObject.ScriptMetaData = scriptMetaData; | ||
69 | foreach (string key in scriptObject.ScriptMetaData.Keys) | ||
70 | { | ||
71 | m_log.DebugFormat("[{0}] Script metadata: Key: \"{1}\", Value: \"{2}\".", Name, key, scriptObject.ScriptMetaData[key]); | ||
72 | } | ||
73 | |||
74 | // | ||
75 | // Load this assembly | ||
76 | // | ||
77 | // TODO: Use Executor to send a command instead? | ||
78 | m_log.DebugFormat("[{0}] Adding script to scheduler", Name); | ||
79 | RegionInfo.FindScheduler(scriptObject.ScriptMetaData).AddScript(scriptObject); | ||
80 | // Add to our internal mapping | ||
81 | //ScriptMapping.Add(itemID, Schedulers[scheduler]); | ||
82 | } | ||
83 | |||
84 | private void Events_RemoveScript(uint localID, UUID itemID) | ||
85 | { | ||
86 | // Tell all schedulers to remove this item | ||
87 | foreach (IScriptScheduler scheduler in RegionInfo.Schedulers.Values) | ||
88 | { | ||
89 | scheduler.Removecript(localID, itemID); | ||
90 | } | ||
91 | } | ||
92 | #endregion | ||
93 | |||
94 | } | ||
95 | } | ||
diff --git a/OpenSim/ScriptEngine/Engines/DotNetEngine/Properties/AssemblyInfo.cs b/OpenSim/ScriptEngine/Engines/DotNetEngine/Properties/AssemblyInfo.cs deleted file mode 100644 index bca9c2c..0000000 --- a/OpenSim/ScriptEngine/Engines/DotNetEngine/Properties/AssemblyInfo.cs +++ /dev/null | |||
@@ -1,63 +0,0 @@ | |||
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 OpenSimulator 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 | using System.Reflection; | ||
29 | using System.Runtime.CompilerServices; | ||
30 | using System.Runtime.InteropServices; | ||
31 | |||
32 | // General Information about an assembly is controlled through the following | ||
33 | // set of attributes. Change these attribute values to modify the information | ||
34 | // associated with an assembly. | ||
35 | [assembly: AssemblyTitle("OpenSim.ScriptEngine.Engines.DotNetEngine")] | ||
36 | [assembly: AssemblyDescription("")] | ||
37 | [assembly: AssemblyConfiguration("")] | ||
38 | [assembly: AssemblyCompany("http://opensimulator.org")] | ||
39 | [assembly: AssemblyProduct("OpenSim.ScriptEngine.Engines.DotNetEngine")] | ||
40 | [assembly: AssemblyCopyright("Copyright © Microsoft 2008")] | ||
41 | [assembly: AssemblyTrademark("")] | ||
42 | [assembly: AssemblyCulture("")] | ||
43 | |||
44 | // Setting ComVisible to false makes the types in this assembly not visible | ||
45 | // to COM components. If you need to access a type in this assembly from | ||
46 | // COM, set the ComVisible attribute to true on that type. | ||
47 | [assembly: ComVisible(false)] | ||
48 | |||
49 | // The following GUID is for the ID of the typelib if this project is exposed to COM | ||
50 | [assembly: Guid("1d1c68a7-026f-4556-a060-4af69f488d2a")] | ||
51 | |||
52 | // Version information for an assembly consists of the following four values: | ||
53 | // | ||
54 | // Major Version | ||
55 | // Minor Version | ||
56 | // Build Number | ||
57 | // Revision | ||
58 | // | ||
59 | // You can specify all the values or you can default the Build and Revision Numbers | ||
60 | // by using the '*' as shown below: | ||
61 | // [assembly: AssemblyVersion("0.6.5.*")] | ||
62 | [assembly: AssemblyVersion("0.6.5.*")] | ||
63 | [assembly: AssemblyFileVersion("0.6.5.0")] | ||
diff --git a/bin/OpenSim.ini.example b/bin/OpenSim.ini.example index 4f1799e..927eb7a 100644 --- a/bin/OpenSim.ini.example +++ b/bin/OpenSim.ini.example | |||
@@ -218,7 +218,6 @@ | |||
218 | ; ## SCRIPT ENGINE | 218 | ; ## SCRIPT ENGINE |
219 | ; ## | 219 | ; ## |
220 | 220 | ||
221 | ;DefaultScriptEngine = "ScriptEngine.DotNetEngine" | ||
222 | DefaultScriptEngine = "XEngine" | 221 | DefaultScriptEngine = "XEngine" |
223 | 222 | ||
224 | ; ## | 223 | ; ## |
@@ -826,137 +825,12 @@ | |||
826 | ; Density of tree population | 825 | ; Density of tree population |
827 | tree_density = 1000.0 | 826 | tree_density = 1000.0 |
828 | 827 | ||
828 | |||
829 | [VectorRender] | 829 | [VectorRender] |
830 | 830 | ||
831 | ; the font to use for rendering text (default: Arial) | 831 | ; the font to use for rendering text (default: Arial) |
832 | ; font_name = "Arial" | 832 | ; font_name = "Arial" |
833 | 833 | ||
834 | [ScriptEngine.DotNetEngine] | ||
835 | Enabled = true | ||
836 | |||
837 | ScriptDelayFactor = 1.0 | ||
838 | ScriptDistanceLimitFactor = 1.0 | ||
839 | |||
840 | ; Maximum length of notecard line read | ||
841 | ; Increasing this to large values potentially opens | ||
842 | ; up the system to malicious scripters | ||
843 | ; NotecardLineReadCharsMax = 255 | ||
844 | |||
845 | ; | ||
846 | ; These settings are specific to DotNetEngine script engine | ||
847 | ; Other script engines based on OpenSim.Region.ScriptEngine.Common.dll will have almost identical settings, but in another section of this config file. | ||
848 | ; | ||
849 | |||
850 | ; When a script receives an event the event is queued. | ||
851 | ; Any free thread will start executing this event. One script can only have one event executed simultaneously. | ||
852 | ; If you have only one thread, and one script has a loop or does a lot of work, then no other scripts can run at the same time. | ||
853 | ; Same if you have 10 threads, then only 10 scripts can be run simultaneously. | ||
854 | ; But because most scripts exit after their task, the threads are free to go on to the next script. | ||
855 | |||
856 | ; Refresh ScriptEngine config options (these settings) every xx seconds | ||
857 | ; 0 = Do not refresh | ||
858 | ; Set it to number of seconds between refresh, for example 30. | ||
859 | ; Will allow you to change ScriptEngine settings while server is running just by using "CONFIG SET" on console | ||
860 | ; For example to increase or decrease number of threads: CONFIG SET NumberOfScriptThreads 10 | ||
861 | ; NOTE! Disabled for now. Feature does not work. | ||
862 | RefreshConfig=0 | ||
863 | |||
864 | ; Number of threads to use for script event execution | ||
865 | ; Threads are shared across all regions | ||
866 | NumberOfScriptThreads=2 | ||
867 | |||
868 | ; Script event execution thread priority inside application. | ||
869 | ; Valid values: Lowest, BelowNormal, Normal, AboveNormal, Highest | ||
870 | ScriptThreadPriority=BelowNormal | ||
871 | |||
872 | ; How long MAX should a script event be allowed to run (per event execution)? | ||
873 | ; Do not set this too low (like 50ms) as there are some time wasted in simply executing a function | ||
874 | ; There is also a small speed penalty for every kill that is made | ||
875 | MaxEventExecutionTimeMs=5000 | ||
876 | |||
877 | ; Should we enable the max script event execution thread to look for scripts that exceed their timeslice? | ||
878 | EnforceMaxEventExecutionTime=true | ||
879 | |||
880 | ; Should we stop the script completely when time exceeds? | ||
881 | ; This is useful if you have a high <MaxEventExecutionTimeMs> and want to deactivate scripts that go wrong | ||
882 | ; Note that for example physics engine can slow down the system and make scripts spend more time | ||
883 | DeactivateScriptOnTimeout=false | ||
884 | |||
885 | ; If no scripts have executed in this pass how long should we sleep before checking again | ||
886 | ; Impact: | ||
887 | ; Too low and you will waste lots of CPU | ||
888 | ; Too high and people touching object or similar will have to wait up to this amount of time before script responding | ||
889 | SleepTimeIfNoScriptExecutionMs=50 | ||
890 | |||
891 | ; AppDomains are used for two things: | ||
892 | ; * Security: Scripts inside AppDomains are limited in permissions. | ||
893 | ; * Script unloading: When a script is deactivated it can not be unloaded. Only whole AppDomains can be unloaded. | ||
894 | ; AppDomains are therefore only unloaded once ALL active scripts inside it has been deactivated (removed from prims). | ||
895 | ; Each AppDomain has some memory overhead. But leaving dead scripts in memory also has memory overhead. | ||
896 | ScriptsPerAppDomain=1 | ||
897 | |||
898 | ; MaintenanceLoop | ||
899 | ; How often to run maintenance loop | ||
900 | ; Maintenance loop is doing: script compile/load, script unload, reload config, adjust running config and enforce max execution time | ||
901 | MaintenanceLoopms=50 | ||
902 | |||
903 | ; How many maintenanceloops between each of these. | ||
904 | ; (if 2 then function will be executed every MaintenanceLoopms*2 ms) | ||
905 | ; Script loading/unloading | ||
906 | |||
907 | ; How long load/unload thread should sleep if there is nothing to do | ||
908 | ; Higher value makes it respond slower when scripts are added/removed from prims | ||
909 | ; But once active it will process all in queue before sleeping again | ||
910 | MaintenanceLoopTicks_ScriptLoadUnload=1 | ||
911 | |||
912 | ; Other tasks | ||
913 | ; check if we need to reload config, adjust running config and enforce max execution time | ||
914 | MaintenanceLoopTicks_Other=10 | ||
915 | |||
916 | ; Allow the use of os* functions (some are dangerous) | ||
917 | ; Default is false | ||
918 | AllowOSFunctions = false | ||
919 | |||
920 | ; Threat level to allow if os functions are enabled | ||
921 | ; One of None, VeryLow, Low, Moderate, High, VeryHigh, Severe | ||
922 | ; Default is VeryLow | ||
923 | OSFunctionThreatLevel = VeryLow | ||
924 | |||
925 | ; Maximum number of items in load/unload queue before we start rejecting loads | ||
926 | ; Note that we will only be rejecting load. Unloads will still be able to queue. | ||
927 | LoadUnloadMaxQueueSize=100 | ||
928 | |||
929 | ; Maximum number of (LSL) events that can be queued before new events are ignored. | ||
930 | EventExecutionMaxQueueSize=300 | ||
931 | |||
932 | ; Async LL command sleep | ||
933 | ; If no async LL commands are waiting, how long should thread sleep before checking again | ||
934 | ; Async LL commands are LSL-commands that causes an event to be fired back with result | ||
935 | ; currently unused | ||
936 | ; AsyncLLCommandLoopms=50 | ||
937 | |||
938 | ; When script is converted from LSL to C#, or just plain compiled, a copy of the script source will be put in the ScriptEngine folder | ||
939 | WriteScriptSourceToDebugFile=false | ||
940 | |||
941 | ; Specify default script compiler | ||
942 | ; If you do not specify //cs, //vb, //js or //lsl tag as the first characters of your script then the default compiler will be chosen | ||
943 | ; Valid languages are: lsl, cs, js and vb | ||
944 | DefaultCompileLanguage=lsl | ||
945 | |||
946 | ; Specify what compilers are allowed to be used | ||
947 | ; Note vb only works on Windows for now (Mono lacks VB compile support) | ||
948 | ; Valid languages are: lsl, cs, js and vb | ||
949 | ; AllowedCompilers=lsl,cs,js,vb. *warning*, non lsl languages have access to static methods such as System.IO.File. Enable at your own risk. | ||
950 | AllowedCompilers=lsl | ||
951 | |||
952 | ; Compile scripts with debugging | ||
953 | ; Probably a thousand times slower, but gives you a line number when something goes wrong. | ||
954 | CompileWithDebugInformation=true | ||
955 | |||
956 | ; Remove old scripts on next startup | ||
957 | ; currently unused | ||
958 | ;CleanUpOldScriptsOnStartup=true | ||
959 | |||
960 | 834 | ||
961 | [LL-Functions] | 835 | [LL-Functions] |
962 | ; Set the following to true to allow administrator owned scripts to execute console commands | 836 | ; Set the following to true to allow administrator owned scripts to execute console commands |