Class: RCON::Packet::Source
- Inherits:
-
Object
- Object
- RCON::Packet::Source
- Defined in:
- lib/rcon/rcon.rb
Constant Summary collapse
- COMMAND_EXEC =
execution command
2- COMMAND_AUTH =
auth command
3- RESPONSE_AUTH =
auth response
2- RESPONSE_NORM =
normal response
0- TRAILER =
packet trailer
"\x00\x00"
Instance Attribute Summary collapse
-
#command_type ⇒ Object
Type of command, normally COMMAND_AUTH or COMMAND_EXEC.
-
#packet_size ⇒ Object
size of the packet (10 bytes for header + string1 length).
-
#request_id ⇒ Object
Request Identifier, used in managing multiple requests at once.
-
#string1 ⇒ Object
First string, the only used one in the protocol, contains commands and responses.
-
#string2 ⇒ Object
Second string, unused by the protocol.
Instance Method Summary collapse
-
#auth(string) ⇒ Object
Generate an authentication packet to be sent to a newly started RCon connection.
-
#build_packet ⇒ Object
Builds a packet ready to deliver, without the size prepended.
-
#command(string) ⇒ Object
Generate a command packet to be sent to an already authenticated RCon connection.
-
#to_s ⇒ Object
Returns a string representation of the packet, useful for sending and debugging.
Instance Attribute Details
#command_type ⇒ Object
Type of command, normally COMMAND_AUTH or COMMAND_EXEC. In response packets, RESPONSE_AUTH or RESPONSE_NORM
44 45 46 |
# File 'lib/rcon/rcon.rb', line 44 def command_type @command_type end |
#packet_size ⇒ Object
size of the packet (10 bytes for header + string1 length)
40 41 42 |
# File 'lib/rcon/rcon.rb', line 40 def packet_size @packet_size end |
#request_id ⇒ Object
Request Identifier, used in managing multiple requests at once
42 43 44 |
# File 'lib/rcon/rcon.rb', line 42 def request_id @request_id end |
#string1 ⇒ Object
First string, the only used one in the protocol, contains commands and responses. Null terminated.
47 48 49 |
# File 'lib/rcon/rcon.rb', line 47 def string1 @string1 end |
#string2 ⇒ Object
Second string, unused by the protocol. Null terminated.
49 50 51 |
# File 'lib/rcon/rcon.rb', line 49 def string2 @string2 end |
Instance Method Details
#auth(string) ⇒ Object
Generate an authentication packet to be sent to a newly started RCon connection. Takes the RCon password as an argument.
72 73 74 75 76 77 78 79 80 81 |
# File 'lib/rcon/rcon.rb', line 72 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 ⇒ Object
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.
88 89 90 |
# File 'lib/rcon/rcon.rb', line 88 def build_packet return [@request_id, @command_type, @string1, @string2].pack("VVa#{@string1.length}a2") end |
#command(string) ⇒ Object
Generate a command packet to be sent to an already authenticated RCon connection. Takes the command as an argument.
56 57 58 59 60 61 62 63 64 65 |
# File 'lib/rcon/rcon.rb', line 56 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 ⇒ Object
Returns a string representation of the packet, useful for sending and debugging. This include the packet size.
94 95 96 97 98 |
# File 'lib/rcon/rcon.rb', line 94 def to_s packet = build_packet @packet_size = packet.length return [@packet_size].pack("V") + packet end |