several changes to lludp FetchInventory

master
UbitUmarov 2020-03-01 18:56:07 +00:00
parent 71b5ca95e6
commit dc225e348d
7 changed files with 137 additions and 97 deletions

View File

@ -223,6 +223,8 @@ namespace OpenSim.Framework
UUID RayTargetID, UUID RayTargetID,
byte RayEndIsIntersection); byte RayEndIsIntersection);
public delegate void AgentDataUpdate(IClientAPI remoteClient, UUID itemID, UUID ownerID);
public delegate void RequestGodlikePowers( public delegate void RequestGodlikePowers(
UUID AgentID, UUID SessionID, UUID token, bool GodLike); UUID AgentID, UUID SessionID, UUID token, bool GodLike);
@ -252,7 +254,7 @@ namespace OpenSim.Framework
public delegate void PurgeInventoryDescendents( public delegate void PurgeInventoryDescendents(
IClientAPI remoteClient, UUID folderID); IClientAPI remoteClient, UUID folderID);
public delegate void FetchInventory(IClientAPI remoteClient, UUID itemID, UUID ownerID); public delegate void FetchInventory(IClientAPI remoteClient, UUID[] items, UUID[] owner);
public delegate void RequestTaskInventory(IClientAPI remoteClient, uint localID); public delegate void RequestTaskInventory(IClientAPI remoteClient, uint localID);
@ -846,7 +848,7 @@ namespace OpenSim.Framework
event Action<IClientAPI> OnRequestAvatarsData; event Action<IClientAPI> OnRequestAvatarsData;
event AddNewPrim OnAddPrim; event AddNewPrim OnAddPrim;
event FetchInventory OnAgentDataUpdateRequest; event AgentDataUpdate OnAgentDataUpdateRequest;
event TeleportLocationRequest OnSetStartLocationRequest; event TeleportLocationRequest OnSetStartLocationRequest;
event RequestGodlikePowers OnRequestGodlikePowers; event RequestGodlikePowers OnRequestGodlikePowers;
@ -1208,7 +1210,7 @@ namespace OpenSim.Framework
List<InventoryFolderBase> folders, int version, bool fetchFolders, List<InventoryFolderBase> folders, int version, bool fetchFolders,
bool fetchItems); bool fetchItems);
void SendInventoryItemDetails(UUID ownerID, InventoryItemBase item); void SendInventoryItemDetails(InventoryItemBase[] items);
/// <summary> /// <summary>
/// Tell the client that we have created the item it requested. /// Tell the client that we have created the item it requested.

View File

