Allow reading of notecards by asset ID.

Fixes Manthis #3420
0.6.5-rc1
Melanie Thielker 2009-04-18 19:08:35 +00:00
parent 2578db3dfa
commit d285ccb5cf
1 changed files with 111 additions and 55 deletions

View File

@ -9167,41 +9167,71 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
} }
public LSL_String llGetNumberOfNotecardLines(string name) public LSL_String llGetNumberOfNotecardLines(string name)
{ {
m_host.AddScriptLPS(1); m_host.AddScriptLPS(1);
TaskInventoryDictionary itemsDictionary = (TaskInventoryDictionary)m_host.TaskInventory.Clone(); TaskInventoryDictionary itemsDictionary = (TaskInventoryDictionary)m_host.TaskInventory.Clone();
foreach (TaskInventoryItem item in itemsDictionary.Values) UUID assetID = UUID.Zero;
if (!UUID.TryParse(name, out assetID))
{ {
if (item.Type == 7 && item.Name == name) foreach (TaskInventoryItem item in itemsDictionary.Values)
{ {
UUID tid = AsyncCommands. if (item.Type == 7 && item.Name == name)
DataserverPlugin.RegisterRequest(m_localID,
m_itemID, item.AssetID.ToString());
if (NotecardCache.IsCached(item.AssetID))
{ {
AsyncCommands. assetID = item.AssetID;
DataserverPlugin.DataserverReply(item.AssetID.ToString(), break;
NotecardCache.GetLines(item.AssetID).ToString());
// ScriptSleep(100);
return tid.ToString();
} }
WithNotecard(item.AssetID, delegate (UUID id, AssetBase a)
{
System.Text.ASCIIEncoding enc =
new System.Text.ASCIIEncoding();
string data = enc.GetString(a.Data);
//m_log.Debug(data);
NotecardCache.Cache(id, data);
AsyncCommands.
DataserverPlugin.DataserverReply(id.ToString(),
NotecardCache.GetLines(id).ToString());
});
// ScriptSleep(100);
return tid.ToString();
} }
} }
if (assetID == UUID.Zero)
{
// => complain loudly, as specified by the LSL docs
ShoutError("Notecard '" + name + "' could not be found.");
}
UUID tid = UUID.Zero;
if (NotecardCache.IsCached(assetID))
{
tid = AsyncCommands.
DataserverPlugin.RegisterRequest(m_localID,
m_itemID, assetID.ToString());
AsyncCommands.
DataserverPlugin.DataserverReply(assetID.ToString(),
NotecardCache.GetLines(assetID).ToString());
// ScriptSleep(100);
return tid.ToString();
}
WithNotecard(assetID, delegate (UUID id, AssetBase a)
{
if (a.Type != 7)
return;
tid = AsyncCommands.
DataserverPlugin.RegisterRequest(m_localID,
m_itemID, assetID.ToString());
System.Text.ASCIIEncoding enc =
new System.Text.ASCIIEncoding();
string data = enc.GetString(a.Data);
//m_log.Debug(data);
NotecardCache.Cache(id, data);
AsyncCommands.
DataserverPlugin.DataserverReply(id.ToString(),
NotecardCache.GetLines(id).ToString());
});
if (tid != UUID.Zero)
{
// ScriptSleep(100);
return tid.ToString();
}
// if we got to here, we didn't find the notecard the script was asking for // if we got to here, we didn't find the notecard the script was asking for
// => complain loudly, as specified by the LSL docs // => complain loudly, as specified by the LSL docs
ShoutError("Notecard '" + name + "' could not be found."); ShoutError("Notecard '" + name + "' could not be found.");
@ -9216,40 +9246,66 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
TaskInventoryDictionary itemsDictionary = (TaskInventoryDictionary)m_host.TaskInventory.Clone(); TaskInventoryDictionary itemsDictionary = (TaskInventoryDictionary)m_host.TaskInventory.Clone();
foreach (TaskInventoryItem item in itemsDictionary.Values) UUID assetID = UUID.Zero;
{
if (item.Type == 7 && item.Name == name)
{
UUID tid = AsyncCommands.
DataserverPlugin.RegisterRequest(m_localID,
m_itemID, item.AssetID.ToString());
if (NotecardCache.IsCached(item.AssetID))
{
AsyncCommands.
DataserverPlugin.DataserverReply(item.AssetID.ToString(),
NotecardCache.GetLine(item.AssetID, line, m_notecardLineReadCharsMax));
// ScriptSleep(100);
return tid.ToString();
}
WithNotecard(item.AssetID, delegate (UUID id, AssetBase a)
{
System.Text.ASCIIEncoding enc =
new System.Text.ASCIIEncoding();
string data = enc.GetString(a.Data);
//m_log.Debug(data);
NotecardCache.Cache(id, data);
AsyncCommands.
DataserverPlugin.DataserverReply(id.ToString(),
NotecardCache.GetLine(id, line, m_notecardLineReadCharsMax));
});
// ScriptSleep(100); if (!UUID.TryParse(name, out assetID))
return tid.ToString(); {
foreach (TaskInventoryItem item in itemsDictionary.Values)
{
if (item.Type == 7 && item.Name == name)
{
assetID = item.AssetID;
break;
}
} }
} }
if (assetID == UUID.Zero)
{
// => complain loudly, as specified by the LSL docs
ShoutError("Notecard '" + name + "' could not be found.");
}
UUID tid = UUID.Zero;
if (NotecardCache.IsCached(assetID))
{
tid = AsyncCommands.
DataserverPlugin.RegisterRequest(m_localID,
m_itemID, assetID.ToString());
AsyncCommands.
DataserverPlugin.DataserverReply(assetID.ToString(),
NotecardCache.GetLine(assetID, line, m_notecardLineReadCharsMax));
// ScriptSleep(100);
return tid.ToString();
}
WithNotecard(assetID, delegate (UUID id, AssetBase a)
{
if (a.Type != 7)
return;
tid = AsyncCommands.
DataserverPlugin.RegisterRequest(m_localID,
m_itemID, assetID.ToString());
System.Text.ASCIIEncoding enc =
new System.Text.ASCIIEncoding();
string data = enc.GetString(a.Data);
//m_log.Debug(data);
NotecardCache.Cache(id, data);
AsyncCommands.
DataserverPlugin.DataserverReply(id.ToString(),
NotecardCache.GetLine(id, line, m_notecardLineReadCharsMax));
});
if (tid != UUID.Zero)
{
// ScriptSleep(100);
return tid.ToString();
}
// if we got to here, we didn't find the notecard the script was asking for // if we got to here, we didn't find the notecard the script was asking for
// => complain loudly, as specified by the LSL docs // => complain loudly, as specified by the LSL docs
ShoutError("Notecard '" + name + "' could not be found."); ShoutError("Notecard '" + name + "' could not be found.");