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

#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(real_id, name, steam_id, *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
# File 'lib/steam/steam_player.rb', line 25

def add_info(real_id, name, steam_id, *player_data)
  @extended = true

  unless name == @name
    raise SteamCondenserException.new('Information to add belongs to a different player.')
  end

  @real_id  = real_id
  @steam_id = steam_id
  if steam_id == 'BOT'
    @state = player_data[0]
  else
    @ip_address, @client_port  = player_data[4].split(':')
    @loss  = player_data[2]
    @ping  = player_data[1]
    @state = player_data[3]
  end
end

#to_sObject

Returns a String representation of this player



45
46
47
48
49
50
51
# File 'lib/steam/steam_player.rb', line 45

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