Exemplo n.º 1
0
        private static async Task FillLastHour()
        {
            var end          = DateTime.Now.RoundDown(TimeSpan.FromHours(1));
            var start        = end - TimeSpan.FromMinutes(60);
            var removeBefore = start - TimeSpan.FromDays(1);

            using (var context = new HypixelContext())
            {
                foreach (var itemId in ItemDetails.Instance.TagLookup.Values)
                {
                    var select = AuctionSelect(start, end, context, itemId);
                    await UpdateAuctionsInRedis(itemId, select, removeBefore);
                }
            }
            await UpdateBazaarFor(start, end, removeBefore);
        }
Exemplo n.º 2
0
        public override async Task Execute(MessageData data)
        {
            var response = data.GetAs <PlayerSyncCommand.PlayerSyncData>();
            var players  = response.Players;
            var ids      = players.Select(p => p.UuId);

            if (players.Count == 0)
            {
                return; // done
            }
            int count = 0;

            using (var context = new HypixelContext())
            {
                var existingPlayers = context.Players.Where(p => ids.Contains(p.UuId));
                var existing        = existingPlayers.ToDictionary(p => p.UuId);
                foreach (var player in players)
                {
                    if (existing.ContainsKey(player.UuId))
                    {
                        var existingPlayer = existingPlayers.Where(p => p.UuId == player.UuId).FirstOrDefault();
                        if (existingPlayer.Name == null)
                        {
                            existingPlayer.Name = player.Name;
                            context.Update(existingPlayer);
                        }
                        continue;
                    }
                    context.Players.Add(player);
                    count++;
                    if (count % 1000 == 0)
                    {
                        await context.SaveChangesAsync();
                    }
                }
                try
                {
                    await context.SaveChangesAsync();
                }
                catch (Exception e)
                {
                    dev.Logger.Instance.Error(e, "playerSync");
                }
                count = context.Players.Count();
            }
            await data.SendBack(data.Create("playerSync", response.Offset));
        }
Exemplo n.º 3
0
 public override Task Execute(MessageData data)
 {
     using (var context = new HypixelContext())
     {
         var items = context.Items.OrderByDescending(p => p.Id)
                     .Select(i => new { IconUrl = i.IconUrl, Name = i.Names.Where(n => n.Name != null && n.Name != "null").FirstOrDefault(), Tag = i.Tag })
                     .Where(i => i.Name != null)
                     .Take(50)
                     .ToList()
                     .Select(i => new Response()
         {
             IconUrl = i.IconUrl, Name = i.Name.Name, Tag = i.Tag
         })
                     .ToList();
         return(data.SendBack(data.Create("newItemsResponse", items, A_HOUR)));
     }
 }
Exemplo n.º 4
0
        public async Task FillHours(System.Threading.CancellationToken token)
        {
            await Task.Delay(1000);

            using (var context = new HypixelContext())
            {
                context.Database.SetCommandTimeout(3600);
                foreach (var itemId in ItemDetails.Instance.TagLookup.Values.ToList())
                {
                    var select = AuctionSelect(DateTime.Now - TimeSpan.FromDays(1), DateTime.Now, context, itemId);
                    await UpdateAuctionsInRedis(itemId, select);

                    if (token.IsCancellationRequested)
                    {
                        return;
                    }
                }

                DateTime start;
                var      bucket = await GetLookupForToday(ItemDetails.Instance.TagLookup.GetValueOrDefault("ENCHANTED_LAVA_BUCKET"));

                Console.WriteLine("----------\nyoungest lava bucket is " + bucket.Youngest.Date);
                var end = DateTime.Now - TimeSpan.FromDays(1);
                if (bucket != null)
                {
                    end = bucket.Youngest.Date.RoundDown(TimeSpan.FromHours(1)) + TimeSpan.FromHours(1);
                }
                var removeBefore = end - TimeSpan.FromHours(1);
                while (end < DateTime.Now)
                {
                    start = end;
                    end   = start + TimeSpan.FromHours(1);
                    Console.WriteLine($"Caching bazaar for {start}");
                    await UpdateBazaarFor(start, end, removeBefore);

                    if (token.IsCancellationRequested)
                    {
                        return;
                    }
                }
            }
            if (token.IsCancellationRequested)
            {
                return;
            }
        }
