aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/ScriptEngine
diff options
context:
space:
mode:
authorKittoFlora2009-11-16 01:40:15 +0100
committerKittoFlora2009-11-16 01:40:15 +0100
commit873c9098d8627972e80a1688e85a4cda45e1e7fe (patch)
treea0edc24aef11d5ad6928493d8985386f48dd2607 /OpenSim/Region/ScriptEngine
parentMerge branch 'vehicles' into tests (diff)
parentMerge branch 'master' into careminster (diff)
downloadopensim-SC-873c9098d8627972e80a1688e85a4cda45e1e7fe.zip
opensim-SC-873c9098d8627972e80a1688e85a4cda45e1e7fe.tar.gz
opensim-SC-873c9098d8627972e80a1688e85a4cda45e1e7fe.tar.bz2
opensim-SC-873c9098d8627972e80a1688e85a4cda45e1e7fe.tar.xz
Merge branch 'careminster' into tests
Diffstat (limited to 'OpenSim/Region/ScriptEngine')
-rw-r--r--OpenSim/Region/ScriptEngine/Interfaces/ICompiler.cs4
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs5
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Implementation/MOD_Api.cs134
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs91
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Interface/IMOD_Api.cs46
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs10
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Runtime/MOD_Stub.cs66
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs28
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OpenSim.Region.ScriptEngine.Shared.Api.Runtime.mdp1
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Runtime/ScriptBase.cs2
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/CodeTools/Compiler.cs191
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs54
-rw-r--r--OpenSim/Region/ScriptEngine/XEngine/XEngine.cs123
13 files changed, 528 insertions, 227 deletions
diff --git a/OpenSim/Region/ScriptEngine/Interfaces/ICompiler.cs b/OpenSim/Region/ScriptEngine/Interfaces/ICompiler.cs
index f8af902..e4ca635 100644
--- a/OpenSim/Region/ScriptEngine/Interfaces/ICompiler.cs
+++ b/OpenSim/Region/ScriptEngine/Interfaces/ICompiler.cs
@@ -34,9 +34,7 @@ namespace OpenSim.Region.ScriptEngine.Interfaces
34{ 34{
35 public interface ICompiler 35 public interface ICompiler
36 { 36 {
37 object PerformScriptCompile(string source, string asset, UUID ownerID); 37 void PerformScriptCompile(string source, string asset, UUID ownerID, out string assembly, out Dictionary<KeyValuePair<int, int>, KeyValuePair<int, int>> linemap);
38 string[] GetWarnings(); 38 string[] GetWarnings();
39 Dictionary<KeyValuePair<int, int>, KeyValuePair<int, int>>
40 LineMap();
41 } 39 }
42} 40}
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs
index 0f01c36..fc17808 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs
@@ -2163,7 +2163,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
2163 public LSL_Vector llGetOmega() 2163 public LSL_Vector llGetOmega()
2164 { 2164 {
2165 m_host.AddScriptLPS(1); 2165 m_host.AddScriptLPS(1);
2166 return new LSL_Vector(m_host.RotationalVelocity.X, m_host.RotationalVelocity.Y, m_host.RotationalVelocity.Z); 2166 return new LSL_Vector(m_host.AngularVelocity.X, m_host.AngularVelocity.Y, m_host.AngularVelocity.Z);
2167 } 2167 }
2168 2168
2169 public LSL_Float llGetTimeOfDay() 2169 public LSL_Float llGetTimeOfDay()
@@ -3163,7 +3163,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3163 public void llTargetOmega(LSL_Vector axis, double spinrate, double gain) 3163 public void llTargetOmega(LSL_Vector axis, double spinrate, double gain)
3164 { 3164 {
3165 m_host.AddScriptLPS(1); 3165 m_host.AddScriptLPS(1);
3166 m_host.RotationalVelocity = new Vector3((float)(axis.x * spinrate), (float)(axis.y * spinrate), (float)(axis.z * spinrate));
3167 m_host.AngularVelocity = new Vector3((float)(axis.x * spinrate), (float)(axis.y * spinrate), (float)(axis.z * spinrate)); 3166 m_host.AngularVelocity = new Vector3((float)(axis.x * spinrate), (float)(axis.y * spinrate), (float)(axis.z * spinrate));
3168 m_host.ScheduleTerseUpdate(); 3167 m_host.ScheduleTerseUpdate();
3169 m_host.SendTerseUpdateToAllClients(); 3168 m_host.SendTerseUpdateToAllClients();
@@ -3821,7 +3820,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3821 { 3820 {
3822 case 1: // DATA_ONLINE (0|1) 3821 case 1: // DATA_ONLINE (0|1)
3823 // TODO: implement fetching of this information 3822 // TODO: implement fetching of this information
3824 if (userProfile.CurrentAgent.AgentOnline) 3823 if (userProfile.CurrentAgent!=null && userProfile.CurrentAgent.AgentOnline)
3825 reply = "1"; 3824 reply = "1";
3826 else 3825 else
3827 reply = "0"; 3826 reply = "0";
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/MOD_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/MOD_Api.cs
new file mode 100644
index 0000000..d4facdd
--- /dev/null
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/MOD_Api.cs
@@ -0,0 +1,134 @@
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
28using System;
29using System.Reflection;
30using System.Collections;
31using System.Collections.Generic;
32using System.Runtime.Remoting.Lifetime;
33using OpenMetaverse;
34using Nini.Config;
35using OpenSim;
36using OpenSim.Framework;
37using OpenSim.Region.Framework.Interfaces;
38using OpenSim.Region.Framework.Scenes;
39using OpenSim.Region.ScriptEngine.Shared;
40using OpenSim.Region.ScriptEngine.Shared.Api.Plugins;
41using OpenSim.Region.ScriptEngine.Shared.ScriptBase;
42using OpenSim.Region.ScriptEngine.Interfaces;
43using OpenSim.Region.ScriptEngine.Shared.Api.Interfaces;
44
45using LSL_Float = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLFloat;
46using LSL_Integer = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLInteger;
47using LSL_Key = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLString;
48using LSL_List = OpenSim.Region.ScriptEngine.Shared.LSL_Types.list;
49using LSL_Rotation = OpenSim.Region.ScriptEngine.Shared.LSL_Types.Quaternion;
50using LSL_String = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLString;
51using LSL_Vector = OpenSim.Region.ScriptEngine.Shared.LSL_Types.Vector3;
52
53namespace OpenSim.Region.ScriptEngine.Shared.Api
54{
55 [Serializable]
56 public class MOD_Api : MarshalByRefObject, IMOD_Api, IScriptApi
57 {
58 internal IScriptEngine m_ScriptEngine;
59 internal SceneObjectPart m_host;
60 internal uint m_localID;
61 internal UUID m_itemID;
62 internal bool m_MODFunctionsEnabled = false;
63 internal IScriptModuleComms m_comms = null;
64
65 public void Initialize(IScriptEngine ScriptEngine, SceneObjectPart host, uint localID, UUID itemID)
66 {
67 m_ScriptEngine = ScriptEngine;
68 m_host = host;
69 m_localID = localID;
70 m_itemID = itemID;
71
72 if (m_ScriptEngine.Config.GetBoolean("AllowMODFunctions", false))
73 m_MODFunctionsEnabled = true;
74
75 m_comms = m_ScriptEngine.World.RequestModuleInterface<IScriptModuleComms>();
76 if (m_comms == null)
77 m_MODFunctionsEnabled = false;
78 }
79
80 public override Object InitializeLifetimeService()
81 {
82 ILease lease = (ILease)base.InitializeLifetimeService();
83
84 if (lease.CurrentState == LeaseState.Initial)
85 {
86 lease.InitialLeaseTime = TimeSpan.FromMinutes(0);
87// lease.RenewOnCallTime = TimeSpan.FromSeconds(10.0);
88// lease.SponsorshipTimeout = TimeSpan.FromMinutes(1.0);
89 }
90 return lease;
91 }
92
93 public Scene World
94 {
95 get { return m_ScriptEngine.World; }
96 }
97
98 internal void MODError(string msg)
99 {
100 throw new Exception("MOD Runtime Error: " + msg);
101 }
102
103 //
104 //Dumps an error message on the debug console.
105 //
106
107 internal void MODShoutError(string message)
108 {
109 if (message.Length > 1023)
110 message = message.Substring(0, 1023);
111
112 World.SimChat(Utils.StringToBytes(message),
113 ChatTypeEnum.Shout, ScriptBaseClass.DEBUG_CHANNEL, m_host.ParentGroup.RootPart.AbsolutePosition, m_host.Name, m_host.UUID, true);
114
115 IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>();
116 wComm.DeliverMessage(ChatTypeEnum.Shout, ScriptBaseClass.DEBUG_CHANNEL, m_host.Name, m_host.UUID, message);
117 }
118
119 public string modSendCommand(string module, string command, string k)
120 {
121 if (!m_MODFunctionsEnabled)
122 {
123 MODShoutError("Module command functions not enabled");
124 return UUID.Zero.ToString();;
125 }
126
127 UUID req = UUID.Random();
128
129 m_comms.RaiseEvent(m_itemID, req.ToString(), module, command, k);
130
131 return req.ToString();
132 }
133 }
134}
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs
index 52396b6..3ffcff0 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs
@@ -199,7 +199,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
199 //Dumps an error message on the debug console. 199 //Dumps an error message on the debug console.
200 // 200 //
201 201
202 internal void OSSLShoutError(string message) 202 internal void OSSLShoutError(string message)
203 { 203 {
204 if (message.Length > 1023) 204 if (message.Length > 1023)
205 message = message.Substring(0, 1023); 205 message = message.Substring(0, 1023);
@@ -384,7 +384,14 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
384 m_host.AddScriptLPS(1); 384 m_host.AddScriptLPS(1);
385 if (World.Entities.ContainsKey(target)) 385 if (World.Entities.ContainsKey(target))
386 { 386 {
387 World.Entities[target].Rotation = rotation; 387 EntityBase entity;
388 if (World.Entities.TryGetValue(target, out entity))
389 {
390 if (entity is SceneObjectGroup)
391 ((SceneObjectGroup)entity).Rotation = rotation;
392 else if (entity is ScenePresence)
393 ((ScenePresence)entity).Rotation = rotation;
394 }
388 } 395 }
389 else 396 else
390 { 397 {
@@ -1169,7 +1176,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1169 1176
1170 land.SetMediaUrl(url); 1177 land.SetMediaUrl(url);
1171 } 1178 }
1172 1179
1173 public void osSetParcelSIPAddress(string SIPAddress) 1180 public void osSetParcelSIPAddress(string SIPAddress)
1174 { 1181 {
1175 // What actually is the difference to the LL function? 1182 // What actually is the difference to the LL function?
@@ -1177,7 +1184,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1177 CheckThreatLevel(ThreatLevel.VeryLow, "osSetParcelMediaURL"); 1184 CheckThreatLevel(ThreatLevel.VeryLow, "osSetParcelMediaURL");
1178 1185
1179 m_host.AddScriptLPS(1); 1186 m_host.AddScriptLPS(1);
1180 1187
1181 1188
1182 ILandObject land 1189 ILandObject land
1183 = World.LandChannel.GetLandObject(m_host.AbsolutePosition.X, m_host.AbsolutePosition.Y); 1190 = World.LandChannel.GetLandObject(m_host.AbsolutePosition.X, m_host.AbsolutePosition.Y);
@@ -1187,16 +1194,16 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1187 OSSLError("osSetParcelSIPAddress: Sorry, you need to own the land to use this function"); 1194 OSSLError("osSetParcelSIPAddress: Sorry, you need to own the land to use this function");
1188 return; 1195 return;
1189 } 1196 }
1190 1197
1191 // get the voice module 1198 // get the voice module
1192 IVoiceModule voiceModule = World.RequestModuleInterface<IVoiceModule>(); 1199 IVoiceModule voiceModule = World.RequestModuleInterface<IVoiceModule>();
1193 1200
1194 if (voiceModule != null) 1201 if (voiceModule != null)
1195 voiceModule.setLandSIPAddress(SIPAddress,land.LandData.GlobalID); 1202 voiceModule.setLandSIPAddress(SIPAddress,land.LandData.GlobalID);
1196 else 1203 else
1197 OSSLError("osSetParcelSIPAddress: No voice module enabled for this land"); 1204 OSSLError("osSetParcelSIPAddress: No voice module enabled for this land");
1198 1205
1199 1206
1200 } 1207 }
1201 1208
1202 public string osGetScriptEngineName() 1209 public string osGetScriptEngineName()
@@ -1476,12 +1483,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1476 m_host.AddScriptLPS(1); 1483 m_host.AddScriptLPS(1);
1477 1484
1478 // Create new asset 1485 // Create new asset
1479 AssetBase asset = new AssetBase(); 1486 AssetBase asset = new AssetBase(UUID.Random(), notecardName, (sbyte)AssetType.Notecard);
1480 asset.Name = notecardName;
1481 asset.Description = "Script Generated Notecard"; 1487 asset.Description = "Script Generated Notecard";
1482 asset.Type = 7; 1488 string notecardData = String.Empty;
1483 asset.FullID = UUID.Random();
1484 string notecardData = "";
1485 1489
1486 for (int i = 0; i < contents.Length; i++) { 1490 for (int i = 0; i < contents.Length; i++) {
1487 notecardData += contents.GetLSLStringItem(i) + "\n"; 1491 notecardData += contents.GetLSLStringItem(i) + "\n";
@@ -1521,10 +1525,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1521 } 1525 }
1522 1526
1523 1527
1524 /*Instead of using the LSL Dataserver event to pull notecard data, 1528 /*Instead of using the LSL Dataserver event to pull notecard data,
1525 this will simply read the requested line and return its data as a string. 1529 this will simply read the requested line and return its data as a string.
1526 1530
1527 Warning - due to the synchronous method this function uses to fetch assets, its use 1531 Warning - due to the synchronous method this function uses to fetch assets, its use
1528 may be dangerous and unreliable while running in grid mode. 1532 may be dangerous and unreliable while running in grid mode.
1529 */ 1533 */
1530 public string osGetNotecardLine(string name, int line) 1534 public string osGetNotecardLine(string name, int line)
@@ -1572,10 +1576,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1572 1576
1573 } 1577 }
1574 1578
1575 /*Instead of using the LSL Dataserver event to pull notecard data line by line, 1579 /*Instead of using the LSL Dataserver event to pull notecard data line by line,
1576 this will simply read the entire notecard and return its data as a string. 1580 this will simply read the entire notecard and return its data as a string.
1577 1581
1578 Warning - due to the synchronous method this function uses to fetch assets, its use 1582 Warning - due to the synchronous method this function uses to fetch assets, its use
1579 may be dangerous and unreliable while running in grid mode. 1583 may be dangerous and unreliable while running in grid mode.
1580 */ 1584 */
1581 1585
@@ -1630,10 +1634,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1630 1634
1631 } 1635 }
1632 1636
1633 /*Instead of using the LSL Dataserver event to pull notecard data, 1637 /*Instead of using the LSL Dataserver event to pull notecard data,
1634 this will simply read the number of note card lines and return this data as an integer. 1638 this will simply read the number of note card lines and return this data as an integer.
1635 1639
1636 Warning - due to the synchronous method this function uses to fetch assets, its use 1640 Warning - due to the synchronous method this function uses to fetch assets, its use
1637 may be dangerous and unreliable while running in grid mode. 1641 may be dangerous and unreliable while running in grid mode.
1638 */ 1642 */
1639 1643
@@ -1833,7 +1837,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1833 1837
1834 return World.RegionInfo.RegionSettings.LoadedCreationID; 1838 return World.RegionInfo.RegionSettings.LoadedCreationID;
1835 } 1839 }
1836 1840
1837 // Threat level is 'Low' because certain users could possibly be tricked into 1841 // Threat level is 'Low' because certain users could possibly be tricked into
1838 // dropping an unverified script into one of their own objects, which could 1842 // dropping an unverified script into one of their own objects, which could
1839 // then gather the physical construction details of the object and transmit it 1843 // then gather the physical construction details of the object and transmit it
@@ -1857,7 +1861,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1857 public LSL_Key osNpcCreate(string firstname, string lastname, LSL_Vector position, LSL_Key cloneFrom) 1861 public LSL_Key osNpcCreate(string firstname, string lastname, LSL_Vector position, LSL_Key cloneFrom)
1858 { 1862 {
1859 CheckThreatLevel(ThreatLevel.High, "osNpcCreate"); 1863 CheckThreatLevel(ThreatLevel.High, "osNpcCreate");
1860 //QueueUserWorkItem 1864 //QueueUserWorkItem
1861 1865
1862 INPCModule module = World.RequestModuleInterface<INPCModule>(); 1866 INPCModule module = World.RequestModuleInterface<INPCModule>();
1863 if (module != null) 1867 if (module != null)
@@ -1906,5 +1910,42 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
1906 module.DeleteNPC(new UUID(npc.m_string), World); 1910 module.DeleteNPC(new UUID(npc.m_string), World);
1907 } 1911 }
1908 } 1912 }
1913
1914 /// <summary>
1915 /// Get current region's map texture UUID
1916 /// </summary>
1917 /// <returns></returns>
1918 public LSL_Key osGetMapTexture()
1919 {
1920 CheckThreatLevel(ThreatLevel.None, "osGetMapTexture");
1921 return m_ScriptEngine.World.RegionInfo.RegionSettings.TerrainImageID.ToString();
1922 }
1923
1924 /// <summary>
1925 /// Get a region's map texture UUID by region UUID or name.
1926 /// </summary>
1927 /// <param name="regionName"></param>
1928 /// <returns></returns>
1929 public LSL_Key osGetRegionMapTexture(string regionName)
1930 {
1931 CheckThreatLevel(ThreatLevel.High, "osGetRegionMapTexture");
1932 Scene scene = m_ScriptEngine.World;
1933 UUID key = UUID.Zero;
1934 GridRegion region;
1935
1936 //If string is a key, use it. Otherwise, try to locate region by name.
1937 if (UUID.TryParse(regionName, out key))
1938 region = scene.GridService.GetRegionByUUID(UUID.Zero, key);
1939 else
1940 region = scene.GridService.GetRegionByName(UUID.Zero, regionName);
1941
1942 // If region was found, return the regions map texture key.
1943 if (region != null)
1944 key = region.TerrainImage;
1945
1946 ScriptSleep(1000);
1947
1948 return key.ToString();
1949 }
1909 } 1950 }
1910} 1951}
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IMOD_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IMOD_Api.cs
new file mode 100644
index 0000000..e08eca5
--- /dev/null
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IMOD_Api.cs
@@ -0,0 +1,46 @@
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
28using System.Collections;
29using OpenSim.Region.ScriptEngine.Interfaces;
30
31using key = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLString;
32using rotation = OpenSim.Region.ScriptEngine.Shared.LSL_Types.Quaternion;
33using vector = OpenSim.Region.ScriptEngine.Shared.LSL_Types.Vector3;
34using LSL_List = OpenSim.Region.ScriptEngine.Shared.LSL_Types.list;
35using LSL_String = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLString;
36using LSL_Integer = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLInteger;
37using LSL_Float = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLFloat;
38
39namespace OpenSim.Region.ScriptEngine.Shared.Api.Interfaces
40{
41 public interface IMOD_Api
42 {
43 //Module functions
44 string modSendCommand(string modules, string command, string k);
45 }
46}
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs
index d8d3c31..2a403bf 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs
@@ -79,7 +79,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Interfaces
79 79
80 // Avatar Info Commands 80 // Avatar Info Commands
81 string osGetAgentIP(string agent); 81 string osGetAgentIP(string agent);
82 LSL_List osGetAgents(); 82 LSL_List osGetAgents();
83 83
84 // Teleport commands 84 // Teleport commands
85 void osTeleportAgent(string agent, string regionName, LSL_Types.Vector3 position, LSL_Types.Vector3 lookat); 85 void osTeleportAgent(string agent, string regionName, LSL_Types.Vector3 position, LSL_Types.Vector3 lookat);
@@ -127,7 +127,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Interfaces
127 string osGetScriptEngineName(); 127 string osGetScriptEngineName();
128 string osGetSimulatorVersion(); 128 string osGetSimulatorVersion();
129 Hashtable osParseJSON(string JSON); 129 Hashtable osParseJSON(string JSON);
130 130
131 void osMessageObject(key objectUUID,string message); 131 void osMessageObject(key objectUUID,string message);
132 132
133 void osMakeNotecard(string notecardName, LSL_Types.list contents); 133 void osMakeNotecard(string notecardName, LSL_Types.list contents);
@@ -138,7 +138,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Interfaces
138 138
139 string osAvatarName2Key(string firstname, string lastname); 139 string osAvatarName2Key(string firstname, string lastname);
140 string osKey2Name(string id); 140 string osKey2Name(string id);
141 141
142 // Grid Info Functions 142 // Grid Info Functions
143 string osGetGridNick(); 143 string osGetGridNick();
144 string osGetGridName(); 144 string osGetGridName();
@@ -151,7 +151,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Interfaces
151 string osLoadedCreationDate(); 151 string osLoadedCreationDate();
152 string osLoadedCreationTime(); 152 string osLoadedCreationTime();
153 string osLoadedCreationID(); 153 string osLoadedCreationID();
154 154
155 LSL_List osGetLinkPrimitiveParams(int linknumber, LSL_List rules); 155 LSL_List osGetLinkPrimitiveParams(int linknumber, LSL_List rules);
156 156
157 157
@@ -160,5 +160,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Interfaces
160 void osNpcSay(key npc, string message); 160 void osNpcSay(key npc, string message);
161 void osNpcRemove(key npc); 161 void osNpcRemove(key npc);
162 162
163 key osGetMapTexture();
164 key osGetRegionMapTexture(string regionName);
163 } 165 }
164} 166}
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/MOD_Stub.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/MOD_Stub.cs
new file mode 100644
index 0000000..6525c76
--- /dev/null
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/MOD_Stub.cs
@@ -0,0 +1,66 @@
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
28using System;
29using System.Runtime.Remoting.Lifetime;
30using System.Threading;
31using System.Reflection;
32using System.Collections;
33using System.Collections.Generic;
34using OpenSim.Framework;
35using OpenSim.Region.Framework.Interfaces;
36using OpenSim.Region.ScriptEngine.Interfaces;
37using OpenSim.Region.ScriptEngine.Shared.Api.Interfaces;
38using integer = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLInteger;
39using vector = OpenSim.Region.ScriptEngine.Shared.LSL_Types.Vector3;
40using rotation = OpenSim.Region.ScriptEngine.Shared.LSL_Types.Quaternion;
41using key = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLString;
42using LSL_List = OpenSim.Region.ScriptEngine.Shared.LSL_Types.list;
43using LSL_String = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLString;
44using LSL_Float = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLFloat;
45using LSL_Integer = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLInteger;
46
47namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
48{
49 public partial class ScriptBaseClass : MarshalByRefObject
50 {
51 public IMOD_Api m_MOD_Functions;
52
53 public void ApiTypeMOD(IScriptApi api)
54 {
55 if (!(api is IMOD_Api))
56 return;
57
58 m_MOD_Functions = (IMOD_Api)api;
59 }
60
61 public string modSendCommand(string module, string command, string k)
62 {
63 return m_MOD_Functions.modSendCommand(module, command, k);
64 }
65 }
66}
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs
index 8dcb1f5..4928e90 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs
@@ -94,7 +94,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
94 { 94 {
95 return m_OSSL_Functions.osWindActiveModelPluginName(); 95 return m_OSSL_Functions.osWindActiveModelPluginName();
96 } 96 }
97 97
98// Not yet plugged in as available OSSL functions, so commented out 98// Not yet plugged in as available OSSL functions, so commented out
99// void osWindParamSet(string plugin, string param, float value) 99// void osWindParamSet(string plugin, string param, float value)
100// { 100// {
@@ -138,14 +138,14 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
138 public string osSetDynamicTextureURLBlendFace(string dynamicID, string contentType, string url, string extraParams, 138 public string osSetDynamicTextureURLBlendFace(string dynamicID, string contentType, string url, string extraParams,
139 bool blend, int disp, int timer, int alpha, int face) 139 bool blend, int disp, int timer, int alpha, int face)
140 { 140 {
141 return m_OSSL_Functions.osSetDynamicTextureURLBlendFace(dynamicID, contentType, url, extraParams, 141 return m_OSSL_Functions.osSetDynamicTextureURLBlendFace(dynamicID, contentType, url, extraParams,
142 blend, disp, timer, alpha, face); 142 blend, disp, timer, alpha, face);
143 } 143 }
144 144
145 public string osSetDynamicTextureDataBlendFace(string dynamicID, string contentType, string data, string extraParams, 145 public string osSetDynamicTextureDataBlendFace(string dynamicID, string contentType, string data, string extraParams,
146 bool blend, int disp, int timer, int alpha, int face) 146 bool blend, int disp, int timer, int alpha, int face)
147 { 147 {
148 return m_OSSL_Functions.osSetDynamicTextureDataBlendFace(dynamicID, contentType, data, extraParams, 148 return m_OSSL_Functions.osSetDynamicTextureDataBlendFace(dynamicID, contentType, data, extraParams,
149 blend, disp, timer, alpha, face); 149 blend, disp, timer, alpha, face);
150 } 150 }
151 151
@@ -183,7 +183,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
183 { 183 {
184 m_OSSL_Functions.osSetParcelMediaURL(url); 184 m_OSSL_Functions.osSetParcelMediaURL(url);
185 } 185 }
186 186
187 public void osSetParcelSIPAddress(string SIPAddress) 187 public void osSetParcelSIPAddress(string SIPAddress)
188 { 188 {
189 m_OSSL_Functions.osSetParcelSIPAddress(SIPAddress); 189 m_OSSL_Functions.osSetParcelSIPAddress(SIPAddress);
@@ -211,7 +211,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
211 m_OSSL_Functions.osTeleportAgent(agent, position, lookat); 211 m_OSSL_Functions.osTeleportAgent(agent, position, lookat);
212 } 212 }
213 213
214 // Avatar info functions 214 // Avatar info functions
215 public string osGetAgentIP(string agent) 215 public string osGetAgentIP(string agent)
216 { 216 {
217 return m_OSSL_Functions.osGetAgentIP(agent); 217 return m_OSSL_Functions.osGetAgentIP(agent);
@@ -326,17 +326,17 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
326 { 326 {
327 return m_OSSL_Functions.osGetScriptEngineName(); 327 return m_OSSL_Functions.osGetScriptEngineName();
328 } 328 }
329 329
330 public string osGetSimulatorVersion() 330 public string osGetSimulatorVersion()
331 { 331 {
332 return m_OSSL_Functions.osGetSimulatorVersion(); 332 return m_OSSL_Functions.osGetSimulatorVersion();
333 } 333 }
334 334
335 public Hashtable osParseJSON(string JSON) 335 public Hashtable osParseJSON(string JSON)
336 { 336 {
337 return m_OSSL_Functions.osParseJSON(JSON); 337 return m_OSSL_Functions.osParseJSON(JSON);
338 } 338 }
339 339
340 public void osMessageObject(key objectUUID,string message) 340 public void osMessageObject(key objectUUID,string message)
341 { 341 {
342 m_OSSL_Functions.osMessageObject(objectUUID,message); 342 m_OSSL_Functions.osMessageObject(objectUUID,message);
@@ -412,7 +412,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
412 { 412 {
413 return m_OSSL_Functions.osLoadedCreationID(); 413 return m_OSSL_Functions.osLoadedCreationID();
414 } 414 }
415 415
416 public LSL_List osGetLinkPrimitiveParams(int linknumber, LSL_List rules) 416 public LSL_List osGetLinkPrimitiveParams(int linknumber, LSL_List rules)
417 { 417 {
418 return m_OSSL_Functions.osGetLinkPrimitiveParams(linknumber, rules); 418 return m_OSSL_Functions.osGetLinkPrimitiveParams(linknumber, rules);
@@ -622,5 +622,15 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
622 } 622 }
623 } 623 }
624 } 624 }
625
626 public key osGetMapTexture()
627 {
628 return m_OSSL_Functions.osGetMapTexture();
629 }
630
631 public key osGetRegionMapTexture(string regionName)
632 {
633 return m_OSSL_Functions.osGetRegionMapTexture(regionName);
634 }
625 } 635 }
626} 636}
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OpenSim.Region.ScriptEngine.Shared.Api.Runtime.mdp b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OpenSim.Region.ScriptEngine.Shared.Api.Runtime.mdp
index feff86a..98bbc68 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OpenSim.Region.ScriptEngine.Shared.Api.Runtime.mdp
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OpenSim.Region.ScriptEngine.Shared.Api.Runtime.mdp
@@ -20,6 +20,7 @@
20 <File name="./Executor.cs" subtype="Code" buildaction="Compile" dependson="" data="" /> 20 <File name="./Executor.cs" subtype="Code" buildaction="Compile" dependson="" data="" />
21 <File name="./LSL_Constants.cs" subtype="Code" buildaction="Compile" dependson="" data="" /> 21 <File name="./LSL_Constants.cs" subtype="Code" buildaction="Compile" dependson="" data="" />
22 <File name="./LSL_Stub.cs" subtype="Code" buildaction="Compile" dependson="" data="" /> 22 <File name="./LSL_Stub.cs" subtype="Code" buildaction="Compile" dependson="" data="" />
23 <File name="./MOD_Stub.cs" subtype="Code" buildaction="Compile" dependson="" data="" />
23 <File name="./OSSL_Stub.cs" subtype="Code" buildaction="Compile" dependson="" data="" /> 24 <File name="./OSSL_Stub.cs" subtype="Code" buildaction="Compile" dependson="" data="" />
24 <File name="./ScriptBase.cs" subtype="Code" buildaction="Compile" dependson="" data="" /> 25 <File name="./ScriptBase.cs" subtype="Code" buildaction="Compile" dependson="" data="" />
25 <File name="./ScriptSponsor.cs" subtype="Code" buildaction="Compile" dependson="" data="" /> 26 <File name="./ScriptSponsor.cs" subtype="Code" buildaction="Compile" dependson="" data="" />
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/ScriptBase.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/ScriptBase.cs
index 917ca44..121159c 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/ScriptBase.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/ScriptBase.cs
@@ -113,7 +113,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
113 return; 113 return;
114 114
115 //ILease lease = (ILease)RemotingServices.GetLifetimeService(data as MarshalByRefObject); 115 //ILease lease = (ILease)RemotingServices.GetLifetimeService(data as MarshalByRefObject);
116 RemotingServices.GetLifetimeService(data as MarshalByRefObject); 116 //RemotingServices.GetLifetimeService(data as MarshalByRefObject);
117// lease.Register(m_sponser); 117// lease.Register(m_sponser);
118 118
119 MethodInfo mi = inits[api]; 119 MethodInfo mi = inits[api];
diff --git a/OpenSim/Region/ScriptEngine/Shared/CodeTools/Compiler.cs b/OpenSim/Region/ScriptEngine/Shared/CodeTools/Compiler.cs
index fe26429..3080c71 100644
--- a/OpenSim/Region/ScriptEngine/Shared/CodeTools/Compiler.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/CodeTools/Compiler.cs
@@ -74,7 +74,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
74 private string FilePrefix; 74 private string FilePrefix;
75 private string ScriptEnginesPath = "ScriptEngines"; 75 private string ScriptEnginesPath = "ScriptEngines";
76 // mapping between LSL and C# line/column numbers 76 // mapping between LSL and C# line/column numbers
77 private Dictionary<KeyValuePair<int, int>, KeyValuePair<int, int>> m_positionMap;
78 private ICodeConverter LSL_Converter; 77 private ICodeConverter LSL_Converter;
79 78
80 private List<string> m_warnings = new List<string>(); 79 private List<string> m_warnings = new List<string>();
@@ -91,6 +90,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
91 private static UInt64 scriptCompileCounter = 0; // And a counter 90 private static UInt64 scriptCompileCounter = 0; // And a counter
92 91
93 public IScriptEngine m_scriptEngine; 92 public IScriptEngine m_scriptEngine;
93 private Dictionary<string, Dictionary<KeyValuePair<int, int>, KeyValuePair<int, int>>> m_lineMaps =
94 new Dictionary<string, Dictionary<KeyValuePair<int, int>, KeyValuePair<int, int>>>();
95
94 public Compiler(IScriptEngine scriptEngine) 96 public Compiler(IScriptEngine scriptEngine)
95 { 97 {
96 m_scriptEngine = scriptEngine; 98 m_scriptEngine = scriptEngine;
@@ -172,8 +174,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
172 else 174 else
173 { 175 {
174#if DEBUG 176#if DEBUG
175// m_log.Debug("[Compiler]: " + 177 // m_log.Debug("[Compiler]: " +
176// "Config OK. Default language \"" + defaultCompileLanguage + "\" specified in \"DefaultCompileLanguage\" is recognized as a valid language."); 178 // "Config OK. Default language \"" + defaultCompileLanguage + "\" specified in \"DefaultCompileLanguage\" is recognized as a valid language.");
177#endif 179#endif
178 // LANGUAGE IS IN ALLOW-LIST 180 // LANGUAGE IS IN ALLOW-LIST
179 DefaultCompileLanguage = LanguageMapping[defaultCompileLanguage]; 181 DefaultCompileLanguage = LanguageMapping[defaultCompileLanguage];
@@ -212,12 +214,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
212 catch (Exception ex) 214 catch (Exception ex)
213 { 215 {
214 m_log.Error("[Compiler]: Exception trying to create ScriptEngine directory \"" + Path.Combine(ScriptEnginesPath, 216 m_log.Error("[Compiler]: Exception trying to create ScriptEngine directory \"" + Path.Combine(ScriptEnginesPath,
215 m_scriptEngine.World.RegionInfo.RegionID.ToString())+ "\": " + ex.ToString()); 217 m_scriptEngine.World.RegionInfo.RegionID.ToString()) + "\": " + ex.ToString());
216 } 218 }
217 } 219 }
218 220
219 foreach (string file in Directory.GetFiles(Path.Combine(ScriptEnginesPath, 221 foreach (string file in Directory.GetFiles(Path.Combine(ScriptEnginesPath,
220 m_scriptEngine.World.RegionInfo.RegionID.ToString()),FilePrefix + "_compiled*")) 222 m_scriptEngine.World.RegionInfo.RegionID.ToString()), FilePrefix + "_compiled*"))
221 { 223 {
222 try 224 try
223 { 225 {
@@ -271,16 +273,15 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
271 /// </summary> 273 /// </summary>
272 /// <param name="Script">LSL script</param> 274 /// <param name="Script">LSL script</param>
273 /// <returns>Filename to .dll assembly</returns> 275 /// <returns>Filename to .dll assembly</returns>
274 public object PerformScriptCompile(string Script, string asset, UUID ownerUUID) 276 public void PerformScriptCompile(string Script, string asset, UUID ownerUUID,
277 out string assembly, out Dictionary<KeyValuePair<int, int>, KeyValuePair<int, int>> linemap)
275 { 278 {
276 m_positionMap = null; 279 linemap = null;
277 m_warnings.Clear(); 280 m_warnings.Clear();
278 281
279 string OutFile = Path.Combine(ScriptEnginesPath, Path.Combine( 282 assembly = Path.Combine(ScriptEnginesPath, Path.Combine(
280 m_scriptEngine.World.RegionInfo.RegionID.ToString(), 283 m_scriptEngine.World.RegionInfo.RegionID.ToString(),
281 FilePrefix + "_compiled_" + asset + ".dll")); 284 FilePrefix + "_compiled_" + asset + ".dll"));
282// string OutFile = Path.Combine(ScriptEnginesPath,
283// FilePrefix + "_compiled_" + asset + ".dll");
284 285
285 if (!Directory.Exists(ScriptEnginesPath)) 286 if (!Directory.Exists(ScriptEnginesPath))
286 { 287 {
@@ -305,60 +306,63 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
305 } 306 }
306 } 307 }
307 308
308 if (Script == String.Empty) 309 // Don't recompile if we already have it
310 // Performing 3 file exists tests for every script can still be slow
311 if (File.Exists(assembly) && File.Exists(assembly + ".text") && File.Exists(assembly + ".map"))
309 { 312 {
310 if (File.Exists(OutFile)) 313 // If we have already read this linemap file, then it will be in our dictionary.
311 return OutFile; 314 // Don't build another copy of the dictionary (saves memory) and certainly
312 315 // don't keep reading the same file from disk multiple times.
313 throw new Exception("Cannot find script assembly and no script text present"); 316 if (!m_lineMaps.ContainsKey(assembly))
317 m_lineMaps[assembly] = ReadMapFile(assembly + ".map");
318 linemap = m_lineMaps[assembly];
319 return;
314 } 320 }
315 321
316 // Don't recompile if we already have it 322 if (Script == String.Empty)
317 //
318 if (File.Exists(OutFile) && File.Exists(OutFile+".text") && File.Exists(OutFile+".map"))
319 { 323 {
320 ReadMapFile(OutFile+".map"); 324 throw new Exception("Cannot find script assembly and no script text present");
321 return OutFile;
322 } 325 }
323 326
324 enumCompileType l = DefaultCompileLanguage; 327 enumCompileType language = DefaultCompileLanguage;
325 328
326 if (Script.StartsWith("//c#", true, CultureInfo.InvariantCulture)) 329 if (Script.StartsWith("//c#", true, CultureInfo.InvariantCulture))
327 l = enumCompileType.cs; 330 language = enumCompileType.cs;
328 if (Script.StartsWith("//vb", true, CultureInfo.InvariantCulture)) 331 if (Script.StartsWith("//vb", true, CultureInfo.InvariantCulture))
329 { 332 {
330 l = enumCompileType.vb; 333 language = enumCompileType.vb;
331 // We need to remove //vb, it won't compile with that 334 // We need to remove //vb, it won't compile with that
332 335
333 Script = Script.Substring(4, Script.Length - 4); 336 Script = Script.Substring(4, Script.Length - 4);
334 } 337 }
335 if (Script.StartsWith("//lsl", true, CultureInfo.InvariantCulture)) 338 if (Script.StartsWith("//lsl", true, CultureInfo.InvariantCulture))
336 l = enumCompileType.lsl; 339 language = enumCompileType.lsl;
337 340
338 if (Script.StartsWith("//js", true, CultureInfo.InvariantCulture)) 341 if (Script.StartsWith("//js", true, CultureInfo.InvariantCulture))
339 l = enumCompileType.js; 342 language = enumCompileType.js;
340 343
341 if (Script.StartsWith("//yp", true, CultureInfo.InvariantCulture)) 344 if (Script.StartsWith("//yp", true, CultureInfo.InvariantCulture))
342 l = enumCompileType.yp; 345 language = enumCompileType.yp;
343 346
344 if (!AllowedCompilers.ContainsKey(l.ToString())) 347 if (!AllowedCompilers.ContainsKey(language.ToString()))
345 { 348 {
346 // Not allowed to compile to this language! 349 // Not allowed to compile to this language!
347 string errtext = String.Empty; 350 string errtext = String.Empty;
348 errtext += "The compiler for language \"" + l.ToString() + "\" is not in list of allowed compilers. Script will not be executed!"; 351 errtext += "The compiler for language \"" + language.ToString() + "\" is not in list of allowed compilers. Script will not be executed!";
349 throw new Exception(errtext); 352 throw new Exception(errtext);
350 } 353 }
351 354
352 if (m_scriptEngine.World.Permissions.CanCompileScript(ownerUUID, (int)l) == false) { 355 if (m_scriptEngine.World.Permissions.CanCompileScript(ownerUUID, (int)language) == false)
356 {
353 // Not allowed to compile to this language! 357 // Not allowed to compile to this language!
354 string errtext = String.Empty; 358 string errtext = String.Empty;
355 errtext += ownerUUID + " is not in list of allowed users for this scripting language. Script will not be executed!"; 359 errtext += ownerUUID + " is not in list of allowed users for this scripting language. Script will not be executed!";
356 throw new Exception(errtext); 360 throw new Exception(errtext);
357 } 361 }
358 362
359 string compileScript = Script; 363 string compileScript = Script;
360 364
361 if (l == enumCompileType.lsl) 365 if (language == enumCompileType.lsl)
362 { 366 {
363 // Its LSL, convert it to C# 367 // Its LSL, convert it to C#
364 LSL_Converter = (ICodeConverter)new CSCodeGenerator(); 368 LSL_Converter = (ICodeConverter)new CSCodeGenerator();
@@ -370,16 +374,19 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
370 AddWarning(warning); 374 AddWarning(warning);
371 } 375 }
372 376
373 m_positionMap = ((CSCodeGenerator) LSL_Converter).PositionMap; 377 linemap = ((CSCodeGenerator)LSL_Converter).PositionMap;
378 // Write the linemap to a file and save it in our dictionary for next time.
379 m_lineMaps[assembly] = linemap;
380 WriteMapFile(assembly + ".map", linemap);
374 } 381 }
375 382
376 if (l == enumCompileType.yp) 383 if (language == enumCompileType.yp)
377 { 384 {
378 // Its YP, convert it to C# 385 // Its YP, convert it to C#
379 compileScript = YP_Converter.Convert(Script); 386 compileScript = YP_Converter.Convert(Script);
380 } 387 }
381 388
382 switch (l) 389 switch (language)
383 { 390 {
384 case enumCompileType.cs: 391 case enumCompileType.cs:
385 case enumCompileType.lsl: 392 case enumCompileType.lsl:
@@ -396,7 +403,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
396 break; 403 break;
397 } 404 }
398 405
399 return CompileFromDotNetText(compileScript, l, asset); 406 assembly = CompileFromDotNetText(compileScript, language, asset, assembly);
407 return;
400 } 408 }
401 409
402 public string[] GetWarnings() 410 public string[] GetWarnings()
@@ -468,22 +476,19 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
468 /// </summary> 476 /// </summary>
469 /// <param name="Script">CS script</param> 477 /// <param name="Script">CS script</param>
470 /// <returns>Filename to .dll assembly</returns> 478 /// <returns>Filename to .dll assembly</returns>
471 internal string CompileFromDotNetText(string Script, enumCompileType lang, string asset) 479 internal string CompileFromDotNetText(string Script, enumCompileType lang, string asset, string assembly)
472 { 480 {
473 string ext = "." + lang.ToString(); 481 string ext = "." + lang.ToString();
474 482
475 // Output assembly name 483 // Output assembly name
476 scriptCompileCounter++; 484 scriptCompileCounter++;
477 string OutFile = Path.Combine(ScriptEnginesPath, Path.Combine(
478 m_scriptEngine.World.RegionInfo.RegionID.ToString(),
479 FilePrefix + "_compiled_" + asset + ".dll"));
480 try 485 try
481 { 486 {
482 File.Delete(OutFile); 487 File.Delete(assembly);
483 } 488 }
484 catch (Exception e) // NOTLEGIT - Should be just FileIOException 489 catch (Exception e) // NOTLEGIT - Should be just FileIOException
485 { 490 {
486 throw new Exception("Unable to delete old existing "+ 491 throw new Exception("Unable to delete old existing " +
487 "script-file before writing new. Compile aborted: " + 492 "script-file before writing new. Compile aborted: " +
488 e.ToString()); 493 e.ToString());
489 } 494 }
@@ -492,7 +497,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
492 if (WriteScriptSourceToDebugFile) 497 if (WriteScriptSourceToDebugFile)
493 { 498 {
494 string srcFileName = FilePrefix + "_source_" + 499 string srcFileName = FilePrefix + "_source_" +
495 Path.GetFileNameWithoutExtension(OutFile) + ext; 500 Path.GetFileNameWithoutExtension(assembly) + ext;
496 try 501 try
497 { 502 {
498 File.WriteAllText(Path.Combine(Path.Combine( 503 File.WriteAllText(Path.Combine(Path.Combine(
@@ -502,7 +507,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
502 } 507 }
503 catch (Exception ex) //NOTLEGIT - Should be just FileIOException 508 catch (Exception ex) //NOTLEGIT - Should be just FileIOException
504 { 509 {
505 m_log.Error("[Compiler]: Exception while "+ 510 m_log.Error("[Compiler]: Exception while " +
506 "trying to write script source to file \"" + 511 "trying to write script source to file \"" +
507 srcFileName + "\": " + ex.ToString()); 512 srcFileName + "\": " + ex.ToString());
508 } 513 }
@@ -528,7 +533,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
528 } 533 }
529 534
530 parameters.GenerateExecutable = false; 535 parameters.GenerateExecutable = false;
531 parameters.OutputAssembly = OutFile; 536 parameters.OutputAssembly = assembly;
532 parameters.IncludeDebugInformation = CompileWithDebugInformation; 537 parameters.IncludeDebugInformation = CompileWithDebugInformation;
533 //parameters.WarningLevel = 1; // Should be 4? 538 //parameters.WarningLevel = 1; // Should be 4?
534 parameters.TreatWarningsAsErrors = false; 539 parameters.TreatWarningsAsErrors = false;
@@ -543,7 +548,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
543 case enumCompileType.cs: 548 case enumCompileType.cs:
544 case enumCompileType.lsl: 549 case enumCompileType.lsl:
545 bool complete = false; 550 bool complete = false;
546 bool retried = false; 551 bool retried = false;
547 do 552 do
548 { 553 {
549 lock (CScodeProvider) 554 lock (CScodeProvider)
@@ -584,7 +589,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
584 parameters, Script); 589 parameters, Script);
585 break; 590 break;
586 default: 591 default:
587 throw new Exception("Compiler is not able to recongnize "+ 592 throw new Exception("Compiler is not able to recongnize " +
588 "language type \"" + lang.ToString() + "\""); 593 "language type \"" + lang.ToString() + "\"");
589 } 594 }
590 595
@@ -609,7 +614,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
609 614
610 if (severity == "Error") 615 if (severity == "Error")
611 { 616 {
612 lslPos = FindErrorPosition(CompErr.Line, CompErr.Column); 617 lslPos = FindErrorPosition(CompErr.Line, CompErr.Column, m_lineMaps[assembly]);
613 string text = CompErr.ErrorText; 618 string text = CompErr.ErrorText;
614 619
615 // Use LSL type names 620 // Use LSL type names
@@ -635,14 +640,14 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
635 // the compile may not be immediately apparent. Wait a 640 // the compile may not be immediately apparent. Wait a
636 // reasonable amount of time before giving up on it. 641 // reasonable amount of time before giving up on it.
637 642
638 if (!File.Exists(OutFile)) 643 if (!File.Exists(assembly))
639 { 644 {
640 for (int i=0; i<20 && !File.Exists(OutFile); i++) 645 for (int i = 0; i < 20 && !File.Exists(assembly); i++)
641 { 646 {
642 System.Threading.Thread.Sleep(250); 647 System.Threading.Thread.Sleep(250);
643 } 648 }
644 // One final chance... 649 // One final chance...
645 if (!File.Exists(OutFile)) 650 if (!File.Exists(assembly))
646 { 651 {
647 errtext = String.Empty; 652 errtext = String.Empty;
648 errtext += "No compile error. But not able to locate compiled file."; 653 errtext += "No compile error. But not able to locate compiled file.";
@@ -650,15 +655,15 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
650 } 655 }
651 } 656 }
652 657
653// m_log.DebugFormat("[Compiler] Compiled new assembly "+ 658 // m_log.DebugFormat("[Compiler] Compiled new assembly "+
654// "for {0}", asset); 659 // "for {0}", asset);
655 660
656 // Because windows likes to perform exclusive locks, we simply 661 // Because windows likes to perform exclusive locks, we simply
657 // write out a textual representation of the file here 662 // write out a textual representation of the file here
658 // 663 //
659 // Read the binary file into a buffer 664 // Read the binary file into a buffer
660 // 665 //
661 FileInfo fi = new FileInfo(OutFile); 666 FileInfo fi = new FileInfo(assembly);
662 667
663 if (fi == null) 668 if (fi == null)
664 { 669 {
@@ -671,7 +676,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
671 676
672 try 677 try
673 { 678 {
674 FileStream fs = File.Open(OutFile, FileMode.Open, FileAccess.Read); 679 FileStream fs = File.Open(assembly, FileMode.Open, FileAccess.Read);
675 fs.Read(data, 0, data.Length); 680 fs.Read(data, 0, data.Length);
676 fs.Close(); 681 fs.Close();
677 } 682 }
@@ -690,40 +695,17 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
690 695
691 Byte[] buf = enc.GetBytes(filetext); 696 Byte[] buf = enc.GetBytes(filetext);
692 697
693 FileStream sfs = File.Create(OutFile+".text"); 698 FileStream sfs = File.Create(assembly + ".text");
694 sfs.Write(buf, 0, buf.Length); 699 sfs.Write(buf, 0, buf.Length);
695 sfs.Close(); 700 sfs.Close();
696 701
697 string posmap = String.Empty; 702 return assembly;
698 if (m_positionMap != null)
699 {
700 foreach (KeyValuePair<KeyValuePair<int, int>, KeyValuePair<int, int>> kvp in m_positionMap)
701 {
702 KeyValuePair<int, int> k = kvp.Key;
703 KeyValuePair<int, int> v = kvp.Value;
704 posmap += String.Format("{0},{1},{2},{3}\n",
705 k.Key, k.Value, v.Key, v.Value);
706 }
707 }
708
709 buf = enc.GetBytes(posmap);
710
711 FileStream mfs = File.Create(OutFile+".map");
712 mfs.Write(buf, 0, buf.Length);
713 mfs.Close();
714
715 return OutFile;
716 }
717
718 public KeyValuePair<int, int> FindErrorPosition(int line, int col)
719 {
720 return FindErrorPosition(line, col, m_positionMap);
721 } 703 }
722 704
723 private class kvpSorter : IComparer<KeyValuePair<int,int>> 705 private class kvpSorter : IComparer<KeyValuePair<int, int>>
724 { 706 {
725 public int Compare(KeyValuePair<int,int> a, 707 public int Compare(KeyValuePair<int, int> a,
726 KeyValuePair<int,int> b) 708 KeyValuePair<int, int> b)
727 { 709 {
728 return a.Key.CompareTo(b.Key); 710 return a.Key.CompareTo(b.Key);
729 } 711 }
@@ -742,8 +724,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
742 out ret)) 724 out ret))
743 return ret; 725 return ret;
744 726
745 List<KeyValuePair<int,int>> sorted = 727 List<KeyValuePair<int, int>> sorted =
746 new List<KeyValuePair<int,int>>(positionMap.Keys); 728 new List<KeyValuePair<int, int>>(positionMap.Keys);
747 729
748 sorted.Sort(new kvpSorter()); 730 sorted.Sort(new kvpSorter());
749 731
@@ -791,32 +773,37 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
791 return message; 773 return message;
792 } 774 }
793 775
794 public Dictionary<KeyValuePair<int, int>, KeyValuePair<int, int>> LineMap() 776
777 private static void WriteMapFile(string filename, Dictionary<KeyValuePair<int, int>, KeyValuePair<int, int>> linemap)
795 { 778 {
796 if (m_positionMap == null) 779 string mapstring = String.Empty;
797 return null; 780 foreach (KeyValuePair<KeyValuePair<int, int>, KeyValuePair<int, int>> kvp in linemap)
798 781 {
799 Dictionary<KeyValuePair<int, int>, KeyValuePair<int, int>> ret = 782 KeyValuePair<int, int> k = kvp.Key;
800 new Dictionary<KeyValuePair<int,int>, KeyValuePair<int, int>>(); 783 KeyValuePair<int, int> v = kvp.Value;
801 784 mapstring += String.Format("{0},{1},{2},{3}\n", k.Key, k.Value, v.Key, v.Value);
802 foreach (KeyValuePair<int, int> kvp in m_positionMap.Keys) 785 }
803 ret.Add(kvp, m_positionMap[kvp]); 786
804 787 System.Text.ASCIIEncoding enc = new System.Text.ASCIIEncoding();
805 return ret; 788 Byte[] mapbytes = enc.GetBytes(mapstring);
789 FileStream mfs = File.Create(filename);
790 mfs.Write(mapbytes, 0, mapbytes.Length);
791 mfs.Close();
806 } 792 }
807 793
808 private void ReadMapFile(string filename) 794
795 private static Dictionary<KeyValuePair<int, int>, KeyValuePair<int, int>> ReadMapFile(string filename)
809 { 796 {
797 Dictionary<KeyValuePair<int, int>, KeyValuePair<int, int>> linemap;
810 try 798 try
811 { 799 {
812 StreamReader r = File.OpenText(filename); 800 StreamReader r = File.OpenText(filename);
801 linemap = new Dictionary<KeyValuePair<int, int>, KeyValuePair<int, int>>();
813 802
814 m_positionMap = new Dictionary<KeyValuePair<int,int>, KeyValuePair<int, int>>();
815
816 string line; 803 string line;
817 while ((line = r.ReadLine()) != null) 804 while ((line = r.ReadLine()) != null)
818 { 805 {
819 String[] parts = line.Split(new Char[] {','}); 806 String[] parts = line.Split(new Char[] { ',' });
820 int kk = System.Convert.ToInt32(parts[0]); 807 int kk = System.Convert.ToInt32(parts[0]);
821 int kv = System.Convert.ToInt32(parts[1]); 808 int kv = System.Convert.ToInt32(parts[1]);
822 int vk = System.Convert.ToInt32(parts[2]); 809 int vk = System.Convert.ToInt32(parts[2]);
@@ -825,12 +812,14 @@ namespace OpenSim.Region.ScriptEngine.Shared.CodeTools
825 KeyValuePair<int, int> k = new KeyValuePair<int, int>(kk, kv); 812 KeyValuePair<int, int> k = new KeyValuePair<int, int>(kk, kv);
826 KeyValuePair<int, int> v = new KeyValuePair<int, int>(vk, vv); 813 KeyValuePair<int, int> v = new KeyValuePair<int, int>(vk, vv);
827 814
828 m_positionMap[k] = v; 815 linemap[k] = v;
829 } 816 }
830 } 817 }
831 catch 818 catch
832 { 819 {
820 linemap = new Dictionary<KeyValuePair<int, int>, KeyValuePair<int, int>>();
833 } 821 }
822 return linemap;
834 } 823 }
835 } 824 }
836} 825}
diff --git a/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs b/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs
index 2b858ec..549c038 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Instance/ScriptInstance.cs
@@ -74,27 +74,27 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
74 private string m_PrimName; 74 private string m_PrimName;
75 private string m_ScriptName; 75 private string m_ScriptName;
76 private string m_Assembly; 76 private string m_Assembly;
77 private int m_StartParam = 0; 77 private int m_StartParam;
78 private string m_CurrentEvent = String.Empty; 78 private string m_CurrentEvent = String.Empty;
79 private bool m_InSelfDelete = false; 79 private bool m_InSelfDelete;
80 private int m_MaxScriptQueue; 80 private int m_MaxScriptQueue;
81 private bool m_SaveState = true; 81 private bool m_SaveState = true;
82 private bool m_ShuttingDown = false; 82 private bool m_ShuttingDown;
83 private int m_ControlEventsInQueue = 0; 83 private int m_ControlEventsInQueue;
84 private int m_LastControlLevel = 0; 84 private int m_LastControlLevel;
85 private bool m_CollisionInQueue = false; 85 private bool m_CollisionInQueue;
86 private TaskInventoryItem m_thisScriptTask; 86 private TaskInventoryItem m_thisScriptTask;
87 // The following is for setting a minimum delay between events 87 // The following is for setting a minimum delay between events
88 private double m_minEventDelay = 0; 88 private double m_minEventDelay;
89 private long m_eventDelayTicks = 0; 89 private long m_eventDelayTicks;
90 private long m_nextEventTimeTicks = 0; 90 private long m_nextEventTimeTicks;
91 private bool m_startOnInit = true; 91 private bool m_startOnInit = true;
92 private UUID m_AttachedAvatar = UUID.Zero; 92 private UUID m_AttachedAvatar;
93 private StateSource m_stateSource; 93 private StateSource m_stateSource;
94 private bool m_postOnRez; 94 private bool m_postOnRez;
95 private bool m_startedFromSavedState = false; 95 private bool m_startedFromSavedState;
96 private string m_CurrentState = String.Empty; 96 private UUID m_CurrentStateHash;
97 private UUID m_RegionID = UUID.Zero; 97 private UUID m_RegionID;
98 98
99 private Dictionary<KeyValuePair<int, int>, KeyValuePair<int, int>> 99 private Dictionary<KeyValuePair<int, int>, KeyValuePair<int, int>>
100 m_LineMap; 100 m_LineMap;
@@ -252,16 +252,22 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
252 { 252 {
253 m_Apis[api] = am.CreateApi(api); 253 m_Apis[api] = am.CreateApi(api);
254 m_Apis[api].Initialize(engine, part, m_LocalID, itemID); 254 m_Apis[api].Initialize(engine, part, m_LocalID, itemID);
255 } 255 }
256
257 try
258 {
259 if (dom != System.AppDomain.CurrentDomain)
260 m_Script = (IScript)dom.CreateInstanceAndUnwrap(
261 Path.GetFileNameWithoutExtension(assembly),
262 "SecondLife.Script");
263 else
264 m_Script = (IScript)Assembly.Load(
265 Path.GetFileNameWithoutExtension(assembly)).CreateInstance(
266 "SecondLife.Script");
256 267
257 try
258 {
259 m_Script = (IScript)dom.CreateInstanceAndUnwrap(
260 Path.GetFileNameWithoutExtension(assembly),
261 "SecondLife.Script");
262 268
263 //ILease lease = (ILease)RemotingServices.GetLifetimeService(m_Script as ScriptBaseClass); 269 //ILease lease = (ILease)RemotingServices.GetLifetimeService(m_Script as ScriptBaseClass);
264 RemotingServices.GetLifetimeService(m_Script as ScriptBaseClass); 270 //RemotingServices.GetLifetimeService(m_Script as ScriptBaseClass);
265// lease.Register(this); 271// lease.Register(this);
266 } 272 }
267 catch (Exception) 273 catch (Exception)
@@ -893,7 +899,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
893 899
894 string xml = ScriptSerializer.Serialize(this); 900 string xml = ScriptSerializer.Serialize(this);
895 901
896 if (m_CurrentState != xml) 902 // Compare hash of the state we just just created with the state last written to disk
903 // If the state is different, update the disk file.
904 UUID hash = UUID.Parse(Utils.MD5String(xml));
905
906 if(hash != m_CurrentStateHash)
897 { 907 {
898 try 908 try
899 { 909 {
@@ -911,7 +921,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
911 //{ 921 //{
912 // throw new Exception("Completed persistence save, but no file was created"); 922 // throw new Exception("Completed persistence save, but no file was created");
913 //} 923 //}
914 m_CurrentState = xml; 924 m_CurrentStateHash = hash;
915 } 925 }
916 } 926 }
917 927
diff --git a/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs b/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs
index 7b19ce3..a60c0ba 100644
--- a/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs
+++ b/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs
@@ -50,6 +50,8 @@ using OpenSim.Region.ScriptEngine.Shared.CodeTools;
50using OpenSim.Region.ScriptEngine.Shared.Instance; 50using OpenSim.Region.ScriptEngine.Shared.Instance;
51using OpenSim.Region.ScriptEngine.Interfaces; 51using OpenSim.Region.ScriptEngine.Interfaces;
52 52
53using ScriptCompileQueue = OpenSim.Framework.LocklessQueue<object[]>;
54
53namespace OpenSim.Region.ScriptEngine.XEngine 55namespace OpenSim.Region.ScriptEngine.XEngine
54{ 56{
55 public class XEngine : INonSharedRegionModule, IScriptModule, IScriptEngine 57 public class XEngine : INonSharedRegionModule, IScriptModule, IScriptEngine
@@ -73,9 +75,11 @@ namespace OpenSim.Region.ScriptEngine.XEngine
73 private bool m_InitialStartup = true; 75 private bool m_InitialStartup = true;
74 private int m_ScriptFailCount; // Number of script fails since compile queue was last empty 76 private int m_ScriptFailCount; // Number of script fails since compile queue was last empty
75 private string m_ScriptErrorMessage; 77 private string m_ScriptErrorMessage;
78 private Dictionary<string, string> m_uniqueScripts = new Dictionary<string, string>();
79 private bool m_AppDomainLoading;
76 80
77// disable warning: need to keep a reference to XEngine.EventManager 81 // disable warning: need to keep a reference to XEngine.EventManager
78// alive to avoid it being garbage collected 82 // alive to avoid it being garbage collected
79#pragma warning disable 414 83#pragma warning disable 414
80 private EventManager m_EventManager; 84 private EventManager m_EventManager;
81#pragma warning restore 414 85#pragma warning restore 414
@@ -114,7 +118,7 @@ namespace OpenSim.Region.ScriptEngine.XEngine
114 private Dictionary<UUID, List<UUID> > m_DomainScripts = 118 private Dictionary<UUID, List<UUID> > m_DomainScripts =
115 new Dictionary<UUID, List<UUID> >(); 119 new Dictionary<UUID, List<UUID> >();
116 120
117 private Queue m_CompileQueue = new Queue(100); 121 private ScriptCompileQueue m_CompileQueue = new ScriptCompileQueue();
118 IWorkItemResult m_CurrentCompile = null; 122 IWorkItemResult m_CurrentCompile = null;
119 123
120 public string ScriptEngineName 124 public string ScriptEngineName
@@ -201,6 +205,7 @@ namespace OpenSim.Region.ScriptEngine.XEngine
201 m_MaxScriptQueue = m_ScriptConfig.GetInt("MaxScriptEventQueue",300); 205 m_MaxScriptQueue = m_ScriptConfig.GetInt("MaxScriptEventQueue",300);
202 m_StackSize = m_ScriptConfig.GetInt("ThreadStackSize", 262144); 206 m_StackSize = m_ScriptConfig.GetInt("ThreadStackSize", 262144);
203 m_SleepTime = m_ScriptConfig.GetInt("MaintenanceInterval", 10) * 1000; 207 m_SleepTime = m_ScriptConfig.GetInt("MaintenanceInterval", 10) * 1000;
208 m_AppDomainLoading = m_ScriptConfig.GetBoolean("AppDomainLoading", true);
204 209
205 m_EventLimit = m_ScriptConfig.GetInt("EventLimit", 30); 210 m_EventLimit = m_ScriptConfig.GetInt("EventLimit", 30);
206 m_KillTimedOutScripts = m_ScriptConfig.GetBoolean("KillTimedOutScripts", false); 211 m_KillTimedOutScripts = m_ScriptConfig.GetBoolean("KillTimedOutScripts", false);
@@ -470,6 +475,12 @@ namespace OpenSim.Region.ScriptEngine.XEngine
470 if (engine != ScriptEngineName) 475 if (engine != ScriptEngineName)
471 return; 476 return;
472 477
478 // If we've seen this exact script text before, use that reference instead
479 if (m_uniqueScripts.ContainsKey(script))
480 script = m_uniqueScripts[script];
481 else
482 m_uniqueScripts[script] = script;
483
473 Object[] parms = new Object[]{localID, itemID, script, startParam, postOnRez, (StateSource)stateSource}; 484 Object[] parms = new Object[]{localID, itemID, script, startParam, postOnRez, (StateSource)stateSource};
474 485
475 if (stateSource == (int)StateSource.ScriptedRez) 486 if (stateSource == (int)StateSource.ScriptedRez)
@@ -478,15 +489,19 @@ namespace OpenSim.Region.ScriptEngine.XEngine
478 } 489 }
479 else 490 else
480 { 491 {
481 lock (m_CompileQueue) 492 m_CompileQueue.Enqueue(parms);
482 {
483 m_CompileQueue.Enqueue(parms);
484 493
485 if (m_CurrentCompile == null) 494 if (m_CurrentCompile == null)
495 {
496 // NOTE: Although we use a lockless queue, the lock here
497 // is required. It ensures that there are never two
498 // compile threads running, which, due to a race
499 // conndition, might otherwise happen
500 //
501 lock (m_CompileQueue)
486 { 502 {
487 m_CurrentCompile = m_ThreadPool.QueueWorkItem( 503 if (m_CurrentCompile == null)
488 new WorkItemCallback(this.DoOnRezScriptQueue), 504 m_CurrentCompile = m_ThreadPool.QueueWorkItem(DoOnRezScriptQueue, null);
489 new Object[0]);
490 } 505 }
491 } 506 }
492 } 507 }
@@ -498,50 +513,38 @@ namespace OpenSim.Region.ScriptEngine.XEngine
498 { 513 {
499 m_InitialStartup = false; 514 m_InitialStartup = false;
500 System.Threading.Thread.Sleep(15000); 515 System.Threading.Thread.Sleep(15000);
501 lock (m_CompileQueue)
502 {
503 if (m_CompileQueue.Count==0)
504 // No scripts on region, so won't get triggered later
505 // by the queue becoming empty so we trigger it here
506 m_Scene.EventManager.TriggerEmptyScriptCompileQueue(0, String.Empty);
507 }
508 }
509 516
510 Object o; 517 if (m_CompileQueue.Count == 0)
511 lock (m_CompileQueue)
512 {
513 o = m_CompileQueue.Dequeue();
514 if (o == null)
515 { 518 {
516 m_CurrentCompile = null; 519 // No scripts on region, so won't get triggered later
517 return null; 520 // by the queue becoming empty so we trigger it here
521 m_Scene.EventManager.TriggerEmptyScriptCompileQueue(0, String.Empty);
518 } 522 }
519 } 523 }
520 524
521 DoOnRezScript(o); 525 object[] o;
526 while (m_CompileQueue.Dequeue(out o))
527 DoOnRezScript(o);
522 528
529 // NOTE: Despite having a lockless queue, this lock is required
530 // to make sure there is never no compile thread while there
531 // are still scripts to compile. This could otherwise happen
532 // due to a race condition
533 //
523 lock (m_CompileQueue) 534 lock (m_CompileQueue)
524 { 535 {
525 if (m_CompileQueue.Count > 0) 536 m_CurrentCompile = null;
526 {
527 m_CurrentCompile = m_ThreadPool.QueueWorkItem(
528 new WorkItemCallback(this.DoOnRezScriptQueue),
529 new Object[0]);
530 }
531 else
532 {
533 m_CurrentCompile = null;
534 m_Scene.EventManager.TriggerEmptyScriptCompileQueue(m_ScriptFailCount,
535 m_ScriptErrorMessage);
536 m_ScriptFailCount = 0;
537 }
538 } 537 }
538 m_Scene.EventManager.TriggerEmptyScriptCompileQueue(m_ScriptFailCount,
539 m_ScriptErrorMessage);
540 m_ScriptFailCount = 0;
541
539 return null; 542 return null;
540 } 543 }
541 544
542 private bool DoOnRezScript(object parm) 545 private bool DoOnRezScript(object[] parms)
543 { 546 {
544 Object[] p = (Object[])parm; 547 Object[] p = parms;
545 uint localID = (uint)p[0]; 548 uint localID = (uint)p[0];
546 UUID itemID = (UUID)p[1]; 549 UUID itemID = (UUID)p[1];
547 string script =(string)p[2]; 550 string script =(string)p[2];
@@ -590,14 +593,12 @@ namespace OpenSim.Region.ScriptEngine.XEngine
590 { 593 {
591 lock (m_AddingAssemblies) 594 lock (m_AddingAssemblies)
592 { 595 {
593 assembly = (string)m_Compiler.PerformScriptCompile(script, 596 m_Compiler.PerformScriptCompile(script, assetID.ToString(), item.OwnerID, out assembly, out linemap);
594 assetID.ToString(), item.OwnerID);
595 if (!m_AddingAssemblies.ContainsKey(assembly)) { 597 if (!m_AddingAssemblies.ContainsKey(assembly)) {
596 m_AddingAssemblies[assembly] = 1; 598 m_AddingAssemblies[assembly] = 1;
597 } else { 599 } else {
598 m_AddingAssemblies[assembly]++; 600 m_AddingAssemblies[assembly]++;
599 } 601 }
600 linemap = m_Compiler.LineMap();
601 } 602 }
602 603
603 string[] warnings = m_Compiler.GetWarnings(); 604 string[] warnings = m_Compiler.GetWarnings();
@@ -696,19 +697,22 @@ namespace OpenSim.Region.ScriptEngine.XEngine
696 Evidence baseEvidence = AppDomain.CurrentDomain.Evidence; 697 Evidence baseEvidence = AppDomain.CurrentDomain.Evidence;
697 Evidence evidence = new Evidence(baseEvidence); 698 Evidence evidence = new Evidence(baseEvidence);
698 699
699 AppDomain sandbox = 700 AppDomain sandbox;
700 AppDomain.CreateDomain( 701 if (m_AppDomainLoading)
701 m_Scene.RegionInfo.RegionID.ToString(), 702 sandbox = AppDomain.CreateDomain(
702 evidence, appSetup); 703 m_Scene.RegionInfo.RegionID.ToString(),
703/* 704 evidence, appSetup);
704 PolicyLevel sandboxPolicy = PolicyLevel.CreateAppDomainLevel(); 705 else
705 AllMembershipCondition sandboxMembershipCondition = new AllMembershipCondition(); 706 sandbox = AppDomain.CurrentDomain;
706 PermissionSet sandboxPermissionSet = sandboxPolicy.GetNamedPermissionSet("Internet"); 707
707 PolicyStatement sandboxPolicyStatement = new PolicyStatement(sandboxPermissionSet); 708 //PolicyLevel sandboxPolicy = PolicyLevel.CreateAppDomainLevel();
708 CodeGroup sandboxCodeGroup = new UnionCodeGroup(sandboxMembershipCondition, sandboxPolicyStatement); 709 //AllMembershipCondition sandboxMembershipCondition = new AllMembershipCondition();
709 sandboxPolicy.RootCodeGroup = sandboxCodeGroup; 710 //PermissionSet sandboxPermissionSet = sandboxPolicy.GetNamedPermissionSet("Internet");
710 sandbox.SetAppDomainPolicy(sandboxPolicy); 711 //PolicyStatement sandboxPolicyStatement = new PolicyStatement(sandboxPermissionSet);
711*/ 712 //CodeGroup sandboxCodeGroup = new UnionCodeGroup(sandboxMembershipCondition, sandboxPolicyStatement);
713 //sandboxPolicy.RootCodeGroup = sandboxCodeGroup;
714 //sandbox.SetAppDomainPolicy(sandboxPolicy);
715
712 m_AppDomains[appDomain] = sandbox; 716 m_AppDomains[appDomain] = sandbox;
713 717
714 m_AppDomains[appDomain].AssemblyResolve += 718 m_AppDomains[appDomain].AssemblyResolve +=
@@ -905,9 +909,10 @@ namespace OpenSim.Region.ScriptEngine.XEngine
905 AppDomain domain = m_AppDomains[id]; 909 AppDomain domain = m_AppDomains[id];
906 m_AppDomains.Remove(id); 910 m_AppDomains.Remove(id);
907 911
908 AppDomain.Unload(domain); 912 if (domain != AppDomain.CurrentDomain)
913 AppDomain.Unload(domain);
909 domain = null; 914 domain = null;
910// m_log.DebugFormat("[XEngine] Unloaded app domain {0}", id.ToString()); 915 // m_log.DebugFormat("[XEngine] Unloaded app domain {0}", id.ToString());
911 } 916 }
912 } 917 }
913 918