Module: RCONPacketFactory

Defined in:
lib/steam/packets/rcon/rcon_packet_factory.rb

Overview

This module provides functionality to handle raw packet data for Source RCON

It’s is used to transform data bytes into packet objects for RCON communication with Source servers.

See Also:

Author:

  • Sebastian Staudt

Class Method Summary collapse

Class Method Details

.packet_from_data(raw_data) ⇒ RCONPacket

Creates a new packet object based on the header byte of the given raw data

Parameters:

  • raw_data (String)

    The raw data of the packet

Returns:

  • (RCONPacket)

    The packet object generated from the packet data

Raises:



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/steam/packets/rcon/rcon_packet_factory.rb', line 26

def self.packet_from_data(raw_data)
  byte_buffer = StringIO.new raw_data

  request_id = byte_buffer.long
  header = byte_buffer.long
  data = byte_buffer.cstring

  case header
    when RCONPacket::SERVERDATA_AUTH_RESPONSE then
      return RCONAuthResponse.new(request_id)
    when RCONPacket::SERVERDATA_RESPONSE_VALUE then
      return RCONExecResponse.new(request_id, data)
    else
      raise PacketFormatException.new("Unknown packet with header #{header.to_s(16)} received.")
  end
end