aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/ScriptEngine/Components/DotNetEngine
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/ScriptEngine/Components/DotNetEngine')
-rw-r--r--OpenSim/ScriptEngine/Components/DotNetEngine/Commands_LSL/Commands_LSL.cs11
-rw-r--r--OpenSim/ScriptEngine/Components/DotNetEngine/Commands_LSL/LSL_BaseClass.cs29
-rw-r--r--OpenSim/ScriptEngine/Components/DotNetEngine/Commands_LSL/LSL_Constants.cs498
-rw-r--r--OpenSim/ScriptEngine/Components/DotNetEngine/Commands_OSSL/Commands_OSSL.cs11
-rw-r--r--OpenSim/ScriptEngine/Components/DotNetEngine/Compilers/CILCompiler.cs186
-rw-r--r--OpenSim/ScriptEngine/Components/DotNetEngine/Compilers/Compiler_CS.cs34
-rw-r--r--OpenSim/ScriptEngine/Components/DotNetEngine/Compilers/Compiler_JS.cs20
-rw-r--r--OpenSim/ScriptEngine/Components/DotNetEngine/Compilers/Compiler_LSL.cs21
-rw-r--r--OpenSim/ScriptEngine/Components/DotNetEngine/Compilers/Compiler_VB.cs20
-rw-r--r--OpenSim/ScriptEngine/Components/DotNetEngine/Compilers/Compiler_YP.cs55
-rw-r--r--OpenSim/ScriptEngine/Components/DotNetEngine/Compilers/LSL/LSL2CS.cs44
-rw-r--r--OpenSim/ScriptEngine/Components/DotNetEngine/Compilers/YP/YP2CS.cs54
-rw-r--r--OpenSim/ScriptEngine/Components/DotNetEngine/Events/LSLEventProvider.cs81
-rw-r--r--OpenSim/ScriptEngine/Components/DotNetEngine/Scheduler/BaseClassFactory.cs213
-rw-r--r--OpenSim/ScriptEngine/Components/DotNetEngine/Scheduler/LoadUnloadStructure.cs22
-rw-r--r--OpenSim/ScriptEngine/Components/DotNetEngine/Scheduler/Scheduler.cs19
-rw-r--r--OpenSim/ScriptEngine/Components/DotNetEngine/Scheduler/ScriptLoader.cs216
-rw-r--r--OpenSim/ScriptEngine/Components/DotNetEngine/Scheduler/ScriptManager.cs176
-rw-r--r--OpenSim/ScriptEngine/Components/DotNetEngine/Scheduler/ScriptManager_ScriptLoadUnload.cs259
19 files changed, 1931 insertions, 38 deletions
diff --git a/OpenSim/ScriptEngine/Components/DotNetEngine/Commands_LSL/Commands_LSL.cs b/OpenSim/ScriptEngine/Components/DotNetEngine/Commands_LSL/Commands_LSL.cs
index 703084c..0b7c894 100644
--- a/OpenSim/ScriptEngine/Components/DotNetEngine/Commands_LSL/Commands_LSL.cs
+++ b/OpenSim/ScriptEngine/Components/DotNetEngine/Commands_LSL/Commands_LSL.cs
@@ -28,18 +28,13 @@
28using System; 28using System;
29using System.Collections.Generic; 29using System.Collections.Generic;
30using System.Text; 30using System.Text;
31using OpenSim.ApplicationPlugins.ScriptEngine.Components; 31using OpenSim.ScriptEngine.Shared;
32 32
33namespace OpenSim.ScriptEngine.Components.DotNetEngine.Commands_LSL 33namespace OpenSim.ScriptEngine.Components.DotNetEngine.Commands_LSL
34{ 34{
35 public class Commands_LSL : CommandBase 35 public class Commands_LSL : IScriptEngineComponent
36 { 36 {
37 public override void Start()
38 {
39 }
40 37
41 public override void Close() 38
42 {
43 }
44 } 39 }
45} 40}
diff --git a/OpenSim/ScriptEngine/Components/DotNetEngine/Commands_LSL/LSL_BaseClass.cs b/OpenSim/ScriptEngine/Components/DotNetEngine/Commands_LSL/LSL_BaseClass.cs
new file mode 100644
index 0000000..173b259
--- /dev/null
+++ b/OpenSim/ScriptEngine/Components/DotNetEngine/Commands_LSL/LSL_BaseClass.cs
@@ -0,0 +1,29 @@
1using System;
2using System.Collections.Generic;
3using System.Reflection;
4using System.Text;
5using log4net;
6using OpenSim.ScriptEngine.Shared;
7
8namespace OpenSim.ScriptEngine.Components.DotNetEngine.Commands_LSL
9{
10 public class Script : IScriptCommandProvider
11 {
12 internal static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
13
14 public void llSay(int channelID, string text)
15 {
16 m_log.InfoFormat("[{0}] llSay({1}, \"{2}\")", "(Commands_LSL)OpenSim.ScriptEngine.Components.DotNetEngine.Commands_LSL.Script", channelID, text);
17 }
18
19 public void ExecuteCommand(string functionName, params object[] args)
20 {
21
22 }
23
24 public string Name
25 {
26 get { return "SECS.DotNetEngine.Commands_LSL.Script"; }
27 }
28 }
29} \ No newline at end of file
diff --git a/OpenSim/ScriptEngine/Components/DotNetEngine/Commands_LSL/LSL_Constants.cs b/OpenSim/ScriptEngine/Components/DotNetEngine/Commands_LSL/LSL_Constants.cs
new file mode 100644
index 0000000..9dd3c2f
--- /dev/null
+++ b/OpenSim/ScriptEngine/Components/DotNetEngine/Commands_LSL/LSL_Constants.cs
@@ -0,0 +1,498 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSim Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using System;
29using vector = OpenSim.Region.ScriptEngine.Shared.LSL_Types.Vector3;
30using rotation = OpenSim.Region.ScriptEngine.Shared.LSL_Types.Quaternion;
31using LSLInteger = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLInteger;
32
33namespace OpenSim.ScriptEngine.Components.DotNetEngine.Commands_LSL
34{
35 public class LSL_Constants : MarshalByRefObject
36 {
37 // LSL CONSTANTS
38 public static readonly LSLInteger TRUE = new LSLInteger(1);
39 public static readonly LSLInteger FALSE = new LSLInteger(0);
40
41 public const int STATUS_PHYSICS = 1;
42 public const int STATUS_ROTATE_X = 2;
43 public const int STATUS_ROTATE_Y = 4;
44 public const int STATUS_ROTATE_Z = 8;
45 public const int STATUS_PHANTOM = 16;
46 public const int STATUS_SANDBOX = 32;
47 public const int STATUS_BLOCK_GRAB = 64;
48 public const int STATUS_DIE_AT_EDGE = 128;
49 public const int STATUS_RETURN_AT_EDGE = 256;
50 public const int STATUS_CAST_SHADOWS = 512;
51
52 public const int AGENT = 1;
53 public const int ACTIVE = 2;
54 public const int PASSIVE = 4;
55 public const int SCRIPTED = 8;
56
57 public const int CONTROL_FWD = 1;
58 public const int CONTROL_BACK = 2;
59 public const int CONTROL_LEFT = 4;
60 public const int CONTROL_RIGHT = 8;
61 public const int CONTROL_UP = 16;
62 public const int CONTROL_DOWN = 32;
63 public const int CONTROL_ROT_LEFT = 256;
64 public const int CONTROL_ROT_RIGHT = 512;
65 public const int CONTROL_LBUTTON = 268435456;
66 public const int CONTROL_ML_LBUTTON = 1073741824;
67
68 //Permissions
69 public const int PERMISSION_DEBIT = 2;
70 public const int PERMISSION_TAKE_CONTROLS = 4;
71 public const int PERMISSION_REMAP_CONTROLS = 8;
72 public const int PERMISSION_TRIGGER_ANIMATION = 16;
73 public const int PERMISSION_ATTACH = 32;
74 public const int PERMISSION_RELEASE_OWNERSHIP = 64;
75 public const int PERMISSION_CHANGE_LINKS = 128;
76 public const int PERMISSION_CHANGE_JOINTS = 256;
77 public const int PERMISSION_CHANGE_PERMISSIONS = 512;
78 public const int PERMISSION_TRACK_CAMERA = 1024;
79 public const int PERMISSION_CONTROL_CAMERA = 2048;
80
81 public const int AGENT_FLYING = 1;
82 public const int AGENT_ATTACHMENTS = 2;
83 public const int AGENT_SCRIPTED = 4;
84 public const int AGENT_MOUSELOOK = 8;
85 public const int AGENT_SITTING = 16;
86 public const int AGENT_ON_OBJECT = 32;
87 public const int AGENT_AWAY = 64;
88 public const int AGENT_WALKING = 128;
89 public const int AGENT_IN_AIR = 256;
90 public const int AGENT_TYPING = 512;
91 public const int AGENT_CROUCHING = 1024;
92 public const int AGENT_BUSY = 2048;
93 public const int AGENT_ALWAYS_RUN = 4096;
94
95 //Particle Systems
96 public const int PSYS_PART_INTERP_COLOR_MASK = 1;
97 public const int PSYS_PART_INTERP_SCALE_MASK = 2;
98 public const int PSYS_PART_BOUNCE_MASK = 4;
99 public const int PSYS_PART_WIND_MASK = 8;
100 public const int PSYS_PART_FOLLOW_SRC_MASK = 16;
101 public const int PSYS_PART_FOLLOW_VELOCITY_MASK = 32;
102 public const int PSYS_PART_TARGET_POS_MASK = 64;
103 public const int PSYS_PART_TARGET_LINEAR_MASK = 128;
104 public const int PSYS_PART_EMISSIVE_MASK = 256;
105 public const int PSYS_PART_FLAGS = 0;
106 public const int PSYS_PART_START_COLOR = 1;
107 public const int PSYS_PART_START_ALPHA = 2;
108 public const int PSYS_PART_END_COLOR = 3;
109 public const int PSYS_PART_END_ALPHA = 4;
110 public const int PSYS_PART_START_SCALE = 5;
111 public const int PSYS_PART_END_SCALE = 6;
112 public const int PSYS_PART_MAX_AGE = 7;
113 public const int PSYS_SRC_ACCEL = 8;
114 public const int PSYS_SRC_PATTERN = 9;
115 public const int PSYS_SRC_INNERANGLE = 10;
116 public const int PSYS_SRC_OUTERANGLE = 11;
117 public const int PSYS_SRC_TEXTURE = 12;
118 public const int PSYS_SRC_BURST_RATE = 13;
119 public const int PSYS_SRC_BURST_PART_COUNT = 15;
120 public const int PSYS_SRC_BURST_RADIUS = 16;
121 public const int PSYS_SRC_BURST_SPEED_MIN = 17;
122 public const int PSYS_SRC_BURST_SPEED_MAX = 18;
123 public const int PSYS_SRC_MAX_AGE = 19;
124 public const int PSYS_SRC_TARGET_KEY = 20;
125 public const int PSYS_SRC_OMEGA = 21;
126 public const int PSYS_SRC_ANGLE_BEGIN = 22;
127 public const int PSYS_SRC_ANGLE_END = 23;
128 public const int PSYS_SRC_PATTERN_DROP = 1;
129 public const int PSYS_SRC_PATTERN_EXPLODE = 2;
130 public const int PSYS_SRC_PATTERN_ANGLE = 4;
131 public const int PSYS_SRC_PATTERN_ANGLE_CONE = 8;
132 public const int PSYS_SRC_PATTERN_ANGLE_CONE_EMPTY = 16;
133
134 public const int VEHICLE_TYPE_NONE = 0;
135 public const int VEHICLE_TYPE_SLED = 1;
136 public const int VEHICLE_TYPE_CAR = 2;
137 public const int VEHICLE_TYPE_BOAT = 3;
138 public const int VEHICLE_TYPE_AIRPLANE = 4;
139 public const int VEHICLE_TYPE_BALLOON = 5;
140 public const int VEHICLE_LINEAR_FRICTION_TIMESCALE = 16;
141 public const int VEHICLE_ANGULAR_FRICTION_TIMESCALE = 17;
142 public const int VEHICLE_LINEAR_MOTOR_DIRECTION = 18;
143 public const int VEHICLE_LINEAR_MOTOR_OFFSET = 20;
144 public const int VEHICLE_ANGULAR_MOTOR_DIRECTION = 19;
145 public const int VEHICLE_HOVER_HEIGHT = 24;
146 public const int VEHICLE_HOVER_EFFICIENCY = 25;
147 public const int VEHICLE_HOVER_TIMESCALE = 26;
148 public const int VEHICLE_BUOYANCY = 27;
149 public const int VEHICLE_LINEAR_DEFLECTION_EFFICIENCY = 28;
150 public const int VEHICLE_LINEAR_DEFLECTION_TIMESCALE = 29;
151 public const int VEHICLE_LINEAR_MOTOR_TIMESCALE = 30;
152 public const int VEHICLE_LINEAR_MOTOR_DECAY_TIMESCALE = 31;
153 public const int VEHICLE_ANGULAR_DEFLECTION_EFFICIENCY = 32;
154 public const int VEHICLE_ANGULAR_DEFLECTION_TIMESCALE = 33;
155 public const int VEHICLE_ANGULAR_MOTOR_TIMESCALE = 34;
156 public const int VEHICLE_ANGULAR_MOTOR_DECAY_TIMESCALE = 35;
157 public const int VEHICLE_VERTICAL_ATTRACTION_EFFICIENCY = 36;
158 public const int VEHICLE_VERTICAL_ATTRACTION_TIMESCALE = 37;
159 public const int VEHICLE_BANKING_EFFICIENCY = 38;
160 public const int VEHICLE_BANKING_MIX = 39;
161 public const int VEHICLE_BANKING_TIMESCALE = 40;
162 public const int VEHICLE_REFERENCE_FRAME = 44;
163 public const int VEHICLE_FLAG_NO_DEFLECTION_UP = 1;
164 public const int VEHICLE_FLAG_LIMIT_ROLL_ONLY = 2;
165 public const int VEHICLE_FLAG_HOVER_WATER_ONLY = 4;
166 public const int VEHICLE_FLAG_HOVER_TERRAIN_ONLY = 8;
167 public const int VEHICLE_FLAG_HOVER_GLOBAL_HEIGHT = 16;
168 public const int VEHICLE_FLAG_HOVER_UP_ONLY = 32;
169 public const int VEHICLE_FLAG_LIMIT_MOTOR_UP = 64;
170 public const int VEHICLE_FLAG_MOUSELOOK_STEER = 128;
171 public const int VEHICLE_FLAG_MOUSELOOK_BANK = 256;
172 public const int VEHICLE_FLAG_CAMERA_DECOUPLED = 512;
173
174 public const int INVENTORY_ALL = -1;
175 public const int INVENTORY_NONE = -1;
176 public const int INVENTORY_TEXTURE = 0;
177 public const int INVENTORY_SOUND = 1;
178 public const int INVENTORY_LANDMARK = 3;
179 public const int INVENTORY_CLOTHING = 5;
180 public const int INVENTORY_OBJECT = 6;
181 public const int INVENTORY_NOTECARD = 7;
182 public const int INVENTORY_SCRIPT = 10;
183 public const int INVENTORY_BODYPART = 13;
184 public const int INVENTORY_ANIMATION = 20;
185 public const int INVENTORY_GESTURE = 21;
186
187 public const int ATTACH_CHEST = 1;
188 public const int ATTACH_HEAD = 2;
189 public const int ATTACH_LSHOULDER = 3;
190 public const int ATTACH_RSHOULDER = 4;
191 public const int ATTACH_LHAND = 5;
192 public const int ATTACH_RHAND = 6;
193 public const int ATTACH_LFOOT = 7;
194 public const int ATTACH_RFOOT = 8;
195 public const int ATTACH_BACK = 9;
196 public const int ATTACH_PELVIS = 10;
197 public const int ATTACH_MOUTH = 11;
198 public const int ATTACH_CHIN = 12;
199 public const int ATTACH_LEAR = 13;
200 public const int ATTACH_REAR = 14;
201 public const int ATTACH_LEYE = 15;
202 public const int ATTACH_REYE = 16;
203 public const int ATTACH_NOSE = 17;
204 public const int ATTACH_RUARM = 18;
205 public const int ATTACH_RLARM = 19;
206 public const int ATTACH_LUARM = 20;
207 public const int ATTACH_LLARM = 21;
208 public const int ATTACH_RHIP = 22;
209 public const int ATTACH_RULEG = 23;
210 public const int ATTACH_RLLEG = 24;
211 public const int ATTACH_LHIP = 25;
212 public const int ATTACH_LULEG = 26;
213 public const int ATTACH_LLLEG = 27;
214 public const int ATTACH_BELLY = 28;
215 public const int ATTACH_RPEC = 29;
216 public const int ATTACH_LPEC = 30;
217
218 public const int LAND_LEVEL = 0;
219 public const int LAND_RAISE = 1;
220 public const int LAND_LOWER = 2;
221 public const int LAND_SMOOTH = 3;
222 public const int LAND_NOISE = 4;
223 public const int LAND_REVERT = 5;
224 public const int LAND_SMALL_BRUSH = 1;
225 public const int LAND_MEDIUM_BRUSH = 2;
226 public const int LAND_LARGE_BRUSH = 3;
227
228 //Agent Dataserver
229 public const int DATA_ONLINE = 1;
230 public const int DATA_NAME = 2;
231 public const int DATA_BORN = 3;
232 public const int DATA_RATING = 4;
233 public const int DATA_SIM_POS = 5;
234 public const int DATA_SIM_STATUS = 6;
235 public const int DATA_SIM_RATING = 7;
236 public const int DATA_PAYINFO = 8;
237 public const int DATA_SIM_RELEASE = 128;
238
239 public const int ANIM_ON = 1;
240 public const int LOOP = 2;
241 public const int REVERSE = 4;
242 public const int PING_PONG = 8;
243 public const int SMOOTH = 16;
244 public const int ROTATE = 32;
245 public const int SCALE = 64;
246 public const int ALL_SIDES = -1;
247 public const int LINK_SET = -1;
248 public const int LINK_ROOT = 1;
249 public const int LINK_ALL_OTHERS = -2;
250 public const int LINK_ALL_CHILDREN = -3;
251 public const int LINK_THIS = -4;
252 public const int CHANGED_INVENTORY = 1;
253 public const int CHANGED_COLOR = 2;
254 public const int CHANGED_SHAPE = 4;
255 public const int CHANGED_SCALE = 8;
256 public const int CHANGED_TEXTURE = 16;
257 public const int CHANGED_LINK = 32;
258 public const int CHANGED_ALLOWED_DROP = 64;
259 public const int CHANGED_OWNER = 128;
260 public const int CHANGED_REGION_RESTART = 256;
261 public const int CHANGED_REGION = 512;
262 public const int CHANGED_TELEPORT = 1024;
263 public const int TYPE_INVALID = 0;
264 public const int TYPE_INTEGER = 1;
265 public const int TYPE_FLOAT = 2;
266 public const int TYPE_STRING = 3;
267 public const int TYPE_KEY = 4;
268 public const int TYPE_VECTOR = 5;
269 public const int TYPE_ROTATION = 6;
270
271 //XML RPC Remote Data Channel
272 public const int REMOTE_DATA_CHANNEL = 1;
273 public const int REMOTE_DATA_REQUEST = 2;
274 public const int REMOTE_DATA_REPLY = 3;
275
276 //llHTTPRequest
277 public const int HTTP_METHOD = 0;
278 public const int HTTP_MIMETYPE = 1;
279 public const int HTTP_BODY_MAXLENGTH = 2;
280 public const int HTTP_VERIFY_CERT = 3;
281
282 public const int PRIM_MATERIAL = 2;
283 public const int PRIM_PHYSICS = 3;
284 public const int PRIM_TEMP_ON_REZ = 4;
285 public const int PRIM_PHANTOM = 5;
286 public const int PRIM_POSITION = 6;
287 public const int PRIM_SIZE = 7;
288 public const int PRIM_ROTATION = 8;
289 public const int PRIM_TYPE = 9;
290 public const int PRIM_TEXTURE = 17;
291 public const int PRIM_COLOR = 18;
292 public const int PRIM_BUMP_SHINY = 19;
293 public const int PRIM_FULLBRIGHT = 20;
294 public const int PRIM_FLEXIBLE = 21;
295 public const int PRIM_TEXGEN = 22;
296 public const int PRIM_CAST_SHADOWS = 24; // Not implemented, here for completeness sake
297 public const int PRIM_POINT_LIGHT = 23; // Huh?
298 public const int PRIM_GLOW = 25;
299 public const int PRIM_TEXGEN_DEFAULT = 0;
300 public const int PRIM_TEXGEN_PLANAR = 1;
301
302 public const int PRIM_TYPE_BOX = 0;
303 public const int PRIM_TYPE_CYLINDER = 1;
304 public const int PRIM_TYPE_PRISM = 2;
305 public const int PRIM_TYPE_SPHERE = 3;
306 public const int PRIM_TYPE_TORUS = 4;
307 public const int PRIM_TYPE_TUBE = 5;
308 public const int PRIM_TYPE_RING = 6;
309 public const int PRIM_TYPE_SCULPT = 7;
310
311 public const int PRIM_HOLE_DEFAULT = 0;
312 public const int PRIM_HOLE_CIRCLE = 16;
313 public const int PRIM_HOLE_SQUARE = 32;
314 public const int PRIM_HOLE_TRIANGLE = 48;
315
316 public const int PRIM_MATERIAL_STONE = 0;
317 public const int PRIM_MATERIAL_METAL = 1;
318 public const int PRIM_MATERIAL_GLASS = 2;
319 public const int PRIM_MATERIAL_WOOD = 3;
320 public const int PRIM_MATERIAL_FLESH = 4;
321 public const int PRIM_MATERIAL_PLASTIC = 5;
322 public const int PRIM_MATERIAL_RUBBER = 6;
323 public const int PRIM_MATERIAL_LIGHT = 7;
324
325 public const int PRIM_SHINY_NONE = 0;
326 public const int PRIM_SHINY_LOW = 1;
327 public const int PRIM_SHINY_MEDIUM = 2;
328 public const int PRIM_SHINY_HIGH = 3;
329 public const int PRIM_BUMP_NONE = 0;
330 public const int PRIM_BUMP_BRIGHT = 1;
331 public const int PRIM_BUMP_DARK = 2;
332 public const int PRIM_BUMP_WOOD = 3;
333 public const int PRIM_BUMP_BARK = 4;
334 public const int PRIM_BUMP_BRICKS = 5;
335 public const int PRIM_BUMP_CHECKER = 6;
336 public const int PRIM_BUMP_CONCRETE = 7;
337 public const int PRIM_BUMP_TILE = 8;
338 public const int PRIM_BUMP_STONE = 9;
339 public const int PRIM_BUMP_DISKS = 10;
340 public const int PRIM_BUMP_GRAVEL = 11;
341 public const int PRIM_BUMP_BLOBS = 12;
342 public const int PRIM_BUMP_SIDING = 13;
343 public const int PRIM_BUMP_LARGETILE = 14;
344 public const int PRIM_BUMP_STUCCO = 15;
345 public const int PRIM_BUMP_SUCTION = 16;
346 public const int PRIM_BUMP_WEAVE = 17;
347
348 public const int PRIM_SCULPT_TYPE_SPHERE = 1;
349 public const int PRIM_SCULPT_TYPE_TORUS = 2;
350 public const int PRIM_SCULPT_TYPE_PLANE = 3;
351 public const int PRIM_SCULPT_TYPE_CYLINDER = 4;
352
353 public const int MASK_BASE = 0;
354 public const int MASK_OWNER = 1;
355 public const int MASK_GROUP = 2;
356 public const int MASK_EVERYONE = 3;
357 public const int MASK_NEXT = 4;
358
359 public const int PERM_TRANSFER = 8192;
360 public const int PERM_MODIFY = 16384;
361 public const int PERM_COPY = 32768;
362 public const int PERM_MOVE = 524288;
363 public const int PERM_ALL = 2147483647;
364
365 public const int PARCEL_MEDIA_COMMAND_STOP = 0;
366 public const int PARCEL_MEDIA_COMMAND_PAUSE = 1;
367 public const int PARCEL_MEDIA_COMMAND_PLAY = 2;
368 public const int PARCEL_MEDIA_COMMAND_LOOP = 3;
369 public const int PARCEL_MEDIA_COMMAND_TEXTURE = 4;
370 public const int PARCEL_MEDIA_COMMAND_URL = 5;
371 public const int PARCEL_MEDIA_COMMAND_TIME = 6;
372 public const int PARCEL_MEDIA_COMMAND_AGENT = 7;
373 public const int PARCEL_MEDIA_COMMAND_UNLOAD = 8;
374 public const int PARCEL_MEDIA_COMMAND_AUTO_ALIGN = 9;
375 public const int PARCEL_MEDIA_COMMAND_TYPE = 10;
376 public const int PARCEL_MEDIA_COMMAND_SIZE = 11;
377 public const int PARCEL_MEDIA_COMMAND_DESC = 12;
378
379 public const int PARCEL_FLAG_ALLOW_FLY = 0x1; // parcel allows flying
380 public const int PARCEL_FLAG_ALLOW_SCRIPTS = 0x2; // parcel allows outside scripts
381 public const int PARCEL_FLAG_ALLOW_LANDMARK = 0x8; // parcel allows landmarks to be created
382 public const int PARCEL_FLAG_ALLOW_TERRAFORM = 0x10; // parcel allows anyone to terraform the land
383 public const int PARCEL_FLAG_ALLOW_DAMAGE = 0x20; // parcel allows damage
384 public const int PARCEL_FLAG_ALLOW_CREATE_OBJECTS = 0x40; // parcel allows anyone to create objects
385 public const int PARCEL_FLAG_USE_ACCESS_GROUP = 0x100; // parcel limits access to a group
386 public const int PARCEL_FLAG_USE_ACCESS_LIST = 0x200; // parcel limits access to a list of residents
387 public const int PARCEL_FLAG_USE_BAN_LIST = 0x400; // parcel uses a ban list, including restricting access based on payment info
388 public const int PARCEL_FLAG_USE_LAND_PASS_LIST = 0x800; // parcel allows passes to be purchased
389 public const int PARCEL_FLAG_LOCAL_SOUND_ONLY = 0x8000; // parcel restricts spatialized sound to the parcel
390 public const int PARCEL_FLAG_RESTRICT_PUSHOBJECT = 0x200000; // parcel restricts llPushObject
391 public const int PARCEL_FLAG_ALLOW_GROUP_SCRIPTS = 0x2000000; // parcel allows scripts owned by group
392 public const int PARCEL_FLAG_ALLOW_CREATE_GROUP_OBJECTS = 0x4000000; // parcel allows group object creation
393 public const int PARCEL_FLAG_ALLOW_ALL_OBJECT_ENTRY = 0x8000000; // parcel allows objects owned by any user to enter
394 public const int PARCEL_FLAG_ALLOW_GROUP_OBJECT_ENTRY = 0x10000000; // parcel allows with the same group to enter
395
396 public const int REGION_FLAG_ALLOW_DAMAGE = 0x1; // region is entirely damage enabled
397 public const int REGION_FLAG_FIXED_SUN = 0x10; // region has a fixed sun position
398 public const int REGION_FLAG_BLOCK_TERRAFORM = 0x40; // region terraforming disabled
399 public const int REGION_FLAG_SANDBOX = 0x100; // region is a sandbox
400 public const int REGION_FLAG_DISABLE_COLLISIONS = 0x1000; // region has disabled collisions
401 public const int REGION_FLAG_DISABLE_PHYSICS = 0x4000; // region has disabled physics
402 public const int REGION_FLAG_BLOCK_FLY = 0x80000; // region blocks flying
403 public const int REGION_FLAG_ALLOW_DIRECT_TELEPORT = 0x100000; // region allows direct teleports
404 public const int REGION_FLAG_RESTRICT_PUSHOBJECT = 0x400000; // region restricts llPushObject
405
406 public const int PAY_HIDE = -1;
407 public const int PAY_DEFAULT = -2;
408
409 public const string NULL_KEY = "00000000-0000-0000-0000-000000000000";
410 public const string EOF = "\n\n\n";
411 public const double PI = 3.14159274f;
412 public const double TWO_PI = 6.28318548f;
413 public const double PI_BY_TWO = 1.57079637f;
414 public const double DEG_TO_RAD = 0.01745329238f;
415 public const double RAD_TO_DEG = 57.29578f;
416 public const double SQRT2 = 1.414213538f;
417 public const int STRING_TRIM_HEAD = 1;
418 public const int STRING_TRIM_TAIL = 2;
419 public const int STRING_TRIM = 3;
420 public const int LIST_STAT_RANGE = 0;
421 public const int LIST_STAT_MIN = 1;
422 public const int LIST_STAT_MAX = 2;
423 public const int LIST_STAT_MEAN = 3;
424 public const int LIST_STAT_MEDIAN = 4;
425 public const int LIST_STAT_STD_DEV = 5;
426 public const int LIST_STAT_SUM = 6;
427 public const int LIST_STAT_SUM_SQUARES = 7;
428 public const int LIST_STAT_NUM_COUNT = 8;
429 public const int LIST_STAT_GEOMETRIC_MEAN = 9;
430 public const int LIST_STAT_HARMONIC_MEAN = 100;
431
432 //ParcelPrim Categories
433 public const int PARCEL_COUNT_TOTAL = 0;
434 public const int PARCEL_COUNT_OWNER = 1;
435 public const int PARCEL_COUNT_GROUP = 2;
436 public const int PARCEL_COUNT_OTHER = 3;
437 public const int PARCEL_COUNT_SELECTED = 4;
438 public const int PARCEL_COUNT_TEMP = 5;
439
440 public const int DEBUG_CHANNEL = 0x7FFFFFFF;
441 public const int PUBLIC_CHANNEL = 0x00000000;
442
443 public const int OBJECT_NAME = 1;
444 public const int OBJECT_DESC = 2;
445 public const int OBJECT_POS = 3;
446 public const int OBJECT_ROT = 4;
447 public const int OBJECT_VELOCITY = 5;
448 public const int OBJECT_OWNER = 6;
449 public const int OBJECT_GROUP = 7;
450 public const int OBJECT_CREATOR = 8;
451
452 // Can not be public const?
453 public static readonly vector ZERO_VECTOR = new vector(0.0, 0.0, 0.0);
454 public static readonly rotation ZERO_ROTATION = new rotation(0.0, 0, 0.0, 1.0);
455
456 // constants for llSetCameraParams
457 public const int CAMERA_PITCH = 0;
458 public const int CAMERA_FOCUS_OFFSET = 1;
459 public const int CAMERA_FOCUS_OFFSET_X = 2;
460 public const int CAMERA_FOCUS_OFFSET_Y = 3;
461 public const int CAMERA_FOCUS_OFFSET_Z = 4;
462 public const int CAMERA_POSITION_LAG = 5;
463 public const int CAMERA_FOCUS_LAG = 6;
464 public const int CAMERA_DISTANCE = 7;
465 public const int CAMERA_BEHINDNESS_ANGLE = 8;
466 public const int CAMERA_BEHINDNESS_LAG = 9;
467 public const int CAMERA_POSITION_THRESHOLD = 10;
468 public const int CAMERA_FOCUS_THRESHOLD = 11;
469 public const int CAMERA_ACTIVE = 12;
470 public const int CAMERA_POSITION = 13;
471 public const int CAMERA_POSITION_X = 14;
472 public const int CAMERA_POSITION_Y = 15;
473 public const int CAMERA_POSITION_Z = 16;
474 public const int CAMERA_FOCUS = 17;
475 public const int CAMERA_FOCUS_X = 18;
476 public const int CAMERA_FOCUS_Y = 19;
477 public const int CAMERA_FOCUS_Z = 20;
478 public const int CAMERA_POSITION_LOCKED = 21;
479 public const int CAMERA_FOCUS_LOCKED = 22;
480
481 // constants for llGetParcelDetails
482 public const int PARCEL_DETAILS_NAME = 0;
483 public const int PARCEL_DETAILS_DESC = 1;
484 public const int PARCEL_DETAILS_OWNER = 2;
485 public const int PARCEL_DETAILS_GROUP = 3;
486 public const int PARCEL_DETAILS_AREA = 4;
487
488 // constants for llSetClickAction
489 public const int CLICK_ACTION_NONE = 0;
490 public const int CLICK_ACTION_TOUCH = 0;
491 public const int CLICK_ACTION_SIT = 1;
492 public const int CLICK_ACTION_BUY = 2;
493 public const int CLICK_ACTION_PAY = 3;
494 public const int CLICK_ACTION_OPEN = 4;
495 public const int CLICK_ACTION_PLAY = 5;
496 public const int CLICK_ACTION_OPEN_MEDIA = 6;
497 }
498}
diff --git a/OpenSim/ScriptEngine/Components/DotNetEngine/Commands_OSSL/Commands_OSSL.cs b/OpenSim/ScriptEngine/Components/DotNetEngine/Commands_OSSL/Commands_OSSL.cs
index 6ba0c63..6b5dc14 100644
--- a/OpenSim/ScriptEngine/Components/DotNetEngine/Commands_OSSL/Commands_OSSL.cs
+++ b/OpenSim/ScriptEngine/Components/DotNetEngine/Commands_OSSL/Commands_OSSL.cs
@@ -28,18 +28,17 @@
28using System; 28using System;
29using System.Collections.Generic; 29using System.Collections.Generic;
30using System.Text; 30using System.Text;
31using OpenSim.ApplicationPlugins.ScriptEngine.Components; 31using OpenSim.ScriptEngine.Shared;
32 32
33namespace OpenSim.ScriptEngine.Components.DotNetEngine.Commands_OSSL 33namespace OpenSim.ScriptEngine.Components.DotNetEngine.Commands_OSSL
34{ 34{
35 public class Commands_OSSL: CommandBase 35 public class Commands_OSSL : IScriptEngineComponent
36 { 36 {
37 public override void Start() 37 private RegionInfoStructure CurrentRegion;
38 public void Initialize(RegionInfoStructure currentRegion)
38 { 39 {
40 CurrentRegion = currentRegion;
39 } 41 }
40 42
41 public override void Close()
42 {
43 }
44 } 43 }
45} 44}
diff --git a/OpenSim/ScriptEngine/Components/DotNetEngine/Compilers/CILCompiler.cs b/OpenSim/ScriptEngine/Components/DotNetEngine/Compilers/CILCompiler.cs
new file mode 100644
index 0000000..e221e1b
--- /dev/null
+++ b/OpenSim/ScriptEngine/Components/DotNetEngine/Compilers/CILCompiler.cs
@@ -0,0 +1,186 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSim Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27using System;
28using System.CodeDom.Compiler;
29using System.Collections.Generic;
30using System.IO;
31using System.Reflection;
32using System.Text.RegularExpressions;
33using log4net;
34using OpenSim.ScriptEngine.Shared;
35using ScriptAssemblies;
36
37namespace 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 internal string ScriptAssemblyName { get; set; }
45
46 // Default inherit
47 protected string ScriptInheritFrom = typeof(ScriptAssemblies.ScriptBase).Name;
48 private readonly System.Security.Cryptography.MD5CryptoServiceProvider MD5Sum = new System.Security.Cryptography.MD5CryptoServiceProvider();
49 protected CodeDomProvider CompileProvider;
50
51 //private string[] AppDomainAssemblies = new string[] { "OpenSim.Region.ScriptEngine.Shared.dll", "OpenSim.Region.ScriptEngine.Shared.Script.dll", "OpenSim.Region.ScriptEngine.Shared.Api.Runtime.dll" };
52 private readonly string[] AppDomainAssemblies = new string[] {
53 Assembly.GetAssembly(typeof(Int32)).Location,
54 "OpenSim.ScriptEngine.Shared.dll",
55 "OpenSim.ScriptEngine.Shared.Script.dll",
56 Path.Combine("ScriptEngines", "OpenSim.Region.ScriptEngine.Shared.dll")
57 };
58
59 public abstract string PreProcessScript(ref string script);
60
61 public CILCompiler()
62 {
63 }
64
65 private static readonly Regex FileNameFixer = new Regex(@"[^a-zA-Z0-9\.\-]", RegexOptions.Compiled | RegexOptions.Singleline);
66 public string Compile(ScriptMetaData data, ref string _script)
67 {
68 // Add "using", "inherit", default constructor, etc around script.
69 string script = PreProcessScript(ref _script);
70
71 // Get filename based on content
72 string md5Sum = System.Convert.ToBase64String(
73 MD5Sum.ComputeHash(
74 System.Text.Encoding.ASCII.GetBytes(script)
75 ));
76 // Unique name for this assembly
77 ScriptAssemblyName = "SECS_Script_" + FileNameFixer.Replace(md5Sum, "_");
78
79 string OutFile = Path.Combine(ScriptEnginesPath, ScriptAssemblyName + ".dll");
80
81 // Make sure target dir exist
82 if (!Directory.Exists(ScriptEnginesPath))
83 try { Directory.CreateDirectory(ScriptEnginesPath); }
84 catch { }
85
86 // Already exist? No point in recompiling
87 if (File.Exists(OutFile))
88 return OutFile;
89
90 //
91 // Dump source code
92 //
93 string dumpFile = OutFile + ".txt";
94 try
95 {
96 if (File.Exists(dumpFile))
97 File.Delete(dumpFile);
98 File.WriteAllText(dumpFile, script);
99 }
100 catch (Exception e)
101 {
102 m_log.DebugFormat("[{0}] Exception trying to dump script source code to file \"{1}\": {2}", Name, dumpFile, e.ToString());
103 }
104
105 //
106 // COMPILE
107 //
108
109 CompilerParameters parameters = new CompilerParameters();
110 parameters.IncludeDebugInformation = true;
111 string rootPath = Path.GetDirectoryName(AppDomain.CurrentDomain.BaseDirectory);
112
113 foreach (string file in AppDomainAssemblies)
114 {
115 parameters.ReferencedAssemblies.Add(file);
116 m_log.DebugFormat("[{0}] Adding reference for compile: \"{1}\".", Name, file);
117 }
118 //lock (commandProvider)
119 //{
120 // foreach (string key in commandProvider.Keys)
121 // {
122 // IScriptCommandProvider cp = commandProvider[key];
123 // string
124 // file = cp.GetType().Assembly.Location;
125 // parameters.ReferencedAssemblies.Add(file);
126 // m_log.DebugFormat("[{0}] Loading command provider assembly \"{1}\" into AppDomain: \"{2}\".", Name,
127 // key, file);
128 // }
129 //}
130
131 parameters.GenerateExecutable = false;
132 parameters.OutputAssembly = OutFile;
133 parameters.IncludeDebugInformation = true;
134 //parameters.WarningLevel = 1; // Should be 4?
135 parameters.TreatWarningsAsErrors = false;
136
137 // Do compile
138 CompilerResults results = CompileProvider.CompileAssemblyFromSource(parameters, script);
139
140
141 //
142 // WARNINGS AND ERRORS
143 //
144 //TODO
145 int display = 5;
146 if (results.Errors.Count > 0)
147 {
148 string errtext = String.Empty;
149 foreach (CompilerError CompErr in results.Errors)
150 {
151 // Show 5 errors max
152 //
153 if (display <= 0)
154 break;
155 display--;
156
157 string severity = "Error";
158 if (CompErr.IsWarning)
159 severity = "Warning";
160
161 //TODO: Implement
162 KeyValuePair<int, int> lslPos = new KeyValuePair<int, int>();
163
164 //lslPos = "NOT IMPLEMENTED";// FindErrorPosition(CompErr.Line, CompErr.Column);
165
166 string text = CompErr.ErrorText;
167
168 // The Second Life viewer's script editor begins
169 // countingn lines and columns at 0, so we subtract 1.
170 errtext += String.Format("Line ({0},{1}): {4} {2}: {3}\n",
171 lslPos.Key - 1, lslPos.Value - 1,
172 CompErr.ErrorNumber, text, severity);
173 }
174
175 if (!File.Exists(OutFile))
176 {
177 throw new Exception(errtext);
178 }
179 }
180
181 // TODO: Process errors
182 return OutFile;
183 }
184
185 }
186}
diff --git a/OpenSim/ScriptEngine/Components/DotNetEngine/Compilers/Compiler_CS.cs b/OpenSim/ScriptEngine/Components/DotNetEngine/Compilers/Compiler_CS.cs
index 9c72359..1286dc5 100644
--- a/OpenSim/ScriptEngine/Components/DotNetEngine/Compilers/Compiler_CS.cs
+++ b/OpenSim/ScriptEngine/Components/DotNetEngine/Compilers/Compiler_CS.cs
@@ -25,20 +25,46 @@
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */ 26 */
27using System; 27using System;
28using System.CodeDom.Compiler;
28using System.Collections.Generic; 29using System.Collections.Generic;
29using System.Text; 30using System.Text;
30using OpenSim.ApplicationPlugins.ScriptEngine.Components; 31using Microsoft.CSharp;
32using OpenSim.ScriptEngine.Shared;
31 33
32namespace OpenSim.ScriptEngine.Components.DotNetEngine.Compilers 34namespace OpenSim.ScriptEngine.Components.DotNetEngine.Compilers
33{ 35{
34 public class Compiler_CS: CompilerBase 36 public class Compiler_CS : CILCompiler, IScriptCompiler
35 { 37 {
36 public override void Start() 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()
37 { 47 {
48 CompileProvider = new CSharpCodeProvider();
38 } 49 }
39 50
40 public override void Close() 51 public override string PreProcessScript(ref string script)
41 { 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;
42 } 67 }
68
43 } 69 }
44} 70}
diff --git a/OpenSim/ScriptEngine/Components/DotNetEngine/Compilers/Compiler_JS.cs b/OpenSim/ScriptEngine/Components/DotNetEngine/Compilers/Compiler_JS.cs
index 3dc8d86..5e9bfba 100644
--- a/OpenSim/ScriptEngine/Components/DotNetEngine/Compilers/Compiler_JS.cs
+++ b/OpenSim/ScriptEngine/Components/DotNetEngine/Compilers/Compiler_JS.cs
@@ -25,20 +25,32 @@
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */ 26 */
27using System; 27using System;
28using System.CodeDom.Compiler;
28using System.Collections.Generic; 29using System.Collections.Generic;
29using System.Text; 30using System.Text;
30using OpenSim.ApplicationPlugins.ScriptEngine.Components; 31using Microsoft.JScript;
32using OpenSim.ScriptEngine.Shared;
31 33
32namespace OpenSim.ScriptEngine.Components.DotNetEngine.Compilers 34namespace OpenSim.ScriptEngine.Components.DotNetEngine.Compilers
33{ 35{
34 public class Compiler_JS : CompilerBase 36 public class Compiler_JS : CILCompiler, IScriptCompiler
35 { 37 {
36 public override void Start() 38
39 public Compiler_JS()
37 { 40 {
41 CompileProvider = new JScriptCodeProvider() as CodeDomProvider;
38 } 42 }
39 43
40 public override void Close() 44 public override string PreProcessScript(ref string script)
41 { 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
42 } 53 }
54
43 } 55 }
44} 56}
diff --git a/OpenSim/ScriptEngine/Components/DotNetEngine/Compilers/Compiler_LSL.cs b/OpenSim/ScriptEngine/Components/DotNetEngine/Compilers/Compiler_LSL.cs
index 3354ce9..d631c99 100644
--- a/OpenSim/ScriptEngine/Components/DotNetEngine/Compilers/Compiler_LSL.cs
+++ b/OpenSim/ScriptEngine/Components/DotNetEngine/Compilers/Compiler_LSL.cs
@@ -26,19 +26,32 @@
26 */ 26 */
27using System; 27using System;
28using System.Collections.Generic; 28using System.Collections.Generic;
29using System.Reflection;
29using System.Text; 30using System.Text;
30using OpenSim.ApplicationPlugins.ScriptEngine.Components; 31using OpenSim.ScriptEngine.Components.DotNetEngine.Compilers.LSL;
32using OpenSim.ScriptEngine.Shared;
31 33
32namespace OpenSim.ScriptEngine.Components.DotNetEngine.Compilers 34namespace OpenSim.ScriptEngine.Components.DotNetEngine.Compilers
33{ 35{
34 public class Compiler_LSL : CompilerBase 36 public class Compiler_LSL : IScriptCompiler
35 { 37 {
36 public override void Start() 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)
37 { 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);
38 } 49 }
39 50
40 public override void Close() 51 public string PreProcessScript(ref string script)
41 { 52 {
53 // This is handled by our converter
54 return script;
42 } 55 }
43 } 56 }
44} 57}
diff --git a/OpenSim/ScriptEngine/Components/DotNetEngine/Compilers/Compiler_VB.cs b/OpenSim/ScriptEngine/Components/DotNetEngine/Compilers/Compiler_VB.cs
index c7078cf..3975fa3 100644
--- a/OpenSim/ScriptEngine/Components/DotNetEngine/Compilers/Compiler_VB.cs
+++ b/OpenSim/ScriptEngine/Components/DotNetEngine/Compilers/Compiler_VB.cs
@@ -25,20 +25,32 @@
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */ 26 */
27using System; 27using System;
28using System.CodeDom.Compiler;
28using System.Collections.Generic; 29using System.Collections.Generic;
29using System.Text; 30using System.Text;
30using OpenSim.ApplicationPlugins.ScriptEngine.Components; 31using Microsoft.VisualBasic;
32using OpenSim.ScriptEngine.Shared;
31 33
32namespace OpenSim.ScriptEngine.Components.DotNetEngine.Compilers 34namespace OpenSim.ScriptEngine.Components.DotNetEngine.Compilers
33{ 35{
34 public class Compiler_VB : CompilerBase 36 public class Compiler_VB : CILCompiler, IScriptCompiler
35 { 37 {
36 public override void Start() 38
39 public Compiler_VB()
37 { 40 {
41 CompileProvider = new VBCodeProvider() as CodeDomProvider;
38 } 42 }
39 43
40 public override void Close() 44 public override string PreProcessScript(ref string script)
41 { 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";
42 } 53 }
43 } 54 }
44} 55}
56
diff --git a/OpenSim/ScriptEngine/Components/DotNetEngine/Compilers/Compiler_YP.cs b/OpenSim/ScriptEngine/Components/DotNetEngine/Compilers/Compiler_YP.cs
new file mode 100644
index 0000000..c81ad76
--- /dev/null
+++ b/OpenSim/ScriptEngine/Components/DotNetEngine/Compilers/Compiler_YP.cs
@@ -0,0 +1,55 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSim Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27using System;
28using System.Collections.Generic;
29using System.Reflection;
30using System.Text;
31using OpenSim.ScriptEngine.Components.DotNetEngine.Compilers.YP;
32using OpenSim.ScriptEngine.Shared;
33
34namespace 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
new file mode 100644
index 0000000..0e8052d
--- /dev/null
+++ b/OpenSim/ScriptEngine/Components/DotNetEngine/Compilers/LSL/LSL2CS.cs
@@ -0,0 +1,44 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSim Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27using System;
28using System.Collections.Generic;
29using System.Text;
30using OpenSim.Region.ScriptEngine.Shared.CodeTools;
31
32namespace 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/YP/YP2CS.cs b/OpenSim/ScriptEngine/Components/DotNetEngine/Compilers/YP/YP2CS.cs
new file mode 100644
index 0000000..e25a800
--- /dev/null
+++ b/OpenSim/ScriptEngine/Components/DotNetEngine/Compilers/YP/YP2CS.cs
@@ -0,0 +1,54 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSim Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27using System;
28using System.Collections.Generic;
29using System.Text;
30
31namespace 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
index b42ceec..794b132 100644
--- a/OpenSim/ScriptEngine/Components/DotNetEngine/Events/LSLEventProvider.cs
+++ b/OpenSim/ScriptEngine/Components/DotNetEngine/Events/LSLEventProvider.cs
@@ -27,19 +27,92 @@
27using System; 27using System;
28using System.Collections.Generic; 28using System.Collections.Generic;
29using System.Text; 29using System.Text;
30using OpenSim.ApplicationPlugins.ScriptEngine.Components; 30using OpenMetaverse;
31using OpenSim.Framework;
32using OpenSim.Region.Environment.Scenes;
33using OpenSim.Region.ScriptEngine.Shared;
34using OpenSim.ScriptEngine.Shared;
35using EventParams=OpenSim.ScriptEngine.Shared.EventParams;
31 36
32namespace OpenSim.ScriptEngine.Components.DotNetEngine.Events 37namespace OpenSim.ScriptEngine.Components.DotNetEngine.Events
33{ 38{
34 public class LSLEventProvider: EventBase 39 public class LSLEventProvider : IScriptEventProvider
35 { 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;
36 48
37 public override void Start() 49 private RegionInfoStructure CurrentRegion;
50 public void Initialize(RegionInfoStructure currentRegion)
38 { 51 {
52 CurrentRegion = currentRegion;
53 HookupEvents();
39 } 54 }
40 55
41 public override void Close() 56 private void HookupEvents()
42 { 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)
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)
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
112 Shared.EventParams ep =
113 new Shared.EventParams(localID, "touch_start", new Object[] {new LSL_Types.LSLInteger(1)}, det);
114 CurrentRegion.Executors_Execute(ep);
115
43 } 116 }
44 } 117 }
45} 118}
diff --git a/OpenSim/ScriptEngine/Components/DotNetEngine/Scheduler/BaseClassFactory.cs b/OpenSim/ScriptEngine/Components/DotNetEngine/Scheduler/BaseClassFactory.cs
new file mode 100644
index 0000000..2f19cae
--- /dev/null
+++ b/OpenSim/ScriptEngine/Components/DotNetEngine/Scheduler/BaseClassFactory.cs
@@ -0,0 +1,213 @@
1using System;
2using System.Collections.Generic;
3using System.IO;
4using System.Reflection;
5using System.Reflection.Emit;
6using System.Text;
7using OpenSim.ScriptEngine.Shared;
8
9namespace OpenSim.ScriptEngine.Components.DotNetEngine.Scheduler
10{
11 public class BaseClassFactory
12 {
13
14
15 public static void MakeBaseClass(ScriptStructure script)
16 {
17 string asmName = "ScriptAssemblies";
18 string ModuleID = asmName;
19 string ClassID = "Script";
20 string moveToDir = "ScriptEngines";
21 string asmFileName = ModuleID + "_" + ClassID + ".dll";
22 if (!Directory.Exists(moveToDir))
23 Directory.CreateDirectory(moveToDir);
24
25 ILGenerator ilgen;
26 AssemblyBuilder asmBuilder = AppDomain.CurrentDomain.DefineDynamicAssembly(
27 new AssemblyName(asmName), AssemblyBuilderAccess.RunAndSave);
28
29 // The module builder
30 ModuleBuilder modBuilder = asmBuilder.DefineDynamicModule(ModuleID, asmFileName);
31
32 // The class builder
33 TypeBuilder classBuilder = modBuilder.DefineType(ClassID, TypeAttributes.Class | TypeAttributes.Public);
34
35 // The default constructor
36 ConstructorBuilder ctorBuilder = classBuilder.DefineDefaultConstructor(MethodAttributes.Public);
37
38
39 Type[] paramsTypeArray = new Type[] {typeof (System.ParamArrayAttribute)};
40 Type[] executeFunctionTypeArray = new Type[] {typeof (string), typeof (System.ParamArrayAttribute)};
41 foreach (IScriptCommandProvider cp in script.RegionInfo.CommandProviders.Values)
42 {
43 Type t = cp.GetType();
44 foreach (MethodInfo mi in t.GetMethods())
45 {
46 MethodBuilder methodBuilder = classBuilder.DefineMethod(mi.Name, mi.Attributes, mi.GetType(), Type.EmptyTypes);
47 methodBuilder.SetParameters(paramsTypeArray);
48 //ParameterBuilder paramBuilder = methodBuilder.DefineParameter(1, ParameterAttributes.None, "args");
49
50 ilgen = methodBuilder.GetILGenerator();
51 //ilgen.Emit(OpCodes.Nop);
52 //ilgen.Emit(OpCodes.Ldarg_0);
53 //ilgen.Emit(OpCodes.Ldc_I4_0);
54 //ilgen.Emit(OpCodes.Ldelem_Ref);
55 //ilgen.MarkSequencePoint(doc, 6, 1, 6, 100);
56
57 MethodInfo ExecuteFunction = typeof(ScriptAssemblies.IScript).GetMethod(
58 "ExecuteFunction",
59 executeFunctionTypeArray);
60
61 ilgen.DeclareLocal(typeof(string));
62 ilgen.Emit(OpCodes.Nop);
63 ilgen.Emit(OpCodes.Ldstr, mi.Name);
64 ilgen.Emit(OpCodes.Stloc_0);
65 ilgen.Emit(OpCodes.Ldarg_0);
66 ilgen.Emit(OpCodes.Ldloc_0);
67 ilgen.Emit(OpCodes.Ldarg_1);
68
69 // FieldInfo testInfo = classBuilder.
70 //BindingFlags.NonPublic | BindingFlags.Instance);
71
72 //ilgen.Emit(OpCodes.Ldfld, testInfo);
73
74 //ilgen.EmitCall(OpCodes.Call, ExecuteFunction, executeFunctionTypeArray);
75 ilgen.EmitCall(OpCodes.Call, typeof(System.Console).GetMethod("WriteLine"), executeFunctionTypeArray);
76
77 // // string.Format("Hello, {0} World!", toWhom)
78 // //
79 // ilgen.Emit(OpCodes.Ldstr, "Hello, {0} World!");
80 // ilgen.Emit(OpCodes.Ldarg_1);
81 // ilgen.Emit(OpCodes.Call, typeof(string).GetMethod
82 //("Format", new Type[] { typeof(string), typeof(object) }));
83
84 // // Console.WriteLine("Hello, World!");
85 // //
86 // ilgen.Emit(OpCodes.Call, typeof(Console).GetMethod
87 // ("WriteLine", new Type[] { typeof(string) }));
88 ilgen.Emit(OpCodes.Ret);
89
90
91
92 //Label eom = ilgen.DefineLabel();
93 //ilgen.Emit(OpCodes.Br_S, eom);
94 //ilgen.MarkLabel(eom);
95 //ilgen.Emit(OpCodes.Ret);
96 //Type test = methodBuilder.SetParameters();
97
98
99 //methodBuilder.SetParameters(typeof (object[]));
100
101
102 }
103 }
104
105
106 //// Two fields: m_firstname, m_lastname
107 //FieldBuilder fBuilderFirstName = classBuilder.DefineField("m_firstname", typeof(string), FieldAttributes.Private);
108 //FieldBuilder fBuilderLastName = classBuilder.DefineField("m_lastname", typeof(string), FieldAttributes.Private);
109
110 //// Two properties for this object: FirstName, LastName
111 //PropertyBuilder pBuilderFirstName = classBuilder.DefineProperty("FirstName", System.Reflection.PropertyAttributes.HasDefault, typeof(string), null);
112 //PropertyBuilder pBuilderLastName = classBuilder.DefineProperty("LastName", System.Reflection.PropertyAttributes.HasDefault, typeof(string), null);
113
114 //// Custom attributes for get, set accessors
115 //MethodAttributes getSetAttr = MethodAttributes.Public | MethodAttributes.HideBySig | MethodAttributes.SpecialName;
116
117 //// get,set accessors for FirstName
118 //MethodBuilder mGetFirstNameBuilder = classBuilder.DefineMethod("get_FirstName", getSetAttr, typeof(string), Type.EmptyTypes);
119
120 //// Code generation
121 //ilgen = mGetFirstNameBuilder.GetILGenerator();
122 //ilgen.Emit(OpCodes.Ldarg_0);
123 //ilgen.Emit(OpCodes.Ldfld, fBuilderFirstName); // returning the firstname field
124 //ilgen.Emit(OpCodes.Ret);
125
126 //MethodBuilder mSetFirstNameBuilder = classBuilder.DefineMethod("set_FirstName", getSetAttr, null, new Type[] { typeof(string) });
127
128 //// Code generation
129 //ilgen = mSetFirstNameBuilder.GetILGenerator();
130 //ilgen.Emit(OpCodes.Ldarg_0);
131 //ilgen.Emit(OpCodes.Ldarg_1);
132 //ilgen.Emit(OpCodes.Stfld, fBuilderFirstName); // setting the firstname field from the first argument (1)
133 //ilgen.Emit(OpCodes.Ret);
134
135 //// get,set accessors for LastName
136 //MethodBuilder mGetLastNameBuilder = classBuilder.DefineMethod("get_LastName", getSetAttr, typeof(string), Type.EmptyTypes);
137
138 //// Code generation
139 //ilgen = mGetLastNameBuilder.GetILGenerator();
140 //ilgen.Emit(OpCodes.Ldarg_0);
141 //ilgen.Emit(OpCodes.Ldfld, fBuilderLastName); // returning the firstname field
142 //ilgen.Emit(OpCodes.Ret);
143
144 //MethodBuilder mSetLastNameBuilder = classBuilder.DefineMethod("set_LastName", getSetAttr, null, new Type[] { typeof(string) });
145
146 //// Code generation
147 //ilgen = mSetLastNameBuilder.GetILGenerator();
148 //ilgen.Emit(OpCodes.Ldarg_0);
149 //ilgen.Emit(OpCodes.Ldarg_1);
150 //ilgen.Emit(OpCodes.Stfld, fBuilderLastName); // setting the firstname field from the first argument (1)
151 //ilgen.Emit(OpCodes.Ret);
152
153 //// Assigning get/set accessors
154 //pBuilderFirstName.SetGetMethod(mGetFirstNameBuilder);
155 //pBuilderFirstName.SetSetMethod(mSetFirstNameBuilder);
156
157 //pBuilderLastName.SetGetMethod(mGetLastNameBuilder);
158 //pBuilderLastName.SetSetMethod(mSetLastNameBuilder);
159
160 //// Now, a custom method named GetFullName that concatenates FirstName and LastName properties
161 //MethodBuilder mGetFullNameBuilder = classBuilder.DefineMethod("GetFullName", MethodAttributes.Public, typeof(string), Type.EmptyTypes);
162
163 //// Code generation
164 //ilgen = mGetFullNameBuilder.GetILGenerator();
165 //ilgen.Emit(OpCodes.Ldarg_0);
166 //ilgen.Emit(OpCodes.Call, mGetFirstNameBuilder); // getting the firstname
167 //ilgen.Emit(OpCodes.Ldstr, " "); // an space
168 //ilgen.Emit(OpCodes.Ldarg_0);
169 //ilgen.Emit(OpCodes.Call, mGetLastNameBuilder); // getting the lastname
170
171 //// We need the 'Concat' method from string type
172 //MethodInfo concatMethod = typeof(String).GetMethod("Concat", new Type[] { typeof(string), typeof(string), typeof(string) });
173
174 //ilgen.Emit(OpCodes.Call, concatMethod); // calling concat and returning the result
175 //ilgen.Emit(OpCodes.Ret);
176
177 //// Another constructor that initializes firstname and lastname
178 //ConstructorBuilder ctorBuilder2 = classBuilder.DefineConstructor(MethodAttributes.Public, CallingConventions.Standard, new Type[] { typeof(string), typeof(string) });
179 //ctorBuilder2.DefineParameter(1, ParameterAttributes.In, "firstname");
180 //ctorBuilder2.DefineParameter(2, ParameterAttributes.In, "lastname");
181
182 //// Code generation
183 //ilgen = ctorBuilder2.GetILGenerator();
184
185 //// First of all, we need to call the base constructor,
186 //// the Object's constructor in this sample
187 //Type objType = Type.GetType("System.Object");
188 //ConstructorInfo objCtor = objType.GetConstructor(Type.EmptyTypes);
189
190 //ilgen.Emit(OpCodes.Ldarg_0);
191 //ilgen.Emit(OpCodes.Call, objCtor); // calling the Object's constructor
192
193 //ilgen.Emit(OpCodes.Ldarg_0);
194 //ilgen.Emit(OpCodes.Ldarg_1);
195 //ilgen.Emit(OpCodes.Call, mSetFirstNameBuilder); // setting the firstname field from the first argument (1)
196 //ilgen.Emit(OpCodes.Ldarg_0);
197 //ilgen.Emit(OpCodes.Ldarg_2);
198 //ilgen.Emit(OpCodes.Call, mSetLastNameBuilder); // setting the lastname field from the second argument (2)
199 //ilgen.Emit(OpCodes.Ret);
200
201 // Finally, create the type and save the assembly
202 classBuilder.CreateType();
203
204 asmBuilder.Save(asmFileName);
205 string toFile = Path.Combine(moveToDir, asmFileName);
206 if (File.Exists(toFile))
207 File.Delete(toFile);
208 File.Move(asmFileName, toFile);
209
210 string a = "";
211 }
212 }
213} \ No newline at end of file
diff --git a/OpenSim/ScriptEngine/Components/DotNetEngine/Scheduler/LoadUnloadStructure.cs b/OpenSim/ScriptEngine/Components/DotNetEngine/Scheduler/LoadUnloadStructure.cs
new file mode 100644
index 0000000..d3d0509
--- /dev/null
+++ b/OpenSim/ScriptEngine/Components/DotNetEngine/Scheduler/LoadUnloadStructure.cs
@@ -0,0 +1,22 @@
1using System;
2using System.Collections.Generic;
3using System.Text;
4using OpenSim.ScriptEngine.Shared;
5
6namespace OpenSim.ScriptEngine.Components.DotNetEngine.Scheduler
7{
8 public struct LoadUnloadStructure
9 {
10 public ScriptStructure Script;
11 public LUType Action;
12 public bool PostOnRez;
13 public int StartParam;
14
15 public enum LUType
16 {
17 Unknown = 0,
18 Load = 1,
19 Unload = 2
20 }
21 }
22}
diff --git a/OpenSim/ScriptEngine/Components/DotNetEngine/Scheduler/Scheduler.cs b/OpenSim/ScriptEngine/Components/DotNetEngine/Scheduler/Scheduler.cs
index 52c59eb..1143b03 100644
--- a/OpenSim/ScriptEngine/Components/DotNetEngine/Scheduler/Scheduler.cs
+++ b/OpenSim/ScriptEngine/Components/DotNetEngine/Scheduler/Scheduler.cs
@@ -27,18 +27,29 @@
27using System; 27using System;
28using System.Collections.Generic; 28using System.Collections.Generic;
29using System.Text; 29using System.Text;
30using OpenSim.ApplicationPlugins.ScriptEngine.Components; 30using OpenMetaverse;
31using OpenSim.ScriptEngine.Shared;
31 32
32namespace OpenSim.ScriptEngine.Components.DotNetEngine.Scheduler 33namespace OpenSim.ScriptEngine.Components.DotNetEngine.Scheduler
33{ 34{
34 public class Scheduler: SchedulerBase 35 public class Scheduler : IScriptScheduler
35 { 36 {
36 public override void Start() 37
38 private ScriptManager m_ScriptManager = new ScriptManager();
39 public void AddScript(ScriptStructure scriptStructure)
37 { 40 {
41 m_ScriptManager.AddScript(scriptStructure);
38 } 42 }
39 43
40 public override void Close() 44 public void Removecript(uint id, UUID itemID)
41 { 45 {
46 m_ScriptManager.RemoveScript(id, itemID);
42 } 47 }
48
49 public void Close()
50 {
51 m_ScriptManager.Close();
52 }
53
43 } 54 }
44} 55}
diff --git a/OpenSim/ScriptEngine/Components/DotNetEngine/Scheduler/ScriptLoader.cs b/OpenSim/ScriptEngine/Components/DotNetEngine/Scheduler/ScriptLoader.cs
new file mode 100644
index 0000000..cb4a870
--- /dev/null
+++ b/OpenSim/ScriptEngine/Components/DotNetEngine/Scheduler/ScriptLoader.cs
@@ -0,0 +1,216 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSim Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27using System;
28using System.Collections;
29using System.Collections.Generic;
30using System.Reflection;
31using System.Text;
32using log4net;
33using OpenSim.ScriptEngine.Shared;
34using IScript=OpenSim.Region.ScriptEngine.Shared.ScriptBase.IScript;
35
36namespace 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
new file mode 100644
index 0000000..3452b03
--- /dev/null
+++ b/OpenSim/ScriptEngine/Components/DotNetEngine/Scheduler/ScriptManager.cs
@@ -0,0 +1,176 @@
1using System;
2using System.Collections.Generic;
3using System.Diagnostics;
4using System.Reflection;
5using System.Text;
6using System.Threading;
7using log4net;
8using OpenMetaverse;
9using OpenSim.Region.ScriptEngine.Shared;
10using OpenSim.ScriptEngine.Shared;
11using EventParams=OpenSim.ScriptEngine.Shared.EventParams;
12
13namespace OpenSim.ScriptEngine.Components.DotNetEngine.Scheduler
14{
15 public partial class ScriptManager: IScriptExecutor
16 {
17 private const int NoWorkSleepMs = 50;
18 private const int NoWorkSleepMsInc = 1; // How much time to increase wait with on every iteration
19 private const int NoWorkSleepMsIncMax = 300; // Max time to wait
20
21 internal static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
22 public string Name { get { return "SECS.DotNetEngine.ScriptManager"; } }
23 private static Thread ScriptLoadUnloadThread;
24 public Dictionary<uint, Dictionary<UUID, ScriptStructure>> Scripts = new Dictionary<uint, Dictionary<UUID, ScriptStructure>>();
25
26 private RegionInfoStructure CurrentRegion;
27 public void Initialize(RegionInfoStructure currentRegion)
28 {
29 CurrentRegion = currentRegion;
30 }
31
32 public ScriptManager()
33 {
34 ScriptLoadUnloadThread = new Thread(LoadUnloadLoop);
35 ScriptLoadUnloadThread.Name = "ScriptLoadUnloadThread";
36 ScriptLoadUnloadThread.IsBackground = true;
37 ScriptLoadUnloadThread.Start();
38 }
39 public void Close() { }
40
41 private void LoadUnloadLoop ()
42 {
43 int _NoWorkSleepMsInc = 0;
44 while (true)
45 {
46 if (DoScriptLoadUnload())
47 {
48 // We found work, reset counter
49 _NoWorkSleepMsInc = NoWorkSleepMs;
50 } else
51 {
52 // We didn't find work
53 // Sleep
54 Thread.Sleep(NoWorkSleepMs + NoWorkSleepMsInc);
55 // Increase sleep delay
56 _NoWorkSleepMsInc += NoWorkSleepMsInc;
57 // Make sure we don't exceed max
58 if (_NoWorkSleepMsInc > NoWorkSleepMsIncMax)
59 _NoWorkSleepMsInc = NoWorkSleepMsIncMax;
60 }
61 }
62 }
63
64 #region Add/Remove/Find script functions for our Script memory structure
65 private void MemAddScript(ScriptStructure script)
66 {
67 lock (scriptLock)
68 {
69 // Create object if it doesn't exist
70 if (!Scripts.ContainsKey(script.LocalID))
71 Scripts.Add(script.LocalID, new Dictionary<UUID, ScriptStructure>());
72
73 // Delete script if it exists
74 Dictionary<UUID, ScriptStructure> Obj;
75 if (Scripts.TryGetValue(script.LocalID, out Obj))
76 if (Obj.ContainsKey(script.ItemID) == true)
77 Obj.Remove(script.ItemID);
78
79 // Add to object
80 Obj.Add(script.ItemID, script);
81 }
82 }
83 private void MemRemoveScript(uint LocalID, UUID ItemID)
84 {
85 // TODO: Also clean up command queue and async commands for object
86 lock (scriptLock)
87 {
88 // Create object if it doesn't exist
89 if (!Scripts.ContainsKey(LocalID))
90 return;
91
92 // Delete script if it exists
93 Dictionary<UUID, ScriptStructure> Obj;
94 if (Scripts.TryGetValue(LocalID, out Obj))
95 if (Obj.ContainsKey(ItemID) == true)
96 Obj.Remove(ItemID);
97
98 // Empty?
99 if (Obj.Count == 0)
100 Scripts.Remove(LocalID);
101
102 }
103 }
104 public bool TryGetScript(uint localID, UUID itemID, ref ScriptStructure script)
105 {
106 lock (scriptLock)
107 {
108
109 if (Scripts.ContainsKey(localID) == false)
110 return false;
111
112 Dictionary<UUID, ScriptStructure> Obj;
113 if (Scripts.TryGetValue(localID, out Obj))
114 if (Obj.ContainsKey(itemID) == false)
115 return false;
116
117 // Get script
118 return Obj.TryGetValue(itemID, out script);
119 }
120 }
121 public ScriptStructure GetScript(uint localID, UUID itemID)
122 {
123 lock (scriptLock)
124 {
125
126 if (Scripts.ContainsKey(localID) == false)
127 throw new Exception("No script with LocalID " + localID + " was found.");
128
129 Dictionary<UUID, ScriptStructure> Obj;
130 if (Scripts.TryGetValue(localID, out Obj))
131 if (Obj.ContainsKey(itemID) == false)
132 throw new Exception("No script with ItemID " + itemID + " was found.");
133
134 // Get script
135 return Obj[itemID];
136 }
137 }
138 public bool TryGetScripts(uint localID, ref Dictionary<UUID, ScriptStructure> returnList)
139 {
140 Dictionary<UUID, ScriptStructure> getList = GetScripts(localID);
141 if (getList != null)
142 {
143 returnList = getList;
144 return true;
145 }
146 return false;
147 }
148 public Dictionary<UUID, ScriptStructure> GetScripts(uint localID)
149 {
150 lock (scriptLock)
151 {
152
153 if (Scripts.ContainsKey(localID) == false)
154 return null;
155 return Scripts[localID];
156 }
157 }
158 #endregion
159
160 public void ExecuteCommand(EventParams p)
161 {
162 ScriptStructure ss = new ScriptStructure();
163 if (TryGetScript(p.LocalID, p.ItemID, ref ss))
164 ExecuteCommand(ref ss, p);
165 }
166
167 public void ExecuteCommand(ref ScriptStructure scriptContainer, EventParams p)
168 {
169 m_log.DebugFormat("[{0}] ######################################################", Name);
170 m_log.DebugFormat("[{0}] Command execution ItemID {1}: \"{2}\".", Name, scriptContainer.ItemID, p.EventName);
171 scriptContainer.ExecuteEvent(p);
172 m_log.DebugFormat("[{0}] ######################################################", Name);
173 }
174
175 }
176}
diff --git a/OpenSim/ScriptEngine/Components/DotNetEngine/Scheduler/ScriptManager_ScriptLoadUnload.cs b/OpenSim/ScriptEngine/Components/DotNetEngine/Scheduler/ScriptManager_ScriptLoadUnload.cs
new file mode 100644
index 0000000..7d362f9
--- /dev/null
+++ b/OpenSim/ScriptEngine/Components/DotNetEngine/Scheduler/ScriptManager_ScriptLoadUnload.cs
@@ -0,0 +1,259 @@
1using System;
2using System.Collections.Generic;
3using System.Globalization;
4using System.Reflection;
5using System.Text;
6using System.Threading;
7using log4net;
8using OpenMetaverse;
9using OpenSim.Framework;
10using OpenSim.Region.Environment.Scenes;
11using OpenSim.Region.ScriptEngine.Interfaces;
12using OpenSim.Region.ScriptEngine.Shared.ScriptBase;
13using OpenSim.ScriptEngine.Shared;
14
15namespace OpenSim.ScriptEngine.Components.DotNetEngine.Scheduler
16{
17 public partial class ScriptManager
18 {
19 private Queue<LoadUnloadStructure> LUQueue = new Queue<LoadUnloadStructure>();
20 private int LoadUnloadMaxQueueSize = 500;
21 private Object scriptLock = new Object();
22 //private Dictionary<InstanceData, DetectParams[]> detparms = new Dictionary<InstanceData, DetectParams[]>();
23
24 // Load/Unload structure
25
26
27 public void AddScript(ScriptStructure script)
28 {
29 lock (LUQueue)
30 {
31 if ((LUQueue.Count >= LoadUnloadMaxQueueSize))
32 {
33 m_log.ErrorFormat("[{0}] ERROR: Load queue count is at {1} of max {2}. Ignoring load request for script LocalID: {3}, ItemID: {4}.",
34 Name, LUQueue.Count, LoadUnloadMaxQueueSize, script.LocalID, script.ItemID);
35 return;
36 }
37
38 LoadUnloadStructure ls = new LoadUnloadStructure();
39 ls.Script = script;
40 ls.Action = LoadUnloadStructure.LUType.Load;
41 LUQueue.Enqueue(ls);
42 }
43
44 }
45 public void RemoveScript(uint localID, UUID itemID)
46 {
47 LoadUnloadStructure ls = new LoadUnloadStructure();
48
49 // See if we can find script
50 if (!TryGetScript(localID, itemID, ref ls.Script))
51 {
52 // Set manually
53 ls.Script.LocalID = localID;
54 ls.Script.ItemID = itemID;
55 }
56 ls.Script.StartParam = 0;
57
58 ls.Action = LoadUnloadStructure.LUType.Unload;
59 ls.PostOnRez = false;
60
61 lock (LUQueue)
62 {
63 LUQueue.Enqueue(ls);
64 }
65 }
66
67 internal bool DoScriptLoadUnload()
68 {
69 bool ret = false;
70 // if (!m_started)
71 // return;
72
73 lock (LUQueue)
74 {
75 if (LUQueue.Count > 0)
76 {
77 LoadUnloadStructure item = LUQueue.Dequeue();
78 ret = true;
79
80 if (item.Action == LoadUnloadStructure.LUType.Unload)
81 {
82 m_log.DebugFormat("[{0}] Unloading script", Name);
83 _StopScript(item.Script.LocalID, item.Script.ItemID);
84 RemoveScript(item.Script.LocalID, item.Script.ItemID);
85 }
86 else if (item.Action == LoadUnloadStructure.LUType.Load)
87 {
88 m_log.DebugFormat("[{0}] Loading script", Name);
89 _StartScript(item);
90 }
91 }
92 }
93 return ret;
94 }
95
96 //public void _StartScript(uint localID, UUID itemID, string Script, int startParam, bool postOnRez)
97 private void _StartScript(LoadUnloadStructure ScriptObject)
98 {
99 m_log.DebugFormat(
100 "[{0}]: ScriptManager StartScript: localID: {1}, itemID: {2}",
101 Name, ScriptObject.Script.LocalID, ScriptObject.Script.ItemID);
102
103 // We will initialize and start the script.
104 // It will be up to the script itself to hook up the correct events.
105
106 SceneObjectPart m_host = ScriptObject.Script.RegionInfo.Scene.GetSceneObjectPart(ScriptObject.Script.LocalID);
107
108 if (null == m_host)
109 {
110 m_log.ErrorFormat(
111 "[{0}]: Could not find scene object part corresponding " +
112 "to localID {1} to start script",
113 Name, ScriptObject.Script.LocalID);
114
115 return;
116 }
117
118 UUID assetID = UUID.Zero;
119 TaskInventoryItem taskInventoryItem = new TaskInventoryItem();
120 if (m_host.TaskInventory.TryGetValue(ScriptObject.Script.ItemID, out taskInventoryItem))
121 assetID = taskInventoryItem.AssetID;
122
123 ScenePresence presence =
124 ScriptObject.Script.RegionInfo.Scene.GetScenePresence(taskInventoryItem.OwnerID);
125
126 CultureInfo USCulture = new CultureInfo("en-US");
127 Thread.CurrentThread.CurrentCulture = USCulture;
128
129 try
130 {
131 //
132 // Compile script to an assembly
133 //
134 //TODO: DEBUG
135 BaseClassFactory.MakeBaseClass(ScriptObject.Script);
136
137 m_log.DebugFormat("[{0}] Compiling script {1}", Name, ScriptObject.Script.Name);
138
139 string fileName = "";
140 try
141 {
142 IScriptCompiler compiler =
143 ScriptObject.Script.RegionInfo.FindCompiler(ScriptObject.Script.ScriptMetaData);
144 RegionInfoStructure currentRegionInfo = ScriptObject.Script.RegionInfo;
145 fileName = compiler.Compile(ScriptObject.Script.ScriptMetaData,
146 ref ScriptObject.Script.Source);
147 ScriptObject.Script.AssemblyFileName = fileName;
148 }
149 catch (Exception e)
150 {
151 m_log.ErrorFormat("[{0}] Internal error while compiling \"{1}\": {2}", Name, ScriptObject.Script.Name, e.ToString());
152 }
153 m_log.DebugFormat("[{0}] Compiled \"{1}\" to assembly: \"{2}\".", Name, ScriptObject.Script.Name, fileName);
154
155 // Add it to our script memstruct
156 MemAddScript(ScriptObject.Script);
157
158 ScriptAssemblies.IScript CompiledScript;
159 CompiledScript = CurrentRegion.ScriptLoader.LoadScript(ScriptObject.Script);
160 ScriptObject.Script.State = "default";
161 ScriptObject.Script.ScriptObject = CompiledScript;
162 ScriptObject.Script.Disabled = false;
163 ScriptObject.Script.Running = true;
164 //id.LineMap = LSLCompiler.LineMap();
165 //id.Script = CompiledScript;
166 //id.Source = item.Script.Script;
167 //item.StartParam = startParam;
168
169
170
171 // TODO: Fire the first start-event
172 //int eventFlags =
173 // m_scriptEngine.m_ScriptManager.GetStateEventFlags(
174 // localID, itemID);
175
176 //m_host.SetScriptEvents(itemID, eventFlags);
177 ScriptObject.Script.RegionInfo.Executors_Execute(ScriptObject.Script,
178 new EventParams(ScriptObject.Script.LocalID, ScriptObject.Script.ItemID, "state_entry", new object[] { }, new Region.ScriptEngine.Shared.DetectParams[0])
179 );
180
181 if (ScriptObject.PostOnRez)
182 {
183 ScriptObject.Script.RegionInfo.Executors_Execute(ScriptObject.Script,
184 new EventParams(ScriptObject.Script.LocalID, "on_rez", new object[]
185 {new Region.ScriptEngine.Shared.LSL_Types.LSLInteger(ScriptObject.StartParam)
186 }, new Region.ScriptEngine.Shared.DetectParams[0]));
187 }
188 }
189 catch (Exception e) // LEGIT: User Scripting
190 {
191 if (presence != null && (!ScriptObject.PostOnRez))
192 presence.ControllingClient.SendAgentAlertMessage(
193 "Script saved with errors, check debug window!",
194 false);
195 try
196 {
197 // DISPLAY ERROR INWORLD
198 string text = "Error compiling script:\n" +
199 e.Message.ToString();
200 if (text.Length > 1100)
201 text = text.Substring(0, 1099);
202
203 ScriptObject.Script.RegionInfo.Scene.SimChat(Utils.StringToBytes(text),
204 ChatTypeEnum.DebugChannel, 2147483647,
205 m_host.AbsolutePosition, m_host.Name, m_host.UUID,
206 false);
207 }
208 catch (Exception e2) // LEGIT: User Scripting
209 {
210 m_log.Error("[" +
211 Name +
212 "]: Error displaying error in-world: " +
213 e2.ToString());
214 m_log.Error("[" +
215 Name + "]: " +
216 "Errormessage: Error compiling script:\r\n" +
217 e2.Message.ToString());
218 }
219 }
220 }
221
222
223
224 public void _StopScript(uint localID, UUID itemID)
225 {
226 ScriptStructure ss = new ScriptStructure();
227 if (!TryGetScript(localID, itemID, ref ss))
228 return;
229
230 // Stop long command on script
231 //AsyncCommandManager.RemoveScript(ss);
232
233 try
234 {
235 // Get AppDomain
236 // Tell script not to accept new requests
237 ss.Running = false;
238 ss.Disabled = true;
239 AppDomain ad = ss.AppDomain;
240
241 // Remove from internal structure
242 MemRemoveScript(localID, itemID);
243
244 // TODO: Tell AppDomain that we have stopped script
245
246 }
247 catch (Exception e) // LEGIT: User Scripting
248 {
249 m_log.Error("[" +
250 Name +
251 "]: Exception stopping script localID: " +
252 localID + " LLUID: " + itemID.ToString() +
253 ": " + e.ToString());
254 }
255 }
256
257
258 }
259}