diff options
Diffstat (limited to 'OpenSim/Region/ScriptEngine')
7 files changed, 930 insertions, 184 deletions
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs index 26969a5..c84afee 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs | |||
@@ -369,7 +369,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
369 | } | 369 | } |
370 | 370 | ||
371 | // convert a LSL_Rotation to a Quaternion | 371 | // convert a LSL_Rotation to a Quaternion |
372 | protected Quaternion Rot2Quaternion(LSL_Rotation r) | 372 | public static Quaternion Rot2Quaternion(LSL_Rotation r) |
373 | { | 373 | { |
374 | Quaternion q = new Quaternion((float)r.x, (float)r.y, (float)r.z, (float)r.s); | 374 | Quaternion q = new Quaternion((float)r.x, (float)r.y, (float)r.z, (float)r.s); |
375 | q.Normalize(); | 375 | q.Normalize(); |
@@ -1204,10 +1204,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
1204 | 1204 | ||
1205 | if ((status & ScriptBaseClass.STATUS_PHANTOM) == ScriptBaseClass.STATUS_PHANTOM) | 1205 | if ((status & ScriptBaseClass.STATUS_PHANTOM) == ScriptBaseClass.STATUS_PHANTOM) |
1206 | { | 1206 | { |
1207 | if (value != 0) | 1207 | if (m_host.ParentGroup != null) |
1208 | m_host.ScriptSetPhantomStatus(true); | 1208 | m_host.ParentGroup.ScriptSetPhantomStatus(value != 0); |
1209 | else | ||
1210 | m_host.ScriptSetPhantomStatus(false); | ||
1211 | } | 1209 | } |
1212 | 1210 | ||
1213 | if ((status & ScriptBaseClass.STATUS_CAST_SHADOWS) == ScriptBaseClass.STATUS_CAST_SHADOWS) | 1211 | if ((status & ScriptBaseClass.STATUS_CAST_SHADOWS) == ScriptBaseClass.STATUS_CAST_SHADOWS) |
@@ -2063,6 +2061,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
2063 | { | 2061 | { |
2064 | return llGetRootRotation(); | 2062 | return llGetRootRotation(); |
2065 | } | 2063 | } |
2064 | |||
2066 | m_host.AddScriptLPS(1); | 2065 | m_host.AddScriptLPS(1); |
2067 | Quaternion q = m_host.GetWorldRotation(); | 2066 | Quaternion q = m_host.GetWorldRotation(); |
2068 | return new LSL_Rotation(q.X, q.Y, q.Z, q.W); | 2067 | return new LSL_Rotation(q.X, q.Y, q.Z, q.W); |
@@ -6446,9 +6445,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
6446 | if (m_host.ParentGroup != null) | 6445 | if (m_host.ParentGroup != null) |
6447 | { | 6446 | { |
6448 | if (!m_host.ParentGroup.IsDeleted) | 6447 | if (!m_host.ParentGroup.IsDeleted) |
6449 | { | 6448 | m_host.ParentGroup.ScriptSetVolumeDetect(detect != 0); |
6450 | m_host.ParentGroup.RootPart.ScriptSetVolumeDetect(detect!=0); | ||
6451 | } | ||
6452 | } | 6449 | } |
6453 | } | 6450 | } |
6454 | 6451 | ||
@@ -6456,7 +6453,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
6456 | /// This is a depecated function so this just replicates the result of | 6453 | /// This is a depecated function so this just replicates the result of |
6457 | /// invoking it in SL | 6454 | /// invoking it in SL |
6458 | /// </summary> | 6455 | /// </summary> |
6459 | |||
6460 | public void llRemoteLoadScript(string target, string name, int running, int start_param) | 6456 | public void llRemoteLoadScript(string target, string name, int running, int start_param) |
6461 | { | 6457 | { |
6462 | m_host.AddScriptLPS(1); | 6458 | m_host.AddScriptLPS(1); |
@@ -7254,14 +7250,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
7254 | return; | 7250 | return; |
7255 | 7251 | ||
7256 | string ph = rules.Data[idx++].ToString(); | 7252 | string ph = rules.Data[idx++].ToString(); |
7257 | bool phantom; | ||
7258 | 7253 | ||
7259 | if (ph.Equals("1")) | 7254 | if (m_host.ParentGroup != null) |
7260 | phantom = true; | 7255 | m_host.ParentGroup.ScriptSetPhantomStatus(ph.Equals("1")); |
7261 | else | ||
7262 | phantom = false; | ||
7263 | 7256 | ||
7264 | part.ScriptSetPhantomStatus(phantom); | ||
7265 | break; | 7257 | break; |
7266 | 7258 | ||
7267 | case (int)ScriptBaseClass.PRIM_PHYSICS: | 7259 | case (int)ScriptBaseClass.PRIM_PHYSICS: |
@@ -7282,14 +7274,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
7282 | if (remain < 1) | 7274 | if (remain < 1) |
7283 | return; | 7275 | return; |
7284 | string temp = rules.Data[idx++].ToString(); | 7276 | string temp = rules.Data[idx++].ToString(); |
7285 | bool tempOnRez; | ||
7286 | 7277 | ||
7287 | if (temp.Equals("1")) | 7278 | if (m_host.ParentGroup != null) |
7288 | tempOnRez = true; | 7279 | m_host.ParentGroup.ScriptSetTemporaryStatus(temp.Equals("1")); |
7289 | else | ||
7290 | tempOnRez = false; | ||
7291 | 7280 | ||
7292 | part.ScriptSetTemporaryStatus(tempOnRez); | ||
7293 | break; | 7281 | break; |
7294 | 7282 | ||
7295 | case (int)ScriptBaseClass.PRIM_TEXGEN: | 7283 | case (int)ScriptBaseClass.PRIM_TEXGEN: |
@@ -7662,7 +7650,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
7662 | case ScriptBaseClass.PRIM_TYPE_BOX: | 7650 | case ScriptBaseClass.PRIM_TYPE_BOX: |
7663 | case ScriptBaseClass.PRIM_TYPE_CYLINDER: | 7651 | case ScriptBaseClass.PRIM_TYPE_CYLINDER: |
7664 | case ScriptBaseClass.PRIM_TYPE_PRISM: | 7652 | case ScriptBaseClass.PRIM_TYPE_PRISM: |
7665 | res.Add(new LSL_Integer(Shape.ProfileCurve)); | 7653 | res.Add(new LSL_Integer(Shape.ProfileCurve) & 0xf0); // Isolate hole shape nibble. |
7666 | res.Add(new LSL_Vector(Shape.ProfileBegin / 50000.0, 1 - Shape.ProfileEnd / 50000.0, 0)); | 7654 | res.Add(new LSL_Vector(Shape.ProfileBegin / 50000.0, 1 - Shape.ProfileEnd / 50000.0, 0)); |
7667 | res.Add(new LSL_Float(Shape.ProfileHollow / 50000.0)); | 7655 | res.Add(new LSL_Float(Shape.ProfileHollow / 50000.0)); |
7668 | res.Add(new LSL_Vector(Shape.PathTwistBegin / 100.0, Shape.PathTwist / 100.0, 0)); | 7656 | res.Add(new LSL_Vector(Shape.PathTwistBegin / 100.0, Shape.PathTwist / 100.0, 0)); |
@@ -7671,7 +7659,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
7671 | break; | 7659 | break; |
7672 | 7660 | ||
7673 | case ScriptBaseClass.PRIM_TYPE_SPHERE: | 7661 | case ScriptBaseClass.PRIM_TYPE_SPHERE: |
7674 | res.Add(new LSL_Integer(Shape.ProfileCurve)); | 7662 | res.Add(new LSL_Integer(Shape.ProfileCurve) & 0xf0); // Isolate hole shape nibble. |
7675 | res.Add(new LSL_Vector(Shape.PathBegin / 50000.0, 1 - Shape.PathEnd / 50000.0, 0)); | 7663 | res.Add(new LSL_Vector(Shape.PathBegin / 50000.0, 1 - Shape.PathEnd / 50000.0, 0)); |
7676 | res.Add(new LSL_Float(Shape.ProfileHollow / 50000.0)); | 7664 | res.Add(new LSL_Float(Shape.ProfileHollow / 50000.0)); |
7677 | res.Add(new LSL_Vector(Shape.PathTwistBegin / 100.0, Shape.PathTwist / 100.0, 0)); | 7665 | res.Add(new LSL_Vector(Shape.PathTwistBegin / 100.0, Shape.PathTwist / 100.0, 0)); |
@@ -7687,7 +7675,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
7687 | case ScriptBaseClass.PRIM_TYPE_TUBE: | 7675 | case ScriptBaseClass.PRIM_TYPE_TUBE: |
7688 | case ScriptBaseClass.PRIM_TYPE_TORUS: | 7676 | case ScriptBaseClass.PRIM_TYPE_TORUS: |
7689 | // holeshape | 7677 | // holeshape |
7690 | res.Add(new LSL_Integer(Shape.ProfileCurve)); | 7678 | res.Add(new LSL_Integer(Shape.ProfileCurve) & 0xf0); // Isolate hole shape nibble. |
7691 | 7679 | ||
7692 | // cut | 7680 | // cut |
7693 | res.Add(new LSL_Vector(Shape.PathBegin / 50000.0, 1 - Shape.PathEnd / 50000.0, 0)); | 7681 | res.Add(new LSL_Vector(Shape.PathBegin / 50000.0, 1 - Shape.PathEnd / 50000.0, 0)); |
@@ -10578,9 +10566,15 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
10578 | } | 10566 | } |
10579 | } | 10567 | } |
10580 | 10568 | ||
10581 | public static string GetLine(UUID assetID, int line, int maxLength) | 10569 | /// <summary> |
10570 | /// Get a notecard line. | ||
10571 | /// </summary> | ||
10572 | /// <param name="assetID"></param> | ||
10573 | /// <param name="line">Lines start at index 0</param> | ||
10574 | /// <returns></returns> | ||
10575 | public static string GetLine(UUID assetID, int lineNumber) | ||
10582 | { | 10576 | { |
10583 | if (line < 0) | 10577 | if (lineNumber < 0) |
10584 | return ""; | 10578 | return ""; |
10585 | 10579 | ||
10586 | string data; | 10580 | string data; |
@@ -10592,17 +10586,32 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
10592 | { | 10586 | { |
10593 | m_Notecards[assetID].lastRef = DateTime.Now; | 10587 | m_Notecards[assetID].lastRef = DateTime.Now; |
10594 | 10588 | ||
10595 | if (line >= m_Notecards[assetID].text.Length) | 10589 | if (lineNumber >= m_Notecards[assetID].text.Length) |
10596 | return "\n\n\n"; | 10590 | return "\n\n\n"; |
10597 | 10591 | ||
10598 | data = m_Notecards[assetID].text[line]; | 10592 | data = m_Notecards[assetID].text[lineNumber]; |
10599 | if (data.Length > maxLength) | ||
10600 | data = data.Substring(0, maxLength); | ||
10601 | 10593 | ||
10602 | return data; | 10594 | return data; |
10603 | } | 10595 | } |
10604 | } | 10596 | } |
10605 | 10597 | ||
10598 | /// <summary> | ||
10599 | /// Get a notecard line. | ||
10600 | /// </summary> | ||
10601 | /// <param name="assetID"></param> | ||
10602 | /// <param name="line">Lines start at index 0</param> | ||
10603 | /// <param name="maxLength">Maximum length of the returned line. Longer lines will be truncated</para> | ||
10604 | /// <returns></returns> | ||
10605 | public static string GetLine(UUID assetID, int lineNumber, int maxLength) | ||
10606 | { | ||
10607 | string line = GetLine(assetID, lineNumber); | ||
10608 | |||
10609 | if (line.Length > maxLength) | ||
10610 | line = line.Substring(0, maxLength); | ||
10611 | |||
10612 | return line; | ||
10613 | } | ||
10614 | |||
10606 | public static void CacheCheck() | 10615 | public static void CacheCheck() |
10607 | { | 10616 | { |
10608 | foreach (UUID key in new List<UUID>(m_Notecards.Keys)) | 10617 | foreach (UUID key in new List<UUID>(m_Notecards.Keys)) |
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs index 8093502..d791885 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs | |||
@@ -28,11 +28,16 @@ | |||
28 | using System; | 28 | using System; |
29 | using System.Collections; | 29 | using System.Collections; |
30 | using System.Collections.Generic; | 30 | using System.Collections.Generic; |
31 | using System.IO; | ||
32 | using System.Reflection; | ||
31 | using System.Runtime.Remoting.Lifetime; | 33 | using System.Runtime.Remoting.Lifetime; |
32 | using System.Text; | 34 | using System.Text; |
33 | using System.Net; | 35 | using System.Net; |
34 | using System.Threading; | 36 | using System.Threading; |
37 | using System.Xml; | ||
38 | using log4net; | ||
35 | using OpenMetaverse; | 39 | using OpenMetaverse; |
40 | using OpenMetaverse.StructuredData; | ||
36 | using Nini.Config; | 41 | using Nini.Config; |
37 | using OpenSim; | 42 | using OpenSim; |
38 | using OpenSim.Framework; | 43 | using OpenSim.Framework; |
@@ -119,6 +124,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
119 | [Serializable] | 124 | [Serializable] |
120 | public class OSSL_Api : MarshalByRefObject, IOSSL_Api, IScriptApi | 125 | public class OSSL_Api : MarshalByRefObject, IOSSL_Api, IScriptApi |
121 | { | 126 | { |
127 | // private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
128 | |||
122 | internal IScriptEngine m_ScriptEngine; | 129 | internal IScriptEngine m_ScriptEngine; |
123 | internal ILSL_Api m_LSL_Api = null; // get a reference to the LSL API so we can call methods housed there | 130 | internal ILSL_Api m_LSL_Api = null; // get a reference to the LSL API so we can call methods housed there |
124 | internal SceneObjectPart m_host; | 131 | internal SceneObjectPart m_host; |
@@ -348,20 +355,19 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
348 | System.Threading.Thread.Sleep(delay); | 355 | System.Threading.Thread.Sleep(delay); |
349 | } | 356 | } |
350 | 357 | ||
351 | // | ||
352 | // OpenSim functions | ||
353 | // | ||
354 | public LSL_Integer osSetTerrainHeight(int x, int y, double val) | 358 | public LSL_Integer osSetTerrainHeight(int x, int y, double val) |
355 | { | 359 | { |
356 | CheckThreatLevel(ThreatLevel.High, "osSetTerrainHeight"); | 360 | CheckThreatLevel(ThreatLevel.High, "osSetTerrainHeight"); |
357 | return SetTerrainHeight(x, y, val); | 361 | return SetTerrainHeight(x, y, val); |
358 | } | 362 | } |
363 | |||
359 | public LSL_Integer osTerrainSetHeight(int x, int y, double val) | 364 | public LSL_Integer osTerrainSetHeight(int x, int y, double val) |
360 | { | 365 | { |
361 | CheckThreatLevel(ThreatLevel.High, "osTerrainSetHeight"); | 366 | CheckThreatLevel(ThreatLevel.High, "osTerrainSetHeight"); |
362 | OSSLDeprecated("osTerrainSetHeight", "osSetTerrainHeight"); | 367 | OSSLDeprecated("osTerrainSetHeight", "osSetTerrainHeight"); |
363 | return SetTerrainHeight(x, y, val); | 368 | return SetTerrainHeight(x, y, val); |
364 | } | 369 | } |
370 | |||
365 | private LSL_Integer SetTerrainHeight(int x, int y, double val) | 371 | private LSL_Integer SetTerrainHeight(int x, int y, double val) |
366 | { | 372 | { |
367 | m_host.AddScriptLPS(1); | 373 | m_host.AddScriptLPS(1); |
@@ -384,12 +390,14 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
384 | CheckThreatLevel(ThreatLevel.None, "osGetTerrainHeight"); | 390 | CheckThreatLevel(ThreatLevel.None, "osGetTerrainHeight"); |
385 | return GetTerrainHeight(x, y); | 391 | return GetTerrainHeight(x, y); |
386 | } | 392 | } |
393 | |||
387 | public LSL_Float osTerrainGetHeight(int x, int y) | 394 | public LSL_Float osTerrainGetHeight(int x, int y) |
388 | { | 395 | { |
389 | CheckThreatLevel(ThreatLevel.None, "osTerrainGetHeight"); | 396 | CheckThreatLevel(ThreatLevel.None, "osTerrainGetHeight"); |
390 | OSSLDeprecated("osTerrainGetHeight", "osGetTerrainHeight"); | 397 | OSSLDeprecated("osTerrainGetHeight", "osGetTerrainHeight"); |
391 | return GetTerrainHeight(x, y); | 398 | return GetTerrainHeight(x, y); |
392 | } | 399 | } |
400 | |||
393 | private LSL_Float GetTerrainHeight(int x, int y) | 401 | private LSL_Float GetTerrainHeight(int x, int y) |
394 | { | 402 | { |
395 | m_host.AddScriptLPS(1); | 403 | m_host.AddScriptLPS(1); |
@@ -862,7 +870,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
862 | ScenePresence target = (ScenePresence)World.Entities[avatarID]; | 870 | ScenePresence target = (ScenePresence)World.Entities[avatarID]; |
863 | if (target != null) | 871 | if (target != null) |
864 | { | 872 | { |
865 | UUID animID=UUID.Zero; | 873 | UUID animID = UUID.Zero; |
866 | lock (m_host.TaskInventory) | 874 | lock (m_host.TaskInventory) |
867 | { | 875 | { |
868 | foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory) | 876 | foreach (KeyValuePair<UUID, TaskInventoryItem> inv in m_host.TaskInventory) |
@@ -1021,6 +1029,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
1021 | drawList += "PenColor " + color + "; "; | 1029 | drawList += "PenColor " + color + "; "; |
1022 | return drawList; | 1030 | return drawList; |
1023 | } | 1031 | } |
1032 | |||
1024 | // Deprecated | 1033 | // Deprecated |
1025 | public string osSetPenColour(string drawList, string colour) | 1034 | public string osSetPenColour(string drawList, string colour) |
1026 | { | 1035 | { |
@@ -1182,11 +1191,13 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
1182 | OSSLDeprecated("osSunGetParam", "osGetSunParam"); | 1191 | OSSLDeprecated("osSunGetParam", "osGetSunParam"); |
1183 | return GetSunParam(param); | 1192 | return GetSunParam(param); |
1184 | } | 1193 | } |
1194 | |||
1185 | public double osGetSunParam(string param) | 1195 | public double osGetSunParam(string param) |
1186 | { | 1196 | { |
1187 | CheckThreatLevel(ThreatLevel.None, "osGetSunParam"); | 1197 | CheckThreatLevel(ThreatLevel.None, "osGetSunParam"); |
1188 | return GetSunParam(param); | 1198 | return GetSunParam(param); |
1189 | } | 1199 | } |
1200 | |||
1190 | private double GetSunParam(string param) | 1201 | private double GetSunParam(string param) |
1191 | { | 1202 | { |
1192 | m_host.AddScriptLPS(1); | 1203 | m_host.AddScriptLPS(1); |
@@ -1208,11 +1219,13 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
1208 | OSSLDeprecated("osSunSetParam", "osSetSunParam"); | 1219 | OSSLDeprecated("osSunSetParam", "osSetSunParam"); |
1209 | SetSunParam(param, value); | 1220 | SetSunParam(param, value); |
1210 | } | 1221 | } |
1222 | |||
1211 | public void osSetSunParam(string param, double value) | 1223 | public void osSetSunParam(string param, double value) |
1212 | { | 1224 | { |
1213 | CheckThreatLevel(ThreatLevel.None, "osSetSunParam"); | 1225 | CheckThreatLevel(ThreatLevel.None, "osSetSunParam"); |
1214 | SetSunParam(param, value); | 1226 | SetSunParam(param, value); |
1215 | } | 1227 | } |
1228 | |||
1216 | private void SetSunParam(string param, double value) | 1229 | private void SetSunParam(string param, double value) |
1217 | { | 1230 | { |
1218 | m_host.AddScriptLPS(1); | 1231 | m_host.AddScriptLPS(1); |
@@ -1222,10 +1235,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
1222 | { | 1235 | { |
1223 | module.SetSunParameter(param, value); | 1236 | module.SetSunParameter(param, value); |
1224 | } | 1237 | } |
1225 | |||
1226 | } | 1238 | } |
1227 | 1239 | ||
1228 | |||
1229 | public string osWindActiveModelPluginName() | 1240 | public string osWindActiveModelPluginName() |
1230 | { | 1241 | { |
1231 | CheckThreatLevel(ThreatLevel.None, "osWindActiveModelPluginName"); | 1242 | CheckThreatLevel(ThreatLevel.None, "osWindActiveModelPluginName"); |
@@ -1304,12 +1315,14 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
1304 | OSSLDeprecated(functionName, "osSetParcelDetails"); | 1315 | OSSLDeprecated(functionName, "osSetParcelDetails"); |
1305 | SetParcelDetails(pos, rules, functionName); | 1316 | SetParcelDetails(pos, rules, functionName); |
1306 | } | 1317 | } |
1318 | |||
1307 | public void osSetParcelDetails(LSL_Vector pos, LSL_List rules) | 1319 | public void osSetParcelDetails(LSL_Vector pos, LSL_List rules) |
1308 | { | 1320 | { |
1309 | const string functionName = "osSetParcelDetails"; | 1321 | const string functionName = "osSetParcelDetails"; |
1310 | CheckThreatLevel(ThreatLevel.High, functionName); | 1322 | CheckThreatLevel(ThreatLevel.High, functionName); |
1311 | SetParcelDetails(pos, rules, functionName); | 1323 | SetParcelDetails(pos, rules, functionName); |
1312 | } | 1324 | } |
1325 | |||
1313 | private void SetParcelDetails(LSL_Vector pos, LSL_List rules, string functionName) | 1326 | private void SetParcelDetails(LSL_Vector pos, LSL_List rules, string functionName) |
1314 | { | 1327 | { |
1315 | m_host.AddScriptLPS(1); | 1328 | m_host.AddScriptLPS(1); |
@@ -1429,8 +1442,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
1429 | voiceModule.setLandSIPAddress(SIPAddress,land.LandData.GlobalID); | 1442 | voiceModule.setLandSIPAddress(SIPAddress,land.LandData.GlobalID); |
1430 | else | 1443 | else |
1431 | OSSLError("osSetParcelSIPAddress: No voice module enabled for this land"); | 1444 | OSSLError("osSetParcelSIPAddress: No voice module enabled for this land"); |
1432 | |||
1433 | |||
1434 | } | 1445 | } |
1435 | 1446 | ||
1436 | public string osGetScriptEngineName() | 1447 | public string osGetScriptEngineName() |
@@ -1683,8 +1694,15 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
1683 | return jsondata; | 1694 | return jsondata; |
1684 | } | 1695 | } |
1685 | 1696 | ||
1686 | // send a message to to object identified by the given UUID, a script in the object must implement the dataserver function | 1697 | /// <summary> |
1687 | // the dataserver function is passed the ID of the calling function and a string message | 1698 | /// Send a message to to object identified by the given UUID |
1699 | /// </summary> | ||
1700 | /// <remarks> | ||
1701 | /// A script in the object must implement the dataserver function | ||
1702 | /// the dataserver function is passed the ID of the calling function and a string message | ||
1703 | /// </remarks> | ||
1704 | /// <param name="objectUUID"></param> | ||
1705 | /// <param name="message"></param> | ||
1688 | public void osMessageObject(LSL_Key objectUUID, string message) | 1706 | public void osMessageObject(LSL_Key objectUUID, string message) |
1689 | { | 1707 | { |
1690 | CheckThreatLevel(ThreatLevel.Low, "osMessageObject"); | 1708 | CheckThreatLevel(ThreatLevel.Low, "osMessageObject"); |
@@ -1699,34 +1717,56 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
1699 | "dataserver", resobj, new DetectParams[0])); | 1717 | "dataserver", resobj, new DetectParams[0])); |
1700 | } | 1718 | } |
1701 | 1719 | ||
1702 | 1720 | /// <summary> | |
1703 | // This needs ThreatLevel high. It is an excellent griefer tool, | 1721 | /// Write a notecard directly to the prim's inventory. |
1704 | // In a loop, it can cause asset bloat and DOS levels of asset | 1722 | /// </summary> |
1705 | // writes. | 1723 | /// <remarks> |
1706 | // | 1724 | /// This needs ThreatLevel high. It is an excellent griefer tool, |
1725 | /// In a loop, it can cause asset bloat and DOS levels of asset | ||
1726 | /// writes. | ||
1727 | /// </remarks> | ||
1728 | /// <param name="notecardName">The name of the notecard to write.</param> | ||
1729 | /// <param name="contents">The contents of the notecard.</param> | ||
1707 | public void osMakeNotecard(string notecardName, LSL_Types.list contents) | 1730 | public void osMakeNotecard(string notecardName, LSL_Types.list contents) |
1708 | { | 1731 | { |
1709 | CheckThreatLevel(ThreatLevel.High, "osMakeNotecard"); | 1732 | CheckThreatLevel(ThreatLevel.High, "osMakeNotecard"); |
1710 | m_host.AddScriptLPS(1); | 1733 | m_host.AddScriptLPS(1); |
1711 | 1734 | ||
1712 | // Create new asset | 1735 | StringBuilder notecardData = new StringBuilder(); |
1713 | AssetBase asset = new AssetBase(UUID.Random(), notecardName, (sbyte)AssetType.Notecard, m_host.OwnerID.ToString()); | ||
1714 | asset.Description = "Script Generated Notecard"; | ||
1715 | string notecardData = String.Empty; | ||
1716 | 1736 | ||
1717 | for (int i = 0; i < contents.Length; i++) { | 1737 | for (int i = 0; i < contents.Length; i++) |
1718 | notecardData += contents.GetLSLStringItem(i) + "\n"; | 1738 | notecardData.Append((string)(contents.GetLSLStringItem(i) + "\n")); |
1719 | } | 1739 | |
1740 | SaveNotecard(notecardName, "Script generated notecard", notecardData.ToString(), false); | ||
1741 | } | ||
1720 | 1742 | ||
1721 | int textLength = notecardData.Length; | 1743 | /// <summary> |
1722 | notecardData = "Linden text version 2\n{\nLLEmbeddedItems version 1\n{\ncount 0\n}\nText length " | 1744 | /// Save a notecard to prim inventory. |
1723 | + textLength.ToString() + "\n" + notecardData + "}\n"; | 1745 | /// </summary> |
1746 | /// <param name="name"></param> | ||
1747 | /// <param name="description">Description of notecard</param> | ||
1748 | /// <param name="notecardData"></param> | ||
1749 | /// <param name="forceSameName"> | ||
1750 | /// If true, then if an item exists with the same name, it is replaced. | ||
1751 | /// If false, then a new item is created witha slightly different name (e.g. name 1) | ||
1752 | /// </param> | ||
1753 | /// <returns>Prim inventory item created.</returns> | ||
1754 | protected TaskInventoryItem SaveNotecard(string name, string description, string data, bool forceSameName) | ||
1755 | { | ||
1756 | // Create new asset | ||
1757 | AssetBase asset = new AssetBase(UUID.Random(), name, (sbyte)AssetType.Notecard, m_host.OwnerID.ToString()); | ||
1758 | asset.Description = description; | ||
1724 | 1759 | ||
1725 | asset.Data = Util.UTF8.GetBytes(notecardData); | 1760 | int textLength = data.Length; |
1761 | data | ||
1762 | = "Linden text version 2\n{\nLLEmbeddedItems version 1\n{\ncount 0\n}\nText length " | ||
1763 | + textLength.ToString() + "\n" + data + "}\n"; | ||
1764 | |||
1765 | asset.Data = Util.UTF8.GetBytes(data); | ||
1726 | World.AssetService.Store(asset); | 1766 | World.AssetService.Store(asset); |
1727 | 1767 | ||
1728 | // Create Task Entry | 1768 | // Create Task Entry |
1729 | TaskInventoryItem taskItem=new TaskInventoryItem(); | 1769 | TaskInventoryItem taskItem = new TaskInventoryItem(); |
1730 | 1770 | ||
1731 | taskItem.ResetIDs(m_host.UUID); | 1771 | taskItem.ResetIDs(m_host.UUID); |
1732 | taskItem.ParentID = m_host.UUID; | 1772 | taskItem.ParentID = m_host.UUID; |
@@ -1748,28 +1788,53 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
1748 | taskItem.PermsMask = 0; | 1788 | taskItem.PermsMask = 0; |
1749 | taskItem.AssetID = asset.FullID; | 1789 | taskItem.AssetID = asset.FullID; |
1750 | 1790 | ||
1751 | m_host.Inventory.AddInventoryItem(taskItem, false); | 1791 | if (forceSameName) |
1792 | m_host.Inventory.AddInventoryItemExclusive(taskItem, false); | ||
1793 | else | ||
1794 | m_host.Inventory.AddInventoryItem(taskItem, false); | ||
1795 | |||
1796 | return taskItem; | ||
1752 | } | 1797 | } |
1753 | 1798 | ||
1799 | /// <summary> | ||
1800 | /// Load the notecard data found at the given prim inventory item name or asset uuid. | ||
1801 | /// </summary> | ||
1802 | /// <param name="notecardNameOrUuid"></param> | ||
1803 | /// <returns>The text loaded. Null if no notecard was found.</returns> | ||
1804 | protected string LoadNotecard(string notecardNameOrUuid) | ||
1805 | { | ||
1806 | UUID assetID = CacheNotecard(notecardNameOrUuid); | ||
1807 | StringBuilder notecardData = new StringBuilder(); | ||
1808 | |||
1809 | for (int count = 0; count < NotecardCache.GetLines(assetID); count++) | ||
1810 | { | ||
1811 | string line = NotecardCache.GetLine(assetID, count) + "\n"; | ||
1812 | |||
1813 | // m_log.DebugFormat("[OSSL]: From notecard {0} loading line {1}", notecardNameOrUuid, line); | ||
1754 | 1814 | ||
1755 | /*Instead of using the LSL Dataserver event to pull notecard data, | 1815 | notecardData.Append(line); |
1756 | this will simply read the requested line and return its data as a string. | 1816 | } |
1757 | 1817 | ||
1758 | Warning - due to the synchronous method this function uses to fetch assets, its use | 1818 | return notecardData.ToString(); |
1759 | may be dangerous and unreliable while running in grid mode. | 1819 | } |
1760 | */ | ||
1761 | public string osGetNotecardLine(string name, int line) | ||
1762 | { | ||
1763 | CheckThreatLevel(ThreatLevel.VeryHigh, "osGetNotecardLine"); | ||
1764 | m_host.AddScriptLPS(1); | ||
1765 | 1820 | ||
1821 | /// <summary> | ||
1822 | /// Cache a notecard's contents. | ||
1823 | /// </summary> | ||
1824 | /// <param name="notecardNameOrUuid"></param> | ||
1825 | /// <returns> | ||
1826 | /// The asset id of the notecard, which is used for retrieving the cached data. | ||
1827 | /// UUID.Zero if no asset could be found. | ||
1828 | /// </returns> | ||
1829 | protected UUID CacheNotecard(string notecardNameOrUuid) | ||
1830 | { | ||
1766 | UUID assetID = UUID.Zero; | 1831 | UUID assetID = UUID.Zero; |
1767 | 1832 | ||
1768 | if (!UUID.TryParse(name, out assetID)) | 1833 | if (!UUID.TryParse(notecardNameOrUuid, out assetID)) |
1769 | { | 1834 | { |
1770 | foreach (TaskInventoryItem item in m_host.TaskInventory.Values) | 1835 | foreach (TaskInventoryItem item in m_host.TaskInventory.Values) |
1771 | { | 1836 | { |
1772 | if (item.Type == 7 && item.Name == name) | 1837 | if (item.Type == 7 && item.Name == notecardNameOrUuid) |
1773 | { | 1838 | { |
1774 | assetID = item.AssetID; | 1839 | assetID = item.AssetID; |
1775 | } | 1840 | } |
@@ -1777,114 +1842,100 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
1777 | } | 1842 | } |
1778 | 1843 | ||
1779 | if (assetID == UUID.Zero) | 1844 | if (assetID == UUID.Zero) |
1780 | { | 1845 | return UUID.Zero; |
1781 | OSSLShoutError("Notecard '" + name + "' could not be found."); | ||
1782 | return "ERROR!"; | ||
1783 | } | ||
1784 | 1846 | ||
1785 | if (!NotecardCache.IsCached(assetID)) | 1847 | if (!NotecardCache.IsCached(assetID)) |
1786 | { | 1848 | { |
1787 | AssetBase a = World.AssetService.Get(assetID.ToString()); | 1849 | AssetBase a = World.AssetService.Get(assetID.ToString()); |
1788 | if (a != null) | ||
1789 | { | ||
1790 | System.Text.UTF8Encoding enc = new System.Text.UTF8Encoding(); | ||
1791 | string data = enc.GetString(a.Data); | ||
1792 | NotecardCache.Cache(assetID, data); | ||
1793 | } | ||
1794 | else | ||
1795 | { | ||
1796 | OSSLShoutError("Notecard '" + name + "' could not be found."); | ||
1797 | return "ERROR!"; | ||
1798 | } | ||
1799 | }; | ||
1800 | 1850 | ||
1801 | return NotecardCache.GetLine(assetID, line, 255); | 1851 | if (a == null) |
1852 | return UUID.Zero; | ||
1802 | 1853 | ||
1854 | System.Text.UTF8Encoding enc = new System.Text.UTF8Encoding(); | ||
1855 | string data = enc.GetString(a.Data); | ||
1856 | NotecardCache.Cache(assetID, data); | ||
1857 | }; | ||
1803 | 1858 | ||
1859 | return assetID; | ||
1804 | } | 1860 | } |
1805 | 1861 | ||
1806 | /*Instead of using the LSL Dataserver event to pull notecard data line by line, | 1862 | /// <summary> |
1807 | this will simply read the entire notecard and return its data as a string. | 1863 | /// Directly get an entire notecard at once. |
1864 | /// </summary> | ||
1865 | /// <remarks> | ||
1866 | /// Instead of using the LSL Dataserver event to pull notecard data | ||
1867 | /// this will simply read the entire notecard and return its data as a string. | ||
1868 | /// | ||
1869 | /// Warning - due to the synchronous method this function uses to fetch assets, its use | ||
1870 | /// may be dangerous and unreliable while running in grid mode. | ||
1871 | /// </remarks> | ||
1872 | /// <param name="name">Name of the notecard or its asset id</param> | ||
1873 | /// <param name="line">The line number to read. The first line is line 0</param> | ||
1874 | /// <returns>Notecard line</returns> | ||
1875 | public string osGetNotecardLine(string name, int line) | ||
1876 | { | ||
1877 | CheckThreatLevel(ThreatLevel.VeryHigh, "osGetNotecardLine"); | ||
1878 | m_host.AddScriptLPS(1); | ||
1879 | |||
1880 | UUID assetID = CacheNotecard(name); | ||
1881 | |||
1882 | if (assetID == UUID.Zero) | ||
1883 | { | ||
1884 | OSSLShoutError("Notecard '" + name + "' could not be found."); | ||
1885 | return "ERROR!"; | ||
1886 | } | ||
1808 | 1887 | ||
1809 | Warning - due to the synchronous method this function uses to fetch assets, its use | 1888 | return NotecardCache.GetLine(assetID, line); |
1810 | may be dangerous and unreliable while running in grid mode. | 1889 | } |
1811 | */ | ||
1812 | 1890 | ||
1891 | /// <summary> | ||
1892 | /// Get an entire notecard at once. | ||
1893 | /// </summary> | ||
1894 | /// <remarks> | ||
1895 | /// Instead of using the LSL Dataserver event to pull notecard data line by line, | ||
1896 | /// this will simply read the entire notecard and return its data as a string. | ||
1897 | /// | ||
1898 | /// Warning - due to the synchronous method this function uses to fetch assets, its use | ||
1899 | /// may be dangerous and unreliable while running in grid mode. | ||
1900 | /// </remarks> | ||
1901 | /// <param name="name">Name of the notecard or its asset id</param> | ||
1902 | /// <returns>Notecard text</returns> | ||
1813 | public string osGetNotecard(string name) | 1903 | public string osGetNotecard(string name) |
1814 | { | 1904 | { |
1815 | CheckThreatLevel(ThreatLevel.VeryHigh, "osGetNotecard"); | 1905 | CheckThreatLevel(ThreatLevel.VeryHigh, "osGetNotecard"); |
1816 | m_host.AddScriptLPS(1); | 1906 | m_host.AddScriptLPS(1); |
1817 | 1907 | ||
1818 | UUID assetID = UUID.Zero; | 1908 | string text = LoadNotecard(name); |
1819 | string NotecardData = ""; | ||
1820 | |||
1821 | if (!UUID.TryParse(name, out assetID)) | ||
1822 | { | ||
1823 | foreach (TaskInventoryItem item in m_host.TaskInventory.Values) | ||
1824 | { | ||
1825 | if (item.Type == 7 && item.Name == name) | ||
1826 | { | ||
1827 | assetID = item.AssetID; | ||
1828 | } | ||
1829 | } | ||
1830 | } | ||
1831 | 1909 | ||
1832 | if (assetID == UUID.Zero) | 1910 | if (text == null) |
1833 | { | 1911 | { |
1834 | OSSLShoutError("Notecard '" + name + "' could not be found."); | 1912 | OSSLShoutError("Notecard '" + name + "' could not be found."); |
1835 | return "ERROR!"; | 1913 | return "ERROR!"; |
1836 | } | 1914 | } |
1837 | 1915 | else | |
1838 | if (!NotecardCache.IsCached(assetID)) | ||
1839 | { | ||
1840 | AssetBase a = World.AssetService.Get(assetID.ToString()); | ||
1841 | if (a != null) | ||
1842 | { | ||
1843 | System.Text.UTF8Encoding enc = new System.Text.UTF8Encoding(); | ||
1844 | string data = enc.GetString(a.Data); | ||
1845 | NotecardCache.Cache(assetID, data); | ||
1846 | } | ||
1847 | else | ||
1848 | { | ||
1849 | OSSLShoutError("Notecard '" + name + "' could not be found."); | ||
1850 | return "ERROR!"; | ||
1851 | } | ||
1852 | }; | ||
1853 | |||
1854 | for (int count = 0; count < NotecardCache.GetLines(assetID); count++) | ||
1855 | { | 1916 | { |
1856 | NotecardData += NotecardCache.GetLine(assetID, count, 255) + "\n"; | 1917 | return text; |
1857 | } | 1918 | } |
1858 | |||
1859 | return NotecardData; | ||
1860 | |||
1861 | |||
1862 | } | 1919 | } |
1863 | 1920 | ||
1864 | /*Instead of using the LSL Dataserver event to pull notecard data, | 1921 | /// <summary> |
1865 | this will simply read the number of note card lines and return this data as an integer. | 1922 | /// Get the number of lines in the given notecard. |
1866 | 1923 | /// </summary> | |
1867 | Warning - due to the synchronous method this function uses to fetch assets, its use | 1924 | /// <remarks> |
1868 | may be dangerous and unreliable while running in grid mode. | 1925 | /// Instead of using the LSL Dataserver event to pull notecard data, |
1869 | */ | 1926 | /// this will simply read the number of note card lines and return this data as an integer. |
1870 | 1927 | /// | |
1928 | /// Warning - due to the synchronous method this function uses to fetch assets, its use | ||
1929 | /// may be dangerous and unreliable while running in grid mode. | ||
1930 | /// </remarks> | ||
1931 | /// <param name="name">Name of the notecard or its asset id</param> | ||
1932 | /// <returns></returns> | ||
1871 | public int osGetNumberOfNotecardLines(string name) | 1933 | public int osGetNumberOfNotecardLines(string name) |
1872 | { | 1934 | { |
1873 | CheckThreatLevel(ThreatLevel.VeryHigh, "osGetNumberOfNotecardLines"); | 1935 | CheckThreatLevel(ThreatLevel.VeryHigh, "osGetNumberOfNotecardLines"); |
1874 | m_host.AddScriptLPS(1); | 1936 | m_host.AddScriptLPS(1); |
1875 | 1937 | ||
1876 | UUID assetID = UUID.Zero; | 1938 | UUID assetID = CacheNotecard(name); |
1877 | |||
1878 | if (!UUID.TryParse(name, out assetID)) | ||
1879 | { | ||
1880 | foreach (TaskInventoryItem item in m_host.TaskInventory.Values) | ||
1881 | { | ||
1882 | if (item.Type == 7 && item.Name == name) | ||
1883 | { | ||
1884 | assetID = item.AssetID; | ||
1885 | } | ||
1886 | } | ||
1887 | } | ||
1888 | 1939 | ||
1889 | if (assetID == UUID.Zero) | 1940 | if (assetID == UUID.Zero) |
1890 | { | 1941 | { |
@@ -1892,22 +1943,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
1892 | return -1; | 1943 | return -1; |
1893 | } | 1944 | } |
1894 | 1945 | ||
1895 | if (!NotecardCache.IsCached(assetID)) | ||
1896 | { | ||
1897 | AssetBase a = World.AssetService.Get(assetID.ToString()); | ||
1898 | if (a != null) | ||
1899 | { | ||
1900 | System.Text.UTF8Encoding enc = new System.Text.UTF8Encoding(); | ||
1901 | string data = enc.GetString(a.Data); | ||
1902 | NotecardCache.Cache(assetID, data); | ||
1903 | } | ||
1904 | else | ||
1905 | { | ||
1906 | OSSLShoutError("Notecard '" + name + "' could not be found."); | ||
1907 | return -1; | ||
1908 | } | ||
1909 | }; | ||
1910 | |||
1911 | return NotecardCache.GetLines(assetID); | 1946 | return NotecardCache.GetLines(assetID); |
1912 | } | 1947 | } |
1913 | 1948 | ||
@@ -1947,15 +1982,17 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
1947 | { | 1982 | { |
1948 | return ""; | 1983 | return ""; |
1949 | } | 1984 | } |
1950 | |||
1951 | } | 1985 | } |
1952 | 1986 | ||
1987 | /// <summary> | ||
1988 | /// Get the nickname of this grid, as set in the [GridInfo] config section. | ||
1989 | /// </summary> | ||
1990 | /// <remarks> | ||
1953 | /// Threat level is Moderate because intentional abuse, for instance | 1991 | /// Threat level is Moderate because intentional abuse, for instance |
1954 | /// scripts that are written to be malicious only on one grid, | 1992 | /// scripts that are written to be malicious only on one grid, |
1955 | /// for instance in a HG scenario, are a distinct possibility. | 1993 | /// for instance in a HG scenario, are a distinct possibility. |
1956 | /// | 1994 | /// </remarks> |
1957 | /// Use value from the config file and return it. | 1995 | /// <returns></returns> |
1958 | /// | ||
1959 | public string osGetGridNick() | 1996 | public string osGetGridNick() |
1960 | { | 1997 | { |
1961 | CheckThreatLevel(ThreatLevel.Moderate, "osGetGridNick"); | 1998 | CheckThreatLevel(ThreatLevel.Moderate, "osGetGridNick"); |
@@ -2063,12 +2100,19 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
2063 | return World.RegionInfo.RegionSettings.LoadedCreationID; | 2100 | return World.RegionInfo.RegionSettings.LoadedCreationID; |
2064 | } | 2101 | } |
2065 | 2102 | ||
2066 | // Threat level is 'Low' because certain users could possibly be tricked into | 2103 | /// <summary> |
2067 | // dropping an unverified script into one of their own objects, which could | 2104 | /// Get the primitive parameters of a linked prim. |
2068 | // then gather the physical construction details of the object and transmit it | 2105 | /// </summary> |
2069 | // to an unscrupulous third party, thus permitting unauthorized duplication of | 2106 | /// <remarks> |
2070 | // the object's form. | 2107 | /// Threat level is 'Low' because certain users could possibly be tricked into |
2071 | // | 2108 | /// dropping an unverified script into one of their own objects, which could |
2109 | /// then gather the physical construction details of the object and transmit it | ||
2110 | /// to an unscrupulous third party, thus permitting unauthorized duplication of | ||
2111 | /// the object's form. | ||
2112 | /// </remarks> | ||
2113 | /// <param name="linknumber"></param> | ||
2114 | /// <param name="rules"></param> | ||
2115 | /// <returns></returns> | ||
2072 | public LSL_List osGetLinkPrimitiveParams(int linknumber, LSL_List rules) | 2116 | public LSL_List osGetLinkPrimitiveParams(int linknumber, LSL_List rules) |
2073 | { | 2117 | { |
2074 | CheckThreatLevel(ThreatLevel.High, "osGetLinkPrimitiveParams"); | 2118 | CheckThreatLevel(ThreatLevel.High, "osGetLinkPrimitiveParams"); |
@@ -2083,25 +2127,122 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
2083 | return retVal; | 2127 | return retVal; |
2084 | } | 2128 | } |
2085 | 2129 | ||
2086 | public LSL_Key osNpcCreate(string firstname, string lastname, LSL_Vector position, LSL_Key cloneFrom) | 2130 | public LSL_Key osNpcCreate(string firstname, string lastname, LSL_Vector position, string notecard) |
2087 | { | 2131 | { |
2088 | CheckThreatLevel(ThreatLevel.High, "osNpcCreate"); | 2132 | CheckThreatLevel(ThreatLevel.High, "osNpcCreate"); |
2089 | //QueueUserWorkItem | ||
2090 | 2133 | ||
2091 | INPCModule module = World.RequestModuleInterface<INPCModule>(); | 2134 | INPCModule module = World.RequestModuleInterface<INPCModule>(); |
2092 | if (module != null) | 2135 | if (module != null) |
2093 | { | 2136 | { |
2137 | AvatarAppearance appearance = null; | ||
2138 | |||
2139 | UUID id; | ||
2140 | if (UUID.TryParse(notecard, out id)) | ||
2141 | { | ||
2142 | ScenePresence clonePresence = World.GetScenePresence(id); | ||
2143 | if (clonePresence != null) | ||
2144 | appearance = clonePresence.Appearance; | ||
2145 | } | ||
2146 | |||
2147 | if (appearance == null) | ||
2148 | { | ||
2149 | string appearanceSerialized = LoadNotecard(notecard); | ||
2150 | |||
2151 | if (appearanceSerialized != null) | ||
2152 | { | ||
2153 | OSDMap appearanceOsd = (OSDMap)OSDParser.DeserializeLLSDXml(appearanceSerialized); | ||
2154 | appearance = new AvatarAppearance(); | ||
2155 | appearance.Unpack(appearanceOsd); | ||
2156 | } | ||
2157 | } | ||
2158 | |||
2159 | if (appearance == null) | ||
2160 | return new LSL_Key(UUID.Zero.ToString()); | ||
2161 | |||
2094 | UUID x = module.CreateNPC(firstname, | 2162 | UUID x = module.CreateNPC(firstname, |
2095 | lastname, | 2163 | lastname, |
2096 | new Vector3((float) position.x, (float) position.y, (float) position.z), | 2164 | new Vector3((float) position.x, (float) position.y, (float) position.z), |
2097 | World, | 2165 | World, |
2098 | new UUID(cloneFrom)); | 2166 | appearance); |
2099 | 2167 | ||
2100 | return new LSL_Key(x.ToString()); | 2168 | return new LSL_Key(x.ToString()); |
2101 | } | 2169 | } |
2170 | |||
2102 | return new LSL_Key(UUID.Zero.ToString()); | 2171 | return new LSL_Key(UUID.Zero.ToString()); |
2103 | } | 2172 | } |
2104 | 2173 | ||
2174 | /// <summary> | ||
2175 | /// Save the current appearance of the NPC permanently to the named notecard. | ||
2176 | /// </summary> | ||
2177 | /// <param name="avatar"></param> | ||
2178 | /// <param name="notecard">The name of the notecard to which to save the appearance.</param> | ||
2179 | /// <returns>The asset ID of the notecard saved.</returns> | ||
2180 | public LSL_Key osNpcSaveAppearance(LSL_Key npc, string notecard) | ||
2181 | { | ||
2182 | CheckThreatLevel(ThreatLevel.High, "osNpcSaveAppearance"); | ||
2183 | |||
2184 | INPCModule npcModule = World.RequestModuleInterface<INPCModule>(); | ||
2185 | |||
2186 | if (npcModule != null) | ||
2187 | { | ||
2188 | UUID npcId; | ||
2189 | if (!UUID.TryParse(npc.m_string, out npcId)) | ||
2190 | return new LSL_Key(UUID.Zero.ToString()); | ||
2191 | |||
2192 | if (!npcModule.IsNPC(npcId, m_host.ParentGroup.Scene)) | ||
2193 | return new LSL_Key(UUID.Zero.ToString()); | ||
2194 | |||
2195 | return SaveAppearanceToNotecard(npcId, notecard); | ||
2196 | } | ||
2197 | |||
2198 | return new LSL_Key(UUID.Zero.ToString()); | ||
2199 | } | ||
2200 | |||
2201 | public void osNpcLoadAppearance(LSL_Key npc, string notecard) | ||
2202 | { | ||
2203 | CheckThreatLevel(ThreatLevel.High, "osNpcLoadAppearance"); | ||
2204 | |||
2205 | INPCModule npcModule = World.RequestModuleInterface<INPCModule>(); | ||
2206 | |||
2207 | if (npcModule != null) | ||
2208 | { | ||
2209 | UUID npcId; | ||
2210 | if (!UUID.TryParse(npc.m_string, out npcId)) | ||
2211 | return; | ||
2212 | |||
2213 | string appearanceSerialized = LoadNotecard(notecard); | ||
2214 | OSDMap appearanceOsd = (OSDMap)OSDParser.DeserializeLLSDXml(appearanceSerialized); | ||
2215 | // OSD a = OSDParser.DeserializeLLSDXml(appearanceSerialized); | ||
2216 | // Console.WriteLine("appearanceSerialized {0}", appearanceSerialized); | ||
2217 | // Console.WriteLine("a.Type {0}, a.ToString() {1}", a.Type, a); | ||
2218 | AvatarAppearance appearance = new AvatarAppearance(); | ||
2219 | appearance.Unpack(appearanceOsd); | ||
2220 | |||
2221 | npcModule.SetNPCAppearance(npcId, appearance, m_host.ParentGroup.Scene); | ||
2222 | } | ||
2223 | } | ||
2224 | |||
2225 | public LSL_Vector osNpcGetPos(LSL_Key npc) | ||
2226 | { | ||
2227 | CheckThreatLevel(ThreatLevel.High, "osNpcGetPos"); | ||
2228 | |||
2229 | INPCModule npcModule = World.RequestModuleInterface<INPCModule>(); | ||
2230 | if (npcModule != null) | ||
2231 | { | ||
2232 | UUID npcId; | ||
2233 | if (!UUID.TryParse(npc.m_string, out npcId)) | ||
2234 | return new LSL_Vector(0, 0, 0); | ||
2235 | |||
2236 | if (!npcModule.IsNPC(npcId, m_host.ParentGroup.Scene)) | ||
2237 | return new LSL_Vector(0, 0, 0); | ||
2238 | |||
2239 | Vector3 pos = World.GetScenePresence(npcId).AbsolutePosition; | ||
2240 | return new LSL_Vector(pos.X, pos.Y, pos.Z); | ||
2241 | } | ||
2242 | |||
2243 | return new LSL_Vector(0, 0, 0); | ||
2244 | } | ||
2245 | |||
2105 | public void osNpcMoveTo(LSL_Key npc, LSL_Vector position) | 2246 | public void osNpcMoveTo(LSL_Key npc, LSL_Vector position) |
2106 | { | 2247 | { |
2107 | CheckThreatLevel(ThreatLevel.High, "osNpcMoveTo"); | 2248 | CheckThreatLevel(ThreatLevel.High, "osNpcMoveTo"); |
@@ -2109,11 +2250,87 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
2109 | INPCModule module = World.RequestModuleInterface<INPCModule>(); | 2250 | INPCModule module = World.RequestModuleInterface<INPCModule>(); |
2110 | if (module != null) | 2251 | if (module != null) |
2111 | { | 2252 | { |
2253 | UUID npcId; | ||
2254 | if (!UUID.TryParse(npc.m_string, out npcId)) | ||
2255 | return; | ||
2256 | |||
2112 | Vector3 pos = new Vector3((float) position.x, (float) position.y, (float) position.z); | 2257 | Vector3 pos = new Vector3((float) position.x, (float) position.y, (float) position.z); |
2113 | module.MoveToTarget(new UUID(npc.m_string), World, pos); | 2258 | module.MoveToTarget(npcId, World, pos, false, true); |
2114 | } | 2259 | } |
2115 | } | 2260 | } |
2116 | 2261 | ||
2262 | public void osNpcMoveToTarget(LSL_Key npc, LSL_Vector target, int options) | ||
2263 | { | ||
2264 | CheckThreatLevel(ThreatLevel.High, "osNpcMoveToTarget"); | ||
2265 | |||
2266 | INPCModule module = World.RequestModuleInterface<INPCModule>(); | ||
2267 | if (module != null) | ||
2268 | { | ||
2269 | UUID npcId; | ||
2270 | if (!UUID.TryParse(npc.m_string, out npcId)) | ||
2271 | return; | ||
2272 | |||
2273 | Vector3 pos = new Vector3((float)target.x, (float)target.y, (float)target.z); | ||
2274 | module.MoveToTarget( | ||
2275 | new UUID(npc.m_string), | ||
2276 | World, | ||
2277 | pos, | ||
2278 | (options & ScriptBaseClass.OS_NPC_NO_FLY) != 0, | ||
2279 | (options & ScriptBaseClass.OS_NPC_LAND_AT_TARGET) != 0); | ||
2280 | } | ||
2281 | } | ||
2282 | |||
2283 | public LSL_Rotation osNpcGetRot(LSL_Key npc) | ||
2284 | { | ||
2285 | CheckThreatLevel(ThreatLevel.High, "osNpcGetRot"); | ||
2286 | |||
2287 | INPCModule npcModule = World.RequestModuleInterface<INPCModule>(); | ||
2288 | if (npcModule != null) | ||
2289 | { | ||
2290 | UUID npcId; | ||
2291 | if (!UUID.TryParse(npc.m_string, out npcId)) | ||
2292 | return new LSL_Rotation(Quaternion.Identity.X, Quaternion.Identity.Y, Quaternion.Identity.Z, Quaternion.Identity.W); | ||
2293 | |||
2294 | if (!npcModule.IsNPC(npcId, m_host.ParentGroup.Scene)) | ||
2295 | return new LSL_Rotation(Quaternion.Identity.X, Quaternion.Identity.Y, Quaternion.Identity.Z, Quaternion.Identity.W); | ||
2296 | |||
2297 | ScenePresence sp = World.GetScenePresence(npcId); | ||
2298 | Quaternion rot = sp.Rotation; | ||
2299 | |||
2300 | return new LSL_Rotation(rot.X, rot.Y, rot.Z, rot.W); | ||
2301 | } | ||
2302 | |||
2303 | return new LSL_Rotation(Quaternion.Identity.X, Quaternion.Identity.Y, Quaternion.Identity.Z, Quaternion.Identity.W); | ||
2304 | } | ||
2305 | |||
2306 | public void osNpcSetRot(LSL_Key npc, LSL_Rotation rotation) | ||
2307 | { | ||
2308 | CheckThreatLevel(ThreatLevel.High, "osNpcSetRot"); | ||
2309 | |||
2310 | INPCModule npcModule = World.RequestModuleInterface<INPCModule>(); | ||
2311 | if (npcModule != null) | ||
2312 | { | ||
2313 | UUID npcId; | ||
2314 | if (!UUID.TryParse(npc.m_string, out npcId)) | ||
2315 | return; | ||
2316 | |||
2317 | if (!npcModule.IsNPC(npcId, m_host.ParentGroup.Scene)) | ||
2318 | return; | ||
2319 | |||
2320 | ScenePresence sp = World.GetScenePresence(npcId); | ||
2321 | sp.Rotation = LSL_Api.Rot2Quaternion(rotation); | ||
2322 | } | ||
2323 | } | ||
2324 | |||
2325 | public void osNpcStopMoveToTarget(LSL_Key npc) | ||
2326 | { | ||
2327 | CheckThreatLevel(ThreatLevel.VeryLow, "osNpcStopMoveTo"); | ||
2328 | |||
2329 | INPCModule module = World.RequestModuleInterface<INPCModule>(); | ||
2330 | if (module != null) | ||
2331 | module.StopMoveToTarget(new UUID(npc.m_string), World); | ||
2332 | } | ||
2333 | |||
2117 | public void osNpcSay(LSL_Key npc, string message) | 2334 | public void osNpcSay(LSL_Key npc, string message) |
2118 | { | 2335 | { |
2119 | CheckThreatLevel(ThreatLevel.High, "osNpcSay"); | 2336 | CheckThreatLevel(ThreatLevel.High, "osNpcSay"); |
@@ -2135,6 +2352,64 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
2135 | module.DeleteNPC(new UUID(npc.m_string), World); | 2352 | module.DeleteNPC(new UUID(npc.m_string), World); |
2136 | } | 2353 | } |
2137 | } | 2354 | } |
2355 | |||
2356 | /// <summary> | ||
2357 | /// Save the current appearance of the script owner permanently to the named notecard. | ||
2358 | /// </summary> | ||
2359 | /// <param name="notecard">The name of the notecard to which to save the appearance.</param> | ||
2360 | /// <returns>The asset ID of the notecard saved.</returns> | ||
2361 | public LSL_Key osOwnerSaveAppearance(string notecard) | ||
2362 | { | ||
2363 | CheckThreatLevel(ThreatLevel.High, "osOwnerSaveAppearance"); | ||
2364 | |||
2365 | return SaveAppearanceToNotecard(m_host.OwnerID, notecard); | ||
2366 | } | ||
2367 | |||
2368 | public LSL_Key osAgentSaveAppearance(LSL_Key avatarId, string notecard) | ||
2369 | { | ||
2370 | CheckThreatLevel(ThreatLevel.VeryHigh, "osAgentSaveAppearance"); | ||
2371 | |||
2372 | return SaveAppearanceToNotecard(avatarId, notecard); | ||
2373 | } | ||
2374 | |||
2375 | protected LSL_Key SaveAppearanceToNotecard(ScenePresence sp, string notecard) | ||
2376 | { | ||
2377 | IAvatarFactory appearanceModule = World.RequestModuleInterface<IAvatarFactory>(); | ||
2378 | |||
2379 | if (appearanceModule != null) | ||
2380 | { | ||
2381 | appearanceModule.SaveBakedTextures(sp.UUID); | ||
2382 | OSDMap appearancePacked = sp.Appearance.Pack(); | ||
2383 | |||
2384 | TaskInventoryItem item | ||
2385 | = SaveNotecard(notecard, "Avatar Appearance", Util.GetFormattedXml(appearancePacked as OSD), true); | ||
2386 | |||
2387 | return new LSL_Key(item.AssetID.ToString()); | ||
2388 | } | ||
2389 | else | ||
2390 | { | ||
2391 | return new LSL_Key(UUID.Zero.ToString()); | ||
2392 | } | ||
2393 | } | ||
2394 | |||
2395 | protected LSL_Key SaveAppearanceToNotecard(UUID avatarId, string notecard) | ||
2396 | { | ||
2397 | ScenePresence sp = World.GetScenePresence(avatarId); | ||
2398 | |||
2399 | if (sp == null || sp.IsChildAgent) | ||
2400 | return new LSL_Key(UUID.Zero.ToString()); | ||
2401 | |||
2402 | return SaveAppearanceToNotecard(sp, notecard); | ||
2403 | } | ||
2404 | |||
2405 | protected LSL_Key SaveAppearanceToNotecard(LSL_Key rawAvatarId, string notecard) | ||
2406 | { | ||
2407 | UUID avatarId; | ||
2408 | if (!UUID.TryParse(rawAvatarId, out avatarId)) | ||
2409 | return new LSL_Key(UUID.Zero.ToString()); | ||
2410 | |||
2411 | return SaveAppearanceToNotecard(avatarId, notecard); | ||
2412 | } | ||
2138 | 2413 | ||
2139 | /// <summary> | 2414 | /// <summary> |
2140 | /// Get current region's map texture UUID | 2415 | /// Get current region's map texture UUID |
@@ -2344,10 +2619,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
2344 | obj.Shape.ProjectionFocus = (float)focus; | 2619 | obj.Shape.ProjectionFocus = (float)focus; |
2345 | obj.Shape.ProjectionAmbiance = (float)amb; | 2620 | obj.Shape.ProjectionAmbiance = (float)amb; |
2346 | 2621 | ||
2347 | |||
2348 | obj.ParentGroup.HasGroupChanged = true; | 2622 | obj.ParentGroup.HasGroupChanged = true; |
2349 | obj.ScheduleFullUpdate(); | 2623 | obj.ScheduleFullUpdate(); |
2350 | |||
2351 | } | 2624 | } |
2352 | 2625 | ||
2353 | /// <summary> | 2626 | /// <summary> |
@@ -2372,6 +2645,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
2372 | } | 2645 | } |
2373 | } | 2646 | } |
2374 | }); | 2647 | }); |
2648 | |||
2375 | return result; | 2649 | return result; |
2376 | } | 2650 | } |
2377 | 2651 | ||
@@ -2391,4 +2665,4 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
2391 | return date.ToString("yyyy-MM-ddTHH:mm:ss.fffffffZ"); | 2665 | return date.ToString("yyyy-MM-ddTHH:mm:ss.fffffffZ"); |
2392 | } | 2666 | } |
2393 | } | 2667 | } |
2394 | } | 2668 | } \ No newline at end of file |
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs index 19352f0..87cfe1a 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs | |||
@@ -168,12 +168,21 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Interfaces | |||
168 | 168 | ||
169 | LSL_List osGetLinkPrimitiveParams(int linknumber, LSL_List rules); | 169 | LSL_List osGetLinkPrimitiveParams(int linknumber, LSL_List rules); |
170 | 170 | ||
171 | 171 | key osNpcCreate(string user, string name, vector position, string notecard); | |
172 | key osNpcCreate(string user, string name, vector position, key cloneFrom); | 172 | LSL_Key osNpcSaveAppearance(key npc, string notecard); |
173 | void osNpcLoadAppearance(key npc, string notecard); | ||
174 | vector osNpcGetPos(key npc); | ||
173 | void osNpcMoveTo(key npc, vector position); | 175 | void osNpcMoveTo(key npc, vector position); |
176 | void osNpcMoveToTarget(key npc, vector target, int options); | ||
177 | rotation osNpcGetRot(key npc); | ||
178 | void osNpcSetRot(LSL_Key npc, rotation rot); | ||
179 | void osNpcStopMoveToTarget(LSL_Key npc); | ||
174 | void osNpcSay(key npc, string message); | 180 | void osNpcSay(key npc, string message); |
175 | void osNpcRemove(key npc); | 181 | void osNpcRemove(key npc); |
176 | 182 | ||
183 | LSL_Key osOwnerSaveAppearance(string notecard); | ||
184 | LSL_Key osAgentSaveAppearance(key agentId, string notecard); | ||
185 | |||
177 | key osGetMapTexture(); | 186 | key osGetMapTexture(); |
178 | key osGetRegionMapTexture(string regionName); | 187 | key osGetRegionMapTexture(string regionName); |
179 | LSL_List osGetRegionStats(); | 188 | LSL_List osGetRegionStats(); |
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Constants.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Constants.cs index 3f90788..e82c281 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Constants.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Constants.cs | |||
@@ -591,6 +591,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase | |||
591 | public const int STATS_ACTIVE_SCRIPTS = 19; | 591 | public const int STATS_ACTIVE_SCRIPTS = 19; |
592 | public const int STATS_SCRIPT_LPS = 20; | 592 | public const int STATS_SCRIPT_LPS = 20; |
593 | 593 | ||
594 | // Constants for osNpc* functions | ||
595 | public const int OS_NPC_FLY = 0; | ||
596 | public const int OS_NPC_NO_FLY = 1; | ||
597 | public const int OS_NPC_LAND_AT_TARGET = 2; | ||
598 | |||
594 | public const string URL_REQUEST_GRANTED = "URL_REQUEST_GRANTED"; | 599 | public const string URL_REQUEST_GRANTED = "URL_REQUEST_GRANTED"; |
595 | public const string URL_REQUEST_DENIED = "URL_REQUEST_DENIED"; | 600 | public const string URL_REQUEST_DENIED = "URL_REQUEST_DENIED"; |
596 | 601 | ||
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs index 7c59098..bbc8cc6 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs | |||
@@ -483,11 +483,46 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase | |||
483 | return m_OSSL_Functions.osNpcCreate(user, name, position, cloneFrom); | 483 | return m_OSSL_Functions.osNpcCreate(user, name, position, cloneFrom); |
484 | } | 484 | } |
485 | 485 | ||
486 | public key osNpcSaveAppearance(key npc, string notecard) | ||
487 | { | ||
488 | return m_OSSL_Functions.osNpcSaveAppearance(npc, notecard); | ||
489 | } | ||
490 | |||
491 | public void osNpcLoadAppearance(key npc, string notecard) | ||
492 | { | ||
493 | m_OSSL_Functions.osNpcLoadAppearance(npc, notecard); | ||
494 | } | ||
495 | |||
496 | public vector osNpcGetPos(LSL_Key npc) | ||
497 | { | ||
498 | return m_OSSL_Functions.osNpcGetPos(npc); | ||
499 | } | ||
500 | |||
486 | public void osNpcMoveTo(key npc, vector position) | 501 | public void osNpcMoveTo(key npc, vector position) |
487 | { | 502 | { |
488 | m_OSSL_Functions.osNpcMoveTo(npc, position); | 503 | m_OSSL_Functions.osNpcMoveTo(npc, position); |
489 | } | 504 | } |
490 | 505 | ||
506 | public void osNpcMoveToTarget(key npc, vector target, int options) | ||
507 | { | ||
508 | m_OSSL_Functions.osNpcMoveToTarget(npc, target, options); | ||
509 | } | ||
510 | |||
511 | public rotation osNpcGetRot(key npc) | ||
512 | { | ||
513 | return m_OSSL_Functions.osNpcGetRot(npc); | ||
514 | } | ||
515 | |||
516 | public void osNpcSetRot(key npc, rotation rot) | ||
517 | { | ||
518 | m_OSSL_Functions.osNpcSetRot(npc, rot); | ||
519 | } | ||
520 | |||
521 | public void osNpcStopMoveToTarget(LSL_Key npc) | ||
522 | { | ||
523 | m_OSSL_Functions.osNpcStopMoveToTarget(npc); | ||
524 | } | ||
525 | |||
491 | public void osNpcSay(key npc, string message) | 526 | public void osNpcSay(key npc, string message) |
492 | { | 527 | { |
493 | m_OSSL_Functions.osNpcSay(npc, message); | 528 | m_OSSL_Functions.osNpcSay(npc, message); |
@@ -498,6 +533,16 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase | |||
498 | m_OSSL_Functions.osNpcRemove(npc); | 533 | m_OSSL_Functions.osNpcRemove(npc); |
499 | } | 534 | } |
500 | 535 | ||
536 | public LSL_Key osOwnerSaveAppearance(string notecard) | ||
537 | { | ||
538 | return m_OSSL_Functions.osOwnerSaveAppearance(notecard); | ||
539 | } | ||
540 | |||
541 | public LSL_Key osAgentSaveAppearance(LSL_Key agentId, string notecard) | ||
542 | { | ||
543 | return m_OSSL_Functions.osAgentSaveAppearance(agentId, notecard); | ||
544 | } | ||
545 | |||
501 | public OSSLPrim Prim; | 546 | public OSSLPrim Prim; |
502 | 547 | ||
503 | [Serializable] | 548 | [Serializable] |
diff --git a/OpenSim/Region/ScriptEngine/Shared/Tests/LSL_ApiTest.cs b/OpenSim/Region/ScriptEngine/Shared/Tests/LSL_ApiTest.cs index 80b60a4..623c82d 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Tests/LSL_ApiTest.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Tests/LSL_ApiTest.cs | |||
@@ -27,11 +27,13 @@ | |||
27 | 27 | ||
28 | using System.Collections.Generic; | 28 | using System.Collections.Generic; |
29 | using NUnit.Framework; | 29 | using NUnit.Framework; |
30 | using OpenSim.Framework; | ||
30 | using OpenSim.Tests.Common; | 31 | using OpenSim.Tests.Common; |
31 | using OpenSim.Region.ScriptEngine.Shared; | 32 | using OpenSim.Region.ScriptEngine.Shared; |
32 | using OpenSim.Region.Framework.Scenes; | 33 | using OpenSim.Region.Framework.Scenes; |
33 | using Nini.Config; | 34 | using Nini.Config; |
34 | using OpenSim.Region.ScriptEngine.Shared.Api; | 35 | using OpenSim.Region.ScriptEngine.Shared.Api; |
36 | using OpenSim.Region.ScriptEngine.Shared.ScriptBase; | ||
35 | using OpenMetaverse; | 37 | using OpenMetaverse; |
36 | using System; | 38 | using System; |
37 | using OpenSim.Tests.Common.Mock; | 39 | using OpenSim.Tests.Common.Mock; |
@@ -47,6 +49,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Tests | |||
47 | 49 | ||
48 | private const double ANGLE_ACCURACY_IN_RADIANS = 1E-6; | 50 | private const double ANGLE_ACCURACY_IN_RADIANS = 1E-6; |
49 | private const double VECTOR_COMPONENT_ACCURACY = 0.0000005d; | 51 | private const double VECTOR_COMPONENT_ACCURACY = 0.0000005d; |
52 | private const double FLOAT_ACCURACY = 0.00005d; | ||
50 | private LSL_Api m_lslApi; | 53 | private LSL_Api m_lslApi; |
51 | 54 | ||
52 | [SetUp] | 55 | [SetUp] |
@@ -57,8 +60,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Tests | |||
57 | IConfig config = initConfigSource.AddConfig("XEngine"); | 60 | IConfig config = initConfigSource.AddConfig("XEngine"); |
58 | config.Set("Enabled", "true"); | 61 | config.Set("Enabled", "true"); |
59 | 62 | ||
60 | Scene scene = SceneSetupHelpers.SetupScene(); | 63 | Scene scene = SceneHelpers.SetupScene(); |
61 | SceneObjectPart part = SceneSetupHelpers.AddSceneObject(scene); | 64 | SceneObjectPart part = SceneHelpers.AddSceneObject(scene); |
62 | 65 | ||
63 | XEngine.XEngine engine = new XEngine.XEngine(); | 66 | XEngine.XEngine engine = new XEngine.XEngine(); |
64 | engine.Initialise(initConfigSource); | 67 | engine.Initialise(initConfigSource); |
@@ -166,6 +169,178 @@ namespace OpenSim.Region.ScriptEngine.Shared.Tests | |||
166 | } | 169 | } |
167 | 170 | ||
168 | [Test] | 171 | [Test] |
172 | // llSetPrimitiveParams and llGetPrimitiveParams test. | ||
173 | public void TestllSetPrimitiveParams() | ||
174 | { | ||
175 | // Create Prim1. | ||
176 | Scene scene = SceneHelpers.SetupScene(); | ||
177 | string obj1Name = "Prim1"; | ||
178 | UUID objUuid = new UUID("00000000-0000-0000-0000-000000000001"); | ||
179 | SceneObjectPart part1 = | ||
180 | new SceneObjectPart(UUID.Zero, PrimitiveBaseShape.Default, | ||
181 | Vector3.Zero, Quaternion.Identity, | ||
182 | Vector3.Zero) { Name = obj1Name, UUID = objUuid }; | ||
183 | Assert.That(scene.AddNewSceneObject(new SceneObjectGroup(part1), false), Is.True); | ||
184 | |||
185 | // Test a sphere. | ||
186 | CheckllSetPrimitiveParams( | ||
187 | "test 1", // Prim test identification string | ||
188 | new LSL_Types.Vector3(6.0d, 9.9d, 9.9d), // Prim size | ||
189 | ScriptBaseClass.PRIM_TYPE_SPHERE, // Prim type | ||
190 | ScriptBaseClass.PRIM_HOLE_DEFAULT, // Prim hole type | ||
191 | new LSL_Types.Vector3(0.0d, 0.075d, 0.0d), // Prim cut | ||
192 | 0.80d, // Prim hollow | ||
193 | new LSL_Types.Vector3(0.0d, 0.0d, 0.0d), // Prim twist | ||
194 | new LSL_Types.Vector3(0.32d, 0.76d, 0.0d)); // Prim dimple | ||
195 | |||
196 | // Test a prism. | ||
197 | CheckllSetPrimitiveParams( | ||
198 | "test 2", // Prim test identification string | ||
199 | new LSL_Types.Vector3(3.5d, 3.5d, 3.5d), // Prim size | ||
200 | ScriptBaseClass.PRIM_TYPE_PRISM, // Prim type | ||
201 | ScriptBaseClass.PRIM_HOLE_CIRCLE, // Prim hole type | ||
202 | new LSL_Types.Vector3(0.0d, 1.0d, 0.0d), // Prim cut | ||
203 | 0.90d, // Prim hollow | ||
204 | new LSL_Types.Vector3(0.0d, 0.0d, 0.0d), // Prim twist | ||
205 | new LSL_Types.Vector3(2.0d, 1.0d, 0.0d), // Prim taper | ||
206 | new LSL_Types.Vector3(0.0d, 0.0d, 0.0d)); // Prim shear | ||
207 | |||
208 | // Test a box. | ||
209 | CheckllSetPrimitiveParams( | ||
210 | "test 3", // Prim test identification string | ||
211 | new LSL_Types.Vector3(3.5d, 3.5d, 3.5d), // Prim size | ||
212 | ScriptBaseClass.PRIM_TYPE_BOX, // Prim type | ||
213 | ScriptBaseClass.PRIM_HOLE_TRIANGLE, // Prim hole type | ||
214 | new LSL_Types.Vector3(0.0d, 1.0d, 0.0d), // Prim cut | ||
215 | 0.90d, // Prim hollow | ||
216 | new LSL_Types.Vector3(1.0d, 0.0d, 0.0d), // Prim twist | ||
217 | new LSL_Types.Vector3(1.0d, 1.0d, 0.0d), // Prim taper | ||
218 | new LSL_Types.Vector3(0.0d, 0.0d, 0.0d)); // Prim shear | ||
219 | |||
220 | // Test a tube. | ||
221 | CheckllSetPrimitiveParams( | ||
222 | "test 4", // Prim test identification string | ||
223 | new LSL_Types.Vector3(4.2d, 4.2d, 4.2d), // Prim size | ||
224 | ScriptBaseClass.PRIM_TYPE_TUBE, // Prim type | ||
225 | ScriptBaseClass.PRIM_HOLE_SQUARE, // Prim hole type | ||
226 | new LSL_Types.Vector3(0.0d, 1.0d, 0.0d), // Prim cut | ||
227 | 0.00d, // Prim hollow | ||
228 | new LSL_Types.Vector3(1.0d, -1.0d, 0.0d), // Prim twist | ||
229 | new LSL_Types.Vector3(1.0d, 0.5d, 0.0d), // Prim hole size | ||
230 | new LSL_Types.Vector3(0.0d, 0.0d, 0.0d), // Prim shear | ||
231 | new LSL_Types.Vector3(0.0d, 1.0d, 0.0d), // Prim profile cut | ||
232 | new LSL_Types.Vector3(-1.0d, 1.0d, 0.0d), // Prim taper | ||
233 | 1.0d, // Prim revolutions | ||
234 | 1.0d, // Prim radius | ||
235 | 0.0d); // Prim skew | ||
236 | } | ||
237 | |||
238 | // Set prim params for a box, cylinder or prism and check results. | ||
239 | public void CheckllSetPrimitiveParams(string primTest, | ||
240 | LSL_Types.Vector3 primSize, int primType, int primHoleType, LSL_Types.Vector3 primCut, | ||
241 | double primHollow, LSL_Types.Vector3 primTwist, LSL_Types.Vector3 primTaper, LSL_Types.Vector3 primShear) | ||
242 | { | ||
243 | // Set the prim params. | ||
244 | m_lslApi.llSetPrimitiveParams(new LSL_Types.list(ScriptBaseClass.PRIM_SIZE, primSize, | ||
245 | ScriptBaseClass.PRIM_TYPE, primType, primHoleType, | ||
246 | primCut, primHollow, primTwist, primTaper, primShear)); | ||
247 | |||
248 | // Get params for prim to validate settings. | ||
249 | LSL_Types.list primParams = | ||
250 | m_lslApi.llGetPrimitiveParams(new LSL_Types.list(ScriptBaseClass.PRIM_SIZE, ScriptBaseClass.PRIM_TYPE)); | ||
251 | |||
252 | // Validate settings. | ||
253 | CheckllSetPrimitiveParamsVector(primSize, m_lslApi.llList2Vector(primParams, 0), primTest + " prim size"); | ||
254 | Assert.AreEqual(primType, m_lslApi.llList2Integer(primParams, 1), | ||
255 | "TestllSetPrimitiveParams " + primTest + " prim type check fail"); | ||
256 | Assert.AreEqual(primHoleType, m_lslApi.llList2Integer(primParams, 2), | ||
257 | "TestllSetPrimitiveParams " + primTest + " prim hole default check fail"); | ||
258 | CheckllSetPrimitiveParamsVector(primCut, m_lslApi.llList2Vector(primParams, 3), primTest + " prim cut"); | ||
259 | Assert.AreEqual(primHollow, m_lslApi.llList2Float(primParams, 4), FLOAT_ACCURACY, | ||
260 | "TestllSetPrimitiveParams " + primTest + " prim hollow check fail"); | ||
261 | CheckllSetPrimitiveParamsVector(primTwist, m_lslApi.llList2Vector(primParams, 5), primTest + " prim twist"); | ||
262 | CheckllSetPrimitiveParamsVector(primTaper, m_lslApi.llList2Vector(primParams, 6), primTest + " prim taper"); | ||
263 | CheckllSetPrimitiveParamsVector(primShear, m_lslApi.llList2Vector(primParams, 7), primTest + " prim shear"); | ||
264 | } | ||
265 | |||
266 | // Set prim params for a sphere and check results. | ||
267 | public void CheckllSetPrimitiveParams(string primTest, | ||
268 | LSL_Types.Vector3 primSize, int primType, int primHoleType, LSL_Types.Vector3 primCut, | ||
269 | double primHollow, LSL_Types.Vector3 primTwist, LSL_Types.Vector3 primDimple) | ||
270 | { | ||
271 | // Set the prim params. | ||
272 | m_lslApi.llSetPrimitiveParams(new LSL_Types.list(ScriptBaseClass.PRIM_SIZE, primSize, | ||
273 | ScriptBaseClass.PRIM_TYPE, primType, primHoleType, | ||
274 | primCut, primHollow, primTwist, primDimple)); | ||
275 | |||
276 | // Get params for prim to validate settings. | ||
277 | LSL_Types.list primParams = | ||
278 | m_lslApi.llGetPrimitiveParams(new LSL_Types.list(ScriptBaseClass.PRIM_SIZE, ScriptBaseClass.PRIM_TYPE)); | ||
279 | |||
280 | // Validate settings. | ||
281 | CheckllSetPrimitiveParamsVector(primSize, m_lslApi.llList2Vector(primParams, 0), primTest + " prim size"); | ||
282 | Assert.AreEqual(primType, m_lslApi.llList2Integer(primParams, 1), | ||
283 | "TestllSetPrimitiveParams " + primTest + " prim type check fail"); | ||
284 | Assert.AreEqual(primHoleType, m_lslApi.llList2Integer(primParams, 2), | ||
285 | "TestllSetPrimitiveParams " + primTest + " prim hole default check fail"); | ||
286 | CheckllSetPrimitiveParamsVector(primCut, m_lslApi.llList2Vector(primParams, 3), primTest + " prim cut"); | ||
287 | Assert.AreEqual(primHollow, m_lslApi.llList2Float(primParams, 4), FLOAT_ACCURACY, | ||
288 | "TestllSetPrimitiveParams " + primTest + " prim hollow check fail"); | ||
289 | CheckllSetPrimitiveParamsVector(primTwist, m_lslApi.llList2Vector(primParams, 5), primTest + " prim twist"); | ||
290 | CheckllSetPrimitiveParamsVector(primDimple, m_lslApi.llList2Vector(primParams, 6), primTest + " prim dimple"); | ||
291 | } | ||
292 | |||
293 | // Set prim params for a torus, tube or ring and check results. | ||
294 | public void CheckllSetPrimitiveParams(string primTest, | ||
295 | LSL_Types.Vector3 primSize, int primType, int primHoleType, LSL_Types.Vector3 primCut, | ||
296 | double primHollow, LSL_Types.Vector3 primTwist, LSL_Types.Vector3 primHoleSize, | ||
297 | LSL_Types.Vector3 primShear, LSL_Types.Vector3 primProfCut, LSL_Types.Vector3 primTaper, | ||
298 | double primRev, double primRadius, double primSkew) | ||
299 | { | ||
300 | // Set the prim params. | ||
301 | m_lslApi.llSetPrimitiveParams(new LSL_Types.list(ScriptBaseClass.PRIM_SIZE, primSize, | ||
302 | ScriptBaseClass.PRIM_TYPE, primType, primHoleType, | ||
303 | primCut, primHollow, primTwist, primHoleSize, primShear, primProfCut, | ||
304 | primTaper, primRev, primRadius, primSkew)); | ||
305 | |||
306 | // Get params for prim to validate settings. | ||
307 | LSL_Types.list primParams = | ||
308 | m_lslApi.llGetPrimitiveParams(new LSL_Types.list(ScriptBaseClass.PRIM_SIZE, ScriptBaseClass.PRIM_TYPE)); | ||
309 | |||
310 | // Valdate settings. | ||
311 | CheckllSetPrimitiveParamsVector(primSize, m_lslApi.llList2Vector(primParams, 0), primTest + " prim size"); | ||
312 | Assert.AreEqual(primType, m_lslApi.llList2Integer(primParams, 1), | ||
313 | "TestllSetPrimitiveParams " + primTest + " prim type check fail"); | ||
314 | Assert.AreEqual(primHoleType, m_lslApi.llList2Integer(primParams, 2), | ||
315 | "TestllSetPrimitiveParams " + primTest + " prim hole default check fail"); | ||
316 | CheckllSetPrimitiveParamsVector(primCut, m_lslApi.llList2Vector(primParams, 3), primTest + " prim cut"); | ||
317 | Assert.AreEqual(primHollow, m_lslApi.llList2Float(primParams, 4), FLOAT_ACCURACY, | ||
318 | "TestllSetPrimitiveParams " + primTest + " prim hollow check fail"); | ||
319 | CheckllSetPrimitiveParamsVector(primTwist, m_lslApi.llList2Vector(primParams, 5), primTest + " prim twist"); | ||
320 | CheckllSetPrimitiveParamsVector(primHoleSize, m_lslApi.llList2Vector(primParams, 6), primTest + " prim hole size"); | ||
321 | CheckllSetPrimitiveParamsVector(primShear, m_lslApi.llList2Vector(primParams, 7), primTest + " prim shear"); | ||
322 | CheckllSetPrimitiveParamsVector(primProfCut, m_lslApi.llList2Vector(primParams, 8), primTest + " prim profile cut"); | ||
323 | CheckllSetPrimitiveParamsVector(primTaper, m_lslApi.llList2Vector(primParams, 9), primTest + " prim taper"); | ||
324 | Assert.AreEqual(primRev, m_lslApi.llList2Float(primParams, 10), FLOAT_ACCURACY, | ||
325 | "TestllSetPrimitiveParams " + primTest + " prim revolution fail"); | ||
326 | Assert.AreEqual(primRadius, m_lslApi.llList2Float(primParams, 11), FLOAT_ACCURACY, | ||
327 | "TestllSetPrimitiveParams " + primTest + " prim radius fail"); | ||
328 | Assert.AreEqual(primSkew, m_lslApi.llList2Float(primParams, 12), FLOAT_ACCURACY, | ||
329 | "TestllSetPrimitiveParams " + primTest + " prim skew fail"); | ||
330 | } | ||
331 | |||
332 | public void CheckllSetPrimitiveParamsVector(LSL_Types.Vector3 vecCheck, LSL_Types.Vector3 vecReturned, string msg) | ||
333 | { | ||
334 | // Check each vector component against expected result. | ||
335 | Assert.AreEqual(vecCheck.x, vecReturned.x, VECTOR_COMPONENT_ACCURACY, | ||
336 | "TestllSetPrimitiveParams " + msg + " vector check fail on x component"); | ||
337 | Assert.AreEqual(vecCheck.y, vecReturned.y, VECTOR_COMPONENT_ACCURACY, | ||
338 | "TestllSetPrimitiveParams " + msg + " vector check fail on y component"); | ||
339 | Assert.AreEqual(vecCheck.z, vecReturned.z, VECTOR_COMPONENT_ACCURACY, | ||
340 | "TestllSetPrimitiveParams " + msg + " vector check fail on z component"); | ||
341 | } | ||
342 | |||
343 | [Test] | ||
169 | // llVecNorm test. | 344 | // llVecNorm test. |
170 | public void TestllVecNorm() | 345 | public void TestllVecNorm() |
171 | { | 346 | { |
diff --git a/OpenSim/Region/ScriptEngine/Shared/Tests/OSSL_ApiAppearanceTest.cs b/OpenSim/Region/ScriptEngine/Shared/Tests/OSSL_ApiAppearanceTest.cs new file mode 100644 index 0000000..7573dff --- /dev/null +++ b/OpenSim/Region/ScriptEngine/Shared/Tests/OSSL_ApiAppearanceTest.cs | |||
@@ -0,0 +1,229 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | using System.Collections.Generic; | ||
30 | using System.Reflection; | ||
31 | using System.Text; | ||
32 | using log4net; | ||
33 | using Nini.Config; | ||
34 | using NUnit.Framework; | ||
35 | using OpenMetaverse; | ||
36 | using OpenMetaverse.Assets; | ||
37 | using OpenMetaverse.StructuredData; | ||
38 | using OpenSim.Framework; | ||
39 | using OpenSim.Region.CoreModules.Avatar.AvatarFactory; | ||
40 | using OpenSim.Region.OptionalModules.World.NPC; | ||
41 | using OpenSim.Region.Framework.Scenes; | ||
42 | using OpenSim.Region.ScriptEngine.Shared; | ||
43 | using OpenSim.Region.ScriptEngine.Shared.Api; | ||
44 | using OpenSim.Services.Interfaces; | ||
45 | using OpenSim.Tests.Common; | ||
46 | using OpenSim.Tests.Common.Mock; | ||
47 | |||
48 | namespace OpenSim.Region.ScriptEngine.Shared.Tests | ||
49 | { | ||
50 | /// <summary> | ||
51 | /// Tests for OSSL_Api | ||
52 | /// </summary> | ||
53 | [TestFixture] | ||
54 | public class OSSL_ApiAppearanceTest | ||
55 | { | ||
56 | protected Scene m_scene; | ||
57 | protected XEngine.XEngine m_engine; | ||
58 | |||
59 | [SetUp] | ||
60 | public void SetUp() | ||
61 | { | ||
62 | IConfigSource initConfigSource = new IniConfigSource(); | ||
63 | IConfig config = initConfigSource.AddConfig("XEngine"); | ||
64 | config.Set("Enabled", "true"); | ||
65 | config.Set("AllowOSFunctions", "true"); | ||
66 | config.Set("OSFunctionThreatLevel", "Severe"); | ||
67 | config = initConfigSource.AddConfig("NPC"); | ||
68 | config.Set("Enabled", "true"); | ||
69 | |||
70 | m_scene = SceneHelpers.SetupScene(); | ||
71 | SceneHelpers.SetupSceneModules(m_scene, initConfigSource, new AvatarFactoryModule(), new NPCModule()); | ||
72 | |||
73 | m_engine = new XEngine.XEngine(); | ||
74 | m_engine.Initialise(initConfigSource); | ||
75 | m_engine.AddRegion(m_scene); | ||
76 | } | ||
77 | |||
78 | /// <summary> | ||
79 | /// Test creation of an NPC where the appearance data comes from a notecard | ||
80 | /// </summary> | ||
81 | [Test] | ||
82 | public void TestOsNpcCreateFromNotecard() | ||
83 | { | ||
84 | TestHelpers.InMethod(); | ||
85 | // log4net.Config.XmlConfigurator.Configure(); | ||
86 | |||
87 | // Store an avatar with a different height from default in a notecard. | ||
88 | UUID userId = TestHelpers.ParseTail(0x1); | ||
89 | float newHeight = 1.9f; | ||
90 | |||
91 | ScenePresence sp = SceneHelpers.AddScenePresence(m_scene, userId); | ||
92 | sp.Appearance.AvatarHeight = newHeight; | ||
93 | SceneObjectGroup so = SceneHelpers.CreateSceneObject(1, userId); | ||
94 | SceneObjectPart part = so.RootPart; | ||
95 | m_scene.AddSceneObject(so); | ||
96 | |||
97 | OSSL_Api osslApi = new OSSL_Api(); | ||
98 | osslApi.Initialize(m_engine, part, part.LocalId, part.UUID); | ||
99 | |||
100 | string notecardName = "appearanceNc"; | ||
101 | osslApi.osOwnerSaveAppearance(notecardName); | ||
102 | |||
103 | // Try creating a bot using the appearance in the notecard. | ||
104 | string npcRaw = osslApi.osNpcCreate("Jane", "Doe", new LSL_Types.Vector3(128, 128, 128), notecardName); | ||
105 | Assert.That(npcRaw, Is.Not.Null); | ||
106 | |||
107 | UUID npcId = new UUID(npcRaw); | ||
108 | ScenePresence npc = m_scene.GetScenePresence(npcId); | ||
109 | Assert.That(npc, Is.Not.Null); | ||
110 | Assert.That(npc.Appearance.AvatarHeight, Is.EqualTo(newHeight)); | ||
111 | } | ||
112 | |||
113 | /// <summary> | ||
114 | /// Test creation of an NPC where the appearance data comes from an avatar already in the region. | ||
115 | /// </summary> | ||
116 | [Test] | ||
117 | public void TestOsNpcCreateFromAvatar() | ||
118 | { | ||
119 | TestHelpers.InMethod(); | ||
120 | // log4net.Config.XmlConfigurator.Configure(); | ||
121 | |||
122 | // Store an avatar with a different height from default in a notecard. | ||
123 | UUID userId = TestHelpers.ParseTail(0x1); | ||
124 | float newHeight = 1.9f; | ||
125 | |||
126 | ScenePresence sp = SceneHelpers.AddScenePresence(m_scene, userId); | ||
127 | sp.Appearance.AvatarHeight = newHeight; | ||
128 | SceneObjectGroup so = SceneHelpers.CreateSceneObject(1, userId); | ||
129 | SceneObjectPart part = so.RootPart; | ||
130 | m_scene.AddSceneObject(so); | ||
131 | |||
132 | OSSL_Api osslApi = new OSSL_Api(); | ||
133 | osslApi.Initialize(m_engine, part, part.LocalId, part.UUID); | ||
134 | |||
135 | string notecardName = "appearanceNc"; | ||
136 | osslApi.osOwnerSaveAppearance(notecardName); | ||
137 | |||
138 | // Try creating a bot using the existing avatar's appearance | ||
139 | string npcRaw = osslApi.osNpcCreate("Jane", "Doe", new LSL_Types.Vector3(128, 128, 128), sp.UUID.ToString()); | ||
140 | Assert.That(npcRaw, Is.Not.Null); | ||
141 | |||
142 | UUID npcId = new UUID(npcRaw); | ||
143 | ScenePresence npc = m_scene.GetScenePresence(npcId); | ||
144 | Assert.That(npc, Is.Not.Null); | ||
145 | Assert.That(npc.Appearance.AvatarHeight, Is.EqualTo(newHeight)); | ||
146 | } | ||
147 | |||
148 | [Test] | ||
149 | public void TestOsOwnerSaveAppearance() | ||
150 | { | ||
151 | TestHelpers.InMethod(); | ||
152 | // log4net.Config.XmlConfigurator.Configure(); | ||
153 | |||
154 | UUID userId = TestHelpers.ParseTail(0x1); | ||
155 | float newHeight = 1.9f; | ||
156 | |||
157 | ScenePresence sp = SceneHelpers.AddScenePresence(m_scene, userId); | ||
158 | sp.Appearance.AvatarHeight = newHeight; | ||
159 | SceneObjectGroup so = SceneHelpers.CreateSceneObject(1, userId); | ||
160 | SceneObjectPart part = so.RootPart; | ||
161 | m_scene.AddSceneObject(so); | ||
162 | |||
163 | OSSL_Api osslApi = new OSSL_Api(); | ||
164 | osslApi.Initialize(m_engine, part, part.LocalId, part.UUID); | ||
165 | |||
166 | string notecardName = "appearanceNc"; | ||
167 | |||
168 | osslApi.osOwnerSaveAppearance(notecardName); | ||
169 | |||
170 | IList<TaskInventoryItem> items = part.Inventory.GetInventoryItems(notecardName); | ||
171 | Assert.That(items.Count, Is.EqualTo(1)); | ||
172 | |||
173 | TaskInventoryItem ncItem = items[0]; | ||
174 | Assert.That(ncItem.Name, Is.EqualTo(notecardName)); | ||
175 | |||
176 | AssetBase ncAsset = m_scene.AssetService.Get(ncItem.AssetID.ToString()); | ||
177 | Assert.That(ncAsset, Is.Not.Null); | ||
178 | |||
179 | AssetNotecard anc = new AssetNotecard(UUID.Zero, ncAsset.Data); | ||
180 | anc.Decode(); | ||
181 | OSDMap appearanceOsd = (OSDMap)OSDParser.DeserializeLLSDXml(anc.BodyText); | ||
182 | AvatarAppearance savedAppearance = new AvatarAppearance(); | ||
183 | savedAppearance.Unpack(appearanceOsd); | ||
184 | |||
185 | Assert.That(savedAppearance.AvatarHeight, Is.EqualTo(sp.Appearance.AvatarHeight)); | ||
186 | } | ||
187 | |||
188 | [Test] | ||
189 | public void TestOsAgentSaveAppearance() | ||
190 | { | ||
191 | TestHelpers.InMethod(); | ||
192 | // log4net.Config.XmlConfigurator.Configure(); | ||
193 | |||
194 | UUID ownerId = TestHelpers.ParseTail(0x1); | ||
195 | UUID nonOwnerId = TestHelpers.ParseTail(0x2); | ||
196 | float newHeight = 1.9f; | ||
197 | |||
198 | ScenePresence sp = SceneHelpers.AddScenePresence(m_scene, nonOwnerId); | ||
199 | sp.Appearance.AvatarHeight = newHeight; | ||
200 | SceneObjectGroup so = SceneHelpers.CreateSceneObject(1, ownerId); | ||
201 | SceneObjectPart part = so.RootPart; | ||
202 | m_scene.AddSceneObject(so); | ||
203 | |||
204 | OSSL_Api osslApi = new OSSL_Api(); | ||
205 | osslApi.Initialize(m_engine, part, part.LocalId, part.UUID); | ||
206 | |||
207 | string notecardName = "appearanceNc"; | ||
208 | |||
209 | osslApi.osAgentSaveAppearance(new LSL_Types.LSLString(nonOwnerId.ToString()), notecardName); | ||
210 | |||
211 | IList<TaskInventoryItem> items = part.Inventory.GetInventoryItems(notecardName); | ||
212 | Assert.That(items.Count, Is.EqualTo(1)); | ||
213 | |||
214 | TaskInventoryItem ncItem = items[0]; | ||
215 | Assert.That(ncItem.Name, Is.EqualTo(notecardName)); | ||
216 | |||
217 | AssetBase ncAsset = m_scene.AssetService.Get(ncItem.AssetID.ToString()); | ||
218 | Assert.That(ncAsset, Is.Not.Null); | ||
219 | |||
220 | AssetNotecard anc = new AssetNotecard(UUID.Zero, ncAsset.Data); | ||
221 | anc.Decode(); | ||
222 | OSDMap appearanceOsd = (OSDMap)OSDParser.DeserializeLLSDXml(anc.BodyText); | ||
223 | AvatarAppearance savedAppearance = new AvatarAppearance(); | ||
224 | savedAppearance.Unpack(appearanceOsd); | ||
225 | |||
226 | Assert.That(savedAppearance.AvatarHeight, Is.EqualTo(sp.Appearance.AvatarHeight)); | ||
227 | } | ||
228 | } | ||
229 | } \ No newline at end of file | ||