Module: GameDig

Defined in:
lib/game_dig.rb,
lib/game_dig/nodo.rb,
lib/game_dig/helper.rb,
lib/game_dig/version.rb,
lib/custom_errors/error.rb,
lib/game_dig/query_result.rb,
lib/custom_errors/cli_not_found.rb

Overview

GameDig

Defined Under Namespace

Classes: CliNotFound, Error, Helper, Nodo, QueryResult

Constant Summary collapse

DEBUG_MESSAGE_END =

When gamedig debug is enabled, this string marks the end of debug output and the beginning of JSON output

'Q#0 Query was successful'
VERSION =
'0.2.0'.freeze

Class Method Summary collapse

Class Method Details

.query(type:, host:, address: nil, port: nil, max_retries: nil, socket_timeout: nil, attempt_timeout: nil, given_port_only: nil, ip_family: nil, debug: nil, request_rules: nil, request_players: nil, request_rules_required: nil, request_players_required: nil, strip_colors: nil, port_cache: nil, no_breadth_order: nil, check_old_ids: nil) ⇒ GameDig::QueryResult

Query a server for insight data. Raises GameDig::Error on failure.

‘type’ and ‘host’ are required parameters, all others are optional.

Parameters:

  • type (String)

    One of the game type IDs listed in the games list: github.com/gamedig/node-gamedig/blob/master/GAMES_LIST.md Or you can use protocol- to select a specific protocol. Protocols are listed here: github.com/gamedig/node-gamedig/blob/master/protocols/index.js

  • host (String)

    The hostname or IP address of the server to query

  • address=nil (String)

    Override the IP address of the server skipping DNS resolution. When set, host will not be resolved, instead address will be connected to. However, some protocols still use host for other reasons e.g. as part of the query.

  • port (Number) (defaults to: nil)

    Connection port or query port for the game server. Some games utilize a separate “query” port. If specifying the game port does not seem to work as expected, passing in this query port may work instead.

  • max_retries=1 (Number)

    Number of retries to query server in case of failure. Note that this amount multiplies with the number of attempts.

  • socket_timeout=2000 (Number)

    Milliseconds to wait for a single packet. Beware that increasing this will cause many queries to take longer even if the server is online.

  • attempt_timeout=10000 (Number)

    Milliseconds allowed for an entire query attempt (including socket_timeout, beware that if this value is smaller (or even equal) to the socket one, the query will always fail).

  • given_port_only=false (Boolean)

    Only attempt to query server on given port. Causes any default ports, port offsets or cached ports to be ignored.

  • ip_family=0 (String)

    IP family/version returned when looking up hostnames via DNS, can be 0 (IPv4 and IPv6), 4 (IPv4 only) or 6 (IPv6 only).

  • debug=true (Boolean)

    Enables massive amounts of debug logging to stdout.

  • request_rules=false (Boolean)

    Valve games only. Additional ‘rules’ may be fetched into the ‘raw’ key.

  • request_players=true (Boolean)

    Valve games only. Disable this if you don’t want to fetch players data.

  • request_rules_required=false (Boolean)

    Valve games only. ‘request_rules’ is always required to have a response or the query will timeout.

  • request_players_required=false (Boolean)

    Valve games only. Querying players is always required to have a response or the query will timeout. Some games may not provide a players response.

  • strip_colors=true (Boolean)

    Enables stripping colors for protocols: unreal2, savage2, quake3, nadeo, gamespy2, doom3, armagetron.

  • port_cache=true (Boolean)

    After you queried a server, the second time you query that exact server (identified by specified ip and port), first add an attempt to query with the last successful port.

  • no_breadth_order=false (Boolean)

    Enable the behaviour of retrying an attempt X times followed by the next attempt X times, otherwise try attempt A, then B, then A, then B until reaching the X retry count of each.

  • check_old_ids=false (Boolean)

    Also checks the old ids amongst the current ones.

Returns:



50
51
52
53
54
55
56
57
58
59
# File 'lib/game_dig.rb', line 50

def self.query(type:, host:, address: nil, port: nil, max_retries: nil, socket_timeout: nil, attempt_timeout: nil, given_port_only: nil, ip_family: nil, debug: nil, request_rules: nil, request_players: nil, request_rules_required: nil, request_players_required: nil, strip_colors: nil, port_cache: nil, no_breadth_order: nil, check_old_ids: nil)
  result = if ENV['GAMEDIG_MODE'] == 'cli'
    perform_cli_query(type: type, host: host, address: address, port: port, max_retries: max_retries, socket_timeout: socket_timeout, attempt_timeout: attempt_timeout, given_port_only: given_port_only, ip_family: ip_family, debug: debug, request_rules: request_rules, request_players: request_players, request_rules_required: request_rules_required, request_players_required: request_players_required, strip_colors: strip_colors, port_cache: port_cache, no_breadth_order: no_breadth_order, check_old_ids: check_old_ids)
  elsif ENV['GAMEDIG_MODE'] == 'nodo'
    perform_nodo_query(type: type, host: host, address: address, port: port, max_retries: max_retries, socket_timeout: socket_timeout, attempt_timeout: attempt_timeout, given_port_only: given_port_only, ip_family: ip_family, debug: debug, request_rules: request_rules, request_players: request_players, request_rules_required: request_rules_required, request_players_required: request_players_required, strip_colors: strip_colors, port_cache: port_cache, no_breadth_order: no_breadth_order, check_old_ids: check_old_ids)
  else
    raise "Unsupported GAMEDIG_MODE: #{ENV['GAMEDIG_MODE']}. Supported modes are 'cli' and 'nodo'."
  end
  GameDig::QueryResult.new(result)
end