Thank you, Orion_Shamroy, for a patch to expand notecard reading

capabilities in OSSL.
Fixes Mantis #3543
0.6.5-rc1
Melanie Thielker 2009-04-27 14:16:01 +00:00
parent c91a79c3d2
commit 36a02441c5
3 changed files with 140 additions and 35 deletions

View File

@ -1369,6 +1369,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
m_host.Inventory.AddInventoryItem(taskItem, false); m_host.Inventory.AddInventoryItem(taskItem, false);
} }
/*Instead of using the LSL Dataserver event to pull notecard data, /*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. this will simply read the requested line and return its data as a string.
@ -1380,58 +1381,156 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
CheckThreatLevel(ThreatLevel.VeryHigh, "osGetNotecardLine"); CheckThreatLevel(ThreatLevel.VeryHigh, "osGetNotecardLine");
m_host.AddScriptLPS(1); m_host.AddScriptLPS(1);
UUID assetID = UUID.Zero;
if (!UUID.TryParse(name, out assetID))
{
foreach (TaskInventoryItem item in m_host.TaskInventory.Values) foreach (TaskInventoryItem item in m_host.TaskInventory.Values)
{ {
if (item.Type == 7 && item.Name == name) if (item.Type == 7 && item.Name == name)
{ {
if (NotecardCache.IsCached(item.AssetID)== false) assetID = item.AssetID;
{ 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. if (assetID == UUID.Zero)
{
OSSLShoutError("Notecard '" + name + "' could not be found."); OSSLShoutError("Notecard '" + name + "' could not be found.");
return "ERROR!"; return "ERROR!";
} }
if (!NotecardCache.IsCached(assetID))
{
AssetBase a = World.CommsManager.AssetCache.GetAsset(assetID, false);
if (a != null)
{
System.Text.ASCIIEncoding enc = new System.Text.ASCIIEncoding();
string data = enc.GetString(a.Data);
NotecardCache.Cache(assetID, data);
}
else
{
OSSLShoutError("Notecard '" + name + "' could not be found.");
return "ERROR!";
}
};
return NotecardCache.GetLine(assetID, line, 255);
}
/*Instead of using the LSL Dataserver event to pull notecard data line by line,
this will simply read the entire notecard 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 osGetNotecard(string name)
{
CheckThreatLevel(ThreatLevel.VeryHigh, "osGetNotecard");
m_host.AddScriptLPS(1);
UUID assetID = UUID.Zero;
string NotecardData = "";
if (!UUID.TryParse(name, out assetID))
{
foreach (TaskInventoryItem item in m_host.TaskInventory.Values)
{
if (item.Type == 7 && item.Name == name)
{
assetID = item.AssetID;
}
}
}
if (assetID == UUID.Zero)
{
OSSLShoutError("Notecard '" + name + "' could not be found.");
return "ERROR!";
}
if (!NotecardCache.IsCached(assetID))
{
AssetBase a = World.CommsManager.AssetCache.GetAsset(assetID, false);
if (a != null)
{
System.Text.ASCIIEncoding enc = new System.Text.ASCIIEncoding();
string data = enc.GetString(a.Data);
NotecardCache.Cache(assetID, data);
}
else
{
OSSLShoutError("Notecard '" + name + "' could not be found.");
return "ERROR!";
}
};
for (int count = 0; count < NotecardCache.GetLines(assetID); count++)
{
NotecardData += NotecardCache.GetLine(assetID, count, 255) + "\n";
}
return NotecardData;
}
/*Instead of using the LSL Dataserver event to pull notecard data, /*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. 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 Warning - due to the synchronous method this function uses to fetch assets, its use
may be dangerous and unreliable while running in grid mode. may be dangerous and unreliable while running in grid mode.
*/ */
public int osGetNumberOfNotecardLines(string name) public int osGetNumberOfNotecardLines(string name)
{ {
CheckThreatLevel(ThreatLevel.VeryHigh, "osGetNumberOfNotecardLines"); CheckThreatLevel(ThreatLevel.VeryHigh, "osGetNumberOfNotecardLines");
m_host.AddScriptLPS(1); m_host.AddScriptLPS(1);
UUID assetID = UUID.Zero;
if (!UUID.TryParse(name, out assetID))
{
foreach (TaskInventoryItem item in m_host.TaskInventory.Values) foreach (TaskInventoryItem item in m_host.TaskInventory.Values)
{ {
if (item.Type == 7 && item.Name == name) if (item.Type == 7 && item.Name == name)
{ {
if (NotecardCache.IsCached(item.AssetID) == false) assetID = item.AssetID;
}
}
}
if (assetID == UUID.Zero)
{ {
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."); OSSLShoutError("Notecard '" + name + "' could not be found.");
return -1; return -1;
} }
if (!NotecardCache.IsCached(assetID))
{
AssetBase a = World.CommsManager.AssetCache.GetAsset(assetID, false);
if (a != null)
{
System.Text.ASCIIEncoding enc = new System.Text.ASCIIEncoding();
string data = enc.GetString(a.Data);
NotecardCache.Cache(assetID, data);
}
else
{
OSSLShoutError("Notecard '" + name + "' could not be found.");
return -1;
}
};
return NotecardCache.GetLines(assetID);
}
public string osAvatarName2Key(string firstname, string lastname) public string osAvatarName2Key(string firstname, string lastname)
{ {
CheckThreatLevel(ThreatLevel.Low, "osAvatarName2Key"); CheckThreatLevel(ThreatLevel.Low, "osAvatarName2Key");

View File

@ -124,6 +124,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Interfaces
void osMakeNotecard(string notecardName, LSL_Types.list contents); void osMakeNotecard(string notecardName, LSL_Types.list contents);
string osGetNotecardLine(string name, int line); string osGetNotecardLine(string name, int line);
string osGetNotecard(string name);
int osGetNumberOfNotecardLines(string name); int osGetNumberOfNotecardLines(string name);
string osAvatarName2Key(string firstname, string lastname); string osAvatarName2Key(string firstname, string lastname);

View File

@ -312,6 +312,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
return m_OSSL_Functions.osGetNotecardLine(name, line); return m_OSSL_Functions.osGetNotecardLine(name, line);
} }
public string osGetNotecard(string name)
{
return m_OSSL_Functions.osGetNotecard(name);
}
public int osGetNumberOfNotecardLines(string name) public int osGetNumberOfNotecardLines(string name)
{ {
return m_OSSL_Functions.osGetNumberOfNotecardLines(name); return m_OSSL_Functions.osGetNumberOfNotecardLines(name);