예제 #1
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>());
        }
예제 #2
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>());
        }
예제 #3
0
        public void UlongToAccountId_NoFail()
        {
            ulong input    = 76561198060315636;
            uint  expected = 100049908;
            uint  actual   = IdConversions.UlongToAccountId(input);

            Assert.AreEqual(expected, actual);
        }
        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));
        }