@ -136,7 +136,7 @@ namespace OpenSim.Region.ClientStack.LindenUDP
public event TeleportCancel OnTeleportCancel; public event TeleportCancel OnTeleportCancel;
public event RequestAvatarProperties OnRequestAvatarProperties; public event RequestAvatarProperties OnRequestAvatarProperties;
public event SetAlwaysRun OnSetAlwaysRun; public event SetAlwaysRun OnSetAlwaysRun;
public event FetchInventory OnAgentDataUpdateRequest; public event AgentDataUpdate OnAgentDataUpdateRequest;
public event TeleportLocationRequest OnSetStartLocationRequest; public event TeleportLocationRequest OnSetStartLocationRequest;
public event UpdateAvatarProperties OnUpdateAvatarProperties; public event UpdateAvatarProperties OnUpdateAvatarProperties;
public event CreateNewInventoryItem OnCreateNewInventoryItem; public event CreateNewInventoryItem OnCreateNewInventoryItem;
@ -2496,50 +2496,74 @@ namespace OpenSim.Region.ClientStack.LindenUDP
return descend; return descend;
} }
public void SendInventoryItemDetails(UUID ownerID, InventoryItemBase item) public void SendInventoryItemDetails(InventoryItemBase[] items)
{ {
// Fudge this value. It's only needed to make the CRC anyway // Fudge this value. It's only needed to make the CRC anyway
const uint FULL_MASK_PERMISSIONS = (uint)0x7fffffff; const uint FULL_MASK_PERMISSIONS = (uint)0x7fffffff;
FetchInventoryReplyPacket inventoryReply = (FetchInventoryReplyPacket)PacketPool.Instance.GetPacket(PacketType.FetchInventoryReply); FetchInventoryReplyPacket inventoryReply = (FetchInventoryReplyPacket)PacketPool.Instance.GetPacket(PacketType.FetchInventoryReply);
// TODO: don't create new blocks if recycling an old packet
inventoryReply.AgentData.AgentID = AgentId; inventoryReply.AgentData.AgentID = AgentId;
inventoryReply.InventoryData = new FetchInventoryReplyPacket.InventoryDataBlock[1];
inventoryReply.InventoryData[0] = new FetchInventoryReplyPacket.InventoryDataBlock();
inventoryReply.InventoryData[0].ItemID = item.ID;
inventoryReply.InventoryData[0].AssetID = item.AssetID;
inventoryReply.InventoryData[0].CreatorID = item.CreatorIdAsUuid;
inventoryReply.InventoryData[0].BaseMask = item.BasePermissions;
inventoryReply.InventoryData[0].CreationDate = item.CreationDate;
inventoryReply.InventoryData[0].Description = Util.StringToBytes256(item.Description); int total = items.Length;
inventoryReply.InventoryData[0].EveryoneMask = item.EveryOnePermissions; int count = 0;
inventoryReply.InventoryData[0].FolderID = item.Folder; for(int i = 0; i < items.Length; ++i)
inventoryReply.InventoryData[0].InvType = (sbyte)item.InvType; {
inventoryReply.InventoryData[0].Name = Util.StringToBytes256(item.Name); if(count == 0)
inventoryReply.InventoryData[0].NextOwnerMask = item.NextPermissions; {
inventoryReply.InventoryData[0].OwnerID = item.Owner; if(total < 10)
inventoryReply.InventoryData[0].OwnerMask = item.CurrentPermissions; {
inventoryReply.InventoryData[0].Type = (sbyte)item.AssetType; inventoryReply.InventoryData = new FetchInventoryReplyPacket.InventoryDataBlock[total];
total = 0;
}
else
{
inventoryReply.InventoryData = new FetchInventoryReplyPacket.InventoryDataBlock[10];
total -= 10;
}
}
inventoryReply.InventoryData[0].GroupID = item.GroupID; inventoryReply.InventoryData[count] = new FetchInventoryReplyPacket.InventoryDataBlock();
inventoryReply.InventoryData[0].GroupOwned = item.GroupOwned; FetchInventoryReplyPacket.InventoryDataBlock data = inventoryReply.InventoryData[count];
inventoryReply.InventoryData[0].GroupMask = item.GroupPermissions;
inventoryReply.InventoryData[0].Flags = item.Flags;
inventoryReply.InventoryData[0].SalePrice = item.SalePrice;
inventoryReply.InventoryData[0].SaleType = item.SaleType;
inventoryReply.InventoryData[0].CRC = data.ItemID = items[i].ID;
Helpers.InventoryCRC( data.AssetID = items[i].AssetID;
1000, 0, inventoryReply.InventoryData[0].InvType, data.CreatorID = items[i].CreatorIdAsUuid;
inventoryReply.InventoryData[0].Type, inventoryReply.InventoryData[0].AssetID, data.BaseMask = items[i].BasePermissions;
inventoryReply.InventoryData[0].GroupID, 100, data.CreationDate = items[i].CreationDate;
inventoryReply.InventoryData[0].OwnerID, inventoryReply.InventoryData[0].CreatorID,
inventoryReply.InventoryData[0].ItemID, inventoryReply.InventoryData[0].FolderID, data.Description = Util.StringToBytes256(items[i].Description);
FULL_MASK_PERMISSIONS, 1, FULL_MASK_PERMISSIONS, FULL_MASK_PERMISSIONS, data.EveryoneMask = items[i].EveryOnePermissions;
FULL_MASK_PERMISSIONS); data.FolderID = items[i].Folder;
inventoryReply.Header.Zerocoded = true; data.InvType = (sbyte)items[i].InvType;
OutPacket(inventoryReply, ThrottleOutPacketType.Asset); data.Name = Util.StringToBytes256(items[i].Name);
data.NextOwnerMask = items[i].NextPermissions;
data.OwnerID = items[i].Owner;
data.OwnerMask = items[i].CurrentPermissions;
data.Type = (sbyte)items[i].AssetType;
data.GroupID = items[i].GroupID;
data.GroupOwned = items[i].GroupOwned;
data.GroupMask = items[i].GroupPermissions;
data.Flags = items[i].Flags;
data.SalePrice = items[i].SalePrice;
data.SaleType = items[i].SaleType;
data.CRC = Helpers.InventoryCRC(
1000, 0, data.InvType, data.Type, data.AssetID,
data.GroupID, 100, data.OwnerID, data.CreatorID,
data.ItemID, data.FolderID, FULL_MASK_PERMISSIONS, 1, FULL_MASK_PERMISSIONS, FULL_MASK_PERMISSIONS,
FULL_MASK_PERMISSIONS);
++count;
if(count == 10 || total == 0)
{
inventoryReply.Header.Zerocoded = true;
OutPacket(inventoryReply, ThrottleOutPacketType.Asset);
if(total == 0)
break;
count = 0;
}
}
} }
protected void SendBulkUpdateInventoryFolder(InventoryFolderBase folderBase) protected void SendBulkUpdateInventoryFolder(InventoryFolderBase folderBase)
@ -10146,11 +10170,18 @@ namespace OpenSim.Region.ClientStack.LindenUDP
if (FetchInventoryx.AgentData.SessionID != SessionId || FetchInventoryx.AgentData.AgentID != AgentId) if (FetchInventoryx.AgentData.SessionID != SessionId || FetchInventoryx.AgentData.AgentID != AgentId)
return; return;
for (int i = 0; i < FetchInventoryx.InventoryData.Length; i++) FetchInventoryPacket.InventoryDataBlock[] data = FetchInventoryx.InventoryData;
UUID[] items = new UUID[data.Length];
UUID[] owners = new UUID[data.Length];
for (int i = 0; i < data.Length; ++i)
{ {
OnFetchInventory?.Invoke(this, FetchInventoryx.InventoryData[i].ItemID, items[i] =data[i].ItemID;
FetchInventoryx.InventoryData[i].OwnerID); owners[i] = data[i].OwnerID;
} }
OnFetchInventory?.Invoke(this, items, owners);
} }
private void HandleFetchInventoryDescendents(Packet Pack) private void HandleFetchInventoryDescendents(Packet Pack)