Exemplo n.º 5
0
        public void WasReferedBy(GoogleUser user, string referer)
        {
            if (user.ReferedBy != 0)
            {
                throw new CoflnetException("already_refered", "You already have used a referal Link. You can only be refered once.");
            }
            var id = hashids.Decode(referer)[0];

            if (id == user.Id)
            {
                throw new CoflnetException("self_refered", "You cant refer yourself");
            }
            using (var context = new HypixelContext())
            {
                user.ReferedBy = id;
                // give the user 'test' premium time
                Server.AddPremiumTime(1, user);
                context.Update(user);
                // persist the boni
                context.Add(new Bonus()
                {
                    BonusTime     = TimeSpan.FromDays(1),
                    ReferenceData = id.ToString(),
                    Type          = Bonus.BonusType.BEING_REFERED,
                    UserId        = user.Id
                });


                var referUser = context.Users.Where(u => u.Id == id).FirstOrDefault();
                if (referUser != null)
                {
                    // award referal bonus to user who refered
                    Server.AddPremiumTime(1, referUser);
                    context.Add(new Bonus()
                    {
                        BonusTime     = TimeSpan.FromDays(1),
                        ReferenceData = user.Id.ToString(),
                        Type          = Bonus.BonusType.REFERAL,
                        UserId        = referUser.Id
                    });
                    context.Update(referUser);
                }
                context.SaveChanges();
            }
        }
Exemplo n.º 6
0
        private static int GetOrCreatePlayerId(HypixelContext context, string uuid)
        {
            if (uuid == null)
            {
                return(-1);
            }
            var id = context.Players.Where(p => p.UuId == uuid).Select(p => p.Id).FirstOrDefault();

            if (id == 0)
            {
                id = Program.AddPlayer(context, uuid, ref Indexer.highestPlayerId);
                if (id != 0 && id % 10 == 0)
                {
                    Console.WriteLine($"Adding player {id} {uuid} {Indexer.highestPlayerId}");
                }
            }
            return(id);
        }
Exemplo n.º 7
0
        private IQueryable <SaveAuction> CreateSelect(ItemSearchQuery details, HypixelContext context, int itemId, int limit = 0, IQueryable <SaveAuction> select = null)
        {
            var min = DateTime.Now - TimeSpan.FromDays(35);

            if (details.Filter != null && details.Start < min)
            {
                throw new CoflnetException("filter_to_large", $"You are only allowed to filter for the last month, please set 'start' to a value greater than {min.AddHours(1).ToUnix()}");
            }
            if (select == null)
            {
                select = AuctionSelect(details.Start, details.End, context, itemId);
            }

            if (details.Filter != null && details.Filter.Count > 0)
            {
                details.Filter["ItemId"] = itemId.ToString();
                return(FilterEngine.AddFilters(select, details.Filter));
            }

            if (details.Enchantments != null && details.Enchantments.Any())
            {
                select = AddEnchantmentWhere(details.Enchantments, select, context, itemId, limit);
            }

            if (details.Reforge != ItemReferences.Reforge.Any)
            {
                select = select.Where(auction => auction.Reforge == details.Reforge);
            }


            if (details.Tier != Tier.UNKNOWN)
            {
                select = select.Where(a => a.Tier == details.Tier);
            }

            /*
             * if(details.Data != null && details.Data.Count > 0)
             * {
             *  var kv = details.Data.First();
             *  select = select.Where(a=>(a.NbtData.Data as Dictionary<string,object>)[kv.Key].ToString() == kv.Value);
             * }*/

            return(select);
        }
Exemplo n.º 8
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);
        }
