Class: Empp::MsgConnect

Inherits:
EmppBase show all
Defined in:
lib/empp/msg_connect.rb

Instance Attribute Summary

Attributes inherited from EmppBase

#command_id, #sequence_id, #total_length

Instance Method Summary collapse

Constructor Details

#initialize(accountId, password) ⇒ MsgConnect

Returns a new instance of MsgConnect.



13
14
15
16
17
18
19
20
# File 'lib/empp/msg_connect.rb', line 13

def initialize(accountId, password)
  @accountId = accountId
  @password = password

  @total_length = 12 + 21 + 16 + 1 + 4
  @command_id = Constants::EMPPCONNECT
  setSequenceId
end

Instance Method Details

#packageObject



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/empp/msg_connect.rb', line 22

def package
  buf = Utils::ByteBuffer.new
  # add header
  buf.append_uint_be(@total_length)

  buf.append_uint_be(@command_id)
  buf.append_uint_be(@sequence_id)

  # 21 bytes accountId
  act_id = @accountId.to_s 
  buf.append_string( act_id.ljust(21, "\0") )

  timestampStr = Utils::Utils.getTimestampStr(Time.now)

  # 16 bytes AuthenticatorSource
  authSource = @accountId.to_s + ''.rjust(9, "\0") + @password + timestampStr
  buf.append_string( MD5.digest(authSource) )

  # 1 byte version, fixed
  buf.append_string( Utils::Utils.getVersion )

  # 4 bytes timestamp
  buf.append_string( Utils::Utils.getUintBe(timestampStr.to_i) )

  buf.data

end