/// <summary> /// Create a tradeoffer object /// Add the passed list of assets to the assets of the itemsToGive list inside the tradeoffer /// Create a NameValueCollection with our data /// Format is Json so we can just do "JsonConvert.SerializeObject" which parses the object into Json string /// Create an url and send the request /// </summary> /// <param name="_tradeOfferItems"></param> /// <param name="_partnerID"></param> /// <param name="_tradeOfferMessage"></param> /// <returns></returns> public async Task <bool> SendTradeOffer(List <TradeOfferItem> _tradeOfferItems, string _partnerID, string _tradeOfferMessage = "") { if (_tradeOfferItems.Count == 0) { return(false); } TradeOfferSend tradeoffer = new TradeOfferSend(); tradeoffer.m_ItemsToGive.m_Assets.AddRange(_tradeOfferItems); NameValueCollection data = new NameValueCollection() { { "sessionid", m_steamWeb.SessionID }, { "serverid", "1" }, { "partner", _partnerID }, { "tradeoffermessage", _tradeOfferMessage }, { "json_tradeoffer", JsonConvert.SerializeObject(tradeoffer) }, { "trade_offer_create_params", "" } }; string referer = $"https://{m_steamWeb.m_SteamCommunityHost}/tradeoffer/new"; string url = $"{referer}/send"; string response = await m_steamWeb.m_WebHelper.GetStringFromRequest(url, data, false, referer).ConfigureAwait(false); TradeOfferAcceptResponse acceptResponse = JsonConvert.DeserializeObject <TradeOfferAcceptResponse>(response); if (acceptResponse != null && (acceptResponse.TradeID != null || acceptResponse.NeedsEmailConfirmation || acceptResponse.NeedsMobileConfirmation)) { return(true); } return(false); }
private void OnNewTradeOffer(TradeOffer offer) { //receiving a trade offer if (IsAdmin) { //parse inventories of bot and other partner //either with webapi or generic inventory //Bot.GetInventory(); //Bot.GetOtherInventory(OtherSID); var myItems = offer.Items.GetMyItems(); var theirItems = offer.Items.GetTheirItems(); Log.Info("They want " + myItems.Count + " of my items."); Log.Info("And I will get " + theirItems.Count + " of their items."); //do validation logic etc if (DummyValidation(myItems, theirItems)) { TradeOfferAcceptResponse acceptResp = offer.Accept(); if (acceptResp.Accepted) { Bot.AcceptAllMobileTradeConfirmations(); Log.Success("Accepted trade offer successfully : Trade ID: " + acceptResp.TradeId); } } else { // maybe we want different items or something //offer.Items.AddMyItem(0, 0, 0); //offer.Items.RemoveTheirItem(0, 0, 0); if (offer.Items.NewVersion) { string newOfferId; if (offer.CounterOffer(out newOfferId)) { Bot.AcceptAllMobileTradeConfirmations(); Log.Success("Counter offered successfully : New Offer ID: " + newOfferId); } } } } else { //we don't know this user so we can decline if (offer.Decline()) { Log.Info("Declined trade offer : " + offer.TradeOfferId + " from untrusted user " + OtherSID.ConvertToUInt64()); } } }
/// <summary> /// WebFunction, use it to modify your response/consoleoutput after getting this /// /// Accept the tradeoffer with the given id /// To accept a trade we need the current sessionID which we have in our steamWebobject stored /// We have to pass a referer else we can't accept the tradeoffer /// Make the Post-Call and get the response from the web /// </summary> /// <param name="_tradeOfferID"></param> /// <returns></returns> public async Task <bool> AcceptTradeOffer(string _tradeOfferID) { NameValueCollection data = new NameValueCollection { { "sessionid", m_steamWeb.SessionID }, { "serverid", "1" }, { "tradeofferid", _tradeOfferID } }; string referer = $"https://steamcommunity.com/tradeoffer/{_tradeOfferID}"; string response = await m_steamWeb.m_WebHelper.GetStringFromRequest($"{referer}/accept", data, false, referer).ConfigureAwait(false); TradeOfferAcceptResponse acceptResponse = JsonConvert.DeserializeObject <TradeOfferAcceptResponse>(response); if (acceptResponse != null && (acceptResponse.TradeID != null || acceptResponse.NeedsEmailConfirmation || acceptResponse.NeedsMobileConfirmation)) { return(true); } return(false); }