Class: RCon::Packet::Source
- Inherits:
-
Object
- Object
- RCon::Packet::Source
- Defined in:
- lib/rcon.rb
Overview
RCon::Packet::Source generates a packet structure useful for RCon::Query::Source protocol queries.
This class is primarily used internally, but is available if you want to do something more advanced with the Source RCon protocol.
Use at your own risk.
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
112 113 114 |
# File 'lib/rcon.rb', line 112 def command_type @command_type end |
#packet_size ⇒ Object
size of the packet (10 bytes for header + string1 length)
108 109 110 |
# File 'lib/rcon.rb', line 108 def packet_size @packet_size end |
#request_id ⇒ Object
Request Identifier, used in managing multiple requests at once
110 111 112 |
# File 'lib/rcon.rb', line 110 def request_id @request_id end |
#string1 ⇒ Object
First string, the only used one in the protocol, contains commands and responses. Null terminated.
115 116 117 |
# File 'lib/rcon.rb', line 115 def string1 @string1 end |
#string2 ⇒ Object
Second string, unused by the protocol. Null terminated.
117 118 119 |
# File 'lib/rcon.rb', line 117 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.
140 141 142 143 144 145 146 147 148 149 |
# File 'lib/rcon.rb', line 140 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.
156 157 158 |
# File 'lib/rcon.rb', line 156 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.
124 125 126 127 128 129 130 131 132 133 |
# File 'lib/rcon.rb', line 124 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.
162 163 164 165 166 |
# File 'lib/rcon.rb', line 162 def to_s packet = build_packet @packet_size = packet.length return [@packet_size].pack("V") + packet end |