Philipp15b / go-steam

Steam's protocol in Go to allow automation of different actions on the Steam network without running an actual Steam client. Includes APIs for friends, chatting, trading, trade offers and TF2 crafting.
https://pkg.go.dev/github.com/Philipp15b/go-steam/v3
Other
392 stars 131 forks source link

Trading session times out #72

Open grahamhawes opened 8 years ago

grahamhawes commented 8 years ago

Hi, I'm working on a trading bot for accepting bets. I had no problem with getting the bot to add my account as a friend, but trading is getting frustrating.

I'm having the bot (which is running on a server) initiate a trade session with my steam account. After I accept the invite that is sent to my personal account, the trade box opens up, but it stalls for a few seconds while displaying "Waiting for BotAccountName" by the bot's inventory, then times out, and I'm sent to the "The trading session has expired." screen.

On the bot's end, TradeResultEvent is caught and handled, then TradeSessionStartEvent is caught and handled (kicking off the trade). The bot polls the event list but never finds anything (even if I send a chat message from my personal account).

All relevant cookies seem to be valid, and the bot calls Web.LogOn() (and waits for a WebSessionIdEvent) beforehand. Btw, I had to update trade.New() to include the SteamLoginSecure cookie as a parameter and to pass it into tradeapi.New(). Want a pull request for that?

Here's the code, please forgive the excessive logging:

func handleTrade(id steamid.SteamId) {
    gramboLogFile.WriteString("Handling trade\n")

    t := trade.New(client.Web.SessionId, client.Web.SteamLogin, client.Web.SteamLoginSecure, id)
    // t.Chat("Take a look at these fine goods")
    err := t.SetReady(true)
    if err != nil {
        panic("Error with trade.SetReady()")
    }

    for {
        eventList, err := t.Poll()
        if err != nil {
            gramboLogFile.WriteString("Error retreiving event list!\n")
            continue
        }

        gramboLogFile.WriteString("Retrieved event list!\n")

        for _, event := range eventList {
            switch e := event.(type) {
            case *trade.ChatEvent:
                // parrot back any chat message
                t.Chat(e.Message)
            case *trade.TradeEndedEvent:
                gramboLogFile.WriteString("Trade ended\n")
                return
            default:
                gramboLogFile.WriteString("Unhandled event type\n")
            }
        }
    }
}

After "Handling trade" prints, "Retrieved event list!" loops forever, even after the trade has timed out from the perspective of my personal account. No other events are caught, nothing panics, nothing prints to stdout. Any idea what is going on? Is there any way to debug this further?

Two other observations: 1) After pulling your recent commits, I couldn't connect to the Steam CM servers (via Client.Connect()) despite many, many retries. I switched to Client.ConnectNorthAmerica() and replaced the NA server IPs with those found here: https://github.com/SteamRE/SteamKit/blob/master/SteamKit2/SteamKit2/Networking/Steam3/CMServerList.cs#L200-L233. Still lots of failures but I eventually get through.

2) Sending a trade invite fails if the sender hasn't set himself to appear offline via SetPersonaState(steamlang.EPersonaState_Online). I had commented that line out due to the (now-fixed) internal package issues, which is why I noticed the problem.

Anyway, thanks for all your work on this library, go is a fun language. I was happy to see the updates last week, and if I come across anything I'll submit a pull request. Sorry for the long post.

ewancook commented 8 years ago

Concerning the servers, fairly sure it's outdated IPs rather than anything internal.

Try using ConnectTo() [https://godoc.org/github.com/Philipp15b/go-steam#Client.ConnectTo] to connect to a specified server; there's an event that returns (working, I assume?) server IPs.

https://godoc.org/github.com/Philipp15b/go-steam#ClientCMListEvent

grahamhawes commented 8 years ago

Agreed that the IPs changed - but I don't understand why I can try connecting to a server four times, time out on every attempt, and then have it work on the fifth try. Any idea whats up with that?

Thanks for the info

grahamhawes commented 8 years ago

Just to add to this, I looked at the statuses coming and found this error: "missing required parameter". No successful, non-error status is ever received.

Does this mean there's a problem with my cookies? A problem with the formatting/contents of the POST? I'm not sure how to debug this further.

Does anyone have trading working?

YellowOrWhite commented 8 years ago

For connect try using InitializeSteamDirectory and then Connect.

Never heard of anyone using trade for gambling site. Why not tradeoffer?

grahamhawes commented 8 years ago

It is for a jackpot-style site (with a goofy twist), I think that the asynchronous nature of trade offers would detract from the fun.

Philipp15b commented 8 years ago

Regarding connection problems, see @Nefarious- answer and #73. I'll update the server list sometime.

If you've got any time, a pull request for the missing steamLoginSecure parameter would be appreciated.

I really don't know why trading is not working anymore, but unfortunately there's the trading timeout when logging in with a new computer, so it'll take some time before I can debug the issue myself. What's weird though is that since I uploaded my fixes for the trade package last year, I can't find any changes in libraries for trading in other languages... SteamDB's SteamTracking project did record some changes in Valve's code, so I'll check those in detail sometime.

In the meantime, did you try trading with actual Steam clients with those accounts? Maybe the client shows some issue go-steam doesn't handle properly.

Philipp15b commented 8 years ago

Also, trading is not supposed to work when you're in offline mode - that's also true for the Steam client. It is a limitation enforced by the Steam network. Maybe some documentation or assertions in the code would be helpful.

grahamhawes commented 8 years ago

I did confirm that trading works with the account. Didn't encounter any problems when I traded normally through the Steam client.

Is "missing required parameter" more generic than it sounds? I'm wondering if its somehow a problem with the session or any of the cookies, and how I'd even debug that. I printed all the cookies out and they seem okay.

And yeah, for trade invitations failing when you're set to appear offline, I was just suggesting some kind of warning in code/documentation, since it will fail pretty silently if you forget.

Philipp15b commented 8 years ago

I've seen "missing required parameter" because I was missing a HTTP header or when I used invalid cookies, so basically you should read it as "something's wrong". I've made the mistake once to search for hours for bugs in the request parameters only to find the header was missing...

I usually used a mix of Wireshark-ing myself and opening the trade site in a web browser with the cookies from go-steam or the Steam client. After some time, you'll hopefully find the difference between what the Steam client does and what go-steam does.

Philipp15b commented 8 years ago

I updated the internal server list and improved the API somewhat regarding connecting: a995980.

Philipp15b commented 8 years ago

So I started debugging the trading issue and I similarly get no output from Poll() because apparently the tradeapi package silently ignores errors from the Steam API which sends responds with status code 200, but sends this:

{"success":false}

I'm not exactly sure what the source of this error actually is, but ignoring errors is at least part of the bug.

iain17 commented 8 years ago

I've stumbled against the same problem. Any update on this?

{"success":false,"error":"missing required parameter"}

Maybe a second episode to the tales of sadness? Another header.

tqwewe commented 7 years ago

I also stumbled upon this problem. I am sure I have it all correct. When I print out each poll, it's just empty and even when I close the trade on my account, the polls keep appearing and they are empty. No one said what solved this guy's problem. Would really appreciate some help too.

CDFN commented 4 years ago

Issue sadly still stands. Trading is impossible using go-steam currently :cry: