Beispiel #1
0
        private async Task InterceptIncomingAsync(DataInterceptedEventArgs continuedFrom = null)
        {
            HPacket packet = await Remote.ReceivePacketAsync().ConfigureAwait(false);

            if (packet != null)
            {
                var args = new DataInterceptedEventArgs(packet, ++_inSteps, false,
                                                        InterceptIncomingAsync, ClientRelayer);

                try { OnDataIncoming(args); }
                catch { args.Restore(); }

                if (!args.IsBlocked && !args.WasRelayed)
                {
                    await SendToClientAsync(args.Packet).ConfigureAwait(false);
                }
                if (!args.HasContinued)
                {
                    args.Continue();
                }
            }
            else
            {
                Disconnect();
            }
        }
        private void OnFurniList(DataInterceptedEventArgs e)
        {
            e.Continue();

            IEnumerable <CHItem> items = CHItem.Parse(e.Packet)
                                         .Where(i => i.TypeId == 3 && !Photos.ContainsKey(i.Id));

            int itemCount = items.Count();

            HabboAlert alert = AlertBuilder.CreateAlert(HabboAlertType.Bubble,
                                                        (itemCount == 0 ? Constants.SCANNING_EMPTY : itemCount.ToString())
                                                        + (itemCount == 1 ? Constants.SCANNING_SINGLE : Constants.SCANNING_MULTI)
                                                        + Constants.SCANNING_INVENTORY_DONE)
                               .WithImageUrl(Constants.BASE_URL + Constants.BUBBLE_ICON_URL);

            Connection.SendToClientAsync(alert.ToPacket(In.NotificationDialog));

            //TODO: Show user the queueu in photo processing pipeline

            _isProcessingItems = true;

            //Send all photo items in inventory to photo data processing pipeline.
            foreach (CHItem item in items)
            {
                var photoItem = PhotoItem.Create(item.Id, item.ExtraData, Hotel, SessionUsername,
                                                 roomId: null);

                _photoPublishingQueue.Enqueue(photoItem);
            }
        }
