Skip to content

Commit

Permalink
Add Ping measurement to Get-SteamServerInfo (#101)
Browse files Browse the repository at this point in the history
feat: add Ping measurement to Get-SteamServerInfo
  • Loading branch information
ericwong3 authored Jun 12, 2024
1 parent fd3b0e6 commit 4aaa92d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
6 changes: 5 additions & 1 deletion SteamPS/Public/Server/Get-SteamServerInfo.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
ExtraDataFlag : 177
IPAddress : 185.15.73.207
Port : 27015
Ping : 65
```
.NOTES
Expand Down Expand Up @@ -72,13 +73,15 @@
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)
$Stopwatch = [System.Diagnostics.Stopwatch]::StartNew()
[void]$Client.Send($A2S_INFO, $A2S_INFO.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
$Ping = $Stopwatch.ElapsedMilliseconds
$Stream = [System.IO.BinaryReader][System.IO.MemoryStream][Byte[]]$ReceivedData

# Challenge:
Expand Down Expand Up @@ -131,6 +134,7 @@
ExtraDataFlag = $Stream.ReadByte()
IPAddress = $IPAddress
Port = $Port
Ping = $Ping
} # PSCustomObject
}
} # Process
Expand Down
2 changes: 2 additions & 0 deletions Tests/Integration/Public/Get-SteamServerInfo.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
ExtraDataFlag = 177
IPAddress = "135.239.211.40"
Port = 27015
Ping = 65
}
}

Expand All @@ -44,6 +45,7 @@
$result.Version | Should -Be "1.0.0.0"
$result.IPAddress | Should -Be "135.239.211.40"
$result.Port | Should -Be 27015
$result.Ping | Should -Be 65
}
}

Expand Down

0 comments on commit 4aaa92d

Please sign in to comment.