Class: Steam::Handler::Collection

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/steam/handler/collection.rb

Overview

Holds a collection of Handler objects

Examples:

Create a collection of Handler objects

collection = Handler::Collection.new
collection << MyHandler.new(client)

Instance Method Summary collapse

Constructor Details

#initializeCollection

Creates an empty list of handlers



13
14
15
# File 'lib/steam/handler/collection.rb', line 13

def initialize
  @handlers = []
end

Instance Method Details

#add(*handlers) ⇒ Object

Add a handler to the collection

Parameters:



36
37
38
39
40
41
# File 'lib/steam/handler/collection.rb', line 36

def add(*handlers)
  handlers.each do |handler|
    @handlers << handler
    Steam.logger.debug("Added handler #{handler.class.name}")
  end
end

#each(&block) ⇒ Object

Iterate through each Handler. Allows the collection to act as an Enumerable



45
46
47
# File 'lib/steam/handler/collection.rb', line 45

def each(&block)
  @handlers.each(&block)
end

#handle(packet) ⇒ Object

Handle a packet. If a handler is found that cares about this packet, the packet object is passed to the handler.

Parameters:



21
22
23
24
25
26
27
28
29
30
31
# File 'lib/steam/handler/collection.rb', line 21

def handle(packet)
  handler = find_handler(packet.msg_type)

  if handler.nil?
    emsg = EMsgUtil.new(packet.emsg)
    Steam.logger.debug("No hander found for: #{emsg.name}")
    return false
  end

  handler.handle(packet)
end