hjorslev / SteamPS

Module that utilizes PowerShell as a wrapper for SteamCMD and interacts with various Steam APIs.
https://www.powershellgallery.com/packages/SteamPS
MIT License
69 stars 14 forks source link

Support the server challenge request (Linux based servers), fixes #47 #51

Closed ThePoShWolf closed 2 years ago

ThePoShWolf commented 2 years ago

PR Summary

Fixes #47 - Supports the server challenge (https://developer.valvesoftware.com/wiki/Server_queries#A2S_INFO). Tested and still works on Windows based servers.

Context

When querying a Linux based Rust server, I was getting a 9 bytes response which turned out to be the 4 byte header, the byte indicating a challenge ('A' or 0x41) followed by the challenge bytes themselves. To handle this and get the requested data, the client needs to send the query again with the challenge appended.

See the steam docs for further details.

Changes

If the first byte of the stream (after the headers) is the challenge indicator, then resend the original query with the challenge bytes appended.

This change was made it Get-SteamServerInfo.ps1.

Checklist

hjorslev commented 2 years ago

Thans so much for this PR!

I will merge and release it this weekend 😊

hjorslev commented 2 years ago

@ThePoShWolf

After the new release when I query my server it skips the first letter of the server name (correct name should be SAS Proving Ground 12 (EU)):

Protocol      : 83
ServerName    : AS Proving Ground 12 (EU)
Map           : PowerStation
InstallDir    : groundbranch
GameName      : Ground Branch
AppID         : 0
Players       : 0
MaxPlayers    : 10
Bots          : 0
ServerType    : Dedicated
Environment   : Windows
Visibility    : Public
VAC           : Unsecured
Version       : 1.0.0.0
ExtraDataFlag : 177
IPAddress     : 185.15.73.207
Port          : 27015

If I change $ReceivedData = $Client.Receive([Ref]$IPEndpoint) | Select-Object -Skip 4 to $ReceivedData = $Client.Receive([Ref]$IPEndpoint) | Select-Object -Skip 3 it seems to work.

Could I get you to review that solution for me and test against a linux based server?

ThePoShWolf commented 2 years ago

@hjorslev - That is strange. Here's the output if I -Skip 3:

Protocol      : 73
ServerName    : ◄Land of the Toddomites
Map           : Procedural Map
InstallDir    : rust
GameName      : Rust
AppID         : 0
Players       : 0
MaxPlayers    : 10
Bots          : 0
ServerType    : Dedicated
Environment   : Linux
Visibility    : Public
VAC           : Secured
Version       : 2336
ExtraDataFlag : 177
IPAddress     : 20.236.47.160
Port          : 28015

There is an extra character in the server name.

If I switch back to -Skip 4, then the protocol changes as well:

Protocol      : 17
ServerName    : Land of the Toddomites
...

I'm not sure what is happening, but when I have more time this weekend I can try digging into that a bit deeper. Feel free to use my server IP above for testing.

ThePoShWolf commented 2 years ago

@hjorslev I figured it out. In Get-SteamServerInfo line 85, the if statement is doing a ReadByte(), so it moves the position forward by one. All it takes to fix is an else with: $Stream.BaseStream.Position = 0. I'll submit a new PR.

ThePoShWolf commented 2 years ago

53 submitted.