Class: Overlook::Csgo::Demo::PacketHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/overlook/csgo/demo/packet_handler.rb

Overview

Determines which handler to use to read a packet and yields that handler along with the message to the block

Defined Under Namespace

Modules: MessageTypes

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(_parser, parser_config) ⇒ PacketHandler

Returns a new instance of PacketHandler.



16
17
18
19
# File 'lib/overlook/csgo/demo/packet_handler.rb', line 16

def initialize(_parser, parser_config)
  @parser = _parser
  @parser_config = parser_config
end

Instance Attribute Details

#parserObject (readonly)

Returns the value of attribute parser.



14
15
16
# File 'lib/overlook/csgo/demo/packet_handler.rb', line 14

def parser
  @parser
end

Instance Method Details

#handle(packet) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/overlook/csgo/demo/packet_handler.rb', line 21

def handle(packet)
  reader = BitReader.new(packet.data)

  loop do
    message_type  = reader.var_int32
    message_size  = reader.var_int32

    handler = handlers[message_type]
    if handler && handle?(handler)
      handler.handle(reader.bytes(message_size))
    else
      reader.skip(message_size)
    end

    break if reader.eof?
  end
end