Jessecar96 / SteamBot

Automated bot software for interacting with Steam Trade
http://scrap.tf
MIT License
1.34k stars 910 forks source link

Bot Crashes on Web Errors when sending trade offer. #669

Closed WortelSoep closed 9 years ago

WortelSoep commented 10 years ago

Sometimes when steamcommunity has troubles, the Web related stuff of SteamTrade gets http errors causing SteamBot.exe to stop responding. Mostly been happening for me on sending trade offers. Maybe it should retry or give an error.

WildCard65 commented 10 years ago

The bot in question for this issue is a bot I wrote for him. Basically, yesterday I wrote a feature for @kingdom200 bot(which I wrote the handler it uses) to add a Lucky Player system where a player gets picked to recieve X number of items that the bot recieved as donations(as long as said player is a donator). The bot reads this information from a mysql database and prepares and sends a trade offer to the user. Mostly it's been 500 internal server error

scholtzm commented 10 years ago

500 should throw an exception. Do you have the stack trace?

WildCard65 commented 10 years ago

Note: @kingdom200 didn't really know what a stacktrace is so I had to explain to him what it was over steam.
Another note: The method that is executed to send a trade offer is on it's own thread seperate of the main steambot thread.
Ok it does throw an exception but only is caught by VS(Visual Studios)'s debugger. The running of the exe itself without VS's debugger just causes the exe to stop responding.
The snippet of code involved in making the offer and sending it is follow(if you want the full method, just ask):

foreach (KeyValuePair<Donator, Dictionary<ItemDonation, int>> kv in luckyUsers)
{
    TradeOffer offer = Bot.NewTradeOffer(kv.Key.DonatorSID);
    foreach (KeyValuePair<ItemDonation, int> kv2 in kv.Value)
    {
        int i = 0;
        foreach (Inventory.Item item in Bot.MyInventory.Items)
        {
            if (item == kv2.Key && i < kv2.Value)
            {
                offer.Items.AddMyItem(item.AppId, item.ContextId, (long)item.Id);
                i++;
            }
        }
    }
    string offerID = "";
    if (String.IsNullOrWhiteSpace(token))
        offer.Send(out offerID, "You were picked as a lucky user!"); //Here
    else
        offer.SendWithToken(out offerID, token, "You were picked as a lucky user!"); //Or here causes error.
    using (MySqlCommand cmd = new MySqlCommand(String.Format("DELETE FROM LuckyPlayer WHERE Donator_ID = {0};", kv.Key.DonatorDID), connection))
    {
        int rowsDel = await cmd.ExecuteNonQueryAsync();
        if (rowsDel <= 0)
            Log.Error("Failed to delete rows from LuckyPlayer!");
    }
}
scholtzm commented 10 years ago

Ok, but do you have the actual stack trace?

WildCard65 commented 10 years ago

He has one that occurred on line 448 of the handler(which is int i = 0; of the above snippet) which I believe should be the foreach statement below it. Picture in this reddit thread shows an http 500 error happening and @kingdom200 said it also crashed bot: http://www.reddit.com/r/SteamBot/comments/2nu2sy/error_when_sending_trade_offer/

WildCard65 commented 10 years ago

Above comment original content was b4 I got answer from @kingdom200 about if the stacktrace in picture in that thread had resulted in the exe stop responding.

scholtzm commented 10 years ago

It clearly shows that the bot failed to fetch the inventory. You can just wrap that with try-catch which I have already suggested.

WildCard65 commented 10 years ago

I try-catched the entire foreach loop posted above and @kingdom200 said it still happens to crash the exe.

scholtzm commented 10 years ago

Well, I don't know what else is there to tell. Debugger is the only way to fix this quickly.

WortelSoep commented 10 years ago

Does someone want to take a look at this? Wildcard65 can't get to the solution.

ElPresidentePro commented 9 years ago

@kingdom200 Hello good I am follower of csgoshop fix after page I am very pissed because of bot that does not connect to the web and only gives errors, need help would be willing to pay if you find it necessary, add me to skype (osmanygon)

BlueRaja commented 9 years ago

FYI you can fake a 500 response using Fiddler's "auto-responder" feature, in order to debug this.