Exemple #1
0
        public bool Auth(ulong SteamID, out XUser user, Client client)
        {
            SteamUser SteamUser = this.GetSteamData(SteamID);

            if (SteamUser != null)
            {
                bool Exist = this.SelectBySteamID(SteamID, out user);
                user.Name = SteamUser.Name;
                user.ProfileURL = SteamUser.ProfileURL;
                user.Avatar = SteamUser.Avatar;

                if (Exist)
                {
                    //update user
                    this.Table.UpdateByID(user, user.ID);
                }
                else
                {
                    //insert new user
                    user.SteamID = SteamID;
                    // -1 (default, no group).
                    user.GroupOwnerID = -1;
                    user.Currency = this.GetCurrency(client);
                    user = this.Table.SelectByID(this.Table.Insert(user));
                }

                client.Session["User"] = user.ID;
                client.Session["Avatar"] = user.Avatar;
                client.Session["ProfileURL"] = user.ProfileURL;
                client.Session["Name"] = user.Name;
                client.Session["SteamID"] = user.SteamID;
                client.Session["Currency"] = user.Currency;

                //localhost/group/79384474774 -- URL
                client.Session["GroupOwnerID"] = user.GroupOwnerID;
                return true;
            }
            user = new XUser();
            return false;
        }
Exemple #2
0
        public void SendLocalItemsToSteam(XUser user, uint SteamGameID, Client client)
        {
            List<USteamItem> SteamItems = Helper.UserHelper.GetSteamLocalInventory(user.ID, SteamGameID, false);
            if (SteamItems.Count > 0)
            {
                Dictionary<uint, List<UTRequestSteamItem>> BotsRequests = new Dictionary<uint, List<UTRequestSteamItem>>();
                Dictionary<long, uint> AssertItemsIDs = new Dictionary<long, uint>();

                foreach (USteamItem SteamItem in SteamItems)
                {
                    XSItemUsersInventory XSItemUsersInventory;
                    if (Helper.UserHelper.Table_SteamItemUsersInventory.SelectOne(data => data.AssertID == SteamItem.AssertID && !data.Deleted, out XSItemUsersInventory))
                    {
                        XSItemUsersInventory.Deleted = true;
                        Helper.UserHelper.Table_SteamItemUsersInventory.UpdateByID(XSItemUsersInventory, XSItemUsersInventory.ID);

                        UTRequestSteamItem UTRequestSteamItem = new UTRequestSteamItem();
                        UTRequestSteamItem.appid = (int)SteamItem.SteamGameID;
                        UTRequestSteamItem.contextid = 2;

                        UTRequestSteamItem.assertid = (long)SteamItem.AssertID;

                        Logger.ConsoleLog("Making dictionary for out item: " + user.ID + " SteamUserID: " + user.SteamID + " Bot ID: " + SteamItem.SteamBotID, ConsoleColor.Cyan, LogLevel.Info);

                        AssertItemsIDs.Add((long)SteamItem.AssertID, SteamItem.ID);
                        if (BotsRequests.ContainsKey(SteamItem.SteamBotID))
                        {
                            BotsRequests[SteamItem.SteamBotID].Add(UTRequestSteamItem);
                        }
                        else
                        {
                            List<UTRequestSteamItem> item_rq = new List<UTRequestSteamItem>();
                            item_rq.Add(UTRequestSteamItem);
                            BotsRequests.Add(SteamItem.SteamBotID, item_rq);
                        }
                    }
                }

                if (!UTSteam.SendClientOffer.ContainsKey(user.SteamID))
                {
                    UTSteam.SendClientOffer.Add(user.SteamID, client);
                }
                else if (UTSteam.SendClientOffer[user.SteamID] != client)
                {
                    UTSteam.SendClientOffer[user.SteamID] = client;
                }

                foreach (uint key in BotsRequests.Keys)
                {
                    XBotsOffer XBotsOffer = new XBotsOffer();
                    XBotsOffer.BotID = key;
                    XBotsOffer.SteamUserID = user.SteamID;
                    XBotsOffer.SentTime = Helper.GetCurrentTime();
                    uint bots_offerid = Helper.SteamBotHelper.Table_BotsOffer.Insert(XBotsOffer);

                    UTRequestSteamMain UTRequestSteamMain = new UTRequestSteamMain();

                    foreach (UTRequestSteamItem URequest in BotsRequests[key])
                    {
                        if (!AssertItemsIDs.ContainsKey(URequest.assertid))
                        {
                            Logger.ConsoleLog("Cлучилась непонятная ошибка: " + URequest.assertid + "user" + user.ID, ConsoleColor.Yellow, LogLevel.Warning);
                            continue;
                        }

                        XBotOffersItem XBotOffersItem = new XBotOffersItem();
                        XBotOffersItem.BotsOfferID = bots_offerid;
                        XBotOffersItem.AssertID = (ulong)URequest.assertid;

                        XBotOffersItem.SteamItemID = AssertItemsIDs[URequest.assertid];
                        Helper.SteamBotHelper.Table_BotOffersItem.Insert(XBotOffersItem);

                        XSteamItemsClassID XSteamItemsClassID;
                        Helper.SteamItemsHelper.Table_ClassID.SelectOne(dt => dt.AssertID == XBotOffersItem.AssertID, out XSteamItemsClassID);
                        URequest.assertid = (long)XSteamItemsClassID.ClassID;

                        UTRequestSteamMain.Items.Add(URequest);

                        Logger.ConsoleLog("-----------------------------");
                        Logger.ConsoleLog("Item class id: " + URequest.assertid);
                        Logger.ConsoleLog("Item contex id: " + URequest.contextid);
                        Logger.ConsoleLog("Item app id: " + URequest.appid);
                        Logger.ConsoleLog("Steam item id: " + XBotOffersItem.SteamItemID);

                        Logger.ConsoleLog("Saving to UTRequestSteamMain:" + user.ID + " SteamUserID: " + user.SteamID + " Bot ID: " + key + " AsserID:" + URequest.assertid, ConsoleColor.Cyan, LogLevel.Info);
                    }

                    UTRequestSteamMain.message = "Peredacha veshhej iz vremennogo inventarja GAMESLOT. Dannoe predlozhenie budet avtomaticheski udaleno spustja chas.";
                    UTRequestSteamMain.BotID = (int)key;

                    UTRequestSteamMain.steamid = user.SteamID.ToString();
                    UTRequestSteamMain.trade_acc_id = user.TradeToken;
                    UTRequestSteamMain.SendItems = true;

                    Logger.ConsoleLog("Sending offer from local inventory... [" + UTRequestSteamMain.Items.Count + "] Bot ID:" + UTRequestSteamMain.BotID);
                    UpTunnel.Sender.Send(UTSteam.sk, UTRequestSteamMain);

                    while (Helper.SteamBotHelper.Table_BotsOffer.SelectOne(bt => bt.SteamUserID == user.SteamID && bt.Status == 0, out XBotsOffer))
                    {
                        Thread.Sleep(300);
                    }

                }
            }
        }