Beispiel #3
0
        private async Task InterceptOutgoingAsync(DataInterceptedEventArgs continuedFrom = null)
        {
            HPacket packet = await Local.ReceivePacketAsync().ConfigureAwait(false);

            if (packet != null)
            {
                var args = new DataInterceptedEventArgs(packet, ++_outSteps, true,
                                                        InterceptOutgoingAsync, ServerRelayer);

                try { OnDataOutgoing(args); }
                catch { args.Restore(); }

                if (!args.IsBlocked && !args.WasRelayed)
                {
                    await SendToServerAsync(args.Packet).ConfigureAwait(false);
                }
                if (!args.HasContinued)
                {
                    args.Continue();
                }
            }
            else
            {
                Disconnect();
            }
        }
        private void OnItemDataUpdate(DataInterceptedEventArgs e)
        {
            e.Continue();

            int id = int.Parse(e.Packet.ReadUTF8());

            if (!_roomPhotoItems.ContainsKey(id))
            {
                return;
            }

            //TODO: Investigate more, hhbr-r-72288657
            ReadOnlySpan <byte> extraDataRaw = e.Packet.ReadBytes(e.Packet.ReadUInt16());

            if (extraDataRaw.StartsWith(ExtraDataPrefix))
            {
                extraDataRaw = extraDataRaw[4..];
        private async void OnItems(DataInterceptedEventArgs e)
        {
            e.Continue();

            IEnumerable <HWallItem> items = HWallItem.Parse(e.Packet)
                                            .Where(i => i.TypeId == 3 && !Photos.ContainsKey(i.Id) &&
                                                   !_roomPhotoQueue.Contains(i.Id));

            IEnumerable <int> unknownIds = await Api.BatchCheckExistingIdsAsync(items.Select(i => i.Id), Hotel).ConfigureAwait(false);

            int itemCount    = items.Count();
            int unknownCount = unknownIds.Count();

            string alertMessage = (itemCount == 0 ? Constants.SCANNING_EMPTY : itemCount.ToString())
                                  + (itemCount == 0 || itemCount > 1 ? Constants.SCANNING_MULTI : Constants.SCANNING_SINGLE)
                                  + Constants.SCANNING_WALLITEMS_DONE;

            if (unknownCount > 0)
            {
                alertMessage += " " + unknownCount + Constants.SCANNING_WALLITEMS_UNDISC;
            }

            HabboAlert alert = AlertBuilder.CreateAlert(HabboAlertType.Bubble, alertMessage)
                               .WithImageUrl(Constants.BASE_URL + Constants.BUBBLE_ICON_URL);

            await Connection.SendToClientAsync(alert.ToPacket(In.NotificationDialog)).ConfigureAwait(false);

            _isProcessingItems = true;

            foreach (HWallItem item in items)
            {
                if (unknownIds.Contains(item.Id))
                {
                    _roomPhotoQueue.Enqueue(item.Id);
                    _roomPhotoItems.TryAdd(item.Id, item);
                }
                else
                {
                    //TODO: Another pipeline.
                    await GetKnownPhotoByIdAsync(item.Id);
                }
            }
        }
Beispiel #6
0
        private void HandleData(DataInterceptedEventArgs e)
        {
            ModuleItem[] moduleItems = Contractor.GetModuleItems();
            bool         isOutgoing  = (e.Packet.Destination == HDestination.Server);

            foreach (ModuleItem moduleItem in moduleItems)
            {
                if (!moduleItem.IsInitialized)
                {
                    continue;
                }

                ITExtension extension = moduleItem.Extension;
                if (extension == null)
                {
                    continue;
                }

                try
                {
                    if (isOutgoing)
                    {
                        extension.HandleOutgoing(e);
                        extension.Triggers?.HandleOutgoing(e);
                    }
                    else
                    {
                        extension.HandleIncoming(e);
                        extension.Triggers?.HandleIncoming(e);
                    }
                }
                catch (Exception ex)
                {
                    if (!e.HasContinued)
                    {
                        e.Continue();
                    }

                    WriteLog(ex);
                    DisplayModuleException(moduleItem, e, ex);
                }
            }
        }
Beispiel #7
0
        private void HandleData(DataInterceptedEventArgs e)
        {
            ModuleItem[] moduleItems = Contractor.GetModuleItems();
            bool         isOutgoing  = (e.Packet.Destination == HDestination.Server);

            if (Contractor.RemoteModule != null)
            {
                string stamp = DateTime.Now.Ticks.ToString();
                stamp += isOutgoing;
                stamp += e.Step;

                Contractor.DataAwaiters[stamp] =
                    new TaskCompletionSource <DataInterceptedEventArgs>();

                var interceptedData = new HMessage((ushort)(e.Packet.Destination + 4));
                interceptedData.WriteString(stamp);
                interceptedData.WriteInteger(e.Step);
                interceptedData.WriteBoolean(e.IsBlocked);
                interceptedData.WriteInteger(e.Packet.Length + 4);
                interceptedData.WriteBytes(e.Packet.ToBytes());
                Contractor.RemoteModule.SendAsync(interceptedData);

                DataInterceptedEventArgs args = Contractor
                                                .DataAwaiters[stamp].Task.Result;

                if (args != null)
                {
                    e.Packet    = args.Packet;
                    e.IsBlocked = args.IsBlocked;
                }
                Contractor.DataAwaiters.Remove(stamp);
            }

            foreach (ModuleItem moduleItem in moduleItems)
            {
                if (!moduleItem.IsInitialized)
                {
                    continue;
                }

                ITExtension extension = moduleItem.Extension;
                if (extension == null)
                {
                    continue;
                }

                try
                {
                    if (isOutgoing)
                    {
                        extension.HandleOutgoing(e);
                        extension.Triggers?.HandleOutgoing(e);
                    }
                    else
                    {
                        extension.HandleIncoming(e);
                        extension.Triggers?.HandleIncoming(e);
                    }
                }
                catch (Exception ex)
                {
                    if (!e.HasContinued)
                    {
                        e.Continue();
                    }

                    WriteLog(ex);
                    DisplayModuleException(moduleItem, e, ex);
                }
            }
        }
Beispiel #8
0
            private void HandleData(DataInterceptedEventArgs e)
            {
                string identifier = e.Timestamp.Ticks.ToString();

                identifier += e.IsOutgoing;
                identifier += e.Step;
                try
                {
                    var interceptedData = new EvaWirePacket(1);
                    interceptedData.Write(identifier);

                    interceptedData.Write(e.Step);
                    interceptedData.Write(e.IsOutgoing);
                    interceptedData.Write(e.Packet.Format.Name);
                    interceptedData.Write(e.IsContinuable && !e.HasContinued);

                    interceptedData.Write(e.GetOriginalData().Length);
                    interceptedData.Write(e.GetOriginalData());

                    interceptedData.Write(e.IsOriginal);
                    if (!e.IsOriginal)
                    {
                        byte[] curPacketData = e.Packet.ToBytes();
                        interceptedData.Write(curPacketData.Length);
                        interceptedData.Write(curPacketData);
                    }

                    _module.DataAwaiters.Add(identifier, new TaskCompletionSource <HPacket>());
                    _module.Node.SendPacketAsync(interceptedData);

                    HPacket handledDataPacket = _module.DataAwaiters[identifier].Task.Result;
                    if (handledDataPacket == null)
                    {
                        return;
                    }
                    // This packet contains the identifier at the start, although we do not read it here.

                    bool isContinuing = handledDataPacket.ReadBoolean();
                    if (isContinuing)
                    {
                        _module.DataAwaiters[identifier] = new TaskCompletionSource <HPacket>();

                        bool wasRelayed = handledDataPacket.ReadBoolean();
                        e.Continue(wasRelayed);

                        if (wasRelayed)
                        {
                            return;             // We have nothing else to do here, packet has already been sent/relayed.
                        }
                        handledDataPacket = _module.DataAwaiters[identifier].Task.Result;
                        isContinuing      = handledDataPacket.ReadBoolean(); // We can ignore this one.
                    }

                    int    newPacketLength = handledDataPacket.ReadInt32();
                    byte[] newPacketData   = handledDataPacket.ReadBytes(newPacketLength);

                    e.Packet    = e.Packet.Format.CreatePacket(newPacketData);
                    e.IsBlocked = handledDataPacket.ReadBoolean();
                }
                finally { _module.DataAwaiters.Remove(identifier); }
            }