View File

@ -27,7 +27,8 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Reflection; using System.Collections.Concurrent;
//using System.Reflection;
using System.Threading; using System.Threading;
using log4net; using log4net;
using OpenMetaverse; using OpenMetaverse;
@ -39,12 +40,14 @@ namespace OpenSim.Region.Framework.Scenes
class FetchHolder class FetchHolder
{ {
public IClientAPI Client { get; private set; } public IClientAPI Client { get; private set; }
public UUID ItemID { get; private set; } public UUID[] Items { get; private set; }
public UUID[] Owners { get; private set; }
public FetchHolder(IClientAPI client, UUID itemID) public FetchHolder(IClientAPI client, UUID[] items, UUID[] owners)
{ {
Client = client; Client = client;
ItemID = itemID; Items = items;
Owners = owners;
} }
} }
@ -77,16 +80,15 @@ namespace OpenSim.Region.Framework.Scenes
/// <summary> /// <summary>
/// Queues fetch requests /// Queues fetch requests
/// </summary> /// </summary>
Queue<FetchHolder> m_fetchHolder = new Queue<FetchHolder>(); private static ConcurrentQueue<FetchHolder> m_fetchHolder = new ConcurrentQueue<FetchHolder>();
static private object m_threadLock = new object();
static private bool m_running;
/// <summary> /// <summary>
/// Signal whether a queue is currently being processed or not. /// Signal whether a queue is currently being processed or not.
/// </summary> /// </summary>
protected volatile bool m_processing;
public AsyncInventorySender(Scene scene) public AsyncInventorySender(Scene scene)
{ {
m_processing = false;
m_scene = scene; m_scene = scene;
} }
@ -96,20 +98,20 @@ namespace OpenSim.Region.Framework.Scenes
/// <param name="remoteClient"></param> /// <param name="remoteClient"></param>
/// <param name="itemID"></param> /// <param name="itemID"></param>
/// <param name="ownerID"></param> /// <param name="ownerID"></param>
public void HandleFetchInventory(IClientAPI remoteClient, UUID itemID, UUID ownerID) public void HandleFetchInventory(IClientAPI remoteClient, UUID[] items, UUID[] owners)
{ {
lock (m_fetchHolder) //m_log.DebugFormat(
{ // "[ASYNC INVENTORY SENDER]: Putting request from {0} for {1} on queue", remoteClient.Name, itemID);
// m_log.DebugFormat(
// "[ASYNC INVENTORY SENDER]: Putting request from {0} for {1} on queue", remoteClient.Name, itemID);
m_fetchHolder.Enqueue(new FetchHolder(remoteClient, itemID)); m_fetchHolder.Enqueue(new FetchHolder(remoteClient, items, owners));
} if (Monitor.TryEnter(m_threadLock))
if (!m_processing)
{ {
m_processing = true; if (!m_running)
ProcessQueue(); {
m_running = true;
Util.FireAndForget(x => ProcessQueue());
}
Monitor.Exit(m_threadLock);
} }
} }
@ -118,37 +120,42 @@ namespace OpenSim.Region.Framework.Scenes
/// </summary> /// </summary>
protected void ProcessQueue() protected void ProcessQueue()
{ {
FetchHolder fh = null; lock(m_threadLock)
while (true)
{ {
lock (m_fetchHolder) try
{ {
// m_log.DebugFormat("[ASYNC INVENTORY SENDER]: {0} items left to process", m_fetchHolder.Count); while (m_fetchHolder.TryDequeue(out FetchHolder fh))
{
if (!fh.Client.IsActive)
continue;
// m_log.DebugFormat(
// "[ASYNC INVENTORY SENDER]: Handling request from {0} for {1} on queue", fh.Client.Name, fh.ItemID);
if (m_fetchHolder.Count == 0) var items = new List<InventoryItemBase>();
{ for(int i = 0; i < fh.Items.Length; ++i )
m_processing = false; {
return; InventoryItemBase item = m_scene.InventoryService.GetItem(fh.Owners[i], fh.Items[i]);
} if (item == null)
else continue;
{
fh = m_fetchHolder.Dequeue(); /*
if (item.AssetType == (int)AssetType.Link)
{
InventoryItemBase itemlk = m_scene.InventoryService.GetItem(fh.Owners[i], item.AssetID);
if(itemlk != null)
items.Add(itemlk);
}
*/
items.Add(item);
}
fh.Client.SendInventoryItemDetails(items.ToArray());
// TODO: Possibly log any failure
} }
} }
catch { }
if (!fh.Client.IsActive) m_running = false;
continue;
// m_log.DebugFormat(
// "[ASYNC INVENTORY SENDER]: Handling request from {0} for {1} on queue", fh.Client.Name, fh.ItemID);
InventoryItemBase item = m_scene.InventoryService.GetItem(fh.Client.AgentId, fh.ItemID);
if (item != null)
fh.Client.SendInventoryItemDetails(item.Owner, item);
// TODO: Possibly log any failure
} }
} }
} }

