vrowser
A Ruby library for building server browsers for HalfLife2-family (Source Engine) games such as Left 4 Dead 2 and Team Fortress 2. It wraps QStat, a game server statistics tool, and handles the whole pipeline: fetching server lists, recording them to a database, and serving them via a JSON API.
Published as a gem, with a command-line tool bundled in.
gem install vrowser
vrowser sample # サンプル設定ファイルを生成
vrowser -f config.yml fetch # マスターサーバーからサーバー一覧を取得
vrowser -f config.yml update # 登録済みサーバーの状態を更新
vrowser -f config.yml daemon # 常駐デーモンとして起動
Internals
The component layout. The central Vrowser class ties together the QStat invocations and DB recording via Sequel (an ORM), so the same operations can be called from the CLI, the resident daemon, or the Sinatra app alike.
- Vrowser (
lib/vrowser.rb) — providesfetch(fetch the server list from the master server and register it in the DB),update(query every registered server and refresh its status), andclear(delete servers that went DOWN) - VrowserModel::Servers — the Sequel model. It carries its schema definition in code and creates the table on first connection if it does not exist. The
hostcolumn is the unique key - Vrowser::HTTPDaemon (
lib/vrowser/http_daemon.rb) — serves a JSON API (/api/updated/json,/api/connected/json) and the listing UI inpublic_html/(built with jQuery DataTables) over WEBrick, while running the fetch loop in a separate thread - plugins/ — per-game extra logic. The bundled
l4d2.rbinfers the game type from regex matches on the server name (co-?op,versus,scavenge, etc.) when it cannot be determined from the server info
The daemon’s update cycle works like this. Since querying the master server is expensive, it is a two-tier design: the full list is re-fetched only about once every 30 minutes, while in between, individual queries (A2S) against the registered servers run at 150-second intervals.
Servers that stop responding are not deleted immediately but marked status=DOWN, then swept up in bulk with clear.
It is built from a combination of my own gems: ruby-qstat for invoking and parsing QStat, and retry-handler for retrying failed master server fetches.