public void ObjectAddHandler(Packet packet, Simulator simulator) { LLVector3 position = null; if (WaitingOnUpdate) { CurrentPrimMutex.WaitOne(); foreach (Block block in packet.Blocks()) { foreach (Field field in block.Fields) { if (field.Layout.Name == "RayEnd") { position = (LLVector3)field.Data; } } } txtLog.AppendText("Received an ObjectAdd, setting CurrentPrim position to " + position.ToString()); CurrentPrim.Position = position; CurrentPrimMutex.ReleaseMutex(); } }
/// <summary> /// Default constructor /// </summary> /// <param name="simulator"></param> /// <param name="seedcaps"></param> internal Caps(Simulator simulator, string seedcaps) { Simulator = simulator; _SeedCapsURI = seedcaps; MakeSeedRequest(); }
protected void AttachedSoundHandler(Packet packet, Simulator simulator) { AttachedSoundPacket sound = (AttachedSoundPacket)packet; if (OnAttachSound != null) { try { OnAttachSound(sound.DataBlock.SoundID, sound.DataBlock.OwnerID, sound.DataBlock.ObjectID, sound.DataBlock.Gain, sound.DataBlock.Flags); } catch (Exception e) { Client.Log(e.ToString(), Helpers.LogLevel.Error); } } }
protected void AttachedSoundGainChangeHandler(Packet packet, Simulator simulator) { AttachedSoundGainChangePacket change = (AttachedSoundGainChangePacket)packet; if (OnAttachSoundGainChange != null) { try { OnAttachSoundGainChange(change.DataBlock.ObjectID, change.DataBlock.Gain); } catch (Exception e) { Client.Log(e.ToString(), Helpers.LogLevel.Error); } } }
void Network_OnEventQueueRunning(Simulator simulator) { if (simulator == Client.Network.CurrentSim) { Console.WriteLine("Event queue connected for the primary simulator, requesting group info"); Client.Groups.RequestCurrentGroups(); } }
private void AgentDataUpdateHandler(Packet packet, Simulator sim) { AgentDataUpdatePacket p = (AgentDataUpdatePacket)packet; if (p.AgentData.AgentID == Client.Self.AgentID) { activeGroup = Helpers.FieldToUTF8String(p.AgentData.GroupName) + " ( " + Helpers.FieldToUTF8String(p.AgentData.GroupTitle) + " )"; GroupsEvent.Set(); } }
void Objects_OnObjectProperties(Simulator simulator, LLObject.ObjectProperties properties) { lock (PrimsWaiting) { Primitive prim; if (PrimsWaiting.TryGetValue(properties.ObjectID, out prim)) { prim.Properties = properties; } PrimsWaiting.Remove(properties.ObjectID); if (PrimsWaiting.Count == 0) AllPropertiesReceived.Set(); } }
protected void PreloadSoundHandler(Packet packet, Simulator simulator) { PreloadSoundPacket preload = (PreloadSoundPacket)packet; if (OnPreloadSound != null) { foreach (PreloadSoundPacket.DataBlockBlock data in preload.DataBlock) { try { OnPreloadSound(data.SoundID, data.OwnerID, data.ObjectID); } catch (Exception e) { Client.Log(e.ToString(), Helpers.LogLevel.Error); } } } }
private void OnPacket(Packet packet, Simulator simulator) { lock (Packets) { if (Count >= Total) { Done = true; } else { Packets.Add(packet); Count++; } } }
private void AvatarAppearanceHandler(Packet packet, Simulator simulator) { AvatarAppearancePacket appearance = (AvatarAppearancePacket)packet; LLObject.TextureEntry te = new LLObject.TextureEntry(appearance.ObjectData.TextureEntry, 0, appearance.ObjectData.TextureEntry.Length); if (IsNullOrZero(te.FaceTextures[(int)AppearanceManager.TextureIndex.EyesBaked] ) && IsNullOrZero(te.FaceTextures[(int)AppearanceManager.TextureIndex.HeadBaked]) && IsNullOrZero(te.FaceTextures[(int)AppearanceManager.TextureIndex.LowerBaked]) && IsNullOrZero(te.FaceTextures[(int)AppearanceManager.TextureIndex.SkirtBaked]) && IsNullOrZero(te.FaceTextures[(int)AppearanceManager.TextureIndex.UpperBaked])) { Console.WriteLine("Avatar " + appearance.Sender.ID.ToString() + " may be a bot"); } }
private void Objects_OnNewAvatar(Simulator simulator, Avatar avatar, ulong regionHandle, ushort timeDilation) { if (imgManager == null) { Console.WriteLine("ImageManager not ready yet, queueing Avatar textures."); TextureQueue.Enqueue(avatar.FirstLifeImage); TextureQueue.Enqueue(avatar.ProfileImage); foreach (TextureEntryFace tef in avatar.Textures.FaceTextures.Values) { TextureQueue.Enqueue(tef.TextureID); } } else { if (avatar.FirstLifeImage != null) { if (imgManager.isCachedImage(avatar.FirstLifeImage) == false) { imgManager.RequestImageAsync(avatar.FirstLifeImage); } } if (avatar.ProfileImage != null) { if (imgManager.isCachedImage(avatar.FirstLifeImage) == false) { imgManager.RequestImageAsync(avatar.ProfileImage); } } if (avatar.Textures != null) { foreach (TextureEntryFace tef in avatar.Textures.FaceTextures.Values) { if (imgManager.isCachedImage(tef.TextureID) == false) { imgManager.RequestImageAsync(tef.TextureID); } else { Console.WriteLine("Already cached: " + tef.TextureID); } } } } }
void Parcels_OnParcelsDownloaded(Simulator simulator, Dictionary<int, Parcel> Parcels, int[,] map) { foreach (KeyValuePair<int, Parcel> parcel in Parcels) { WaterType type = ParcelDownloader.GetWaterType(map, parcel.Value.LocalID); float delta = ParcelDownloader.GetHeightRange(map, parcel.Value.LocalID); int deviation = ParcelDownloader.GetRectangularDeviation(parcel.Value.AABBMin, parcel.Value.AABBMax, parcel.Value.Area); Console.WriteLine("Parcels[{0}]: Name: \"{1}\", Description: \"{2}\" ACL Count: {3}, " + "Location: {4}, Height Range: {5}, Shape Deviation: {6}", parcel.Key, parcel.Value.Name, parcel.Value.Desc, parcel.Value.AccessList.Count, type.ToString(), delta, deviation); } ParcelCount = Parcels.Count; ParcelsDownloaded.Set(); }
public void ObjectUpdateHandler(Packet packet, Simulator simulator) { uint id = 0; LLUUID uuid = null; if (WaitingOnUpdate) { CurrentPrimMutex.WaitOne(); foreach (Block block in packet.Blocks()) { foreach (Field field in block.Fields) { if (field.Layout.Name == "ID") { id = (uint)field.Data; } else if (field.Layout.Name == "FullID") { uuid = (LLUUID)field.Data; } else if (field.Layout.Name == "ObjectData") { byte[] byteArray = (byte[])field.Data; LLVector3 position = new LLVector3(byteArray, 0); if (CurrentPrim != null && position != CurrentPrim.Position) { txtLog.AppendText(position.ToString() + " doesn't match CurrentPrim.Position " + CurrentPrim.Position.ToString() + "\n"/* + ", ignoring"*/); //return; } } } } CurrentPrim.ID = id; CurrentPrim.UUID = uuid; WaitingOnUpdate = false; CurrentPrimMutex.ReleaseMutex(); } }
/// <summary> /// Fire the events registered for this packet type synchronously /// </summary> /// <param name="packetType">Incoming packet type</param> /// <param name="packet">Incoming packet</param> /// <param name="simulator">Simulator this packet was received from</param> internal void RaiseEvent(PacketType packetType, Packet packet, Simulator simulator) { NetworkManager.PacketCallback callback; if (_EventTable.TryGetValue(packetType, out callback)) { try { callback(packet, simulator); } catch (Exception ex) { Client.Log("Packet Event Handler: " + ex.ToString(), Helpers.LogLevel.Error); } } else if (packetType != PacketType.Default && packetType != PacketType.PacketAck) { Client.Log("No handler registered for packet event " + packetType, Helpers.LogLevel.Debug); } }
public static void QueryHandler(Packet packet, Simulator simulator) { DirPeopleReplyPacket reply = (DirPeopleReplyPacket)packet; if (reply.QueryReplies.Length < 1) { Console.WriteLine("ERROR: Got an empty reply"); } else { if (reply.QueryReplies.Length > 1) { Console.WriteLine("ERROR: Ambiguous name. Returning first match"); } Console.WriteLine("UUID: " + reply.QueryReplies[0].AgentID.ToString()); } waiting = false; }
void Terrain_OnLandPatch(Simulator simulator, int x, int y, int width, float[] data) { if (x >= 16 || y >= 16) { Console.WriteLine("Bad patch coordinates, x = " + x + ", y = " + y); return; } if (width != 16) { Console.WriteLine("Unhandled patch size " + width + "x" + width); return; } Bitmap patch = new Bitmap(16, 16, PixelFormat.Format24bppRgb); for (int yp = 0; yp < 16; yp++) { for (int xp = 0; xp < 16; xp++) { float height = data[yp * 16 + xp]; int colorVal = Helpers.FloatToByte(height, 0.0f, 60.0f); int lesserVal = (int)((float)colorVal * 0.75f); Color color; if (height >= simulator.WaterHeight) color = Color.FromArgb(lesserVal, colorVal, lesserVal); else color = Color.FromArgb(lesserVal, lesserVal, colorVal); patch.SetPixel(xp, yp, color); } } Boxes[x, y].Image = (Image)patch; }
private void ParcelPropertiesHandler(Packet packet, Simulator simulator) { ParcelPropertiesPacket properties = (ParcelPropertiesPacket)packet; byte[] Bitmap = properties.ParcelData.Bitmap; int LocalID = properties.ParcelData.LocalID; // Mark this area as downloaded int x, y, index, subindex; byte val; for (x = 0; x < 64; x++) { for (y = 0; y < 64; y++) { if (simulator.Region.ParcelMarked[y, x] == 0) { index = ((x * 64) + y); subindex = index % 8; index /= 8; val = Bitmap[index]; simulator.Region.ParcelMarked[y, x] = ((val >> subindex) & 1) == 1 ? LocalID : 0; } } } // Fire off the next request, if we are downloading the whole sim bool hasTriggered = false; if (simulator.Region.ParcelDownloading) { for (x = 0; x < 64; x++) { for (y = 0; y < 64; y++) { if (simulator.Region.ParcelMarked[x, y] == 0) { ParcelPropertiesRequestPacket tPacket = new ParcelPropertiesRequestPacket(); tPacket.AgentData.AgentID = Client.Network.AgentID; tPacket.AgentData.SessionID = Client.Network.SessionID; tPacket.ParcelData.SequenceID = -10000; tPacket.ParcelData.West = (x * 4.0f); tPacket.ParcelData.South = (y * 4.0f); tPacket.ParcelData.East = (x * 4.0f) + 4.0f; tPacket.ParcelData.North = (y * 4.0f) + 4.0f; simulator.SendPacket((Packet)tPacket, true); hasTriggered = true; goto exit; } } } exit: ; } // This map is complete, fire callback if (!hasTriggered) { simulator.Region.FilledParcels(); } Parcel parcel = null; lock (simulator.Region.Parcels) { if (!simulator.Region.Parcels.ContainsKey(LocalID)) { simulator.Region.Parcels[LocalID] = new Parcel(simulator); } parcel = simulator.Region.Parcels[LocalID]; } // Save this parcels data // TODO: Lots of values are not being stored, Parcel needs to be expanded to take all the data. // August2006: God help me should I have to type this out again... argh. // October2006: I really shouldnt have typed that. parcel.RequestResult = properties.ParcelData.RequestResult; parcel.SequenceID = properties.ParcelData.SequenceID; parcel.SnapSelection = properties.ParcelData.SnapSelection; parcel.SelfCount = properties.ParcelData.SelfCount; parcel.OtherCount = properties.ParcelData.OtherCount; parcel.PublicCount = properties.ParcelData.PublicCount; parcel.LocalID = LocalID; parcel.OwnerID = properties.ParcelData.OwnerID; parcel.IsGroupOwned = properties.ParcelData.IsGroupOwned; parcel.AuctionID = properties.ParcelData.AuctionID; parcel.ReservedNewbie = properties.ParcelData.ReservedNewbie; parcel.ClaimDate = properties.ParcelData.ClaimDate; parcel.ClaimPrice = properties.ParcelData.ClaimPrice; parcel.RentPrice = properties.ParcelData.RentPrice; parcel.AABBMin = properties.ParcelData.AABBMin; parcel.AABBMax = properties.ParcelData.AABBMax; parcel.Bitmap = properties.ParcelData.Bitmap; parcel.Area = properties.ParcelData.Area; parcel.Status = properties.ParcelData.Status; parcel.SimWideMaxObjects = properties.ParcelData.SimWideMaxPrims; parcel.SimWideTotalObjects = properties.ParcelData.SimWideTotalPrims; parcel.MaxObjects = properties.ParcelData.MaxPrims; parcel.TotalObjects = properties.ParcelData.TotalPrims; parcel.OwnerObjects = properties.ParcelData.OwnerPrims; parcel.GroupObjects = properties.ParcelData.GroupPrims; parcel.OtherObjects = properties.ParcelData.OtherPrims; parcel.ParcelObjectBonus = properties.ParcelData.ParcelPrimBonus; parcel.OtherCleanTime = properties.ParcelData.OtherCleanTime; parcel.ParcelFlags = properties.ParcelData.ParcelFlags; parcel.SalePrice = properties.ParcelData.SalePrice; parcel.Name = Helpers.FieldToString(properties.ParcelData.Name); parcel.Desc = Helpers.FieldToString(properties.ParcelData.Desc); parcel.MusicURL = Helpers.FieldToString(properties.ParcelData.MusicURL); parcel.MediaURL = Helpers.FieldToString(properties.ParcelData.MediaURL); parcel.MediaID = properties.ParcelData.MediaID; parcel.MediaAutoScale = properties.ParcelData.MediaAutoScale; parcel.GroupID = properties.ParcelData.GroupID; parcel.PassPrice = properties.ParcelData.PassPrice; parcel.PassHours = properties.ParcelData.PassHours; parcel.Category = properties.ParcelData.Category; parcel.AuthBuyerID = properties.ParcelData.AuthBuyerID; parcel.SnapshotID = properties.ParcelData.SnapshotID; parcel.UserLocation = properties.ParcelData.UserLocation; parcel.UserLookAt = properties.ParcelData.UserLookAt; parcel.LandingType = properties.ParcelData.LandingType; }
/// <summary> /// Connect to a simulator /// </summary> /// <param name="endPoint">IP address and port to connect to</param> /// <param name="handle">Handle for this simulator, to identify its /// location in the grid</param> /// <param name="setDefault">Whether to set CurrentSim to this new /// connection, use this if the avatar is moving in to this simulator</param> /// <param name="seedcaps">URL of the capabilities server to use for /// this sim connection</param> /// <returns>A Simulator object on success, otherwise null</returns> public Simulator Connect(IPEndPoint endPoint, ulong handle, bool setDefault, string seedcaps) { Simulator simulator = FindSimulator(endPoint); if (simulator == null) { // We're not tracking this sim, create a new Simulator object simulator = new Simulator(Client, endPoint, handle); // Immediately add this simulator to the list of current sims. It will be removed if the // connection fails lock (Simulators) Simulators.Add(simulator); } if (!simulator.Connected) { if (!connected) { // Mark that we are connecting/connected to the grid connected = true; // restart the blocking queue in case of re-connect PacketInbox.Open(); // Start the packet decoding thread Thread decodeThread = new Thread(new ThreadStart(PacketHandler)); decodeThread.Start(); } // Fire the OnSimConnecting event if (OnSimConnecting != null) { try { if (!OnSimConnecting(simulator)) { // Callback is requesting that we abort this connection lock (Simulators) Simulators.Remove(simulator); return(null); } } catch (Exception e) { Logger.Log(e.Message, Helpers.LogLevel.Error, Client, e); } } // Attempt to establish a connection to the simulator if (simulator.Connect(setDefault)) { if (DisconnectTimer == null) { // Start a timer that checks if we've been disconnected DisconnectTimer = new Timer(new TimerCallback(DisconnectTimer_Elapsed), null, Client.Settings.SIMULATOR_TIMEOUT, Client.Settings.SIMULATOR_TIMEOUT); } if (setDefault) { SetCurrentSim(simulator, seedcaps); } // Fire the simulator connection callback if one is registered if (OnSimConnected != null) { try { OnSimConnected(simulator); } catch (Exception e) { Logger.Log(e.Message, Helpers.LogLevel.Error, Client, e); } } // If enabled, send an AgentThrottle packet to the server to increase our bandwidth if (Client.Settings.SEND_AGENT_THROTTLE) { Client.Throttle.Set(simulator); } return(simulator); } else { // Connection failed, remove this simulator from our list and destroy it lock (Simulators) Simulators.Remove(simulator); return(null); } } else if (setDefault) { // We're already connected to this server, but need to set it to the default SetCurrentSim(simulator, seedcaps); // Move in to this simulator Client.Self.CompleteAgentMovement(simulator); // Send an initial AgentUpdate to complete our movement in to the sim if (Client.Settings.SEND_AGENT_UPDATES) { Client.Self.Movement.SendUpdate(true, simulator); } return(simulator); } else { // Already connected to this simulator and wasn't asked to set it as the default, // just return a reference to the existing object return(simulator); } }
/// <summary> /// /// </summary> /// <param name="simulator"></param> public Parcel(Simulator simulator) { Sim = simulator; init(); }
public void RequestTaskInventory(uint objectLocalID, Simulator simulator) { RequestTaskInventoryPacket request = new RequestTaskInventoryPacket(); request.AgentData.AgentID = _Client.Self.AgentID; request.AgentData.SessionID = _Client.Self.SessionID; request.InventoryData.LocalID = objectLocalID; _Client.Network.SendPacket(request, simulator); }
/// <summary> /// Rez an object from inventory /// </summary> /// <param name="simulator">Simulator to place object in</param> /// <param name="rotation">Rotation of the object when rezzed</param> /// <param name="position">Vector of where to place object</param> /// <param name="item">InventoryObject object containing item details</param> /// <param name="groupOwner">LLUUID of group to own the object</param> public LLUUID RequestRezFromInventory(Simulator simulator, LLQuaternion rotation, LLVector3 position, InventoryObject item, LLUUID groupOwner) { return RequestRezFromInventory(simulator, rotation, position, item, groupOwner, LLUUID.Random(), false); }
private void PacketHandler() { IncomingPacket incomingPacket = new IncomingPacket(); Packet packet = null; Simulator simulator = null; while (connected) { // Reset packet to null for the check below packet = null; if (PacketInbox.Dequeue(200, ref incomingPacket)) { packet = incomingPacket.Packet; simulator = incomingPacket.Simulator; if (packet != null) { // Skip the ACK handling on packets synthesized from CAPS messages if (packet.Header.Sequence != 0) { #region ACK accounting // TODO: Replace PacketArchive Queue<> with something more efficient // Check the archives to see whether we already received this packet lock (simulator.PacketArchive) { if (simulator.PacketArchive.Contains(packet.Header.Sequence)) { if (packet.Header.Resent) { Logger.DebugLog("Received resent packet #" + packet.Header.Sequence, Client); } else { Logger.Log(String.Format("Received a duplicate of packet #{0}, current type: {1}", packet.Header.Sequence, packet.Type), Helpers.LogLevel.Warning, Client); } // Avoid firing a callback twice for the same packet continue; } else { // Keep the PacketArchive size within a certain capacity while (simulator.PacketArchive.Count >= Settings.PACKET_ARCHIVE_SIZE) { simulator.PacketArchive.Dequeue(); simulator.PacketArchive.Dequeue(); simulator.PacketArchive.Dequeue(); simulator.PacketArchive.Dequeue(); } simulator.PacketArchive.Enqueue(packet.Header.Sequence); } } #endregion ACK accounting #region ACK handling // Handle appended ACKs if (packet.Header.AppendedAcks) { lock (simulator.NeedAck) { for (int i = 0; i < packet.Header.AckList.Length; i++) { simulator.NeedAck.Remove(packet.Header.AckList[i]); } } } // Handle PacketAck packets if (packet.Type == PacketType.PacketAck) { PacketAckPacket ackPacket = (PacketAckPacket)packet; lock (simulator.NeedAck) { for (int i = 0; i < ackPacket.Packets.Length; i++) { simulator.NeedAck.Remove(ackPacket.Packets[i].ID); } } } #endregion ACK handling } #region FireCallbacks if (Client.Settings.SYNC_PACKETCALLBACKS) { PacketEvents.RaiseEvent(PacketType.Default, packet, simulator); PacketEvents.RaiseEvent(packet.Type, packet, simulator); } else { PacketEvents.BeginRaiseEvent(PacketType.Default, packet, simulator); PacketEvents.BeginRaiseEvent(packet.Type, packet, simulator); } #endregion FireCallbacks } } } }
private void Network_OnEventQueueRunning(Simulator simulator) { Logger.DebugLog("Event queue is running for " + simulator.ToString() + ", enabling uploads", Client); EnableUpload(); }
/// <summary> /// Rez an object from inventory /// </summary> /// <param name="simulator">Simulator to place object in</param> /// <param name="rotation">Rotation of the object when rezzed</param> /// <param name="position">Vector of where to place object</param> /// <param name="item">InventoryObject object containing item details</param> public LLUUID RequestRezFromInventory(Simulator simulator, LLQuaternion rotation, LLVector3 position, InventoryObject item) { return RequestRezFromInventory(simulator, rotation, position, item, _Client.Self.ActiveGroup, LLUUID.Random(), false); }
private void InventoryDescendentsHandler(Packet packet, Simulator simulator) { InventoryDescendentsPacket reply = (InventoryDescendentsPacket)packet; if (reply.AgentData.Descendents > 0) { // InventoryDescendantsReply sends a null folder if the parent doesnt contain any folders if (reply.FolderData[0].FolderID != LLUUID.Zero) { // Iterate folders in this packet for (int i = 0; i < reply.FolderData.Length; i++) { InventoryFolder folder = new InventoryFolder(reply.FolderData[i].FolderID); folder.ParentUUID = reply.FolderData[i].ParentID; folder.Name = Helpers.FieldToUTF8String(reply.FolderData[i].Name); folder.PreferredType = (AssetType)reply.FolderData[i].Type; folder.OwnerID = reply.AgentData.OwnerID; _Store[folder.UUID] = folder; } } // InventoryDescendantsReply sends a null item if the parent doesnt contain any items. if (reply.ItemData[0].ItemID != LLUUID.Zero) { // Iterate items in this packet for (int i = 0; i < reply.ItemData.Length; i++) { if (reply.ItemData[i].ItemID != LLUUID.Zero) { InventoryItem item = CreateInventoryItem((InventoryType)reply.ItemData[i].InvType,reply.ItemData[i].ItemID); item.ParentUUID = reply.ItemData[i].FolderID; item.CreatorID = reply.ItemData[i].CreatorID; item.AssetType = (AssetType)reply.ItemData[i].Type; item.AssetUUID = reply.ItemData[i].AssetID; item.CreationDate = Helpers.UnixTimeToDateTime((uint)reply.ItemData[i].CreationDate); item.Description = Helpers.FieldToUTF8String(reply.ItemData[i].Description); item.Flags = reply.ItemData[i].Flags; item.Name = Helpers.FieldToUTF8String(reply.ItemData[i].Name); item.GroupID = reply.ItemData[i].GroupID; item.GroupOwned = reply.ItemData[i].GroupOwned; item.Permissions = new Permissions( reply.ItemData[i].BaseMask, reply.ItemData[i].EveryoneMask, reply.ItemData[i].GroupMask, reply.ItemData[i].NextOwnerMask, reply.ItemData[i].OwnerMask); item.SalePrice = reply.ItemData[i].SalePrice; item.SaleType = (SaleType)reply.ItemData[i].SaleType; item.OwnerID = reply.AgentData.OwnerID; _Store[item.UUID] = item; } } } } InventoryFolder parentFolder = null; if (_Store.Contains(reply.AgentData.FolderID) && _Store[reply.AgentData.FolderID] is InventoryFolder) { parentFolder = _Store[reply.AgentData.FolderID] as InventoryFolder; } else { _Client.Log("Don't have a reference to FolderID " + reply.AgentData.FolderID.ToString() + " or it is not a folder", Helpers.LogLevel.Error); return; } if (reply.AgentData.Version < parentFolder.Version) { _Client.Log("Got an outdated InventoryDescendents packet for folder " + parentFolder.Name + ", this version = " + reply.AgentData.Version + ", latest version = " + parentFolder.Version, Helpers.LogLevel.Warning); return; } parentFolder.Version = reply.AgentData.Version; // FIXME: reply.AgentData.Descendants is not parentFolder.DescendentCount if we didn't // request items and folders parentFolder.DescendentCount = reply.AgentData.Descendents; #region FindObjectsByPath Handling if (_Searches.Count > 0) { lock (_Searches) { StartSearch: // Iterate over all of the outstanding searches for (int i = 0; i < _Searches.Count; i++) { InventorySearch search = _Searches[i]; List<InventoryBase> folderContents = _Store.GetContents(search.Folder); // Iterate over all of the inventory objects in the base search folder for (int j = 0; j < folderContents.Count; j++) { // Check if this inventory object matches the current path node if (folderContents[j].Name == search.Path[search.Level]) { if (search.Level == search.Path.Length - 1) { _Client.DebugLog("Finished patch search of " + String.Join("/", search.Path)); // This is the last node in the path, fire the callback and clean up if (OnFindObjectByPath != null) { try { OnFindObjectByPath(String.Join("/", search.Path), folderContents[j].UUID); } catch (Exception e) { _Client.Log(e.ToString(), Helpers.LogLevel.Error); } } // Remove this entry and restart the loop since we are changing the collection size _Searches.RemoveAt(i); goto StartSearch; } else { // We found a match but it is not the end of the path, request the next level _Client.DebugLog(String.Format("Matched level {0}/{1} in a path search of {2}", search.Level, search.Path.Length - 1, String.Join("/", search.Path))); search.Folder = folderContents[j].UUID; search.Level++; _Searches[i] = search; RequestFolderContents(search.Folder, search.Owner, true, true, InventorySortOrder.ByName); } } } } } } #endregion FindObjectsByPath Handling // Callback for inventory folder contents being updated if (OnFolderUpdated != null) { try { OnFolderUpdated(parentFolder.UUID); } catch (Exception e) { _Client.Log(e.ToString(), Helpers.LogLevel.Error); } } }
/// <summary> /// Rez an object from inventory /// </summary> /// <param name="simulator">Simulator to place object in</param> /// <param name="rotation">Rotation of the object when rezzed</param> /// <param name="position">Vector of where to place object</param> /// <param name="item">InventoryObject object containing item details</param> /// <param name="groupOwner">LLUUID of group to own the object</param> /// <param name="queryID">User defined queryID to correlate replies</param> /// <param name="requestObjectDetails">if set to true the simulator /// will automatically send object detail packet(s) back to the client</param> public LLUUID RequestRezFromInventory(Simulator simulator, LLQuaternion rotation, LLVector3 position, InventoryObject item, LLUUID groupOwner, LLUUID queryID, bool requestObjectDetails) { RezObjectPacket add = new RezObjectPacket(); add.AgentData.AgentID = _Client.Self.AgentID; add.AgentData.SessionID = _Client.Self.SessionID; add.AgentData.GroupID = groupOwner; add.RezData.FromTaskID = LLUUID.Zero; add.RezData.BypassRaycast = 1; add.RezData.RayStart = position; add.RezData.RayEnd = position; add.RezData.RayTargetID = LLUUID.Zero; add.RezData.RayEndIsIntersection = false; add.RezData.RezSelected = requestObjectDetails; add.RezData.RemoveItem = false; add.RezData.ItemFlags = item.Flags; add.RezData.GroupMask = (uint)item.Permissions.GroupMask; add.RezData.EveryoneMask = (uint)item.Permissions.EveryoneMask; add.RezData.NextOwnerMask = (uint)item.Permissions.NextOwnerMask; add.InventoryData.ItemID = item.UUID; add.InventoryData.FolderID = item.ParentUUID; add.InventoryData.CreatorID = item.CreatorID; add.InventoryData.OwnerID = item.OwnerID; add.InventoryData.GroupID = item.GroupID; add.InventoryData.BaseMask = (uint)item.Permissions.BaseMask; add.InventoryData.OwnerMask = (uint)item.Permissions.OwnerMask; add.InventoryData.GroupMask = (uint)item.Permissions.GroupMask; add.InventoryData.EveryoneMask = (uint)item.Permissions.EveryoneMask; add.InventoryData.NextOwnerMask = (uint)item.Permissions.NextOwnerMask; add.InventoryData.GroupOwned = item.GroupOwned; add.InventoryData.TransactionID = queryID; add.InventoryData.Type = (sbyte)item.InventoryType; add.InventoryData.InvType = (sbyte)item.InventoryType; add.InventoryData.Flags = item.Flags; add.InventoryData.SaleType = (byte)item.SaleType; add.InventoryData.SalePrice = item.SalePrice; add.InventoryData.Name = Helpers.StringToField(item.Name); add.InventoryData.Description = Helpers.StringToField(item.Description); add.InventoryData.CreationDate = (int)Helpers.DateTimeToUnixTime(item.CreationDate); _Client.Network.SendPacket(add, simulator); return queryID; }
private void MoveInventoryItemHandler(Packet packet, Simulator simulator) { MoveInventoryItemPacket move = (MoveInventoryItemPacket)packet; for (int i = 0; i < move.InventoryData.Length; i++) { // FIXME: Do something here string newName = Helpers.FieldToUTF8String(move.InventoryData[i].NewName); _Client.Log(String.Format( "MoveInventoryItemHandler: Item {0} is moving to Folder {1} with new name \"{2}\". Someone write this function!", move.InventoryData[i].ItemID.ToString(), move.InventoryData[i].FolderID.ToString(), newName), Helpers.LogLevel.Warning); } }
private void SaveAssetIntoInventoryHandler(Packet packet, Simulator simulator) { SaveAssetIntoInventoryPacket save = (SaveAssetIntoInventoryPacket)packet; // FIXME: Find this item in the inventory structure and mark the parent as needing an update //save.InventoryData.ItemID; _Client.Log("SaveAssetIntoInventory packet received, someone write this function!", Helpers.LogLevel.Error); }
private void FetchInventoryReplyHandler(Packet packet, Simulator simulator) { FetchInventoryReplyPacket reply = packet as FetchInventoryReplyPacket; foreach (FetchInventoryReplyPacket.InventoryDataBlock dataBlock in reply.InventoryData) { if (dataBlock.InvType == (sbyte)InventoryType.Folder) { _Client.Log("Received FetchInventoryReply for an inventory folder, this should not happen!", Helpers.LogLevel.Error); continue; } InventoryItem item = CreateInventoryItem((InventoryType)dataBlock.InvType,dataBlock.ItemID); item.AssetType = (AssetType)dataBlock.Type; item.AssetUUID = dataBlock.AssetID; item.CreationDate = Helpers.UnixTimeToDateTime(dataBlock.CreationDate); item.CreatorID = dataBlock.CreatorID; item.Description = Helpers.FieldToUTF8String(dataBlock.Description); item.Flags = dataBlock.Flags; item.GroupID = dataBlock.GroupID; item.GroupOwned = dataBlock.GroupOwned; item.Name = Helpers.FieldToUTF8String(dataBlock.Name); item.OwnerID = dataBlock.OwnerID; item.ParentUUID = dataBlock.FolderID; item.Permissions = new Permissions( dataBlock.BaseMask, dataBlock.EveryoneMask, dataBlock.GroupMask, dataBlock.NextOwnerMask, dataBlock.OwnerMask); item.SalePrice = dataBlock.SalePrice; item.SaleType = (SaleType)dataBlock.SaleType; _Store[item.UUID] = item; // Fire the callback for an item being fetched if (OnItemReceived != null) { try { OnItemReceived(item); } catch (Exception e) { _Client.Log(e.ToString(), Helpers.LogLevel.Error); } } } }
/// <summary> /// UpdateCreateInventoryItem packets are received when a new inventory item /// is created. This may occur when an object that's rezzed in world is /// taken into inventory, when an item is created using the CreateInventoryItem /// packet, or when an object is purchased /// </summary> private void UpdateCreateInventoryItemHandler(Packet packet, Simulator simulator) { UpdateCreateInventoryItemPacket reply = packet as UpdateCreateInventoryItemPacket; foreach (UpdateCreateInventoryItemPacket.InventoryDataBlock dataBlock in reply.InventoryData) { if (dataBlock.InvType == (sbyte)InventoryType.Folder) { _Client.Log("Received InventoryFolder in an UpdateCreateInventoryItem packet, this should not happen!", Helpers.LogLevel.Error); continue; } InventoryItem item = CreateInventoryItem((InventoryType)dataBlock.InvType,dataBlock.ItemID); item.AssetType = (AssetType)dataBlock.Type; item.AssetUUID = dataBlock.AssetID; item.CreationDate = Helpers.UnixTimeToDateTime(dataBlock.CreationDate); item.CreatorID = dataBlock.CreatorID; item.Description = Helpers.FieldToUTF8String(dataBlock.Description); item.Flags = dataBlock.Flags; item.GroupID = dataBlock.GroupID; item.GroupOwned = dataBlock.GroupOwned; item.Name = Helpers.FieldToUTF8String(dataBlock.Name); item.OwnerID = dataBlock.OwnerID; item.ParentUUID = dataBlock.FolderID; item.Permissions = new Permissions( dataBlock.BaseMask, dataBlock.EveryoneMask, dataBlock.GroupMask, dataBlock.NextOwnerMask, dataBlock.OwnerMask); item.SalePrice = dataBlock.SalePrice; item.SaleType = (SaleType)dataBlock.SaleType; // Update the local copy _Store[item.UUID] = item; // Look for an "item created" callback ItemCreatedCallback createdCallback; if (_ItemCreatedCallbacks.TryGetValue(dataBlock.CallbackID, out createdCallback)) { _ItemCreatedCallbacks.Remove(dataBlock.CallbackID); try { createdCallback(true, item); } catch (Exception e) { _Client.Log(e.ToString(), Helpers.LogLevel.Error); } } // TODO: Is this callback even triggered when items are copied? // Look for an "item copied" callback ItemCopiedCallback copyCallback; if (_ItemCopiedCallbacks.TryGetValue(dataBlock.CallbackID, out copyCallback)) { _ItemCopiedCallbacks.Remove(dataBlock.CallbackID); try { copyCallback(item); } catch (Exception e) { _Client.Log(e.ToString(), Helpers.LogLevel.Error); } } //This is triggered when an item is received from a task if (OnTaskItemReceived != null) { try { OnTaskItemReceived(item.UUID, dataBlock.FolderID, item.CreatorID, item.AssetUUID, item.InventoryType); } catch (Exception e) { _Client.Log(e.ToString(), Helpers.LogLevel.Error); } } } }
private void Self_OnInstantMessage(InstantMessage im, Simulator simulator) { // TODO: MainAvatar.InstantMessageDialog.GroupNotice can also be an inventory offer, should we // handle it here? if (OnObjectOffered != null && (im.Dialog == InstantMessageDialog.InventoryOffered || im.Dialog == InstantMessageDialog.TaskInventoryOffered)) { AssetType type = AssetType.Unknown; LLUUID objectID = LLUUID.Zero; bool fromTask = false; if (im.Dialog == InstantMessageDialog.InventoryOffered) { if (im.BinaryBucket.Length == 17) { type = (AssetType)im.BinaryBucket[0]; objectID = new LLUUID(im.BinaryBucket, 1); fromTask = false; } else { _Client.Log("Malformed inventory offer from agent", Helpers.LogLevel.Warning); return; } } else if (im.Dialog == InstantMessageDialog.TaskInventoryOffered) { if (im.BinaryBucket.Length == 1) { type = (AssetType)im.BinaryBucket[0]; fromTask = true; } else { _Client.Log("Malformed inventory offer from object", Helpers.LogLevel.Warning); return; } } // Find the folder where this is going to go LLUUID destinationFolderID = FindFolderForType(type); // Fire the callback try { ImprovedInstantMessagePacket imp = new ImprovedInstantMessagePacket(); imp.AgentData.AgentID = _Client.Self.AgentID; imp.AgentData.SessionID = _Client.Self.SessionID; imp.MessageBlock.FromGroup = false; imp.MessageBlock.ToAgentID = im.FromAgentID; imp.MessageBlock.Offline = 0; imp.MessageBlock.ID = im.IMSessionID; imp.MessageBlock.Timestamp = 0; imp.MessageBlock.FromAgentName = Helpers.StringToField(_Client.Self.Name); imp.MessageBlock.Message = new byte[0]; imp.MessageBlock.ParentEstateID = 0; imp.MessageBlock.RegionID = LLUUID.Zero; imp.MessageBlock.Position = _Client.Self.SimPosition; if (OnObjectOffered(im.FromAgentID, im.FromAgentName, im.ParentEstateID, im.RegionID, im.Position, im.Timestamp, type, objectID, fromTask)) { // Accept the inventory offer switch (im.Dialog) { case InstantMessageDialog.InventoryOffered: imp.MessageBlock.Dialog = (byte)InstantMessageDialog.InventoryAccepted; break; case InstantMessageDialog.TaskInventoryOffered: imp.MessageBlock.Dialog = (byte)InstantMessageDialog.TaskInventoryAccepted; break; case InstantMessageDialog.GroupNotice: imp.MessageBlock.Dialog = (byte)InstantMessageDialog.GroupNoticeInventoryAccepted; break; } imp.MessageBlock.BinaryBucket = destinationFolderID.GetBytes(); } else { // Decline the inventory offer switch (im.Dialog) { case InstantMessageDialog.InventoryOffered: imp.MessageBlock.Dialog = (byte)InstantMessageDialog.InventoryDeclined; break; case InstantMessageDialog.TaskInventoryOffered: imp.MessageBlock.Dialog = (byte)InstantMessageDialog.TaskInventoryDeclined; break; case InstantMessageDialog.GroupNotice: imp.MessageBlock.Dialog = (byte)InstantMessageDialog.GroupNoticeInventoryDeclined; break; } imp.MessageBlock.BinaryBucket = new byte[0]; } _Client.Network.SendPacket(imp, simulator); } catch (Exception e) { _Client.Log(e.ToString(), Helpers.LogLevel.Error); } } }
private void BulkUpdateInventoryHandler(Packet packet, Simulator simulator) { BulkUpdateInventoryPacket update = packet as BulkUpdateInventoryPacket; if (update.FolderData.Length > 0 && update.FolderData[0].FolderID != LLUUID.Zero) { foreach (BulkUpdateInventoryPacket.FolderDataBlock dataBlock in update.FolderData) { if (!_Store.Contains(dataBlock.FolderID)) _Client.Log("Received BulkUpdate for unknown folder: " + dataBlock.FolderID, Helpers.LogLevel.Warning); InventoryFolder folder = new InventoryFolder(dataBlock.FolderID); folder.Name = Helpers.FieldToUTF8String(dataBlock.Name); folder.OwnerID = update.AgentData.AgentID; folder.ParentUUID = dataBlock.ParentID; _Store[folder.UUID] = folder; } } if (update.ItemData.Length > 0 && update.ItemData[0].ItemID != LLUUID.Zero) { for (int i = 0; i < update.ItemData.Length; i++) { BulkUpdateInventoryPacket.ItemDataBlock dataBlock = update.ItemData[i]; if (!_Store.Contains(dataBlock.ItemID)) _Client.Log("Received BulkUpdate for unknown item: " + dataBlock.ItemID, Helpers.LogLevel.Warning); InventoryItem item = SafeCreateInventoryItem((InventoryType)dataBlock.InvType, dataBlock.ItemID); item.AssetType = (AssetType)dataBlock.Type; if (dataBlock.AssetID != LLUUID.Zero) item.AssetUUID = dataBlock.AssetID; item.CreationDate = Helpers.UnixTimeToDateTime(dataBlock.CreationDate); item.CreatorID = dataBlock.CreatorID; item.Description = Helpers.FieldToUTF8String(dataBlock.Description); item.Flags = dataBlock.Flags; item.GroupID = dataBlock.GroupID; item.GroupOwned = dataBlock.GroupOwned; item.Name = Helpers.FieldToUTF8String(dataBlock.Name); item.OwnerID = dataBlock.OwnerID; item.ParentUUID = dataBlock.FolderID; item.Permissions = new Permissions( dataBlock.BaseMask, dataBlock.EveryoneMask, dataBlock.GroupMask, dataBlock.NextOwnerMask, dataBlock.OwnerMask); item.SalePrice = dataBlock.SalePrice; item.SaleType = (SaleType)dataBlock.SaleType; _Store[item.UUID] = item; // Look for an "item created" callback ItemCreatedCallback callback; if (_ItemCreatedCallbacks.TryGetValue(dataBlock.CallbackID, out callback)) { _ItemCreatedCallbacks.Remove(dataBlock.CallbackID); try { callback(true, item); } catch (Exception e) { _Client.Log(e.ToString(), Helpers.LogLevel.Error); } } // Look for an "item copied" callback ItemCopiedCallback copyCallback; if (_ItemCopiedCallbacks.TryGetValue(dataBlock.CallbackID, out copyCallback)) { _ItemCopiedCallbacks.Remove(dataBlock.CallbackID); try { copyCallback(item); } catch (Exception e) { _Client.Log(e.ToString(), Helpers.LogLevel.Error); } } } } }
private void DisableSimulatorHandler(Packet packet, Simulator simulator) { Logger.DebugLog("Received a DisableSimulator packet from " + simulator + ", shutting it down", Client); DisconnectSim(simulator, false); }
private void ReplyTaskInventoryHandler(Packet packet, Simulator simulator) { if (OnTaskInventoryReply != null) { ReplyTaskInventoryPacket reply = (ReplyTaskInventoryPacket)packet; try { OnTaskInventoryReply(reply.InventoryData.TaskID, reply.InventoryData.Serial, Helpers.FieldToUTF8String(reply.InventoryData.Filename)); } catch (Exception e) { _Client.Log(e.ToString(), Helpers.LogLevel.Error); } } }
private void SimStatsHandler(Packet packet, Simulator simulator) { if (!Client.Settings.ENABLE_SIMSTATS) { return; } SimStatsPacket stats = (SimStatsPacket)packet; for (int i = 0; i < stats.Stat.Length; i++) { SimStatsPacket.StatBlock s = stats.Stat[i]; switch (s.StatID) { case 0: simulator.Stats.Dilation = s.StatValue; break; case 1: simulator.Stats.FPS = Convert.ToInt32(s.StatValue); break; case 2: simulator.Stats.PhysicsFPS = s.StatValue; break; case 3: simulator.Stats.AgentUpdates = s.StatValue; break; case 4: simulator.Stats.FrameTime = s.StatValue; break; case 5: simulator.Stats.NetTime = s.StatValue; break; case 6: simulator.Stats.OtherTime = s.StatValue; break; case 7: simulator.Stats.PhysicsTime = s.StatValue; break; case 8: simulator.Stats.AgentTime = s.StatValue; break; case 9: simulator.Stats.ImageTime = s.StatValue; break; case 10: simulator.Stats.ScriptTime = s.StatValue; break; case 11: simulator.Stats.Objects = Convert.ToInt32(s.StatValue); break; case 12: simulator.Stats.ScriptedObjects = Convert.ToInt32(s.StatValue); break; case 13: simulator.Stats.Agents = Convert.ToInt32(s.StatValue); break; case 14: simulator.Stats.ChildAgents = Convert.ToInt32(s.StatValue); break; case 15: simulator.Stats.ActiveScripts = Convert.ToInt32(s.StatValue); break; case 16: simulator.Stats.LSLIPS = Convert.ToInt32(s.StatValue); break; case 17: simulator.Stats.INPPS = Convert.ToInt32(s.StatValue); break; case 18: simulator.Stats.OUTPPS = Convert.ToInt32(s.StatValue); break; case 19: simulator.Stats.PendingDownloads = Convert.ToInt32(s.StatValue); break; case 20: simulator.Stats.PendingUploads = Convert.ToInt32(s.StatValue); break; case 21: simulator.Stats.VirtualSize = Convert.ToInt32(s.StatValue); break; case 22: simulator.Stats.ResidentSize = Convert.ToInt32(s.StatValue); break; case 23: simulator.Stats.PendingLocalUploads = Convert.ToInt32(s.StatValue); break; case 24: simulator.Stats.UnackedBytes = Convert.ToInt32(s.StatValue); break; } } }
static void client_OnEventQueueRunning(Simulator sim) { EventQueueRunningEvent.Set(); }
private void MapItemReplyHandler(Packet packet, Simulator simulator) { if (OnGridItems != null) { MapItemReplyPacket reply = (MapItemReplyPacket)packet; GridItemType type = (GridItemType)reply.RequestData.ItemType; List <GridItem> items = new List <GridItem>(); for (int i = 0; i < reply.Data.Length; i++) { string name = Helpers.FieldToUTF8String(reply.Data[i].Name); switch (type) { case GridItemType.AgentLocations: GridAgentLocation location = new GridAgentLocation(); location.GlobalX = reply.Data[i].X; location.GlobalY = reply.Data[i].Y; location.Identifier = name; location.AvatarCount = reply.Data[i].Extra; items.Add(location); break; case GridItemType.Classified: //FIXME: Client.Log("FIXME", Helpers.LogLevel.Error); break; case GridItemType.LandForSale: //FIXME: Client.Log("FIXME", Helpers.LogLevel.Error); break; case GridItemType.MatureEvent: case GridItemType.PgEvent: //FIXME: Client.Log("FIXME", Helpers.LogLevel.Error); break; case GridItemType.Popular: //FIXME: Client.Log("FIXME", Helpers.LogLevel.Error); break; case GridItemType.Telehub: //FIXME: Client.Log("FIXME", Helpers.LogLevel.Error); break; default: Client.Log("Unknown map item type " + type, Helpers.LogLevel.Warning); break; } } try { OnGridItems(type, items); } catch (Exception e) { Client.Log(e.ToString(), Helpers.LogLevel.Error); } } }