Exemple #3
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;
        }
Exemple #4
0
        public bool SelectBySteamID(ulong SteamID, out XUser user)
        {
            if (this.Table.SelectOne(data => data.SteamID == SteamID, out user))
            {
                return true;
            }

            user = new XUser();
            return false;
        }
Exemple #5
0
        public bool IsUserHaveSteamItem_SteamInventory(ulong AssertID, uint ItemID, XUser User, uint SteamGameID)
        {
            UsersInventory UsersInventory;
            if (this.GetSteamInventory(User.ID, SteamGameID, out UsersInventory))
            {
                foreach(USteamItem Item in UsersInventory.SteamItems)
                {
                    if(Item.AssertID == AssertID && Item.ID == ItemID)
                    {
                        return true;
                    }
                }
            }
               /* else
            {
                //Logger.ConsoleLog("Using parsging for check item!");
                if (UsersInventoryString.Contains("{\"id\":\"" + AssertID + "\""))
                {
                    string classID = Regex.Split(Regex.Split(UsersInventoryString, "{\"id\":\"" + AssertID + "\"")[1], "\"classid\":\"")[1].Split('"')[0];
                    string ItemContent = Regex.Split(UsersInventoryString, "{\"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 it;
                    if (Helper.SteamItemsHelper.SelectByName(name, SteamGameID, out it, 0))
                    {
                        return true;
                    }
                }
            }*/

            return false;
        }
Exemple #6
0
 public bool GetCurrentUser(Client client, out XUser user)
 {
     if (client != null)
     {
         if (client.Session.Contains("User") && client.Session["User"] != null && this.Table.SelectByID((uint)client.Session["User"], out user))
         {
             return true;
         }
     }
     user = new XUser();
     return false;
 }
