public static Task EnqueuePackets(IEnumerable <BasePacket> packets, QueuePriority priority = QueuePriority.Low,
                                          bool delaySend = true, CancellationToken cancellationToken = default)
        {
            lock ( _actionPacketQueueLock )
            {
                if (_actionPacketQueue.Count() > Options.CurrentOptions.UseObjectQueueAmount)
                {
                    Commands.SystemMessage(Strings.Object_queue_full, (int)Commands.SystemMessageHues.Yellow, true,
                                           true);

                    return(Task.CompletedTask);
                }

                List <EventWaitHandle> handles = new List <EventWaitHandle>();

                foreach (BasePacket packet in packets)
                {
                    byte[] data = packet.ToArray();

                    PacketQueueItem packetQueueItem =
                        new PacketQueueItem(data, data.Length, delaySend)
                    {
                        Token = cancellationToken
                    };
                    handles.Add(packetQueueItem.WaitHandle);

                    _actionPacketQueue.Enqueue(packetQueueItem, priority);
                }

                return(handles.ToTask());
            }
        }
Exemplo n.º 2
0
        public static Task EnqueuePacket(PacketQueueItem packetQueueItem, QueuePriority priority)
        {
            lock ( _actionPacketQueueLock )
            {
                _actionPacketQueue.Enqueue(packetQueueItem, priority);

                return(packetQueueItem.WaitHandle.ToTask());
            }
        }
        //TODO Change to ActionQueueItem with CancellationToken
        public static Task EnqueueDragDropGround(int serial, int amount, int x, int y, int z,
                                                 QueuePriority priority = QueuePriority.Low, bool delaySend = true)
        {
            lock ( _actionPacketQueueLock )
            {
                byte[] dragPacket = new DragItem(serial, amount).ToArray();
                byte[] dropItem   = new DropItem(serial, -1, x, y, z).ToArray();

                PacketQueueItem dragPacketQueueItem = new PacketQueueItem(dragPacket, dragPacket.Length, delaySend);
                _actionPacketQueue.Enqueue(dragPacketQueueItem, priority);

                PacketQueueItem dropPacketQueueItem = new PacketQueueItem(dropItem, dropItem.Length, delaySend);
                _actionPacketQueue.Enqueue(dropPacketQueueItem, priority);

                return(new[] { dragPacketQueueItem.WaitHandle, dropPacketQueueItem.WaitHandle }.ToTask());
            }
        }
        public static Task EnqueuePacket(PacketQueueItem packetQueueItem, QueuePriority priority)
        {
            lock ( _actionPacketQueueLock )
            {
                if (_actionPacketQueue.Count() > Options.CurrentOptions.UseObjectQueueAmount)
                {
                    Commands.SystemMessage(Strings.Object_queue_full, (int)Commands.SystemMessageHues.Yellow, true,
                                           true);

                    return(Task.CompletedTask);
                }

                _actionPacketQueue.Enqueue(packetQueueItem, priority);

                return(packetQueueItem.WaitHandle.ToTask());
            }
        }
Exemplo n.º 5
0
        public static Task EnqueueActionPackets(IEnumerable <BasePacket> packets,
                                                QueuePriority priority = QueuePriority.Low, bool delaySend = true)
        {
            lock ( _actionPacketQueueLock )
            {
                List <EventWaitHandle> handles = new List <EventWaitHandle>();

                foreach (BasePacket packet in packets)
                {
                    byte[] data = packet.ToArray();

                    PacketQueueItem packetQueueItem = new PacketQueueItem(data, data.Length, delaySend);
                    handles.Add(packetQueueItem.WaitHandle);

                    _actionPacketQueue.Enqueue(packetQueueItem, priority);
                }

                return(handles.ToTask());
            }
        }