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
Type of command, normally COMMAND_AUTH
or COMMAND_EXEC
. In response packets, RESPONSE_AUTH
or RESPONSE_NORM
size of the packet (10 bytes for header + string1 length)
Request Identifier, used in managing multiple requests at once
First string, the only used one in the protocol, contains commands and responses. Null terminated.
Second string, unused by the protocol. Null terminated.
Public Instance Methods
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
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
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
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