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 ⇒ Fixnum
readonly
Returns the client port of this player.
-
#connect_time ⇒ Float
readonly
Returns the time this player is connected to the server.
-
#id ⇒ Fixnum
readonly
Returns the ID of this player.
-
#ip_address ⇒ String
readonly
Returns the IP address of this player.
-
#loss ⇒ String
readonly
Returns the packet loss of this player’s connection.
-
#name ⇒ String
readonly
Returns the nickname of this player.
-
#ping ⇒ Fixnum
readonly
Returns the ping of this player.
-
#rate ⇒ Fixnum
readonly
Returns the rate of this player.
-
#real_id ⇒ Fixnum
readonly
Returns the real ID (as used on the server) of this player.
-
#score ⇒ Fixnum
readonly
Returns the score of this player.
-
#state ⇒ String
readonly
Returns the connection state of this player.
-
#steam_id ⇒ String
readonly
Returns the SteamID of this player.
Instance Method Summary collapse
-
#add_info(player_data) ⇒ Object
Extends a player object with information retrieved from a RCON call to the status command.
-
#bot? ⇒ Boolean
Returns whether this player is a bot.
-
#extended? ⇒ Boolean
Returns whether this player object has extended information gathered using RCON.
-
#initialize(id, name, score, connect_time) ⇒ SteamPlayer
constructor
Creates a new player instance with the given information.
-
#to_s ⇒ String
Returns a string representation of this player.
Constructor Details
#initialize(id, name, score, connect_time) ⇒ SteamPlayer
Creates a new player instance with the given information
79 80 81 82 83 84 85 |
# File 'lib/steam/steam_player.rb', line 79 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 ⇒ Fixnum (readonly)
Returns the client port of this player
16 17 18 |
# File 'lib/steam/steam_player.rb', line 16 def client_port @client_port end |
#connect_time ⇒ Float (readonly)
Returns the time this player is connected to the server
21 22 23 |
# File 'lib/steam/steam_player.rb', line 21 def connect_time @connect_time end |
#id ⇒ Fixnum (readonly)
Returns the ID of this player
26 27 28 |
# File 'lib/steam/steam_player.rb', line 26 def id @id end |
#ip_address ⇒ String (readonly)
Returns the IP address of this player
31 32 33 |
# File 'lib/steam/steam_player.rb', line 31 def ip_address @ip_address end |
#loss ⇒ String (readonly)
Returns the packet loss of this player’s connection
41 42 43 |
# File 'lib/steam/steam_player.rb', line 41 def loss @loss end |
#name ⇒ String (readonly)
Returns the nickname of this player
36 37 38 |
# File 'lib/steam/steam_player.rb', line 36 def name @name end |
#ping ⇒ Fixnum (readonly)
Returns the ping of this player
46 47 48 |
# File 'lib/steam/steam_player.rb', line 46 def ping @ping end |
#rate ⇒ Fixnum (readonly)
Returns the rate of this player
51 52 53 |
# File 'lib/steam/steam_player.rb', line 51 def rate @rate end |
#real_id ⇒ Fixnum (readonly)
Returns the real ID (as used on the server) of this player
56 57 58 |
# File 'lib/steam/steam_player.rb', line 56 def real_id @real_id end |
#score ⇒ Fixnum (readonly)
Returns the score of this player
61 62 63 |
# File 'lib/steam/steam_player.rb', line 61 def score @score end |
#state ⇒ String (readonly)
Returns the connection state of this player
66 67 68 |
# File 'lib/steam/steam_player.rb', line 66 def state @state end |
#steam_id ⇒ String (readonly)
Returns the SteamID of this player
71 72 73 |
# File 'lib/steam/steam_player.rb', line 71 def steam_id @steam_id end |
Instance Method Details
#add_info(player_data) ⇒ Object
Extends a player object with information retrieved from a RCON call to the status command
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/steam/steam_player.rb', line 93 def add_info(player_data) unless player_data[:name] == @name raise SteamCondenserError, '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
120 121 122 |
# File 'lib/steam/steam_player.rb', line 120 def bot? @steam_id == 'BOT' end |
#extended? ⇒ Boolean
Returns whether this player object has extended information gathered using RCON
128 129 130 |
# File 'lib/steam/steam_player.rb', line 128 def extended? @extended end |
#to_s ⇒ String
Returns a string representation of this player
135 136 137 138 139 140 141 |
# File 'lib/steam/steam_player.rb', line 135 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 |