Class: SteamPlayer

Inherits:
Object
  • Object
show all
Defined in:
lib/steam/steam_player.rb

Overview

The SteamPlayer class represents a player connected to a server

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id, name, score, connect_time) ⇒ SteamPlayer

Creates a new SteamPlayer object based on the given information



15
16
17
18
19
20
21
# File 'lib/steam/steam_player.rb', line 15

def initialize(id, name, score, connect_time)
  @connect_time = connect_time
  @id = id
  @name = name
  @score = score
  @extended = false
end

Instance Attribute Details

#client_portObject (readonly)

Returns the value of attribute client_port.



11
12
13
# File 'lib/steam/steam_player.rb', line 11

def client_port
  @client_port
end

#connect_timeObject (readonly)

Returns the value of attribute connect_time.



11
12
13
# File 'lib/steam/steam_player.rb', line 11

def connect_time
  @connect_time
end

#idObject (readonly)

Returns the value of attribute id.



11
12
13
# File 'lib/steam/steam_player.rb', line 11

def id
  @id
end

#ip_addressObject (readonly)

Returns the value of attribute ip_address.



11
12
13
# File 'lib/steam/steam_player.rb', line 11

def ip_address
  @ip_address
end

#lossObject (readonly)

Returns the value of attribute loss.



11
12
13
# File 'lib/steam/steam_player.rb', line 11

def loss
  @loss
end

#nameObject (readonly)

Returns the value of attribute name.



11
12
13
# File 'lib/steam/steam_player.rb', line 11

def name
  @name
end

#pingObject (readonly)

Returns the value of attribute ping.



11
12
13
# File 'lib/steam/steam_player.rb', line 11

def ping
  @ping
end

#rateObject (readonly)

Returns the value of attribute rate.



11
12
13
# File 'lib/steam/steam_player.rb', line 11

def rate
  @rate
end

#real_idObject (readonly)

Returns the value of attribute real_id.



11
12
13
# File 'lib/steam/steam_player.rb', line 11

def real_id
  @real_id
end

#scoreObject (readonly)

Returns the value of attribute score.



11
12
13
# File 'lib/steam/steam_player.rb', line 11

def score
  @score
end

#stateObject (readonly)

Returns the value of attribute state.



11
12
13
# File 'lib/steam/steam_player.rb', line 11

def state
  @state
end

#steam_idObject (readonly)

Returns the value of attribute steam_id.



11
12
13
# File 'lib/steam/steam_player.rb', line 11

def steam_id
  @steam_id
end

Instance Method Details

#add_info(player_data) ⇒ Object

Extends this player object with additional information acquired using RCON status



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/steam/steam_player.rb', line 25

def add_info(player_data)
  unless player_data[:name] == @name
    raise SteamCondenserException.new('Information to add belongs to a different player.')
  end

  @extended = true

  @real_id  = player_data[:userid].to_i
  @steam_id = player_data[:uniqueid]
  @state    = player_data[:state] if player_data.key? :state

  if !bot?
    @loss = player_data[:loss].to_i
    @ping = player_data[:ping].to_i

    if player_data.key? :adr
      @ip_address, @client_port  = player_data[:adr].split(':')
      @client_port = @client_port.to_i
    end

    @rate  = player_data[:rate].to_i if player_data.key? :rate
  end
end

#bot?Boolean

Returns whether this player is a bot

Returns:

  • (Boolean)


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

def bot?
  @steam_id == 'BOT'
end

#extended?Boolean

Returns whether this player object has extended information

Returns:

  • (Boolean)


55
56
57
# File 'lib/steam/steam_player.rb', line 55

def extended?
  @extended
end

#to_sObject

Returns a String representation of this player



60
61
62
63
64
65
66
# File 'lib/steam/steam_player.rb', line 60

def to_s
  if @extended
    "\##{@real_id} \"#{@name}\", SteamID: #{@steam_id}, Score: #{@score}, Time: #{@connect_time}"
  else
    "\##{@id} \"#{@name}\", Score: #{@score}, Time: #{@connect_time}"
  end
end