diff options
author | Melanie Thielker | 2009-04-27 12:05:49 +0000 |
---|---|---|
committer | Melanie Thielker | 2009-04-27 12:05:49 +0000 |
commit | d98a9160065355d23b090d9a182b5c5cfdf913b7 (patch) | |
tree | 1b9e2af437c22a44e67468e18335581c64d2cc3e /OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs | |
parent | From: Alan M Webb <alan_webb@us.ibm.com> (diff) | |
download | opensim-SC-d98a9160065355d23b090d9a182b5c5cfdf913b7.zip opensim-SC-d98a9160065355d23b090d9a182b5c5cfdf913b7.tar.gz opensim-SC-d98a9160065355d23b090d9a182b5c5cfdf913b7.tar.bz2 opensim-SC-d98a9160065355d23b090d9a182b5c5cfdf913b7.tar.xz |
Thank you, Orion_Shamroy, for a patch that adds osGetNotecardLine and
osGetNumberOfNotecardLines
Fixes Mantis #2942
Diffstat (limited to 'OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs')
-rw-r--r-- | OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs index 275969a..446a972 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs | |||
@@ -183,6 +183,22 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
183 | throw new Exception("OSSL Runtime Error: " + msg); | 183 | throw new Exception("OSSL Runtime Error: " + msg); |
184 | } | 184 | } |
185 | 185 | ||
186 | // | ||
187 | //Dumps an error message on the debug console. | ||
188 | // | ||
189 | |||
190 | internal void OSSLShoutError(string message) | ||
191 | { | ||
192 | if (message.Length > 1023) | ||
193 | message = message.Substring(0, 1023); | ||
194 | |||
195 | World.SimChat(Utils.StringToBytes(message), | ||
196 | ChatTypeEnum.Shout, ScriptBaseClass.DEBUG_CHANNEL, m_host.ParentGroup.RootPart.AbsolutePosition, m_host.Name, m_host.UUID, true); | ||
197 | |||
198 | IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>(); | ||
199 | wComm.DeliverMessage(ChatTypeEnum.Shout, ScriptBaseClass.DEBUG_CHANNEL, m_host.Name, m_host.UUID, message); | ||
200 | } | ||
201 | |||
186 | public void CheckThreatLevel(ThreatLevel level, string function) | 202 | public void CheckThreatLevel(ThreatLevel level, string function) |
187 | { | 203 | { |
188 | if (!m_OSFunctionsEnabled) | 204 | if (!m_OSFunctionsEnabled) |
@@ -1353,6 +1369,69 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
1353 | m_host.Inventory.AddInventoryItem(taskItem, false); | 1369 | m_host.Inventory.AddInventoryItem(taskItem, false); |
1354 | } | 1370 | } |
1355 | 1371 | ||
1372 | /*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 | |||
1375 | 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. | ||
1377 | */ | ||
1378 | public string osGetNotecardLine(string name, int line) | ||
1379 | { | ||
1380 | CheckThreatLevel(ThreatLevel.VeryHigh, "osGetNotecardLine"); | ||
1381 | m_host.AddScriptLPS(1); | ||
1382 | |||
1383 | foreach (TaskInventoryItem item in m_host.TaskInventory.Values) | ||
1384 | { | ||
1385 | if (item.Type == 7 && item.Name == name) | ||
1386 | { | ||
1387 | if (NotecardCache.IsCached(item.AssetID)== false) | ||
1388 | { AssetBase a = World.CommsManager.AssetCache.GetAsset(item.AssetID, false); | ||
1389 | System.Text.ASCIIEncoding enc = new System.Text.ASCIIEncoding(); | ||
1390 | string data = enc.GetString(a.Data); | ||
1391 | NotecardCache.Cache(item.AssetID, data); | ||
1392 | }; | ||
1393 | |||
1394 | return NotecardCache.GetLine(item.AssetID, line, 255); | ||
1395 | } | ||
1396 | } | ||
1397 | |||
1398 | //If all else fails just return error. | ||
1399 | OSSLShoutError("Notecard '" + name + "' could not be found."); | ||
1400 | return "ERROR!"; | ||
1401 | } | ||
1402 | |||
1403 | /*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. | ||
1405 | |||
1406 | 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. | ||
1408 | */ | ||
1409 | public int osGetNumberOfNotecardLines(string name) | ||
1410 | { | ||
1411 | CheckThreatLevel(ThreatLevel.VeryHigh, "osGetNumberOfNotecardLines"); | ||
1412 | m_host.AddScriptLPS(1); | ||
1413 | |||
1414 | foreach (TaskInventoryItem item in m_host.TaskInventory.Values) | ||
1415 | { | ||
1416 | if (item.Type == 7 && item.Name == name) | ||
1417 | { | ||
1418 | if (NotecardCache.IsCached(item.AssetID) == false) | ||
1419 | { | ||
1420 | AssetBase a = World.CommsManager.AssetCache.GetAsset(item.AssetID, false); | ||
1421 | System.Text.ASCIIEncoding enc = new System.Text.ASCIIEncoding(); | ||
1422 | string data = enc.GetString(a.Data); | ||
1423 | NotecardCache.Cache(item.AssetID, data); | ||
1424 | }; | ||
1425 | |||
1426 | return NotecardCache.GetLines(item.AssetID); | ||
1427 | } | ||
1428 | } | ||
1429 | |||
1430 | //If all else fails just return error. | ||
1431 | OSSLShoutError("Notecard '" + name + "' could not be found."); | ||
1432 | return -1; | ||
1433 | } | ||
1434 | |||
1356 | public string osAvatarName2Key(string firstname, string lastname) | 1435 | public string osAvatarName2Key(string firstname, string lastname) |
1357 | { | 1436 | { |
1358 | CheckThreatLevel(ThreatLevel.Low, "osAvatarName2Key"); | 1437 | CheckThreatLevel(ThreatLevel.Low, "osAvatarName2Key"); |