class

RCON::Client

Inherits Reference < Object

This class represents a RCON connection.

RCON::Client.open(address, port, password) do |client|
  client.command "say Hello from RCON =)"
end

Use as a Server

While this is primarily a client implementation it can also be used as for a server because both ends work in the same manner.

def handle_connection(socket)do
  rcon = RCON::Client.new(socket)
  packet = rcon.read_
  puts "Received packet #{packet}"
  # Probably need some authentication logic here
  socket.close
end

TCPServer.open(27015) do |server|
  while socket = server.accept?
    spawn handle_connection(socket)
  end
end

Constructors

new(socket : IO, sync_close : Bool = true)

Creates a new client instance wrapping socket.

The socket should usually be a TCPSocket, but it can really be any IO.

Calling .open is recommended for most use cases. When using this constructor, authentication needs to be handled explicitly (see #authenticate).

Source

Class methods

open(address : String, port : Int32, password : String | Nil, & : self -> )

Opens a new connection to the server at address:port and authenticates with password. Yields the client instance to the block and ensures the connection is closed after returning.

Source
open(uri : URI, & : self -> )

Opens a new connection to the server at uri and authenticates.

URI format: rcon://:password@host:port

Yields the client instance to the block and ensures the connection is closed after returning.

Source

Instance methods

authenticate(password) : Bool

Sends an auth command to authenticate with password.

Return true if authenticated successfully and false otherwise. Raises AuthenticationError if there was an error in the authentication process.

Source
close

Sends close command and closes the connection.

Source
closed?

Returns true when this client has been closed.

Source
command(command : String) : String | Nil

Sends command and returns the server's response.

Source
read

Reads a response from the server.

Returns nil if the connection is closed.

Source
send(command : String | Bytes, cmd_type : Command | Int32 = Command::EXEC_COMMAND) : Int32

Sends command and returns the request id.

Source
send(packet : Packet)

Sends packet and returns the request id.

Source