DoctorMcKay / node-globaloffensive

A Node.js module to connect to and interact with the CS2 game coordinator. Mostly used to get item data.
https://www.npmjs.com/package/globaloffensive
MIT License
262 stars 61 forks source link

Inconsistent availability state #37

Closed Luluno01 closed 4 years ago

Luluno01 commented 5 years ago

Problem description

The documentation requires users try to do nothing before receiving the connectedToGC event. At the same time it requires users to call methods only when the haveGCSession is true.

However, I noticed that I can actually send item inspect queries and receive responses from the server when haveGCSession is false.

Now I have to explain why my haveGCSession property is false and that's actually another issue:

I called user.gamesPlayed(730) for the first time, and received connectedToGC event as expected. I checked the haveGCSession property, it was also true as expected. Later, I called user.gamesPlayed([]), the disconnectedFromGC event did not fired but haveGCSession became false. I also called inspectItem after that, no response received (that is what I expected). Finally, I called user.gamesPlayed(730) again and:

  1. No connectedToGC event fired
  2. haveGCSession was still false

I was confused, so I called inspectItem to see what would happen, and I received responses to the inspect query.

Also, there could be a connection leak caused by the aforementioned operation sequence as mentioned here.

DoctorMcKay commented 4 years ago

I'm going to close this, because this is a consequence of how GC connections work. Basically, saying that you have a "connection" to the GC is kind of wrong. It's more of a UDP type of thing rather than a TCP type of thing. Messages get sent to the GC via Steam and Steam essentially just passes them along as-is. There is no concept of a "connection", only GC sessions.

It seems that sometimes when you go out-of-game, Steam doesn't relay that along to the GC so the session is not terminated. In that case, the GC just waits for the session to time out, I suppose. Sending a request while out-of-game doesn't work because Steam won't relay a message to a GC unless you're in that game.

You then go in-game and the GC never saw you as having left. connectedToGC will eventually get emitted because a new session will be negotiated, but your old session is actually still valid.

Regardless, even if there is technically an active session, I would rather keep the documentation saying that you need to wait for connectedToGC, to prevent confusion.

Luluno01 commented 4 years ago

@DoctorMcKay Thanks for your explanation! My workaround is to fully relogin and reconnect when user becomes offline or when GC disconnects to ensure a valid GC session.