Module: SteamCondenser::Servers::Packets::RCON::RCONPacketFactory

Defined in:
lib/steam-condenser/servers/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) ⇒ BasePacket

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:

  • (BasePacket)

    The packet object generated from the packet data

Raises:


30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/steam-condenser/servers/packets/rcon/rcon_packet_factory.rb', line 30

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 BasePacket::SERVERDATA_AUTH_RESPONSE then
      return RCONAuthResponse.new(request_id)
    when BasePacket::SERVERDATA_RESPONSE_VALUE then
      return RCONExecResponse.new(request_id, data)
    else
      raise SteamCondenser::Error::PacketFormat, "Unknown packet with header #{header.to_s(16)} received."
  end
end