Class: SteamPlayer
- Inherits:
-
Object
- Object
- SteamPlayer
- Defined in:
- lib/steam/steam_player.rb
Overview
The SteamPlayer class represents a player connected to a server
Instance Attribute Summary collapse
-
#client_port ⇒ Object
readonly
Returns the value of attribute client_port.
-
#connect_time ⇒ Object
readonly
Returns the value of attribute connect_time.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#ip_address ⇒ Object
readonly
Returns the value of attribute ip_address.
-
#loss ⇒ Object
readonly
Returns the value of attribute loss.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#ping ⇒ Object
readonly
Returns the value of attribute ping.
-
#rate ⇒ Object
readonly
Returns the value of attribute rate.
-
#real_id ⇒ Object
readonly
Returns the value of attribute real_id.
-
#score ⇒ Object
readonly
Returns the value of attribute score.
-
#state ⇒ Object
readonly
Returns the value of attribute state.
-
#steam_id ⇒ Object
readonly
Returns the value of attribute steam_id.
Instance Method Summary collapse
-
#add_info(player_data) ⇒ Object
Extends this player object with additional information acquired using RCON status.
-
#bot? ⇒ Boolean
Returns whether this player is a bot.
-
#extended? ⇒ Boolean
Returns whether this player object has extended information.
-
#initialize(id, name, score, connect_time) ⇒ SteamPlayer
constructor
Creates a new SteamPlayer object based on the given information.
-
#to_s ⇒ Object
Returns a String representation of this player.
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_port ⇒ Object (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_time ⇒ Object (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 |
#id ⇒ Object (readonly)
Returns the value of attribute id.
11 12 13 |
# File 'lib/steam/steam_player.rb', line 11 def id @id end |
#ip_address ⇒ Object (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 |
#loss ⇒ Object (readonly)
Returns the value of attribute loss.
11 12 13 |
# File 'lib/steam/steam_player.rb', line 11 def loss @loss end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
11 12 13 |
# File 'lib/steam/steam_player.rb', line 11 def name @name end |
#ping ⇒ Object (readonly)
Returns the value of attribute ping.
11 12 13 |
# File 'lib/steam/steam_player.rb', line 11 def ping @ping end |
#rate ⇒ Object (readonly)
Returns the value of attribute rate.
11 12 13 |
# File 'lib/steam/steam_player.rb', line 11 def rate @rate end |
#real_id ⇒ Object (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 |
#score ⇒ Object (readonly)
Returns the value of attribute score.
11 12 13 |
# File 'lib/steam/steam_player.rb', line 11 def score @score end |
#state ⇒ Object (readonly)
Returns the value of attribute state.
11 12 13 |
# File 'lib/steam/steam_player.rb', line 11 def state @state end |
#steam_id ⇒ Object (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
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
55 56 57 |
# File 'lib/steam/steam_player.rb', line 55 def extended? @extended end |
#to_s ⇒ Object
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 |