View File

@ -28,7 +28,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.Concurrent; using System.Collections.Concurrent;
using System.Reflection; //using System.Reflection;
using System.Threading; using System.Threading;
using log4net; using log4net;
using OpenMetaverse; using OpenMetaverse;
@ -52,7 +52,7 @@ namespace OpenSim.Region.Framework.Scenes
/// </summary> /// </summary>
public class AsyncSceneObjectGroupDeleter public class AsyncSceneObjectGroupDeleter
{ {
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); //private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
/// <value> /// <value>
/// Is the deleter currently enabled? /// Is the deleter currently enabled?
/// </value> /// </value>
@ -145,8 +145,8 @@ namespace OpenSim.Region.Framework.Scenes
} }
catch (Exception e) catch (Exception e)
{ {
m_log.ErrorFormat( //m_log.ErrorFormat(
"[ASYNC OBJECT DELETER]: Exception background sending object: {0}{1}", e.Message, e.StackTrace); // "[ASYNC OBJECT DELETER]: Exception background sending object: {0}{1}", e.Message, e.StackTrace);
} }
} }
// m_log.Debug("[ASYNC DELETER]: No objects left in inventory send queue."); // m_log.Debug("[ASYNC DELETER]: No objects left in inventory send queue.");

View File

@ -714,7 +714,7 @@ namespace OpenSim.Region.OptionalModules.Agent.InternetRelayClientView.Server
public event AvatarPickerRequest OnAvatarPickerRequest; public event AvatarPickerRequest OnAvatarPickerRequest;
public event Action<IClientAPI> OnRequestAvatarsData; public event Action<IClientAPI> OnRequestAvatarsData;
public event AddNewPrim OnAddPrim; public event AddNewPrim OnAddPrim;
public event FetchInventory OnAgentDataUpdateRequest; public event AgentDataUpdate OnAgentDataUpdateRequest;
public event TeleportLocationRequest OnSetStartLocationRequest; public event TeleportLocationRequest OnSetStartLocationRequest;
public event RequestGodlikePowers OnRequestGodlikePowers; public event RequestGodlikePowers OnRequestGodlikePowers;
public event GodKickUser OnGodKickUser; public event GodKickUser OnGodKickUser;
@ -1124,7 +1124,7 @@ namespace OpenSim.Region.OptionalModules.Agent.InternetRelayClientView.Server
} }
public void SendInventoryItemDetails(UUID ownerID, InventoryItemBase item) public void SendInventoryItemDetails(InventoryItemBase[] items)
{ {
} }

