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

Issue with inspectItem function #77

Closed AlexisPelcik closed 1 year ago

AlexisPelcik commented 1 year ago

I'm trying to use the function inspectItem, but I'm experiencing some issues. When I pass what I assume to be a valid inspect link, none of the listeners inspectItemInfo or inspectItemTimedOut is triggered. However, when I pass an invalid link, inspectItemTimedOut is triggered after 10 seconds as specified in the documentation.

Any help in resolving this issue would be greatly appreciated. Thank you!

This is my code:

import SteamUser from "steam-user";
import GlobalOffensive from "globaloffensive";

class Bot {
  steamUser: SteamUser;
  csgo: GlobalOffensive;
  available: boolean = false;
  busy: boolean = false;
  accountName: string;
  password: string;
  relogIn: boolean = false;

  constructor(accountName: string, password: string) {
    this.steamUser = new SteamUser({
      enablePicsCache: true, 
    });
    this.csgo = new GlobalOffensive(this.steamUser);
    this.accountName = accountName;
    this.password = password;
    this.bindEvents();
    this.logOn();
  }

  private bindEvents() {
    this.steamUser.on("loggedOn", () => {});

    this.steamUser.once("ownershipCached", () => {
      if (this.relogIn) return;
      if (this.steamUser.ownsApp(730)) {
        console.error("[steam][ownershipCached]", "Already own CSGO");
        this.steamUser.gamesPlayed([730], true);
      } else {
        this.steamUser.requestFreeLicense([730], (error, grantedPackages) => {
          console.log(grantedPackages);
          if (error) {
            console.error(error);
            this.logOff();
            return;
          }
          this.steamUser.gamesPlayed([730], true);
        });
      }
    });

    this.steamUser.on("error", (error) => {
      console.error(error);
    });

    this.steamUser.on("debug", (message) => {
      console.log("[steam]", message);
    });

    this.csgo.on("connectedToGC", () => {
      console.log("[csgo]", "connected to GC");
      this.available = true;
      this.busy = false;
    });

    this.csgo.on("connectionStatus", (status, data) => {
      console.log("[csgo][connectionStatus]", status, data);
    });

    this.csgo.on("inspectItemInfo", (itemData) => {
      console.log("[csgo][inspectItemInfo] succeeded");
    });

    this.csgo.on("inspectItemTimedOut", (assetid) => {
      console.log("[csgo][inspectItemTimedOut]", assetid);
      this.available = true;
      this.busy = false;
    });

    this.csgo.on("debug", (message) => {
      console.log("[csgo][debug]", message);
    });
  }

  private logOn() {
    this.steamUser.logOn({
      accountName: this.accountName,
      password: this.password,
    });
  }

  logOff() {
    this.steamUser.logOff();
  }

  async inspectItem(link: string) {
    this.available = false;
    this.busy = true;
    console.log("[csgo][inspectItem]", link);
    this.csgo.inspectItem(link, undefined, undefined, (response) => {
      console.log("[csgo][inspectItem][response]", response);
      this.available = true;
      this.busy = false;
    });
  }
}

const accountName = "*********";
const password = "*********";

const delay = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms));

async function main() {
  const bot = new Bot(accountName, password);

  let stop = false;
  while (!stop) {
    if (bot.available && !bot.busy) {
      bot.inspectItem(
        "steam://rungame/730/76561202255233023/+csgo_econ_action_preview%20S76561198079827697A30163036560D5246174743514963300"
      );
    } else {
      await delay(1000);
    }
  }
  return;
}

main()
  .then(() => console.log("done"))
  .catch(console.error);

in this output i let the script run for approximately 1 minute with a valid link.

[steam] [T1] TCP connection established
[steam] [T1] Handled message: ChannelEncryptRequest
[steam] Channel encrypt request: protocol 1, universe 1, nonce 372706b1776d74c1412c28790f4fbc27, 0 remaining bytes
[steam] Sending message: ChannelEncryptResponse
[steam] [T1] Handled message: ChannelEncryptResult
[steam] Node version is new enough for steam-session; performing new auth
[steam] Sending message: ClientHello
.....
[csgo][debug] GC connection established
[csgo] connected to GC
[steam] [T1#23] Handled message: ClientFromGC
[steam] Received 730 GC message 9173
[csgo][debug] Got unhandled GC message 9173
[csgo][inspectItem] steam://rungame/730/76561202255233023/+csgo_econ_action_preview%20S76561198079827697A30163036560D5246174743514963300
[csgo][debug] Sending GC message Client2GCEconPreviewDataBlockRequest
[steam] Sending 730 GC message 9156
[steam] Sending message: ClientToGC
[steam] [T1#24] Unhandled message: ClientServersAvailable
[steam] Sending message: ClientPICSChangesSinceRequest
[steam] [T1#25] Handled message: ClientPICSChangesSinceResponse

in this output i let the script run with an invalid link.

[steam] [T1] TCP connection established
[steam] [T1] Handled message: ChannelEncryptRequest
[steam] Channel encrypt request: protocol 1, universe 1, nonce 86b64817f014a86b04ba7f50048328af, 0 remaining bytes
[steam] Sending message: ChannelEncryptResponse
[steam] [T1] Handled message: ChannelEncryptResult
[steam] Node version is new enough for steam-session; performing new auth
[steam] Sending message: ClientHello
.....
[csgo][debug] GC connection established
[csgo] connected to GC
[steam] [T1#22] Handled message: ClientFromGC
[steam] Received 730 GC message 9173
[csgo][debug] Got unhandled GC message 9173
[csgo][inspectItem] steam://rungame/730/76561202255233023/+csgo_econ_action_preview%20S77697A30160
[csgo][debug] Sending GC message Client2GCEconPreviewDataBlockRequest
[steam] Sending 730 GC message 9156
[steam] Sending message: ClientToGC
[steam] [T1#23] Unhandled message: ClientServersAvailable
[csgo][inspectItemTimedOut] undefined
AlexisPelcik commented 1 year ago

During my testing, I attempted to log in to the Steam account that was used in the script and I am unable to inspect skins in-game to. However, when I tried using my main account not problem. It seems that there might be some kind of limitation or restriction.

UPDATE: Without changing nothing now inspectItemInfo is trigger perfectly so it really about some temporally restrictions to the steam account, If someone has a deeper understanding or more expertise regarding these restrictions.