Reputation: 105
I'm trying to create an NPM module to get steam game versions from the appID.
Currently, I can get the game info with https://store.steampowered.com/api/appdetails?appids=730 (730 is CSGO appID)
How do I get the current game version?
This is so I can check if an update I available.
Upvotes: 5
Views: 9806
Reputation: 31
I found that SteamCMD is a clumsy broken tool. And if you only want a quick check for updates when a game server is running. So only a check and decide in code if you want to stop your server and update on the result of your check. Then SteamCMD is not your friend.
So i did write a short powershell script to get more useful info out of SteamCMD.
param(
[Parameter(Mandatory)][string]$SteamCMD, # Path to SteamCMD.exe, path can have spaces. Example: -SteamCMD C:\SteamCMD\steamcmd.exe
[Parameter(Mandatory)][string]$AppID, # Steam AppID. Example for ARK Ascended server: -AppID 2430930
[Parameter(Mandatory)][string]$branch, # Branch you want to check for updates. Example: -branch public
[Parameter(Mandatory)][string]$force_install_dir, # Path of local install you want to check for updates, path cannot have spaces (SteamCMD limitation)
# Example: -force_install_dir C:\SERVERS\ArkAscended\server\
[ValidateSet("update_available","installed_version","latest_version","app_status_json","app_info_json")]
[Parameter(Mandatory)][string]$output="update_available"
# What output do you want.
# -output update_available (will output single line with true or false)
# -output installed_version (will output a single line with a number)
# -output latest_version (will output a single line with a number)
# -output app_status_json (will output what SteamCMD should have output when they would have developed their tooling right)
# -output app_info_json (will output what SteamCMD should have output when they would have developed their tooling right)
)
$exec = @'
& "$SteamCMD" +@ShutdownOnFailedCommand 1 +@NoPromptForPassword 1 +force_install_dir $force_install_dir +login anonymous +app_info_update 1 +app_status $AppID +quit
'@
$App_Status_stdout=Invoke-Expression -Command $exec
$App_Status = [PSCustomObject]@{}
foreach($App_Status_line in $App_Status_stdout){
if($App_Status_line.StartsWith('AppID')){
$Items=$App_Status_line -split "\(",2
$App_Status | Add-Member -MemberType NoteProperty -Name ($Items[0].Trim() -split " ",2)[0] -Value ($Items[0].Trim() -split " ",2)[1]
$App_Status | Add-Member -MemberType NoteProperty -Name 'Name' -Value ($Items[1].Trim() -split "\)",2)[0]
}
if($App_Status_line.StartsWith(' - ') -or $App_Status_line.StartsWith(' ')){
if($App_Status_line.StartsWith(' ')){
#Add-NoteProperty -InputObject $App_Status -Property "mounted_depots.$(($App_Status_line -split ':',2)[0].Replace(' - ','').trim().replace(' ','_'))" -Value ($App_Status_line -split ':',2)[1].trim()
$App_Status.mounted_depots | Add-Member -MemberType NoteProperty -Name ($App_Status_line -split ':',2)[0].Replace(' - ','').trim().replace(' ','_') -Value ($App_Status_line -split ':',2)[1].trim()
}else{
if(($App_Status_line -split ':',2)[0].Replace(' - ','').trim().replace(' ','_') -eq "mounted_depots"){
$App_Status | Add-Member -MemberType NoteProperty -Name ($App_Status_line -split ':',2)[0].Replace(' - ','').trim().replace(' ','_') -Value (New-Object PSCustomObject) -Force:$Force.IsPresent
}else{
$App_Status | Add-Member -MemberType NoteProperty -Name ($App_Status_line -split ':',2)[0].Replace(' - ','').trim().replace(' ','_') -Value ($App_Status_line -split ':',2)[1].trim()
}
}
}
}
$exec = @'
& "$SteamCMD" +@ShutdownOnFailedCommand 1 +@NoPromptForPassword 1 +login anonymous +app_info_update 1 +app_info_print $AppID +logoff +quit
'@
$App_Info_stdout=Invoke-Expression -Command $exec
#Remove unwanted content from the output of App_Info
$App_Info= ($App_Info_stdout | ? {$_.contains('{') -or $_.contains('}') -or $_.contains('"')}) -join "`r`n" | Out-String
$App_Info = $App_Info.SubString($App_Info.IndexOf("{"),$App_Info.LastIndexOf("}")+1-$App_Info.IndexOf("{"))
#Correct the output to be proper json and convert to object
$App_Info = ConvertFrom-Json $App_Info.Replace("`t", "").Replace('""','":"').Replace("`"`r`n{","`":`r`n{").Replace("`"`r`n`"","`",`r`n`"").Replace("}`r`n`"","},`r`n`"")
Switch($output){
"update_available" {
If($($App_Status.size_on_disk.Split(',',2)[1].trim().split(' ',2)[1]) -ne $($App_Info.depots.branches."$($branch)".buildid)){
Write-Host "true"
}else{
Write-Host "false"
}
}
"installed_version" {
Write-Host $($App_Status.size_on_disk.Split(',',2)[1].trim().split(' ',2)[1])
}
"latest_version" {
Write-Host $($App_Info.depots.branches."$($branch)".buildid)
}
"app_status_json" {
Write-Host (ConvertTo-Json $App_Status -Depth 99)
}
"app_info_json" {
Write-Host (ConvertTo-Json $App_Info -Depth 99)
}
}
Upvotes: 0
Reputation: 1723
You can query buildid
using steamdb.info or steamcmd. This increments any time files change.
Upvotes: 1