Class: Overlook::Csgo::Demo::UserMessageMessageHandler

Inherits:
Object
  • Object
show all
Includes:
SteamIDs
Defined in:
lib/overlook/csgo/demo/user_message_message_handler.rb

Instance Method Summary collapse

Constructor Details

#initialize(parser) ⇒ UserMessageMessageHandler

Returns a new instance of UserMessageMessageHandler.



9
10
11
# File 'lib/overlook/csgo/demo/user_message_message_handler.rb', line 9

def initialize(parser)
  @parser = parser
end

Instance Method Details

#handle(message) ⇒ Object



13
14
15
16
17
18
19
20
21
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
# File 'lib/overlook/csgo/demo/user_message_message_handler.rb', line 13

def handle(message)
  user_message = ::Csgo::CSVCMsg_UserMessage.decode(message)

  case user_message.msg_type
  when ::Csgo::ECstrike15UserMessages::CS_UM_XpUpdate
    xp_update_message =  ::Csgo::CCSUsrMsg_XpUpdate.decode(user_message.msg_data)
    community_id = SteamID32.parse("[U:1:#{xp_update_message.data.}]").to_steamID64.to_s

    xp_update = {
      community_id => {
        xp: xp_update_message.data.current_xp,
        lvl: xp_update_message.data.current_level,
        progress: xp_update_message.data.xp_progress_data.map do |item|
          { category: item.xp_category, xp: item.xp_points }
        end
      }
    }

    @parser.emit(:xp_update, xp_update)
  when ::Csgo::ECstrike15UserMessages::CS_UM_ServerRankUpdate
    server_rank_update_message = ::Csgo::CCSUsrMsg_ServerRankUpdate.decode(user_message.msg_data)

    server_rank_update_message.rank_update.each do |update|
      # The account_id is used in the 'modern' steam format.
      # [U:1:account_id]
      community_id = SteamID32.parse("[U:1:#{update.}]").to_steamID64.to_s

      rank_update_payload = { rank_change: update.rank_change.to_i, wins: update.num_wins,
                                community_id: community_id, rank: update.rank_new }

      @parser.emit(:rank_update, rank_update_payload)
    end
  end
end