Class: SteamHldsLogParser::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/steam_hlds_log_parser/client.rb

Overview

Listens to HLDS logs received via UDP on configured port

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(displayer, options = {}) ⇒ Client

Creates a new client

Parameters:

  • displayer (Class)

    Callback class which will receive parsed content, do what you want with this class

  • options (Hash) (defaults to: {})

    Optional parameters to setup your client

Options Hash (options):

  • :host (String) — default: 0.0.0.0

    IP Address the client will be running, usually localhost

  • :port (Integer) — default: 27115

    Port will be listening to

  • :locale (Symbol) — default: :en

    Set the language of returned content

  • :display_end_map (Boolean) — default: true

    Enable display of score at the end of each map

  • :display_end_round (Boolean) — default: true

    Enable display of score after each round

  • :display_kills (Boolean) — default: true

    Enable kills / frags detail

  • :display_actions (Boolean) — default: true

    Enable players actions / defuse / … detail

  • :display_changelevel (Boolean) — default: true

    Enable changelevel (map) display

  • :display_chat (Boolean) — default: true

    Enable chat (‘say’) display

  • :display_team_chat (Boolean) — default: true

    Enable chat (‘say_team’) display

  • :display_connect (Boolean) — default: true

    Enable player connection display

  • :display_disconnect (Boolean) — default: true

    Enable player disconnection display



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/steam_hlds_log_parser/client.rb', line 29

def initialize(displayer, options = {})
 default_options = {
   :host                 => "0.0.0.0",
   :port                 => 27115,
   :locale               => :en,
   :display_end_map      => true,
   :display_end_round    => true,
   :display_kills        => true,
   :display_actions      => true,
   :display_changelevel  => true,
   :display_chat         => true,
   :display_team_chat    => true,
   :display_connect      => true,
   :display_disconnect   => true
 }
 @options      = default_options.merge(options)
 @displayer    = displayer
end

Instance Attribute Details

#displayerObject (readonly)

Returns the value of attribute displayer.



9
10
11
# File 'lib/steam_hlds_log_parser/client.rb', line 9

def displayer
  @displayer
end

#optionsHash (readonly)

Client options

Returns:

  • (Hash)

    the current value of options



7
8
9
# File 'lib/steam_hlds_log_parser/client.rb', line 7

def options
  @options
end

Instance Method Details

#startObject

Starts the client which will receive HLDS logs (using UDP)



49
50
51
52
53
54
55
56
57
58
59
# File 'lib/steam_hlds_log_parser/client.rb', line 49

def start
 # setting locale
 I18n.locale = @options[:locale] || I18n.default_locale
 EM.run {
   # catch CTRL+C
   Signal.trap("INT")  { EM.stop }
   Signal.trap("TERM") { EM.stop }
   # Let's start
   EM::open_datagram_socket(@options[:host], @options[:port], Handler, @displayer, @options)
 }       
end

#stopObject

Stops the client



62
63
64
65
# File 'lib/steam_hlds_log_parser/client.rb', line 62

def stop
  puts "## #{@options[:host]}:#{@options[:port]} => #{I18n.t('client_stop')}"
  EM::stop_event_loop
end