Exemplo n.º 9
0
        /// <summary>
        /// Tries to find and return an item by name
        /// </summary>
        /// <param name="fullName">Full Item name</param>
        /// <returns></returns>
        public DBItem GetDetails(string fullName)
        {
            if (Items == null)
            {
                LoadFromDB();
            }
            var cleanedName = ItemReferences.RemoveReforgesAndLevel(fullName);

            /*if (ReverseNames.TryGetValue(name, out string key) &&
             *  Items.TryGetValue(key, out Item value))
             * {
             *  return value;
             * }*/

            using (var context = new HypixelContext())
            {
                var id = GetItemIdForName(cleanedName, false);
                if (id == 0)
                {
                    id = context.AltItemNames.Where(name => name.Name == fullName || name.Name == cleanedName)
                         .Select(name => name.DBItemId).FirstOrDefault();
                }

                if (id > 1)
                {
                    var item = context.Items.Include(i => i.Names).Where(i => i.Id == id).First();
                    if (item.Names != null)
                    {
                        item.Names = item.Names.OrderBy(n => GetScoreFor(n)).ToList();
                    }
                    item.Name = fullName;
                    // cooler icons
                    //if (!item.Tag.StartsWith("POTION") && !item.Tag.StartsWith("PET") && !item.Tag.StartsWith("RUNE"))
                    //    item.IconUrl = "https://sky.lea.moe/item/" + item.Tag;
                    return(item);
                }
            }

            return(new DBItem()
            {
                Tag = "Unknown", Name = fullName
            });
        }
Exemplo n.º 10
0
 private async Task Work()
 {
     using (var context = new HypixelContext())
     {
         if (updateCount % 11 == 9)
         {
             await AddOccurences(context);
         }
         if (updateCount % 10000 == 9999)
         {
             ShrinkHits(context);
         }
         if (updateCount % 2 == 0)
         {
             await PrefetchCache();
         }
     }
     await SaveHits();
 }
Exemplo n.º 11
0
        private async Task FulfillOrder(Stripe.Checkout.Session session)
        {
            Console.WriteLine("Furfilling order");
            var googleId = Int32.Parse(session.ClientReferenceId);
            var id       = session.CustomerId;
            //var email = session.CustomerEmail;
            var days = Int32.Parse(session.Metadata["days"]);

            Console.WriteLine("STRIPE");
            using (var context = new HypixelContext())
            {
                var user = await context.Users.Where(u => u.Id == googleId).FirstAsync();

                UserService.Instance.SavePurchase(user, days, session.Id);
                await context.SaveChangesAsync();

                Console.WriteLine("order completed");
            }
        }
Exemplo n.º 12
0
        private async Task FillYesterDayForever()
        {
            while (true)
            {
                try
                {
                    var start = (DateTime.Now - TimeSpan.FromDays(1)).Date;
                    var end   = start + TimeSpan.FromDays(1);
                    using (var context = new HypixelContext())
                    {
                        context.Database.SetCommandTimeout(3600);
                        var idOfLava = ItemDetails.Instance.GetItemIdForName("ENCHANTED_LAVA_BUCKET");
                        if (!context.Prices.Where(p => p.Date >= start && p.Date <= end && p.ItemId == idOfLava).Any())
                        {
                            await context.Prices.AddRangeAsync(await AvgBazzarHistory(start, end));
                        }

                        await context.SaveChangesAsync();

                        foreach (var itemId in ItemDetails.Instance.TagLookup.Values)
                        {
                            if (context.Prices.Where(p => p.Date >= start && p.Date <= end && p.ItemId == itemId).Any())
                            {
                                continue;
                            }
                            var select = AuctionSelect(start, end, context, itemId);
                            var result = await AvgFromAuctions(itemId, select);

                            await context.Prices.AddRangeAsync(result);

                            await context.SaveChangesAsync();
                        }
                    }
                    // wait for tomorrow (only when no exception)
                    await Task.Delay(DateTime.Now.Date + TimeSpan.FromDays(1.0001) - DateTime.Now);
                }
                catch (Exception e)
                {
                    Logger.Instance.Error($"Daily prices failed: {e.Message} \n {e.StackTrace}");
                    await Task.Delay(TimeSpan.FromMinutes(2));
                }
            }
        }
