class RCON::Packet::Source

Constants

COMMAND_AUTH

auth command

COMMAND_EXEC

execution command

RESPONSE_AUTH

auth response

RESPONSE_NORM

normal response

TRAILER

packet trailer

Attributes

command_type[RW]

Type of command, normally COMMAND_AUTH or COMMAND_EXEC. In response packets, RESPONSE_AUTH or RESPONSE_NORM

packet_size[RW]

size of the packet (10 bytes for header + string1 length)

request_id[RW]

Request Identifier, used in managing multiple requests at once

string1[RW]

First string, the only used one in the protocol, contains commands and responses. Null terminated.

string2[RW]

Second string, unused by the protocol. Null terminated.

Public Instance Methods

auth(string) click to toggle source

Generate an authentication packet to be sent to a newly started RCon connection. Takes the RCon password as an argument.

# File lib/rcon/rcon.rb, line 73
def auth(string)
  @request_id = rand(1000)
  @string1 = string
  @string2 = TRAILER
  @command_type = COMMAND_AUTH

  @packet_size = build_packet.length

  return self
end
build_packet() click to toggle source

Builds a packet ready to deliver, without the size prepended. Used to calculate the packet size, use to_s to get the packet that srcds actually needs.

# File lib/rcon/rcon.rb, line 89
def build_packet
  return [@request_id, @command_type, @string1, @string2].pack("VVa#{@string1.length}a2")
end
command(string) click to toggle source

Generate a command packet to be sent to an already authenticated RCon connection. Takes the command as an argument.

# File lib/rcon/rcon.rb, line 57
def command(string)
  @request_id = rand(1000)
  @string1 = string
  @string2 = TRAILER
  @command_type = COMMAND_EXEC

  @packet_size = build_packet.length

  return self
end
to_s() click to toggle source

Returns a string representation of the packet, useful for sending and debugging. This include the packet size.

# File lib/rcon/rcon.rb, line 95
def to_s
  packet = build_packet
  @packet_size = packet.length
  return [@packet_size].pack("V") + packet
end