예제 #1
0
 public AuctionResult(SaveAuction a)
 {
     AuctionId  = a.Uuid;
     HighestBid = a.HighestBidAmount;
     ItemName   = a.ItemName;
     End        = a.End;
 }
예제 #2
0
        public int GetOrCreateItemIdForAuction(SaveAuction auction, HypixelContext context)
        {
            var clearedName = ItemReferences.RemoveReforgesAndLevel(auction.ItemName);
            var tag         = GetIdForName(auction.Tag ?? clearedName);

            if (tag != null && TagLookup.TryGetValue(tag, out int value))
            {
                return(value);
            }

            Console.WriteLine($"Creating item {clearedName} ({auction.ItemName},{auction.Tag})");
            // doesn't exist yet, create it
            var itemByTag = context.Items.Where(item => item.Tag == auction.Tag).FirstOrDefault();

            if (itemByTag != null)
            {
                // new alternative name
                if (clearedName != null)
                {
                    this.ReverseNames[clearedName] = auction.Tag;
                }
                TagLookup.Add(auction.Tag, itemByTag.Id);
                var exists = context.AltItemNames
                             .Where(name => name.Name == clearedName && name.DBItemId == itemByTag.Id)
                             .Any();
                if (!exists)
                {
                    context.AltItemNames.Add(new AlternativeName()
                    {
                        DBItemId = itemByTag.Id, Name = clearedName
                    });
                }
                return(itemByTag.Id);
            }
            Console.WriteLine($"!! completely new !! {JsonConvert.SerializeObject(auction)}");
            // new Item
            //var tempAuction = new Hypixel.NET.SkyblockApi.Auction(){Category=auction.Category,};
            //AddNewItem(tempAuction,auction.ItemName,auction.Tag,null);
            var item = new DBItem()
            {
                Tag   = auction.Tag,
                Name  = auction.ItemName,
                Names = new List <AlternativeName>()
                {
                    new AlternativeName()
                    {
                        Name = auction.ItemName
                    }
                }
            };

            if (item.Tag == null)
            {
                // unindexable item
                return(MAX_MEDIUM_INT);
            }
            ToFillDetails[item.Tag] = item;
            return(AddItemToDB(item));
            //throw new CoflnetException("can_add","can't add this item");
        }
예제 #3
0
        private static void NumberAuction(HypixelContext context, SaveAuction auction)
        {
            auction.SellerId = GetOrCreatePlayerId(context, auction.AuctioneerId);

            if (auction.SellerId == 0)
            {
                // his player has not yet received his number
                return;
            }

            if (auction.ItemId == 0)
            {
                var id = ItemDetails.Instance.GetOrCreateItemIdForAuction(auction, context);
                auction.ItemId = id;


                foreach (var enchant in auction.Enchantments)
                {
                    enchant.ItemType = auction.ItemId;
                }
            }


            context.Auctions.Update(auction);
        }
예제 #4
0
 private static void WaitForDatabaseCreation()
 {
     try
     {
         using (var context = new HypixelContext())
         {
             try
             {
                 var testAuction = new SaveAuction()
                 {
                     Uuid = "00000000000000000000000000000000"
                 };
                 context.Auctions.Add(testAuction);
                 context.SaveChanges();
                 context.Auctions.Remove(testAuction);
                 context.SaveChanges();
             }
             catch (Exception)
             {
                 // looks like db doesn't exist yet
                 Console.WriteLine("Waiting for db creating in the background");
                 System.Threading.Thread.Sleep(10000);
             }
             // TODO: switch to .Migrate()
             context.Database.Migrate();
         }
     }
     catch (Exception e)
     {
         Console.WriteLine($"Waiting for db creating in the background {e.Message} {e.InnerException?.Message}");
         System.Threading.Thread.Sleep(10000);
     }
 }
예제 #5
0
 private static void MigrateAuction(SaveAuction auction)
 {
     if (auction.Reforge == ItemReferences.Reforge.Migration)
     {
         auction.Reforge = ItemReferences.Reforge.Unknown;
     }
 }
예제 #6
0
        public void Outbid(SubscribeItem sub, SaveAuction auction, SaveBids bid)
        {
            var outBidBy = auction.HighestBidAmount - bid.Amount;
            var text     = $"You were outbid on {auction.ItemName} by {PlayerSearch.Instance.GetNameWithCache(auction.Bids.FirstOrDefault().Bidder)} by {outBidBy}";

            Task.Run(() => Send(sub.UserId, "Outbid", text, AuctionUrl(auction), ItemIconUrl(auction.Tag), FormatAuction(auction))).ConfigureAwait(false);
        }
