private void SignalTaskInventoryChange(LLAgent agent, LLPrimitive prim)
{
// Send an ObjectPropertiesReply to inform the client that inventory has changed
ObjectPropertiesPacket props = new ObjectPropertiesPacket();
props.ObjectData = new ObjectPropertiesPacket.ObjectDataBlock[1];
props.ObjectData[0] = LLUtil.BuildEntityPropertiesBlock(prim);
m_udp.SendPacket(agent, props, ThrottleCategory.Task, false);
// Signal this prim for serialization
m_scene.EntityAddOrUpdate(this, prim, UpdateFlags.Serialize, 0);
}
private void TransferDownload(LLAgent agent, UUID transferID, UUID assetID, AssetType type, Asset asset)
{
const int MAX_CHUNK_SIZE = 1000;
string contentType = LLUtil.LLAssetTypeToContentType((int)type);
if (contentType == asset.ContentType)
{
m_log.Debug(String.Format("Transferring asset {0} ({1})", asset.ID, asset.ContentType));
TransferInfoPacket response = new TransferInfoPacket();
response.TransferInfo = new TransferInfoPacket.TransferInfoBlock();
response.TransferInfo.TransferID = transferID;
// Set the response channel type
response.TransferInfo.ChannelType = (int)ChannelType.Asset;
// Params
response.TransferInfo.Params = new byte[20];
assetID.ToBytes(response.TransferInfo.Params, 0);
Utils.IntToBytes((int)type, response.TransferInfo.Params, 16);
response.TransferInfo.Size = asset.Data.Length;
response.TransferInfo.Status = (int)StatusCode.OK;
response.TransferInfo.TargetType = (int)TargetType.Unknown; // Doesn't seem to be used by the client
m_udp.SendPacket(agent, response, ThrottleCategory.Asset, false);
// Transfer system does not wait for ACKs, just sends all of the
// packets for this transfer out
int processedLength = 0;
int packetNum = 0;
while (processedLength < asset.Data.Length)
{
TransferPacketPacket transfer = new TransferPacketPacket();
transfer.TransferData.ChannelType = (int)ChannelType.Asset;
transfer.TransferData.TransferID = transferID;
transfer.TransferData.Packet = packetNum++;
int chunkSize = Math.Min(asset.Data.Length - processedLength, MAX_CHUNK_SIZE);
transfer.TransferData.Data = new byte[chunkSize];
Buffer.BlockCopy(asset.Data, processedLength, transfer.TransferData.Data, 0, chunkSize);
processedLength += chunkSize;
if (processedLength >= asset.Data.Length)
transfer.TransferData.Status = (int)StatusCode.Done;
else
transfer.TransferData.Status = (int)StatusCode.OK;
m_udp.SendPacket(agent, transfer, ThrottleCategory.Asset, false);
}
}
else
{
m_log.WarnFormat("Request for asset {0} with type {1} does not match actual asset type {2}",
assetID, type, asset.ContentType);
TransferNotFound(agent, transferID, assetID, type);
}
}
开发者ID:thoys,项目名称:simian,代码行数:60,代码来源:Assets.cs
示例3: TransferRequestHandler
private void TransferRequestHandler(Packet packet, LLAgent agent)
{
TransferRequestPacket request = (TransferRequestPacket)packet;
ChannelType channel = (ChannelType)request.TransferInfo.ChannelType;
SourceType source = (SourceType)request.TransferInfo.SourceType;
if (channel == ChannelType.Asset)
{
if (source == SourceType.Asset)
{
// Parse the request
UUID assetID = new UUID(request.TransferInfo.Params, 0);
AssetType type = (AssetType)(sbyte)Utils.BytesToInt(request.TransferInfo.Params, 16);
string contentType = LLUtil.LLAssetTypeToContentType((int)type);
// Permission check
if (!CanDownloadInventory(agent, type, assetID))
{
TransferNotFound(agent, request.TransferInfo.TransferID, assetID, type);
return;
}
// Check if we have this asset
Asset asset;
if (m_assets.TryGetAsset(assetID, contentType, out asset))
TransferDownload(agent, request.TransferInfo.TransferID, assetID, type, asset);
else
TransferNotFound(agent, request.TransferInfo.TransferID, assetID, type);
}
else if (source == SourceType.SimInventoryItem)
{
//UUID agentID = new UUID(request.TransferInfo.Params, 0);
//UUID sessionID = new UUID(request.TransferInfo.Params, 16);
//UUID ownerID = new UUID(request.TransferInfo.Params, 32);
UUID taskID = new UUID(request.TransferInfo.Params, 48);
UUID itemID = new UUID(request.TransferInfo.Params, 64);
UUID assetID = new UUID(request.TransferInfo.Params, 80);
AssetType type = (AssetType)(sbyte)Utils.BytesToInt(request.TransferInfo.Params, 96);
string contentType = LLUtil.LLAssetTypeToContentType((int)type);
if (taskID != UUID.Zero)
{
// Task (prim) inventory request permission check
if (!CanDownloadTaskInventory(agent, type, taskID, itemID))
{
TransferNotFound(agent, request.TransferInfo.TransferID, assetID, type);
return;
}
}
else
{
// Agent inventory request permission check
if (!CanDownloadInventory(agent, type, assetID))
{
TransferNotFound(agent, request.TransferInfo.TransferID, assetID, type);
return;
}
}
// Check if we have this asset
Asset asset;
if (m_assets.TryGetAsset(assetID, contentType, out asset))
TransferDownload(agent, request.TransferInfo.TransferID, assetID, type, asset);
else
TransferNotFound(agent, request.TransferInfo.TransferID, assetID, type);
}
else if (source == SourceType.SimEstate)
{
//UUID agentID = new UUID(request.TransferInfo.Params, 0);
//UUID sessionID = new UUID(request.TransferInfo.Params, 16);
//EstateAssetType type = (EstateAssetType)Utils.BytesToInt(request.TransferInfo.Params, 32);
m_log.Warn("Don't know what to do with an estate asset transfer request");
}
else
{
m_log.WarnFormat(
"Received a TransferRequest that we don't know how to handle. Channel: {0}, Source: {1}",
channel, source);
}
}
else
{
m_log.WarnFormat(
"Received a TransferRequest that we don't know how to handle. Channel: {0}, Source: {1}",
channel, source);
}
}
开发者ID:thoys,项目名称:simian,代码行数:89,代码来源:Assets.cs
示例4: CanDownloadTaskInventory
private bool CanDownloadTaskInventory(LLAgent agent, AssetType type, UUID taskID, UUID itemID)
{
ISceneEntity entity;
if (m_scene.TryGetEntity(taskID, out entity))
{
if (entity is LLPrimitive)
{
LLPrimitive prim = (LLPrimitive)entity;
LLInventoryTaskItem item;
if (prim.Inventory.TryGetItem(itemID, out item))
{
bool success;
if (item.OwnerID == agent.ID)
success = item.Permissions.OwnerMask.HasPermission(PermissionMask.Modify);
else
success = item.Permissions.EveryoneMask.HasPermission(PermissionMask.Modify);
if (!success)
m_log.Warn("Denying task inventory download from " + agent.Name + " for item " + item.Name + " in task " + taskID);
return success;
}
}
}
return false;
}
开发者ID:thoys,项目名称:simian,代码行数:29,代码来源:Assets.cs
示例5: RequestXferHandler
private void RequestXferHandler(Packet packet, LLAgent agent)
{
RequestXferPacket request = (RequestXferPacket)packet;
string filename = Utils.BytesToString(request.XferID.Filename);
UUID taskInventoryID;
if (filename.StartsWith("inventory_") && filename.EndsWith(".tmp") && UUID.TryParse(filename.Substring(10, 36), out taskInventoryID))
{
// This is a request for a task inventory listing, which we generate on demand
ISceneEntity entity;
if (m_scene.TryGetEntity(taskInventoryID, out entity) && entity is LLPrimitive)
{
LLPrimitive prim = (LLPrimitive)entity;
byte[] assetData = Encoding.UTF8.GetBytes(prim.Inventory.GetTaskInventoryAsset());
SendXferPacketPacket xfer = new SendXferPacketPacket();
xfer.XferID.ID = request.XferID.ID;
if (assetData.Length < 1000)
{
xfer.XferID.Packet = 0 | LAST_PACKET_MARKER;
xfer.DataPacket.Data = new byte[assetData.Length + 4];
Utils.IntToBytes(assetData.Length, xfer.DataPacket.Data, 0);
Buffer.BlockCopy(assetData, 0, xfer.DataPacket.Data, 4, assetData.Length);
m_udp.SendPacket(agent, xfer, ThrottleCategory.Asset, false);
m_log.Debug("Completed single packet xfer download of " + filename);
}
else
{
xfer.XferID.Packet = 0;
xfer.DataPacket.Data = new byte[1000 + 4];
Utils.IntToBytes(assetData.Length, xfer.DataPacket.Data, 0);
Buffer.BlockCopy(assetData, 0, xfer.DataPacket.Data, 4, 1000);
// We don't need the entire XferDownload class, just the asset data and the current packet number
XferDownload download = new XferDownload();
download.AssetData = assetData;
download.PacketNum = 1;
download.Filename = filename;
lock (currentDownloads)
currentDownloads[request.XferID.ID] = download;
m_udp.SendPacket(agent, xfer, ThrottleCategory.Asset, false);
}
}
else
{
m_log.Warn("Could not find primitive " + taskInventoryID);
}
}
else
{
m_log.Warn("Got a RequestXfer for an unknown file: " + filename);
}
}
开发者ID:thoys,项目名称:simian,代码行数:57,代码来源:Assets.cs
示例6: ChatFromViewerHandler
private void ChatFromViewerHandler(Packet packet, LLAgent agent)
{
ChatFromViewerPacket chat = (ChatFromViewerPacket)packet;
ChatType chatType = (ChatType)chat.ChatData.Type;
string message = Utils.BytesToString(chat.ChatData.Message);
int channel = chat.ChatData.Channel;
// Don't allow clients to chat on negative channels
if (channel < 0)
channel = 0;
// Start/stop typing messages are specific to the LLUDP protocol, so we create events
// directly that will be processed by this same class. Chat messages are a generic
// event that can be supported by multiple protocols, so we call IScene.EntityChat and
// hook IScene.OnChat to do the actual processing
// Event IDs for start/stop typing are generated with UUID.Combine(agent.ID, TYPING_EVENT_ID)
// to create an ID that is unique to each agent in the context of typing. Newer typing
// events will overwrite older ones
switch (chatType)
{
case ChatType.StartTyping:
m_scene.CreateInterestListEvent(new InterestListEvent(UUID.Combine(agent.ID, TYPING_EVENT_ID),
VIEWER_TYPING, agent.ScenePosition, new Vector3(NORMAL_DIST),
new TypingData { Source = agent, StartTyping = true }));
break;
case ChatType.StopTyping:
m_scene.CreateInterestListEvent(new InterestListEvent(UUID.Combine(agent.ID, TYPING_EVENT_ID),
VIEWER_TYPING, agent.ScenePosition, new Vector3(NORMAL_DIST),
new TypingData { Source = agent, StartTyping = false }));
break;
case ChatType.Whisper:
m_scene.EntityChat(this, agent, WHISPER_DIST, message, channel, EntityChatType.Normal);
break;
case ChatType.Shout:
m_scene.EntityChat(this, agent, SHOUT_DIST, message, channel, EntityChatType.Normal);
break;
case ChatType.Normal:
default:
m_scene.EntityChat(this, agent, NORMAL_DIST, message, channel, EntityChatType.Normal);
break;
}
}
开发者ID:thoys,项目名称:simian,代码行数:44,代码来源:Chat.cs
示例7: AssetUploadRequestHandler
private void AssetUploadRequestHandler(Packet packet, LLAgent agent)
{
AssetUploadRequestPacket request = (AssetUploadRequestPacket)packet;
UUID assetID = UUID.Combine(request.AssetBlock.TransactionID, agent.SecureSessionID);
AssetType type = (AssetType)request.AssetBlock.Type;
// Check if the agent is allowed to upload an asset
string uploadError;
if (m_permissions != null && !m_permissions.TryUploadOneAsset(agent, out uploadError))
{
m_scene.PresenceAlert(this, agent, uploadError);
return;
}
bool local = request.AssetBlock.StoreLocal | type == AssetType.LSLBytecode;
bool temp = request.AssetBlock.Tempfile;
// Check if the asset is small enough to fit in a single packet
if (request.AssetBlock.AssetData.Length != 0)
{
// Create a new asset from the completed upload
Asset asset = CreateAsset(type, assetID, DateTime.UtcNow, agent.ID, local, temp, request.AssetBlock.AssetData);
if (asset == null)
{
m_log.Warn("Failed to create asset from uploaded data");
return;
}
if (type != AssetType.LSLBytecode)
{
// Store the asset
m_log.DebugFormat("Storing uploaded asset {0} ({1})", assetID, asset.ContentType);
if (!m_assets.StoreAsset(asset))
m_log.ErrorFormat("Failed to store uploaded asset {0} ({1})", assetID, asset.ContentType);
}
else
{
m_log.Debug("Ignoring LSL bytecode upload " + assetID);
}
// Send a success response
AssetUploadCompletePacket complete = new AssetUploadCompletePacket();
complete.AssetBlock.Success = true;
complete.AssetBlock.Type = request.AssetBlock.Type;
complete.AssetBlock.UUID = assetID;
m_udp.SendPacket(agent, complete, ThrottleCategory.Task, false);
}
else
{
// Create a new (empty) asset for the upload
Asset asset = CreateAsset(type, assetID, DateTime.UtcNow, agent.ID, local, temp, null);
if (asset == null)
{
m_log.Warn("Failed to create asset from uploaded data");
return;
}
asset.Temporary = (request.AssetBlock.Tempfile | request.AssetBlock.StoreLocal);
ulong transferID = request.AssetBlock.TransactionID.GetULong();
// Prevent LSL bytecode transfers from colliding with LSL source transfers, which
// use a colliding UUID
if (type == AssetType.LSLBytecode)
++transferID;
RequestXferPacket xfer = new RequestXferPacket();
xfer.XferID.DeleteOnCompletion = request.AssetBlock.Tempfile;
xfer.XferID.FilePath = 0;
xfer.XferID.Filename = Utils.EmptyBytes;
xfer.XferID.ID = transferID;
xfer.XferID.UseBigPackets = false;
xfer.XferID.VFileID = asset.ID;
xfer.XferID.VFileType = request.AssetBlock.Type;
m_log.DebugFormat("Starting upload for {0} / {1} ({2})", assetID, transferID, asset.ContentType);
// Add this asset to the current upload list
lock (currentUploads)
currentUploads[transferID] = asset;
m_udp.SendPacket(agent, xfer, ThrottleCategory.Task, false);
}
}
开发者ID:thoys,项目名称:simian,代码行数:86,代码来源:Assets.cs
示例8: ImprovedInstantMessageHandler
private void ImprovedInstantMessageHandler(Packet packet, LLAgent agent)
{
ImprovedInstantMessagePacket im = (ImprovedInstantMessagePacket)packet;
// The following fields are unused since we already have this information, plus the
// client could forge it:
// - im.MessageBlock.FromAgentName
// - im.MessageBlock.FromGroup;
// - im.MessageBlock.RegionID
// - im.MessageBlock.Position
// - im.MessageBlock.Timestamp
// - im.MessageBlock.ParentEstateID
InstantMessageDialog type = (InstantMessageDialog)im.MessageBlock.Dialog;
string message = Utils.BytesToString(im.MessageBlock.Message);
bool allowOffline = (im.MessageBlock.Offline != 0);
switch (type)
{
case InstantMessageDialog.MessageFromAgent:
case InstantMessageDialog.StartTyping:
case InstantMessageDialog.StopTyping:
SendInstantMessage(im.MessageBlock.ID, im.MessageBlock.ToAgentID, agent.Name,
agent.ScenePosition, agent.Scene.ID, false, type, message, allowOffline,
DateTime.UtcNow, im.MessageBlock.BinaryBucket);
break;
case InstantMessageDialog.RequestTeleport:
case InstantMessageDialog.GodLikeRequestTeleport:
case InstantMessageDialog.Lure911:
case InstantMessageDialog.AcceptTeleport:
case InstantMessageDialog.DenyTeleport:
case InstantMessageDialog.BusyAutoResponse:
break;
case InstantMessageDialog.FriendshipOffered:
case InstantMessageDialog.FriendshipAccepted:
case InstantMessageDialog.FriendshipDeclined:
break;
case InstantMessageDialog.GroupInvitation:
case InstantMessageDialog.GroupInvitationAccept:
case InstantMessageDialog.GroupInvitationDecline:
break;
case InstantMessageDialog.GroupNotice:
case InstantMessageDialog.GroupNoticeRequested:
case InstantMessageDialog.GroupNoticeInventoryAccepted:
case InstantMessageDialog.GroupNoticeInventoryDeclined:
case InstantMessageDialog.GroupVote:
break;
case InstantMessageDialog.InventoryOffered:
case InstantMessageDialog.InventoryAccepted:
case InstantMessageDialog.InventoryDeclined:
break;
case InstantMessageDialog.TaskInventoryOffered:
case InstantMessageDialog.TaskInventoryAccepted:
case InstantMessageDialog.TaskInventoryDeclined:
break;
case InstantMessageDialog.SessionAdd:
case InstantMessageDialog.SessionOfflineAdd:
case InstantMessageDialog.SessionCardlessStart:
case InstantMessageDialog.Session911Start:
case InstantMessageDialog.SessionDrop:
case InstantMessageDialog.SessionGroupStart:
case InstantMessageDialog.SessionSend:
break;
//case InstantMessageDialog.MessageFromObject:
//case InstantMessageDialog.FromTaskAsAlert:
//case InstantMessageDialog.MessageBox:
//case InstantMessageDialog.GotoUrl:
//case InstantMessageDialog.ConsoleAndChatHistory:
//case InstantMessageDialog.NewUserDefault:
default:
m_log.Warn("Received an IM with unhandled type " + type + " from " + agent.Name);
return;
}
}
开发者ID:thoys,项目名称:simian,代码行数:82,代码来源:Messaging.cs
示例9: ViewerEffectHandler
private void ViewerEffectHandler(Packet packet, LLAgent agent)
{
ViewerEffectPacket effect = (ViewerEffectPacket)packet;
// Broadcast this viewer effect to everyone
for (int i = 0; i < effect.Effect.Length; i++)
{
ViewerEffectPacket.EffectBlock block = effect.Effect[i];
if (block.AgentID == agent.ID)
m_scene.CreateInterestListEvent(new InterestListEvent(UUID.Combine(block.ID, EFFECT_EVENT_ID), VIEWER_EFFECT, agent.ScenePosition, Vector3.One, block));
else
m_log.Warn("Skipping ViewerEffect block for " + block.AgentID + " from " + agent.ID + " (" + agent.Name + ")");
}
}
请发表评论