Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Ping measurement to Get-SteamServerInfo #101

Merged
merged 1 commit into from
Jun 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)

Check warning on line 80 in SteamPS/Public/Server/Get-SteamServerInfo.ps1

View check run for this annotation

Codecov / codecov/patch

SteamPS/Public/Server/Get-SteamServerInfo.ps1#L79-L80

Added lines #L79 - L80 were not covered by tests

# 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

Check warning on line 84 in SteamPS/Public/Server/Get-SteamServerInfo.ps1

View check run for this annotation

Codecov / codecov/patch

SteamPS/Public/Server/Get-SteamServerInfo.ps1#L84

Added line #L84 was not covered by tests
$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

Check warning on line 137 in SteamPS/Public/Server/Get-SteamServerInfo.ps1

View check run for this annotation

Codecov / codecov/patch

SteamPS/Public/Server/Get-SteamServerInfo.ps1#L137

Added line #L137 was not covered by tests
} # 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