예제 #7
0
        private static void AddToQueue(SaveAuction auction)
        {
            auctionsQueue.Enqueue(auction);

            if (QueueCount > MAX_QUEUE_SIZE)
            {
                PersistQueueBatch();
            }
        }
예제 #8
0
 public void PushOrIgnore(SaveAuction auction)
 {
     NotifyChange(auction.Uuid, auction);
     NotifyChange(auction.AuctioneerId, auction);
     foreach (var bids in auction.Bids)
     {
         NotifyChange(bids.Bidder, auction);
     }
 }
예제 #9
0
 public AuctionResult(SaveAuction a)
 {
     AuctionId   = a.Uuid;
     HighestBid  = a.HighestBidAmount;
     ItemName    = a.ItemName;
     End         = a.End;
     Tag         = a.Tag;
     StartingBid = a.StartingBid;
     Bin         = a.Bin;
 }
예제 #10
0
 public ItemIndexElement(SaveAuction auction) : this(
         auction.Uuid,
         auction.End,
         auction.HighestBidAmount,
         ItemReferences.GetReforges(auction.ItemName),
         auction.Enchantments,
         auction.Count,
         (short)auction.Bids.Count)
 {
 }
예제 #11
0
        private static int DetermineWorth(int c, SaveAuction auction)
        {
            var price = auction.HighestBidAmount == 0 ? auction.StartingBid : auction.HighestBidAmount;

            if (price > 500_000)
            {
                return(c + 1);
            }
            return(c - 20);
        }
예제 #12
0
 private static BidResult NewBidResult(SaveAuction a, SaveBids highestOwn)
 {
     return(new BidResult()
     {
         AuctionId = a.Uuid,
         HighestBid = a.Bids.Last().Amount,
         HighestOwnBid = highestOwn.Amount,
         ItemName = a.ItemName,
         End = a.End
     });
 }
예제 #13
0
 private static AveragePrice AverageFromAuction(SaveAuction auction)
 {
     return(new AveragePrice()
     {
         Avg = auction.HighestBidAmount,
         Date = auction.End,
         Volume = auction.Count,
         Min = auction.HighestBidAmount,
         Max = auction.HighestBidAmount,
         ItemId = auction.ItemId
     });
 }
예제 #14
0
        public static void FillDetails(SaveAuction auction, string itemBytes)
        {
            var f = File(Convert.FromBase64String(itemBytes));
            var a = f.RootTag.ToString();

            auction.Tag           = ItemID(f).Truncate(40);
            auction.Enchantments  = Enchantments(f);
            auction.AnvilUses     = AnvilUses(f);
            auction.Count         = Count(f);
            auction.ItemCreatedAt = GetDateTime(f);
            auction.Reforge       = GetReforge(f);
            auction.NbtData       = new NbtData(f);
        }
예제 #15
0
        /// <summary>
        /// Called from <see cref="BinUpdater"/>
        /// </summary>
        /// <param name="auction"></param>
        public void BinSold(SaveAuction auction)
        {
            var key = auction.AuctioneerId;

            NotifyIfExisting(this.Sold, key, sub =>
            {
                NotificationService.Instance.Sold(sub, auction);
            });
            NotifyIfExisting(this.AuctionSub, auction.Uuid, sub =>
            {
                NotificationService.Instance.AuctionOver(sub, auction);
            });
        }
예제 #16
0
            public BidResult(SaveAuction a, string userUuid)
            {
                var highestOwn = a.Bids?.Where(bid => bid.Bidder == userUuid)
                                 .OrderByDescending(bid => bid.Amount).FirstOrDefault();

                AuctionId = a.Uuid;
                if (a.Bids != null)
                {
                    HighestBid = a.Bids.Last().Amount;
                }
                if (highestOwn != null)
                {
                    HighestOwnBid = highestOwn.Amount;
                }
                ItemName = a.ItemName;
                End      = a.End;
                Tag      = a.Tag;
            }
