Class: S2A_PLAYER_Packet

Inherits:
Object
  • Object
show all
Includes:
SteamPacket
Defined in:
lib/steam/packets/s2a_player_packet.rb

Overview

This class represents a S2A_PLAYER response sent by a game server

It is used to transfer a list of players currently playing on the server.

See Also:

  • GameServer#update_player_info

Author:

  • Sebastian Staudt

Constant Summary

Constants included from SteamPacket

SteamPacket::A2M_GET_SERVERS_BATCH2_HEADER, SteamPacket::A2S_INFO_HEADER, SteamPacket::A2S_PLAYER_HEADER, SteamPacket::A2S_RULES_HEADER, SteamPacket::A2S_SERVERQUERY_GETCHALLENGE_HEADER, SteamPacket::C2M_CHECKMD5_HEADER, SteamPacket::M2A_SERVER_BATCH_HEADER, SteamPacket::M2C_ISVALIDMD5_HEADER, SteamPacket::M2S_REQUESTRESTART_HEADER, SteamPacket::RCON_GOLDSRC_CHALLENGE_HEADER, SteamPacket::RCON_GOLDSRC_NO_CHALLENGE_HEADER, SteamPacket::RCON_GOLDSRC_RESPONSE_HEADER, SteamPacket::S2A_INFO2_HEADER, SteamPacket::S2A_INFO_DETAILED_HEADER, SteamPacket::S2A_LOGSTRING_HEADER, SteamPacket::S2A_PLAYER_HEADER, SteamPacket::S2A_RULES_HEADER, SteamPacket::S2C_CHALLENGE_HEADER, SteamPacket::S2C_CONNREJECT_HEADER, SteamPacket::S2M_HEARTBEAT2_HEADER

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from SteamPacket

#to_s

Constructor Details

#initialize(content_data) ⇒ S2A_PLAYER_Packet

Creates a new S2A_PLAYER response object based on the given data

Parameters:

  • content_data (String)

    The raw packet data sent by the server

Raises:



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

def initialize(content_data)
  if content_data.nil?
    raise PacketFormatError, 'Wrong formatted S2A_PLAYER packet.'
  end

  super S2A_PLAYER_HEADER, content_data

  @content_data.byte
  @player_hash = {}

  while @content_data.remaining > 0
    player_data = @content_data.byte, @content_data.cstring, @content_data.signed_long, @content_data.float
    @player_hash[player_data[1]] = SteamPlayer.new(*player_data[0..3])
  end
end

Instance Attribute Details

#player_hashHash<String, SteamPlayer> (readonly)

Returns the list of active players provided by the server

Returns:

  • (Hash<String, SteamPlayer>)

    All active players on the server



22
23
24
# File 'lib/steam/packets/s2a_player_packet.rb', line 22

def player_hash
  @player_hash
end