SteamCMDでサーバーのアップデートをチェックする
サーバーのアップデートを知りたい
Steamで販売されているマルチゲーの中には7d2dやCSシリーズなど自分で専用サーバーを構築し、友人と遊べるものがいくつかあります。
そういったものはSteamCMDというツールを用いてSteamからサーバーのデータをダウンロードすることができます。
24時間サーバーを運用していると、自動でアップデートをしたいなということがあります。
アップデート自体はインストール時と同じコマンドを使用すればいいので、楽なのですが、
問題はアップデートを発火する際のアップデート検知をどうするかということです。
SteamCMDを用いることでアップデート検知っぽいことができるため、書き残しておきます。
ローカルのビルド番号
+app_status
という引数を使用することで、ローカルの情報を手に入れることができます。
BuildIDがバージョン毎に一意っぽそうなので、これを使用します。
steam@4392b786b33c:~/steamcmd$ ./steamcmd.sh +force_install_dir /home/steam/palworld +login anonymous +app_status 2394010 +quit
tid(766) burning pthread_key_t == 0 so we never use it
Redirecting stderr to '/home/steam/Steam/logs/stderr.txt'
Logging directory: '/home/steam/Steam/logs'
[ 0%] Checking for available updates...
[----] Verifying installation...
Steam Console Client (c) Valve Corporation - version 1705108307
-- type 'quit' to exit --
Loading Steam API...OK
Connecting anonymously to Steam Public...OK
Waiting for client config...OK
Waiting for user info...OK
AppID 2394010 (Palworld Dedicated Server): src/clientdll/configstore.cpp (409) : GSteamEngine().IsEngineThreadRunning()
src/clientdll/configstore.cpp (409) : GSteamEngine().IsEngineThreadRunning()
src/clientdll/configstore.cpp (409) : GSteamEngine().IsEngineThreadRunning()
src/clientdll/configstore.cpp (409) : GSteamEngine().IsEngineThreadRunning()
src/clientdll/configstore.cpp (409) : GSteamEngine().IsEngineThreadRunning()
src/clientdll/configstore.cpp (409) : GSteamEngine().IsEngineThreadRunning()
src/clientdll/configstore.cpp (409) : GSteamEngine().IsEngineThreadRunning()
src/clientdll/configstore.cpp (409) : GSteamEngine().IsEngineThreadRunning()
src/clientdll/configstore.cpp (409) : GSteamEngine().IsEngineThreadRunning()
src/clientdll/configstore.cpp (409) : GSteamEngine().IsEngineThreadRunning()
- release state: released (Subscribed,Permanent,)
- owner account: 94139569
- install state: Fully Installed,
- install dir: "/home/steam/palworld"
- mounted depots:
1006 : 73.78 MB (manifest 4884950798805348056)
2394012 : 2.17 GB (manifest 1354752814336157338)
- size on disk: 2248053389 bytes, BuildID 13269059
- update started: Thu Jan 1 09:00:00 1970, staged: 0/0 MB 0%, downloaded: 0/0 MB 0% - 0 KB/s
- update state: ( No Error )
- user config: "UserConfig"
{
}
steam@4392b786b33c:~/steamcmd$
なので、以下のコマンドでビルド番号だけ手に入れれますね。
steam@4392b786b33c:~/steamcmd$ ./steamcmd.sh +force_install_dir /home/steam/palworld +login anonymous +app_status 2394010 +quit | awk '/BuildID/{print$8}'
13269059
steam@4392b786b33c:~/steamcmd$
リモートのビルド番号
+app_info_print
を使用することで、リモートの情報を手に入れることができます。
返り値はjsonっぽいのですが、標準出力にsteamcmdのログ自体も出ちゃうのでそのままjqなどには渡せそうにもなさそうです。
steam@4392b786b33c:~/steamcmd$ ./steamcmd.sh +login anonymous +app_info_print 2394010 +quit
tid(988) burning pthread_key_t == 0 so we never use it
Redirecting stderr to '/home/steam/Steam/logs/stderr.txt'
Logging directory: '/home/steam/Steam/logs'
[ 0%] Checking for available updates...
[----] Verifying installation...
Steam Console Client (c) Valve Corporation - version 1705108307
-- type 'quit' to exit --
Loading Steam API...OK
Connecting anonymously to Steam Public...OK
Waiting for client config...OK
Waiting for user info...OK
AppID : 2394010, change number : 22049244/0, last change : Thu Jan 25 22:16:19 2024
"2394010"
{
"common"
{
"name" "Palworld Dedicated Server"
"type" "Tool"
"parent" "1623730"
"ReleaseState" "released"
"oslist" "windows,linux"
"osarch" "64"
"osextended" ""
"icon" "606e637a2f0610f3805893e917c0e22d1d043ba6"
"clienttga" "2032a63848f1ab00b518b7e984bd533c1ce0cf07"
"clienticon" "22a20bdaa6d782f60caa45eb7b02fc2411dcd988"
"linuxclienticon" "d26e2c064a36a71a1ae404a0fc9bef6c2182f611"
"associations"
{
}
"gameid" "2394010"
}
"extended"
{
"gamedir" "Palworld"
"serverbrowsername" "Palworld"
}
"config"
{
"installdir" "PalServer"
"launch"
{
"0"
{
"executable" "PalServer.exe"
"arguments" "-useperfthreads -NoAsyncLoadingThread -UseMultithreadForDS"
"type" "default"
"config"
{
"oslist" "windows"
}
}
"1"
{
"executable" "PalServer.sh"
"arguments" "EpicApp=PalServer -useperfthreads -NoAsyncLoadingThread -UseMultithreadForDS"
"type" "default"
"config"
{
"oslist" "linux"
}
}
"2"
{
"executable" "PalServer.exe"
"arguments" "EpicApp=PalServer -useperfthreads -NoAsyncLoadingThread -UseMultithreadForDS"
"description_loc"
{
"english" "Open and start as a community server"
}
"description" "Open and start as a community server"
}
}
}
"depots"
{
"1004"
{
"config"
{
"oslist" "windows"
}
"manifests"
{
"public"
{
"gid" "1923798258558304932"
"size" "44194776"
"download" "13804528"
}
}
"depotfromapp" "1007"
}
"1005"
{
"config"
{
"oslist" "macos"
}
"manifests"
{
"public"
{
"gid" "2135359612286175146"
"size" "0"
"download" "0"
}
}
"depotfromapp" "1007"
}
"1006"
{
"config"
{
"oslist" "linux"
}
"manifests"
{
"public"
{
"gid" "4884950798805348056"
"size" "73781292"
"download" "20270768"
}
}
"depotfromapp" "1007"
}
"228989"
{
"config"
{
"oslist" "windows"
}
"depotfromapp" "228980"
"sharedinstall" "1"
}
"2394011"
{
"config"
{
"oslist" "windows"
"osarch" "64"
}
"manifests"
{
"public"
{
"gid" "4468658849500059666"
"size" "2622063597"
"download" "1805693520"
}
}
"encryptedmanifests"
{
"main_development"
{
"gid" "3AE4D26F2D03EC7D2A8A7D112E177C06"
"size" "A1AD164A52CA25BDBAED4EC591F87776"
"download" "85B9D7B410F4939E485DAE004F4DF906"
}
# ~省略~
"qa_test"
{
"gid" "14C063452DF564FD9B612FB3E46EB35D"
"size" "47DDD4B4959F888208B287CF2E65C566"
"download" "0AE23C438212BC3D34B66552B944976F"
}
}
}
"2394012"
{
"config"
{
"oslist" "linux"
"osarch" "64"
}
"manifests"
{
"public"
{
"gid" "1354752814336157338"
"size" "2174272097"
"download" "1696115984"
}
}
"encryptedmanifests"
{
"main_development"
{
"gid" "BF1A5C0544A7B3FCC26139558A5F1924"
"size" "4D48B63BA9CED7286DAD6D169A18C07C"
"download" "F2C3DA47775F83CB839BA31510F41585"
}
# ~省略~
"qa_test"
{
"gid" "E19548E7A8B25163517A42D5DB82E0D2"
"size" "5FFD8D859FAE0D1116AEFD6497407E6E"
"download" "D362EEC9F4D1F63624869D808CA702A2"
}
}
}
"branches"
{
"public"
{
"buildid" "13269059"
"timeupdated" "1706184024"
}
"main_development"
{
"buildid" "13270483"
"pwdrequired" "1"
"timeupdated" "1706183303"
}
# ~省略~
"qa_test"
{
"buildid" "13269059"
"pwdrequired" "1"
"timeupdated" "1706174084"
}
}
}
}
steam@4392b786b33c:~/steamcmd$
jsonなので行が多い・・・。
必要なのはpublic
版のビルド番号なので適当にえいやしちゃいます。
steam@4392b786b33c:~/steamcmd$ ./steamcmd.sh +login anonymous +app_info_print 2394010 +quit | grep -A2 "public" | awk -F\" '/buildid/{print$4}'
13269059
steam@4392b786b33c:~/steamcmd$
比較
あとは一定時間ごとに返り値同士を比較して等しくなければ(もしくはリモートが大きければ)アップデートを走らせる。という処理を書いてあげたらよさそうですね。
以下は例
SteamCMD="/home/steam/steamcmd/steamcmd.sh"
GameDir="/home/steam/palworld"
while :; do
# Fetch Current Version
current_version=$($SteamCMD +force_install_dir ${GameDir} +login anonymous +app_status 2394010 +quit | awk '/BuildID/{print$8}')
# Fetch Remote Version
remote_version=$($SteamCMD +login anonymous +app_info_print 2394010 +quit | grep -A2 "public" | awk -F\" '/buildid/{print$4}')
echo "[Updater] Current Version: ${current_version}"
echo "[Updater] Remote Version : ${remote_version}"
if [ "${current_version}" -ne "${remote_version}" ]; then
echo "[Updater] A new version is available!"
# アップデート処理ごにょごにょ
else
echo "[Updater] There are no new versions."
sleep 3h
fi
done
まとめ
SteamCMD君json投げるか普通に文字列投げるかどっちかにしてほしい・・・。
以下宣伝 CopiPe Palworld ServerというPalworldの公開サーバーを運営しています!
もしよかったら遊びに来てください!