예제 #17
0
        public static void GrabAuctions(HypixelApi hypixelApi)
        {
            var expired  = hypixelApi.getAuctionsEnded();
            var auctions = expired.Auctions.Select(item =>
            {
                var a = new SaveAuction()
                {
                    Uuid         = item.Uuid,
                    AuctioneerId = item.Seller,
                    Bids         = new List <SaveBids>()
                    {
                        new SaveBids()
                        {
                            Amount    = item.Price,
                            Bidder    = item.Buyer,
                            Timestamp = item.TimeStamp,
                            ProfileId = "unknown"
                        }
                    },
                    HighestBidAmount = item.Price,
                    Bin = item.BuyItemNow,
                    End = DateTime.Now,
                    UId = AuctionService.Instance.GetId(item.Uuid)
                };

                NBT.FillDetails(a, item.ItemBytes);
                return(a);
            }).ToList();

            SoldLastMin = auctions;
            Indexer.AddToQueue(auctions);

            Task.Run(() =>
            {
                foreach (var item in auctions)
                {
                    SubscribeEngine.Instance.BinSold(item);
                    Flipper.FlipperEngine.Instance.AuctionSold(item);
                }
            }).ConfigureAwait(false);
            Console.WriteLine($"Updated {expired.Auctions.Count} bin sells eg {expired.Auctions.First().Uuid}");
        }
예제 #18
0
 /// <summary>
 /// Called from the <see cref="Indexer"/>
 /// </summary>
 /// <param name="auction"></param>
 public void NewBids(SaveAuction auction)
 {
     foreach (var bid in auction.Bids.OrderByDescending(b => b.Amount).Skip(1))
     {
         NotifyIfExisting(this.outbid, bid.Bidder, sub =>
         {
             NotificationService.Instance.Outbid(sub, auction, bid);
         });
     }
     NotifyIfExisting(this.AuctionSub, auction.Uuid, sub =>
     {
         NotificationService.Instance.NewBid(sub, auction, auction.Bids.OrderBy(b => b.Amount).Last());
     });
     foreach (var bid in auction.Bids)
     {
         NotifyIfExisting(UserAuction, bid.Bidder, sub =>
         {
             sub.NotifyAuction(auction);
         });
     }
 }
예제 #19
0
 /// <summary>
 /// Called from <see cref="Updater"/>
 /// </summary>
 /// <param name="auction"></param>
 public void NewAuction(SaveAuction auction)
 {
     if (this.PriceUpdate.TryGetValue(auction.Tag, out ConcurrentBag <SubscribeItem> subscribers))
     {
         foreach (var item in subscribers)
         {
             if ((auction.StartingBid < item.Price && item.Type.HasFlag(SubscribeItem.SubType.PRICE_LOWER_THAN) ||
                  auction.StartingBid > item.Price && item.Type.HasFlag(SubscribeItem.SubType.PRICE_HIGHER_THAN)) &&
                 (!item.Type.HasFlag(SubscribeItem.SubType.BIN) || auction.Bin))
             {
                 NotificationService.Instance.AuctionPriceAlert(item, auction);
             }
         }
     }
     if (this.UserAuction.TryGetValue(auction.AuctioneerId, out subscribers))
     {
         foreach (var item in subscribers)
         {
             item.NotifyAuction(auction);
         }
     }
 }
예제 #20
0
        private static void UpdateAuction(HypixelContext context, BidComparer comparer, SaveAuction auction, SaveAuction dbauction)
        {
            if (auction.AuctioneerId == null)
            {
                // an ended auction
                dbauction.End = auction.End;
                context.Auctions.Update(dbauction);
                return;
            }
            SubscribeEngine.Instance.NewBids(auction);
            foreach (var bid in auction.Bids)
            {
                bid.Auction = dbauction;
                if (!dbauction.Bids.Contains(bid, comparer))
                {
                    context.Bids.Add(bid);
                    dbauction.HighestBidAmount = auction.HighestBidAmount;
                }
            }
            if (auction.Bin)
            {
                dbauction.Bin = true;
            }
            if (dbauction.ItemName == null)
            {
                dbauction.ItemName = auction.ItemName;
            }
            if (dbauction.ProfileId == null)
            {
                dbauction.ProfileId = auction.ProfileId;
            }
            if (dbauction.Start == default(DateTime))
            {
                dbauction.Start = auction.Start;
            }
            dbauction.End = auction.End;
            if (dbauction.Category == Category.UNKNOWN)
            {
                dbauction.Category = auction.Category;
            }

            // update
            context.Auctions.Update(dbauction);
        }
예제 #21
0
        internal void Sold(SubscribeItem sub, SaveAuction auction)
        {
            var text = $"{auction.ItemName} was sold to {PlayerSearch.Instance.GetNameWithCache(auction.Bids.FirstOrDefault().Bidder)} for {auction.HighestBidAmount}";

            Task.Run(() => Send(sub.UserId, "Item Sold", text, AuctionUrl(auction), ItemIconUrl(auction.Tag), FormatAuction(auction))).ConfigureAwait(false);
        }
