Class: SteamCondenser::Servers::Packets::M2A_SERVER_BATCH_Packet

Inherits:
Object
  • Object
show all
Includes:
BasePacket
Defined in:
lib/steam-condenser/servers/packets/m2a_server_batch_packet.rb

Overview

This packet class represents a M2A_SERVER_BATCH response replied by a master server

It contains a list of IP addresses and ports of game servers matching the requested criteria.

See Also:

Author:

  • Sebastian Staudt

Constant Summary

Constants included from BasePacket

BasePacket::A2M_GET_SERVERS_BATCH2_HEADER, BasePacket::A2S_INFO_HEADER, BasePacket::A2S_PLAYER_HEADER, BasePacket::A2S_RULES_HEADER, BasePacket::A2S_SERVERQUERY_GETCHALLENGE_HEADER, BasePacket::C2M_CHECKMD5_HEADER, BasePacket::M2A_SERVER_BATCH_HEADER, BasePacket::RCON_GOLDSRC_CHALLENGE_HEADER, BasePacket::RCON_GOLDSRC_NO_CHALLENGE_HEADER, BasePacket::RCON_GOLDSRC_RESPONSE_HEADER, BasePacket::S2A_INFO2_HEADER, BasePacket::S2A_INFO_DETAILED_HEADER, BasePacket::S2A_PLAYER_HEADER, BasePacket::S2A_RULES_HEADER, BasePacket::S2C_CHALLENGE_HEADER, BasePacket::S2C_CONNREJECT_HEADER

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from BasePacket

#to_s

Constructor Details

#initialize(data) ⇒ M2A_SERVER_BATCH_Packet

Creates a new M2A_SERVER_BATCH response object based on the given data

Parameters:

  • data (String)

    The raw packet data replied from the server

Raises:


33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/steam-condenser/servers/packets/m2a_server_batch_packet.rb', line 33

def initialize(data)
  super M2A_SERVER_BATCH_HEADER, data

  unless @content_data.getbyte == 0x0A
    raise SteamCondenser::Error::PacketFormat, 'Master query response is missing additional 0x0A byte.'
  end

  @servers = []

  begin
    first_octet = @content_data.getbyte
    second_octet = @content_data.getbyte
    third_octet = @content_data.getbyte
    fourth_octet = @content_data.getbyte
    port_number = @content_data.short
    port_number = ((port_number & 0xFF) << 8) + (port_number >> 8)

    @servers << "#{first_octet}.#{second_octet}.#{third_octet}.#{fourth_octet}:#{port_number}"
  end while @content_data.remaining > 0
end

Instance Attribute Details

#serversArray<String> (readonly)

Returns the list of servers returned from the server in this packet

Returns:

  • (Array<String>)

    An array of server addresses (i.e. IP addresses + port numbers)


27
28
29
# File 'lib/steam-condenser/servers/packets/m2a_server_batch_packet.rb', line 27

def servers
  @servers
end