View File

@ -348,7 +348,7 @@ namespace OpenSim.Region.OptionalModules.World.NPC
public event SpinStop OnSpinStop; public event SpinStop OnSpinStop;
public event ViewerEffectEventHandler OnViewerEffect; public event ViewerEffectEventHandler OnViewerEffect;
public event FetchInventory OnAgentDataUpdateRequest; public event AgentDataUpdate OnAgentDataUpdateRequest;
public event TeleportLocationRequest OnSetStartLocationRequest; public event TeleportLocationRequest OnSetStartLocationRequest;
public event UpdateShape OnUpdatePrimShape; public event UpdateShape OnUpdatePrimShape;
@ -847,7 +847,7 @@ namespace OpenSim.Region.OptionalModules.World.NPC
{ {
} }
public virtual void SendInventoryItemDetails(UUID ownerID, InventoryItemBase item) public virtual void SendInventoryItemDetails(InventoryItemBase[] items)
{ {
} }

View File

@ -141,7 +141,7 @@ namespace OpenSim.Tests.Common
public event SpinStop OnSpinStop; public event SpinStop OnSpinStop;
public event ViewerEffectEventHandler OnViewerEffect; public event ViewerEffectEventHandler OnViewerEffect;
public event FetchInventory OnAgentDataUpdateRequest; public event AgentDataUpdate OnAgentDataUpdateRequest;
public event TeleportLocationRequest OnSetStartLocationRequest; public event TeleportLocationRequest OnSetStartLocationRequest;
public event UpdateShape OnUpdatePrimShape; public event UpdateShape OnUpdatePrimShape;
@ -796,7 +796,7 @@ namespace OpenSim.Tests.Common
{ {
} }
public virtual void SendInventoryItemDetails(UUID ownerID, InventoryItemBase item) public virtual void SendInventoryItemDetails(InventoryItemBase[] items)
{ {
} }