Beispiel #1
0
        public SP_OutboxSend(User usr)
        {
            newPacket(30752);
            addBlock(1117);
            addBlock(1);
            addBlock(usr.dinar);
            addBlock(0);
            addBlock(usr.cash);
            addBlock("LIST");
            addBlock(usr.OutboxItems.Count);
            var sortedDictionary = usr.OutboxItems.OrderByDescending(i => i.Key).ToList();

            foreach (var i in sortedDictionary)
            {
                OutboxItem Item = i.Value;
                addBlock(Item.id);
                addBlock(usr.userId);
                addBlock(Item.itemcode);
                addBlock((Item.count > 1 ? Item.count : Item.days));
                addBlock("NULL");
                addBlock("NULL");
                addBlock(usr.nickname);
                addBlock(0);
            }
            addBlock(1);
            addBlock(Inventory.Itemlist(usr));
            addBlock(usr.AvailableSlots); //Slots Enabled
            addBlock(Inventory.Costumelist(usr));
            addBlock(0);
            addBlock(1);
        }
Beispiel #2
0
        public override void Handle(User usr)
        {
            SubCodes subcode  = (SubCodes)int.Parse(getBlock(0));
            int      outboxId = int.Parse(getBlock(1));

            switch (subcode)
            {
            case SubCodes.Delete:
            {
                if (usr.OutboxItems.Count <= 0)
                {
                    return;
                }
                string itemCode = getBlock(4);

                if (Inventory.HasOutboxItem(usr, itemCode))
                {
                    Inventory.RemoveOutBoxItem(usr, outboxId);
                    usr.send(new SP_Outbox(usr));
                }
                break;
            }

            case SubCodes.Activate:
            {
                if (usr.OutboxItems.Count <= 0)
                {
                    return;
                }
                string itemCode = getBlock(4);

                if (Inventory.HasOutboxItem(usr, itemCode))
                {
                    bool found = usr.OutboxItems.Values.Where(r => r.id == outboxId).Count() > 0;
                    if (found)
                    {
                        OutboxItem i    = usr.OutboxItems.Values.Where(r => r.id == outboxId).FirstOrDefault();
                        int        days = i.days;
                        if (Inventory.GetFreeItemSlotCount(usr) > 0)
                        {
                            Managers.Item item = Managers.ItemManager.GetItem(i.itemcode);
                            if (item != null)
                            {
                                Inventory.PerformAddItem(usr, itemCode, days, i.count);
                                Inventory.RemoveOutBoxItem(usr, outboxId);
                                usr.send(new SP_OutboxUse(usr, itemCode));
                                usr.send(new SP_Outbox(usr));
                            }
                        }
                        else
                        {
                            usr.send(new SP_DinarItemBuy(SP_DinarItemBuy.ErrorCodes.InventoryFull));
                        }
                    }
                }
                break;
            }
            }
        }
        protected virtual async Task Dispatch(OutboxItem item, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();
            await Producer.Produce(item);

            Remove(item);
            Logger.Information <OutboxDispatcher>($"Dispatched {item}");
        }
        public virtual async Task Produce(OutboxItem item)
        {
            string topic     = GetTopic(item);
            string key       = GetKey(item);
            string message   = GetMessage(item);
            int    partition = GetPartition(item.EntityId);

            await Produce(new KafkaMessage(topic, partition, key, message));
        }
Beispiel #5
0
        private IEvent TransformEvent(IEvent eventToPublish, OutboxItem item)
        {
            var transformer = _transformerLookUp.LookUpTransformer(eventToPublish);

            if (transformer != null)
            {
                eventToPublish = transformer.Transform(eventToPublish);
                _logger.LogInformation($"Event '{item.EventType}-{item.EventId}' Transformed");
            }
            return(eventToPublish);
        }
        public override byte[] PrepareToSend(byte[] data)
        {
            data = InternalChannel.PrepareToSend(data);
            byte[] sequenceBytes = BitConverter.GetBytes(_outgoingSequence);
            var    newData       = new byte[data.Length + sequenceBytes.Length];

            Array.Copy(sequenceBytes, 0, newData, 0, sequenceBytes.Length);
            Array.Copy(data, 0, newData, sequenceBytes.Length, data.Length);
            if (_sendAcks)
            {
                lock (_outboxLock)
                {
                    _outbox[_outgoingSequence] = new OutboxItem()
                    {
                        data = newData, nextSendTime = DateTime.UtcNow.Ticks + ACK_TIMEOUT_DURATION_IN_TICKS
                    };
                }
            }
            _outgoingSequence++;
            return(newData);
        }
Beispiel #7
0
        public override byte[] PrepareToSend(byte[] data)
        {
            data = InternalChannel.PrepareToSend(data);
            byte[] sequenceBytes = BitConverter.GetBytes(_outgoingSequence);
            var    newData       = new byte[data.Length + sequenceBytes.Length];

            Array.Copy(sequenceBytes, 0, newData, 0, sequenceBytes.Length);
            Array.Copy(data, 0, newData, sequenceBytes.Length, data.Length);
            if (_sendAcks)
            {
                lock (_outboxLock)
                {
                    _outbox[_outgoingSequence] = new OutboxItem()
                    {
                        data = newData, lastSendTime = DateTime.UtcNow.Ticks
                    };
                }
            }
            _outgoingSequence++;
            //UnityEngine.Debug.LogError("Prepare: " + GetType().ToString() + ": " + DeBox.Teleport.Debugging.TeleportDebugUtils.DebugString(newData));
            return(newData);
        }
 public virtual void Remove(OutboxItem item)
 {
     Logger.Debug <OutboxRepository>($"Removing {item}");
     Context.Outbox.Remove(item);
     RetryPolicy.Execute(() => Context.SaveChanges());
 }
 protected virtual void Remove(OutboxItem item)
 {
     Repository.Remove(item);
 }
 protected virtual string GetTopic(OutboxItem item)
 {
     return(item.Context);
 }
 protected virtual string GetMessage(OutboxItem item)
 {
     return(item.Message);
 }
 protected virtual string GetKey(OutboxItem item)
 {
     return($"{item.Entity}:{item.EntityId}:{item.Type}:{item.Id}");
 }