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
72 stars 13 forks source link

Get-SteamServerInfo always displays an error with Valheim server #41

Closed ThePoShWolf closed 3 years ago

ThePoShWolf commented 3 years ago

Describe "Module Bug or Issue"

Whenever I use the Get-SteamServerInfo function against my self hosted Valheim server, it always displays an error.

Context "The Problem"

Get-SteamServerInfo -IPAddress <server ip> -Port <server port>

Error message:

MethodInvocationException: C:\Users\antwon\Documents\PowerShell\Modules\SteamPS\3.2.0\Private\Server\Get-PacketString.ps1:38
Line |
  38 |          [System.Text.Encoding]::UTF8.GetString($stringBytes)
     |          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | Exception calling "GetString" with "1" argument(s): "Array cannot be null. (Parameter 'bytes')"

However, it does display information:

Protocol      : 17
ServerName    : <map name>
Map           : <map name>
InstallDir    : valheim
GameName      :
AppID         : 0
Players       : 0
MaxPlayers    : 10
Bots          : 0
ServerType    : Dedicated
Environment   : Windows
Visibility    : Private
VAC           : Unsecured
Version       : 1.0.0.0
ExtraDataFlag : 177
IPAddress     : <redacted>
Port          : <redacted>

Context "Expected Behavior"

I would expect it not to error.

Context "Additional Information"

Get-Module -Name SteamPS -ListAvailable |
>>     Select-Object -Property Name, Version

Name    Version
----    -------
SteamPS 3.2.0

$PSVersionTable | Out-String

Name                           Value
----                           -----
PSVersion                      7.1.3
PSEdition                      Core
GitCommitId                    7.1.3
OS                             Microsoft Windows 10.0.19041
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

I did also try this on Windows PowerShell 5.1, same error.

I believe the resolution to this is to simply add an if statement to line 38 on Get-PacketString:

        if ($stringBytes.Count -gt 0) {
            [System.Text.Encoding]::UTF8.GetString($stringBytes)
        }
hjorslev commented 3 years ago

Thanks @ThePoShWolf. I am releasing a patch with your resolution soon.

Best, Frederik

ThePoShWolf commented 3 years ago

Sweet. Thanks for the fix and for the module! 👍