예제 #22
0
 public void AddNew(SaveAuction auction)
 {
     AddNew(AverageFromAuction(auction));
 }
예제 #23
0
 private static SaveBids FindHighestOwnBid(Player databaseResult, SaveAuction a)
 {
     return(a.Bids.Where(bid => bid.Bidder == databaseResult.UuId)
            .OrderByDescending(bid => bid.Amount).FirstOrDefault());
 }
예제 #24
0
        public void NewBid(SubscribeItem sub, SaveAuction auction, SaveBids bid)
        {
            var text = $"New bid on {auction.ItemName} by {PlayerSearch.Instance.GetNameWithCache(auction.Bids.FirstOrDefault().Bidder)} for {auction.HighestBidAmount}";

            Task.Run(() => Send(sub.UserId, "New bid", text, AuctionUrl(auction), ItemIconUrl(auction.Tag), auction)).ConfigureAwait(false);
        }
 public override async void NotifyAuction(SaveAuction auction)
 {
     OnNewAuction(auction);
     if (this.GeneratedAt < DateTime.Now - TimeSpan.FromMinutes(10))
         await SubscribeEngine.Instance.Unsubscribe(this.UserId, this.TopicId, this.Type);
 }
예제 #26
0
        internal void AuctionOver(SubscribeItem sub, SaveAuction auction)
        {
            var text = $"Highest bid is {auction.HighestBidAmount}";

            Task.Run(() => Send(sub.UserId, $"Auction for {auction.ItemName} ended", text, AuctionUrl(auction), ItemIconUrl(auction.Tag), FormatAuction(auction))).ConfigureAwait(false);
        }
예제 #27
0
        // builds the index for all auctions in the last hour

        Task <int> Save(GetAuctionPage res, DateTime lastUpdate, ConcurrentDictionary <string, bool> activeUuids)
        {
            int count = 0;

            var processed = res.Auctions.Where(item =>
            {
                activeUuids[item.Uuid] = true;
                // nothing changed if the last bid is older than the last update
                return(!(item.Bids.Count > 0 && item.Bids[item.Bids.Count - 1].Timestamp < lastUpdate ||
                         item.Bids.Count == 0 && item.Start < lastUpdate));
            })
                            .Select(a =>
            {
                if (Program.Migrated)
                {
                    ItemDetails.Instance.AddOrIgnoreDetails(a);
                }
                count++;
                var auction = new SaveAuction(a);
                return(auction);
            }).ToList();


            if (DateTime.Now.Minute % 30 == 7)
            {
                foreach (var a in res.Auctions)
                {
                    var auction = new SaveAuction(a);
                    AuctionCount.AddOrUpdate(auction.Tag, k =>
                    {
                        return(DetermineWorth(0, auction));
                    }, (k, c) =>
                    {
                        return(DetermineWorth(c, auction));
                    });
                }
            }

            var ended = res.Auctions.Where(a => a.End < DateTime.Now).Select(a => new SaveAuction(a));

            /* var variableHereToRemoveWarning = taskFactory.StartNew(async () =>
             * {
             *   await Task.Delay(TimeSpan.FromSeconds(20));
             *   await ItemPrices.Instance.AddEndedAuctions(ended);
             * });*/


            if (Program.FullServerMode)
            {
                Indexer.AddToQueue(processed);
            }
            else
            {
                FileController.SaveAs($"apull/{DateTime.Now.Ticks}", processed);
            }


            var started = processed.Where(a => a.Start > lastUpdate).ToList();

            // do not slow down the update
            var min = DateTime.Now - TimeSpan.FromMinutes(15);

            Flipper.FlipperEngine.Instance.NewAuctions(started.Where(a => a.Start > min));
            foreach (var auction in started)
            {
                SubscribeEngine.Instance.NewAuction(auction);
            }

            return(Task.FromResult(count));
        }
예제 #28
0
 string AuctionUrl(SaveAuction auction)
 {
     return(BaseUrl + "/auction/" + auction.Uuid);
 }
예제 #29
0
 private object FormatAuction(SaveAuction auction)
 {
     return(new { type = "auction", auction = JsonConvert.SerializeObject(auction) });
 }
예제 #30
0
        internal void AuctionPriceAlert(SubscribeItem sub, SaveAuction auction)
        {
            var text = $"New Auction for {auction.ItemName} for {auction.StartingBid}";

            Task.Run(() => Send(sub.UserId, $"Price Alert", text, AuctionUrl(auction), ItemIconUrl(auction.Tag), FormatAuction(auction))).ConfigureAwait(false);
        }