TeamFortress2の鯖を立ててみたくなった、のでやってみる。OSはFreeBSD。現在のsourceエンジンじゃない、hlds(half life dedicated server)の時代から、パフォーマンスを出すならLinuxで、というのが定石だ。詳しい仕組みはわからないんだけれど、サーバでの更新レートを秒間1000回出すためにはlinuxのネイティブ環境じゃないとダメなのだ。更新レート秒間1000回ってのは俗に言う、「鯖のFPS1000」ってやつ。hlds時代の実験ではFreeBSDで動くsteam鯖はあくまでlinuxのエミュレートなのでどうしても秒間500回までしかでなかった。でも今回はパフォーマンスをそこまで気にしていないのでFreeBSDでやってみる。
あと現状がどうなってるのかもよくわかんない。
以前にたぶんL4D2用にsrcds鯖を立てたことがあったので参考にしながらやってみた。
まずはsteam鯖をportsからインストール。linuxエミュレート環境がないとココのインスコでコケちゃう。
linuxエミュレート環境はrc.confにlinux_enableをYESと書いてlinux.koをkldloadしてやる。最近だと標準で付いてくるケースが多い気がするけど、もしかすると環境によってはportsでlinux.koを入れないとダメかも。
shell> echo ‘linux_enable=”YES”’ >> /etc/rc.conf
shell> kldload linux.ko
shell> games/linux-steam
インストールするとパッケージからの情報として下記の通りメモが出てきた。ログイン情報はいらなくなったよ、とのことらしい。前々からアレについてはよくわかんなかったんだよね。
===>>> pkg-message for linux-steam-1.1
------------------------------------------------------------------------
Linux HLDS Update Tool has been successfully installed!
To get started:
cd /usr/local/steam
./steam -command update -game [name] -dir .
Steam will then begin downloading the game content to your system. Once
complete you may start your server by:
./hlds_run -game [name] +map [mapname] -maxplayers [#] \
-autoupdate
OR
./srcds_run -game [name] +map [mapname] -maxplayers [#] \
-autoupdate
NOTE: Steam no longer requires login information.
------------------------------------------------------------------------
メモにあるとおり、/usr/local/steamにsteamという名前のバイナリが転がってる。ココにゲームのサーバ本体を入れたりして運用しましょう、ということらしい。アップデートのためにsteamバイナリを何度か動かして、その後でゲームリストを拾ってみる。steamバイナリを動かすときはroot権限とかの、/usr/local/steamに書き込み権限がないとアップデートで落としてくるファイルを書き込めなくてエラーになる。
shell> ./steam -command help
Checking bootstrapper version ...
Getting version 48 of Steam HLDS Update Tool
Downloading. . . . . . . . . . . .Steam Linux Client updated, please retry the command
shell> ./steam -command help
Checking bootstrapper version ...
removing stale semaphore last operated on by process 2786 with name 0eBlobRegistryMutex_07692C9F0DCCAB9B49E0AA2095A1952C
removing stale semaphore last operated on by process 2786 with name 0eBlobRegistrySignal_07692C9F0DCCAB9B49E0AA2095A1952C
Use: steam -command <command> [parameters] [flags]
Commands:
update: Install or update HLDS
parameters:
-game <game> - Game name (use '-command list' to see available games)
-dir <installdir> - HLDS Install dir
(if dir not specified, will use value from last run of tool)
flags:
-verify_all - Verify all HLDS files are up to date
-retry - Automatically retry every 30 seconds if the Steam Network is busy
-remember_password - Remember password (if a username is supplied)
For example: steam -command update -game cstrike -dir /hlds
version: View installed versions
list: View available games
Optional parameters for all commands:
-nobootstrapupdate - Do not check for updates to the update tool
shell> ./steam -command list
Checking bootstrapper version ...
removing stale semaphore last operated on by process 2793 with name 0eBlobRegistryMutex_07692C9F0DCCAB9B49E0AA2095A1952C
removing stale semaphore last operated on by process 2793 with name 0eBlobRegistrySignal_07692C9F0DCCAB9B49E0AA2095A1952C
** 'game' options for Source DS Install:
"Counter-Strike Source"
"ageofchivalry"
"alienswarm"
"cssbeta"
"diprip"
"dods"
"dystopia"
"episode1"
"esmod"
"garrysmod"
"garrysmodbeta"
"hl2mp"
"insurgency"
"l4d_full"
"left4dead"
"left4dead2"
"left4dead2_demo"
"orangebox"
"pvkii"
"smashball"
"synergy"
"tf"
"tf_beta"
"zps"
** 'game' options for HL1 DS Install:
"cstrike"
"cstrike_beta"
"czero"
"dmc"
"dod"
"gearbox"
"ricochet"
"tfc"
"valve"
** 'game' options for Third-Party game servers:
"ageofchivalry"
"aliensvspredator"
"americasarmy3"
"brink"
"darkesthour"
"darkmessiah"
"defencealliance2"
"dinodday"
"diprip"
"dystopia"
"esmod"
"garrysmod"
"garrysmodbeta"
"hauntedhellsreach"
"homefront"
"homefrontjpn"
"insurgency"
"killingfloor"
"killingfloor_beta"
"marenostrum"
"modernwarfare3"
"mondaynightcombat"
"naturalselection2"
"nucleardawn"
"pvkii"
"redorchestra"
"redorchestra2"
"redorchestra_beta"
"serioussam3"
"serioussamhdse"
"ship"
"sin"
"smashball"
"synergy"
"tshb"
"zps"
どうやらTeamFortress2のゲーム名はtfらしい。TeamFortressClassicとカブりそうな気もするけどいいのかな。
下記のコマンドを入れるといろいろとファイルをダウンロードしてくる。結構時間かかりました。
shell> ./steam –command update –game tf –dir ./
…(略)…
102:08 100.00% downloading .//orangebox/hl2/navplace.db
102:08 100.00% downloading .//orangebox/hl2/pure_server_whitelist.txt
102:08 100.00% downloading .//orangebox/libcurl.so.4
102:08 100.00% downloading .//orangebox/libcurl.so.4.2.0
102:09 100.00% downloading .//orangebox/srcds_linux
102:09 100.00% downloading .//orangebox/srcds_run
102:09 [63.150.140.70:27030] Disconnecting
HLDS installation up to date
http://tfortress2.wikiwiki.jp/?server.cfg
上記サイトを参考にサーバの設定をしてみた。コンフィグの置き場所はsteamバイナリが置いてある場所から相対で orangebox/tf/cfg/server.cfg に新規作成。
shell> cat orangebox/tf/cfg/server.cfg
hostname "l2tp tf2 server"
rcon_password "rcon"
mp_chattime 10
mp_stalemate_enable 0
mp_stalemate_timelimit 240
mp_bonusroundtime 5
mp_winlimit 0
mp_maxrounds 0
tf_flag_caps_per_round 3
sv_alltalk 0
mp_timelimit 15
hostname
sv_pure 0
sv_lan 0
sv_consistency 1
sv_stats 1
sv_region 4
log on
sv_log_onefile 0
sv_logfile 1
sv_logbans 1
sv_logecho 1
fps_max 600
sv_minrate 0
sv_maxrate 20000
sv_minupdaterate 10
sv_maxupdaterate 66
sv_allowupload 1
sv_allowdownload 1
net_maxfilesize 15
mp_autoteambalance 1
mp_autoteambalance_delay 60
mp_autoteambalance_warning_delay 30
mp_teams_unbalance_limit 1
mp_enableroundwaittime 1
mp_bonusroundtime 8
mp_restartround 0
mp_stalemate_enable 1
mp_stalemate_timelimit 300
mp_timelimit 35
mp_forcecamera 0
mp_allowspectators 1
mp_footsteps 1
sv_cheats 0
sv_timeout 900
mp_idlemaxtime 15
mp_idledealmethod 2
decalfrequency 0
sv_voiceenable 1
mp_chattime 10
tf_birthday 1
tv_enable 1
tv_name "l2tp hltv"
tv_maxclients 5 // (0-255, default 128)
tv_delay 10 // (10-120[sec], default 30)
tv_delaymapchange 1 // (1 | 0)
tv_port 21520 // (default 27020)
tv_maxrate 0 // (default 5000[bps], 0:unlimited)
tv_autorecord 0
tv_debug 1 // (1 | 0)
//tv_snapshotrate 24 // (default 16)
tv_dispatchmode 1 // (0=never, 1=if appropriate, 2=always)
//tv_overrideroot 0 // (0 | 1)
tv_allow_camera_man 1
tv_allow_static_shots 1 //
//tv_relayvoice 1
tv_transmitall 1
そして実行。+ipで与えるアドレスはsrcds_runのプロセスがバインドするアドレスなのでnapt配下の環境ではローカルipを渡してやる。
一瞬ゲームサーバとかに広告するアドレスでグローバルを書くべきかなとか思ったけど違うみたい。
shell> cd orangebox
shell> ./srcds_run -console -game tf +map ctf_2fort +maxplayers 20 +ip 192.168.1.1 –autoupdate
Auto detecting CPU
Using default binary: ./srcds_linux
Server will auto-restart if there is a crash.
INFO: Located steam: ../steam
Updating server using Steam.
Checking bootstrapper version ...
Getting version 48 of Steam HLDS Update Tool
Downloading. . . . . . . . . . . .Cannot open output file 'LinuxHldsUpdateTool_48.pkg'
2012G/ 47n14F| EZMKF| 11;~42J,28IC JST: Steam Update failed, ignoring.
Unable to determine CPU Frequency
2012G/ 47n14F| EZMKF| 11;~42J,28IC JST: Server restart in 10 seconds
Updating server using Steam.
Checking bootstrapper version ...
removing stale semaphore last operated on by process 22499 with name 0eBlobRegistryMutex_1F7241AEB333B3B7B12FBB9F8A43FDED
なにやら更新作業をしようとして失敗のループをしてる。
Downloading. . . . . . . . . . . .Cannot open output file ‘LinuxHldsUpdateTool_48.pkg’
どうやらファイルをダウンロードしたけど書き込めないよ、とのことらしい。
root権限で動かすとセキュリティリスクがあるよって怒られた。プロセスが乗っ取られるとまずいよね、って。ひとまずroot権限で動かして後でユーザ所有のディレクトリに変えてやる。
shell> sudo ./srcds_run -console -game tf +map ctf_2fort +maxplayers 20 +ip 192.168.1.1 -autoupdate
************** WARNING ***************
Running the dedicated server as root
is highly discouraged. It is generally
unnecessary to use root privileges to
execute the dedicated server.
**************************************
The server will continue to launch in 10 seconds\rThe server will continue to launch in 9 seconds\rThe server will continue to launch in 8 seconds\rThe server will continue to launch in 7 seconds\rThe server will continue to launch in 6 seconds\rThe server will continue to launch in 5 seconds\rThe server will continue to launch in 4 seconds\rThe server will continue to launch in 3 seconds\rThe server will continue to launch in 2 seconds\rThe server will continue to launch in 1 seconds\rAuto detecting CPU
Using default binary: ./srcds_linux
Server will auto-restart if there is a crash.
INFO: Located steam: ../steam
と、またもやループしてる。
見れば
Unable to determine CPU Frequency
と出ている。どうやらCPUの周波数が分からないよ、と。FreeBSDだとLinuxと違ってprocinfoにCPUの情報が無いからだろう。
過去の記事を参考にprocinfoを引けるようにしてあげる。
shell> echo "linprocfs /compat/linux/proc linprocfs rw 0 0" >> /etc/fstab
shell> mount -a
動いた。でもLANモードオンリーとかって気になる文字列が。
shell> ./srcds_run -console -game tf +map ctf_2fort +maxplayers 20 +ip 192.168.1.1 –autoupdate
…(略)…
*********************************************************
* Unable to load Steam support library.*
* This server will operate in LAN mode only.*
*********************************************************
原因はポートの待ち受け設定をnaptでやってないことだった。naptでポートの転送先をちゃんと設定するとうまく動いた。
以上で一通りの動作を確認できた。あとは動かしながら調整していこうと思う。