Skip to content

Commit

Permalink
supporting the challenge, #47 (#51)
Browse files Browse the repository at this point in the history
  • Loading branch information
ThePoShWolf authored May 13, 2022
1 parent 24b3b14 commit 60da818
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions SteamPS/Public/Server/Get-SteamServerInfo.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,31 @@

process {
try {
# Instantiate client and endpoint
$Client = New-Object -TypeName Net.Sockets.UDPClient(0)
[void]$Client.Send($A2S_INFO, $A2S_INFO.Length, $IPAddress, $Port)
$Client.Client.SendTimeout = $Timeout
$Client.Client.ReceiveTimeout = $Timeout
$IPEndpoint = New-Object -TypeName Net.IPEndpoint([Net.IPAddress]::Any, 0)

# The first 4 bytes are 255 which seems to be some sort of header.
$ReceivedData = $Client.Receive([Ref]$IPEndpoint) | Select-Object -Skip 4
$Stream = [System.IO.BinaryReader][System.IO.MemoryStream][Byte[]]$ReceivedData

# Challenge:
if ($Stream.ReadByte() -eq 65) {
# If the response is a challenge, resend query with last 4 bytes of the challenge
$challenge = while ($Stream.BaseStream.Position -lt $Stream.BaseStream.Length) {
$Stream.ReadByte()
}
$newQuery = $A2S_INFO + $challenge

[void]$Client.Send($newQuery, $newQuery.Length, $IPAddress, $Port)
# The first 4 bytes are 255 which seems to be some sort of header.
$ReceivedData = $Client.Receive([Ref]$IPEndpoint) | Select-Object -Skip 4
$Stream = [System.IO.BinaryReader][System.IO.MemoryStream][Byte[]]$ReceivedData
}

$Client.Close()
} catch {
$Exception = [Exception]::new("Could not reach server {0}:{1}.") -f $IPAddress, $Port
Expand Down

0 comments on commit 60da818

Please sign in to comment.