public bool SelectByName(string name, uint SteamGameID, out XSteamItem XSteamItem) { return this.Table.SelectOne(data => data.Name.Equals(name) && data.SteamGameID == SteamGameID, out XSteamItem) ? true : false; }
private UsersInventory UpdateSteamInventory(XUser User, uint SteamGameID, int GetItemsNum = 30) { UsersInventory UsersInventory = new UsersInventory(); UsersInventory.Opened = false; if (!this.GetUpdatingInventories()[SteamGameID].ContainsKey(User.ID)) { double TotalPrice = 0d; lock (_UpdatingInventories) { UpdatingInventories[SteamGameID][User.ID] = Helper.GetCurrentTime(); } try { string data; bool result = this.GetUsersSteamInventory_Json(User.ID, SteamGameID, out data, 1); // Logger.ConsoleLog(data); if (User.SteamInventoryHash.Equals(BaseFuncs.MD5(data)) && UsersInventories.ContainsKey(SteamGameID) && UsersInventories[SteamGameID].ContainsKey(User.ID) && SteamItemsHelper.LastItemPricesUpdate < UsersInventories[SteamGameID][User.ID].LastUpdate) { UsersInventory = UsersInventories[SteamGameID][User.ID]; } else if (result) { List<USteamItem> SteamItems = new List<USteamItem>(); string[] Item = Regex.Split(data, "{\"id\":\""); for (int i = 1; i < Item.Length; i++) { //Logger.ConsoleLog("On " + i + " from " + (Item.Length - 1)); string classid = Regex.Split(Item[i], "\"classid\":\"")[1].Split('"')[0]; string ItemContent = Regex.Split(data, "{\"appid\":\"" + SteamGameID + "\",\"classid\":\"" + classid + "\"")[1]; string name = Regex.Split(ItemContent, "\"market_hash_name\":\"")[1].Split('"')[0]; name = Encoding.Unicode.GetString(Encoding.Unicode.GetBytes(name)); USteamItem SteamItem; if (!Helper.SteamItemsHelper.SelectByName(name, SteamGameID, out SteamItem, User.Currency)) { XSteamItem XSteamItem = new XSteamItem(); XSteamItem.Name = name; SteamItem = new USteamItem(); SteamItem.Price = XSteamItem.Price = Helper.SteamItemsHelper.GetMarketPrice(XSteamItem.Name, SteamGameID); if (XSteamItem.Price < 0) { SteamItem.Price = XSteamItem.Price = 0; } SteamItem.Price_Str = SteamItem.Price.ToString("###,##0.00"); XSteamItem.Rarity = Regex.Split(ItemContent, "internal_name\":\"Rarity_")[1].Split('"')[0]; SteamItem.Color = XSteamItem.Color = Regex.Split(ItemContent, "\"name_color\":\"")[1].Split('"')[0]; ; string RusName = Regex.Split(ItemContent, "\"market_name\":\"")[1].Split('"')[0]; XSteamItem.RusName = Helper.SteamItemsHelper.MakeTextFromRealDich(RusName); if (SteamGameID == Configs.CSGO_STEAM_GAME_ID) { if (XSteamItem.Rarity.Contains("_")) { XSteamItem.Rarity = XSteamItem.Rarity.Split('_')[0]; } } if (User.Currency == 1) { SteamItem.Name = XSteamItem.RusName; } else { SteamItem.Name = XSteamItem.Name; } SteamItem.Image = XSteamItem.Image = "http://steamcommunity-a.akamaihd.net/economy/image/" + Regex.Split(ItemContent, "\"icon_url\":\"")[1].Split('"')[0]; SteamItem.Rarity = XSteamItem.Rarity; SteamItem.RarityColor = Helper.SteamItemsHelper.GetRarityColor(XSteamItem.Rarity, SteamGameID); SteamItem.SteamGameID = XSteamItem.SteamGameID = SteamGameID; SteamItem.ID = Helper.SteamItemsHelper.Table.Insert(XSteamItem); } string iimgg; if (!Helper.SteamItemsHelper.GetImageFromMemory(SteamItem.ID, SteamItem.SteamGameID, out iimgg)) { SteamItemImageQueue SteamItemImageQueue = new SteamItemImageQueue(); SteamItem.ID = SteamItemImageQueue.ID = SteamItem.ID; SteamItemImageQueue.SteamGameID = SteamItem.SteamGameID; SteamItemImageQueue.ImageURL = SteamItem.Image; Helper.SteamItemsHelper.AddToQueueDownloadImage(SteamItemImageQueue); } if (SteamItem.Price >= Configs.MIN_ITEMS_PRICE) { SteamItem.AssertID = Convert.ToUInt64(Item[i].Split('"')[0]); XSteamItemsClassID XSteamItemsClassID; if (!Helper.SteamItemsHelper.Table_ClassID.SelectOne(dt => dt.AssertID == SteamItem.AssertID, out XSteamItemsClassID)) { XSteamItemsClassID = new XSteamItemsClassID(); XSteamItemsClassID.AssertID = SteamItem.AssertID; XSteamItemsClassID.ClassID = Convert.ToUInt64(classid); Helper.SteamItemsHelper.Table_ClassID.Insert(XSteamItemsClassID); } if (User.Currency == 1) { SteamItem.Price = SteamItem.Price * Helper.Rub_ExchangeRate; SteamItem.Price_Str = SteamItem.Price.ToString("###,###,##0"); } else { SteamItem.Price_Str = SteamItem.Price.ToString("###,##0.00"); } SteamItems.Add(SteamItem); TotalPrice += SteamItem.Price; } } UsersInventory.SteamItems = (from it in SteamItems orderby it.Price descending select it).ToList(); UsersInventory.TotalPrice = TotalPrice; if (User.Currency == 1) { UsersInventory.TotalPrice_Str = TotalPrice.ToString("###,###,##0"); } else { UsersInventory.TotalPrice_Str = TotalPrice.ToString("###,##0.00"); } UsersInventory.Opened = true; XUser cur_usr = this.Table.SelectByID(User.ID); cur_usr.SteamInventoryHash = BaseFuncs.MD5(data); this.Table.UpdateByID(cur_usr, User.ID); } } catch (Exception Exception) { Logger.ConsoleLog(Exception); } UsersInventory.LastUpdate = Helper.GetCurrentTime(); lock (_UsersSteamInventories) { UsersInventories[SteamGameID][User.ID] = UsersInventory; } lock (_UpdatingInventories) { UpdatingInventories[SteamGameID].Remove(User.ID); } if (InventoryClients[SteamGameID].ContainsKey(User.ID)) { for (int i = 0; i < InventoryClients[SteamGameID][User.ID].Count; i++) { if (InventoryClients[SteamGameID][User.ID][i].Client != null && !InventoryClients[SteamGameID][User.ID][i].Client.Closed) { WebSocketPage.GetWebsocket_SteamInventory(UsersInventory, InventoryClients[SteamGameID][User.ID][i].Client, 0, 0, InventoryClients[SteamGameID][User.ID][i].ItemNum, SteamGameID, ""); } } InventoryClients[SteamGameID].Remove(User.ID); } } return UsersInventory; }
public bool SelectByID(uint id, uint SteamGameID, out XSteamItem XSteamItem) { return this.Table.SelectOne(data => data.ID == id && data.SteamGameID == SteamGameID, out XSteamItem) ? true : false; }