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.

Component diagram of vrowser

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.

Sequence diagram of the vrowser update cycle

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.