Module: Steam::Protocol::Message

Included in:
ClientMessage, GcMessage, ProtobufMessage
Defined in:
lib/steam/protocol/message.rb

Overview

The base Steam message. Each message contains a header, body and emsg attribute.

The #emsg corresponds to the constants EMsg in the SteamLanguage

Constant Summary collapse

PROTO_MASK =

Valve's mask for determining if a packet is Protobuf backed

0x80000000

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#bodyObject (readonly)

Each packet has a body, this is the Message being held in the packet.



24
25
26
# File 'lib/steam/protocol/message.rb', line 24

def body
  @body
end

#emsgObject (readonly)

The Message type

See Also:

  • EMsg


32
33
34
# File 'lib/steam/protocol/message.rb', line 32

def emsg
  @emsg
end

#headerObject (readonly)

Each packet has a header. The header is defined by the Steam Language. A header can be a MsgHdr, or a MsgHdrProtoBuf

See Also:

  • MsgHdrProtoBuf
  • MsgHdr


20
21
22
# File 'lib/steam/protocol/message.rb', line 20

def header
  @header
end

#payloadObject (readonly)

Each packet has an optional byte string payload



27
28
29
# File 'lib/steam/protocol/message.rb', line 27

def payload
  @payload
end

Instance Method Details

#decode(io) ⇒ Object

Decode a Packet from an io object

Parameters:

  • io (#read)

    The IO stream



70
71
72
73
74
75
76
77
78
79
80
# File 'lib/steam/protocol/message.rb', line 70

def decode(io)
  @header.decode_from(io)

  if @body.respond_to?(:decode_from)
    # Steam language
    @body.decode_from(io)
  else
    # Proto
    @body = @body.class.decode(io.read)
  end
end

#encodeString

Encode a Packet from to a string

Returns:

  • (String)

    The byte representation of the Packet

See Also:

  • Packet


86
87
88
89
90
91
92
93
94
95
96
# File 'lib/steam/protocol/message.rb', line 86

def encode
  io = StringIO.new
  io.set_encoding('BINARY')

  @header.encode_to(io)
  body = @body.encode
  io.write(body)
  io.write(@payload.string)

  io.string
end

#initialize(header, body, emsg) ⇒ Object

Instantiate a Message object

Parameters:

  • header (MsgHdr, MsgHdrProtoBuf)
  • body
  • emsg


39
40
41
42
43
44
45
46
# File 'lib/steam/protocol/message.rb', line 39

def initialize(header, body, emsg)
  @header = header
  @body = body
  @header.msg = emsg
  @payload = ByteWriter.new
  @emsg = emsg
  nil
end

#proto?Boolean

By default a Message is not Protobuf backed

Returns:

  • (Boolean)


49
50
51
# File 'lib/steam/protocol/message.rb', line 49

def proto?
  false
end

#session_id=(_sid) ⇒ Object

The session id associated with the message

Parameters:

  • _sid (String)

    the Session id

Raises:

  • (NotImplementedError)


63
64
65
# File 'lib/steam/protocol/message.rb', line 63

def session_id=(_sid)
  raise NotImplementedError
end

#steam_id=(_sid) ⇒ Object

The steam id associated with the message

Parameters:

  • _sid (String)

    the Steam id

Raises:

  • (NotImplementedError)


56
57
58
# File 'lib/steam/protocol/message.rb', line 56

def steam_id=(_sid)
  raise NotImplementedError
end