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

How can I reconnect to the gc? #45

Closed Wurstfach404 closed 4 years ago

Wurstfach404 commented 4 years ago

After ~10 hours the Bot lost the connection to the GC.

How can I reconnect?

I tried it like this:

if ( csgo.haveGCSession ) {
    some code...
} else {
      log("Connection lost, trying to reconnect.");
      csgo.on("connectedToGC", function() {
    some code...
});
 };

But I wasn't succesful with that, am I doing something wrong?

DoctorMcKay commented 4 years ago

If you know that you're not connected, I'd advise going out-of-game (user.gamesPlayed([])), waiting 5-10 seconds, then going into CS:GO again (user.gamesPlayed([730])).

Wurstfach404 commented 4 years ago

So I got this for restarting the game.

else {
      console.log("Connection lost, trying to reconnect.");
      user.gamesPlayed();
      console.log("CS:GO stopped. Wait 10 seconds...");
      sleep(10000);
      user.gamesPlayed(730);
};

And thats what I get:

Connection lost, trying to reconnect.
CS:GO stopped. Wait 10 seconds...
Got handled GC message ClientConnectionStatus
Connection status: NO_SESSION (2); have session: no
Got handled GC message ClientConnectionStatus
Connection status: NO_SESSION (2); have session: no

Can I also force to lose the connection, it's frustating to only be able to test this every 10-20 hours :D

DoctorMcKay commented 4 years ago

I dunno if calling gamesPlayed without an argument works. You should pass an empty array.

I can't think of a way to force a GC session to die.