T2ServerQuery (T2ServerQuery v0.1.3) View Source

Querying a Tribes 2 server actually requires sending 2 different packets to the server where the first byte is denoting the type of information we're asking for. The first is called the info packet which doesnt contain much more then the server name. The second is called the status packet which contains all the meat and potatoes.

The T2ServerQuery.query/3 function makes requests for both info and status and combines them into a single response for easy consumption.

Installation

def deps do
  [
    {:t2_server_query, "~> 0.1.3"}
  ]
end

Usage

# T2ServerQuery.query("35.239.88.241", port // 28_000, timeout // 3_500)
T2ServerQuery.query("35.239.88.241")

Link to this section Summary

Functions

Perform a server query. Results should be in the form of a tuple with either :ok or :error

Link to this section Functions

Link to this function

query(server_ip, port \\ 28000, timeout \\ 3500)

View Source

Specs

Perform a server query. Results should be in the form of a tuple with either :ok or :error

{:ok, %T2ServerQuery.QueryResult{...} }

{:error, %T2ServerQuery.QueryResult{...} }

Examples

iex> T2ServerQuery.query("35.239.88.241")
{:ok,
%T2ServerQuery.QueryResult{
  bot_count: 0,
  game_type: "Classic",
  map_name: "Canker",
  max_player_count: 64,
  mission_type: "LakRabbit",
  player_count: 0,
  players: [%{}],
  server_description: "Celebrating 20 Years of Tribes2! More information in Discord. <a:playt2.com/discord>playt2.com/discord</a>",
  server_name: "Discord PUB",
  server_status: :online,
  team_count: 1,
  teams: [%{name: "Storm", score: 0}]
}}

iex> T2ServerQuery.query("127.0.0.1")
{:error,
%T2ServerQuery.QueryResult{
  bot_count: 0,
  game_type: "",
  map_name: "",
  max_player_count: 0,
  mission_type: "",
  player_count: 0,
  players: [],
  server_description: "Host unreachable, timed out.",
  server_name: "127.0.0.1:28000",
  server_status: :offline,
  team_count: 0,
  teams: []
}}