Exemple #7
0
        public static void SendLotteryRoulette(XLottery XLottery, List<LotteryRouletteData> RouletteData, XUser Winner)
        {
            if (ClientsLotteryPage.ContainsKey(XLottery.ID))
            {
                // from 1: JackpotItems 2: JackpotPrice 3:Winner.ID 4: Winner.Name 5:RaundNumber 6: WinnerToken 7:(JackpotPrice * 100) 8: Winner.Avatar
                string ws = "";
                // 12: data
                foreach (LotteryRouletteData data in RouletteData)
                {
                    ws += data.UsersAvatar + "↑" + data.Token.ToString("D8") + "↑" + data.Winner + "↓";
                }

                for (int i = 0; i < WebSocketPage.ClientsLotteryPage[XLottery.ID].Count; i++)
                {
                    if (WebSocketPage.ClientsLotteryPage[XLottery.ID][i] == null || WebSocketPage.ClientsLotteryPage[XLottery.ID][i].Closed)
                    {
                        WebSocketPage.ClientsLotteryPage[XLottery.ID].RemoveAt(i--);
                        continue;
                    }

                    string extra = XLottery.JackpotItemsNum + BaseFuncs.WSplit;

                    string WinnersBetPrice;
                    if (Helper.UserHelper.GetCurrency(WebSocketPage.ClientsLotteryPage[XLottery.ID][i]) == 1)
                    {
                        extra += (XLottery.JackpotPrice * XLottery.RubCurrency).ToString("###,###,##0");
                        WinnersBetPrice = (XLottery.WinnersBetPrice * XLottery.RubCurrency).ToString("###,###,##0");
                    }
                    else
                    {
                        extra += XLottery.JackpotPrice.ToString("###,##0.00");
                        WinnersBetPrice = XLottery.WinnersBetPrice.ToString("###.##0.00");
                    }

                    extra += BaseFuncs.WSplit + Winner.ID + BaseFuncs.WSplit + Winner.Name + BaseFuncs.WSplit;
                    extra += XLottery.RaundNumber + BaseFuncs.WSplit + XLottery.WinnersToken + BaseFuncs.WSplit + (XLottery.JackpotPrice * 100) + BaseFuncs.WSplit + Winner.Avatar + BaseFuncs.WSplit;
                    // 9: wonrate; 10: winners_items_num; 11: winners_price
                    extra += XLottery.Wonrate + BaseFuncs.WSplit + XLottery.WinnersBetItemsNum + BaseFuncs.WSplit + WinnersBetPrice + BaseFuncs.WSplit;
                    extra += ws + BaseFuncs.WSplit;

                    XUser CurrentUser;
                    if (Helper.UserHelper.GetCurrentUser(WebSocketPage.ClientsLotteryPage[XLottery.ID][i], out CurrentUser) && CurrentUser.ID == Winner.ID)
                    {
                        extra += 1.ToString();
                        Logger.ConsoleLog("Winner detected!", ConsoleColor.Yellow);
                    }
                    else
                    {
                        extra += 0.ToString();
                    }
                    //14
                    extra += BaseFuncs.WSplit + BaseFuncs.MD5(XLottery.RaundNumber.ToString());

                    Logger.ConsoleLog("User:"******"LotteryRouletteStarted" + BaseFuncs.WSplit + extra);
                }

                WebSocketPage.ClientsLotteryPage.Remove(XLottery.ID);
            }

            WebSocketPage.UpdateMainPageLotteries(XLottery);
        }
Exemple #8
0
        public bool SelectByID(uint id, out UGroup group, out XUser Owner, Client client)
        {
            XUser user;
            if(Helper.UserHelper.Table.SelectByID(id, out user))
            {
                group = new UGroup();
                group.ID = user.ID;
                group.Name = user.GroupName != null && user.GroupName != "" ? user.GroupName : user.Name;
                group.Users = this.GetUsers(user.ID);
                group.UserCount = group.Users.Count();

                group.Winrate = this.CalcWinrate(group.ID);
                group.BetItemsCount = user.DOTA_GroupTotalBetItemsCount + user.CSGO_GroupTotalBetItemsCount;

                ushort currency = Helper.UserHelper.GetCurrency(client);
                if (currency == 1)
                {
                    group.BetPrice = user.DOTA_RUB_GroupTotalBetPrice + user.CSGO_RUB_GroupTotalBetPrice;
                    group.BetItemsPrice_Str = group.BetPrice.ToString("###,###,##0");

                    group.GotPriceFromGroup = user.DOTA_RUB_GotPriceFromGroup + user.CSGO_RUB_GotPriceFromGroup;
                    group.GotPriceFromGroup_Str = group.GotPriceFromGroup.ToString("###,###,##0");
                }
                else
                {
                    group.BetPrice = user.DOTA_GroupTotalBetPrice + user.CSGO_GroupTotalBetPrice;
                    group.BetItemsPrice_Str = group.BetPrice.ToString("###,##0.00");

                    group.GotPriceFromGroup = user.DOTA_GotPriceFromGroup + user.CSGO_GotPriceFromGroup;
                    group.GotPriceFromGroup_Str = group.GotPriceFromGroup.ToString("###,##0.00");
                }

                group.GotItemsFromGroup = user.DOTA_GotItemsFromGroup + user.CSGO_GotItemsFromGroup;

                Owner = user;
                return true;
            }

            group = null;
            Owner = new XUser();
            return false;
        }