diff options
author | Melanie Thielker | 2009-04-27 14:16:01 +0000 |
---|---|---|
committer | Melanie Thielker | 2009-04-27 14:16:01 +0000 |
commit | 36a02441c55ecb6028bc008c3502d7bf3cb4ed63 (patch) | |
tree | b0795d06e8a4517ffaf0d4f97fbfebd667526d39 /OpenSim | |
parent | From: Alan Webb <alan_webb@us.ibm.com> (diff) | |
download | opensim-SC_OLD-36a02441c55ecb6028bc008c3502d7bf3cb4ed63.zip opensim-SC_OLD-36a02441c55ecb6028bc008c3502d7bf3cb4ed63.tar.gz opensim-SC_OLD-36a02441c55ecb6028bc008c3502d7bf3cb4ed63.tar.bz2 opensim-SC_OLD-36a02441c55ecb6028bc008c3502d7bf3cb4ed63.tar.xz |
Thank you, Orion_Shamroy, for a patch to expand notecard reading
capabilities in OSSL.
Fixes Mantis #3543
Diffstat (limited to 'OpenSim')
3 files changed, 136 insertions, 31 deletions
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs index 446a972..1cd25e7 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs | |||
@@ -1369,68 +1369,167 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
1369 | m_host.Inventory.AddInventoryItem(taskItem, false); | 1369 | m_host.Inventory.AddInventoryItem(taskItem, false); |
1370 | } | 1370 | } |
1371 | 1371 | ||
1372 | |||
1372 | /*Instead of using the LSL Dataserver event to pull notecard data, | 1373 | /*Instead of using the LSL Dataserver event to pull notecard data, |
1373 | this will simply read the requested line and return its data as a string. | 1374 | this will simply read the requested line and return its data as a string. |
1375 | |||
1376 | Warning - due to the synchronous method this function uses to fetch assets, its use | ||
1377 | may be dangerous and unreliable while running in grid mode. | ||
1378 | */ | ||
1379 | public string osGetNotecardLine(string name, int line) | ||
1380 | { | ||
1381 | CheckThreatLevel(ThreatLevel.VeryHigh, "osGetNotecardLine"); | ||
1382 | m_host.AddScriptLPS(1); | ||
1383 | |||
1384 | UUID assetID = UUID.Zero; | ||
1385 | |||
1386 | if (!UUID.TryParse(name, out assetID)) | ||
1387 | { | ||
1388 | foreach (TaskInventoryItem item in m_host.TaskInventory.Values) | ||
1389 | { | ||
1390 | if (item.Type == 7 && item.Name == name) | ||
1391 | { | ||
1392 | assetID = item.AssetID; | ||
1393 | } | ||
1394 | } | ||
1395 | } | ||
1396 | |||
1397 | if (assetID == UUID.Zero) | ||
1398 | { | ||
1399 | OSSLShoutError("Notecard '" + name + "' could not be found."); | ||
1400 | return "ERROR!"; | ||
1401 | } | ||
1402 | |||
1403 | if (!NotecardCache.IsCached(assetID)) | ||
1404 | { | ||
1405 | AssetBase a = World.CommsManager.AssetCache.GetAsset(assetID, false); | ||
1406 | if (a != null) | ||
1407 | { | ||
1408 | System.Text.ASCIIEncoding enc = new System.Text.ASCIIEncoding(); | ||
1409 | string data = enc.GetString(a.Data); | ||
1410 | NotecardCache.Cache(assetID, data); | ||
1411 | } | ||
1412 | else | ||
1413 | { | ||
1414 | OSSLShoutError("Notecard '" + name + "' could not be found."); | ||
1415 | return "ERROR!"; | ||
1416 | } | ||
1417 | }; | ||
1418 | |||
1419 | return NotecardCache.GetLine(assetID, line, 255); | ||
1420 | |||
1421 | |||
1422 | } | ||
1423 | |||
1424 | /*Instead of using the LSL Dataserver event to pull notecard data line by line, | ||
1425 | this will simply read the entire notecard and return its data as a string. | ||
1374 | 1426 | ||
1375 | Warning - due to the synchronous method this function uses to fetch assets, its use | 1427 | Warning - due to the synchronous method this function uses to fetch assets, its use |
1376 | may be dangerous and unreliable while running in grid mode. | 1428 | may be dangerous and unreliable while running in grid mode. |
1377 | */ | 1429 | */ |
1378 | public string osGetNotecardLine(string name, int line) | 1430 | |
1431 | public string osGetNotecard(string name) | ||
1379 | { | 1432 | { |
1380 | CheckThreatLevel(ThreatLevel.VeryHigh, "osGetNotecardLine"); | 1433 | CheckThreatLevel(ThreatLevel.VeryHigh, "osGetNotecard"); |
1381 | m_host.AddScriptLPS(1); | 1434 | m_host.AddScriptLPS(1); |
1382 | 1435 | ||
1383 | foreach (TaskInventoryItem item in m_host.TaskInventory.Values) | 1436 | UUID assetID = UUID.Zero; |
1437 | string NotecardData = ""; | ||
1438 | |||
1439 | if (!UUID.TryParse(name, out assetID)) | ||
1440 | { | ||
1441 | foreach (TaskInventoryItem item in m_host.TaskInventory.Values) | ||
1442 | { | ||
1443 | if (item.Type == 7 && item.Name == name) | ||
1444 | { | ||
1445 | assetID = item.AssetID; | ||
1446 | } | ||
1447 | } | ||
1448 | } | ||
1449 | |||
1450 | if (assetID == UUID.Zero) | ||
1451 | { | ||
1452 | OSSLShoutError("Notecard '" + name + "' could not be found."); | ||
1453 | return "ERROR!"; | ||
1454 | } | ||
1455 | |||
1456 | if (!NotecardCache.IsCached(assetID)) | ||
1384 | { | 1457 | { |
1385 | if (item.Type == 7 && item.Name == name) | 1458 | AssetBase a = World.CommsManager.AssetCache.GetAsset(assetID, false); |
1459 | if (a != null) | ||
1386 | { | 1460 | { |
1387 | if (NotecardCache.IsCached(item.AssetID)== false) | 1461 | System.Text.ASCIIEncoding enc = new System.Text.ASCIIEncoding(); |
1388 | { AssetBase a = World.CommsManager.AssetCache.GetAsset(item.AssetID, false); | 1462 | string data = enc.GetString(a.Data); |
1389 | System.Text.ASCIIEncoding enc = new System.Text.ASCIIEncoding(); | 1463 | NotecardCache.Cache(assetID, data); |
1390 | string data = enc.GetString(a.Data); | ||
1391 | NotecardCache.Cache(item.AssetID, data); | ||
1392 | }; | ||
1393 | |||
1394 | return NotecardCache.GetLine(item.AssetID, line, 255); | ||
1395 | } | 1464 | } |
1465 | else | ||
1466 | { | ||
1467 | OSSLShoutError("Notecard '" + name + "' could not be found."); | ||
1468 | return "ERROR!"; | ||
1469 | } | ||
1470 | }; | ||
1471 | |||
1472 | for (int count = 0; count < NotecardCache.GetLines(assetID); count++) | ||
1473 | { | ||
1474 | NotecardData += NotecardCache.GetLine(assetID, count, 255) + "\n"; | ||
1396 | } | 1475 | } |
1397 | 1476 | ||
1398 | //If all else fails just return error. | 1477 | return NotecardData; |
1399 | OSSLShoutError("Notecard '" + name + "' could not be found."); | 1478 | |
1400 | return "ERROR!"; | 1479 | |
1401 | } | 1480 | } |
1402 | 1481 | ||
1403 | /*Instead of using the LSL Dataserver event to pull notecard data, | 1482 | /*Instead of using the LSL Dataserver event to pull notecard data, |
1404 | this will simply read the number of note card lines and return this data as an integer. | 1483 | this will simply read the number of note card lines and return this data as an integer. |
1405 | 1484 | ||
1406 | Warning - due to the synchronous method this function uses to fetch assets, its use | 1485 | Warning - due to the synchronous method this function uses to fetch assets, its use |
1407 | may be dangerous and unreliable while running in grid mode. | 1486 | may be dangerous and unreliable while running in grid mode. |
1408 | */ | 1487 | */ |
1488 | |||
1409 | public int osGetNumberOfNotecardLines(string name) | 1489 | public int osGetNumberOfNotecardLines(string name) |
1410 | { | 1490 | { |
1411 | CheckThreatLevel(ThreatLevel.VeryHigh, "osGetNumberOfNotecardLines"); | 1491 | CheckThreatLevel(ThreatLevel.VeryHigh, "osGetNumberOfNotecardLines"); |
1412 | m_host.AddScriptLPS(1); | 1492 | m_host.AddScriptLPS(1); |
1413 | 1493 | ||
1414 | foreach (TaskInventoryItem item in m_host.TaskInventory.Values) | 1494 | UUID assetID = UUID.Zero; |
1495 | |||
1496 | if (!UUID.TryParse(name, out assetID)) | ||
1415 | { | 1497 | { |
1416 | if (item.Type == 7 && item.Name == name) | 1498 | foreach (TaskInventoryItem item in m_host.TaskInventory.Values) |
1417 | { | 1499 | { |
1418 | if (NotecardCache.IsCached(item.AssetID) == false) | 1500 | if (item.Type == 7 && item.Name == name) |
1419 | { | 1501 | { |
1420 | AssetBase a = World.CommsManager.AssetCache.GetAsset(item.AssetID, false); | 1502 | assetID = item.AssetID; |
1421 | System.Text.ASCIIEncoding enc = new System.Text.ASCIIEncoding(); | 1503 | } |
1422 | string data = enc.GetString(a.Data); | ||
1423 | NotecardCache.Cache(item.AssetID, data); | ||
1424 | }; | ||
1425 | |||
1426 | return NotecardCache.GetLines(item.AssetID); | ||
1427 | } | 1504 | } |
1428 | } | 1505 | } |
1429 | 1506 | ||
1430 | //If all else fails just return error. | 1507 | if (assetID == UUID.Zero) |
1431 | OSSLShoutError("Notecard '" + name + "' could not be found."); | 1508 | { |
1432 | return -1; | 1509 | OSSLShoutError("Notecard '" + name + "' could not be found."); |
1433 | } | 1510 | return -1; |
1511 | } | ||
1512 | |||
1513 | if (!NotecardCache.IsCached(assetID)) | ||
1514 | { | ||
1515 | AssetBase a = World.CommsManager.AssetCache.GetAsset(assetID, false); | ||
1516 | if (a != null) | ||
1517 | { | ||
1518 | System.Text.ASCIIEncoding enc = new System.Text.ASCIIEncoding(); | ||
1519 | string data = enc.GetString(a.Data); | ||
1520 | NotecardCache.Cache(assetID, data); | ||
1521 | } | ||
1522 | else | ||
1523 | { | ||
1524 | OSSLShoutError("Notecard '" + name + "' could not be found."); | ||
1525 | return -1; | ||
1526 | } | ||
1527 | }; | ||
1528 | |||
1529 | return NotecardCache.GetLines(assetID); | ||
1530 | |||
1531 | |||
1532 | } | ||
1434 | 1533 | ||
1435 | public string osAvatarName2Key(string firstname, string lastname) | 1534 | public string osAvatarName2Key(string firstname, string lastname) |
1436 | { | 1535 | { |
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs index 526c7d0..7c0f086 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs | |||
@@ -124,6 +124,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Interfaces | |||
124 | void osMakeNotecard(string notecardName, LSL_Types.list contents); | 124 | void osMakeNotecard(string notecardName, LSL_Types.list contents); |
125 | 125 | ||
126 | string osGetNotecardLine(string name, int line); | 126 | string osGetNotecardLine(string name, int line); |
127 | string osGetNotecard(string name); | ||
127 | int osGetNumberOfNotecardLines(string name); | 128 | int osGetNumberOfNotecardLines(string name); |
128 | 129 | ||
129 | string osAvatarName2Key(string firstname, string lastname); | 130 | string osAvatarName2Key(string firstname, string lastname); |
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs index 0f25983..a66ed30 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs | |||
@@ -312,6 +312,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase | |||
312 | return m_OSSL_Functions.osGetNotecardLine(name, line); | 312 | return m_OSSL_Functions.osGetNotecardLine(name, line); |
313 | } | 313 | } |
314 | 314 | ||
315 | public string osGetNotecard(string name) | ||
316 | { | ||
317 | return m_OSSL_Functions.osGetNotecard(name); | ||
318 | } | ||
319 | |||
315 | public int osGetNumberOfNotecardLines(string name) | 320 | public int osGetNumberOfNotecardLines(string name) |
316 | { | 321 | { |
317 | return m_OSSL_Functions.osGetNumberOfNotecardLines(name); | 322 | return m_OSSL_Functions.osGetNumberOfNotecardLines(name); |