RCON v0.4.0 RCON.Client View Source

Provides functionality to connect to a RCON server.

Link to this section Summary

Functions

Authenticate a connection given a password.

Connects to an RCON server.

Execute a command.

Receive a RCON packet.

Send a RCON packet.

Link to this section Types

Specs

connection() :: {Socket.TCP.t(), RCON.Packet.id(), boolean()}

Specs

options() :: [multi: boolean(), timeout: timeout()]

Link to this section Functions

Link to this function

authenticate(conn, password)

View Source

Specs

authenticate(connection(), binary()) ::
  {:ok, connection(), boolean()} | {:error, binary()}

Authenticate a connection given a password.

Examples

# Successful auth
{:ok, conn, true} = RCON.Client.authenticate(conn, "correct-password")
# Failed auth
{:ok, conn, false} = RCON.Client.authenticate(conn, "bad-password")
Link to this function

connect(address, port, options \\ [])

View Source

Specs

connect(Socket.Address.t(), :inet.port_number(), options()) ::
  {:ok, connection()}
  | {:error, %Socket.Error{__exception__: term(), message: term()}}

Connects to an RCON server.

Single/multi packet response support

When sending a command with multi packet response support enabled (default), the original command is sent followed by a second dummy request. When the response to the second request is received, we know the first request has finished sending its entire response. This is how multi-packet responses work.

Games such as Minecraft and Factorio don't support multi-packet responses well or at all. To support them configure the connection as multi: false and only a single RCON request will be sent and the first response packet received will be returned.

Specs

exec(connection(), binary()) ::
  {:ok, connection(), binary()} | {:error, binary()}

Execute a command.

Examples

# Send a command given a RCON connection
{:ok, conn, "command response..."} = RCON.Client.exec(conn, "command...")

Specs

recv(connection()) :: {:ok, RCON.Packet.t()} | {:error, binary()}

Receive a RCON packet.

Specs

send(connection(), RCON.Packet.kind(), RCON.Packet.body()) ::
  {:ok, connection(), RCON.Packet.id()} | {:error, binary()}

Send a RCON packet.