Thank you, Orion_Shamroy, for a patch that adds osGetNotecardLine and

osGetNumberOfNotecardLines
Fixes Mantis #2942
0.6.5-rc1
Melanie Thielker 2009-04-27 12:05:49 +00:00
parent 515e62dc2f
commit d98a916006
3 changed files with 93 additions and 0 deletions

View File

@ -183,6 +183,22 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
throw new Exception("OSSL Runtime Error: " + msg);
}
//
//Dumps an error message on the debug console.
//
internal void OSSLShoutError(string message)
{
if (message.Length > 1023)
message = message.Substring(0, 1023);
World.SimChat(Utils.StringToBytes(message),
ChatTypeEnum.Shout, ScriptBaseClass.DEBUG_CHANNEL, m_host.ParentGroup.RootPart.AbsolutePosition, m_host.Name, m_host.UUID, true);
IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>();
wComm.DeliverMessage(ChatTypeEnum.Shout, ScriptBaseClass.DEBUG_CHANNEL, m_host.Name, m_host.UUID, message);
}
public void CheckThreatLevel(ThreatLevel level, string function)
{
if (!m_OSFunctionsEnabled)
@ -1353,6 +1369,69 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
m_host.Inventory.AddInventoryItem(taskItem, false);
}
/*Instead of using the LSL Dataserver event to pull notecard data,
this will simply read the requested line and return its data as a string.
Warning - due to the synchronous method this function uses to fetch assets, its use
may be dangerous and unreliable while running in grid mode.
*/
public string osGetNotecardLine(string name, int line)
{
CheckThreatLevel(ThreatLevel.VeryHigh, "osGetNotecardLine");
m_host.AddScriptLPS(1);
foreach (TaskInventoryItem item in m_host.TaskInventory.Values)
{
if (item.Type == 7 && item.Name == name)
{
if (NotecardCache.IsCached(item.AssetID)== false)
{ AssetBase a = World.CommsManager.AssetCache.GetAsset(item.AssetID, false);
System.Text.ASCIIEncoding enc = new System.Text.ASCIIEncoding();
string data = enc.GetString(a.Data);
NotecardCache.Cache(item.AssetID, data);
};
return NotecardCache.GetLine(item.AssetID, line, 255);
}
}
//If all else fails just return error.
OSSLShoutError("Notecard '" + name + "' could not be found.");
return "ERROR!";
}
/*Instead of using the LSL Dataserver event to pull notecard data,
this will simply read the number of note card lines and return this data as an integer.
Warning - due to the synchronous method this function uses to fetch assets, its use
may be dangerous and unreliable while running in grid mode.
*/
public int osGetNumberOfNotecardLines(string name)
{
CheckThreatLevel(ThreatLevel.VeryHigh, "osGetNumberOfNotecardLines");
m_host.AddScriptLPS(1);
foreach (TaskInventoryItem item in m_host.TaskInventory.Values)
{
if (item.Type == 7 && item.Name == name)
{
if (NotecardCache.IsCached(item.AssetID) == false)
{
AssetBase a = World.CommsManager.AssetCache.GetAsset(item.AssetID, false);
System.Text.ASCIIEncoding enc = new System.Text.ASCIIEncoding();
string data = enc.GetString(a.Data);
NotecardCache.Cache(item.AssetID, data);
};
return NotecardCache.GetLines(item.AssetID);
}
}
//If all else fails just return error.
OSSLShoutError("Notecard '" + name + "' could not be found.");
return -1;
}
public string osAvatarName2Key(string firstname, string lastname)
{
CheckThreatLevel(ThreatLevel.Low, "osAvatarName2Key");

View File

@ -122,6 +122,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Interfaces
void osMessageObject(key objectUUID,string message);
void osMakeNotecard(string notecardName, LSL_Types.list contents);
string osGetNotecardLine(string name, int line);
int osGetNumberOfNotecardLines(string name);
string osAvatarName2Key(string firstname, string lastname);
string osKey2Name(string id);

View File

@ -307,6 +307,16 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
m_OSSL_Functions.osMakeNotecard(notecardName, contents);
}
public string osGetNotecardLine(string name, int line)
{
return m_OSSL_Functions.osGetNotecardLine(name, line);
}
public int osGetNumberOfNotecardLines(string name)
{
return m_OSSL_Functions.osGetNumberOfNotecardLines(name);
}
public string osAvatarName2Key(string firstname, string lastname)
{
return m_OSSL_Functions.osAvatarName2Key(firstname, lastname);