Beispiel #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())));
        }
Beispiel #2
0
        /// <summary>
        /// Sends a trade offer to the specified recipient that's not on your friends list using the trade url. If is not the case, use SendTradeOffer function.
        /// </summary>
        /// <param name="partnerSid">The SteamId64 (ulong) of the person to send the offer to.</param>
        /// <param name="token">The token part from the recipient's trade url. Example: a1b2cdEF</param>
        /// <param name="tradeoffermessage">An optional message to be sent with the offer. Can be null.</param>
        /// <param name="serverid">Almost always 1, not quite sure what other numbers do.</param>
        /// <param name="offer">A TradeOffer object containing the trade parameters.</param>
        /// <param name="container">Auth Cookies MUST be passed here, the function will fail if not.</param>
        /// <returns>A SendOfferResponse object.</returns>
        public SendOfferResponse SendTradeOfferWithLink(ulong partnerSid, string token, string tradeoffermessage,
                                                        string serverid, TradeOffer offer, CookieContainer container)
        {
            const string url = "https://steamcommunity.com/tradeoffer/new/send";

            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();

            CEconTradeOffer offerToken = new CEconTradeOffer {
                TradeOfferAccessToken = token
            };

            var data = new Dictionary <string, string>
            {
                { "sessionid", sessionid },
                { "serverid", serverid },
                { "partner", partnerSid.ToString() },
                { "tradeoffermessage", tradeoffermessage },
                { "json_tradeoffer", JsonConvert.SerializeObject(offer) },
                { "captcha", string.Empty },
                { "trade_offer_create_params", JsonConvert.SerializeObject(offerToken) }
            };

            return
                (_web.RetryFetch(TimeSpan.FromSeconds(10), 20, url, "POST", data, container, false,
                                 string.Format("https://steamcommunity.com/tradeoffer/new/?partner={0}&token={1}",
                                               IdConversions.UlongToAccountId(partnerSid), token))
                 .DeserializeJson <SendOfferResponse>());
        }
Beispiel #3
0
        /// <summary>
        /// Sends a trade offer to the specified recipient.
        /// </summary>
        /// <param name="partnerSid">The SteamId64 (ulong) of the person to send the offer to.</param>
        /// <param name="tradeoffermessage">An optional message to be sent with the offer. Can be null.</param>
        /// <param name="serverid">Almost always 1, not quite sure what other numbers do.</param>
        /// <param name="offer">A TradeOffer object containing the trade parameters.</param>
        /// <param name="container">Auth Cookies MUST be passed here, the function will fail if not.</param>
        /// <returns>A SendOfferResponse object.</returns>
        public SendOfferResponse SendTradeOffer(ulong partnerSid, string tradeoffermessage,
                                                string serverid, TradeOffer offer, CookieContainer container)
        {
            const string url = "https://steamcommunity.com/tradeoffer/new/send";

            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();

            var data = new Dictionary <string, string>
            {
                { "sessionid", sessionid },
                { "serverid", serverid },
                { "partner", partnerSid.ToString() },
                { "tradeoffermessage", tradeoffermessage },
                { "json_tradeoffer", JsonConvert.SerializeObject(offer) },
                { "captcha", string.Empty },
                { "trade_offer_create_params", "{}" }
            };

            return(_web.Fetch(url, "POST", data, container, false,
                              "https://steamcommunity.com/tradeoffer/new/?partner=" +
                              IdConversions.UlongToAccountId(partnerSid), false, 10000, 20)
                   .DeserializeJson <SendOfferResponse>());
        }
Beispiel #4
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!");
        }
Beispiel #5
0
        public void UlongToAccountId_NoFail()
        {
            ulong input    = 76561198060315636;
            uint  expected = 100049908;
            uint  actual   = IdConversions.UlongToAccountId(input);

            Assert.AreEqual(expected, actual);
        }
Beispiel #6
0
        public void UlongToSteamIdText_NoFail()
        {
            ulong  input    = 76561198060315636;
            string expected = "STEAM_0:0:50024954";
            string actual   = IdConversions.UlongToSteamIdText(input);

            Assert.AreEqual(expected, actual);
        }
Beispiel #7
0
        public void SteamIdTextToAccountId_NoFail()
        {
            string input    = "STEAM_0:0:50024954";
            uint   expected = 100049908;
            uint   actual   = IdConversions.SteamIdTextToAccountId(input);

            Assert.AreEqual(expected, actual);
        }
Beispiel #8
0
        public void SteamIdTextToUlong_NoFail()
        {
            string input    = "STEAM_0:0:50024954";
            ulong  expected = 76561198060315636;
            ulong  actual   = IdConversions.SteamIdTextToUlong(input);

            Assert.AreEqual(expected, actual);
        }
Beispiel #9
0
        public void AccountIdToUlong_NoFail()
        {
            uint  input    = 100049908;
            ulong expected = 76561198060315636;
            ulong actual   = IdConversions.AccountIdToUlong(input);

            Assert.AreEqual(expected, actual);
        }
Beispiel #10
0
        public void AccountIdToSteamIdText_NoFail()
        {
            uint   input    = 100049908;
            string expected = "STEAM_0:0:50024954";
            string actual   = IdConversions.AccountIdToSteamIdText(input);

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

            if (control == null)
            {
                return;
            }
            InvokeHandleMessage(control, e.ChatMessage.Text);
        }
Beispiel #12
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);
        }
        private void PopulateFriendList()
        {
            List <Friend> friends = SteamUserHandler.GetFriendList(_account.SteamId, "friend");

            foreach (
                PlayerSummary friendSummary in
                friends.Select(
                    friend =>
                    SteamUserHandler.GetPlayerSummariesV2(new List <ulong> {
                friend.SteamId
            }).FirstOrDefault())
                .Where(friendSummary => friendSummary != null))
            {
                FriendSummaries.Add(friendSummary);

                FriendStateResponse state =
                    ChatHandler.FriendState(IdConversions.UlongToAccountId(friendSummary.SteamId));
                friendsStackPanel.Dispatcher.Invoke(() =>
                {
                    var control = new FriendControl(new ChatUser {
                        State = state, Summary = friendSummary
                    });
                    control.MouseDoubleClick += FriendItem_Clicked;
                    friendsStackPanel.Children.Add(control);
                });
            }

            friendsStackPanel.Dispatcher.Invoke(() =>
            {
                //sort
                List <FriendControl> controls =
                    friendsStackPanel.Children.Cast <FriendControl>().OrderBy(x => x.Friend.Summary.PersonaName).ToList();

                friendsStackPanel.Children.Clear();

                foreach (FriendControl friendControl in controls)
                {
                    friendsStackPanel.Children.Add(friendControl);
                }
            });
        }
        static void GoOnline()
        {
            PollResponse response;
            Message      responseMessage = null;

            do
            {
                response = ChatHandler.Poll(10);
                if (response.Messages == null)
                {
                    continue;
                }
                responseMessage = response.Messages.FirstOrDefault(x => x.AccountIdFrom == IdConversions.UlongToAccountId(_account.SteamId));
                Thread.Sleep(TimeSpan.FromSeconds(2));
            } while ((response.Error != "OK" || responseMessage?.PersonaState == 0));
        }