Skip to content

Commit d94ca2b

Browse files
committed
Add doc for Rex::Proto::Steam
1 parent 6330c42 commit d94ca2b

File tree

2 files changed

+26
-9
lines changed

2 files changed

+26
-9
lines changed

lib/rex/proto/steam/message.rb

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,30 @@ module Proto
88
#
99
##
1010
module Steam
11+
# The Steam header ussed when the message is fragmented.
1112
FRAGMENTED_HEADER = 0xFFFFFFFE
13+
# The Steam header ussed when the message is not fragmented.
1214
UNFRAGMENTED_HEADER = 0xFFFFFFFF
1315

16+
# Decodes a Steam response message.
17+
#
18+
# @param message [String] the message to decode
19+
# @return [Array] the message type and body
1420
def decode_message(message)
1521
# minimum size is header (4) + type (1)
1622
return if message.length < 5
1723
header, type = message.unpack('NC')
1824
# TODO: handle fragmented responses
1925
return if header != UNFRAGMENTED_HEADER
20-
[header, type, message[5, message.length]]
26+
[type, message[5, message.length]]
2127
end
2228

23-
def encode_message(type, payload)
29+
# Encodes a Steam message.
30+
#
31+
# @param type [String, Fixnum] the message type
32+
# @param body [String] the message body
33+
# @return [String] the encoded Steam message
34+
def encode_message(type, body)
2435
if type.is_a? Fixnum
2536
type_num = type
2637
elsif type.is_a? String
@@ -29,23 +40,30 @@ def encode_message(type, payload)
2940
fail ArgumentError, 'type must be a String or Fixnum'
3041
end
3142

32-
[UNFRAGMENTED_HEADER, type_num ].pack('NC') + payload
43+
[UNFRAGMENTED_HEADER, type_num ].pack('NC') + body
3344
end
3445

46+
# Builds an A2S_INFO message
47+
#
48+
# @return [String] the A2S_INFO message
3549
def a2s_info
3650
encode_message('T', "Source Engine Query\x00")
3751
end
3852

39-
def a2s_info_decode(message)
53+
# Decodes an A2S_INFO response message
54+
#
55+
# @parameter response [String] the A2S_INFO resposne to decode
56+
# @return [Hash] the fields extracted from the response
57+
def a2s_info_decode(response)
4058
# abort if it is impossibly short
41-
return nil if message.length < 19
42-
_header, message_type, payload = decode_message(message)
59+
return nil if response.length < 19
60+
message_type, body = decode_message(response)
4361
# abort if it isn't a valid Steam response
4462
return nil if message_type != 0x49 # 'I'
4563
info = {}
4664
info[:version], info[:name], info[:map], info[:folder], info[:game_name],
4765
info[:game_id], players, players_max, info[:bots],
48-
type, env, vis, vac, info[:game_version], _edf = payload.unpack("CZ*Z*Z*Z*SCCCCCCCZ*C")
66+
type, env, vis, vac, info[:game_version], _edf = body.unpack("CZ*Z*Z*Z*SCCCCCCCZ*C")
4967

5068
# translate type
5169
case type

spec/lib/rex/proto/steam/message_spec.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@
2626
end
2727

2828
it 'properly decodes valid messages' do
29-
header, type, message = steam.decode_message("\xFF\xFF\xFF\xFF\x54Test")
30-
expect(header).to eq(Rex::Proto::Steam::UNFRAGMENTED_HEADER)
29+
type, message = steam.decode_message("\xFF\xFF\xFF\xFF\x54Test")
3130
expect(type).to eq(0x54)
3231
expect(message).to eq('Test')
3332
end

0 commit comments

Comments
 (0)