Esempio n. 1
0
        /// <summary>
        /// Accepts a specified trade offer.
        /// </summary>
        /// <param name="tradeId">A ulong representing the trade to accept.</param>
        /// <param name="container">Auth Cookies MUST be passed here, the function will fail if not.</param>
        /// <param name="partnerId">The AccountId of the person to trade with.</param>
        /// <param name="serverid">Almost always 1, not quite sure what other numbers do.</param>
        /// <returns>The TradeId of the offer that was accepted.</returns>
        public Trade AcceptTradeOffer(uint tradeId, uint partnerId, CookieContainer container, string serverid)
        {
            container.Add(new Cookie("bCompletedTradeOfferTutorial", "true")
            {
                Domain = "steamcommunity.com"
            });
            string sessionid = (from Cookie cookie in container.GetCookies(new Uri("https://steamcommunity.com"))
                                where cookie.Name == "sessionid"
                                select cookie.Value).FirstOrDefault();

            const string url  = "https://steamcommunity.com/tradeoffer/{0}/accept";
            var          data = new Dictionary <string, string>
            {
                { "sessionid", sessionid },
                { "serverid", serverid },
                { "tradeofferid", tradeId.ToString() },
                { "partner", IdConversions.AccountIdToUlong(partnerId).ToString() },
                { "captcha", string.Empty }
            };

            return
                (JsonConvert.DeserializeObject <Trade>(
                     WebUtility.UrlDecode(_web.Fetch(string.Format(url, tradeId), "POST",
                                                     data, container, false, "https://steamcommunity.com/tradeoffer/" + tradeId + "/").ReadStream())));
        }
Esempio n. 2
0
        //chat message event fires whenever we receive an actual message
        private static void OnChatMessage(object sender, ChatMessageArgs e)
        {
            switch (e.ChatMessage.Text.ToLower())
            {
            case "!utc":
                ChatHandler.Message(IdConversions.AccountIdToUlong(e.ChatMessage.AccountIdFrom), "saytext",
                                    "The current UTC timestamp is: " + e.ChatMessage.UtcTimestamp);
                return;

            case "!timestamp":
                ChatHandler.Message(IdConversions.AccountIdToUlong(e.ChatMessage.AccountIdFrom), "saytext",
                                    "The current timestamp is: " + e.ChatMessage.Timestamp);
                return;

            case "!myfriendcount":
                List <Friend> friends = SteamUserHandler.GetFriendList(IdConversions.AccountIdToUlong(e.ChatMessage.AccountIdFrom), "friend");
                if (friends == null)
                {
                    throw new ArgumentNullException(nameof(friends));
                }
                ChatHandler.Message(IdConversions.AccountIdToUlong(e.ChatMessage.AccountIdFrom), "saytext",
                                    "You have " + friends.Count + " friends.");
                return;

            case "!logoff":
                ChatEventsManager.EndMessageLoop();
                ChatHandler.Logoff();
                return;
                //more commands...
            }

            //actual messages etc...
            ChatHandler.Message(IdConversions.AccountIdToUlong(e.ChatMessage.AccountIdFrom), "saytext",
                                "Hello!");
        }
Esempio n. 3
0
        public void AccountIdToUlong_NoFail()
        {
            uint  input    = 100049908;
            ulong expected = 76561198060315636;
            ulong actual   = IdConversions.AccountIdToUlong(input);

            Assert.AreEqual(expected, actual);
        }
Esempio n. 4
0
        void OnChatMessage(object sender, ChatMessageArgs e)
        {
            ChatControl control = FindMatchingChatControl(IdConversions.AccountIdToUlong(e.ChatMessage.AccountIdFrom));

            if (control == null)
            {
                return;
            }
            InvokeHandleMessage(control, e.ChatMessage.Text);
        }
Esempio n. 5
0
        private static void PollOffers()
        {
            Console.WriteLine("Polling offers every ten seconds.");

            bool isPolling = true;

            var offerHandler  = new EconServiceHandler(_config.ApiKey);
            var marketHandler = new MarketHandler();

            Inventory csgoInventory = new Inventory(_account.SteamId, 730);

            marketHandler.EligibilityCheck(_account.SteamId, _account.AuthContainer);
            //required to perform trades (?). Checks to see whether or not we're allowed to trade.

            // ReSharper disable once ConditionIsAlwaysTrueOrFalse
            // ReSharper disable once LoopVariableIsNeverChangedInsideLoop
            while (isPolling) //permanent loop, can be changed
            {
                Thread.Sleep(10000);

                var recData = new Dictionary <string, string>
                {
                    { "get_received_offers", "1" },
                    { "active_only", "1" },
                    { "time_historical_cutoff", "999999999999" }
                    //arbitrarily high number to retrieve latest offers
                };

                var offers = offerHandler.GetTradeOffers(recData).TradeOffersReceived;

                if (offers == null)
                {
                    continue;
                }

                foreach (CEconTradeOffer cEconTradeOffer in offers)
                {
                    TradeOffer offer = new TradeOffer();
                    offer.Them.Assets = cEconTradeOffer.ItemsToReceive;
                    offer.Me.Assets.Add(csgoInventory.Items.First().Value.Items.First().ToCEconAsset(730));
                    offerHandler.ModifyTradeOffer(IdConversions.AccountIdToUlong(cEconTradeOffer.AccountIdOther),
                                                  "Here you go!", "1", cEconTradeOffer.TradeOfferId, offer, _account.AuthContainer);
                }
            }
        }
        void OnMessage(object sender, ChatMessageArgs e)
        {
            CheckCreateChatWindow();

            PlayerSummary summary =
                FriendSummaries.FirstOrDefault(
                    x => x.SteamId == IdConversions.AccountIdToUlong(e.ChatMessage.AccountIdFrom));

            if (summary == null)
            {
                MessageBox.Show("I was lazy and I don't poll for new friends. They attempted to send you a message.");
                return;
            }

            List <FriendControl> friendControls = new List <FriendControl>();
            ChatUser             friend         = null;

            friendsStackPanel.Dispatcher.Invoke(() =>
            {
                friendControls = friendsStackPanel.Children.Cast <FriendControl>().ToList();
            });

            foreach (FriendControl control in friendControls)
            {
                ulong steamId = 0;
                control.Dispatcher.Invoke(() => { steamId = control.Friend.Summary.SteamId; });
                if (steamId != summary.SteamId)
                {
                    continue;
                }
                control.Dispatcher.Invoke(() => { friend = control.Friend; });
                break;
            }

            if (friend == null)
            {
                throw new Exception("Could not locate friend, please report this!");
            }

            ChatWindow.AddChatWindow(friend, e.ChatMessage.Text);
        }