gamedig / node-gamedig

Query game servers and not only! Node.JS/Deno/Bun or Bash (via the CLI).
https://www.npmjs.com/package/gamedig
MIT License
608 stars 146 forks source link

bug: players array not always returning #632

Open delboychad opened 2 months ago

delboychad commented 2 months ago

Describe the bug The state.players array is currently returning Players(0) [] even when it further up it recognises there is 12 numplayers.

However there are occasions it works, its just mixing between the two.

Expected behavior Should return the data array of players.

Screenshots or Data let playerList; if (state.players && state.players.length > 0) { playerList = state.players.map(player => player.name || 'Unknown').join('\n'); // Add line breaks here } else if (state.numplayers > 0) { playerList = 'Player details unavailable'; } else { playerList = 'No players online'; }

Console (from public server, used for test): Results { name: 'Gaminglight ▌ ImperialRP ▌ Custom ▌ No Training', map: 'rp_anaxes_v2-5', password: false, raw: { protocol: 17, folder: 'garrysmod', game: 'starwarsrp', appId: 4000, numbots: 0, listentype: 'd', environment: 'l', secure: 1, steamid: '85568392923361747', tags: [ ' gm:starwarsrp loc:us ver:240809' ], players: [] }, version: '2023.06.28', maxplayers: 110, numplayers: 12, players: Players(0) [], bots: Players(0) [], queryPort: 27015, connect: '193.243.190.36:27015', ping: 19 } Players(0) []

CosminPerRam commented 2 months ago

Garrys mod runs on the Valve protocol, which has players number in the 'general informations' query (this is why you see the players count but no players): https://github.com/gamedig/node-gamedig/blob/ba2f3739861d3c50206a30b4778cbd0e53112706/protocols/valve.js#L69

Although I see that on gametracker it does report some players, while making our query, the server does not respond to the players query which times out:

Q#0 Requesting player list ...
193.243.190.36:27015 UDP(49902)-->
Buffer length: 9 bytes
ff ff ff ff 55 ff ff ff ff 
            U              

193.243.190.36:27015 <--UDP(49902)
Buffer length: 9 bytes
ff ff ff ff 41 83 79 d9 bc 
            A     y        

Q#0 Registered RTT: 41ms
Q#0 Received full packet
Q#0 Received 0x41 expected 0x44
Q#0 Received new challenge key: 0xbcd97983
Q#0 UDP send finished by callback
193.243.190.36:27015 UDP(49902)-->
Buffer length: 9 bytes
ff ff ff ff 55 83 79 d9 bc 
            U     y        

Q#0 UDP timeout detected
Q#0 UDP timeout resolved by callback

(the logs show the initial query to which responds with a new challenge code, the final query is with the provided challenge, and it times out)

Although I queried the server a bunch of times, it always fails the players query, which is weird considering it works for you sometimes. It is possible that it runs a plugin related to the query protocol (e.g. for protection, against stuff like DDOS) but I'll have to look into other servers to see if this is the case just for this server or more of a general problem. Using RCON could provide us more info about players but we dont have it yet.

CosminPerRam commented 2 months ago

Could you try to run the query with debug: true (or --debug for CLI) and post the logs here if a query responds with the players?

CosminPerRam commented 1 month ago

Bump.