public override void OnMessage(string message, EChatEntryType type) { if (IsAdmin) { //creating a new trade offer var offer = Bot.NewTradeOffer(OtherSID); //offer.Items.AddMyItem(0, 0, 0); if (offer.Items.NewVersion) { string newOfferId; if (offer.Send(out newOfferId)) { Bot.AcceptAllMobileTradeConfirmations(); Log.Success("Trade offer sent : Offer ID " + newOfferId); } } //creating a new trade offer with token var offerWithToken = Bot.NewTradeOffer(OtherSID); //offer.Items.AddMyItem(0, 0, 0); if (offerWithToken.Items.NewVersion) { string newOfferId; // "token" should be replaced with the actual token from the other user if (offerWithToken.SendWithToken(out newOfferId, "token")) { Bot.AcceptAllMobileTradeConfirmations(); Log.Success("Trade offer sent : Offer ID " + newOfferId); } } } }
public override void OnBotCommand(string command) { if (command.Equals("withdraw")) { //Get current pot and all items in inventory string withdrawUrl = "http://csgowinbig.com/php/bot-withdraw.php"; var withdrawRequest = (HttpWebRequest)WebRequest.Create(withdrawUrl); var withdrawResponse = (HttpWebResponse)withdrawRequest.GetResponse(); string withdrawString = new StreamReader(withdrawResponse.GetResponseStream()).ReadToEnd(); WithdrawResponse botInventory = JsonConvert.DeserializeObject <WithdrawResponse> (withdrawString); var data = botInventory.data; var rgInventory = data.rgInventory; var currentPot = data.currentPot; var withdrawTradeOffer = Bot.NewTradeOffer(new SteamID(76561198020620333)); foreach (var inventoryItemKeyVal in rgInventory) { var invItem = inventoryItemKeyVal.Value; long classId = invItem.classid, instanceId = invItem.instanceid; bool withdrawThisItem = true; //Check to see if this item is in the current pot foreach (var potItem in currentPot) { long classIdPot = potItem.classid, instanceIdPot = potItem.instanceid; if (classId == classIdPot && instanceId == instanceIdPot) { withdrawThisItem = false; } } if (withdrawThisItem) { var assetId = invItem.id; withdrawTradeOffer.Items.AddMyItem(730, 2, assetId, 1); } } if (withdrawTradeOffer.Items.GetMyItems().Count != 0) { string withdrawOfferId; withdrawTradeOffer.Send(out withdrawOfferId, "Here are the withdraw items requested."); Log.Success("Withdraw trade offer sent. Offer ID: " + withdrawOfferId); } else { Log.Error("There are no profit items to withdraw at this time."); } } }
public override void OnMessage(string message, EChatEntryType type) { message = message.ToLower(); Log.Success(Bot.SteamFriends.GetFriendPersonaName(OtherSID) + " : " + message); Bot.SteamFriends.SendChatMessage(ownerID, EChatEntryType.ChatMsg, Bot.SteamFriends.GetFriendPersonaName(OtherSID) + " : " + message); #region Buy if (message.StartsWith("!buy")) { if (message == "!buy") { SendChatMessage("You have to put a amount in. Ex: !buy 2 for buying 2 keys."); } else { bool notEnough = false; SendChatMessage("Your request will be dealt with shortly."); int amount = 0; if (message.Substring(6) == "x") { amount = 0; SendChatMessage("You didn't enter a number. Ex: !buy 2 for buying 2 keys."); } else { try { amount = int.Parse(message.Substring(5)); } catch { SendChatMessage("You didn't put a valid number in. Example: !buy 2 for buying 2 keys"); } } // Check if the user has escrow. if (Bot.GetEscrowDuration(new SteamID(OtherSID), "").DaysTheirEscrow > 2) { SendChatMessage("Sorry, You require to have an account with a valid Phone Authenticator."); } else { // Bot adds keys. User adds metal. List <long> contextId = new List <long>(); contextId.Add(2); contextId.Add(6); mySteamInventory.load(440, contextId, Bot.SteamClient.SteamID); OtherSteamInventory.load(440, contextId, OtherSID); #region User-part //Checking users stock. int UserRefCount = 0; int UserRecCount = 0; int UserScrapCount = 0; int KeysInStock = 0; foreach (GenericInventory.Item item in OtherSteamInventory.items.Values) { if (OtherSteamInventory.getDescription(item.assetid).name == "Refined Metal" && OtherSteamInventory.getDescription(item.assetid).tradable) { UserRefCount++; } else if (OtherSteamInventory.getDescription(item.assetid).name == "Reclaimed Metal" && OtherSteamInventory.getDescription(item.assetid).tradable) { UserRecCount++; } else if (OtherSteamInventory.getDescription(item.assetid).name == "Scrap Metal" && OtherSteamInventory.getDescription(item.assetid).tradable) { UserScrapCount++; } } int MetalRequired = amount * sellPrice; int OfferChangeRequired = 0; decimal RefRequired = Math.Floor((decimal)MetalRequired / 9); if (UserRefCount < RefRequired) { RefRequired = UserRefCount; } decimal metalRequiredR = MetalRequired - (RefRequired * 9); decimal RecRequired = Math.Floor((decimal)metalRequiredR / 3); if (UserRecCount < RecRequired) { RecRequired = UserRecCount; } decimal ScrapRequired = metalRequiredR - (RecRequired * 3); if (UserScrapCount < ScrapRequired) { while (UserScrapCount < ScrapRequired) { RecRequired++; ScrapRequired -= 3; if (ScrapRequired < 0) { OfferChangeRequired = (int)ScrapRequired * -1; ScrapRequired = 0; } } } if (UserRecCount < RecRequired) { while (UserRecCount < RecRequired) { if (UserRefCount > RefRequired) { RefRequired++; RecRequired -= 3; if (RecRequired < 0) { OfferChangeRequired = ((int)RecRequired * -1) * 3; RecRequired = 0; } } else { ScrapRequired += 3; RecRequired--; } } } var offer = Bot.NewTradeOffer(OtherSID); foreach (GenericInventory.Item item in OtherSteamInventory.items.Values) { if (OtherSteamInventory.getDescription(item.assetid).name == "Refined Metal" && OtherSteamInventory.getDescription(item.assetid).tradable) { if (RefRequired > 0) { offer.Items.AddTheirItem(item.appid, item.contextid, (long)item.assetid); RefRequired--; } } else if (OtherSteamInventory.getDescription(item.assetid).name == "Reclaimed Metal" && OtherSteamInventory.getDescription(item.assetid).tradable) { if (RecRequired > 0) { offer.Items.AddTheirItem(item.appid, item.contextid, (long)item.assetid); RecRequired--; } } else if (OtherSteamInventory.getDescription(item.assetid).name == "Scrap Metal" && OtherSteamInventory.getDescription(item.assetid).tradable) { if (ScrapRequired > 0) { offer.Items.AddTheirItem(item.appid, item.contextid, (long)item.assetid); ScrapRequired--; } } if (RefRequired == 0 && RecRequired == 0 && ScrapRequired == 0) { break; } } if (!(RefRequired == 0 && RecRequired == 0 && ScrapRequired == 0)) { notEnough = true; SendChatMessage("Sorry, You dont have enough metal. (You need " + string.Format("{0:0.000}", (int.Parse("" + ScrapRequired) / 9.0)).Substring(0, 4) + " Scrap more.)"); } foreach (GenericInventory.Item item in mySteamInventory.items.Values) { if (mySteamInventory.getDescription(item.assetid).name == "Mann Co. Supply Crate Key" && mySteamInventory.getDescription(item.assetid).tradable) { KeysInStock++; } } if (amount > KeysInStock) { SendChatMessage("Sorry, I dont have enough keys in stock. (Current stock: " + KeysInStock + " keys)."); notEnough = true; } #endregion #region BotPart if (!notEnough) { int KeysRemaining = amount; foreach (GenericInventory.Item item in mySteamInventory.items.Values) { if (KeysRemaining > 0) { if (mySteamInventory.getDescription(item.assetid).name == "Mann Co. Supply Crate Key" && mySteamInventory.getDescription(item.assetid).tradable&& !UsedAssetIDs.Contains(item.assetid)) { offer.Items.AddMyItem(item.appid, item.contextid, (long)item.assetid); KeysRemaining--; } } if (OfferChangeRequired >= 9) { if (mySteamInventory.getDescription(item.assetid).name == "Refined Metal" && mySteamInventory.getDescription(item.assetid).tradable&& !UsedAssetIDs.Contains(item.assetid)) { offer.Items.AddMyItem(item.appid, item.contextid, (long)item.assetid); OfferChangeRequired -= 9; } } } foreach (GenericInventory.Item item in mySteamInventory.items.Values) { if (OfferChangeRequired >= 3 && OfferChangeRequired < 9) { if (mySteamInventory.getDescription(item.assetid).name == "Reclaimed Metal" && mySteamInventory.getDescription(item.assetid).tradable&& !UsedAssetIDs.Contains(item.assetid)) { offer.Items.AddMyItem(item.appid, item.contextid, (long)item.assetid); OfferChangeRequired -= 3; } } } foreach (GenericInventory.Item item in mySteamInventory.items.Values) { if (OfferChangeRequired >= 1 && OfferChangeRequired < 3) { if (mySteamInventory.getDescription(item.assetid).name == "Scrap Metal" && mySteamInventory.getDescription(item.assetid).tradable&& !UsedAssetIDs.Contains(item.assetid)) { offer.Items.AddMyItem(item.appid, item.contextid, (long)item.assetid); OfferChangeRequired -= 1; } } } if (KeysRemaining != 0 && OfferChangeRequired != 0) { SendChatMessage("Sorry, I dont have enough stock to send this order."); } #endregion #region Sending Offer.. else { if (offer.Items.NewVersion) { string newOfferId; if (offer.Send(out newOfferId, "Please leave a +rep if liked it!")) { Bot.AcceptAllMobileTradeConfirmations(); SendChatMessage("Thanks for trading with us.Your order (" + amount + " keys) has been sent."); //SendChatMessage("If you like a comment from me, Send me \"+rep\" in the chat."); SendChatMessage("You can accept it here: https://steamcommunity.com/tradeoffer/" + newOfferId + "/"); Log.Success("Trade offer sent : Offer ID " + newOfferId); Bot.SteamFriends.SendChatMessage(ownerID, EChatEntryType.ChatMsg, "I've sold a key to " + Bot.SteamFriends.GetFriendPersonaName(OtherSID)); } } } } #endregion } } } #endregion #region Sell else if (message.StartsWith("!sell")) { if (message == "!sell") { SendChatMessage("You have to put a amount in. Ex: !sell 2 for selling 2 keys."); } else { bool notEnough = false; SendChatMessage("Your request will be dealt with shortly."); int amount = 0; if (message.Substring(6) == "x") { amount = 0; SendChatMessage("You didn't enter a number. Ex: !sell 2 for selling 2 keys."); } else { try { amount = int.Parse(message.Substring(6)); } catch { SendChatMessage("You didn't put a valid number in. Example: !sell 2 for selling 2 keys"); } } // Check if the user has escrow. if (Bot.GetEscrowDuration(new SteamID(OtherSID), "").DaysTheirEscrow > 2) { SendChatMessage("Sorry, You require to have an account with a valid Phone Authenticator."); } else { List <long> contextId = new List <long>(); contextId.Add(2); contextId.Add(6); mySteamInventory.load(440, contextId, Bot.SteamClient.SteamID); OtherSteamInventory.load(440, contextId, OtherSID); int KeysRequired = amount; int MetalRequired = amount * buyPrice; var offer = Bot.NewTradeOffer(OtherSID); #region User-part //Checking users stock. foreach (GenericInventory.Item item in OtherSteamInventory.items.Values) { if (KeysRequired != 0) { if (OtherSteamInventory.getDescription(item.assetid).name == "Mann Co. Supply Crate Key" && OtherSteamInventory.getDescription(item.assetid).tradable) { offer.Items.AddTheirItem(item.appid, item.contextid, (long)item.assetid); KeysRequired--; } } } if (KeysRequired != 0) { SendChatMessage("You dont have enough keys available for selling " + amount + " keys."); notEnough = true; } #endregion #region Bot-part else { foreach (GenericInventory.Item item in mySteamInventory.items.Values) { if (mySteamInventory.getDescription(item.assetid).name == "Refined Metal" && mySteamInventory.getDescription(item.assetid).tradable&& !UsedAssetIDs.Contains(item.assetid)) { if (MetalRequired >= 9) { offer.Items.AddMyItem(item.appid, item.contextid, (long)item.assetid); MetalRequired -= 9; } } } foreach (GenericInventory.Item item in mySteamInventory.items.Values) { if (mySteamInventory.getDescription(item.assetid).name == "Reclaimed Metal" && mySteamInventory.getDescription(item.assetid).tradable&& !UsedAssetIDs.Contains(item.assetid)) { if (MetalRequired >= 3 && MetalRequired <= 8) { offer.Items.AddMyItem(item.appid, item.contextid, (long)item.assetid); MetalRequired -= 3; } } } foreach (GenericInventory.Item item in mySteamInventory.items.Values) { if (mySteamInventory.getDescription(item.assetid).name == "Scrap Metal" && mySteamInventory.getDescription(item.assetid).tradable&& !UsedAssetIDs.Contains(item.assetid)) { if (MetalRequired >= 1 && MetalRequired < 9) { offer.Items.AddMyItem(item.appid, item.contextid, (long)item.assetid); MetalRequired -= 1; } } } if (MetalRequired != 0) { Console.WriteLine(MetalRequired); SendChatMessage("I dont have enough metal."); } #endregion #region Sending Offer.. else { if (offer.Items.NewVersion) { string newOfferId; offer.Send(out newOfferId, "Please leave a +rep if liked it!"); if (!(newOfferId == null || newOfferId == String.Empty)) { Bot.AcceptAllMobileTradeConfirmations(); SendChatMessage("Thanks for trading with us. Your order (" + amount + " keys) has been sent."); SendChatMessage("You can accept it here: https://steamcommunity.com/tradeoffer/" + newOfferId + "/"); Log.Success("Trade offer sent : Offer ID " + newOfferId); Bot.SteamFriends.SendChatMessage(ownerID, EChatEntryType.ChatMsg, "I've bought a key from " + Bot.SteamFriends.GetFriendPersonaName(OtherSID)); } } } #endregion } } } } #endregion #region Help else if (message.Contains("help")) { SendChatMessage("For first you have to check if I have keys or metals in my inventory. You can do it by writing \"stock\" (without quotation marks) to me. Also dont forget to check current price by writing \"price\". If you do this and you're sure I have things you want in my stock and you agree with price, use command \"!buy x\" or \"!sell x\" - \"x\" is amount of goods you want to buy. Right after doing that bot will send you trade offer with key(s) and metals."); SendChatMessage("*Example* - you want to buy 2 keys, so write !buy 2 and wait for offer."); } #endregion #region Stock else if (message.Contains("stock")) { int StockScrap = 0; int StockReclaimed = 0; int StockRefined = 0; int StockKey = 0; Bot.GetInventory(); Inventory myInventory = Bot.MyInventory; foreach (Inventory.Item item in myInventory.Items) { if (item.Defindex == 5000) { StockScrap++; } else if (item.Defindex == 5001) { StockReclaimed++; } else if (item.Defindex == 5002) { StockRefined++; } else if (item.Defindex == 5021) { StockKey++; } } if ((StockScrap / 9.0) + (StockReclaimed / 3.0) + (StockRefined) < 10) { Bot.SteamFriends.SendChatMessage(OtherSID, EChatEntryType.ChatMsg, "I have : " + string.Format("{0:0.000}", (StockScrap / 9.0) + (StockReclaimed / 3.0) + (StockRefined)).Substring(0, 4) + " refined. (" + StockRefined + " refined, " + StockReclaimed + " reclaimed, " + StockScrap + " scrap) and " + StockKey + " key(s)."); } else { Bot.SteamFriends.SendChatMessage(OtherSID, EChatEntryType.ChatMsg, "I have : " + string.Format("{0:0.000}", (StockScrap / 9.0) + (StockReclaimed / 3.0) + (StockRefined)).Substring(0, 5) + " refined. (" + StockRefined + " refined, " + StockReclaimed + " reclaimed, " + StockScrap + " scrap) and " + StockKey + " key(s)."); } } #endregion #region Price else if (message.Contains("price") || message == ("p") || message.Contains("buying") || message.Contains("selling")) { Bot.SteamFriends.SendChatMessage(OtherSID, type, "I'm buying keys for " + string.Format("{0:0.000}", buyPrice / 9.0).Substring(0, 5) + " refined, and selling for " + string.Format("{0:0.000}", sellPrice / 9.0).Substring(0, 5) + " refined."); } #endregion #region Owner else if (message.Contains("owner") || message.Contains("mod") || message.Contains("admin")) { SendChatMessage("My owner is Krypton. ( https://steamcommunity.com/id/KryptonGas )"); } #endregion #region Group else if (message.Contains("group") || message.Contains("community")) { SendChatMessage("You can get latest info, updates and helpful things in our group. ( http://steamcommunity.com/groups/TF2bot )"); } #endregion #region Play else if (message.Contains(".play")) { if (IsAdmin) { string PlayID = message.Substring(6); if (PlayID.Contains("list")) { //List of GameIDs Bot.SteamFriends.SendChatMessage(OtherSID, type, "List of GameIDs:"); Bot.SteamFriends.SendChatMessage(OtherSID, type, "440. Team Fortress 2"); Bot.SteamFriends.SendChatMessage(OtherSID, type, "570. Dota 2"); Bot.SteamFriends.SendChatMessage(OtherSID, type, "301520. RoboCraft"); } if (PlayID.Contains("n")) { //No, None, Nothing etc. Bot.SetGamePlaying(0); } else { // Play-Part int PlayMessage = Int32.Parse(PlayID); Bot.SetGamePlaying(PlayMessage); } } else { Bot.SteamFriends.SendChatMessage(OtherSID, type, "No."); } } #endregion #region Trade else if (message.Contains("trade")) { SendChatMessage("Sorry, You can't trade with normal trading, Use trade offers instead, Do command \"help\" to know how!"); } #endregion #region Escrow else if (message.Contains("escrow") || (message.Contains("hold") && message.Contains("trade"))) { bool HasEscrow = Bot.GetEscrowDuration(new SteamID(OtherSID), "").DaysTheirEscrow > 0; if (HasEscrow) { SendChatMessage("You have escrow :( , Which means you are unable to trade with this bot."); SendChatMessage("You can find more information about activating Phone Authentication here: https://support.steampowered.com/kb_article.php?ref=4440-RTUI-9218 ."); } else { SendChatMessage("You have no escrow!!! You are able to trade with this bot!"); } } #endregion #region getauth else if (message == "getauth") { if (IsAdmin) { try { SendChatMessage("Generated Steam Guard code: " + Bot.SteamGuardAccount.GenerateSteamGuardCode()); } catch (NullReferenceException) { SendChatMessage("Unable to generate Steam Guard code."); } } } #endregion #region Else else { SendChatMessage("Sorry, I dont know what you mean.. Available commands: \"!buy\", \"!sell\", \"help\", \"stock\", \"price\", \"owner\", \"group\"."); } #endregion }
private void sendWinnings(JSONClass winningsResponseObj) { if (winningsResponseObj.success != 1) { Log.Error("Server request failed. Error message:\n" + winningsResponseObj.errMsg); return; } Data winningsData = winningsResponseObj.data; //Get items to give and keep, and the winner and their trade token var itemsToGive = winningsData.tradeItems; var itemsToKeep = winningsData.profitItems; string winnerSteamIDString = winningsData.winnerSteamId; SteamID winnerSteamID = new SteamID(winnerSteamIDString); string winnerTradeToken = winningsData.winnerTradeToken; Log.Success("Winner steam id: " + winnerSteamIDString + ", token: " + winnerTradeToken); //Get bot's inventory json string botInvUrl = "http://steamcommunity.com/profiles/" + Bot.SteamUser.SteamID.ConvertToUInt64() + "/inventory/json/730/2"; var botInvRequest = (HttpWebRequest)WebRequest.Create(botInvUrl); var botInvResponse = (HttpWebResponse)botInvRequest.GetResponse(); string botInvString = new StreamReader(botInvResponse.GetResponseStream()).ReadToEnd(); BotInventory botInventory = JsonConvert.DeserializeObject <BotInventory>(botInvString); if (botInventory.success != true) { Log.Error("An error occured while fetching the bot's inventory."); return; } var rgInventory = botInventory.rgInventory; //Create trade offer for the winner var winnerTradeOffer = Bot.NewTradeOffer(winnerSteamID); //Loop through all winner's items and add them to trade List <long> alreadyAddedToWinnerTrade = new List <long>(); foreach (CSGOItemFromWeb item in itemsToGive) { long classId = item.classId, instanceId = item.instanceId; //Loop through all inventory items and find the asset id for the item long assetId = 0; foreach (var inventoryItem in rgInventory) { var value = inventoryItem.Value; long tAssetId = value.id, tClassId = value.classid, tInstanceId = value.instanceid; if (tClassId == classId && tInstanceId == instanceId) { //Check if this assetId has already been added to the trade if (alreadyAddedToWinnerTrade.Contains(tAssetId)) { continue; //This is for when there are 2 of the same weapon, but they have different assetIds } assetId = tAssetId; break; } } //Log.Success ("Adding item to winner trade offer. Asset ID: " + assetId); winnerTradeOffer.Items.AddMyItem(730, 2, assetId, 1); alreadyAddedToWinnerTrade.Add(assetId); } //Send trade offer to winner if (itemsToGive.Count > 0) { string winnerTradeOfferId, winnerMessage = "Congratulations, you have won on " + Bot.BotWebsiteName + "! Here are your items."; //Try sending them 10 times, whatever doWebWithCatch(10, () => { winnerTradeOffer.SendWithToken(out winnerTradeOfferId, winnerTradeToken, winnerMessage); }); Bot.AcceptAllMobileTradeConfirmations(); Log.Success("Offer sent to winner."); } else { Log.Info("No items to give to the winner... strange"); } }
public override void OnBotCommand(string command) { if (IsAdmin) { if (command.Equals("confirm")) { Bot.AcceptAllMobileTradeConfirmations(); Log.Success("All trade offers confirmed... on bot: " + Bot.SteamUser.SteamID.ConvertToUInt64()); } } if (command.Equals("skins")) { //Get current pot and all items in inventory string withdrawUrl = Bot.BotWebsiteURL + "/php/bot-withdraw.php"; var withdrawRequest = (HttpWebRequest)WebRequest.Create(withdrawUrl); var withdrawResponse = (HttpWebResponse)withdrawRequest.GetResponse(); string withdrawString = new StreamReader(withdrawResponse.GetResponseStream()).ReadToEnd(); WithdrawResponse botInventory = JsonConvert.DeserializeObject <WithdrawResponse>(withdrawString); var data = botInventory.data; var rgInventory = data.rgInventory; var currentPot = data.currentPot; var withdrawTradeOffer = Bot.NewTradeOffer(new SteamID(Bot.ProfitAdmin)); foreach (var inventoryItemKeyVal in rgInventory) { var invItem = inventoryItemKeyVal.Value; long classId = invItem.classid, instanceId = invItem.instanceid; bool withdrawThisItem = true; //Check to see if this item is in the current pot foreach (var potItem in currentPot) { long classIdPot = potItem.classid, instanceIdPot = potItem.instanceid; if (classId == classIdPot && instanceId == instanceIdPot) { withdrawThisItem = false; } } if (withdrawThisItem) { if (invItem.instanceid != 0) { if (invItem.instanceid != 519977179) { var assetId = invItem.id; withdrawTradeOffer.Items.AddMyItem(730, 2, assetId, 1); } } } } if (withdrawTradeOffer.Items.GetMyItems().Count != 0) { string withdrawOfferId; withdrawTradeOffer.Send(out withdrawOfferId, "Here are the withdraw items requested."); Bot.AcceptAllMobileTradeConfirmations(); Log.Success("Withdraw trade offer sent. Offer ID: " + withdrawOfferId); } else { Log.Error("There are no profit items to withdraw at this time."); } } if (command.Equals("withdraw")) { //Get current pot and all items in inventory string withdrawUrl = Bot.BotWebsiteURL + "/php/bot-withdraw.php"; var withdrawRequest = (HttpWebRequest)WebRequest.Create(withdrawUrl); var withdrawResponse = (HttpWebResponse)withdrawRequest.GetResponse(); string withdrawString = new StreamReader(withdrawResponse.GetResponseStream()).ReadToEnd(); WithdrawResponse botInventory = JsonConvert.DeserializeObject <WithdrawResponse>(withdrawString); var data = botInventory.data; var rgInventory = data.rgInventory; var currentPot = data.currentPot; var withdrawTradeOffer = Bot.NewTradeOffer(new SteamID(Bot.ProfitAdmin)); foreach (var inventoryItemKeyVal in rgInventory) { var invItem = inventoryItemKeyVal.Value; long classId = invItem.classid, instanceId = invItem.instanceid; bool withdrawThisItem = true; //Check to see if this item is in the current pot foreach (var potItem in currentPot) { long classIdPot = potItem.classid, instanceIdPot = potItem.instanceid; if (classId == classIdPot && instanceId == instanceIdPot) { withdrawThisItem = false; } } if (withdrawThisItem) { var assetId = invItem.id; withdrawTradeOffer.Items.AddMyItem(730, 2, assetId, 1); } } if (withdrawTradeOffer.Items.GetMyItems().Count != 0) { string withdrawOfferId; withdrawTradeOffer.Send(out withdrawOfferId, "Here are the withdraw items requested."); Bot.AcceptAllMobileTradeConfirmations(); Log.Success("Withdraw trade offer sent. Offer ID: " + withdrawOfferId); } else { Log.Error("There are no profit items to withdraw at this time."); } } }
public override void OnNewTradeOffer(TradeOffer offer) { //Get password from file on desktop string pass = System.IO.File.ReadAllText(@"C:\Users\Jordan Turley\Desktop\password.txt"); //Get items in the trade, and ID of user sending trade var theirItems = offer.Items.GetTheirItems(); var myItems = offer.Items.GetMyItems(); var userID = offer.PartnerSteamId; bool shouldDecline = false; //Check if they are trying to get items from the bot if (myItems.Count > 0 || theirItems.Count == 0) { shouldDecline = true; Log.Error("Offer declined because the offer wasn't a gift; the user wanted items instead of giving."); } //Check to make sure all items are for CS: GO. foreach (TradeAsset item in theirItems) { if (item.AppId != 730) { shouldDecline = true; Log.Error("Offer declined because one or more items was not for CS: GO."); } } //Check if there are more than 10 items in the trade if (theirItems.Count > 10) { shouldDecline = true; Log.Error("Offer declined because there were more than 10 items in the deposit."); } if (shouldDecline) { if (offer.Decline()) { Log.Error("Offer declined."); } return; } Log.Success("Offer approved, accepting."); //Send items to server and check if all items add up to more than $1. //If they do, accept the trade. If they don't, decline the trade. string postData = "password="******"&owner=" + userID; string theirItemsJSON = JsonConvert.SerializeObject(theirItems); postData += "&items=" + theirItemsJSON; string url = "http://csgowinbig.com/php/check-items.php"; var request = (HttpWebRequest)WebRequest.Create(url); var data = Encoding.ASCII.GetBytes(postData); request.Method = "POST"; request.ContentType = "application/x-www-form-urlencoded"; request.ContentLength = data.Length; using (var stream = request.GetRequestStream()) { stream.Write(data, 0, data.Length); } var response = (HttpWebResponse)request.GetResponse(); var responseString = new StreamReader(response.GetResponseStream()).ReadToEnd(); //Log.Success ("Response received from server: \n" + responseString); JSONClass responseJsonObj = JsonConvert.DeserializeObject <JSONClass> (responseString); if (responseJsonObj.success == 1) { //Get data array from json var jsonData = responseJsonObj.data; if (jsonData.minDeposit == 1) { if (offer.Accept()) { Log.Success("Offer accepted from " + userID); //Put items into the pot string urlPutItemsIn = "http://csgowinbig.com/php/deposit.php"; var requestUrlPutItemsIn = (HttpWebRequest)WebRequest.Create(urlPutItemsIn); string postDataPutItemsIn = "password="******"&owner=" + userID; postDataPutItemsIn += "&items=" + jsonData.allItems; //Log.Success (jsonData.allItems); var dataPutItemsIn = Encoding.ASCII.GetBytes(postDataPutItemsIn); requestUrlPutItemsIn.Method = "POST"; requestUrlPutItemsIn.ContentType = "application/x-www-form-urlencoded"; requestUrlPutItemsIn.ContentLength = dataPutItemsIn.Length; using (var stream = requestUrlPutItemsIn.GetRequestStream()) { stream.Write(dataPutItemsIn, 0, dataPutItemsIn.Length); } var responsePutItemsIn = (HttpWebResponse)requestUrlPutItemsIn.GetResponse(); string responsePutItemsInString = new StreamReader(responsePutItemsIn.GetResponseStream()).ReadToEnd(); JSONClass responseJsonObjPutItemsIn = JsonConvert.DeserializeObject <JSONClass> (responsePutItemsInString); jsonData = responseJsonObjPutItemsIn.data; } //Check if the pot is over if (jsonData.potOver == 1) { //Get items to give and keep, and the winner and their trade token var itemsToGive = jsonData.tradeItems; var itemsToKeep = jsonData.profitItems; string winnerSteamIDString = jsonData.winnerSteamID; SteamID winnerSteamID = new SteamID(winnerSteamIDString); string winnerTradeToken = jsonData.winnerTradeToken; Log.Success("Winner steam id: " + winnerSteamIDString + ", token: " + winnerTradeToken); //Get bot's inventory json string botInvUrl = "http://steamcommunity.com/profiles/76561198238743988/inventory/json/730/2"; var botInvRequest = (HttpWebRequest)WebRequest.Create(botInvUrl); var botInvResponse = (HttpWebResponse)botInvRequest.GetResponse(); string botInvString = new StreamReader(botInvResponse.GetResponseStream()).ReadToEnd(); BotInventory botInventory = JsonConvert.DeserializeObject <BotInventory> (botInvString); if (botInventory.success != true) { Log.Error("An error occured while fetching the bot's inventory."); return; } var rgInventory = botInventory.rgInventory; //Create trade offer for the winner var winnerTradeOffer = Bot.NewTradeOffer(winnerSteamID); //Loop through all winner's items and add them to trade List <long> alreadyAddedToWinnerTrade = new List <long> (); foreach (CSGOItemFromWeb item in itemsToGive) { long classId = item.classId, instanceId = item.instanceId; //Loop through all inventory items and find the asset id for the item long assetId = 0; foreach (var inventoryItem in rgInventory) { var value = inventoryItem.Value; long tAssetId = value.id, tClassId = value.classid, tInstanceId = value.instanceid; if (tClassId == classId && tInstanceId == instanceId) { //Check if this assetId has already been added to the trade if (alreadyAddedToWinnerTrade.Contains(tAssetId)) { continue; //This is for when there are 2 of the same weapon, but they have different assetIds } assetId = tAssetId; break; } } //Log.Success ("Adding item to winner trade offer. Asset ID: " + assetId); winnerTradeOffer.Items.AddMyItem(730, 2, assetId, 1); alreadyAddedToWinnerTrade.Add(assetId); } //Send trade offer to winner if (itemsToGive.Count > 0) { string winnerTradeOfferId, winnerMessage = "Congratulations, you have won on CSGO Win Big! Here are your items."; winnerTradeOffer.SendWithToken(out winnerTradeOfferId, winnerTradeToken, winnerMessage); Log.Success("Offer sent to winner."); } else { Log.Info("No items to give... strange"); } } } else { if (offer.Decline()) { Log.Error("Minimum deposit not reached, offer declined."); } } } else { Log.Error("Server deposit request failed, declining trade. Error message:\n" + responseJsonObj.errMsg); offer.Decline(); } }
private void timerEvent(object CancellationTokenSource, ElapsedEventArgs e) { timerTime++; //Check if the timer is at 2 minutes if (timerTime >= 120) { //If the timer is done, stop the timer and call to server to end the round/pick a winner timer.Stop(); timerTime = 0; timerRunning = false; //Get password from file on desktop string pass = Bot.BotDBPassword; string urlTimerEnd = Bot.BotWebsiteURL + "/php/timer-end.php"; var requestUrlTimerEnd = (HttpWebRequest)WebRequest.Create(urlTimerEnd); string postDataTimerEnd = "password="******"POST"; requestUrlTimerEnd.ContentType = "application/x-www-form-urlencoded"; requestUrlTimerEnd.ContentLength = dataTimerEnd.Length; using (var stream = requestUrlTimerEnd.GetRequestStream()) { stream.Write(dataTimerEnd, 0, dataTimerEnd.Length); } var responseTimerEnd = (HttpWebResponse)requestUrlTimerEnd.GetResponse(); string responseTimerEndString = new StreamReader(responseTimerEnd.GetResponseStream()).ReadToEnd(); //Uncomment this line to print out the response from timer-end.php //Log.Success ("Response received from timer-end.php: " + responseTimerEndString); JSONClass timerEndJsonObj = JsonConvert.DeserializeObject <JSONClass>(responseTimerEndString); if (timerEndJsonObj.success != 1) { Log.Error("Server request failed. Error message:\n" + timerEndJsonObj.errMsg); return; } Data timerEndData = timerEndJsonObj.data; //Get items to give and keep, and the winner and their trade token var itemsToGive = timerEndData.tradeItems; var itemsToKeep = timerEndData.profitItems; string winnerSteamIDString = timerEndData.winnerSteamId; SteamID winnerSteamID = new SteamID(winnerSteamIDString); string winnerTradeToken = timerEndData.winnerTradeToken; Log.Success("Winner steam id: " + winnerSteamIDString + ", token: " + winnerTradeToken); //Get bot's inventory json string botInvUrl = "http://steamcommunity.com/profiles/" + Bot.SteamUser.SteamID.ConvertToUInt64() + "/inventory/json/730/2"; var botInvRequest = (HttpWebRequest)WebRequest.Create(botInvUrl); var botInvResponse = (HttpWebResponse)botInvRequest.GetResponse(); string botInvString = new StreamReader(botInvResponse.GetResponseStream()).ReadToEnd(); BotInventory botInventory = JsonConvert.DeserializeObject <BotInventory>(botInvString); if (botInventory.success != true) { Log.Error("An error occured while fetching the bot's inventory."); return; } var rgInventory = botInventory.rgInventory; //Create trade offer for the winner var winnerTradeOffer = Bot.NewTradeOffer(winnerSteamID); //Loop through all winner's items and add them to trade List <long> alreadyAddedToWinnerTrade = new List <long>(); foreach (CSGOItemFromWeb item in itemsToGive) { long classId = item.classId, instanceId = item.instanceId; //Loop through all inventory items and find the asset id for the item long assetId = 0; foreach (var inventoryItem in rgInventory) { var value = inventoryItem.Value; long tAssetId = value.id, tClassId = value.classid, tInstanceId = value.instanceid; if (tClassId == classId && tInstanceId == instanceId) { //Check if this assetId has already been added to the trade if (alreadyAddedToWinnerTrade.Contains(tAssetId)) { continue; //This is for when there are 2 of the same weapon, but they have different assetIds } assetId = tAssetId; break; } } //Log.Success ("Adding item to winner trade offer. Asset ID: " + assetId); winnerTradeOffer.Items.AddMyItem(730, 2, assetId, 1); alreadyAddedToWinnerTrade.Add(assetId); } //Send trade offer to winner if (itemsToGive.Count > 0) { string winnerTradeOfferId, winnerMessage = "Congratulations, you have won on " + Bot.BotWebsiteName + "! Here are your items."; doWebWithCatch(-1, () => { winnerTradeOffer.SendWithToken(out winnerTradeOfferId, winnerTradeToken, winnerMessage); }); Bot.AcceptAllMobileTradeConfirmations(); Log.Success("Offer sent to winner."); } else { Log.Info("No items to give... strange"); } //Now, send all of the profit items to my own account var profitTradeOffer = Bot.NewTradeOffer(new SteamID(Bot.ProfitAdmin)); //Loop through all profit items and add them to trade List <long> alreadyAddedToProfitTrade = new List <long>(); foreach (CSGOItemFromWeb item in itemsToKeep) { long classId = item.classId, instanceId = item.instanceId; //Loop through all inventory items and find the asset id for the item long assetId = 0; foreach (var inventoryItem in rgInventory) { var value = inventoryItem.Value; long tAssetId = value.id, tClassId = value.classid, tInstanceId = value.instanceid; if (tClassId == classId && tInstanceId == instanceId) { //Check if this assetId has already been added to the trade if (alreadyAddedToProfitTrade.Contains(tAssetId)) { continue; //This is for when there are 2 of the same weapon, but they have different assetIds } assetId = tAssetId; break; } } //Log.Success ("Adding item to winner trade offer. Asset ID: " + assetId); profitTradeOffer.Items.AddMyItem(730, 2, assetId, 1); alreadyAddedToProfitTrade.Add(assetId); } //Send trade offer to myself with profit items if (itemsToKeep.Count > 0) { string profitTradeOfferId, profitMessage = "Here are the profit items from the round."; doWebWithCatch(10, () => { profitTradeOffer.Send(out profitTradeOfferId, profitMessage); }); Bot.AcceptAllMobileTradeConfirmations(); Log.Success("Profit offer sent."); } } }
public override void OnNewTradeOffer(TradeOffer offer) { var escrow = Bot.GetEscrowDuration(offer.TradeOfferId); if (escrow.DaysMyEscrow != 0 || escrow.DaysTheirEscrow != 0) { doWebWithCatch(1, () => { if (offer.Decline()) { Log.Error("User has not been using the Mobile Authenticator for 7 days or has turned off trade confirmations, offer declined."); } }); } else { //Get password from file on desktop string pass = Bot.BotDBPassword; //Get items in the trade, and ID of user sending trade var theirItems = offer.Items.GetTheirItems(); var myItems = offer.Items.GetMyItems(); var userID = offer.PartnerSteamId; bool shouldDecline = false; //Check if they are trying to get items from the bot if (myItems.Count > 0 || theirItems.Count == 0) { //shouldDecline = true; Log.Error("Offer declined because the offer wasn't a gift; the user wanted items instead of giving."); } //Check to make sure all items are for CS: GO. foreach (TradeAsset item in theirItems) { if (item.AppId != 730) { shouldDecline = true; Log.Error("Offer declined because one or more items was not for CS: GO."); } } //Check if there are more than 10 items in the trade if (theirItems.Count > 10) { shouldDecline = true; Log.Error("Offer declined because there were more than 10 items in the deposit."); } if (shouldDecline) { doWebWithCatch(1, () => { if (offer.Decline()) { Log.Error("Offer declined."); } }); return; } Log.Success("Offer approved, accepting."); //Send items to server and check if all items add up to more than $1. //If they do, accept the trade. If they don't, decline the trade. string postData = "password="******"&owner=" + userID; string theirItemsJSON = JsonConvert.SerializeObject(theirItems); postData += "&items=" + theirItemsJSON; string url = Bot.BotWebsiteURL + "/php/check-items.php"; var request = (HttpWebRequest)WebRequest.Create(url); var data = Encoding.ASCII.GetBytes(postData); request.Method = "POST"; request.ContentType = "application/x-www-form-urlencoded"; request.ContentLength = data.Length; using (var stream = request.GetRequestStream()) { stream.Write(data, 0, data.Length); } var response = (HttpWebResponse)request.GetResponse(); var responseString = new StreamReader(response.GetResponseStream()).ReadToEnd(); //Uncomment this line to view the response from check-items.php //Log.Success ("Response received from check-items.php: \n" + responseString); JSONClass responseJsonObj = JsonConvert.DeserializeObject <JSONClass>(responseString); if (responseJsonObj.success == 1) { //Get data array from json var jsonData = responseJsonObj.data; if (jsonData.minDeposit == 1) { doWebWithCatch(10, () => { if (offer.Accept()) { Log.Success("Offer accepted from " + userID); //Put items into the pot string urlPutItemsIn = Bot.BotWebsiteURL + "/php/deposit.php"; var requestUrlPutItemsIn = (HttpWebRequest)WebRequest.Create(urlPutItemsIn); string postDataPutItemsIn = "password="******"&owner=" + userID; postDataPutItemsIn += "&items=" + jsonData.allItems; //Log.Success (jsonData.allItems); var dataPutItemsIn = Encoding.ASCII.GetBytes(postDataPutItemsIn); requestUrlPutItemsIn.Method = "POST"; requestUrlPutItemsIn.ContentType = "application/x-www-form-urlencoded"; requestUrlPutItemsIn.ContentLength = dataPutItemsIn.Length; using (var stream = requestUrlPutItemsIn.GetRequestStream()) { stream.Write(dataPutItemsIn, 0, dataPutItemsIn.Length); } var responsePutItemsIn = (HttpWebResponse)requestUrlPutItemsIn.GetResponse(); string responsePutItemsInString = new StreamReader(responsePutItemsIn.GetResponseStream()).ReadToEnd(); //Uncomment this line to view the response from deposit.php //Log.Success ("Response received from deposit.php: " + responsePutItemsInString); JSONClass responseJsonObjPutItemsIn = JsonConvert.DeserializeObject <JSONClass>(responsePutItemsInString); jsonData = responseJsonObjPutItemsIn.data; } }); //Check if it should start the timer if (jsonData.startTimer == 1) { //Check if the timer is already running. if (!timerRunning) { timer = new System.Timers.Timer(); timer.Elapsed += new ElapsedEventHandler(timerEvent); timer.Interval = 1000; timer.Start(); timerRunning = true; } } //Check if the pot is over if (jsonData.potOver == 1) { //End the timer timerTime = 0; timer.Stop(); //Get items to give and keep, and the winner and their trade token var itemsToGive = jsonData.tradeItems; var itemsToKeep = jsonData.profitItems; string winnerSteamIDString = jsonData.winnerSteamId; SteamID winnerSteamID = new SteamID(winnerSteamIDString); string winnerTradeToken = jsonData.winnerTradeToken; Log.Success("Winner steam id: " + winnerSteamIDString + ", token: " + winnerTradeToken); //Get bot's inventory json string botInvUrl = "http://steamcommunity.com/profiles/" + Bot.SteamUser.SteamID.ConvertToUInt64() + "/inventory/json/730/2"; var botInvRequest = (HttpWebRequest)WebRequest.Create(botInvUrl); var botInvResponse = (HttpWebResponse)botInvRequest.GetResponse(); string botInvString = new StreamReader(botInvResponse.GetResponseStream()).ReadToEnd(); BotInventory botInventory = JsonConvert.DeserializeObject <BotInventory>(botInvString); if (botInventory.success != true) { Log.Error("An error occured while fetching the bot's inventory."); return; } var rgInventory = botInventory.rgInventory; //Create trade offer for the winner var winnerTradeOffer = Bot.NewTradeOffer(winnerSteamID); //Loop through all winner's items and add them to trade List <long> alreadyAddedToWinnerTrade = new List <long>(); foreach (CSGOItemFromWeb item in itemsToGive) { long classId = item.classId, instanceId = item.instanceId; //Loop through all inventory items and find the asset id for the item long assetId = 0; foreach (var inventoryItem in rgInventory) { var value = inventoryItem.Value; long tAssetId = value.id, tClassId = value.classid, tInstanceId = value.instanceid; if (tClassId == classId && tInstanceId == instanceId) { //Check if this assetId has already been added to the trade if (alreadyAddedToWinnerTrade.Contains(tAssetId)) { continue; //This is for when there are 2 of the same weapon, but they have different assetIds } assetId = tAssetId; break; } } //Log.Success ("Adding item to winner trade offer. Asset ID: " + assetId); winnerTradeOffer.Items.AddMyItem(730, 2, assetId, 1); alreadyAddedToWinnerTrade.Add(assetId); } //Send trade offer to winner if (itemsToGive.Count > 0) { string winnerTradeOfferId, winnerMessage = "Congratulations, you have won on " + Bot.BotWebsiteName + "! Here are your items."; doWebWithCatch(-1, () => { if (winnerTradeOffer.SendWithToken(out winnerTradeOfferId, winnerTradeToken, winnerMessage)) { Bot.AcceptAllMobileTradeConfirmations(); Log.Success("Offer sent to winner."); } }); } else { Log.Info("No items to give... strange"); } //Now, send all of the profit items to my own account //Put your own Steam ID here var profitTradeOffer = Bot.NewTradeOffer(new SteamID(Bot.ProfitAdmin)); //Loop through all profit items and add them to trade List <long> alreadyAddedToProfitTrade = new List <long>(); foreach (CSGOItemFromWeb item in itemsToKeep) { long classId = item.classId, instanceId = item.instanceId; //Loop through all inventory items and find the asset id for the item long assetId = 0; foreach (var inventoryItem in rgInventory) { var value = inventoryItem.Value; long tAssetId = value.id, tClassId = value.classid, tInstanceId = value.instanceid; if (tClassId == classId && tInstanceId == instanceId) { //Check if this assetId has already been added to the trade if (alreadyAddedToProfitTrade.Contains(tAssetId)) { continue; //This is for when there are 2 of the same weapon, but they have different assetIds } assetId = tAssetId; break; } } //Log.Success ("Adding item to winner trade offer. Asset ID: " + assetId); profitTradeOffer.Items.AddMyItem(730, 2, assetId, 1); alreadyAddedToProfitTrade.Add(assetId); } //Send trade offer to myself with profit items Log.Success(itemsToKeep.Count + ""); if (itemsToKeep.Count > 0) { string profitTradeOfferId, profitMessage = "Here are the profit items from the round."; doWebWithCatch(10, () => { if (profitTradeOffer.Send(out profitTradeOfferId, profitMessage)) { //Don't need the token because I am friends with the bot. Bot.AcceptAllMobileTradeConfirmations(); Log.Success("Profit trade offer sent."); } }); } } else { //Only try this one time, because even if it gives an error, it still gets declined. doWebWithCatch(1, () => { if (offer.Decline()) { Log.Error("Server deposit request failed, declining trade. Error message:\n" + responseJsonObj.errMsg); } }); } } else { //Only try this one time, because even if it gives an error, it still gets declined. doWebWithCatch(1, () => { if (offer.Decline()) { Log.Error("Minimum deposit not reached, offer declined."); } }); } } } }
private void checkForTrades() { string password = System.IO.File.ReadAllText(@"../cstrade_admin_password.txt"); TradeList data; string getUrl = "http://skinbonanza.com/backend/get_items.php"; var getRequest = (HttpWebRequest)WebRequest.Create (getUrl); string getData = "password="******"&bot_steam_id=" + Bot.SteamUser.SteamID.ConvertToUInt64(); var getData_encoded = Encoding.ASCII.GetBytes (getData); getRequest.Method = "POST"; getRequest.ContentType = "application/x-www-form-urlencoded"; getRequest.ContentLength = getData_encoded.Length; using (var stream = getRequest.GetRequestStream ()) { stream.Write (getData_encoded, 0, getData_encoded.Length); } for(int attempts = 0;;attempts++) { try { var getResponse = (HttpWebResponse)getRequest.GetResponse (); //THIS LINE/AREA IS CAUSING A LOT OF ISSUES... TRY CATCH NEEDED string getString = new StreamReader (getResponse.GetResponseStream()).ReadToEnd(); if (debug_output) { Log.Info(getString + ""); } data = JsonConvert.DeserializeObject<TradeList> (getString); break; } catch (Exception e) { getRequest.Abort (); Log.Error (e.Message); if(attempts > 4) throw e; } } //Prevent valid trades from being cancelled because they dont exist in tradeStatuses yet foreach(TradeData trade in data.trades) { bool tradeValue; if(tradesDone.TryGetValue(trade.tradeid, out tradeValue)) { //Log.Info("Trade " + trade.tradeid + " already made"); } else if(trade.status == 2 || trade.status == 9 || trade.status == 11) { //Trade not in update list, bot must have restarted, add now Log.Info("Incomplete Trade Missing with tradeID: " + trade.tradeid); tradesDone[trade.tradeid] = true; tradeStatuses[trade.tradeid] = new TradeStatus(trade.user.steamid, trade.steamid, trade.tradeid, trade.type); } } foreach(TradeData trade in data.trades) { bool tradeValue; if(tradesDone.TryGetValue(trade.tradeid, out tradeValue)) { //Log.Info("Trade " + trade.tradeid + " already made"); } else { Log.Info("Trade " + trade.tradeid + " not completed... Attempting"); TradeUser user = trade.user; var tradeOffer = Bot.NewTradeOffer(new SteamID(user.steamid)); int count = 0; foreach(long item in trade.items) { Log.Info("Adding Item with AssetID: " + item + " to Trade"); if(trade.type.Equals("d", StringComparison.Ordinal) || trade.type.Equals("t", StringComparison.Ordinal)) { tradeOffer.Items.AddTheirItem(730, 2, item); } else if(trade.type.Equals("w", StringComparison.Ordinal)) { tradeOffer.Items.AddMyItem(730, 2, item); } count++; } if(trade.type.Equals("d", StringComparison.Ordinal) || trade.type.Equals("t", StringComparison.Ordinal)) { Log.Info("Deposit/MultiTrade: " + count + " items being traded from user " + user.steamid); } else if(trade.type.Equals("w", StringComparison.Ordinal)) { Log.Info("Withdrawal: " + count + " items being traded to user " + user.steamid); } if (tradeOffer.Items.NewVersion == null) { Log.Error ("TradeOffer is appearing as NULL, restarting the bot may fix?"); } if (tradeOffer.Items.NewVersion) { string tradeID = ""; string tradeError = ""; bool sent = tradeOffer.SendWithToken(out tradeID, out tradeError, trade.user.token, "Secure Code: " + trade.code); if(sent) { Log.Success("New TradeID: " + tradeID); tradesDone[trade.tradeid] = true; //Add trade to list of trades to check status of (accepted, declined, etc) tradeStatuses[trade.tradeid] = new TradeStatus(user.steamid, tradeID, trade.tradeid, trade.type); string setTradeIDData = "password="******"&trade_id=" + trade.tradeid; setTradeIDData += "&trade_steam_id=" + tradeID; string url = "http://skinbonanza.com/backend/update_trade.php"; var updaterequest = (HttpWebRequest)WebRequest.Create (url); var setTradeID_data = Encoding.ASCII.GetBytes (setTradeIDData); updaterequest.Method = "POST"; updaterequest.ContentType = "application/x-www-form-urlencoded"; updaterequest.ContentLength = setTradeID_data.Length; using (var stream = updaterequest.GetRequestStream ()) { stream.Write (setTradeID_data, 0, setTradeID_data.Length); } for(int attempts = 0;;attempts++) { try { var response = (HttpWebResponse)updaterequest.GetResponse (); var responseString = new StreamReader (response.GetResponseStream ()).ReadToEnd (); if(responseString.Contains("success")) { Log.Info("Steam TradeID set in update_trade."); } break; } catch (Exception e) { Log.Error (e.Message); if(attempts > 4) throw e; } } } else { int statusID = 12; if (!String.IsNullOrEmpty (tradeError)) { if (tradeError.Contains ("JSonException")) { Log.Error ("Trade may have been sent, but a JSON conversion error occurred"); statusID = 14; } else if (tradeError.Contains ("ResponseEmpty")) { Log.Error ("The request was sent, but Steam returned an empty response"); statusID = 15; } else if (tradeError.Contains ("(26)")) { Log.Error ("The trade contains an invalid trade item"); statusID = 16; } else if (tradeError.Contains ("(15)")) { Log.Error ("The trade url for the user is invalid"); statusID = 17; } else if (tradeError.Contains ("(50)")) { Log.Error ("Too many concurrent trade offers sent (5 max)"); statusID = 18; } else { Log.Error ("Error: {0}", tradeError); } } else { Log.Error ("Trade not sent and trade error is null/empty!"); } int knownActiveTradesCount = 0; foreach(KeyValuePair<int, TradeStatus> knowntrade in tradeStatuses) { if(knowntrade.Value.state == TradeOfferState.TradeOfferStateCanceled || knowntrade.Value.state == TradeOfferState.TradeOfferStateCountered || knowntrade.Value.state == TradeOfferState.TradeOfferStateDeclined || knowntrade.Value.state == TradeOfferState.TradeOfferStateExpired || knowntrade.Value.state == TradeOfferState.TradeOfferStateInvalid || knowntrade.Value.state == TradeOfferState.TradeOfferStateInvalidItems || knowntrade.Value.state == TradeOfferState.TradeOfferStateCanceledBySecondFactor || knowntrade.Value.itemsPushed == true) { } else { knownActiveTradesCount++; } } OffersResponse offersresponse = Bot.tradeOfferManager.webApi.GetActiveTradeOffers(true, false, false); List<Offer> activeTrades = offersresponse.TradeOffersSent; bool unmatched = false; if(activeTrades.Count != knownActiveTradesCount) { foreach(Offer offer in activeTrades) { //GetActiveOffers still gets cancelled and declined trades //so check that the trade is actually active if(offer.TradeOfferState == TradeOfferState.TradeOfferStateActive || offer.TradeOfferState == TradeOfferState.TradeOfferStateNeedsConfirmation || offer.TradeOfferState == TradeOfferState.TradeOfferStateInEscrow) { foreach(KeyValuePair<int, TradeStatus> checkTrade in tradeStatuses) { if(checkTrade.Value.state == TradeOfferState.TradeOfferStateCanceled || checkTrade.Value.state == TradeOfferState.TradeOfferStateCountered || checkTrade.Value.state == TradeOfferState.TradeOfferStateDeclined || checkTrade.Value.state == TradeOfferState.TradeOfferStateExpired || checkTrade.Value.state == TradeOfferState.TradeOfferStateInvalid || checkTrade.Value.state == TradeOfferState.TradeOfferStateInvalidItems || checkTrade.Value.state == TradeOfferState.TradeOfferStateCanceledBySecondFactor || checkTrade.Value.itemsPushed == true) { } else { if(checkTrade.Value.steam_trade_id == offer.TradeOfferId) { //matching trade found continue; } } } //no matching trade found //trade not being tracked unmatched = true; Log.Error("Untracked trade found {0}, cancelling it", offer.TradeOfferId); Bot.tradeOfferManager.session.Cancel(offer.TradeOfferId); } } } if(!unmatched) Log.Success("No non-tracked trades found."); string postData = "password="******"&trade_id=" + trade.tradeid; postData += "&trade_status=" + statusID; postData += "&user_steam_id=" + user.steamid; postData += "&bot_steam_id=" + Bot.SteamUser.SteamID.ConvertToUInt64(); string url = "http://skinbonanza.com/backend/update_trade.php"; var updaterequest = (HttpWebRequest)WebRequest.Create (url); var failedTrade_data = Encoding.ASCII.GetBytes (postData); updaterequest.Method = "POST"; updaterequest.ContentType = "application/x-www-form-urlencoded"; updaterequest.ContentLength = failedTrade_data.Length; using (var stream = updaterequest.GetRequestStream ()) { stream.Write (failedTrade_data, 0, failedTrade_data.Length); } for (int attempts = 0;; attempts++) { try { var response = (HttpWebResponse)updaterequest.GetResponse (); var responseString = new StreamReader (response.GetResponseStream ()).ReadToEnd (); if (responseString.Contains ("success")) { Log.Success ("Trade status updated."); } break; } catch (Exception e) { Log.Error (e.Message); if (attempts > 4) throw e; } } } } else { Log.Error("Old version of trade. Cancelling."); string postData = "password="******"&trade_id=" + trade.tradeid; postData += "&trade_status=" + 6; postData += "&user_steam_id=" + user.steamid; postData += "&bot_steam_id=" + Bot.SteamUser.SteamID.ConvertToUInt64(); string url = "http://skinbonanza.com/backend/update_trade.php"; var updaterequest = (HttpWebRequest)WebRequest.Create (url); var failedTrade_data = Encoding.ASCII.GetBytes (postData); updaterequest.Method = "POST"; updaterequest.ContentType = "application/x-www-form-urlencoded"; updaterequest.ContentLength = failedTrade_data.Length; using (var stream = updaterequest.GetRequestStream ()) { stream.Write (failedTrade_data, 0, failedTrade_data.Length); } for (int attempts = 0;; attempts++) { try { var response = (HttpWebResponse)updaterequest.GetResponse (); var responseString = new StreamReader (response.GetResponseStream ()).ReadToEnd (); if (responseString.Contains ("success")) { Log.Success ("Trade status updated."); } break; } catch (Exception e) { Log.Error (e.Message); if (attempts > 4) throw e; } } } } } //https://steamcommunity.com/tradeoffer/new/?partner=81920318&token=od9DZwUG }