ruby-qstat

A wrapper gem for using QStat, a game server statistics tool, from Ruby. It launches the qstat command and returns the results — server lists fetched from master servers and status queries against individual game servers — as Ruby objects.

The requirements stated in the README are Ruby 1.9 and QStat 2.12.

Usage

gem install ruby-qstat

Examples from the README.

# マスターサーバーからサーバー一覧を取得
QStat.query_serverlist("hl2master.steampowered.com:27011", "stm", "left4dead2", maxping = 100)

# 個別サーバーの状態を取得
QStat.query("xxx.yyy.zzz.qqq", "a2s")

# 個別サーバーの状態を取得(サーバー情報のみ)
QStat.query_serverinfo("xxx.yyy.zzz.qqq", "a2s")

Internals

The library itself is a single file, lib/ruby-qstat.rb, and the API is provided as class methods on the QStat class (it cannot be instantiated). Launching the qstat command is centralized in a shared exec_cmd, and parsing splits into two paths depending on the output format.

Component diagram of ruby-qstat

The flow of fetching a server list (query_serverlist). It is built to cut qstat off as soon as a server exceeding maxping appears, and the truncated XML is handed to Nokogiri as-is for parsing.

Sequence diagram of query_serverlist

My own gem vrowser (a server browser library for HalfLife2-family games) is built on top of this gem. It is also used by the server browser published on my site.