Exemplo n.º 13
0
 private static void CleanDB()
 {
     // try cleaning when the dust settled
     System.Threading.Thread.Sleep(TimeSpan.FromHours(1));
     using (var context = new HypixelContext())
     {
         // remove dupplicate itemnames
         context.Database.ExecuteSqlRaw(@"
         DELETE
         FROM AltItemNames
         WHERE ID NOT IN
         (
             SELECT MIN(ID)
             FROM AltItemNames
             GROUP BY Name,DBItemId
         )
         ");
     }
 }
Exemplo n.º 14
0
        private static void ProcessAuction(HypixelContext context, Dictionary <string, SaveAuction> inDb, BidComparer comparer, SaveAuction auction)
        {
            try
            {
                var id = auction.Uuid;
                MigrateAuction(auction);

                if (inDb.TryGetValue(id, out SaveAuction dbauction))
                {
                    UpdateAuction(context, comparer, auction, dbauction);
                }
                else
                {
                    if (auction.AuctioneerId == null)
                    {
                        Logger.Instance.Error($"auction removed bevore in db " + auction.Uuid);
                        return;
                    }
                    context.Auctions.Add(auction);
                    try
                    {
                        auction.NBTLookup = NBT.CreateLookup(auction.NbtData);
                    }
                    catch (Exception e)
                    {
                        Logger.Instance.Error($"Error on CreateLookup: {e.Message} \n{e.StackTrace} \n{JSON.Stringify(auction.NbtData.Data)}");
                        throw e;
                    }
                }

                count++;
                if (!minimumOutput && count % 5 == 0)
                {
                    Console.Write($"\r         Indexed: {count} Saved: {StorageManager.SavedOnDisc} \tcache: {StorageManager.CacheItems}  NameRequests: {Program.RequestsSinceStart}");
                }
            }
            catch (Exception e)
            {
                Logger.Instance.Error($"Error {e.Message} on {auction.ItemName} {auction.Uuid} from {auction.AuctioneerId}");
                Logger.Instance.Error(e.StackTrace);
            }
        }
Exemplo n.º 15
0
        public SaveAuction GetAuction(string uuid, Func <IQueryable <SaveAuction>, IQueryable <SaveAuction> > includeFunc = null)
        {
            var uId = GetId(uuid);

            using (var context = new HypixelContext())
            {
                IQueryable <SaveAuction> select = context.Auctions;
                if (includeFunc != null)
                {
                    select = includeFunc(select);
                }
                var auction = select.Where(a => a.UId == uId).FirstOrDefault();
                if (auction == null)
                {
                    // fall through to old select
                    auction = select.Where(a => a.Uuid == uuid).FirstOrDefault();
                }
                return(auction);
            }
        }
Exemplo n.º 16
0
        public override Task Execute(MessageData data)
        {
            var auctions = data.GetAs <List <AuctionSync> >();

            using (var context = new HypixelContext())
            {
                List <string> incomplete = new List <string>();

                foreach (var auction in auctions)
                {
                    var a = context.Auctions.Where(p => p.Uuid == auction.Id).Select(a => new { a.Id, a.HighestBidAmount }).FirstOrDefault();
                    if (a.HighestBidAmount == auction.HighestBid)
                    {
                        continue;
                    }
                    incomplete.Add(auction.Id);
                }
            }
            return(Task.CompletedTask);
        }
Exemplo n.º 17
0
        public void Sync()
        {
            using (var context = new HypixelContext())
            {
                var done        = false;
                var index       = 0;
                var batchAmount = 5000;
                while (!done)
                {
                    var response = context.Auctions.Skip(batchAmount * index++).Take(batchAmount).Select(a => new { a.Uuid, a.HighestBidAmount }).ToList();
                    if (response.Count == 0)
                    {
                        return;
                    }

                    // socket.Send()
                    // data.SendBack(data.Create("playerSyncResponse", response));
                }
            }
        }
Exemplo n.º 18
0
 private int AddItemToDB(DBItem item)
 {
     using (var context = new HypixelContext())
     {
         // make sure it doesn't exist
         if (!context.Items.Where(i => i.Tag == item.Tag).Any())
         {
             context.Items.Add(item);
         }
         try
         {
             context.SaveChanges();
         }
         catch (Exception)
         {
             Console.WriteLine($"Ran into an error while saving {JsonConvert.SerializeObject(item)}");
             throw;
         }
         return(item.Id);
     }
 }
Exemplo n.º 19
0
        internal async Task <IEnumerable <ItemSearchResult> > Search(string search, int count = 5)
        {
            search = search.TrimStart();
            var tagified = search.ToUpper().Replace(' ', '_');

            using (var context = new HypixelContext())
            {
                var items = await context.Items
                            .Include(item => item.Names)
                            .Where(item =>
                                   item.Names
                                   .Where(name => EF.Functions.Like(name.Name, search + '%') ||
                                          EF.Functions.Like(name.Name, "Enchanted " + search + '%')).Any() ||
                                   EF.Functions.Like(item.Tag, tagified + '%')
                                   ).OrderBy(item => item.Name.Length / 2 - item.HitCount - (item.Name == search ? 10000000 : 0))
                            .Take(count)
                            .ToListAsync();

                return(ToSearchResult(items, search));
            }
        }
Exemplo n.º 20
0
        internal async Task <List <AuctionPreview> > GetActiveAuctions(GetActiveAuctionsCommand.ActiveItemSearchQuery query, int amount = 24)
        {
            query.Start = DateTime.Now.Subtract(TimeSpan.FromDays(14)).RoundDown(TimeSpan.FromDays(1));
            using (var context = new HypixelContext())
            {
                var itemId   = ItemDetails.Instance.GetItemIdForName(query.name);
                var dbselect = context.Auctions.Where(a => a.ItemId == itemId && a.End > DateTime.Now);

                var select = CreateSelect(query, context, itemId, amount, dbselect)
                             .Select(a => new
                {
                    a.End,
                    Price = a.HighestBidAmount == 0 ? a.StartingBid : a.HighestBidAmount,
                    a.AuctioneerId,
                    a.Uuid
                });
                switch (query.Order)
                {
                case GetActiveAuctionsCommand.SortOrder.ENDING_SOON:
                    select = select.OrderBy(a => a.End);
                    break;

                case GetActiveAuctionsCommand.SortOrder.LOWEST_PRICE:
                    select = select.OrderBy(a => a.Price);
                    break;

                default:
                    select = select.OrderByDescending(a => a.Price);
                    break;
                }
                return((await select.Take(amount).ToListAsync()).Select(async a => new AuctionPreview()
                {
                    End = a.End,
                    Price = a.Price,
                    Seller = a.AuctioneerId,
                    Uuid = a.Uuid,
                    PlayerName = await PlayerSearch.Instance.GetNameWithCacheAsync(a.AuctioneerId)
                }).Select(a => a.Result).ToList());
            }
        }
Exemplo n.º 21
0
 public ReeralInfo GetReferalInfo(GoogleUser user)
 {
     using (var context = new HypixelContext())
     {
         var referedUsers = context.Users.Where(u => u.ReferedBy == user.Id).ToList();
         var minDate      = new DateTime(2020, 2, 2);
         var upgraded     = context.Boni.Where(b => b.UserId == user.Id && b.Type == Bonus.BonusType.REFERED_UPGRADE).ToList();
         var receivedTime = TimeSpan.FromDays(referedUsers.Count);
         if (upgraded.Count > 0)
         {
             receivedTime += upgraded.Select(b => b.BonusTime).Aggregate((a, b) => a + b);
         }
         return(new ReeralInfo()
         {
             RefId = hashids.Encode(user.Id),
             BougthPremium = upgraded.Count,
             ReceivedTime = receivedTime,
             ReceivedHours = (int)receivedTime.TotalHours,
             ReferCount = referedUsers.Count
         });
     }
 }
Exemplo n.º 22
0
        public override Task Execute(MessageData data)
        {
            var uuid = data.GetAs <string>();

            System.Console.WriteLine(uuid);
            using (var context = new HypixelContext())
            {
                var auction = context.Auctions
                              .Where(a => a.Uuid == uuid)
                              .Include(a => a.NbtData)
                              .Include(a => a.Enchantments)
                              .FirstOrDefault();
                if (auction == null)
                {
                    throw new CoflnetException("auction_unkown", "not found");
                }
                if (Flipper.FlipperEngine.Instance.relevantAuctionIds.TryGetValue(auction.UId, out List <long> ids))
                {
                    return(data.SendBack(data.Create("basedOnResp", context.Auctions.Where(a => ids.Contains(a.UId)).Select(a => new Response()
                    {
                        uuid = a.Uuid,
                        highestBid = a.HighestBidAmount,
                        end = a.End
                    }).ToList(), 120)));
                }
                System.Console.WriteLine($"uuid not found on id list " + Flipper.FlipperEngine.Instance.relevantAuctionIds.Count);

                var result = Flipper.FlipperEngine.Instance.GetRelevantAuctions(auction, context);
                result.Wait();
                return(data.SendBack(data.Create("basedOnResp", result.Result.Item1
                                                 .Select(a => new Response()
                {
                    uuid = a.Uuid,
                    highestBid = a.HighestBidAmount,
                    end = a.End
                }),
                                                 A_HOUR)));
            }
        }
        public override async Task Execute(MessageData data)
        {
            var uuid = data.GetAs<string>();
            var amount = (new Random()).Next(20, 999);
            var userId = 1;//data.UserId;
            var player = await PlayerService.Instance.GetPlayer(uuid);
            if (player == default(Player))
                throw new CoflnetException("unkown_player", "This player was not found");

            var sub = new VerifySub(a =>
            {
                var code = a.StartingBid;
                if(a.AuctioneerId != uuid)
                    code = a.Bids.Where(u => u.Bidder == uuid).Select(b => b.Amount).Where(b => b % 1000 == amount).FirstOrDefault();
                Console.WriteLine("vertifying " + code);
                if (code % 1000 == amount)
                    using (var context = new HypixelContext())
                    {
                        var user = context.Users.Where(u => u.Id == userId).FirstOrDefault();
                        user.MinecraftUuid = a.AuctioneerId;
                        context.Update(user);
                        context.SaveChanges();
                    }
            });
            sub.Type = SubscribeItem.SubType.PLAYER;
            sub.UserId = userId;
            sub.TopicId = uuid;
            sub.Price = amount;

            SubscribeEngine.Instance.AddNew(sub);

            var response = new Response()
            {
                StartingBid = amount
            };

            await data.SendBack(data.Create("connectMc", response));
        }
Exemplo n.º 24
0
 internal void AddToken(int userId, string deviceName, string token)
 {
     using (var context = new HypixelContext())
     {
         var user = context.Users.Where(u => u.Id == userId).Include(u => u.Devices).FirstOrDefault();
         if (user == null)
         {
             throw new CoflnetException("unknown_user", "The user is not known");
         }
         var target = user.Devices.Where(d => d.Name == deviceName);
         if (target.Any())
         {
             var device = target.First();
             device.Token = token;
             context.Update(device);
         }
         else
         {
             var hasPremium = user.PremiumExpires > DateTime.Now;
             if (!hasPremium && user.Devices.Count >= 3)
             {
                 throw new CoflnetException("no_premium", "You need premium to add more than 3 devices");
             }
             if (user.Devices.Count > 10)
             {
                 throw new CoflnetException("limit_reached", "You can't have more than 11 devices linked to your account");
             }
             var device = new Device()
             {
                 UserId = user.Id, Name = deviceName, Token = token
             };
             user.Devices.Add(device);
             context.Update(user);
             context.Add(device);
         }
         context.SaveChanges();
     }
 }
Exemplo n.º 25
0
 private static void FlagChanged()
 {
     if (newPlayers.Count() == 0)
     {
         return;
     }
     using (var context = new HypixelContext())
     {
         while (newPlayers.TryDequeue(out IdAndName result))
         {
             var player = context.Players.Where(p => p.UuId == result.Uuid).FirstOrDefault();
             if (player != null)
             {
                 player.ChangedFlag = true;
                 player.Name        = result.Name;
                 context.Players.Update(player);
                 continue;
             }
             Program.AddPlayer(context, result.Uuid, ref Indexer.highestPlayerId, result.Name);
         }
         context.SaveChanges();
     }
 }
Exemplo n.º 26
0
        public IEnumerable <AuctionPreview> GetRecentAuctions(ItemSearchQuery query, int amount = 12)
        {
            using (var context = new HypixelContext())
            {
                var itemId = ItemDetails.Instance.GetItemIdForName(query.name);

                var result = CreateSelect(query, context, itemId, amount)
                             .OrderByDescending(a => a.End).Take(amount).Select(a => new
                {
                    a.End,
                    Price = a.HighestBidAmount,
                    a.AuctioneerId,
                    a.Uuid
                }).ToList();
                return(result.Select(async a => new AuctionPreview()
                {
                    End = a.End,
                    Price = a.Price,
                    Seller = a.AuctioneerId,
                    Uuid = a.Uuid,
                    PlayerName = await PlayerSearch.Instance.GetNameWithCacheAsync(a.AuctioneerId)
                }).Select(a => a.Result).ToList());
            }
        }
Exemplo n.º 27
0
        private static async Task ResetDoublePlayers(HypixelContext context, int doublePlayersId)
        {
            if (doublePlayersId % 3 == 0)
            {
                Console.WriteLine($"Found Double player id: {doublePlayersId}, renumbering, highestId: {Indexer.highestPlayerId}");
            }

            foreach (var item in context.Players.Where(p => p.Id == doublePlayersId))
            {
                item.Id = 0;
                context.Update(item);
            }
            foreach (var item in context.Auctions.Where(p => p.SellerId == doublePlayersId))
            {
                item.SellerId = 0;
                context.Update(item);
            }
            foreach (var item in context.Bids.Where(p => p.BidderId == doublePlayersId))
            {
                item.BidderId = 0;
                context.Update(item);
            }
            await context.SaveChangesAsync();
        }
Exemplo n.º 28
0
        public DBItem GetDetailsWithCache(int id)
        {
            // THIS IS INPERFORMANT, Todo: find a better way
            var    key = TagLookup.Where(a => a.Value == id).FirstOrDefault();
            string itemTag;

            if (key.Value != 0)
            {
                itemTag = key.Key;
            }
            else
            {
                using (var context = new HypixelContext())
                {
                    var dbResult = context.Items.Where(i => i.Id == id).FirstOrDefault();
                    if (dbResult == null)
                    {
                        return(new DBItem());
                    }
                    itemTag = dbResult.Tag;
                }
            }
            return(GetDetailsWithCache(itemTag).GetAwaiter().GetResult());
        }
Exemplo n.º 29
0
        public async Task DoBatch()
        {
            await Task.Delay(TimeSpan.FromMinutes(5));

            var batchSize = 2000;

            using (var context = new HypixelContext())
            {
                var select = context.Auctions
                             .Where(a => a.Id < minId)
                             .OrderByDescending(a => a.Id)
                             .Include(a => a.NBTLookup)
                             .Include(a => a.NbtData)
                             .Take(batchSize);
                foreach (var auction in select)
                {
                    if (auction.NBTLookup != null && auction.NBTLookup.Count > 0)
                    {
                        continue;
                    }
                    try
                    {
                        auction.NBTLookup = NBT.CreateLookup(auction.NbtData);
                        context.Update(auction);
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine($"could not generate nbtlookup for {auction.Uuid} {e.Message} \n{e.StackTrace} \n {e.InnerException?.Message} {e.InnerException.StackTrace}");
                    }
                }
                int updated = await context.SaveChangesAsync();

                Console.WriteLine($"updated nbt lookup for {updated} auctions, highest: {minId}");
                minId -= batchSize;
            }
        }
Exemplo n.º 30
0
        private static async Task <int> DoBatch(IEnumerable <AveragePrice> items, int count, HypixelContext context)
        {
            var lookup  = items.Select(p => p.Date).ToList();
            var exising = context.Prices.Where(p => lookup.Any(l => l == p.Date)).ToList();

            Console.WriteLine($"loaded a total of {exising.Count} prices to check against");
            foreach (var item in items)
            {
                if (context.Prices.Any(p => p.ItemId == item.ItemId && p.Date == item.Date))
                {
                    continue;
                }
                item.Id = 0;
                context.Prices.Add(item);

                count++;
            }
            await context.SaveChangesAsync();

            if (context.Items.Any() && context.Players.Count() > 20_000)
            {
                Program.Migrated = true;
            }
            return(count);
        }