Module: Steam::Handler::Base

Included in:
Auth, GameCoordinator, SteamApps, SteamUser
Defined in:
lib/steam/handler/base.rb

Overview

Defines the base Handler

Examples:

Creating a handler

class MyHandler
  include HandlerBase

  handles :CLIENT_LOG_OFF

  def handle(packet)
  end
end

Defined Under Namespace

Modules: ClassMethods

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#clientObject (readonly)

The Client object

See Also:



24
25
26
# File 'lib/steam/handler/base.rb', line 24

def client
  @client
end

Class Method Details

.included(base) ⇒ Object

Inject class methods into the hosting class



17
18
19
# File 'lib/steam/handler/base.rb', line 17

def self.included(base)
  base.send(:extend, ClassMethods)
end

Instance Method Details

#handle(_packet) ⇒ Object

Handle the incoming packet

Parameters:

Raises:

  • (NotImplementedError)


41
42
43
# File 'lib/steam/handler/base.rb', line 41

def handle(_packet)
  raise NotImplementedError
end

#handles?(msg) ⇒ Bool

Determines if this handler can handle the given message type. It compares the symbols given via .handles to known EMsg constants.

Parameters:

  • msg (Integer)

Returns:

  • (Bool)


50
51
52
# File 'lib/steam/handler/base.rb', line 50

def handles?(msg)
  self.class.handled_messages.any? { |m| msg == m }
end

#initialize(client) ⇒ Object

Instantiate a Handler with a Client

Examples:

Creating a Handler

class MyHandler
  include Handler::Base
end

handler = MyHandler.new(Client.new)


34
35
36
# File 'lib/steam/handler/base.rb', line 34

def initialize(client)
  @client = client
end

#send_msg(msg) ⇒ Bool

Send a message to the client

Parameters:

  • msg (Message)

    The Message to send to steam

Returns:

  • (Bool)


58
59
60
# File 'lib/steam/handler/base.rb', line 58

def send_msg(msg)
  @client.send_msg(msg)
end