示例#1
0
 private void AddNewInventorySet(UsersInventory inventory)
 {
     foreach (InventoryFolderBase folder in inventory.Folders.Values)
     {
         AddFolder(folder);
     }
 }
        // See IInventoryServices
        public bool CreateUserInventory(UUID user)
        {
            InventoryFolderBase existingRootFolder;

            try
            {
                existingRootFolder = GetRootFolder(user);
            }
            catch /*(Exception e)*/
            {
                // Munch the exception, it has already been reported
                //
                return(false);
            }

            if (null != existingRootFolder)
            {
                m_log.WarnFormat(
                    "[INVENTORY SERVICE]: Did not create a new inventory for user {0} since they already have "
                    + "a root inventory folder with id {1}",
                    user, existingRootFolder.ID);
            }
            else
            {
                UsersInventory inven = new UsersInventory();
                inven.CreateNewInventorySet(user);
                AddNewInventorySet(inven);

                return(true);
            }

            return(false);
        }
示例#3
0
        // See IInventoryServices
        public bool CreateNewUserInventory(UUID user)
        {
            InventoryFolderBase existingRootFolder = RequestRootFolder(user);

            if (null != existingRootFolder)
            {
                m_log.WarnFormat(
                    "[AGENT INVENTORY]: Did not create a new inventory for user {0} since they already have "
                    + "a root inventory folder with id {1}",
                    user, existingRootFolder.ID);
            }
            else
            {
                UsersInventory inven = new UsersInventory();
                inven.CreateNewInventorySet(user);
                AddNewInventorySet(inven);

                return(true);
            }

            return(false);
        }
 private void AddNewInventorySet(UsersInventory inventory)
 {
     foreach (InventoryFolderBase folder in inventory.Folders.Values)
     {
         AddFolder(folder);
     }
 }
        // See IInventoryServices
        public bool CreateUserInventory(UUID user)
        {
            InventoryFolderBase existingRootFolder;
            try
            {
                existingRootFolder = GetRootFolder(user);
            }
            catch /*(Exception e)*/
            {
                // Munch the exception, it has already been reported
                //
                return false;
            }

            if (null != existingRootFolder)
            {
                m_log.WarnFormat(
                    "[INVENTORY SERVICE]: Did not create a new inventory for user {0} since they already have "
                    + "a root inventory folder with id {1}",
                    user, existingRootFolder.ID);
            }
            else
            {
                UsersInventory inven = new UsersInventory();
                inven.CreateNewInventorySet(user);
                AddNewInventorySet(inven);

                return true;
            }

            return false;
        }
示例#6
0
        // See IInventoryServices
        public bool CreateNewUserInventory(UUID user)
        {
            InventoryFolderBase existingRootFolder = RequestRootFolder(user);

            if (null != existingRootFolder)
            {
                m_log.WarnFormat(
                    "[AGENT INVENTORY]: Did not create a new inventory for user {0} since they already have "
                    + "a root inventory folder with id {1}",
                    user, existingRootFolder.ID);
            }
            else
            {
                UsersInventory inven = new UsersInventory();
                inven.CreateNewInventorySet(user);
                AddNewInventorySet(inven);

                return true;
            }

            return false;
        }
示例#7
0
        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;
        }
示例#8
0
        public bool GetSteamInventory(uint UserID, uint SteamGameID, out UsersInventory UsersInventory, bool wait = false)
        {
            XUser User;
            if (this.Table.SelectByID(UserID, out User))
            {
                if (UsersInventories.ContainsKey(SteamGameID) && UsersInventories[SteamGameID].ContainsKey(User.ID))
                {
                    UsersInventory = UsersInventories[SteamGameID][User.ID];
                    //Logger.ConsoleLog(UsersInventory.Opened + "CERCE");
                    if (!this.GetUpdatingInventories()[SteamGameID].ContainsKey(User.ID) && UsersInventory.LastUpdate + Configs.INVENTORY_UPDATE_TIME < Helper.GetCurrentTime())
                    {
                        //Logger.ConsoleLog("again update!");
                        if (wait)
                        {
                            this.UpdateSteamInventory(User, SteamGameID);
                        }
                        else
                        {
                            new Thread(delegate() { this.UpdateSteamInventory(User, SteamGameID); }).Start();
                            //return false;
                        }
                    }

                    return true;
                }

                if (!this.GetUpdatingInventories()[SteamGameID].ContainsKey(User.ID))
                {
                    //Logger.ConsoleLog("update!");
                    if (wait)
                    {
                        this.UpdateSteamInventory(User, SteamGameID);
                    }
                    else
                    {
                        new Thread(delegate() { this.UpdateSteamInventory(User, SteamGameID); }).Start();
                    }
                }
            }
            UsersInventory = null;
            return false;
        }
示例#9
0
        public static void GetWebsocket_SteamInventory(UsersInventory Inventory, Client client, ushort SortByLowPrice, int FromNum, int ItemsNum, uint SteamGameID, string SearchString)
        {
            if (!Inventory.Opened)
            {
                WebSocketPage.UpdateInventory("", 0.ToString(), 0, client, false);
            }
            else
            {
                string StrItems = "";
                List<USteamItem> SteamItems = Helper.SteamItemsHelper.SearchByString(Inventory.SteamItems, SearchString);

                if (SortByLowPrice == 1)
                {
                    SteamItems = (from it in SteamItems orderby it.Price ascending select it).ToList();
                }

                if (FromNum < 0)
                {
                    FromNum = 0;
                }
                else if (FromNum > ItemsNum && FromNum == SteamItems.Count)
                {
                    FromNum -= ItemsNum;
                }
                Logger.ConsoleLog("From num: " + FromNum + " ItemsNum:" + ItemsNum);
                for (int i = FromNum; i < Math.Min(FromNum + ItemsNum, SteamItems.Count); i++)
                {
                    StrItems += WebSocketPage.InventoryItemToString(SteamItems[i]);
                }

                Logger.ConsoleLog("Total price of steam inventory: " + Inventory.TotalPrice + "|" + Inventory.TotalPrice_Str);
                WebSocketPage.UpdateInventory(StrItems, Inventory.TotalPrice_Str, SteamItems.Count, client, true);
            }
        }