Class: SteamCondenser::Servers::SteamPlayer

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

Overview

The SteamPlayer class represents a player connected to a server

Author:

  • Sebastian Staudt

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Creates a new player instance with the given information


82
83
84
85
86
87
88
# File 'lib/steam-condenser/servers/steam_player.rb', line 82

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

Instance Attribute Details

#client_portFixnum (readonly)

Returns the client port of this player


18
19
20
# File 'lib/steam-condenser/servers/steam_player.rb', line 18

def client_port
  @client_port
end

#connect_timeFloat (readonly)

Returns the time this player is connected to the server


23
24
25
# File 'lib/steam-condenser/servers/steam_player.rb', line 23

def connect_time
  @connect_time
end

#idFixnum (readonly)

Returns the ID of this player


28
29
30
# File 'lib/steam-condenser/servers/steam_player.rb', line 28

def id
  @id
end

#ip_addressString (readonly)

Returns the IP address of this player


33
34
35
# File 'lib/steam-condenser/servers/steam_player.rb', line 33

def ip_address
  @ip_address
end

#lossString (readonly)

Returns the packet loss of this player's connection


43
44
45
# File 'lib/steam-condenser/servers/steam_player.rb', line 43

def loss
  @loss
end

#nameString (readonly)

Returns the nickname of this player


38
39
40
# File 'lib/steam-condenser/servers/steam_player.rb', line 38

def name
  @name
end

#pingFixnum (readonly)

Returns the ping of this player


48
49
50
# File 'lib/steam-condenser/servers/steam_player.rb', line 48

def ping
  @ping
end

#rateFixnum (readonly)

Returns the rate of this player


53
54
55
# File 'lib/steam-condenser/servers/steam_player.rb', line 53

def rate
  @rate
end

#real_idFixnum (readonly)

Returns the real ID (as used on the server) of this player


58
59
60
# File 'lib/steam-condenser/servers/steam_player.rb', line 58

def real_id
  @real_id
end

#scoreFixnum (readonly)

Returns the score of this player


63
64
65
# File 'lib/steam-condenser/servers/steam_player.rb', line 63

def score
  @score
end

#stateString (readonly)

Returns the connection state of this player


68
69
70
# File 'lib/steam-condenser/servers/steam_player.rb', line 68

def state
  @state
end

#steam_idString (readonly)

Returns the SteamID of this player


73
74
75
# File 'lib/steam-condenser/servers/steam_player.rb', line 73

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

Raises:

  • (Error)

    if the information belongs to another player


95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/steam-condenser/servers/steam_player.rb', line 95

def add_info(player_data)
  unless player_data[:name] == @name
    raise Error, '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


122
123
124
# File 'lib/steam-condenser/servers/steam_player.rb', line 122

def bot?
  @steam_id == 'BOT'
end

#extended?Boolean

Returns whether this player object has extended information gathered using RCON


130
131
132
# File 'lib/steam-condenser/servers/steam_player.rb', line 130

def extended?
  @extended
end

#to_sString

Returns a string representation of this player


137
138
139
140
141
142
143
# File 'lib/steam-condenser/servers/steam_player.rb', line 137

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