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

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

Constant Summary collapse

SERVER_RANK_UPDATE_MESSAGE_TYPE =
52
XP_UPDATE_MESSAGE_TYPE =
65
SEND_PLAYER_ITEM_DROP_MESSAGE_TYPE =
61

Instance Method Summary collapse

Constructor Details

#initialize(parser) ⇒ UserMessageMessageHandler

Returns a new instance of UserMessageMessageHandler.



13
14
15
# File 'lib/overlook/csgo/demo/user_message_message_handler.rb', line 13

def initialize(parser)
  @parser = parser
end

Instance Method Details

#handle(message) ⇒ Object



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
47
48
49
50
51
52
# File 'lib/overlook/csgo/demo/user_message_message_handler.rb', line 17

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

  case user_message.msg_type
  when SEND_PLAYER_ITEM_DROP_MESSAGE_TYPE
    # nop
  when XP_UPDATE_MESSAGE_TYPE
    xp_update_message =  CCSUsrMsg_XpUpdate.decode(user_message.msg_data)
    community_id = SteamID32.parse("[U:1:#{xp_update_message.data.account_id}]").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 SERVER_RANK_UPDATE_MESSAGE_TYPE
    server_rank_update_message = 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.account_id}]").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